mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fix for 171520, node length of type-id expression
This commit is contained in:
parent
a92749a43e
commit
fe49cf75df
5 changed files with 48 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,12 +7,15 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Mar 11, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
|
@ -68,6 +71,10 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(AST2TemplateTests.class);
|
||||
}
|
||||
|
||||
public void testBasicClassTemplate() throws Exception {
|
||||
IASTTranslationUnit tu = parse( "template <class T> class A{ T t; };", ParserLanguage.CPP ); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
|
@ -15,7 +16,7 @@ import java.io.Writer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
|
@ -68,6 +69,7 @@ import org.eclipse.cdt.core.parser.NullLogService;
|
|||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
|
@ -90,7 +92,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CompleteParser2Tests extends TestCase {
|
||||
public class CompleteParser2Tests extends BaseTestCase {
|
||||
|
||||
private static final NullLogService NULL_LOG = new NullLogService();
|
||||
|
||||
|
@ -100,6 +102,10 @@ public class CompleteParser2Tests extends TestCase {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(CompleteParser2Tests.class);
|
||||
}
|
||||
|
||||
static private class CPPNameCollector extends CPPASTVisitor {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -11,6 +11,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
|
@ -75,6 +77,10 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
setName(name);
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(DOMLocationTests.class);
|
||||
}
|
||||
|
||||
public void testBaseCase() throws ParserException {
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
|
@ -671,7 +677,7 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
assertSoleLocation(problems[0], buffer.indexOf("X"), "X".length() );
|
||||
}
|
||||
|
||||
public void _testBug171520() throws Exception {
|
||||
public void testBug171520() throws Exception {
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171520
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int i = sizeof(int);");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -28,10 +28,10 @@ public class DOMParserTestSuite extends TestCase {
|
|||
suite.addTest( AST2Tests.suite() );
|
||||
suite.addTestSuite( GCCTests.class );
|
||||
suite.addTestSuite( AST2CPPTests.class );
|
||||
suite.addTestSuite( AST2TemplateTests.class );
|
||||
suite.addTest( AST2TemplateTests.suite() );
|
||||
suite.addTestSuite( QuickParser2Tests.class );
|
||||
suite.addTestSuite( CompleteParser2Tests.class );
|
||||
suite.addTestSuite( DOMLocationTests.class );
|
||||
suite.addTest( CompleteParser2Tests.suite() );
|
||||
suite.addTest( DOMLocationTests.suite() );
|
||||
suite.addTestSuite( DOMLocationMacroTests.class );
|
||||
suite.addTest( DOMLocationInclusionTests.suite() );
|
||||
suite.addTestSuite( AST2KnRTests.class );
|
||||
|
|
|
@ -2080,6 +2080,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
protected IASTNode[] parseTypeIdOrUnaryExpression(
|
||||
boolean typeIdWithParentheses) throws EndOfFileException {
|
||||
return parseTypeIdOrUnaryExpression(typeIdWithParentheses, new int[1]);
|
||||
}
|
||||
|
||||
protected IASTNode[] parseTypeIdOrUnaryExpression(
|
||||
boolean typeIdWithParentheses, int[] endoffset) throws EndOfFileException {
|
||||
IASTTypeId typeId = null;
|
||||
IASTExpression unaryExpression = null;
|
||||
IToken typeIdLA = null, unaryExpressionLA = null;
|
||||
|
@ -2094,13 +2099,18 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
switch (LT(1)) {
|
||||
case IToken.tRPAREN:
|
||||
case IToken.tEOC:
|
||||
consume();
|
||||
endoffset[0]= consume().getEndOffset();
|
||||
break;
|
||||
default:
|
||||
typeId = null;
|
||||
}
|
||||
}
|
||||
if (typeId != null) typeIdLA = LA(1);
|
||||
if (typeId != null) {
|
||||
typeIdLA = LA(1);
|
||||
if (!typeIdWithParentheses) {
|
||||
endoffset[0]= calculateEndOffset(typeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (BacktrackException e) {
|
||||
typeId = null;
|
||||
|
@ -2123,6 +2133,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
backup(unaryExpressionLA);
|
||||
result = new IASTNode[1];
|
||||
result[0] = unaryExpression;
|
||||
endoffset[0]= calculateEndOffset(unaryExpression);
|
||||
return result;
|
||||
}
|
||||
if (unaryExpression != null && typeId != null
|
||||
|
@ -2141,27 +2152,26 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
protected IASTExpression parseSizeofExpression() throws BacktrackException,
|
||||
EndOfFileException {
|
||||
int startingOffset = consume().getOffset(); // t_sizeof
|
||||
IASTNode[] choice = parseTypeIdOrUnaryExpression(true);
|
||||
int[] endoffset= new int[] {0};
|
||||
IASTNode[] choice = parseTypeIdOrUnaryExpression(true, endoffset);
|
||||
switch (choice.length) {
|
||||
case 1:
|
||||
int lastOffset = calculateEndOffset(choice[0]);
|
||||
if (choice[0] instanceof IASTExpression)
|
||||
return buildUnaryExpression(IASTUnaryExpression.op_sizeof,
|
||||
(IASTExpression) choice[0], startingOffset, lastOffset);
|
||||
(IASTExpression) choice[0], startingOffset, endoffset[0]);
|
||||
else if (choice[0] instanceof IASTTypeId)
|
||||
return buildTypeIdExpression(IASTTypeIdExpression.op_sizeof,
|
||||
(IASTTypeId) choice[0], startingOffset, lastOffset);
|
||||
(IASTTypeId) choice[0], startingOffset, endoffset[0]);
|
||||
throwBacktrack(LA(1));
|
||||
break;
|
||||
case 2:
|
||||
lastOffset = calculateEndOffset(choice[0]);
|
||||
IASTAmbiguousExpression ambExpr = createAmbiguousExpression();
|
||||
IASTExpression e1 = buildTypeIdExpression(
|
||||
IASTTypeIdExpression.op_sizeof, (IASTTypeId) choice[0],
|
||||
startingOffset, lastOffset);
|
||||
startingOffset, endoffset[0]);
|
||||
IASTExpression e2 = buildUnaryExpression(
|
||||
IASTUnaryExpression.op_sizeof, (IASTExpression) choice[1],
|
||||
startingOffset, lastOffset);
|
||||
startingOffset, endoffset[0]);
|
||||
ambExpr.addExpression(e1);
|
||||
e1.setParent(ambExpr);
|
||||
e1.setPropertyInParent(IASTAmbiguousExpression.SUBEXPRESSION);
|
||||
|
|
Loading…
Add table
Reference in a new issue