mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-02 22:55:26 +02:00
fix memory leak in the symbol table.
also fix a couple of places that were still doing symbol forwarding the old way
This commit is contained in:
parent
b78e2165a2
commit
e560975741
9 changed files with 36 additions and 39 deletions
|
@ -51,7 +51,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
|
|||
|
||||
public ParserSymbolTable newTable( ParserLanguage language ){
|
||||
table = new ParserSymbolTable( language, ParserMode.COMPLETE_PARSE );
|
||||
provider = TypeInfoProvider.getProvider( table );
|
||||
provider = table.getTypeInfoProvider();
|
||||
return table;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ParserSymbolTableTest extends TestCase {
|
|||
|
||||
public ParserSymbolTable newTable( ParserLanguage language, ParserMode mode ){
|
||||
table = new ParserSymbolTable( language, mode );
|
||||
provider = TypeInfoProvider.getProvider( table );
|
||||
provider = table.getTypeInfoProvider();
|
||||
return table;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -1563,7 +1563,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
|
||||
//basic types
|
||||
if( kind.isBasicType() ){
|
||||
TypeInfoProvider provider = TypeInfoProvider.getProvider( pst );
|
||||
TypeInfoProvider provider = pst.getTypeInfoProvider();
|
||||
provider.beginTypeConstruction();
|
||||
|
||||
if( literal != null && !literal.equals(EMPTY_STRING) && kind.isLiteral() ){
|
||||
|
@ -2226,7 +2226,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
}
|
||||
|
||||
protected ITypeInfo getParameterTypeInfo( IASTAbstractDeclaration absDecl)throws ASTSemanticException{
|
||||
TypeInfoProvider provider = TypeInfoProvider.getProvider( pst );
|
||||
TypeInfoProvider provider = pst.getTypeInfoProvider();
|
||||
provider.beginTypeConstruction();
|
||||
if( absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier )
|
||||
{
|
||||
|
@ -3022,7 +3022,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
{
|
||||
ISymbol symbol = null;
|
||||
|
||||
TypeInfoProvider provider = TypeInfoProvider.getProvider( pst );
|
||||
TypeInfoProvider provider = pst.getTypeInfoProvider();
|
||||
provider.beginTypeConstruction();
|
||||
|
||||
if( defaultValue != null ){
|
||||
|
|
|
@ -1090,11 +1090,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
|||
if( !alreadyReturned.contains( extensible ) ){
|
||||
if( extensible instanceof ISymbol ){
|
||||
ISymbol symbol = (ISymbol) extensible;
|
||||
if( symbol.isForwardDeclaration() && symbol.getTypeSymbol() != null &&
|
||||
symbol.getTypeSymbol().getContainingSymbol() == ContainerSymbol.this )
|
||||
if( symbol.isForwardDeclaration() && symbol.getForwardSymbol() != null &&
|
||||
symbol.getForwardSymbol().getContainingSymbol() == ContainerSymbol.this )
|
||||
{
|
||||
alreadyReturned.add( symbol.getTypeSymbol() );
|
||||
return symbol.getTypeSymbol();
|
||||
alreadyReturned.add( symbol.getForwardSymbol() );
|
||||
return symbol.getForwardSymbol();
|
||||
}
|
||||
} else if( extensible instanceof IUsingDeclarationSymbol ){
|
||||
IUsingDeclarationSymbol using = (IUsingDeclarationSymbol) extensible;
|
||||
|
|
|
@ -201,7 +201,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
|
|||
paramType = TemplateEngine.instantiateWithinTemplateScope( this, (ITemplateSymbol) getContainingSymbol() );
|
||||
}
|
||||
|
||||
ITypeInfo param = TypeInfoProvider.getProvider(getSymbolTable()).getTypeInfo( ITypeInfo.t_type );
|
||||
ITypeInfo param = getSymbolTable().getTypeInfoProvider().getTypeInfo( ITypeInfo.t_type );
|
||||
param.setType( ITypeInfo.t_type );
|
||||
param.setBit( true, ITypeInfo.isConst );
|
||||
param.setTypeSymbol( paramType );
|
||||
|
|
|
@ -456,7 +456,7 @@ public class ParserSymbolTable {
|
|||
return true;
|
||||
}
|
||||
|
||||
TypeInfoProvider provider = TypeInfoProvider.getProvider( symbol.getSymbolTable() );
|
||||
TypeInfoProvider provider = symbol.getSymbolTable().getTypeInfoProvider();
|
||||
ITypeInfo typeInfo = ParserSymbolTable.getFlatTypeInfo( symbol.getTypeInfo(), provider );
|
||||
boolean accept = data.getFilter().shouldAccept( symbol, typeInfo ) || data.getFilter().shouldAccept( symbol );
|
||||
provider.returnTypeInfo( typeInfo );
|
||||
|
@ -817,7 +817,7 @@ public class ParserSymbolTable {
|
|||
|
||||
//friend class declarations
|
||||
if( origSymbol.getIsInvisible() && origSymbol.isType( newSymbol.getType() ) ){
|
||||
origSymbol.getTypeInfo().setTypeSymbol( newSymbol );
|
||||
origSymbol.setForwardSymbol( newSymbol );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1008,8 +1008,8 @@ public class ParserSymbolTable {
|
|||
for (int i = 0; i < numFns; i++) {
|
||||
IParameterizedSymbol fn = (IParameterizedSymbol) functions.get(i);
|
||||
if( fn.isForwardDeclaration() && fn.getForwardSymbol() != null ){
|
||||
if( functions.contains( fn.getTypeSymbol() ) ){
|
||||
return (IParameterizedSymbol) fn.getTypeSymbol();
|
||||
if( functions.contains( fn.getForwardSymbol() ) ){
|
||||
return (IParameterizedSymbol) fn.getForwardSymbol();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1041,7 +1041,7 @@ public class ParserSymbolTable {
|
|||
List sourceParameters = null; //the parameters the function is being called with
|
||||
List targetParameters = null; //the current function's parameters
|
||||
|
||||
TypeInfoProvider infoProvider = TypeInfoProvider.getProvider( this );
|
||||
TypeInfoProvider infoProvider = getTypeInfoProvider();
|
||||
|
||||
if( numSourceParams == 0 ){
|
||||
//f() is the same as f( void )
|
||||
|
@ -1852,7 +1852,7 @@ public class ParserSymbolTable {
|
|||
}
|
||||
|
||||
protected Cost checkStandardConversionSequence( ITypeInfo source, ITypeInfo target ) throws ParserSymbolTableException{
|
||||
Cost cost = lvalue_to_rvalue( TypeInfoProvider.getProvider( this ), source, target );
|
||||
Cost cost = lvalue_to_rvalue( getTypeInfoProvider(), source, target );
|
||||
|
||||
if( cost.getSource() == null || cost.getTarget() == null ){
|
||||
return cost;
|
||||
|
@ -1900,7 +1900,7 @@ public class ParserSymbolTable {
|
|||
try{
|
||||
derivedToBaseConversion( cost );
|
||||
} catch ( ParserSymbolTableException e ){
|
||||
cost.release( TypeInfoProvider.getProvider( this ) );
|
||||
cost.release( getTypeInfoProvider() );
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
@ -1948,7 +1948,7 @@ public class ParserSymbolTable {
|
|||
}
|
||||
}
|
||||
|
||||
TypeInfoProvider provider = TypeInfoProvider.getProvider( this );
|
||||
TypeInfoProvider provider = getTypeInfoProvider();
|
||||
//conversion operators
|
||||
if( source.getType() == ITypeInfo.t_type ){
|
||||
source = getFlatTypeInfo( source, provider );
|
||||
|
@ -2139,6 +2139,7 @@ public class ParserSymbolTable {
|
|||
|
||||
private IContainerSymbol _compilationUnit;
|
||||
private ParserLanguage _language;
|
||||
private TypeInfoProvider _typeInfoProvider;
|
||||
private ParserMode _mode;
|
||||
|
||||
public void setLanguage( ParserLanguage language ){
|
||||
|
@ -2154,7 +2155,7 @@ public class ParserSymbolTable {
|
|||
}
|
||||
|
||||
public TypeInfoProvider getTypeInfoProvider(){
|
||||
return TypeInfoProvider.getProvider( this );
|
||||
return _typeInfoProvider;
|
||||
}
|
||||
|
||||
// protected void pushCommand( Command command ){
|
||||
|
|
|
@ -177,7 +177,7 @@ public final class TemplateEngine {
|
|||
return true;
|
||||
} else {
|
||||
Cost cost = null;
|
||||
TypeInfoProvider provider = TypeInfoProvider.getProvider( param.getSymbolTable() );
|
||||
TypeInfoProvider provider = param.getSymbolTable().getTypeInfoProvider();
|
||||
try{
|
||||
ITypeInfo info = provider.getTypeInfo( param.getTypeInfo().getTemplateParameterType() );
|
||||
try {
|
||||
|
@ -462,6 +462,8 @@ public final class TemplateEngine {
|
|||
if( symbol == null || ( a.isType( ITypeInfo.t_type) && aSymbol == null ) || a.isType( ITypeInfo.t_undef ))
|
||||
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
|
||||
if( symbol instanceof IDeferredTemplateInstance || symbol.isTemplateInstance() ){
|
||||
if( aSymbol == null )
|
||||
return false;
|
||||
return deduceFromTemplateTemplateArguments(map, symbol, aSymbol);
|
||||
}
|
||||
if( symbol.isType( ITypeInfo.t_templateParameter ) ){
|
||||
|
@ -1308,6 +1310,9 @@ public final class TemplateEngine {
|
|||
ITemplateSymbol t1 = getContainingTemplate( p1 );
|
||||
ITemplateSymbol t2 = getContainingTemplate( p2 );
|
||||
|
||||
if( t1 == null || t2 == null )
|
||||
return false;
|
||||
|
||||
if( p1.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName )
|
||||
{
|
||||
List l1 = t1.getParameterList(), l2 = t2.getParameterList();
|
||||
|
|
|
@ -307,7 +307,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
|
|||
//in defining the explicit specialization for a member function, the factory would have set
|
||||
//the specialization as the definition of the original declaration, which it is not
|
||||
if( found.isForwardDeclaration() && found.getForwardSymbol() == symbol )
|
||||
found.setTypeSymbol( null );
|
||||
found.setForwardSymbol( null );
|
||||
|
||||
//TODO, once we can instantiate members as we need them instead of at the same time as the class
|
||||
//then found should stay as the instance, for now though, we need the original (not 100% correct
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.parser.pst;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.PtrOp;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.eType;
|
||||
|
||||
|
@ -27,7 +24,6 @@ public class TypeInfoProvider
|
|||
private static final int TYPE = 1;
|
||||
private static final int TEMPLATE = 2;
|
||||
private static final int POOL_SIZE = 16;
|
||||
private static final Map providerMap = new HashMap();
|
||||
|
||||
private final ITypeInfo [][] pool;
|
||||
private final boolean [][] free;
|
||||
|
@ -42,24 +38,17 @@ public class TypeInfoProvider
|
|||
|
||||
for( int i = 0; i < POOL_SIZE; i++ )
|
||||
{
|
||||
pool[i] = new ITypeInfo[] { new BasicTypeInfo(), new TypeInfo(), new TemplateParameterTypeInfo() };
|
||||
pool[i] = new ITypeInfo[] { newInfo( ITypeInfo.t_void, true ),
|
||||
newInfo( ITypeInfo.t_type, true ),
|
||||
newInfo( ITypeInfo.t_templateParameter, true ) };
|
||||
free[i] = new boolean [] { true, true, true };
|
||||
}
|
||||
}
|
||||
|
||||
static public TypeInfoProvider getProvider( ParserSymbolTable table ){
|
||||
if( providerMap.containsKey( table ) )
|
||||
return (TypeInfoProvider) providerMap.get( table );
|
||||
|
||||
TypeInfoProvider provider = new TypeInfoProvider();
|
||||
providerMap.put( table, provider );
|
||||
return provider;
|
||||
}
|
||||
|
||||
public ITypeInfo getTypeInfo( eType type )
|
||||
{
|
||||
int idx = BASIC;
|
||||
if( type == ITypeInfo.t_type )
|
||||
if( type == ITypeInfo.t_type || type == ITypeInfo.t_enumerator )
|
||||
idx = TYPE;
|
||||
else if( type == ITypeInfo.t_templateParameter )
|
||||
idx = TEMPLATE;
|
||||
|
@ -196,7 +185,7 @@ public class TypeInfoProvider
|
|||
* @param def
|
||||
* @return
|
||||
*/
|
||||
public static ITypeInfo newTypeInfo( eType type, int bits, ISymbol symbol, PtrOp op, Object def ) {
|
||||
public final static ITypeInfo newTypeInfo( eType type, int bits, ISymbol symbol, PtrOp op, Object def ) {
|
||||
ITypeInfo newInfo = newInfo( type, def != null );
|
||||
|
||||
newInfo.setType( type );
|
||||
|
@ -209,7 +198,7 @@ public class TypeInfoProvider
|
|||
/**
|
||||
* @return
|
||||
*/
|
||||
public static ITypeInfo newTypeInfo() {
|
||||
public final static ITypeInfo newTypeInfo() {
|
||||
return new BasicTypeInfo();
|
||||
}
|
||||
|
||||
|
@ -250,10 +239,12 @@ public class TypeInfoProvider
|
|||
if( templateParamType != null )
|
||||
newInfo.setTemplateParameterType( templateParamType );
|
||||
|
||||
//clear the fields
|
||||
beginTypeConstruction();
|
||||
return newInfo;
|
||||
}
|
||||
|
||||
private static ITypeInfo newInfo( eType type, boolean def ){
|
||||
private final static ITypeInfo newInfo( eType type, boolean def ){
|
||||
ITypeInfo newInfo = null;
|
||||
if( type == ITypeInfo.t_type || type == ITypeInfo.t_enumerator ){
|
||||
if( def )
|
||||
|
|
Loading…
Add table
Reference in a new issue