mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Support for case-ranges, bug 211882.
This commit is contained in:
parent
7a1ab1e347
commit
81a7a466e9
7 changed files with 83 additions and 15 deletions
|
@ -4493,4 +4493,15 @@ public class AST2Tests extends AST2BaseTest {
|
|||
parseAndCheckBindings(code, ParserLanguage.C, true);
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP, true);
|
||||
}
|
||||
|
||||
// void test(int count) {
|
||||
// switch(count) {
|
||||
// case 1 ... 3: break;
|
||||
// }
|
||||
// }
|
||||
public void testCaseRange_Bug211882() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.C, true);
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
|
||||
/**
|
||||
* This interface represents a binary expression.
|
||||
*
|
||||
|
@ -194,9 +195,40 @@ public interface IASTBinaryExpression extends IASTExpression {
|
|||
public static final int op_notequals = 29;
|
||||
|
||||
/**
|
||||
* op_last is the field used in subinterfaces to start their operators at
|
||||
* For c==, only.
|
||||
* <code>op_pmdot</code> pointer-to-member field dereference.
|
||||
*/
|
||||
public static final int op_last = op_notequals;
|
||||
public static final int op_pmdot = 30;
|
||||
|
||||
/**
|
||||
* For c++, only.
|
||||
* <code>op_pmarrow</code> pointer-to-member pointer dereference.
|
||||
*/
|
||||
public static final int op_pmarrow = 31;
|
||||
|
||||
/**
|
||||
* For g++, only.
|
||||
* <code>op_max</code> represents >?
|
||||
*/
|
||||
public static final int op_max = 32;
|
||||
|
||||
/**
|
||||
* For g++, only.
|
||||
* <code>op_min</code> represents <?
|
||||
*/
|
||||
public static final int op_min = 33;
|
||||
|
||||
/**
|
||||
* For gcc compilers, only.
|
||||
* <code>op_ellipses</code> represents ... as used for case ranges.
|
||||
*/
|
||||
public static final int op_ellipses= 34;
|
||||
|
||||
/**
|
||||
* @deprecated all constants must be defined here, to avoid using the same value twice.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final int op_last = op_ellipses;
|
||||
|
||||
/**
|
||||
* Get the first operand.
|
||||
|
|
|
@ -22,15 +22,17 @@ public interface ICPPASTBinaryExpression extends IASTBinaryExpression {
|
|||
/**
|
||||
* <code>op_pmdot</code> pointer-to-member field dereference.
|
||||
*/
|
||||
public static final int op_pmdot = IASTBinaryExpression.op_last + 1;
|
||||
public static final int op_pmdot = IASTBinaryExpression.op_pmdot;
|
||||
|
||||
/**
|
||||
* <code>op_pmarrow</code> pointer-to-member pointer dereference.
|
||||
*/
|
||||
public static final int op_pmarrow = IASTBinaryExpression.op_last + 2;
|
||||
public static final int op_pmarrow = IASTBinaryExpression.op_pmarrow;
|
||||
|
||||
/**
|
||||
* <code>op_last</code> is defined for subinterfaces to further extend.
|
||||
* @deprecated all constants must be defined in {@link IASTBinaryExpression}, to avoid
|
||||
* duplicate usage of the same constant.
|
||||
*/
|
||||
public static final int op_last = op_pmarrow;
|
||||
@Deprecated
|
||||
public static final int op_last = IASTBinaryExpression.op_last;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.gnu.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||
|
||||
/**
|
||||
|
@ -22,16 +23,18 @@ public interface IGPPASTBinaryExpression extends ICPPASTBinaryExpression {
|
|||
/**
|
||||
* <code>op_max</code> represents >?
|
||||
*/
|
||||
public static final int op_max = ICPPASTBinaryExpression.op_last + 1;
|
||||
public static final int op_max = IASTBinaryExpression.op_max;
|
||||
|
||||
/**
|
||||
* <code>op_min</code> represents <?
|
||||
*/
|
||||
public static final int op_min = ICPPASTBinaryExpression.op_last + 2;
|
||||
public static final int op_min = IASTBinaryExpression.op_min;
|
||||
|
||||
/**
|
||||
* <code>op_last</code> provided for sub-interfaces to extend.
|
||||
* @deprecated all constants must be defined in {@link IASTBinaryExpression} to avoid
|
||||
* using a constant twice.
|
||||
*/
|
||||
public static final int op_last = op_min;
|
||||
@Deprecated
|
||||
public static final int op_last = IASTBinaryExpression.op_last;
|
||||
|
||||
}
|
||||
|
|
|
@ -43,17 +43,23 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx
|
|||
|
||||
public static void addAdditionalGNUKeywords(CharArrayIntMap target) {
|
||||
target.put(GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ );
|
||||
target.put(GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ );
|
||||
target.put(GCCKeywords.cp__ASM, IToken.t_asm);
|
||||
target.put(GCCKeywords.cp__ASM__, IToken.t_asm);
|
||||
target.put(GCCKeywords.cp__ATTRIBUTE, IGCCToken.t__attribute__ );
|
||||
target.put(GCCKeywords.cp__ATTRIBUTE__, IGCCToken.t__attribute__ );
|
||||
target.put(GCCKeywords.cp__CONST, IToken.t_const);
|
||||
target.put(GCCKeywords.cp__CONST__, IToken.t_const);
|
||||
target.put(GCCKeywords.cp__DECLSPEC, IGCCToken.t__declspec );
|
||||
target.put(GCCKeywords.cp__INLINE, IToken.t_inline);
|
||||
target.put(GCCKeywords.cp__INLINE__, IToken.t_inline);
|
||||
target.put(GCCKeywords.cp__RESTRICT, IToken.t_restrict);
|
||||
target.put(GCCKeywords.cp__RESTRICT__, IToken.t_restrict);
|
||||
target.put(GCCKeywords.cp__VOLATILE, IToken.t_volatile);
|
||||
target.put(GCCKeywords.cp__VOLATILE__, IToken.t_volatile);
|
||||
target.put(GCCKeywords.cp__SIGNED, IToken.t_signed);
|
||||
target.put(GCCKeywords.cp__SIGNED__, IToken.t_signed);
|
||||
target.put(GCCKeywords.cp__TYPEOF, IGCCToken.t_typeof);
|
||||
target.put(GCCKeywords.cp__TYPEOF__, IGCCToken.t_typeof);
|
||||
target.put(GCCKeywords.cpTYPEOF, IGCCToken.t_typeof );
|
||||
}
|
||||
|
|
|
@ -27,14 +27,20 @@ public class GCCKeywords {
|
|||
public static final char [] cp__ATTRIBUTE__ = __ATTRIBUTE__.toCharArray();
|
||||
public static final char [] cp__DECLSPEC = __DECLSPEC.toCharArray();
|
||||
|
||||
public static final char [] cp__ALIGNOF = "__alignof".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__ATTRIBUTE = "__attribute".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__ASM= "__asm".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__ASM__= "__asm__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__CONST__= "__const__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__CONST= "__const".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__CONST__= "__const__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__INLINE= "__inline".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__INLINE__= "__inline__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__RESTRICT__= "__restrict__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__RESTRICT= "__restrict".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__RESTRICT__= "__restrict__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__VOLATILE= "__volatile".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__VOLATILE__= "__volatile__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__SIGNED= "__signed".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__SIGNED__= "__signed__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__TYPEOF= "__typeof".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__TYPEOF__= "__typeof__".toCharArray(); //$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -1689,9 +1689,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
protected IASTStatement parseCaseStatement() throws EndOfFileException, BacktrackException {
|
||||
int startOffset = consume().getOffset(); // t_case
|
||||
IASTExpression case_exp = constantExpression();
|
||||
IASTExpression caseExpression = constantExpression();
|
||||
int lt1 = LT(1);
|
||||
if (lt1 == IToken.tELLIPSIS) {
|
||||
consume();
|
||||
IASTExpression upperBoundExpression= constantExpression();
|
||||
caseExpression = buildBinaryExpression(IASTBinaryExpression.op_assign,
|
||||
caseExpression, upperBoundExpression, calculateEndOffset(upperBoundExpression));
|
||||
lt1= LT(1);
|
||||
}
|
||||
int lastOffset = 0;
|
||||
switch (LT(1)) {
|
||||
switch (lt1) {
|
||||
case IToken.tCOLON:
|
||||
case IToken.tEOC:
|
||||
lastOffset = consume().getEndOffset();
|
||||
|
@ -1702,7 +1710,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
IASTCaseStatement cs = createCaseStatement();
|
||||
((ASTNode) cs).setOffsetAndLength(startOffset, lastOffset - startOffset);
|
||||
cs.setExpression(case_exp);
|
||||
cs.setExpression(caseExpression);
|
||||
return cs;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue