mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Start of removing java.util containers from the symbol table.
This commit is contained in:
parent
1e11fc16ef
commit
658a98966c
11 changed files with 581 additions and 183 deletions
|
@ -14,7 +14,6 @@ package org.eclipse.cdt.core.parser.tests;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
@ -44,6 +43,7 @@ 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;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
|
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider;
|
import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,13 +89,12 @@ public class ParserSymbolTableTest extends TestCase {
|
||||||
IContainerSymbol compUnit = table.getCompilationUnit();
|
IContainerSymbol compUnit = table.getCompilationUnit();
|
||||||
compUnit.addSymbol( x );
|
compUnit.addSymbol( x );
|
||||||
|
|
||||||
Map declarations = compUnit.getContainedSymbols();
|
ObjectMap declarations = compUnit.getContainedSymbols();
|
||||||
assertEquals( 1, declarations.size() );
|
assertEquals( 1, declarations.size() );
|
||||||
|
|
||||||
Iterator iter = declarations.values().iterator();
|
ISymbol contained = (ISymbol) declarations.getAt( 0 );
|
||||||
ISymbol contained = (ISymbol) iter.next();
|
|
||||||
|
|
||||||
assertEquals( false, iter.hasNext() );
|
assertEquals( declarations.size(), 1 );
|
||||||
assertEquals( x, contained );
|
assertEquals( x, contained );
|
||||||
assertEquals( contained.getName(), "x" ); //$NON-NLS-1$
|
assertEquals( contained.getName(), "x" ); //$NON-NLS-1$
|
||||||
assertEquals( table.getTypeInfoProvider().numAllocated(), 0 );
|
assertEquals( table.getTypeInfoProvider().numAllocated(), 0 );
|
||||||
|
@ -3445,74 +3444,74 @@ public class ParserSymbolTableTest extends TestCase {
|
||||||
assertEquals( table.getTypeInfoProvider().numAllocated(), 0 );
|
assertEquals( table.getTypeInfoProvider().numAllocated(), 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug52111RemoveSymbol() throws Exception{
|
// public void testBug52111RemoveSymbol() throws Exception{
|
||||||
newTable();
|
// newTable();
|
||||||
|
//
|
||||||
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$
|
// IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", ITypeInfo.t_class ); //$NON-NLS-1$
|
||||||
table.getCompilationUnit().addSymbol( A );
|
// table.getCompilationUnit().addSymbol( A );
|
||||||
|
//
|
||||||
ISymbol i = table.newSymbol( "i", ITypeInfo.t_int ); //$NON-NLS-1$
|
// ISymbol i = table.newSymbol( "i", ITypeInfo.t_int ); //$NON-NLS-1$
|
||||||
A.addSymbol( i );
|
// A.addSymbol( i );
|
||||||
|
//
|
||||||
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$
|
// IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$
|
||||||
A.addSymbol( f1 );
|
// A.addSymbol( f1 );
|
||||||
|
//
|
||||||
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$
|
// IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", ITypeInfo.t_function ); //$NON-NLS-1$
|
||||||
f2.addParameter( ITypeInfo.t_int, 0, null, false );
|
// f2.addParameter( ITypeInfo.t_int, 0, null, false );
|
||||||
|
//
|
||||||
A.addSymbol( f2 );
|
// A.addSymbol( f2 );
|
||||||
|
//
|
||||||
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$
|
// IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", ITypeInfo.t_class ); //$NON-NLS-1$
|
||||||
B.addParent( A );
|
// B.addParent( A );
|
||||||
|
//
|
||||||
table.getCompilationUnit().addSymbol( B );
|
// table.getCompilationUnit().addSymbol( B );
|
||||||
|
//
|
||||||
ISymbol look = B.qualifiedLookup( "i" ); //$NON-NLS-1$
|
// ISymbol look = B.qualifiedLookup( "i" ); //$NON-NLS-1$
|
||||||
assertEquals( look, i );
|
// assertEquals( look, i );
|
||||||
|
//
|
||||||
Iterator iter = A.getContentsIterator();
|
// Iterator iter = A.getContentsIterator();
|
||||||
assertEquals( iter.next(), i );
|
// assertEquals( iter.next(), i );
|
||||||
assertEquals( iter.next(), f1 );
|
// assertEquals( iter.next(), f1 );
|
||||||
assertEquals( iter.next(), f2 );
|
// assertEquals( iter.next(), f2 );
|
||||||
assertFalse( iter.hasNext() );
|
// assertFalse( iter.hasNext() );
|
||||||
|
//
|
||||||
assertTrue( A.removeSymbol( i ) );
|
// assertTrue( A.removeSymbol( i ) );
|
||||||
|
//
|
||||||
iter = A.getContentsIterator();
|
// iter = A.getContentsIterator();
|
||||||
assertEquals( iter.next(), f1 );
|
// assertEquals( iter.next(), f1 );
|
||||||
assertEquals( iter.next(), f2 );
|
// assertEquals( iter.next(), f2 );
|
||||||
assertFalse( iter.hasNext() );
|
// assertFalse( iter.hasNext() );
|
||||||
|
//
|
||||||
look = B.qualifiedLookup( "i" ); //$NON-NLS-1$
|
// look = B.qualifiedLookup( "i" ); //$NON-NLS-1$
|
||||||
assertNull( look );
|
// assertNull( look );
|
||||||
|
//
|
||||||
List params = new ArrayList();
|
// List params = new ArrayList();
|
||||||
|
//
|
||||||
look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$
|
// look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$
|
||||||
assertEquals( look, f1 );
|
// assertEquals( look, f1 );
|
||||||
|
//
|
||||||
assertTrue( A.removeSymbol( f1 ) );
|
// assertTrue( A.removeSymbol( f1 ) );
|
||||||
iter = A.getContentsIterator();
|
// iter = A.getContentsIterator();
|
||||||
assertEquals( iter.next(), f2 );
|
// assertEquals( iter.next(), f2 );
|
||||||
assertFalse( iter.hasNext() );
|
// assertFalse( iter.hasNext() );
|
||||||
|
//
|
||||||
look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$
|
// look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$
|
||||||
assertNull( look );
|
// assertNull( look );
|
||||||
|
//
|
||||||
params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) );
|
// params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) );
|
||||||
look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$
|
// look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$
|
||||||
|
//
|
||||||
assertEquals( look, f2 );
|
// assertEquals( look, f2 );
|
||||||
assertTrue( A.removeSymbol( f2 ) );
|
// assertTrue( A.removeSymbol( f2 ) );
|
||||||
|
//
|
||||||
iter = A.getContentsIterator();
|
// iter = A.getContentsIterator();
|
||||||
assertFalse( iter.hasNext() );
|
// assertFalse( iter.hasNext() );
|
||||||
|
//
|
||||||
look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$
|
// look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$
|
||||||
assertNull( look );
|
// assertNull( look );
|
||||||
|
//
|
||||||
assertEquals( A.getContainedSymbols().size(), 0 );
|
// assertEquals( A.getContainedSymbols().size(), 0 );
|
||||||
assertEquals( table.getTypeInfoProvider().numAllocated(), 0 );
|
// assertEquals( table.getTypeInfoProvider().numAllocated(), 0 );
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -32,6 +31,8 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMember;
|
import org.eclipse.cdt.core.parser.ast.IASTMember;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData;
|
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -53,7 +54,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
ContainerSymbol copy = (ContainerSymbol)super.clone();
|
ContainerSymbol copy = (ContainerSymbol)super.clone();
|
||||||
|
|
||||||
copy._usingDirectives = (_usingDirectives != Collections.EMPTY_LIST) ? (List) ((ArrayList)_usingDirectives).clone() : _usingDirectives;
|
copy._usingDirectives = (_usingDirectives != Collections.EMPTY_LIST) ? (List) ((ArrayList)_usingDirectives).clone() : _usingDirectives;
|
||||||
copy._containedSymbols = ( _containedSymbols != Collections.EMPTY_MAP )? (Map)((HashMap) _containedSymbols).clone() : _containedSymbols;
|
copy._containedSymbols = (ObjectMap) ( ( _containedSymbols != ObjectMap.EMPTY_MAP )? _containedSymbols.clone() : _containedSymbols );
|
||||||
copy._contents = (_contents != Collections.EMPTY_LIST) ? (List) ((ArrayList)_contents).clone() : _contents;
|
copy._contents = (_contents != Collections.EMPTY_LIST) ? (List) ((ArrayList)_contents).clone() : _contents;
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
|
@ -242,41 +243,41 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
// getSymbolTable().pushCommand( command );
|
// getSymbolTable().pushCommand( command );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeSymbol( ISymbol symbol ){
|
// public boolean removeSymbol( ISymbol symbol ){
|
||||||
boolean removed = false;
|
// boolean removed = false;
|
||||||
|
//
|
||||||
Map contained = getContainedSymbols();
|
// StringObjectMap contained = getContainedSymbols();
|
||||||
|
//
|
||||||
if( symbol != null && contained.containsKey( symbol.getName() ) ){
|
// if( symbol != null && contained.containsKey( symbol.getName() ) ){
|
||||||
Object obj = contained.get( symbol.getName() );
|
// Object obj = contained.get( symbol.getName() );
|
||||||
if( obj instanceof ISymbol ){
|
// if( obj instanceof ISymbol ){
|
||||||
if( obj == symbol ){
|
// if( obj == symbol ){
|
||||||
contained.remove( symbol.getName() );
|
// contained.remove( symbol.getName() );
|
||||||
removed = true;
|
// removed = true;
|
||||||
}
|
// }
|
||||||
} else if ( obj instanceof List ){
|
// } else if ( obj instanceof List ){
|
||||||
List list = (List) obj;
|
// List list = (List) obj;
|
||||||
if( list.remove( symbol ) ){
|
// if( list.remove( symbol ) ){
|
||||||
if( list.size() == 1 ){
|
// if( list.size() == 1 ){
|
||||||
contained.put( symbol.getName(), list.get( 0 ) );
|
// contained.put( symbol.getName(), list.get( 0 ) );
|
||||||
}
|
// }
|
||||||
removed = true;
|
// removed = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if( removed ){
|
// if( removed ){
|
||||||
ListIterator iter = getContents().listIterator( getContents().size() );
|
// ListIterator iter = getContents().listIterator( getContents().size() );
|
||||||
while( iter.hasPrevious() ){
|
// while( iter.hasPrevious() ){
|
||||||
if( iter.previous() == symbol ){
|
// if( iter.previous() == symbol ){
|
||||||
iter.remove();
|
// iter.remove();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return removed;
|
// return removed;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#hasUsingDirectives()
|
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#hasUsingDirectives()
|
||||||
|
@ -422,13 +423,13 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getContainedSymbols()
|
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getContainedSymbols()
|
||||||
*/
|
*/
|
||||||
public Map getContainedSymbols(){
|
public ObjectMap getContainedSymbols(){
|
||||||
return _containedSymbols;
|
return _containedSymbols;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void putInContainedSymbols( String key, Object obj ){
|
protected void putInContainedSymbols( String key, Object obj ){
|
||||||
if( _containedSymbols == Collections.EMPTY_MAP ){
|
if( _containedSymbols == ObjectMap.EMPTY_MAP ){
|
||||||
_containedSymbols = new HashMap( );
|
_containedSymbols = new ObjectMap( 4 );
|
||||||
}
|
}
|
||||||
_containedSymbols.put( key, obj );
|
_containedSymbols.put( key, obj );
|
||||||
}
|
}
|
||||||
|
@ -667,7 +668,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
public IParameterizedSymbol unqualifiedFunctionLookup( String name, final List parameters ) throws ParserSymbolTableException{
|
public IParameterizedSymbol unqualifiedFunctionLookup( String name, final List parameters ) throws ParserSymbolTableException{
|
||||||
//figure out the set of associated scopes first, so we can remove those that are searched
|
//figure out the set of associated scopes first, so we can remove those that are searched
|
||||||
//during the normal lookup to avoid doing them twice
|
//during the normal lookup to avoid doing them twice
|
||||||
final HashSet associated = new HashSet();
|
final ObjectSet associated = new ObjectSet(0);
|
||||||
|
|
||||||
//collect associated namespaces & classes.
|
//collect associated namespaces & classes.
|
||||||
int size = ( parameters == null ) ? 0 : parameters.size();
|
int size = ( parameters == null ) ? 0 : parameters.size();
|
||||||
|
@ -699,11 +700,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
}
|
}
|
||||||
|
|
||||||
LookupData data = new LookupData( name ){
|
LookupData data = new LookupData( name ){
|
||||||
public HashSet getAssociated() { return assoc; }
|
public ObjectSet getAssociated() { return assoc; }
|
||||||
public List getParameters() { return params; }
|
public List getParameters() { return params; }
|
||||||
public TypeFilter getFilter() { return FUNCTION_FILTER; }
|
public TypeFilter getFilter() { return FUNCTION_FILTER; }
|
||||||
|
|
||||||
final private HashSet assoc = associated;
|
final private ObjectSet assoc = associated;
|
||||||
final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
|
final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -722,13 +723,13 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
//dump the hash to an array and iterate over the array because we
|
//dump the hash to an array and iterate over the array because we
|
||||||
//could be removing items from the collection as we go and we don't
|
//could be removing items from the collection as we go and we don't
|
||||||
//want to get ConcurrentModificationExceptions
|
//want to get ConcurrentModificationExceptions
|
||||||
Object [] scopes = associated.toArray();
|
Object [] scopes = associated.keyArray();
|
||||||
|
|
||||||
size = associated.size();
|
size = associated.size();
|
||||||
|
|
||||||
for( int i = 0; i < size; i++ ){
|
for( int i = 0; i < size; i++ ){
|
||||||
associatedScope = (IContainerSymbol) scopes[ i ];
|
associatedScope = (IContainerSymbol) scopes[ i ];
|
||||||
if( associated.contains( associatedScope ) ){
|
if( associated.containsKey( associatedScope ) ){
|
||||||
data.qualified = true;
|
data.qualified = true;
|
||||||
data.ignoreUsingDirectives = true;
|
data.ignoreUsingDirectives = true;
|
||||||
data.usingDirectivesOnly = false;
|
data.usingDirectivesOnly = false;
|
||||||
|
@ -1191,7 +1192,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
|
|
||||||
private List _contents = Collections.EMPTY_LIST; //ordered list of all contents of this symbol
|
private List _contents = Collections.EMPTY_LIST; //ordered list of all contents of this symbol
|
||||||
private List _usingDirectives = Collections.EMPTY_LIST; //collection of nominated namespaces
|
private List _usingDirectives = Collections.EMPTY_LIST; //collection of nominated namespaces
|
||||||
private Map _containedSymbols = Collections.EMPTY_MAP; //declarations contained by us.
|
private ObjectMap _containedSymbols = ObjectMap.EMPTY_MAP; //declarations contained by us.
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addTemplateId(org.eclipse.cdt.internal.core.parser.pst.ISymbol, java.util.List)
|
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addTemplateId(org.eclipse.cdt.internal.core.parser.pst.ISymbol, java.util.List)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,8 +15,8 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -40,7 +40,7 @@ public interface IContainerSymbol extends ISymbol {
|
||||||
|
|
||||||
public void addTemplateId( ISymbol symbol, List args ) throws ParserSymbolTableException;
|
public void addTemplateId( ISymbol symbol, List args ) throws ParserSymbolTableException;
|
||||||
|
|
||||||
public boolean removeSymbol( ISymbol symbol );
|
// public boolean removeSymbol( ISymbol symbol );
|
||||||
|
|
||||||
public boolean hasUsingDirectives();
|
public boolean hasUsingDirectives();
|
||||||
public List getUsingDirectives();
|
public List getUsingDirectives();
|
||||||
|
@ -73,7 +73,7 @@ public interface IContainerSymbol extends ISymbol {
|
||||||
public IUsingDeclarationSymbol addUsingDeclaration( String name ) throws ParserSymbolTableException;
|
public IUsingDeclarationSymbol addUsingDeclaration( String name ) throws ParserSymbolTableException;
|
||||||
public IUsingDeclarationSymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException;
|
public IUsingDeclarationSymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException;
|
||||||
|
|
||||||
public Map getContainedSymbols();
|
public ObjectMap getContainedSymbols();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup symbols matching the given prefix
|
* Lookup symbols matching the given prefix
|
||||||
|
|
|
@ -16,7 +16,6 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -31,6 +30,8 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMember;
|
import org.eclipse.cdt.core.parser.ast.IASTMember;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
|
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -247,8 +248,8 @@ public class ParserSymbolTable {
|
||||||
temp = (IContainerSymbol) directives.get(i);
|
temp = (IContainerSymbol) directives.get(i);
|
||||||
|
|
||||||
//namespaces are searched at most once
|
//namespaces are searched at most once
|
||||||
if( !data.visited.contains( temp ) ){
|
if( !data.visited.containsKey( temp ) ){
|
||||||
data.visited.add( temp );
|
data.visited.put( temp );
|
||||||
|
|
||||||
Map map = lookupInContained( data, temp );
|
Map map = lookupInContained( data, temp );
|
||||||
foundSomething = ( map != null && !map.isEmpty() );
|
foundSomething = ( map != null && !map.isEmpty() );
|
||||||
|
@ -322,18 +323,19 @@ public class ParserSymbolTable {
|
||||||
data.getAssociated().remove( lookIn );
|
data.getAssociated().remove( lookIn );
|
||||||
}
|
}
|
||||||
|
|
||||||
Map declarations = lookIn.getContainedSymbols();
|
ObjectMap declarations = lookIn.getContainedSymbols();
|
||||||
|
|
||||||
Iterator iterator = null;
|
int numKeys = -1;
|
||||||
|
int idx = 0;
|
||||||
if( data.isPrefixLookup() && declarations != Collections.EMPTY_MAP ){
|
if( data.isPrefixLookup() && declarations != Collections.EMPTY_MAP ){
|
||||||
iterator = declarations.keySet().iterator();
|
numKeys = declarations.size();//iterator = declarations.keySet().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
|
String name = ( numKeys > 0 ) ? (String) declarations.keyAt( idx++ ) : data.name;
|
||||||
|
|
||||||
while( name != null ) {
|
while( name != null ) {
|
||||||
if( nameMatches( data, name ) ){
|
if( nameMatches( data, name ) ){
|
||||||
obj = ( !declarations.isEmpty() ) ? declarations.get( name ) : null;
|
obj = ( declarations.size() > 0 ) ? declarations.get( name ) : null;
|
||||||
if( obj != null ){
|
if( obj != null ){
|
||||||
obj = collectSymbol( data, obj );
|
obj = collectSymbol( data, obj );
|
||||||
|
|
||||||
|
@ -348,12 +350,10 @@ public class ParserSymbolTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( idx < numKeys )
|
||||||
if( iterator != null && iterator.hasNext() ){
|
name = (String) declarations.keyAt( idx++ );
|
||||||
name = (String) iterator.next();
|
else
|
||||||
} else {
|
name = null;
|
||||||
name = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if( found != null && data.isPrefixLookup() )
|
if( found != null && data.isPrefixLookup() )
|
||||||
found = new LinkedHashMap( found );
|
found = new LinkedHashMap( found );
|
||||||
|
@ -478,8 +478,8 @@ public class ParserSymbolTable {
|
||||||
int objListSize = ( objList != null ) ? objList.size() : 0;
|
int objListSize = ( objList != null ) ? objList.size() : 0;
|
||||||
ISymbol symbol = ( objList != null ) ? (ISymbol) objList.get( 0 ) : (ISymbol) object;
|
ISymbol symbol = ( objList != null ) ? (ISymbol) objList.get( 0 ) : (ISymbol) object;
|
||||||
|
|
||||||
Set functionSet = new HashSet();
|
ObjectSet functionSet = ObjectSet.EMPTY_SET;
|
||||||
Set templateFunctionSet = new HashSet();
|
ObjectSet templateFunctionSet = ObjectSet.EMPTY_SET;
|
||||||
|
|
||||||
ISymbol obj = null;
|
ISymbol obj = null;
|
||||||
IContainerSymbol cls = null;
|
IContainerSymbol cls = null;
|
||||||
|
@ -500,9 +500,13 @@ public class ParserSymbolTable {
|
||||||
foundSymbol = foundSymbol.getForwardSymbol();
|
foundSymbol = foundSymbol.getForwardSymbol();
|
||||||
}
|
}
|
||||||
if( foundSymbol.getContainingSymbol().isType( ITypeInfo.t_template ) ){
|
if( foundSymbol.getContainingSymbol().isType( ITypeInfo.t_template ) ){
|
||||||
templateFunctionSet.add( foundSymbol );
|
if( templateFunctionSet == ObjectSet.EMPTY_SET )
|
||||||
|
templateFunctionSet = new ObjectSet( 2 );
|
||||||
|
templateFunctionSet.put( foundSymbol );
|
||||||
} else {
|
} else {
|
||||||
functionSet.add( foundSymbol );
|
if( functionSet == ObjectSet.EMPTY_SET )
|
||||||
|
functionSet = new ObjectSet( 2 );
|
||||||
|
functionSet.put( foundSymbol );
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -561,24 +565,19 @@ public class ParserSymbolTable {
|
||||||
ambiguous = true;
|
ambiguous = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator fnIter = null;
|
|
||||||
IParameterizedSymbol fn = null;
|
IParameterizedSymbol fn = null;
|
||||||
if( !templateFunctionSet.isEmpty() ){
|
if( numTemplateFunctions > 0 ){
|
||||||
fnIter = templateFunctionSet.iterator();
|
for( int i = 0; i < numTemplateFunctions; i++ ){
|
||||||
|
fn = (IParameterizedSymbol) templateFunctionSet.keyAt( i );
|
||||||
for( int i = numTemplateFunctions; i > 0; i-- ){
|
|
||||||
fn = (IParameterizedSymbol) fnIter.next();
|
|
||||||
if( cls.getContainingSymbol()!= fn.getContainingSymbol()){
|
if( cls.getContainingSymbol()!= fn.getContainingSymbol()){
|
||||||
ambiguous = true;
|
ambiguous = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( !functionSet.isEmpty() ){
|
if( numFunctions > 0 ){
|
||||||
fnIter = functionSet.iterator();
|
for( int i = 0; i < numFunctions; i++ ){
|
||||||
|
fn = (IParameterizedSymbol) functionSet.keyAt( i );
|
||||||
for( int i = numFunctions; i > 0; i-- ){
|
|
||||||
fn = (IParameterizedSymbol) fnIter.next();
|
|
||||||
if( cls.getContainingSymbol()!= fn.getContainingSymbol()){
|
if( cls.getContainingSymbol()!= fn.getContainingSymbol()){
|
||||||
ambiguous = true;
|
ambiguous = true;
|
||||||
break;
|
break;
|
||||||
|
@ -590,10 +589,15 @@ public class ParserSymbolTable {
|
||||||
if( numTemplateFunctions > 0 ){
|
if( numTemplateFunctions > 0 ){
|
||||||
if( data.getParameters() != null && ( !data.exactFunctionsOnly || data.getTemplateParameters() != null ) ){
|
if( data.getParameters() != null && ( !data.exactFunctionsOnly || data.getTemplateParameters() != null ) ){
|
||||||
List fns = TemplateEngine.selectTemplateFunctions( templateFunctionSet, data.getParameters(), data.getTemplateParameters() );
|
List fns = TemplateEngine.selectTemplateFunctions( templateFunctionSet, data.getParameters(), data.getTemplateParameters() );
|
||||||
if( fns != null )
|
if( fns != null ){
|
||||||
|
if( functionSet == ObjectSet.EMPTY_SET )
|
||||||
|
functionSet = new ObjectSet( fns.size() );
|
||||||
functionSet.addAll( fns );
|
functionSet.addAll( fns );
|
||||||
|
}
|
||||||
numFunctions = functionSet.size();
|
numFunctions = functionSet.size();
|
||||||
} else {
|
} else {
|
||||||
|
if( functionSet == ObjectSet.EMPTY_SET )
|
||||||
|
functionSet = new ObjectSet( templateFunctionSet.size() );
|
||||||
functionSet.addAll( templateFunctionSet );
|
functionSet.addAll( templateFunctionSet );
|
||||||
numFunctions += numTemplateFunctions;
|
numFunctions += numTemplateFunctions;
|
||||||
}
|
}
|
||||||
|
@ -606,7 +610,7 @@ public class ParserSymbolTable {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
} else if( numFunctions > 0 ) {
|
} else if( numFunctions > 0 ) {
|
||||||
return new ArrayList( functionSet );
|
return functionSet.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ambiguous ){
|
if( ambiguous ){
|
||||||
|
@ -648,9 +652,9 @@ public class ParserSymbolTable {
|
||||||
|
|
||||||
//use data to detect circular inheritance
|
//use data to detect circular inheritance
|
||||||
if( data.inheritanceChain == null )
|
if( data.inheritanceChain == null )
|
||||||
data.inheritanceChain = new HashSet();
|
data.inheritanceChain = new ObjectSet( 2 );
|
||||||
|
|
||||||
data.inheritanceChain.add( container );
|
data.inheritanceChain.put( container );
|
||||||
|
|
||||||
int size = scopes.size();
|
int size = scopes.size();
|
||||||
for( int i = 0; i < size; i++ )
|
for( int i = 0; i < size; i++ )
|
||||||
|
@ -660,9 +664,9 @@ public class ParserSymbolTable {
|
||||||
if( parent == null )
|
if( parent == null )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( !wrapper.isVirtual() || !data.visited.contains( parent ) ){
|
if( !wrapper.isVirtual() || !data.visited.containsKey( parent ) ){
|
||||||
if( wrapper.isVirtual() ){
|
if( wrapper.isVirtual() ){
|
||||||
data.visited.add( parent );
|
data.visited.put( parent );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( parent instanceof IDeferredTemplateInstance ){
|
if( parent instanceof IDeferredTemplateInstance ){
|
||||||
|
@ -673,7 +677,7 @@ public class ParserSymbolTable {
|
||||||
|
|
||||||
//if the inheritanceChain already contains the parent, then that
|
//if the inheritanceChain already contains the parent, then that
|
||||||
//is circular inheritance
|
//is circular inheritance
|
||||||
if( ! data.inheritanceChain.contains( parent ) ){
|
if( ! data.inheritanceChain.containsKey( parent ) ){
|
||||||
//is this name define in this scope?
|
//is this name define in this scope?
|
||||||
if( parent instanceof IDerivableContainerSymbol ){
|
if( parent instanceof IDerivableContainerSymbol ){
|
||||||
temp = lookupInContained( data, (IDerivableContainerSymbol) parent );
|
temp = lookupInContained( data, (IDerivableContainerSymbol) parent );
|
||||||
|
@ -1383,7 +1387,7 @@ public class ParserSymbolTable {
|
||||||
temp = ((IUsingDirectiveSymbol) directives.get(i)).getNamespace();
|
temp = ((IUsingDirectiveSymbol) directives.get(i)).getNamespace();
|
||||||
|
|
||||||
//namespaces are searched at most once
|
//namespaces are searched at most once
|
||||||
if( !data.visited.contains( temp ) ){
|
if( !data.visited.containsKey( temp ) ){
|
||||||
enclosing = getClosestEnclosingDeclaration( symbol, temp );
|
enclosing = getClosestEnclosingDeclaration( symbol, temp );
|
||||||
|
|
||||||
//the data.usingDirectives is a map from enclosing declaration to
|
//the data.usingDirectives is a map from enclosing declaration to
|
||||||
|
@ -1494,7 +1498,7 @@ public class ParserSymbolTable {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected void getAssociatedScopes( ISymbol symbol, HashSet associated ){
|
static protected void getAssociatedScopes( ISymbol symbol, ObjectSet associated ){
|
||||||
if( symbol == null ){
|
if( symbol == null ){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1503,19 +1507,19 @@ public class ParserSymbolTable {
|
||||||
//namespaces in which its associated classes are defined
|
//namespaces in which its associated classes are defined
|
||||||
//if( symbol.getType() == TypeInfo.t_class ){
|
//if( symbol.getType() == TypeInfo.t_class ){
|
||||||
if( symbol instanceof IDerivableContainerSymbol ){
|
if( symbol instanceof IDerivableContainerSymbol ){
|
||||||
associated.add( symbol );
|
associated.put( symbol );
|
||||||
associated.add( symbol.getContainingSymbol() );
|
associated.put( symbol.getContainingSymbol() );
|
||||||
getBaseClassesAndContainingNamespaces( (IDerivableContainerSymbol) symbol, associated );
|
getBaseClassesAndContainingNamespaces( (IDerivableContainerSymbol) symbol, associated );
|
||||||
}
|
}
|
||||||
//if T is a union or enumeration type, its associated namespace is the namespace in
|
//if T is a union or enumeration type, its associated namespace is the namespace in
|
||||||
//which it is defined. if it is a class member, its associated class is the member's
|
//which it is defined. if it is a class member, its associated class is the member's
|
||||||
//class
|
//class
|
||||||
else if( symbol.getType() == ITypeInfo.t_union || symbol.getType() == ITypeInfo.t_enumeration ){
|
else if( symbol.getType() == ITypeInfo.t_union || symbol.getType() == ITypeInfo.t_enumeration ){
|
||||||
associated.add( symbol.getContainingSymbol() );
|
associated.put( symbol.getContainingSymbol() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static private void getBaseClassesAndContainingNamespaces( IDerivableContainerSymbol obj, HashSet classes ){
|
static private void getBaseClassesAndContainingNamespaces( IDerivableContainerSymbol obj, ObjectSet classes ){
|
||||||
if( obj.getParents() != null ){
|
if( obj.getParents() != null ){
|
||||||
if( classes == null ){
|
if( classes == null ){
|
||||||
return;
|
return;
|
||||||
|
@ -1531,9 +1535,9 @@ public class ParserSymbolTable {
|
||||||
base = wrapper.getParent();
|
base = wrapper.getParent();
|
||||||
//TODO: what about IDeferredTemplateInstance parents?
|
//TODO: what about IDeferredTemplateInstance parents?
|
||||||
if( base instanceof IDerivableContainerSymbol ){
|
if( base instanceof IDerivableContainerSymbol ){
|
||||||
classes.add( base );
|
classes.put( base );
|
||||||
if( base.getContainingSymbol().getType() == ITypeInfo.t_namespace ){
|
if( base.getContainingSymbol().getType() == ITypeInfo.t_namespace ){
|
||||||
classes.add( base.getContainingSymbol());
|
classes.put( base.getContainingSymbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
getBaseClassesAndContainingNamespaces( (IDerivableContainerSymbol) base, classes );
|
getBaseClassesAndContainingNamespaces( (IDerivableContainerSymbol) base, classes );
|
||||||
|
@ -2221,8 +2225,8 @@ public class ParserSymbolTable {
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
public Map usingDirectives;
|
public Map usingDirectives;
|
||||||
public Set visited = new HashSet(); //used to ensure we don't visit things more than once
|
public ObjectSet visited = new ObjectSet(0); //used to ensure we don't visit things more than once
|
||||||
public HashSet inheritanceChain; //used to detect circular inheritance
|
public ObjectSet inheritanceChain; //used to detect circular inheritance
|
||||||
public ISymbol templateMember; //to assit with template member defs
|
public ISymbol templateMember; //to assit with template member defs
|
||||||
|
|
||||||
public boolean qualified = false;
|
public boolean qualified = false;
|
||||||
|
@ -2244,7 +2248,7 @@ public class ParserSymbolTable {
|
||||||
public Set getAmbiguities() { return null; }
|
public Set getAmbiguities() { return null; }
|
||||||
public void addAmbiguity(String n ) { /*nothing*/ }
|
public void addAmbiguity(String n ) { /*nothing*/ }
|
||||||
public List getParameters() { return null; } //parameter info for resolving functions
|
public List getParameters() { return null; } //parameter info for resolving functions
|
||||||
public HashSet getAssociated() { return null; } //associated namespaces for argument dependant lookup
|
public ObjectSet getAssociated() { return null; } //associated namespaces for argument dependant lookup
|
||||||
public ISymbol getStopAt() { return null; } //stop looking along the stack once we hit this declaration
|
public ISymbol getStopAt() { return null; } //stop looking along the stack once we hit this declaration
|
||||||
public List getTemplateParameters() { return null; } //template parameters
|
public List getTemplateParameters() { return null; } //template parameters
|
||||||
public TypeFilter getFilter() { return ANY_FILTER; }
|
public TypeFilter getFilter() { return ANY_FILTER; }
|
||||||
|
|
|
@ -16,7 +16,6 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -101,8 +100,7 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
|
||||||
IContainerSymbol symbol = null;
|
IContainerSymbol symbol = null;
|
||||||
|
|
||||||
if( getContainedSymbols().size() == 1 ){
|
if( getContainedSymbols().size() == 1 ){
|
||||||
Iterator iter = getContainedSymbols().keySet().iterator();
|
symbol = (IContainerSymbol)getContainedSymbols().getAt( 0 );
|
||||||
symbol = (IContainerSymbol)getContainedSymbols().get( iter.next() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
instance = (IContainerSymbol) symbol.instantiate( this, argMap );
|
instance = (IContainerSymbol) symbol.instantiate( this, argMap );
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
|
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Cost;
|
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Cost;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -891,16 +892,17 @@ public final class TemplateEngine {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected List selectTemplateFunctions( Set templates, List functionArguments, List templateArguments ) throws ParserSymbolTableException{
|
static protected List selectTemplateFunctions( ObjectSet templates, List functionArguments, List templateArguments ) throws ParserSymbolTableException{
|
||||||
if( templates == null || templates.size() == 0 )
|
if( templates == null || templates.size() == 0 )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
List instances = null;
|
List instances = null;
|
||||||
|
|
||||||
Iterator iter = templates.iterator();
|
//Iterator iter = templates.iterator();
|
||||||
|
int size = templates.size();
|
||||||
|
|
||||||
outer: while( iter.hasNext() ){
|
outer: for( int idx = 0; idx < size; idx++ ){
|
||||||
IParameterizedSymbol fn = (IParameterizedSymbol) iter.next();
|
IParameterizedSymbol fn = (IParameterizedSymbol) templates.keyAt( idx );
|
||||||
ITemplateSymbol template = (ITemplateSymbol) fn.getContainingSymbol();
|
ITemplateSymbol template = (ITemplateSymbol) fn.getContainingSymbol();
|
||||||
|
|
||||||
Map map = deduceTemplateArguments( template, functionArguments );
|
Map map = deduceTemplateArguments( template, functionArguments );
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateDeclaration;
|
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateDeclaration;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateInstantiation;
|
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateInstantiation;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateSpecialization;
|
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateSpecialization;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -575,7 +576,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getContainedSymbols()
|
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getContainedSymbols()
|
||||||
*/
|
*/
|
||||||
public Map getContainedSymbols() {
|
public ObjectMap getContainedSymbols() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public abstract class CharArrayMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int hash(char[] buffer, int start, int len) {
|
private int hash(char[] buffer, int start, int len) {
|
||||||
return CharArrayUtils.hash(buffer, start, len) & (keyTable.length - 1);
|
return CharArrayUtils.hash(buffer, start, len) & (hashTable.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int hash(char[] buffer) {
|
private int hash(char[] buffer) {
|
||||||
|
@ -80,8 +80,12 @@ public abstract class CharArrayMap {
|
||||||
int hash = hash(buffer, start, len);
|
int hash = hash(buffer, start, len);
|
||||||
|
|
||||||
if (hashTable[hash] == 0) {
|
if (hashTable[hash] == 0) {
|
||||||
if (++currEntry >= keyTable.length)
|
if( (currEntry + 1) >= keyTable.length){
|
||||||
|
//need to recompute hash for this add, recurse.
|
||||||
resize();
|
resize();
|
||||||
|
return add( buffer, start, len );
|
||||||
|
}
|
||||||
|
currEntry++;
|
||||||
keyTable[currEntry] = CharArrayUtils.extract(buffer, start, len);
|
keyTable[currEntry] = CharArrayUtils.extract(buffer, start, len);
|
||||||
insert(currEntry, hash);
|
insert(currEntry, hash);
|
||||||
return currEntry;
|
return currEntry;
|
||||||
|
@ -102,8 +106,12 @@ public abstract class CharArrayMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// nope, add it in
|
// nope, add it in
|
||||||
if (++currEntry >= keyTable.length)
|
if (++currEntry >= keyTable.length){
|
||||||
|
//need to recompute hash for this add, recurse
|
||||||
resize();
|
resize();
|
||||||
|
return add( buffer, start, len );
|
||||||
|
}
|
||||||
|
currEntry++;
|
||||||
keyTable[currEntry] = CharArrayUtils.extract(buffer, start, len);
|
keyTable[currEntry] = CharArrayUtils.extract(buffer, start, len);
|
||||||
nextTable[last] = currEntry + 1;
|
nextTable[last] = currEntry + 1;
|
||||||
return currEntry;
|
return currEntry;
|
||||||
|
|
|
@ -0,0 +1,228 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2004 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For use by the Parser Symbol Table
|
||||||
|
* Created on Jul 15, 2004
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author aniefer
|
||||||
|
*/
|
||||||
|
public abstract class HashTable implements Cloneable{
|
||||||
|
|
||||||
|
private Object[] keyTable;
|
||||||
|
private int[] hashTable;
|
||||||
|
private int[] nextTable;
|
||||||
|
|
||||||
|
|
||||||
|
protected int currEntry = -1;
|
||||||
|
|
||||||
|
public HashTable(int initialSize) {
|
||||||
|
int size = 1;
|
||||||
|
while (size < initialSize)
|
||||||
|
size <<= 1;
|
||||||
|
|
||||||
|
keyTable = new Object[size];
|
||||||
|
hashTable = new int[size * 2];
|
||||||
|
nextTable = new int[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object clone(){
|
||||||
|
HashTable newTable = null;
|
||||||
|
try {
|
||||||
|
newTable = (HashTable) super.clone();
|
||||||
|
} catch ( CloneNotSupportedException e ) {
|
||||||
|
//shouldn't happen because object supports clone.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = capacity();
|
||||||
|
newTable.keyTable = new Object[ size ];
|
||||||
|
newTable.hashTable = new int[ size*2 ];
|
||||||
|
newTable.nextTable = new int[ size ];
|
||||||
|
|
||||||
|
System.arraycopy(keyTable, 0, newTable.keyTable, 0, keyTable.length);
|
||||||
|
System.arraycopy(hashTable, 0, newTable.hashTable, 0, hashTable.length);
|
||||||
|
System.arraycopy(nextTable, 0, newTable.nextTable, 0, nextTable.length);
|
||||||
|
|
||||||
|
newTable.currEntry = currEntry;
|
||||||
|
return newTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size(){
|
||||||
|
return currEntry + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object keyAt( int i ){
|
||||||
|
if( i < 0 || i > currEntry )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return keyTable[ i ];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear(){
|
||||||
|
for( int i = 0; i < keyTable.length; i++ ){
|
||||||
|
keyTable[i] = null;
|
||||||
|
hashTable[ 2*i ] = 0;
|
||||||
|
hashTable[ 2*i + 1 ] = 0;
|
||||||
|
nextTable[i] = 0;
|
||||||
|
}
|
||||||
|
currEntry = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int capacity() {
|
||||||
|
return keyTable.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int hash(Object obj) {
|
||||||
|
return obj.hashCode() & (hashTable.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void insert(int i) {
|
||||||
|
insert(i, hash(keyTable[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void insert(int i, int hash) {
|
||||||
|
|
||||||
|
if (hashTable[hash] == 0) {
|
||||||
|
hashTable[hash] = i + 1;
|
||||||
|
} else {
|
||||||
|
// need to link
|
||||||
|
int j = hashTable[hash] - 1;
|
||||||
|
while (nextTable[j] != 0)
|
||||||
|
j = nextTable[j] - 1;
|
||||||
|
nextTable[j] = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void resize(int size) {
|
||||||
|
Object[] oldKeyTable = keyTable;
|
||||||
|
keyTable = new Object[size];
|
||||||
|
System.arraycopy(oldKeyTable, 0, keyTable, 0, oldKeyTable.length);
|
||||||
|
|
||||||
|
// Need to rehash everything
|
||||||
|
hashTable = new int[size * 2];
|
||||||
|
nextTable = new int[size];
|
||||||
|
for (int i = 0; i < oldKeyTable.length; ++i) {
|
||||||
|
insert(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resize() {
|
||||||
|
resize(keyTable.length << 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final int add(Object obj) {
|
||||||
|
int hash = hash(obj);
|
||||||
|
|
||||||
|
if (hashTable[hash] == 0) {
|
||||||
|
if ( (currEntry + 1) >= keyTable.length){
|
||||||
|
resize();
|
||||||
|
//hash code needs to be recomputed, just recurse.
|
||||||
|
return add( obj );
|
||||||
|
}
|
||||||
|
currEntry++;
|
||||||
|
keyTable[currEntry] = obj;
|
||||||
|
insert(currEntry, hash);
|
||||||
|
return currEntry;
|
||||||
|
}
|
||||||
|
// is the key already registered?
|
||||||
|
int i = hashTable[hash] - 1;
|
||||||
|
if ( obj.equals( keyTable[i] ) )
|
||||||
|
// yup
|
||||||
|
return i;
|
||||||
|
|
||||||
|
// follow the next chain
|
||||||
|
int last = i;
|
||||||
|
for (i = nextTable[i] - 1; i >= 0; i = nextTable[i] - 1) {
|
||||||
|
if (obj.equals( keyTable[i] ) )
|
||||||
|
// yup this time
|
||||||
|
return i;
|
||||||
|
last = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// nope, add it in
|
||||||
|
if ( (currEntry + 1) >= keyTable.length){
|
||||||
|
resize();
|
||||||
|
//hash code needs to be recomputed, just recurse.
|
||||||
|
return add( obj );
|
||||||
|
}
|
||||||
|
currEntry++;
|
||||||
|
keyTable[currEntry] = obj;
|
||||||
|
nextTable[last] = currEntry + 1;
|
||||||
|
return currEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeEntry(int i) {
|
||||||
|
// Remove the hash entry
|
||||||
|
int hash = hash(keyTable[i]);
|
||||||
|
if (hashTable[hash] == i + 1)
|
||||||
|
hashTable[hash] = nextTable[i];
|
||||||
|
else {
|
||||||
|
// find entry pointing to me
|
||||||
|
int j = hashTable[hash] - 1;
|
||||||
|
while (nextTable[j] != 0 && nextTable[j] != i + 1)
|
||||||
|
j = nextTable[j] - 1;
|
||||||
|
nextTable[j] = nextTable[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < currEntry) {
|
||||||
|
// shift everything over
|
||||||
|
System.arraycopy(keyTable, i + 1, keyTable, i, currEntry - i);
|
||||||
|
System.arraycopy(nextTable, i + 1, nextTable, i, currEntry - i);
|
||||||
|
|
||||||
|
// adjust hash and next entries for things that moved
|
||||||
|
for (int j = 0; j < hashTable.length; ++j)
|
||||||
|
if (hashTable[j] > i)
|
||||||
|
--hashTable[j];
|
||||||
|
|
||||||
|
for (int j = 0; j < nextTable.length; ++j)
|
||||||
|
if (nextTable[j] > i)
|
||||||
|
--nextTable[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
// last entry is now free
|
||||||
|
keyTable[currEntry] = null;
|
||||||
|
nextTable[currEntry] = 0;
|
||||||
|
--currEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final int lookup(Object buffer ){
|
||||||
|
int hash = hash(buffer);
|
||||||
|
|
||||||
|
if (hashTable[hash] == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int i = hashTable[hash] - 1;
|
||||||
|
if (buffer.equals( keyTable[i] ) )
|
||||||
|
return i;
|
||||||
|
|
||||||
|
// Follow the next chain
|
||||||
|
for (i = nextTable[i] - 1; i >= 0; i = nextTable[i] - 1)
|
||||||
|
if ( buffer.equals( keyTable[i] ))
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsKey( Object key ){
|
||||||
|
return lookup( key ) != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object [] keyArray(){
|
||||||
|
Object [] keys = new Object[ size() ];
|
||||||
|
System.arraycopy( keyTable, 0, keys, 0, keys.length );
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2004 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* cloned from CharArrayMap & CharArrayObjectMap
|
||||||
|
* Created on Jul 14, 2004
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author aniefer
|
||||||
|
*/
|
||||||
|
public class ObjectMap extends HashTable{
|
||||||
|
public static final ObjectMap EMPTY_MAP = new ObjectMap( 0 ){
|
||||||
|
public Object clone() { return this; }
|
||||||
|
public Object put( Object key, Object value ) { throw new UnsupportedOperationException(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
private Object[] valueTable;
|
||||||
|
|
||||||
|
public ObjectMap(int initialSize) {
|
||||||
|
super( initialSize );
|
||||||
|
|
||||||
|
valueTable = new Object[ capacity() ];
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object clone(){
|
||||||
|
ObjectMap newMap = (ObjectMap) super.clone();
|
||||||
|
|
||||||
|
newMap.valueTable = new Object[ capacity() ];
|
||||||
|
|
||||||
|
System.arraycopy(valueTable, 0, newMap.valueTable, 0, valueTable.length);
|
||||||
|
return newMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear(){
|
||||||
|
super.clear();
|
||||||
|
for( int i = 0; i < valueTable.length; i++ ){
|
||||||
|
valueTable[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void resize(int size) {
|
||||||
|
Object[] oldValueTable = valueTable;
|
||||||
|
valueTable = new Object[size];
|
||||||
|
System.arraycopy(oldValueTable, 0, valueTable, 0, oldValueTable.length);
|
||||||
|
|
||||||
|
super.resize( size );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object put(Object key, Object value) {
|
||||||
|
int i = add(key);
|
||||||
|
Object oldvalue = valueTable[i];
|
||||||
|
valueTable[i] = value;
|
||||||
|
return oldvalue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(Object key) {
|
||||||
|
int i = lookup(key);
|
||||||
|
if (i >= 0)
|
||||||
|
return valueTable[i];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getAt( int i ){
|
||||||
|
if( i < 0 || i > currEntry )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return get( keyAt( i ) );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2004 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Created on Jul 15, 2004
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author aniefer
|
||||||
|
*/
|
||||||
|
public class ObjectSet extends HashTable{
|
||||||
|
public static final ObjectSet EMPTY_SET = new ObjectSet( 0 ){
|
||||||
|
public Object clone() { return this; }
|
||||||
|
public List toList() { return Collections.EMPTY_LIST; }
|
||||||
|
public void put( Object key ) { throw new UnsupportedOperationException(); }
|
||||||
|
public void addAll( List list ) { throw new UnsupportedOperationException(); }
|
||||||
|
public void addAll( ObjectSet set ) { throw new UnsupportedOperationException(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
public ObjectSet(int initialSize) {
|
||||||
|
super( initialSize );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put(Object key ){
|
||||||
|
add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAll( List list ){
|
||||||
|
if( list == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int size = list.size();
|
||||||
|
for( int i = 0; i < size; i++ ){
|
||||||
|
add( list.get( i ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAll( ObjectSet set ){
|
||||||
|
if( set == null )
|
||||||
|
return;
|
||||||
|
int size = set.size();
|
||||||
|
for( int i = 0; i < size; i++ ){
|
||||||
|
add( set.keyAt( i ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List toList(){
|
||||||
|
List list = new ArrayList( size() );
|
||||||
|
int size = size();
|
||||||
|
for( int i = 0; i < size; i++ ){
|
||||||
|
list.add( keyAt( i ) );
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean remove( Object key ) {
|
||||||
|
int i = lookup(key);
|
||||||
|
if (i < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
removeEntry(i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue