diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 095b6259e35..75e757623e5 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -2,6 +2,10 @@ Modified CCompletionProposalsTest to complete on a body file that includes a header file. +2003-09-02 Andrew Niefer + added ParserSymbolTableTest.testNamespaceAlias() + added ParserSymbolTableTest.testUsingNamespaceAlias() + 2003-08-28 Andrew Niefer Modified BaseSearchTest.setup to properly include the "include.h" file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java index a82ffcec3e7..249b6b65244 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java @@ -2204,6 +2204,7 @@ public class ParserSymbolTableTest extends TestCase { * * @throws Exception */ + //TODO public void incompletetestTemplateSpecialization() throws Exception{ newTable(); @@ -2502,5 +2503,78 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( lookup, constructor2 ); } + + /** + * + * @throws Exception + * + * namespace A + * { + * int x; + * } + * namespace B = A; + * + * ++B::x; + */ + public void testNamespaceAlias() throws Exception{ + newTable(); + + IContainerSymbol NSA = table.newContainerSymbol( "A", TypeInfo.t_namespace ); + table.getCompilationUnit().addSymbol( NSA ); + + ISymbol x = table.newSymbol( "x", TypeInfo.t_int ); + NSA.addSymbol( x ); + + IContainerSymbol NSB = table.newContainerSymbol( "B", TypeInfo.t_namespace ); + NSB.setTypeSymbol( NSA ); //alias B to A + + table.getCompilationUnit().addSymbol( NSB ); + + ISymbol lookup = table.getCompilationUnit().lookup( "B" ); + assertEquals( lookup, NSB ); + + lookup = NSB.lookup( "x" ); + assertEquals( lookup, x ); + } + + /** + * + * @throws Exception + * namespace A + * { + * void f( ); + * } + * namespace B = A; + * + * B::f(); + * + * using namespace B; + * f(); + */ + public void testUsingNamespaceAlias() throws Exception{ + newTable(); + + IContainerSymbol NSA = table.newContainerSymbol( "A", TypeInfo.t_namespace ); + table.getCompilationUnit().addSymbol( NSA ); + + IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function ); + f.setReturnType( table.newSymbol( "", TypeInfo.t_void ) ); + + NSA.addSymbol( f ); + + IContainerSymbol NSB = table.newContainerSymbol( "B", TypeInfo.t_namespace ); + NSB.setTypeSymbol( NSA ); + table.getCompilationUnit().addSymbol( NSB ); + + //look for function that has no parameters + LinkedList paramList = new LinkedList(); + ISymbol look = NSB.qualifiedFunctionLookup( "f", paramList ); + assertEquals( look, f ); + + table.getCompilationUnit().addUsingDirective( NSB ); + + look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", paramList ); + assertEquals( look, f ); + } } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 1e905b14114..e8c13fc7dbc 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,6 @@ +2003-09-02 Andrew Niefer + bug41935 - Modifications to PST to allow for namespace aliases + 2003-08-28 John Camelon Fixed bug39535 - Parser fails on namesapce aliases diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java index e0ae598b659..1a9dfdceb9b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java @@ -88,6 +88,14 @@ public class ParserSymbolTable { throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); } + //handle namespace aliases + if( inSymbol.isType( TypeInfo.t_namespace ) ){ + ISymbol symbol = inSymbol.getTypeSymbol(); + if( symbol != null && symbol.isType( TypeInfo.t_namespace ) ){ + inSymbol = (IContainerSymbol) symbol; + } + } + ISymbol symbol = null; //the return value LinkedList transitives = new LinkedList(); //list of transitive using directives @@ -2884,7 +2892,13 @@ public class ParserSymbolTable { if( namespace.getType() != TypeInfo.t_namespace ){ throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing ); } - + + //handle namespace aliasing + ISymbol alias = namespace.getTypeSymbol(); + if( alias != null && alias.isType( TypeInfo.t_namespace ) ){ + namespace = (IContainerSymbol) alias; + } + if( _usingDirectives == null ){ _usingDirectives = new LinkedList(); } @@ -2950,8 +2964,18 @@ public class ParserSymbolTable { public ISymbol lookupMemberForDefinition( String name ) throws ParserSymbolTableException{ LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() ); data.qualified = true; - - ParserSymbolTable.lookupInContained( data, this ); + + IContainerSymbol container = this; + + //handle namespace aliases + if( container.isType( TypeInfo.t_namespace ) ){ + ISymbol symbol = container.getTypeSymbol(); + if( symbol != null && symbol.isType( TypeInfo.t_namespace ) ){ + container = (IContainerSymbol) symbol; + } + } + + ParserSymbolTable.lookupInContained( data, container ); return ParserSymbolTable.resolveAmbiguities( data ); }