1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

ITokenDuple support for seperating fully qualified names that use template-ids,

also modify IASTFactory.createField & createVariable to take ITokenDuple for name
Better treatement for definitions of static members of template classes.
This commit is contained in:
Andrew Niefer 2004-03-25 22:10:50 +00:00
parent 7d0581e51c
commit 2153d2d6ec
18 changed files with 396 additions and 166 deletions

View file

@ -1,3 +1,7 @@
2003-04-25 Andrew Niefer
-added parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.testClassTemplateStaticMemberDefinition()
-modified parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.testPointersToMemberFunctions
2003-03-23 Andrew Niefer 2003-03-23 Andrew Niefer
bug 55673 & fix recursive loop in template instantiation bug 55673 & fix recursive loop in template instantiation
-parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.testInstantiatingDeferredInstances() -parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.testInstantiatingDeferredInstances()

View file

@ -1834,4 +1834,20 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
} }
public void testClassTemplateStaticMemberDefinition() throws Exception {
Writer writer = new StringWriter();
writer.write( "template< class T > class A{ \n" );
writer.write( " typedef T * PT; \n" );
writer.write( " static T member; \n" );
writer.write( "}; \n" );
writer.write( "template< class T> A<T>::PT A<T>::member = null; \n" );
Iterator i = parse( writer.toString() ).getDeclarations();
IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next();
IASTTemplateDeclaration template2 = (IASTTemplateDeclaration) i.next();
IASTField member = (IASTField) getDeclarations( template2 ).next();
assertEquals( member.getName(), "member" );
}
} }

View file

@ -1645,7 +1645,7 @@ public class QuickParseASTTests extends BaseASTTest
{ {
IASTVariable p2m = (IASTVariable)parse("void (A::*name)(void);").getDeclarations().next(); IASTVariable p2m = (IASTVariable)parse("void (A::*name)(void);").getDeclarations().next();
assertSimpleType( p2m, IASTSimpleTypeSpecifier.Type.VOID ); assertSimpleType( p2m, IASTSimpleTypeSpecifier.Type.VOID );
assertEquals( p2m.getName(), "A::name"); assertEquals( p2m.getName(), "A::* name");
assertEquals( p2m.getAbstractDeclaration().getPointerToFunctionOperator(), ASTPointerOperator.POINTER); assertEquals( p2m.getAbstractDeclaration().getPointerToFunctionOperator(), ASTPointerOperator.POINTER);
Iterator parameters = p2m.getAbstractDeclaration().getParameters(); Iterator parameters = p2m.getAbstractDeclaration().getParameters();
IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next();

View file

@ -1,3 +1,8 @@
2004-03-25 Andrew Niefer
-modify IASTFactory.createField & .createVariable to take ITokenDuple's for the name
-modify ITokenDuple to support manipulating TokenDuples that have template arguments in them
-fix NullPointer & ClassCast exceptions found while parsing <string>
2004-03-25 Hoda Amer 2004-03-25 Hoda Amer
Joined effort with Bogdan: Added a parserTimeout() method to ISourceElementRequestor Joined effort with Bogdan: Added a parserTimeout() method to ISourceElementRequestor
and the ability for the parser to timeout. and the ability for the parser to timeout.

View file

@ -32,6 +32,11 @@ public interface ITokenDuple {
public abstract IToken getLastToken(); public abstract IToken getLastToken();
public List [] getTemplateIdArgLists(); public List [] getTemplateIdArgLists();
public IToken consumeTemplateIdArguments( IToken name, Iterator iter );
public ITokenDuple getLastSegment();
public ITokenDuple getLeadingSegments();
public int getSegmentCount();
public abstract Iterator iterator(); public abstract Iterator iterator();
public abstract String toString(); public abstract String toString();

View file

@ -199,10 +199,10 @@ public interface IASTFactory
boolean isVolatile, boolean isVolatile,
boolean isVirtual, boolean isExplicit, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments) throws ASTSemanticException; boolean isVirtual, boolean isExplicit, 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, public IASTVariable createVariable(IASTScope scope, ITokenDuple name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression,
IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression ) throws ASTSemanticException; IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression ) throws ASTSemanticException;
public IASTField createField( IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, ASTAccessVisibility visibility) throws ASTSemanticException; public IASTField createField( IASTScope scope, ITokenDuple name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, ASTAccessVisibility visibility) throws ASTSemanticException;
public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier ); public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier );

View file

