1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

Partial fix for 81806 - [Parser2] Constructor Initializer is mistaken as function prototype

This commit is contained in:
John Camelon 2005-01-26 15:57:10 +00:00
parent ddeca093ea
commit ae8ed5955f

View file

@ -1784,6 +1784,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4; private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4;
private static final int DEFAULT_SIZE_EXCEPTIONS_LIST = 2; private static final int DEFAULT_SIZE_EXCEPTIONS_LIST = 2;
private static final int DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE = 4; private static final int DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE = 4;
private IASTNode mostRelevantScopeNode;
/** /**
* This is the standard cosntructor that we expect the Parser to be * This is the standard cosntructor that we expect the Parser to be
@ -2286,8 +2287,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTProblem firstFailure = null; IASTProblem firstFailure = null;
IASTProblem secondFailure = null; IASTProblem secondFailure = null;
try { try {
IASTDeclaration d = simpleDeclaration(SimpleDeclarationStrategy.TRY_CONSTRUCTOR, IASTDeclaration d = simpleDeclaration(
false); SimpleDeclarationStrategy.TRY_CONSTRUCTOR, false);
throwAwayMarksForInitializerClause(); throwAwayMarksForInitializerClause();
return d; return d;
} catch (BacktrackException bt) { } catch (BacktrackException bt) {
@ -2298,8 +2299,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
backup(simpleDeclarationMark); backup(simpleDeclarationMark);
try { try {
IASTDeclaration d = simpleDeclaration(SimpleDeclarationStrategy.TRY_FUNCTION, IASTDeclaration d = simpleDeclaration(
false); SimpleDeclarationStrategy.TRY_FUNCTION, false);
throwAwayMarksForInitializerClause(); throwAwayMarksForInitializerClause();
return d; return d;
} catch (BacktrackException bt2) { } catch (BacktrackException bt2) {
@ -2366,6 +2367,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
namespaceDefinition.setName(name); namespaceDefinition.setName(name);
name.setParent(namespaceDefinition); name.setParent(namespaceDefinition);
name.setPropertyInParent(ICPPASTNamespaceDefinition.NAMESPACE_NAME); name.setPropertyInParent(ICPPASTNamespaceDefinition.NAMESPACE_NAME);
IASTNode n = mostRelevantScopeNode;
mostRelevantScopeNode = namespaceDefinition;
try {
namespaceDeclarationLoop: while (LT(1) != IToken.tRBRACE) { namespaceDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
int checkToken = LA(1).hashCode(); int checkToken = LA(1).hashCode();
switch (LT(1)) { switch (LT(1)) {
@ -2397,6 +2403,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (checkToken == LA(1).hashCode()) if (checkToken == LA(1).hashCode())
failParseWithErrorHandling(); failParseWithErrorHandling();
} }
} finally {
mostRelevantScopeNode = n;
}
// consume the } // consume the }
int end = consume(IToken.tRBRACE).getEndOffset(); int end = consume(IToken.tRBRACE).getEndOffset();
((CPPASTNode) namespaceDefinition).setLength(end - first.getOffset()); ((CPPASTNode) namespaceDefinition).setLength(end - first.getOffset());
@ -2635,7 +2644,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
declSpec.setParent(funcDefinition); declSpec.setParent(funcDefinition);
declSpec.setPropertyInParent(IASTFunctionDefinition.DECL_SPECIFIER); declSpec.setPropertyInParent(IASTFunctionDefinition.DECL_SPECIFIER);
funcDefinition.setDeclarator((IASTStandardFunctionDeclarator) declarator); funcDefinition
.setDeclarator((IASTStandardFunctionDeclarator) declarator);
declarator.setParent(funcDefinition); declarator.setParent(funcDefinition);
declarator.setPropertyInParent(IASTFunctionDefinition.DECLARATOR); declarator.setPropertyInParent(IASTFunctionDefinition.DECLARATOR);
@ -2674,8 +2684,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (consumedSemi) if (consumedSemi)
length = semiOffset - firstOffset; length = semiOffset - firstOffset;
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset, ((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset, length);
length);
simpleDeclaration.setDeclSpecifier(declSpec); simpleDeclaration.setDeclSpecifier(declSpec);
declSpec.setParent(simpleDeclaration); declSpec.setParent(simpleDeclaration);
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER); declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
@ -3457,7 +3466,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
consumePointerOperators(pointerOps); consumePointerOperators(pointerOps);
if (!pointerOps.isEmpty()) if (!pointerOps.isEmpty())
finalOffset = calculateEndOffset( (IASTNode) pointerOps.get( pointerOps.size() - 1 ) ); finalOffset = calculateEndOffset((IASTNode) pointerOps
.get(pointerOps.size() - 1));
if (!forTypeID && LT(1) == IToken.tLPAREN) { if (!forTypeID && LT(1) == IToken.tLPAREN) {
IToken mark = mark(); IToken mark = mark();
@ -3640,7 +3650,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE); arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
consumeArrayModifiers(arrayMods); consumeArrayModifiers(arrayMods);
if (!arrayMods.isEmpty()) if (!arrayMods.isEmpty())
finalOffset = calculateEndOffset( (IASTNode) arrayMods.get( arrayMods.size() - 1 ) ); finalOffset = calculateEndOffset((IASTNode) arrayMods
.get(arrayMods.size() - 1));
continue; continue;
case IToken.tCOLON: case IToken.tCOLON:
consume(IToken.tCOLON); consume(IToken.tCOLON);
@ -3670,7 +3681,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
.get(i); .get(i);
p.setParent(fc); p.setParent(fc);
p.setPropertyInParent(IASTStandardFunctionDeclarator.FUNCTION_PARAMETER); p
.setPropertyInParent(IASTStandardFunctionDeclarator.FUNCTION_PARAMETER);
fc.addParameterDeclaration(p); fc.addParameterDeclaration(p);
} }
fc.setConst(isConst); fc.setConst(isConst);
@ -3716,7 +3728,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME); declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME);
} }
((ASTNode)d).setOffsetAndLength( startingOffset, finalOffset - startingOffset ); ((ASTNode) d).setOffsetAndLength(startingOffset, finalOffset
- startingOffset);
return d; return d;
} }
@ -3886,6 +3899,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (LT(1) == IToken.tLBRACE) { if (LT(1) == IToken.tLBRACE) {
consume(IToken.tLBRACE); consume(IToken.tLBRACE);
IASTNode n = mostRelevantScopeNode;
mostRelevantScopeNode = astClassSpecifier;
try {
memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) { memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
int checkToken = LA(1).hashCode(); int checkToken = LA(1).hashCode();
switch (LT(1)) { switch (LT(1)) {
@ -3927,10 +3944,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (checkToken == LA(1).hashCode()) if (checkToken == LA(1).hashCode())
errorHandling(); errorHandling();
} }
}
if (checkToken == LA(1).hashCode()) if (checkToken == LA(1).hashCode())
failParseWithErrorHandling(); failParseWithErrorHandling();
} }
}
} finally {
mostRelevantScopeNode = n;
}
// consume the } // consume the }
int l = consume(IToken.tRBRACE).getEndOffset(); int l = consume(IToken.tRBRACE).getEndOffset();
((ASTNode) astClassSpecifier).setLength(l - classKey.getOffset()); ((ASTNode) astClassSpecifier).setLength(l - classKey.getOffset());
@ -4209,6 +4230,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
} }
translationUnit.setLocationResolver(scanner.getLocationResolver()); translationUnit.setLocationResolver(scanner.getLocationResolver());
mostRelevantScopeNode = translationUnit;
while (true) { while (true) {
try { try {
int checkOffset = LA(1).hashCode(); int checkOffset = LA(1).hashCode();