Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-patch] Symbol Table storage changes

updated and resubmitted





Andrew Niefer/Ottawa/IBM@IBMCA 
Sent by: cdt-patch-admin@xxxxxxxxxxx
01/13/2004 03:53 PM
Please respond to
cdt-patch


To
cdt-patch@xxxxxxxxxxx
cc

Subject
Re: [cdt-patch] Symbol Table storage changes






This patch replaces the last patch I sent.

For normal lookups in the symbol table, a HashMap is faster than the tree 
map, but for prefix lookups the TreeMap is faster.  So we are now using 
the HashMap for normal parses, and we use the TreeMap in the parse mode 
used by content assist.

Note that with these changes the results returned by the IASTNode.lookup 
function used by content assist are now in predictable order:  they are 
first sorted in the order of the scopes visited during the lookup and then 

they are sorted alphabetically

Core:
        Modified symbol table constructor to take a ParseMode as a 
parameter.
        Modified symbol table to use a TreeMap instead of HashMap when 
ParseMode is CONTEXTUAL_PARSE
        Modified ASTNode.lookup to throw ASTNotImplementedException if 
called when ParseMode is not CONTEXTUAL_PARSE

Core.test:
        Moved testBug48307_FriendFunction_1 & 
testBug48307_FriendFunction_2 to ContextualParseTest
        Updated ContextualParseTest now that the order of prefix lookup 
results is predictable.

Core.UI:
        Updated CompletionEngine to catch ASTNotImplementedException from 
IASTNode.lookup

tested on windows & linux

-Andrew

[attachment "01.13.04.core.txt" deleted by Andrew Niefer/Ottawa/IBM] 
[attachment "01.13.04.core.test.txt" deleted by Andrew Niefer/Ottawa/IBM] 
[attachment "01.13.04.ui.txt" deleted by Andrew Niefer/Ottawa/IBM] 
Index: parser/ChangeLog-parser
===================================================================
retrieving revision 1.19
diff -u -r1.19 ChangeLog-parser
--- parser/ChangeLog-parser	15 Jan 2004 18:06:14 -0000	1.19
+++ parser/ChangeLog-parser	15 Jan 2004 22:22:37 -0000
@@ -1,3 +1,8 @@
+2004-01-15 Andrew Niefer
+	Modified symbol table constructor to take a ParseMode as a parameter.
+	Modified symbol table to use a TreeMap instead of HashMap when ParseMode is CONTEXTUAL_PARSE
+	Modified ASTNode.lookup to throw ASTNotImplementedException if called when ParseMode is not CONTEXTUAL_PARSE
+	
 2004-01-15 Hoda Amer
 	
 2004-01-15 John Camelon
Index: parser/org/eclipse/cdt/core/parser/ParserFactory.java
===================================================================
retrieving revision 1.17
diff -u -r1.17 ParserFactory.java
--- parser/org/eclipse/cdt/core/parser/ParserFactory.java	15 Jan 2004 13:37:52 -0000	1.17
+++ parser/org/eclipse/cdt/core/parser/ParserFactory.java	15 Jan 2004 22:22:38 -0000
@@ -37,7 +37,7 @@
 		if( mode == ParserMode.QUICK_PARSE )
 			return new QuickParseASTFactory(); 
 		else
-			return new CompleteParseASTFactory( language ); 
+			return new CompleteParseASTFactory( language, mode ); 
 	}
 	
     public static IParser createParser( IScanner scanner, ISourceElementRequestor callback, ParserMode mode, ParserLanguage language, IParserLogService log ) throws ParserFactoryError
Index: parser/org/eclipse/cdt/core/parser/ast/IASTNode.java
===================================================================
retrieving revision 1.11
diff -u -r1.11 IASTNode.java
--- parser/org/eclipse/cdt/core/parser/ast/IASTNode.java	15 Jan 2004 18:06:14 -0000	1.11
+++ parser/org/eclipse/cdt/core/parser/ast/IASTNode.java	15 Jan 2004 22:22:38 -0000
@@ -66,6 +66,6 @@
 	 * @return
 	 * @throws LookupException
 	 */
