mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
Switch without compound statement, bug 105334.
This commit is contained in:
parent
e6baa5b577
commit
307d084357
4 changed files with 45 additions and 8 deletions
|
@ -56,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||||
|
@ -5019,4 +5020,23 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertEquals(";", empty.getRawSignature());
|
assertEquals(";", empty.getRawSignature());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void test() {
|
||||||
|
// int foux = 3;
|
||||||
|
// switch(foux) // no brace!
|
||||||
|
// case 0:
|
||||||
|
// case 1:
|
||||||
|
// foux= 0;
|
||||||
|
// foux= 1;
|
||||||
|
// }
|
||||||
|
public void testSwitchWithoutCompound_Bug105334() throws Exception {
|
||||||
|
final String comment= getAboveComment();
|
||||||
|
for (ParserLanguage lang : ParserLanguage.values()) {
|
||||||
|
IASTTranslationUnit tu= parse(comment, lang);
|
||||||
|
IASTFunctionDefinition fdef= getDeclaration(tu, 0);
|
||||||
|
IASTSwitchStatement sw= getStatement(fdef, 1);
|
||||||
|
IASTStatement stmt= getStatement(fdef, 2);
|
||||||
|
assertEquals("foux= 1;", stmt.getRawSignature());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1650,6 +1650,27 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
return break_statement;
|
return break_statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IASTStatement parseSwitchBody() throws EndOfFileException, BacktrackException {
|
||||||
|
IASTStatement stmt= null;
|
||||||
|
if (LT(1) != IToken.tEOC)
|
||||||
|
stmt= statement();
|
||||||
|
|
||||||
|
if (stmt instanceof IASTCaseStatement == false)
|
||||||
|
return stmt;
|
||||||
|
|
||||||
|
// bug 105334, switch without compound statement
|
||||||
|
IASTCompoundStatement comp= createCompoundStatement();
|
||||||
|
((ASTNode) comp).setOffsetAndLength((ASTNode) stmt);
|
||||||
|
comp.addStatement(stmt);
|
||||||
|
|
||||||
|
while (LT(1) != IToken.tEOC && stmt instanceof IASTCaseStatement) {
|
||||||
|
stmt= statement();
|
||||||
|
comp.addStatement(stmt);
|
||||||
|
}
|
||||||
|
adjustLength(comp, stmt);
|
||||||
|
return comp;
|
||||||
|
}
|
||||||
|
|
||||||
protected IASTStatement parseContinueStatement() throws EndOfFileException,
|
protected IASTStatement parseContinueStatement() throws EndOfFileException,
|
||||||
BacktrackException {
|
BacktrackException {
|
||||||
int startOffset = consume().getOffset(); // t_continue
|
int startOffset = consume().getOffset(); // t_continue
|
||||||
|
|
|
@ -2488,10 +2488,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
default:
|
default:
|
||||||
throwBacktrack(LA(1));
|
throwBacktrack(LA(1));
|
||||||
}
|
}
|
||||||
IASTStatement switch_body = null;
|
|
||||||
if (LT(1) != IToken.tEOC)
|
IASTStatement switch_body = parseSwitchBody();
|
||||||
switch_body = statement();
|
|
||||||
|
|
||||||
IASTSwitchStatement switch_statement = createSwitchStatement();
|
IASTSwitchStatement switch_statement = createSwitchStatement();
|
||||||
((ASTNode) switch_statement).setOffsetAndLength(startOffset,
|
((ASTNode) switch_statement).setOffsetAndLength(startOffset,
|
||||||
(switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset);
|
(switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset);
|
||||||
|
|
|
@ -4799,10 +4799,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
default:
|
default:
|
||||||
throwBacktrack(LA(1));
|
throwBacktrack(LA(1));
|
||||||
}
|
}
|
||||||
IASTStatement switch_body = null;
|
|
||||||
if (LT(1) != IToken.tEOC)
|
IASTStatement switch_body = parseSwitchBody();
|
||||||
switch_body = statement();
|
|
||||||
|
|
||||||
ICPPASTSwitchStatement switch_statement = createSwitchStatement();
|
ICPPASTSwitchStatement switch_statement = createSwitchStatement();
|
||||||
((ASTNode) switch_statement).setOffsetAndLength(startOffset,
|
((ASTNode) switch_statement).setOffsetAndLength(startOffset,
|
||||||
(switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset);
|
(switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset);
|
||||||
|
|
Loading…
Add table
Reference in a new issue