@ -33,6 +33,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
/** /**
* @author jcamelon * @author jcamelon
* *
@ -403,9 +404,11 @@ public class DeclarationWrapper implements IDeclaratorOwner
declarator.getArrayModifiers(), declarator.getArrayModifiers(),
convertedParms, convertedParms,
(ASTPointerOperator)i.next()); (ASTPointerOperator)i.next());
String name = ( d.getPointerOperatorNameDuple() != null ) ? d.getPointerOperatorNameDuple().toString() + d.getName() : d.getName();
ITokenDuple name = ( d.getPointerOperatorNameDuple() != null ) ? new TokenDuple( d.getPointerOperatorNameDuple(), d.getNameDuple() ) : d.getNameDuple();
if( typedef ) if( typedef )
return astFactory.createTypedef(scope, name, abs, return astFactory.createTypedef(scope, name.toString(), abs,
getStartingOffset(), getStartingLine(), d getStartingOffset(), getStartingLine(), d
.getNameStartOffset(), d.getNameEndOffset(), d .getNameStartOffset(), d.getNameEndOffset(), d
.getNameLine()); .getNameLine());
@ -499,7 +502,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
{ {
return astFactory.createField( return astFactory.createField(
scope, scope,
nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), nested ? declarator.getOwnedDeclarator().getNameDuple() : declarator.getNameDuple(),
auto, auto,
declarator.getInitializerClause(), declarator.getInitializerClause(),
declarator.getBitFieldExpression(), declarator.getBitFieldExpression(),
@ -551,7 +554,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
{ {
return astFactory.createVariable( return astFactory.createVariable(
scope, scope,
nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), nested ? declarator.getOwnedDeclarator().getNameDuple() : declarator.getNameDuple(),
isAuto(), isAuto(),
declarator.getInitializerClause(), declarator.getInitializerClause(),
declarator.getBitFieldExpression(), declarator.getBitFieldExpression(),

View file

@ -267,15 +267,17 @@ public class ExpressionParser implements IExpressionParser {
IToken last = null; IToken last = null;
IToken mark = mark(); IToken mark = mark();
if (LT(1) == IToken.tCOLONCOLON) List argumentList = new LinkedList();
boolean hasTemplateId = false;
if (LT(1) == IToken.tCOLONCOLON){
argumentList.add( null );
last = consume( IToken.tCOLONCOLON ); last = consume( IToken.tCOLONCOLON );
}
if (LT(1) == IToken.tCOMPL) if (LT(1) == IToken.tCOMPL)
consume(); consume();
List argumentList = new LinkedList();
boolean hasTemplateId = false;
switch (LT(1)) switch (LT(1))
{ {
case IToken.tIDENTIFIER : case IToken.tIDENTIFIER :

View file

@ -48,7 +48,12 @@ public class ASTTemplateDeclaration extends ASTSymbol implements IASTTemplateDec
{ {
super( template ); super( template );
IContainerSymbol container = ((ASTScope)scope).getContainerSymbol(); IContainerSymbol container = null;
if( scope instanceof ASTTemplateDeclaration )
container = ((ASTTemplateDeclaration)scope).getContainerSymbol();
else
container = ((ASTScope)scope).getContainerSymbol();
if( container instanceof ITemplateFactory ){ if( container instanceof ITemplateFactory ){
factory = (ITemplateFactory) container; factory = (ITemplateFactory) container;
} else { } else {

View file

@ -18,7 +18,6 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Stack; import java.util.Stack;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.parser.Enum; import org.eclipse.cdt.core.parser.Enum;
import org.eclipse.cdt.core.parser.IFilenameProvider; import org.eclipse.cdt.core.parser.IFilenameProvider;
@ -301,7 +300,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( ((IASTCodeScope) startingScope.getASTExtension().getPrimaryDeclaration()).getContainingFunction() instanceof IASTMethod ) if( ((IASTCodeScope) startingScope.getASTExtension().getPrimaryDeclaration()).getContainingFunction() instanceof IASTMethod )
{ {
IASTClassSpecifier classSpecifier = ((IASTMethod) ((IASTCodeScope) startingScope.getASTExtension().getPrimaryDeclaration()).getContainingFunction()).getOwnerClassSpecifier(); IASTClassSpecifier classSpecifier = ((IASTMethod) ((IASTCodeScope) startingScope.getASTExtension().getPrimaryDeclaration()).getContainingFunction()).getOwnerClassSpecifier();
((ASTClassSpecifier)classSpecifier).addUnresolvedReference( new UnresolvedReferenceDuple( startingScope, name )); if( classSpecifier != null )
((ASTClassSpecifier)classSpecifier).addUnresolvedReference( new UnresolvedReferenceDuple( startingScope, name ));
break; break;
} }
} }
@ -330,18 +330,23 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
int offset = t.getOffset(); int offset = t.getOffset();
if( templateArgLists != null && templateArgLists[ idx ] != null ){ if( templateArgLists != null && templateArgLists[ idx ] != null ){
t = consumeTemplateIdArguments( t, iter ); if( iter.hasNext() && t.getNext().getType() == IToken.tLT )
t = name.consumeTemplateIdArguments( (IToken) iter.next(), iter );
} }
try try
{ {
if( result instanceof IDeferredTemplateInstance ){
result = ((IDeferredTemplateInstance)result).getTemplate().getTemplatedSymbol();
}
if( t == name.getLastToken() ) if( t == name.getLastToken() )
if( templateArgLists != null ) if( templateArgLists != null )
result = lookupElement((IContainerSymbol)result, image, type, parameters, getTemplateArgList( templateArgLists[idx] ), ( lookup == LookupType.FORDEFINITION ) ? lookup : LookupType.QUALIFIED ); result = lookupElement((IContainerSymbol)result, image, type, parameters, getTemplateArgList( templateArgLists[idx] ), ( lookup == LookupType.FORDEFINITION ) ? lookup : LookupType.QUALIFIED );
else else
result = lookupElement((IContainerSymbol)result, image, type, parameters, ( lookup == LookupType.FORDEFINITION ) ? lookup : LookupType.QUALIFIED ); result = lookupElement((IContainerSymbol)result, image, type, parameters, ( lookup == LookupType.FORDEFINITION ) ? lookup : LookupType.QUALIFIED );
else else
if( templateArgLists != null ) if( templateArgLists != null && templateArgLists[idx] != null )
result = ((IContainerSymbol)result).lookupTemplateId( image, getTemplateArgList( templateArgLists[idx] ) ); result = ((IContainerSymbol)result).lookupTemplateId( image, getTemplateArgList( templateArgLists[idx] ) );
else else
result = ((IContainerSymbol)result).lookupNestedNameSpecifier( image ); result = ((IContainerSymbol)result).lookupNestedNameSpecifier( image );
@ -650,29 +655,26 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean isTemplateId = false; boolean isTemplateId = false;
if( name != null ){ if( name != null ){
IToken lastToken = name.getLastToken(); IToken nameToken = null;
if( name.length() != 1 ) // qualified name if( name.getSegmentCount() != 1 ) // qualified name
{ {
int idx = name.findLastTokenType( IToken.tCOLONCOLON ); ITokenDuple containerSymbolName = name.getLeadingSegments();
if( idx != -1 ){ currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, containerSymbolName, references, true);
ITokenDuple containerSymbolName = if( currentScopeSymbol == null )
name.getSubrange( 0, idx - 1 ); // -1 for index, -2 for last hop of qualified name handleProblem( IProblem.SEMANTIC_NAME_NOT_FOUND, containerSymbolName.toString(), containerSymbolName.getFirstToken().getOffset(), containerSymbolName.getLastToken().getEndOffset(), containerSymbolName.getLastToken().getLineNumber() );
currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol,
containerSymbolName, references, true);
if( currentScopeSymbol == null )
handleProblem( IProblem.SEMANTIC_NAME_NOT_FOUND, containerSymbolName.toString(), containerSymbolName.getFirstToken().getOffset(), containerSymbolName.getLastToken().getEndOffset(), containerSymbolName.getLastToken().getLineNumber() );
}
//template-id
List [] array = name.getTemplateIdArgLists();
if( array != null ){
isTemplateId = true;
templateIdArgList = array[ array.length - 1 ];
lastToken = name.getToken( idx + 1);
}
nameToken = name.getLastSegment().getFirstToken();
} else {
nameToken = name.getFirstToken();
} }
newSymbolName = lastToken.getImage(); //template-id
List [] array = name.getTemplateIdArgLists();
if( array != null ){
isTemplateId = true;
templateIdArgList = array[ array.length - 1 ];
}
newSymbolName = nameToken.getImage();
} }
ISymbol classSymbol = null; ISymbol classSymbol = null;
@ -1708,9 +1710,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
int offset = current.getOffset(); int offset = current.getOffset();
if( argLists != null && argLists[ idx ] != null ){ if( argLists != null && argLists[ idx ] != null ){
current = consumeTemplateIdArguments( current, i ); if( i.hasNext() && current.getNext().getType() == IToken.tLT )
current = typeName.consumeTemplateIdArguments( (IToken) i.next(), i );
} }
if( typeSymbol instanceof IDeferredTemplateInstance ){
typeSymbol = ((IDeferredTemplateInstance)typeSymbol).getTemplate().getTemplatedSymbol();
}
try try
{ {
if( argLists != null && argLists[ idx ] != null ) if( argLists != null && argLists[ idx ] != null )
@ -1771,15 +1777,19 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
IContainerSymbol ownerScope = scopeToSymbol( scope ); IContainerSymbol ownerScope = scopeToSymbol( scope );
// check if this is a method in a body file // check if this is a method in a body file
if(name.length() > 1){ if(name.getSegmentCount() > 1){
IContainerSymbol parentScope = (IContainerSymbol) ISymbol symbol = lookupQualifiedName( ownerScope,
lookupQualifiedName( name.getLeadingSegments(),
ownerScope, references,
name.getSubrange( 0, name.findLastTokenType( IToken.tCOLONCOLON ) - 1), false,
references, LookupType.FORPARENTSCOPE );
false,
LookupType.FORPARENTSCOPE );
IContainerSymbol parentScope = null;
if( symbol instanceof IContainerSymbol )
parentScope = (IContainerSymbol) symbol;
else if( symbol instanceof IDeferredTemplateInstance )
parentScope = ((IDeferredTemplateInstance) symbol).getTemplate().getTemplatedSymbol();
if((parentScope != null) && if((parentScope != null) &&
( (parentScope.getType() == TypeInfo.t_class) ( (parentScope.getType() == TypeInfo.t_class)
@ -1787,9 +1797,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|| (parentScope.getType() == TypeInfo.t_union)) || (parentScope.getType() == TypeInfo.t_union))
){ ){
IASTScope methodParentScope = (IASTScope)parentScope.getASTExtension().getPrimaryDeclaration(); IASTScope methodParentScope = (IASTScope)parentScope.getASTExtension().getPrimaryDeclaration();
ITokenDuple newName = name.getSubrange( ITokenDuple newName = name.getLastSegment();
name.findLastTokenType( IToken.tCOLONCOLON) + 1,
name.length() - 1 );
return createMethod( return createMethod(
methodParentScope, methodParentScope,
newName, newName,
@ -1815,7 +1823,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
} }
IParameterizedSymbol symbol = pst.newParameterizedSymbol( name.getLastToken().getImage(), TypeInfo.t_function ); IParameterizedSymbol symbol = pst.newParameterizedSymbol( name.getFirstToken().getImage(), TypeInfo.t_function );
setFunctionTypeInfoBits(isInline, isFriend, isStatic, symbol); setFunctionTypeInfoBits(isInline, isFriend, isStatic, symbol);
symbol.setHasVariableArgs( hasVariableArguments ); symbol.setHasVariableArgs( hasVariableArguments );
@ -1838,7 +1846,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
IParameterizedSymbol functionDeclaration = null; IParameterizedSymbol functionDeclaration = null;
functionDeclaration = functionDeclaration =
(IParameterizedSymbol) lookupQualifiedName(ownerScope, name.getLastToken().getImage(), TypeInfo.t_function, functionParameters, 0, new ArrayList(), false, LookupType.FORDEFINITION ); (IParameterizedSymbol) lookupQualifiedName(ownerScope, name.getFirstToken().getImage(), TypeInfo.t_function, functionParameters, 0, new ArrayList(), false, LookupType.FORDEFINITION );
if( functionDeclaration != null ){ if( functionDeclaration != null ){
previouslyDeclared = true; previouslyDeclared = true;
@ -2273,7 +2281,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
*/ */
public IASTVariable createVariable( public IASTVariable createVariable(
IASTScope scope, IASTScope scope,
String name, ITokenDuple name,
boolean isAuto, boolean isAuto,
IASTInitializerClause initializerClause, IASTInitializerClause initializerClause,
IASTExpression bitfieldExpression, IASTExpression bitfieldExpression,
@ -2288,58 +2296,36 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
List references = new ArrayList(); List references = new ArrayList();
IContainerSymbol ownerScope = scopeToSymbol( scope ); IContainerSymbol ownerScope = scopeToSymbol( scope );
// check if this is a scoped field, not a variable if(name.getSegmentCount() > 1)
StringTokenizer tokenizer = new StringTokenizer(name,DOUBLE_COLON); {
int tokencount = tokenizer.countTokens(); ISymbol symbol = lookupQualifiedName( ownerScope,
if(tokencount > 1){ name.getLeadingSegments(),
List tokens = new ArrayList(); references,
String oneToken = ""; //$NON-NLS-1$ false,
// This is NOT a function. This is a method definition LookupType.FORPARENTSCOPE );
while (tokenizer.hasMoreTokens()){ IContainerSymbol parentScope = null;
oneToken = tokenizer.nextToken();
tokens.add(oneToken);
}
String fieldName = oneToken; if( symbol instanceof IContainerSymbol )
parentScope = (IContainerSymbol) symbol;
else if( symbol instanceof IDeferredTemplateInstance )
parentScope = ((IDeferredTemplateInstance) symbol).getTemplate().getTemplatedSymbol();
int numOfTokens = 1; if( (parentScope != null) && ( (parentScope.getType() == TypeInfo.t_class) ||
int offset = nameOffset; (parentScope.getType() == TypeInfo.t_struct)||
IContainerSymbol parentScope = ownerScope; (parentScope.getType() == TypeInfo.t_union) ) )
Iterator i = tokens.iterator(); {
while (i.hasNext() && (numOfTokens++) < tokens.size()){
String token = (String) i.next();
IContainerSymbol parentSymbol = null;
try {
parentSymbol = parentScope.lookupNestedNameSpecifier( token );
if( parentSymbol != null )
addReference( references, createReference( parentSymbol, name, offset ));
} catch (ParserSymbolTableException e1) {
//do nothing
}
if(parentSymbol == null)
break;
else {
parentScope = parentSymbol;
offset += token.length()+ DOUBLE_COLON.length();
}
}
if((parentScope != null) &&
( (parentScope.getType() == TypeInfo.t_class)
|| (parentScope.getType() == TypeInfo.t_struct)
|| (parentScope.getType() == TypeInfo.t_union))
){
IASTScope fieldParentScope = (IASTScope)parentScope.getASTExtension().getPrimaryDeclaration(); IASTScope fieldParentScope = (IASTScope)parentScope.getASTExtension().getPrimaryDeclaration();
return createField(fieldParentScope, fieldName,isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern,
isRegister, isStatic, startingOffset, startingLine, offset, nameEndOffset, nameLine, constructorExpression, ASTAccessVisibility.PRIVATE, references); ITokenDuple newName = name.getLastSegment();
return createField(fieldParentScope, newName,isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern,
isRegister, isStatic, startingOffset, startingLine, newName.getStartOffset(), nameEndOffset, nameLine, constructorExpression, ASTAccessVisibility.PRIVATE, references);
} }
} }
ISymbol newSymbol = cloneSimpleTypeSymbol(name, abstractDeclaration, references); ISymbol newSymbol = cloneSimpleTypeSymbol(name.getFirstToken().getImage(), abstractDeclaration, references);
if( newSymbol == null ) if( newSymbol == null )
handleProblem( IProblem.SEMANTICS_RELATED, name ); handleProblem( IProblem.SEMANTICS_RELATED, name.toString() );
setVariableTypeInfoBits( setVariableTypeInfoBits(
isAuto, isAuto,
@ -2354,7 +2340,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
newSymbol.setIsForwardDeclaration(isStatic); newSymbol.setIsForwardDeclaration(isStatic);
boolean previouslyDeclared = false; boolean previouslyDeclared = false;
if(!isStatic){ if(!isStatic){
ISymbol variableDeclaration = lookupQualifiedName(ownerScope, name, new ArrayList(), false, LookupType.UNQUALIFIED); ISymbol variableDeclaration = lookupQualifiedName(ownerScope, name.toString(), new ArrayList(), false, LookupType.UNQUALIFIED);
if( variableDeclaration != null ) if( variableDeclaration != null )
{ {
@ -2368,7 +2354,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
catch (ParserSymbolTableException e) catch (ParserSymbolTableException e)
{ {
handleProblem(e.createProblemID(), name ); handleProblem(e.createProblemID(), name.getFirstToken().getImage() );
} }
ASTVariable variable = new ASTVariable( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, references, constructorExpression, previouslyDeclared ); ASTVariable variable = new ASTVariable( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, references, constructorExpression, previouslyDeclared );
@ -2497,8 +2483,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
symbolToBeCloned = pst.newSymbol( name, TypeInfo.t_type ); symbolToBeCloned = pst.newSymbol( name, TypeInfo.t_type );
symbolToBeCloned.setTypeSymbol(((ASTEnumerationSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol()); symbolToBeCloned.setTypeSymbol(((ASTEnumerationSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol());
} }
newSymbol = (ISymbol) symbolToBeCloned.clone(); if( symbolToBeCloned != null ){
newSymbol.setName( name ); newSymbol = (ISymbol) symbolToBeCloned.clone();
newSymbol.setName( name );
}
return newSymbol; return newSymbol;
} }
@ -2507,7 +2495,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
*/ */
public IASTField createField( public IASTField createField(
IASTScope scope, IASTScope scope,
String name, ITokenDuple name,
boolean isAuto, boolean isAuto,
IASTInitializerClause initializerClause, IASTInitializerClause initializerClause,
IASTExpression bitfieldExpression, IASTExpression bitfieldExpression,
@ -2526,7 +2514,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
public IASTField createField( public IASTField createField(
IASTScope scope, IASTScope scope,
String name, ITokenDuple name,
boolean isAuto, boolean isAuto,
IASTInitializerClause initializerClause, IASTInitializerClause initializerClause,
IASTExpression bitfieldExpression, IASTExpression bitfieldExpression,
@ -2546,9 +2534,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if(references == null) if(references == null)
references = new ArrayList(); references = new ArrayList();
ISymbol newSymbol = cloneSimpleTypeSymbol(name, abstractDeclaration, references); ISymbol newSymbol = cloneSimpleTypeSymbol(name.toString(), abstractDeclaration, references);
if( newSymbol == null ) if( newSymbol == null )
handleProblem( IProblem.SEMANTICS_RELATED, name ); handleProblem( IProblem.SEMANTICS_RELATED, name.toString() );
setVariableTypeInfoBits( setVariableTypeInfoBits(
@ -2565,7 +2553,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean previouslyDeclared = false; boolean previouslyDeclared = false;
if(!isStatic){ if(!isStatic){
List fieldReferences = new ArrayList(); List fieldReferences = new ArrayList();
ISymbol fieldDeclaration = lookupQualifiedName(ownerScope, name, fieldReferences, false, LookupType.FORDEFINITION); ISymbol fieldDeclaration = lookupQualifiedName(ownerScope, name.toString(), fieldReferences, false, LookupType.FORDEFINITION);
if( fieldDeclaration != null ) if( fieldDeclaration != null )
{ {
@ -2583,7 +2571,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
catch (ParserSymbolTableException e) catch (ParserSymbolTableException e)
{ {
handleProblem(e.createProblemID(), name ); handleProblem(e.createProblemID(), name.toString() );
} }
ASTField field = new ASTField( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, references, previouslyDeclared, constructorExpression, visibility ); ASTField field = new ASTField( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, references, previouslyDeclared, constructorExpression, visibility );
@ -2734,32 +2722,31 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
IContainerSymbol currentScopeSymbol = scopeToSymbol(scope); IContainerSymbol currentScopeSymbol = scopeToSymbol(scope);
TypeInfo.eType pstType = classKindToTypeInfo(kind); TypeInfo.eType pstType = classKindToTypeInfo(kind);
List references = new ArrayList(); List references = new ArrayList();
IToken lastToken = name.getLastToken();
IToken nameToken = name.getFirstToken();
String newSymbolName = ""; //$NON-NLS-1$ String newSymbolName = ""; //$NON-NLS-1$
List templateIdArgList = null; List templateIdArgList = null;
boolean isTemplateId = false; boolean isTemplateId = false;
if( name.length() != 1 ) // qualified name if( name.getSegmentCount() != 1 ) // qualified name
{ {
int idx = name.findLastTokenType( IToken.tCOLONCOLON ); ITokenDuple containerSymbolName = name.getLeadingSegments();
if( idx != -1 ){ currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, containerSymbolName, references, true);
ITokenDuple containerSymbolName = name.getSubrange( 0, idx - 1 ); if( currentScopeSymbol == null )
currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, containerSymbolName, references, true); handleProblem( IProblem.SEMANTIC_NAME_NOT_FOUND, containerSymbolName.toString(), containerSymbolName.getFirstToken().getOffset(), containerSymbolName.getLastToken().getEndOffset(), containerSymbolName.getLastToken().getLineNumber() );
if( currentScopeSymbol == null )
handleProblem( IProblem.SEMANTIC_NAME_NOT_FOUND, containerSymbolName.toString(), containerSymbolName.getFirstToken().getOffset(), containerSymbolName.getLastToken().getEndOffset(), containerSymbolName.getLastToken().getLineNumber() );
}
//template-id nameToken = name.getLastSegment().getFirstToken();
List [] array = name.getTemplateIdArgLists();
if( array != null ){
isTemplateId = true;
templateIdArgList = array[ array.length - 1 ];
lastToken = name.getToken( idx + 1);
}
} }
newSymbolName = lastToken.getImage(); //template-id
List [] array = name.getTemplateIdArgLists();
if( array != null ){
isTemplateId = true;
templateIdArgList = array[ array.length - 1 ];
}
newSymbolName = nameToken.getImage();
ISymbol checkSymbol = null; ISymbol checkSymbol = null;
if( !isTemplateId ){ if( !isTemplateId ){
@ -2773,7 +2760,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
catch (ParserSymbolTableException e) catch (ParserSymbolTableException e)
{ {
handleProblem(e.createProblemID(),lastToken.getImage(), lastToken.getOffset(), lastToken.getEndOffset(), lastToken.getLineNumber() ); handleProblem(e.createProblemID(),nameToken.getImage(), nameToken.getOffset(), nameToken.getEndOffset(), nameToken.getLineNumber() );
} }
} }
@ -2802,7 +2789,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
catch (ParserSymbolTableException e1) catch (ParserSymbolTableException e1)
{ {
handleProblem(e1.createProblemID(),lastToken.getImage(), lastToken.getOffset(), lastToken.getEndOffset(), lastToken.getLineNumber() ); handleProblem(e1.createProblemID(),nameToken.getImage(), nameToken.getOffset(), nameToken.getEndOffset(), nameToken.getLineNumber() );
} }
ASTElaboratedTypeSpecifier elab = ASTElaboratedTypeSpecifier elab =
@ -2827,7 +2814,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTElaboratedTypeSpecifier ) if( checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTElaboratedTypeSpecifier )
return (IASTElaboratedTypeSpecifier)checkSymbol.getASTExtension().getPrimaryDeclaration(); return (IASTElaboratedTypeSpecifier)checkSymbol.getASTExtension().getPrimaryDeclaration();
} else { } else {
handleProblem(IProblem.SEMANTIC_NAME_NOT_FOUND, newSymbolName, lastToken.getOffset(), lastToken.getEndOffset(), lastToken.getLineNumber() ); handleProblem(IProblem.SEMANTIC_NAME_NOT_FOUND, newSymbolName, nameToken.getOffset(), nameToken.getEndOffset(), nameToken.getLineNumber() );
} }

View file

@ -625,7 +625,7 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
*/ */
public IASTVariable createVariable( public IASTVariable createVariable(
IASTScope scope, IASTScope scope,
String name, ITokenDuple name,
boolean isAuto, boolean isAuto,
IASTInitializerClause initializerClause, IASTInitializerClause initializerClause,
IASTExpression bitfieldExpression, IASTExpression bitfieldExpression,
@ -659,7 +659,7 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
*/ */
public IASTField createField( public IASTField createField(
IASTScope scope, IASTScope scope,
String name, ITokenDuple name,
boolean isAuto, boolean isAuto,
IASTInitializerClause initializerClause, IASTInitializerClause initializerClause,
IASTExpression bitfieldExpression, IASTExpression bitfieldExpression,

View file

@ -232,17 +232,17 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createVariable(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, boolean, org.eclipse.cdt.core.parser.ast.IASTInitializerClause, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean, boolean, boolean, boolean) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createVariable(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, boolean, org.eclipse.cdt.core.parser.ast.IASTInitializerClause, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean, boolean, boolean, boolean)
*/ */
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 startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression) public IASTVariable createVariable(IASTScope scope, ITokenDuple name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression)
{ {
return new ASTVariable(scope, name, isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern, isRegister, isStatic, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, constructorExpression); return new ASTVariable(scope, ( name != null ? name.toString() : "" ), isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern, isRegister, isStatic, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, constructorExpression); //$NON-NLS-1$
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createField(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, boolean, org.eclipse.cdt.core.parser.ast.IASTInitializerClause, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean, boolean, boolean, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createField(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, boolean, org.eclipse.cdt.core.parser.ast.IASTInitializerClause, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean, boolean, boolean, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility)
*/ */
public IASTField createField(IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, ASTAccessVisibility visibility) public IASTField createField(IASTScope scope, ITokenDuple name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, ASTAccessVisibility visibility)
{ {
return new ASTField(scope, name, isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern, isRegister, isStatic, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, constructorExpression, visibility); return new ASTField(scope, ( name != null ? name.toString() : "" ), isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern, isRegister, isStatic, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, constructorExpression, visibility); //$NON-NLS-1$
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -201,7 +201,10 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError );
} }
boolean validOverride = ((origList == null) ? ParserSymbolTable.isValidOverload( origDecl, obj ) : ParserSymbolTable.isValidOverload( origList, obj ) ); boolean validOverride = ( !unnamed ? ( (origList == null) ? ParserSymbolTable.isValidOverload( origDecl, obj )
: ParserSymbolTable.isValidOverload( origList, obj ) )
: true );
if( unnamed || validOverride ) if( unnamed || validOverride )
{ {
if( origList == null ){ if( origList == null ){

View file

@ -770,7 +770,7 @@ public class ParserSymbolTable {
if( origType == TypeInfo.t_template ){ if( origType == TypeInfo.t_template ){
ITemplateSymbol template = (ITemplateSymbol) origSymbol; ITemplateSymbol template = (ITemplateSymbol) origSymbol;
origSymbol = (ISymbol) template.getContainedSymbols().get( template.getName() ); origSymbol = (ISymbol) template.getTemplatedSymbol();
if( origSymbol == null ) if( origSymbol == null )
return true; return true;
else else
@ -779,7 +779,7 @@ public class ParserSymbolTable {
if( newType == TypeInfo.t_template ){ if( newType == TypeInfo.t_template ){
ITemplateSymbol template = (ITemplateSymbol) newSymbol; ITemplateSymbol template = (ITemplateSymbol) newSymbol;
newSymbol = (ISymbol) template.getContainedSymbols().get( template.getName() ); newSymbol = (ISymbol) template.getTemplatedSymbol();
if( newSymbol == null ) if( newSymbol == null )
return true; return true;
else else

View file

@ -309,7 +309,7 @@ public final class TemplateEngine {
* @param aInfo * @param aInfo
* @return * @return
*/ */
static private TypeInfo getArgumentTypeForDeduction( TypeInfo aInfo, boolean pIsAReferenceType ){ static private TypeInfo getArgumentTypeForDeduction( TypeInfo aInfo, boolean pIsAReferenceType ) throws ParserSymbolTableException{
TypeInfo a = ParserSymbolTable.getFlatTypeInfo( aInfo ); TypeInfo a = ParserSymbolTable.getFlatTypeInfo( aInfo );
@ -317,8 +317,10 @@ public final class TemplateEngine {
List aPtrs = a.getPtrOperators(); List aPtrs = a.getPtrOperators();
ISymbol aSymbol = a.getTypeSymbol(); ISymbol aSymbol = a.getTypeSymbol();
if( a.getType() == TypeInfo.t_type && aSymbol.isType( TypeInfo.t_function ) ){ if( a.getType() == TypeInfo.t_type ){
if( aPtrs.size() == 0 ){ if( aSymbol == null ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument );
} else if( aSymbol.isType( TypeInfo.t_function ) && aPtrs.size() == 0 ){
aPtrs.add( new PtrOp( PtrOp.t_pointer ) ); aPtrs.add( new PtrOp( PtrOp.t_pointer ) );
} }
} }
@ -420,7 +422,7 @@ public final class TemplateEngine {
return aSymbol; return aSymbol;
} }
static private boolean deduceTemplateArgument( Map map, ISymbol pSymbol, TypeInfo a ){//, Map argumentMap ){ static private boolean deduceTemplateArgument( Map map, ISymbol pSymbol, TypeInfo a ) throws ParserSymbolTableException{//, Map argumentMap ){
ISymbol symbol; ISymbol symbol;
boolean pIsAReferenceType = false; boolean pIsAReferenceType = false;
@ -613,7 +615,11 @@ public final class TemplateEngine {
TypeInfo arg = transformTypeInfo( aIter.next(), null ); TypeInfo arg = transformTypeInfo( aIter.next(), null );
if( !deduceTemplateArgument( map, sym, arg ) ){ try {
if( !deduceTemplateArgument( map, sym, arg ) ){
return false;
}
} catch (ParserSymbolTableException e) {
return false; return false;
} }
} }
@ -677,7 +683,11 @@ public final class TemplateEngine {
Iterator aIter = arguments.iterator(); Iterator aIter = arguments.iterator();
while( pIter.hasNext() ){ while( pIter.hasNext() ){
if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), (TypeInfo) aIter.next() ) ){ try {
if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), (TypeInfo) aIter.next() ) ){
return null;
}
} catch (ParserSymbolTableException e) {
return null; return null;
} }
} }

View file

@ -96,7 +96,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
} }
public void addSymbol(ISymbol symbol) throws ParserSymbolTableException { public void addSymbol(ISymbol symbol) throws ParserSymbolTableException {
lastSymbol = (IContainerSymbol) (( symbols.size() > 0 ) ? symbols.get( symbols.size() - 1) : null); lastSymbol = getLastSymbol();
Iterator iter = symbols.iterator(); Iterator iter = symbols.iterator();
ListIterator tIter = templates.listIterator(); ListIterator tIter = templates.listIterator();
@ -281,14 +281,27 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
// } // }
} }
private IContainerSymbol getLastSymbol() {
if( lastSymbol != null )
return lastSymbol;
else if( !symbols.isEmpty() ) {
ISymbol symbol = (ISymbol) symbols.get( symbols.size() - 1 );
if( symbol instanceof IDeferredTemplateInstance )
return ((IDeferredTemplateInstance)symbol).getTemplate().getTemplatedSymbol();
else if( symbol instanceof IContainerSymbol )
return (IContainerSymbol) symbol;
}
return null;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory#lookupMemberForDefinition(java.lang.String) * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory#lookupMemberForDefinition(java.lang.String)
*/ */
public ISymbol lookupMemberForDefinition(String name) throws ParserSymbolTableException { public ISymbol lookupMemberForDefinition(String name) throws ParserSymbolTableException {
ISymbol look = null; ISymbol look = null;
if( lastSymbol != null || !symbols.isEmpty() ){ IContainerSymbol last = getLastSymbol();
IContainerSymbol symbol = (lastSymbol != null ) ? lastSymbol : (IContainerSymbol) symbols.get( symbols.size() - 1 ); if( last != null ){
look = ((IContainerSymbol)symbol).lookupMemberForDefinition( name ); look = last.lookupMemberForDefinition( name );
} else { } else {
look = getContainingSymbol().lookupMemberForDefinition( name ); look = getContainingSymbol().lookupMemberForDefinition( name );
} }
@ -401,9 +414,9 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupMethodForDefinition(java.lang.String, java.util.List) * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupMethodForDefinition(java.lang.String, java.util.List)
*/ */
public IParameterizedSymbol lookupMethodForDefinition(String name, List parameters) throws ParserSymbolTableException { public IParameterizedSymbol lookupMethodForDefinition(String name, List parameters) throws ParserSymbolTableException {
if( lastSymbol != null || !symbols.isEmpty() ){ IContainerSymbol last = getLastSymbol();
IContainerSymbol symbol = (lastSymbol != null ) ? lastSymbol : (IContainerSymbol) symbols.get( symbols.size() - 1 ); if( last != null ){
IParameterizedSymbol found = ((IContainerSymbol)symbol).lookupMethodForDefinition( name, parameters ); IParameterizedSymbol found = last.lookupMethodForDefinition( name, parameters );
if( found != null ){ if( found != null ){
return found; return found;
} }
@ -458,9 +471,9 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
*/ */
public ISymbol lookupTemplateId(String name, List arguments) throws ParserSymbolTableException { public ISymbol lookupTemplateId(String name, List arguments) throws ParserSymbolTableException {
ISymbol look = null; ISymbol look = null;
if( lastSymbol != null || !symbols.isEmpty() ){ IContainerSymbol last = getLastSymbol();
IContainerSymbol symbol = (lastSymbol != null ) ? lastSymbol : (IContainerSymbol) symbols.get( symbols.size() - 1 ); if( last != null ){
look = ((IContainerSymbol)symbol).lookupTemplateId( name, arguments ); look = last.lookupTemplateId( name, arguments );
} else { } else {
look = getContainingSymbol().lookupTemplateId( name, arguments ); look = getContainingSymbol().lookupTemplateId( name, arguments );
} }
@ -469,9 +482,9 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
public IContainerSymbol lookupTemplateIdForDefinition(String name, List arguments) throws ParserSymbolTableException { public IContainerSymbol lookupTemplateIdForDefinition(String name, List arguments) throws ParserSymbolTableException {
ISymbol look = null; ISymbol look = null;
if( lastSymbol != null || !symbols.isEmpty() ){ IContainerSymbol last = getLastSymbol();
IContainerSymbol symbol = (lastSymbol != null ) ? lastSymbol : (IContainerSymbol) symbols.get( symbols.size() - 1 ); if( last != null ){
look = ((IContainerSymbol)symbol).lookupMemberForDefinition( name ); look = last.lookupMemberForDefinition( name );
} else { } else {
look = getContainingSymbol().lookupMemberForDefinition( name ); look = getContainingSymbol().lookupMemberForDefinition( name );
} }
@ -772,15 +785,17 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#lookupConstructor(java.util.List) * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#lookupConstructor(java.util.List)
*/ */
public IParameterizedSymbol lookupConstructor(List parameters) throws ParserSymbolTableException { public IParameterizedSymbol lookupConstructor(List parameters) throws ParserSymbolTableException {
if( lastSymbol != null || !symbols.isEmpty() ){ IContainerSymbol last = getLastSymbol();
IContainerSymbol symbol = (lastSymbol != null ) ? lastSymbol : (IContainerSymbol) symbols.get( symbols.size() - 1 ); if( last != null && last instanceof IDerivableContainerSymbol ){
if( symbol instanceof IDerivableContainerSymbol ){ IDerivableContainerSymbol derivable = (IDerivableContainerSymbol) last;
IParameterizedSymbol found = ((IDerivableContainerSymbol)symbol).lookupConstructor( parameters ); IParameterizedSymbol found = derivable.lookupConstructor( parameters );
if( found != null ) if( found != null )
return found; return found;
}
} }
return ((IDerivableContainerSymbol) getContainingSymbol()).lookupConstructor( parameters ); if( getContainingSymbol() instanceof IDerivableContainerSymbol )
return ((IDerivableContainerSymbol) getContainingSymbol()).lookupConstructor( parameters );
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -487,7 +487,10 @@ public class TypeInfo {
IParameterizedSymbol f2 = (IParameterizedSymbol) type._typeDeclaration; IParameterizedSymbol f2 = (IParameterizedSymbol) type._typeDeclaration;
result &= f1.hasSameParameters( f2 ); result &= f1.hasSameParameters( f2 );
result &= f1.getReturnType().getTypeInfo().equals( f2.getReturnType().getTypeInfo() ); if( f1.getReturnType() != null && f2.getReturnType() != null )
result &= f1.getReturnType().getTypeInfo().equals( f2.getReturnType().getTypeInfo() );
else
result &= (f1.getReturnType() == f2.getReturnType());
} else if( _typeDeclaration.isType( TypeInfo.t_templateParameter ) && } else if( _typeDeclaration.isType( TypeInfo.t_templateParameter ) &&
type._typeDeclaration.isType( TypeInfo.t_templateParameter ) ){ type._typeDeclaration.isType( TypeInfo.t_templateParameter ) ){
//template parameters //template parameters

View file

@ -10,7 +10,9 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.token; package org.eclipse.cdt.internal.core.parser.token;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -45,8 +47,31 @@ public class TokenDuple implements ITokenDuple {
} }
} }
public TokenDuple( ITokenDuple firstDuple, ITokenDuple secondDuple ){
firstToken = firstDuple.getFirstToken();
lastToken = secondDuple.getLastToken();
List [] a1 = firstDuple.getTemplateIdArgLists();
List [] a2 = secondDuple.getTemplateIdArgLists();
if( a1 == null && a2 == null ){
argLists = null;
} else {
int l1 = ( a1 != null ) ? a1.length : firstDuple.getSegmentCount();
int l2 = ( a2 != null ) ? a2.length : firstDuple.getSegmentCount();
argLists = new List[ l1 + l2 ];
if( a1 != null )
System.arraycopy( a1, 0, argLists, 0, l1 );
if( a2 != null )
System.arraycopy( a2, 0, argLists, l1, l2 );
}
}
protected final IToken firstToken, lastToken; protected final IToken firstToken, lastToken;
protected final List [] argLists; protected final List [] argLists;
private int numSegments = -1;
/** /**
* @return * @return
*/ */
@ -66,6 +91,153 @@ public class TokenDuple implements ITokenDuple {
return new TokenIterator(); return new TokenIterator();
} }
public ITokenDuple getLastSegment() {
Iterator iter = iterator();
if( !iter.hasNext() )
return null;
IToken first = null, last = null, token = null;
while( iter.hasNext() ){
token = (IToken) iter.next();
if( first == null )
first = token;
if( token.getType() == IToken.tLT )
token = consumeTemplateIdArguments( token, iter );
else if( token.getType() == IToken.tCOLONCOLON ){
first = null;
continue;
}
last = token;
}
List [] args = getTemplateIdArgLists();
if( args != null && args[ args.length - 1 ] != null ){
List newArgs = new ArrayList( 1 );
newArgs.add( args[ args.length - 1 ] );
return new TokenDuple( first, last, newArgs );
} else {
return new TokenDuple( first, last );
}
}
public ITokenDuple getLeadingSegments(){
Iterator iter = iterator();
if( !iter.hasNext() )
return null;
int num = getSegmentCount();
if( num <= 1 )
return null;
IToken first = null, last = null;
IToken previous = null, token = null;
while( iter.hasNext() ){
token = (IToken) iter.next();
if( first == null )
first = token;
if( token.getType() == IToken.tLT )
token = consumeTemplateIdArguments( token, iter );
else if( token.getType() == IToken.tCOLONCOLON ){
last = previous;
continue;
}
previous = token;
}
if( last == null ){
//"::A"
return null;
}
if( getTemplateIdArgLists() != null ){
List[] args = getTemplateIdArgLists();
List newArgs = new ArrayList( args.length - 1 );
boolean foundArgs = false;
for( int i = 0; i < args.length - 1; i++ ){
newArgs.add( args[i] );
if( args[i] != null )
foundArgs = true;
}
return new TokenDuple( first, last, ( foundArgs ? newArgs : null ) );
} else {
return new TokenDuple( first, last );
}
}
public int getSegmentCount()
{
if( numSegments > -1 )
return numSegments;
numSegments = 1;
if( firstToken == lastToken )
return numSegments;
Iterator iter = iterator();
IToken token = null;
while( iter.hasNext() ){
token = (IToken) iter.next();
if( token.getType() == IToken.tLT )
token = consumeTemplateIdArguments( token, iter );
if( token.getType() == IToken.tCOLONCOLON ){
numSegments++;
continue;
}
}
return numSegments;
}
private static final Integer LT = new Integer( IToken.tLT );
private static final Integer LBRACKET = new Integer( IToken.tLBRACKET );
private static final Integer LPAREN = new Integer( IToken.tLPAREN );
public IToken consumeTemplateIdArguments( IToken name, Iterator iter ){
IToken token = name;
if( token.getType() == IToken.tLT )
{
if( ! iter.hasNext() )
return token;
token = (IToken) iter.next();
LinkedList scopes = new LinkedList();
scopes.add( LT );
while (!scopes.isEmpty() && iter.hasNext() )
{
Integer top;
token = (IToken) iter.next();
switch( token.getType() ){
case IToken.tGT:
if( scopes.getLast() == LT ) {
scopes.removeLast();
}
break;
case IToken.tRBRACKET :
do {
top = (Integer)scopes.removeLast();
} while (!scopes.isEmpty() && top == LT);
break;
case IToken.tRPAREN :
do {
top = (Integer)scopes.removeLast();
} while (!scopes.isEmpty() && top == LT);
break;
case IToken.tLT: scopes.add( LT ); break;
case IToken.tLBRACKET: scopes.add( LBRACKET ); break;
case IToken.tLPAREN: scopes.add( LPAREN ); break;
}
}
}
return token;
}
private class TokenIterator implements Iterator private class TokenIterator implements Iterator
{ {
private IToken iter = TokenDuple.this.firstToken; private IToken iter = TokenDuple.this.firstToken;