1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-13 19:25:38 +02:00

add generic type to ObjectSet, ObjectTable

This commit is contained in:
Andrew Ferguson 2008-04-04 13:51:07 +00:00
parent fc2be4a64b
commit 924e43ef60
11 changed files with 122 additions and 94 deletions

View file

@ -22,7 +22,7 @@ import java.util.List;
/** /**
* @author aniefer * @author aniefer
*/ */
public class ObjectMap extends ObjectTable { public class ObjectMap extends ObjectTable<Object> {
public static final ObjectMap EMPTY_MAP = new ObjectMap(0) { public static final ObjectMap EMPTY_MAP = new ObjectMap(0) {
public Object clone() { return this; } public Object clone() { return this; }
public List<Object> toList() { return Collections.emptyList(); } public List<Object> toList() { return Collections.emptyList(); }
@ -139,20 +139,20 @@ public class ObjectMap extends ObjectTable {
} }
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("{"); StringBuilder sb = new StringBuilder("{"); //$NON-NLS-1$
for (int i = 0; i < size(); i++) { for (int i = 0; i < size(); i++) {
Object key = keyAt(i); Object key = keyAt(i);
if (key != null) { if (key != null) {
if (sb.length() > 1) { if (sb.length() > 1) {
sb.append(", "); sb.append(", "); //$NON-NLS-1$
} }
Object value = valueTable[i]; Object value = valueTable[i];
sb.append(String.valueOf(key)); sb.append(String.valueOf(key));
sb.append(": "); sb.append(": "); //$NON-NLS-1$
sb.append(String.valueOf(value)); sb.append(String.valueOf(value));
} }
} }
sb.append("}"); sb.append("}"); //$NON-NLS-1$
return sb.toString(); return sb.toString();
} }
} }

View file

