Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Applied Re: [cdt-patch] Content Assist work in Parser & Symbol Table


Thanks Andrew.

Hoda Amer
Staff Software Engineer
Rational Software - IBM Software Group



Andrew Niefer/Ottawa/IBM@IBMCA
Sent by: cdt-patch-admin@xxxxxxxxxxx

12/17/2003 03:36 PM

Please respond to
cdt-patch

To
cdt-patch@xxxxxxxxxxx
cc
Subject
[cdt-patch] Content Assist work in Parser & Symbol Table





Core:
handle friend classes in the parser and in the symbol table.  Consider
friendship in IContainerSymbol.isVisible.
Note that friend functions are not yet handled.
Also fix a bug with finding function parameters during prefix lookup.

Core.tests:
added ContextualParseTest.testCompletionLookup_FriendClass_1()
added ContextualParseTest.testCompletionLookup_FriendClass_2()
added
ContextualParseTest.testCompletionLookup_ParametersAsLocalVariables()
modified ParserSymbolTableTest.testVisibilityDetermination()

-Andrew

Index: parser/ChangeLog-parser
===================================================================
retrieving revision 1.8
diff -u -r1.8 ChangeLog-parser
--- parser/ChangeLog-parser	17 Dec 2003 19:21:20 -0000	1.8
+++ parser/ChangeLog-parser	17 Dec 2003 20:34:36 -0000
@@ -1,3 +1,9 @@
+2003-12-17 Andrew Niefer
+	Content Assist work: 
+	- change parser & symbol table to handle handle friend classes
+	- change visibility filtering to check for friendship
+	- fix finding function parameters in prefix lookup
+
 2003-12-17 Hoda Amer
 	Content Assist work : Integrated with Parser and Symbol table modifications
 	
Index: parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java
===================================================================
retrieving revision 1.42
diff -u -r1.42 IASTFactory.java
--- parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java	16 Dec 2003 15:18:16 -0000	1.42
+++ parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java	17 Dec 2003 20:34:37 -0000
@@ -97,7 +97,7 @@
         IASTScope scope,
         ASTClassKind elaboratedClassKind,
         ITokenDuple typeName,
-        int startingOffset, int endOffset, boolean isForewardDecl) throws ASTSemanticException;
+        int startingOffset, int endOffset, boolean isForewardDecl, boolean isFriend) throws ASTSemanticException;
 
     public IASTEnumerationSpecifier createEnumerationSpecifier(
         IASTScope scope,
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
retrieving revision 1.131
diff -u -r1.131 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java	17 Dec 2003 19:21:20 -0000	1.131
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java	17 Dec 2003 20:34:40 -0000
@@ -1654,7 +1654,7 @@
                     d,
                     t.getOffset(),
                     d.getLastToken().getEndOffset(), 
-                    isForewardDecl );
+                    isForewardDecl, sdw.isFriend() );
         }
         catch (ASTSemanticException e)
         {
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
retrieving revision 1.60
diff -u -r1.60 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	16 Dec 2003 15:18:15 -0000	1.60
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	17 Dec 2003 20:34:43 -0000
@@ -2485,7 +2485,7 @@
     }
 
     
