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

Refactoring pst.TypeInfo for memory performance. see parser.changelog

this is a small step toward a faster parser
(see bugs 59468, 54040, 60902, et al)
This commit is contained in:
Andrew Niefer 2004-07-07 20:15:06 +00:00
parent 04c74b6af0
commit c9c666335f
38 changed files with 2952 additions and 2520 deletions

View file

@ -1887,8 +1887,8 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
Writer writer = new StringWriter();
writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$
writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$
writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\n"); //$NON-NLS-1$
writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\n"); //$NON-NLS-1$
writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); //$NON-NLS-1$
writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); //$NON-NLS-1$
writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$
writer.write( "enum e {\n"); //$NON-NLS-1$
writer.write( "blah1 = 5,\n"); //$NON-NLS-1$

View file

@ -1125,8 +1125,8 @@ public class CompletionParseTest extends CompletionParseBaseTest {
Writer writer = new StringWriter();
writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$
writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$
writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\n"); //$NON-NLS-1$
writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\n"); //$NON-NLS-1$
writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); //$NON-NLS-1$
writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); //$NON-NLS-1$
writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$
writer.write( "enum e {\n"); //$NON-NLS-1$
writer.write( "blah1 = 5,\n"); //$NON-NLS-1$

View file

@ -1,3 +1,17 @@
2004-07-07 Andrew Niefer
Symbol Table Refactoring:
- TypeInfo._typeDeclaration is no longer used for forward declarations, instead BasicSymbol._instantiatedSymbol
has been renamed to _symbolDef and is used for forwarding and also for its original template purpose.
- TypeInfo._operatorExpressions has been removed. You now apply operator expressions directly to the TypeInfo
with TypeInfo.applyOperatorExpression.
- a new interface ITypeInfo has been created. This interface should now be used instead of TypeInfo.
- the old TypeInfo has been separated into BasicTypeInfo, TypeInfo, and TemplateParameterTypeInfo, as well as dynamic
overrides of these classes.
- all construction of TypeInfo objects should now be done through TypeInfoProvider.newTypeInfo( ... ) functions
to ensure the object obtain has the needed fields.
The sum total of these changes is a reduction of memory used while parsing the combination of stdio.h,
iostream, and windows.h by about 4 Megs.
2004-06-22 Alain Magloire
Part of PR 68246.

View file

@ -257,7 +257,54 @@ public interface IASTExpression extends ISourceElementCallbackDelegate, IASTNode
return false;
}
public boolean isBasicType(){
if(this == PRIMARY_EMPTY
|| this == THROWEXPRESSION
|| this == POSTFIX_DOT_DESTRUCTOR
|| this == POSTFIX_ARROW_DESTRUCTOR
|| this == DELETE_CASTEXPRESSION
|| this == DELETE_VECTORCASTEXPRESSION
|| this == PRIMARY_INTEGER_LITERAL
|| this == POSTFIX_SIMPLETYPE_INT
|| this == UNARY_SIZEOF_TYPEID
|| this == UNARY_SIZEOF_UNARYEXPRESSION
|| this == PRIMARY_CHAR_LITERAL
|| this == POSTFIX_SIMPLETYPE_CHAR
|| this == PRIMARY_STRING_LITERAL
|| this == PRIMARY_FLOAT_LITERAL
|| this == POSTFIX_SIMPLETYPE_FLOAT
|| this == POSTFIX_SIMPLETYPE_DOUBLE
|| this == POSTFIX_SIMPLETYPE_WCHART
|| this == PRIMARY_BOOLEAN_LITERAL
|| this == POSTFIX_SIMPLETYPE_BOOL
|| this == RELATIONAL_GREATERTHAN
|| this == RELATIONAL_GREATERTHANEQUALTO
|| this == RELATIONAL_LESSTHAN
|| this == RELATIONAL_LESSTHANEQUALTO
|| this == EQUALITY_EQUALS
|| this == EQUALITY_NOTEQUALS
|| this == LOGICALANDEXPRESSION
|| this == LOGICALOREXPRESSION
)
return true;
return false;
}
public boolean isPostfixSimpleType(){
if((this == POSTFIX_SIMPLETYPE_INT)
|| (this == POSTFIX_SIMPLETYPE_SHORT)
|| (this == POSTFIX_SIMPLETYPE_DOUBLE)
|| (this == POSTFIX_SIMPLETYPE_FLOAT)
|| (this == POSTFIX_SIMPLETYPE_CHAR)
|| (this == POSTFIX_SIMPLETYPE_WCHART)
|| (this == POSTFIX_SIMPLETYPE_SIGNED)
|| (this == POSTFIX_SIMPLETYPE_UNSIGNED)
|| (this == POSTFIX_SIMPLETYPE_BOOL)
|| (this == POSTFIX_SIMPLETYPE_LONG) )
{
return true;
}
return false;
}
}
public interface IASTNewExpressionDescriptor extends ISourceElementCallbackDelegate

View file

@ -23,8 +23,8 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
/**
* @author jcamelon
@ -53,7 +53,7 @@ public interface IASTFactoryExtension {
* @param typeId
* @return TODO
*/
public TypeInfo getExpressionResultType(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTTypeId typeId);
public ITypeInfo getExpressionResultType(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTTypeId typeId);
public boolean overrideCreateSimpleTypeSpecifierMethod(Type type);

View file

@ -35,8 +35,9 @@ import org.eclipse.cdt.internal.core.parser.ast.complete.gcc.GCCASTCompleteExten
import org.eclipse.cdt.internal.core.parser.ast.expression.GCCASTExpressionExtension;
import org.eclipse.cdt.internal.core.parser.ast.gcc.ASTGCCDesignator;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider;
/**
* @author jcamelon
@ -68,35 +69,34 @@ public abstract class GCCASTExtension implements IASTFactoryExtension {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#getExpressionResultType(org.eclipse.cdt.internal.core.parser.pst.TypeInfo, org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTTypeId, org.eclipse.cdt.internal.core.parser.pst.ISymbol)
*/
public TypeInfo getExpressionResultType(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTTypeId typeId) {
TypeInfo info = null;
public ITypeInfo getExpressionResultType(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTTypeId typeId) {
ITypeInfo info = null;
if( kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID ||
kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION )
{
info = new TypeInfo();
info.setType(TypeInfo.t_int);
info.setBit(true, TypeInfo.isUnsigned);
info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int );
info.setBit(true, ITypeInfo.isUnsigned);
}
else if( kind == IASTGCCExpression.Kind.RELATIONAL_MAX ||
kind == IASTGCCExpression.Kind.RELATIONAL_MIN )
{
if( lhs instanceof ASTExpression )
info = new TypeInfo( ((ASTExpression)lhs).getResultType().getResult() );
info = TypeInfoProvider.newTypeInfo( ((ASTExpression)lhs).getResultType().getResult() );
}
else if( kind == IASTGCCExpression.Kind.UNARY_TYPEOF_TYPEID )
{
if( typeId instanceof ASTTypeId )
info = new TypeInfo( ((ASTTypeId)typeId).getTypeSymbol().getTypeInfo() );
info = TypeInfoProvider.newTypeInfo( ((ASTTypeId)typeId).getTypeSymbol().getTypeInfo() );
}
else if ( kind == IASTGCCExpression.Kind.UNARY_TYPEOF_UNARYEXPRESSION )
{
if( lhs instanceof ASTExpression )
info = new TypeInfo( ((ASTExpression)lhs).getResultType().getResult() );
info = TypeInfoProvider.newTypeInfo( ((ASTExpression)lhs).getResultType().getResult() );
}
if( info != null )
return info;
return new TypeInfo();
return TypeInfoProvider.newTypeInfo();
}
/* (non-Javadoc)

View file

@ -23,8 +23,8 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TypeInfoProvider;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider;
/**
* @author jcamelon
@ -177,13 +177,13 @@ public abstract class ASTExpression extends ASTNode implements IASTExpression
public IContainerSymbol getLookupQualificationSymbol() throws LookupError {
ExpressionResult result = getResultType();
TypeInfo type = (result != null ) ? result.getResult() : null;
ITypeInfo type = (result != null ) ? result.getResult() : null;
IContainerSymbol containerSymbol = null;
if( type != null && type.getTypeSymbol() != null ){
TypeInfoProvider provider = type.getTypeSymbol().getSymbolTable().getTypeInfoProvider();
type = type.getFinalType( provider );
if( type.isType( TypeInfo.t_type ) &&
if( type.isType( ITypeInfo.t_type ) &&
type.getTypeSymbol() != null && type.getTypeSymbol() instanceof IContainerSymbol )
{
containerSymbol = (IContainerSymbol) type.getTypeSymbol();
@ -196,15 +196,15 @@ public abstract class ASTExpression extends ASTNode implements IASTExpression
public boolean shouldFilterLookupResult( ISymbol symbol ){
ExpressionResult result = getResultType();
TypeInfo type = ( result != null ) ? result.getResult() : null;
ITypeInfo type = ( result != null ) ? result.getResult() : null;
if( type != null ){
boolean answer = false;
TypeInfoProvider provider = symbol.getSymbolTable().getTypeInfoProvider();
type = type.getFinalType( provider );
if( type.checkBit( TypeInfo.isConst ) && !symbol.getTypeInfo().checkBit( TypeInfo.isConst ) )
if( type.checkBit( ITypeInfo.isConst ) && !symbol.getTypeInfo().checkBit( ITypeInfo.isConst ) )
answer = true;
if( type.checkBit( TypeInfo.isVolatile ) && !symbol.getTypeInfo().checkBit( TypeInfo.isVolatile ) )
if( type.checkBit( ITypeInfo.isVolatile ) && !symbol.getTypeInfo().checkBit( ITypeInfo.isVolatile ) )
answer = true;
provider.returnTypeInfo( type );

View file

@ -27,7 +27,7 @@ import org.eclipse.cdt.core.parser.ast.IReferenceManager;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
/**
* @author jcamelon
@ -79,7 +79,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
*/
public boolean isInline()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isInline );
return symbol.getTypeInfo().checkBit( ITypeInfo.isInline );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#isFriend()
@ -93,7 +93,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
*/
public boolean isStatic()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isStatic );
return symbol.getTypeInfo().checkBit( ITypeInfo.isStatic );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName()

View file

@ -27,11 +27,11 @@ import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
/**
* @author jcamelon
@ -78,14 +78,14 @@ public class ASTMethod extends ASTFunction implements IASTMethod
*/
public boolean isVirtual()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isVirtual );
return symbol.getTypeInfo().checkBit( ITypeInfo.isVirtual );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTMethod#isExplicit()
*/
public boolean isExplicit()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isExplicit);
return symbol.getTypeInfo().checkBit( ITypeInfo.isExplicit);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTMethod#isConstructor()
@ -106,14 +106,14 @@ public class ASTMethod extends ASTFunction implements IASTMethod
*/
public boolean isConst()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isConst);
return symbol.getTypeInfo().checkBit( ITypeInfo.isConst);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTMethod#isVolatile()
*/
public boolean isVolatile()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isVolatile );
return symbol.getTypeInfo().checkBit( ITypeInfo.isVolatile );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTMethod#isPureVirtual()

View file

@ -18,7 +18,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
import org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
/**
* @author jcamelon
@ -49,23 +49,23 @@ public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpe
*/
public Type getType()
{
if( symbol.getType() == TypeInfo.t_int )
if( symbol.getType() == ITypeInfo.t_int )
return IASTSimpleTypeSpecifier.Type.INT;
if( symbol.getType() == TypeInfo.t_double )
if( symbol.getType() == ITypeInfo.t_double )
return IASTSimpleTypeSpecifier.Type.DOUBLE;
if( symbol.getType() == TypeInfo.t_float )
if( symbol.getType() == ITypeInfo.t_float )
return IASTSimpleTypeSpecifier.Type.FLOAT;
if( symbol.getType() == TypeInfo.t_bool )
if( symbol.getType() == ITypeInfo.t_bool )
return IASTSimpleTypeSpecifier.Type.BOOL;
if( symbol.getType() == TypeInfo.t_type )
if( symbol.getType() == ITypeInfo.t_type )
return IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
if( symbol.getType() == TypeInfo.t_char )
if( symbol.getType() == ITypeInfo.t_char )
return IASTSimpleTypeSpecifier.Type.CHAR;
if( symbol.getType() == TypeInfo.t_void )
if( symbol.getType() == ITypeInfo.t_void )
return IASTSimpleTypeSpecifier.Type.VOID;
if( symbol.getType() == TypeInfo.t_wchar_t)
if( symbol.getType() == ITypeInfo.t_wchar_t)
return IASTSimpleTypeSpecifier.Type.WCHAR_T;
if( symbol.getType() == TypeInfo.t__Bool )
if( symbol.getType() == ITypeInfo.t__Bool )
return IASTSimpleTypeSpecifier.Type._BOOL;
return IASTSimpleTypeSpecifier.Type.UNSPECIFIED;
@ -83,28 +83,28 @@ public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpe
*/
public boolean isLong()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isLong );
return symbol.getTypeInfo().checkBit( ITypeInfo.isLong );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isShort()
*/
public boolean isShort()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isShort );
return symbol.getTypeInfo().checkBit( ITypeInfo.isShort );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isSigned()
*/
public boolean isSigned()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isSigned);
return symbol.getTypeInfo().checkBit( ITypeInfo.isSigned);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isUnsigned()
*/
public boolean isUnsigned()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isUnsigned );
return symbol.getTypeInfo().checkBit( ITypeInfo.isUnsigned );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isTypename()
@ -139,7 +139,7 @@ public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpe
*/
public boolean isComplex()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isComplex );
return symbol.getTypeInfo().checkBit( ITypeInfo.isComplex );
}
/* (non-Javadoc)
@ -147,7 +147,7 @@ public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpe
*/
public boolean isImaginary()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isImaginary );
return symbol.getTypeInfo().checkBit( ITypeInfo.isImaginary );
}
/* (non-Javadoc)

View file

@ -15,9 +15,9 @@ import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider;
/**
* @author jcamelon
@ -44,8 +44,8 @@ public abstract class ASTSymbol extends ASTSymbolOwner implements ISymbolOwner,
public IContainerSymbol getLookupQualificationSymbol() throws LookupError {
ISymbol sym = getSymbol();
IContainerSymbol result = null;
ParserSymbolTable.TypeInfoProvider provider = sym.getSymbolTable().getTypeInfoProvider();
TypeInfo info = null;
TypeInfoProvider provider = sym.getSymbolTable().getTypeInfoProvider();
ITypeInfo info = null;
try{
info = sym.getTypeInfo().getFinalType( provider );
@ -53,7 +53,7 @@ public abstract class ASTSymbol extends ASTSymbolOwner implements ISymbolOwner,
throw new LookupError();
}
if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() != null && info.getTypeSymbol() instanceof IContainerSymbol )
if( info.isType( ITypeInfo.t_type ) && info.getTypeSymbol() != null && info.getTypeSymbol() instanceof IContainerSymbol )
result = (IContainerSymbol) info.getTypeSymbol();
else if( sym instanceof IContainerSymbol )
result = (IContainerSymbol) sym;
@ -64,18 +64,18 @@ public abstract class ASTSymbol extends ASTSymbolOwner implements ISymbolOwner,
public boolean shouldFilterLookupResult( ISymbol sym ){
boolean result = false;
ParserSymbolTable.TypeInfoProvider provider = sym.getSymbolTable().getTypeInfoProvider();
TypeInfo info = null;
TypeInfoProvider provider = sym.getSymbolTable().getTypeInfoProvider();
ITypeInfo info = null;
try{
info = getSymbol().getTypeInfo().getFinalType( provider );
} catch( ParserSymbolTableError e ){
return true;
}
if( info.checkBit( TypeInfo.isConst ) && !sym.getTypeInfo().checkBit( TypeInfo.isConst ) )
if( info.checkBit( ITypeInfo.isConst ) && !sym.getTypeInfo().checkBit( ITypeInfo.isConst ) )
result = true;
if( info.checkBit( TypeInfo.isVolatile ) && !sym.getTypeInfo().checkBit( TypeInfo.isVolatile ) )
if( info.checkBit( ITypeInfo.isVolatile ) && !sym.getTypeInfo().checkBit( ITypeInfo.isVolatile ) )
result = true;
provider.returnTypeInfo( info );

View file

@ -27,7 +27,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
/**
* @author aniefer
@ -67,11 +67,11 @@ public class ASTTemplateParameter extends ASTSymbol implements IASTTemplateParam
* @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getTemplateParameterKind()
*/
public ParamKind getTemplateParameterKind() {
TypeInfo.eType type = symbol.getTypeInfo().getTemplateParameterType();
if( type == TypeInfo.t_typeName )
ITypeInfo.eType type = symbol.getTypeInfo().getTemplateParameterType();
if( type == ITypeInfo.t_typeName )
//TODO: difference between class & typename?
return ParamKind.TYPENAME;
else if( type == TypeInfo.t_template )
else if( type == ITypeInfo.t_template )
return ParamKind.TEMPLATE_LIST;
else
return ParamKind.PARAMETER;

View file

@ -22,7 +22,7 @@ import org.eclipse.cdt.core.parser.ast.IReferenceManager;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
/**
* @author jcamelon
@ -64,35 +64,35 @@ public class ASTVariable extends ASTSymbol implements IASTVariable
*/
public boolean isAuto()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isAuto );
return symbol.getTypeInfo().checkBit( ITypeInfo.isAuto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isRegister()
*/
public boolean isRegister()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isRegister);
return symbol.getTypeInfo().checkBit( ITypeInfo.isRegister);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isStatic()
*/
public boolean isStatic()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isStatic);
return symbol.getTypeInfo().checkBit( ITypeInfo.isStatic);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isExtern()
*/
public boolean isExtern()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isExtern );
return symbol.getTypeInfo().checkBit( ITypeInfo.isExtern );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isMutable()
*/
public boolean isMutable()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isMutable);
return symbol.getTypeInfo().checkBit( ITypeInfo.isMutable);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#getAbstractDeclaration()

View file

@ -10,7 +10,8 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider;
/**
* @author hamer
@ -19,26 +20,26 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
public class ExpressionResult {
private TypeInfo result;
private ITypeInfo result;
private boolean failedToDereference = false;
ExpressionResult(){
result = new TypeInfo();
result = TypeInfoProvider.newTypeInfo();
}
ExpressionResult(TypeInfo result){
ExpressionResult(ITypeInfo result){
this.result = result;
}
/**
* @return
*/
public TypeInfo getResult() {
public ITypeInfo getResult() {
return result;
}
/**
* @param info
*/
public void setResult(TypeInfo info) {
public void setResult(ITypeInfo info) {
result = info;
}

View file

@ -12,7 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
/**
* @author hamer
@ -27,15 +27,15 @@ public class ExpressionResultList extends ExpressionResult {
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ExpressionResult#getResult()
*/
public TypeInfo getResult() {
public ITypeInfo getResult() {
// TODO Auto-generated method stub
return (TypeInfo)resultList.get(0);
return (ITypeInfo)resultList.get(0);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ast.complete.ExpressionResult#setResult(org.eclipse.cdt.internal.core.parser.pst.TypeInfo)
*/
public void setResult(TypeInfo info) {
public void setResult(ITypeInfo info) {
// TODO Auto-generated method stub
resultList.add(info);
}

View file

@ -16,28 +16,19 @@ package org.eclipse.cdt.internal.core.parser.pst;
import java.util.List;
import java.util.Map;
public class BasicSymbol extends ExtensibleSymbol implements ISymbol
{
public BasicSymbol( ParserSymbolTable table, String name ){
super( table );
_name = name;
_typeInfo = new TypeInfo();
}
}
public BasicSymbol( ParserSymbolTable table, String name, ISymbolASTExtension obj ){
super( table, obj );
_name = name;
_typeInfo = new TypeInfo();
}
public BasicSymbol( ParserSymbolTable table, String name, TypeInfo.eType typeInfo )
public BasicSymbol( ParserSymbolTable table, String name, ITypeInfo.eType typeInfo )
{
super( table );
_name = name;
_typeInfo = new TypeInfo( typeInfo, 0, null );
_typeInfo = TypeInfoProvider.newTypeInfo( typeInfo );
}
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{
@ -60,27 +51,27 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
_depth = scope.getDepth() + 1;
}
public void setType(TypeInfo.eType t){
public void setType(ITypeInfo.eType t){
getTypeInfo().setType( t );
}
public TypeInfo.eType getType(){
public ITypeInfo.eType getType(){
return getTypeInfo().getType();
}
public boolean isType( TypeInfo.eType type ){
return getTypeInfo().isType( type, TypeInfo.t_undef );
public boolean isType( ITypeInfo.eType type ){
return getTypeInfo().isType( type, ITypeInfo.t_undef );
}
public boolean isType( TypeInfo.eType type, TypeInfo.eType upperType ){
public boolean isType( ITypeInfo.eType type, ITypeInfo.eType upperType ){
return getTypeInfo().isType( type, upperType );
}
public ISymbol getTypeSymbol(){
ISymbol symbol = getTypeInfo().getTypeSymbol();
if( symbol != null && symbol.getTypeInfo().isForwardDeclaration() && symbol.getTypeSymbol() != null ){
return symbol.getTypeSymbol();
if( symbol != null && symbol.isForwardDeclaration() && symbol.getForwardSymbol() != null ){
return symbol.getForwardSymbol();
}
return symbol;
@ -90,22 +81,27 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
getTypeInfo().setTypeSymbol( type );
}
public TypeInfo getTypeInfo(){
return _typeInfo;
public ITypeInfo getTypeInfo(){
return ( _typeInfo != null ) ? _typeInfo : (_typeInfo = new TypeInfo());
}
public void setTypeInfo( TypeInfo info ) {
public void setTypeInfo( ITypeInfo info ) {
_typeInfo = info;
}
public boolean isForwardDeclaration(){
return getTypeInfo().isForwardDeclaration();
return _isForwardDeclaration;
}
public void setIsForwardDeclaration( boolean forward ){
getTypeInfo().setIsForwardDeclaration( forward );
_isForwardDeclaration = forward;
}
public void setForwardSymbol( ISymbol forward ){
_symbolDef = forward;
}
public ISymbol getForwardSymbol(){
return (_isForwardDeclaration || isType( ITypeInfo.t_namespace) ) ? _symbolDef : null;
}
/**
* returns 0 if same, non zero otherwise
*/
@ -118,10 +114,10 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
} else if( size == 0 )
return 0;
else {
TypeInfo.PtrOp op1 = null, op2 = null;
ITypeInfo.PtrOp op1 = null, op2 = null;
for( int i = 0; i > size; i++ ){
op1 = (TypeInfo.PtrOp)symbol.getTypeInfo().getPtrOperators().get(i);
op2 = (TypeInfo.PtrOp)getTypeInfo().getPtrOperators().get(i);
op1 = (ITypeInfo.PtrOp)symbol.getTypeInfo().getPtrOperators().get(i);
op2 = (ITypeInfo.PtrOp)getTypeInfo().getPtrOperators().get(i);
if( op1.compareCVTo( op2 ) != 0 ){
return -1;
@ -135,7 +131,7 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
public List getPtrOperators(){
return getTypeInfo().getPtrOperators();
}
public void addPtrOperator( TypeInfo.PtrOp ptrOp ){
public void addPtrOperator( ITypeInfo.PtrOp ptrOp ){
getTypeInfo().addPtrOperator( ptrOp );
}
public void preparePtrOperatros(int numPtrOps) {
@ -154,13 +150,13 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
_isTemplateMember = isMember;
}
public boolean isTemplateInstance(){
return ( _instantiatedSymbol != null );
return ( _symbolDef != null );
}
public ISymbol getInstantiatedSymbol(){
return _instantiatedSymbol;
return _symbolDef;
}
public void setInstantiatedSymbol( ISymbol symbol ){
_instantiatedSymbol = symbol;
_symbolDef = symbol;
}
public boolean getIsInvisible(){
@ -171,13 +167,14 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
}
private String _name; //our name
private TypeInfo _typeInfo; //our type info
private ITypeInfo _typeInfo; //our type info
private int _depth; //how far down the scope stack we are
private boolean _isInvisible = false; //used by friend declarations (11.4-9)
private boolean _isTemplateMember = false;
private ISymbol _instantiatedSymbol = null;
private boolean _isForwardDeclaration = false;
private ISymbol _symbolDef = null; //used for forward declarations and template instantiations
/* (non-Javadoc)
@ -186,7 +183,7 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
public Object clone() {
BasicSymbol s = (BasicSymbol) super.clone();
s._typeInfo = new TypeInfo( s._typeInfo );
s._typeInfo = TypeInfoProvider.newTypeInfo( s._typeInfo );
return s;
}
}

View file

@ -0,0 +1,309 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jul 5, 2004
*/
package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
/**
* @author aniefer
*/
public class BasicTypeInfo implements ITypeInfo {
public void setBit( boolean b, int mask ) {
if( b ){
_typeBits = _typeBits | mask;
} else {
_typeBits = _typeBits & ~mask;
}
}
public boolean checkBit( int mask ) {
return (_typeBits & mask) != 0;
}
public void setType( ITypeInfo.eType t ) {
_type = t;
}
public ITypeInfo.eType getType() {
return _type;
}
public boolean isType( ITypeInfo.eType type ) {
return isType( type, t_undef );
}
public int getTypeBits() {
return _typeBits;
}
public void setTypeBits( int typeInfo ) {
_typeBits = typeInfo;
}
/**
*
* @param infoProvider - TypeInfoProvider to use if pooling the TypeInfo created, if null,
* pooling is not used. If pooling is used, TypeInfoProvider.returnTypeInfo
* must be called when the TypeInfo is no longer needed
* @return
*/
public ITypeInfo getFinalType( TypeInfoProvider infoProvider ) {
return ParserSymbolTable.getFlatTypeInfo( this, infoProvider );
}
/**
*
* @param type
* @param upperType
* @return boolean
*
* type checking, check that this declaration's type is between type and
* upperType (inclusive). upperType of 0 means no range and our type must
* be type.
*/
public boolean isType( ITypeInfo.eType type, ITypeInfo.eType upperType ) {
//type of -1 means we don't care
if( type == t_any )
return true;
//upperType of 0 means no range
if( upperType == t_undef ){
return ( getType() == type );
}
return ( getType().compareTo( type ) >= 0 && getType().compareTo( upperType ) <= 0 );
}
public boolean hasPtrOperators() {
return _ptrOperators.size() > 0;
}
public List getPtrOperators() {
return _ptrOperators;
}
public boolean hasSamePtrs( ITypeInfo type ) {
int size = getPtrOperators().size();
int size2 = type.getPtrOperators().size();
ITypeInfo.PtrOp ptr1 = null, ptr2 = null;
if( size == size2 ){
if( size > 0 ){
for( int i = 0; i < size; i++ ){
ptr1 = (ITypeInfo.PtrOp)getPtrOperators().get(i);
ptr2 = (ITypeInfo.PtrOp)type.getPtrOperators().get(i);
if( ptr1.getType() != ptr2.getType() ){
return false;
}
}
}
return true;
}
return false;
}
public void applyOperatorExpression( ITypeInfo.OperatorExpression op ) {
if( op == null )
return;
if( op == ITypeInfo.OperatorExpression.indirection ||
op == ITypeInfo.OperatorExpression.subscript )
{
//indirection operator, can only be applied to a pointer
//subscript should be applied to something that is "pointer to T", the result is a lvalue of type "T"
if( hasPtrOperators() ){
ListIterator iterator = getPtrOperators().listIterator( getPtrOperators().size() );
ITypeInfo.PtrOp last = (ITypeInfo.PtrOp)iterator.previous();
if( last.getType() == ITypeInfo.PtrOp.t_pointer ||
last.getType() == ITypeInfo.PtrOp.t_array )
{
iterator.remove();
}
}
} else if( op == ITypeInfo.OperatorExpression.addressof ){
//Address-of unary operator, results in pointer to T
//TODO or pointer to member
ITypeInfo.PtrOp newOp = new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer );
addPtrOperator( newOp );
}
}
public void addPtrOperator( ITypeInfo.PtrOp ptr ) {
if( ptr != null ){
if( _ptrOperators == Collections.EMPTY_LIST ){
_ptrOperators = new ArrayList(4);
}
_ptrOperators.add( ptr );
}
}
public void addPtrOperator( List ptrs ) {
if( ptrs == null || ptrs.size() == 0 )
return;
if( _ptrOperators == Collections.EMPTY_LIST ){
_ptrOperators = new ArrayList( ptrs.size() );
}
int size = ptrs.size();
for( int i = 0; i < size; i++ ){
_ptrOperators.add( ptrs.get( i ) );
}
}
public void preparePtrOperators( int numPtrOps ) {
if( _ptrOperators == Collections.EMPTY_LIST )
_ptrOperators = new ArrayList( numPtrOps );
else
((ArrayList) _ptrOperators).ensureCapacity( numPtrOps );
}
/**
* canHold
* @param type
* @return boolean
* return true if our type can hold all the values of the passed in
* type.
* TODO, for now return true if our type is "larger" (based on ordering of
* the type values)
*/
public boolean canHold( ITypeInfo type ) {
if( getType().compareTo( type.getType()) > 0 ){
return true;
}
int mask = isShort | isLong | isLongLong;
return ( getTypeBits() & mask ) >= ( type.getTypeBits() & mask );
}
public boolean equals( Object t ) {
if( t == null || !(t instanceof ITypeInfo) ){
return false;
}
ITypeInfo type = (ITypeInfo)t;
boolean result = ( _typeBits == type.getTypeBits() );
result &= ( _type == type.getType() );
// Object def1 = getDefault();
// Object def2 = type.getDefault();
// result &= ( (def1 == null && def2 == null) ||
// (def1 != null && def2 != null && def1.equals( def2 )) );
//
if( !result )
return false;
int size1 = _ptrOperators.size();
int size2 = type.getPtrOperators().size();
if( size1 == size2 ){
if( size1 != 0 ){
ITypeInfo.PtrOp op1 = null, op2 = null;
for( int i = 0; i < size1; i++ ){
op1 = (ITypeInfo.PtrOp)_ptrOperators.get(i);
op2 = (ITypeInfo.PtrOp)type.getPtrOperators().get(i);
if( !op1.equals(op2) ){
return false;
}
}
}
} else {
return false;
}
return result;
}
private static final String _image[] = { "", //$NON-NLS-1$ t_undef
"", //$NON-NLS-1$ t_type
"namespace", //$NON-NLS-1$ t_namespace
"class", //$NON-NLS-1$ t_class
"struct", //$NON-NLS-1$ t_struct
"union", //$NON-NLS-1$ t_union
"enum", //$NON-NLS-1$ t_enumeration
"", //$NON-NLS-1$ t_constructor
"", //$NON-NLS-1$ t_function
"_Bool", //$NON-NLS-1$ t__Bool
"bool", //$NON-NLS-1$ t_bool
"char", //$NON-NLS-1$ t_char
"wchar_t", //$NON-NLS-1$ t_wchar_t
"int", //$NON-NLS-1$ t_int
"float", //$NON-NLS-1$ t_float
"double", //$NON-NLS-1$ t_double
"void", //$NON-NLS-1$ t_void
"", //$NON-NLS-1$ t_enumerator
"", //$NON-NLS-1$ t_block
"template", //$NON-NLS-1$ t_template
"", //$NON-NLS-1$ t_asm
"", //$NON-NLS-1$ t_linkage
"", //$NON-NLS-1$ t_templateParameter
"typename" //$NON-NLS-1$ t_typeName
};
public String toString() {
if( isType( t_type ) && getTypeSymbol() != null ){
return getTypeSymbol().getName();
}
return _image[ getType().toInt() ];
}
public void clear() {
_typeBits = 0;
_type = t_undef;
_ptrOperators = Collections.EMPTY_LIST;
}
public void copy( ITypeInfo t ) {
if( t == null )
return;
_typeBits = t.getTypeBits();
_type = t.getType();
if( t.getPtrOperators() != Collections.EMPTY_LIST )
_ptrOperators = (ArrayList)((ArrayList)t.getPtrOperators()).clone();
else
_ptrOperators = Collections.EMPTY_LIST;
}
public boolean getHasDefault(){
return _hasDefault;
}
public void setHasDefault( boolean def ){
_hasDefault = def;
}
/**
* The following functions are implemented in derived classes
*/
public ITypeInfo.eType getTemplateParameterType() { return ITypeInfo.t_undef; }
public void setTemplateParameterType( ITypeInfo.eType type ) { throw new UnsupportedOperationException(); }
public ISymbol getTypeSymbol() { return null; }
public void setTypeSymbol( ISymbol type ) { if( type != null ) throw new UnsupportedOperationException(); }
public void setDefault( Object t ) { if( t != null ) throw new UnsupportedOperationException(); }
public Object getDefault() { return null; }
protected int _typeBits = 0;
protected ITypeInfo.eType _type = t_undef;
protected List _ptrOperators = Collections.EMPTY_LIST;
protected boolean _hasDefault = false;
}

View file

@ -47,11 +47,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
super( table, name );
}
protected ContainerSymbol( ParserSymbolTable table, String name, ISymbolASTExtension obj ){
super( table, name, obj );
}
protected ContainerSymbol( ParserSymbolTable table, String name, TypeInfo.eType typeInfo ){
protected ContainerSymbol( ParserSymbolTable table, String name, ITypeInfo.eType typeInfo ){
super( table, name, typeInfo );
}
@ -93,7 +89,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
newContainer._contents.add( containedSymbol );
} else {
ISymbol symbol = (ISymbol) containedSymbol;
if( symbol.isForwardDeclaration() && symbol.getTypeSymbol() != null ){
if( symbol.isForwardDeclaration() && symbol.getForwardSymbol() != null ){
continue;
}
@ -134,7 +130,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
newSymbol.setContainingSymbol( newContainer );
newContainer._contents.add( newSymbol );
if( newSymbol instanceof IParameterizedSymbol && newSymbol.isType( TypeInfo.t_constructor ) ){
if( newSymbol instanceof IParameterizedSymbol && newSymbol.isType( ITypeInfo.t_constructor ) ){
collectInstantiatedConstructor( (IParameterizedSymbol) containedSymbol );
} else {
if( newContainer.getContainedSymbols().containsKey( newSymbol.getName() ) ){
@ -168,10 +164,10 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
IContainerSymbol containing = this;
//handle enumerators
if( obj.getType() == TypeInfo.t_enumerator ){
if( obj.getType() == ITypeInfo.t_enumerator ){
//a using declaration of an enumerator will not be contained in a
//enumeration.
if( containing.getType() == TypeInfo.t_enumeration ){
if( containing.getType() == ITypeInfo.t_enumeration ){
//Following the closing brace of an enum-specifier, each enumerator has the type of its
//enumeration
obj.setTypeSymbol( containing );
@ -180,7 +176,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
}
}
if( obj.isType( TypeInfo.t_template ) ){
if( obj.isType( ITypeInfo.t_template ) ){
if( ! TemplateEngine.canAddTemplate( containing, (ITemplateSymbol) obj ) ) {
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
}
@ -188,13 +184,13 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
//in C, structs, unions, enums don't nest
if( getSymbolTable().getLanguage() == ParserLanguage.C ){
if( obj.isType( TypeInfo.t_struct, TypeInfo.t_enumeration ) ){
if( obj.isType( ITypeInfo.t_struct, ITypeInfo.t_enumeration ) ){
containing = getScopeForCTag( containing );
}
}
//14.6.1-4 A Template parameter shall not be redeclared within its scope.
if( isTemplateMember() || isType( TypeInfo.t_template ) ){
if( isTemplateMember() || isType( ITypeInfo.t_template ) ){
if( TemplateEngine.alreadyHasTemplateParameter( this, obj.getName() ) ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_RedeclaredTemplateParam );
}
@ -245,7 +241,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
((ContainerSymbol)containing).putInContainedSymbols( obj.getName(), obj );
}
obj.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template );
obj.setIsTemplateMember( isTemplateMember() || getType() == ITypeInfo.t_template );
addToContents( obj );
@ -312,17 +308,17 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDirective(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol)
*/
public IUsingDirectiveSymbol addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException{
if( namespace.getType() != TypeInfo.t_namespace ){
if( namespace.getType() != ITypeInfo.t_namespace ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing );
}
//7.3.4 A using-directive shall not appear in class scope
if( isType( TypeInfo.t_class, TypeInfo.t_union ) ){
if( isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing );
}
//handle namespace aliasing
ISymbol alias = namespace.getTypeSymbol();
if( alias != null && alias.isType( TypeInfo.t_namespace ) ){
ISymbol alias = namespace.getForwardSymbol();
if( alias != null && alias.isType( ITypeInfo.t_namespace ) ){
namespace = (IContainerSymbol) alias;
}
@ -450,15 +446,15 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#elaboratedLookup(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType, java.lang.String)
*/
public ISymbol elaboratedLookup( final TypeInfo.eType type, String name ) throws ParserSymbolTableException{
public ISymbol elaboratedLookup( final ITypeInfo.eType type, String name ) throws ParserSymbolTableException{
LookupData data = new LookupData( name ){
public TypeFilter getFilter() {
if( t == TypeInfo.t_any ) return ANY_FILTER;
if( t == ITypeInfo.t_any ) return ANY_FILTER;
if( filter == null ) filter = new TypeFilter( t );
return filter;
}
private TypeFilter filter = null;
private final TypeInfo.eType t = type;
private final ITypeInfo.eType t = type;
};
ParserSymbolTable.lookup( data, this );
@ -537,9 +533,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
IContainerSymbol container = this;
//handle namespace aliases
if( container.isType( TypeInfo.t_namespace ) ){
ISymbol symbol = container.getTypeSymbol();
if( symbol != null && symbol.isType( TypeInfo.t_namespace ) ){
if( container.isType( ITypeInfo.t_namespace ) ){
ISymbol symbol = container.getForwardSymbol();
if( symbol != null && symbol.isType( ITypeInfo.t_namespace ) ){
container = (IContainerSymbol) symbol;
}
}
@ -561,9 +557,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
IContainerSymbol container = this;
//handle namespace aliases
if( container.isType( TypeInfo.t_namespace ) ){
ISymbol symbol = container.getTypeSymbol();
if( symbol != null && symbol.isType( TypeInfo.t_namespace ) ){
if( container.isType( ITypeInfo.t_namespace ) ){
ISymbol symbol = container.getForwardSymbol();
if( symbol != null && symbol.isType( ITypeInfo.t_namespace ) ){
container = (IContainerSymbol) symbol;
}
}
@ -596,10 +592,10 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
private IContainerSymbol lookupNestedNameSpecifier(String name, IContainerSymbol inSymbol ) throws ParserSymbolTableException{
ISymbol foundSymbol = null;
final TypeFilter filter = new TypeFilter( TypeInfo.t_namespace );
filter.addAcceptedType( TypeInfo.t_class );
filter.addAcceptedType( TypeInfo.t_struct );
filter.addAcceptedType( TypeInfo.t_union );
final TypeFilter filter = new TypeFilter( ITypeInfo.t_namespace );
filter.addAcceptedType( ITypeInfo.t_class );
filter.addAcceptedType( ITypeInfo.t_struct );
filter.addAcceptedType( ITypeInfo.t_union );
LookupData data = new LookupData( name ){
public TypeFilter getFilter() { return typeFilter; }
@ -636,10 +632,10 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedLookup(java.lang.String, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType)
*/
public ISymbol qualifiedLookup( String name, final TypeInfo.eType t ) throws ParserSymbolTableException{
public ISymbol qualifiedLookup( String name, final ITypeInfo.eType t ) throws ParserSymbolTableException{
LookupData data = new LookupData( name ){
public TypeFilter getFilter() {
if( t == TypeInfo.t_any ) return ANY_FILTER;
if( t == ITypeInfo.t_any ) return ANY_FILTER;
if( filter == null )
filter = new TypeFilter( t );
@ -687,11 +683,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
//collect associated namespaces & classes.
int size = ( parameters == null ) ? 0 : parameters.size();
TypeInfo param = null;
ITypeInfo param = null;
ISymbol paramType = null;
for( int i = 0; i < size; i++ ){
param = (TypeInfo) parameters.get(i);
TypeInfo info = ParserSymbolTable.getFlatTypeInfo( param, getSymbolTable().getTypeInfoProvider() );
param = (ITypeInfo) parameters.get(i);
ITypeInfo info = ParserSymbolTable.getFlatTypeInfo( param, getSymbolTable().getTypeInfoProvider() );
paramType = info.getTypeSymbol();
getSymbolTable().getTypeInfoProvider().returnTypeInfo( info );
@ -704,9 +700,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
//if T is a pointer to a data member of class X, its associated namespaces and classes
//are those associated with the member type together with those associated with X
if( param.hasPtrOperators() && param.getPtrOperators().size() == 1 ){
TypeInfo.PtrOp op = (TypeInfo.PtrOp)param.getPtrOperators().get(0);
if( op.getType() == TypeInfo.PtrOp.t_pointer &&
paramType.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) )
ITypeInfo.PtrOp op = (ITypeInfo.PtrOp)param.getPtrOperators().get(0);
if( op.getType() == ITypeInfo.PtrOp.t_pointer &&
paramType.getContainingSymbol().isType( ITypeInfo.t_class, ITypeInfo.t_union ) )
{
ParserSymbolTable.getAssociatedScopes( paramType.getContainingSymbol(), associated );
}
@ -728,7 +724,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
//if we haven't found anything, or what we found is not a class member, consider the
//associated scopes
if( found == null || found.getContainingSymbol().getType() != TypeInfo.t_class ){
if( found == null || found.getContainingSymbol().getType() != ITypeInfo.t_class ){
// if( found != null ){
// data.foundItems.add( found );
// }
@ -808,11 +804,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
ParserSymbolTable.lookup( data, this );
ISymbol found = getSymbolTable().resolveAmbiguities( data );
if( found != null ){
if( (found.isType( TypeInfo.t_templateParameter ) && found.getTypeInfo().getTemplateParameterType() == TypeInfo.t_template) ||
found.isType( TypeInfo.t_template ) )
if( (found.isType( ITypeInfo.t_templateParameter ) && found.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template) ||
found.isType( ITypeInfo.t_template ) )
{
found = ((ITemplateSymbol) found).instantiate( arguments );
} else if( found.getContainingSymbol().isType( TypeInfo.t_template ) ){
} else if( found.getContainingSymbol().isType( ITypeInfo.t_template ) ){
found = ((ITemplateSymbol) found.getContainingSymbol()).instantiate( arguments );
}
}
@ -872,7 +868,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
ParserSymbolTable.lookup( data, this );
List constructors = null;
if( filter != null && filter.willAccept( TypeInfo.t_constructor ) && (this instanceof IDerivableContainerSymbol) ){
if( filter != null && filter.willAccept( ITypeInfo.t_constructor ) && (this instanceof IDerivableContainerSymbol) ){
if( getName().startsWith( prefix ) ){
List temp = ((IDerivableContainerSymbol)this).getConstructors();
int size = temp.size();
@ -914,7 +910,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
getSymbolTable().resolveFunction( data, (List) obj );
list.addAll( (List) obj );
} else{
if( paramList != null && ((ISymbol)obj).isType( TypeInfo.t_function ) )
if( paramList != null && ((ISymbol)obj).isType( ITypeInfo.t_function ) )
{
if( tempList == null )
tempList = new ArrayList(1);
@ -958,7 +954,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
IContainerSymbol container = getContainingSymbol();
IContainerSymbol symbolContainer = symbol.getContainingSymbol();
if( !symbolContainer.isType( TypeInfo.t_class, TypeInfo.t_union ) ||
if( !symbolContainer.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ||
symbolContainer.equals( container ) )
{
return true;
@ -986,10 +982,10 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
if( symbol instanceof IDerivableContainerSymbol ){
IContainerSymbol container = this.getContainingSymbol();
while( container != null && container.isType( TypeInfo.t_block ) ){
while( container != null && container.isType( ITypeInfo.t_block ) ){
container = container.getContainingSymbol();
}
if( container != null && !container.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
if( container != null && !container.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){
container = null;
}
@ -999,9 +995,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
int size = friends.size();
for( int i = 0; i < size; i++ ){
ISymbol friend = (ISymbol) friends.get(i);
ISymbol typeSymbol = friend.getTypeSymbol();
if( friend == this || typeSymbol == this ||
friend == container || ( container != null && typeSymbol == container ) )
ISymbol forwardSymbol = friend.getForwardSymbol();
if( friend == this || forwardSymbol == this ||
friend == container || ( container != null && forwardSymbol == container ) )
{
return true;
}
@ -1011,9 +1007,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
}
private IContainerSymbol getScopeForCTag( IContainerSymbol container ){
while( !container.isType( TypeInfo.t_namespace ) &&
!container.isType( TypeInfo.t_function ) &&
!container.isType( TypeInfo.t_block ) )
while( !container.isType( ITypeInfo.t_namespace ) &&
!container.isType( ITypeInfo.t_function ) &&
!container.isType( ITypeInfo.t_block ) )
{
container = container.getContainingSymbol();
}
@ -1022,11 +1018,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
protected void addToContents( IExtensibleSymbol symbol ){
if( _contents == Collections.EMPTY_LIST ){
if( isType( TypeInfo.t_namespace ) )
if( isType( ITypeInfo.t_namespace ) )
_contents = new ArrayList( 64 );
else if( isType( TypeInfo.t_class ) || isType( TypeInfo.t_struct ) )
else if( isType( ITypeInfo.t_class ) || isType( ITypeInfo.t_struct ) )
_contents = new ArrayList( 32 );
else if( isType( TypeInfo.t_function ) )
else if( isType( ITypeInfo.t_function ) )
_contents = new ArrayList( 16 );
else
_contents = new ArrayList( 8 );
@ -1063,11 +1059,12 @@ 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 )
ISymbol forward = symbol.getForwardSymbol();
if( symbol.isForwardDeclaration() && forward != null &&
forward.getContainingSymbol() == ContainerSymbol.this )
{
alreadyReturned.add( symbol.getTypeSymbol() );
next = symbol.getTypeSymbol();
alreadyReturned.add( forward );
next = forward;
return true;
}
} else if( extensible instanceof IUsingDeclarationSymbol ){

View file

@ -52,13 +52,13 @@ public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTe
List newArgs = new ArrayList( args.size() );
int size = args.size();
for( int i = 0; i < size; i++ ){
TypeInfo arg = (TypeInfo) args.get(i);
ITypeInfo arg = (ITypeInfo) args.get(i);
newArgs.add( TemplateEngine.instantiateTypeInfo( arg, template, argMap ) );
}
ITemplateSymbol deferredTemplate = getTemplate();
if( deferredTemplate.isType( TypeInfo.t_templateParameter ) && argMap.containsKey( deferredTemplate ) ){
TypeInfo i = (TypeInfo) argMap.get( deferredTemplate );
if( deferredTemplate.isType( ITypeInfo.t_templateParameter ) && argMap.containsKey( deferredTemplate ) ){
ITypeInfo i = (ITypeInfo) argMap.get( deferredTemplate );
deferredTemplate = (ITemplateSymbol) i.getTypeSymbol();
}
@ -69,7 +69,7 @@ public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTe
return instance;
}
public boolean isType( TypeInfo.eType type, TypeInfo.eType upperType ){
public boolean isType( ITypeInfo.eType type, ITypeInfo.eType upperType ){
ISymbol symbol = _template.getTemplatedSymbol();
if( symbol != null )
return symbol.isType( type, upperType );
@ -77,21 +77,21 @@ public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTe
}
public TypeInfo.eType getType(){
public ITypeInfo.eType getType(){
ISymbol symbol = _template.getTemplatedSymbol();
if( symbol != null )
return symbol.getType();
return super.getType();
}
public TypeInfo getTypeInfo(){
public ITypeInfo getTypeInfo(){
ISymbol symbol = _template.getTemplatedSymbol();
if( symbol != null )
return symbol.getTypeInfo();
return super.getTypeInfo();
}
public boolean isType( TypeInfo.eType type ){
public boolean isType( ITypeInfo.eType type ){
return _template.getTemplatedSymbol().isType( type );
}

View file

@ -34,12 +34,8 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
protected DerivableContainerSymbol( ParserSymbolTable table, String name ){
super( table, name );
}
protected DerivableContainerSymbol( ParserSymbolTable table, String name, ISymbolASTExtension obj ){
super( table, name, obj );
}
protected DerivableContainerSymbol( ParserSymbolTable table, String name, TypeInfo.eType typeInfo ){
protected DerivableContainerSymbol( ParserSymbolTable table, String name, ITypeInfo.eType typeInfo ){
super( table, name, typeInfo );
}
@ -73,8 +69,8 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
if( parent instanceof IDeferredTemplateInstance ){
template.registerDeferredInstatiation( newSymbol, parent, ITemplateSymbol.DeferredKind.PARENT, argMap );
} else if( parent.isType( TypeInfo.t_templateParameter ) && argMap.containsKey( parent ) ){
TypeInfo info = (TypeInfo) argMap.get( parent );
} else if( parent.isType( ITypeInfo.t_templateParameter ) && argMap.containsKey( parent ) ){
ITypeInfo info = (ITypeInfo) argMap.get( parent );
parent = info.getTypeSymbol();
}
newSymbol.addParent( parent, wrapper.isVirtual(), wrapper.getAccess(), wrapper.getOffset(), wrapper.getReferences() );
@ -119,7 +115,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
}
protected void collectInstantiatedConstructor( IParameterizedSymbol constructor ){
if( constructor.isType( TypeInfo.t_constructor ) )
if( constructor.isType( ITypeInfo.t_constructor ) )
addToConstructors( constructor );
}
@ -172,7 +168,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addConstructor(org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol)
*/
public void addConstructor(IParameterizedSymbol constructor) throws ParserSymbolTableException {
if( !constructor.isType( TypeInfo.t_constructor ) )
if( !constructor.isType( ITypeInfo.t_constructor ) )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
List constructors = getConstructors();
@ -184,7 +180,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
}
constructor.setContainingSymbol( this );
constructor.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template );
constructor.setIsTemplateMember( isTemplateMember() || getType() == ITypeInfo.t_template );
addThis( constructor );
@ -205,24 +201,25 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
paramType = TemplateEngine.instantiateWithinTemplateScope( this, (ITemplateSymbol) getContainingSymbol() );
}
TypeInfo param = getSymbolTable().getTypeInfoProvider().getTypeInfo();
param.setType( TypeInfo.t_type );
param.setBit( true, TypeInfo.isConst );
ITypeInfo param = TypeInfoProvider.getProvider(getSymbolTable()).getTypeInfo( ITypeInfo.t_type );
param.setType( ITypeInfo.t_type );
param.setBit( true, ITypeInfo.isConst );
param.setTypeSymbol( paramType );
param.addPtrOperator( new TypeInfo.PtrOp( TypeInfo.PtrOp.t_reference, false, false ) );
param.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, false, false ) );
parameters.add( param );
IParameterizedSymbol constructor = null;
try{
constructor = lookupConstructor( parameters );
} catch ( ParserSymbolTableException e ){
/* nothing */
} finally {
getSymbolTable().getTypeInfoProvider().returnTypeInfo( param );
}
if( constructor == null ){
constructor = getSymbolTable().newParameterizedSymbol( getName(), TypeInfo.t_constructor );
constructor.addParameter( this, TypeInfo.isConst, new TypeInfo.PtrOp( TypeInfo.PtrOp.t_reference, false, false ), false );
constructor = getSymbolTable().newParameterizedSymbol( getName(), ITypeInfo.t_constructor );
constructor.addParameter( this, ITypeInfo.isConst, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, false, false ), false );
addConstructor( constructor );
}
@ -274,13 +271,13 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
return false;
}
TypeInfo type = obj.getTypeInfo();
if( ( !type.isType( TypeInfo.t_function ) && !type.isType( TypeInfo.t_constructor) ) ||
type.checkBit( TypeInfo.isStatic ) ){
ITypeInfo type = obj.getTypeInfo();
if( ( !type.isType( ITypeInfo.t_function ) && !type.isType( ITypeInfo.t_constructor) ) ||
type.checkBit( ITypeInfo.isStatic ) ){
return false;
}
if( obj.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) ){
if( obj.getContainingSymbol().isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){
//check to see if there is already a this object, since using declarations
//of function will have them from the original declaration
boolean foundThis = false;
@ -296,13 +293,13 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
//if we didn't find "this" then foundItems will still be null, no need to actually
//check its contents
if( !foundThis ){
ISymbol thisObj = getSymbolTable().newSymbol( ParserSymbolTable.THIS, TypeInfo.t_type );
ISymbol thisObj = getSymbolTable().newSymbol( ParserSymbolTable.THIS, ITypeInfo.t_type );
thisObj.setTypeSymbol( obj.getContainingSymbol() );
//thisObj.setCVQualifier( obj.getCVQualifier() );
TypeInfo.PtrOp ptr = new TypeInfo.PtrOp();
ptr.setType( TypeInfo.PtrOp.t_pointer );
thisObj.getTypeInfo().setBit( obj.getTypeInfo().checkBit( TypeInfo.isConst ), TypeInfo.isConst );
thisObj.getTypeInfo().setBit( obj.getTypeInfo().checkBit( TypeInfo.isVolatile ), TypeInfo.isVolatile );
ITypeInfo.PtrOp ptr = new ITypeInfo.PtrOp();
ptr.setType( ITypeInfo.PtrOp.t_pointer );
thisObj.getTypeInfo().setBit( obj.getTypeInfo().checkBit( ITypeInfo.isConst ), ITypeInfo.isConst );
thisObj.getTypeInfo().setBit( obj.getTypeInfo().checkBit( ITypeInfo.isVolatile ), ITypeInfo.isVolatile );
thisObj.addPtrOperator(ptr);
@ -336,11 +333,11 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
//its not, it goes in the innermost enclosing namespace
IContainerSymbol enclosing = getContainingSymbol();
boolean local = enclosing.isType( TypeInfo.t_constructor ) ||
enclosing.isType( TypeInfo.t_function ) ||
enclosing.isType( TypeInfo.t_block );
boolean local = enclosing.isType( ITypeInfo.t_constructor ) ||
enclosing.isType( ITypeInfo.t_function ) ||
enclosing.isType( ITypeInfo.t_block );
while( enclosing != null && !enclosing.isType( TypeInfo.t_namespace ) ){
while( enclosing != null && !enclosing.isType( ITypeInfo.t_namespace ) ){
enclosing = enclosing.getContainingSymbol();
}
@ -349,6 +346,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
try {
enclosing.addSymbol( friend );
} catch (ParserSymbolTableException e) {
/* nothing */
}
}
@ -369,8 +367,8 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
*/
public ISymbol lookupForFriendship( String name ) throws ParserSymbolTableException{
IContainerSymbol enclosing = getContainingSymbol();
if( enclosing != null && enclosing.isType( TypeInfo.t_namespace, TypeInfo.t_union ) ){
while( enclosing != null && ( enclosing.getType() != TypeInfo.t_namespace) )
if( enclosing != null && enclosing.isType( ITypeInfo.t_namespace, ITypeInfo.t_union ) ){
while( enclosing != null && ( enclosing.getType() != ITypeInfo.t_namespace) )
{
enclosing = enclosing.getContainingSymbol();
}
@ -391,8 +389,8 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
IContainerSymbol enclosing = getContainingSymbol();
if( enclosing != null && enclosing.isType( TypeInfo.t_namespace, TypeInfo.t_union ) ){
while( enclosing != null && ( enclosing.getType() != TypeInfo.t_namespace) )
if( enclosing != null && enclosing.isType( ITypeInfo.t_namespace, ITypeInfo.t_union ) ){
while( enclosing != null && ( enclosing.getType() != ITypeInfo.t_namespace) )
{
enclosing = enclosing.getContainingSymbol();
}

View file

@ -98,13 +98,13 @@ public interface IContainerSymbol extends ISymbol {
* IDerivableContainerSymbol
* r_CircularInheritance if during lookup of the name, we come across a class with a circular inheritance tree
*/
public ISymbol elaboratedLookup( TypeInfo.eType type, String name ) throws ParserSymbolTableException;
public ISymbol elaboratedLookup( ITypeInfo.eType type, String name ) throws ParserSymbolTableException;
public ISymbol lookup( String name ) throws ParserSymbolTableException;
public ISymbol lookupMemberForDefinition( String name ) throws ParserSymbolTableException;
public IParameterizedSymbol lookupMethodForDefinition( String name, List parameters ) throws ParserSymbolTableException;
public IContainerSymbol lookupNestedNameSpecifier( String name ) throws ParserSymbolTableException;
public ISymbol qualifiedLookup( String name ) throws ParserSymbolTableException;
public ISymbol qualifiedLookup( String name, TypeInfo.eType t ) throws ParserSymbolTableException;
public ISymbol qualifiedLookup( String name, ITypeInfo.eType t ) throws ParserSymbolTableException;
public IParameterizedSymbol unqualifiedFunctionLookup( String name, List parameters ) throws ParserSymbolTableException;
public IParameterizedSymbol memberFunctionLookup( String name, List parameters ) throws ParserSymbolTableException;
public IParameterizedSymbol qualifiedFunctionLookup( String name, List parameters ) throws ParserSymbolTableException;

View file

@ -29,8 +29,8 @@ import java.util.Map;
public interface IParameterizedSymbol extends IContainerSymbol {
public void addParameter( ISymbol param );
public void addParameter( TypeInfo.eType type, int info, TypeInfo.PtrOp ptrOp, boolean hasDefault );
public void addParameter( ISymbol typeSymbol, int info, TypeInfo.PtrOp ptrOp, boolean hasDefault );
public void addParameter( ITypeInfo.eType type, int info, ITypeInfo.PtrOp ptrOp, boolean hasDefault );
public void addParameter( ISymbol typeSymbol, int info, ITypeInfo.PtrOp ptrOp, boolean hasDefault );
public Map getParameterMap();
public List getParameterList();

View file

@ -26,7 +26,7 @@ import java.util.List;
*/
public interface ISpecializedSymbol extends ITemplateSymbol {
public void addArgument( TypeInfo arg );
public void addArgument( ITypeInfo arg );
public List getArgumentList();

View file

@ -39,21 +39,23 @@ public interface ISymbol extends Cloneable, IExtensibleSymbol {
public IContainerSymbol getContainingSymbol();
public void setContainingSymbol( IContainerSymbol containing );
public boolean isType( TypeInfo.eType type );
public boolean isType( TypeInfo.eType type, TypeInfo.eType upperType );
public TypeInfo.eType getType();
public void setType(TypeInfo.eType t);
public TypeInfo getTypeInfo();
public void setTypeInfo( TypeInfo info );
public boolean isType( ITypeInfo.eType type );
public boolean isType( ITypeInfo.eType type, ITypeInfo.eType upperType );
public ITypeInfo.eType getType();
public void setType(ITypeInfo.eType t);
public ITypeInfo getTypeInfo();
public void setTypeInfo( ITypeInfo info );
public ISymbol getTypeSymbol();
public void setTypeSymbol( ISymbol type );
public boolean isForwardDeclaration();
public void setIsForwardDeclaration( boolean forward );
public void setForwardSymbol( ISymbol forward );
public ISymbol getForwardSymbol();
public int compareCVQualifiersTo( ISymbol symbol );
public List getPtrOperators();
public void addPtrOperator( TypeInfo.PtrOp ptrOp );
public void addPtrOperator( ITypeInfo.PtrOp ptrOp );
public boolean isTemplateInstance();
public ISymbol getInstantiatedSymbol();

View file

@ -0,0 +1,254 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jul 5, 2004
*/
package org.eclipse.cdt.internal.core.parser.pst;
import java.util.List;
import org.eclipse.cdt.core.parser.Enum;
/**
* @author aniefer
*/
public interface ITypeInfo {
public static class OperatorExpression extends Enum{
//5.3.1-1 : The unary * operator, the expression to which it is applied shall be
//a pointer to an object type or a pointer to a function type and the result
//is an lvalue refering to the object or function to which the expression points
public static final OperatorExpression indirection = new OperatorExpression( 1 );
//5.3.1-2 : The result of the unary & operator is a pointer to its operand
public static final OperatorExpression addressof = new OperatorExpression( 0 );
//5.2.1 A postfix expression followed by an expression in square brackets is a postfix
//expression. one of the expressions shall have the type "pointer to T" and the other
//shall have a enumeration or integral type. The result is an lvalue of type "T"
public static final OperatorExpression subscript = new OperatorExpression( 2 );
protected OperatorExpression(int enumValue) {
super(enumValue);
}
}
public static class PtrOp {
public PtrOp( eType type ){
this.type = type;
}
public PtrOp( eType type, boolean isConst, boolean isVolatile ){
this.type = type;
this.isConstPtr = isConst;
this.isVolatilePtr = isVolatile;
}
public PtrOp( ISymbol memberOf, boolean isConst, boolean isVolatile ){
this.type = PtrOp.t_memberPointer;
this.isConstPtr = isConst;
this.isVolatilePtr = isVolatile;
this.memberOf = memberOf;
}
public PtrOp(){
super();
}
public static final eType t_undef_ptr = new eType( 0 );
public static final eType t_pointer = new eType( 1 );
public static final eType t_reference = new eType( 2 );
public static final eType t_array = new eType( 3 );
public static final eType t_memberPointer = new eType( 4 );
public eType getType() { return type; }
public void setType( eType type ) { this.type = type; }
public boolean isConst() { return isConstPtr; }
public boolean isVolatile() { return isVolatilePtr; }
public void setConst( boolean isConst ) { this.isConstPtr = isConst; }
public void setVolatile(boolean isVolatile) { this.isVolatilePtr = isVolatile; }
public ISymbol getMemberOf() { return memberOf; }
public void setMemberOf( ISymbol member ) { this.memberOf = member; }
public int compareCVTo( ITypeInfo.PtrOp ptr ){
int cv1 = ( isConst() ? 1 : 0 ) + ( isVolatile() ? 1 : 0 );
int cv2 = ( ptr.isConst() ? 1 : 0 ) + ( ptr.isVolatile() ? 1 : 0 );
return cv1 - cv2;
}
public boolean equals( Object o ){
if( o == null || !(o instanceof ITypeInfo.PtrOp) ){
return false;
}
ITypeInfo.PtrOp op = (ITypeInfo.PtrOp)o;
return ( isConst() == op.isConst() &&
isVolatile() == op.isVolatile() &&
getType() == op.getType() );
}
private eType type = PtrOp.t_undef_ptr;
private boolean isConstPtr = false;
private boolean isVolatilePtr = false;
private ISymbol memberOf = null;
}
public static class eType extends Enum implements Comparable{
protected eType( int v ){
super( v );
}
public int compareTo( Object o ){
ITypeInfo.eType t = (ITypeInfo.eType) o;
return getEnumValue() - t.getEnumValue();
}
public int toInt() {
return getEnumValue();
}
}
public static final int isAuto = 1 << 0;
public static final int isRegister = 1 << 1;
public static final int isStatic = 1 << 2;
public static final int isExtern = 1 << 3;
public static final int isMutable = 1 << 4;
public static final int isInline = 1 << 5;
public static final int isVirtual = 1 << 6;
public static final int isExplicit = 1 << 7;
public static final int isTypedef = 1 << 8;
public static final int isFriend = 1 << 9;
public static final int isConst = 1 << 10;
public static final int isVolatile = 1 << 11;
public static final int isUnsigned = 1 << 12;
public static final int isShort = 1 << 13;
public static final int isLong = 1 << 14;
public static final int isForward = 1 << 15;
public static final int isComplex = 1 << 16;
public static final int isImaginary = 1 << 17;
public static final int isLongLong = 1 << 18;
public static final int isSigned = 1 << 19;
// Types
// Note that these should be considered ordered and if you change
// the order, you should consider the ParserSymbolTable uses
public static final ITypeInfo.eType t_any = new ITypeInfo.eType( -1 ); //don't care
public static final ITypeInfo.eType t_undef = new ITypeInfo.eType( 0 ); //not specified
public static final ITypeInfo.eType t_type = new ITypeInfo.eType( 1 ); //Type Specifier
public static final ITypeInfo.eType t_namespace = new ITypeInfo.eType( 2 );
public static final ITypeInfo.eType t_class = new ITypeInfo.eType( 3 );
public static final ITypeInfo.eType t_struct = new ITypeInfo.eType( 4 );
public static final ITypeInfo.eType t_union = new ITypeInfo.eType( 5 );
public static final ITypeInfo.eType t_enumeration = new ITypeInfo.eType( 6 );
public static final ITypeInfo.eType t_constructor = new ITypeInfo.eType( 7 );
public static final ITypeInfo.eType t_function = new ITypeInfo.eType( 8 );
public static final ITypeInfo.eType t__Bool = new ITypeInfo.eType( 9 );
public static final ITypeInfo.eType t_bool = new ITypeInfo.eType( 10 );
public static final ITypeInfo.eType t_char = new ITypeInfo.eType( 11 );
public static final ITypeInfo.eType t_wchar_t = new ITypeInfo.eType( 12 );
public static final ITypeInfo.eType t_int = new ITypeInfo.eType( 13 );
public static final ITypeInfo.eType t_float = new ITypeInfo.eType( 14 );
public static final ITypeInfo.eType t_double = new ITypeInfo.eType( 15 );
public static final ITypeInfo.eType t_void = new ITypeInfo.eType( 16 );
public static final ITypeInfo.eType t_enumerator = new ITypeInfo.eType( 17 );
public static final ITypeInfo.eType t_block = new ITypeInfo.eType( 18 );
public static final ITypeInfo.eType t_template = new ITypeInfo.eType( 19 );
public static final ITypeInfo.eType t_asm = new ITypeInfo.eType( 20 );
public static final ITypeInfo.eType t_linkage = new ITypeInfo.eType( 21 );
public static final ITypeInfo.eType t_templateParameter = new ITypeInfo.eType( 22 );
public static final ITypeInfo.eType t_typeName = new ITypeInfo.eType( 23 );
public abstract void setBit( boolean b, int mask );
public abstract boolean checkBit( int mask );
public abstract void setType( ITypeInfo.eType t );
public abstract ITypeInfo.eType getType();
public abstract boolean isType( ITypeInfo.eType type );
public abstract int getTypeBits();
public abstract void setTypeBits( int typeInfo );
public abstract ITypeInfo.eType getTemplateParameterType();
public abstract void setTemplateParameterType( ITypeInfo.eType type );
/**
*
* @param infoProvider - TypeInfoProvider to use if pooling the TypeInfo created, if null,
* pooling is not used. If pooling is used, TypeInfoProvider.returnTypeInfo
* must be called when the TypeInfo is no longer needed
* @return
*/
public abstract ITypeInfo getFinalType( TypeInfoProvider infoProvider );
/**
*
* @param type
* @param upperType
* @return boolean
*
* type checking, check that this declaration's type is between type and
* upperType (inclusive). upperType of 0 means no range and our type must
* be type.
*/
public abstract boolean isType( ITypeInfo.eType type,
ITypeInfo.eType upperType );
public abstract ISymbol getTypeSymbol();
public abstract void setTypeSymbol( ISymbol type );
public abstract boolean hasPtrOperators();
public abstract List getPtrOperators();
public abstract boolean hasSamePtrs( ITypeInfo type );
public abstract void applyOperatorExpression( ITypeInfo.OperatorExpression op );
public abstract void addPtrOperator( ITypeInfo.PtrOp ptr );
public abstract void addPtrOperator( List ptrs );
public abstract void preparePtrOperators( int numPtrOps );
public abstract boolean getHasDefault();
public abstract void setHasDefault( boolean def );
public abstract void setDefault( Object t );
public abstract Object getDefault();
/**
* canHold
* @param type
* @return boolean
* return true if our type can hold all the values of the passed in
* type.
* TODO, for now return true if our type is "larger" (based on ordering of
* the type values)
*/
public abstract boolean canHold( ITypeInfo type );
public abstract boolean equals( Object t );
public abstract String toString();
public abstract void clear();
public abstract void copy( ITypeInfo t );
}

View file

@ -22,8 +22,6 @@ import java.util.Map;
import java.util.TreeMap;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TypeInfoProvider;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
/**
* @author aniefer
@ -37,11 +35,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
super( table, name );
}
protected ParameterizedSymbol( ParserSymbolTable table, String name, ISymbolASTExtension obj ){
super( table, name, obj );
}
protected ParameterizedSymbol( ParserSymbolTable table, String name, TypeInfo.eType typeInfo ){
protected ParameterizedSymbol( ParserSymbolTable table, String name, ITypeInfo.eType typeInfo ){
super( table, name, typeInfo );
}
@ -66,10 +60,10 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
ParameterizedSymbol newParameterized = (ParameterizedSymbol) super.instantiate( template, argMap );
if( _returnType != null ){
if( _returnType.isType( TypeInfo.t_templateParameter ) ){
if( _returnType.isType( ITypeInfo.t_templateParameter ) ){
if( argMap.containsKey( _returnType ) ){
newParameterized.setReturnType( getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME ) );
newParameterized.getReturnType().setTypeInfo( (TypeInfo) argMap.get( _returnType ) );
newParameterized.getReturnType().setTypeInfo( (ITypeInfo) argMap.get( _returnType ) );
newParameterized.getReturnType().setInstantiatedSymbol( _returnType );
}
} else {
@ -81,7 +75,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
}
//handle template parameter lists in TemplateSymbol, only do function parameter lists here.
if( !isType( TypeInfo.t_template ) ){
if( !isType( ITypeInfo.t_template ) ){
List params = getParameterList();
int size = params.size();
@ -148,7 +142,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
}
param.setContainingSymbol( this );
param.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template );
param.setIsTemplateMember( isTemplateMember() || getType() == ITypeInfo.t_template );
// Command command = new AddParameterCommand( this, param );
// getSymbolTable().pushCommand( command );
@ -157,14 +151,11 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType, int, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp, boolean)
*/
public void addParameter( TypeInfo.eType type, int info, TypeInfo.PtrOp ptrOp, boolean hasDefault ){
public void addParameter( ITypeInfo.eType type, int info, ITypeInfo.PtrOp ptrOp, boolean hasDefault ){
BasicSymbol param = new BasicSymbol(getSymbolTable(), ParserSymbolTable.EMPTY_NAME);
TypeInfo t = param.getTypeInfo();
t.setTypeInfo( info );
t.setType( type );
t.addPtrOperator( ptrOp );
t.setHasDefault( hasDefault );
ITypeInfo t = TypeInfoProvider.newTypeInfo( type, info, ptrOp, hasDefault );
param.setTypeInfo( t );
addParameter( param );
}
@ -172,15 +163,11 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.ISymbol, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp, boolean)
*/
public void addParameter( ISymbol typeSymbol, int info, TypeInfo.PtrOp ptrOp, boolean hasDefault ){
public void addParameter( ISymbol typeSymbol, int info, ITypeInfo.PtrOp ptrOp, boolean hasDefault ){
BasicSymbol param = new BasicSymbol(getSymbolTable(), ParserSymbolTable.EMPTY_NAME);
TypeInfo nfo = param.getTypeInfo();
nfo.setTypeInfo( info );
nfo.setType( TypeInfo.t_type );
nfo.setTypeSymbol( typeSymbol );
nfo.addPtrOperator( ptrOp );
nfo.setHasDefault( hasDefault );
ITypeInfo nfo = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, info, typeSymbol, ptrOp, hasDefault );
param.setTypeInfo( nfo );
addParameter( param );
}
@ -225,8 +212,8 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
List params = getParameterList();
List functionParams = function.getParameterList();
TypeInfo info = null;
TypeInfo fInfo = null;
ITypeInfo info = null;
ITypeInfo fInfo = null;
TypeInfoProvider provider = getSymbolTable().getTypeInfoProvider();
@ -241,33 +228,33 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
info = ParserSymbolTable.getFlatTypeInfo( info, provider );
fInfo = ParserSymbolTable.getFlatTypeInfo( fInfo, provider );
for( TypeInfo nfo = info; nfo != null; nfo = fInfo ){
for( ITypeInfo nfo = info; nfo != null; nfo = fInfo ){
//an array declaration is adjusted to become a pointer declaration
//only the second and subsequent array dimensions are significant in parameter types
ListIterator ptrs = nfo.getPtrOperators().listIterator();
if( ptrs.hasNext() ){
PtrOp op = (PtrOp) ptrs.next();
if( op.getType() == PtrOp.t_array ){
ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) ptrs.next();
if( op.getType() == ITypeInfo.PtrOp.t_array ){
ptrs.remove();
ptrs.add( new PtrOp( PtrOp.t_pointer, op.isConst(), op.isVolatile() ) );
ptrs.add( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, op.isConst(), op.isVolatile() ) );
}
}
//a function type is adjusted to become a pointer to function type
if( nfo.isType( TypeInfo.t_type ) && nfo.getTypeSymbol() != null &&
nfo.getTypeSymbol().isType( TypeInfo.t_function ) )
if( nfo.isType( ITypeInfo.t_type ) && nfo.getTypeSymbol() != null &&
nfo.getTypeSymbol().isType( ITypeInfo.t_function ) )
{
if( nfo.getPtrOperators().size() == 0 ){
nfo.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
nfo.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) );
}
}
//const and volatile type-specifiers are ignored (only the outermost level)
if( nfo.getPtrOperators().size() == 0 ){
nfo.setBit( false, TypeInfo.isConst );
nfo.setBit( false, TypeInfo.isVolatile );
nfo.setBit( false, ITypeInfo.isConst );
nfo.setBit( false, ITypeInfo.isVolatile );
} else {
PtrOp op = (PtrOp) nfo.getPtrOperators().get( nfo.getPtrOperators().size() - 1 );
ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) nfo.getPtrOperators().get( nfo.getPtrOperators().size() - 1 );
op.setConst( false );
op.setVolatile( false );
}
@ -295,7 +282,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
public void setReturnType( ISymbol type ){
_returnType = type;
_returnType.setContainingSymbol( this );
_returnType.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template );
_returnType.setIsTemplateMember( isTemplateMember() || getType() == ITypeInfo.t_template );
}
/* (non-Javadoc)

View file

@ -31,7 +31,6 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTMember;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
/**
* @author aniefer
@ -49,7 +48,7 @@ public class ParserSymbolTable {
*/
public ParserSymbolTable( ParserLanguage language, ParserMode mode ) {
super();
_compilationUnit = newContainerSymbol( EMPTY_NAME, TypeInfo.t_namespace );
_compilationUnit = newContainerSymbol( EMPTY_NAME, ITypeInfo.t_namespace );
_language = language;
_mode = mode;
}
@ -62,7 +61,7 @@ public class ParserSymbolTable {
if( name == null ) name = EMPTY_NAME;
return new ContainerSymbol( this, name );
}
public IContainerSymbol newContainerSymbol( String name, TypeInfo.eType type ){
public IContainerSymbol newContainerSymbol( String name, ITypeInfo.eType type ){
if( name == null ) name = EMPTY_NAME;
return new ContainerSymbol( this, name, type );
}
@ -71,7 +70,7 @@ public class ParserSymbolTable {
if( name == null ) name = EMPTY_NAME;
return new BasicSymbol( this, name );
}
public ISymbol newSymbol( String name, TypeInfo.eType type ){
public ISymbol newSymbol( String name, ITypeInfo.eType type ){
if( name == null ) name = EMPTY_NAME;
return new BasicSymbol( this, name, type );
}
@ -80,7 +79,7 @@ public class ParserSymbolTable {
if( name == null ) name = EMPTY_NAME;
return new DerivableContainerSymbol( this, name );
}
public IDerivableContainerSymbol newDerivableContainerSymbol( String name, TypeInfo.eType type ){
public IDerivableContainerSymbol newDerivableContainerSymbol( String name, ITypeInfo.eType type ){
if( name == null ) name = EMPTY_NAME;
return new DerivableContainerSymbol( this, name, type );
}
@ -88,7 +87,7 @@ public class ParserSymbolTable {
if( name == null ) name = EMPTY_NAME;
return new ParameterizedSymbol( this, name );
}
public IParameterizedSymbol newParameterizedSymbol( String name, TypeInfo.eType type ){
public IParameterizedSymbol newParameterizedSymbol( String name, ITypeInfo.eType type ){
if( name == null ) name = EMPTY_NAME;
return new ParameterizedSymbol( this, name, type );
}
@ -116,9 +115,9 @@ public class ParserSymbolTable {
static protected void lookup( LookupData data, IContainerSymbol inSymbol ) throws ParserSymbolTableException
{
//handle namespace aliases
if( inSymbol.isType( TypeInfo.t_namespace ) ){
ISymbol symbol = inSymbol.getTypeSymbol();
if( symbol != null && symbol.isType( TypeInfo.t_namespace ) ){
if( inSymbol.isType( ITypeInfo.t_namespace ) ){
ISymbol symbol = inSymbol.getForwardSymbol();
if( symbol != null && symbol.isType( ITypeInfo.t_namespace ) ){
inSymbol = (IContainerSymbol) symbol;
}
}
@ -457,8 +456,8 @@ public class ParserSymbolTable {
return true;
}
TypeInfoProvider provider = symbol.getSymbolTable().getTypeInfoProvider();
TypeInfo typeInfo = ParserSymbolTable.getFlatTypeInfo( symbol.getTypeInfo(), provider );
TypeInfoProvider provider = TypeInfoProvider.getProvider( symbol.getSymbolTable() );
ITypeInfo typeInfo = ParserSymbolTable.getFlatTypeInfo( symbol.getTypeInfo(), provider );
boolean accept = data.getFilter().shouldAccept( symbol, typeInfo ) || data.getFilter().shouldAccept( symbol );
provider.returnTypeInfo( typeInfo );
@ -491,13 +490,13 @@ public class ParserSymbolTable {
if( ( data.returnInvisibleSymbols || !symbol.getIsInvisible() ) && checkType( data, symbol ) ){
foundSymbol = symbol;
if( foundSymbol.isType( TypeInfo.t_function ) ){
if( foundSymbol.isForwardDeclaration() && foundSymbol.getTypeSymbol() != null &&
foundSymbol.getTypeSymbol().getContainingSymbol() == foundSymbol.getContainingSymbol() )
if( foundSymbol.isType( ITypeInfo.t_function ) ){
if( foundSymbol.isForwardDeclaration() && foundSymbol.getForwardSymbol() != null &&
foundSymbol.getForwardSymbol().getContainingSymbol() == foundSymbol.getContainingSymbol() )
{
foundSymbol = foundSymbol.getTypeSymbol();
foundSymbol = foundSymbol.getForwardSymbol();
}
if( foundSymbol.getContainingSymbol().isType( TypeInfo.t_template ) ){
if( foundSymbol.getContainingSymbol().isType( ITypeInfo.t_template ) ){
templateFunctionSet.add( foundSymbol );
} else {
functionSet.add( foundSymbol );
@ -505,14 +504,14 @@ public class ParserSymbolTable {
} else {
//if this is a class-name, other stuff hides it
if( foundSymbol.isType( TypeInfo.t_class, TypeInfo.t_enumeration ) ){
if( foundSymbol.isType( ITypeInfo.t_class, ITypeInfo.t_enumeration ) ){
if( cls == null ){
cls = (IContainerSymbol) foundSymbol;
} else {
if( cls.getTypeInfo().isForwardDeclaration() && cls.getTypeSymbol() == foundSymbol ){
if( cls.isForwardDeclaration() && cls.getForwardSymbol() == foundSymbol ){
//cls is a forward declaration of decl, we want decl.
cls = (IContainerSymbol) foundSymbol;
} else if( foundSymbol.getTypeInfo().isForwardDeclaration() && foundSymbol.getTypeSymbol() == cls ){
} else if( foundSymbol.isForwardDeclaration() && foundSymbol.getForwardSymbol() == cls ){
//decl is a forward declaration of cls, we already have what we want (cls)
} else {
if( data.isPrefixLookup() ){
@ -738,8 +737,8 @@ public class ParserSymbolTable {
ISymbol symbol = ( objList != null ) ? (ISymbol) objList.get(0) : ( ISymbol )obj1;
int idx = 1;
while( symbol != null ) {
TypeInfo type = ((ISymbol)obj1).getTypeInfo();
if( !type.checkBit( TypeInfo.isStatic ) && !type.isType( TypeInfo.t_enumerator ) ){
ITypeInfo type = ((ISymbol)obj1).getTypeInfo();
if( !type.checkBit( ITypeInfo.isStatic ) && !type.isType( ITypeInfo.t_enumerator ) ){
return false;
}
@ -788,10 +787,10 @@ public class ParserSymbolTable {
* it finds the name to be a function name"
*/
protected static boolean isValidOverload( ISymbol origSymbol, ISymbol newSymbol ){
TypeInfo.eType origType = origSymbol.getType();
TypeInfo.eType newType = newSymbol.getType();
ITypeInfo.eType origType = origSymbol.getType();
ITypeInfo.eType newType = newSymbol.getType();
if( origType == TypeInfo.t_template ){
if( origType == ITypeInfo.t_template ){
ITemplateSymbol template = (ITemplateSymbol) origSymbol;
origSymbol = template.getTemplatedSymbol();
if( origSymbol == null )
@ -799,7 +798,7 @@ public class ParserSymbolTable {
origType = origSymbol.getType();
}
if( newType == TypeInfo.t_template ){
if( newType == ITypeInfo.t_template ){
ITemplateSymbol template = (ITemplateSymbol) newSymbol;
newSymbol = template.getTemplatedSymbol();
if( newSymbol == null )
@ -808,8 +807,8 @@ public class ParserSymbolTable {
}
//handle forward decls
if( origSymbol.getTypeInfo().isForwardDeclaration() ){
if( origSymbol.getTypeSymbol() == newSymbol )
if( origSymbol.isForwardDeclaration() ){
if( origSymbol.getForwardSymbol() == newSymbol )
return true;
//friend class declarations
@ -819,8 +818,8 @@ public class ParserSymbolTable {
}
}
if( (origType.compareTo(TypeInfo.t_class) >= 0 && origType.compareTo(TypeInfo.t_enumeration) <= 0) && //class name or enumeration ...
( newType == TypeInfo.t_type || (newType.compareTo( TypeInfo.t_function ) >= 0 /*&& newType <= TypeInfo.typeMask*/) ) ){
if( (origType.compareTo(ITypeInfo.t_class) >= 0 && origType.compareTo(ITypeInfo.t_enumeration) <= 0) && //class name or enumeration ...
( newType == ITypeInfo.t_type || (newType.compareTo( ITypeInfo.t_function ) >= 0 /*&& newType <= TypeInfo.typeMask*/) ) ){
return true;
}
@ -835,7 +834,7 @@ public class ParserSymbolTable {
if( origList.size() == 1 ){
return isValidOverload( (ISymbol)origList.get(0), newSymbol );
} else if ( origList.size() > 1 ){
if( newSymbol.isType( TypeInfo.t_template ) ){
if( newSymbol.isType( ITypeInfo.t_template ) ){
ITemplateSymbol template = (ITemplateSymbol) newSymbol;
newSymbol = (ISymbol) template.getContainedSymbols().get( template.getName() );
}
@ -843,14 +842,14 @@ public class ParserSymbolTable {
//the first thing can be a class-name or enumeration name, but the rest
//must be functions. So make sure the newDecl is a function before even
//considering the list
if( newSymbol.getType() != TypeInfo.t_function && newSymbol.getType() != TypeInfo.t_constructor ){
if( newSymbol.getType() != ITypeInfo.t_function && newSymbol.getType() != ITypeInfo.t_constructor ){
return false;
}
//Iterator iter = origList.iterator();
ISymbol symbol = (ISymbol) origList.get(0);
int numSymbols = origList.size();
if( symbol.isType( TypeInfo.t_template ) ){
if( symbol.isType( ITypeInfo.t_template ) ){
IParameterizedSymbol template = (IParameterizedSymbol) symbol;
symbol = (ISymbol) template.getContainedSymbols().get( template.getName() );
}
@ -859,7 +858,7 @@ public class ParserSymbolTable {
int idx = 1;
while( valid && idx < numSymbols ){
symbol = (ISymbol) origList.get(idx++);
if( symbol.isType( TypeInfo.t_template ) ){
if( symbol.isType( ITypeInfo.t_template ) ){
ITemplateSymbol template = (ITemplateSymbol) symbol;
symbol = template.getTemplatedSymbol();
}
@ -874,21 +873,21 @@ public class ParserSymbolTable {
}
private static boolean isValidFunctionOverload( IParameterizedSymbol origSymbol, IParameterizedSymbol newSymbol ){
if( ( !origSymbol.isType( TypeInfo.t_function ) && !origSymbol.isType( TypeInfo.t_constructor ) ) ||
( ! newSymbol.isType( TypeInfo.t_function ) && ! newSymbol.isType( TypeInfo.t_constructor ) ) ){
if( ( !origSymbol.isType( ITypeInfo.t_function ) && !origSymbol.isType( ITypeInfo.t_constructor ) ) ||
( ! newSymbol.isType( ITypeInfo.t_function ) && ! newSymbol.isType( ITypeInfo.t_constructor ) ) ){
return false;
}
//handle forward decls
if( origSymbol.getTypeInfo().isForwardDeclaration() &&
origSymbol.getTypeSymbol() == newSymbol )
if( origSymbol.isForwardDeclaration() &&
origSymbol.getForwardSymbol() == newSymbol )
{
return true;
}
if( origSymbol.hasSameParameters( newSymbol ) ){
//functions with the same name and same parameter types cannot be overloaded if any of them
//is static
if( origSymbol.getTypeInfo().checkBit( TypeInfo.isStatic ) || newSymbol.getTypeInfo().checkBit( TypeInfo.isStatic ) ){
if( origSymbol.getTypeInfo().checkBit( ITypeInfo.isStatic ) || newSymbol.getTypeInfo().checkBit( ITypeInfo.isStatic ) ){
return false;
}
@ -940,12 +939,12 @@ public class ParserSymbolTable {
functionList.addAll( (List) object );
} else {
ISymbol symbol = (ISymbol) object;
if( symbol.isType( TypeInfo.t_function ) ){
if( symbol.isType( ITypeInfo.t_function ) ){
functionList = new ArrayList(1);
functionList.add( symbol );
} else {
if( symbol.isTemplateMember() && !symbol.isTemplateInstance() &&
!symbol.isType( TypeInfo.t_templateParameter ) && symbol.getContainingSymbol().isType( TypeInfo.t_template ))
!symbol.isType( ITypeInfo.t_templateParameter ) && symbol.getContainingSymbol().isType( ITypeInfo.t_template ))
{
resolvedSymbol = symbol.getContainingSymbol();
if( resolvedSymbol instanceof ISpecializedSymbol ){
@ -1004,7 +1003,7 @@ public class ParserSymbolTable {
} else if ( numFns == 2 ){
for (int i = 0; i < numFns; i++) {
IParameterizedSymbol fn = (IParameterizedSymbol) functions.get(i);
if( fn.getTypeInfo().isForwardDeclaration() && fn.getTypeSymbol() != null ){
if( fn.isForwardDeclaration() && fn.getForwardSymbol() != null ){
if( functions.contains( fn.getTypeSymbol() ) ){
return (IParameterizedSymbol) fn.getTypeSymbol();
}
@ -1021,9 +1020,9 @@ public class ParserSymbolTable {
Cost [] bestFnCost = null; //the cost of the best function
Cost [] currFnCost = null; //the cost for the current function
TypeInfo source = null; //parameter we are called with
TypeInfo target = null; //function's parameter
TypeInfo voidInfo = null; //used to compare f() and f(void)
ITypeInfo source = null; //parameter we are called with
ITypeInfo target = null; //function's parameter
ITypeInfo voidInfo = null; //used to compare f() and f(void)
int comparison;
Cost cost = null; //the cost of converting source to target
@ -1038,13 +1037,13 @@ public class ParserSymbolTable {
List sourceParameters = null; //the parameters the function is being called with
List targetParameters = null; //the current function's parameters
TypeInfoProvider infoProvider = getTypeInfoProvider();
TypeInfoProvider infoProvider = TypeInfoProvider.getProvider( this );
if( numSourceParams == 0 ){
//f() is the same as f( void )
sourceParameters = new ArrayList(1);
voidInfo = infoProvider.getTypeInfo();
voidInfo.setType( TypeInfo.t_void );
voidInfo = infoProvider.getTypeInfo( ITypeInfo.t_void );
voidInfo.setType( ITypeInfo.t_void );
sourceParameters.add( voidInfo );
numSourceParams = 1;
} else {
@ -1056,10 +1055,10 @@ public class ParserSymbolTable {
currFn = (IParameterizedSymbol) functions.get( fnIdx );
if( bestFn != null ){
if( bestFn.isForwardDeclaration() && bestFn.getTypeSymbol() == currFn ){
if( bestFn.isForwardDeclaration() && bestFn.getForwardSymbol() == currFn ){
bestFn = currFn;
continue;
} else if( currFn.isForwardDeclaration() && currFn.getTypeSymbol() == bestFn ){
} else if( currFn.isForwardDeclaration() && currFn.getForwardSymbol() == bestFn ){
continue;
}
}
@ -1069,7 +1068,7 @@ public class ParserSymbolTable {
//the only way we get here and have no parameters, is if we are looking
//for a function that takes void parameters ie f( void )
targetParameters = new ArrayList(1);
targetParameters.add( currFn.getSymbolTable().newSymbol( "", TypeInfo.t_void ) ); //$NON-NLS-1$
targetParameters.add( currFn.getSymbolTable().newSymbol( "", ITypeInfo.t_void ) ); //$NON-NLS-1$
} else {
targetParameters = currFn.getParameterList();
}
@ -1083,7 +1082,7 @@ public class ParserSymbolTable {
boolean varArgs = false;
for( int j = 0; j < numSourceParams; j++ ){
source = (TypeInfo) sourceParameters.get(j);
source = (ITypeInfo) sourceParameters.get(j);
if( j < numTargetParams )
target = ((ISymbol)targetParameters.get(j)).getTypeInfo();
@ -1093,7 +1092,7 @@ public class ParserSymbolTable {
if( varArgs ){
cost = new Cost( infoProvider, source, null );
cost.rank = Cost.ELLIPSIS_CONVERSION;
} else if ( target.getHasDefault() && source.isType( TypeInfo.t_void ) && !source.hasPtrOperators() ){
} else if ( target.getHasDefault() && source.isType( ITypeInfo.t_void ) && !source.hasPtrOperators() ){
//source is just void, ie no parameter, if target had a default, then use that
cost = new Cost( infoProvider, source, target );
cost.rank = Cost.IDENTITY_RANK;
@ -1258,12 +1257,12 @@ public class ParserSymbolTable {
return function.getParameterList().isEmpty();
}
//create a new function that has params as its parameters, then use IParameterizedSymbol.hasSameParameters
IParameterizedSymbol tempFn = function.getSymbolTable().newParameterizedSymbol( EMPTY_NAME, TypeInfo.t_function );
IParameterizedSymbol tempFn = function.getSymbolTable().newParameterizedSymbol( EMPTY_NAME, ITypeInfo.t_function );
int size = params.size();
for( int i = 0; i < size; i++ ){
ISymbol param = function.getSymbolTable().newSymbol( EMPTY_NAME );
param.setTypeInfo( (TypeInfo) params.get(i) );
param.setTypeInfo( (ITypeInfo) params.get(i) );
tempFn.addParameter( param );
}
@ -1289,7 +1288,7 @@ public class ParserSymbolTable {
//sanity check
if( obj instanceof IParameterizedSymbol ){
function = (IParameterizedSymbol) obj;
if( !function.isType( TypeInfo.t_function) && !function.isType( TypeInfo.t_constructor ) ){
if( !function.isType( ITypeInfo.t_function) && !function.isType( ITypeInfo.t_constructor ) ){
functions.remove( i-- );
size--;
continue;
@ -1314,12 +1313,12 @@ public class ParserSymbolTable {
//check for void
else if( numParameters == 0 && num == 1 ){
ISymbol param = (ISymbol)function.getParameterList().get(0);
if( param.isType( TypeInfo.t_void ) )
if( param.isType( ITypeInfo.t_void ) )
continue;
}
else if( numParameters == 1 && num == 0 ){
TypeInfo paramType = (TypeInfo) data.getParameters().get(0);
if( paramType.isType( TypeInfo.t_void ) )
ITypeInfo paramType = (ITypeInfo) data.getParameters().get(0);
if( paramType.isType( ITypeInfo.t_void ) )
continue;
}
@ -1341,7 +1340,7 @@ public class ParserSymbolTable {
continue;
}
List params = function.getParameterList();
TypeInfo param;
ITypeInfo param;
for( int j = num - 1; j > ( numParameters - num); j-- ){
param = ((ISymbol)params.get(j)).getTypeInfo();
if( !param.getHasDefault() ){
@ -1504,7 +1503,7 @@ public class ParserSymbolTable {
//if T is a union or enumeration type, its associated namespace is the namespace in
//which it is defined. if it is a class member, its associated class is the member's
//class
else if( symbol.getType() == TypeInfo.t_union || symbol.getType() == TypeInfo.t_enumeration ){
else if( symbol.getType() == ITypeInfo.t_union || symbol.getType() == ITypeInfo.t_enumeration ){
associated.add( symbol.getContainingSymbol() );
}
}
@ -1526,7 +1525,7 @@ public class ParserSymbolTable {
//TODO: what about IDeferredTemplateInstance parents?
if( base instanceof IDerivableContainerSymbol ){
classes.add( base );
if( base.getContainingSymbol().getType() == TypeInfo.t_namespace ){
if( base.getContainingSymbol().getType() == ITypeInfo.t_namespace ){
classes.add( base.getContainingSymbol());
}
@ -1541,11 +1540,11 @@ public class ParserSymbolTable {
boolean okToAdd = false;
//7.3.3-5 A using-declaration shall not name a template-id
if( obj.isTemplateMember() && obj.getContainingSymbol().isType( TypeInfo.t_template ) ){
if( obj.isTemplateMember() && obj.getContainingSymbol().isType( ITypeInfo.t_template ) ){
okToAdd = false;
}
//7.3.3-4
else if( context.isType( TypeInfo.t_class, TypeInfo.t_struct ) ){
else if( context.isType( ITypeInfo.t_class, ITypeInfo.t_struct ) ){
IContainerSymbol container = obj.getContainingSymbol();
try{
@ -1553,7 +1552,7 @@ public class ParserSymbolTable {
if( obj.getContainingSymbol().getType() == context.getType() ){
okToAdd = ( hasBaseClass( context, container ) > 0 );
}
else if ( obj.getContainingSymbol().getType() == TypeInfo.t_union ) {
else if ( obj.getContainingSymbol().getType() == ITypeInfo.t_union ) {
// TODO : must be an _anonymous_ union
container = container.getContainingSymbol();
okToAdd = ( container instanceof IDerivableContainerSymbol )
@ -1561,7 +1560,7 @@ public class ParserSymbolTable {
: false;
}
//an enumerator for an enumeration
else if ( obj.getType() == TypeInfo.t_enumerator ){
else if ( obj.getType() == ITypeInfo.t_enumerator ){
container = container.getContainingSymbol();
okToAdd = ( container instanceof IDerivableContainerSymbol )
? ( hasBaseClass( context, container ) > 0 )
@ -1577,14 +1576,14 @@ public class ParserSymbolTable {
return okToAdd;
}
static private Cost lvalue_to_rvalue( TypeInfoProvider provider, TypeInfo source, TypeInfo target ){
static private Cost lvalue_to_rvalue( TypeInfoProvider provider, ITypeInfo source, ITypeInfo target ){
//lvalues will have type t_type
if( source.isType( TypeInfo.t_type ) ){
if( source.isType( ITypeInfo.t_type ) ){
source = getFlatTypeInfo( source, null );
}
if( target.isType( TypeInfo.t_type ) ){
if( target.isType( ITypeInfo.t_type ) ){
target = getFlatTypeInfo( target, null );
}
@ -1596,19 +1595,19 @@ public class ParserSymbolTable {
return cost;
}
TypeInfo.PtrOp op = null;
ITypeInfo.PtrOp op = null;
if( cost.getSource().hasPtrOperators() ){
List sourcePtrs = cost.getSource().getPtrOperators();
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)sourcePtrs.get( 0 );
if( ptr.getType() == TypeInfo.PtrOp.t_reference ){
ITypeInfo.PtrOp ptr = (ITypeInfo.PtrOp)sourcePtrs.get( 0 );
if( ptr.getType() == ITypeInfo.PtrOp.t_reference ){
sourcePtrs.remove( 0 );
}
int size = sourcePtrs.size();
for( int i = 0; i < size; i++ ){
op = (TypeInfo.PtrOp) sourcePtrs.get( 0 );
if( op.getType() == TypeInfo.PtrOp.t_array ){
op.setType( TypeInfo.PtrOp.t_pointer );
op = (ITypeInfo.PtrOp) sourcePtrs.get( 0 );
if( op.getType() == ITypeInfo.PtrOp.t_array ){
op.setType( ITypeInfo.PtrOp.t_pointer );
}
}
}
@ -1616,17 +1615,17 @@ public class ParserSymbolTable {
if( cost.getTarget().hasPtrOperators() ){
List targetPtrs = cost.getTarget().getPtrOperators();
//ListIterator iterator = targetPtrs.listIterator();
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)targetPtrs.get(0);
ITypeInfo.PtrOp ptr = (ITypeInfo.PtrOp)targetPtrs.get(0);
if( ptr.getType() == TypeInfo.PtrOp.t_reference ){
if( ptr.getType() == ITypeInfo.PtrOp.t_reference ){
targetPtrs.remove(0);
cost.targetHadReference = true;
}
int size = targetPtrs.size();
for( int i = 0; i < size; i++ ){
op = (TypeInfo.PtrOp) targetPtrs.get(0);
if( op.getType() == TypeInfo.PtrOp.t_array ){
op.setType( TypeInfo.PtrOp.t_pointer );
op = (ITypeInfo.PtrOp) targetPtrs.get(0);
if( op.getType() == ITypeInfo.PtrOp.t_array ){
op.setType( ITypeInfo.PtrOp.t_pointer );
}
}
}
@ -1646,20 +1645,20 @@ public class ParserSymbolTable {
int size = sourcePtrs.size();
int size2 = targetPtrs.size();
TypeInfo.PtrOp op1 = null, op2 = null;
ITypeInfo.PtrOp op1 = null, op2 = null;
boolean canConvert = true;
if( size != size2 ){
canConvert = false;
} else if( size > 0 ){
op1 = (TypeInfo.PtrOp) sourcePtrs.get(0);
op2 = (TypeInfo.PtrOp) targetPtrs.get(0);
op1 = (ITypeInfo.PtrOp) sourcePtrs.get(0);
op2 = (ITypeInfo.PtrOp) targetPtrs.get(0);
boolean constInEveryCV2k = true;
for( int j= 1; j < size; j++ ){
op1 = (TypeInfo.PtrOp) sourcePtrs.get(j);
op2 = (TypeInfo.PtrOp) targetPtrs.get(j);
op1 = (ITypeInfo.PtrOp) sourcePtrs.get(j);
op2 = (ITypeInfo.PtrOp) targetPtrs.get(j);
//pointer types must be similar
if( op1.getType() != op2.getType() ){
@ -1684,8 +1683,8 @@ public class ParserSymbolTable {
}
}
if( ( cost.getSource().checkBit( TypeInfo.isConst ) && !cost.getTarget().checkBit( TypeInfo.isConst ) ) ||
( cost.getSource().checkBit( TypeInfo.isVolatile ) && !cost.getTarget().checkBit( TypeInfo.isVolatile ) ) )
if( ( cost.getSource().checkBit( ITypeInfo.isConst ) && !cost.getTarget().checkBit( ITypeInfo.isConst ) ) ||
( cost.getSource().checkBit( ITypeInfo.isVolatile ) && !cost.getTarget().checkBit( ITypeInfo.isVolatile ) ) )
{
canConvert = false;
}
@ -1713,23 +1712,23 @@ public class ParserSymbolTable {
* 4.6 float can be promoted to double
*/
static private void promotion( Cost cost ){
TypeInfo src = cost.getSource();
TypeInfo trg = cost.getTarget();
ITypeInfo src = cost.getSource();
ITypeInfo trg = cost.getTarget();
int mask = TypeInfo.isShort | TypeInfo.isLong | TypeInfo.isUnsigned | TypeInfo.isLongLong | TypeInfo.isSigned;
int mask = ITypeInfo.isShort | ITypeInfo.isLong | ITypeInfo.isUnsigned | ITypeInfo.isLongLong | ITypeInfo.isSigned;
if( (src.isType( TypeInfo.t__Bool, TypeInfo.t_float ) || src.isType( TypeInfo.t_enumeration )) &&
(trg.isType( TypeInfo.t_int ) || trg.isType( TypeInfo.t_double )) )
if( (src.isType( ITypeInfo.t__Bool, ITypeInfo.t_float ) || src.isType( ITypeInfo.t_enumeration )) &&
(trg.isType( ITypeInfo.t_int ) || trg.isType( ITypeInfo.t_double )) )
{
if( src.getType() == trg.getType() && (( src.getTypeInfo() & mask) == (trg.getTypeInfo() & mask)) ){
if( src.getType() == trg.getType() && (( src.getTypeBits() & mask) == (trg.getTypeBits() & mask)) ){
//same, no promotion needed
return;
}
if( src.isType( TypeInfo.t_float ) ){
cost.promotion = trg.isType( TypeInfo.t_double ) ? 1 : 0;
if( src.isType( ITypeInfo.t_float ) ){
cost.promotion = trg.isType( ITypeInfo.t_double ) ? 1 : 0;
} else {
cost.promotion = ( trg.isType( TypeInfo.t_int ) && trg.canHold( src ) ) ? 1 : 0;
cost.promotion = ( trg.isType( ITypeInfo.t_int ) && trg.canHold( src ) ) ? 1 : 0;
}
} else {
@ -1747,8 +1746,8 @@ public class ParserSymbolTable {
*
*/
static private void conversion( Cost cost ){
TypeInfo src = cost.getSource();
TypeInfo trg = cost.getTarget();
ITypeInfo src = cost.getSource();
ITypeInfo trg = cost.getTarget();
int temp = -1;
@ -1759,17 +1758,17 @@ public class ParserSymbolTable {
return;
}
if( src.hasPtrOperators() && src.getPtrOperators().size() == 1 ){
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)src.getPtrOperators().get(0);
ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null;
ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null;
if( ptr.getType() == TypeInfo.PtrOp.t_pointer ){
if( srcDecl == null || (trgDecl == null && !trg.isType( TypeInfo.t_void )) ){
ITypeInfo.PtrOp ptr = (ITypeInfo.PtrOp)src.getPtrOperators().get(0);
ISymbol srcDecl = src.isType( ITypeInfo.t_type ) ? src.getTypeSymbol() : null;
ISymbol trgDecl = trg.isType( ITypeInfo.t_type ) ? trg.getTypeSymbol() : null;
if( ptr.getType() == ITypeInfo.PtrOp.t_pointer ){
if( srcDecl == null || (trgDecl == null && !trg.isType( ITypeInfo.t_void )) ){
return;
}
//4.10-2 an rvalue of type "pointer to cv T", where T is an object type can be
//converted to an rvalue of type "pointer to cv void"
if( trg.isType( TypeInfo.t_void ) ){
if( trg.isType( ITypeInfo.t_void ) ){
cost.rank = Cost.CONVERSION_RANK;
cost.conversion = 1;
cost.detail = 2;
@ -1791,7 +1790,7 @@ public class ParserSymbolTable {
cost.detail = 1;
return;
}
} else if( ptr.getType() == TypeInfo.PtrOp.t_memberPointer ){
} else if( ptr.getType() == ITypeInfo.PtrOp.t_memberPointer ){
//4.11-2 An rvalue of type "pointer to member of B of type cv T", where B is a class type,
//can be converted to an rvalue of type "pointer to member of D of type cv T" where D is a
//derived class of B
@ -1799,8 +1798,8 @@ public class ParserSymbolTable {
return;
}
TypeInfo.PtrOp srcPtr = trg.hasPtrOperators() ? (TypeInfo.PtrOp)trg.getPtrOperators().get(0) : null;
if( trgDecl.isType( srcDecl.getType() ) && srcPtr != null && srcPtr.getType() == TypeInfo.PtrOp.t_memberPointer ){
ITypeInfo.PtrOp srcPtr = trg.hasPtrOperators() ? (ITypeInfo.PtrOp)trg.getPtrOperators().get(0) : null;
if( trgDecl.isType( srcDecl.getType() ) && srcPtr != null && srcPtr.getType() == ITypeInfo.PtrOp.t_memberPointer ){
try {
temp = hasBaseClass( ptr.getMemberOf(), srcPtr.getMemberOf() );
} catch (ParserSymbolTableException e) {
@ -1815,12 +1814,12 @@ public class ParserSymbolTable {
} else if( !src.hasPtrOperators() ) {
//4.7 An rvalue of an integer type can be converted to an rvalue of another integer type.
//An rvalue of an enumeration type can be converted to an rvalue of an integer type.
if( src.isType( TypeInfo.t__Bool, TypeInfo.t_int ) ||
src.isType( TypeInfo.t_float, TypeInfo.t_double ) ||
src.isType( TypeInfo.t_enumeration ) )
if( src.isType( ITypeInfo.t__Bool, ITypeInfo.t_int ) ||
src.isType( ITypeInfo.t_float, ITypeInfo.t_double ) ||
src.isType( ITypeInfo.t_enumeration ) )
{
if( trg.isType( TypeInfo.t__Bool, TypeInfo.t_int ) ||
trg.isType( TypeInfo.t_float, TypeInfo.t_double ) )
if( trg.isType( ITypeInfo.t__Bool, ITypeInfo.t_int ) ||
trg.isType( ITypeInfo.t_float, ITypeInfo.t_double ) )
{
cost.rank = Cost.CONVERSION_RANK;
cost.conversion = 1;
@ -1830,11 +1829,11 @@ public class ParserSymbolTable {
}
static private void derivedToBaseConversion( Cost cost ) throws ParserSymbolTableException{
TypeInfo src = cost.getSource();
TypeInfo trg = cost.getTarget();
ITypeInfo src = cost.getSource();
ITypeInfo trg = cost.getTarget();
ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null;
ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null;
ISymbol srcDecl = src.isType( ITypeInfo.t_type ) ? src.getTypeSymbol() : null;
ISymbol trgDecl = trg.isType( ITypeInfo.t_type ) ? trg.getTypeSymbol() : null;
if( !src.hasSamePtrs( trg ) || srcDecl == null || trgDecl == null || !cost.targetHadReference ){
return;
@ -1848,8 +1847,8 @@ public class ParserSymbolTable {
}
}
protected Cost checkStandardConversionSequence( TypeInfo source, TypeInfo target ) throws ParserSymbolTableException{
Cost cost = lvalue_to_rvalue( getTypeInfoProvider(), source, target );
protected Cost checkStandardConversionSequence( ITypeInfo source, ITypeInfo target ) throws ParserSymbolTableException{
Cost cost = lvalue_to_rvalue( TypeInfoProvider.getProvider( this ), source, target );
if( cost.getSource() == null || cost.getTarget() == null ){
return cost;
@ -1868,7 +1867,7 @@ public class ParserSymbolTable {
}
//was the qualification conversion enough?
if( cost.getSource().isType( TypeInfo.t_type ) && cost.getTarget().isType( TypeInfo.t_type ) ){
if( cost.getSource().isType( ITypeInfo.t_type ) && cost.getTarget().isType( ITypeInfo.t_type ) ){
if( cost.getTarget().hasSamePtrs( cost.getSource() ) ){
ISymbol srcSymbol = cost.getSource().getTypeSymbol();
ISymbol trgSymbol = cost.getTarget().getTypeSymbol();
@ -1880,7 +1879,7 @@ public class ParserSymbolTable {
}
}
} else if( cost.getSource().getType() == cost.getTarget().getType() &&
(cost.getSource().getTypeInfo() & ~TypeInfo.isConst & ~TypeInfo.isVolatile) == (cost.getTarget().getTypeInfo() & ~TypeInfo.isConst & ~TypeInfo.isVolatile) )
(cost.getSource().getTypeBits() & ~ITypeInfo.isConst & ~ITypeInfo.isVolatile) == (cost.getTarget().getTypeBits() & ~ITypeInfo.isConst & ~ITypeInfo.isVolatile) )
{
return cost;
}
@ -1897,14 +1896,14 @@ public class ParserSymbolTable {
try{
derivedToBaseConversion( cost );
} catch ( ParserSymbolTableException e ){
cost.release( getTypeInfoProvider() );
cost.release( TypeInfoProvider.getProvider( this ) );
throw e;
}
return cost;
}
private Cost checkUserDefinedConversionSequence( TypeInfo source, TypeInfo target ) throws ParserSymbolTableException {
private Cost checkUserDefinedConversionSequence( ITypeInfo source, ITypeInfo target ) throws ParserSymbolTableException {
Cost cost = null;
Cost constructorCost = null;
Cost conversionCost = null;
@ -1915,12 +1914,12 @@ public class ParserSymbolTable {
IParameterizedSymbol conversion = null;
//constructors
if( target.getType() == TypeInfo.t_type ){
if( target.getType() == ITypeInfo.t_type ){
targetDecl = target.getTypeSymbol();
if( targetDecl == null ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
}
if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
if( targetDecl.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){
LookupData data = new LookupData( EMPTY_NAME){
public List getParameters() { return parameters; }
public TypeFilter getFilter() { return CONSTRUCTOR_FILTER; }
@ -1938,18 +1937,19 @@ public class ParserSymbolTable {
ArrayList constructors = new ArrayList( container.getConstructors() );
constructor = resolveFunction( data, constructors );
}
if( constructor != null && constructor.getTypeInfo().checkBit( TypeInfo.isExplicit ) ){
if( constructor != null && constructor.getTypeInfo().checkBit( ITypeInfo.isExplicit ) ){
constructor = null;
}
}
}
TypeInfoProvider provider = TypeInfoProvider.getProvider( this );
//conversion operators
if( source.getType() == TypeInfo.t_type ){
source = getFlatTypeInfo( source, getTypeInfoProvider() );
if( source.getType() == ITypeInfo.t_type ){
source = getFlatTypeInfo( source, provider );
sourceDecl = ( source != null ) ? source.getTypeSymbol() : null;
getTypeInfoProvider().returnTypeInfo( source );
provider.returnTypeInfo( source );
if( sourceDecl != null && (sourceDecl instanceof IContainerSymbol) ){
String name = target.toString();
@ -1968,18 +1968,16 @@ public class ParserSymbolTable {
try {
if( constructor != null ){
TypeInfo info = getTypeInfoProvider().getTypeInfo();
info.setType( TypeInfo.t_type );
ITypeInfo info = provider.getTypeInfo( ITypeInfo.t_type );
info.setTypeSymbol( constructor.getContainingSymbol() );
constructorCost = checkStandardConversionSequence( info, target );
getTypeInfoProvider().returnTypeInfo( info );
provider.returnTypeInfo( info );
}
if( conversion != null ){
TypeInfo info = getTypeInfoProvider().getTypeInfo();
info.setType( target.getType() );
ITypeInfo info = provider.getTypeInfo( target.getType() );
info.setTypeSymbol( target.getTypeSymbol() );
conversionCost = checkStandardConversionSequence( info, target );
getTypeInfoProvider().returnTypeInfo( info );
provider.returnTypeInfo( info );
}
//if both are valid, then the conversion is ambiguous
@ -2002,9 +2000,9 @@ public class ParserSymbolTable {
}
} finally {
if( constructorCost != null && constructorCost != cost )
constructorCost.release( getTypeInfoProvider() );
constructorCost.release( provider );
if( conversionCost != null && conversionCost != cost )
conversionCost.release( getTypeInfoProvider() );
conversionCost.release( provider );
}
return cost;
}
@ -2021,9 +2019,9 @@ public class ParserSymbolTable {
* - If neither can be converted, further checking must be done (return null)
* - If exactly one conversion is possible, that conversion is applied ( return the other TypeInfo )
*/
public TypeInfo getConditionalOperand( TypeInfo secondOp, TypeInfo thirdOp ) throws ParserSymbolTableException{
public ITypeInfo getConditionalOperand( ITypeInfo secondOp, ITypeInfo thirdOp ) throws ParserSymbolTableException{
Cost thirdCost = null, secondCost = null;
TypeInfo temp = null;
ITypeInfo temp = null;
TypeInfoProvider provider = getTypeInfoProvider();
try{
//can secondOp convert to thirdOp ?
@ -2081,24 +2079,25 @@ public class ParserSymbolTable {
* The top level TypeInfo represents modifications to the object and the
* remaining TypeInfo's represent the object.
*/
static protected TypeInfo getFlatTypeInfo( TypeInfo topInfo, TypeInfoProvider infoProvider ){
TypeInfo returnInfo = null;
TypeInfo info = null;
static protected ITypeInfo getFlatTypeInfo( ITypeInfo topInfo, TypeInfoProvider infoProvider ){
ITypeInfo returnInfo = null;
ITypeInfo info = null;
if( topInfo.getType() == TypeInfo.t_type && topInfo.getTypeSymbol() != null ){
if( infoProvider != null ) returnInfo = infoProvider.getTypeInfo();
else returnInfo = new TypeInfo();
if( topInfo.getType() == ITypeInfo.t_type && topInfo.getTypeSymbol() != null ){
if( infoProvider != null ) returnInfo = infoProvider.getTypeInfo( ITypeInfo.t_type );
else returnInfo = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type );
returnInfo.setTypeInfo( topInfo.getTypeInfo() );
returnInfo.setTypeBits( topInfo.getTypeBits() );
ISymbol typeSymbol = topInfo.getTypeSymbol();
info = typeSymbol.getTypeInfo();
int j = 0;
while( info.getTypeSymbol() != null && ( info.getType() == TypeInfo.t_type || info.isForwardDeclaration() ) ){
typeSymbol = info.getTypeSymbol();
while( (info.getTypeSymbol() != null && info.getType() == ITypeInfo.t_type) ||
(typeSymbol != null && typeSymbol.isForwardDeclaration() && typeSymbol.getForwardSymbol() != null ) ){
typeSymbol = info.isType( ITypeInfo.t_type) ? info.getTypeSymbol() : typeSymbol.getForwardSymbol();
returnInfo.addPtrOperator( info.getPtrOperators() );
returnInfo.setTypeInfo( ( returnInfo.getTypeInfo() | info.getTypeInfo() ) & ~TypeInfo.isTypedef & ~TypeInfo.isForward );
returnInfo.setTypeBits( ( returnInfo.getTypeBits() | info.getTypeBits() ) & ~ITypeInfo.isTypedef & ~ITypeInfo.isForward );
info = typeSymbol.getTypeInfo();
if( ++j > TYPE_LOOP_THRESHOLD ){
if( infoProvider != null )
@ -2107,46 +2106,33 @@ public class ParserSymbolTable {
}
}
if( info.isType( TypeInfo.t_class, TypeInfo.t_enumeration ) || info.isType( TypeInfo.t_function ) ){
returnInfo.setType( TypeInfo.t_type );
if( info.isType( ITypeInfo.t_class, ITypeInfo.t_enumeration ) || info.isType( ITypeInfo.t_function ) ){
returnInfo.setType( ITypeInfo.t_type );
returnInfo.setTypeSymbol( typeSymbol );
} else {
returnInfo.setTypeInfo( ( returnInfo.getTypeInfo() | info.getTypeInfo() ) & ~TypeInfo.isTypedef & ~TypeInfo.isForward );
returnInfo.setTypeBits( ( returnInfo.getTypeBits() | info.getTypeBits() ) & ~ITypeInfo.isTypedef & ~ITypeInfo.isForward );
returnInfo.setType( info.getType() );
returnInfo.setTypeSymbol( null );
returnInfo.addPtrOperator( info.getPtrOperators() );
}
if( returnInfo.isType( TypeInfo.t_templateParameter ) ){
if( returnInfo.isType( ITypeInfo.t_templateParameter ) ){
returnInfo.setTypeSymbol( typeSymbol );
}
returnInfo.applyOperatorExpressions( topInfo.getOperatorExpressions() );
if( topInfo.hasPtrOperators() ){
TypeInfo.PtrOp topPtr = (PtrOp) topInfo.getPtrOperators().get(0);
TypeInfo.PtrOp ptr = new PtrOp( topPtr.getType(), topPtr.isConst(), topPtr.isVolatile() );
returnInfo.addPtrOperator( ptr );
returnInfo.addPtrOperator( topInfo.getPtrOperators() );
}
} else {
if( infoProvider != null ){
returnInfo = infoProvider.getTypeInfo();
returnInfo = infoProvider.getTypeInfo( topInfo.getType() );
returnInfo.copy( topInfo );
} else
returnInfo = new TypeInfo( topInfo );
returnInfo.applyOperatorExpressions( topInfo.getOperatorExpressions() );
returnInfo.getOperatorExpressions().clear();
returnInfo = TypeInfoProvider.newTypeInfo( topInfo );
}
return returnInfo;
}
/**
* @return
*/
public TypeInfoProvider getTypeInfoProvider() {
return _provider;
}
private TypeInfoProvider _provider = new TypeInfoProvider();
private IContainerSymbol _compilationUnit;
private ParserLanguage _language;
private ParserMode _mode;
@ -2163,6 +2149,10 @@ public class ParserSymbolTable {
return _mode;
}
public TypeInfoProvider getTypeInfoProvider(){
return TypeInfoProvider.getProvider( this );
}
// protected void pushCommand( Command command ){
// undoList.addFirst( command );
// }
@ -2214,9 +2204,9 @@ public class ParserSymbolTable {
static protected class LookupData
{
protected static final TypeFilter ANY_FILTER = new TypeFilter( TypeInfo.t_any );
protected static final TypeFilter CONSTRUCTOR_FILTER = new TypeFilter( TypeInfo.t_constructor );
protected static final TypeFilter FUNCTION_FILTER = new TypeFilter( TypeInfo.t_function );
protected static final TypeFilter ANY_FILTER = new TypeFilter( ITypeInfo.t_any );
protected static final TypeFilter CONSTRUCTOR_FILTER = new TypeFilter( ITypeInfo.t_constructor );
protected static final TypeFilter FUNCTION_FILTER = new TypeFilter( ITypeInfo.t_function );
public String name;
public Map usingDirectives;
@ -2241,7 +2231,7 @@ public class ParserSymbolTable {
//this LookupData
public boolean isPrefixLookup(){ return false;} //prefix lookup
public Set getAmbiguities() { return null; }
public void addAmbiguity(String n ) { }
public void addAmbiguity(String n ) { /*nothing*/ }
public List getParameters() { return null; } //parameter info for resolving functions
public HashSet getAssociated() { return null; } //associated namespaces for argument dependant lookup
public ISymbol getStopAt() { return null; } //stop looking along the stack once we hit this declaration
@ -2253,18 +2243,19 @@ public class ParserSymbolTable {
static protected class Cost
{
public Cost( TypeInfoProvider provider, TypeInfo s, TypeInfo t ){
source = provider.getTypeInfo();
if( s != null )
public Cost( TypeInfoProvider provider, ITypeInfo s, ITypeInfo t ){
if( s != null ){
source = provider.getTypeInfo( s.getType() );
source.copy( s );
target = provider.getTypeInfo();
if( t != null )
}
if( t != null ){
target = provider.getTypeInfo( t.getType() );
target.copy( t );
}
}
private TypeInfo source;
private TypeInfo target;
private ITypeInfo source;
private ITypeInfo target;
public boolean targetHadReference = false;
@ -2336,12 +2327,12 @@ public class ParserSymbolTable {
ListIterator iter1 = cost.getTarget().getPtrOperators().listIterator( size );
ListIterator iter2 = getTarget().getPtrOperators().listIterator( size2 );
TypeInfo.PtrOp op1 = null, op2 = null;
ITypeInfo.PtrOp op1 = null, op2 = null;
int subOrSuper = 0;
for( int i = ( size < size2 ) ? size : size2; i > 0; i-- ){
op1 = (TypeInfo.PtrOp)iter1.previous();
op2 = (TypeInfo.PtrOp)iter2.previous();
op1 = (ITypeInfo.PtrOp)iter1.previous();
op2 = (ITypeInfo.PtrOp)iter2.previous();
if( subOrSuper == 0)
subOrSuper = op1.compareCVTo( op2 );
@ -2370,14 +2361,14 @@ public class ParserSymbolTable {
/**
* @return Returns the source.
*/
public TypeInfo getSource() {
public ITypeInfo getSource() {
return source;
}
/**
* @return Returns the target.
*/
public TypeInfo getTarget() {
public ITypeInfo getTarget() {
return target;
}
}
@ -2423,7 +2414,7 @@ public class ParserSymbolTable {
//if static or an enumerator, the symbol could be visible through more than one path through the heirarchy,
//so we need to check all paths
boolean checkAllPaths = ( symbol.isType( TypeInfo.t_enumerator ) || symbol.getTypeInfo().checkBit( TypeInfo.isStatic ) );
boolean checkAllPaths = ( symbol.isType( ITypeInfo.t_enumerator ) || symbol.getTypeInfo().checkBit( ITypeInfo.isStatic ) );
ASTAccessVisibility resultingAccess = null;
for( int i = 0; i < numParents; i++ ){
parent = (IParentSymbol) parents.get(i);
@ -2455,62 +2446,4 @@ public class ParserSymbolTable {
}
return resultingAccess;
}
public static class TypeInfoProvider
{
private final int POOL_SIZE = 16;
private final TypeInfo [] pool;
private final boolean [] free;
private int firstFreeHint = 0;
public TypeInfoProvider()
{
pool = new TypeInfo[ POOL_SIZE ];
free = new boolean[POOL_SIZE];
for( int i = 0; i < POOL_SIZE; i++ )
{
pool[i] = new TypeInfo();
free[i] = true;
}
}
public TypeInfo getTypeInfo()
{
for( int i = firstFreeHint; i < POOL_SIZE; ++i )
{
if( free[i] )
{
free[i] = false;
firstFreeHint = i + 1;
return pool[i];
}
}
//if there is nothing free, just give them a new one
return new TypeInfo();
}
public void returnTypeInfo( TypeInfo t )
{
for( int i = 0; i < POOL_SIZE; i++ ){
if( pool[i] == t ){
t.clear();
free[i] = true;
if( i < firstFreeHint ){
firstFreeHint = i;
}
return;
}
}
//else it was one allocated outside the pool
}
public int numAllocated(){
int num = 0;
for( int i = 0; i < POOL_SIZE; i++ ){
if( !free[i] )
num++;
}
return num;
}
}
}

View file

@ -29,10 +29,6 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
super( table, name );
}
protected SpecializedSymbol( ParserSymbolTable table, String name, ISymbolASTExtension obj ){
super( table, name, obj );
}
public Object clone(){
SpecializedSymbol copy = (SpecializedSymbol)super.clone();
@ -67,16 +63,16 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
int numSpecArgs = specArgs.size();
for( int i = 0; i < numSpecArgs; i++ ){
TypeInfo info = (TypeInfo) specArgs.get(i);
TypeInfo mappedInfo = (TypeInfo) arguments.get(i);
ITypeInfo info = (ITypeInfo) specArgs.get(i);
ITypeInfo mappedInfo = (ITypeInfo) arguments.get(i);
//If the argument is a template parameter, we can't instantiate yet, defer for later
if( mappedInfo.isType( TypeInfo.t_type ) && mappedInfo.getTypeSymbol().isType( TypeInfo.t_templateParameter ) ){
if( mappedInfo.isType( ITypeInfo.t_type ) && mappedInfo.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) ){
return deferredInstance( arguments );
}
actualArgs.add( mappedInfo );
if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol().isType( TypeInfo.t_templateParameter )){
if( info.isType( ITypeInfo.t_type ) && info.getTypeSymbol().isType( ITypeInfo.t_templateParameter )){
ISymbol param = info.getTypeSymbol();
param = TemplateEngine.translateParameterForDefinition ( templatedSymbol, param, getDefinitionParameterMap() );
@ -141,7 +137,7 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addArgument(org.eclipse.cdt.internal.core.parser.pst.ISymbol)
*/
public void addArgument(TypeInfo arg) {
public void addArgument(ITypeInfo arg) {
if( _argumentList == Collections.EMPTY_LIST )
_argumentList = new ArrayList(4);

View file

@ -20,44 +20,43 @@ import java.util.Set;
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Cost;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
/**
* @author aniefer
*/
public final class TemplateEngine {
static protected TypeInfo instantiateTypeInfo( TypeInfo info, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{
static protected ITypeInfo instantiateTypeInfo( ITypeInfo info, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{
if( argMap == null )
return info;
if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() == null )
if( info.isType( ITypeInfo.t_type ) && info.getTypeSymbol() == null )
return info;
if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() instanceof IDeferredTemplateInstance ){
if( info.isType( ITypeInfo.t_type ) && info.getTypeSymbol() instanceof IDeferredTemplateInstance ){
IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) info.getTypeSymbol();
TypeInfo newInfo = new TypeInfo( info );
ITypeInfo newInfo = TypeInfoProvider.newTypeInfo( info );
//newInfo.setTypeSymbol( deferred.instantiate( template, argMap ) );
template.registerDeferredInstatiation( newInfo, deferred, ITemplateSymbol.DeferredKind.TYPE_SYMBOL, argMap );
newInfo.setTypeSymbol( deferred );
return newInfo;
} else if( info.isType( TypeInfo.t_type ) &&
info.getTypeSymbol().isType( TypeInfo.t_templateParameter ) &&
} else if( info.isType( ITypeInfo.t_type ) &&
info.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) &&
argMap.containsKey( info.getTypeSymbol() ) )
{
TypeInfo targetInfo = new TypeInfo( (TypeInfo) argMap.get( info.getTypeSymbol() ) );
ITypeInfo targetInfo = TypeInfoProvider.newTypeInfo( (ITypeInfo) argMap.get( info.getTypeSymbol() ) );
if( info.hasPtrOperators() ){
targetInfo.addPtrOperator( info.getPtrOperators() );
}
if( info.checkBit( TypeInfo.isConst ) )
targetInfo.setBit( true, TypeInfo.isConst );
if( info.checkBit( ITypeInfo.isConst ) )
targetInfo.setBit( true, ITypeInfo.isConst );
if( info.checkBit( TypeInfo.isVolatile ) )
targetInfo.setBit( true, TypeInfo.isVolatile );
if( info.checkBit( ITypeInfo.isVolatile ) )
targetInfo.setBit( true, ITypeInfo.isVolatile );
return targetInfo;
} else if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol().isType( TypeInfo.t_function ) ){
TypeInfo newInfo = new TypeInfo( info );
} else if( info.isType( ITypeInfo.t_type ) && info.getTypeSymbol().isType( ITypeInfo.t_function ) ){
ITypeInfo newInfo = TypeInfoProvider.newTypeInfo( info );
newInfo.setTypeSymbol( info.getTypeSymbol().instantiate( template, argMap ) );
return newInfo;
}
@ -65,7 +64,7 @@ public final class TemplateEngine {
}
static protected void instantiateDeferredTypeInfo( TypeInfo info, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException {
static protected void instantiateDeferredTypeInfo( ITypeInfo info, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException {
info.setTypeSymbol( info.getTypeSymbol().instantiate( template, argMap ) );
}
@ -74,7 +73,7 @@ public final class TemplateEngine {
* @param symbol
* @param map
*/
public static void discardDeferredTypeInfo(TypeInfo info, TemplateSymbol template, Map map) {
public static void discardDeferredTypeInfo(ITypeInfo info, TemplateSymbol template, Map map) {
ISymbol instance = info.getTypeSymbol();
if( !(instance instanceof IDeferredTemplateInstance ) )
template.removeInstantiation( (IContainerSymbol) instance );
@ -105,12 +104,12 @@ public final class TemplateEngine {
int specArgsSize = specArgs.size();
HashMap map = new HashMap();
TypeInfo info1 = null, info2 = null;
ITypeInfo info1 = null, info2 = null;
boolean match = true;
for( int j = 0; j < specArgsSize; j++ ){
info1 = (TypeInfo) specArgs.get(j);
info2 = (TypeInfo) args.get(j);
info1 = (ITypeInfo) specArgs.get(j);
info2 = (ITypeInfo) args.get(j);
ISymbol sym1 = template.getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME );
sym1.setTypeInfo( info1 );
@ -140,17 +139,17 @@ public final class TemplateEngine {
return bestMatch;
}
static protected boolean matchTemplateParameterAndArgument( ISymbol param, TypeInfo arg ){
static protected boolean matchTemplateParameterAndArgument( ISymbol param, ITypeInfo arg ){
if( !isValidArgument(param, arg) ){
return false;
}
if( param.getTypeInfo().getTemplateParameterType() == TypeInfo.t_typeName ){
if( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName ){
return true;
} else if( param.getTypeInfo().getTemplateParameterType() == TypeInfo.t_template ){
} else if( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){
ISymbol symbol = arg.getTypeSymbol();
if( !arg.isType( TypeInfo.t_type ) || symbol == null || !symbol.isType( TypeInfo.t_template ) ){
if( !arg.isType( ITypeInfo.t_type ) || symbol == null || !symbol.isType( ITypeInfo.t_template ) ){
return false;
}
@ -178,12 +177,18 @@ public final class TemplateEngine {
return true;
} else {
Cost cost = null;
TypeInfoProvider provider = TypeInfoProvider.getProvider( param.getSymbolTable() );
try{
ITypeInfo info = provider.getTypeInfo( param.getTypeInfo().getTemplateParameterType() );
try {
TypeInfo info = new TypeInfo( param.getTypeInfo() );
info.copy( param.getTypeInfo() );
info.setType( info.getTemplateParameterType() );
cost = param.getSymbolTable().checkStandardConversionSequence( arg, info );
provider.returnTypeInfo( info );
} catch (ParserSymbolTableException e) {
//nothing
} finally {
provider.returnTypeInfo( info );
}
if( cost == null || cost.rank != Cost.NO_MATCH_RANK ){
@ -191,16 +196,16 @@ public final class TemplateEngine {
}
} finally{
if( cost != null )
cost.release( param.getSymbolTable().getTypeInfoProvider() );
cost.release( provider );
}
}
return true;
}
static private boolean isValidArgument(ISymbol param, TypeInfo arg) {
if( param.getTypeInfo().getTemplateParameterType() == TypeInfo.t_typeName ){
static private boolean isValidArgument(ISymbol param, ITypeInfo arg) {
if( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName ){
//14.3.1, local type, type with no name
if( arg.isType( TypeInfo.t_type ) && arg.getTypeSymbol() != null ){
if( arg.isType( ITypeInfo.t_type ) && arg.getTypeSymbol() != null ){
ISymbol symbol = arg.getTypeSymbol();
if( symbol.getName().equals( ParserSymbolTable.EMPTY_NAME ) ){
return false;
@ -208,15 +213,15 @@ public final class TemplateEngine {
return false;
}
}
} else if ( param.getTypeInfo().getTemplateParameterType() == TypeInfo.t_template ){
} else if ( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){
//TODO
} else {
List ptrs = param.getPtrOperators();
PtrOp op = ( ptrs.size() > 0 ) ? (PtrOp) ptrs.get(0) : null;
ITypeInfo.PtrOp op = ( ptrs.size() > 0 ) ? (ITypeInfo.PtrOp) ptrs.get(0) : null;
//if the parameter has reference type
if( op != null && op.getType() == PtrOp.t_reference ){
if( arg.isType( TypeInfo.t_type ) && arg.getTypeSymbol() != null ){
if( op != null && op.getType() == ITypeInfo.PtrOp.t_reference ){
if( arg.isType( ITypeInfo.t_type ) && arg.getTypeSymbol() != null ){
if( arg.getTypeSymbol().getName().equals( ParserSymbolTable.EMPTY_NAME ) ){
return false;
}
@ -225,17 +230,17 @@ public final class TemplateEngine {
}
List argPtrs = arg.getPtrOperators();
PtrOp argOp = (argPtrs.size() > 0 ) ? (PtrOp)argPtrs.get(0) : null;
ITypeInfo.PtrOp argOp = (argPtrs.size() > 0 ) ? (ITypeInfo.PtrOp)argPtrs.get(0) : null;
//address of an object with external linkage exluding nonstatic class members
//name of an object with external linkage excluding nonstatic class members
if( (argOp != null && argOp.getType() == PtrOp.t_pointer ) ||
( arg.isType( TypeInfo.t_type ) ) )
if( (argOp != null && argOp.getType() == ITypeInfo.PtrOp.t_pointer ) ||
( arg.isType( ITypeInfo.t_type ) ) )
{
ISymbol symbol = arg.getTypeSymbol();
if ( symbol != null && symbol.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) ){
if( !symbol.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
if( !symbol.getTypeInfo().checkBit( TypeInfo.isStatic ) ){
if ( symbol != null && symbol.getContainingSymbol().isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){
if( !symbol.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){
if( !symbol.getTypeInfo().checkBit( ITypeInfo.isStatic ) ){
return false;
}
}
@ -245,16 +250,16 @@ public final class TemplateEngine {
}
//integral or enumeration type
if( op == null && ( arg.isType( TypeInfo.t_bool, TypeInfo.t_int ) ||
arg.isType( TypeInfo.t_enumerator ) ) )
if( op == null && ( arg.isType( ITypeInfo.t_bool, ITypeInfo.t_int ) ||
arg.isType( ITypeInfo.t_enumerator ) ) )
{
return true;
}
//name of a non-type template parameter
if( arg.isType( TypeInfo.t_templateParameter ) &&
arg.getTemplateParameterType() != TypeInfo.t_typeName &&
arg.getTemplateParameterType() != TypeInfo.t_template )
if( arg.isType( ITypeInfo.t_templateParameter ) &&
arg.getTemplateParameterType() != ITypeInfo.t_typeName &&
arg.getTemplateParameterType() != ITypeInfo.t_template )
{
return true;
}
@ -263,25 +268,25 @@ public final class TemplateEngine {
return true;
}
static protected boolean hasExternalLinkage( TypeInfo type ){
if( ! type.isType( TypeInfo.t_type ) )
static protected boolean hasExternalLinkage( ITypeInfo type ){
if( ! type.isType( ITypeInfo.t_type ) )
return false;
return !hasNoLinkage( type );
}
static protected boolean hasInternalLinkage( TypeInfo type ){
static protected boolean hasInternalLinkage( ITypeInfo type ){
return !hasNoLinkage( type );
}
static protected boolean hasNoLinkage( TypeInfo type ){
if( type.isType( TypeInfo.t_type ) ){
static protected boolean hasNoLinkage( ITypeInfo type ){
if( type.isType( ITypeInfo.t_type ) ){
ISymbol symbol = type.getTypeSymbol();
if( symbol.getContainingSymbol() == null ){
return true; //a temporary
}
return symbol.getContainingSymbol().isType( TypeInfo.t_function );
return symbol.getContainingSymbol().isType( ITypeInfo.t_function );
}
return false;
@ -293,20 +298,20 @@ public final class TemplateEngine {
* @param pSymbol
* @return
*/
static private TypeInfo getParameterTypeForDeduction( ISymbol pSymbol ){
TypeInfo p = new TypeInfo( pSymbol.getTypeInfo () );
static private ITypeInfo getParameterTypeForDeduction( ISymbol pSymbol ){
ITypeInfo p = TypeInfoProvider.newTypeInfo( pSymbol.getTypeInfo () );
List pPtrs = p.getPtrOperators();
if( pPtrs.size() > 0 ){
PtrOp pOp = (PtrOp) pPtrs.get( 0 );
if( pOp.getType() == PtrOp.t_reference || pOp.getType() == PtrOp.t_undef_ptr ){
ITypeInfo.PtrOp pOp = (ITypeInfo.PtrOp) pPtrs.get( 0 );
if( pOp.getType() == ITypeInfo.PtrOp.t_reference || pOp.getType() == ITypeInfo.PtrOp.t_undef_ptr ){
pPtrs.remove( 0 );
} else {
PtrOp newOp = new PtrOp( pOp.getType(), false, false );
ITypeInfo.PtrOp newOp = new ITypeInfo.PtrOp( pOp.getType(), false, false );
pPtrs.set( 0, newOp );
}
} else {
p.setBit( false, TypeInfo.isConst );
p.setBit( false, TypeInfo.isVolatile );
p.setBit( false, ITypeInfo.isConst );
p.setBit( false, ITypeInfo.isVolatile );
}
@ -322,32 +327,32 @@ public final class TemplateEngine {
* @param aInfo
* @return
*/
static private TypeInfo getArgumentTypeForDeduction( TypeInfo aInfo, boolean pIsAReferenceType ) throws ParserSymbolTableException{
static private ITypeInfo getArgumentTypeForDeduction( ITypeInfo aInfo, boolean pIsAReferenceType ) throws ParserSymbolTableException{
TypeInfo a = ParserSymbolTable.getFlatTypeInfo( aInfo, null );
ITypeInfo a = ParserSymbolTable.getFlatTypeInfo( aInfo, null );
if( !pIsAReferenceType ){
ISymbol aSymbol = a.getTypeSymbol();
if( a.getType() == TypeInfo.t_type ){
if( a.getType() == ITypeInfo.t_type ){
if( aSymbol == null ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument );
} else if( aSymbol.isType( TypeInfo.t_function ) && a.getPtrOperators().size() == 0 ){
a.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
} else if( aSymbol.isType( ITypeInfo.t_function ) && a.getPtrOperators().size() == 0 ){
a.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) );
}
}
List aPtrs = a.getPtrOperators();
if( aPtrs.size() > 0 ){
PtrOp pOp = (PtrOp) aPtrs.get( 0 );
ITypeInfo.PtrOp pOp = (ITypeInfo.PtrOp) aPtrs.get( 0 );
if( pOp.getType() == PtrOp.t_array ){
aPtrs.set( 0, new PtrOp( PtrOp.t_pointer, false, false ) );
if( pOp.getType() == ITypeInfo.PtrOp.t_array ){
aPtrs.set( 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) );
} else {
aPtrs.set( 0, new PtrOp( pOp.getType(), false, false ) );
aPtrs.set( 0, new ITypeInfo.PtrOp( pOp.getType(), false, false ) );
}
} else {
a.setBit( false, TypeInfo.isConst );
a.setBit( false, TypeInfo.isVolatile );
a.setBit( false, ITypeInfo.isConst );
a.setBit( false, ITypeInfo.isVolatile );
}
}
@ -437,30 +442,30 @@ public final class TemplateEngine {
return aSymbol;
}
static private boolean deduceTemplateArgument( Map map, ISymbol pSymbol, TypeInfo a ) throws ParserSymbolTableException{//, Map argumentMap ){
static private boolean deduceTemplateArgument( Map map, ISymbol pSymbol, ITypeInfo a ) throws ParserSymbolTableException{
ISymbol symbol;
boolean pIsAReferenceType = false;
List ptrOps = pSymbol.getPtrOperators();
if( ptrOps.size() > 0 && ((PtrOp)ptrOps.get(0)).getType() == TypeInfo.PtrOp.t_reference ){
if( ptrOps.size() > 0 && ((ITypeInfo.PtrOp)ptrOps.get(0)).getType() == ITypeInfo.PtrOp.t_reference ){
pIsAReferenceType = true;
}
TypeInfo p = getParameterTypeForDeduction( pSymbol );
ITypeInfo p = getParameterTypeForDeduction( pSymbol );
a = getArgumentTypeForDeduction( a, pIsAReferenceType );
if( p.isType( TypeInfo.t_type ) ){
if( p.isType( ITypeInfo.t_type ) ){
symbol = p.getTypeSymbol();
ISymbol aSymbol = a.getTypeSymbol();
if( symbol == null || ( a.isType( TypeInfo.t_type) && aSymbol == null ) || a.isType( TypeInfo.t_undef ))
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() ){
return deduceFromTemplateTemplateArguments(map, symbol, aSymbol);
}
if( symbol.isType( TypeInfo.t_templateParameter ) ){
if( symbol.getTypeInfo().getTemplateParameterType() == TypeInfo.t_typeName ){
if( symbol.isType( ITypeInfo.t_templateParameter ) ){
if( symbol.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName ){
//a = getFlatTypeInfo( a );
List aPtrs = a.getPtrOperators();
List pPtrs = p.getPtrOperators();
@ -475,13 +480,13 @@ public final class TemplateEngine {
if( pSize != aSize )
return false;
PtrOp pOp = null;
PtrOp aOp = null;
ITypeInfo.PtrOp pOp = null;
ITypeInfo.PtrOp aOp = null;
int aIdx = 0;
for( int i = 0; i < pSize; i++ ){
pOp = (PtrOp) pPtrs.get(i);
aOp = (PtrOp) aPtrs.get(aIdx++);
pOp = (ITypeInfo.PtrOp) pPtrs.get(i);
aOp = (ITypeInfo.PtrOp) aPtrs.get(aIdx++);
if( pOp.getType() == aOp.getType() ){
if( !pOp.equals( aOp ) )
return false;
@ -492,22 +497,22 @@ public final class TemplateEngine {
}
}
//cvlist T
if( p.checkBit( TypeInfo.isConst ) ){
if( !a.checkBit( TypeInfo.isConst ) )
if( p.checkBit( ITypeInfo.isConst ) ){
if( !a.checkBit( ITypeInfo.isConst ) )
return false;
a.setBit( false, TypeInfo.isConst);
a.setBit( false, ITypeInfo.isConst);
}
if( p.checkBit( TypeInfo.isVolatile ) ){
if( !a.checkBit( TypeInfo.isVolatile ) )
if( p.checkBit( ITypeInfo.isVolatile ) ){
if( !a.checkBit( ITypeInfo.isVolatile ) )
return false;
a.setBit( false, TypeInfo.isVolatile);
a.setBit( false, ITypeInfo.isVolatile);
}
//T
return deduceArgument( map, symbol, a );
} else if ( symbol.getTypeInfo().getTemplateParameterType() == TypeInfo.t_template ){
} else if ( symbol.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){
//TODO
} else {
//non-type parameter
if( symbol.getTypeInfo().getTemplateParameterType() == a.getType() ){
@ -517,9 +522,9 @@ public final class TemplateEngine {
}
}
//T (*) ( ), T ( T::* ) ( T ), & variations
else if( symbol.isType( TypeInfo.t_function ) ){
else if( symbol.isType( ITypeInfo.t_function ) ){
if( !(aSymbol instanceof IParameterizedSymbol)||
!aSymbol.isType( TypeInfo.t_function ) )
!aSymbol.isType( ITypeInfo.t_function ) )
{
return false;
}
@ -533,9 +538,9 @@ public final class TemplateEngine {
List pPtrs = p.getPtrOperators();
if( pPtrs.size() != 0 ){
PtrOp op = (PtrOp) pPtrs.get(0);
if( op.getType() == PtrOp.t_memberPointer ){
TypeInfo info = new TypeInfo( TypeInfo.t_type, 0, aFunction.getContainingSymbol() );
ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) pPtrs.get(0);
if( op.getType() == ITypeInfo.PtrOp.t_memberPointer ){
ITypeInfo info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, aFunction.getContainingSymbol() );
if( !deduceTemplateArgument( map, op.getMemberOf(), info ) ){
return false;
}
@ -549,7 +554,7 @@ public final class TemplateEngine {
}
int size = pParams.size();
for( int i = 0; i < size; i++ ){
TypeInfo info = ((ISymbol)aParams.get( i )).getTypeInfo();
ITypeInfo info = ((ISymbol)aParams.get( i )).getTypeInfo();
if( !deduceTemplateArgument( map, (ISymbol)pParams.get(i), info ) ){
return false;
}
@ -558,7 +563,7 @@ public final class TemplateEngine {
}
}
if( p.isType( TypeInfo.t_templateParameter ) ){
if( p.isType( ITypeInfo.t_templateParameter ) ){
return deduceArgument( map, pSymbol, a );
}
if( p.getType() == a.getType() ){
@ -621,10 +626,10 @@ public final class TemplateEngine {
sym = (ISymbol) obj;
} else {
sym = pSymbol.getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME );
sym.setTypeInfo( (TypeInfo) obj );
sym.setTypeInfo( (ITypeInfo) obj );
}
TypeInfo arg = transformTypeInfo( aList.get( i ), null );
ITypeInfo arg = transformTypeInfo( aList.get( i ), null );
try {
if( !deduceTemplateArgument( map, sym, arg ) ){
@ -676,7 +681,7 @@ public final class TemplateEngine {
}
ISymbol templateSymbol = template.getTemplatedSymbol();
if( !templateSymbol.isType( TypeInfo.t_function ) ){
if( !templateSymbol.isType( ITypeInfo.t_function ) ){
return null;
}
@ -693,7 +698,7 @@ public final class TemplateEngine {
int size = pList.size();
for( int i = 0; i < size; i++ ){
try {
if( !deduceTemplateArgument( map, (ISymbol) pList.get(i), (TypeInfo) arguments.get(i) ) ){
if( !deduceTemplateArgument( map, (ISymbol) pList.get(i), (ITypeInfo) arguments.get(i) ) ){
return null;
}
} catch (ParserSymbolTableException e) {
@ -704,12 +709,12 @@ public final class TemplateEngine {
return map;
}
static private boolean deduceArgument( Map map, ISymbol p, TypeInfo a ){
static private boolean deduceArgument( Map map, ISymbol p, ITypeInfo a ){
a = ParserSymbolTable.getFlatTypeInfo( a, null );
if( map.containsKey( p ) ){
TypeInfo current = (TypeInfo)map.get( p );
ITypeInfo current = (ITypeInfo)map.get( p );
return current.equals( a );
}
map.put( p, a );
@ -733,7 +738,7 @@ public final class TemplateEngine {
ITemplateSymbol template1 = spec1;
ITemplateSymbol template2 = spec2;
if( decl.isType( TypeInfo.t_class, TypeInfo.t_union ) ) {
if( decl.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ) {
template1 = classTemplateSpecializationToFunctionTemplate( spec1 );
template2 = classTemplateSpecializationToFunctionTemplate( spec2 );
}
@ -805,22 +810,22 @@ public final class TemplateEngine {
static private Map createMapForFunctionTemplateOrdering( ITemplateSymbol template ){
HashMap map = new HashMap();
TypeInfo val = null;
ITypeInfo val = null;
List paramList = template.getParameterList();
int size = paramList.size();
for( int i = 0; i < size; i++ ){
ISymbol param = (ISymbol) paramList.get( i );
//template type parameter
if( param.getTypeInfo().getTemplateParameterType() == TypeInfo.t_typeName ){
val = new TypeInfo( TypeInfo.t_type, 0, template.getSymbolTable().newSymbol( "", TypeInfo.t_class ) ); //$NON-NLS-1$
if( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName ){
val = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, template.getSymbolTable().newSymbol( "", ITypeInfo.t_class ) ); //$NON-NLS-1$
}
//template parameter
else if ( param.getTypeInfo().getTemplateParameterType() == TypeInfo.t_template ) {
else if ( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ) {
//TODO
}
//non type parameter
else {
val = new TypeInfo( param.getTypeInfo().getTemplateParameterType(), 0, null );
val = TypeInfoProvider.newTypeInfo( param.getTypeInfo().getTemplateParameterType() );
}
map.put( param, val );
}
@ -844,13 +849,13 @@ public final class TemplateEngine {
//TODO clean up this
((ContainerSymbol)transformed).getContents().clear();
IParameterizedSymbol function = specialization.getSymbolTable().newParameterizedSymbol( transformed.getName(), TypeInfo.t_function );
IParameterizedSymbol function = specialization.getSymbolTable().newParameterizedSymbol( transformed.getName(), ITypeInfo.t_function );
try{
transformed.addSymbol( function );
} catch ( ParserSymbolTableException e ){
//we shouldn't get this because there aren't any other symbols in the template
}
ISymbol param = specialization.getSymbolTable().newSymbol( "", TypeInfo.t_type ); //$NON-NLS-1$
ISymbol param = specialization.getSymbolTable().newSymbol( "", ITypeInfo.t_type ); //$NON-NLS-1$
param.setTypeSymbol( specialization.instantiate( specialization.getArgumentList() ) );
@ -859,22 +864,22 @@ public final class TemplateEngine {
return transformed;
}
static private TypeInfo transformTypeInfo( Object obj, Map argumentMap ){
TypeInfo info = null;
static private ITypeInfo transformTypeInfo( Object obj, Map argumentMap ){
ITypeInfo info = null;
if( obj instanceof ISymbol ){
info = new TypeInfo( TypeInfo.t_type, 0, (ISymbol) obj );
info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, (ISymbol) obj );
} else {
info = (TypeInfo) obj;
info = (ITypeInfo) obj;
}
if( argumentMap == null )
return info;
if( info.isType( TypeInfo.t_type ) &&
info.getTypeSymbol().isType( TypeInfo.t_templateParameter ) &&
argumentMap.containsKey( info.getTypeSymbol() ) )
if( info.isType( ITypeInfo.t_type ) &&
info.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) &&
argumentMap.containsKey( info.getTypeSymbol() ) )
{
TypeInfo newType = new TypeInfo( (TypeInfo) argumentMap.get( info.getTypeSymbol() ) );
ITypeInfo newType = TypeInfoProvider.newTypeInfo( (ITypeInfo) argumentMap.get( info.getTypeSymbol() ) );
if( info.hasPtrOperators() )
newType.addPtrOperator( info.getPtrOperators() );
@ -907,8 +912,8 @@ public final class TemplateEngine {
List instanceArgs = new ArrayList( templateParams.size() );
for( int i = 0; i < numTemplateParams; i++ ){
ISymbol param = (ISymbol) templateParams.get(i);
TypeInfo arg = (TypeInfo) ( i < numTemplateArgs ? templateArguments.get(i) : null);
TypeInfo mapped = (TypeInfo) map.get( param );
ITypeInfo arg = (ITypeInfo) ( i < numTemplateArgs ? templateArguments.get(i) : null);
ITypeInfo mapped = (ITypeInfo) map.get( param );
if( arg != null && mapped != null )
if( arg.equals( mapped ) )
@ -952,7 +957,7 @@ public final class TemplateEngine {
} else if( !parameters.isEmpty() ){
int size = parameters.size();
for( int i = 0; i < size; i++ ){
if( parameters.get(i) != ((TypeInfo) arguments.get(i)).getTypeSymbol() ){
if( parameters.get(i) != ((ITypeInfo) arguments.get(i)).getTypeSymbol() ){
forPrimary = false;
break;
}
@ -1025,12 +1030,12 @@ public final class TemplateEngine {
int a1Size = a1.size();
for( int i = 0; i < a1Size; i++ ){
TypeInfo t1 = (TypeInfo) a1.get( i );
TypeInfo t2 = (TypeInfo) a2.get( i );
ITypeInfo t1 = (ITypeInfo) a1.get( i );
ITypeInfo t2 = (ITypeInfo) a2.get( i );
if( t1.equals( t2 ) ){
continue;
} else if( t1.isType( TypeInfo.t_type ) && t2.isType( TypeInfo.t_type ) ) {
} else if( t1.isType( ITypeInfo.t_type ) && t2.isType( ITypeInfo.t_type ) ) {
ISymbol s1 = t1.getTypeSymbol(), s2 = t2.getTypeSymbol();
if( m[0].containsKey( s1 ) && m[1].containsKey( s2 ) && m[0].get( s1 ).equals( m[1].get( s2 ) ) )
continue;
@ -1097,7 +1102,7 @@ public final class TemplateEngine {
*/
static protected ISymbol instantiateWithinTemplateScope( IContainerSymbol container, ITemplateSymbol symbol ) throws ParserSymbolTableException
{
if( symbol.getTemplatedSymbol().isType( TypeInfo.t_function ) ){
if( symbol.getTemplatedSymbol().isType( ITypeInfo.t_function ) ){
return symbol;
}
@ -1115,7 +1120,7 @@ public final class TemplateEngine {
}
containing = containing.getContainingSymbol();
if( containing != null && !containing.isTemplateMember() || !containing.isType( TypeInfo.t_template ) ){
if( containing != null && !containing.isTemplateMember() || !containing.isType( ITypeInfo.t_template ) ){
break;
}
}
@ -1129,7 +1134,7 @@ public final class TemplateEngine {
int size = params.size();
List args = new ArrayList( size );
for( int i = 0; i < size; i++ ){
args.add( new TypeInfo( TypeInfo.t_type, 0, (ISymbol) params.get(i) ) );
args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, (ISymbol) params.get(i) ) );
}
instance = template.instantiate( args );
@ -1154,14 +1159,14 @@ public final class TemplateEngine {
static protected boolean canAddTemplate( IContainerSymbol containing, ITemplateSymbol template ){
//14-2 A template-declaration can appear only as a namespace scope or class scope declaration
if( !containing.isType( TypeInfo.t_namespace ) && !containing.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
if( !containing.isType( ITypeInfo.t_namespace ) && !containing.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){
return false;
}
//14.5.2-3 A member function template shall not be virtual
if( containing.isTemplateMember() && containing.getContainingSymbol().isType( TypeInfo.t_template ) ){
if( containing.isTemplateMember() && containing.getContainingSymbol().isType( ITypeInfo.t_template ) ){
ISymbol symbol = template.getTemplatedSymbol();
if( symbol != null && symbol.isType( TypeInfo.t_function ) && symbol.getTypeInfo().checkBit( TypeInfo.isVirtual ) ){
if( symbol != null && symbol.isType( ITypeInfo.t_function ) && symbol.getTypeInfo().checkBit( ITypeInfo.isVirtual ) ){
return false;
}
}
@ -1178,7 +1183,7 @@ public final class TemplateEngine {
for( int i = 0; i < numParams; i++ ){
ISymbol param = (ISymbol) params.get(i);
if( i < numArgs ){
TypeInfo arg = (TypeInfo) arguments.get(i);
ITypeInfo arg = (ITypeInfo) arguments.get(i);
if( matchTemplateParameterAndArgument( param, arg ) ){
actualArgs.add( arg );
} else {
@ -1220,7 +1225,7 @@ public final class TemplateEngine {
int numArgs = args.size();
for( int i = 0; i < numParams && i < numArgs; i++ ){
ISymbol param = (ISymbol) params.get(i);
TypeInfo arg = (TypeInfo) args.get(i);
ITypeInfo arg = (ITypeInfo) args.get(i);
if( map.containsKey( param ) ) {
if( !map.get( param ).equals( arg )){
continue outer;
@ -1250,9 +1255,9 @@ public final class TemplateEngine {
int numArgs = ( args != null ) ? args.size() : 0;
for( int i = 0; i < numParams; i++ ){
ISymbol param = (ISymbol) params.get(i);
TypeInfo arg = null;
ITypeInfo arg = null;
if( i < numArgs ){
arg = (TypeInfo) args.get(i);
arg = (ITypeInfo) args.get(i);
} else {
if( map == null ){
map = deduceTemplateArgumentsUsingParameterList( template, fn );
@ -1260,7 +1265,7 @@ public final class TemplateEngine {
return null;
}
if( map.containsKey( param ) ){
arg = (TypeInfo) map.get( param );
arg = (ITypeInfo) map.get( param );
}
}
@ -1294,7 +1299,7 @@ public final class TemplateEngine {
}
static protected boolean templateParametersAreEquivalent( ISymbol p1, ISymbol p2 ){
if( !p1.isType( TypeInfo.t_templateParameter ) || !p2.isType( TypeInfo.t_templateParameter ) ||
if( !p1.isType( ITypeInfo.t_templateParameter ) || !p2.isType( ITypeInfo.t_templateParameter ) ||
p1.getTypeInfo().getTemplateParameterType() != p2.getTypeInfo().getTemplateParameterType() )
{
return false;
@ -1303,11 +1308,11 @@ public final class TemplateEngine {
ITemplateSymbol t1 = getContainingTemplate( p1 );
ITemplateSymbol t2 = getContainingTemplate( p2 );
if( p1.getTypeInfo().getTemplateParameterType() == TypeInfo.t_typeName )
if( p1.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName )
{
List l1 = t1.getParameterList(), l2 = t2.getParameterList();
return ( l1 != null && l2 != null && l1.indexOf( p1 ) == l2.indexOf( p2 ) );
} else if( p1.getTypeInfo().getTemplateParameterType() == TypeInfo.t_template ){
} else if( p1.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){
ITemplateSymbol pt1 = (ITemplateSymbol)p1.getTypeSymbol();
ITemplateSymbol pt2 = (ITemplateSymbol)p2.getTypeSymbol();
return checkTemplateParameterListsAreEquivalent( pt1.getParameterList(), pt2.getParameterList() );
@ -1343,8 +1348,8 @@ public final class TemplateEngine {
return false;
for( int i = 0; i < size; i++ ){
TypeInfo info1 = (TypeInfo) args.get(i);
TypeInfo info2 = (TypeInfo) args2.get(i);
ITypeInfo info1 = (ITypeInfo) args.get(i);
ITypeInfo info2 = (ITypeInfo) args2.get(i);
if( ! info1.equals( info2 ) )
return false;

View file

@ -21,8 +21,6 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateInstantiation;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateSpecialization;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType;
/**
* @author aniefer
@ -84,7 +82,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
size = args.size();
spec.prepareArguments( size );
for( int i = 0; i < size; i++){
spec.addArgument( (TypeInfo) args.get(i) );
spec.addArgument( (ITypeInfo) args.get(i) );
}
spec.addSymbol( symbol );
@ -114,7 +112,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
int templatesSize = templates.size(), templatesIdx = 0;
for( int i = 0; i < size; i++ ){
sym = (ISymbol) symbols.get( i );
if( !sym.getContainingSymbol().isType( TypeInfo.t_template ) ){
if( !sym.getContainingSymbol().isType( ITypeInfo.t_template ) ){
symbols.remove( i-- );
size--;
} else if( templatesIdx < templatesSize ) {
@ -165,12 +163,12 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
}
}
if( symbol.isType( TypeInfo.t_function ) ){
if( symbol.isType( ITypeInfo.t_function ) ){
if( args != null )
previous = lookupFunctionTemplateId( symbol.getName(), argList, args, false );
else
previous = lookupMethodForDefinition( symbol.getName(), argList );
} else if ( symbol.isType( TypeInfo.t_constructor ) ){
} else if ( symbol.isType( ITypeInfo.t_constructor ) ){
previous = lookupConstructor( argList );
} else {
previous = lookupMemberForDefinition( symbol.getName() );
@ -318,7 +316,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
ISymbol instantiated = sym.getInstantiatedSymbol();
if( instantiated != null ){
IContainerSymbol container = instantiated.getContainingSymbol();
if( container.isType( TypeInfo.t_template ) ){
if( container.isType( ITypeInfo.t_template ) ){
((ITemplateSymbol) container ).removeInstantiation( sym );
}
}
@ -363,7 +361,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#elaboratedLookup(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType, java.lang.String)
*/
public ISymbol elaboratedLookup(eType type, String name) throws ParserSymbolTableException {
public ISymbol elaboratedLookup(ITypeInfo.eType type, String name) throws ParserSymbolTableException {
ListIterator iter = templates.listIterator( templates.size() );
while( iter.hasPrevious() ){
ITemplateSymbol template = (ITemplateSymbol) iter.previous();
@ -425,7 +423,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedLookup(java.lang.String, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType)
*/
public ISymbol qualifiedLookup(String name, eType t) throws ParserSymbolTableException {
public ISymbol qualifiedLookup(String name, ITypeInfo.eType t) throws ParserSymbolTableException {
return getContainingSymbol().qualifiedLookup( name, t );
}
@ -517,7 +515,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
int templateIdx = 0;
for( int i = 0; i < numSymbols; i++ ){
ISymbol symbol = (ISymbol) symbols.get(i);
if( symbol.getContainingSymbol().isType( TypeInfo.t_template ) ){
if( symbol.getContainingSymbol().isType( ITypeInfo.t_template ) ){
if( templateIdx < numTemplates )
templateIdx++;
else
@ -556,21 +554,21 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDirective(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol)
*/
public IUsingDirectiveSymbol addUsingDirective(IContainerSymbol namespace) throws ParserSymbolTableException {
public IUsingDirectiveSymbol addUsingDirective(IContainerSymbol namespace) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(java.lang.String)
*/
public IUsingDeclarationSymbol addUsingDeclaration(String name) throws ParserSymbolTableException {
public IUsingDeclarationSymbol addUsingDeclaration(String name) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(java.lang.String, org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol)
*/
public IUsingDeclarationSymbol addUsingDeclaration(String name, IContainerSymbol declContext) throws ParserSymbolTableException {
public IUsingDeclarationSymbol addUsingDeclaration(String name, IContainerSymbol declContext) {
return null;
}
@ -584,7 +582,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#prefixLookup(org.eclipse.cdt.internal.core.parser.pst.TypeFilter, java.lang.String, boolean)
*/
public List prefixLookup(TypeFilter filter, String prefix, boolean qualified, List paramList) throws ParserSymbolTableException {
public List prefixLookup(TypeFilter filter, String prefix, boolean qualified, List paramList) {
return null;
}
/* (non-Javadoc)
@ -611,7 +609,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#instantiate(org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol, java.util.Map)
*/
public ISymbol instantiate(ITemplateSymbol template, Map argMapParm) throws ParserSymbolTableException {
public ISymbol instantiate(ITemplateSymbol template, Map argMapParm) {
return null;
}
@ -619,6 +617,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setName(java.lang.String)
*/
public void setName(String name) {
/* nothing */
}
/* (non-Javadoc)
@ -631,41 +630,43 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#isType(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType)
*/
public boolean isType(eType type) {
public boolean isType(ITypeInfo.eType type) {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#isType(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType)
*/
public boolean isType(eType type, eType upperType) {
public boolean isType(ITypeInfo.eType type, ITypeInfo.eType upperType) {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getType()
*/
public eType getType() {
public ITypeInfo.eType getType() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setType(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType)
*/
public void setType(eType t) {
public void setType(ITypeInfo.eType t) {
/* nothing */
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getTypeInfo()
*/
public TypeInfo getTypeInfo() {
public ITypeInfo getTypeInfo() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setTypeInfo(org.eclipse.cdt.internal.core.parser.pst.TypeInfo)
*/
public void setTypeInfo(TypeInfo info) {
public void setTypeInfo(ITypeInfo info) {
/* nothing */
}
/* (non-Javadoc)
@ -679,6 +680,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setTypeSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol)
*/
public void setTypeSymbol(ISymbol type) {
/* nothing */
}
/* (non-Javadoc)
@ -692,6 +694,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setIsForwardDeclaration(boolean)
*/
public void setIsForwardDeclaration(boolean forward) {
/* nothing */
}
/* (non-Javadoc)
@ -711,7 +714,8 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#addPtrOperator(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp)
*/
public void addPtrOperator(PtrOp ptrOp) {
public void addPtrOperator(ITypeInfo.PtrOp ptrOp) {
/* nothing */
}
/* (non-Javadoc)
@ -732,6 +736,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setInstantiatedSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol)
*/
public void setInstantiatedSymbol(ISymbol symbol) {
/* nothing */
}
/* (non-Javadoc)
@ -745,6 +750,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setIsTemplateMember(boolean)
*/
public void setIsTemplateMember(boolean isMember) {
/* nothing */
}
/* (non-Javadoc)
@ -765,18 +771,21 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setIsInvisible(boolean)
*/
public void setIsInvisible(boolean invisible) {
/* nothing */
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addParent(org.eclipse.cdt.internal.core.parser.pst.ISymbol)
*/
public void addParent(ISymbol parent) {
/* nothing */
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addParent(org.eclipse.cdt.internal.core.parser.pst.ISymbol, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, int, java.util.List)
*/
public void addParent(ISymbol parent, boolean virtual, ASTAccessVisibility visibility, int offset, List references) {
/* nothing */
}
/* (non-Javadoc)
@ -796,13 +805,15 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addConstructor(org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol)
*/
public void addConstructor(IParameterizedSymbol constructor) throws ParserSymbolTableException {
public void addConstructor(IParameterizedSymbol constructor) {
/* nothing */
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addCopyConstructor()
*/
public void addCopyConstructor() throws ParserSymbolTableException {
public void addCopyConstructor() {
/* nothing */
}
/* (non-Javadoc)
@ -816,19 +827,20 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addFriend(org.eclipse.cdt.internal.core.parser.pst.ISymbol)
*/
public void addFriend(ISymbol friend) {
/* nothing */
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#lookupForFriendship(java.lang.String)
*/
public ISymbol lookupForFriendship(String name) throws ParserSymbolTableException {
public ISymbol lookupForFriendship(String name) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#lookupFunctionForFriendship(java.lang.String, java.util.List)
*/
public IParameterizedSymbol lookupFunctionForFriendship(String name, List parameters) throws ParserSymbolTableException {
public IParameterizedSymbol lookupFunctionForFriendship(String name, List parameters) {
return null;
}
@ -843,5 +855,20 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#preparePtrOperatros(int)
*/
public void preparePtrOperatros(int numPtrOps) {
/* nothing */
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setForwardSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol)
*/
public void setForwardSymbol(ISymbol forward) {
/* nothing */
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getForwardSymbol()
*/
public ISymbol getForwardSymbol() {
return null;
}
}

View file

@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jul 5, 2004
*/
package org.eclipse.cdt.internal.core.parser.pst;
/**
* @author aniefer
*/
public class TemplateParameterTypeInfo extends TypeInfo {
public ITypeInfo.eType getTemplateParameterType() {
return _templateParameterType;
}
public void setTemplateParameterType( ITypeInfo.eType type ) {
_templateParameterType = type;
}
public boolean equals( Object t ) {
if( !super.equals( t ) ){
return false;
}
return _templateParameterType == ((ITypeInfo)t).getTemplateParameterType();
}
private ITypeInfo.eType _templateParameterType = t_typeName;
}

View file

@ -17,8 +17,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
/**
* @author aniefer
*
@ -28,11 +26,7 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymbol {
protected TemplateSymbol ( ParserSymbolTable table, String name ){
super( table, name, TypeInfo.t_template );
}
protected TemplateSymbol( ParserSymbolTable table, String name, ISymbolASTExtension obj ){
super( table, name, obj );
super( table, name, ITypeInfo.t_template );
}
public Object clone(){
@ -57,9 +51,9 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#instantiate(java.util.List)
*/
public ISymbol instantiate( List arguments ) throws ParserSymbolTableException{
if( getType() != TypeInfo.t_template &&
( getType() != TypeInfo.t_templateParameter ||
getTypeInfo().getTemplateParameterType() != TypeInfo.t_template ) )
if( getType() != ITypeInfo.t_template &&
( getType() != ITypeInfo.t_templateParameter ||
getTypeInfo().getTemplateParameterType() != ITypeInfo.t_template ) )
{
return null;
}
@ -84,7 +78,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
HashMap map = new HashMap();
ISymbol param = null;
TypeInfo arg = null;
ITypeInfo arg = null;
List actualArgs = new ArrayList( numParams );
ISymbol templatedSymbol = template.getTemplatedSymbol();
@ -98,27 +92,27 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
param = TemplateEngine.translateParameterForDefinition ( templatedSymbol, param, getDefinitionParameterMap() );
if( i < numArgs ){
arg = (TypeInfo) arguments.get(i);
arg = (ITypeInfo) arguments.get(i);
//If the argument is a template parameter, we can't instantiate yet, defer for later
if( arg.isType( TypeInfo.t_type ) ){
if( arg.isType( ITypeInfo.t_type ) ){
if( arg.getTypeSymbol() == null )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument );
else if( arg.getTypeSymbol().isType( TypeInfo.t_templateParameter ) )
else if( arg.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) )
return deferredInstance( arguments );
}
} else {
Object obj = param.getTypeInfo().getDefault();
if( obj != null && obj instanceof TypeInfo ){
arg = (TypeInfo) obj;
if( arg.isType( TypeInfo.t_type ) && arg.getTypeSymbol().isType( TypeInfo.t_templateParameter ) ){
if( obj != null && obj instanceof ITypeInfo ){
arg = (ITypeInfo) obj;
if( arg.isType( ITypeInfo.t_type ) && arg.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) ){
if( map.containsKey( arg.getTypeSymbol() ) ){
arg = (TypeInfo) map.get( arg.getTypeSymbol() );
arg = (ITypeInfo) map.get( arg.getTypeSymbol() );
} else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument );
}
} else if( arg.isType( TypeInfo.t_type ) && arg.getTypeSymbol() instanceof IDeferredTemplateInstance ){
} else if( arg.isType( ITypeInfo.t_type ) && arg.getTypeSymbol() instanceof IDeferredTemplateInstance ){
IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) arg.getTypeSymbol();
arg = new TypeInfo( arg );
arg = TypeInfoProvider.newTypeInfo( arg );
arg.setTypeSymbol( deferred.instantiate( this, map ) );
}
} else {
@ -138,7 +132,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
if( instance != null ){
return instance;
}
if( template.isType( TypeInfo.t_templateParameter ) ){
if( template.isType( ITypeInfo.t_templateParameter ) ){
//template template parameter. must defer instantiation
return deferredInstance( arguments );
}
@ -177,8 +171,8 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
for( int i = 0; i < size; i++ ){
param = (ISymbol) parameters.get(i);
Object obj = param.getTypeInfo().getDefault();
if( obj instanceof TypeInfo ){
param.getTypeInfo().setDefault( TemplateEngine.instantiateTypeInfo( (TypeInfo) obj, template, argMap ) );
if( obj instanceof ITypeInfo ){
param.getTypeInfo().setDefault( TemplateEngine.instantiateTypeInfo( (ITypeInfo) obj, template, argMap ) );
}
}
@ -190,7 +184,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
}
public void addTemplateParameter( ISymbol param ) throws ParserSymbolTableException {
if( isType( TypeInfo.t_template ) || getTypeInfo().getTemplateParameterType() == TypeInfo.t_template ){
if( isType( ITypeInfo.t_template ) || getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){
if( !isAllowableTemplateParameter( param ) ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateParameter );
}
@ -201,17 +195,17 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
}
private boolean isAllowableTemplateParameter( ISymbol param ) {
if( !param.isType( TypeInfo.t_templateParameter ) )
if( !param.isType( ITypeInfo.t_templateParameter ) )
return false;
if( !getName().equals( ParserSymbolTable.EMPTY_NAME ) && param.getName().equals( getName() ) ){
return false;
}
if( param.getTypeInfo().getTemplateParameterType() != TypeInfo.t_typeName &&
param.getTypeInfo().getTemplateParameterType() != TypeInfo.t_template )
if( param.getTypeInfo().getTemplateParameterType() != ITypeInfo.t_typeName &&
param.getTypeInfo().getTemplateParameterType() != ITypeInfo.t_template )
{
TypeInfo info = param.getTypeInfo();
ITypeInfo info = param.getTypeInfo();
//a non-type template parameter shall have one of the following:
//integral or enumeration type
//pointer to object or pointer to function
@ -221,13 +215,13 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
//14.1-7
//A non-type template-parameter shall not be declared to have floating point, class or void type
if( info.getPtrOperators().size() == 0 )
if( info.getTemplateParameterType() == TypeInfo.t_float ||
info.getTemplateParameterType() == TypeInfo.t_double ||
info.getTemplateParameterType() == TypeInfo.t_class ||
info.getTemplateParameterType() == TypeInfo.t_struct ||
info.getTemplateParameterType() == TypeInfo.t_union ||
info.getTemplateParameterType() == TypeInfo.t_enumeration ||
info.getTemplateParameterType() == TypeInfo.t_void )
if( info.getTemplateParameterType() == ITypeInfo.t_float ||
info.getTemplateParameterType() == ITypeInfo.t_double ||
info.getTemplateParameterType() == ITypeInfo.t_class ||
info.getTemplateParameterType() == ITypeInfo.t_struct ||
info.getTemplateParameterType() == ITypeInfo.t_union ||
info.getTemplateParameterType() == ITypeInfo.t_enumeration ||
info.getTemplateParameterType() == ITypeInfo.t_void )
{
return false;
}
@ -238,12 +232,12 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
private void modifyTemplateParameter( ISymbol param ){
List ptrs = param.getPtrOperators();
if( ptrs.size() > 0 ){
PtrOp op = (PtrOp) ptrs.get( 0 );
if( op.getType() == PtrOp.t_array ){
op.setType( PtrOp.t_pointer );
ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) ptrs.get( 0 );
if( op.getType() == ITypeInfo.PtrOp.t_array ){
op.setType( ITypeInfo.PtrOp.t_pointer );
}
} else if ( param.isType( TypeInfo.t_type ) && param.getTypeSymbol().isType( TypeInfo.t_function ) ){
param.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
} else if ( param.isType( ITypeInfo.t_type ) && param.getTypeSymbol().isType( ITypeInfo.t_function ) ){
param.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) );
}
}
@ -286,7 +280,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
ISymbol found = null;
try{
if( symbol.isType( TypeInfo.t_function ) || symbol.isType( TypeInfo.t_constructor ) ){
if( symbol.isType( ITypeInfo.t_function ) || symbol.isType( ITypeInfo.t_constructor ) ){
List params = ((IParameterizedSymbol) symbol).getParameterList();
int size = params.size();
List fnArgs = new ArrayList( size );
@ -298,6 +292,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
found = getTemplatedSymbol().lookupMemberForDefinition( symbol.getName() );
}
} catch (ParserSymbolTableException e) {
/* nothing */
}
if( found == null && getTemplatedSymbol().getName().equals( symbol.getName() ) ){
found = getTemplatedSymbol();
@ -311,7 +306,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
if( found != null ){
//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.getTypeInfo().isForwardDeclaration() && found.getTypeSymbol() == symbol )
if( found.isForwardDeclaration() && found.getForwardSymbol() == symbol )
found.setTypeSymbol( null );
//TODO, once we can instantiate members as we need them instead of at the same time as the class
@ -457,7 +452,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
ParameterizedSymbol p = (ParameterizedSymbol) objs[0];
p.instantiateDeferredReturnType( (ISymbol) objs[1], this, (Map) objs[3] );
} else if( kind == DeferredKind.TYPE_SYMBOL ){
TemplateEngine.instantiateDeferredTypeInfo( (TypeInfo) objs[0], this, (Map) objs[3] );
TemplateEngine.instantiateDeferredTypeInfo( (ITypeInfo) objs[0], this, (Map) objs[3] );
}
numProcessed++;
}
@ -485,7 +480,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
ParameterizedSymbol p = (ParameterizedSymbol) objs[0];
p.discardDeferredReturnType( (ISymbol) objs[1], this, (Map) objs[3] );
} else if( kind == DeferredKind.TYPE_SYMBOL ){
TemplateEngine.discardDeferredTypeInfo( (TypeInfo) objs[0], this, (Map) objs[3] );
TemplateEngine.discardDeferredTypeInfo( (ITypeInfo) objs[0], this, (Map) objs[3] );
}
}
_deferredInstantiations.clear();

View file

@ -28,7 +28,7 @@ public class TypeFilter {
acceptedTypes.addAll( types );
}
public TypeFilter( TypeInfo.eType type ){
public TypeFilter( ITypeInfo.eType type ){
acceptedTypes.add( type );
}
@ -37,7 +37,7 @@ public class TypeFilter {
populatedAcceptedTypes( kind );
}
public void addAcceptedType( TypeInfo.eType type ){
public void addAcceptedType( ITypeInfo.eType type ){
acceptedTypes.add( type );
}
@ -46,16 +46,16 @@ public class TypeFilter {
acceptedKinds.add( kind );
}
public boolean willAccept( TypeInfo.eType type ){
return( acceptedTypes.contains( TypeInfo.t_any ) ||
public boolean willAccept( ITypeInfo.eType type ){
return( acceptedTypes.contains( ITypeInfo.t_any ) ||
acceptedTypes.contains( type ) );
}
public boolean shouldAccept( ISymbol symbol ){
return shouldAccept( symbol, symbol.getTypeInfo() );
}
public boolean shouldAccept( ISymbol symbol, TypeInfo typeInfo ){
if( acceptedTypes.contains( TypeInfo.t_any ) ){
public boolean shouldAccept( ISymbol symbol, ITypeInfo typeInfo ){
if( acceptedTypes.contains( ITypeInfo.t_any ) ){
return true;
}
@ -65,11 +65,11 @@ public class TypeFilter {
IContainerSymbol container = symbol.getContainingSymbol();
boolean symbolIsMember = container.isType( TypeInfo.t_class, TypeInfo.t_union );
boolean symbolIsLocal = container.isType( TypeInfo.t_constructor, TypeInfo.t_function ) ||
container.isType( TypeInfo.t_block );
boolean symbolIsMember = container.isType( ITypeInfo.t_class, ITypeInfo.t_union );
boolean symbolIsLocal = container.isType( ITypeInfo.t_constructor, ITypeInfo.t_function ) ||
container.isType( ITypeInfo.t_block );
if( typeInfo.isType( TypeInfo.t_function ) )
if( typeInfo.isType( ITypeInfo.t_function ) )
{
if( ( acceptedKinds.contains( LookupKind.FUNCTIONS ) && !symbolIsMember ) ||
( acceptedKinds.contains( LookupKind.METHODS ) && symbolIsMember ) )
@ -78,7 +78,7 @@ public class TypeFilter {
}
return false;
}
else if ( typeInfo.isType( TypeInfo.t_type ) && typeInfo.checkBit( TypeInfo.isTypedef ) ){
else if ( typeInfo.isType( ITypeInfo.t_type ) && typeInfo.checkBit( ITypeInfo.isTypedef ) ){
if( acceptedKinds.contains( LookupKind.TYPEDEFS ) ||
acceptedKinds.contains( LookupKind.TYPES ) )
{
@ -86,7 +86,7 @@ public class TypeFilter {
}
return false;
}
else if ( typeInfo.isType( TypeInfo.t_type ) || typeInfo.isType( TypeInfo.t__Bool, TypeInfo.t_void ) )
else if ( typeInfo.isType( ITypeInfo.t_type ) || typeInfo.isType( ITypeInfo.t__Bool, ITypeInfo.t_void ) )
{
if( ( acceptedKinds.contains( LookupKind.VARIABLES ) && !symbolIsMember && !symbolIsLocal ) ||
( acceptedKinds.contains( LookupKind.LOCAL_VARIABLES ) && !symbolIsMember && symbolIsLocal ) ||
@ -106,22 +106,22 @@ public class TypeFilter {
* @param lookupKind
*/
private void populatedAcceptedTypes(LookupKind kind) {
if ( kind == LookupKind.ALL ) { acceptedTypes.add( TypeInfo.t_any ); }
else if ( kind == LookupKind.STRUCTURES ) { acceptedTypes.add( TypeInfo.t_class );
acceptedTypes.add( TypeInfo.t_struct );
acceptedTypes.add( TypeInfo.t_union ); }
else if ( kind == LookupKind.STRUCTS ) { acceptedTypes.add( TypeInfo.t_struct ); }
else if ( kind == LookupKind.UNIONS ) { acceptedTypes.add( TypeInfo.t_union ); }
else if ( kind == LookupKind.CLASSES ) { acceptedTypes.add( TypeInfo.t_class ); }
else if ( kind == LookupKind.CONSTRUCTORS ){ acceptedTypes.add( TypeInfo.t_constructor ); }
else if ( kind == LookupKind.NAMESPACES ) { acceptedTypes.add( TypeInfo.t_namespace ); }
else if ( kind == LookupKind.ENUMERATIONS ){ acceptedTypes.add( TypeInfo.t_enumeration ); }
else if ( kind == LookupKind.ENUMERATORS ) { acceptedTypes.add( TypeInfo.t_enumerator ); }
if ( kind == LookupKind.ALL ) { acceptedTypes.add( ITypeInfo.t_any ); }
else if ( kind == LookupKind.STRUCTURES ) { acceptedTypes.add( ITypeInfo.t_class );
acceptedTypes.add( ITypeInfo.t_struct );
acceptedTypes.add( ITypeInfo.t_union ); }
else if ( kind == LookupKind.STRUCTS ) { acceptedTypes.add( ITypeInfo.t_struct ); }
else if ( kind == LookupKind.UNIONS ) { acceptedTypes.add( ITypeInfo.t_union ); }
else if ( kind == LookupKind.CLASSES ) { acceptedTypes.add( ITypeInfo.t_class ); }
else if ( kind == LookupKind.CONSTRUCTORS ){ acceptedTypes.add( ITypeInfo.t_constructor ); }
else if ( kind == LookupKind.NAMESPACES ) { acceptedTypes.add( ITypeInfo.t_namespace ); }
else if ( kind == LookupKind.ENUMERATIONS ){ acceptedTypes.add( ITypeInfo.t_enumeration ); }
else if ( kind == LookupKind.ENUMERATORS ) { acceptedTypes.add( ITypeInfo.t_enumerator ); }
// else if ( kind == LookupKind.TYPEDEFS ) { acceptedTypes.add( TypeInfo.t_type ); }
else if ( kind == LookupKind.TYPES ) { acceptedTypes.add( TypeInfo.t_class );
acceptedTypes.add( TypeInfo.t_struct );
acceptedTypes.add( TypeInfo.t_union );
acceptedTypes.add( TypeInfo.t_enumeration ); }
else if ( kind == LookupKind.TYPES ) { acceptedTypes.add( ITypeInfo.t_class );
acceptedTypes.add( ITypeInfo.t_struct );
acceptedTypes.add( ITypeInfo.t_union );
acceptedTypes.add( ITypeInfo.t_enumeration ); }
}

View file

@ -10,575 +10,86 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import org.eclipse.cdt.core.parser.Enum;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TypeInfoProvider;
public class TypeInfo {
public TypeInfo(){
public class TypeInfo extends BasicTypeInfo implements ITypeInfo{
public TypeInfo(){
super();
}
public TypeInfo( TypeInfo.eType type, int bits, ISymbol symbol ){
super();
_typeBits = bits;
_type = type;
_typeDeclaration = symbol;
}
public ISymbol getTypeSymbol() {
return _typeDeclaration;
}
public TypeInfo( TypeInfo.eType type, int bits, ISymbol symbol, TypeInfo.PtrOp op, boolean hasDefault ){
super();
_typeBits = bits;
_type = type;
_typeDeclaration = symbol;
if( op != null ){
_ptrOperators = new ArrayList(2);
_ptrOperators.add( op );
} else {
_ptrOperators = Collections.EMPTY_LIST;
}
_hasDefaultValue = hasDefault;
}
public TypeInfo( TypeInfo.eType type, int bits, ISymbol symbol, TypeInfo.PtrOp op, Object def ){
super();
_typeBits = bits;
_type = type;
_typeDeclaration = symbol;
if( op != null ){
_ptrOperators = new ArrayList( 1 );
_ptrOperators.add( op );
} else {
_ptrOperators = Collections.EMPTY_LIST;
}
_hasDefaultValue = true;
setDefault( def );
}
public void setTypeSymbol( ISymbol type ) {
_typeDeclaration = type;
}
public boolean getHasDefault() {
return _hasDefaultValue;
}
public TypeInfo( TypeInfo info ){
super();
_typeBits = info._typeBits;
_type = info._type;
_typeDeclaration = info._typeDeclaration;
_ptrOperators = ( info._ptrOperators == Collections.EMPTY_LIST ) ? info._ptrOperators : (ArrayList)((ArrayList)info._ptrOperators).clone();
_hasDefaultValue = info._hasDefaultValue;
_defaultValue = info._defaultValue;
}
public void setHasDefault( boolean def ) {
_hasDefaultValue = def;
}
public static final int isAuto = 0x00001;
public static final int isRegister = 0x00002;
public static final int isStatic = 0x00004;
public static final int isExtern = 0x00008;
public static final int isMutable = 0x00010;
public static final int isInline = 0x00020;
public static final int isVirtual = 0x00040;
public static final int isExplicit = 0x00080;
public static final int isTypedef = 0x00100;
public static final int isFriend = 0x00200;
public static final int isConst = 0x00400;
public static final int isVolatile = 0x00800;
public static final int isUnsigned = 0x01000;
public static final int isShort = 0x02000;
public static final int isLong = 0x04000;
public static final int isForward = 0x08000;
public static final int isComplex = 0x10000;
public static final int isImaginary= 0x20000;
public static final int isLongLong = 0x40000;
public static final int isSigned = 0x80000;
// Types (maximum type is typeMask
// Note that these should be considered ordered and if you change
// the order, you should consider the ParserSymbolTable uses
public static final TypeInfo.eType t_any = new TypeInfo.eType( -1 ); //don't care
public static final TypeInfo.eType t_undef = new TypeInfo.eType( 0 ); //not specified
public static final TypeInfo.eType t_type = new TypeInfo.eType( 1 ); //Type Specifier
public static final TypeInfo.eType t_namespace = new TypeInfo.eType( 2 );
public static final TypeInfo.eType t_class = new TypeInfo.eType( 3 );
public static final TypeInfo.eType t_struct = new TypeInfo.eType( 4 );
public static final TypeInfo.eType t_union = new TypeInfo.eType( 5 );
public static final TypeInfo.eType t_enumeration = new TypeInfo.eType( 6 );
public static final TypeInfo.eType t_constructor = new TypeInfo.eType( 7 );
public static final TypeInfo.eType t_function = new TypeInfo.eType( 8 );
public static final TypeInfo.eType t__Bool = new TypeInfo.eType( 9 );
public static final TypeInfo.eType t_bool = new TypeInfo.eType( 10 );
public static final TypeInfo.eType t_char = new TypeInfo.eType( 11 );
public static final TypeInfo.eType t_wchar_t = new TypeInfo.eType( 12 );
public static final TypeInfo.eType t_int = new TypeInfo.eType( 13 );
public static final TypeInfo.eType t_float = new TypeInfo.eType( 14 );
public static final TypeInfo.eType t_double = new TypeInfo.eType( 15 );
public static final TypeInfo.eType t_void = new TypeInfo.eType( 16 );
public static final TypeInfo.eType t_enumerator = new TypeInfo.eType( 17 );
public static final TypeInfo.eType t_block = new TypeInfo.eType( 18 );
public static final TypeInfo.eType t_template = new TypeInfo.eType( 19 );
public static final TypeInfo.eType t_asm = new TypeInfo.eType( 20 );
public static final TypeInfo.eType t_linkage = new TypeInfo.eType( 21 );
public static final TypeInfo.eType t_templateParameter = new TypeInfo.eType( 22 );
public static final TypeInfo.eType t_typeName = new TypeInfo.eType( 23 );
//public static final eType t_templateParameter = new eType( 18 );
public static class eType implements Comparable{
protected eType( int v ){
_val = v;
}
public int compareTo( Object o ){
TypeInfo.eType t = (TypeInfo.eType) o;
return _val - t._val;
}
public int toInt(){
return _val;
}
private int _val;
}
public static class OperatorExpression extends Enum{
//5.3.1-1 : The unary * operator, the expression to which it is applied shall be
//a pointer to an object type or a pointer to a function type and the result
//is an lvalue refering to the object or function to which the expression points
public static final OperatorExpression indirection = new OperatorExpression( 1 );
//5.3.1-2 : The result of the unary & operator is a pointer to its operand
public static final OperatorExpression addressof = new OperatorExpression( 0 );
//5.2.1 A postfix expression followed by an expression in square brackets is a postfix
//expression. one of the expressions shall have the type "pointer to T" and the other
//shall have a enumeration or integral type. The result is an lvalue of type "T"
public static final OperatorExpression subscript = new OperatorExpression( 2 );
protected OperatorExpression(int enumValue) {
super(enumValue);
}
}
public static class PtrOp {
public PtrOp( TypeInfo.eType type ){
this.type = type;
}
public PtrOp( TypeInfo.eType type, boolean isConst, boolean isVolatile ){
this.type = type;
this.isConstPtr = isConst;
this.isVolatilePtr = isVolatile;
}
public PtrOp( ISymbol memberOf, boolean isConst, boolean isVolatile ){
this.type = PtrOp.t_memberPointer;
this.isConstPtr = isConst;
this.isVolatilePtr = isVolatile;
this.memberOf = memberOf;
}
public PtrOp(){
super();
}
public static final TypeInfo.eType t_undef_ptr = new TypeInfo.eType( 0 );
public static final TypeInfo.eType t_pointer = new TypeInfo.eType( 1 );
public static final TypeInfo.eType t_reference = new TypeInfo.eType( 2 );
public static final TypeInfo.eType t_array = new TypeInfo.eType( 3 );
public static final TypeInfo.eType t_memberPointer = new TypeInfo.eType( 4 );
public void clear() {
super.clear();
_typeDeclaration = null;
_hasDefaultValue = false;
}
public TypeInfo.eType getType() { return type; }
public void setType( TypeInfo.eType type ) { this.type = type; }
public boolean isConst() { return isConstPtr; }
public boolean isVolatile() { return isVolatilePtr; }
public void setConst( boolean isConst ) { this.isConstPtr = isConst; }
public void setVolatile(boolean isVolatile) { this.isVolatilePtr = isVolatile; }
public ISymbol getMemberOf() { return memberOf; }
public void setMemberOf( ISymbol member ) { this.memberOf = member; }
public int compareCVTo( TypeInfo.PtrOp ptr ){
int cv1 = ( isConst() ? 1 : 0 ) + ( isVolatile() ? 1 : 0 );
int cv2 = ( ptr.isConst() ? 1 : 0 ) + ( ptr.isVolatile() ? 1 : 0 );
return cv1 - cv2;
}
public boolean equals( Object o ){
if( o == null || !(o instanceof TypeInfo.PtrOp) ){
return false;
}
TypeInfo.PtrOp op = (TypeInfo.PtrOp)o;
return ( isConst() == op.isConst() &&
isVolatile() == op.isVolatile() &&
getType() == op.getType() );
}
private TypeInfo.eType type = PtrOp.t_undef_ptr;
private boolean isConstPtr = false;
private boolean isVolatilePtr = false;
private ISymbol memberOf = null;
}
public void copy( ITypeInfo t ) {
super.copy( t );
_typeDeclaration = t.getTypeSymbol();
_hasDefaultValue = t.getHasDefault();
}
private static final String _image[] = { "", //$NON-NLS-1$ t_undef
"", //$NON-NLS-1$ t_type
"namespace", //$NON-NLS-1$ t_namespace
"class", //$NON-NLS-1$ t_class
"struct", //$NON-NLS-1$ t_struct
"union", //$NON-NLS-1$ t_union
"enum", //$NON-NLS-1$ t_enumeration
"", //$NON-NLS-1$ t_constructor
"", //$NON-NLS-1$ t_function
"_Bool", //$NON-NLS-1$ t__Bool
"bool", //$NON-NLS-1$ t_bool
"char", //$NON-NLS-1$ t_char
"wchar_t", //$NON-NLS-1$ t_wchar_t
"int", //$NON-NLS-1$ t_int
"float", //$NON-NLS-1$ t_float
"double", //$NON-NLS-1$ t_double
"void", //$NON-NLS-1$ t_void
"", //$NON-NLS-1$ t_enumerator
"", //$NON-NLS-1$ t_block
"template", //$NON-NLS-1$ t_template
"", //$NON-NLS-1$ t_asm
"", //$NON-NLS-1$ t_linkage
"", //$NON-NLS-1$ t_templateParameter
"typename" //$NON-NLS-1$ t_typeName
};
// Convenience methods
public void setBit(boolean b, int mask){
if( b ){
_typeBits = _typeBits | mask;
} else {
_typeBits = _typeBits & ~mask;
}
}
public boolean checkBit(int mask){
return (_typeBits & mask) != 0;
}
public void setType( TypeInfo.eType t){
_type = t;
}
public TypeInfo.eType getType(){
return _type;
}
public boolean equals( Object t ) {
if( !super.equals( t ) ){
return false;
}
ITypeInfo type = (ITypeInfo)t;
boolean result = true;
ISymbol symbol = type.getTypeSymbol();
if( _typeDeclaration != null && symbol != null ){
if( _typeDeclaration.isType( t__Bool, t_void ) &&
symbol.isType( t__Bool, t_void ) )
{
//if typeDeclaration is a basic type, then only need the types the same
result &= ( _typeDeclaration.getType() == symbol.getType() );
} else if( _typeDeclaration.isType( t_function ) &&
symbol.isType( t_function ) )
{
//function pointers... functions must have same parameter lists and return types
IParameterizedSymbol f1 = (IParameterizedSymbol) _typeDeclaration;
IParameterizedSymbol f2 = (IParameterizedSymbol) symbol;
result &= f1.hasSameParameters( f2 );
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( t_templateParameter ) &&
symbol.isType( t_templateParameter ) )
{
//template parameters
result &= TemplateEngine.templateParametersAreEquivalent( _typeDeclaration, symbol );
} else if ( _typeDeclaration instanceof IDeferredTemplateInstance &&
symbol instanceof IDeferredTemplateInstance )
{
result &= TemplateEngine.deferedInstancesAreEquivalent( (IDeferredTemplateInstance) _typeDeclaration, (IDeferredTemplateInstance)symbol );
}else {
//otherwise, its a user defined type, need the decls the same
result &= ( _typeDeclaration == symbol );
}
} else {
result &= ( _typeDeclaration == symbol );
}
return result;
}
public boolean isType( TypeInfo.eType type ){
return isType( type, TypeInfo.t_undef );
}
public int getTypeInfo(){
return _typeBits;
}
public void setTypeInfo( int typeInfo ){
_typeBits = typeInfo;
}
public eType getTemplateParameterType(){
return _templateParameterType;
}
public void setTemplateParameterType( eType type ){
_templateParameterType = type;
}
/**
*
* @param infoProvider - TypeInfoProvider to use if pooling the TypeInfo created, if null,
* pooling is not used. If pooling is used, TypeInfoProvider.returnTypeInfo
* must be called when the TypeInfo is no longer needed
* @return
*/
public TypeInfo getFinalType(TypeInfoProvider infoProvider){
return ParserSymbolTable.getFlatTypeInfo( this, infoProvider );
}
/**
*
* @param type
* @param upperType
* @return boolean
*
* type checking, check that this declaration's type is between type and
* upperType (inclusive). upperType of 0 means no range and our type must
* be type.
*/
public boolean isType( TypeInfo.eType type, TypeInfo.eType upperType ){
//type of -1 means we don't care
if( type == TypeInfo.t_any )
return true;
//upperType of 0 means no range
if( upperType == TypeInfo.t_undef ){
return ( getType() == type );
}
return ( getType().compareTo( type ) >= 0 && getType().compareTo( upperType ) <= 0 );
}
public ISymbol getTypeSymbol(){
return _typeDeclaration;
}
public void setTypeSymbol( ISymbol type ){
_typeDeclaration = type;
}
public boolean hasPtrOperators(){
return _ptrOperators.size() > 0;
}
public List getPtrOperators(){
return _ptrOperators;
}
public boolean hasSamePtrs( TypeInfo type ){
int size = getPtrOperators().size();
int size2 = type.getPtrOperators().size();
TypeInfo.PtrOp ptr1 = null, ptr2 = null;
if( size == size2 ){
if( size > 0 ){
for( int i = 0; i < size; i++ ){
ptr1 = (TypeInfo.PtrOp)getPtrOperators().get(i);
ptr2 = (TypeInfo.PtrOp)type.getPtrOperators().get(i);
if( ptr1.getType() != ptr2.getType() ){
return false;
}
}
}
return true;
}
return false;
}
public List getOperatorExpressions(){
return _operatorExpressions;
}
public void applyOperatorExpressions( List ops ){
if( ops == null || ops.isEmpty() )
return;
int size = ops.size();
OperatorExpression op = null;
for( int i = 0; i < size; i++ ){
op = (OperatorExpression)ops.get(i);
if( op == OperatorExpression.indirection ||
op == OperatorExpression.subscript )
{
//indirection operator, can only be applied to a pointer
//subscript should be applied to something that is "pointer to T", the result is a lvalue of type "T"
if( hasPtrOperators() ){
ListIterator iterator = getPtrOperators().listIterator( getPtrOperators().size() );
TypeInfo.PtrOp last = (TypeInfo.PtrOp)iterator.previous();
if( last.getType() == TypeInfo.PtrOp.t_pointer ||
last.getType() == TypeInfo.PtrOp.t_array )
{
iterator.remove();
}
}
} else if( op == OperatorExpression.addressof ){
//Address-of unary operator, results in pointer to T
//TODO or pointer to member
TypeInfo.PtrOp newOp = new TypeInfo.PtrOp( PtrOp.t_pointer );
addPtrOperator( newOp );
}
}
}
public void addPtrOperator( TypeInfo.PtrOp ptr ){
if( _ptrOperators == Collections.EMPTY_LIST ){
_ptrOperators = new ArrayList(4);
}
if( ptr != null )
_ptrOperators.add( ptr );
}
public void addPtrOperator( List ptrs ){
if( ptrs == null || ptrs.size() == 0 )
return;
if( _ptrOperators == Collections.EMPTY_LIST ){
_ptrOperators = new ArrayList( ptrs.size() );
}
int size = ptrs.size();
for( int i = 0; i < size; i++ ){
_ptrOperators.add( ptrs.get( i ) );
}
}
public void preparePtrOperators(int numPtrOps) {
if( _ptrOperators == Collections.EMPTY_LIST )
_ptrOperators = new ArrayList( numPtrOps );
else
((ArrayList) _ptrOperators).ensureCapacity( numPtrOps );
}
public void addOperatorExpression( OperatorExpression exp ){
if( _operatorExpressions == Collections.EMPTY_LIST ){
_operatorExpressions = new ArrayList(4);
}
_operatorExpressions.add( exp );
}
public boolean getHasDefault(){
return _hasDefaultValue;
}
public void setHasDefault( boolean def ){
_hasDefaultValue = def;
}
public void setDefault( Object t ){
_defaultValue = t;
}
public Object getDefault(){
return _defaultValue;
}
public boolean isForwardDeclaration(){
return checkBit( isForward );
}
public void setIsForwardDeclaration( boolean forward ){
setBit( forward, isForward );
}
/**
* canHold
* @param type
* @return boolean
* return true if our type can hold all the values of the passed in
* type.
* TODO, for now return true if our type is "larger" (based on ordering of
* the type values)
*/
public boolean canHold( TypeInfo type ){
if( getType().compareTo( type.getType()) > 0 ){
return true;
}
int mask = TypeInfo.isShort | TypeInfo.isLong | TypeInfo.isLongLong;
return ( getTypeInfo() & mask ) >= ( type.getTypeInfo() & mask );
}
public boolean equals( Object t ){
if( t == null || !(t instanceof TypeInfo) ){
return false;
}
TypeInfo type = (TypeInfo)t;
boolean result = ( _typeBits == type._typeBits );
result &= ( _type == type._type );
if( _typeDeclaration != null && type._typeDeclaration != null ){
if( _typeDeclaration.isType( TypeInfo.t__Bool, TypeInfo.t_void ) &&
type._typeDeclaration.isType( TypeInfo.t__Bool, TypeInfo.t_void ) )
{
//if typeDeclaration is a basic type, then only need the types the same
result &= ( _typeDeclaration.getType() == type._typeDeclaration.getType() );
} else if( _typeDeclaration.isType( TypeInfo.t_function ) &&
type._typeDeclaration.isType( TypeInfo.t_function ) )
{
//function pointers... functions must have same parameter lists and return types
IParameterizedSymbol f1 = (IParameterizedSymbol) _typeDeclaration;
IParameterizedSymbol f2 = (IParameterizedSymbol) type._typeDeclaration;
result &= f1.hasSameParameters( f2 );
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 ) &&
type._typeDeclaration.isType( TypeInfo.t_templateParameter ) )
{
//template parameters
result &= TemplateEngine.templateParametersAreEquivalent( _typeDeclaration, type._typeDeclaration );
} else if ( _typeDeclaration instanceof IDeferredTemplateInstance &&
type._typeDeclaration instanceof IDeferredTemplateInstance )
{
result &= TemplateEngine.deferedInstancesAreEquivalent( (IDeferredTemplateInstance) _typeDeclaration, (IDeferredTemplateInstance)type._typeDeclaration );
}else {
//otherwise, its a user defined type, need the decls the same
result &= ( _typeDeclaration == type._typeDeclaration );
}
} else {
result &= ( _typeDeclaration == type._typeDeclaration );
}
int size1 = _ptrOperators.size();
int size2 = type._ptrOperators.size();
if( size1 == size2 ){
if( size1 != 0 ){
TypeInfo.PtrOp op1 = null, op2 = null;
for( int i = 0; i < size1; i++ ){
op1 = (TypeInfo.PtrOp)_ptrOperators.get(i);
op2 = (TypeInfo.PtrOp)type._ptrOperators.get(i);
if( !op1.equals(op2) ){
return false;
}
}
}
} else {
return false;
}
return result;
}
public String toString(){
if( isType( TypeInfo.t_type ) ){
return _typeDeclaration.getName();
}
return TypeInfo._image[ getType().toInt() ];
}
public void clear(){
_typeBits = 0;
_type = TypeInfo.t_undef;
_templateParameterType = t_typeName;
_typeDeclaration = null;
_hasDefaultValue = false;
_defaultValue = null;
_ptrOperators = Collections.EMPTY_LIST;
_operatorExpressions = Collections.EMPTY_LIST;
}
public void copy( TypeInfo t ){
_typeBits = t._typeBits;
_type = t._type;
_templateParameterType = t._templateParameterType;
_typeDeclaration = t._typeDeclaration;
_hasDefaultValue = t._hasDefaultValue;
_defaultValue = t._defaultValue;
if( t._ptrOperators != Collections.EMPTY_LIST )
_ptrOperators = (ArrayList)((ArrayList)t._ptrOperators).clone();
else
_ptrOperators = Collections.EMPTY_LIST;
if( t._operatorExpressions != Collections.EMPTY_LIST )
_operatorExpressions = (ArrayList)((ArrayList)t._operatorExpressions).clone();
else
_operatorExpressions = Collections.EMPTY_LIST;
}
// public void release() {
// ParserSymbolTable.TypeInfoProvider.returnTypeInfo( this );
// }
private int _typeBits = 0;
private eType _type = TypeInfo.t_undef;
private eType _templateParameterType = t_typeName;
private ISymbol _typeDeclaration;
private boolean _hasDefaultValue = false;
private Object _defaultValue = null;
private List _ptrOperators = Collections.EMPTY_LIST;
private List _operatorExpressions = Collections.EMPTY_LIST;
private ISymbol _typeDeclaration = null;
private boolean _hasDefaultValue = false;
}

View file

@ -0,0 +1,291 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jul 5, 2004
*/
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;
public class TypeInfoProvider
{
private static final int BASIC = 0;
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;
private final int [] firstFreeHint;
private TypeInfoProvider()
{
pool = new ITypeInfo[POOL_SIZE][3];
free = new boolean [POOL_SIZE][3];
firstFreeHint = new int [] { 0, 0, 0 };
for( int i = 0; i < POOL_SIZE; i++ )
{
pool[i] = new ITypeInfo[] { new BasicTypeInfo(), new TypeInfo(), new TemplateParameterTypeInfo() };
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 )
idx = TYPE;
else if( type == ITypeInfo.t_templateParameter )
idx = TEMPLATE;
ITypeInfo returnType = null;
for( int i = firstFreeHint[idx]; i < POOL_SIZE; ++i )
{
if( free[i][idx] )
{
free[i][idx] = false;
firstFreeHint[idx] = i + 1;
returnType = pool[i][idx];
break;
}
}
if( returnType == null ){
//if there is nothing free, just give them a new one
if( type == ITypeInfo.t_type ){
returnType = new TypeInfo();
} else if( type == ITypeInfo.t_templateParameter ) {
returnType = new TemplateParameterTypeInfo();
} else {
returnType = new BasicTypeInfo();
}
}
returnType.setType( type );
return returnType;
}
public void returnTypeInfo( ITypeInfo t )
{
int idx = BASIC;
if( t instanceof TemplateParameterTypeInfo )
idx = TEMPLATE;
else if ( t instanceof TypeInfo )
idx = TYPE;
for( int i = 0; i < POOL_SIZE; i++ ){
if( pool[i][idx] == t ){
t.clear();
free[i][idx] = true;
if( i < firstFreeHint[idx] ){
firstFreeHint[idx] = i;
}
return;
}
}
//else it was one allocated outside the pool
}
public int numAllocated(){
int num = 0;
for( int i = 0; i < POOL_SIZE; i++ ){
num += ( free[i][0] ? 0 : 1 ) +
( free[i][1] ? 0 : 1 ) +
( free[i][2] ? 0 : 1 );
}
return num;
}
/**
* @param topInfo
* @return
*/
static final public ITypeInfo newTypeInfo( ITypeInfo topInfo ) {
ITypeInfo newInfo = newInfo( topInfo.getType(), topInfo.getDefault() != null );
newInfo.copy( topInfo );
return newInfo;
}
/**
*
* @param type
* @param bits
* @param typeSymbol
* @param ptrOp
* @param hasDefault
* @return
*/
static final public ITypeInfo newTypeInfo( eType type, int bits, ISymbol typeSymbol, PtrOp ptrOp, boolean hasDefault ) {
ITypeInfo newInfo = newTypeInfo( type, bits, ptrOp, hasDefault );
newInfo.setTypeSymbol( typeSymbol );
return newInfo;
}
/**
*
* @param type
* @param bits
* @param typeSymbol
* @return
*/
static final public ITypeInfo newTypeInfo( eType type, int bits, ISymbol typeSymbol ) {
ITypeInfo newInfo = newTypeInfo( type );
newInfo.setTypeBits( bits );
newInfo.setTypeSymbol( typeSymbol );
return newInfo;
}
/**
*
* @param type
* @param bits
* @param ptrOp
* @param hasDefault
* @return
*/
static final public ITypeInfo newTypeInfo( eType type, int bits, PtrOp ptrOp, boolean hasDefault ) {
ITypeInfo newInfo = newTypeInfo( type );
newInfo.setTypeBits( bits );
newInfo.addPtrOperator( ptrOp );
newInfo.setHasDefault( hasDefault );
return newInfo;
}
/**
* @param typeInfo
* @return
*/
static final public ITypeInfo newTypeInfo( eType type ) {
ITypeInfo newInfo = newInfo( type, false );
newInfo.setType( type );
return newInfo;
}
/**
*
* @param type
* @param bits
* @param symbol
* @param op
* @param def
* @return
*/
public static ITypeInfo newTypeInfo( eType type, int bits, ISymbol symbol, PtrOp op, Object def ) {
ITypeInfo newInfo = newInfo( type, def != null );
newInfo.setType( type );
newInfo.setTypeBits( bits );
newInfo.setDefault( def );
newInfo.setTypeSymbol( symbol );
newInfo.addPtrOperator( op );
return newInfo;
}
/**
* @return
*/
public static ITypeInfo newTypeInfo() {
return new BasicTypeInfo();
}
/**
* Functions for constructing a Type info a piece at a time.
*/
private eType type;
private ISymbol typeSymbol;
private int bits;
private Object defaultObj;
private boolean hasDef;
private eType templateParamType;
public void setType( eType t ) { type = t; }
public void setTypeSymbol( ISymbol s ) { typeSymbol = s; }
public void setTypeBits( int b ) { bits = b; }
public void setHasDef( boolean b ) { hasDef = b; }
public void setDefaultObj( Object obj ) { defaultObj = obj; }
public void setTemplateParameterType( eType t ) { templateParamType = t; }
public void setBit( boolean b, int mask ) {
if( b ) bits = bits | mask;
else bits = bits & ~mask;
}
public void beginTypeConstruction(){
type = ITypeInfo.t_undef;
typeSymbol = null;
bits = 0;
defaultObj = null;
templateParamType = null;
hasDef = false;
}
public ITypeInfo completeConstruction(){
ITypeInfo newInfo = newTypeInfo( type, bits, typeSymbol, null, defaultObj );
newInfo.setHasDefault( hasDef );
if( templateParamType != null )
newInfo.setTemplateParameterType( templateParamType );
return newInfo;
}
private static ITypeInfo newInfo( eType type, boolean def ){
ITypeInfo newInfo = null;
if( type == ITypeInfo.t_type || type == ITypeInfo.t_enumerator ){
if( def )
newInfo = new TypeInfo(){
public void copy( ITypeInfo t ) { super.copy( t ); _defObj = t.getDefault(); }
public void setDefault( Object t ) { _defObj = t; }
public Object getDefault() { return _defObj;}
private Object _defObj;
};
else
newInfo = new TypeInfo();
} else if( type == ITypeInfo.t_templateParameter ){
if( def )
newInfo = new TemplateParameterTypeInfo(){
public void copy( ITypeInfo t ) { super.copy( t ); _defObj = t.getDefault(); }
public void setDefault( Object t ) { _defObj = t; }
public Object getDefault() { return _defObj;}
private Object _defObj;
};
else
newInfo = new TemplateParameterTypeInfo();
} else {
if( def )
newInfo = new BasicTypeInfo(){
public void copy( ITypeInfo t ) { super.copy( t ); _defObj = t.getDefault(); }
public void setDefault( Object t ) { _defObj = t; }
public Object getDefault() { return _defObj;}
private Object _defObj;
};
else
newInfo = new BasicTypeInfo();
}
return newInfo;
}
}