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

Patch for Andrew Niefer:

Core:
- refactor symbol table function names to start with lower case letters
- added better constructor support :
        - IDerivableContainerSymbol.addConstructor
        - IDerivableContainerSymbol.lookupConstructor
        - IDerivableContainerSymbol.getConstructors
- implicit user-defined conversion sequences now only use constructors not 
marked explicit
- user-defined conversion sequences are now only applied at most once 
(12.3-4 in spec) 
- changed ParserSymbolTableException.r_Unspecified to r_InternalError 
which is thrown on internal symbol table inconsistancies (likely from bugs 
rather than semantic problems with the parsed code)

Core.tests:
- updated tests to reflect function name refactoring
- added ParserSymbolTableTest.testConstructors
This commit is contained in:
Doug Schaefer 2003-08-07 14:46:58 +00:00
parent ca668ed712
commit 65003d3ab2
9 changed files with 403 additions and 263 deletions

View file

@ -1,3 +1,7 @@
2003-08-05 Andrew Niefer
- refactoring Parser Symbol Table function names
- added ParserSymbolTableTest.testConstructors()
2003-08-01 Andrew Niefer 2003-08-01 Andrew Niefer
Added resources/search/header.h Added resources/search/header.h
Added ClassDeclarationPatternTests.testHeadersVisitedTwice() Added ClassDeclarationPatternTests.testHeadersVisitedTwice()

View file

