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:
parent
ddeca093ea
commit
ae8ed5955f
1 changed files with 109 additions and 87 deletions
|
@ -1784,6 +1784,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4;
|
||||
private static final int DEFAULT_SIZE_EXCEPTIONS_LIST = 2;
|
||||
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
|
||||
|
@ -2286,8 +2287,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTProblem firstFailure = null;
|
||||
IASTProblem secondFailure = null;
|
||||
try {
|
||||
IASTDeclaration d = simpleDeclaration(SimpleDeclarationStrategy.TRY_CONSTRUCTOR,
|
||||
false);
|
||||
IASTDeclaration d = simpleDeclaration(
|
||||
SimpleDeclarationStrategy.TRY_CONSTRUCTOR, false);
|
||||
throwAwayMarksForInitializerClause();
|
||||
return d;
|
||||
} catch (BacktrackException bt) {
|
||||
|
@ -2298,8 +2299,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
backup(simpleDeclarationMark);
|
||||
|
||||
try {
|
||||
IASTDeclaration d = simpleDeclaration(SimpleDeclarationStrategy.TRY_FUNCTION,
|
||||
false);
|
||||
IASTDeclaration d = simpleDeclaration(
|
||||
SimpleDeclarationStrategy.TRY_FUNCTION, false);
|
||||
throwAwayMarksForInitializerClause();
|
||||
return d;
|
||||
} catch (BacktrackException bt2) {
|
||||
|
@ -2366,6 +2367,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
namespaceDefinition.setName(name);
|
||||
name.setParent(namespaceDefinition);
|
||||
name.setPropertyInParent(ICPPASTNamespaceDefinition.NAMESPACE_NAME);
|
||||
|
||||
IASTNode n = mostRelevantScopeNode;
|
||||
mostRelevantScopeNode = namespaceDefinition;
|
||||
|
||||
try {
|
||||
namespaceDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
|
||||
int checkToken = LA(1).hashCode();
|
||||
switch (LT(1)) {
|
||||
|
@ -2397,6 +2403,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (checkToken == LA(1).hashCode())
|
||||
failParseWithErrorHandling();
|
||||
}
|
||||
} finally {
|
||||
mostRelevantScopeNode = n;
|
||||
}
|
||||
// consume the }
|
||||
int end = consume(IToken.tRBRACE).getEndOffset();
|
||||
((CPPASTNode) namespaceDefinition).setLength(end - first.getOffset());
|
||||
|
@ -2635,7 +2644,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
declSpec.setParent(funcDefinition);
|
||||
declSpec.setPropertyInParent(IASTFunctionDefinition.DECL_SPECIFIER);
|
||||
|
||||
funcDefinition.setDeclarator((IASTStandardFunctionDeclarator) declarator);
|
||||
funcDefinition
|
||||
.setDeclarator((IASTStandardFunctionDeclarator) declarator);
|
||||
declarator.setParent(funcDefinition);
|
||||
declarator.setPropertyInParent(IASTFunctionDefinition.DECLARATOR);
|
||||
|
||||
|
@ -2671,11 +2681,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
|
||||
int length = figureEndOffset(declSpec, declarators) - firstOffset;
|
||||
if( consumedSemi )
|
||||
if (consumedSemi)
|
||||
length = semiOffset - firstOffset;
|
||||
|
||||
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset,
|
||||
length);
|
||||
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset, length);
|
||||
simpleDeclaration.setDeclSpecifier(declSpec);
|
||||
declSpec.setParent(simpleDeclaration);
|
||||
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
|
||||
|
@ -3456,8 +3465,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
overallLoop: do {
|
||||
|
||||
consumePointerOperators(pointerOps);
|
||||
if( ! pointerOps.isEmpty() )
|
||||
finalOffset = calculateEndOffset( (IASTNode) pointerOps.get( pointerOps.size() - 1 ) );
|
||||
if (!pointerOps.isEmpty())
|
||||
finalOffset = calculateEndOffset((IASTNode) pointerOps
|
||||
.get(pointerOps.size() - 1));
|
||||
|
||||
if (!forTypeID && LT(1) == IToken.tLPAREN) {
|
||||
IToken mark = mark();
|
||||
|
@ -3639,13 +3649,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
case IToken.tLBRACKET:
|
||||
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
||||
consumeArrayModifiers(arrayMods);
|
||||
if( ! arrayMods.isEmpty() )
|
||||
finalOffset = calculateEndOffset( (IASTNode) arrayMods.get( arrayMods.size() - 1 ) );
|
||||
if (!arrayMods.isEmpty())
|
||||
finalOffset = calculateEndOffset((IASTNode) arrayMods
|
||||
.get(arrayMods.size() - 1));
|
||||
continue;
|
||||
case IToken.tCOLON:
|
||||
consume(IToken.tCOLON);
|
||||
bitField = constantExpression();
|
||||
finalOffset = calculateEndOffset( bitField );
|
||||
finalOffset = calculateEndOffset(bitField);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -3670,7 +3681,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
|
||||
.get(i);
|
||||
p.setParent(fc);
|
||||
p.setPropertyInParent(IASTStandardFunctionDeclarator.FUNCTION_PARAMETER);
|
||||
p
|
||||
.setPropertyInParent(IASTStandardFunctionDeclarator.FUNCTION_PARAMETER);
|
||||
fc.addParameterDeclaration(p);
|
||||
}
|
||||
fc.setConst(isConst);
|
||||
|
@ -3716,7 +3728,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME);
|
||||
}
|
||||
|
||||
((ASTNode)d).setOffsetAndLength( startingOffset, finalOffset - startingOffset );
|
||||
((ASTNode) d).setOffsetAndLength(startingOffset, finalOffset
|
||||
- startingOffset);
|
||||
return d;
|
||||
|
||||
}
|
||||
|
@ -3886,6 +3899,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (LT(1) == IToken.tLBRACE) {
|
||||
consume(IToken.tLBRACE);
|
||||
|
||||
IASTNode n = mostRelevantScopeNode;
|
||||
mostRelevantScopeNode = astClassSpecifier;
|
||||
|
||||
try {
|
||||
memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
|
||||
int checkToken = LA(1).hashCode();
|
||||
switch (LT(1)) {
|
||||
|
@ -3927,10 +3944,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (checkToken == LA(1).hashCode())
|
||||
errorHandling();
|
||||
}
|
||||
}
|
||||
|
||||
if (checkToken == LA(1).hashCode())
|
||||
failParseWithErrorHandling();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
mostRelevantScopeNode = n;
|
||||
}
|
||||
// consume the }
|
||||
int l = consume(IToken.tRBRACE).getEndOffset();
|
||||
((ASTNode) astClassSpecifier).setLength(l - classKey.getOffset());
|
||||
|
@ -4209,6 +4230,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
translationUnit.setLocationResolver(scanner.getLocationResolver());
|
||||
|
||||
mostRelevantScopeNode = translationUnit;
|
||||
while (true) {
|
||||
try {
|
||||
int checkOffset = LA(1).hashCode();
|
||||
|
|
Loading…
Add table
Reference in a new issue