1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00
Added in preliminary support for Field/Variable w/cross references on their types.  

TESTS
	Updated CompleteParseASTTests.
This commit is contained in:
John Camelon 2003-07-22 22:02:24 +00:00
parent a91ac220d1
commit 443dc9c1ec
28 changed files with 1332 additions and 652 deletions

View file

@ -1,3 +1,6 @@
2003-07-22 John Camelon
Updated CompleteParseASTTests.
2003-07-21 Bogdan Gheorghe
Added new indexer test for newly added declarations

View file

@ -48,6 +48,7 @@ import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
import org.eclipse.cdt.core.parser.ast.IASTPointerToFunction;
import org.eclipse.cdt.core.parser.ast.IASTPointerToMethod;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
@ -112,7 +113,7 @@ public class CompleteParseASTTest extends TestCase
*/
public void acceptVariable(IASTVariable variable)
{
getCurrentScope().addDeclaration( variable );
}
/* (non-Javadoc)
@ -612,5 +613,52 @@ public class CompleteParseASTTest extends TestCase
assertEquals( callback.getReferences().size(), 2 );
}
public void testSimpleVariable() throws Exception
{
Iterator declarations = parse( "int x;").getDeclarations();
IASTVariable v = (IASTVariable)declarations.next();
assertEquals( v.getName(), "x");
assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT );
}
public void testSimpleClassReferenceVariable() throws Exception
{
Iterator declarations = parse( "class A { }; A x;").getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier();
IASTVariable v = (IASTVariable)declarations.next();
assertEquals( v.getName(), "x");
assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA );
}
public void testNestedClassReferenceVariable() throws Exception
{
Iterator declarations = parse( "namespace N { class A { }; } N::A x;").getDeclarations();
IASTNamespaceDefinition namespace = (IASTNamespaceDefinition)declarations.next();
Iterator iter = getDeclarations( namespace );
IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)iter.next()).getTypeSpecifier();
IASTVariable v = (IASTVariable)declarations.next();
assertEquals( v.getName(), "x");
assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA );
assertEquals( callback.getReferences().size(), 2 );
}
public void testMultipleDeclaratorsVariable() throws Exception
{
Iterator declarations = parse( "class A { }; A x, y, z;").getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier();
IASTVariable v = (IASTVariable)declarations.next();
assertEquals( v.getName(), "x");
assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA );
assertEquals( callback.getReferences().size(), 3 );
}
public void testSimpleField() throws Exception
{
Iterator declarations = parse( "class A { double x; };").getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier();
Iterator fields =getDeclarations(classA);
IASTField f = (IASTField)fields.next();
assertEquals( f.getName(), "x" );
assertEquals( ((IASTSimpleTypeSpecifier)f.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE );
}
}

View file

@ -26,10 +26,10 @@ import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Mark;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TypeInfo.PtrOp;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
@ -171,7 +171,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( firstX );
IDerivableContainerSymbol firstClass = table.newDerivableContainerSymbol("class");
firstClass.setType( ParserSymbolTable.TypeInfo.t_class );
firstClass.setType( TypeInfo.t_class );
table.getCompilationUnit().addSymbol( firstClass );
ISymbol look = firstClass.Lookup( "x" );
@ -199,7 +199,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( x );
IDerivableContainerSymbol decl = table.newDerivableContainerSymbol("class");
decl.setType( ParserSymbolTable.TypeInfo.t_class );
decl.setType( TypeInfo.t_class );
table.getCompilationUnit().addSymbol( decl );
ISymbol look = decl.Lookup( "x" );
@ -217,10 +217,10 @@ public class ParserSymbolTableTest extends TestCase {
newTable();
IDerivableContainerSymbol parent = table.newDerivableContainerSymbol("parent");
parent.setType( ParserSymbolTable.TypeInfo.t_class );
parent.setType( TypeInfo.t_class );
IDerivableContainerSymbol class1 = table.newDerivableContainerSymbol("class");
class1.setType( ParserSymbolTable.TypeInfo.t_class );
class1.setType( TypeInfo.t_class );
class1.addParent( parent );
ISymbol decl = table.new Declaration("x");
@ -393,13 +393,13 @@ public class ParserSymbolTableTest extends TestCase {
compUnit.addSymbol( d );
IContainerSymbol enum = table.new Declaration("enum");
enum.setType( ParserSymbolTable.TypeInfo.t_enumeration );
enum.setType( TypeInfo.t_enumeration );
ISymbol enumerator = table.new Declaration( "enumerator" );
enumerator.setType( ParserSymbolTable.TypeInfo.t_enumerator );
enumerator.setType( TypeInfo.t_enumerator );
ISymbol stat = table.new Declaration("static");
stat.getTypeInfo().setBit( true, ParserSymbolTable.TypeInfo.isStatic );
stat.getTypeInfo().setBit( true, TypeInfo.isStatic );
ISymbol x = table.new Declaration("x");
@ -448,13 +448,13 @@ public class ParserSymbolTableTest extends TestCase {
newTable();
IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "class" );
cls.setType( ParserSymbolTable.TypeInfo.t_class );
cls.setType( TypeInfo.t_class );
IDerivableContainerSymbol struct = table.newDerivableContainerSymbol("struct");
struct.setType( ParserSymbolTable.TypeInfo.t_struct );
struct.setType( TypeInfo.t_struct );
IContainerSymbol union = table.newContainerSymbol("union");
union.setType( ParserSymbolTable.TypeInfo.t_union );
union.setType( TypeInfo.t_union );
IDerivableContainerSymbol hideCls = table.newDerivableContainerSymbol( "class" );
IDerivableContainerSymbol hideStruct = table.newDerivableContainerSymbol("struct");
@ -476,11 +476,11 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( a );
table.getCompilationUnit().addSymbol( b );
ISymbol look = a.ElaboratedLookup( ParserSymbolTable.TypeInfo.t_class, "class" );
ISymbol look = a.ElaboratedLookup( TypeInfo.t_class, "class" );
assertEquals( look, cls );
look = a.ElaboratedLookup( ParserSymbolTable.TypeInfo.t_struct, "struct" );
look = a.ElaboratedLookup( TypeInfo.t_struct, "struct" );
assertEquals( look, struct );
look = a.ElaboratedLookup( ParserSymbolTable.TypeInfo.t_union, "union" );
look = a.ElaboratedLookup( TypeInfo.t_union, "union" );
assertEquals( look, union );
}
@ -541,18 +541,18 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IDerivableContainerSymbol struct = table.newDerivableContainerSymbol("stat");
struct.setType( ParserSymbolTable.TypeInfo.t_struct );
struct.setType( TypeInfo.t_struct );
compUnit.addSymbol( struct );
IParameterizedSymbol function = table.newParameterizedSymbol( "stat" );
function.setType( ParserSymbolTable.TypeInfo.t_function );
function.setType( TypeInfo.t_function );
compUnit.addSymbol( function );
IParameterizedSymbol f = table.newParameterizedSymbol("f");
f.setType( ParserSymbolTable.TypeInfo.t_function );
f.setType( TypeInfo.t_function );
compUnit.addSymbol( f );
ISymbol look = f.ElaboratedLookup( ParserSymbolTable.TypeInfo.t_struct, "stat" );
ISymbol look = f.ElaboratedLookup( TypeInfo.t_struct, "stat" );
assertEquals( look, struct );
look = f.Lookup( "stat" );
@ -594,18 +594,18 @@ public class ParserSymbolTableTest extends TestCase {
newTable();
IContainerSymbol nsA = table.newContainerSymbol("A");
nsA.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsA.setType( TypeInfo.t_namespace );
table.getCompilationUnit().addSymbol( nsA );
ISymbol nsA_i = table.newSymbol("i");
nsA.addSymbol( nsA_i );
IContainerSymbol nsB = table.newContainerSymbol("B");
nsB.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsB.setType( TypeInfo.t_namespace );
nsA.addSymbol( nsB );
IContainerSymbol nsC = table.newContainerSymbol("C");
nsC.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsC.setType( TypeInfo.t_namespace );
nsB.addSymbol( nsC );
ISymbol nsC_i = table.newSymbol("i");
@ -616,7 +616,7 @@ public class ParserSymbolTableTest extends TestCase {
nsB.addUsingDirective( nsC );
IParameterizedSymbol f1 = table.newParameterizedSymbol("f");
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.setType( TypeInfo.t_function );
nsB.addSymbol( f1 );
@ -624,7 +624,7 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( look, nsC_i ); //C::i visible and hides A::i
IContainerSymbol nsD = table.newContainerSymbol("D");
nsD.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsD.setType( TypeInfo.t_namespace );
nsA.addSymbol( nsD );
look = nsD.Lookup("B");
@ -636,7 +636,7 @@ public class ParserSymbolTableTest extends TestCase {
nsD.addUsingDirective( nsC );
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f2" );
f2.setType( ParserSymbolTable.TypeInfo.t_function );
f2.setType( TypeInfo.t_function );
nsD.addSymbol( f2 );
try
@ -651,14 +651,14 @@ public class ParserSymbolTableTest extends TestCase {
}
IParameterizedSymbol f3 = table.newParameterizedSymbol("f3");
f3.setType( ParserSymbolTable.TypeInfo.t_function );
f3.setType( TypeInfo.t_function );
nsA.addSymbol( f3 );
look = f3.Lookup("i");
assertEquals( look, nsA_i ); //uses A::i
IParameterizedSymbol f4 = table.newParameterizedSymbol("f4");
f4.setType( ParserSymbolTable.TypeInfo.t_function );
f4.setType( TypeInfo.t_function );
table.getCompilationUnit().addSymbol( f4 );
look = f4.Lookup("i");
@ -691,7 +691,7 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IContainerSymbol nsM = table.newContainerSymbol( "M" );
nsM.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsM.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsM );
@ -699,7 +699,7 @@ public class ParserSymbolTableTest extends TestCase {
nsM.addSymbol( nsM_i );
IContainerSymbol nsN = table.newContainerSymbol( "N" );
nsN.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsN.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsN );
@ -759,30 +759,30 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IContainerSymbol nsA = table.newContainerSymbol("A");
nsA.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsA.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsA );
ISymbol a = table.newSymbol("a");
nsA.addSymbol( a );
IContainerSymbol nsB = table.newContainerSymbol("B");
nsB.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsB.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsB );
nsB.addUsingDirective( nsA );
IContainerSymbol nsC = table.newContainerSymbol("C");
nsC.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsC.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsC );
nsC.addUsingDirective( nsA );
IContainerSymbol nsBC = table.newContainerSymbol("BC");
nsBC.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsBC.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsBC );
nsBC.addUsingDirective( nsB );
nsBC.addUsingDirective( nsC );
IParameterizedSymbol f = table.newParameterizedSymbol("f");
f.setType(ParserSymbolTable.TypeInfo.t_function);
f.setType(TypeInfo.t_function);
compUnit.addSymbol( f );
ISymbol look = f.LookupNestedNameSpecifier("BC");
@ -820,14 +820,14 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IContainerSymbol nsB = table.newContainerSymbol( "B" );
nsB.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsB.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsB );
ISymbol b = table.newSymbol("b");
nsB.addSymbol( b );
IContainerSymbol nsA = table.newContainerSymbol( "A" );
nsA.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsA.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsA );
nsA.addUsingDirective( nsB );
@ -883,11 +883,11 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IContainerSymbol nsA = table.newContainerSymbol( "A" );
nsA.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsA.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsA );
IContainerSymbol nsB = table.newContainerSymbol( "B" );
nsB.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsB.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsB );
nsB.addUsingDirective( nsA );
@ -932,32 +932,32 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IContainerSymbol nsA = table.newContainerSymbol("A");
nsA.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsA.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsA );
IContainerSymbol structX = table.newContainerSymbol("x");
structX.setType( ParserSymbolTable.TypeInfo.t_struct );
structX.setType( TypeInfo.t_struct );
nsA.addSymbol( structX );
ISymbol intX = table.newSymbol("x");
intX.setType( ParserSymbolTable.TypeInfo.t_int );
intX.setType( TypeInfo.t_int );
nsA.addSymbol( intX );
ISymbol intY = table.newSymbol("y");
intY.setType( ParserSymbolTable.TypeInfo.t_int );
intY.setType( TypeInfo.t_int );
nsA.addSymbol( intY );
IContainerSymbol nsB = table.newContainerSymbol("B");
nsB.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsB.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsB );
IContainerSymbol structY = table.newContainerSymbol("y");
structY.setType( ParserSymbolTable.TypeInfo.t_struct );
structY.setType( TypeInfo.t_struct );
nsB.addSymbol( structY );
IContainerSymbol nsC = table.newContainerSymbol("C");
nsC.setType( ParserSymbolTable.TypeInfo.t_namespace);
nsC.setType( TypeInfo.t_namespace);
compUnit.addSymbol( nsC );
ISymbol look = nsC.Lookup("A");
@ -1006,15 +1006,15 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IContainerSymbol nsA = table.newContainerSymbol( "A" );
nsA.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsA.setType( TypeInfo.t_namespace );
compUnit.addSymbol( nsA );
IContainerSymbol nsB = table.newContainerSymbol( "B" );
nsB.setType( ParserSymbolTable.TypeInfo.t_namespace );
nsB.setType( TypeInfo.t_namespace );
nsA.addSymbol( nsB );
IParameterizedSymbol f1 = table.newParameterizedSymbol("f1");
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.setType( TypeInfo.t_function );
nsB.addSymbol( f1 );
nsA.addUsingDirective( nsB );
@ -1060,19 +1060,19 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B");
B.setType( ParserSymbolTable.TypeInfo.t_struct );
B.setType( TypeInfo.t_struct );
compUnit.addSymbol( B );
IParameterizedSymbol f = table.newParameterizedSymbol("f");
f.setType( ParserSymbolTable.TypeInfo.t_function );
f.setType( TypeInfo.t_function );
B.addSymbol( f );
IContainerSymbol E = table.newContainerSymbol( "E" );
E.setType( ParserSymbolTable.TypeInfo.t_enumeration );
E.setType( TypeInfo.t_enumeration );
B.addSymbol( E );
ISymbol e = table.newSymbol( "e" );
e.setType( ParserSymbolTable.TypeInfo.t_enumerator );
e.setType( TypeInfo.t_enumerator );
E.addSymbol( e );
/**
@ -1080,15 +1080,15 @@ public class ParserSymbolTableTest extends TestCase {
*/
IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C" );
C.setType( ParserSymbolTable.TypeInfo.t_class );
C.setType( TypeInfo.t_class );
compUnit.addSymbol( C );
IParameterizedSymbol g = table.newParameterizedSymbol( "g" );
g.setType( ParserSymbolTable.TypeInfo.t_function );
g.setType( TypeInfo.t_function );
C.addSymbol( g );
IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D" );
D.setType( ParserSymbolTable.TypeInfo.t_struct );
D.setType( TypeInfo.t_struct );
ISymbol look = compUnit.Lookup( "B" );
assertEquals( look, B );
D.addParent( B );
@ -1146,13 +1146,13 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
ParserSymbolTable.Declaration A = table.new Declaration( "A" );
A.setType( ParserSymbolTable.TypeInfo.t_namespace );
A.setType( TypeInfo.t_namespace );
compUnit.addSymbol( A );
ParserSymbolTable.Declaration f1 = table.new Declaration( "f" );
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.setType( TypeInfo.t_function );
f1.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f1.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
f1.addParameter( TypeInfo.t_int, 0, null, false );
A.addSymbol( f1 );
ISymbol look = compUnit.LookupNestedNameSpecifier("A");
@ -1164,18 +1164,18 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( look, A );
IParameterizedSymbol f2 = table.newParameterizedSymbol("f");
f2.setType( ParserSymbolTable.TypeInfo.t_function );
f2.setType( TypeInfo.t_function );
f2.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f2.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, null, false );
f2.addParameter( TypeInfo.t_char, 0, null, false );
A.addSymbol( f2 );
IParameterizedSymbol foo = table.newParameterizedSymbol("foo");
foo.setType( ParserSymbolTable.TypeInfo.t_function );
foo.setType( TypeInfo.t_function );
compUnit.addSymbol( foo );
LinkedList paramList = new LinkedList();
ParserSymbolTable.TypeInfo param = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_char, 0, null );
TypeInfo param = new TypeInfo( TypeInfo.t_char, 0, null );
paramList.add( param );
look = foo.UnqualifiedFunctionLookup( "f", paramList );
@ -1183,8 +1183,8 @@ public class ParserSymbolTableTest extends TestCase {
assertTrue( usingF.hasSameParameters( f1 ) );
IParameterizedSymbol bar = table.newParameterizedSymbol( "bar" );
bar.setType( ParserSymbolTable.TypeInfo.t_function );
bar.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, null, false );
bar.setType( TypeInfo.t_function );
bar.addParameter( TypeInfo.t_char, 0, null, false );
compUnit.addSymbol( bar );
look = bar.LookupNestedNameSpecifier( "A" );
@ -1208,10 +1208,10 @@ public class ParserSymbolTableTest extends TestCase {
newTable();
IContainerSymbol cls = table.newContainerSymbol("class");
cls.setType( ParserSymbolTable.TypeInfo.t_class );
cls.setType( TypeInfo.t_class );
IParameterizedSymbol fn = table.newParameterizedSymbol("function");
fn.setType( ParserSymbolTable.TypeInfo.t_function );
fn.setType( TypeInfo.t_function );
fn.getTypeInfo().addPtrOperator( new PtrOp( PtrOp.t_undef, true, false ) );
//fn.setCVQualifier( ParserSymbolTable.TypeInfo.cvConst );
@ -1221,7 +1221,7 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol look = fn.Lookup("this");
assertTrue( look != null );
assertEquals( look.getType(), ParserSymbolTable.TypeInfo.t_type );
assertEquals( look.getType(), TypeInfo.t_type );
assertEquals( look.getTypeSymbol(), cls );
assertEquals( ((PtrOp)look.getPtrOperators().getFirst()).getType(), TypeInfo.PtrOp.t_pointer );
assertTrue( ((PtrOp)look.getPtrOperators().getFirst()).isConst() );
@ -1240,16 +1240,16 @@ public class ParserSymbolTableTest extends TestCase {
newTable();
IContainerSymbol cls = table.newContainerSymbol("class");
cls.setType( ParserSymbolTable.TypeInfo.t_class );
cls.setType( TypeInfo.t_class );
IContainerSymbol enumeration = table.newContainerSymbol("enumeration");
enumeration.setType( ParserSymbolTable.TypeInfo.t_enumeration );
enumeration.setType( TypeInfo.t_enumeration );
table.getCompilationUnit().addSymbol( cls );
cls.addSymbol( enumeration );
ISymbol enumerator = table.newSymbol( "enumerator" );
enumerator.setType( ParserSymbolTable.TypeInfo.t_enumerator );
enumerator.setType( TypeInfo.t_enumerator );
enumeration.addSymbol( enumerator );
ISymbol look = cls.Lookup( "enumerator" );
@ -1277,17 +1277,17 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IContainerSymbol NS = table.newContainerSymbol("NS");
NS.setType( ParserSymbolTable.TypeInfo.t_namespace );
NS.setType( TypeInfo.t_namespace );
compUnit.addSymbol( NS );
IDerivableContainerSymbol T = table.newDerivableContainerSymbol("T");
T.setType( ParserSymbolTable.TypeInfo.t_class );
T.setType( TypeInfo.t_class );
NS.addSymbol( T );
IParameterizedSymbol f = table.newParameterizedSymbol("f");
f.setType( ParserSymbolTable.TypeInfo.t_function );
f.setType( TypeInfo.t_function );
f.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
ISymbol look = NS.Lookup( "T" );
@ -1302,19 +1302,19 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( look, T );
ISymbol param = table.newSymbol("parm");
param.setType( ParserSymbolTable.TypeInfo.t_type );
param.setType( TypeInfo.t_type );
param.setTypeSymbol( look );
compUnit.addSymbol( param );
IParameterizedSymbol main = table.newParameterizedSymbol("main");
main.setType( ParserSymbolTable.TypeInfo.t_function );
main.setType( TypeInfo.t_function );
main.setReturnType( table.newSymbol( "", TypeInfo.t_int ) );
compUnit.addSymbol( main );
LinkedList paramList = new LinkedList();
look = main.Lookup( "parm" );
assertEquals( look, param );
ParserSymbolTable.TypeInfo p = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, 0, look );
TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, look );
paramList.add( p );
look = main.UnqualifiedFunctionLookup( "f", paramList );
@ -1350,18 +1350,18 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IContainerSymbol NS1 = table.newContainerSymbol( "NS1" );
NS1.setType( ParserSymbolTable.TypeInfo.t_namespace );
NS1.setType( TypeInfo.t_namespace );
compUnit.addSymbol( NS1 );
ParserSymbolTable.Declaration f1 = table.new Declaration( "f" );
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.setType( TypeInfo.t_function );
f1.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f1.addParameter( ParserSymbolTable.TypeInfo.t_void, 0, new PtrOp( PtrOp.t_pointer ), false );
f1.addParameter( TypeInfo.t_void, 0, new PtrOp( PtrOp.t_pointer ), false );
NS1.addSymbol( f1 );
IContainerSymbol NS2 = table.newContainerSymbol( "NS2" );
NS2.setType( ParserSymbolTable.TypeInfo.t_namespace );
NS2.setType( TypeInfo.t_namespace );
compUnit.addSymbol( NS2 );
@ -1370,17 +1370,17 @@ public class ParserSymbolTableTest extends TestCase {
NS2.addUsingDirective( NS1 );
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B" );
B.setType( ParserSymbolTable.TypeInfo.t_class );
B.setType( TypeInfo.t_class );
NS2.addSymbol( B );
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" );
f2.setType( ParserSymbolTable.TypeInfo.t_function );
f2.setType( TypeInfo.t_function );
f2.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f2.addParameter( ParserSymbolTable.TypeInfo.t_void, 0, new PtrOp( PtrOp.t_pointer ), false );
f2.addParameter( TypeInfo.t_void, 0, new PtrOp( PtrOp.t_pointer ), false );
NS2.addSymbol( f2 );
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" );
A.setType( ParserSymbolTable.TypeInfo.t_class );
A.setType( TypeInfo.t_class );
look = compUnit.LookupNestedNameSpecifier( "NS2" );
assertEquals( look, NS2 );
@ -1393,14 +1393,14 @@ public class ParserSymbolTableTest extends TestCase {
look = compUnit.Lookup( "A" );
assertEquals( look, A );
ISymbol a = table.newSymbol( "a" );
a.setType( ParserSymbolTable.TypeInfo.t_type );
a.setType( TypeInfo.t_type );
a.setTypeSymbol( look );
compUnit.addSymbol( a );
LinkedList paramList = new LinkedList();
look = compUnit.Lookup( "a" );
assertEquals( look, a );
ParserSymbolTable.TypeInfo param = new ParserSymbolTable.TypeInfo( look.getType(), 0, look, new PtrOp( PtrOp.t_reference ), false );
TypeInfo param = new TypeInfo( look.getType(), 0, look, new PtrOp( PtrOp.t_reference ), false );
paramList.add( param );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList );
@ -1433,27 +1433,27 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C" );
C.setType( ParserSymbolTable.TypeInfo.t_class );
C.setType( TypeInfo.t_class );
compUnit.addSymbol(C);
IParameterizedSymbol f1 = table.newParameterizedSymbol("foo");
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.setType( TypeInfo.t_function );
f1.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f1.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
f1.addParameter( TypeInfo.t_int, 0, null, false );
C.addSymbol( f1 );
IParameterizedSymbol f2 = table.newParameterizedSymbol("foo");
f2.setType( ParserSymbolTable.TypeInfo.t_function );
f2.setType( TypeInfo.t_function );
f2.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f2.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
f2.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, null, false );
f2.addParameter( TypeInfo.t_int, 0, null, false );
f2.addParameter( TypeInfo.t_char, 0, null, false );
C.addSymbol( f2 );
IParameterizedSymbol f3 = table.newParameterizedSymbol("foo");
f3.setType( ParserSymbolTable.TypeInfo.t_function );
f3.setType( TypeInfo.t_function );
f3.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f3.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
f3.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, null, false );
f3.addParameter( TypeInfo.t_int, 0, null, false );
f3.addParameter( TypeInfo.t_char, 0, null, false );
f3.addParameter( C, new PtrOp( PtrOp.t_pointer ), false );
C.addSymbol( f3 );
@ -1461,7 +1461,7 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( look, C );
ISymbol c = table.newSymbol("c");
c.setType( ParserSymbolTable.TypeInfo.t_type );
c.setType( TypeInfo.t_type );
c.setTypeSymbol( look );
c.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) );
compUnit.addSymbol( c );
@ -1472,9 +1472,9 @@ public class ParserSymbolTableTest extends TestCase {
LinkedList paramList = new LinkedList();
ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_int, 0, null );
ParserSymbolTable.TypeInfo p2 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_char, 0, null );
ParserSymbolTable.TypeInfo p3 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, 0, c );
TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null );
TypeInfo p2 = new TypeInfo( TypeInfo.t_char, 0, null );
TypeInfo p3 = new TypeInfo( TypeInfo.t_type, 0, c );
paramList.add( p1 );
look = C.MemberFunctionLookup( "foo", paramList );
@ -1507,30 +1507,30 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IParameterizedSymbol f1 = table.newParameterizedSymbol("f");
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
f1.setType( TypeInfo.t_function );
f1.addParameter( TypeInfo.t_int, 0, null, false );
compUnit.addSymbol( f1 );
IParameterizedSymbol f2 = table.newParameterizedSymbol("f");
f2.setType( ParserSymbolTable.TypeInfo.t_function );
f2.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, null, true );
f2.setType( TypeInfo.t_function );
f2.addParameter( TypeInfo.t_char, 0, null, true );
compUnit.addSymbol( f2 );
LinkedList paramList = new LinkedList();
ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_int, 0, null );
TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null );
paramList.add( p1 );
ISymbol look = compUnit.UnqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 );
paramList.clear();
ParserSymbolTable.TypeInfo p2 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_char, 0, null );
TypeInfo p2 = new TypeInfo( TypeInfo.t_char, 0, null );
paramList.add( p2 );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f2 );
paramList.clear();
ParserSymbolTable.TypeInfo p3 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_bool, 0, null );
TypeInfo p3 = new TypeInfo( TypeInfo.t_bool, 0, null );
paramList.add( p3 );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 );
@ -1562,47 +1562,47 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" );
A.setType( ParserSymbolTable.TypeInfo.t_class );
A.setType( TypeInfo.t_class );
compUnit.addSymbol( A );
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B" );
B.setType( ParserSymbolTable.TypeInfo.t_class );
B.setType( TypeInfo.t_class );
B.addParent( A );
compUnit.addSymbol( B );
IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C" );
C.setType( ParserSymbolTable.TypeInfo.t_class );
C.setType( TypeInfo.t_class );
C.addParent( B );
compUnit.addSymbol( C );
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f" );
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.setType( TypeInfo.t_function );
f1.addParameter( A, new PtrOp( PtrOp.t_pointer ), false );
compUnit.addSymbol( f1 );
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" );
f2.setType( ParserSymbolTable.TypeInfo.t_function );
f2.setType( TypeInfo.t_function );
f2.addParameter( B, new PtrOp( PtrOp.t_pointer ), false );
compUnit.addSymbol( f2 );
ISymbol a = table.newSymbol( "a" );
a.setType( ParserSymbolTable.TypeInfo.t_type );
a.setType( TypeInfo.t_type );
a.setTypeSymbol( A );
a.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) );
ISymbol c = table.newSymbol( "c" );
c.setType( ParserSymbolTable.TypeInfo.t_type );
c.setType( TypeInfo.t_type );
c.setTypeSymbol( C );
c.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) );
LinkedList paramList = new LinkedList();
ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, 0, a );
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, a );
paramList.add( p1 );
ISymbol look = compUnit.UnqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 );
paramList.clear();
ParserSymbolTable.TypeInfo p2 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, 0, c );
TypeInfo p2 = new TypeInfo( TypeInfo.t_type, 0, c );
paramList.add( p2 );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f2 );
@ -1634,42 +1634,42 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" );
A.setType( ParserSymbolTable.TypeInfo.t_class );
A.setType( TypeInfo.t_class );
compUnit.addSymbol( A );
ISymbol B = table.newSymbol( "B" );
B.setType( ParserSymbolTable.TypeInfo.t_type );
B.setType( TypeInfo.t_type );
B.setTypeSymbol( A );
B.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) );
compUnit.addSymbol( B );
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f" );
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.setType( TypeInfo.t_function );
f1.addParameter( A, new PtrOp( PtrOp.t_pointer ), false );
compUnit.addSymbol( f1 );
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" );
f2.setType( ParserSymbolTable.TypeInfo.t_function );
f2.setType( TypeInfo.t_function );
f2.addParameter( A, null, false );
compUnit.addSymbol( f2 );
ISymbol a = table.newSymbol( "a" );
a.setType( ParserSymbolTable.TypeInfo.t_type );
a.setType( TypeInfo.t_type );
a.setTypeSymbol( A );
compUnit.addSymbol( a );
ISymbol b = table.newSymbol( "b" );
b.setType( ParserSymbolTable.TypeInfo.t_type );
b.setType( TypeInfo.t_type );
b.setTypeSymbol( B );
compUnit.addSymbol( b );
ISymbol array = table.newSymbol( "array" );
array.setType( ParserSymbolTable.TypeInfo.t_type );
array.setType( TypeInfo.t_type );
array.setTypeSymbol( A );
array.addPtrOperator( new PtrOp( PtrOp.t_array, false, false ) );
LinkedList paramList = new LinkedList();
ParserSymbolTable.TypeInfo p = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, 0, a );
TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a );
paramList.add( p );
ISymbol look = compUnit.UnqualifiedFunctionLookup( "f", paramList );
@ -1717,31 +1717,31 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" );
A.setType( ParserSymbolTable.TypeInfo.t_class );
A.setType( TypeInfo.t_class );
compUnit.addSymbol( A );
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B" );
B.setType( ParserSymbolTable.TypeInfo.t_class );
B.setType( TypeInfo.t_class );
compUnit.addSymbol( B );
//12.1-1 "Constructors do not have names"
IParameterizedSymbol constructor = table.newParameterizedSymbol("");
constructor.setType( ParserSymbolTable.TypeInfo.t_function );
constructor.setType( TypeInfo.t_function );
constructor.addParameter( A, null, false );
B.addSymbol( constructor );
IParameterizedSymbol f = table.newParameterizedSymbol( "f" );
f.setType( ParserSymbolTable.TypeInfo.t_function );
f.setType( TypeInfo.t_function );
f.addParameter( B, null, false );
compUnit.addSymbol( f );
ISymbol a = table.newSymbol( "a" );
a.setType( ParserSymbolTable.TypeInfo.t_type );
a.setType( TypeInfo.t_type );
a.setTypeSymbol( A );
compUnit.addSymbol( a );
LinkedList paramList = new LinkedList();
ParserSymbolTable.TypeInfo p = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, 0, a );
TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a );
paramList.add( p );
ISymbol look = compUnit.UnqualifiedFunctionLookup( "f", paramList );
@ -1775,34 +1775,34 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f" );
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer, true, false ), false );
f1.addParameter( ParserSymbolTable.TypeInfo.t_int, ParserSymbolTable.TypeInfo.isShort, null, false );
f1.setType( TypeInfo.t_function );
f1.addParameter( TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer, true, false ), false );
f1.addParameter( TypeInfo.t_int, TypeInfo.isShort, null, false );
compUnit.addSymbol( f1 );
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" );
f2.setType( ParserSymbolTable.TypeInfo.t_function );
f2.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer ), false );
f2.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
f2.setType( TypeInfo.t_function );
f2.addParameter( TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer ), false );
f2.addParameter( TypeInfo.t_int, 0, null, false );
compUnit.addSymbol( f2 );
ISymbol i = table.newSymbol( "i" );
i.setType( ParserSymbolTable.TypeInfo.t_int );
i.setType( TypeInfo.t_int );
compUnit.addSymbol( i );
ISymbol s = table.newSymbol( "s" );
s.setType( ParserSymbolTable.TypeInfo.t_int );
s.getTypeInfo().setBit( true, ParserSymbolTable.TypeInfo.isShort );
s.setType( TypeInfo.t_int );
s.getTypeInfo().setBit( true, TypeInfo.isShort );
compUnit.addSymbol( s );
IParameterizedSymbol main = table.newParameterizedSymbol( "main" );
main.setType( ParserSymbolTable.TypeInfo.t_function );
main.setType( TypeInfo.t_function );
compUnit.addSymbol( main );
LinkedList params = new LinkedList();
ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, 0, i, new PtrOp( PtrOp.t_reference ), false );
ParserSymbolTable.TypeInfo p2 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, 0, s );
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, i, new PtrOp( PtrOp.t_reference ), false );
TypeInfo p2 = new TypeInfo( TypeInfo.t_type, 0, s );
params.add( p1 );
params.add( p2 );
@ -1816,14 +1816,14 @@ public class ParserSymbolTableTest extends TestCase {
}
params.clear();
ParserSymbolTable.TypeInfo p3 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_int, ParserSymbolTable.TypeInfo.isLong, null );
TypeInfo p3 = new TypeInfo( TypeInfo.t_int, TypeInfo.isLong, null );
params.add( p1 );
params.add( p3 );
look = main.UnqualifiedFunctionLookup( "f", params );
assertEquals( look, f2 );
params.clear();
ParserSymbolTable.TypeInfo p4 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_char, 0, null );
TypeInfo p4 = new TypeInfo( TypeInfo.t_char, 0, null );
params.add( p1 );
params.add( p4 );
look = main.UnqualifiedFunctionLookup( "f", params );
@ -1868,34 +1868,34 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit();
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B" );
B.setType( ParserSymbolTable.TypeInfo.t_class );
B.setType( TypeInfo.t_class );
compUnit.addSymbol( B );
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" );
A.setType( ParserSymbolTable.TypeInfo.t_class );
A.setType( TypeInfo.t_class );
compUnit.addSymbol( A );
IParameterizedSymbol constructA = table.newParameterizedSymbol( "" );
constructA.setType( ParserSymbolTable.TypeInfo.t_function );
constructA.setType( TypeInfo.t_function );
constructA.addParameter( B, new PtrOp( PtrOp.t_reference ), false );
A.addSymbol( constructA );
IParameterizedSymbol operator = table.newParameterizedSymbol( "operator A" );
operator.setType( ParserSymbolTable.TypeInfo.t_function );
operator.setType( TypeInfo.t_function );
B.addSymbol( operator );
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f" );
f1.setType( ParserSymbolTable.TypeInfo.t_function );
f1.setType( TypeInfo.t_function );
f1.addParameter( A, null, false );
compUnit.addSymbol( f1 );
ISymbol b = table.newSymbol( "b" );
b.setType( ParserSymbolTable.TypeInfo.t_type );
b.setType( TypeInfo.t_type );
b.setTypeSymbol( B );
LinkedList params = new LinkedList();
ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, 0, b );
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, b );
params.add( p1 );
ISymbol look = null;
@ -1908,16 +1908,16 @@ public class ParserSymbolTableTest extends TestCase {
}
IDerivableContainerSymbol C = table.newDerivableContainerSymbol("C");
C.setType( ParserSymbolTable.TypeInfo.t_class );
C.setType( TypeInfo.t_class );
compUnit.addSymbol( C );
IParameterizedSymbol constructC = table.newParameterizedSymbol("");
constructC.setType( ParserSymbolTable.TypeInfo.t_function );
constructC.setType( TypeInfo.t_function );
constructC.addParameter( B, new PtrOp( PtrOp.t_reference ), false );
C.addSymbol( constructC );
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" );
f2.setType( ParserSymbolTable.TypeInfo.t_function );
f2.setType( TypeInfo.t_function );
f2.addParameter( C, null, false );
compUnit.addSymbol( f2 );
@ -1929,7 +1929,7 @@ public class ParserSymbolTableTest extends TestCase {
}
IParameterizedSymbol f3 = table.newParameterizedSymbol( "f" );
f3.setType( ParserSymbolTable.TypeInfo.t_function );
f3.setType( TypeInfo.t_function );
f3.addParameter( B, null, false );
compUnit.addSymbol( f3 );

