1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

Cached SimpleTypeSpecifiers in the CompleteParseASTFactory. Reduced parse footprint by a couple of MB.

This commit is contained in:
John Camelon 2004-06-21 20:24:36 +00:00
parent ef6d22fb3f
commit 58d2390a65
4 changed files with 40 additions and 23 deletions

View file

@ -792,20 +792,14 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
*/
public void testBug43373() throws Exception
{
try { // This is to prove that there are no exceptions
// Used to cause AST Semantic exception
Iterator i = parse( "class A { static int x; }; int A::x = 5;" ).getDeclarations(); //$NON-NLS-1$
IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
Iterator j = getDeclarations(classA);
IASTField field1 = (IASTField) j.next();
Iterator i = parse( "class A { static int x; }; int A::x = 5;" ).getDeclarations(); //$NON-NLS-1$
IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
Iterator j = getDeclarations(classA);
IASTField field1 = (IASTField) j.next();
// Note : this used to be considered a variable, not a field
IASTField field2 = (IASTField)i.next();
assertTrue (field1.getVisiblity() == field2.getVisiblity());
assertAllReferences( 1, createTaskList( new Task( classA )));
}catch (Exception e){
fail();
}
IASTField field2 = (IASTField)i.next();
assertTrue (field1.getVisiblity() == field2.getVisiblity());
assertAllReferences( 1, createTaskList( new Task( classA )));
}
public void testBug39504() throws Exception

View file

@ -10,6 +10,7 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
@ -122,7 +123,7 @@ public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpe
public List getReferences()
{
return refs;
return (refs == null ) ? Collections.EMPTY_LIST : refs;
}
/* (non-Javadoc)

View file

@ -124,6 +124,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
private final ReferenceCache cache = new ReferenceCache();
private static final int BUILTIN_TYPE_SIZE = 64;
private final Hashtable typeIdCache = new Hashtable( BUILTIN_TYPE_SIZE );
private final Hashtable simpleTypeSpecCache = new Hashtable( BUILTIN_TYPE_SIZE );
private static final int DEFAULT_QUALIFIEDNAME_REFERENCE_SIZE = 4;
static
{
@ -1956,6 +1958,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{
if( extension.overrideCreateSimpleTypeSpecifierMethod( kind ))
return extension.createSimpleTypeSpecifier(pst, scope, kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename, isComplex, isImaginary, isGlobal, extensionParms );
String typeNameAsString = typeName.toString();
if( kind != Type.CLASS_OR_TYPENAME )
{
IASTSimpleTypeSpecifier query = (IASTSimpleTypeSpecifier) simpleTypeSpecCache.get( typeNameAsString );
if( query != null )
return query;
}
TypeInfo.eType type = null;
if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
@ -1975,7 +1985,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
else if( kind == IASTSimpleTypeSpecifier.Type._BOOL )
type = TypeInfo.t__Bool;
List references = new ArrayList();
List references = ( kind == Type.CLASS_OR_TYPENAME ) ? new ArrayList( DEFAULT_QUALIFIEDNAME_REFERENCE_SIZE ): null;
ISymbol s = pst.newSymbol( EMPTY_STRING, type );
if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
{
@ -2047,7 +2057,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
s.getTypeInfo().setBit( isImaginary, TypeInfo.isImaginary );
s.getTypeInfo().setBit( isSigned, TypeInfo.isSigned );
return new ASTSimpleTypeSpecifier( s, false, typeName.toString(), references );
IASTSimpleTypeSpecifier result = new ASTSimpleTypeSpecifier( s, false, typeNameAsString, references );
if( kind != Type.CLASS_OR_TYPENAME )
simpleTypeSpecCache.put( typeNameAsString, result );
return result;
}
/* (non-Javadoc)
@ -3001,16 +3014,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
}
symbol = template;
} else {
symbol = pst.newSymbol( identifier, TypeInfo.t_templateParameter );
if( kind == ParamKind.CLASS || kind == ParamKind.TYPENAME ){
symbol = pst.newSymbol( identifier, TypeInfo.t_templateParameter );
symbol.getTypeInfo().setTemplateParameterType( TypeInfo.t_typeName );
} else /*ParamKind.PARAMETER*/ {
symbol.setName( parameter.getName() );
symbol.setTypeInfo( ((ASTSimpleTypeSpecifier)parameter.getTypeSpecifier()).getSymbol().getTypeInfo() );
symbol = cloneSimpleTypeSymbol( parameter.getName(), parameter, null );
symbol.getTypeInfo().setTemplateParameterType( symbol.getType() );
symbol.setType( TypeInfo.t_templateParameter );
setPointerOperators( symbol, parameter.getPointerOperators(), parameter.getArrayModifiers() );
symbol.setType( TypeInfo.t_templateParameter );
}
}

View file

@ -177,5 +177,16 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
private boolean _isInvisible = false; //used by friend declarations (11.4-9)
private boolean _isTemplateMember = false;
private ISymbol _instantiatedSymbol = null;
private ISymbol _instantiatedSymbol = null;
/* (non-Javadoc)
* @see java.lang.Object#clone()
*/
public Object clone() {
BasicSymbol s = (BasicSymbol) super.clone();
s._typeInfo = new TypeInfo( s._typeInfo );
return s;
}
}