1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 02:06:01 +02:00

Fix case ranges, bug 270430.

This commit is contained in:
Markus Schorn 2009-04-01 11:56:47 +00:00
parent ef28bd3a93
commit c98bf28da7
5 changed files with 55 additions and 6 deletions

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
@ -4840,8 +4841,26 @@ public class AST2Tests extends AST2BaseTest {
// }
public void testCaseRange_Bug211882() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.C, true);
parseAndCheckBindings(code, ParserLanguage.CPP, true);
{
IASTTranslationUnit tu = parseAndCheckBindings(code, ParserLanguage.C, true);
IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody();
IASTSwitchStatement switchStmt = (IASTSwitchStatement)body.getStatements()[0];
IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement)switchStmt.getBody()).getStatements()[0];
IASTBinaryExpression binExpr = (IASTBinaryExpression)caseStmt.getExpression();
assertTrue(binExpr.getOperator() == IASTBinaryExpression.op_ellipses);
assertTrue(binExpr.getOperand1() instanceof IASTLiteralExpression);
assertTrue(binExpr.getOperand2() instanceof IASTLiteralExpression);
}
{
IASTTranslationUnit tu = parseAndCheckBindings(code, ParserLanguage.CPP, true);
IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody();
IASTSwitchStatement switchStmt = (IASTSwitchStatement)body.getStatements()[0];
IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement)switchStmt.getBody()).getStatements()[0];
IASTBinaryExpression binExpr = (IASTBinaryExpression)caseStmt.getExpression();
assertTrue(binExpr.getOperator() == IASTBinaryExpression.op_ellipses);
assertTrue(binExpr.getOperand1() instanceof IASTLiteralExpression);
assertTrue(binExpr.getOperand2() instanceof IASTLiteralExpression);
}
}
// template<typename T> class X {

View file

@ -206,6 +206,36 @@ void foo()
}
//!GNUSwitchStatementTest
//%CPP
int foo(int a)
{
switch (a){
case 1:
return 1;
case 2 ... 4:
return 0;
default:
return -1;
}
}
//!GNUSwitchStatementTest
//%C
int foo(int a)
{
switch (a){
case 1:
return 1;
case 2 ... 4:
return 0;
default:
return -1;
}
}
//!WhileStatementTest
//%CPP
void foo()

View file

@ -2020,7 +2020,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
if (lt1 == IToken.tELLIPSIS) {
consume();
IASTExpression upperBoundExpression= constantExpression();
caseExpression = buildBinaryExpression(IASTBinaryExpression.op_assign,
caseExpression = buildBinaryExpression(IASTBinaryExpression.op_ellipses,
caseExpression, upperBoundExpression, calculateEndOffset(upperBoundExpression));
lt1= LT(1);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0