mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +02:00
add generic type to ObjectSet, ObjectTable
This commit is contained in:
parent
fc2be4a64b
commit
924e43ef60
11 changed files with 122 additions and 94 deletions
|
@ -22,7 +22,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class ObjectMap extends ObjectTable {
|
||||
public class ObjectMap extends ObjectTable<Object> {
|
||||
public static final ObjectMap EMPTY_MAP = new ObjectMap(0) {
|
||||
public Object clone() { return this; }
|
||||
public List<Object> toList() { return Collections.emptyList(); }
|
||||
|
@ -139,20 +139,20 @@ public class ObjectMap extends ObjectTable {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
StringBuilder sb = new StringBuilder("{"); //$NON-NLS-1$
|
||||
for (int i = 0; i < size(); i++) {
|
||||
Object key = keyAt(i);
|
||||
if (key != null) {
|
||||
if (sb.length() > 1) {
|
||||
sb.append(", ");
|
||||
sb.append(", "); //$NON-NLS-1$
|
||||
}
|
||||
Object value = valueTable[i];
|
||||
sb.append(String.valueOf(key));
|
||||
sb.append(": ");
|
||||
sb.append(": "); //$NON-NLS-1$
|
||||
sb.append(String.valueOf(value));
|
||||
}
|
||||
}
|
||||
sb.append("}");
|
||||
sb.append("}"); //$NON-NLS-1$
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,16 +20,17 @@ import java.util.List;
|
|||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class ObjectSet extends ObjectTable {
|
||||
public class ObjectSet<T> extends ObjectTable<T> {
|
||||
/**
|
||||
* Represents the empty ObjectSet
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
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(); }
|
||||
@Override public Object clone() { return this; }
|
||||
@Override public List toList() { return Collections.EMPTY_LIST; }
|
||||
@Override public void put( Object key ) { throw new UnsupportedOperationException(); }
|
||||
@Override public void addAll( List list ) { throw new UnsupportedOperationException(); }
|
||||
@Override public void addAll( ObjectSet set ) { throw new UnsupportedOperationException(); }
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -38,7 +39,7 @@ public class ObjectSet extends ObjectTable {
|
|||
* @param initialSize
|
||||
*/
|
||||
public ObjectSet(int initialSize) {
|
||||
super( initialSize );
|
||||
super(initialSize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +47,7 @@ public class ObjectSet extends ObjectTable {
|
|||
* if the parameter is null
|
||||
* @param items
|
||||
*/
|
||||
public ObjectSet(Object[] items) {
|
||||
public ObjectSet(T[] items) {
|
||||
super( items == null ? 2 : items.length );
|
||||
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
|
||||
* @param key the item to add (may be null)
|
||||
*/
|
||||
public void checkPut(Object key) {
|
||||
public void checkPut(T key) {
|
||||
if(key!=null)
|
||||
add(key);
|
||||
}
|
||||
|
@ -64,7 +65,7 @@ public class ObjectSet extends ObjectTable {
|
|||
* Adds the specified item to the set
|
||||
* @param key the (non-null) object to store
|
||||
*/
|
||||
public void put(Object key ){
|
||||
public void put(T 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
|
||||
* @param list a list (may be null)
|
||||
*/
|
||||
public void addAll( List list ){
|
||||
public void addAll(List<T> list ) {
|
||||
if( list == null )
|
||||
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
|
||||
* @param set a set (may be null)
|
||||
*/
|
||||
public void addAll( ObjectSet set ){
|
||||
public void addAll(ObjectSet<? extends T> set ){
|
||||
if( set == null )
|
||||
return;
|
||||
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
|
||||
* @param objs an array (may be null)
|
||||
*/
|
||||
public void addAll( Object[] objs ){
|
||||
public void addAll(T[] objs ){
|
||||
if( objs == null )
|
||||
return;
|
||||
|
||||
|
@ -113,7 +114,7 @@ public class ObjectSet extends ObjectTable {
|
|||
* @param key the (non-null) object to remove
|
||||
* @return whether an object was removed
|
||||
*/
|
||||
public boolean remove( Object key ) {
|
||||
public boolean remove(T key ) {
|
||||
int i = lookup(key);
|
||||
if (i < 0)
|
||||
return false;
|
||||
|
@ -121,4 +122,4 @@ public class ObjectSet extends ObjectTable {
|
|||
removeEntry(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,26 +23,28 @@ import java.util.List;
|
|||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public abstract class ObjectTable extends HashTable implements Cloneable{
|
||||
protected Object[] keyTable;
|
||||
public abstract class ObjectTable<T> extends HashTable implements Cloneable{
|
||||
protected T[] keyTable;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ObjectTable(int initialSize) {
|
||||
super(initialSize);
|
||||
keyTable = new Object[capacity()];
|
||||
keyTable= (T[]) new Object[capacity()];
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object clone(){
|
||||
ObjectTable newTable = (ObjectTable) super.clone();
|
||||
ObjectTable<T> newTable = (ObjectTable<T>) super.clone();
|
||||
|
||||
int size = capacity();
|
||||
newTable.keyTable = new Object[ size ];
|
||||
newTable.keyTable = (T[]) new Object[size];
|
||||
System.arraycopy(keyTable, 0, newTable.keyTable, 0, keyTable.length);
|
||||
|
||||
return newTable;
|
||||
}
|
||||
|
||||
public List toList(){
|
||||
List list = new ArrayList( size() );
|
||||
public List<T> toList(){
|
||||
List<T> list = new ArrayList<T>(size());
|
||||
int size = size();
|
||||
for( int i = 0; i < size; i++ ){
|
||||
list.add( keyAt( i ) );
|
||||
|
@ -50,11 +52,11 @@ public abstract class ObjectTable extends HashTable implements Cloneable{
|
|||
return list;
|
||||
}
|
||||
|
||||
public Object keyAt( int i ){
|
||||
if( i < 0 || i > currEntry )
|
||||
public T keyAt(int i){
|
||||
if(i<0 || i>currEntry)
|
||||
return null;
|
||||
|
||||
return keyTable[ i ];
|
||||
return keyTable[i];
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
|
@ -71,15 +73,15 @@ public abstract class ObjectTable extends HashTable implements Cloneable{
|
|||
return obj.hashCode() & ((capacity() * 2) - 1);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void resize(int size) {
|
||||
Object[] oldKeyTable = keyTable;
|
||||
keyTable = new Object[size];
|
||||
keyTable = (T[]) new Object[size];
|
||||
System.arraycopy(oldKeyTable, 0, keyTable, 0, oldKeyTable.length);
|
||||
|
||||
super.resize(size);
|
||||
}
|
||||
|
||||
protected final int add(Object obj) {
|
||||
protected final int add(T obj) {
|
||||
int pos = lookup(obj);
|
||||
if (pos != -1)
|
||||
return pos;
|
||||
|
@ -133,8 +135,8 @@ public abstract class ObjectTable extends HashTable implements Cloneable{
|
|||
return -1;
|
||||
}
|
||||
|
||||
public boolean containsKey( Object key ){
|
||||
return lookup( key ) != -1;
|
||||
public boolean containsKey(T key){
|
||||
return lookup(key) != -1;
|
||||
}
|
||||
|
||||
public Object [] keyArray(){
|
||||
|
@ -143,8 +145,9 @@ public abstract class ObjectTable extends HashTable implements Cloneable{
|
|||
return keys;
|
||||
}
|
||||
|
||||
public Object [] keyArray( Class c ){
|
||||
Object [] keys = (Object[]) Array.newInstance( c, size() );
|
||||
@SuppressWarnings("unchecked")
|
||||
public <X> X[] keyArray(Class<X> c) {
|
||||
X[] keys = (X[]) Array.newInstance( c, size() );
|
||||
System.arraycopy( keyTable, 0, keys, 0, keys.length );
|
||||
return keys;
|
||||
}
|
||||
|
|
|
@ -1235,6 +1235,7 @@ public class CVisitor {
|
|||
}
|
||||
|
||||
boolean prefix = ( bits & PREFIX_LOOKUP ) != 0;
|
||||
@SuppressWarnings("unchecked")
|
||||
Object binding = prefix ? new ObjectSet( 2 ) : null;
|
||||
IIndexBinding foundIndexBinding= null;
|
||||
CharArrayObjectMap prefixMap = prefix ? new CharArrayObjectMap(2) : null;
|
||||
|
|
|
@ -179,6 +179,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
super.addName(name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void addConstructor(Object constructor) {
|
||||
if (bindings == null)
|
||||
bindings = new CharArrayObjectMap(1);
|
||||
|
@ -266,6 +267,8 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
static protected ICPPConstructor[] getConstructors(CharArrayObjectMap bindings, boolean forceResolve) {
|
||||
return getConstructors(bindings, forceResolve, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static protected ICPPConstructor[] getConstructors(CharArrayObjectMap bindings, boolean forceResolve, IASTName forName) {
|
||||
if (bindings == null)
|
||||
return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
|
||||
|
|
|
@ -137,7 +137,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
|
|||
}
|
||||
|
||||
static private class NamespaceMemberCollector extends CPPASTVisitor {
|
||||
public ObjectSet members = new ObjectSet(8);
|
||||
public ObjectSet<IBinding> members = new ObjectSet<IBinding>(8);
|
||||
public NamespaceMemberCollector(){
|
||||
shouldVisitNamespaces = 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;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
return physicalNode;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addName(IASTName name) throws DOMException {
|
||||
if (bindings == null)
|
||||
bindings = new CharArrayObjectMap(1);
|
||||
|
@ -100,9 +101,9 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
Object o = bindings.get(c);
|
||||
if (o != null) {
|
||||
if (o instanceof ObjectSet) {
|
||||
((ObjectSet)o).put(name);
|
||||
((ObjectSet<Object>)o).put(name);
|
||||
} else {
|
||||
ObjectSet temp = new ObjectSet(2);
|
||||
ObjectSet<Object> temp = new ObjectSet<Object>(2);
|
||||
temp.put(o);
|
||||
temp.put(name);
|
||||
bindings.put(c, temp);
|
||||
|
@ -189,7 +190,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
Object obj = bindings != null ? bindings.get(c) : null;
|
||||
if (obj != null) {
|
||||
if (obj instanceof ObjectSet) {
|
||||
ObjectSet os = (ObjectSet) obj;
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectSet<Object> os = (ObjectSet<Object>) obj;
|
||||
if (forceResolve)
|
||||
return CPPSemantics.resolveAmbiguities(name, os.keyArray());
|
||||
IBinding[] bs = null;
|
||||
|
@ -291,7 +293,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
obj = ArrayUtil.trim(Object.class, obj);
|
||||
for (int i = 0; i < obj.length; i++) {
|
||||
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++) {
|
||||
Object o = os.keyAt(j);
|
||||
if (o instanceof IASTName) {
|
||||
|
@ -346,13 +349,14 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
removeBinding(key, binding);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void removeBinding(char[] key, IBinding binding) {
|
||||
if (bindings == null || ! bindings.containsKey(key))
|
||||
return;
|
||||
|
||||
Object obj = bindings.get(key);
|
||||
if (obj instanceof ObjectSet) {
|
||||
ObjectSet set = (ObjectSet) obj;
|
||||
ObjectSet<Object> set = (ObjectSet<Object>) obj;
|
||||
for (int i = set.size() - 1; i > 0; i--) {
|
||||
Object o = set.keyAt(i);
|
||||
if ((o instanceof IBinding && o == binding) ||
|
||||
|
@ -383,6 +387,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
bindings.clear();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addBinding(IBinding binding) {
|
||||
if (bindings == null)
|
||||
bindings = new CharArrayObjectMap(1);
|
||||
|
@ -390,9 +395,9 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
Object o = bindings.get(c);
|
||||
if (o != null) {
|
||||
if (o instanceof ObjectSet) {
|
||||
((ObjectSet)o).put(binding);
|
||||
((ObjectSet<Object>)o).put(binding);
|
||||
} else {
|
||||
ObjectSet set = new ObjectSet(2);
|
||||
ObjectSet<Object> set = new ObjectSet<Object>(2);
|
||||
set.put(o);
|
||||
set.put(binding);
|
||||
bindings.put(c, set);
|
||||
|
|
|
@ -71,7 +71,7 @@ class ClassTypeMixin {
|
|||
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();
|
||||
for( int i = 0; i < members.length; 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 {
|
||||
|
@ -179,7 +179,7 @@ class ClassTypeMixin {
|
|||
}
|
||||
|
||||
public ICPPMethod[] getMethods() throws DOMException {
|
||||
ObjectSet set = new ObjectSet(4);
|
||||
ObjectSet<ICPPMethod> set = new ObjectSet<ICPPMethod>(4);
|
||||
set.addAll(getDeclaredMethods());
|
||||
ICPPClassScope scope = (ICPPClassScope) host.getCompositeScope();
|
||||
set.addAll( scope.getImplicitMethods() );
|
||||
|
@ -189,7 +189,7 @@ class ClassTypeMixin {
|
|||
if( b instanceof ICPPClassType )
|
||||
set.addAll( ((ICPPClassType)b).getMethods() );
|
||||
}
|
||||
return (ICPPMethod[]) set.keyArray( ICPPMethod.class );
|
||||
return set.keyArray(ICPPMethod.class);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -380,10 +380,10 @@ public class CPPSemantics {
|
|||
return data;
|
||||
}
|
||||
|
||||
static private ObjectSet getAssociatedScopes( LookupData data ) {
|
||||
static private ObjectSet<IScope> getAssociatedScopes( LookupData data ) {
|
||||
IType [] ps = getSourceParameterTypes( data.functionParameters );
|
||||
ObjectSet namespaces = new ObjectSet(2);
|
||||
ObjectSet classes = new ObjectSet(2);
|
||||
ObjectSet<IScope> namespaces = new ObjectSet<IScope>(2);
|
||||
ObjectSet<ICPPClassType> classes = new ObjectSet<ICPPClassType>(2);
|
||||
for( int i = 0; i < ps.length; i++ ){
|
||||
IType p = ps[i];
|
||||
p = getUltimateType( p, true );
|
||||
|
@ -395,11 +395,12 @@ public class CPPSemantics {
|
|||
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
|
||||
if( t instanceof ICPPClassType ){
|
||||
if( !classes.containsKey( t ) ){
|
||||
classes.put( t );
|
||||
if(t instanceof ICPPClassType) {
|
||||
ICPPClassType ct= (ICPPClassType) t;
|
||||
if(!classes.containsKey(ct)) {
|
||||
classes.put(ct);
|
||||
IScope scope = getContainingNamespaceScope( (IBinding) t, tu);
|
||||
if( scope != null )
|
||||
namespaces.put( scope );
|
||||
|
@ -722,7 +723,7 @@ public class CPPSemantics {
|
|||
|
||||
//use data to detect circular inheritance
|
||||
if( data.inheritanceChain == null )
|
||||
data.inheritanceChain = new ObjectSet( 2 );
|
||||
data.inheritanceChain = new ObjectSet<IScope>( 2 );
|
||||
|
||||
data.inheritanceChain.put( lookIn );
|
||||
|
||||
|
@ -825,7 +826,7 @@ public class CPPSemantics {
|
|||
|
||||
public static void visitVirtualBaseClasses( LookupData data, ICPPClassType cls ) throws DOMException {
|
||||
if( data.inheritanceChain == null )
|
||||
data.inheritanceChain = new ObjectSet( 2 );
|
||||
data.inheritanceChain = new ObjectSet<IScope>(2);
|
||||
|
||||
IScope scope = cls.getCompositeScope();
|
||||
if (scope != null)
|
||||
|
@ -949,7 +950,7 @@ public class CPPSemantics {
|
|||
* Computes the common enclosing scope of s1 and s2.
|
||||
*/
|
||||
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;
|
||||
while( parent != null ){
|
||||
set.put( parent );
|
||||
|
@ -1540,13 +1541,13 @@ public class CPPSemantics {
|
|||
if( !data.hasResults() || data.contentAssist )
|
||||
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 obj = null;
|
||||
IBinding temp = null;
|
||||
ObjectSet fns = ObjectSet.EMPTY_SET;
|
||||
boolean fnsFromAST= false;
|
||||
ObjectSet templateFns = ObjectSet.EMPTY_SET;
|
||||
|
||||
Object [] items = (Object[]) data.foundItems;
|
||||
for( int i = 0; i < items.length && items[i] != null; i++ ){
|
||||
|
@ -1584,17 +1585,18 @@ public class CPPSemantics {
|
|||
items = (Object[]) data.foundItems;
|
||||
continue;
|
||||
} else if( temp instanceof IFunction ){
|
||||
if( temp instanceof ICPPTemplateDefinition ){
|
||||
IFunction function= (IFunction) temp;
|
||||
if( function instanceof ICPPFunctionTemplate ){
|
||||
if( templateFns == ObjectSet.EMPTY_SET )
|
||||
templateFns = new ObjectSet(2);
|
||||
templateFns.put( temp );
|
||||
templateFns = new ObjectSet<IFunction>(2);
|
||||
templateFns.put(function);
|
||||
} else {
|
||||
if( fns == ObjectSet.EMPTY_SET )
|
||||
fns = new ObjectSet(2);
|
||||
if (isFromIndex(temp)) {
|
||||
fns = new ObjectSet<IFunction>(2);
|
||||
if (isFromIndex(function)) {
|
||||
// accept bindings from index only, in case we have none in the AST
|
||||
if (!fnsFromAST) {
|
||||
fns.put(temp);
|
||||
fns.put(function);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -1602,7 +1604,7 @@ public class CPPSemantics {
|
|||
fns.clear();
|
||||
fnsFromAST= true;
|
||||
}
|
||||
fns.put( temp );
|
||||
fns.put( function );
|
||||
}
|
||||
}
|
||||
} else if( temp instanceof IType ){
|
||||
|
@ -1658,7 +1660,7 @@ public class CPPSemantics {
|
|||
IFunction [] fs = CPPTemplates.selectTemplateFunctions( templateFns, data.functionParameters, data.astName );
|
||||
if( fs != null && fs.length > 0){
|
||||
if( fns == ObjectSet.EMPTY_SET )
|
||||
fns = new ObjectSet( fs.length );
|
||||
fns = new ObjectSet<IFunction>( fs.length );
|
||||
fns.addAll( fs );
|
||||
}
|
||||
} else {
|
||||
|
@ -1677,7 +1679,7 @@ public class CPPSemantics {
|
|||
if( numFns > 0 ){
|
||||
if( obj != null )
|
||||
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;
|
||||
|
@ -1859,8 +1861,8 @@ public class CPPSemantics {
|
|||
return result;
|
||||
}
|
||||
|
||||
static IBinding resolveFunction( LookupData data, IBinding[] fns ) throws DOMException{
|
||||
fns = (IBinding[]) ArrayUtil.trim( IBinding.class, fns );
|
||||
static IBinding resolveFunction(LookupData data, IFunction[] fns) throws DOMException {
|
||||
fns= (IFunction[]) ArrayUtil.trim(IFunction.class, fns);
|
||||
if( fns == null || fns.length == 0 )
|
||||
return null;
|
||||
|
||||
|
@ -1894,7 +1896,6 @@ public class CPPSemantics {
|
|||
|
||||
int comparison;
|
||||
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 hasBetter = false; //currFn has a better parameter fit than bestFn
|
||||
|
@ -1908,7 +1909,7 @@ public class CPPSemantics {
|
|||
|
||||
// loop over all functions
|
||||
function_loop: for( int fnIdx = 0; fnIdx < fns.length; fnIdx++ ){
|
||||
currFn = (IFunction) fns[fnIdx];
|
||||
currFn= fns[fnIdx];
|
||||
if (currFn == null || bestFn == currFn) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1960,9 +1961,9 @@ public class CPPSemantics {
|
|||
//a single value. (also prevents infinite loop)
|
||||
if (!data.forUserDefinedConversion && (cost.rank == Cost.NO_MATCH_RANK ||
|
||||
cost.rank == Cost.FUZZY_TEMPLATE_PARAMETERS)) {
|
||||
temp = Conversions.checkUserDefinedConversionSequence( source, target );
|
||||
if( temp != null ){
|
||||
cost = temp;
|
||||
Cost udcCost= Conversions.checkUserDefinedConversionSequence( source, target );
|
||||
if( udcCost != null ){
|
||||
cost = udcCost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2408,7 +2409,7 @@ public class CPPSemantics {
|
|||
if( items == null )
|
||||
return new IBinding[0];
|
||||
|
||||
ObjectSet set = new ObjectSet( items.length );
|
||||
ObjectSet<IBinding> set = new ObjectSet<IBinding>(items.length);
|
||||
IBinding binding = null;
|
||||
for( int i = 0; i < items.length; i++ ){
|
||||
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) {
|
||||
|
|
|
@ -871,8 +871,8 @@ public class CPPTemplates {
|
|||
}
|
||||
|
||||
private static class ClearBindingAction extends CPPASTVisitor {
|
||||
public ObjectSet bindings = null;
|
||||
public ClearBindingAction(ObjectSet bindings) {
|
||||
public ObjectSet<IBinding> bindings = null;
|
||||
public ClearBindingAction(ObjectSet<IBinding> bindings) {
|
||||
shouldVisitNames = true;
|
||||
shouldVisitStatements = true;
|
||||
this.bindings = bindings;
|
||||
|
@ -885,9 +885,11 @@ public class CPPTemplates {
|
|||
if (!clear && binding instanceof ICPPTemplateInstance) {
|
||||
IType[] args = ((ICPPTemplateInstance) binding).getArguments();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (bindings.containsKey(args[i])) {
|
||||
clear = true;
|
||||
break;
|
||||
if (args[i] instanceof IBinding) {
|
||||
if(bindings.containsKey((IBinding)args[i])) {
|
||||
clear = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -924,13 +926,13 @@ public class CPPTemplates {
|
|||
if (defParams.length != templateParams.length)
|
||||
return false;
|
||||
|
||||
ObjectSet bindingsToClear = null;
|
||||
ObjectSet<IBinding> bindingsToClear = null;
|
||||
for (int i = 0; i < templateParams.length; i++) {
|
||||
IASTName tn = getTemplateParameterName(templateParams[i]);
|
||||
if (tn.getBinding() != null)
|
||||
return (tn.getBinding() == defParams[i]);
|
||||
if (bindingsToClear == null)
|
||||
bindingsToClear = new ObjectSet(templateParams.length);
|
||||
bindingsToClear = new ObjectSet<IBinding>(templateParams.length);
|
||||
tn.setBinding(defParams[i]);
|
||||
if (defParams[i] instanceof ICPPInternalBinding)
|
||||
((ICPPInternalBinding) defParams[i]).addDeclaration(tn);
|
||||
|
@ -1015,8 +1017,10 @@ public class CPPTemplates {
|
|||
return result;
|
||||
}
|
||||
|
||||
static protected IFunction[] selectTemplateFunctions(ObjectSet templates,
|
||||
Object[] functionArguments, IASTName name) {//IASTNode[] templateArguments) {
|
||||
static protected IFunction[] selectTemplateFunctions(
|
||||
ObjectSet<IFunction> templates,
|
||||
Object[] functionArguments, IASTName name) {
|
||||
|
||||
if (templates == null || templates.size() == 0)
|
||||
return null;
|
||||
|
||||
|
|
|
@ -70,9 +70,19 @@ class LookupData {
|
|||
protected IASTName astName;
|
||||
protected CPPASTTranslationUnit tu;
|
||||
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 ignoreUsingDirectives = false;
|
||||
|
@ -84,11 +94,11 @@ class LookupData {
|
|||
public boolean prefixLookup = false;
|
||||
public boolean typesOnly = false;
|
||||
public boolean considerConstructors = false;
|
||||
|
||||
public Object foundItems = null;
|
||||
public Object [] functionParameters;
|
||||
public IASTNode [] templateArguments;
|
||||
public ProblemBinding problem;
|
||||
|
||||
|
||||
public LookupData( IASTName n ){
|
||||
astName = n;
|
||||
|
|
Loading…
Add table
Reference in a new issue