From 66c2e911bf7827e6a48d6cc7b5a30d02a947ac62 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Tue, 8 Feb 2005 02:05:24 +0000 Subject: [PATCH] Fixed JUnits. --- .../tests/ast2/CompleteParser2Tests.java | 6 +-- .../parser/AbstractGNUSourceCodeParser.java | 6 +-- .../core/dom/parser/c/GNUCSourceParser.java | 8 ++-- .../dom/parser/cpp/GNUCPPSourceParser.java | 44 +++++++++++-------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index 879dc7e3501..f3ef92c2640 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -786,12 +786,12 @@ public class CompleteParser2Tests extends TestCase { public void testNewExpressions() throws Exception { - IASTTranslationUnit tu = parse( "int A; int B; int C; int D; int P; int*p = new (P) (A)[B][C][D];" ); //$NON-NLS-1$ + IASTTranslationUnit tu = parse( "typedef int A; int B; int C; int D; int P; int*p = new (P) (A)[B][C][D];" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); CPPVisitor.visitTranslationUnit( tu, col ); assertEquals( col.size(), 11 ); - IVariable A = (IVariable) col.getName(0).resolveBinding(); + ITypedef A = (ITypedef) col.getName(0).resolveBinding(); IVariable B = (IVariable) col.getName(1).resolveBinding(); IVariable C = (IVariable) col.getName(2).resolveBinding(); IVariable D = (IVariable) col.getName(3).resolveBinding(); @@ -1173,7 +1173,7 @@ public class CompleteParser2Tests extends TestCase { public void testBug39504() throws Exception { - IASTTranslationUnit tu = parse( "const int w = 2; int x[ 5 ]; int y = sizeof (x[w]);" ); //$NON-NLS-1$ + IASTTranslationUnit tu = parse( "const int w = 2; int x[ 5 ]; int y = sizeof ( x[w] );" ); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); CPPVisitor.visitTranslationUnit( tu, col ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index c8532a63e4f..609ef571b1d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -592,7 +592,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected abstract IASTExpression multiplicativeExpression() throws BacktrackException, EndOfFileException; - protected abstract IASTTypeId typeId(boolean skipArrayMods) + protected abstract IASTTypeId typeId(boolean skipArrayMods, boolean forNewExpression) throws BacktrackException, EndOfFileException; protected abstract IASTExpression castExpression() @@ -894,7 +894,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (LT(1) == IToken.tLPAREN) { try { consume(IToken.tLPAREN); - d = typeId(false); + d = typeId(false, false); lastOffset = consume(IToken.tRPAREN).getEndOffset(); } catch (BacktrackException bt) { backup(m); @@ -930,7 +930,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } else try { consume(IToken.tLPAREN); - d = typeId(false); + d = typeId(false, false); lastOffset = consume(IToken.tRPAREN).getEndOffset(); } catch (BacktrackException bt) { backup(m); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 17e0bb2a69f..3e2c40b3507 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -771,7 +771,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { // If this isn't a type name, then we shouldn't be here try { try { - typeId = typeId(false); + typeId = typeId(false, false); consume(IToken.tRPAREN); castExpression = castExpression(); } catch (BacktrackException bte) { @@ -821,7 +821,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tLPAREN) { try { consume(IToken.tLPAREN); - typeId = typeId(false); + typeId = typeId(false, false); lastOffset = consume(IToken.tRPAREN).getEndOffset(); } catch (BacktrackException bt) { backup(mark); @@ -896,7 +896,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IToken m = mark(); try { int offset = consume(IToken.tLPAREN).getOffset(); - IASTTypeId t = typeId(false); + IASTTypeId t = typeId(false, false); int lastOffset = consume(IToken.tRPAREN).getEndOffset(); IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST); firstExpression = buildTypeIdInitializerExpression(t, i, offset, @@ -1150,7 +1150,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTIdExpression(); } - protected IASTTypeId typeId(boolean skipArrayModifiers) + protected IASTTypeId typeId(boolean skipArrayModifiers, boolean forNewExpression) throws EndOfFileException, BacktrackException { IToken mark = mark(); int startingOffset = mark.getOffset(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index b0ac22365d8..483c67ef92b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -270,7 +270,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken mark = mark(); try { - IASTTypeId typeId = typeId(false); + IASTTypeId typeId = typeId(false, false); list.add(typeId); completedArg = true; } catch (BacktrackException e) { @@ -443,7 +443,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { // must be a conversion function IToken t = LA(1); - typeId(true); + typeId(true, false); if (t != LA(1)) { while (t.getNext() != LA(1)) { t = t.getNext(); @@ -858,7 +858,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // If this isn't a type name, then we shouldn't be here try { try { - typeId = typeId(false); + typeId = typeId(false, false); consume(IToken.tRPAREN); } catch (BacktrackException bte) { backup(mark); @@ -887,7 +887,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * @throws BacktrackException */ - protected IASTTypeId typeId(boolean skipArrayModifiers) + protected IASTTypeId typeId(boolean skipArrayModifiers, boolean forNewExpression) throws EndOfFileException, BacktrackException { IToken mark = mark(); int startingOffset = mark.getOffset(); @@ -897,7 +897,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { declSpecifier = declSpecifierSeq(true, true); declarator = declarator(SimpleDeclarationStrategy.TRY_CONSTRUCTOR, - true); + true, forNewExpression ); } catch (BacktrackException bt) { backup(mark); throwBacktrack(startingOffset, figureEndOffset(declSpecifier, @@ -918,6 +918,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { declarator) - startingOffset); } + if ( declarator instanceof IASTArrayDeclarator && skipArrayModifiers ) { + backup(mark); + throwBacktrack(startingOffset, figureEndOffset(declSpecifier, + declarator) + - startingOffset); + } IASTTypeId result = createTypeId(); ((ASTNode) result).setOffsetAndLength(startingOffset, figureEndOffset( @@ -1061,7 +1067,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // CASE: new (typeid-not-looking-as-placement) ... // the first expression in () is not a placement // - then it has to be typeId - typeId = typeId(true); + typeId = typeId(true, false); lastOffset = consume(IToken.tRPAREN).getEndOffset(); if (templateIdScopes.size() > 0) { templateIdScopes.pop(); @@ -1084,7 +1090,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // - then it has to be typeId try { backtrackMarker = mark(); - typeId = typeId(true); + typeId = typeId(true, true); lastOffset = calculateEndOffset(typeId); break master_new_loop; } catch (BacktrackException e) { @@ -1102,7 +1108,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // The problem is, the first expression might as well be a // typeid try { - typeId = typeId(true); + typeId = typeId(true, false); lastOffset = consume(IToken.tRPAREN).getEndOffset(); if (templateIdScopes.size() > 0) { templateIdScopes.pop(); @@ -1156,7 +1162,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // CASE: new typeid ... // new parameters do not start with '(' // i.e it has to be a plain typeId - typeId = typeId(true); + typeId = typeId(true, true); lastOffset = calculateEndOffset(typeId); isNewTypeId = true; break master_new_loop; @@ -1269,7 +1275,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tLPAREN) { try { consume(IToken.tLPAREN); - typeId = typeId(false); + typeId = typeId(true, false); lastOffset = consume(IToken.tRPAREN).getEndOffset(); } catch (BacktrackException bt) { backup(mark); @@ -1411,7 +1417,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTTypeId typeId = null; try { - typeId = typeId(false); + typeId = typeId(false, false); } catch (BacktrackException b) { isTypeId = false; lhs = expression(); @@ -1780,7 +1786,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { int startingOffset = LA(1).getOffset(); consume(); consume(IToken.tLT); - IASTTypeId typeID = typeId(false); + IASTTypeId typeID = typeId(false, false); consume(IToken.tGT); consume(IToken.tLPAREN); IASTExpression lhs = expression(); @@ -2168,7 +2174,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tASSIGN) // optional = type-id { consume(IToken.tASSIGN); - typeId = typeId(false); // type-id + typeId = typeId(false, false); // type-id lastOffset = calculateEndOffset(typeId); } } else { @@ -3350,7 +3356,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ protected IASTDeclarator initDeclarator(SimpleDeclarationStrategy strategy) throws EndOfFileException, BacktrackException { - IASTDeclarator d = declarator(strategy, false); + IASTDeclarator d = declarator(strategy, false, false ); IASTInitializer initializer = optionalCPPInitializer(); if (initializer != null) { @@ -3478,17 +3484,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * (oldKRParameterDeclaration)* * * declaratorId : name - * * @param forTypeID * TODO + * @param skipArrayDeclarator TODO * @param container * IParserCallback object that represents the owner declaration. + * * @return declarator that this parsing produced. * @throws BacktrackException * request a backtrack */ protected IASTDeclarator declarator(SimpleDeclarationStrategy strategy, - boolean forTypeID) throws EndOfFileException, BacktrackException { + boolean forTypeID, boolean skipArrayDeclarator) throws EndOfFileException, BacktrackException { IToken la = LA(1); int startingOffset = la.getOffset(); @@ -3516,7 +3523,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken mark = mark(); try { consume(); - innerDecl = declarator(strategy, forTypeID); + innerDecl = declarator(strategy, forTypeID, skipArrayDeclarator); finalOffset = consume(IToken.tRPAREN).getEndOffset(); } catch (BacktrackException bte) { backup(mark); @@ -3647,7 +3654,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break; default: try { - exceptionSpecIds.add(typeId(false)); + exceptionSpecIds.add(typeId(false, false ) ); } catch (BacktrackException e) { IASTProblem p = failParse(e); IASTProblemTypeId typeIdProblem = createTypeIDProblem(); @@ -3691,6 +3698,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } break; case IToken.tLBRACKET: + if( skipArrayDeclarator ) break; arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE); consumeArrayModifiers(arrayMods); if (!arrayMods.isEmpty())