View file

@ -1,3 +1,6 @@
2003-07-22 John Camelon
Added in preliminary support for Field/Variable w/cross references on their types.
2003-07-21 John Camelon
Addded in support for BaseSpecifier & class/namespace reference callbacks upon those.

View file

@ -10,11 +10,13 @@
***********************************************************************/
package org.eclipse.cdt.core.parser.ast;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
/**
* @author jcamelon
*
*/
public interface IASTEnumerator extends IASTOffsetableNamedElement {
public interface IASTEnumerator extends IASTOffsetableNamedElement, ISourceElementCallbackDelegate {
public IASTEnumerationSpecifier getOwnerEnumerationSpecifier();
public IASTExpression getInitialValue();

View file

@ -0,0 +1,19 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.core.parser.ast;
/**
* @author jcamelon
*
*/
public interface IASTEnumeratorReference extends IASTReference
{
}

View file

@ -116,13 +116,13 @@ public interface IASTFactory
ITokenDuple duple,
IASTExpression expressionList);
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(
IASTScope scope,
IASTSimpleTypeSpecifier.Type kind,
ITokenDuple typeName,
boolean isShort,
boolean isLong,
boolean isSigned,
boolean isUnsigned,
boolean isTypename);
boolean isUnsigned, boolean isTypename) throws ASTSemanticException;
public IASTFunction createFunction(
IASTScope scope,
String name,

View file

@ -21,6 +21,6 @@ public interface IASTReference extends ISourceElementCallbackDelegate
public int getOffset();
public String getName();
public IASTScopedElement getReferencedElement();
public ISourceElementCallbackDelegate getReferencedElement();
}

