1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 69833 - Use hashmaps during completion parse and then just sort the

prefix lookup results at the end
This commit is contained in:
Andrew Niefer 2004-07-12 18:03:48 +00:00
parent 44fdb04953
commit 993b0299f4
3 changed files with 30 additions and 49 deletions

View file

@ -26,10 +26,8 @@ import java.util.ListIterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeMap;
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;
@ -55,12 +53,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
ContainerSymbol copy = (ContainerSymbol)super.clone();
copy._usingDirectives = (_usingDirectives != Collections.EMPTY_LIST) ? (List) ((ArrayList)_usingDirectives).clone() : _usingDirectives;
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
copy._containedSymbols = ( _containedSymbols != Collections.EMPTY_MAP )? (Map)((TreeMap) _containedSymbols).clone() : _containedSymbols;
else
copy._containedSymbols = ( _containedSymbols != Collections.EMPTY_MAP )? (Map)((HashMap) _containedSymbols).clone() : _containedSymbols;
copy._containedSymbols = ( _containedSymbols != Collections.EMPTY_MAP )? (Map)((HashMap) _containedSymbols).clone() : _containedSymbols;
copy._contents = (_contents != Collections.EMPTY_LIST) ? (List) ((ArrayList)_contents).clone() : _contents;
return copy;
@ -435,11 +428,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
protected void putInContainedSymbols( String key, Object obj ){
if( _containedSymbols == Collections.EMPTY_MAP ){
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE ){
_containedSymbols = new TreeMap( new SymbolTableComparator() );
} else {
_containedSymbols = new HashMap( );
}
_containedSymbols = new HashMap( );
}
_containedSymbols.put( key, obj );
}

View file

@ -19,9 +19,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.cdt.core.parser.ParserMode;
/**
* @author aniefer
@ -43,11 +40,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
ParameterizedSymbol copy = (ParameterizedSymbol)super.clone();
copy._parameterList = ( _parameterList != Collections.EMPTY_LIST ) ? (List) ((ArrayList)_parameterList).clone() : _parameterList;
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
copy._parameterMap = ( _parameterMap != Collections.EMPTY_MAP ) ? (Map) ((TreeMap) _parameterMap).clone() : _parameterMap;
else
copy._parameterMap = ( _parameterMap != Collections.EMPTY_MAP ) ? (Map) ((HashMap) _parameterMap).clone() : _parameterMap;
copy._parameterMap = ( _parameterMap != Collections.EMPTY_MAP ) ? (Map) ((HashMap) _parameterMap).clone() : _parameterMap;
return copy;
}
@ -131,10 +124,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
if( name != null && !name.equals(ParserSymbolTable.EMPTY_NAME) )
{
if( _parameterMap == Collections.EMPTY_MAP ){
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
_parameterMap = new TreeMap( new SymbolTableComparator() );
else
_parameterMap = new HashMap( );
_parameterMap = new HashMap( );
}
if( !_parameterMap.containsKey( name ) )

View file

@ -23,7 +23,7 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
@ -326,11 +326,7 @@ public class ParserSymbolTable {
Iterator iterator = null;
if( data.isPrefixLookup() && declarations != Collections.EMPTY_MAP ){
if( declarations instanceof SortedMap ){
iterator = ((SortedMap)declarations).tailMap( data.name.toLowerCase() ).keySet().iterator();
} else {
throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError );
}
iterator = declarations.keySet().iterator();
}
String name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
@ -342,13 +338,15 @@ public class ParserSymbolTable {
obj = collectSymbol( data, obj );
if( obj != null ){
if( found == null )
found = new LinkedHashMap();
if( found == null ){
if( data.isPrefixLookup() )
found = new TreeMap( new ContainerSymbol.SymbolTableComparator() );
else
found = new LinkedHashMap();
}
found.put( name, obj );
}
}
} else {
break;
}
if( iterator != null && iterator.hasNext() ){
@ -357,6 +355,8 @@ public class ParserSymbolTable {
name = null;
}
}
if( found != null && data.isPrefixLookup() )
found = new LinkedHashMap( found );
if( found != null && !data.isPrefixLookup() ){
return found;
@ -401,13 +401,17 @@ public class ParserSymbolTable {
if( nameMatches( data, symbol.getName() ) ){
obj = collectSymbol( data, symbol );
if( obj != null ){
if( found == null )
found = new LinkedHashMap();
if( found == null ){
if( data.isPrefixLookup() )
found = new TreeMap( new ContainerSymbol.SymbolTableComparator() );
else
found = new LinkedHashMap();
}
found.put( symbol.getName(), obj );
}
}
}
return found;
return ( found instanceof TreeMap ) ? new LinkedHashMap( found ) : found;
}
}
@ -415,11 +419,7 @@ public class ParserSymbolTable {
if( parameters != Collections.EMPTY_MAP ){
iterator = null;
if( data.isPrefixLookup() ){
if( parameters instanceof SortedMap ){
iterator = ((SortedMap) parameters).tailMap( data.name.toLowerCase() ).keySet().iterator();
} else {
throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError );
}
iterator = parameters.keySet().iterator();
}
name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
@ -428,12 +428,14 @@ public class ParserSymbolTable {
obj = parameters.get( name );
obj = collectSymbol( data, obj );
if( obj != null ){
if( found == null )
found = new LinkedHashMap();
if( found == null ){
if( data.isPrefixLookup() )
found = new TreeMap( new ContainerSymbol.SymbolTableComparator() );
else
found = new LinkedHashMap();
}
found.put( name, obj );
}
} else {
break;
}
if( iterator != null && iterator.hasNext() ){
@ -443,7 +445,7 @@ public class ParserSymbolTable {
}
}
}
return found;
return ( found instanceof TreeMap ) ? new LinkedHashMap( found ) : found;
}
private static boolean nameMatches( LookupData data, String name ){
@ -452,7 +454,7 @@ public class ParserSymbolTable {
}
return name.equals( data.name );
}
private static boolean checkType( LookupData data, ISymbol symbol ) { //, TypeInfo.eType type, TypeInfo.eType upperType ){
private static boolean checkType( LookupData data, ISymbol symbol ) {
if( data.getFilter() == null ){
return true;
}