@ -20,16 +20,17 @@ import java.util.List;
/** /**
* @author aniefer * @author aniefer
*/ */
public class ObjectSet extends ObjectTable { public class ObjectSet<T> extends ObjectTable<T> {
/** /**
* Represents the empty ObjectSet * Represents the empty ObjectSet
*/ */
@SuppressWarnings("unchecked")
public static final ObjectSet EMPTY_SET = new ObjectSet( 0 ){ public static final ObjectSet EMPTY_SET = new ObjectSet( 0 ){
public Object clone() { return this; } @Override public Object clone() { return this; }
public List toList() { return Collections.EMPTY_LIST; } @Override public List toList() { return Collections.EMPTY_LIST; }
public void put( Object key ) { throw new UnsupportedOperationException(); } @Override public void put( Object key ) { throw new UnsupportedOperationException(); }
public void addAll( List list ) { throw new UnsupportedOperationException(); } @Override public void addAll( List list ) { throw new UnsupportedOperationException(); }
public void addAll( ObjectSet set ) { throw new UnsupportedOperationException(); } @Override public void addAll( ObjectSet set ) { throw new UnsupportedOperationException(); }
}; };
/** /**
@ -38,7 +39,7 @@ public class ObjectSet extends ObjectTable {
* @param initialSize * @param initialSize
*/ */
public ObjectSet(int initialSize) { public ObjectSet(int initialSize) {
super( initialSize ); super(initialSize);
} }
/** /**
@ -46,7 +47,7 @@ public class ObjectSet extends ObjectTable {
* if the parameter is null * if the parameter is null
* @param items * @param items
*/ */
public ObjectSet(Object[] items) { public ObjectSet(T[] items) {
super( items == null ? 2 : items.length ); super( items == null ? 2 : items.length );
addAll( items ); addAll( items );
} }
@ -55,7 +56,7 @@ public class ObjectSet extends ObjectTable {
* Adds the specified item to the set, or no-ops if the key is null * Adds the specified item to the set, or no-ops if the key is null
* @param key the item to add (may be null) * @param key the item to add (may be null)
*/ */
public void checkPut(Object key) { public void checkPut(T key) {
if(key!=null) if(key!=null)
add(key); add(key);
} }
@ -64,7 +65,7 @@ public class ObjectSet extends ObjectTable {
* Adds the specified item to the set * Adds the specified item to the set
* @param key the (non-null) object to store * @param key the (non-null) object to store
*/ */
public void put(Object key ){ public void put(T key){
add(key); add(key);
} }
@ -72,7 +73,7 @@ public class ObjectSet extends ObjectTable {
* Adds each item in the list to this ObjectSet, or no-ops if list is null * Adds each item in the list to this ObjectSet, or no-ops if list is null
* @param list a list (may be null) * @param list a list (may be null)
*/ */
public void addAll( List list ){ public void addAll(List<T> list ) {
if( list == null ) if( list == null )
return; return;
@ -86,7 +87,7 @@ public class ObjectSet extends ObjectTable {
* Adds each item in the specified ObjectSet, or no-ops if the set is null * Adds each item in the specified ObjectSet, or no-ops if the set is null
* @param set a set (may be null) * @param set a set (may be null)
*/ */
public void addAll( ObjectSet set ){ public void addAll(ObjectSet<? extends T> set ){
if( set == null ) if( set == null )
return; return;
int size = set.size(); int size = set.size();
@ -99,7 +100,7 @@ public class ObjectSet extends ObjectTable {
* Adds each of the items in the specified array, or no-ops if the array is null * Adds each of the items in the specified array, or no-ops if the array is null
* @param objs an array (may be null) * @param objs an array (may be null)
*/ */
public void addAll( Object[] objs ){ public void addAll(T[] objs ){
if( objs == null ) if( objs == null )
return; return;
@ -113,7 +114,7 @@ public class ObjectSet extends ObjectTable {
* @param key the (non-null) object to remove * @param key the (non-null) object to remove
* @return whether an object was removed * @return whether an object was removed
*/ */
public boolean remove( Object key ) { public boolean remove(T key ) {
int i = lookup(key); int i = lookup(key);
if (i < 0) if (i < 0)
return false; return false;

View file

@ -23,26 +23,28 @@ import java.util.List;
/** /**
* @author aniefer * @author aniefer
*/ */
public abstract class ObjectTable extends HashTable implements Cloneable{ public abstract class ObjectTable<T> extends HashTable implements Cloneable{
protected Object[] keyTable; protected T[] keyTable;
@SuppressWarnings("unchecked")
public ObjectTable(int initialSize) { public ObjectTable(int initialSize) {
super(initialSize); super(initialSize);
keyTable = new Object[capacity()]; keyTable= (T[]) new Object[capacity()];
} }
@SuppressWarnings("unchecked")
public Object clone(){ public Object clone(){
ObjectTable newTable = (ObjectTable) super.clone(); ObjectTable<T> newTable = (ObjectTable<T>) super.clone();
int size = capacity(); int size = capacity();
newTable.keyTable = new Object[ size ]; newTable.keyTable = (T[]) new Object[size];
System.arraycopy(keyTable, 0, newTable.keyTable, 0, keyTable.length); System.arraycopy(keyTable, 0, newTable.keyTable, 0, keyTable.length);
return newTable; return newTable;
} }
public List toList(){ public List<T> toList(){
List list = new ArrayList( size() ); List<T> list = new ArrayList<T>(size());
int size = size(); int size = size();
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
list.add( keyAt( i ) ); list.add( keyAt( i ) );
@ -50,11 +52,11 @@ public abstract class ObjectTable extends HashTable implements Cloneable{
return list; return list;
} }
public Object keyAt( int i ){ public T keyAt(int i){
if( i < 0 || i > currEntry ) if(i<0 || i>currEntry)
return null; return null;
return keyTable[ i ]; return keyTable[i];
} }
public void clear(){ public void clear(){
@ -71,15 +73,15 @@ public abstract class ObjectTable extends HashTable implements Cloneable{
return obj.hashCode() & ((capacity() * 2) - 1); return obj.hashCode() & ((capacity() * 2) - 1);
} }
@SuppressWarnings("unchecked")
protected void resize(int size) { protected void resize(int size) {
Object[] oldKeyTable = keyTable; Object[] oldKeyTable = keyTable;
keyTable = new Object[size]; keyTable = (T[]) new Object[size];
System.arraycopy(oldKeyTable, 0, keyTable, 0, oldKeyTable.length); System.arraycopy(oldKeyTable, 0, keyTable, 0, oldKeyTable.length);
super.resize(size); super.resize(size);
} }
protected final int add(Object obj) { protected final int add(T obj) {
int pos = lookup(obj); int pos = lookup(obj);
if (pos != -1) if (pos != -1)
return pos; return pos;
@ -133,8 +135,8 @@ public abstract class ObjectTable extends HashTable implements Cloneable{
return -1; return -1;
} }
public boolean containsKey( Object key ){ public boolean containsKey(T key){
return lookup( key ) != -1; return lookup(key) != -1;
} }
public Object [] keyArray(){ public Object [] keyArray(){
@ -143,8 +145,9 @@ public abstract class ObjectTable extends HashTable implements Cloneable{
return keys; return keys;
} }
public Object [] keyArray( Class c ){ @SuppressWarnings("unchecked")
Object [] keys = (Object[]) Array.newInstance( c, size() ); public <X> X[] keyArray(Class<X> c) {
X[] keys = (X[]) Array.newInstance( c, size() );
System.arraycopy( keyTable, 0, keys, 0, keys.length ); System.arraycopy( keyTable, 0, keys, 0, keys.length );
return keys; return keys;
} }

View file

@ -1235,6 +1235,7 @@ public class CVisitor {
} }
boolean prefix = ( bits & PREFIX_LOOKUP ) != 0; boolean prefix = ( bits & PREFIX_LOOKUP ) != 0;
@SuppressWarnings("unchecked")
Object binding = prefix ? new ObjectSet( 2 ) : null; Object binding = prefix ? new ObjectSet( 2 ) : null;
IIndexBinding foundIndexBinding= null; IIndexBinding foundIndexBinding= null;
CharArrayObjectMap prefixMap = prefix ? new CharArrayObjectMap(2) : null; CharArrayObjectMap prefixMap = prefix ? new CharArrayObjectMap(2) : null;

View file

@ -179,6 +179,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
super.addName(name); super.addName(name);
} }
@SuppressWarnings("unchecked")
private void addConstructor(Object constructor) { private void addConstructor(Object constructor) {
if (bindings == null) if (bindings == null)
bindings = new CharArrayObjectMap(1); bindings = new CharArrayObjectMap(1);
@ -266,6 +267,8 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
static protected ICPPConstructor[] getConstructors(CharArrayObjectMap bindings, boolean forceResolve) { static protected ICPPConstructor[] getConstructors(CharArrayObjectMap bindings, boolean forceResolve) {
return getConstructors(bindings, forceResolve, null); return getConstructors(bindings, forceResolve, null);
} }
@SuppressWarnings("unchecked")
static protected ICPPConstructor[] getConstructors(CharArrayObjectMap bindings, boolean forceResolve, IASTName forName) { static protected ICPPConstructor[] getConstructors(CharArrayObjectMap bindings, boolean forceResolve, IASTName forName) {
if (bindings == null) if (bindings == null)
return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;

View file

@ -137,7 +137,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
} }
static private class NamespaceMemberCollector extends CPPASTVisitor { static private class NamespaceMemberCollector extends CPPASTVisitor {
public ObjectSet members = new ObjectSet(8); public ObjectSet<IBinding> members = new ObjectSet<IBinding>(8);
public NamespaceMemberCollector(){ public NamespaceMemberCollector(){
shouldVisitNamespaces = true; shouldVisitNamespaces = true;
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -336,7 +336,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
} }
} }
} }
return (IBinding[]) collector.members.keyArray( IBinding.class ); return collector.members.keyArray(IBinding.class);
} }
return IBinding.EMPTY_BINDING_ARRAY; return IBinding.EMPTY_BINDING_ARRAY;
} }

View file

@ -78,6 +78,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
return physicalNode; return physicalNode;
} }
@SuppressWarnings("unchecked")
public void addName(IASTName name) throws DOMException { public void addName(IASTName name) throws DOMException {
if (bindings == null) if (bindings == null)
bindings = new CharArrayObjectMap(1); bindings = new CharArrayObjectMap(1);
@ -100,9 +101,9 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
Object o = bindings.get(c); Object o = bindings.get(c);
if (o != null) { if (o != null) {
if (o instanceof ObjectSet) { if (o instanceof ObjectSet) {
((ObjectSet)o).put(name); ((ObjectSet<Object>)o).put(name);
} else { } else {
ObjectSet temp = new ObjectSet(2); ObjectSet<Object> temp = new ObjectSet<Object>(2);
temp.put(o); temp.put(o);
temp.put(name); temp.put(name);
bindings.put(c, temp); bindings.put(c, temp);
@ -189,7 +190,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
Object obj = bindings != null ? bindings.get(c) : null; Object obj = bindings != null ? bindings.get(c) : null;
if (obj != null) { if (obj != null) {
if (obj instanceof ObjectSet) { if (obj instanceof ObjectSet) {
ObjectSet os = (ObjectSet) obj; @SuppressWarnings("unchecked")
ObjectSet<Object> os = (ObjectSet<Object>) obj;
if (forceResolve) if (forceResolve)
return CPPSemantics.resolveAmbiguities(name, os.keyArray()); return CPPSemantics.resolveAmbiguities(name, os.keyArray());
IBinding[] bs = null; IBinding[] bs = null;
@ -291,7 +293,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
obj = ArrayUtil.trim(Object.class, obj); obj = ArrayUtil.trim(Object.class, obj);
for (int i = 0; i < obj.length; i++) { for (int i = 0; i < obj.length; i++) {
if (obj[i] instanceof ObjectSet) { if (obj[i] instanceof ObjectSet) {
ObjectSet os = (ObjectSet) obj[i]; @SuppressWarnings("unchecked")
ObjectSet<Object> os= (ObjectSet<Object>) obj[i];
for (int j = 0; j < os.size(); j++) { for (int j = 0; j < os.size(); j++) {
Object o = os.keyAt(j); Object o = os.keyAt(j);
if (o instanceof IASTName) { if (o instanceof IASTName) {
@ -346,13 +349,14 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
removeBinding(key, binding); removeBinding(key, binding);
} }
@SuppressWarnings("unchecked")
protected void removeBinding(char[] key, IBinding binding) { protected void removeBinding(char[] key, IBinding binding) {
if (bindings == null || ! bindings.containsKey(key)) if (bindings == null || ! bindings.containsKey(key))
return; return;
Object obj = bindings.get(key); Object obj = bindings.get(key);
if (obj instanceof ObjectSet) { if (obj instanceof ObjectSet) {
ObjectSet set = (ObjectSet) obj; ObjectSet<Object> set = (ObjectSet<Object>) obj;
for (int i = set.size() - 1; i > 0; i--) { for (int i = set.size() - 1; i > 0; i--) {
Object o = set.keyAt(i); Object o = set.keyAt(i);
if ((o instanceof IBinding && o == binding) || if ((o instanceof IBinding && o == binding) ||
@ -383,6 +387,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
bindings.clear(); bindings.clear();
} }
@SuppressWarnings("unchecked")
public void addBinding(IBinding binding) { public void addBinding(IBinding binding) {
if (bindings == null) if (bindings == null)
bindings = new CharArrayObjectMap(1); bindings = new CharArrayObjectMap(1);
@ -390,9 +395,9 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
Object o = bindings.get(c); Object o = bindings.get(c);
if (o != null) { if (o != null) {
if (o instanceof ObjectSet) { if (o instanceof ObjectSet) {
((ObjectSet)o).put(binding); ((ObjectSet<Object>)o).put(binding);
} else { } else {
ObjectSet set = new ObjectSet(2); ObjectSet<Object> set = new ObjectSet<Object>(2);
set.put(o); set.put(o);
set.put(binding); set.put(binding);
bindings.put(c, set); bindings.put(c, set);

View file

@ -71,7 +71,7 @@ class ClassTypeMixin {
return new IBinding [] { new ProblemBinding( node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, host.getNameCharArray() ) }; return new IBinding [] { new ProblemBinding( node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, host.getNameCharArray() ) };
} }
} }
ObjectSet resultSet = new ObjectSet(2); ObjectSet<IBinding> resultSet = new ObjectSet<IBinding>(2);
IASTDeclaration [] members = host.getCompositeTypeSpecifier().getMembers(); IASTDeclaration [] members = host.getCompositeTypeSpecifier().getMembers();
for( int i = 0; i < members.length; i++ ){ for( int i = 0; i < members.length; i++ ){
IASTDeclaration decl = members[i]; IASTDeclaration decl = members[i];
@ -101,7 +101,7 @@ class ClassTypeMixin {
} }
} }
return (IBinding[]) resultSet.keyArray( IBinding.class ); return resultSet.keyArray(IBinding.class);
} }
public ICPPMethod[] getConversionOperators() throws DOMException { public ICPPMethod[] getConversionOperators() throws DOMException {
@ -179,7 +179,7 @@ class ClassTypeMixin {
} }
public ICPPMethod[] getMethods() throws DOMException { public ICPPMethod[] getMethods() throws DOMException {
ObjectSet set = new ObjectSet(4); ObjectSet<ICPPMethod> set = new ObjectSet<ICPPMethod>(4);
set.addAll(getDeclaredMethods()); set.addAll(getDeclaredMethods());
ICPPClassScope scope = (ICPPClassScope) host.getCompositeScope(); ICPPClassScope scope = (ICPPClassScope) host.getCompositeScope();
set.addAll( scope.getImplicitMethods() ); set.addAll( scope.getImplicitMethods() );
@ -189,7 +189,7 @@ class ClassTypeMixin {
if( b instanceof ICPPClassType ) if( b instanceof ICPPClassType )
set.addAll( ((ICPPClassType)b).getMethods() ); set.addAll( ((ICPPClassType)b).getMethods() );
} }
return (ICPPMethod[]) set.keyArray( ICPPMethod.class ); return set.keyArray(ICPPMethod.class);
} }

View file

@ -380,10 +380,10 @@ public class CPPSemantics {
return data; return data;
} }
static private ObjectSet getAssociatedScopes( LookupData data ) { static private ObjectSet<IScope> getAssociatedScopes( LookupData data ) {
IType [] ps = getSourceParameterTypes( data.functionParameters ); IType [] ps = getSourceParameterTypes( data.functionParameters );
ObjectSet namespaces = new ObjectSet(2); ObjectSet<IScope> namespaces = new ObjectSet<IScope>(2);
ObjectSet classes = new ObjectSet(2); ObjectSet<ICPPClassType> classes = new ObjectSet<ICPPClassType>(2);
for( int i = 0; i < ps.length; i++ ){ for( int i = 0; i < ps.length; i++ ){
IType p = ps[i]; IType p = ps[i];
p = getUltimateType( p, true ); p = getUltimateType( p, true );
@ -395,11 +395,12 @@ public class CPPSemantics {
return namespaces; return namespaces;
} }
static private void getAssociatedScopes( IType t, ObjectSet namespaces, ObjectSet classes, CPPASTTranslationUnit tu) throws DOMException{ static private void getAssociatedScopes( IType t, ObjectSet<IScope> namespaces, ObjectSet<ICPPClassType> classes, CPPASTTranslationUnit tu) throws DOMException{
//3.4.2-2 //3.4.2-2
if( t instanceof ICPPClassType ){ if(t instanceof ICPPClassType) {
if( !classes.containsKey( t ) ){ ICPPClassType ct= (ICPPClassType) t;
classes.put( t ); if(!classes.containsKey(ct)) {
classes.put(ct);
IScope scope = getContainingNamespaceScope( (IBinding) t, tu); IScope scope = getContainingNamespaceScope( (IBinding) t, tu);
if( scope != null ) if( scope != null )
namespaces.put( scope ); namespaces.put( scope );
@ -722,7 +723,7 @@ public class CPPSemantics {
//use data to detect circular inheritance //use data to detect circular inheritance
if( data.inheritanceChain == null ) if( data.inheritanceChain == null )
data.inheritanceChain = new ObjectSet( 2 ); data.inheritanceChain = new ObjectSet<IScope>( 2 );
data.inheritanceChain.put( lookIn ); data.inheritanceChain.put( lookIn );
@ -825,7 +826,7 @@ public class CPPSemantics {
public static void visitVirtualBaseClasses( LookupData data, ICPPClassType cls ) throws DOMException { public static void visitVirtualBaseClasses( LookupData data, ICPPClassType cls ) throws DOMException {
if( data.inheritanceChain == null ) if( data.inheritanceChain == null )
data.inheritanceChain = new ObjectSet( 2 ); data.inheritanceChain = new ObjectSet<IScope>(2);
IScope scope = cls.getCompositeScope(); IScope scope = cls.getCompositeScope();
if (scope != null) if (scope != null)
@ -949,7 +950,7 @@ public class CPPSemantics {
* Computes the common enclosing scope of s1 and s2. * Computes the common enclosing scope of s1 and s2.
*/ */
static private ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, CPPASTTranslationUnit tu) throws DOMException { static private ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, CPPASTTranslationUnit tu) throws DOMException {
ObjectSet set = new ObjectSet( 2 ); ObjectSet<IScope> set = new ObjectSet<IScope>(2);
IScope parent= s1; IScope parent= s1;
while( parent != null ){ while( parent != null ){
set.put( parent ); set.put( parent );
@ -1541,12 +1542,12 @@ public class CPPSemantics {
return null; return null;
final boolean indexBased= data.tu == null ? false : data.tu.getIndex() != null; final boolean indexBased= data.tu == null ? false : data.tu.getIndex() != null;
@SuppressWarnings("unchecked")
ObjectSet<IFunction> fns= ObjectSet.EMPTY_SET, templateFns= ObjectSet.EMPTY_SET;
IBinding type = null; IBinding type = null;
IBinding obj = null; IBinding obj = null;
IBinding temp = null; IBinding temp = null;
ObjectSet fns = ObjectSet.EMPTY_SET;
boolean fnsFromAST= false; boolean fnsFromAST= false;
ObjectSet templateFns = ObjectSet.EMPTY_SET;
Object [] items = (Object[]) data.foundItems; Object [] items = (Object[]) data.foundItems;
for( int i = 0; i < items.length && items[i] != null; i++ ){ for( int i = 0; i < items.length && items[i] != null; i++ ){
@ -1584,17 +1585,18 @@ public class CPPSemantics {
items = (Object[]) data.foundItems; items = (Object[]) data.foundItems;
continue; continue;
} else if( temp instanceof IFunction ){ } else if( temp instanceof IFunction ){
if( temp instanceof ICPPTemplateDefinition ){ IFunction function= (IFunction) temp;
if( function instanceof ICPPFunctionTemplate ){
if( templateFns == ObjectSet.EMPTY_SET ) if( templateFns == ObjectSet.EMPTY_SET )
templateFns = new ObjectSet(2); templateFns = new ObjectSet<IFunction>(2);
templateFns.put( temp ); templateFns.put(function);
} else { } else {
if( fns == ObjectSet.EMPTY_SET ) if( fns == ObjectSet.EMPTY_SET )
fns = new ObjectSet(2); fns = new ObjectSet<IFunction>(2);
if (isFromIndex(temp)) { if (isFromIndex(function)) {
// accept bindings from index only, in case we have none in the AST // accept bindings from index only, in case we have none in the AST
if (!fnsFromAST) { if (!fnsFromAST) {
fns.put(temp); fns.put(function);
} }
} }
else { else {
@ -1602,7 +1604,7 @@ public class CPPSemantics {
fns.clear(); fns.clear();
fnsFromAST= true; fnsFromAST= true;
} }
fns.put( temp ); fns.put( function );
} }
} }
} else if( temp instanceof IType ){ } else if( temp instanceof IType ){
@ -1658,7 +1660,7 @@ public class CPPSemantics {
IFunction [] fs = CPPTemplates.selectTemplateFunctions( templateFns, data.functionParameters, data.astName ); IFunction [] fs = CPPTemplates.selectTemplateFunctions( templateFns, data.functionParameters, data.astName );
if( fs != null && fs.length > 0){ if( fs != null && fs.length > 0){
if( fns == ObjectSet.EMPTY_SET ) if( fns == ObjectSet.EMPTY_SET )
fns = new ObjectSet( fs.length ); fns = new ObjectSet<IFunction>( fs.length );
fns.addAll( fs ); fns.addAll( fs );
} }
} else { } else {
@ -1677,7 +1679,7 @@ public class CPPSemantics {
if( numFns > 0 ){ if( numFns > 0 ){
if( obj != null ) if( obj != null )
return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() );
return resolveFunction( data, (IBinding[]) fns.keyArray( IBinding.class ) ); return resolveFunction(data, fns.keyArray(IFunction.class));
} }
return obj; return obj;
@ -1859,8 +1861,8 @@ public class CPPSemantics {
return result; return result;
} }
static IBinding resolveFunction( LookupData data, IBinding[] fns ) throws DOMException{ static IBinding resolveFunction(LookupData data, IFunction[] fns) throws DOMException {
fns = (IBinding[]) ArrayUtil.trim( IBinding.class, fns ); fns= (IFunction[]) ArrayUtil.trim(IFunction.class, fns);
if( fns == null || fns.length == 0 ) if( fns == null || fns.length == 0 )
return null; return null;
@ -1894,7 +1896,6 @@ public class CPPSemantics {
int comparison; int comparison;
Cost cost = null; //the cost of converting source to target Cost cost = null; //the cost of converting source to target
Cost temp = null; //the cost of using a user defined conversion to convert source to target
boolean hasWorse = false; //currFn has a worse parameter fit than bestFn boolean hasWorse = false; //currFn has a worse parameter fit than bestFn
boolean hasBetter = false; //currFn has a better parameter fit than bestFn boolean hasBetter = false; //currFn has a better parameter fit than bestFn
@ -1908,7 +1909,7 @@ public class CPPSemantics {
// loop over all functions // loop over all functions
function_loop: for( int fnIdx = 0; fnIdx < fns.length; fnIdx++ ){ function_loop: for( int fnIdx = 0; fnIdx < fns.length; fnIdx++ ){
currFn = (IFunction) fns[fnIdx]; currFn= fns[fnIdx];
if (currFn == null || bestFn == currFn) { if (currFn == null || bestFn == currFn) {
continue; continue;
} }
@ -1960,9 +1961,9 @@ public class CPPSemantics {
//a single value. (also prevents infinite loop) //a single value. (also prevents infinite loop)
if (!data.forUserDefinedConversion && (cost.rank == Cost.NO_MATCH_RANK || if (!data.forUserDefinedConversion && (cost.rank == Cost.NO_MATCH_RANK ||
cost.rank == Cost.FUZZY_TEMPLATE_PARAMETERS)) { cost.rank == Cost.FUZZY_TEMPLATE_PARAMETERS)) {
temp = Conversions.checkUserDefinedConversionSequence( source, target ); Cost udcCost= Conversions.checkUserDefinedConversionSequence( source, target );
if( temp != null ){ if( udcCost != null ){
cost = temp; cost = udcCost;
} }
} }
} }
@ -2408,7 +2409,7 @@ public class CPPSemantics {
if( items == null ) if( items == null )
return new IBinding[0]; return new IBinding[0];
ObjectSet set = new ObjectSet( items.length ); ObjectSet<IBinding> set = new ObjectSet<IBinding>(items.length);
IBinding binding = null; IBinding binding = null;
for( int i = 0; i < items.length; i++ ){ for( int i = 0; i < items.length; i++ ){
if( items[i] instanceof IASTName ) if( items[i] instanceof IASTName )
@ -2428,7 +2429,7 @@ public class CPPSemantics {
} }
} }
return (IBinding[]) set.keyArray( IBinding.class ); return set.keyArray(IBinding.class);
} }
public static boolean isSameFunction(IFunction function, IASTDeclarator declarator) { public static boolean isSameFunction(IFunction function, IASTDeclarator declarator) {

View file

@ -871,8 +871,8 @@ public class CPPTemplates {
} }
private static class ClearBindingAction extends CPPASTVisitor { private static class ClearBindingAction extends CPPASTVisitor {
public ObjectSet bindings = null; public ObjectSet<IBinding> bindings = null;
public ClearBindingAction(ObjectSet bindings) { public ClearBindingAction(ObjectSet<IBinding> bindings) {
shouldVisitNames = true; shouldVisitNames = true;
shouldVisitStatements = true; shouldVisitStatements = true;
this.bindings = bindings; this.bindings = bindings;
@ -885,12 +885,14 @@ public class CPPTemplates {
if (!clear && binding instanceof ICPPTemplateInstance) { if (!clear && binding instanceof ICPPTemplateInstance) {
IType[] args = ((ICPPTemplateInstance) binding).getArguments(); IType[] args = ((ICPPTemplateInstance) binding).getArguments();
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
if (bindings.containsKey(args[i])) { if (args[i] instanceof IBinding) {
if(bindings.containsKey((IBinding)args[i])) {
clear = true; clear = true;
break; break;
} }
} }
} }
}
if (clear) { if (clear) {
if (binding instanceof ICPPInternalBinding) if (binding instanceof ICPPInternalBinding)
((ICPPInternalBinding) binding).removeDeclaration(name); ((ICPPInternalBinding) binding).removeDeclaration(name);
@ -924,13 +926,13 @@ public class CPPTemplates {
if (defParams.length != templateParams.length) if (defParams.length != templateParams.length)
return false; return false;
ObjectSet bindingsToClear = null; ObjectSet<IBinding> bindingsToClear = null;
for (int i = 0; i < templateParams.length; i++) { for (int i = 0; i < templateParams.length; i++) {
IASTName tn = getTemplateParameterName(templateParams[i]); IASTName tn = getTemplateParameterName(templateParams[i]);
if (tn.getBinding() != null) if (tn.getBinding() != null)
return (tn.getBinding() == defParams[i]); return (tn.getBinding() == defParams[i]);
if (bindingsToClear == null) if (bindingsToClear == null)
bindingsToClear = new ObjectSet(templateParams.length); bindingsToClear = new ObjectSet<IBinding>(templateParams.length);
tn.setBinding(defParams[i]); tn.setBinding(defParams[i]);
if (defParams[i] instanceof ICPPInternalBinding) if (defParams[i] instanceof ICPPInternalBinding)
((ICPPInternalBinding) defParams[i]).addDeclaration(tn); ((ICPPInternalBinding) defParams[i]).addDeclaration(tn);
@ -1015,8 +1017,10 @@ public class CPPTemplates {
return result; return result;
} }
static protected IFunction[] selectTemplateFunctions(ObjectSet templates, static protected IFunction[] selectTemplateFunctions(
Object[] functionArguments, IASTName name) {//IASTNode[] templateArguments) { ObjectSet<IFunction> templates,
Object[] functionArguments, IASTName name) {
if (templates == null || templates.size() == 0) if (templates == null || templates.size() == 0)
return null; return null;

View file

@ -70,9 +70,19 @@ class LookupData {
protected IASTName astName; protected IASTName astName;
protected CPPASTTranslationUnit tu; protected CPPASTTranslationUnit tu;
public Map<ICPPNamespaceScope, List<ICPPNamespaceScope>> usingDirectives= Collections.emptyMap(); public Map<ICPPNamespaceScope, List<ICPPNamespaceScope>> usingDirectives= Collections.emptyMap();
public ObjectSet visited= new ObjectSet(1); //used to ensure we don't visit things more than once
public ObjectSet inheritanceChain; //used to detect circular inheritance /*
public ObjectSet associated = ObjectSet.EMPTY_SET; * Used to ensure we don't visit things more than once
*/
public ObjectSet<IScope> visited= new ObjectSet<IScope>(1);
/*
* Used to detect circular inheritance
*/
public ObjectSet<IScope> inheritanceChain;
@SuppressWarnings("unchecked")
public ObjectSet<IScope> associated = ObjectSet.EMPTY_SET;
public boolean checkWholeClassScope = false; public boolean checkWholeClassScope = false;
public boolean ignoreUsingDirectives = false; public boolean ignoreUsingDirectives = false;
@ -84,12 +94,12 @@ class LookupData {
public boolean prefixLookup = false; public boolean prefixLookup = false;
public boolean typesOnly = false; public boolean typesOnly = false;
public boolean considerConstructors = false; public boolean considerConstructors = false;
public Object foundItems = null; public Object foundItems = null;
public Object [] functionParameters; public Object [] functionParameters;
public IASTNode [] templateArguments; public IASTNode [] templateArguments;
public ProblemBinding problem; public ProblemBinding problem;
public LookupData( IASTName n ){ public LookupData( IASTName n ){
astName = n; astName = n;
tu= (CPPASTTranslationUnit) astName.getTranslationUnit(); tu= (CPPASTTranslationUnit) astName.getTranslationUnit();