diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 1369cd845d2..4b390f921ed 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-09-30 Andrew Niefer + added testBug43503_AmbiguousUsing() and testBug43503_UnableToResolveFunction() to + ParserSymbolTableTest + 2003-09-29 Andrew Niefer added testBug43062 and testConstructorDestructor to FunctionMethodPatternTests modified resources/search/classDecl.cpp & include.h to include more operators and a constructor 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 ee484457dba..77daec870eb 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 @@ -2844,5 +2844,73 @@ public class ParserSymbolTableTest extends TestCase { look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters ); assertEquals( look, f ); } + + /** + * + * namespace A{ + * void f(); + * } + * namespace B{ + * int f; + * } + * namespace C{ + * using namespace A; + * using namespace B; + * using f; //ambiguous, int f or void f()? + * } + */ + public void testBug43503_AmbiguousUsing() throws Exception{ + newTable(); + IContainerSymbol NSA = table.newContainerSymbol( "A", TypeInfo.t_namespace ); + table.getCompilationUnit().addSymbol( NSA ); + + IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", TypeInfo.t_function ); + NSA.addSymbol( f1 ); + + IContainerSymbol NSB = table.newContainerSymbol( "B", TypeInfo.t_namespace ); + table.getCompilationUnit().addSymbol( NSB ); + + ISymbol f2 = table.newSymbol( "f", TypeInfo.t_int ); + NSB.addSymbol( f2 ); + + IContainerSymbol NSC = table.newContainerSymbol( "C", TypeInfo.t_namespace ); + table.getCompilationUnit().addSymbol( NSC ); + NSC.addUsingDirective( NSA ); + NSC.addUsingDirective( NSB ); + + try{ + NSC.addUsingDeclaration( "f" ); + assertTrue( false ); + } catch ( ParserSymbolTableException e ){ + assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); + } + } + + /** + * void f( void ); + * void f( int ); + * + * void * pF = &f; //lookup without function parameters, should be ambiguous + * @throws Exception + */ + public void testBug43503_UnableToResolveFunction() throws Exception{ + newTable(); + + IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", TypeInfo.t_function ); + + IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function ); + f2.addParameter( TypeInfo.t_int, 0, null, false ); + + table.getCompilationUnit().addSymbol( f1 ); + table.getCompilationUnit().addSymbol( f2 ); + + try{ + table.getCompilationUnit().lookup( "f" ); + assertTrue( false ); + } catch( ParserSymbolTableException e ){ + assertEquals( e.reason, ParserSymbolTableException.r_UnableToResolveFunction ); + } + + } } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 162ee34e444..a09e127f6a7 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,10 @@ +2003-09-30 Andrew Niefer + PST changes for bug 43503 - parser needs to know the different between ambiguous functions + and no functions when no parameter information is provided + - throw r_UnableToResolveFunction if we have more than 1 function and no parameter info was given + - handle this case in addUsingDeclaration. + * note that r_UnableToResolveFunction doesn't necessarily mean ambiguous if we had enough information + 2003-09-29 Hoda Amer Solution to bug#43679 : Exceptions in indexer 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 bfe5016d2f2..869c4523184 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 @@ -657,7 +657,7 @@ public class ParserSymbolTable { return (ISymbol) functionList.getFirst(); } else { data.foundItems.addAll( functionList ); - return null; + throw new ParserSymbolTableException( ParserSymbolTableException.r_UnableToResolveFunction ); } } else { return resolveFunction( data, functionList ); @@ -3074,7 +3074,14 @@ public class ParserSymbolTable { //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); - BasicSymbol obj = (BasicSymbol)ParserSymbolTable.resolveAmbiguities( data ); + BasicSymbol obj = null; + try{ + obj = (BasicSymbol)ParserSymbolTable.resolveAmbiguities( data ); + } catch ( ParserSymbolTableException e ) { + if( e.reason != ParserSymbolTableException.r_UnableToResolveFunction ){ + throw e; + } + } if( data.foundItems == null ){ throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableException.java index 2250b26008b..b562e49fddc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableException.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableException.java @@ -44,6 +44,7 @@ public class ParserSymbolTableException extends Exception { public static final int r_BadTemplate = 4; public static final int r_InvalidUsing = 5; public static final int r_BadVisibility = 6; + public static final int r_UnableToResolveFunction = 7; public int reason = -1; } \ No newline at end of file