-	public ILookupResult lookup( String prefix, LookupKind[] kind, IASTNode context) throws LookupException;
+	public ILookupResult lookup( String prefix, LookupKind[] kind, IASTNode context) throws LookupException, ASTNotImplementedException;
 }
 
Index: parser/org/eclipse/cdt/internal/core/parser/ContextualParser.java
===================================================================
retrieving revision 1.4
diff -u -r1.4 ContextualParser.java
--- parser/org/eclipse/cdt/internal/core/parser/ContextualParser.java	15 Jan 2004 13:37:52 -0000	1.4
+++ parser/org/eclipse/cdt/internal/core/parser/ContextualParser.java	15 Jan 2004 22:22:39 -0000
@@ -51,7 +51,7 @@
 	 */
 	public ContextualParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log) {
 		super(scanner, callback, language, log);
-		astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETE_PARSE, language);
+		astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETION_PARSE, language);
 		scanner.setASTFactory(astFactory);
 	}
 	
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java
===================================================================
retrieving revision 1.5
diff -u -r1.5 ASTNode.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java	15 Jan 2004 13:37:53 -0000	1.5
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java	15 Jan 2004 22:22:40 -0000
@@ -14,6 +14,8 @@
 import java.util.List;
 import java.util.ListIterator;
 
+import org.eclipse.cdt.core.parser.ParserMode;
+import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
 import org.eclipse.cdt.core.parser.ast.IASTNode;
 import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
 import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
@@ -31,13 +33,18 @@
 	/* (non-Javadoc)
 	 * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind, org.eclipse.cdt.core.parser.ast.IASTNode)
 	 */
-	public ILookupResult lookup(String prefix, LookupKind[] kind, IASTNode context) throws LookupException {
+	public ILookupResult lookup(String prefix, LookupKind[] kind, IASTNode context) throws LookupException, ASTNotImplementedException {
+
 		if( ! ( this instanceof ISymbolOwner ) || ( context != null && !(context instanceof ISymbolOwner) ) ){
 			return null;
 		}
 		
 		IContainerSymbol thisContainer = (IContainerSymbol) ((ISymbolOwner)this).getSymbol();
 		IContainerSymbol qualification = null;
+		
+		if( thisContainer.getSymbolTable().getParserMode() != ParserMode.COMPLETION_PARSE ){
+			throw new ASTNotImplementedException();
+		}
 		
 		if( context != null ){
 			ISymbol sym = (IContainerSymbol) ((ISymbolOwner)context).getSymbol();
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
retrieving revision 1.65
diff -u -r1.65 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	15 Jan 2004 13:37:53 -0000	1.65
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	15 Jan 2004 22:22:41 -0000
@@ -20,6 +20,7 @@
 import org.eclipse.cdt.core.parser.IToken;
 import org.eclipse.cdt.core.parser.ITokenDuple;
 import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.ParserMode;
 import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
 import org.eclipse.cdt.core.parser.ast.ASTClassKind;
 import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
@@ -115,11 +116,11 @@
 		}
     }
     
-    public CompleteParseASTFactory( ParserLanguage language )
+    public CompleteParseASTFactory( ParserLanguage language, ParserMode mode )
     {
         super();
         
-		pst = new ParserSymbolTable( language );
+		pst = new ParserSymbolTable( language, mode );
     }
 
 	/*
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java
===================================================================
retrieving revision 1.7
diff -u -r1.7 ContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java	15 Jan 2004 13:37:53 -0000	1.7
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java	15 Jan 2004 22:22:42 -0000
@@ -14,6 +14,7 @@
  
 package org.eclipse.cdt.internal.core.parser.pst;
 
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -21,7 +22,9 @@
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
+import java.util.TreeMap;
 
+import org.eclipse.cdt.core.parser.ParserMode;
 import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
 import org.eclipse.cdt.core.parser.ast.IASTMember;
 import org.eclipse.cdt.core.parser.ast.IASTNode;
@@ -51,9 +54,13 @@
 	public Object clone(){
 		ContainerSymbol copy = (ContainerSymbol)super.clone();
 			
-		copy._usingDirectives  = ( _usingDirectives != null ) ? (LinkedList) _usingDirectives.clone() : null; 
-		copy._containedSymbols = ( _containedSymbols != null )? (HashMap) _containedSymbols.clone() : null;
-
+		copy._usingDirectives  = ( _usingDirectives != null ) ? (LinkedList) _usingDirectives.clone() : null;
+		
+		if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
+			copy._containedSymbols = ( _containedSymbols != null )? (Map)((TreeMap) _containedSymbols).clone() : null;
+		else 
+			copy._containedSymbols = ( _containedSymbols != null )? (Map)((HashMap) _containedSymbols).clone() : null;
+			
 		return copy;	
 	}
 	
@@ -118,7 +125,6 @@
 					origList.add( origDecl );
 					origList.add( obj );
 			
-					declarations.remove( origDecl );
 					declarations.put( obj.getName(), origList );
 				} else	{
 					origList.add( obj );
@@ -264,7 +270,12 @@
 	 */
 	public Map getContainedSymbols(){
 		if( _containedSymbols == null ){
-			_containedSymbols = new HashMap();
+			if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE ){
+				_containedSymbols = new TreeMap( new SymbolTableComparator() );
+			} else {
+				_containedSymbols = new HashMap( );
+			}
+			
 		}
 		return _containedSymbols;
 	}
@@ -760,7 +771,6 @@
 					}
 				}
 				if( list.size() == 1 ){
-					_context.getContainedSymbols().remove( _symbol.getName() );
 					_context.getContainedSymbols().put( _symbol.getName(), list.getFirst() );
 				}
 			} else if( obj instanceof BasicSymbol ){
@@ -786,8 +796,22 @@
 		private IContainerSymbol _decl;
 		private IContainerSymbol _namespace;
 	}
-
+	
+	static protected class SymbolTableComparator implements Comparator{
+		public int compare( Object o1, Object o2 ){
+			int result = ((String) o1).compareToIgnoreCase( (String) o2 );
+			if( result == 0 ){
+				return ((String) o1).compareTo( (String) o2 );
+			}
+			return result;
+		}
+		
+		public boolean equals( Object obj ){
+			return ( obj instanceof SymbolTableComparator );
+		}
+	}
+	
 	private		LinkedList	_usingDirectives;		//collection of nominated namespaces
-	private		HashMap 	_containedSymbols;		//declarations contained by us.
+	private		Map 		_containedSymbols;		//declarations contained by us.
 
 }
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java
===================================================================
retrieving revision 1.3
diff -u -r1.3 ParameterizedSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java	15 Jan 2004 13:37:53 -0000	1.3
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java	15 Jan 2004 22:22:42 -0000
@@ -18,7 +18,9 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
+import org.eclipse.cdt.core.parser.ParserMode;
 import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Command;
 
 /**
@@ -45,8 +47,12 @@
 		ParameterizedSymbol copy = (ParameterizedSymbol)super.clone();
 			
 		copy._parameterList = ( _parameterList != null ) ? (LinkedList) _parameterList.clone() : null;
-		copy._parameterMap	= ( _parameterMap  != null ) ? (HashMap) _parameterMap.clone() : null;
 		
+		if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
+			copy._parameterMap	= ( _parameterMap  != null ) ? (Map) ((TreeMap) _parameterMap).clone() : null;
+		else 
+			copy._parameterMap	= ( _parameterMap  != null ) ? (Map) ((HashMap) _parameterMap).clone() : null;
+			
 		copy._argumentList	  = ( _argumentList != null ) ? (LinkedList) _argumentList.clone() : null;
 		copy._specializations = ( _specializations != null ) ? (LinkedList) _specializations.clone() : null;
 		
@@ -142,7 +148,10 @@
 	 */
 	public Map getParameterMap(){
 		if( _parameterMap == null ){
-			_parameterMap = new HashMap();
+			if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
+				_parameterMap = new TreeMap( new SymbolTableComparator() );
+			else 
+				_parameterMap = new HashMap( );
 		}
 		return _parameterMap;
 	}
