mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Fixed Bug 86316 [Parser] bad expression inside if statement causes parser to go crazy
This commit is contained in:
parent
887dc877d4
commit
98c8876390
2 changed files with 23 additions and 15 deletions
|
@ -1837,7 +1837,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
if_loop: while (true) {
|
||||
int so = consume(IToken.t_if).getOffset();
|
||||
consume(IToken.tLPAREN);
|
||||
boolean passedCondition = true;
|
||||
IASTExpression condition = null;
|
||||
try {
|
||||
condition = condition();
|
||||
|
@ -1851,20 +1850,27 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
p.setParent(ps);
|
||||
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
||||
condition = ps;
|
||||
if( LT(1) == IToken.tRPAREN )
|
||||
consume();
|
||||
else if( LT(2) == IToken.tRPAREN )
|
||||
{
|
||||
consume();
|
||||
consume();
|
||||
}
|
||||
else
|
||||
failParseWithErrorHandling();
|
||||
passedCondition = false;
|
||||
}
|
||||
|
||||
IASTStatement thenClause = null;
|
||||
if (passedCondition) {
|
||||
thenClause = statement();
|
||||
}
|
||||
IASTStatement thenClause = statement();
|
||||
|
||||
IASTIfStatement new_if_statement = createIfStatement();
|
||||
((ASTNode) new_if_statement).setOffset(so);
|
||||
if( condition != null ) // shouldn't be possible but failure in condition() makes it so
|
||||
{
|
||||
new_if_statement.setCondition(condition);
|
||||
condition.setParent(new_if_statement);
|
||||
condition.setPropertyInParent(IASTIfStatement.CONDITION);
|
||||
}
|
||||
if (thenClause != null) {
|
||||
new_if_statement.setThenClause(thenClause);
|
||||
thenClause.setParent(new_if_statement);
|
||||
|
@ -1914,6 +1920,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
if_statement = new_if_statement;
|
||||
}
|
||||
} else {
|
||||
if( thenClause != null )
|
||||
((ASTNode) new_if_statement)
|
||||
.setLength(calculateEndOffset(thenClause) - start);
|
||||
if (if_statement != null) {
|
||||
|
@ -1956,6 +1963,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
- r.getOffset());
|
||||
} else {
|
||||
ASTNode then_clause = (ASTNode) current.getThenClause();
|
||||
if( then_clause != null )
|
||||
r.setLength(then_clause.getOffset() + then_clause.getLength()
|
||||
- r.getOffset());
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
*/
|
||||
public char[] toCharArray() {
|
||||
if (names == null)
|
||||
return "".toCharArray();
|
||||
return "".toCharArray(); //$NON-NLS-1$
|
||||
removeNullNames();
|
||||
|
||||
//count first
|
||||
|
|
Loading…
Add table
Reference in a new issue