1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Enhanced the performance & footprint of the parser by reducing number of lists created and getting rid of extraneous cross-reference construction in ParserMode's that do not warrant it.

This commit is contained in:
John Camelon 2004-05-14 19:26:59 +00:00
parent 35b475be54
commit bab1a0f7cf
26 changed files with 123 additions and 148 deletions

View file

@ -277,11 +277,5 @@ public interface IASTFactory
*/ */
public boolean validateDirectMemberOperation(IASTNode node); public boolean validateDirectMemberOperation(IASTNode node);
/**
* @param ourScope
* @param newDescriptor TODO
* @return
*/
public IASTNode lookupConstructor(IASTScope ourScope, IASTNewExpressionDescriptor newDescriptor);
} }

View file

@ -75,7 +75,6 @@ import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
*/ */
public abstract class Parser extends ExpressionParser implements IParser public abstract class Parser extends ExpressionParser implements IParser
{ {
protected static final List EMPTY_LIST = Collections.unmodifiableList(new ArrayList());
protected ISourceElementRequestor requestor = null; protected ISourceElementRequestor requestor = null;
/** /**
@ -1880,7 +1879,7 @@ public abstract class Parser extends ExpressionParser implements IParser
consume( IToken.tASSIGN ); consume( IToken.tASSIGN );
simpleDeclarationMark = null; simpleDeclarationMark = null;
setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY); setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY);
d.setInitializerClause( cInitializerClause(scope, EMPTY_LIST, constructInitializers ) ); d.setInitializerClause( cInitializerClause(scope, Collections.EMPTY_LIST, constructInitializers ) );
setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY); setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY);
} }
} }
@ -1979,7 +1978,7 @@ public abstract class Parser extends ExpressionParser implements IParser
return createInitializerClause( return createInitializerClause(
scope, scope,
IASTInitializerClause.Kind.EMPTY, IASTInitializerClause.Kind.EMPTY,
null, null, EMPTY_LIST, constructInitializers ); null, null, Collections.EMPTY_LIST, constructInitializers );
} }
catch (Exception e) catch (Exception e)
{ {
@ -2009,7 +2008,7 @@ public abstract class Parser extends ExpressionParser implements IParser
return createInitializerClause( return createInitializerClause(
scope, scope,
IASTInitializerClause.Kind.INITIALIZER_LIST, IASTInitializerClause.Kind.INITIALIZER_LIST,
null, initializerClauses == null ? EMPTY_LIST : initializerClauses, EMPTY_LIST, constructInitializers ); null, initializerClauses == null ? Collections.EMPTY_LIST : initializerClauses, Collections.EMPTY_LIST, constructInitializers );
} }
catch (Exception e) catch (Exception e)
{ {
@ -2031,7 +2030,7 @@ public abstract class Parser extends ExpressionParser implements IParser
return createInitializerClause( return createInitializerClause(
scope, scope,
IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION, IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION,
assignmentExpression, null, EMPTY_LIST, constructInitializers ); assignmentExpression, null, Collections.EMPTY_LIST, constructInitializers );
} }
catch (Exception e) catch (Exception e)
{ {

View file

@ -10,9 +10,8 @@
package org.eclipse.cdt.internal.core.parser.ast; package org.eclipse.cdt.internal.core.parser.ast;
import java.util.ArrayList; import java.util.Collections;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
@ -49,7 +48,6 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
public class GCCASTExtension implements IASTFactoryExtension { public class GCCASTExtension implements IASTFactoryExtension {
private final ParserMode mode; private final ParserMode mode;
private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final List EMPTY_LIST = new ArrayList( 0 );
/** /**
* @param mode * @param mode
*/ */
@ -167,7 +165,7 @@ public class GCCASTExtension implements IASTFactoryExtension {
ASTExpression typeOfExpression = (ASTExpression) extensionParms.get( IASTGCCSimpleTypeSpecifier.TYPEOF_EXRESSION ); ASTExpression typeOfExpression = (ASTExpression) extensionParms.get( IASTGCCSimpleTypeSpecifier.TYPEOF_EXRESSION );
ISymbol s = pst.newSymbol( EMPTY_STRING ); ISymbol s = pst.newSymbol( EMPTY_STRING );
s.setTypeInfo( typeOfExpression.getResultType().getResult() ); s.setTypeInfo( typeOfExpression.getResultType().getResult() );
return new ASTGCCSimpleTypeSpecifier( s, isTypename, ( typeName == null ? EMPTY_STRING : typeName.toString()), EMPTY_LIST, typeOfExpression ); return new ASTGCCSimpleTypeSpecifier( s, isTypename, ( typeName == null ? EMPTY_STRING : typeName.toString()), Collections.EMPTY_LIST, typeOfExpression );
} }
return null; return null;
} }

View file