@@ -282,7 +291,7 @@
 	}
 	
 	private 	LinkedList	_parameterList;			//have my cake
-	private 	HashMap		_parameterMap;			//and eat it too
+	private 	Map			_parameterMap;			//and eat it too
 	private		LinkedList	_specializations;		//template specializations
 	private		LinkedList	_argumentList;			//template specialization arguments
 	private 	ISymbol		_returnType;
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
===================================================================
retrieving revision 1.34
diff -u -r1.34 ParserSymbolTable.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java	15 Jan 2004 13:37:53 -0000	1.34
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java	15 Jan 2004 22:22:43 -0000
@@ -22,9 +22,11 @@
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.SortedMap;
 
 import org.eclipse.cdt.core.parser.Enum;
 import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.ParserMode;
 import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
 import org.eclipse.cdt.core.parser.ast.IASTMember;
 import org.eclipse.cdt.core.parser.ast.IASTNode;
@@ -43,10 +45,11 @@
 	/**
 	 * Constructor for ParserSymbolTable.
 	 */
-	public ParserSymbolTable( ParserLanguage language ) {
+	public ParserSymbolTable( ParserLanguage language, ParserMode mode ) {
 		super();
 		_compilationUnit = newContainerSymbol( EMPTY_NAME, TypeInfo.t_namespace );
 		_language = language;
+		_mode = mode;
 	}
 
 	public IContainerSymbol getCompilationUnit(){
@@ -301,7 +304,15 @@
 		
 		Map declarations = lookIn.getContainedSymbols();
 		
-		Iterator iterator = ( data.mode == LookupMode.PREFIX ) ? declarations.keySet().iterator() : null;
+		Iterator iterator = null;
+		if( data.mode == LookupMode.PREFIX ){
+			if( declarations instanceof SortedMap ){
+				iterator = ((SortedMap)declarations).tailMap( data.name.toLowerCase() ).keySet().iterator();
+			} else {
+				throw new ParserSymbolTableException( ParserSymbolTableException.r_InternalError );
+			}
+		}
+		
 		String name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
 		
 		while( name != null ) {
@@ -312,6 +323,8 @@
 				
 				if( obj != null )
 					found.put( name, obj );
+			} else {
+				break;
 			}
 						
 			if( iterator != null && iterator.hasNext() ){
@@ -328,7 +341,14 @@
 		if( lookIn instanceof IParameterizedSymbol ){
 			Map parameters = ((IParameterizedSymbol)lookIn).getParameterMap();
 			if( parameters != null ){
-				iterator = ( data.mode == LookupMode.PREFIX ) ? parameters.keySet().iterator() : null;
+				iterator = null;
+				if( data.mode == LookupMode.PREFIX ){
+					if( parameters instanceof SortedMap ){
+						iterator = ((SortedMap) parameters).tailMap( data.name.toLowerCase() ).keySet().iterator();
+					} else {
+						throw new ParserSymbolTableException( ParserSymbolTableException.r_InternalError );
+					}
+				}
 				name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
 				while( name != null ){
 					if( nameMatches( data, name ) ){
@@ -337,7 +357,10 @@
 						if( obj != null ){
 							found.put( name, obj );
 						}
+					} else {
+						break;
 					}
+					
 					if( iterator != null && iterator.hasNext() ){
 						name = (String) iterator.next();
 					} else {
@@ -2184,7 +2207,8 @@
 
 	//private Stack _contextStack = new Stack();
 	private IContainerSymbol _compilationUnit;
-	private ParserLanguage    _language;
+	private ParserLanguage   _language;
+	private ParserMode		 _mode;
 	private LinkedList undoList = new LinkedList();
 	private HashSet markSet = new HashSet();
 	
@@ -2194,6 +2218,10 @@
 	
 	public ParserLanguage getLanguage(){
 		return _language;
+	}
+	
+	public ParserMode getParserMode(){
+		return _mode;
 	}
 	
 	protected void pushCommand( Command command ){
Index: ChangeLog
===================================================================
retrieving revision 1.166
diff -u -r1.166 ChangeLog
--- ChangeLog	15 Jan 2004 18:05:41 -0000	1.166
+++ ChangeLog	15 Jan 2004 22:24:20 -0000
@@ -1,3 +1,7 @@
+2004-01-15 Andrew Niefer
+	Moved testBug48307_FriendFunction_1 & testBug48307_FriendFunction_2 to ContextualParseTest
+	Updated ContextualParseTest now that the order of prefix lookup results is predictable.
+
 2004-01-15 Hoda Amer
 	Moved Content Assist testing to the UI.tests plugin
 	
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
===================================================================
retrieving revision 1.48
diff -u -r1.48 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	15 Jan 2004 13:37:12 -0000	1.48
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	15 Jan 2004 22:24:23 -0000
@@ -32,7 +32,6 @@
 import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
 import org.eclipse.cdt.core.parser.ast.IASTMethod;
 import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
-import org.eclipse.cdt.core.parser.ast.IASTNode;
 import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
 import org.eclipse.cdt.core.parser.ast.IASTReference;
 import org.eclipse.cdt.core.parser.ast.IASTScope;
@@ -42,7 +41,6 @@
 import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
 import org.eclipse.cdt.core.parser.ast.IASTVariable;
 import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
-import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
 import org.eclipse.cdt.internal.core.parser.ParserException;
 
 
@@ -1159,49 +1157,5 @@
 		foo = (IASTFunction)i.next();
 		assertTrue( foo.takesVarArgs() );
 		assertAllReferences( 1, createTaskList( new Task( foo ) ) );
-	}
-	
-	public void testBug48307_FriendFunction_1() throws Exception {
-		StringWriter writer = new StringWriter();
-		writer.write( "class A{ public : void foo(); }; " );
-		writer.write( "class B{ ");
-		writer.write( "   private : int aPrivate;" );
-		writer.write( "   friend void A::foo(); ");
-		writer.write( "};" );
-		writer.write( "void A::foo(){}" );
-		
-		Iterator i = parse( writer.toString() ).getDeclarations();
-		
-		IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
-		IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
-		IASTMethod method = (IASTMethod) i.next();
-		
-		ILookupResult result = method.lookup( "a", new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL }, classB );
-
-		assertEquals( result.getResultsSize(), 1 );
-		IASTField field = (IASTField) result.getNodes().next();
-		assertEquals( field.getName(), "aPrivate" );
-	}
-
-	public void testBug48307_FriendFunction_2() throws Exception {
-		StringWriter writer = new StringWriter();
-		writer.write( "void global();" );
-		writer.write( "class B{ ");
-		writer.write( "   private : int aPrivate;" );
-		writer.write( "   friend void global(); ");
-		writer.write( "};" );
-		writer.write( "void global(){}" );
-				
-		Iterator i = parse( writer.toString() ).getDeclarations();
-		
-		IASTFunction functionDecl  = (IASTFunction) i.next();
-		IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
-		IASTFunction functionDef = (IASTFunction) i.next();
-		
-		ILookupResult result = functionDef.lookup( "a", new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL }, classB );
-
-		assertEquals( result.getResultsSize(), 1 );
-		IASTField field = (IASTField) result.getNodes().next();
-		assertEquals( field.getName(), "aPrivate" );
 	}
 }
Index: parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java
===================================================================
retrieving revision 1.9
diff -u -r1.9 ContextualParseTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java	15 Jan 2004 13:37:12 -0000	1.9
+++ parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java	15 Jan 2004 22:24:23 -0000
@@ -26,8 +26,8 @@
 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.LookupKind;
 import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
+import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
 import org.eclipse.cdt.internal.core.parser.ParserLogService;
 
 /**
@@ -150,12 +150,14 @@
 			Iterator iter = result.getNodes();
 			
 			IASTVariable anotherVar = (IASTVariable) iter.next();
+			
+			IASTVariable aVar = (IASTVariable) iter.next();
+			
 			if( i != 0 )
 			{
 				IASTFunction foo = (IASTFunction) iter.next();
 				assertEquals( foo.getName(), "foo");
 			}
-			IASTVariable aVar = (IASTVariable) iter.next();
 					
 			assertFalse( iter.hasNext() );
 			assertEquals( anotherVar.getName(), "anotherVar" );
@@ -198,18 +200,8 @@
 		
 		Iterator iter = result.getNodes();
 		
-		IASTMethod aMethod = null;
-		IASTField aField = null;
-		
-		//we can't currently predict the order in this case
-		for( int i = 1; i <= 2; i++ ){
-			IASTNode astNode = (IASTNode) iter.next();
-			if( astNode instanceof IASTMethod ){
-				aMethod = (IASTMethod) astNode;
-			} else{
-				aField = (IASTField) astNode;
-			}
-		}
+		IASTField aField = (IASTField) iter.next();
+		IASTMethod aMethod = (IASTMethod) iter.next();
 		
 		assertFalse( iter.hasNext() );
 		
@@ -561,5 +553,53 @@
 		
 		ILookupResult result = inquestion.lookup( "a", kinds, null );
 		assertEquals(result.getResultsSize(), 3 );
+	}
+	
+	public void testBug48307_FriendFunction_1() throws Exception {
+		StringWriter writer = new StringWriter();
+		writer.write( "class A{ public : void foo(); }; " );
+		writer.write( "class B{ ");
+		writer.write( "   private : int aPrivate;" );
+		writer.write( "   friend void A::foo(); ");
+		writer.write( "};" );
+		writer.write( "void A::foo(){" );
+		writer.write( "   B b;");
+		writer.write( "   b.aP" );
+		
+		String code = writer.toString();
+		int index = code.indexOf( "b.aP" );
+		IASTCompletionNode node = parse( code, index + 4  );
+		
+		ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), 
+				new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL }, 
+				node.getCompletionContext() );
+
+		assertEquals( result.getResultsSize(), 1 );
+		IASTField field = (IASTField) result.getNodes().next();
+		assertEquals( field.getName(), "aPrivate" );
+	}
+
+	public void testBug48307_FriendFunction_2() throws Exception {
+		StringWriter writer = new StringWriter();
+		writer.write( "void global();" );
+		writer.write( "class B{ ");
+		writer.write( "   private : int aPrivate;" );
+		writer.write( "   friend void global(); ");
+		writer.write( "};" );
+		writer.write( "void global(){" );
+		writer.write( "   B b;");
+		writer.write( "   b.aP" );
+		
+		String code = writer.toString();
+		int index = code.indexOf( "b.aP" );
+		IASTCompletionNode node = parse( code, index + 4  );
+		
+		ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), 
+				new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL }, 
+				node.getCompletionContext() );
+
+		assertEquals( result.getResultsSize(), 1 );
+		IASTField field = (IASTField) result.getNodes().next();
+		assertEquals( field.getName(), "aPrivate" );
 	}
 }
Index: parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java
===================================================================
retrieving revision 1.30
diff -u -r1.30 ParserSymbolTableTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java	15 Jan 2004 13:37:12 -0000	1.30
+++ parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java	15 Jan 2004 22:24:24 -0000
@@ -20,6 +20,7 @@
 import junit.framework.TestCase;
 
 import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.ParserMode;
 import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
 import org.eclipse.cdt.core.parser.ast.ASTClassKind;
 import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
@@ -66,11 +67,11 @@
 	}
 	
 	public ParserSymbolTable newTable(){
-		return newTable( ParserLanguage.CPP );
+		return newTable( ParserLanguage.CPP, ParserMode.COMPLETE_PARSE );
 	}
 	
-	public ParserSymbolTable newTable( ParserLanguage language ){
-		table = new ParserSymbolTable( language );
+	public ParserSymbolTable newTable( ParserLanguage language, ParserMode mode ){
+		table = new ParserSymbolTable( language, mode );
 		return table;
 	}
 	/**
@@ -3011,7 +3012,7 @@
 	 * }
 	 */
 	public void testPrefixLookup_Unqualified() throws Exception {
-		newTable();
+		newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE );
 		
 		ISymbol aVar = table.newSymbol( "aVar", TypeInfo.t_int );
 		table.getCompilationUnit().addSymbol( aVar );
@@ -3042,7 +3043,7 @@
 	 * d.a(CTRL+SPACE)
 	 */
 	public void testPrefixLookup_Qualified() throws Exception {
-		newTable();
+		newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE );
 		
 		ISymbol aVar = table.newSymbol( "aVar", TypeInfo.t_int );
 		table.getCompilationUnit().addSymbol( aVar );
@@ -3082,7 +3083,7 @@
 	 * @throws Exception
 	 */
 	public void testPrefixLookup_Inheritance() throws Exception {
-		newTable();
+		newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE );
 		
 		IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
 		table.getCompilationUnit().addSymbol( A );
@@ -3143,7 +3144,7 @@
 	 * @throws Exception
 	 */
 	public void testPrefixLookup_Ambiguities() throws Exception{
-		newTable();
+		newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE );
 		
 		ISymbol aa = table.newSymbol( "aa", TypeInfo.t_int );
 		table.getCompilationUnit().addSymbol( aa );
@@ -3288,7 +3289,7 @@
 	 * @throws Exception
 	 */
 	public void testPrefixFiltering() throws Exception{
-		newTable();
+		newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE );
 		IDerivableContainerSymbol a1 = table.newDerivableContainerSymbol( "a1", TypeInfo.t_struct );
 		table.getCompilationUnit().addSymbol( a1 );
 		
Index: ChangeLog
===================================================================
retrieving revision 1.242
diff -u -r1.242 ChangeLog
--- ChangeLog	15 Jan 2004 18:05:58 -0000	1.242
+++ ChangeLog	15 Jan 2004 22:25:18 -0000
@@ -1,3 +1,6 @@
+2004-01-13 Andrew Niefer
+	Updated CompletionEngine to catch ASTNotImplementedException from IASTNode.lookup
+
 2004-01-15 Hoda Amer
 	Moved Content Assist log to the UI plugin
 	
Index: src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java
===================================================================
retrieving revision 1.13
diff -u -r1.13 CompletionEngine.java
--- src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java	15 Jan 2004 18:05:58 -0000	1.13
+++ src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java	15 Jan 2004 22:25:26 -0000
@@ -32,6 +32,7 @@
 import org.eclipse.cdt.core.parser.ParserUtil;
 import org.eclipse.cdt.core.parser.ScannerInfo;
 import org.eclipse.cdt.core.parser.ast.ASTClassKind;
+import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
 import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
 import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
 import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
@@ -400,6 +401,10 @@
 		} catch (IASTNode.LookupException ilk ){
 			// do we want to do something here?
 			ilk.printStackTrace();
+			return null;
+		} catch (ASTNotImplementedException e) {
+			// shouldn't happen
+			e.printStackTrace();
 			return null;
 		}
 	}

Back to the top