@ -90,7 +90,7 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol x = table.new Declaration( "x" ); ISymbol x = table.new Declaration( "x" );
table.getCompilationUnit().addSymbol( x ); table.getCompilationUnit().addSymbol( x );
ISymbol look = table.getCompilationUnit().Lookup( "x" ); ISymbol look = table.getCompilationUnit().lookup( "x" );
assertEquals( x, look ); assertEquals( x, look );
} }
@ -98,7 +98,7 @@ public class ParserSymbolTableTest extends TestCase {
public void testLookupNonExistant() throws Exception{ public void testLookupNonExistant() throws Exception{
newTable(); newTable();
ISymbol look = table.getCompilationUnit().Lookup("boo"); ISymbol look = table.getCompilationUnit().lookup("boo");
assertEquals( look, null ); assertEquals( look, null );
} }
@ -113,7 +113,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( x ); table.getCompilationUnit().addSymbol( x );
ISymbol look = table.getCompilationUnit().Lookup( "x" ); ISymbol look = table.getCompilationUnit().lookup( "x" );
assertEquals( look.getASTExtension(), extension ); assertEquals( look.getASTExtension(), extension );
} }
@ -134,16 +134,16 @@ public class ParserSymbolTableTest extends TestCase {
firstClass.setType( TypeInfo.t_class ); firstClass.setType( TypeInfo.t_class );
table.getCompilationUnit().addSymbol( firstClass ); table.getCompilationUnit().addSymbol( firstClass );
ISymbol look = firstClass.Lookup( "x" ); ISymbol look = firstClass.lookup( "x" );
assertEquals( look, firstX ); assertEquals( look, firstX );
ISymbol secondX = table.newSymbol("x"); ISymbol secondX = table.newSymbol("x");
firstClass.addSymbol( secondX ); firstClass.addSymbol( secondX );
look = firstClass.Lookup( "x" ); look = firstClass.lookup( "x" );
assertEquals( look, secondX ); assertEquals( look, secondX );
look = table.getCompilationUnit().Lookup( "x" ); look = table.getCompilationUnit().lookup( "x" );
assertEquals( look, firstX ); assertEquals( look, firstX );
} }
@ -162,7 +162,7 @@ public class ParserSymbolTableTest extends TestCase {
decl.setType( TypeInfo.t_class ); decl.setType( TypeInfo.t_class );
table.getCompilationUnit().addSymbol( decl ); table.getCompilationUnit().addSymbol( decl );
ISymbol look = decl.Lookup( "x" ); ISymbol look = decl.lookup( "x" );
assertEquals( x, look ); assertEquals( x, look );
} }
@ -189,7 +189,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( parent ); table.getCompilationUnit().addSymbol( parent );
table.getCompilationUnit().addSymbol( class1 ); table.getCompilationUnit().addSymbol( class1 );
ISymbol look = class1.Lookup( "x" ); ISymbol look = class1.lookup( "x" );
assertEquals( look, decl ); assertEquals( look, decl );
} }
@ -208,14 +208,14 @@ public class ParserSymbolTableTest extends TestCase {
IDerivableContainerSymbol parent2 = table.newDerivableContainerSymbol("parent2"); IDerivableContainerSymbol parent2 = table.newDerivableContainerSymbol("parent2");
table.getCompilationUnit().addSymbol( parent2 ); table.getCompilationUnit().addSymbol( parent2 );
IDerivableContainerSymbol class1 = (IDerivableContainerSymbol) table.getCompilationUnit().Lookup( "class" ); IDerivableContainerSymbol class1 = (IDerivableContainerSymbol) table.getCompilationUnit().lookup( "class" );
class1.addParent( parent2 ); class1.addParent( parent2 );
ISymbol decl = table.new Declaration("x"); ISymbol decl = table.new Declaration("x");
parent2.addSymbol( decl ); parent2.addSymbol( decl );
try{ try{
class1.Lookup( "x" ); class1.lookup( "x" );
assertTrue( false ); assertTrue( false );
} }
catch ( ParserSymbolTableException e ){ catch ( ParserSymbolTableException e ){
@ -241,7 +241,7 @@ public class ParserSymbolTableTest extends TestCase {
a.addParent( b ); a.addParent( b );
try{ try{
ISymbol look = a.Lookup("foo"); ISymbol look = a.lookup("foo");
assertTrue( false ); assertTrue( false );
} catch ( ParserSymbolTableException e) { } catch ( ParserSymbolTableException e) {
assertEquals( e.reason, ParserSymbolTableException.r_CircularInheritance ); assertEquals( e.reason, ParserSymbolTableException.r_CircularInheritance );
@ -285,7 +285,7 @@ public class ParserSymbolTableTest extends TestCase {
compUnit.addSymbol( a ); compUnit.addSymbol( a );
compUnit.addSymbol( b ); compUnit.addSymbol( b );
ISymbol look = decl.Lookup( "x" ); ISymbol look = decl.lookup( "x" );
assertEquals( look, x ); assertEquals( look, x );
} }
@ -306,8 +306,8 @@ public class ParserSymbolTableTest extends TestCase {
IContainerSymbol compUnit = table.getCompilationUnit(); IContainerSymbol compUnit = table.getCompilationUnit();
IDerivableContainerSymbol cls = (IDerivableContainerSymbol) compUnit.Lookup("class"); IDerivableContainerSymbol cls = (IDerivableContainerSymbol) compUnit.lookup("class");
IDerivableContainerSymbol c = (IDerivableContainerSymbol) compUnit.Lookup("C"); IDerivableContainerSymbol c = (IDerivableContainerSymbol) compUnit.lookup("C");
IDerivableContainerSymbol d = table.newDerivableContainerSymbol("D"); IDerivableContainerSymbol d = table.newDerivableContainerSymbol("D");
d.addParent( c ); d.addParent( c );
@ -316,7 +316,7 @@ public class ParserSymbolTableTest extends TestCase {
compUnit.addSymbol( d ); compUnit.addSymbol( d );
try{ try{
cls.Lookup( "x" ); cls.lookup( "x" );
assertTrue( false ); assertTrue( false );
} }
catch( ParserSymbolTableException e){ catch( ParserSymbolTableException e){
@ -375,7 +375,7 @@ public class ParserSymbolTableTest extends TestCase {
c.addParent( d ); c.addParent( d );
try{ try{
a.Lookup( "enumerator" ); a.lookup( "enumerator" );
assertTrue( true ); assertTrue( true );
} }
catch ( ParserSymbolTableException e){ catch ( ParserSymbolTableException e){
@ -383,7 +383,7 @@ public class ParserSymbolTableTest extends TestCase {
} }
try{ try{
a.Lookup( "static" ); a.lookup( "static" );
assertTrue( true ); assertTrue( true );
} }
catch ( ParserSymbolTableException e){ catch ( ParserSymbolTableException e){
@ -391,7 +391,7 @@ public class ParserSymbolTableTest extends TestCase {
} }
try{ try{
a.Lookup( "x" ); a.lookup( "x" );
assertTrue( false ); assertTrue( false );
} }
catch ( ParserSymbolTableException e){ catch ( ParserSymbolTableException e){
@ -436,11 +436,11 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( a ); table.getCompilationUnit().addSymbol( a );
table.getCompilationUnit().addSymbol( b ); table.getCompilationUnit().addSymbol( b );
ISymbol look = a.ElaboratedLookup( TypeInfo.t_class, "class" ); ISymbol look = a.elaboratedLookup( TypeInfo.t_class, "class" );
assertEquals( look, cls ); assertEquals( look, cls );
look = a.ElaboratedLookup( TypeInfo.t_struct, "struct" ); look = a.elaboratedLookup( TypeInfo.t_struct, "struct" );
assertEquals( look, struct ); assertEquals( look, struct );
look = a.ElaboratedLookup( TypeInfo.t_union, "union" ); look = a.elaboratedLookup( TypeInfo.t_union, "union" );
assertEquals( look, union ); assertEquals( look, union );
} }
@ -465,19 +465,19 @@ public class ParserSymbolTableTest extends TestCase {
A.addSymbol(member); A.addSymbol(member);
//at time of "A a;" //at time of "A a;"
ISymbol look = compUnit.Lookup("A"); ISymbol look = compUnit.lookup("A");
assertEquals( look, A ); assertEquals( look, A );
ISymbol a = table.newSymbol("a"); ISymbol a = table.newSymbol("a");
a.setTypeSymbol( look ); a.setTypeSymbol( look );
compUnit.addSymbol( a ); compUnit.addSymbol( a );
//later "a.member" //later "a.member"
look = compUnit.Lookup("a"); look = compUnit.lookup("a");
assertEquals( look, a ); assertEquals( look, a );
IContainerSymbol type = (IContainerSymbol) look.getTypeSymbol(); IContainerSymbol type = (IContainerSymbol) look.getTypeSymbol();
assertEquals( type, A ); assertEquals( type, A );
look = type.Lookup("member"); look = type.lookup("member");
assertEquals( look, member ); assertEquals( look, member );
} }
@ -512,10 +512,10 @@ public class ParserSymbolTableTest extends TestCase {
f.setType( TypeInfo.t_function ); f.setType( TypeInfo.t_function );
compUnit.addSymbol( f ); compUnit.addSymbol( f );
ISymbol look = f.ElaboratedLookup( TypeInfo.t_struct, "stat" ); ISymbol look = f.elaboratedLookup( TypeInfo.t_struct, "stat" );
assertEquals( look, struct ); assertEquals( look, struct );
look = f.Lookup( "stat" ); look = f.lookup( "stat" );
assertEquals( look, function ); assertEquals( look, function );
} }
@ -571,7 +571,7 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol nsC_i = table.newSymbol("i"); ISymbol nsC_i = table.newSymbol("i");
nsC.addSymbol( nsC_i ); nsC.addSymbol( nsC_i );
ISymbol look = nsB.Lookup("C"); ISymbol look = nsB.lookup("C");
assertEquals( look, nsC ); assertEquals( look, nsC );
nsB.addUsingDirective( nsC ); nsB.addUsingDirective( nsC );
@ -580,18 +580,18 @@ public class ParserSymbolTableTest extends TestCase {
nsB.addSymbol( f1 ); nsB.addSymbol( f1 );
look = f1.Lookup( "i" ); look = f1.lookup( "i" );
assertEquals( look, nsC_i ); //C::i visible and hides A::i assertEquals( look, nsC_i ); //C::i visible and hides A::i
IContainerSymbol nsD = table.newContainerSymbol("D"); IContainerSymbol nsD = table.newContainerSymbol("D");
nsD.setType( TypeInfo.t_namespace ); nsD.setType( TypeInfo.t_namespace );
nsA.addSymbol( nsD ); nsA.addSymbol( nsD );
look = nsD.Lookup("B"); look = nsD.lookup("B");
assertEquals( look, nsB ); assertEquals( look, nsB );
nsD.addUsingDirective( nsB ); nsD.addUsingDirective( nsB );
look = nsD.Lookup("C"); look = nsD.lookup("C");
assertEquals( look, nsC ); assertEquals( look, nsC );
nsD.addUsingDirective( nsC ); nsD.addUsingDirective( nsC );
@ -601,7 +601,7 @@ public class ParserSymbolTableTest extends TestCase {
try try
{ {
look = f2.Lookup( "i" ); look = f2.lookup( "i" );
assertTrue( false ); assertTrue( false );
} }
catch ( ParserSymbolTableException e ) catch ( ParserSymbolTableException e )
@ -614,14 +614,14 @@ public class ParserSymbolTableTest extends TestCase {
f3.setType( TypeInfo.t_function ); f3.setType( TypeInfo.t_function );
nsA.addSymbol( f3 ); nsA.addSymbol( f3 );
look = f3.Lookup("i"); look = f3.lookup("i");
assertEquals( look, nsA_i ); //uses A::i assertEquals( look, nsA_i ); //uses A::i
IParameterizedSymbol f4 = table.newParameterizedSymbol("f4"); IParameterizedSymbol f4 = table.newParameterizedSymbol("f4");
f4.setType( TypeInfo.t_function ); f4.setType( TypeInfo.t_function );
table.getCompilationUnit().addSymbol( f4 ); table.getCompilationUnit().addSymbol( f4 );
look = f4.Lookup("i"); look = f4.lookup("i");
assertEquals( look, null );//neither i is visible here. assertEquals( look, null );//neither i is visible here.
} }
/** /**
@ -675,7 +675,7 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol look = null; ISymbol look = null;
try try
{ {
look = f.Lookup( "i" ); look = f.lookup( "i" );
assertTrue( false ); assertTrue( false );
} }
catch ( ParserSymbolTableException e ) catch ( ParserSymbolTableException e )
@ -684,8 +684,8 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous );
} }
look = f.LookupNestedNameSpecifier("N"); look = f.lookupNestedNameSpecifier("N");
look = ((IContainerSymbol) look).QualifiedLookup("i"); //ok look = ((IContainerSymbol) look).qualifiedLookup("i"); //ok
assertEquals( look, nsN_i ); assertEquals( look, nsN_i );
} }
@ -745,9 +745,9 @@ public class ParserSymbolTableTest extends TestCase {
f.setType(TypeInfo.t_function); f.setType(TypeInfo.t_function);
compUnit.addSymbol( f ); compUnit.addSymbol( f );
ISymbol look = f.LookupNestedNameSpecifier("BC"); ISymbol look = f.lookupNestedNameSpecifier("BC");
assertEquals( look, nsBC ); assertEquals( look, nsBC );
look = ((IContainerSymbol)look).QualifiedLookup("a"); look = ((IContainerSymbol)look).qualifiedLookup("a");
assertEquals( look, a ); assertEquals( look, a );
} }
@ -800,18 +800,18 @@ public class ParserSymbolTableTest extends TestCase {
IParameterizedSymbol f = table.newParameterizedSymbol("f"); IParameterizedSymbol f = table.newParameterizedSymbol("f");
compUnit.addSymbol(f); compUnit.addSymbol(f);
IContainerSymbol lookA = f.LookupNestedNameSpecifier("A"); IContainerSymbol lookA = f.lookupNestedNameSpecifier("A");
ISymbol look = lookA.QualifiedLookup("a"); ISymbol look = lookA.qualifiedLookup("a");
assertEquals( look, a ); assertEquals( look, a );
look = lookA.QualifiedLookup("b"); look = lookA.qualifiedLookup("b");
assertEquals( look, b ); assertEquals( look, b );
IContainerSymbol lookB = f.LookupNestedNameSpecifier("B"); IContainerSymbol lookB = f.lookupNestedNameSpecifier("B");
look = lookB.QualifiedLookup("a"); look = lookB.qualifiedLookup("a");
assertEquals( look, a ); assertEquals( look, a );
look = lookB.QualifiedLookup("b"); look = lookB.qualifiedLookup("b");
assertEquals( look, b ); assertEquals( look, b );
} }
@ -858,7 +858,7 @@ public class ParserSymbolTableTest extends TestCase {
f.addUsingDirective(nsA); f.addUsingDirective(nsA);
f.addUsingDirective(nsB); f.addUsingDirective(nsB);
ISymbol look = f.Lookup("i"); ISymbol look = f.lookup("i");
assertEquals( look, null ); assertEquals( look, null );
} }
@ -920,26 +920,26 @@ public class ParserSymbolTableTest extends TestCase {
nsC.setType( TypeInfo.t_namespace); nsC.setType( TypeInfo.t_namespace);
compUnit.addSymbol( nsC ); compUnit.addSymbol( nsC );
ISymbol look = nsC.Lookup("A"); ISymbol look = nsC.lookup("A");
assertEquals( look, nsA ); assertEquals( look, nsA );
nsC.addUsingDirective( nsA ); nsC.addUsingDirective( nsA );
look = nsC.Lookup("B"); look = nsC.lookup("B");
assertEquals( look, nsB ); assertEquals( look, nsB );
nsC.addUsingDirective( nsB ); nsC.addUsingDirective( nsB );
//lookup C::x //lookup C::x
look = nsC.LookupNestedNameSpecifier("C"); look = nsC.lookupNestedNameSpecifier("C");
assertEquals( look, nsC ); assertEquals( look, nsC );
look = ((IContainerSymbol)look).QualifiedLookup( "x" ); look = ((IContainerSymbol)look).qualifiedLookup( "x" );
assertEquals( look, intX ); assertEquals( look, intX );
//lookup C::y //lookup C::y
look = nsC.LookupNestedNameSpecifier("C"); look = nsC.lookupNestedNameSpecifier("C");
assertEquals( look, nsC ); assertEquals( look, nsC );
try{ try{
look = ((IContainerSymbol)look).QualifiedLookup( "y" ); look = ((IContainerSymbol)look).qualifiedLookup( "y" );
assertTrue(false); assertTrue(false);
} catch ( ParserSymbolTableException e ) { } catch ( ParserSymbolTableException e ) {
assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous );
@ -979,14 +979,14 @@ public class ParserSymbolTableTest extends TestCase {
nsA.addUsingDirective( nsB ); nsA.addUsingDirective( nsB );
IContainerSymbol lookA = compUnit.LookupNestedNameSpecifier( "A" ); IContainerSymbol lookA = compUnit.lookupNestedNameSpecifier( "A" );
assertEquals( nsA, lookA ); assertEquals( nsA, lookA );
ISymbol look = lookA.LookupMemberForDefinition( "f1" ); ISymbol look = lookA.lookupMemberForDefinition( "f1" );
assertEquals( look, null ); assertEquals( look, null );
//but notice if you wanted to do A::f1 as a function call, it is ok //but notice if you wanted to do A::f1 as a function call, it is ok
look = lookA.QualifiedLookup( "f1" ); look = lookA.qualifiedLookup( "f1" );
assertEquals( look, f1 ); assertEquals( look, f1 );
} }
@ -1049,13 +1049,13 @@ public class ParserSymbolTableTest extends TestCase {
IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D" ); IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D" );
D.setType( TypeInfo.t_struct ); D.setType( TypeInfo.t_struct );
ISymbol look = compUnit.Lookup( "B" ); ISymbol look = compUnit.lookup( "B" );
assertEquals( look, B ); assertEquals( look, B );
D.addParent( B ); D.addParent( B );
compUnit.addSymbol( D ); compUnit.addSymbol( D );
IContainerSymbol lookB = D.LookupNestedNameSpecifier("B"); IContainerSymbol lookB = D.lookupNestedNameSpecifier("B");
assertEquals( lookB, B ); assertEquals( lookB, B );
D.addUsingDeclaration( "f", lookB ); D.addUsingDeclaration( "f", lookB );
@ -1064,7 +1064,7 @@ public class ParserSymbolTableTest extends TestCase {
//TBD anonymous union //TBD anonymous union
//D.addUsingDeclaration( "x", lookB ); //D.addUsingDeclaration( "x", lookB );
look = D.LookupNestedNameSpecifier("C"); look = D.lookupNestedNameSpecifier("C");
assertEquals( look, C ); assertEquals( look, C );
try{ try{
@ -1115,12 +1115,12 @@ public class ParserSymbolTableTest extends TestCase {
f1.addParameter( TypeInfo.t_int, 0, null, false ); f1.addParameter( TypeInfo.t_int, 0, null, false );
A.addSymbol( f1 ); A.addSymbol( f1 );
ISymbol look = compUnit.LookupNestedNameSpecifier("A"); ISymbol look = compUnit.lookupNestedNameSpecifier("A");
assertEquals( look, A ); assertEquals( look, A );
IParameterizedSymbol usingF = (IParameterizedSymbol) compUnit.addUsingDeclaration( "f", A ); IParameterizedSymbol usingF = (IParameterizedSymbol) compUnit.addUsingDeclaration( "f", A );
look = compUnit.Lookup("A"); look = compUnit.lookup("A");
assertEquals( look, A ); assertEquals( look, A );
IParameterizedSymbol f2 = table.newParameterizedSymbol("f"); IParameterizedSymbol f2 = table.newParameterizedSymbol("f");
@ -1138,7 +1138,7 @@ public class ParserSymbolTableTest extends TestCase {
TypeInfo param = new TypeInfo( TypeInfo.t_char, 0, null ); TypeInfo param = new TypeInfo( TypeInfo.t_char, 0, null );
paramList.add( param ); paramList.add( param );
look = foo.UnqualifiedFunctionLookup( "f", paramList ); look = foo.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, usingF ); assertEquals( look, usingF );
assertTrue( usingF.hasSameParameters( f1 ) ); assertTrue( usingF.hasSameParameters( f1 ) );
@ -1147,11 +1147,11 @@ public class ParserSymbolTableTest extends TestCase {
bar.addParameter( TypeInfo.t_char, 0, null, false ); bar.addParameter( TypeInfo.t_char, 0, null, false );
compUnit.addSymbol( bar ); compUnit.addSymbol( bar );
look = bar.LookupNestedNameSpecifier( "A" ); look = bar.lookupNestedNameSpecifier( "A" );
assertEquals( look, A ); assertEquals( look, A );
bar.addUsingDeclaration( "f", A ); bar.addUsingDeclaration( "f", A );
look = bar.UnqualifiedFunctionLookup( "f", paramList ); look = bar.unqualifiedFunctionLookup( "f", paramList );
assertTrue( look != null ); assertTrue( look != null );
assertTrue( ((IParameterizedSymbol) look).hasSameParameters( f2 ) ); assertTrue( ((IParameterizedSymbol) look).hasSameParameters( f2 ) );
} }
@ -1178,7 +1178,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( cls ); table.getCompilationUnit().addSymbol( cls );
cls.addSymbol( fn ); cls.addSymbol( fn );
ISymbol look = fn.Lookup("this"); ISymbol look = fn.lookup("this");
assertTrue( look != null ); assertTrue( look != null );
assertEquals( look.getType(), TypeInfo.t_type ); assertEquals( look.getType(), TypeInfo.t_type );
@ -1212,7 +1212,7 @@ public class ParserSymbolTableTest extends TestCase {
enumerator.setType( TypeInfo.t_enumerator ); enumerator.setType( TypeInfo.t_enumerator );
enumeration.addSymbol( enumerator ); enumeration.addSymbol( enumerator );
ISymbol look = cls.Lookup( "enumerator" ); ISymbol look = cls.lookup( "enumerator" );
assertEquals( look, enumerator ); assertEquals( look, enumerator );
assertEquals( look.getContainingSymbol(), cls ); assertEquals( look.getContainingSymbol(), cls );
assertEquals( look.getTypeSymbol(), enumeration ); assertEquals( look.getTypeSymbol(), enumeration );
@ -1250,15 +1250,15 @@ public class ParserSymbolTableTest extends TestCase {
f.setType( TypeInfo.t_function ); f.setType( TypeInfo.t_function );
f.setReturnType( table.newSymbol( "", TypeInfo.t_void ) ); f.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
ISymbol look = NS.Lookup( "T" ); ISymbol look = NS.lookup( "T" );
assertEquals( look, T ); assertEquals( look, T );
f.addParameter( look, null, false ); f.addParameter( look, null, false );
NS.addSymbol( f ); NS.addSymbol( f );
look = compUnit.LookupNestedNameSpecifier( "NS" ); look = compUnit.lookupNestedNameSpecifier( "NS" );
assertEquals( look, NS ); assertEquals( look, NS );
look = NS.QualifiedLookup( "T" ); look = NS.qualifiedLookup( "T" );
assertEquals( look, T ); assertEquals( look, T );
ISymbol param = table.newSymbol("parm"); ISymbol param = table.newSymbol("parm");
@ -1272,12 +1272,12 @@ public class ParserSymbolTableTest extends TestCase {
compUnit.addSymbol( main ); compUnit.addSymbol( main );
LinkedList paramList = new LinkedList(); LinkedList paramList = new LinkedList();
look = main.Lookup( "parm" ); look = main.lookup( "parm" );
assertEquals( look, param ); assertEquals( look, param );
TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, look ); TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, look );
paramList.add( p ); paramList.add( p );
look = main.UnqualifiedFunctionLookup( "f", paramList ); look = main.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f ); assertEquals( look, f );
} }
@ -1325,7 +1325,7 @@ public class ParserSymbolTableTest extends TestCase {
compUnit.addSymbol( NS2 ); compUnit.addSymbol( NS2 );
ISymbol look = NS2.Lookup( "NS1" ); ISymbol look = NS2.lookup( "NS1" );
assertEquals( look, NS1 ); assertEquals( look, NS1 );
NS2.addUsingDirective( NS1 ); NS2.addUsingDirective( NS1 );
@ -1341,16 +1341,16 @@ public class ParserSymbolTableTest extends TestCase {
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" ); IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A" );
A.setType( TypeInfo.t_class ); A.setType( TypeInfo.t_class );
look = compUnit.LookupNestedNameSpecifier( "NS2" ); look = compUnit.lookupNestedNameSpecifier( "NS2" );
assertEquals( look, NS2 ); assertEquals( look, NS2 );
look = NS2.QualifiedLookup( "B" ); look = NS2.qualifiedLookup( "B" );
assertEquals( look, B ); assertEquals( look, B );
A.addParent( B ); A.addParent( B );
compUnit.addSymbol( A ); compUnit.addSymbol( A );
look = compUnit.Lookup( "A" ); look = compUnit.lookup( "A" );
assertEquals( look, A ); assertEquals( look, A );
ISymbol a = table.newSymbol( "a" ); ISymbol a = table.newSymbol( "a" );
a.setType( TypeInfo.t_type ); a.setType( TypeInfo.t_type );
@ -1358,12 +1358,12 @@ public class ParserSymbolTableTest extends TestCase {
compUnit.addSymbol( a ); compUnit.addSymbol( a );
LinkedList paramList = new LinkedList(); LinkedList paramList = new LinkedList();
look = compUnit.Lookup( "a" ); look = compUnit.lookup( "a" );
assertEquals( look, a ); assertEquals( look, a );
TypeInfo param = new 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 ); paramList.add( param );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f2 ); assertEquals( look, f2 );
} }
@ -1417,7 +1417,7 @@ public class ParserSymbolTableTest extends TestCase {
f3.addParameter( C, new PtrOp( PtrOp.t_pointer ), false ); f3.addParameter( C, new PtrOp( PtrOp.t_pointer ), false );
C.addSymbol( f3 ); C.addSymbol( f3 );
ISymbol look = compUnit.Lookup("C"); ISymbol look = compUnit.lookup("C");
assertEquals( look, C ); assertEquals( look, C );
ISymbol c = table.newSymbol("c"); ISymbol c = table.newSymbol("c");
@ -1426,7 +1426,7 @@ public class ParserSymbolTableTest extends TestCase {
c.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) ); c.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) );
compUnit.addSymbol( c ); compUnit.addSymbol( c );
look = compUnit.Lookup( "c" ); look = compUnit.lookup( "c" );
assertEquals( look, c ); assertEquals( look, c );
assertEquals( look.getTypeSymbol(), C ); assertEquals( look.getTypeSymbol(), C );
@ -1437,15 +1437,15 @@ public class ParserSymbolTableTest extends TestCase {
TypeInfo p3 = new TypeInfo( TypeInfo.t_type, 0, c ); TypeInfo p3 = new TypeInfo( TypeInfo.t_type, 0, c );
paramList.add( p1 ); paramList.add( p1 );
look = C.MemberFunctionLookup( "foo", paramList ); look = C.memberFunctionLookup( "foo", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
paramList.add( p2 ); paramList.add( p2 );
look = C.MemberFunctionLookup( "foo", paramList ); look = C.memberFunctionLookup( "foo", paramList );
assertEquals( look, f2 ); assertEquals( look, f2 );
paramList.add( p3 ); paramList.add( p3 );
look = C.MemberFunctionLookup( "foo", paramList ); look = C.memberFunctionLookup( "foo", paramList );
assertEquals( look, f3 ); assertEquals( look, f3 );
} }
@ -1480,22 +1480,22 @@ public class ParserSymbolTableTest extends TestCase {
TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null ); TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null );
paramList.add( p1 ); paramList.add( p1 );
ISymbol look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
paramList.clear(); paramList.clear();
TypeInfo p2 = new TypeInfo( TypeInfo.t_char, 0, null ); TypeInfo p2 = new TypeInfo( TypeInfo.t_char, 0, null );
paramList.add( p2 ); paramList.add( p2 );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f2 ); assertEquals( look, f2 );
paramList.clear(); paramList.clear();
TypeInfo p3 = new TypeInfo( TypeInfo.t_bool, 0, null ); TypeInfo p3 = new TypeInfo( TypeInfo.t_bool, 0, null );
paramList.add( p3 ); paramList.add( p3 );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
look = compUnit.UnqualifiedFunctionLookup( "f", null ); look = compUnit.unqualifiedFunctionLookup( "f", null );
assertEquals( look, f2 ); assertEquals( look, f2 );
} }
@ -1558,13 +1558,13 @@ public class ParserSymbolTableTest extends TestCase {
LinkedList paramList = new LinkedList(); LinkedList paramList = new LinkedList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, a ); TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, a );
paramList.add( p1 ); paramList.add( p1 );
ISymbol look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
paramList.clear(); paramList.clear();
TypeInfo p2 = new TypeInfo( TypeInfo.t_type, 0, c ); TypeInfo p2 = new TypeInfo( TypeInfo.t_type, 0, c );
paramList.add( p2 ); paramList.add( p2 );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f2 ); assertEquals( look, f2 );
} }
@ -1633,25 +1633,25 @@ public class ParserSymbolTableTest extends TestCase {
TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a ); TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a );
paramList.add( p ); paramList.add( p );
ISymbol look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f2 ); assertEquals( look, f2 );
p.addPtrOperator( new PtrOp( PtrOp.t_reference, false, false ) ); p.addPtrOperator( new PtrOp( PtrOp.t_reference, false, false ) );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
p.setTypeSymbol( b ); p.setTypeSymbol( b );
p.getPtrOperators().clear(); p.getPtrOperators().clear();
look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
p.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) ); p.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) );
look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f2 ); assertEquals( look, f2 );
p.setTypeSymbol( array ); p.setTypeSymbol( array );
p.getPtrOperators().clear(); p.getPtrOperators().clear();
look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
} }
@ -1685,11 +1685,10 @@ public class ParserSymbolTableTest extends TestCase {
B.setType( TypeInfo.t_class ); B.setType( TypeInfo.t_class );
compUnit.addSymbol( B ); compUnit.addSymbol( B );
//12.1-1 "Constructors do not have names" IParameterizedSymbol constructor = table.newParameterizedSymbol("B");
IParameterizedSymbol constructor = table.newParameterizedSymbol(""); constructor.setType( TypeInfo.t_constructor );
constructor.setType( TypeInfo.t_function );
constructor.addParameter( A, null, false ); constructor.addParameter( A, null, false );
B.addSymbol( constructor ); B.addConstructor( constructor );
IParameterizedSymbol f = table.newParameterizedSymbol( "f" ); IParameterizedSymbol f = table.newParameterizedSymbol( "f" );
f.setType( TypeInfo.t_function ); f.setType( TypeInfo.t_function );
@ -1705,7 +1704,7 @@ public class ParserSymbolTableTest extends TestCase {
TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a ); TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a );
paramList.add( p ); paramList.add( p );
ISymbol look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f ); assertEquals( look, f );
} }
@ -1770,7 +1769,7 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol look = null; ISymbol look = null;
try{ try{
look = main.UnqualifiedFunctionLookup( "f", params ); look = main.unqualifiedFunctionLookup( "f", params );
assertTrue( false ); assertTrue( false );
} catch ( ParserSymbolTableException e ){ } catch ( ParserSymbolTableException e ){
assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous );
@ -1780,21 +1779,21 @@ public class ParserSymbolTableTest extends TestCase {
TypeInfo p3 = new TypeInfo( TypeInfo.t_int, TypeInfo.isLong, null ); TypeInfo p3 = new TypeInfo( TypeInfo.t_int, TypeInfo.isLong, null );
params.add( p1 ); params.add( p1 );
params.add( p3 ); params.add( p3 );
look = main.UnqualifiedFunctionLookup( "f", params ); look = main.unqualifiedFunctionLookup( "f", params );
assertEquals( look, f2 ); assertEquals( look, f2 );
params.clear(); params.clear();
TypeInfo p4 = new TypeInfo( TypeInfo.t_char, 0, null ); TypeInfo p4 = new TypeInfo( TypeInfo.t_char, 0, null );
params.add( p1 ); params.add( p1 );
params.add( p4 ); params.add( p4 );
look = main.UnqualifiedFunctionLookup( "f", params ); look = main.unqualifiedFunctionLookup( "f", params );
assertEquals( look, f2 ); assertEquals( look, f2 );
params.clear(); params.clear();
((PtrOp)p1.getPtrOperators().getFirst()).setConst( true ); ((PtrOp)p1.getPtrOperators().getFirst()).setConst( true );
params.add( p1 ); params.add( p1 );
params.add( p3 ); params.add( p3 );
look = main.UnqualifiedFunctionLookup( "f", params ); look = main.unqualifiedFunctionLookup( "f", params );
assertEquals( look, f1 ); assertEquals( look, f1 );
} }
@ -1837,10 +1836,10 @@ public class ParserSymbolTableTest extends TestCase {
A.setType( TypeInfo.t_class ); A.setType( TypeInfo.t_class );
compUnit.addSymbol( A ); compUnit.addSymbol( A );
IParameterizedSymbol constructA = table.newParameterizedSymbol( "" ); IParameterizedSymbol constructA = table.newParameterizedSymbol( "A" );
constructA.setType( TypeInfo.t_function ); constructA.setType( TypeInfo.t_constructor );
constructA.addParameter( B, new PtrOp( PtrOp.t_reference ), false ); constructA.addParameter( B, new PtrOp( PtrOp.t_reference ), false );
A.addSymbol( constructA ); A.addConstructor( constructA );
IParameterizedSymbol operator = table.newParameterizedSymbol( "operator A" ); IParameterizedSymbol operator = table.newParameterizedSymbol( "operator A" );
operator.setType( TypeInfo.t_function ); operator.setType( TypeInfo.t_function );
@ -1862,7 +1861,7 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol look = null; ISymbol look = null;
try{ try{
look = compUnit.UnqualifiedFunctionLookup( "f", params ); look = compUnit.unqualifiedFunctionLookup( "f", params );
assertTrue( false ); assertTrue( false );
} catch( ParserSymbolTableException e ){ } catch( ParserSymbolTableException e ){
assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous );
@ -1872,10 +1871,10 @@ public class ParserSymbolTableTest extends TestCase {
C.setType( TypeInfo.t_class ); C.setType( TypeInfo.t_class );
compUnit.addSymbol( C ); compUnit.addSymbol( C );
IParameterizedSymbol constructC = table.newParameterizedSymbol(""); IParameterizedSymbol constructC = table.newParameterizedSymbol("C");
constructC.setType( TypeInfo.t_function ); constructC.setType( TypeInfo.t_constructor );
constructC.addParameter( B, new PtrOp( PtrOp.t_reference ), false ); constructC.addParameter( B, new PtrOp( PtrOp.t_reference ), false );
C.addSymbol( constructC ); C.addConstructor( constructC );
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" ); IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" );
f2.setType( TypeInfo.t_function ); f2.setType( TypeInfo.t_function );
@ -1883,7 +1882,7 @@ public class ParserSymbolTableTest extends TestCase {
compUnit.addSymbol( f2 ); compUnit.addSymbol( f2 );
try{ try{
look = compUnit.UnqualifiedFunctionLookup( "f", params ); look = compUnit.unqualifiedFunctionLookup( "f", params );
assertTrue( false ); assertTrue( false );
} catch( ParserSymbolTableException e ){ } catch( ParserSymbolTableException e ){
assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous );
@ -1894,7 +1893,7 @@ public class ParserSymbolTableTest extends TestCase {
f3.addParameter( B, null, false ); f3.addParameter( B, null, false );
compUnit.addSymbol( f3 ); compUnit.addSymbol( f3 );
look = compUnit.UnqualifiedFunctionLookup( "f", params ); look = compUnit.unqualifiedFunctionLookup( "f", params );
assertEquals( look, f3 ); assertEquals( look, f3 );
} }
@ -1910,12 +1909,12 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol f = table.newSymbol("f"); ISymbol f = table.newSymbol("f");
A.addSymbol( f ); A.addSymbol( f );
ISymbol look = A.Lookup("f"); ISymbol look = A.lookup("f");
assertEquals( look, f ); assertEquals( look, f );
assertTrue( table.rollBack( mark ) ); assertTrue( table.rollBack( mark ) );
look = A.Lookup("f"); look = A.lookup("f");
assertEquals( look, null ); assertEquals( look, null );
IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B"); IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B");
@ -1984,7 +1983,7 @@ public class ParserSymbolTableTest extends TestCase {
LinkedList args = new LinkedList(); LinkedList args = new LinkedList();
args.add( type ); args.add( type );
ParserSymbolTable.TemplateInstance instance = table.getCompilationUnit().TemplateLookup( "A", args ); ParserSymbolTable.TemplateInstance instance = table.getCompilationUnit().templateLookup( "A", args );
assertEquals( instance.getInstantiatedSymbol(), A ); assertEquals( instance.getInstantiatedSymbol(), A );
ISymbol a = table.newSymbol( "a", TypeInfo.t_type ); ISymbol a = table.newSymbol( "a", TypeInfo.t_type );
@ -1992,14 +1991,14 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( a ); table.getCompilationUnit().addSymbol( a );
ISymbol look = table.getCompilationUnit().Lookup( "a" ); ISymbol look = table.getCompilationUnit().lookup( "a" );
assertEquals( look, a ); assertEquals( look, a );
ISymbol symbol = a.getTypeSymbol(); ISymbol symbol = a.getTypeSymbol();
assertEquals( symbol, instance ); assertEquals( symbol, instance );
look = ((IContainerSymbol)instance.getInstantiatedSymbol()).Lookup( "i" ); look = ((IContainerSymbol)instance.getInstantiatedSymbol()).lookup( "i" );
assertEquals( look, i ); assertEquals( look, i );
} }
@ -2023,7 +2022,7 @@ public class ParserSymbolTableTest extends TestCase {
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", TypeInfo.t_class ); IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
ISymbol t = table.newSymbol( "t", TypeInfo.t_type ); ISymbol t = table.newSymbol( "t", TypeInfo.t_type );
ISymbol look = template.Lookup( "T" ); ISymbol look = template.lookup( "T" );
assertEquals( look, param ); assertEquals( look, param );
t.setTypeSymbol( param ); t.setTypeSymbol( param );
@ -2038,7 +2037,7 @@ public class ParserSymbolTableTest extends TestCase {
LinkedList args = new LinkedList(); LinkedList args = new LinkedList();
args.add( type ); args.add( type );
look = table.getCompilationUnit().TemplateLookup( "A", args ); look = table.getCompilationUnit().templateLookup( "A", args );
assertTrue( look instanceof ParserSymbolTable.TemplateInstance ); assertTrue( look instanceof ParserSymbolTable.TemplateInstance );
B.addParent( look ); B.addParent( look );
@ -2048,10 +2047,10 @@ public class ParserSymbolTableTest extends TestCase {
b.setTypeSymbol( B ); b.setTypeSymbol( B );
table.getCompilationUnit().addSymbol( b ); table.getCompilationUnit().addSymbol( b );
look = table.getCompilationUnit().Lookup( "b" ); look = table.getCompilationUnit().lookup( "b" );
assertEquals( look, b ); assertEquals( look, b );
look = ((IDerivableContainerSymbol) b.getTypeSymbol()).Lookup( "t" ); look = ((IDerivableContainerSymbol) b.getTypeSymbol()).lookup( "t" );
assertTrue( look instanceof TemplateInstance ); assertTrue( look instanceof TemplateInstance );
TemplateInstance instance = (TemplateInstance) look; TemplateInstance instance = (TemplateInstance) look;
@ -2084,7 +2083,7 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol paramT = table.newSymbol( "T", TypeInfo.t_undef ); ISymbol paramT = table.newSymbol( "T", TypeInfo.t_undef );
template.addParameter( paramT ); template.addParameter( paramT );
ISymbol look = template.Lookup( "T" ); ISymbol look = template.lookup( "T" );
assertEquals( look, paramT ); assertEquals( look, paramT );
ISymbol paramU = table.newSymbol( "U", TypeInfo.t_undef ); ISymbol paramU = table.newSymbol( "U", TypeInfo.t_undef );
paramU.getTypeInfo().setDefault( new TypeInfo( TypeInfo.t_type, 0, look ) ); paramU.getTypeInfo().setDefault( new TypeInfo( TypeInfo.t_type, 0, look ) );
@ -2093,13 +2092,13 @@ public class ParserSymbolTableTest extends TestCase {
IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X", TypeInfo.t_class ); IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X", TypeInfo.t_class );
template.addSymbol( X ); template.addSymbol( X );
look = X.Lookup( "T" ); look = X.lookup( "T" );
assertEquals( look, paramT ); assertEquals( look, paramT );
ISymbol t = table.newSymbol( "t", TypeInfo.t_type ); ISymbol t = table.newSymbol( "t", TypeInfo.t_type );
t.setTypeSymbol( look ); t.setTypeSymbol( look );
X.addSymbol( t ); X.addSymbol( t );
look = X.Lookup( "U" ); look = X.lookup( "U" );
assertEquals( look, paramU ); assertEquals( look, paramU );
ISymbol u = table.newSymbol( "u", TypeInfo.t_type ); ISymbol u = table.newSymbol( "u", TypeInfo.t_type );
u.setTypeSymbol( look ); u.setTypeSymbol( look );
@ -2110,16 +2109,16 @@ public class ParserSymbolTableTest extends TestCase {
TypeInfo type = new TypeInfo( TypeInfo.t_char, 0, null ); TypeInfo type = new TypeInfo( TypeInfo.t_char, 0, null );
LinkedList args = new LinkedList(); LinkedList args = new LinkedList();
args.add( type ); args.add( type );
look = table.getCompilationUnit().TemplateLookup( "X", args ); look = table.getCompilationUnit().templateLookup( "X", args );
assertTrue( look instanceof TemplateInstance ); assertTrue( look instanceof TemplateInstance );
TemplateInstance instance = (TemplateInstance) look; TemplateInstance instance = (TemplateInstance) look;
look = ((IDerivableContainerSymbol) instance.getInstantiatedSymbol()).Lookup( "t" ); look = ((IDerivableContainerSymbol) instance.getInstantiatedSymbol()).lookup( "t" );
assertTrue( look instanceof TemplateInstance ); assertTrue( look instanceof TemplateInstance );
assertTrue( ((TemplateInstance) look).isType( TypeInfo.t_char ) ); assertTrue( ((TemplateInstance) look).isType( TypeInfo.t_char ) );
look = ((IDerivableContainerSymbol) instance.getInstantiatedSymbol()).Lookup( "u" ); look = ((IDerivableContainerSymbol) instance.getInstantiatedSymbol()).lookup( "u" );
assertTrue( look instanceof TemplateInstance ); assertTrue( look instanceof TemplateInstance );
assertTrue( ((TemplateInstance) look).isType( TypeInfo.t_char ) ); assertTrue( ((TemplateInstance) look).isType( TypeInfo.t_char ) );
} }
@ -2158,7 +2157,7 @@ public class ParserSymbolTableTest extends TestCase {
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", TypeInfo.t_class ); IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", TypeInfo.t_class );
table.getCompilationUnit().addSymbol( B ); table.getCompilationUnit().addSymbol( B );
IParameterizedSymbol temp = (IParameterizedSymbol) table.getCompilationUnit().Lookup( "A" ); IParameterizedSymbol temp = (IParameterizedSymbol) table.getCompilationUnit().lookup( "A" );
assertEquals( temp, template ); assertEquals( temp, template );
LinkedList args = new LinkedList(); LinkedList args = new LinkedList();
@ -2184,7 +2183,7 @@ public class ParserSymbolTableTest extends TestCase {
LinkedList params = new LinkedList(); LinkedList params = new LinkedList();
params.add( new TypeInfo( TypeInfo.t_type, 0, a ) ); params.add( new TypeInfo( TypeInfo.t_type, 0, a ) );
ISymbol look = table.getCompilationUnit().UnqualifiedFunctionLookup( "f", params ); ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
assertEquals( look, f2 ); assertEquals( look, f2 );
} }
@ -2288,7 +2287,7 @@ public class ParserSymbolTableTest extends TestCase {
template5.addSymbol( cls5 ); template5.addSymbol( cls5 );
template1.addSpecialization( template5 ); template1.addSpecialization( template5 );
IParameterizedSymbol a = (IParameterizedSymbol) table.getCompilationUnit().Lookup( "A" ); IParameterizedSymbol a = (IParameterizedSymbol) table.getCompilationUnit().lookup( "A" );
LinkedList args = new LinkedList(); LinkedList args = new LinkedList();
@ -2352,8 +2351,8 @@ public class ParserSymbolTableTest extends TestCase {
/*...*/ /*...*/
ISymbol lookup = table.getCompilationUnit().Lookup( "A" ); ISymbol lookup = table.getCompilationUnit().lookup( "A" );
ISymbol otherLookup = table.getCompilationUnit().ElaboratedLookup( TypeInfo.t_class, "A" ); ISymbol otherLookup = table.getCompilationUnit().elaboratedLookup( TypeInfo.t_class, "A" );
assertEquals( lookup, otherLookup ); assertEquals( lookup, otherLookup );
assertEquals( lookup, forwardSymbol ); assertEquals( lookup, forwardSymbol );
@ -2366,21 +2365,21 @@ public class ParserSymbolTableTest extends TestCase {
/*...*/ /*...*/
lookup = table.getCompilationUnit().Lookup( "A" ); lookup = table.getCompilationUnit().lookup( "A" );
IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A", TypeInfo.t_class ); IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
assertTrue( lookup.isForwardDeclaration() ); assertTrue( lookup.isForwardDeclaration() );
lookup.setTypeSymbol( classA ); lookup.setTypeSymbol( classA );
table.getCompilationUnit().addSymbol( classA ); table.getCompilationUnit().addSymbol( classA );
lookup = table.getCompilationUnit().Lookup( "a" ); lookup = table.getCompilationUnit().lookup( "a" );
assertEquals( lookup, a ); assertEquals( lookup, a );
assertEquals( a.getTypeSymbol(), classA ); assertEquals( a.getTypeSymbol(), classA );
lookup = table.getCompilationUnit().Lookup( "A" ); lookup = table.getCompilationUnit().lookup( "A" );
assertEquals( lookup, classA ); assertEquals( lookup, classA );
lookup = table.getCompilationUnit().ElaboratedLookup( TypeInfo.t_class, "A" ); lookup = table.getCompilationUnit().elaboratedLookup( TypeInfo.t_class, "A" );
assertEquals( lookup, classA ); assertEquals( lookup, classA );
} }
@ -2418,7 +2417,7 @@ public class ParserSymbolTableTest extends TestCase {
IDerivableContainerSymbol classB = table.newDerivableContainerSymbol( "B", TypeInfo.t_class ); IDerivableContainerSymbol classB = table.newDerivableContainerSymbol( "B", TypeInfo.t_class );
IParameterizedSymbol fn1 = table.newParameterizedSymbol( "f", TypeInfo.t_function ); IParameterizedSymbol fn1 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
ISymbol lookup = table.getCompilationUnit().Lookup( "A" ); ISymbol lookup = table.getCompilationUnit().lookup( "A" );
assertEquals( lookup, forwardSymbol ); assertEquals( lookup, forwardSymbol );
fn1.addParameter( lookup, new PtrOp( PtrOp.t_pointer ), false ); fn1.addParameter( lookup, new PtrOp( PtrOp.t_pointer ), false );
fn1.getTypeInfo().setBit( true, TypeInfo.isStatic ); fn1.getTypeInfo().setBit( true, TypeInfo.isStatic );
@ -2434,7 +2433,7 @@ public class ParserSymbolTableTest extends TestCase {
/*...*/ /*...*/
ISymbol a1 = table.newSymbol( "a1", TypeInfo.t_type ); ISymbol a1 = table.newSymbol( "a1", TypeInfo.t_type );
lookup = table.getCompilationUnit().Lookup( "A" ); lookup = table.getCompilationUnit().lookup( "A" );
assertEquals( lookup, forwardSymbol ); assertEquals( lookup, forwardSymbol );
a1.setTypeSymbol( lookup ); a1.setTypeSymbol( lookup );
a1.addPtrOperator( new PtrOp( PtrOp.t_pointer ) ); a1.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
@ -2443,7 +2442,7 @@ public class ParserSymbolTableTest extends TestCase {
/*...*/ /*...*/
lookup = table.getCompilationUnit().Lookup( "A" ); lookup = table.getCompilationUnit().lookup( "A" );
IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A", TypeInfo.t_class ); IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
assertTrue( lookup.isForwardDeclaration() ); assertTrue( lookup.isForwardDeclaration() );
lookup.setTypeSymbol( classA ); lookup.setTypeSymbol( classA );
@ -2451,7 +2450,7 @@ public class ParserSymbolTableTest extends TestCase {
/*..*/ /*..*/
ISymbol a2 = table.newSymbol( "a2", TypeInfo.t_type ); ISymbol a2 = table.newSymbol( "a2", TypeInfo.t_type );
lookup = table.getCompilationUnit().Lookup( "A" ); lookup = table.getCompilationUnit().lookup( "A" );
assertEquals( lookup, classA ); assertEquals( lookup, classA );
a2.setTypeSymbol( lookup ); a2.setTypeSymbol( lookup );
a2.addPtrOperator( new PtrOp( PtrOp.t_pointer ) ); a2.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
@ -2463,14 +2462,45 @@ public class ParserSymbolTableTest extends TestCase {
LinkedList paramList = new LinkedList(); LinkedList paramList = new LinkedList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, a1 ); TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, a1 );
paramList.add( p1 ); paramList.add( p1 );
ISymbol look = classB.MemberFunctionLookup( "f", paramList ); ISymbol look = classB.memberFunctionLookup( "f", paramList );
assertEquals( look, fn1 ); assertEquals( look, fn1 );
paramList.clear(); paramList.clear();
p1 = new TypeInfo( TypeInfo.t_type, 0, a2 ); p1 = new TypeInfo( TypeInfo.t_type, 0, a2 );
paramList.add( p1 ); paramList.add( p1 );
look = classB.MemberFunctionLookup( "f", paramList ); look = classB.memberFunctionLookup( "f", paramList );
assertEquals( look, fn1 ); assertEquals( look, fn1 );
} }
public void testConstructors() throws Exception{
newTable();
IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
IParameterizedSymbol constructor1 = table.newParameterizedSymbol( "A", TypeInfo.t_constructor );
constructor1.addParameter( classA, new PtrOp( PtrOp.t_reference ), false );
IParameterizedSymbol constructor2 = table.newParameterizedSymbol( "A", TypeInfo.t_constructor );
constructor2.addParameter( TypeInfo.t_int, 0, null, false );
classA.addConstructor( constructor1 );
classA.addConstructor( constructor2 );
assertEquals( classA.getConstructors().size(), 2 );
IParameterizedSymbol cloned = (IParameterizedSymbol) constructor2.clone();
try{
classA.addConstructor( cloned );
} catch ( ParserSymbolTableException e ) {
assertEquals( e.reason, ParserSymbolTableException.r_InvalidOverload );
}
LinkedList paramList = new LinkedList();
paramList.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
ISymbol lookup = classA.lookupConstructor( paramList );
assertEquals( lookup, constructor2 );
}
} }

View file

@ -1,3 +1,13 @@
2003-08-05 Andrew Niefer
- Refactor symbol table functions to start with lower case letters
- Added better constructor support :
IDerivableContainerSymbol.addConstructor
IDerivableContainerSymbol.lookupConstructor
IDerivableContainerSymbol.getConstructors
- Changed ParserSymbolTableException.r_Unspecified to r_InternalError
- implicit user-defined conversion sequences now only use constructors not marked explicit
- user-defined conversion sequences are now only applied at most once (12.3-4 in spec)
2003-07-31 Andrew Niefer 2003-07-31 Andrew Niefer
Added better support to the parser symbol table for forward declarations Added better support to the parser symbol table for forward declarations

View file

@ -111,7 +111,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( t.getType() == IToken.tCOLONCOLON ) continue; if( t.getType() == IToken.tCOLONCOLON ) continue;
try try
{ {
symbol = symbol.LookupNestedNameSpecifier( t.getImage() ); symbol = symbol.lookupNestedNameSpecifier( t.getImage() );
references.add( createReference( symbol, t.getImage(), t.getOffset() )); references.add( createReference( symbol, t.getImage(), t.getOffset() ));
} }
catch( ParserSymbolTableException pste ) catch( ParserSymbolTableException pste )
@ -178,9 +178,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
try try
{ {
if( t != name.getLastToken() ) if( t != name.getLastToken() )
symbol = ((IContainerSymbol)symbol).LookupNestedNameSpecifier( t.getImage() ); symbol = ((IContainerSymbol)symbol).lookupNestedNameSpecifier( t.getImage() );
else else
symbol = ((IContainerSymbol)symbol).Lookup( t.getImage() ); symbol = ((IContainerSymbol)symbol).lookup( t.getImage() );
} }
catch (ParserSymbolTableException e) catch (ParserSymbolTableException e)
{ {
@ -229,7 +229,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ISymbol namespaceSymbol = null; ISymbol namespaceSymbol = null;
try try
{ {
namespaceSymbol = pstScope.Lookup( identifier ); namespaceSymbol = pstScope.lookup( identifier );
} }
catch (ParserSymbolTableException e) catch (ParserSymbolTableException e)
{ {
@ -396,9 +396,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
try try
{ {
if( t == parentClassName.getLastToken()) if( t == parentClassName.getLastToken())
symbol = (IContainerSymbol)symbol.Lookup( t.getImage() ); symbol = (IContainerSymbol)symbol.lookup( t.getImage() );
else else
symbol = symbol.LookupNestedNameSpecifier( t.getImage() ); symbol = symbol.lookupNestedNameSpecifier( t.getImage() );
references.add( createReference( symbol, t.getImage(), t.getOffset() )); references.add( createReference( symbol, t.getImage(), t.getOffset() ));
} }
catch( ParserSymbolTableException pste ) catch( ParserSymbolTableException pste )
@ -672,9 +672,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
try try
{ {
if( current != typeName.getLastToken() ) if( current != typeName.getLastToken() )
typeSymbol = ((IContainerSymbol)typeSymbol).LookupNestedNameSpecifier( current.getImage()); typeSymbol = ((IContainerSymbol)typeSymbol).lookupNestedNameSpecifier( current.getImage());
else else
typeSymbol = ((IContainerSymbol)typeSymbol).Lookup( current.getImage()); typeSymbol = ((IContainerSymbol)typeSymbol).lookup( current.getImage());
references.add( createReference( typeSymbol, current.getImage(), current.getOffset() )); references.add( createReference( typeSymbol, current.getImage(), current.getOffset() ));
} }

View file

@ -41,14 +41,14 @@ public interface IContainerSymbol extends ISymbol {
public Map getContainedSymbols(); public Map getContainedSymbols();
public ISymbol ElaboratedLookup( TypeInfo.eType type, String name ) throws ParserSymbolTableException; public ISymbol elaboratedLookup( TypeInfo.eType type, String name ) throws ParserSymbolTableException;
public ISymbol Lookup( String name ) throws ParserSymbolTableException; public ISymbol lookup( String name ) throws ParserSymbolTableException;
public ISymbol LookupMemberForDefinition( String name ) throws ParserSymbolTableException; public ISymbol lookupMemberForDefinition( String name ) throws ParserSymbolTableException;
public IContainerSymbol LookupNestedNameSpecifier( String name ) throws ParserSymbolTableException; public IContainerSymbol lookupNestedNameSpecifier( String name ) throws ParserSymbolTableException;
public ISymbol QualifiedLookup( String name ) throws ParserSymbolTableException; public ISymbol qualifiedLookup( String name ) throws ParserSymbolTableException;
public IParameterizedSymbol UnqualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException; public IParameterizedSymbol unqualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException;
public IParameterizedSymbol MemberFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException; public IParameterizedSymbol memberFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException;
public IParameterizedSymbol qualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException;
public TemplateInstance TemplateLookup( String name, LinkedList arguments ) throws ParserSymbolTableException; public TemplateInstance templateLookup( String name, LinkedList arguments ) throws ParserSymbolTableException;
public TemplateInstance instantiate( LinkedList arguments ) throws ParserSymbolTableException; public TemplateInstance instantiate( LinkedList arguments ) throws ParserSymbolTableException;
} }

View file

@ -16,6 +16,7 @@
*/ */
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
@ -33,6 +34,10 @@ public interface IDerivableContainerSymbol extends IContainerSymbol {
public List getParents(); public List getParents();
public boolean hasParents(); public boolean hasParents();
public void addConstructor( IParameterizedSymbol constructor ) throws ParserSymbolTableException;
public IParameterizedSymbol lookupConstructor( LinkedList parameters ) throws ParserSymbolTableException;
public LinkedList getConstructors();
public interface IParentSymbol{ public interface IParentSymbol{
public void setParent( ISymbol parent ); public void setParent( ISymbol parent );
public ISymbol getParent(); public ISymbol getParent();

View file

@ -82,7 +82,7 @@ public class ParserSymbolTable {
* @return Declaration * @return Declaration
* @throws ParserSymbolTableException * @throws ParserSymbolTableException
*/ */
static private void Lookup( LookupData data, IContainerSymbol inSymbol ) throws ParserSymbolTableException static private void lookup( LookupData data, IContainerSymbol inSymbol ) throws ParserSymbolTableException
{ {
if( data.type != TypeInfo.t_any && data.type.compareTo(TypeInfo.t_class) < 0 && data.upperType.compareTo(TypeInfo.t_union) > 0 ){ if( data.type != TypeInfo.t_any && data.type.compareTo(TypeInfo.t_class) < 0 && data.upperType.compareTo(TypeInfo.t_union) > 0 ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
@ -92,7 +92,7 @@ public class ParserSymbolTable {
LinkedList transitives = new LinkedList(); //list of transitive using directives LinkedList transitives = new LinkedList(); //list of transitive using directives
//if this name define in this scope? //if this name define in this scope?
LookupInContained( data, inSymbol ); lookupInContained( data, inSymbol );
if( !data.ignoreUsingDirectives ){ if( !data.ignoreUsingDirectives ){
//check nominated namespaces //check nominated namespaces
@ -101,24 +101,24 @@ public class ParserSymbolTable {
data.visited.clear(); //each namesapce is searched at most once, so keep track data.visited.clear(); //each namesapce is searched at most once, so keep track
LookupInNominated( data, inSymbol, transitives ); lookupInNominated( data, inSymbol, transitives );
//if we are doing a qualified lookup, only process using directives if //if we are doing a qualified lookup, only process using directives if
//we haven't found the name yet (and if we aren't ignoring them). //we haven't found the name yet (and if we aren't ignoring them).
if( !data.qualified || data.foundItems == null ){ if( !data.qualified || data.foundItems == null ){
ProcessDirectives( inSymbol, data, transitives ); processDirectives( inSymbol, data, transitives );
if( inSymbol.hasUsingDirectives() ){ if( inSymbol.hasUsingDirectives() ){
ProcessDirectives( inSymbol, data, inSymbol.getUsingDirectives() ); processDirectives( inSymbol, data, inSymbol.getUsingDirectives() );
} }
while( data.usingDirectives != null && data.usingDirectives.get( inSymbol ) != null ){ while( data.usingDirectives != null && data.usingDirectives.get( inSymbol ) != null ){
transitives.clear(); transitives.clear();
LookupInNominated( data, inSymbol, transitives ); lookupInNominated( data, inSymbol, transitives );
if( !data.qualified || data.foundItems == null ){ if( !data.qualified || data.foundItems == null ){
ProcessDirectives( inSymbol, data, transitives ); processDirectives( inSymbol, data, transitives );
} }
} }
} }
@ -131,7 +131,7 @@ public class ParserSymbolTable {
if( inSymbol instanceof IDerivableContainerSymbol ){ if( inSymbol instanceof IDerivableContainerSymbol ){
//if we still havn't found it, check any parents we have //if we still havn't found it, check any parents we have
data.visited.clear(); //each virtual base class is searched at most once data.visited.clear(); //each virtual base class is searched at most once
symbol = LookupInParents( data, (IDerivableContainerSymbol)inSymbol ); symbol = lookupInParents( data, (IDerivableContainerSymbol)inSymbol );
//there is a resolveAmbiguities inside LookupInParents, which means if we found //there is a resolveAmbiguities inside LookupInParents, which means if we found
//something the foundItems set will be non-null, but empty. So, add the decl into //something the foundItems set will be non-null, but empty. So, add the decl into
@ -143,7 +143,7 @@ public class ParserSymbolTable {
//if still not found, check our containing scope. //if still not found, check our containing scope.
if( data.foundItems == null && inSymbol.getContainingSymbol() != null ){ if( data.foundItems == null && inSymbol.getContainingSymbol() != null ){
Lookup( data, inSymbol.getContainingSymbol() ); lookup( data, inSymbol.getContainingSymbol() );
} }
return; return;
@ -168,7 +168,7 @@ public class ParserSymbolTable {
* directives, the effect is as if the using-directives from the second * directives, the effect is as if the using-directives from the second
* namespace also appeared in the first. * namespace also appeared in the first.
*/ */
static private void LookupInNominated( LookupData data, IContainerSymbol symbol, LinkedList transitiveDirectives ){ static private void lookupInNominated( LookupData data, IContainerSymbol symbol, LinkedList transitiveDirectives ){
//if the data.usingDirectives is empty, there is nothing to do. //if the data.usingDirectives is empty, there is nothing to do.
if( data.usingDirectives == null ){ if( data.usingDirectives == null ){
return; return;
@ -197,7 +197,7 @@ public class ParserSymbolTable {
if( !data.visited.contains( temp ) ){ if( !data.visited.contains( temp ) ){
data.visited.add( temp ); data.visited.add( temp );
foundSomething = LookupInContained( data, temp ); foundSomething = lookupInContained( data, temp );
//only consider the transitive using directives if we are an unqualified //only consider the transitive using directives if we are an unqualified
//lookup, or we didn't find the name in decl //lookup, or we didn't find the name in decl
@ -218,7 +218,7 @@ public class ParserSymbolTable {
* *
* Look for data.name in our collection _containedDeclarations * Look for data.name in our collection _containedDeclarations
*/ */
private static boolean LookupInContained( LookupData data, IContainerSymbol lookIn ){ private static boolean lookupInContained( LookupData data, IContainerSymbol lookIn ){
boolean foundSomething = false; boolean foundSomething = false;
ISymbol temp = null; ISymbol temp = null;
@ -323,14 +323,14 @@ public class ParserSymbolTable {
* @return Declaration * @return Declaration
* @throws ParserSymbolTableException * @throws ParserSymbolTableException
*/ */
private static ISymbol LookupInParents( LookupData data, ISymbol lookIn ) throws ParserSymbolTableException{ private static ISymbol lookupInParents( LookupData data, ISymbol lookIn ) throws ParserSymbolTableException{
IDerivableContainerSymbol container = null; IDerivableContainerSymbol container = null;
if( lookIn instanceof TemplateInstance ){ if( lookIn instanceof TemplateInstance ){
} else if( lookIn instanceof IDerivableContainerSymbol ){ } else if( lookIn instanceof IDerivableContainerSymbol ){
container = (IDerivableContainerSymbol) lookIn; container = (IDerivableContainerSymbol) lookIn;
} else{ } else{
throw new ParserSymbolTableException(); throw new ParserSymbolTableException( ParserSymbolTableException.r_InternalError );
} }
List scopes = container.getParents(); List scopes = container.getParents();
@ -380,18 +380,18 @@ public class ParserSymbolTable {
data.templateInstance = (TemplateInstance) parent; data.templateInstance = (TemplateInstance) parent;
ISymbol instance = ((TemplateInstance)parent).getInstantiatedSymbol(); ISymbol instance = ((TemplateInstance)parent).getInstantiatedSymbol();
if( instance instanceof IContainerSymbol ) if( instance instanceof IContainerSymbol )
LookupInContained( data, (IContainerSymbol)instance ); lookupInContained( data, (IContainerSymbol)instance );
else else
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
data.templateInstance = tempInstance; data.templateInstance = tempInstance;
} else if( parent instanceof IDerivableContainerSymbol ){ } else if( parent instanceof IDerivableContainerSymbol ){
LookupInContained( data, (IDerivableContainerSymbol) parent ); lookupInContained( data, (IDerivableContainerSymbol) parent );
} else { } else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
} }
temp = ResolveAmbiguities( data ); temp = resolveAmbiguities( data );
if( temp == null ){ if( temp == null ){
temp = LookupInParents( data, parent ); temp = lookupInParents( data, parent );
} }
} else { } else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_CircularInheritance ); throw new ParserSymbolTableException( ParserSymbolTableException.r_CircularInheritance );
@ -491,7 +491,8 @@ public class ParserSymbolTable {
} }
private static boolean isValidFunctionOverload( IParameterizedSymbol origSymbol, IParameterizedSymbol newSymbol ){ private static boolean isValidFunctionOverload( IParameterizedSymbol origSymbol, IParameterizedSymbol newSymbol ){
if( origSymbol.getType() != TypeInfo.t_function || newSymbol.getType() != TypeInfo.t_function ){ if( ( !origSymbol.isType( TypeInfo.t_function ) && !origSymbol.isType( TypeInfo.t_constructor ) ) ||
( ! newSymbol.isType( TypeInfo.t_function ) && ! newSymbol.isType( TypeInfo.t_constructor ) ) ){
return false; return false;
} }
@ -533,7 +534,7 @@ public class ParserSymbolTable {
* all, when looking for functions with no parameters, an empty list must be * all, when looking for functions with no parameters, an empty list must be
* provided in data.parameters. * provided in data.parameters.
*/ */
static private ISymbol ResolveAmbiguities( LookupData data ) throws ParserSymbolTableException{ static private ISymbol resolveAmbiguities( LookupData data ) throws ParserSymbolTableException{
ISymbol decl = null; ISymbol decl = null;
ISymbol obj = null; ISymbol obj = null;
IContainerSymbol cls = null; IContainerSymbol cls = null;
@ -643,7 +644,7 @@ public class ParserSymbolTable {
return null; return null;
} }
} else { } else {
return ResolveFunction( data, functionList ); return resolveFunction( data, functionList );
} }
} }
@ -654,9 +655,12 @@ public class ParserSymbolTable {
} }
} }
static private IParameterizedSymbol ResolveFunction( LookupData data, LinkedList functions ) throws ParserSymbolTableException{ static private IParameterizedSymbol resolveFunction( LookupData data, LinkedList functions ) throws ParserSymbolTableException{
if( functions == null ){
return null;
}
ReduceToViable( data, functions ); reduceToViable( data, functions );
int numSourceParams = ( data.parameters == null ) ? 0 : data.parameters.size(); int numSourceParams = ( data.parameters == null ) ? 0 : data.parameters.size();
int numFns = functions.size(); int numFns = functions.size();
@ -726,7 +730,9 @@ public class ParserSymbolTable {
} else { } else {
cost = checkStandardConversionSequence( source, target ); cost = checkStandardConversionSequence( source, target );
if( cost.rank == -1){ //12.3-4 At most one user-defined conversion is implicitly applied to
//a single value. (also prevents infinite loop)
if( cost.rank == -1 && !data.forUserDefinedConversion ){
temp = checkUserDefinedConversionSequence( source, target ); temp = checkUserDefinedConversionSequence( source, target );
if( temp != null ){ if( temp != null ){
cost = temp; cost = temp;
@ -779,7 +785,7 @@ public class ParserSymbolTable {
return bestFn; return bestFn;
} }
static private void ReduceToViable( LookupData data, LinkedList functions ){ static private void reduceToViable( LookupData data, LinkedList functions ){
int numParameters = ( data.parameters == null ) ? 0 : data.parameters.size(); int numParameters = ( data.parameters == null ) ? 0 : data.parameters.size();
int num; int num;
@ -829,7 +835,7 @@ public class ParserSymbolTable {
* nominated namespace to the lookup data for consideration when we reach * nominated namespace to the lookup data for consideration when we reach
* the enclosing declaration. * the enclosing declaration.
*/ */
static private void ProcessDirectives( IContainerSymbol symbol, LookupData data, List directives ){ static private void processDirectives( IContainerSymbol symbol, LookupData data, List directives ){
IContainerSymbol enclosing = null; IContainerSymbol enclosing = null;
IContainerSymbol temp = null; IContainerSymbol temp = null;
@ -1341,19 +1347,25 @@ public class ParserSymbolTable {
if( target.getType() == TypeInfo.t_type ){ if( target.getType() == TypeInfo.t_type ){
targetDecl = target.getTypeSymbol(); targetDecl = target.getTypeSymbol();
if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){ if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
LookupData data = new LookupData( "", TypeInfo.t_function, null ); LookupData data = new LookupData( "", TypeInfo.t_constructor, null );
LinkedList params = new LinkedList(); data.parameters = new LinkedList();
params.add( source ); data.parameters.add( source );
data.parameters = params; data.forUserDefinedConversion = true;
IDerivableContainerSymbol container = (IDerivableContainerSymbol) targetDecl;
if( targetDecl instanceof TemplateInstance ){ if( targetDecl instanceof TemplateInstance ){
data.templateInstance = targetDecl; data.templateInstance = targetDecl;
TemplateInstance instance = (TemplateInstance) targetDecl; container = (IDerivableContainerSymbol)((TemplateInstance) targetDecl).getInstantiatedSymbol();
LookupInContained( data, (IContainerSymbol) instance.getInstantiatedSymbol() ); }
} else {
LookupInContained( data, (IContainerSymbol) targetDecl ); if( container.getConstructors() != null ){
constructor = resolveFunction( data, container.getConstructors() );
}
if( constructor != null && constructor.getTypeInfo().checkBit( TypeInfo.isExplicit ) ){
constructor = null;
} }
constructor = (IParameterizedSymbol)ResolveAmbiguities( data );
} }
} }
@ -1369,9 +1381,10 @@ public class ParserSymbolTable {
LookupData data = new LookupData( "operator " + name, TypeInfo.t_function, null ); LookupData data = new LookupData( "operator " + name, TypeInfo.t_function, null );
LinkedList params = new LinkedList(); LinkedList params = new LinkedList();
data.parameters = params; data.parameters = params;
data.forUserDefinedConversion = true;
LookupInContained( data, (IContainerSymbol) sourceDecl ); lookupInContained( data, (IContainerSymbol) sourceDecl );
conversion = (IParameterizedSymbol)ResolveAmbiguities( data ); conversion = (IParameterizedSymbol)resolveAmbiguities( data );
} }
} }
} }
@ -1856,8 +1869,8 @@ public class ParserSymbolTable {
} else if( obj instanceof BasicSymbol ){ } else if( obj instanceof BasicSymbol ){
_context.getContainedSymbols().remove( _decl.getName() ); _context.getContainedSymbols().remove( _decl.getName() );
} }
if( _removeThis ){ if( _removeThis && _decl instanceof IParameterizedSymbol ){
_context.getContainedSymbols().remove( "this" ); ((IParameterizedSymbol)_decl).getContainedSymbols().remove( "this" );
} }
} }
@ -1866,6 +1879,36 @@ public class ParserSymbolTable {
private boolean _removeThis; private boolean _removeThis;
} }
static private class AddConstructorCommand extends Command{
AddConstructorCommand( Declaration newConstr, Declaration context, boolean removeThis ){
_constructor = newConstr;
_context = context;
_removeThis = removeThis;
}
public void undoIt(){
LinkedList constructors = _context.getConstructors();
ListIterator iter = constructors.listIterator();
int size = constructors.size();
Declaration item = null;
for( int i = 0; i < size; i++ ){
item = (Declaration)iter.next();
if( item == _constructor ){
iter.remove();
break;
}
}
if( _removeThis ){
_constructor.getContainedSymbols().remove( "this" );
}
}
private Declaration _constructor;
private Declaration _context;
private boolean _removeThis;
}
static private class AddParentCommand extends Command{ static private class AddParentCommand extends Command{
public AddParentCommand( Declaration container, Declaration.ParentWrapper wrapper ){ public AddParentCommand( Declaration container, Declaration.ParentWrapper wrapper ){
_decl = container; _decl = container;
@ -1943,6 +1986,7 @@ public class ParserSymbolTable {
public TypeInfo.eType upperType = TypeInfo.t_undef; public TypeInfo.eType upperType = TypeInfo.t_undef;
public boolean qualified = false; public boolean qualified = false;
public boolean ignoreUsingDirectives = false; public boolean ignoreUsingDirectives = false;
public boolean forUserDefinedConversion = false;
public HashSet foundItems = null; public HashSet foundItems = null;
@ -2413,6 +2457,16 @@ public class ParserSymbolTable {
return _containedDeclarations; return _containedDeclarations;
} }
public LinkedList getConstructors(){
return _constructors;
}
public LinkedList createConstructors(){
if( _constructors == null )
_constructors = new LinkedList();
return _constructors;
}
public boolean hasParents(){ public boolean hasParents(){
return ( _parentScopes != null && !_parentScopes.isEmpty() ); return ( _parentScopes != null && !_parentScopes.isEmpty() );
} }
@ -2594,7 +2648,7 @@ public class ParserSymbolTable {
} else if( origObj.getClass() == LinkedList.class ){ } else if( origObj.getClass() == LinkedList.class ){
origList = (LinkedList)origObj; origList = (LinkedList)origObj;
} else { } else {
throw new ParserSymbolTableException(); throw new ParserSymbolTableException( ParserSymbolTableException.r_InternalError );
} }
boolean validOverride = ((origList == null) ? isValidOverload( origDecl, obj ) : isValidOverload( origList, obj ) ); boolean validOverride = ((origList == null) ? isValidOverload( origDecl, obj ) : isValidOverload( origList, obj ) );
@ -2605,7 +2659,7 @@ public class ParserSymbolTable {
origList.add( origDecl ); origList.add( origDecl );
origList.add( obj ); origList.add( obj );
declarations.remove( obj ); declarations.remove( origDecl );
declarations.put( obj.getName(), origList ); declarations.put( obj.getName(), origList );
} else { } else {
origList.add( obj ); origList.add( obj );
@ -2624,14 +2678,37 @@ public class ParserSymbolTable {
TypeInfo type = obj.getTypeInfo(); TypeInfo type = obj.getTypeInfo();
boolean addedThis = false; boolean addedThis = false;
if( type.isType( TypeInfo.t_function ) && !type.checkBit( TypeInfo.isStatic ) ){ if( type.isType( TypeInfo.t_function ) && !type.checkBit( TypeInfo.isStatic ) ){
addThis( (Declaration) obj ); addedThis = addThis( (Declaration) obj );
addedThis = true;
} }
Command command = new AddDeclarationCommand( (BasicSymbol) obj, containing, addedThis ); Command command = new AddDeclarationCommand( (BasicSymbol) obj, containing, addedThis );
pushCommand( command ); pushCommand( command );
} }
public void addConstructor(IParameterizedSymbol constructor) throws ParserSymbolTableException {
if( !constructor.isType( TypeInfo.t_constructor ) )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
Object origObj = null;
LinkedList constructors = getConstructors();
if( constructors == null )
constructors = createConstructors();
if( constructors.size() == 0 || isValidOverload( constructors, constructor ) ){
constructors.add( constructor );
} else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload );
}
constructor.setContainingSymbol( this );
boolean addedThis = addThis( (Declaration) constructor );
Command command = new AddConstructorCommand( (Declaration)constructor, this, addedThis );
pushCommand( command );
}
/** /**
* *
* @param obj * @param obj
@ -2641,17 +2718,18 @@ public class ParserSymbolTable {
* this is const X*, if the member function is declared volatile, the type * this is const X*, if the member function is declared volatile, the type
* of this is volatile X*.... * of this is volatile X*....
*/ */
private void addThis( Declaration obj ){ private boolean addThis( Declaration obj ){
TypeInfo type = obj.getTypeInfo(); TypeInfo type = obj.getTypeInfo();
if( !type.isType( TypeInfo.t_function ) || type.checkBit( TypeInfo.isStatic ) ){ if( ( !type.isType( TypeInfo.t_function ) && !type.isType( TypeInfo.t_constructor) ) ||
return; type.checkBit( TypeInfo.isStatic ) ){
return false;
} }
if( obj.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) ){ if( obj.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) ){
//check to see if there is already a this object, since using declarations //check to see if there is already a this object, since using declarations
//of function will have them from the original declaration //of function will have them from the original declaration
LookupData data = new LookupData( "this", TypeInfo.t_any, null ); LookupData data = new LookupData( "this", TypeInfo.t_any, null );
LookupInContained( data, obj ); lookupInContained( data, obj );
//if we didn't find "this" then foundItems will still be null, no need to actually //if we didn't find "this" then foundItems will still be null, no need to actually
//check its contents //check its contents
if( data.foundItems == null ){ if( data.foundItems == null ){
@ -2671,11 +2749,13 @@ public class ParserSymbolTable {
try{ try{
obj.addSymbol( thisObj ); obj.addSymbol( thisObj );
} catch ( ParserSymbolTableException e ) { } catch ( ParserSymbolTableException e ) {
//won't happen because we checked that "this" didn't exist already //shouldn't happen because we checked that "this" didn't exist already
return false;
} }
} }
} }
return true;
} }
/** /**
@ -2692,7 +2772,7 @@ public class ParserSymbolTable {
* (public/protected/private) we will need to do more to record friendship. * (public/protected/private) we will need to do more to record friendship.
*/ */
public Declaration addFriend( String name ) throws ParserSymbolTableException{ public Declaration addFriend( String name ) throws ParserSymbolTableException{
Declaration friend = LookupForFriendship( name ); Declaration friend = lookupForFriendship( name );
if( friend == null ){ if( friend == null ){
friend = new Declaration( name ); friend = new Declaration( name );
@ -2723,7 +2803,7 @@ public class ParserSymbolTable {
* without considering scopes that are outside the innermost enclosing non- * without considering scopes that are outside the innermost enclosing non-
* class scope. * class scope.
*/ */
private Declaration LookupForFriendship( String name ) throws ParserSymbolTableException{ private Declaration lookupForFriendship( String name ) throws ParserSymbolTableException{
LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() );
boolean inClass = ( getType() == TypeInfo.t_class); boolean inClass = ( getType() == TypeInfo.t_class);
@ -2737,8 +2817,8 @@ public class ParserSymbolTable {
data.stopAt = enclosing; data.stopAt = enclosing;
ParserSymbolTable.Lookup( data, this ); ParserSymbolTable.lookup( data, this );
return (Declaration)ParserSymbolTable.ResolveAmbiguities( data ); return (Declaration)ParserSymbolTable.resolveAmbiguities( data );
} }
/** /**
@ -2767,17 +2847,17 @@ public class ParserSymbolTable {
if( declContext != null ){ if( declContext != null ){
data.qualified = true; data.qualified = true;
data.templateInstance = declContext.getTemplateInstance(); data.templateInstance = declContext.getTemplateInstance();
ParserSymbolTable.Lookup( data, declContext ); ParserSymbolTable.lookup( data, declContext );
} else { } else {
ParserSymbolTable.Lookup( data, this ); ParserSymbolTable.lookup( data, this );
} }
//figure out which declaration we are talking about, if it is a set of functions, //figure out which declaration we are talking about, if it is a set of functions,
//then they will be in data.foundItems (since we provided no parameter info); //then they will be in data.foundItems (since we provided no parameter info);
BasicSymbol obj = (BasicSymbol)ParserSymbolTable.ResolveAmbiguities( data ); BasicSymbol obj = (BasicSymbol)ParserSymbolTable.resolveAmbiguities( data );
if( data.foundItems == null ){ if( data.foundItems == null ){
throw new ParserSymbolTableException(); throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing );
} }
BasicSymbol clone = null; BasicSymbol clone = null;
@ -2793,7 +2873,7 @@ public class ParserSymbolTable {
clone = (BasicSymbol) obj.clone(); //7.3.3-9 clone = (BasicSymbol) obj.clone(); //7.3.3-9
addSymbol( clone ); addSymbol( clone );
} else { } else {
throw new ParserSymbolTableException(); throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing );
} }
} }
@ -2802,7 +2882,7 @@ public class ParserSymbolTable {
public void addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException{ public void addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException{
if( namespace.getType() != TypeInfo.t_namespace ){ if( namespace.getType() != TypeInfo.t_namespace ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing );
} }
if( _usingDirectives == null ){ if( _usingDirectives == null ){
@ -2823,20 +2903,20 @@ public class ParserSymbolTable {
return _usingDirectives; return _usingDirectives;
} }
public ISymbol ElaboratedLookup( TypeInfo.eType type, String name ) throws ParserSymbolTableException{ public ISymbol elaboratedLookup( TypeInfo.eType type, String name ) throws ParserSymbolTableException{
LookupData data = new LookupData( name, type, getTemplateInstance() ); LookupData data = new LookupData( name, type, getTemplateInstance() );
ParserSymbolTable.Lookup( data, this ); ParserSymbolTable.lookup( data, this );
return ParserSymbolTable.ResolveAmbiguities( data ); return ParserSymbolTable.resolveAmbiguities( data );
} }
public ISymbol Lookup( String name ) throws ParserSymbolTableException { public ISymbol lookup( String name ) throws ParserSymbolTableException {
LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() );
ParserSymbolTable.Lookup( data, this ); ParserSymbolTable.lookup( data, this );
return ParserSymbolTable.ResolveAmbiguities( data ); return ParserSymbolTable.resolveAmbiguities( data );
} }
/** /**
@ -2867,13 +2947,13 @@ public class ParserSymbolTable {
* ie, We need a seperate lookup function for looking up the member names * ie, We need a seperate lookup function for looking up the member names
* for a definition. * for a definition.
*/ */
public ISymbol LookupMemberForDefinition( String name ) throws ParserSymbolTableException{ public ISymbol lookupMemberForDefinition( String name ) throws ParserSymbolTableException{
LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() );
data.qualified = true; data.qualified = true;
ParserSymbolTable.LookupInContained( data, this ); ParserSymbolTable.lookupInContained( data, this );
return ParserSymbolTable.ResolveAmbiguities( data ); return ParserSymbolTable.resolveAmbiguities( data );
} }
/** /**
@ -2886,23 +2966,23 @@ public class ParserSymbolTable {
* the ::, object, function and enumerator names are ignored. If the name * the ::, object, function and enumerator names are ignored. If the name
* is not a class-name or namespace-name, the program is ill-formed * is not a class-name or namespace-name, the program is ill-formed
*/ */
public IContainerSymbol LookupNestedNameSpecifier( String name ) throws ParserSymbolTableException { public IContainerSymbol lookupNestedNameSpecifier( String name ) throws ParserSymbolTableException {
return LookupNestedNameSpecifier( name, this ); return lookupNestedNameSpecifier( name, this );
} }
private Declaration LookupNestedNameSpecifier(String name, Declaration inDeclaration ) throws ParserSymbolTableException{ private Declaration lookupNestedNameSpecifier(String name, Declaration inDeclaration ) throws ParserSymbolTableException{
Declaration foundDeclaration = null; Declaration foundDeclaration = null;
LookupData data = new LookupData( name, TypeInfo.t_namespace, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_namespace, getTemplateInstance() );
data.upperType = TypeInfo.t_union; data.upperType = TypeInfo.t_union;
ParserSymbolTable.LookupInContained( data, inDeclaration ); ParserSymbolTable.lookupInContained( data, inDeclaration );
if( data.foundItems != null ){ if( data.foundItems != null ){
foundDeclaration = (Declaration) ParserSymbolTable.ResolveAmbiguities( data );//, data.foundItems ); foundDeclaration = (Declaration) ParserSymbolTable.resolveAmbiguities( data );//, data.foundItems );
} }
if( foundDeclaration == null && inDeclaration.getContainingSymbol() != null ){ if( foundDeclaration == null && inDeclaration.getContainingSymbol() != null ){
foundDeclaration = LookupNestedNameSpecifier( name, (Declaration)inDeclaration.getContainingSymbol() ); foundDeclaration = lookupNestedNameSpecifier( name, (Declaration)inDeclaration.getContainingSymbol() );
} }
return foundDeclaration; return foundDeclaration;
@ -2918,49 +2998,57 @@ public class ParserSymbolTable {
* Member lookup really proceeds as an unqualified lookup, but doesn't * Member lookup really proceeds as an unqualified lookup, but doesn't
* include argument dependant scopes * include argument dependant scopes
*/ */
public IParameterizedSymbol MemberFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol memberFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name, TypeInfo.t_function, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_function, getTemplateInstance() );
//if parameters == null, thats no parameters, but we need to distinguish that from //if parameters == null, thats no parameters, but we need to distinguish that from
//no parameter information at all, so make an empty list. //no parameter information at all, so make an empty list.
data.parameters = ( parameters == null ) ? new LinkedList() : parameters; data.parameters = ( parameters == null ) ? new LinkedList() : parameters;
ParserSymbolTable.Lookup( data, (IContainerSymbol) this ); ParserSymbolTable.lookup( data, (IContainerSymbol) this );
return (IParameterizedSymbol) ParserSymbolTable.ResolveAmbiguities( data ); return (IParameterizedSymbol) ParserSymbolTable.resolveAmbiguities( data );
} }
public IParameterizedSymbol QualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol qualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name, TypeInfo.t_function, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_function, getTemplateInstance() );
data.qualified = true; data.qualified = true;
//if parameters == null, thats no parameters, but we need to distinguish that from //if parameters == null, thats no parameters, but we need to distinguish that from
//no parameter information at all, so make an empty list. //no parameter information at all, so make an empty list.
data.parameters = ( parameters == null ) ? new LinkedList() : parameters; data.parameters = ( parameters == null ) ? new LinkedList() : parameters;
ParserSymbolTable.Lookup( data, (IContainerSymbol)this ); ParserSymbolTable.lookup( data, (IContainerSymbol)this );
return (IParameterizedSymbol) ParserSymbolTable.ResolveAmbiguities( data ); return (IParameterizedSymbol) ParserSymbolTable.resolveAmbiguities( data );
} }
public ISymbol QualifiedLookup( String name ) throws ParserSymbolTableException{ public ISymbol qualifiedLookup( String name ) throws ParserSymbolTableException{
LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() );
data.qualified = true; data.qualified = true;
ParserSymbolTable.Lookup( data, this ); ParserSymbolTable.lookup( data, this );
return ParserSymbolTable.ResolveAmbiguities( data ); return ParserSymbolTable.resolveAmbiguities( data );
} }
public TemplateInstance TemplateLookup( String name, LinkedList arguments ) throws ParserSymbolTableException public TemplateInstance templateLookup( String name, LinkedList arguments ) throws ParserSymbolTableException
{ {
LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() );
data.parameters = arguments; data.parameters = arguments;
ParserSymbolTable.Lookup( data, (IContainerSymbol) this ); ParserSymbolTable.lookup( data, (IContainerSymbol) this );
ISymbol found = ParserSymbolTable.ResolveAmbiguities( data ); ISymbol found = ParserSymbolTable.resolveAmbiguities( data );
if( found.isType( TypeInfo.t_template ) ){ if( found.isType( TypeInfo.t_template ) ){
return ((IParameterizedSymbol) found).instantiate( arguments ); return ((IParameterizedSymbol) found).instantiate( arguments );
} }
return null; return null;
} }
public IParameterizedSymbol lookupConstructor( LinkedList parameters ) throws ParserSymbolTableException
{
LookupData data = new LookupData( "", TypeInfo.t_constructor, null );
data.parameters = parameters;
return ParserSymbolTable.resolveFunction( data, getConstructors() );
}
/** /**
* UnqualifiedFunctionLookup * UnqualifiedFunctionLookup
* @param name * @param name
@ -2983,7 +3071,7 @@ public class ParserSymbolTable {
* ordinary unqualified lookup and the set of declarations found in the * ordinary unqualified lookup and the set of declarations found in the
* namespaces and classes associated with the argument types. * namespaces and classes associated with the argument types.
*/ */
public IParameterizedSymbol UnqualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol unqualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{
//figure out the set of associated scopes first, so we can remove those that are searched //figure out the set of associated scopes first, so we can remove those that are searched
//during the normal lookup to avoid doing them twice //during the normal lookup to avoid doing them twice
HashSet associated = new HashSet(); HashSet associated = new HashSet();
@ -3018,9 +3106,9 @@ public class ParserSymbolTable {
data.parameters = ( parameters == null ) ? new LinkedList() : parameters; data.parameters = ( parameters == null ) ? new LinkedList() : parameters;
data.associated = associated; data.associated = associated;
ParserSymbolTable.Lookup( data, this ); ParserSymbolTable.lookup( data, this );
Declaration found = (Declaration)ResolveAmbiguities( data ); Declaration found = (Declaration)resolveAmbiguities( data );
//if we haven't found anything, or what we found is not a class member, consider the //if we haven't found anything, or what we found is not a class member, consider the
//associated scopes //associated scopes
@ -3044,11 +3132,11 @@ public class ParserSymbolTable {
if( associated.contains( decl ) ){ if( associated.contains( decl ) ){
data.qualified = true; data.qualified = true;
data.ignoreUsingDirectives = true; data.ignoreUsingDirectives = true;
ParserSymbolTable.Lookup( data, decl ); ParserSymbolTable.lookup( data, decl );
} }
} }
found = (Declaration)ParserSymbolTable.ResolveAmbiguities( data ); found = (Declaration)ParserSymbolTable.resolveAmbiguities( data );
} }
return found; return found;
@ -3136,6 +3224,8 @@ public class ParserSymbolTable {
private LinkedList _parameterList; //have my cake private LinkedList _parameterList; //have my cake
private HashMap _parameterHash; //and eat it too private HashMap _parameterHash; //and eat it too
private LinkedList _constructors; //constructor list
private ISymbol _returnType; private ISymbol _returnType;
@ -3196,5 +3286,4 @@ public class ParserSymbolTable {
} }
} }
} }

View file

@ -36,12 +36,13 @@ public class ParserSymbolTableException extends Exception {
reason = r; reason = r;
} }
public static final int r_Unspecified = -1; public static final int r_InternalError = -1;
public static final int r_Ambiguous = 0; public static final int r_Ambiguous = 0;
public static final int r_BadTypeInfo = 1; public static final int r_BadTypeInfo = 1;
public static final int r_CircularInheritance = 2; public static final int r_CircularInheritance = 2;
public static final int r_InvalidOverload = 3; public static final int r_InvalidOverload = 3;
public static final int r_BadTemplate = 4; public static final int r_BadTemplate = 4;
public static final int r_InvalidUsing = 5;
public int reason = -1; public int reason = -1;
} }

View file

@ -97,19 +97,20 @@ public class TypeInfo {
public static final TypeInfo.eType t_struct = new TypeInfo.eType( 4 ); 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_union = new TypeInfo.eType( 5 );
public static final TypeInfo.eType t_enumeration = new TypeInfo.eType( 6 ); 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_constructor = new TypeInfo.eType( 7 );
public static final TypeInfo.eType t_bool = new TypeInfo.eType( 8 ); public static final TypeInfo.eType t_function = new TypeInfo.eType( 8 );
public static final TypeInfo.eType t_char = new TypeInfo.eType( 9 ); public static final TypeInfo.eType t_bool = new TypeInfo.eType( 9 );
public static final TypeInfo.eType t_wchar_t = new TypeInfo.eType( 10 ); public static final TypeInfo.eType t_char = new TypeInfo.eType( 10 );
public static final TypeInfo.eType t_int = new TypeInfo.eType( 11 ); public static final TypeInfo.eType t_wchar_t = new TypeInfo.eType( 11 );
public static final TypeInfo.eType t_float = new TypeInfo.eType( 12 ); public static final TypeInfo.eType t_int = new TypeInfo.eType( 12 );
public static final TypeInfo.eType t_double = new TypeInfo.eType( 13 ); public static final TypeInfo.eType t_float = new TypeInfo.eType( 13 );
public static final TypeInfo.eType t_void = new TypeInfo.eType( 14 ); public static final TypeInfo.eType t_double = new TypeInfo.eType( 14 );
public static final TypeInfo.eType t_enumerator = new TypeInfo.eType( 15 ); public static final TypeInfo.eType t_void = new TypeInfo.eType( 15 );
public static final TypeInfo.eType t_block = new TypeInfo.eType( 16 ); public static final TypeInfo.eType t_enumerator = new TypeInfo.eType( 16 );
public static final TypeInfo.eType t_template = new TypeInfo.eType( 17 ); public static final TypeInfo.eType t_block = new TypeInfo.eType( 17 );
public static final TypeInfo.eType t_asm = new TypeInfo.eType( 18 ); public static final TypeInfo.eType t_template = new TypeInfo.eType( 18 );
public static final TypeInfo.eType t_linkage = new TypeInfo.eType( 19 ); public static final TypeInfo.eType t_asm = new TypeInfo.eType( 19 );
public static final TypeInfo.eType t_linkage = new TypeInfo.eType( 20 );
//public static final eType t_templateParameter = new eType( 18 ); //public static final eType t_templateParameter = new eType( 18 );
public static class eType implements Comparable{ public static class eType implements Comparable{