-    public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier(IASTScope scope, ASTClassKind kind, ITokenDuple name, int startingOffset, int endOffset, boolean isForewardDecl) throws ASTSemanticException
+    public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier(IASTScope scope, ASTClassKind kind, ITokenDuple name, int startingOffset, int endOffset, boolean isForewardDecl, boolean isFriend) throws ASTSemanticException
     {
 		IContainerSymbol currentScopeSymbol = scopeToSymbol(scope);
 		TypeInfo.eType pstType = classKindToTypeInfo(kind);		
@@ -2504,7 +2504,14 @@
 		ISymbol checkSymbol = null;
 		try
 		{
-			checkSymbol = currentScopeSymbol.elaboratedLookup( pstType, lastToken.getImage());
+            if( isFriend ){
+                if( !(currentScopeSymbol instanceof IDerivableContainerSymbol) ){
+                    throw new ASTSemanticException();
+                }
+                checkSymbol = ((IDerivableContainerSymbol)currentScopeSymbol).lookupForFriendship( lastToken.getImage() );
+            } else {
+                checkSymbol = currentScopeSymbol.elaboratedLookup( pstType, lastToken.getImage());
+			}
 		}
 		catch (ParserSymbolTableException e)
 		{
@@ -2520,7 +2527,11 @@
 				checkSymbol.setIsForwardDeclaration( true );
 				try
 	            {
-	                currentScopeSymbol.addSymbol( checkSymbol  );
+                    if( isFriend ){
+                        ((IDerivableContainerSymbol)currentScopeSymbol).addFriend( checkSymbol );
+                    } else {
+                        currentScopeSymbol.addSymbol( checkSymbol  );
+                    }
 	            }
 	            catch (ParserSymbolTableException e1)
 	            {
@@ -2538,6 +2549,13 @@
                 {
                 	throw new ASTSemanticException();
                 }
+			} else if( isFriend ){
+				try {
+					((IDerivableContainerSymbol)currentScopeSymbol).addFriend( checkSymbol );
+				} catch (ParserSymbolTableException e1) {
+					throw new ASTSemanticException();
+				}
+				
 			}
  		}
  		
@@ -2612,7 +2630,7 @@
 	public IASTCodeScope createNewCodeBlock(IASTScope scope) {
 		IContainerSymbol symbol = scopeToSymbol( scope );
 		
-		IContainerSymbol newScope = pst.newContainerSymbol("");
+		IContainerSymbol newScope = pst.newContainerSymbol("", TypeInfo.t_block);
 		newScope.setContainingSymbol(symbol);
 		
 		ASTCodeScope codeScope = new ASTCodeScope( newScope );
Index: parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java
===================================================================
retrieving revision 1.42
diff -u -r1.42 QuickParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java	16 Dec 2003 15:18:16 -0000	1.42
+++ parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java	17 Dec 2003 20:34:44 -0000
@@ -263,7 +263,7 @@
         return new ASTAbstractTypeSpecifierDeclaration( scope, typeSpecifier, template, startingOffset, endingOffset );
     }
 
-    public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier(IASTScope scope, ASTClassKind elaboratedClassKind, ITokenDuple typeName, int startingOffset, int endOffset, boolean isForewardDecl)
+    public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier(IASTScope scope, ASTClassKind elaboratedClassKind, ITokenDuple typeName, int startingOffset, int endOffset, boolean isForewardDecl, boolean isFriend)
     {
         return new ASTElaboratedTypeSpecifier( scope, elaboratedClassKind, typeName.toString(), startingOffset, typeName.getFirstToken().getOffset(), typeName.getLastToken().getEndOffset(), endOffset );
     }
Index: parser/org/eclipse/cdt/internal/core/parser/pst/BasicSymbol.java
===================================================================
retrieving revision 1.1
diff -u -r1.1 BasicSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/BasicSymbol.java	20 Nov 2003 15:22:56 -0000	1.1
+++ parser/org/eclipse/cdt/internal/core/parser/pst/BasicSymbol.java	17 Dec 2003 20:34:44 -0000
@@ -169,12 +169,21 @@
 	public Map getArgumentMap(){
 		return null;
 	}
+	
+	public boolean getIsInvisible(){
+		return _isInvisible;
+	}
+	public void setIsInvisible( boolean invisible ){
+		_isInvisible = invisible ;
+	}
+	
 	private 	String 				_name;					//our name
 	private		ISymbolASTExtension	_object;				//the object associated with us
 	private		TypeInfo			_typeInfo;				//our type info
 	private		IContainerSymbol	_containingScope;		//the scope that contains us
 	private		int 				_depth;					//how far down the scope stack we are
 	
+	private 	boolean				_isInvisible = false;	//used by friend declarations (11.4-9)	
 	private		boolean				_isTemplateMember = false;		
 	private		TemplateInstance	_templateInstance;		
 }
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java
===================================================================
retrieving revision 1.4
diff -u -r1.4 ContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java	10 Dec 2003 00:07:26 -0000	1.4
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java	17 Dec 2003 20:34:45 -0000
@@ -635,8 +635,12 @@
 			{
 				return true;
 			}
+
+			//if this is a friend of the symbolContainer, then we are good
+			if( isFriendOf( symbolContainer ) ){
+				return true;
+			}
 			
-			//TODO: friendship
 			if( visibility == ASTAccessVisibility.PROTECTED )
 			{
 				try {
@@ -649,6 +653,33 @@
 			}
 		}
 		return true;
+	}
+	
+	protected boolean isFriendOf( IContainerSymbol symbol ){
+		if( symbol instanceof IDerivableContainerSymbol ){
+			IContainerSymbol container = this.getContainingSymbol();
+			
+			while( container != null && container.isType( TypeInfo.t_block ) ){
+				container = container.getContainingSymbol();
+			}
+			if( container != null && !container.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
+				container = null;
+			}
+			
+			IDerivableContainerSymbol derivable = (IDerivableContainerSymbol) symbol;
+			
+			Iterator iter = derivable.getFriends().iterator();
+			while( iter.hasNext() ){
+				ISymbol friend = (ISymbol) iter.next();
+				ISymbol typeSymbol = friend.getTypeSymbol();
+				if( friend == this      || typeSymbol == this ||
+					friend == container || ( container != null && typeSymbol == container ) )
+				{
+					return true;
+				}
+			}
+		}
+		return false;
 	}
 	
 	/* (non-Javadoc)
Index: parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java
===================================================================
retrieving revision 1.2
diff -u -r1.2 DerivableContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java	28 Nov 2003 04:57:50 -0000	1.2
+++ parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java	17 Dec 2003 20:34:45 -0000
@@ -241,24 +241,22 @@
 	 * TODO: if/when the parser symbol table starts caring about visibility
 	 * (public/protected/private) we will need to do more to record friendship.
 	 */
-	private ISymbol addFriend( String name ) throws ParserSymbolTableException{
-		ISymbol friend = lookupForFriendship( name  );
-	
-		if( friend == null ){
-			friend = getSymbolTable().newSymbol( name );
-			friend.getTypeInfo().setIsForwardDeclaration( true );
-		
-			IContainerSymbol containing = getContainingSymbol();
-			//find innermost enclosing namespace
-			while( containing != null && containing.getType() != TypeInfo.t_namespace ){
-				containing = containing.getContainingSymbol();
+	public void addFriend( ISymbol friend ) throws ParserSymbolTableException{
+		//is this symbol already in the table?
+		IContainerSymbol containing = friend.getContainingSymbol();
+		if( containing == null ){
+			//its not, it goes in the innermost enclosing namespace
+			IContainerSymbol enclosing = getContainingSymbol();
+			while( enclosing != null && !enclosing.isType( TypeInfo.t_namespace ) ){
+				enclosing = enclosing.getContainingSymbol();
 			}
-		
-			IContainerSymbol namespace = ( containing == null ) ?  getSymbolTable().getCompilationUnit() : containing;
-			namespace.addSymbol( friend );
+			
+			friend.setIsInvisible( true );
+			friend.setIsForwardDeclaration( true );
+			enclosing.addSymbol( friend );
 		}
 		
-		return friend;
+		getFriends().add( friend );
 	}
 	
 	/**
@@ -273,24 +271,28 @@
 	 * without considering scopes that are outside the innermost enclosing non-
 	 * class scope.
 	 */
-	private ISymbol lookupForFriendship( String name ) throws ParserSymbolTableException{
+	public ISymbol lookupForFriendship( String name ) throws ParserSymbolTableException{
 		LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() );
-	
-		boolean inClass = ( getType() == TypeInfo.t_class);
-	
+		
 		IContainerSymbol enclosing = getContainingSymbol();
-		while( enclosing != null && (inClass ? enclosing.getType() != TypeInfo.t_class
-											  :	enclosing.getType() == TypeInfo.t_namespace) )
-		{                                        		
-			enclosing = enclosing.getContainingSymbol();
+		if( enclosing != null && enclosing.isType( TypeInfo.t_namespace, TypeInfo.t_union ) ){
+			while( enclosing != null && ( enclosing.getType() != TypeInfo.t_namespace) )
+			{                                        		
+				enclosing = enclosing.getContainingSymbol();
+			}
 		}
-
 		data.stopAt = enclosing;
 	
 		ParserSymbolTable.lookup( data, this );
 		return ParserSymbolTable.resolveAmbiguities( data ); 
 	}
 	
+	public List getFriends(){ 
+		if( _friends == null ){
+			_friends = new LinkedList();
+		}
+		return _friends;
+	}
 	
 	static private class AddParentCommand extends Command{
 		public AddParentCommand( IDerivableContainerSymbol container, ParentWrapper wrapper ){
@@ -363,4 +365,5 @@
 	
 	private 	LinkedList 	_constructors;			//constructor list
 	private		LinkedList	_parentScopes;			//inherited scopes (is base classes)
+	private		LinkedList	_friends;
 }
Index: parser/org/eclipse/cdt/internal/core/parser/pst/IDerivableContainerSymbol.java
===================================================================
retrieving revision 1.7
diff -u -r1.7 IDerivableContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/IDerivableContainerSymbol.java	20 Nov 2003 15:22:56 -0000	1.7
+++ parser/org/eclipse/cdt/internal/core/parser/pst/IDerivableContainerSymbol.java	17 Dec 2003 20:34:45 -0000
@@ -38,6 +38,10 @@
 	public IParameterizedSymbol lookupConstructor( List parameters ) throws ParserSymbolTableException;
 	public List getConstructors();
 	
+	public void addFriend( ISymbol friend ) throws ParserSymbolTableException;
+	public ISymbol lookupForFriendship( String name ) throws ParserSymbolTableException;
+	public List getFriends();
+	
 	public interface IParentSymbol{
 		public void setParent( ISymbol parent );
 		public ISymbol getParent();
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java
===================================================================
retrieving revision 1.9
diff -u -r1.9 ISymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java	20 Nov 2003 15:22:56 -0000	1.9
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java	17 Dec 2003 20:34:45 -0000
@@ -54,6 +54,8 @@
 	public void setTemplateInstance( TemplateInstance instance );
 
 	public int getDepth();
+	public boolean getIsInvisible();
+	public void setIsInvisible( boolean invisible );
 
     /**
      * @param name
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
===================================================================
retrieving revision 1.30
diff -u -r1.30 ParserSymbolTable.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java	16 Dec 2003 15:18:15 -0000	1.30
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java	17 Dec 2003 20:34:46 -0000
@@ -335,7 +335,7 @@
 				name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
 				while( name != null ){
 					if( nameMatches( data, name ) ){
-						obj = parameters.get( data.name );
+						obj = parameters.get( name );
 						obj = collectSymbol( data, obj );
 						if( obj != null ){
 							found.put( name, obj );
@@ -393,7 +393,7 @@
 		IContainerSymbol cls = null;
 		
 		while( symbol != null ){
-			if( checkType( data, symbol ) ){//, data.type, data.upperType ) ){
+			if( !symbol.getIsInvisible() && checkType( data, symbol ) ){//, data.type, data.upperType ) ){
 				if( symbol.isTemplateMember() && data.templateInstance != null )
 					foundSymbol = new TemplateInstance( symbol.getSymbolTable(), symbol, data.templateInstance.getArgumentMap() );
 				else
@@ -674,12 +674,17 @@
 		TypeInfo.eType newType  = newSymbol.getType();
 		
 		//handle forward decls
-		if( origSymbol.getTypeInfo().isForwardDeclaration() &&
-			origSymbol.getTypeSymbol() == newSymbol )
-		{
-			return true;
+		if( origSymbol.getTypeInfo().isForwardDeclaration() ){
+			if( origSymbol.getTypeSymbol() == newSymbol )
+				return true;
+			
+			//friend class declarations
+			if( origSymbol.getIsInvisible() && origSymbol.isType( newSymbol.getType() ) ){
+				origSymbol.getTypeInfo().setTypeSymbol(  newSymbol );
+				return true;
+			}
 		}
-		
+				
 		if( (origType.compareTo(TypeInfo.t_class) >= 0 && origType.compareTo(TypeInfo.t_enumeration) <= 0) && //class name or enumeration ...
 			( newType == TypeInfo.t_type || (newType.compareTo( TypeInfo.t_function ) >= 0 /*&& newType <= TypeInfo.typeMask*/) ) ){
 				
@@ -707,7 +712,8 @@
 			
 			Iterator iter = origList.iterator();
 			ISymbol symbol = (ISymbol) iter.next();
-			boolean valid = ( (symbol.getType().compareTo( TypeInfo.t_class ) >= 0 ) && (symbol.getType().compareTo( TypeInfo.t_enumeration ) <= 0 ) );
+			boolean valid = isValidOverload( symbol, newSymbol );//( (symbol.getType().compareTo( TypeInfo.t_class ) >= 0 ) && (symbol.getType().compareTo( TypeInfo.t_enumeration ) <= 0 ) );
+			
 			if( !valid && (symbol instanceof IParameterizedSymbol) )
 				valid = isValidFunctionOverload( (IParameterizedSymbol)symbol, (IParameterizedSymbol)newSymbol );
 			
@@ -2239,7 +2245,6 @@
 	
 	static protected class LookupData
 	{
-		
 		public Set ambiguities;
 		public String name;
 		public Map usingDirectives; 
@@ -2256,7 +2261,7 @@
 		public boolean ignoreUsingDirectives = false;
 		public boolean usingDirectivesOnly = false;
 		public boolean forUserDefinedConversion = false;
-
+		
 		public Map foundItems = null;
 		
 		public ISymbol templateInstance = null;
Index: ChangeLog
===================================================================
retrieving revision 1.156
diff -u -r1.156 ChangeLog
--- ChangeLog	17 Dec 2003 19:21:32 -0000	1.156
+++ ChangeLog	17 Dec 2003 20:26:15 -0000
@@ -1,3 +1,10 @@
+2003-12-17 Andrew Niefer
+	test changes for content assist
+	added ContextualParseTest.testCompletionLookup_FriendClass_1() 
+	added ContextualParseTest.testCompletionLookup_FriendClass_2() 
+	added ContextualParseTest.testCompletionLookup_ParametersAsLocalVariables() 
+	modified ParserSymbolTableTest.testVisibilityDetermination() 
+
 2003-12-17 Hoda Amer
 	Small modifications to cope with the new interfaces
 	
Index: parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java
===================================================================
retrieving revision 1.5
diff -u -r1.5 ContextualParseTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java	17 Dec 2003 19:21:32 -0000	1.5
+++ parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java	17 Dec 2003 20:26:17 -0000
@@ -17,11 +17,13 @@
 import org.eclipse.cdt.core.parser.ParserMode;
 import org.eclipse.cdt.core.parser.ScannerInfo;
 import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
 import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
 import org.eclipse.cdt.core.parser.ast.IASTField;
 import org.eclipse.cdt.core.parser.ast.IASTFunction;
 import org.eclipse.cdt.core.parser.ast.IASTMethod;
 import org.eclipse.cdt.core.parser.ast.IASTNode;
+import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
 import org.eclipse.cdt.core.parser.ast.IASTVariable;
 import org.eclipse.cdt.core.parser.ast.IASTNode.LookupResult;
 import org.eclipse.cdt.internal.core.parser.ParserLogService;
@@ -245,5 +247,128 @@
 		
 		assertEquals( method.getName(), "aMethod" );
 		assertEquals( baseMethod.getName(), "aPublicBaseMethod" );
+	}
+	
+	public void testCompletionLookup_FriendClass_1() throws Exception{
+		StringWriter writer = new StringWriter();
+		writer.write( "class A {" );
+		writer.write( "   private:  void aPrivateMethod();" );
+		writer.write( "   friend class C;" );
+		writer.write( "};" );
+		
+		writer.write( "class C {" );
+		writer.write( "   void foo();" );
+		writer.write( "};" );	
+		
+		writer.write( "void C::foo(){" );		
+		writer.write( "   A a;" );		
+		writer.write( "   a.a \n" );
+		
+		String code = writer.toString();
+		int index = code.indexOf( "a.a" );
+		
+		IASTCompletionNode node = parse( code, index + 3 );
+		
+		assertNotNull( node );
+		
+		String prefix = node.getCompletionPrefix();
+		assertEquals( prefix, "a" );
+		
+		assertTrue( node.getCompletionScope() instanceof IASTFunction );
+		assertEquals( node.getCompletionKind(),  IASTCompletionNode.CompletionKind.MEMBER_REFERENCE );
+		assertNotNull( node.getCompletionContext() );
+		assertTrue( node.getCompletionContext() instanceof IASTClassSpecifier );
+		
+		LookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext() );
+		assertEquals( result.getPrefix(), prefix );
+		
+		Iterator iter = result.getNodes();
+		assertTrue( iter.hasNext() );
+		
+		IASTMethod method = (IASTMethod) iter.next();
+		
+		assertFalse( iter.hasNext() );
+		
+		assertEquals( method.getName(), "aPrivateMethod" );
+	}
+	
+	public void testCompletionLookup_FriendClass_2() throws Exception{
+		StringWriter writer = new StringWriter();
+		writer.write( "class C {" );
+		writer.write( "   void foo();" );
+		writer.write( "};" );		
+		writer.write( "class A {" );
+		writer.write( "   private:  void aPrivateMethod();" );
+		writer.write( "   friend class C;" );
+		writer.write( "};" );
+
+		writer.write( "void C::foo(){" );		
+		writer.write( "   A a;" );		
+		writer.write( "   a.a \n" );
+		
+		String code = writer.toString();
+		int index = code.indexOf( "a.a" );
+		
+		IASTCompletionNode node = parse( code, index + 3 );
+		
+		assertNotNull( node );
+		
+		String prefix = node.getCompletionPrefix();
+		assertEquals( prefix, "a" );
+		
+		assertTrue( node.getCompletionScope() instanceof IASTFunction );
+		assertEquals( node.getCompletionKind(),  IASTCompletionNode.CompletionKind.MEMBER_REFERENCE );
+		assertNotNull( node.getCompletionContext() );
+		assertTrue( node.getCompletionContext() instanceof IASTClassSpecifier );
+		
+		LookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext() );
+		assertEquals( result.getPrefix(), prefix );
+		
+		Iterator iter = result.getNodes();
+		assertTrue( iter.hasNext() );
+		
+		IASTMethod method = (IASTMethod) iter.next();
+		
+		assertFalse( iter.hasNext() );
+		
+		assertEquals( method.getName(), "aPrivateMethod" );
+	}
+	
+	public void testCompletionLookup_ParametersAsLocalVariables() throws Exception{
+		StringWriter writer = new StringWriter();
+		writer.write( "int foo( int aParameter ){" );
+		writer.write( "   int aLocal;" );
+		writer.write( "   if( aLocal != 0 ){" );		
+		writer.write( "      int aBlockLocal;" );
+		writer.write( "      a \n" );
+		
+		String code = writer.toString();
+		int index = code.indexOf( " a " );
+		
+		IASTCompletionNode node = parse( code, index + 2 );
+		
+		assertNotNull( node );
+		
+		String prefix = node.getCompletionPrefix();
+		assertEquals( prefix, "a" );
+		
+		assertTrue( node.getCompletionScope() instanceof IASTCodeScope );
+		assertEquals( node.getCompletionKind(),  IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE );
+		assertNull( node.getCompletionContext() );
+				
+		LookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.LOCAL_VARIABLES }, node.getCompletionContext() );
+		assertEquals( result.getPrefix(), prefix );
+		
+		Iterator iter = result.getNodes();
+				
+		IASTVariable aBlockLocal = (IASTVariable) iter.next();
+		IASTVariable aLocal = (IASTVariable) iter.next();
+		IASTParameterDeclaration aParameter = (IASTParameterDeclaration) iter.next();
+		
+		assertFalse( iter.hasNext() );
+		
+		assertEquals( aBlockLocal.getName(), "aBlockLocal" );
+		assertEquals( aLocal.getName(), "aLocal" );
+		assertEquals( aParameter.getName(), "aParameter" );
 	}
 }
Index: parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java
===================================================================
retrieving revision 1.27
diff -u -r1.27 ParserSymbolTableTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java	10 Dec 2003 00:07:32 -0000	1.27
+++ parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java	17 Dec 2003 20:26:19 -0000
@@ -3209,20 +3209,36 @@
 	}
 	
 	/**
-	 * class A { public: static int i; };
+	 * class D { };
+	 * class A { 
+	 * 	   public: static int i; 
+	 *     private: static int j;
+	 *     friend class D;
+	 * };
 	 * class B : private A {};
 	 * class C : public B, public A {};
 	 * 
+	 * 
 	 * @throws Exception
 	 */
 	public void testVisibilityDetermination() throws Exception{
 		newTable();
 		
+		IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D", TypeInfo.t_class );
+		table.getCompilationUnit().addSymbol( D );
+		
 		IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
 		ISymbol i = table.newSymbol( "i", TypeInfo.t_int );
+		ISymbol j = table.newSymbol( "j", TypeInfo.t_int );
 		
 		table.getCompilationUnit().addSymbol( A );
+		
+		ISymbol friend = A.lookupForFriendship( "D" );
+		assertEquals( friend, D );
+		A.addFriend( friend );
+		
 		A.addSymbol( i );
+		A.addSymbol( j );
 
 		IASTCompilationUnit compUnit = new ASTCompilationUnit(table.getCompilationUnit() );
 		ISymbolASTExtension cuExtension = new StandardSymbolExtension( table.getCompilationUnit(), (ASTSymbol) compUnit );
@@ -3235,6 +3251,10 @@
 		IASTField field = new ASTField(i, null, null, null, 0, 0, 0, new ArrayList(), false, null, ASTAccessVisibility.PUBLIC );
 		ISymbolASTExtension extension = new StandardSymbolExtension( i, (ASTSymbol) field );
 		i.setASTExtension( extension );
+		
+		field = new ASTField(i, null, null, null, 0, 0, 0, new ArrayList(), false, null, ASTAccessVisibility.PRIVATE );
+		extension = new StandardSymbolExtension( j, (ASTSymbol) field );
+		j.setASTExtension( extension );
 	
 		IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", TypeInfo.t_class );
 		B.addParent( A, false, ASTAccessVisibility.PRIVATE, 0, null );
@@ -3248,6 +3268,8 @@
 		assertTrue( table.getCompilationUnit().isVisible( i, A ) );
 		assertFalse( table.getCompilationUnit().isVisible( i, B ) );
 		assertTrue( table.getCompilationUnit().isVisible(i, C ) );
+		assertTrue( D.isVisible( j, A ) );
+		assertFalse( D.isVisible( j, B ) );
 	}
 	
 	/**

Back to the top