Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] bug41935: PST support for Namespace aliases

Added support to the parser symbol table for namespace aliases.

tests:
        added ParserSymbolTableTest.testNamespaceAlias()
        added ParserSymbolTableTest.testUsingNamespaceAlias()

-Andrew

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.71
diff -u -r1.71 ChangeLog
--- ChangeLog	28 Aug 2003 20:14:11 -0000	1.71
+++ ChangeLog	2 Sep 2003 18:35:14 -0000
@@ -1,3 +1,7 @@
+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
 
Index: parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java,v
retrieving revision 1.13
diff -u -r1.13 ParserSymbolTableTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java	7 Aug 2003 14:46:44 -0000	1.13
+++ parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java	2 Sep 2003 18:35:15 -0000
@@ -2204,6 +2204,7 @@
 	 * 
 	 * @throws Exception   
 	 */
+	//TODO
 	public void incompletetestTemplateSpecialization() throws Exception{
 		newTable();
 		
@@ -2501,6 +2502,79 @@
 		ISymbol lookup = classA.lookupConstructor( paramList );
 		
 		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 );
 	}
 }
 
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.106
diff -u -r1.106 ChangeLog
--- parser/ChangeLog	28 Aug 2003 15:02:52 -0000	1.106
+++ parser/ChangeLog	2 Sep 2003 18:32:28 -0000
@@ -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
 	
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java,v
retrieving revision 1.14
diff -u -r1.14 ParserSymbolTable.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java	28 Aug 2003 15:50:31 -0000	1.14
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java	2 Sep 2003 18:32:29 -0000
@@ -88,6 +88,14 @@
 			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 @@
 			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 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 );
 		}

Back to the top