mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Patch for Andrew Niefer.
Added support to the parser symbol table for namespace aliases. tests: added ParserSymbolTableTest.testNamespaceAlias() added ParserSymbolTableTest.testUsingNamespaceAlias()
This commit is contained in:
parent
08ceac730e
commit
7ce8f5c91e
4 changed files with 108 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue