mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
Correct parsing of typeof-expressions, bug 226492.
This commit is contained in:
parent
1e97408e2b
commit
b74edd50a1
2 changed files with 16 additions and 7 deletions
|
@ -4478,6 +4478,15 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
// void test(int count) {
|
// void test(int count) {
|
||||||
// __typeof__(count) a= 1;
|
// __typeof__(count) a= 1;
|
||||||
// int ret0 = ((__typeof__(count)) 1);
|
// int ret0 = ((__typeof__(count)) 1);
|
||||||
|
// }
|
||||||
|
public void testTypeofUnaryExpression_Bug226492() throws Exception {
|
||||||
|
final String code = getAboveComment();
|
||||||
|
parseAndCheckBindings(code, ParserLanguage.C, true);
|
||||||
|
parseAndCheckBindings(code, ParserLanguage.CPP, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// void test(int count) {
|
||||||
|
// typeof(count==1) a= 1;
|
||||||
// }
|
// }
|
||||||
public void testTypeofExpression_Bug226492() throws Exception {
|
public void testTypeofExpression_Bug226492() throws Exception {
|
||||||
final String code = getAboveComment();
|
final String code = getAboveComment();
|
||||||
|
|
|
@ -850,15 +850,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
BacktrackException {
|
BacktrackException {
|
||||||
int offset = consume().getOffset(); // t_typeof
|
int offset = consume().getOffset(); // t_typeof
|
||||||
IASTTypeId d = null;
|
IASTTypeId d = null;
|
||||||
IASTExpression unaryExpression = null;
|
IASTExpression expression = null;
|
||||||
|
|
||||||
int lastOffset = 0;
|
int lastOffset = 0;
|
||||||
// prefer unary expressions over type-expressions
|
// prefer expressions over type-ids
|
||||||
if (LT(1) == IToken.tLPAREN && LT(2) != IToken.tLBRACE) {
|
if (LT(1) == IToken.tLPAREN && LT(2) != IToken.tLBRACE) {
|
||||||
consume();
|
consume();
|
||||||
final IToken m = mark();
|
final IToken m = mark();
|
||||||
try {
|
try {
|
||||||
unaryExpression= unaryExpression();
|
expression= expression();
|
||||||
}
|
}
|
||||||
catch (BacktrackException e) {
|
catch (BacktrackException e) {
|
||||||
backup(m);
|
backup(m);
|
||||||
|
@ -868,14 +868,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
}
|
}
|
||||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
} else {
|
} else {
|
||||||
unaryExpression = unaryExpression();
|
expression = unaryExpression();
|
||||||
lastOffset = calculateEndOffset(unaryExpression);
|
lastOffset = calculateEndOffset(expression);
|
||||||
}
|
}
|
||||||
if (d != null)
|
if (d != null)
|
||||||
return buildTypeIdExpression(IGNUASTTypeIdExpression.op_typeof, d, offset, lastOffset);
|
return buildTypeIdExpression(IGNUASTTypeIdExpression.op_typeof, d, offset, lastOffset);
|
||||||
|
|
||||||
if (unaryExpression != null)
|
if (expression != null)
|
||||||
return buildUnaryExpression(IGNUASTUnaryExpression.op_typeof, unaryExpression, offset, lastOffset);
|
return buildUnaryExpression(IGNUASTUnaryExpression.op_typeof, expression, offset, lastOffset);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue