1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 09:16:02 +02:00

Patch for Andrew Niefer

This patch implements an iterator on all the contents of IContainerSymbol. 
This is a first step to an iterator on the IAST nodes.  

Core:
        Created IExtensibleSymbol, which is a new base class for the symbol interfaces
        Created IUsingDirectiveSymbol and UsingDirectiveSymbol
        Modified ASTUsingDirective to use IUsingDirectiveSymbol
        Modified CompleteParseASTFactory.createUsingDirective
        Added IContainerSymbol.getContentsIterator()
        Implemented getContentsIterator in ContainerSymbol

Core.tests:
        Modified CompleteParseASTTest.testUsingClauses
        Added ParserSymbolTableTest.testIterator_1 & testIterator_2
This commit is contained in:
John Camelon 2004-01-17 00:18:24 +00:00
parent bcdd0ab7c3
commit 9cac774800
14 changed files with 319 additions and 48 deletions

View file

@ -1,3 +1,7 @@
2004-01-16 Andrew Niefer
Modified CompleteParseASTTest.testUsingClauses
Added ParserSymbolTableTest.testIterator_1 & testIterator_2
2004-01-16 Hoda Amer 2004-01-16 Hoda Amer
Modified CModelElementsTest to test for enumerator constant expression Modified CModelElementsTest to test for enumerator constant expression
Bug#47552 Bug#47552

View file

@ -1,5 +1,5 @@
/********************************************************************** /**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others. * Copyright (c) 2002,2003,2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5 * are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -194,6 +194,7 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertQualifiedName( fieldY.getFullyQualifiedName(), new String [] { "A", "B", "C", "y" } ); assertQualifiedName( fieldY.getFullyQualifiedName(), new String [] { "A", "B", "C", "y" } );
IASTUsingDirective directive = (IASTUsingDirective)declarations.next(); IASTUsingDirective directive = (IASTUsingDirective)declarations.next();
assertEquals( directive.getNamespaceDefinition(), namespaceB ); assertEquals( directive.getNamespaceDefinition(), namespaceB );
assertEquals( directive.getNamespaceName(), "A::B" );
IASTUsingDeclaration declaration = (IASTUsingDeclaration)declarations.next(); IASTUsingDeclaration declaration = (IASTUsingDeclaration)declarations.next();
assertEquals( declaration.getUsingType(), variableX ); assertEquals( declaration.getUsingType(), variableX );
declaration = (IASTUsingDeclaration)declarations.next(); declaration = (IASTUsingDeclaration)declarations.next();

View file

@ -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.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;
import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
@ -3434,5 +3435,125 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( foo1, look ); assertEquals( foo1, look );
} }
/**
* int global;
* class A {
* A();
* int var;
* void foo();
* };
*
*/
public void testIterator_1() throws Exception{
newTable();
ISymbol global = table.newSymbol( "global", TypeInfo.t_int );
table.getCompilationUnit().addSymbol( global );
IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
table.getCompilationUnit().addSymbol( cls );
IParameterizedSymbol constructor = table.newParameterizedSymbol( "A", TypeInfo.t_constructor );
cls.addConstructor( constructor );
ISymbol var = table.newSymbol( "var", TypeInfo.t_int );
cls.addSymbol( var );
IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", TypeInfo.t_function );
cls.addSymbol( foo );
Iterator iter = table.getCompilationUnit().getContentsIterator();
assertEquals( iter.next(), global );
IContainerSymbol symbol = (IContainerSymbol) iter.next();
assertEquals( symbol, cls );
assertFalse( iter.hasNext() );
iter = symbol.getContentsIterator();
assertEquals( iter.next(), constructor );
assertEquals( iter.next(), var );
assertEquals( iter.next(), foo );
assertFalse( iter.hasNext() );
}
/**
* int foo();
* namespace A{
* int bar();
* int bar( int );
* };
* class B{
* void func(){
* using namespace A;
* }
* };
* @throws Exception
*/
public void testIterator_2() throws Exception{
newTable();
IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", TypeInfo.t_function );
table.getCompilationUnit().addSymbol( foo );
IContainerSymbol nsA = table.newContainerSymbol( "A", TypeInfo.t_namespace );
table.getCompilationUnit().addSymbol( nsA );
IParameterizedSymbol bar1 = table.newParameterizedSymbol( "bar", TypeInfo.t_function );
nsA.addSymbol( bar1 );
IParameterizedSymbol bar2 = table.newParameterizedSymbol( "bar", TypeInfo.t_function );
bar2.addParameter( TypeInfo.t_int, 0, null, false );
nsA.addSymbol( bar2 );
IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B", TypeInfo.t_class);
table.getCompilationUnit().addSymbol( B );
B.addCopyConstructor();
IParameterizedSymbol func = table.newParameterizedSymbol( "func", TypeInfo.t_function );
B.addSymbol( func );
IUsingDirectiveSymbol using = func.addUsingDirective( nsA );
Iterator iter = table.getCompilationUnit().getContentsIterator();
assertEquals( iter.next(), foo );
IContainerSymbol s1 = (IContainerSymbol) iter.next();
assertEquals( s1, nsA );
IContainerSymbol s2 = (IContainerSymbol) iter.next();
assertEquals( s2, B );
assertFalse( iter.hasNext() );
iter = s1.getContentsIterator();
assertEquals( iter.next(), bar1 );
assertEquals( iter.next(), bar2 );
assertFalse( iter.hasNext() );
iter = s2.getContentsIterator();
//Copy constructor!!
ISymbol copy = (ISymbol) iter.next();
assertTrue( copy instanceof IParameterizedSymbol );
assertEquals( copy.getName(), "B" );
assertEquals( copy.getType(), TypeInfo.t_constructor );
assertEquals( iter.next(), func );
assertFalse( iter.hasNext() );
iter = func.getContentsIterator();
//this pointer!!
ISymbol th = (ISymbol) iter.next();
assertEquals( th.getName(), "this" );
assertEquals( th.getTypeSymbol(), B );
assertEquals( iter.next(), using );
assertFalse( iter.hasNext() );
}
} }

View file

@ -1,3 +1,11 @@
2004-01-16 Andrew Niefer
Created IExtensibleSymbol, which is a new base class for the symbol interfaces
Created IUsingDirectiveSymbol and UsingDirectiveSymbol
Modified ASTUsingDirective to use IUsingDirectiveSymbol
Modified CompleteParseASTFactory.createUsingDirective
Added IContainerSymbol.getContentsIterator()
Implemented getContentsIterator in ContainerSymbol
2004-01-16 John Camelon 2004-01-16 John Camelon
Changed IASTNode.LookupException to IASTNode.LookupError. Changed IASTNode.LookupException to IASTNode.LookupError.
Updated IASTElaboratedTypeSpecifier to remove redundant extends relationships. Updated IASTElaboratedTypeSpecifier to remove redundant extends relationships.

View file

@ -1,5 +1,5 @@
/********************************************************************** /**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others. * Copyright (c) 2002,2003, 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5 * are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -17,6 +17,7 @@ import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
import org.eclipse.cdt.internal.core.parser.ast.Offsets; import org.eclipse.cdt.internal.core.parser.ast.Offsets;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.IUsingDirectiveSymbol;
/** /**
* @author jcamelon * @author jcamelon
@ -24,7 +25,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
*/ */
public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUsingDirective public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUsingDirective
{ {
private final IASTNamespaceDefinition namespace; private final IUsingDirectiveSymbol using;
private Offsets offsets = new Offsets(); private Offsets offsets = new Offsets();
private final ASTReferenceStore referenceDelegate; private final ASTReferenceStore referenceDelegate;
/** /**
@ -32,10 +33,12 @@ public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUs
* @param startingOffset * @param startingOffset
* @param endingOffset * @param endingOffset
*/ */
public ASTUsingDirective(IContainerSymbol ownerSymbol, IASTNamespaceDefinition namespaceDefinition, int startingOffset, int endingOffset, List references ) //public ASTUsingDirective(IContainerSymbol ownerSymbol, IASTNamespaceDefinition namespaceDefinition, int startingOffset, int endingOffset, List references )
public ASTUsingDirective(IContainerSymbol ownerSymbol, IUsingDirectiveSymbol usingDirective, int startingOffset, int endingOffset, List references )
{ {
super( ownerSymbol ); super( ownerSymbol );
namespace = namespaceDefinition; //namespace = namespaceDefinition;
using = usingDirective;
setStartingOffset(startingOffset); setStartingOffset(startingOffset);
setEndingOffset(endingOffset); setEndingOffset(endingOffset);
referenceDelegate = new ASTReferenceStore( references ); referenceDelegate = new ASTReferenceStore( references );
@ -46,7 +49,8 @@ public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUs
*/ */
public String getNamespaceName() public String getNamespaceName()
{ {
String [] fqn = namespace.getFullyQualifiedName(); IASTNamespaceDefinition namespace = getNamespaceDefinition();
String [] fqn = namespace.getFullyQualifiedName();
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
for( int i = 0; i < fqn.length; ++i ) for( int i = 0; i < fqn.length; ++i )
{ {
@ -118,7 +122,9 @@ public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUs
*/ */
public IASTNamespaceDefinition getNamespaceDefinition() public IASTNamespaceDefinition getNamespaceDefinition()
{ {
return namespace; IContainerSymbol namespaceSymbol = using.getNamespace();
return (IASTNamespaceDefinition)namespaceSymbol.getASTExtension().getPrimaryDeclaration();
} }
} }

View file

@ -1,5 +1,5 @@
/********************************************************************** /**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others. * Copyright (c) 2002,2003, 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5 * are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -76,6 +76,7 @@ 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.ISymbolOwner; import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner;
import org.eclipse.cdt.internal.core.parser.pst.IUsingDirectiveSymbol;
import org.eclipse.cdt.internal.core.parser.pst.NamespaceSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.NamespaceSymbolExtension;
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;
@ -326,13 +327,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ISymbol symbol = lookupQualifiedName( ISymbol symbol = lookupQualifiedName(
scopeToSymbol( scope), duple, references, true ); scopeToSymbol( scope), duple, references, true );
IUsingDirectiveSymbol usingDirective = null;
try { try {
((ASTScope)scope).getContainerSymbol().addUsingDirective( (IContainerSymbol)symbol ); usingDirective = ((ASTScope)scope).getContainerSymbol().addUsingDirective( (IContainerSymbol)symbol );
} catch (ParserSymbolTableException pste) { } catch (ParserSymbolTableException pste) {
throw new ASTSemanticException(); throw new ASTSemanticException();
} }
IASTUsingDirective astUD = new ASTUsingDirective( scopeToSymbol(scope), ((IASTNamespaceDefinition)symbol.getASTExtension().getPrimaryDeclaration()), startingOffset, endingOffset, references ); IASTUsingDirective astUD = new ASTUsingDirective( scopeToSymbol(scope), usingDirective, startingOffset, endingOffset, references );
return astUD; return astUD;
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003 IBM Corporation and others. * Copyright (c) 2003,2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5 * are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -139,6 +139,8 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
obj.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template ); obj.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template );
getContents().add( obj );
Command command = new AddSymbolCommand( obj, containing ); Command command = new AddSymbolCommand( obj, containing );
getSymbolTable().pushCommand( command ); getSymbolTable().pushCommand( command );
} }
@ -163,7 +165,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDirective(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDirective(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol)
*/ */
public void addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException{ public IUsingDirectiveSymbol addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException{
if( namespace.getType() != TypeInfo.t_namespace ){ if( namespace.getType() != TypeInfo.t_namespace ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing ); throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing );
} }
@ -180,10 +182,15 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
List usingDirectives = getUsingDirectives(); List usingDirectives = getUsingDirectives();
usingDirectives.add( namespace ); IUsingDirectiveSymbol usingDirective = new UsingDirectiveSymbol( getSymbolTable(), namespace );
usingDirectives.add( usingDirective );
Command command = new AddUsingDirectiveCommand( this, namespace ); getContents().add( usingDirective );
Command command = new AddUsingDirectiveCommand( this, usingDirective );
getSymbolTable().pushCommand( command ); getSymbolTable().pushCommand( command );
return usingDirective;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -749,6 +756,17 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
return instance; return instance;
} }
protected List getContents(){
if(_contents == null ){
_contents = new LinkedList();
}
return _contents;
}
public Iterator getContentsIterator(){
return getContents().iterator();
}
static private class AddSymbolCommand extends Command{ static private class AddSymbolCommand extends Command{
AddSymbolCommand( ISymbol newDecl, IContainerSymbol context ){ AddSymbolCommand( ISymbol newDecl, IContainerSymbol context ){
_symbol = newDecl; _symbol = newDecl;
@ -776,25 +794,44 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} else if( obj instanceof BasicSymbol ){ } else if( obj instanceof BasicSymbol ){
_context.getContainedSymbols().remove( _symbol.getName() ); _context.getContainedSymbols().remove( _symbol.getName() );
} }
// if( _removeThis && _symbol instanceof IParameterizedSymbol ){
// ((IParameterizedSymbol)_symbol).getContainedSymbols().remove( ParserSymbolTable.THIS ); //this is an inefficient way of doing this, we can modify the interfaces if the undo starts
// } //being used often.
Iterator iter = _context.getContentsIterator();
while( iter.hasNext() ){
IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
if( ext == _symbol ){
iter.remove();
break;
}
}
} }
private ISymbol _symbol; private final ISymbol _symbol;
private IContainerSymbol _context; private final IContainerSymbol _context;
} }
static private class AddUsingDirectiveCommand extends Command{ static private class AddUsingDirectiveCommand extends Command{
public AddUsingDirectiveCommand( IContainerSymbol container, IContainerSymbol namespace ){ public AddUsingDirectiveCommand( IContainerSymbol container, IUsingDirectiveSymbol directive ){
_decl = container; _decl = container;
_namespace = namespace; _directive = directive;
} }
public void undoIt(){ public void undoIt(){
_decl.getUsingDirectives().remove( _namespace ); _decl.getUsingDirectives().remove( _directive );
//this is an inefficient way of doing this, we can modify the interfaces if the undo starts
//being used often.
Iterator iter = _decl.getContentsIterator();
while( iter.hasNext() ){
IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
if( ext == _directive ){
iter.remove();
break;
}
}
} }
private IContainerSymbol _decl; private final IContainerSymbol _decl;
private IContainerSymbol _namespace; private final IUsingDirectiveSymbol _directive;
} }
static protected class SymbolTableComparator implements Comparator{ static protected class SymbolTableComparator implements Comparator{
@ -811,6 +848,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
} }
private LinkedList _contents; //ordered list of all contents of this symbol
private LinkedList _usingDirectives; //collection of nominated namespaces private LinkedList _usingDirectives; //collection of nominated namespaces
private Map _containedSymbols; //declarations contained by us. private Map _containedSymbols; //declarations contained by us.

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003 IBM Corporation and others. * Copyright (c) 2003, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5 * are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,9 +14,9 @@
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -120,6 +120,8 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
constructor.setContainingSymbol( this ); constructor.setContainingSymbol( this );
addThis( constructor ); addThis( constructor );
getContents().add( constructor );
Command command = new AddConstructorCommand( constructor, this ); Command command = new AddConstructorCommand( constructor, this );
getSymbolTable().pushCommand( command ); getSymbolTable().pushCommand( command );
} }
@ -335,7 +337,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
} }
public void undoIt(){ public void undoIt(){
List constructors = _context.getConstructors(); List constructors = _context.getConstructors();
ListIterator iter = constructors.listIterator(); Iterator iter = constructors.listIterator();
int size = constructors.size(); int size = constructors.size();
IParameterizedSymbol item = null; IParameterizedSymbol item = null;
@ -346,10 +348,19 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
break; break;
} }
} }
iter = _context.getContentsIterator();
while( iter.hasNext() ){
IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
if( ext == _constructor ){
iter.remove();
break;
}
}
} }
private IParameterizedSymbol _constructor; private final IParameterizedSymbol _constructor;
private IDerivableContainerSymbol _context; private final IDerivableContainerSymbol _context;
} }
public class ParentWrapper implements IDerivableContainerSymbol.IParentSymbol public class ParentWrapper implements IDerivableContainerSymbol.IParentSymbol

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003 IBM Corporation and others. * Copyright (c) 2003, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5 * are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -16,6 +16,7 @@
*/ */
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -32,7 +33,7 @@ public interface IContainerSymbol extends ISymbol {
public boolean hasUsingDirectives(); public boolean hasUsingDirectives();
public List getUsingDirectives(); public List getUsingDirectives();
public void addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException; public IUsingDirectiveSymbol addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException;
public ISymbol addUsingDeclaration( String name ) throws ParserSymbolTableException; public ISymbol addUsingDeclaration( String name ) throws ParserSymbolTableException;
public ISymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException; public ISymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException;
@ -55,4 +56,6 @@ public interface IContainerSymbol extends ISymbol {
public TemplateInstance instantiate( List arguments ) throws ParserSymbolTableException; public TemplateInstance instantiate( List arguments ) throws ParserSymbolTableException;
public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol ); public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol );
public Iterator getContentsIterator();
} }

View file

@ -0,0 +1,35 @@
/**********************************************************************
* Copyright (c) 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst;
/**
* @author aniefer
*/
public interface IExtensibleSymbol {
/**
* get the instance of ParserSymbolTable with wich this symbol is associated
* @return ParserSymbolTable
*/
public ParserSymbolTable getSymbolTable();
/**
* get the ISymbolASTExtension attached to this symbol
* @return ISymbolASTExtension
*/
public ISymbolASTExtension getASTExtension();
/**
* attach an ISymbolASTExtension to this symbol
* @param obj
*/
public void setASTExtension( ISymbolASTExtension obj );
}

View file

@ -1,5 +1,5 @@
/********************************************************************** /**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others. * Copyright (c) 2002,2003, 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5 * are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -17,15 +17,11 @@ import java.util.Map;
* @author jcamelon * @author jcamelon
* *
*/ */
public interface ISymbol extends Cloneable { public interface ISymbol extends Cloneable, IExtensibleSymbol {
public ParserSymbolTable getSymbolTable();
public Object clone(); public Object clone();
public ISymbolASTExtension getASTExtension(); public void setName(String name);
public void setASTExtension( ISymbolASTExtension obj );
public String getName(); public String getName();
public IContainerSymbol getContainingSymbol(); public IContainerSymbol getContainingSymbol();
@ -56,9 +52,4 @@ public interface ISymbol extends Cloneable {
public int getDepth(); public int getDepth();
public boolean getIsInvisible(); public boolean getIsInvisible();
public void setIsInvisible( boolean invisible ); public void setIsInvisible( boolean invisible );
/**
* @param name
*/
public void setName(String name);
} }

View file

@ -0,0 +1,16 @@
/**********************************************************************
* Copyright (c) 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst;
public interface IUsingDirectiveSymbol extends IExtensibleSymbol{
public IContainerSymbol getNamespace();
}

View file

@ -1,5 +1,5 @@
/********************************************************************** /**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others. * Copyright (c) 2002,2003,2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5 * are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -243,7 +243,7 @@ public class ParserSymbolTable {
//only consider the transitive using directives if we are an unqualified //only consider the transitive using directives if we are an unqualified
//lookup, or we didn't find the name in decl //lookup, or we didn't find the name in decl
if( (!data.qualified || !foundSomething || data.mode == LookupMode.PREFIX ) && temp.getUsingDirectives() != null ){ if( (!data.qualified || !foundSomething || data.mode == LookupMode.PREFIX ) && temp.hasUsingDirectives() ){
//name wasn't found, add transitive using directives for later consideration //name wasn't found, add transitive using directives for later consideration
transitiveDirectives.addAll( temp.getUsingDirectives() ); transitiveDirectives.addAll( temp.getUsingDirectives() );
} }
@ -1091,7 +1091,7 @@ public class ParserSymbolTable {
Iterator iter = directives.iterator(); Iterator iter = directives.iterator();
for( int i = size; i > 0; i-- ){ for( int i = size; i > 0; i-- ){
temp = (IContainerSymbol) iter.next(); temp = ((IUsingDirectiveSymbol) iter.next()).getNamespace();
//namespaces are searched at most once //namespaces are searched at most once
if( !data.visited.contains( temp ) ){ if( !data.visited.contains( temp ) ){

View file

@ -0,0 +1,35 @@
/**********************************************************************
* Copyright (c) 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst;
public class UsingDirectiveSymbol implements IUsingDirectiveSymbol{
private final ParserSymbolTable symbolTable;
public UsingDirectiveSymbol( ParserSymbolTable table, IContainerSymbol ns ){
namespace = ns;
symbolTable = table;
}
public IContainerSymbol getNamespace(){
return namespace;
}
public ISymbolASTExtension getASTExtension() { return extension; }
public void setASTExtension( ISymbolASTExtension ext ) { extension = ext; }
private ISymbolASTExtension extension;
private final IContainerSymbol namespace;
public ParserSymbolTable getSymbolTable() {
return symbolTable;
}
}