View file

@ -48,5 +48,7 @@ public interface IASTSimpleTypeSpecifier extends IASTTypeSpecifier
public boolean isShort();
public boolean isSigned();
public boolean isUnsigned();
public boolean isTypename();
public boolean isTypename();
public IASTTypeSpecifier getTypeSpecifier() throws ASTNotImplementedException;
}

View file

@ -428,7 +428,7 @@ public class Parser implements IParser
try
{
List parms = templateParameterList();
List parms = templateParameterList(scope);
consume(IToken.tGT);
IASTTemplateDeclaration templateDecl = astFactory.createTemplateDeclaration( scope, parms, exported, firstToken.getOffset() );
templateDecl.enterScope( requestor );
@ -466,7 +466,7 @@ public class Parser implements IParser
* @param templateDeclaration Callback's templateDeclaration which serves as a scope to this list.
* @throws Backtrack request for a backtrack
*/
protected List templateParameterList()
protected List templateParameterList(IASTScope scope)
throws Backtrack
{
// if we have gotten this far then we have a true template-declaration
@ -518,7 +518,7 @@ public class Parser implements IParser
IToken kind = consume(IToken.t_template);
consume(IToken.tLT);
List subResult = templateParameterList();
List subResult = templateParameterList(scope);
consume(IToken.tGT);
consume(IToken.t_class);
IToken optionalId = null;
@ -551,7 +551,7 @@ public class Parser implements IParser
else
{
ParameterCollection c = new ParameterCollection();
parameterDeclaration(c);
parameterDeclaration(c, scope);
DeclarationWrapper wrapper =
(DeclarationWrapper)c.getParameters().get(0);
Declarator declarator =
@ -764,16 +764,21 @@ public class Parser implements IParser
new DeclarationWrapper(scope, LA(1).getOffset(), ownerTemplate);
declSpecifierSeq(false, tryConstructor, sdw);
if (sdw.getTypeSpecifier() == null )
sdw.setTypeSpecifier(
astFactory.createSimpleTypeSpecifier(
sdw.getSimpleType(),
sdw.getName(),
sdw.isShort(),
sdw.isLong(),
sdw.isSigned(),
sdw.isUnsigned(),
sdw.isTypeNamed()));
try
{
if (sdw.getTypeSpecifier() == null )
sdw.setTypeSpecifier(
astFactory.createSimpleTypeSpecifier(
scope,
sdw.getSimpleType(),
sdw.getName(),
sdw.isShort(),
sdw.isLong(),
sdw.isSigned(),
sdw.isUnsigned(), sdw.isTypeNamed()));
} catch( ASTSemanticException se )
{
}
Declarator declarator = null;
if (LT(1) != IToken.tSEMI)
@ -947,7 +952,7 @@ public class Parser implements IParser
* @throws Backtrack request a backtrack
*/
protected void parameterDeclaration(
IParameterCollection collection)
IParameterCollection collection, IASTScope scope)
throws Backtrack
{
IToken current = LA(1);
@ -955,18 +960,23 @@ public class Parser implements IParser
DeclarationWrapper sdw =
new DeclarationWrapper(null, current.getOffset(), null);
declSpecifierSeq(true, false, sdw);
if (sdw.getTypeSpecifier() == null
&& sdw.getSimpleType()
!= IASTSimpleTypeSpecifier.Type.UNSPECIFIED)
sdw.setTypeSpecifier(
astFactory.createSimpleTypeSpecifier(
sdw.getSimpleType(),
sdw.getName(),
sdw.isShort(),
sdw.isLong(),
sdw.isSigned(),
sdw.isUnsigned(),
sdw.isTypeNamed()));
try
{
if (sdw.getTypeSpecifier() == null
&& sdw.getSimpleType()
!= IASTSimpleTypeSpecifier.Type.UNSPECIFIED)
sdw.setTypeSpecifier(
astFactory.createSimpleTypeSpecifier(
scope,
sdw.getSimpleType(),
sdw.getName(),
sdw.isShort(),
sdw.isLong(),
sdw.isSigned(),
sdw.isUnsigned(), sdw.isTypeNamed()));
}
catch( ASTSemanticException se ) { }
if (LT(1) != IToken.tSEMI)
try
{
@ -1618,7 +1628,7 @@ public class Parser implements IParser
DeclarationWrapper sdw)
throws Backtrack
{
Declarator d = declarator(sdw);
Declarator d = declarator(sdw, sdw.getScope());
// handle = initializerClause
if (LT(1) == IToken.tASSIGN)
{
@ -1713,7 +1723,7 @@ public class Parser implements IParser
* @throws Backtrack request a backtrack
*/
protected Declarator declarator(
IDeclaratorOwner owner)
IDeclaratorOwner owner, IASTScope scope)
throws Backtrack
{
Declarator d = null;
@ -1736,7 +1746,7 @@ public class Parser implements IParser
if (LT(1) == IToken.tLPAREN)
{
consume();
declarator(d);
declarator(d, scope);
consume(IToken.tRPAREN);
}
else if (LT(1) == IToken.t_operator)
@ -1806,7 +1816,7 @@ public class Parser implements IParser
default :
if (seenParameter)
throw backtrack;
parameterDeclaration(d);
parameterDeclaration(d, scope);
seenParameter = true;
}
}

View file

@ -8,7 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick;
package org.eclipse.cdt.internal.core.parser.ast;
import java.util.Iterator;
import java.util.List;

View file

@ -10,10 +10,10 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTScopedElement;
/**
* @author jcamelon
@ -37,7 +37,7 @@ public class ASTClassReference
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement()
*/
public IASTScopedElement getReferencedElement()
public ISourceElementCallbackDelegate getReferencedElement()
{
return reference;
}

View file

@ -0,0 +1,59 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
/**
* @author jcamelon
*
*/
public class ASTField extends ASTVariable implements IASTField
{
private final ASTAccessVisibility visibility;
/**
* @param newSymbol
* @param abstractDeclaration
* @param initializerClause
* @param bitfieldExpression
* @param startingOffset
* @param nameOffset
* @param references
* @param visibility
*/
public ASTField(ISymbol newSymbol, IASTAbstractDeclaration abstractDeclaration, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, int startingOffset, int nameOffset, List references, ASTAccessVisibility visibility)
{
super( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references );
this.visibility = visibility;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTMember#getVisiblity()
*/
public ASTAccessVisibility getVisiblity()
{
return visibility;
}
public void acceptElement(ISourceElementRequestor requestor)
{
requestor.acceptField(this);
referenceDelegate.processReferences(requestor);
}
}

View file

@ -10,10 +10,10 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
import org.eclipse.cdt.core.parser.ast.IASTScopedElement;
/**
* @author jcamelon
@ -39,7 +39,7 @@ public class ASTNamespaceReference
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement()
*/
public IASTScopedElement getReferencedElement()
public ISourceElementCallbackDelegate getReferencedElement()
{
return reference;
}

View file

@ -0,0 +1,133 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
/**
* @author jcamelon
*
*/
public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
{
private final List refs;
private ISymbol symbol;
private final boolean isTypename;
private final String name;
/**
* @param s
* @param b
* @param string
*/
public ASTSimpleTypeSpecifier(ISymbol s, boolean b, String string, List references )
{
this.symbol = s;
this.isTypename = b;
this.name = string;
this.refs = references;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getType()
*/
public Type getType()
{
if( symbol.getType() == TypeInfo.t_int )
return IASTSimpleTypeSpecifier.Type.INT;
if( symbol.getType() == TypeInfo.t_double )
return IASTSimpleTypeSpecifier.Type.DOUBLE;
if( symbol.getType() == TypeInfo.t_float )
return IASTSimpleTypeSpecifier.Type.FLOAT;
if( symbol.getType() == TypeInfo.t_bool )
return IASTSimpleTypeSpecifier.Type.BOOL;
if( symbol.getType() == TypeInfo.t_type )
return IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
if( symbol.getType() == TypeInfo.t_char )
return IASTSimpleTypeSpecifier.Type.CHAR;
if( symbol.getType() == TypeInfo.t_void )
return IASTSimpleTypeSpecifier.Type.VOID;
if( symbol.getType() == TypeInfo.t_wchar_t)
return IASTSimpleTypeSpecifier.Type.WCHAR_T;
return IASTSimpleTypeSpecifier.Type.UNSPECIFIED;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getTypename()
*/
public String getTypename()
{
return name;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isLong()
*/
public boolean isLong()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isLong );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isShort()
*/
public boolean isShort()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isShort );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isSigned()
*/
public boolean isSigned()
{
return ! symbol.getTypeInfo().checkBit( TypeInfo.isUnsigned);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isUnsigned()
*/
public boolean isUnsigned()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isUnsigned );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isTypename()
*/
public boolean isTypename()
{
return isTypename;
}
/**
* @return
*/
public ISymbol getSymbol()
{
return symbol;
}
public List getReferences()
{
return refs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getTypeSpecifier()
*/
public IASTTypeSpecifier getTypeSpecifier() throws ASTNotImplementedException
{
return (IASTTypeSpecifier)getSymbol().getTypeSymbol().getASTExtension().getPrimaryDeclaration();
}
}

View file

@ -0,0 +1,204 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
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;
/**
* @author jcamelon
*
*/
public class ASTVariable extends ASTSymbol implements IASTVariable
{
protected final ASTReferenceStore referenceDelegate;
private final ASTQualifiedNamedElement qualifiedName;
private NamedOffsets offsets = new NamedOffsets();
private final IASTExpression bitfieldExpression;
private final IASTInitializerClause initializerClause;
private final IASTAbstractDeclaration abstractDeclaration;
/**
* @param newSymbol
* @param abstractDeclaration
* @param initializerClause
* @param bitfieldExpression
* @param startingOffset
* @param nameOffset
* @param references
*/
public ASTVariable(ISymbol newSymbol, IASTAbstractDeclaration abstractDeclaration, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, int startingOffset, int nameOffset, List references)
{
super( newSymbol );
this.abstractDeclaration = abstractDeclaration;
this.initializerClause = initializerClause;
this.bitfieldExpression = bitfieldExpression;
setStartingOffset( startingOffset );
setNameOffset( nameOffset );
referenceDelegate = new ASTReferenceStore( references );
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), newSymbol.getName() );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isAuto()
*/
public boolean isAuto()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isAuto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isRegister()
*/
public boolean isRegister()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isRegister);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isStatic()
*/
public boolean isStatic()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isStatic);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isExtern()
*/
public boolean isExtern()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isExtern );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isMutable()
*/
public boolean isMutable()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isMutable);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#getAbstractDeclaration()
*/
public IASTAbstractDeclaration getAbstractDeclaration()
{
return abstractDeclaration;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName()
*/
public String getName()
{
return getSymbol().getName();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#getInitializerClause()
*/
public IASTInitializerClause getInitializerClause()
{
return initializerClause;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isBitfield()
*/
public boolean isBitfield()
{
return ( bitfieldExpression != null );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#getBitfieldExpression()
*/
public IASTExpression getBitfieldExpression()
{
return bitfieldExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset()
*/
public int getNameOffset()
{
return offsets.getNameOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int)
*/
public void setNameOffset(int o)
{
offsets.setNameOffset(o);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName()
*/
public String[] getFullyQualifiedName()
{
return qualifiedName.getFullyQualifiedName();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope()
*/
public IASTScope getOwnerScope()
{
return (IASTScope)getSymbol().getContainingSymbol().getASTExtension().getPrimaryDeclaration();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
requestor.acceptVariable(this);
referenceDelegate.processReferences(requestor);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void enterScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void exitScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int)
*/
public void setStartingOffset(int o)
{
offsets.setStartingOffset(o);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int)
*/
public void setEndingOffset(int o)
{
offsets.setEndingOffset(o);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset()
*/
public int getStartingOffset()
{
return offsets.getStartingOffset();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset()
*/
public int getEndingOffset()
{
return offsets.getEndingOffset();
}
}

View file

@ -58,6 +58,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescripto
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind;
import org.eclipse.cdt.internal.core.parser.ast.ASTAbstractDeclaration;
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier;
import org.eclipse.cdt.internal.core.parser.pst.ForewardDeclaredSymbolExtension;
@ -69,6 +70,7 @@ import org.eclipse.cdt.internal.core.parser.pst.NamespaceSymbolExtension;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException;
/**
@ -206,12 +208,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( namespaceSymbol != null )
{
if( namespaceSymbol.getType() != ParserSymbolTable.TypeInfo.t_namespace )
if( namespaceSymbol.getType() != TypeInfo.t_namespace )
throw new ASTSemanticException();
}
else
{
namespaceSymbol = pst.newContainerSymbol( identifier, ParserSymbolTable.TypeInfo.t_namespace );
namespaceSymbol = pst.newContainerSymbol( identifier, TypeInfo.t_namespace );
try
{
pstScope.addSymbol( namespaceSymbol );
@ -304,14 +306,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
int nameOffset) throws ASTSemanticException
{
IContainerSymbol containerSymbol = scopeToSymbol(scope);
ParserSymbolTable.TypeInfo.eType pstType = null;
TypeInfo.eType pstType = null;
if( kind == ASTClassKind.CLASS )
pstType = ParserSymbolTable.TypeInfo.t_class;
pstType = TypeInfo.t_class;
else if( kind == ASTClassKind.STRUCT )
pstType = ParserSymbolTable.TypeInfo.t_struct;
pstType = TypeInfo.t_struct;
else if( kind == ASTClassKind.UNION )
pstType = ParserSymbolTable.TypeInfo.t_union;
pstType = TypeInfo.t_union;
else
throw new ASTSemanticException();
@ -384,16 +386,18 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
*/
private IASTReference createReference(ISymbol symbol, String string, int offset ) throws ASTSemanticException
{
if( symbol.getType() == ParserSymbolTable.TypeInfo.t_namespace )
if( symbol.getType() == TypeInfo.t_namespace )
{
return new ASTNamespaceReference( offset, string, (IASTNamespaceDefinition)symbol.getASTExtension().getPrimaryDeclaration());
}
else if( symbol.getType() == ParserSymbolTable.TypeInfo.t_class ||
symbol.getType() == ParserSymbolTable.TypeInfo.t_struct ||
symbol.getType() == ParserSymbolTable.TypeInfo.t_union )
else if( symbol.getType() == TypeInfo.t_class ||
symbol.getType() == TypeInfo.t_struct ||
symbol.getType() == TypeInfo.t_union )
{
return new ASTClassReference( offset, string, (IASTClassSpecifier)symbol.getASTExtension().getPrimaryDeclaration() );
}
// else if( symbol.getType() == ParserSymbolTable.TypeInfo.t_enumeration )
// return new
throw new ASTSemanticException();
}
@ -498,16 +502,93 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type, org.eclipse.cdt.core.parser.ITokenDuple, boolean, boolean, boolean, boolean, boolean)
*/
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(
IASTScope scope,
Type kind,
ITokenDuple typeName,
boolean isShort,
boolean isLong,
boolean isSigned,
boolean isUnsigned,
boolean isTypename)
boolean isUnsigned, boolean isTypename) throws ASTSemanticException
{
// TODO Auto-generated method stub
return null;
TypeInfo.eType type = null;
if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
{
type = TypeInfo.t_type;
}
else if( kind == IASTSimpleTypeSpecifier.Type.BOOL )
{
type = TypeInfo.t_bool;
}
else if( kind == IASTSimpleTypeSpecifier.Type.CHAR )
{
type = TypeInfo.t_char;
}
else if( kind == IASTSimpleTypeSpecifier.Type.DOUBLE )
{
type = TypeInfo.t_double;
}
else if( kind == IASTSimpleTypeSpecifier.Type.FLOAT )
{
type = TypeInfo.t_double;
}
else if( kind == IASTSimpleTypeSpecifier.Type.INT )
{
type = TypeInfo.t_int;
}
else if( kind == IASTSimpleTypeSpecifier.Type.VOID )
{
type = TypeInfo.t_void;
}
else if( kind == IASTSimpleTypeSpecifier.Type.WCHAR_T)
{
type = TypeInfo.t_wchar_t;
}
List references = new ArrayList();
ISymbol s = pst.newSymbol( "", type );
if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
{
// lookup the duple
Iterator i = typeName.iterator();
IToken first = typeName.getFirstToken();
IContainerSymbol typeSymbol = null;
if( first.getType() == IToken.tCOLONCOLON )
{
typeSymbol = pst.getCompilationUnit();
i.next(); // waste this token
}
else
{
typeSymbol = scopeToSymbol( scope );
}
while( i.hasNext() )
{
IToken current = (IToken)i.next();
if( current.getType() == IToken.tCOLONCOLON ) continue;
try
{
typeSymbol = typeSymbol.LookupNestedNameSpecifier( current.getImage());
references.add( createReference( typeSymbol, current.getImage(), current.getOffset() ));
}
catch (ParserSymbolTableException e)
{
throw new ASTSemanticException();
}
}
s.setTypeSymbol( typeSymbol );
}
s.getTypeInfo().setBit( isLong, TypeInfo.isLong );
s.getTypeInfo().setBit( isShort, TypeInfo.isShort);
s.getTypeInfo().setBit( isUnsigned, TypeInfo.isUnsigned );
return new ASTSimpleTypeSpecifier( s, false, typeName.toString(), references );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createFunction(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplate)
@ -537,8 +618,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
List pointerOperators,
List arrayModifiers)
{
// TODO Auto-generated method stub
return null;
return new ASTAbstractDeclaration( isConst, typeSpecifier, pointerOperators, arrayModifiers );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createMethod(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplate, boolean, boolean, boolean, boolean, boolean, boolean, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility)
@ -584,8 +664,59 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
int startingOffset,
int nameOffset)
{
// TODO Auto-generated method stub
return null;
List references = new ArrayList();
ISymbol newSymbol = cloneSimpleTypeSymbol(scope, name, abstractDeclaration, references);
setSymbolBits(
isAuto,
abstractDeclaration,
isMutable,
isExtern,
isRegister,
isStatic,
newSymbol);
return new ASTVariable( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references );
}
private void setSymbolBits(
boolean isAuto,
IASTAbstractDeclaration abstractDeclaration,
boolean isMutable,
boolean isExtern,
boolean isRegister,
boolean isStatic,
ISymbol newSymbol)
{
newSymbol.getTypeInfo().setBit( isMutable, TypeInfo.isMutable );
newSymbol.getTypeInfo().setBit( isAuto, TypeInfo.isAuto );
newSymbol.getTypeInfo().setBit( isExtern, TypeInfo.isExplicit );
newSymbol.getTypeInfo().setBit( isRegister, TypeInfo.isRegister );
newSymbol.getTypeInfo().setBit( isStatic, TypeInfo.isStatic );
newSymbol.getTypeInfo().setBit( abstractDeclaration.isConst(), TypeInfo.isConst );
}
private ISymbol cloneSimpleTypeSymbol(
IASTScope scope,
String name,
IASTAbstractDeclaration abstractDeclaration,
List references)
{
ISymbol newSymbol = null;
if( abstractDeclaration.getTypeSpecifier() instanceof ASTSimpleTypeSpecifier )
{
ISymbol symbolToBeCloned = ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol();
newSymbol = (ISymbol)symbolToBeCloned.clone();
newSymbol.setName( name );
IContainerSymbol containerSymbol = scopeToSymbol(scope);
try
{
containerSymbol.addSymbol( newSymbol );
}
catch (ParserSymbolTableException e)
{
// TODO Auto-generated catch block
}
references.addAll( ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getReferences() );
}
return newSymbol;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createField(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, boolean, org.eclipse.cdt.core.parser.ast.IASTInitializerClause, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility)
@ -605,8 +736,20 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
int nameOffset,
ASTAccessVisibility visibility)
{
// TODO Auto-generated method stub
return null;
List references = new ArrayList();
ISymbol newSymbol = cloneSimpleTypeSymbol(scope, name, abstractDeclaration, references);
setSymbolBits(
isAuto,
abstractDeclaration,
isMutable,
isExtern,
isRegister,
isStatic,
newSymbol);
return new ASTField( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references, visibility );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createParameterDeclaration(boolean, org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier, java.util.List, java.util.List, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTInitializerClause)

View file

@ -10,6 +10,7 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
@ -107,4 +108,22 @@ public class ASTEnumerator
{
return initialValue;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void enterScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void exitScope(ISourceElementRequestor requestor)
{
}
}

View file

@ -14,7 +14,9 @@ import java.util.Hashtable;
import java.util.Map;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
/**
* @author jcamelon
@ -150,4 +152,12 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
{
return isTypename;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getTypeSpecifier()
*/
public IASTTypeSpecifier getTypeSpecifier() throws ASTNotImplementedException
{
throw new ASTNotImplementedException();
}
}

View file

@ -55,6 +55,7 @@ import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
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.ast.*;
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
import org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier;
@ -202,7 +203,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType, org.eclipse.cdt.core.parser.ITokenDuple)
*/
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename )
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename )
{
return new ASTSimpleTypeSpecifier( kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename );
}

View file

@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException;
/**
* @author jcamelon

View file

@ -21,7 +21,6 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TypeInfo;
/**
* @author aniefer

View file

@ -19,7 +19,6 @@ package org.eclipse.cdt.internal.core.parser.pst;
import java.util.HashMap;
import java.util.LinkedList;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TypeInfo;
/**
* @author aniefer

View file

@ -14,12 +14,11 @@ import java.util.HashMap;
import java.util.LinkedList;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TypeInfo;
/**
* @author jcamelon
*
*/
public interface ISymbol {
public interface ISymbol extends Cloneable {
public ParserSymbolTable getSymbolTable();
@ -78,4 +77,9 @@ public interface ISymbol {
}
*/
public int getDepth();
/**
* @param name
*/
public void setName(String name);
}

View file

@ -16,6 +16,7 @@ import java.util.List;
import java.util.NoSuchElementException;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException;
/**
* @author jcamelon

View file

@ -3158,435 +3158,4 @@ public class ParserSymbolTable {
}
}
static public class TypeInfo {
public TypeInfo(){
super();
}
public TypeInfo( eType type, int info, ISymbol symbol ){
super();
_typeInfo = info;
_type = type;
_typeDeclaration = symbol;
}
public TypeInfo( eType type, int info, ISymbol symbol, PtrOp op, boolean hasDefault ){
super();
_typeInfo = info;
_type = type;
_typeDeclaration = symbol;
if( op != null ){
_ptrOperators = new LinkedList();
_ptrOperators.add( op );
} else {
_ptrOperators = null;
}
_hasDefaultValue = hasDefault;
}
public TypeInfo( eType type, int info, ISymbol symbol, PtrOp op, Object def ){
super();
_typeInfo = info;
_type = type;
_typeDeclaration = symbol;
if( op != null ){
_ptrOperators = new LinkedList();
_ptrOperators.add( op );
} else {
_ptrOperators = null;
}
_hasDefaultValue = true;
setDefault( def );
}
public TypeInfo( TypeInfo info ){
super();
_typeInfo = info._typeInfo;
_type = info._type;
_typeDeclaration = info._typeDeclaration;
_ptrOperators = ( info._ptrOperators == null ) ? null : (LinkedList)info._ptrOperators.clone();
_hasDefaultValue = info._hasDefaultValue;
}
public static final int typeMask = 0x001f;
public static final int isAuto = 0x0020;
public static final int isRegister = 0x0040;
public static final int isStatic = 0x0080;
public static final int isExtern = 0x0100;
public static final int isMutable = 0x0200;
public static final int isInline = 0x0400;
public static final int isVirtual = 0x0800;
public static final int isExplicit = 0x1000;
public static final int isTypedef = 0x2000;
public static final int isFriend = 0x4000;
public static final int isConst = 0x8000;
public static final int isVolatile = 0x10000;
public static final int isUnsigned = 0x20000;
public static final int isShort = 0x40000;
public static final int isLong = 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 eType t_any = new eType( -1 ); //don't care
public static final eType t_undef = new eType( 0 ); //not specified
public static final eType t_type = new eType( 1 ); //Type Specifier
public static final eType t_namespace = new eType( 2 );
public static final eType t_class = new eType( 3 );
public static final eType t_struct = new eType( 4 );
public static final eType t_union = new eType( 5 );
public static final eType t_enumeration = new eType( 6 );
public static final eType t_function = new eType( 7 );
public static final eType t_bool = new eType( 8 );
public static final eType t_char = new eType( 9 );
public static final eType t_wchar_t = new eType( 10 );
public static final eType t_int = new eType( 11 );
public static final eType t_float = new eType( 12 );
public static final eType t_double = new eType( 13 );
public static final eType t_void = new eType( 14 );
public static final eType t_enumerator = new eType( 15 );
public static final eType t_block = new eType( 16 );
public static final eType t_template = new eType( 17 );
public static final eType t_asm = new eType( 18 );
public static final eType t_linkage = new eType( 19 );
//public static final eType t_templateParameter = new eType( 18 );
public static class eType implements Comparable{
private eType( int v ){
_val = v;
}
public int compareTo( Object o ){
eType t = (eType) o;
return _val - t._val;
}
public int toInt(){
return _val;
}
private int _val;
}
public static class PtrOp {
public PtrOp( eType type ){
this.type = type;
}
public PtrOp( eType type, boolean isConst, boolean isVolatile ){
this.type = type;
this.isConst = isConst;
this.isVolatile = isVolatile;
}
public PtrOp( ISymbol memberOf, boolean isConst, boolean isVolatile ){
this.type = t_memberPointer;
this.isConst = isConst;
this.isVolatile = isVolatile;
this.memberOf = memberOf;
}
public PtrOp(){
super();
}
public static final eType t_undef = 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 isConst; }
public boolean isVolatile() { return isVolatile; }
public void setConst( boolean isConst ) { this.isConst = isConst; }
public void setVolatile(boolean isVolatile) { this.isVolatile = isVolatile; }
public ISymbol getMemberOf() { return memberOf; }
public void setMemberOf( ISymbol member ) { this.memberOf = member; }
public int compareCVTo( 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 PtrOp) ){
return false;
}
PtrOp op = (PtrOp)o;
return ( isConst() == op.isConst() &&
isVolatile() == op.isVolatile() &&
getType() == op.getType() );
}
private eType type = t_undef;
private boolean isConst = false;
private boolean isVolatile = false;
private ISymbol memberOf = null;
}
private static final String _image[] = { "",
"",
"namespace",
"template",
"class",
"struct",
"union",
"enum",
"",
"bool",
"char",
"wchar_t",
"int",
"float",
"double",
"void",
""
};
//Partial ordering :
// none < const
// none < volatile
// none < const volatile
// const < const volatile
// volatile < const volatile
public static final int cvConst = 2;
public static final int cvVolatile = 3;
public static final int cvConstVolatile = 5;
// Convenience methods
public void setBit(boolean b, int mask){
if( b ){
_typeInfo = _typeInfo | mask;
} else {
_typeInfo = _typeInfo & ~mask;
}
}
public boolean checkBit(int mask){
return (_typeInfo & mask) != 0;
}
public void setType( eType t){
_type = t;
}
public eType getType(){
return _type;
}
public boolean isType( eType type ){
return isType( type, t_undef );
}
public int getTypeInfo(){
return _typeInfo;
}
public void setTypeInfo( int typeInfo ){
_typeInfo = typeInfo;
}
/**
*
* @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( eType type, 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 );
} else {
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 != null && _ptrOperators.size() > 0 );
}
public LinkedList getPtrOperators(){
return _ptrOperators;
}
public boolean hasSamePtrs( TypeInfo type ){
int size = hasPtrOperators() ? getPtrOperators().size() : 0;
int size2 = type.hasPtrOperators() ? type.getPtrOperators().size() : 0;
if( size == size2 ){
if( size > 0 ){
Iterator iter1 = getPtrOperators().iterator();
Iterator iter2 = type.getPtrOperators().iterator();
PtrOp ptr1 = null, ptr2 = null;
for( int i = size; i > 0; i-- ){
ptr1 = (PtrOp)iter1.next();
ptr2 = (PtrOp)iter2.next();
if( ptr1.getType() != ptr2.getType() ){
return false;
}
}
}
return true;
}
return false;
}
public void applyPtrsAsUnaryOperators( LinkedList ptrs ){
if( ptrs == null || ptrs.isEmpty() )
return;
int size = ptrs.size();
Iterator iter = ptrs.iterator();
PtrOp op = null;
for( int i = size; i > 0; i-- ){
op = (PtrOp)iter.next();
if( op.getType() == PtrOp.t_pointer ){
//indirection operator, can only be applied to a pointer
if( hasPtrOperators() ){
PtrOp first = (PtrOp)getPtrOperators().getFirst();
if( first.getType() == PtrOp.t_pointer )
{
getPtrOperators().removeFirst();
if( op.isConst() || op.isVolatile() ){
if( hasPtrOperators() ){
((PtrOp)getPtrOperators().getFirst()).setConst( op.isConst() );
((PtrOp)getPtrOperators().getFirst()).setVolatile( op.isVolatile() );
} else {
PtrOp newOp = new PtrOp( PtrOp.t_undef, op.isConst(), op.isVolatile() );
addPtrOperator( newOp );
}
}
}
} else {
//???
}
} else if( op.getType() == PtrOp.t_reference ){
//Address-of unary operator, results in pointer to T
//TODO or pointer to member
PtrOp newOp = new PtrOp( PtrOp.t_pointer, op.isConst(), op.isVolatile() );
addPtrOperator( newOp );
}
}
}
public void addPtrOperator( PtrOp ptr ){
if( _ptrOperators == null ){
_ptrOperators = new LinkedList();
}
if( ptr != null )
_ptrOperators.add( ptr );
}
public void addPtrOperator( List ptrs ){
if( _ptrOperators == null ){
_ptrOperators = new LinkedList();
}
if( ptrs != null )
_ptrOperators.addAll( ptrs );
}
public boolean getHasDefault(){
return _hasDefaultValue;
}
public void setHasDefault( boolean def ){
_hasDefaultValue = def;
}
public void setDefault( Object t ){
_defaultValue = t;
}
public Object getDefault(){
return _defaultValue;
}
/**
* canHold
* @param type
* @return boolean
* return true is the 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 ){
return getType().compareTo( type.getType() ) >= 0;
}
public boolean equals( Object t ){
if( t == null || !(t instanceof TypeInfo) ){
return false;
}
TypeInfo type = (TypeInfo)t;
boolean result = ( _typeInfo == type._typeInfo );
result &= ( _type == type._type );
if( _typeDeclaration instanceof TemplateInstance ){
result &= _typeDeclaration.equals( type._typeDeclaration );
} else {
result &= ( _typeDeclaration == type._typeDeclaration );
}
int size1 = (_ptrOperators == null) ? 0 : _ptrOperators.size();
int size2 = (type._ptrOperators == null) ? 0 : type._ptrOperators.size();
if( size1 == size2 ){
if( size1 != 0 ){
Iterator iter1 = _ptrOperators.iterator();
Iterator iter2 = type._ptrOperators.iterator();
PtrOp op1 = null, op2 = null;
for( int i = size1; i > 0; i-- ){
op1 = (PtrOp)iter1.next();
op2 = (PtrOp)iter2.next();
if( !op1.equals(op2) ){
return false;
}
}
}
} else {
return false;
}
return result;
}
public String toString(){
if( isType( t_type ) ){
return _typeDeclaration.getName();
} else {
return _image[ getType().toInt() ];
}
}
private int _typeInfo = 0;
private eType _type = t_undef;
private ISymbol _typeDeclaration;
private boolean _hasDefaultValue = false;
private Object _defaultValue = null;
private LinkedList _ptrOperators;
}
}

View file

@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException;
/**

View file

@ -0,0 +1,450 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance;
public class TypeInfo {
public TypeInfo(){
super();
}
public TypeInfo( TypeInfo.eType type, int info, ISymbol symbol ){
super();
_typeInfo = info;
_type = type;
_typeDeclaration = symbol;
}
public TypeInfo( TypeInfo.eType type, int info, ISymbol symbol, TypeInfo.PtrOp op, boolean hasDefault ){
super();
_typeInfo = info;
_type = type;
_typeDeclaration = symbol;
if( op != null ){
_ptrOperators = new LinkedList();
_ptrOperators.add( op );
} else {
_ptrOperators = null;
}
_hasDefaultValue = hasDefault;
}
public TypeInfo( TypeInfo.eType type, int info, ISymbol symbol, TypeInfo.PtrOp op, Object def ){
super();
_typeInfo = info;
_type = type;
_typeDeclaration = symbol;
if( op != null ){
_ptrOperators = new LinkedList();
_ptrOperators.add( op );
} else {
_ptrOperators = null;
}
_hasDefaultValue = true;
setDefault( def );
}
public TypeInfo( TypeInfo info ){
super();
_typeInfo = info._typeInfo;
_type = info._type;
_typeDeclaration = info._typeDeclaration;
_ptrOperators = ( info._ptrOperators == null ) ? null : (LinkedList)info._ptrOperators.clone();
_hasDefaultValue = info._hasDefaultValue;
}
public static final int typeMask = 0x001f;
public static final int isAuto = 0x0020;
public static final int isRegister = 0x0040;
public static final int isStatic = 0x0080;
public static final int isExtern = 0x0100;
public static final int isMutable = 0x0200;
public static final int isInline = 0x0400;
public static final int isVirtual = 0x0800;
public static final int isExplicit = 0x1000;
public static final int isTypedef = 0x2000;
public static final int isFriend = 0x4000;
public static final int isConst = 0x8000;
public static final int isVolatile = 0x10000;
public static final int isUnsigned = 0x20000;
public static final int isShort = 0x40000;
public static final int isLong = 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_function = new TypeInfo.eType( 7 );
public static final TypeInfo.eType t_bool = new TypeInfo.eType( 8 );
public static final TypeInfo.eType t_char = new TypeInfo.eType( 9 );
public static final TypeInfo.eType t_wchar_t = new TypeInfo.eType( 10 );
public static final TypeInfo.eType t_int = new TypeInfo.eType( 11 );
public static final TypeInfo.eType t_float = new TypeInfo.eType( 12 );
public static final TypeInfo.eType t_double = new TypeInfo.eType( 13 );
public static final TypeInfo.eType t_void = new TypeInfo.eType( 14 );
public static final TypeInfo.eType t_enumerator = new TypeInfo.eType( 15 );
public static final TypeInfo.eType t_block = new TypeInfo.eType( 16 );
public static final TypeInfo.eType t_template = new TypeInfo.eType( 17 );
public static final TypeInfo.eType t_asm = new TypeInfo.eType( 18 );
public static final TypeInfo.eType t_linkage = new TypeInfo.eType( 19 );
//public static final eType t_templateParameter = new eType( 18 );
public static class eType implements Comparable{
private 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 PtrOp {
public PtrOp( TypeInfo.eType type ){
this.type = type;
}
public PtrOp( TypeInfo.eType type, boolean isConst, boolean isVolatile ){
this.type = type;
this.isConst = isConst;
this.isVolatile = isVolatile;
}
public PtrOp( ISymbol memberOf, boolean isConst, boolean isVolatile ){
this.type = PtrOp.t_memberPointer;
this.isConst = isConst;
this.isVolatile = isVolatile;
this.memberOf = memberOf;
}
public PtrOp(){
super();
}
public static final TypeInfo.eType t_undef = 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 TypeInfo.eType getType() { return type; }
public void setType( TypeInfo.eType type ) { this.type = type; }
public boolean isConst() { return isConst; }
public boolean isVolatile() { return isVolatile; }
public void setConst( boolean isConst ) { this.isConst = isConst; }
public void setVolatile(boolean isVolatile) { this.isVolatile = 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;
private boolean isConst = false;
private boolean isVolatile = false;
private ISymbol memberOf = null;
}
private static final String _image[] = { "",
"",
"namespace",
"template",
"class",
"struct",
"union",
"enum",
"",
"bool",
"char",
"wchar_t",
"int",
"float",
"double",
"void",
""
};
//Partial ordering :
// none < const
// none < volatile
// none < const volatile
// const < const volatile
// volatile < const volatile
public static final int cvConst = 2;
public static final int cvVolatile = 3;
public static final int cvConstVolatile = 5;
// Convenience methods
public void setBit(boolean b, int mask){
if( b ){
_typeInfo = _typeInfo | mask;
} else {
_typeInfo = _typeInfo & ~mask;
}
}
public boolean checkBit(int mask){
return (_typeInfo & mask) != 0;
}
public void setType( TypeInfo.eType t){
_type = t;
}
public TypeInfo.eType getType(){
return _type;
}
public boolean isType( TypeInfo.eType type ){
return isType( type, TypeInfo.t_undef );
}
public int getTypeInfo(){
return _typeInfo;
}
public void setTypeInfo( int typeInfo ){
_typeInfo = typeInfo;
}
/**
*
* @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 );
} else {
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 != null && _ptrOperators.size() > 0 );
}
public LinkedList getPtrOperators(){
return _ptrOperators;
}
public boolean hasSamePtrs( TypeInfo type ){
int size = hasPtrOperators() ? getPtrOperators().size() : 0;
int size2 = type.hasPtrOperators() ? type.getPtrOperators().size() : 0;
if( size == size2 ){
if( size > 0 ){
Iterator iter1 = getPtrOperators().iterator();
Iterator iter2 = type.getPtrOperators().iterator();
TypeInfo.PtrOp ptr1 = null, ptr2 = null;
for( int i = size; i > 0; i-- ){
ptr1 = (TypeInfo.PtrOp)iter1.next();
ptr2 = (TypeInfo.PtrOp)iter2.next();
if( ptr1.getType() != ptr2.getType() ){
return false;
}
}
}
return true;
}
return false;
}
public void applyPtrsAsUnaryOperators( LinkedList ptrs ){
if( ptrs == null || ptrs.isEmpty() )
return;
int size = ptrs.size();
Iterator iter = ptrs.iterator();
TypeInfo.PtrOp op = null;
for( int i = size; i > 0; i-- ){
op = (TypeInfo.PtrOp)iter.next();
if( op.getType() == PtrOp.t_pointer ){
//indirection operator, can only be applied to a pointer
if( hasPtrOperators() ){
TypeInfo.PtrOp first = (TypeInfo.PtrOp)getPtrOperators().getFirst();
if( first.getType() == TypeInfo.PtrOp.t_pointer )
{
getPtrOperators().removeFirst();
if( op.isConst() || op.isVolatile() ){
if( hasPtrOperators() ){
((TypeInfo.PtrOp)getPtrOperators().getFirst()).setConst( op.isConst() );
((TypeInfo.PtrOp)getPtrOperators().getFirst()).setVolatile( op.isVolatile() );
} else {
TypeInfo.PtrOp newOp = new TypeInfo.PtrOp( TypeInfo.PtrOp.t_undef, op.isConst(), op.isVolatile() );
addPtrOperator( newOp );
}
}
}
} else {
//???
}
} else if( op.getType() == PtrOp.t_reference ){
//Address-of unary operator, results in pointer to T
//TODO or pointer to member
TypeInfo.PtrOp newOp = new TypeInfo.PtrOp( PtrOp.t_pointer , op.isConst(), op.isVolatile() );
addPtrOperator( newOp );
}
}
}
public void addPtrOperator( TypeInfo.PtrOp ptr ){
if( _ptrOperators == null ){
_ptrOperators = new LinkedList();
}
if( ptr != null )
_ptrOperators.add( ptr );
}
public void addPtrOperator( List ptrs ){
if( _ptrOperators == null ){
_ptrOperators = new LinkedList();
}
if( ptrs != null )
_ptrOperators.addAll( ptrs );
}
public boolean getHasDefault(){
return _hasDefaultValue;
}
public void setHasDefault( boolean def ){
_hasDefaultValue = def;
}
public void setDefault( Object t ){
_defaultValue = t;
}
public Object getDefault(){
return _defaultValue;
}
/**
* canHold
* @param type
* @return boolean
* return true is the 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 ){
return getType().compareTo( type.getType() ) >= 0;
}
public boolean equals( Object t ){
if( t == null || !(t instanceof TypeInfo) ){
return false;
}
TypeInfo type = (TypeInfo)t;
boolean result = ( _typeInfo == type._typeInfo );
result &= ( _type == type._type );
if( _typeDeclaration instanceof TemplateInstance ){
result &= _typeDeclaration.equals( type._typeDeclaration );
} else {
result &= ( _typeDeclaration == type._typeDeclaration );
}
int size1 = (_ptrOperators == null) ? 0 : _ptrOperators.size();
int size2 = (type._ptrOperators == null) ? 0 : type._ptrOperators.size();
if( size1 == size2 ){
if( size1 != 0 ){
Iterator iter1 = _ptrOperators.iterator();
Iterator iter2 = type._ptrOperators.iterator();
TypeInfo.PtrOp op1 = null, op2 = null;
for( int i = size1; i > 0; i-- ){
op1 = (TypeInfo.PtrOp)iter1.next();
op2 = (TypeInfo.PtrOp)iter2.next();
if( !op1.equals(op2) ){
return false;
}
}
}
} else {
return false;
}
return result;
}
public String toString(){
if( isType( TypeInfo.t_type ) ){
return _typeDeclaration.getName();
} else {
return TypeInfo._image[ getType().toInt() ];
}
}
private int _typeInfo = 0;
private TypeInfo.eType _type = TypeInfo.t_undef;
private ISymbol _typeDeclaration;
private boolean _hasDefaultValue = false;
private Object _defaultValue = null;
private LinkedList _ptrOperators;
}