1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00
Renamed IToken::tELIPSE to IToken::tELLIPSIS
	Partially fixed Bug 43110 : Parser support needed for functions with ellipses 

TESTS
	Added CompleteParseASTTest::testBug43110() and QuickParseASTTests::testBug43110().
This commit is contained in:
John Camelon 2004-01-06 15:26:48 +00:00
parent 0ec807acad
commit d02df84a93
18 changed files with 95 additions and 33 deletions

View file

@ -1,3 +1,6 @@
2004-01-06 John Camelon
Added CompleteParseASTTest::testBug43110() and QuickParseASTTests::testBug43110().
2003-12-31 Hoda Amer
Small change to test parameters with initial clause in ITemplateTest

View file

@ -1102,4 +1102,15 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertAllReferences( 5, createTaskList( new Task( namespace, 2 ), new Task( classA, 2 ), new Task( a ) ) );
}
public void testBug43110() throws Exception
{
StringBuffer buffer = new StringBuffer();
buffer.append("void x( int y, ... );\n");
buffer.append("void y( int x... );\n");
buffer.append("void z(...);");
Iterator i = parse(buffer.toString() ).getDeclarations();
while( i.hasNext() )
assertTrue( ((IASTFunction)i.next()).takesVarArgs() );
}
}

View file

@ -2022,4 +2022,12 @@ public class QuickParseASTTests extends BaseASTTest
assertEquals( exp.getLiteralString(), "ab");
}
public void testBug43110() throws Exception
{
IASTFunction function = (IASTFunction) assertSoleDeclaration( "void x( int y, ... );");
assertTrue( function.takesVarArgs() );
function = (IASTFunction) assertSoleDeclaration( "void x( int y... );");
assertTrue( function.takesVarArgs() );
}
}

View file

@ -190,7 +190,7 @@ public class ScannerTestCase extends BaseScannerTest
validateFloatingPointLiteral( "3.");
validateFloatingPointLiteral( "4E5");
validateFloatingPointLiteral( "2.01E-03" );
validateToken( IToken.tELIPSE );
validateToken( IToken.tELLIPSIS );
validateEOF();
}
catch( ScannerException se )
@ -1033,7 +1033,7 @@ public class ScannerTestCase extends BaseScannerTest
initializeScanner( "foo...bar");
validateIdentifier("foo");
validateToken( IToken.tELIPSE );
validateToken( IToken.tELLIPSIS );
validateIdentifier("bar");
validateEOF();
}

View file

@ -1,3 +1,7 @@
2004-01-06 John Camelon
Renamed IToken::tELIPSE to IToken::tELLIPSIS
Partially fixed Bug 43110 : Parser support needed for functions with ellipses
2004-01-05 John Camelon
Removed warnings.
Moved StructuralParseCallback from model to parser directory to facilitate building the parser standalone.

View file

@ -123,7 +123,7 @@ public interface IToken {
static public final int tSHIFTLASSIGN = 47;
static public final int tELIPSE = 48;
static public final int tELLIPSIS = 48;
static public final int tDOTSTAR = 49;

View file

@ -26,7 +26,7 @@ public interface IASTFactory
String name,
int startingOffset,
int nameOffset,
int nameEndOffset, int endingOffset) ;
int nameEndOffset, int endingOffset);
public IASTInclusion createInclusion(
String name,
@ -131,7 +131,7 @@ public interface IASTFactory
/**
* @param exp
*/
public IASTArrayModifier createArrayModifier(IASTExpression exp) ;
public IASTArrayModifier createArrayModifier(IASTExpression exp);
/**
* @param duple
@ -169,7 +169,7 @@ public interface IASTFactory
boolean isVolatile,
boolean isVirtual,
boolean isExplicit,
boolean isPureVirtual, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock ) throws ASTSemanticException;
boolean isPureVirtual, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments ) throws ASTSemanticException;
public IASTAbstractDeclaration createAbstractDeclaration(
@ -195,7 +195,7 @@ public interface IASTFactory
boolean isVolatile,
boolean isVirtual,
boolean isExplicit,
boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock) throws ASTSemanticException;
boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments) throws ASTSemanticException;
public IASTVariable createVariable(IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression,
IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression ) throws ASTSemanticException;

View file

@ -22,6 +22,8 @@ public interface IASTFunction extends IASTCodeScope, IASTOffsetableNamedElement,
public boolean isFriend();
public boolean isStatic();
public boolean takesVarArgs();
public String getName();
public IASTAbstractDeclaration getReturnType();

View file

@ -483,7 +483,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
virtual,
explicit,
declarator.isPureVirtual(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode(),
declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody(), declarator.hasFunctionTryBlock());
declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody(), declarator.hasFunctionTryBlock(), declarator.isVarArgs());
}
catch (ASTSemanticException e)
{
@ -524,7 +524,8 @@ public class DeclarationWrapper implements IDeclaratorOwner
virtual,
explicit,
declarator.isPureVirtual(),
declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody(), declarator.hasFunctionTryBlock() );
declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody(), declarator.hasFunctionTryBlock(),
declarator.isVarArgs() );
}
catch (ASTSemanticException e)
{

View file

@ -51,7 +51,8 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
private boolean isKandR = false;
private int nameStartOffset, nameEndOffset;
private int nameStartOffset, nameEndOffset;
private boolean varArgs;
public Declarator( IDeclaratorOwner owner )
{
@ -433,4 +434,18 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
hasFunctionTryBlock = b;
}
/**
* @param b
*/
public void setIsVarArgs(boolean b) {
varArgs = b;
}
/**
* @return Returns the varArgs.
*/
public boolean isVarArgs() {
return varArgs;
}
}

