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_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,10 +2299,10 @@ 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) {
|
||||||
if (simpleDeclarationMark == null) {
|
if (simpleDeclarationMark == null) {
|
||||||
if (firstFailure != null && (bt2.getProblem() == null))
|
if (firstFailure != null && (bt2.getProblem() == null))
|
||||||
|
@ -2366,36 +2367,44 @@ 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);
|
||||||
namespaceDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
|
|
||||||
int checkToken = LA(1).hashCode();
|
IASTNode n = mostRelevantScopeNode;
|
||||||
switch (LT(1)) {
|
mostRelevantScopeNode = namespaceDefinition;
|
||||||
case IToken.tRBRACE:
|
|
||||||
break namespaceDeclarationLoop;
|
try {
|
||||||
default:
|
namespaceDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
|
||||||
try {
|
int checkToken = LA(1).hashCode();
|
||||||
IASTDeclaration d = declaration();
|
switch (LT(1)) {
|
||||||
d.setParent(namespaceDefinition);
|
case IToken.tRBRACE:
|
||||||
d
|
break namespaceDeclarationLoop;
|
||||||
.setPropertyInParent(ICPPASTNamespaceDefinition.OWNED_DECLARATION);
|
default:
|
||||||
namespaceDefinition.addDeclaration(d);
|
try {
|
||||||
} catch (BacktrackException bt) {
|
IASTDeclaration d = declaration();
|
||||||
IASTProblem p = failParse(bt);
|
d.setParent(namespaceDefinition);
|
||||||
IASTProblemDeclaration pd = createProblemDeclaration();
|
d
|
||||||
p.setParent(pd);
|
.setPropertyInParent(ICPPASTNamespaceDefinition.OWNED_DECLARATION);
|
||||||
pd.setProblem(p);
|
namespaceDefinition.addDeclaration(d);
|
||||||
((CPPASTNode) pd).setOffsetAndLength((CPPASTNode) p);
|
} catch (BacktrackException bt) {
|
||||||
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
IASTProblem p = failParse(bt);
|
||||||
namespaceDefinition.addDeclaration(pd);
|
IASTProblemDeclaration pd = createProblemDeclaration();
|
||||||
pd.setParent(namespaceDefinition);
|
p.setParent(pd);
|
||||||
pd
|
pd.setProblem(p);
|
||||||
.setPropertyInParent(ICPPASTNamespaceDefinition.OWNED_DECLARATION);
|
((CPPASTNode) pd).setOffsetAndLength((CPPASTNode) p);
|
||||||
errorHandling();
|
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
||||||
if (checkToken == LA(1).hashCode())
|
namespaceDefinition.addDeclaration(pd);
|
||||||
|
pd.setParent(namespaceDefinition);
|
||||||
|
pd
|
||||||
|
.setPropertyInParent(ICPPASTNamespaceDefinition.OWNED_DECLARATION);
|
||||||
errorHandling();
|
errorHandling();
|
||||||
}
|
if (checkToken == LA(1).hashCode())
|
||||||
|
errorHandling();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (checkToken == LA(1).hashCode())
|
||||||
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
if (checkToken == LA(1).hashCode())
|
} finally {
|
||||||
failParseWithErrorHandling();
|
mostRelevantScopeNode = n;
|
||||||
}
|
}
|
||||||
// consume the }
|
// consume the }
|
||||||
int end = consume(IToken.tRBRACE).getEndOffset();
|
int end = consume(IToken.tRBRACE).getEndOffset();
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -2671,11 +2681,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
|
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
|
||||||
int length = figureEndOffset(declSpec, declarators) - firstOffset;
|
int length = figureEndOffset(declSpec, declarators) - firstOffset;
|
||||||
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);
|
||||||
|
@ -3456,8 +3465,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
overallLoop: do {
|
overallLoop: do {
|
||||||
|
|
||||||
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();
|
||||||
|
@ -3639,13 +3649,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
case IToken.tLBRACKET:
|
case IToken.tLBRACKET:
|
||||||
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);
|
||||||
bitField = constantExpression();
|
bitField = constantExpression();
|
||||||
finalOffset = calculateEndOffset( bitField );
|
finalOffset = calculateEndOffset(bitField);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -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,50 +3899,58 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (LT(1) == IToken.tLBRACE) {
|
if (LT(1) == IToken.tLBRACE) {
|
||||||
consume(IToken.tLBRACE);
|
consume(IToken.tLBRACE);
|
||||||
|
|
||||||
memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
|
IASTNode n = mostRelevantScopeNode;
|
||||||
int checkToken = LA(1).hashCode();
|
mostRelevantScopeNode = astClassSpecifier;
|
||||||
switch (LT(1)) {
|
|
||||||
case IToken.t_public:
|
try {
|
||||||
case IToken.t_protected:
|
memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
|
||||||
case IToken.t_private:
|
int checkToken = LA(1).hashCode();
|
||||||
IToken key = consume();
|
switch (LT(1)) {
|
||||||
int l = consume(IToken.tCOLON).getEndOffset();
|
case IToken.t_public:
|
||||||
ICPPASTVisiblityLabel label = createVisibilityLabel();
|
case IToken.t_protected:
|
||||||
((ASTNode) label).setOffsetAndLength(key.getOffset(), l
|
case IToken.t_private:
|
||||||
- key.getOffset());
|
IToken key = consume();
|
||||||
label.setVisibility(token2Visibility(key.getType()));
|
int l = consume(IToken.tCOLON).getEndOffset();
|
||||||
astClassSpecifier.addMemberDeclaration(label);
|
ICPPASTVisiblityLabel label = createVisibilityLabel();
|
||||||
label.setParent(astClassSpecifier);
|
((ASTNode) label).setOffsetAndLength(key.getOffset(), l
|
||||||
label
|
- key.getOffset());
|
||||||
.setPropertyInParent(ICPPASTCompositeTypeSpecifier.VISIBILITY_LABEL);
|
label.setVisibility(token2Visibility(key.getType()));
|
||||||
break;
|
astClassSpecifier.addMemberDeclaration(label);
|
||||||
case IToken.tRBRACE:
|
label.setParent(astClassSpecifier);
|
||||||
consume(IToken.tRBRACE);
|
label
|
||||||
break memberDeclarationLoop;
|
.setPropertyInParent(ICPPASTCompositeTypeSpecifier.VISIBILITY_LABEL);
|
||||||
default:
|
break;
|
||||||
try {
|
case IToken.tRBRACE:
|
||||||
IASTDeclaration d = declaration();
|
consume(IToken.tRBRACE);
|
||||||
astClassSpecifier.addMemberDeclaration(d);
|
break memberDeclarationLoop;
|
||||||
d.setParent(astClassSpecifier);
|
default:
|
||||||
d
|
try {
|
||||||
.setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION);
|
IASTDeclaration d = declaration();
|
||||||
} catch (BacktrackException bt) {
|
astClassSpecifier.addMemberDeclaration(d);
|
||||||
IASTProblem p = failParse(bt);
|
d.setParent(astClassSpecifier);
|
||||||
IASTProblemDeclaration pd = createProblemDeclaration();
|
d
|
||||||
pd.setProblem(p);
|
.setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION);
|
||||||
((CPPASTNode) pd).setOffsetAndLength(((CPPASTNode) p));
|
} catch (BacktrackException bt) {
|
||||||
p.setParent(pd);
|
IASTProblem p = failParse(bt);
|
||||||
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
IASTProblemDeclaration pd = createProblemDeclaration();
|
||||||
astClassSpecifier.addMemberDeclaration(pd);
|
pd.setProblem(p);
|
||||||
pd.setParent(astClassSpecifier);
|
((CPPASTNode) pd).setOffsetAndLength(((CPPASTNode) p));
|
||||||
pd
|
p.setParent(pd);
|
||||||
.setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION);
|
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
||||||
|
astClassSpecifier.addMemberDeclaration(pd);
|
||||||
|
pd.setParent(astClassSpecifier);
|
||||||
|
pd
|
||||||
|
.setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION);
|
||||||
|
if (checkToken == LA(1).hashCode())
|
||||||
|
errorHandling();
|
||||||
|
}
|
||||||
|
|
||||||
if (checkToken == LA(1).hashCode())
|
if (checkToken == LA(1).hashCode())
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (checkToken == LA(1).hashCode())
|
} finally {
|
||||||
failParseWithErrorHandling();
|
mostRelevantScopeNode = n;
|
||||||
}
|
}
|
||||||
// consume the }
|
// consume the }
|
||||||
int l = consume(IToken.tRBRACE).getEndOffset();
|
int l = consume(IToken.tRBRACE).getEndOffset();
|
||||||
|
@ -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();
|
||||||
|
|
Loading…
Add table
Reference in a new issue