1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45: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

@ -56,7 +56,7 @@ TestClass::TestClass(int a)
}
void undefPar(const char *c) throw (int);
virtual void pure() =0;
virtual void pure() = 0;
int getV() const;
int vol() volatile;

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
@ -82,7 +82,7 @@ public class ExpressionWriter extends NodeWriter{
private static final String MAX_OP = " >? "; //$NON-NLS-1$
private static final String PMARROW_OP = "->*"; //$NON-NLS-1$
private static final String PMDOT_OP = ".*"; //$NON-NLS-1$
private static final String ELLIPSES = "..."; //$NON-NLS-1$
private static final String ELLIPSES = " ... "; //$NON-NLS-1$
private static final String NOT_EQUALS_OP = " != "; //$NON-NLS-1$
private static final String EQUALS_OP = " == "; //$NON-NLS-1$
private static final String BINARY_OR_ASSIGN = " |= "; //$NON-NLS-1$