mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 02:35:37 +02:00
Fix for a bogus c++-syntax-error and 2 exceptions, bug 223777.
This commit is contained in:
parent
064d4429ba
commit
9f5748de37
4 changed files with 165 additions and 117 deletions
|
@ -5838,4 +5838,15 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertTrue(td instanceof ITypedef);
|
||||
assertTrue(((ITypedef) td).getType() instanceof ICPPBasicType);
|
||||
}
|
||||
|
||||
// void func() {
|
||||
// int a, b;
|
||||
// a < b || (a==b && a < b);
|
||||
// if (a > b) {
|
||||
// }
|
||||
// }
|
||||
public void testResettingTemplateIdScopesStack_Bug223777() throws Exception{
|
||||
final String code = getContents(1)[0].toString();
|
||||
parseAndCheckBindings(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -835,13 +835,16 @@ public class CPPVisitor {
|
|||
IScope scope= getContainingScopeOrNull(name);
|
||||
if (scope == null) {
|
||||
return new CPPScope.CPPScopeProblem(name, IProblemBinding.SEMANTIC_BAD_SCOPE,
|
||||
name.toCharArray());
|
||||
name == null ? CharArrayUtils.EMPTY : name.toCharArray());
|
||||
}
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
||||
private static IScope getContainingScopeOrNull(IASTName name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
IASTNode parent = name.getParent();
|
||||
try {
|
||||
if (parent instanceof ICPPASTTemplateId) {
|
||||
|
|
|
@ -282,8 +282,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
boolean completedArg = false;
|
||||
boolean failed = false;
|
||||
|
||||
final int initialTemplateIdScopesSize= templateIdScopes.size();
|
||||
templateIdScopes.push(IToken.tLT);
|
||||
|
||||
try {
|
||||
while (LT(1) != IToken.tGT && LT(1) != IToken.tEOC) {
|
||||
completedArg = false;
|
||||
|
||||
|
@ -318,9 +319,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
finally {
|
||||
do {
|
||||
templateIdScopes.pop();
|
||||
|
||||
} while (templateIdScopes.size() > initialTemplateIdScopesSize);
|
||||
}
|
||||
if (failed)
|
||||
throwBacktrack(startingOffset, endOffset - startingOffset);
|
||||
|
||||
|
@ -407,6 +411,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IASTExpression conditionalExpression() throws BacktrackException, EndOfFileException {
|
||||
final IASTExpression expr= super.conditionalExpression();
|
||||
if (templateArgListCount > 0) {
|
||||
|
@ -912,10 +917,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IToken mark = mark();
|
||||
consume();
|
||||
|
||||
if (templateIdScopes.size() > 0)
|
||||
final int initialSize= templateIdScopes.size();
|
||||
if (initialSize > 0)
|
||||
templateIdScopes.push(IToken.tLPAREN);
|
||||
|
||||
boolean popped = false;
|
||||
try {
|
||||
IASTTypeId typeId = null;
|
||||
IToken startCastExpression=null;
|
||||
|
||||
|
@ -926,9 +932,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (typeId != null && LT(1) == IToken.tRPAREN) {
|
||||
consume();
|
||||
startCastExpression=mark();
|
||||
if (templateIdScopes.size() > 0) {
|
||||
if (initialSize > 0) {
|
||||
templateIdScopes.pop();
|
||||
popped = true;
|
||||
}
|
||||
try {
|
||||
IASTExpression castExpression = castExpression();
|
||||
|
@ -952,7 +957,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
}
|
||||
backup(mark);
|
||||
if (templateIdScopes.size() > 0 && !popped) { templateIdScopes.pop(); }
|
||||
}
|
||||
finally {
|
||||
while (templateIdScopes.size() > initialSize) {
|
||||
templateIdScopes.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
return unaryExpression();
|
||||
|
||||
|
@ -1395,14 +1405,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTName name = createName(nestedName);
|
||||
|
||||
consume(IToken.tLPAREN);
|
||||
int lastOffset;
|
||||
IASTExpression expressionList;
|
||||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.push(IToken.tLPAREN);
|
||||
}
|
||||
IASTExpression expressionList = expression();
|
||||
int lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||
try {
|
||||
expressionList = expression();
|
||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||
}
|
||||
finally {
|
||||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.pop();
|
||||
}
|
||||
}
|
||||
|
||||
ICPPASTTypenameExpression result = createTypenameExpression();
|
||||
((ASTNode) result).setOffsetAndLength(o, lastOffset - o);
|
||||
|
@ -1460,11 +1476,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.push(IToken.tLPAREN);
|
||||
}
|
||||
IASTNode[] n = parseTypeIdOrUnaryExpression(false);
|
||||
IASTNode[] n;
|
||||
try {
|
||||
n= parseTypeIdOrUnaryExpression(false);
|
||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||
}
|
||||
finally {
|
||||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.pop();
|
||||
}
|
||||
}
|
||||
|
||||
switch (n.length) {
|
||||
case 0:
|
||||
|
@ -1509,8 +1530,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.push(IToken.tLBRACKET);
|
||||
}
|
||||
secondExpression = expression();
|
||||
int lastOffset;
|
||||
try {
|
||||
secondExpression = expression();
|
||||
switch (LT(1)) {
|
||||
case IToken.tRBRACKET:
|
||||
case IToken.tEOC:
|
||||
|
@ -1519,9 +1541,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
default:
|
||||
throw backtrack;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.pop();
|
||||
}
|
||||
}
|
||||
|
||||
IASTArraySubscriptExpression s = createArraySubscriptExpression();
|
||||
((ASTNode) s).setOffsetAndLength(((ASTNode) firstExpression)
|
||||
|
@ -1537,6 +1562,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.push(IToken.tLPAREN);
|
||||
}
|
||||
try {
|
||||
if (LT(1) != IToken.tRPAREN)
|
||||
secondExpression = expression();
|
||||
else
|
||||
|
@ -1549,10 +1575,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
default:
|
||||
throw backtrack;
|
||||
}
|
||||
|
||||
}
|
||||
finally {
|
||||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.pop();
|
||||
}
|
||||
}
|
||||
|
||||
IASTFunctionCallExpression fce = createFunctionCallExpression();
|
||||
((ASTNode) fce).setOffsetAndLength(((ASTNode) firstExpression)
|
||||
|
@ -1743,17 +1771,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.push(IToken.tLPAREN);
|
||||
}
|
||||
IASTExpression lhs = expression();
|
||||
int finalOffset= 0;
|
||||
IASTExpression lhs;
|
||||
try {
|
||||
lhs = expression();
|
||||
if (LT(1) == IToken.tRPAREN) {
|
||||
finalOffset = consume().getEndOffset();
|
||||
} else {
|
||||
// missing parenthesis, assume it's there and keep going.
|
||||
finalOffset = LA(1).getOffset();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (templateIdScopes.size() > 0) {
|
||||
templateIdScopes.pop();
|
||||
}
|
||||
}
|
||||
return buildUnaryExpression(IASTUnaryExpression.op_bracketedPrimary, lhs, t.getOffset(), finalOffset);
|
||||
case IToken.tIDENTIFIER:
|
||||
case IToken.tCOLONCOLON:
|
||||
|
|
|
@ -89,12 +89,13 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
|
|||
IParameter[] sParams= sFunc.getParameters();
|
||||
IType[] sParamTypes= sFunc.getType().getParameterTypes();
|
||||
|
||||
final int length= Math.min(sParamTypes.length, params.length);
|
||||
final int length= Math.min(sParams.length, params.length);
|
||||
db.putInt(record + NUM_PARAMS, length);
|
||||
for (int i=0; i<length; ++i) {
|
||||
int typeRecord= i<paramTypes.length && paramTypes[i]!=null ? ((PDOMNode)paramTypes[i]).getRecord() : 0;
|
||||
//TODO shouldn't need to make new parameter (find old one)
|
||||
PDOMCPPParameter sParam = new PDOMCPPParameter(pdom, this, sParams[i], sParamTypes[i]);
|
||||
final IType type= i<sParamTypes.length ? sParamTypes[i] : null;
|
||||
PDOMCPPParameter sParam = new PDOMCPPParameter(pdom, this, sParams[i], type);
|
||||
setFirstParameter(new PDOMCPPParameterSpecialization(pdom, this, (ICPPParameter) params[i], sParam, typeRecord));
|
||||
}
|
||||
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(function));
|
||||
|
|
Loading…
Add table
Reference in a new issue