@ -24,7 +24,7 @@ import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
*/ */
public class ASTBaseSpecifier implements IASTBaseSpecifier public class ASTBaseSpecifier implements IASTBaseSpecifier
{ {
private ASTReferenceStore referenceDelegate; private List references;
private final boolean isVirtual; private final boolean isVirtual;
private final ISymbol symbol; private final ISymbol symbol;
private final ASTAccessVisibility visibility; private final ASTAccessVisibility visibility;
@ -40,7 +40,7 @@ public class ASTBaseSpecifier implements IASTBaseSpecifier
this.visibility = visibility; this.visibility = visibility;
this.symbol = symbol; this.symbol = symbol;
this.offset = nameOffset; this.offset = nameOffset;
referenceDelegate = new ASTReferenceStore( references ); this.references = references;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -81,20 +81,14 @@ public class ASTBaseSpecifier implements IASTBaseSpecifier
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTReferenceStore#processReferences()
*/
public void processReferences(ISourceElementRequestor requestor)
{
referenceDelegate.processReferences(requestor);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/ */
public void acceptElement(ISourceElementRequestor requestor) public void acceptElement(ISourceElementRequestor requestor)
{ {
referenceDelegate.processReferences(requestor); ASTReferenceStore.processReferences( references, requestor );
references = null;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -89,7 +89,7 @@ public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier
private final ASTClassKind classKind; private final ASTClassKind classKind;
private ASTAccessVisibility currentVisibility; private ASTAccessVisibility currentVisibility;
private final ASTQualifiedNamedElement qualifiedName; private final ASTQualifiedNamedElement qualifiedName;
private final ASTReferenceStore references; private List references;
/** /**
* @param symbol * @param symbol
@ -104,7 +104,7 @@ public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier
setNameOffset(nameOffset); setNameOffset(nameOffset);
setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); setNameEndOffsetAndLineNumber(nameEndOffset, nameLine);
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() ); qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() );
this.references = new ASTReferenceStore( references ); this.references = references;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getClassNameType() * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getClassNameType()
@ -174,7 +174,8 @@ public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier
*/ */
public void enterScope(ISourceElementRequestor requestor) public void enterScope(ISourceElementRequestor requestor)
{ {
references.processReferences( requestor ); ASTReferenceStore.processReferences( references, requestor );
references = null;
try try
{ {
requestor.enterClassSpecifier(this); requestor.enterClassSpecifier(this);

View file

@ -27,7 +27,7 @@ public class ASTConstructorMemberInitializer
private final boolean requireNameResolution; private final boolean requireNameResolution;
private final String name; private final String name;
private final IASTExpression expression; private final IASTExpression expression;
private final List references; private List references;
/** /**
* *
*/ */
@ -58,8 +58,8 @@ public class ASTConstructorMemberInitializer
*/ */
public void acceptElement(ISourceElementRequestor requestor) public void acceptElement(ISourceElementRequestor requestor)
{ {
ASTReferenceStore store = new ASTReferenceStore( references ); ASTReferenceStore.processReferences( references, requestor );
store.processReferences( requestor ); references = null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)

View file

@ -30,7 +30,6 @@ public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElabora
private final ASTClassKind kind; private final ASTClassKind kind;
private final ASTQualifiedNamedElement qualifiedName; private final ASTQualifiedNamedElement qualifiedName;
private NamedOffsets offsets = new NamedOffsets(); private NamedOffsets offsets = new NamedOffsets();
private final ASTReferenceStore store;
/** /**
* @param checkSymbol * @param checkSymbol
@ -47,7 +46,6 @@ public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElabora
setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); setNameEndOffsetAndLineNumber(nameEndOffset, nameLine);
setEndingOffsetAndLineNumber( endOffset, endingLine ); setEndingOffsetAndLineNumber( endOffset, endingLine );
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), checkSymbol.getName() ); qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), checkSymbol.getName() );
store = new ASTReferenceStore( references );
isForwardDeclaration = isDecl; isForwardDeclaration = isDecl;
this.references = references; this.references = references;
} }
@ -114,7 +112,8 @@ public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElabora
{ {
/* do nothing */ /* do nothing */
} }
store.processReferences(requestor); ASTReferenceStore.processReferences( references, requestor );
references = null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)

View file

@ -24,7 +24,7 @@ import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
public class ASTExceptionSpecification implements IASTExceptionSpecification public class ASTExceptionSpecification implements IASTExceptionSpecification
{ {
private final List typeIds; private final List typeIds;
private final ASTReferenceStore store; private List references;
/** /**
* @param newTypeIds * @param newTypeIds
* @param references * @param references
@ -32,7 +32,7 @@ public class ASTExceptionSpecification implements IASTExceptionSpecification
public ASTExceptionSpecification(List newTypeIds, List references) public ASTExceptionSpecification(List newTypeIds, List references)
{ {
this.typeIds = newTypeIds; this.typeIds = newTypeIds;
store = new ASTReferenceStore( references ); this.references = references;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -49,7 +49,8 @@ public class ASTExceptionSpecification implements IASTExceptionSpecification
*/ */
public void acceptElement(ISourceElementRequestor requestor) public void acceptElement(ISourceElementRequestor requestor)
{ {
store.processReferences(requestor); ASTReferenceStore.processReferences( references, requestor );
references = null;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -31,7 +31,7 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
public abstract class ASTExpression extends ASTNode implements IASTExpression public abstract class ASTExpression extends ASTNode implements IASTExpression
{ {
private final Kind kind; private final Kind kind;
private final List references; private List references;
private ExpressionResult resultType; private ExpressionResult resultType;
/** /**
@ -75,9 +75,9 @@ public abstract class ASTExpression extends ASTNode implements IASTExpression
{ {
// will not get thrown // will not get thrown
} }
if( ! references.isEmpty() ) ASTReferenceStore.processReferences( references, requestor );
new ASTReferenceStore( references ).processReferences(requestor); references = null;
processCallbacks(requestor); processCallbacks(requestor);
try try

View file

@ -61,7 +61,9 @@ public class ASTField extends ASTVariable implements IASTField
{ {
/* do nothing */ /* do nothing */
} }
referenceDelegate.processReferences(requestor); ASTReferenceStore.processReferences(references, requestor);
references = null;
if( getInitializerClause() != null ) if( getInitializerClause() != null )
getInitializerClause().acceptElement(requestor); getInitializerClause().acceptElement(requestor);
if( getAbstractDeclaration() != null ) if( getAbstractDeclaration() != null )

View file

@ -43,7 +43,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
private NamedOffsets offsets = new NamedOffsets(); private NamedOffsets offsets = new NamedOffsets();
private final ASTQualifiedNamedElement qualifiedName; private final ASTQualifiedNamedElement qualifiedName;
private final List parameters; private final List parameters;
protected final ASTReferenceStore references; protected List references;
private List declarations = new ArrayList(); private List declarations = new ArrayList();
/** /**
* @param symbol * @param symbol
@ -65,7 +65,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
setNameOffset(nameOffset); setNameOffset(nameOffset);
setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); setNameEndOffsetAndLineNumber(nameEndOffset, nameLine);
this.ownerTemplate = ownerTemplate; this.ownerTemplate = ownerTemplate;
this.references = new ASTReferenceStore( references ); this.references = references;
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() ); qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() );
this.previouslyDeclared =previouslyDeclared; this.previouslyDeclared =previouslyDeclared;
this.hasFunctionTryBlock = hasFunctionTryBlock; this.hasFunctionTryBlock = hasFunctionTryBlock;
@ -215,7 +215,8 @@ public class ASTFunction extends ASTScope implements IASTFunction
protected void functionCallbacks(ISourceElementRequestor requestor) protected void functionCallbacks(ISourceElementRequestor requestor)
{ {
references.processReferences(requestor); ASTReferenceStore.processReferences(references, requestor);
references = null;
processParameterInitializersAndArrayMods(requestor); processParameterInitializersAndArrayMods(requestor);
if( getReturnType() != null ) if( getReturnType() != null )
getReturnType().acceptElement(requestor); getReturnType().acceptElement(requestor);

View file

@ -83,8 +83,8 @@ public class ASTInitializerClause implements IASTInitializerClause
if( assignmentExpression != null ) if( assignmentExpression != null )
assignmentExpression.acceptElement( requestor ); assignmentExpression.acceptElement( requestor );
ASTReferenceStore store = new ASTReferenceStore( getReferences() ); ASTReferenceStore.processReferences(references, requestor);
store.processReferences(requestor); references = null;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -27,7 +27,7 @@ public class ASTNamespaceAlias extends ASTSymbol implements IASTNamespaceAlias
private NamedOffsets offsets = new NamedOffsets(); private NamedOffsets offsets = new NamedOffsets();
private final String alias; private final String alias;
private final IASTNamespaceDefinition namespace; private final IASTNamespaceDefinition namespace;
private final ASTReferenceStore store; private List references;
/** /**
* @param scope * @param scope
* @param symbol * @param symbol
@ -44,7 +44,7 @@ public class ASTNamespaceAlias extends ASTSymbol implements IASTNamespaceAlias
setEndingOffsetAndLineNumber(endOffset, endingLine); setEndingOffsetAndLineNumber(endOffset, endingLine);
setNameOffset(nameOffset); setNameOffset(nameOffset);
setNameEndOffsetAndLineNumber(nameEndOffset, nameEndOffset); setNameEndOffsetAndLineNumber(nameEndOffset, nameEndOffset);
store = new ASTReferenceStore( references); this.references = references;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getAlias() * @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getAlias()
@ -65,7 +65,8 @@ public class ASTNamespaceAlias extends ASTSymbol implements IASTNamespaceAlias
*/ */
public void acceptElement(ISourceElementRequestor requestor) public void acceptElement(ISourceElementRequestor requestor)
{ {
store.processReferences(requestor); ASTReferenceStore.processReferences(references, requestor);
references = null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)

View file

@ -10,7 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete; package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -23,18 +23,14 @@ import org.eclipse.cdt.core.parser.ast.IASTReference;
*/ */
public class ASTReferenceStore public class ASTReferenceStore
{ {
private List references = new ArrayList();
public ASTReferenceStore( List assortedReferences )
{
references.addAll( assortedReferences );
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTReferenceStore#processReferences() * @see org.eclipse.cdt.core.parser.ast.IASTReferenceStore#processReferences()
*/ */
public void processReferences(ISourceElementRequestor requestor) public static void processReferences(List references, ISourceElementRequestor requestor)
{ {
if( references == null || references == Collections.EMPTY_LIST || references.isEmpty() )
return;
Iterator i = references.iterator(); Iterator i = references.iterator();
while( i.hasNext() ) while( i.hasNext() )
((IASTReference)i.next()).acceptElement(requestor); ((IASTReference)i.next()).acceptElement(requestor);

View file

@ -192,11 +192,8 @@ public class ASTTypeId implements IASTTypeId
*/ */
public void acceptElement(ISourceElementRequestor requestor) public void acceptElement(ISourceElementRequestor requestor)
{ {
if( references != null && ! references.isEmpty() ) ASTReferenceStore.processReferences(references, requestor);
{ references = null;
ASTReferenceStore store = new ASTReferenceStore( references );
store.processReferences(requestor);
}
Iterator arrayMods = getArrayModifiers(); Iterator arrayMods = getArrayModifiers();
while( arrayMods.hasNext() ) while( arrayMods.hasNext() )
{ {

View file

@ -32,7 +32,7 @@ public class ASTTypedef extends ASTSymbol implements IASTTypedefDeclaration
private final IASTAbstractDeclaration mapping; private final IASTAbstractDeclaration mapping;
private NamedOffsets offsets = new NamedOffsets(); private NamedOffsets offsets = new NamedOffsets();
private final ASTQualifiedNamedElement qualifiedName; private final ASTQualifiedNamedElement qualifiedName;
private final ASTReferenceStore referenceStore; private List references;
/** /**
* @param newSymbol * @param newSymbol
@ -45,7 +45,7 @@ public class ASTTypedef extends ASTSymbol implements IASTTypedefDeclaration
{ {
super( newSymbol ); super( newSymbol );
this.mapping = mapping; this.mapping = mapping;
this.referenceStore = new ASTReferenceStore( references ); this.references = references;
this.qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), newSymbol.getName()); this.qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), newSymbol.getName());
setStartingOffsetAndLineNumber(startingOffset, startingLine); setStartingOffsetAndLineNumber(startingOffset, startingLine);
setNameOffset(nameOffset); setNameOffset(nameOffset);
@ -81,7 +81,8 @@ public class ASTTypedef extends ASTSymbol implements IASTTypedefDeclaration
{ {
/* do nothing */ /* do nothing */
} }
referenceStore.processReferences(requestor); ASTReferenceStore.processReferences(references, requestor);
references = null;
getAbstractDeclarator().acceptElement( requestor ); getAbstractDeclarator().acceptElement( requestor );
} }

View file

@ -30,7 +30,7 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
private final boolean isTypeName; private final boolean isTypeName;
private final List declarations = new ArrayList(); private final List declarations = new ArrayList();
private Offsets offsets = new Offsets(); private Offsets offsets = new Offsets();
private final ASTReferenceStore delegate; private List references;
private String name; private String name;
/** /**
@ -44,7 +44,7 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
this.declarations.addAll( declarations ); this.declarations.addAll( declarations );
setStartingOffsetAndLineNumber(startingOffset, startingLine); setStartingOffsetAndLineNumber(startingOffset, startingLine);
setEndingOffsetAndLineNumber(endingOffset, endingLine); setEndingOffsetAndLineNumber(endingOffset, endingLine);
delegate = new ASTReferenceStore( references ); this.references = references;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#isTypename() * @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#isTypename()
@ -108,7 +108,8 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
{ {
/* do nothing */ /* do nothing */
} }
delegate.processReferences(requestor); ASTReferenceStore.processReferences(references, requestor);
references = null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)

View file

@ -27,7 +27,7 @@ public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUs
{ {
private final IUsingDirectiveSymbol using; private final IUsingDirectiveSymbol using;
private Offsets offsets = new Offsets(); private Offsets offsets = new Offsets();
private final ASTReferenceStore referenceDelegate; private List references;
/** /**
* @param namespaceDefinition * @param namespaceDefinition
* @param startingOffset * @param startingOffset
@ -41,7 +41,7 @@ public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUs
using = usingDirective; using = usingDirective;
setStartingOffsetAndLineNumber(startingOffset, startingLine); setStartingOffsetAndLineNumber(startingOffset, startingLine);
setEndingOffsetAndLineNumber(endingOffset, endingLine); setEndingOffsetAndLineNumber(endingOffset, endingLine);
referenceDelegate = new ASTReferenceStore( references ); this.references = references;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -102,7 +102,8 @@ public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUs
{ {
/* do nothing */ /* do nothing */
} }
referenceDelegate.processReferences(requestor); ASTReferenceStore.processReferences(references, requestor);
references = null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)

View file

@ -30,12 +30,12 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
public class ASTVariable extends ASTSymbol implements IASTVariable public class ASTVariable extends ASTSymbol implements IASTVariable
{ {
private final IASTExpression constructorExpression; private final IASTExpression constructorExpression;
protected final ASTReferenceStore referenceDelegate;
private final ASTQualifiedNamedElement qualifiedName; private final ASTQualifiedNamedElement qualifiedName;
private NamedOffsets offsets = new NamedOffsets(); private NamedOffsets offsets = new NamedOffsets();
private final IASTExpression bitfieldExpression; private final IASTExpression bitfieldExpression;
private final IASTInitializerClause initializerClause; private final IASTInitializerClause initializerClause;
private final IASTAbstractDeclaration abstractDeclaration; private final IASTAbstractDeclaration abstractDeclaration;
protected List references;
/** /**
* @param newSymbol * @param newSymbol
* @param abstractDeclaration * @param abstractDeclaration
@ -55,7 +55,7 @@ public class ASTVariable extends ASTSymbol implements IASTVariable
setStartingOffsetAndLineNumber( startingOffset, startingLine ); setStartingOffsetAndLineNumber( startingOffset, startingLine );
setNameOffset( nameOffset ); setNameOffset( nameOffset );
setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); setNameEndOffsetAndLineNumber(nameEndOffset, nameLine);
referenceDelegate = new ASTReferenceStore( references ); this.references = references;
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), newSymbol.getName() ); qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), newSymbol.getName() );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -169,7 +169,8 @@ public class ASTVariable extends ASTSymbol implements IASTVariable
{ {
/* do nothing */ /* do nothing */
} }
referenceDelegate.processReferences(requestor); ASTReferenceStore.processReferences(references, requestor);
references = null;
if( initializerClause != null ) if( initializerClause != null )
initializerClause.acceptElement(requestor); initializerClause.acceptElement(requestor);
if( constructorExpression != null ) if( constructorExpression != null )

View file

@ -114,6 +114,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
private final static List SUBSCRIPT; private final static List SUBSCRIPT;
private final static IProblemFactory problemFactory = new ASTProblemFactory(); private final static IProblemFactory problemFactory = new ASTProblemFactory();
private final IFilenameProvider fileProvider; private final IFilenameProvider fileProvider;
private final ParserMode mode;
static static
{ {
@ -139,6 +140,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
super(extension); super(extension);
pst = new ParserSymbolTable( language, mode ); pst = new ParserSymbolTable( language, mode );
fileProvider = filenameProvider; fileProvider = filenameProvider;
this.mode = mode;
} }
/* /*
@ -319,8 +321,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
else else
((ITemplateFactory)startingScope).pushSymbol( result ); ((ITemplateFactory)startingScope).pushSymbol( result );
} }
addReference( references, createReference( result, image, name.getStartOffset() )); if( references != null )
if( args != null ) addReference( references, createReference( result, image, name.getStartOffset() ));
if( args != null && references != null )
addTemplateIdReferences( references, templateArgLists[0] ); addTemplateIdReferences( references, templateArgLists[0] );
} }
else else
@ -385,8 +388,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
else else
((ITemplateFactory)startingScope).pushSymbol( result ); ((ITemplateFactory)startingScope).pushSymbol( result );
} }
addReference( references, createReference( result, image, offset )); if( references != null )
if( templateArgLists != null && templateArgLists[idx] != null ) addReference( references, createReference( result, image, offset ));
if( references != null && templateArgLists != null && templateArgLists[idx] != null )
addTemplateIdReferences( references, templateArgLists[idx] ); addTemplateIdReferences( references, templateArgLists[idx] );
} }
else else
@ -558,10 +562,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{ {
Iterator i = endResult.getReferencedSymbols().iterator(); Iterator i = endResult.getReferencedSymbols().iterator();
while( i.hasNext() ) while( i.hasNext() )
{ addReference( references, createReference( (ISymbol) i.next(), name.getLastToken().getImage(), name.getLastToken().getOffset() ) );
IASTReference reference = createReference( (ISymbol) i.next(), name.getLastToken().getImage(), name.getLastToken().getOffset() );
addReference( references, reference );
}
} }
ASTUsingDeclaration using = new ASTUsingDeclaration( scope, name.getLastToken().getImage(), ASTUsingDeclaration using = new ASTUsingDeclaration( scope, name.getLastToken().getImage(),
endResult.getReferencedSymbols(), isTypeName, startingOffset, startingLine, endingOffset, endingLine, references ); endResult.getReferencedSymbols(), isTypeName, startingOffset, startingLine, endingOffset, endingLine, references );
@ -903,11 +905,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
*/ */
protected IASTReference createReference(ISymbol symbol, String referenceElementName, int offset ) throws ASTSemanticException protected IASTReference createReference(ISymbol symbol, String referenceElementName, int offset ) throws ASTSemanticException
{ {
if( symbol.getASTExtension() == null ){ if( mode != ParserMode.COMPLETE_PARSE )
//referenced symbol doesn't have an attached AST node, could happen say for the copy constructor added
//by the symbol table.
return null; return null;
} //referenced symbol doesn't have an attached AST node, could happen say for the copy constructor added
//by the symbol table.
if( symbol.getASTExtension() == null )
return null;
Iterator i = symbol.getASTExtension().getAllDefinitions(); Iterator i = symbol.getASTExtension().getAllDefinitions();
ASTSymbol declaration = i.hasNext() ? (ASTSymbol) i.next() : null; ASTSymbol declaration = i.hasNext() ? (ASTSymbol) i.next() : null;
@ -2083,7 +2087,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
IParameterizedSymbol functionDeclaration = null; IParameterizedSymbol functionDeclaration = null;
functionDeclaration = functionDeclaration =
(IParameterizedSymbol) lookupQualifiedName(ownerScope, name.getFirstToken().getImage(), TypeInfo.t_function, functionParameters, 0, new ArrayList(), false, LookupType.FORDEFINITION ); (IParameterizedSymbol) lookupQualifiedName(ownerScope, name.getFirstToken().getImage(), TypeInfo.t_function, functionParameters, 0, null, false, LookupType.FORDEFINITION );
if( functionDeclaration != null && symbol.isType( TypeInfo.t_function )){ if( functionDeclaration != null && symbol.isType( TypeInfo.t_function )){
previouslyDeclared = true; previouslyDeclared = true;
@ -2230,7 +2234,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
newReferences = new ArrayList(); newReferences = new ArrayList();
newReferences.addAll( elab.getReferences() ); newReferences.addAll( elab.getReferences() );
if( xrefSymbol != null ) if( xrefSymbol != null )
newReferences.add( createReference( xrefSymbol, elab.getName(), elab.getNameOffset()) ); addReference( newReferences, createReference( xrefSymbol, elab.getName(), elab.getNameOffset()) );
} }
String paramName = EMPTY_STRING; String paramName = EMPTY_STRING;
@ -2451,8 +2455,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{ {
functionDeclaration.setTypeSymbol( symbol ); functionDeclaration.setTypeSymbol( symbol );
// set the definition visibility = declaration visibility // set the definition visibility = declaration visibility
ASTMethodReference reference = (ASTMethodReference) functionReferences.iterator().next(); // ASTMethodReference reference = (ASTMethodReference) functionReferences.iterator().next();
visibility = ((IASTMethod)reference.getReferencedElement()).getVisiblity(); visibility = ((IASTMethod)(functionDeclaration.getASTExtension().getPrimaryDeclaration())).getVisiblity();
} }
} }
@ -2601,7 +2605,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
newSymbol.setIsForwardDeclaration( isStatic || isExtern ); newSymbol.setIsForwardDeclaration( isStatic || isExtern );
boolean previouslyDeclared = false; boolean previouslyDeclared = false;
if(!isStatic){ if(!isStatic){
ISymbol variableDeclaration = lookupQualifiedName(ownerScope, name.toString(), new ArrayList(), false, LookupType.UNQUALIFIED); ISymbol variableDeclaration = lookupQualifiedName(ownerScope, name.toString(), null, false, LookupType.UNQUALIFIED);
if( variableDeclaration != null && newSymbol.getType() == variableDeclaration.getType() ) if( variableDeclaration != null && newSymbol.getType() == variableDeclaration.getType() )
{ {
@ -2670,7 +2674,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
try try
{ {
if( lookup != null ) if( lookup != null )
clause.getReferences().add( createReference( lookup, designator.fieldName(), designator.fieldOffset() )); addReference( clause.getReferences(), createReference( lookup, designator.fieldName(), designator.fieldOffset() ));
} }
catch (ASTSemanticException e1) catch (ASTSemanticException e1)
{ {
@ -2728,7 +2732,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( abstractDeclaration.getTypeSpecifier() instanceof ASTSimpleTypeSpecifier ) if( abstractDeclaration.getTypeSpecifier() instanceof ASTSimpleTypeSpecifier )
{ {
symbolToBeCloned = ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol(); symbolToBeCloned = ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol();
references.addAll( ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getReferences() ); if( references != null )
references.addAll( ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getReferences() );
} }
else if( abstractDeclaration.getTypeSpecifier() instanceof ASTClassSpecifier ) else if( abstractDeclaration.getTypeSpecifier() instanceof ASTClassSpecifier )
{ {
@ -2740,8 +2745,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ASTElaboratedTypeSpecifier elab = ((ASTElaboratedTypeSpecifier)abstractDeclaration.getTypeSpecifier()); ASTElaboratedTypeSpecifier elab = ((ASTElaboratedTypeSpecifier)abstractDeclaration.getTypeSpecifier());
symbolToBeCloned = pst.newSymbol(name, TypeInfo.t_type); symbolToBeCloned = pst.newSymbol(name, TypeInfo.t_type);
symbolToBeCloned.setTypeSymbol(elab.getSymbol()); symbolToBeCloned.setTypeSymbol(elab.getSymbol());
if( elab.getSymbol() != null ) if( elab.getSymbol() != null && references != null )
references.add( createReference( elab.getSymbol(), elab.getName(), elab.getNameOffset()) ); addReference( references, createReference( elab.getSymbol(), elab.getName(), elab.getNameOffset()) );
} }
else if ( abstractDeclaration.getTypeSpecifier() instanceof ASTEnumerationSpecifier ) else if ( abstractDeclaration.getTypeSpecifier() instanceof ASTEnumerationSpecifier )
{ {
@ -2829,9 +2834,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{ {
previouslyDeclared = true; previouslyDeclared = true;
fieldDeclaration.setTypeSymbol( newSymbol ); fieldDeclaration.setTypeSymbol( newSymbol );
// set the definition visibility = declaration visibility // // set the definition visibility = declaration visibility
ASTReference reference = (ASTReference) fieldReferences.iterator().next(); // ASTReference reference = (ASTReference) fieldReferences.iterator().next();
visibility = ((IASTField)reference.getReferencedElement()).getVisiblity(); } visibility = ((IASTField)fieldDeclaration.getASTExtension().getPrimaryDeclaration()).getVisiblity();
}
} }
} }
@ -2978,7 +2984,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
int startingLine, int nameOffset, int nameEndOffset, int nameLine) throws ASTSemanticException int startingLine, int nameOffset, int nameEndOffset, int nameLine) throws ASTSemanticException
{ {
IContainerSymbol containerSymbol = scopeToSymbol(scope); IContainerSymbol containerSymbol = scopeToSymbol(scope);
ISymbol typeSymbol = cloneSimpleTypeSymbol( name, mapping, new ArrayList() ); ISymbol typeSymbol = cloneSimpleTypeSymbol( name, mapping, null );
if( typeSymbol == null ) if( typeSymbol == null )
handleProblem( scope, IProblem.SEMANTICS_RELATED, name, nameOffset, nameEndOffset, nameLine ); handleProblem( scope, IProblem.SEMANTICS_RELATED, name, nameOffset, nameEndOffset, nameLine );
@ -3161,7 +3167,6 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
protected ParserSymbolTable pst; protected ParserSymbolTable pst;
protected static final List DUD_LIST = new ArrayList( 64 );
/* /*
@ -3258,7 +3263,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
lookupQualifiedName( lookupQualifiedName(
scopeToSymbol(scope), scopeToSymbol(scope),
nameInQuestion, nameInQuestion,
new ArrayList(), null,
false); false);
} catch (ASTSemanticException e) { } catch (ASTSemanticException e) {
// won't get thrown // won't get thrown
@ -3406,7 +3411,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ISymbol s = null; ISymbol s = null;
if( reference == null ) { if( reference == null ) {
try { try {
s = lookupQualifiedName( scopeToSymbol( scope ), duple, new ArrayList(), false ); s = lookupQualifiedName( scopeToSymbol( scope ), duple, null, false );
} catch (ASTSemanticException e) { } catch (ASTSemanticException e) {
} }
} }
@ -3418,7 +3423,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION ) if( expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION )
{ {
try { try {
s = lookupQualifiedName( scopeToSymbol( scope ), duple, new ArrayList(), false ); s = lookupQualifiedName( scopeToSymbol( scope ), duple, null, false );
} catch (ASTSemanticException e1) { } catch (ASTSemanticException e1) {
} }
} }
@ -3427,7 +3432,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{ {
IContainerSymbol classSymbol = null; IContainerSymbol classSymbol = null;
try { try {
classSymbol = (IContainerSymbol) lookupQualifiedName(scopeToSymbol( scope ), duple, DUD_LIST, false ); classSymbol = (IContainerSymbol) lookupQualifiedName(scopeToSymbol( scope ), duple, null, false );
} catch (ASTSemanticException e) { } catch (ASTSemanticException e) {
} }
if( classSymbol != null && classSymbol.getTypeInfo().checkBit( TypeInfo.isTypedef ) ){ if( classSymbol != null && classSymbol.getTypeInfo().checkBit( TypeInfo.isTypedef ) ){
@ -3463,7 +3468,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( ownerExpression.getExpressionKind().isPostfixMemberReference() ) if( ownerExpression.getExpressionKind().isPostfixMemberReference() )
{ {
try { try {
s = lookupQualifiedName( getSearchScope(ownerExpression.getExpressionKind(), ownerExpression.getLHSExpression(), scopeToSymbol(scope)), duple, new ArrayList(), false ); s = lookupQualifiedName( getSearchScope(ownerExpression.getExpressionKind(), ownerExpression.getLHSExpression(), scopeToSymbol(scope)), duple, null, false );
} catch (ASTSemanticException e) { } catch (ASTSemanticException e) {
return null; return null;
} }
@ -3471,7 +3476,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
else else
{ {
try { try {
s = lookupQualifiedName( scopeToSymbol( scope ), duple, new ArrayList(), false ); s = lookupQualifiedName( scopeToSymbol( scope ), duple, null, false );
} catch (ASTSemanticException e1) { } catch (ASTSemanticException e1) {
} }
} }
@ -3571,11 +3576,4 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
return expression; return expression;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#lookupConstructor(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor)
*/
public IASTNode lookupConstructor(IASTScope ourScope, IASTNewExpressionDescriptor newDescriptor) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -914,12 +914,4 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
return ExpressionFactory.createExpression( kind, literal, isHex ); return ExpressionFactory.createExpression( kind, literal, isHex );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#lookupConstructor(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ITokenDuple)
*/
public IASTNode lookupConstructor(IASTScope ourScope, IASTNewExpressionDescriptor newDescriptor) {
return null;
}
} }

View file

@ -390,11 +390,4 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
public IASTExpression createExpression(Kind kind, long literal, boolean isHex) throws ASTSemanticException { public IASTExpression createExpression(Kind kind, long literal, boolean isHex) throws ASTSemanticException {
return ExpressionFactory.createExpression(kind, literal, isHex ); return ExpressionFactory.createExpression(kind, literal, isHex );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#lookupConstructor(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ITokenDuple)
*/
public IASTNode lookupConstructor(IASTScope ourScope, IASTNewExpressionDescriptor newDescriptor) {
return null;
}
} }

View file

@ -10,7 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.ArrayList; import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IMacroDescriptor;
@ -23,7 +23,6 @@ import org.eclipse.cdt.core.parser.IMacroDescriptor;
*/ */
public class DynamicMacroDescriptor implements IMacroDescriptor { public class DynamicMacroDescriptor implements IMacroDescriptor {
private final List EMPTY_LIST = new ArrayList();
private final String name; private final String name;
private final DynamicMacroEvaluator proxy; private final DynamicMacroEvaluator proxy;
@ -43,14 +42,14 @@ public class DynamicMacroDescriptor implements IMacroDescriptor {
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
*/ */
public List getParameters() { public List getParameters() {
return EMPTY_LIST; return Collections.EMPTY_LIST;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
*/ */
public List getTokenizedExpansion() { public List getTokenizedExpansion() {
return EMPTY_LIST; return Collections.EMPTY_LIST;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -76,9 +77,8 @@ public class GCCScannerExtension implements IScannerExtension {
private static final String __ATTRIBUTE__ = "__attribute__"; //$NON-NLS-1$ private static final String __ATTRIBUTE__ = "__attribute__"; //$NON-NLS-1$
private static final String __DECLSPEC = "__declspec"; //$NON-NLS-1$ private static final String __DECLSPEC = "__declspec"; //$NON-NLS-1$
private static final List EMPTY_LIST = new ArrayList(); protected static final FunctionMacroDescriptor DECLSPEC_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, Collections.EMPTY_LIST, "" ); //$NON-NLS-1$
protected static final FunctionMacroDescriptor DECLSPEC_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, EMPTY_LIST, "" ); //$NON-NLS-1$ protected static final FunctionMacroDescriptor ATTRIBUTE_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersAttribute, Collections.EMPTY_LIST, "" ); //$NON-NLS-1$
protected static final FunctionMacroDescriptor ATTRIBUTE_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersAttribute, EMPTY_LIST, "" ); //$NON-NLS-1$
private static final String __EXTENSION__ = "__extension__"; //$NON-NLS-1$ private static final String __EXTENSION__ = "__extension__"; //$NON-NLS-1$
private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String EMPTY_STRING = ""; //$NON-NLS-1$

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -22,7 +23,6 @@ import org.eclipse.cdt.core.parser.IToken;
*/ */
public class ObjectMacroDescriptor implements IMacroDescriptor { public class ObjectMacroDescriptor implements IMacroDescriptor {
private static final ArrayList EMPTY_LIST = new ArrayList(0);
private final String expansionSignature; private final String expansionSignature;
private final String name; private final String name;
private final IToken token; private final IToken token;
@ -54,14 +54,14 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
*/ */
public List getParameters() { public List getParameters() {
return EMPTY_LIST; return Collections.EMPTY_LIST;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
*/ */
public List getTokenizedExpansion() { public List getTokenizedExpansion() {
if( token == null ) return EMPTY_LIST; if( token == null ) return Collections.EMPTY_LIST;
if( tokenizedExpansion == null ) if( tokenizedExpansion == null )
{ {
tokenizedExpansion = new ArrayList(1); tokenizedExpansion = new ArrayList(1);

View file

@ -19,7 +19,6 @@ import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.EmptyStackException; import java.util.EmptyStackException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -690,6 +689,7 @@ public class Scanner implements IScanner {
private boolean tokenizingMacroReplacementList = false; private boolean tokenizingMacroReplacementList = false;
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$ protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
private Map tempMap = new HashMap(); //$NON-NLS-1$
public void setTokenizingMacroReplacementList( boolean mr ){ public void setTokenizingMacroReplacementList( boolean mr ){
tokenizingMacroReplacementList = mr; tokenizingMacroReplacementList = mr;
} }
@ -2092,8 +2092,8 @@ public class Scanner implements IScanner {
IScanner subScanner = new Scanner( IScanner subScanner = new Scanner(
new StringReader(expression), new StringReader(expression),
SCRATCH, SCRATCH,
EMPTY_MAP, getTemporaryHashtable(),
EMPTY_LIST, Collections.EMPTY_LIST,
NULL_REQUESTOR, NULL_REQUESTOR,
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
scannerData.getLanguage(), scannerData.getLanguage(),
@ -2137,6 +2137,14 @@ public class Scanner implements IScanner {
throwEOF( node ); throwEOF( node );
} }
/**
* @return
*/
private Map getTemporaryHashtable() {
tempMap.clear();
return tempMap = new HashMap();
}
protected void handleInvalidCompletion() throws EndOfFileException protected void handleInvalidCompletion() throws EndOfFileException
{ {
throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.UNREACHABLE_CODE, null, null, EMPTY_STRING, KeywordSets.getKeywords(KeywordSets.Key.EMPTY, scannerData.getLanguage()) , EMPTY_STRING, null)); throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.UNREACHABLE_CODE, null, null, EMPTY_STRING, KeywordSets.getKeywords(KeywordSets.Key.EMPTY, scannerData.getLanguage()) , EMPTY_STRING, null));
@ -2638,14 +2646,12 @@ public class Scanner implements IScanner {
handleInclusion(directive.getFilename().trim(), directive.useIncludePaths(), beginningOffset, startLine, directive.getStartOffset(), nameLine, directive.getEndOffset(), endLine); handleInclusion(directive.getFilename().trim(), directive.useIncludePaths(), beginningOffset, startLine, directive.getStartOffset(), nameLine, directive.getEndOffset(), endLine);
} }
protected static final Hashtable EMPTY_MAP = new Hashtable();
protected static final List EMPTY_LIST = new ArrayList();
protected Map definitionsBackupMap = null; protected Map definitionsBackupMap = null;
protected void temporarilyReplaceDefinitionsMap() protected void temporarilyReplaceDefinitionsMap()
{ {
definitionsBackupMap = scannerData.getPublicDefinitions(); definitionsBackupMap = scannerData.getPublicDefinitions();
scannerData.setDefinitions( EMPTY_MAP ); scannerData.setDefinitions( Collections.EMPTY_MAP );
} }
protected void restoreDefinitionsMap() protected void restoreDefinitionsMap()
@ -2676,7 +2682,7 @@ public class Scanner implements IScanner {
helperScanner = new Scanner( helperScanner = new Scanner(
new StringReader(replacementString), new StringReader(replacementString),
SCRATCH, SCRATCH,
EMPTY_MAP, EMPTY_LIST, getTemporaryHashtable(), Collections.EMPTY_LIST,
NULL_REQUESTOR, NULL_REQUESTOR,
scannerData.getParserMode(), scannerData.getParserMode(),
scannerData.getLanguage(), scannerData.getLanguage(),
@ -2811,7 +2817,7 @@ public class Scanner implements IScanner {
macroReplacementTokens = ( ! replacementString.equals( "" ) ) ? //$NON-NLS-1$ macroReplacementTokens = ( ! replacementString.equals( "" ) ) ? //$NON-NLS-1$
tokenizeReplacementString( beginning, key, replacementString, parameterIdentifiers ) : tokenizeReplacementString( beginning, key, replacementString, parameterIdentifiers ) :
EMPTY_LIST; Collections.EMPTY_LIST;
descriptor = new FunctionMacroDescriptor( descriptor = new FunctionMacroDescriptor(
key, key,
@ -2951,7 +2957,7 @@ public class Scanner implements IScanner {
new StringReader((String)parameters.elementAt(i)), new StringReader((String)parameters.elementAt(i)),
TEXT, TEXT,
scannerData.getPublicDefinitions(), scannerData.getPublicDefinitions(),
EMPTY_LIST, Collections.EMPTY_LIST,
NULL_REQUESTOR, NULL_REQUESTOR,
scannerData.getParserMode(), scannerData.getParserMode(),
scannerData.getLanguage(), scannerData.getLanguage(),