From 965904453b8ab54c1d7be76033d5c14b178a2880 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Wed, 18 Feb 2004 21:03:42 +0000 Subject: [PATCH] bug 52412 - using declarations are problematic in the PST --- core/org.eclipse.cdt.core.tests/ChangeLog | 3 ++ .../parser/tests/ParserSymbolTableTest.java | 21 ++++++++-- .../parser/ChangeLog-parser | 4 ++ .../core/parser/pst/ContainerSymbol.java | 12 ++++-- .../core/parser/pst/IContainerSymbol.java | 4 +- .../parser/pst/IUsingDeclarationSymbol.java | 23 +++++++++++ .../parser/pst/UsingDeclarationSymbol.java | 39 +++++++++++++++++++ 7 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDeclarationSymbol.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 782e09293e5..44a221195bd 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,6 @@ +2004-02-18 Andrew Niefer + modify ParserSymbolTableTests.testUsingDeclaration_2 + 2004-02-17 Andrew Niefer added ParserSymbolTableTests.testBug52111RemoveSymbol 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 caeb39d2b26..df8b0f60534 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 @@ -37,6 +37,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; +import org.eclipse.cdt.internal.core.parser.pst.IUsingDeclarationSymbol; import org.eclipse.cdt.internal.core.parser.pst.IUsingDirectiveSymbol; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; @@ -1137,7 +1138,12 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = compUnit.lookupNestedNameSpecifier("A"); assertEquals( look, A ); - IParameterizedSymbol usingF = (IParameterizedSymbol) compUnit.addUsingDeclaration( "f", A ); + IUsingDeclarationSymbol using = compUnit.addUsingDeclaration( "f", A ); + assertEquals( using.getReferencedSymbols().size(), 1 ); + + assertEquals( using.getReferencedSymbols().get(0), f1 ); + + IParameterizedSymbol usingF = (IParameterizedSymbol)using.getDeclaredSymbols().get(0); look = compUnit.lookup("A"); assertEquals( look, A ); @@ -1168,11 +1174,20 @@ public class ParserSymbolTableTest extends TestCase { look = bar.lookupNestedNameSpecifier( "A" ); assertEquals( look, A ); - bar.addUsingDeclaration( "f", A ); + + using = bar.addUsingDeclaration( "f", A ); + + Iterator iter = using.getReferencedSymbols().iterator(); + assertEquals( iter.next(), f1 ); + assertEquals( iter.next(), f2 ); + assertFalse( iter.hasNext() ); + + iter = using.getDeclaredSymbols().iterator(); + iter.next(); look = bar.unqualifiedFunctionLookup( "f", paramList ); assertTrue( look != null ); - assertTrue( ((IParameterizedSymbol) look).hasSameParameters( f2 ) ); + assertEquals( look, iter.next() ); } /** diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog-parser b/core/org.eclipse.cdt.core/parser/ChangeLog-parser index 7893134ac9d..d458298d578 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog-parser +++ b/core/org.eclipse.cdt.core/parser/ChangeLog-parser @@ -1,3 +1,7 @@ +2004-02-18 Andrew Niefer + added IUsingDeclarationSymbol and UsingDeclarationSymbol + changed IContainerSymbol.addUsingDeclaration to return a IUsingDeclarationSymbol + 2004-02-17 Andrew Niefer bug 52111 : added IContainerSymbol.removeSymbol() which is implemented as ContainerSymbol.removeSymbol() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java index 78ea32722d3..3de0cf6e626 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java @@ -318,14 +318,14 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { * class being defined, or shall refer to an enumerator for an enumeration * type that is a member of a base class of the class being defined. */ - public ISymbol addUsingDeclaration( String name ) throws ParserSymbolTableException { + public IUsingDeclarationSymbol addUsingDeclaration( String name ) throws ParserSymbolTableException { return addUsingDeclaration( name, null ); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(java.lang.String, org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) */ - public ISymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException{ + public IUsingDeclarationSymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException{ LookupData data = new LookupData( name, TypeInfo.t_any ); if( declContext != null ){ @@ -359,6 +359,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { symbol = ( iter != null && iter.hasNext() ) ? (ISymbol)iter.next() : null; } + List usingDecs = new LinkedList(); + List usingRefs = new LinkedList(); + while( symbol != null ){ if( ParserSymbolTable.okToAddUsingDeclaration( symbol, this ) ){ clone = (ISymbol) symbol.clone(); //7.3.3-9 @@ -367,6 +370,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing ); } + usingDecs.add( clone ); + usingRefs.add( symbol ); + if( iter != null && iter.hasNext() ){ symbol = (ISymbol) iter.next(); } else { @@ -374,7 +380,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { } } - return clone; + return new UsingDeclarationSymbol( getSymbolTable(), usingRefs, usingDecs ); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java index 59c14f44560..1a7eb5783ee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java @@ -68,8 +68,8 @@ public interface IContainerSymbol extends ISymbol { * IDerivableContainerSymbol * r_CircularInheritance if during lookup of the name, we come across a class with a circular inheritance tree */ - public ISymbol addUsingDeclaration( String name ) throws ParserSymbolTableException; - public ISymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException; + public IUsingDeclarationSymbol addUsingDeclaration( String name ) throws ParserSymbolTableException; + public IUsingDeclarationSymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException; public Map getContainedSymbols(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDeclarationSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDeclarationSymbol.java new file mode 100644 index 00000000000..dbfc0f8aa8b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDeclarationSymbol.java @@ -0,0 +1,23 @@ +/* + * Created on Feb 18, 2004 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.cdt.internal.core.parser.pst; + +import java.util.List; + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +public interface IUsingDeclarationSymbol extends IExtensibleSymbol { + + List getReferencedSymbols(); + + List getDeclaredSymbols(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java new file mode 100644 index 00000000000..35f3ba7f89e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java @@ -0,0 +1,39 @@ +/* + * Created on Feb 18, 2004 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.eclipse.cdt.internal.core.parser.pst; + +import java.util.List; + + +/** + * @author aniefer + * + * To change the template for this generated type comment go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +public class UsingDeclarationSymbol implements IUsingDeclarationSymbol { + + public UsingDeclarationSymbol( ParserSymbolTable table, List referenced, List declared ){ + referencedSymbol = referenced; + declaredSymbol = declared; + symbolTable = table; + } + + public List getReferencedSymbols() { return referencedSymbol; } + public List getDeclaredSymbols() { return declaredSymbol; } + + public ISymbolASTExtension getASTExtension() { return extension; } + public void setASTExtension( ISymbolASTExtension ext ) { extension = ext; } + + public ParserSymbolTable getSymbolTable() { return symbolTable; } + + private ISymbolASTExtension extension; + private final List referencedSymbol; + private final List declaredSymbol; + private final ParserSymbolTable symbolTable; + +}