View file

@ -2198,8 +2198,9 @@ public abstract class Parser implements IParser
case IToken.tRPAREN :
consume();
break parameterDeclarationLoop;
case IToken.tELIPSE :
case IToken.tELLIPSIS :
consume();
d.setIsVarArgs( true );
break;
case IToken.tCOMMA :
consume();
@ -3046,8 +3047,8 @@ public abstract class Parser implements IParser
{
consume(IToken.t_catch);
consume(IToken.tLPAREN);
if( LT(1) == IToken.tELIPSE )
consume( IToken.tELIPSE );
if( LT(1) == IToken.tELLIPSIS )
consume( IToken.tELLIPSIS );
else
declaration(scope, null); // was exceptionDeclaration
consume(IToken.tRPAREN);

View file

@ -944,7 +944,7 @@ public class Scanner implements IScanner {
return newToken( IToken.tDOTSTAR, ".*", contextStack.getCurrentContext() );
} else if( c == '.' ){
if( getChar() == '.' )
return newToken( IToken.tELIPSE, "..." );
return newToken( IToken.tELLIPSIS, "..." );
else
handleProblem( IProblem.SCANNER_BAD_FLOATING_POINT, null, beginOffset, false, true, true );
} else {
@ -1557,7 +1557,7 @@ public class Scanner implements IScanner {
switch (c) {
case '.' :
return newToken(
IToken.tELIPSE,
IToken.tELLIPSIS,
"...",
contextStack.getCurrentContext());
default :

View file

@ -55,7 +55,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
* @param ownerTemplate
* @param references
*/
public ASTFunction(IParameterizedSymbol symbol, int nameEndOffset, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int nameOffset, IASTTemplate ownerTemplate, List references, boolean previouslyDeclared, boolean hasFunctionTryBlock )
public ASTFunction(IParameterizedSymbol symbol, int nameEndOffset, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int nameOffset, IASTTemplate ownerTemplate, List references, boolean previouslyDeclared, boolean hasFunctionTryBlock, boolean hasVarArgs)
{
super( symbol );
this.parameters = parameters;
@ -70,6 +70,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() );
this.previouslyDeclared =previouslyDeclared;
this.hasFunctionTryBlock = hasFunctionTryBlock;
this.varArgs = hasVarArgs;
}
@ -305,6 +306,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
private boolean hasFunctionTryBlock = false;
private final boolean varArgs;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionTryBlock(boolean)
*/
@ -329,5 +331,12 @@ public class ASTFunction extends ASTScope implements IASTFunction
{
declarations.add(declaration);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#takesVarArgs()
*/
public boolean takesVarArgs() {
return varArgs;
}
}

View file

@ -46,7 +46,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
* @param references
*/
public ASTMethod(IParameterizedSymbol symbol, int nameEndOffset, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int nameOffset, IASTTemplate ownerTemplate, List references, boolean previouslyDeclared,
boolean isConstructor, boolean isDestructor, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean hasFunctionTryBlock )
boolean isConstructor, boolean isDestructor, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean hasFunctionTryBlock, boolean hasVariableArguments )
{
super(
symbol,
@ -57,7 +57,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
startOffset,
nameOffset,
ownerTemplate,
references, previouslyDeclared, hasFunctionTryBlock );
references, previouslyDeclared, hasFunctionTryBlock, hasVariableArguments );
this.visibility = visibility;
this.isConstructor = isConstructor;
this.isDestructor = isDestructor;

View file

@ -1596,7 +1596,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean isExplicit,
boolean isPureVirtual,
List constructorChain,
boolean isFunctionDefinition, boolean hasFunctionTryBlock ) throws ASTSemanticException
boolean isFunctionDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments ) throws ASTSemanticException
{
List references = new ArrayList();
IContainerSymbol ownerScope = scopeToSymbol( scope );
@ -1641,7 +1641,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ASTAccessVisibility.PRIVATE,
constructorChain,
references,
isFunctionDefinition, hasFunctionTryBlock );
isFunctionDefinition, hasFunctionTryBlock, hasVariableArguments );
}
}
@ -1684,7 +1684,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{
throw new ASTSemanticException();
}
ASTFunction function = new ASTFunction( symbol, nameEndOffset, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, previouslyDeclared, hasFunctionTryBlock );
ASTFunction function = new ASTFunction( symbol, nameEndOffset, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, previouslyDeclared, hasFunctionTryBlock, hasVariableArguments );
try
{
attachSymbolExtension(symbol, function);
@ -1892,12 +1892,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean isVirtual,
boolean isExplicit,
boolean isPureVirtual,
ASTAccessVisibility visibility, List constructorChain, boolean isFunctionDefinition, boolean hasFunctionTryBlock ) throws ASTSemanticException
ASTAccessVisibility visibility, List constructorChain, boolean isFunctionDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments ) throws ASTSemanticException
{
return createMethod(scope, name, parameters, returnType, exception,
isInline, isFriend, isStatic, startOffset, nameOffset, nameEndOffset,
ownerTemplate, isConst, isVolatile, isVirtual, isExplicit, isPureVirtual,
visibility, constructorChain, null, isFunctionDefinition, hasFunctionTryBlock );
visibility, constructorChain, null, isFunctionDefinition, hasFunctionTryBlock, hasVariableArguments );
}
public IASTMethod createMethod(
@ -1920,7 +1920,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean isPureVirtual,
ASTAccessVisibility visibility,
List constructorChain,
List references, boolean isFunctionDefinition, boolean hasFunctionTryBlock ) throws ASTSemanticException
List references, boolean isFunctionDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments ) throws ASTSemanticException
{
boolean isConstructor = false;
boolean isDestructor = false;
@ -1997,7 +1997,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
resolveLeftoverConstructorInitializerMembers( symbol, constructorChain );
ASTMethod method = new ASTMethod( symbol, nameEndOffset, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, previouslyDeclared, isConstructor, isDestructor, isPureVirtual, visibility, constructorChain, hasFunctionTryBlock );
ASTMethod method = new ASTMethod( symbol, nameEndOffset, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, previouslyDeclared, isConstructor, isDestructor, isPureVirtual, visibility, constructorChain, hasFunctionTryBlock, hasVariableArguments );
try
{
attachSymbolExtension( symbol, method );

View file

@ -35,7 +35,7 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction
* @param scope
*/
public ASTFunction(IASTScope scope, String name, int nameEndOffset, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception,
boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, boolean hasFunctionTryBlock )
boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, boolean hasFunctionTryBlock, boolean hasVarArgs )
{
super(ownerTemplate != null ? null : scope );
this.name = name;
@ -53,6 +53,7 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction
qualifiedName = new ASTQualifiedNamedElement( scope, name );
setNameEndOffset(nameEndOffset);
this.hasFunctionTryBlock = hasFunctionTryBlock;
this.varArgs = hasVarArgs;
}
private boolean previouslyDeclared;
@ -265,6 +266,7 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction
}
private boolean hasFunctionTryBlock = false;
private final boolean varArgs;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionTryBlock(boolean)
*/
@ -280,4 +282,10 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction
{
return hasFunctionTryBlock;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#takesVarArgs()
*/
public boolean takesVarArgs() {
return varArgs;
}
}

View file

@ -71,7 +71,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
boolean isVirtual,
boolean isExplicit,
boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChainElements,
boolean hasFunctionTryBlock )
boolean hasFunctionTryBlock, boolean hasVarArgs )
{
super(
scope,
@ -85,7 +85,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
isStatic,
startOffset,
nameOffset,
ownerTemplate, hasFunctionTryBlock);
ownerTemplate, hasFunctionTryBlock, hasVarArgs);
this.isVirtual = isVirtual;
this.isPureVirtual = isPureVirtual;
this.isConstructor = isConstructor;

View file

@ -185,17 +185,17 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createFunction(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
*/
public IASTFunction createFunction(IASTScope scope, ITokenDuple name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, int nameEndOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, List constructorChain, boolean isFunctionDefinition, boolean hasFunctionTryBlock )
public IASTFunction createFunction(IASTScope scope, ITokenDuple name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, int nameEndOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, List constructorChain, boolean isFunctionDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments )
{
return new ASTFunction(scope, name.toString(), nameEndOffset, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate, hasFunctionTryBlock );
return new ASTFunction(scope, name.toString(), nameEndOffset, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate, hasFunctionTryBlock, hasVariableArguments );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createMethod(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration, boolean, boolean, boolean, boolean, boolean, boolean, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility)
*/
public IASTMethod createMethod(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, int nameEndOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isFunctionDefinition, boolean hasFunctionTryBlock )
public IASTMethod createMethod(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, int nameEndOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isFunctionDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments )
{
return new ASTMethod(scope, name, nameEndOffset, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate, isConst, isVolatile, false, false, isVirtual, isExplicit, isPureVirtual, visibility, constructorChain, hasFunctionTryBlock);
return new ASTMethod(scope, name, nameEndOffset, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate, isConst, isVolatile, false, false, isVirtual, isExplicit, isPureVirtual, visibility, constructorChain, hasFunctionTryBlock, hasVariableArguments);
}
/* (non-Javadoc)