mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
Fixes potential NPEs.
This commit is contained in:
parent
ae39bd607b
commit
5dacb8918f
3 changed files with 34 additions and 31 deletions
|
@ -1141,6 +1141,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
} else {
|
} else {
|
||||||
IToken la = LA(1);
|
IToken la = LA(1);
|
||||||
throwBacktrack(la.getOffset(), la.getLength());
|
throwBacktrack(la.getOffset(), la.getLength());
|
||||||
|
return null; // line is never reached, hint for the parser
|
||||||
}
|
}
|
||||||
IASTExpression initialValue = null;
|
IASTExpression initialValue = null;
|
||||||
if (LT(1) == IToken.tASSIGN) {
|
if (LT(1) == IToken.tASSIGN) {
|
||||||
|
|
|
@ -1256,13 +1256,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
try {
|
try {
|
||||||
lookAheadForDeclarator(flags);
|
lookAheadForDeclarator(flags);
|
||||||
} catch (FoundDeclaratorException e) {
|
} catch (FoundDeclaratorException e) {
|
||||||
ICASTSimpleDeclSpecifier declSpec = null;
|
ICASTSimpleDeclSpecifier declSpec= createSimpleTypeSpecifier();
|
||||||
if (typeofExpression != null) {
|
|
||||||
declSpec = createGCCSimpleTypeSpecifier();
|
|
||||||
((IGCCASTSimpleDeclSpecifier) declSpec).setTypeofExpression(typeofExpression);
|
|
||||||
} else {
|
|
||||||
declSpec = createSimpleTypeSpecifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
declSpec.setConst(isConst);
|
declSpec.setConst(isConst);
|
||||||
declSpec.setRestrict(isRestrict);
|
declSpec.setRestrict(isRestrict);
|
||||||
|
@ -1276,12 +1270,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
declSpec.setUnsigned(isUnsigned);
|
declSpec.setUnsigned(isUnsigned);
|
||||||
declSpec.setSigned(isSigned);
|
declSpec.setSigned(isSigned);
|
||||||
declSpec.setShort(isShort);
|
declSpec.setShort(isShort);
|
||||||
if( typeofExpression != null && last == null ){
|
((ASTNode) declSpec).setOffsetAndLength(startingOffset,
|
||||||
((ASTNode)declSpec).setOffsetAndLength( (ASTNode)typeofExpression );
|
(last != null) ? last.getEndOffset() - startingOffset : 0);
|
||||||
} else {
|
|
||||||
((ASTNode) declSpec).setOffsetAndLength(startingOffset,
|
|
||||||
(last != null) ? last.getEndOffset() - startingOffset : 0);
|
|
||||||
}
|
|
||||||
e.declSpec = declSpec;
|
e.declSpec = declSpec;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -1385,7 +1375,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
declSpec.setInline(isInline);
|
declSpec.setInline(isInline);
|
||||||
declSpec.setStorageClass(storageClass);
|
declSpec.setStorageClass(storageClass);
|
||||||
|
|
||||||
((ASTNode) declSpec).setOffsetAndLength(startingOffset, last.getEndOffset() - startingOffset);
|
if (last != null) {
|
||||||
|
((ASTNode) declSpec).setOffsetAndLength(startingOffset, last.getEndOffset() - startingOffset);
|
||||||
|
}
|
||||||
IASTName name = createName(identifier);
|
IASTName name = createName(identifier);
|
||||||
declSpec.setName(name);
|
declSpec.setName(name);
|
||||||
return declSpec;
|
return declSpec;
|
||||||
|
@ -1462,6 +1454,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throwBacktrack(mark.getOffset(), mark.getLength());
|
throwBacktrack(mark.getOffset(), mark.getLength());
|
||||||
|
return null; // line never reached, hint for the parser.
|
||||||
}
|
}
|
||||||
|
|
||||||
// if __attribute__ or __declspec occurs after struct/union/class and before the identifier
|
// if __attribute__ or __declspec occurs after struct/union/class and before the identifier
|
||||||
|
@ -1636,13 +1629,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.tCOMMA:
|
case IToken.tCOMMA:
|
||||||
last = consume();
|
last = consume();
|
||||||
seenParameter = false;
|
parmNames[i] = createName(identifier());
|
||||||
|
seenParameter = true;
|
||||||
|
break;
|
||||||
case IToken.tIDENTIFIER:
|
case IToken.tIDENTIFIER:
|
||||||
if (seenParameter)
|
if (seenParameter)
|
||||||
throwBacktrack(startingOffset, last.getEndOffset() - startingOffset);
|
throwBacktrack(startingOffset, last.getEndOffset() - startingOffset);
|
||||||
|
|
||||||
parmNames[i] = createName(identifier());
|
parmNames[i] = createName(identifier());
|
||||||
|
|
||||||
seenParameter = true;
|
seenParameter = true;
|
||||||
break;
|
break;
|
||||||
case IToken.tRPAREN:
|
case IToken.tRPAREN:
|
||||||
|
@ -1694,8 +1688,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
parmDeclarations[i] = declaration;
|
parmDeclarations[i] = declaration;
|
||||||
} else {
|
} else {
|
||||||
parmDeclarations[i] = createKnRCProblemDeclaration(
|
parmDeclarations[i] = createKnRCProblemDeclaration(
|
||||||
((ASTNode) declaration).getLength(),
|
((ASTNode) decl).getLength(),
|
||||||
((ASTNode) declaration).getOffset());
|
((ASTNode) decl).getOffset());
|
||||||
}
|
}
|
||||||
} catch (BacktrackException b) {
|
} catch (BacktrackException b) {
|
||||||
parmDeclarations[i] = createKnRCProblemDeclaration(
|
parmDeclarations[i] = createKnRCProblemDeclaration(
|
||||||
|
|
|
@ -1414,7 +1414,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
switch (n.length) {
|
switch (n.length) {
|
||||||
case 0:
|
case 0:
|
||||||
throwBacktrack(LA(1));
|
throwBacktrack(LA(1));
|
||||||
break;
|
return null; // line is never reached, hint for the parser
|
||||||
case 1:
|
case 1:
|
||||||
if (n[0] instanceof IASTTypeId) {
|
if (n[0] instanceof IASTTypeId) {
|
||||||
firstExpression = buildTypeIdExpression(
|
firstExpression = buildTypeIdExpression(
|
||||||
|
@ -1424,6 +1424,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
firstExpression = buildUnaryExpression(
|
firstExpression = buildUnaryExpression(
|
||||||
ICPPASTUnaryExpression.op_typeid,
|
ICPPASTUnaryExpression.op_typeid,
|
||||||
(IASTExpression) n[0], so, lastOffset);
|
(IASTExpression) n[0], so, lastOffset);
|
||||||
|
} else {
|
||||||
|
throwBacktrack(LA(1));
|
||||||
|
return null; // line is never reached, hint for the parser
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -1439,6 +1442,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
((ASTNode) ambExpr).setOffsetAndLength((ASTNode) e2);
|
((ASTNode) ambExpr).setOffsetAndLength((ASTNode) e2);
|
||||||
firstExpression = ambExpr;
|
firstExpression = ambExpr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert false;
|
||||||
|
throwBacktrack(LA(1));
|
||||||
|
return null; // line is never reached, hint for the parser
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -3056,21 +3064,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
catch( FoundDeclaratorException fde )
|
catch( FoundDeclaratorException fde )
|
||||||
{
|
{
|
||||||
ICPPASTSimpleDeclSpecifier simpleDeclSpec = null;
|
ICPPASTSimpleDeclSpecifier simpleDeclSpec = null;
|
||||||
if (isLongLong || typeofExpression != null) {
|
if (isLongLong) {
|
||||||
simpleDeclSpec = createGPPSimpleDeclSpecifier();
|
simpleDeclSpec = createGPPSimpleDeclSpecifier();
|
||||||
((IGPPASTSimpleDeclSpecifier) simpleDeclSpec).setLongLong(isLongLong);
|
((IGPPASTSimpleDeclSpecifier) simpleDeclSpec).setLongLong(isLongLong);
|
||||||
if (typeofExpression != null) {
|
|
||||||
((IGPPASTSimpleDeclSpecifier) simpleDeclSpec).setTypeofExpression(typeofExpression);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
simpleDeclSpec = createSimpleDeclSpecifier();
|
simpleDeclSpec = createSimpleDeclSpecifier();
|
||||||
|
|
||||||
if( last == null && typeofExpression != null ){
|
int l = last != null ? last.getEndOffset() - firstToken.getOffset() : 0;
|
||||||
((ASTNode) simpleDeclSpec).setOffsetAndLength((ASTNode) typeofExpression);
|
((ASTNode) simpleDeclSpec).setOffsetAndLength(firstToken.getOffset(), l);
|
||||||
} else {
|
|
||||||
int l = last != null ? last.getEndOffset() - firstToken.getOffset() : 0;
|
|
||||||
((ASTNode) simpleDeclSpec).setOffsetAndLength(firstToken.getOffset(), l);
|
|
||||||
}
|
|
||||||
simpleDeclSpec.setConst(isConst);
|
simpleDeclSpec.setConst(isConst);
|
||||||
simpleDeclSpec.setVolatile(isVolatile);
|
simpleDeclSpec.setVolatile(isVolatile);
|
||||||
if (simpleDeclSpec instanceof IGPPASTDeclSpecifier)
|
if (simpleDeclSpec instanceof IGPPASTDeclSpecifier)
|
||||||
|
@ -3203,7 +3205,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
nameSpec.setStorageClass(storageClass);
|
nameSpec.setStorageClass(storageClass);
|
||||||
nameSpec.setVirtual(isVirtual);
|
nameSpec.setVirtual(isVirtual);
|
||||||
nameSpec.setExplicit(isExplicit);
|
nameSpec.setExplicit(isExplicit);
|
||||||
((ASTNode) nameSpec).setOffsetAndLength(startOffset, last.getEndOffset() - startOffset);
|
if (last != null) {
|
||||||
|
((ASTNode) nameSpec).setOffsetAndLength(startOffset, last.getEndOffset() - startOffset);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
((ASTNode) nameSpec).setOffsetAndLength(startOffset, duple.getLastToken().getEndOffset() - startOffset);
|
||||||
|
}
|
||||||
return nameSpec;
|
return nameSpec;
|
||||||
}
|
}
|
||||||
ICPPASTSimpleDeclSpecifier simpleDeclSpec = null;
|
ICPPASTSimpleDeclSpecifier simpleDeclSpec = null;
|
||||||
|
@ -3830,7 +3837,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
throwBacktrack(mark.getOffset(), endOffset - mark.getOffset());
|
throwBacktrack(mark.getOffset(), endOffset - mark.getOffset());
|
||||||
}
|
}
|
||||||
int endOffset = (mark != null) ? mark.getEndOffset() : 0;
|
int endOffset= mark.getEndOffset();
|
||||||
backup(mark);
|
backup(mark);
|
||||||
throwBacktrack(mark.getOffset(), endOffset - mark.getOffset());
|
throwBacktrack(mark.getOffset(), endOffset - mark.getOffset());
|
||||||
|
|
||||||
|
@ -3869,6 +3876,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throwBacktrack(mark.getOffset(), mark.getLength());
|
throwBacktrack(mark.getOffset(), mark.getLength());
|
||||||
|
return null; // line is never reached, hint for the parser
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTName name = null;
|
IASTName name = null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue