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) {
|
if_loop: while (true) {
|
||||||
int so = consume(IToken.t_if).getOffset();
|
int so = consume(IToken.t_if).getOffset();
|
||||||
consume(IToken.tLPAREN);
|
consume(IToken.tLPAREN);
|
||||||
boolean passedCondition = true;
|
|
||||||
IASTExpression condition = null;
|
IASTExpression condition = null;
|
||||||
try {
|
try {
|
||||||
condition = condition();
|
condition = condition();
|
||||||
|
@ -1851,20 +1850,27 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
p.setParent(ps);
|
p.setParent(ps);
|
||||||
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
||||||
condition = ps;
|
condition = ps;
|
||||||
failParseWithErrorHandling();
|
if( LT(1) == IToken.tRPAREN )
|
||||||
passedCondition = false;
|
consume();
|
||||||
|
else if( LT(2) == IToken.tRPAREN )
|
||||||
|
{
|
||||||
|
consume();
|
||||||
|
consume();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTStatement thenClause = null;
|
IASTStatement thenClause = statement();
|
||||||
if (passedCondition) {
|
|
||||||
thenClause = statement();
|
|
||||||
}
|
|
||||||
|
|
||||||
IASTIfStatement new_if_statement = createIfStatement();
|
IASTIfStatement new_if_statement = createIfStatement();
|
||||||
((ASTNode) new_if_statement).setOffset(so);
|
((ASTNode) new_if_statement).setOffset(so);
|
||||||
new_if_statement.setCondition(condition);
|
if( condition != null ) // shouldn't be possible but failure in condition() makes it so
|
||||||
condition.setParent(new_if_statement);
|
{
|
||||||
condition.setPropertyInParent(IASTIfStatement.CONDITION);
|
new_if_statement.setCondition(condition);
|
||||||
|
condition.setParent(new_if_statement);
|
||||||
|
condition.setPropertyInParent(IASTIfStatement.CONDITION);
|
||||||
|
}
|
||||||
if (thenClause != null) {
|
if (thenClause != null) {
|
||||||
new_if_statement.setThenClause(thenClause);
|
new_if_statement.setThenClause(thenClause);
|
||||||
thenClause.setParent(new_if_statement);
|
thenClause.setParent(new_if_statement);
|
||||||
|
@ -1914,8 +1920,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
if_statement = new_if_statement;
|
if_statement = new_if_statement;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
((ASTNode) new_if_statement)
|
if( thenClause != null )
|
||||||
.setLength(calculateEndOffset(thenClause) - start);
|
((ASTNode) new_if_statement)
|
||||||
|
.setLength(calculateEndOffset(thenClause) - start);
|
||||||
if (if_statement != null) {
|
if (if_statement != null) {
|
||||||
if_statement.setElseClause(new_if_statement);
|
if_statement.setElseClause(new_if_statement);
|
||||||
new_if_statement.setParent(if_statement);
|
new_if_statement.setParent(if_statement);
|
||||||
|
@ -1956,8 +1963,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
- r.getOffset());
|
- r.getOffset());
|
||||||
} else {
|
} else {
|
||||||
ASTNode then_clause = (ASTNode) current.getThenClause();
|
ASTNode then_clause = (ASTNode) current.getThenClause();
|
||||||
r.setLength(then_clause.getOffset() + then_clause.getLength()
|
if( then_clause != null )
|
||||||
- r.getOffset());
|
r.setLength(then_clause.getOffset() + then_clause.getLength()
|
||||||
|
- r.getOffset());
|
||||||
}
|
}
|
||||||
if (current.getParent() != null
|
if (current.getParent() != null
|
||||||
&& current.getParent() instanceof IASTIfStatement)
|
&& current.getParent() instanceof IASTIfStatement)
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
||||||
*/
|
*/
|
||||||
public char[] toCharArray() {
|
public char[] toCharArray() {
|
||||||
if (names == null)
|
if (names == null)
|
||||||
return "".toCharArray();
|
return "".toCharArray(); //$NON-NLS-1$
|
||||||
removeNullNames();
|
removeNullNames();
|
||||||
|
|
||||||
//count first
|
//count first
|
||||||
|
|
Loading…
Add table
Reference in a new issue