mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
bug 52412 - using declarations are problematic in the PST
This commit is contained in:
parent
82d727f5e6
commit
965904453b
7 changed files with 98 additions and 8 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
2004-02-18 Andrew Niefer
|
||||||
|
modify ParserSymbolTableTests.testUsingDeclaration_2
|
||||||
|
|
||||||
2004-02-17 Andrew Niefer
|
2004-02-17 Andrew Niefer
|
||||||
added ParserSymbolTableTests.testBug52111RemoveSymbol
|
added ParserSymbolTableTests.testBug52111RemoveSymbol
|
||||||
|
|
||||||
|
|
|
@ -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.IParameterizedSymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
|
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.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.IUsingDirectiveSymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
|
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
|
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
|
||||||
|
@ -1137,7 +1138,12 @@ public class ParserSymbolTableTest extends TestCase {
|
||||||
ISymbol look = compUnit.lookupNestedNameSpecifier("A");
|
ISymbol look = compUnit.lookupNestedNameSpecifier("A");
|
||||||
assertEquals( look, 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");
|
look = compUnit.lookup("A");
|
||||||
assertEquals( look, A );
|
assertEquals( look, A );
|
||||||
|
@ -1168,11 +1174,20 @@ public class ParserSymbolTableTest extends TestCase {
|
||||||
|
|
||||||
look = bar.lookupNestedNameSpecifier( "A" );
|
look = bar.lookupNestedNameSpecifier( "A" );
|
||||||
assertEquals( look, 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 );
|
look = bar.unqualifiedFunctionLookup( "f", paramList );
|
||||||
assertTrue( look != null );
|
assertTrue( look != null );
|
||||||
assertTrue( ((IParameterizedSymbol) look).hasSameParameters( f2 ) );
|
assertEquals( look, iter.next() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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
|
2004-02-17 Andrew Niefer
|
||||||
bug 52111 : added IContainerSymbol.removeSymbol() which is implemented as ContainerSymbol.removeSymbol()
|
bug 52111 : added IContainerSymbol.removeSymbol() which is implemented as ContainerSymbol.removeSymbol()
|
||||||
|
|
||||||
|
|
|
@ -318,14 +318,14 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
* class being defined, or shall refer to an enumerator for an enumeration
|
* 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.
|
* 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 );
|
return addUsingDeclaration( name, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(java.lang.String, org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol)
|
* @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 );
|
LookupData data = new LookupData( name, TypeInfo.t_any );
|
||||||
|
|
||||||
if( declContext != null ){
|
if( declContext != null ){
|
||||||
|
@ -359,6 +359,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
symbol = ( iter != null && iter.hasNext() ) ? (ISymbol)iter.next() : null;
|
symbol = ( iter != null && iter.hasNext() ) ? (ISymbol)iter.next() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List usingDecs = new LinkedList();
|
||||||
|
List usingRefs = new LinkedList();
|
||||||
|
|
||||||
while( symbol != null ){
|
while( symbol != null ){
|
||||||
if( ParserSymbolTable.okToAddUsingDeclaration( symbol, this ) ){
|
if( ParserSymbolTable.okToAddUsingDeclaration( symbol, this ) ){
|
||||||
clone = (ISymbol) symbol.clone(); //7.3.3-9
|
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 );
|
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usingDecs.add( clone );
|
||||||
|
usingRefs.add( symbol );
|
||||||
|
|
||||||
if( iter != null && iter.hasNext() ){
|
if( iter != null && iter.hasNext() ){
|
||||||
symbol = (ISymbol) iter.next();
|
symbol = (ISymbol) iter.next();
|
||||||
} else {
|
} else {
|
||||||
|
@ -374,7 +380,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return clone;
|
return new UsingDeclarationSymbol( getSymbolTable(), usingRefs, usingDecs );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -68,8 +68,8 @@ public interface IContainerSymbol extends ISymbol {
|
||||||
* IDerivableContainerSymbol
|
* IDerivableContainerSymbol
|
||||||
* r_CircularInheritance if during lookup of the name, we come across a class with a circular inheritance tree
|
* 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 IUsingDeclarationSymbol addUsingDeclaration( String name ) throws ParserSymbolTableException;
|
||||||
public ISymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException;
|
public IUsingDeclarationSymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException;
|
||||||
|
|
||||||
public Map getContainedSymbols();
|
public Map getContainedSymbols();
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue