mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Fixed JUnits.
This commit is contained in:
parent
2e1c3b3f50
commit
66c2e911bf
4 changed files with 36 additions and 28 deletions
|
@ -786,12 +786,12 @@ public class CompleteParser2Tests extends TestCase {
|
||||||
|
|
||||||
public void testNewExpressions() throws Exception
|
public void testNewExpressions() throws Exception
|
||||||
{
|
{
|
||||||
IASTTranslationUnit tu = parse( "int A; int B; int C; int D; int P; int*p = new (P) (A)[B][C][D];" ); //$NON-NLS-1$
|
IASTTranslationUnit tu = parse( "typedef int A; int B; int C; int D; int P; int*p = new (P) (A)[B][C][D];" ); //$NON-NLS-1$
|
||||||
CPPNameCollector col = new CPPNameCollector();
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
CPPVisitor.visitTranslationUnit( tu, col );
|
CPPVisitor.visitTranslationUnit( tu, col );
|
||||||
|
|
||||||
assertEquals( col.size(), 11 );
|
assertEquals( col.size(), 11 );
|
||||||
IVariable A = (IVariable) col.getName(0).resolveBinding();
|
ITypedef A = (ITypedef) col.getName(0).resolveBinding();
|
||||||
IVariable B = (IVariable) col.getName(1).resolveBinding();
|
IVariable B = (IVariable) col.getName(1).resolveBinding();
|
||||||
IVariable C = (IVariable) col.getName(2).resolveBinding();
|
IVariable C = (IVariable) col.getName(2).resolveBinding();
|
||||||
IVariable D = (IVariable) col.getName(3).resolveBinding();
|
IVariable D = (IVariable) col.getName(3).resolveBinding();
|
||||||
|
@ -1173,7 +1173,7 @@ public class CompleteParser2Tests extends TestCase {
|
||||||
|
|
||||||
public void testBug39504() throws Exception
|
public void testBug39504() throws Exception
|
||||||
{
|
{
|
||||||
IASTTranslationUnit tu = parse( "const int w = 2; int x[ 5 ]; int y = sizeof (x[w]);" ); //$NON-NLS-1$
|
IASTTranslationUnit tu = parse( "const int w = 2; int x[ 5 ]; int y = sizeof ( x[w] );" ); //$NON-NLS-1$
|
||||||
CPPNameCollector col = new CPPNameCollector();
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
CPPVisitor.visitTranslationUnit( tu, col );
|
CPPVisitor.visitTranslationUnit( tu, col );
|
||||||
|
|
||||||
|
|
|
@ -592,7 +592,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
protected abstract IASTExpression multiplicativeExpression()
|
protected abstract IASTExpression multiplicativeExpression()
|
||||||
throws BacktrackException, EndOfFileException;
|
throws BacktrackException, EndOfFileException;
|
||||||
|
|
||||||
protected abstract IASTTypeId typeId(boolean skipArrayMods)
|
protected abstract IASTTypeId typeId(boolean skipArrayMods, boolean forNewExpression)
|
||||||
throws BacktrackException, EndOfFileException;
|
throws BacktrackException, EndOfFileException;
|
||||||
|
|
||||||
protected abstract IASTExpression castExpression()
|
protected abstract IASTExpression castExpression()
|
||||||
|
@ -894,7 +894,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
if (LT(1) == IToken.tLPAREN) {
|
if (LT(1) == IToken.tLPAREN) {
|
||||||
try {
|
try {
|
||||||
consume(IToken.tLPAREN);
|
consume(IToken.tLPAREN);
|
||||||
d = typeId(false);
|
d = typeId(false, false);
|
||||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(m);
|
backup(m);
|
||||||
|
@ -930,7 +930,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
} else
|
} else
|
||||||
try {
|
try {
|
||||||
consume(IToken.tLPAREN);
|
consume(IToken.tLPAREN);
|
||||||
d = typeId(false);
|
d = typeId(false, false);
|
||||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(m);
|
backup(m);
|
||||||
|
|
|
@ -771,7 +771,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// If this isn't a type name, then we shouldn't be here
|
// If this isn't a type name, then we shouldn't be here
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
typeId = typeId(false);
|
typeId = typeId(false, false);
|
||||||
consume(IToken.tRPAREN);
|
consume(IToken.tRPAREN);
|
||||||
castExpression = castExpression();
|
castExpression = castExpression();
|
||||||
} catch (BacktrackException bte) {
|
} catch (BacktrackException bte) {
|
||||||
|
@ -821,7 +821,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (LT(1) == IToken.tLPAREN) {
|
if (LT(1) == IToken.tLPAREN) {
|
||||||
try {
|
try {
|
||||||
consume(IToken.tLPAREN);
|
consume(IToken.tLPAREN);
|
||||||
typeId = typeId(false);
|
typeId = typeId(false, false);
|
||||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
|
@ -896,7 +896,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IToken m = mark();
|
IToken m = mark();
|
||||||
try {
|
try {
|
||||||
int offset = consume(IToken.tLPAREN).getOffset();
|
int offset = consume(IToken.tLPAREN).getOffset();
|
||||||
IASTTypeId t = typeId(false);
|
IASTTypeId t = typeId(false, false);
|
||||||
int lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
int lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST);
|
IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST);
|
||||||
firstExpression = buildTypeIdInitializerExpression(t, i, offset,
|
firstExpression = buildTypeIdInitializerExpression(t, i, offset,
|
||||||
|
@ -1150,7 +1150,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
return new CASTIdExpression();
|
return new CASTIdExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IASTTypeId typeId(boolean skipArrayModifiers)
|
protected IASTTypeId typeId(boolean skipArrayModifiers, boolean forNewExpression)
|
||||||
throws EndOfFileException, BacktrackException {
|
throws EndOfFileException, BacktrackException {
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
int startingOffset = mark.getOffset();
|
int startingOffset = mark.getOffset();
|
||||||
|
|
|
@ -270,7 +270,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IASTTypeId typeId = typeId(false);
|
IASTTypeId typeId = typeId(false, false);
|
||||||
list.add(typeId);
|
list.add(typeId);
|
||||||
completedArg = true;
|
completedArg = true;
|
||||||
} catch (BacktrackException e) {
|
} catch (BacktrackException e) {
|
||||||
|
@ -443,7 +443,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
} else {
|
} else {
|
||||||
// must be a conversion function
|
// must be a conversion function
|
||||||
IToken t = LA(1);
|
IToken t = LA(1);
|
||||||
typeId(true);
|
typeId(true, false);
|
||||||
if (t != LA(1)) {
|
if (t != LA(1)) {
|
||||||
while (t.getNext() != LA(1)) {
|
while (t.getNext() != LA(1)) {
|
||||||
t = t.getNext();
|
t = t.getNext();
|
||||||
|
@ -858,7 +858,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// If this isn't a type name, then we shouldn't be here
|
// If this isn't a type name, then we shouldn't be here
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
typeId = typeId(false);
|
typeId = typeId(false, false);
|
||||||
consume(IToken.tRPAREN);
|
consume(IToken.tRPAREN);
|
||||||
} catch (BacktrackException bte) {
|
} catch (BacktrackException bte) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
|
@ -887,7 +887,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
/**
|
/**
|
||||||
* @throws BacktrackException
|
* @throws BacktrackException
|
||||||
*/
|
*/
|
||||||
protected IASTTypeId typeId(boolean skipArrayModifiers)
|
protected IASTTypeId typeId(boolean skipArrayModifiers, boolean forNewExpression)
|
||||||
throws EndOfFileException, BacktrackException {
|
throws EndOfFileException, BacktrackException {
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
int startingOffset = mark.getOffset();
|
int startingOffset = mark.getOffset();
|
||||||
|
@ -897,7 +897,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
try {
|
try {
|
||||||
declSpecifier = declSpecifierSeq(true, true);
|
declSpecifier = declSpecifierSeq(true, true);
|
||||||
declarator = declarator(SimpleDeclarationStrategy.TRY_CONSTRUCTOR,
|
declarator = declarator(SimpleDeclarationStrategy.TRY_CONSTRUCTOR,
|
||||||
true);
|
true, forNewExpression );
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
throwBacktrack(startingOffset, figureEndOffset(declSpecifier,
|
throwBacktrack(startingOffset, figureEndOffset(declSpecifier,
|
||||||
|
@ -918,6 +918,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
declarator)
|
declarator)
|
||||||
- startingOffset);
|
- startingOffset);
|
||||||
}
|
}
|
||||||
|
if ( declarator instanceof IASTArrayDeclarator && skipArrayModifiers ) {
|
||||||
|
backup(mark);
|
||||||
|
throwBacktrack(startingOffset, figureEndOffset(declSpecifier,
|
||||||
|
declarator)
|
||||||
|
- startingOffset);
|
||||||
|
}
|
||||||
|
|
||||||
IASTTypeId result = createTypeId();
|
IASTTypeId result = createTypeId();
|
||||||
((ASTNode) result).setOffsetAndLength(startingOffset, figureEndOffset(
|
((ASTNode) result).setOffsetAndLength(startingOffset, figureEndOffset(
|
||||||
|
@ -1061,7 +1067,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// CASE: new (typeid-not-looking-as-placement) ...
|
// CASE: new (typeid-not-looking-as-placement) ...
|
||||||
// the first expression in () is not a placement
|
// the first expression in () is not a placement
|
||||||
// - then it has to be typeId
|
// - then it has to be typeId
|
||||||
typeId = typeId(true);
|
typeId = typeId(true, false);
|
||||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
if (templateIdScopes.size() > 0) {
|
if (templateIdScopes.size() > 0) {
|
||||||
templateIdScopes.pop();
|
templateIdScopes.pop();
|
||||||
|
@ -1084,7 +1090,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// - then it has to be typeId
|
// - then it has to be typeId
|
||||||
try {
|
try {
|
||||||
backtrackMarker = mark();
|
backtrackMarker = mark();
|
||||||
typeId = typeId(true);
|
typeId = typeId(true, true);
|
||||||
lastOffset = calculateEndOffset(typeId);
|
lastOffset = calculateEndOffset(typeId);
|
||||||
break master_new_loop;
|
break master_new_loop;
|
||||||
} catch (BacktrackException e) {
|
} catch (BacktrackException e) {
|
||||||
|
@ -1102,7 +1108,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// The problem is, the first expression might as well be a
|
// The problem is, the first expression might as well be a
|
||||||
// typeid
|
// typeid
|
||||||
try {
|
try {
|
||||||
typeId = typeId(true);
|
typeId = typeId(true, false);
|
||||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
if (templateIdScopes.size() > 0) {
|
if (templateIdScopes.size() > 0) {
|
||||||
templateIdScopes.pop();
|
templateIdScopes.pop();
|
||||||
|
@ -1156,7 +1162,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// CASE: new typeid ...
|
// CASE: new typeid ...
|
||||||
// new parameters do not start with '('
|
// new parameters do not start with '('
|
||||||
// i.e it has to be a plain typeId
|
// i.e it has to be a plain typeId
|
||||||
typeId = typeId(true);
|
typeId = typeId(true, true);
|
||||||
lastOffset = calculateEndOffset(typeId);
|
lastOffset = calculateEndOffset(typeId);
|
||||||
isNewTypeId = true;
|
isNewTypeId = true;
|
||||||
break master_new_loop;
|
break master_new_loop;
|
||||||
|
@ -1269,7 +1275,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (LT(1) == IToken.tLPAREN) {
|
if (LT(1) == IToken.tLPAREN) {
|
||||||
try {
|
try {
|
||||||
consume(IToken.tLPAREN);
|
consume(IToken.tLPAREN);
|
||||||
typeId = typeId(false);
|
typeId = typeId(true, false);
|
||||||
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
|
@ -1411,7 +1417,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTTypeId typeId = null;
|
IASTTypeId typeId = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
typeId = typeId(false);
|
typeId = typeId(false, false);
|
||||||
} catch (BacktrackException b) {
|
} catch (BacktrackException b) {
|
||||||
isTypeId = false;
|
isTypeId = false;
|
||||||
lhs = expression();
|
lhs = expression();
|
||||||
|
@ -1780,7 +1786,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
int startingOffset = LA(1).getOffset();
|
int startingOffset = LA(1).getOffset();
|
||||||
consume();
|
consume();
|
||||||
consume(IToken.tLT);
|
consume(IToken.tLT);
|
||||||
IASTTypeId typeID = typeId(false);
|
IASTTypeId typeID = typeId(false, false);
|
||||||
consume(IToken.tGT);
|
consume(IToken.tGT);
|
||||||
consume(IToken.tLPAREN);
|
consume(IToken.tLPAREN);
|
||||||
IASTExpression lhs = expression();
|
IASTExpression lhs = expression();
|
||||||
|
@ -2168,7 +2174,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (LT(1) == IToken.tASSIGN) // optional = type-id
|
if (LT(1) == IToken.tASSIGN) // optional = type-id
|
||||||
{
|
{
|
||||||
consume(IToken.tASSIGN);
|
consume(IToken.tASSIGN);
|
||||||
typeId = typeId(false); // type-id
|
typeId = typeId(false, false); // type-id
|
||||||
lastOffset = calculateEndOffset(typeId);
|
lastOffset = calculateEndOffset(typeId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -3350,7 +3356,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
*/
|
*/
|
||||||
protected IASTDeclarator initDeclarator(SimpleDeclarationStrategy strategy)
|
protected IASTDeclarator initDeclarator(SimpleDeclarationStrategy strategy)
|
||||||
throws EndOfFileException, BacktrackException {
|
throws EndOfFileException, BacktrackException {
|
||||||
IASTDeclarator d = declarator(strategy, false);
|
IASTDeclarator d = declarator(strategy, false, false );
|
||||||
|
|
||||||
IASTInitializer initializer = optionalCPPInitializer();
|
IASTInitializer initializer = optionalCPPInitializer();
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
|
@ -3478,17 +3484,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
* (oldKRParameterDeclaration)*
|
* (oldKRParameterDeclaration)*
|
||||||
*
|
*
|
||||||
* declaratorId : name
|
* declaratorId : name
|
||||||
*
|
|
||||||
* @param forTypeID
|
* @param forTypeID
|
||||||
* TODO
|
* TODO
|
||||||
|
* @param skipArrayDeclarator TODO
|
||||||
* @param container
|
* @param container
|
||||||
* IParserCallback object that represents the owner declaration.
|
* IParserCallback object that represents the owner declaration.
|
||||||
|
*
|
||||||
* @return declarator that this parsing produced.
|
* @return declarator that this parsing produced.
|
||||||
* @throws BacktrackException
|
* @throws BacktrackException
|
||||||
* request a backtrack
|
* request a backtrack
|
||||||
*/
|
*/
|
||||||
protected IASTDeclarator declarator(SimpleDeclarationStrategy strategy,
|
protected IASTDeclarator declarator(SimpleDeclarationStrategy strategy,
|
||||||
boolean forTypeID) throws EndOfFileException, BacktrackException {
|
boolean forTypeID, boolean skipArrayDeclarator) throws EndOfFileException, BacktrackException {
|
||||||
|
|
||||||
IToken la = LA(1);
|
IToken la = LA(1);
|
||||||
int startingOffset = la.getOffset();
|
int startingOffset = la.getOffset();
|
||||||
|
@ -3516,7 +3523,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
try {
|
try {
|
||||||
consume();
|
consume();
|
||||||
innerDecl = declarator(strategy, forTypeID);
|
innerDecl = declarator(strategy, forTypeID, skipArrayDeclarator);
|
||||||
finalOffset = consume(IToken.tRPAREN).getEndOffset();
|
finalOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
} catch (BacktrackException bte) {
|
} catch (BacktrackException bte) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
|
@ -3647,7 +3654,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
try {
|
try {
|
||||||
exceptionSpecIds.add(typeId(false));
|
exceptionSpecIds.add(typeId(false, false ) );
|
||||||
} catch (BacktrackException e) {
|
} catch (BacktrackException e) {
|
||||||
IASTProblem p = failParse(e);
|
IASTProblem p = failParse(e);
|
||||||
IASTProblemTypeId typeIdProblem = createTypeIDProblem();
|
IASTProblemTypeId typeIdProblem = createTypeIDProblem();
|
||||||
|
@ -3691,6 +3698,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IToken.tLBRACKET:
|
case IToken.tLBRACKET:
|
||||||
|
if( skipArrayDeclarator ) break;
|
||||||
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
||||||
consumeArrayModifiers(arrayMods);
|
consumeArrayModifiers(arrayMods);
|
||||||
if (!arrayMods.isEmpty())
|
if (!arrayMods.isEmpty())
|
||||||
|
|
Loading…
Add table
Reference in a new issue