mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
switching from lists to arrays in bindings.
This commit is contained in:
parent
199268d640
commit
d1621f3b56
18 changed files with 261 additions and 209 deletions
|
@ -10,7 +10,6 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -33,5 +32,5 @@ public interface IScope {
|
|||
* @param searchString
|
||||
* @return List of IBinding
|
||||
*/
|
||||
public List find(String name) throws DOMException;
|
||||
public IBinding[] find(String name) throws DOMException;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ public interface ICPPMember {
|
|||
*/
|
||||
public int getVisibility() throws DOMException;
|
||||
|
||||
public boolean isStatic() throws DOMException;
|
||||
|
||||
public static final int v_private = ICPPASTVisiblityLabel.v_private;
|
||||
public static final int v_protected = ICPPASTVisiblityLabel.v_protected;
|
||||
public static final int v_public = ICPPASTVisiblityLabel.v_public;
|
||||
|
|
|
@ -20,6 +20,10 @@ import java.lang.reflect.Array;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class ArrayUtil {
|
||||
public static final class ArrayWrapper {
|
||||
public Object [] array = null;
|
||||
}
|
||||
|
||||
public static final int DEFAULT_LENGTH = 2;
|
||||
/**
|
||||
* Adds obj to array in the first null slot.
|
||||
|
@ -55,6 +59,10 @@ public class ArrayUtil {
|
|||
return array;
|
||||
}
|
||||
|
||||
static public Object [] append( Object[] array, Object obj ){
|
||||
return append( Object.class, array, obj );
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims the given array and returns a new array with no null entries.
|
||||
* if array == null, a new array of length 0 is returned
|
||||
|
@ -91,4 +99,39 @@ public class ArrayUtil {
|
|||
public static Object[] trim( Class c, Object[] array ) {
|
||||
return trim( c, array, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param transitives
|
||||
* @param usings
|
||||
*/
|
||||
public static Object[] addAll( Class c, Object[] dest, Object[] source ) {
|
||||
if( source == null || source.length == 0 )
|
||||
return dest;
|
||||
|
||||
int numToAdd = 0;
|
||||
while( numToAdd < source.length && source[numToAdd] != null )
|
||||
numToAdd++;
|
||||
|
||||
if( numToAdd == 0 )
|
||||
return dest;
|
||||
|
||||
if( dest == null || dest.length == 0 ){
|
||||
dest = (Object[]) Array.newInstance( c, numToAdd );
|
||||
System.arraycopy( source, 0, dest, 0, numToAdd );
|
||||
return dest;
|
||||
}
|
||||
|
||||
int firstFree = 0;
|
||||
while( firstFree < dest.length && dest[firstFree] != null )
|
||||
firstFree++;
|
||||
|
||||
if( firstFree + numToAdd <= dest.length ){
|
||||
System.arraycopy( source, 0, dest, firstFree, numToAdd );
|
||||
return dest;
|
||||
}
|
||||
Object [] temp = (Object[]) Array.newInstance( c, firstFree + numToAdd );
|
||||
System.arraycopy( dest, 0, temp, 0, firstFree );
|
||||
System.arraycopy( source, 0, temp, firstFree, numToAdd );
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
@ -131,7 +131,7 @@ public class ProblemBinding implements IProblemBinding, IType, IScope {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||
*/
|
||||
public List find( String name ) throws DOMException {
|
||||
public IBinding[] find( String name ) throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
||||
|
@ -68,7 +66,7 @@ public class CCompositeTypeScope implements ICCompositeTypeScope {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||
*/
|
||||
public List find( String name ) {
|
||||
public IBinding[] find( String name ) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
|
||||
|
@ -23,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.ILabel;
|
|||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICScope;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
||||
|
||||
|
@ -80,26 +78,28 @@ public class CFunctionScope implements ICFunctionScope {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||
*/
|
||||
public List find(String name) {
|
||||
public IBinding[] find(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List getLabels(){
|
||||
public ILabel[] getLabels(){
|
||||
FindLabelsAction action = new FindLabelsAction();
|
||||
CVisitor.visitDeclaration( function, action );
|
||||
|
||||
List list = new ArrayList();
|
||||
for( int i = 0; i < action.labels.size(); i++ ){
|
||||
IASTLabelStatement labelStatement = (IASTLabelStatement) action.labels.get(i);
|
||||
IBinding binding = labelStatement.getName().resolveBinding();
|
||||
if( binding != null )
|
||||
list.add( binding );
|
||||
ILabel [] result = null;
|
||||
if( action.labels != null ){
|
||||
for( int i = 0; i < action.labels.length && action.labels[i] != null; i++ ){
|
||||
IASTLabelStatement labelStatement = action.labels[i];
|
||||
IBinding binding = labelStatement.getName().resolveBinding();
|
||||
if( binding != null )
|
||||
result = (ILabel[]) ArrayUtil.append( ILabel.class, result, binding );
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return (ILabel[]) ArrayUtil.trim( ILabel.class, result );
|
||||
}
|
||||
|
||||
static private class FindLabelsAction extends CBaseVisitorAction {
|
||||
public List labels = new ArrayList();
|
||||
public IASTLabelStatement [] labels = null;
|
||||
|
||||
public FindLabelsAction(){
|
||||
processStatements = true;
|
||||
|
@ -107,7 +107,7 @@ public class CFunctionScope implements ICFunctionScope {
|
|||
|
||||
public int processStatement( IASTStatement statement ) {
|
||||
if( statement instanceof IASTLabelStatement ){
|
||||
labels.add( statement );
|
||||
labels = (IASTLabelStatement[]) ArrayUtil.append( IASTLabelStatement.class, labels, statement );
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
|
@ -46,7 +44,7 @@ public class CScope implements ICScope {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||
*/
|
||||
public List find( String name ) {
|
||||
public IBinding[] find( String name ) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
|
@ -550,9 +548,9 @@ public class CVisitor {
|
|||
IScope scope = getContainingScope( statement );
|
||||
if( scope != null && scope instanceof ICFunctionScope ){
|
||||
CFunctionScope functionScope = (CFunctionScope) scope;
|
||||
List labels = functionScope.getLabels();
|
||||
for( int i = 0; i < labels.size(); i++ ){
|
||||
ILabel label = (ILabel) labels.get(i);
|
||||
ILabel [] labels = functionScope.getLabels();
|
||||
for( int i = 0; i < labels.length; i++ ){
|
||||
ILabel label = labels[i];
|
||||
if( CharArrayUtils.equals( label.getNameCharArray(), gotoName) ){
|
||||
return label;
|
||||
}
|
||||
|
|
|
@ -13,10 +13,6 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -32,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
|
@ -95,13 +92,10 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
char [] c = binding.getNameCharArray();
|
||||
Object o = bindings.get( c );
|
||||
if( o != null ){
|
||||
if( o instanceof List ){
|
||||
((List)o).add( binding );
|
||||
if( o instanceof IBinding[] ){
|
||||
bindings.put( c, ArrayUtil.append( IBinding.class, (Object[]) o, binding ) );
|
||||
} else {
|
||||
List list = new ArrayList(2);
|
||||
list.add( o );
|
||||
list.add( binding );
|
||||
bindings.put( c, list );
|
||||
bindings.put( c, new IBinding[] { (IBinding) o, binding } );
|
||||
}
|
||||
} else {
|
||||
bindings.put( c, binding );
|
||||
|
@ -135,7 +129,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
if( isConstructorReference( name ) ){
|
||||
if( constructors == null )
|
||||
return null;
|
||||
return CPPSemantics.resolveAmbiguities( name, Arrays.asList( constructors ) );
|
||||
return CPPSemantics.resolveAmbiguities( name, constructors );
|
||||
}
|
||||
//9.2 ... The class-name is also inserted into the scope of the class itself
|
||||
return compType.getName().resolveBinding();
|
||||
|
@ -143,8 +137,8 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
|
||||
Object obj = bindings.get( c );
|
||||
if( obj != null ){
|
||||
if( obj instanceof List ){
|
||||
obj = CPPSemantics.resolveAmbiguities( name, (List) obj );
|
||||
if( obj instanceof IBinding[] ){
|
||||
obj = CPPSemantics.resolveAmbiguities( name, (IBinding[]) obj );
|
||||
}
|
||||
}
|
||||
return (IBinding) obj;
|
||||
|
@ -172,7 +166,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||
*/
|
||||
public List find(String name) {
|
||||
public IBinding[] find(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
public IScope getParent() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public List find(String name) throws DOMException {
|
||||
public IBinding[] find(String name) throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public IBinding[] getFriends() throws DOMException {
|
||||
|
|
|
@ -13,13 +13,12 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPCompositeBinding;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -28,9 +27,8 @@ public class CPPCompositeBinding implements ICPPCompositeBinding {
|
|||
|
||||
IBinding [] bindings = null;
|
||||
|
||||
public CPPCompositeBinding( List bindingList ){
|
||||
bindings = new IBinding[ bindingList.size() ];
|
||||
bindingList.toArray( bindings );
|
||||
public CPPCompositeBinding( IBinding[] bindingList ){
|
||||
bindings = (IBinding[]) ArrayUtil.trim( IBinding.class, bindingList, true );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -14,7 +14,11 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
|
||||
/**
|
||||
|
@ -30,12 +34,12 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPBinding {
|
|||
super( id, arg );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility()
|
||||
*/
|
||||
public int getVisibility() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
}
|
||||
|
||||
public CPPField( IASTDeclarator declarator ){
|
||||
|
@ -49,4 +53,20 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPBinding {
|
|||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#isStatic()
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
IASTDeclarator dtor = (IASTDeclarator) getPhysicalNode();
|
||||
while( dtor.getPropertyInParent() == IASTDeclarator.NESTED_DECLARATOR )
|
||||
dtor = (IASTDeclarator) dtor.getParent();
|
||||
|
||||
IASTNode node = dtor.getParent();
|
||||
if( node instanceof IASTSimpleDeclaration ){
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)node).getDeclSpecifier();
|
||||
return (declSpec.getStorageClass() == IASTDeclSpecifier.sc_static );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -66,7 +64,7 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||
*/
|
||||
public List find(String name) {
|
||||
public IBinding[] find(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -15,13 +15,16 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
|
||||
|
@ -46,6 +49,9 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
public int getVisibility() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
public boolean isStatic() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
}
|
||||
|
||||
public CPPMethod( ICPPASTFunctionDeclarator declarator ){
|
||||
|
@ -141,4 +147,25 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
}
|
||||
return declarations[0].getName().toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#isStatic()
|
||||
*/
|
||||
public boolean isStatic() throws DOMException {
|
||||
IASTDeclarator dtor = (IASTDeclarator) getPrimaryDeclaration();
|
||||
if( dtor == null ) return false;
|
||||
|
||||
while( dtor.getPropertyInParent() == IASTDeclarator.NESTED_DECLARATOR )
|
||||
dtor = (IASTDeclarator) dtor.getParent();
|
||||
|
||||
IASTNode node = dtor.getParent();
|
||||
if( node instanceof IASTSimpleDeclaration ){
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)node).getDeclSpecifier();
|
||||
return (declSpec.getStorageClass() == IASTDeclSpecifier.sc_static );
|
||||
} else if( node instanceof IASTFunctionDefinition ){
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)node).getDeclSpecifier();
|
||||
return (declSpec.getStorageClass() == IASTDeclSpecifier.sc_static );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,14 +13,12 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
|
||||
/**
|
||||
|
@ -41,13 +39,10 @@ public class CPPNamespaceScope extends CPPScope implements ICPPNamespaceScope{
|
|||
char [] c = binding.getNameCharArray();
|
||||
Object o = bindings.get( c );
|
||||
if( o != null ){
|
||||
if( o instanceof List ){
|
||||
((List)o).add( binding );
|
||||
if( o instanceof IBinding[] ){
|
||||
bindings.put( c, ArrayUtil.append( IBinding.class, (Object[]) o, binding ) );
|
||||
} else {
|
||||
List list = new ArrayList(2);
|
||||
list.add( o );
|
||||
list.add( binding );
|
||||
bindings.put( c, list );
|
||||
bindings.put( c, new IBinding[] { (IBinding) o, binding } );
|
||||
}
|
||||
} else {
|
||||
bindings.put( c, binding );
|
||||
|
@ -61,8 +56,8 @@ public class CPPNamespaceScope extends CPPScope implements ICPPNamespaceScope{
|
|||
char [] c = name.toCharArray();
|
||||
Object obj = bindings.get( c );
|
||||
if( obj != null ){
|
||||
if( obj instanceof List ){
|
||||
obj = CPPSemantics.resolveAmbiguities( name, (List) obj );
|
||||
if( obj instanceof IBinding[] ){
|
||||
obj = CPPSemantics.resolveAmbiguities( name, (IBinding[]) obj );
|
||||
}
|
||||
}
|
||||
return (IBinding) obj;
|
||||
|
@ -71,7 +66,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPNamespaceScope{
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||
*/
|
||||
public List find(String name) {
|
||||
public IBinding[] find(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -43,7 +41,7 @@ abstract public class CPPScope implements ICPPScope{
|
|||
throw new DOMException( this );
|
||||
}
|
||||
|
||||
public List find( String name ) throws DOMException {
|
||||
public IBinding[] find( String name ) throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,6 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
|
@ -47,6 +43,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
|
@ -76,6 +73,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPCompositeBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
|
@ -84,13 +82,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil.ArrayWrapper;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -114,7 +112,7 @@ public class CPPSemantics {
|
|||
public boolean ignoreUsingDirectives = false;
|
||||
public boolean usingDirectivesOnly = false;
|
||||
public boolean forceQualified = false;
|
||||
public List foundItems = null;
|
||||
public Object [] foundItems = null;
|
||||
public Object [] functionParameters;
|
||||
public boolean forUserDefinedConversion;
|
||||
public ProblemBinding problem;
|
||||
|
@ -564,31 +562,28 @@ public class CPPSemantics {
|
|||
if( scope.getPhysicalNode() != blockItem.getParent() && !(scope instanceof ICPPNamespaceScope) )
|
||||
blockItem = node;
|
||||
|
||||
List directives = null;
|
||||
ArrayWrapper directives = null;
|
||||
if( !data.usingDirectivesOnly ){
|
||||
IBinding binding = scope.getBinding( data.astName );
|
||||
if( binding == null ){
|
||||
directives = new ArrayList(2);
|
||||
directives = new ArrayWrapper();
|
||||
data.foundItems = lookupInScope( data, scope, blockItem, directives );
|
||||
} else {
|
||||
data.foundItems = new ArrayList();
|
||||
data.foundItems.add( binding );
|
||||
data.foundItems = ArrayUtil.append( Object.class, data.foundItems, binding );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( !data.ignoreUsingDirectives ) {
|
||||
data.visited.clear();
|
||||
if( data.foundItems == null || data.foundItems.isEmpty() ){
|
||||
List transitives = lookupInNominated( data, scope, null );
|
||||
if( data.foundItems == null || data.foundItems.length == 0 ){
|
||||
Object[] transitives = lookupInNominated( data, scope, null );
|
||||
|
||||
processDirectives( data, scope, transitives );
|
||||
if( directives != null && directives.size() != 0 )
|
||||
processDirectives( data, scope, directives );
|
||||
if( directives != null && directives.array != null && directives.array.length != 0 )
|
||||
processDirectives( data, scope, directives.array );
|
||||
|
||||
while( !data.usingDirectives.isEmpty() && data.usingDirectives.get( scope ) != null ){
|
||||
if( transitives != null )
|
||||
transitives.clear();
|
||||
transitives = lookupInNominated( data, scope, transitives );
|
||||
|
||||
if( !data.qualified() || data.foundItems == null ){
|
||||
|
@ -598,14 +593,14 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
if( data.problem != null || data.foundItems != null && !data.foundItems.isEmpty() )
|
||||
if( data.problem != null || data.foundItems != null && data.foundItems.length != 0 )
|
||||
return;
|
||||
|
||||
if( !data.usingDirectivesOnly && scope instanceof ICPPClassScope ){
|
||||
data.foundItems = lookupInParents( data, (ICPPClassScope) scope );
|
||||
}
|
||||
|
||||
if( data.problem != null || data.foundItems != null && !data.foundItems.isEmpty() )
|
||||
if( data.problem != null || data.foundItems != null && data.foundItems.length != 0 )
|
||||
return;
|
||||
|
||||
//if still not found, loop and check our containing scope
|
||||
|
@ -618,12 +613,12 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
private static List lookupInParents( CPPSemantics.LookupData data, ICPPClassScope lookIn ) throws DOMException{
|
||||
private static IASTName[] lookupInParents( CPPSemantics.LookupData data, ICPPClassScope lookIn ) throws DOMException{
|
||||
ICPPASTCompositeTypeSpecifier compositeTypeSpec = (ICPPASTCompositeTypeSpecifier) lookIn.getPhysicalNode();
|
||||
ICPPASTBaseSpecifier [] bases = compositeTypeSpec.getBaseSpecifiers();
|
||||
|
||||
List inherited = null;
|
||||
List result = null;
|
||||
IASTName[] inherited = null;
|
||||
IASTName[] result = null;
|
||||
|
||||
if( bases.length == 0 )
|
||||
return null;
|
||||
|
@ -664,7 +659,7 @@ public class CPPSemantics {
|
|||
//is this name define in this scope?
|
||||
inherited = lookupInScope( data, parent, null, null );
|
||||
|
||||
if( inherited == null || inherited.isEmpty() ){
|
||||
if( inherited == null || inherited.length == 0 ){
|
||||
inherited = lookupInParents( data, parent );
|
||||
}
|
||||
} else {
|
||||
|
@ -673,13 +668,13 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
if( inherited != null && !inherited.isEmpty() ){
|
||||
if( result == null || result.isEmpty() ){
|
||||
if( inherited != null && inherited.length != 0 ){
|
||||
if( result == null || result.length == 0 ){
|
||||
result = inherited;
|
||||
} else if ( inherited != null && !inherited.isEmpty() ) {
|
||||
for( int j = 0; j < result.size(); j++ ) {
|
||||
IASTName n = (IASTName) result.get(j);
|
||||
if( !checkAmbiguity( n, inherited ) ){
|
||||
} else if ( inherited != null && inherited.length != 0 ) {
|
||||
for( int j = 0; j < result.length && result[j] != null; j++ ) {
|
||||
IASTName n = result[j];
|
||||
if( checkAmbiguity( n, inherited ) ){
|
||||
data.problem = new ProblemBinding( IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, n.toCharArray() );
|
||||
return null;
|
||||
}
|
||||
|
@ -695,40 +690,39 @@ public class CPPSemantics {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static boolean checkAmbiguity( Object obj1, Object obj2 ){
|
||||
//it is not ambiguous if they are the same thing and it is static or an enumerator
|
||||
if( obj1 == obj2 ){
|
||||
List objList = ( obj1 instanceof List ) ? (List) obj1 : null;
|
||||
int objListSize = ( objList != null ) ? objList.size() : 0;
|
||||
ISymbol symbol = ( objList != null ) ? (ISymbol) objList.get(0) : ( ISymbol )obj1;
|
||||
int idx = 1;
|
||||
while( symbol != null ) {
|
||||
ITypeInfo type = ((ISymbol)obj1).getTypeInfo();
|
||||
if( !type.checkBit( ITypeInfo.isStatic ) && !type.isType( ITypeInfo.t_enumerator ) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
if( objList != null && idx < objListSize ){
|
||||
symbol = (ISymbol) objList.get( idx++ );
|
||||
} else {
|
||||
symbol = null;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private static boolean checkAmbiguity( IASTName n, IASTName []names ) throws DOMException{
|
||||
names = (IASTName[]) ArrayUtil.trim( IASTName.class, names );
|
||||
if( names.length == 0 )
|
||||
return false;
|
||||
|
||||
//it is not ambiguous if they are the same thing and it is static or an enumerator
|
||||
IBinding binding = n.resolveBinding();
|
||||
for( int i = 0; i < names.length && names[i] != null; i++ ){
|
||||
|
||||
IBinding b = names[i].resolveBinding();
|
||||
|
||||
if( binding != b )
|
||||
return true;
|
||||
if( binding instanceof IEnumerator )
|
||||
continue;
|
||||
else if( binding instanceof ICPPMember && ((ICPPMember)binding).isStatic() )
|
||||
continue;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static private void processDirectives( CPPSemantics.LookupData data, IScope scope, List directives ) throws DOMException{
|
||||
if( directives == null || directives.size() == 0 )
|
||||
static private void processDirectives( CPPSemantics.LookupData data, IScope scope, Object[] directives ) throws DOMException{
|
||||
if( directives == null || directives.length == 0 )
|
||||
return;
|
||||
|
||||
ICPPScope enclosing = null;
|
||||
IScope temp = null;
|
||||
|
||||
int size = directives.size();
|
||||
for( int i = 0; i < size; i++ ){
|
||||
Object d = directives.get(i);
|
||||
int size = directives.length;
|
||||
for( int i = 0; i < size && directives[i] != null; i++ ){
|
||||
Object d = directives[i];
|
||||
IBinding binding = null;
|
||||
if( d instanceof ICPPASTUsingDirective ){
|
||||
binding = ((ICPPASTUsingDirective)d).getQualifiedName().resolveBinding();
|
||||
|
@ -744,18 +738,14 @@ public class CPPSemantics {
|
|||
if( !data.visited.containsKey( temp ) ){
|
||||
enclosing = getClosestEnclosingScope( scope, temp );
|
||||
|
||||
//data.usingDirectives is a map from enclosing scope to a list
|
||||
//data.usingDirectives is a map from enclosing scope to a IScope[]
|
||||
//of namespaces to consider when we reach that enclosing scope
|
||||
List list = data.usingDirectives.isEmpty() ? null : (List) data.usingDirectives.get( enclosing );
|
||||
if( list == null ){
|
||||
list = new ArrayList();
|
||||
|
||||
if( data.usingDirectives == ObjectMap.EMPTY_MAP ){
|
||||
data.usingDirectives = new ObjectMap(2);
|
||||
}
|
||||
data.usingDirectives.put( enclosing, list );
|
||||
}
|
||||
list.add( temp );
|
||||
IScope [] scopes = (IScope[]) ( data.usingDirectives.isEmpty() ? null : data.usingDirectives.get( enclosing ) );
|
||||
scopes = (IScope[]) ArrayUtil.append( IScope.class, scopes, temp );
|
||||
if( data.usingDirectives == ObjectMap.EMPTY_MAP ){
|
||||
data.usingDirectives = new ObjectMap(2);
|
||||
}
|
||||
data.usingDirectives.put( enclosing, scopes );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -781,7 +771,7 @@ public class CPPSemantics {
|
|||
* @return List of encountered using directives
|
||||
* @throws DOMException
|
||||
*/
|
||||
static private List lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem, List usingDirectives ) throws DOMException {
|
||||
static private IASTName[] lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem, ArrayWrapper usingDirectives ) throws DOMException {
|
||||
IASTName possible = null;
|
||||
IASTNode [] nodes = null;
|
||||
IASTNode parent = scope.getPhysicalNode();
|
||||
|
@ -794,7 +784,7 @@ public class CPPSemantics {
|
|||
data.associated.remove( scope );
|
||||
}
|
||||
|
||||
List found = null;
|
||||
IASTName[] found = null;
|
||||
|
||||
if( parent instanceof IASTCompoundStatement ){
|
||||
if( parent.getParent() instanceof IASTFunctionDefinition ){
|
||||
|
@ -838,13 +828,11 @@ public class CPPSemantics {
|
|||
((ICPPASTNamespaceDefinition)item).getName().toCharArray().length == 0) ) )
|
||||
{
|
||||
if( usingDirectives != null )
|
||||
usingDirectives.add( item );
|
||||
usingDirectives.array = ArrayUtil.append( usingDirectives.array, item );
|
||||
} else {
|
||||
possible = collectResult( data, scope, item, (item == parent) );
|
||||
if( possible != null ){
|
||||
if( found == null )
|
||||
found = new ArrayList(2);
|
||||
found.add( possible );
|
||||
found = (IASTName[]) ArrayUtil.append( IASTName.class, found, possible );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -880,38 +868,34 @@ public class CPPSemantics {
|
|||
return found;
|
||||
}
|
||||
|
||||
static private List lookupInNominated( CPPSemantics.LookupData data, ICPPScope scope, List transitives ) throws DOMException{
|
||||
static private Object[] lookupInNominated( CPPSemantics.LookupData data, ICPPScope scope, Object[] transitives ) throws DOMException{
|
||||
if( data.usingDirectives.isEmpty() )
|
||||
return transitives;
|
||||
|
||||
List directives = null;
|
||||
ICPPScope temp = null;
|
||||
|
||||
directives = (List) data.usingDirectives.remove( scope );
|
||||
if( directives == null || directives.size() == 0 ) {
|
||||
IScope [] directives = (IScope[]) data.usingDirectives.remove( scope );
|
||||
if( directives == null || directives.length == 0 ) {
|
||||
return transitives;
|
||||
}
|
||||
for( int i = 0; i < directives.size(); i++ ){
|
||||
temp = (ICPPScope) directives.get(i);
|
||||
for( int i = 0; i < directives.length && directives[i] != null; i++ ){
|
||||
temp = (ICPPScope) directives[i];
|
||||
if( !data.visited.containsKey( temp ) ){
|
||||
if( data.visited == ObjectSet.EMPTY_SET ) {
|
||||
data.visited = new ObjectSet(2);
|
||||
}
|
||||
data.visited.put( temp );
|
||||
List usings = new ArrayList(2);
|
||||
List found = lookupInScope( data, temp, null, usings );
|
||||
ArrayWrapper usings = new ArrayWrapper();
|
||||
Object[] found = lookupInScope( data, temp, null, usings );
|
||||
if( data.foundItems == null )
|
||||
data.foundItems = found;
|
||||
else if( found != null )
|
||||
data.foundItems.addAll( found );
|
||||
|
||||
data.foundItems = ArrayUtil.addAll( Object.class, data.foundItems, found );
|
||||
|
||||
//only consider the transitive using directives if we are an unqualified
|
||||
//lookup, or we didn't find the name in decl
|
||||
if( usings != null && usings.size() > 0 && (!data.qualified() || found == null ) ){
|
||||
if( transitives == null )
|
||||
transitives = new ArrayList(2);
|
||||
transitives.addAll( usings );
|
||||
if( usings.array != null && usings.array.length > 0 && (!data.qualified() || found == null ) ){
|
||||
transitives = ArrayUtil.addAll( Object.class, transitives, usings.array );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1054,11 +1038,12 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
static protected IBinding resolveAmbiguities( IASTName name, List bindings ){
|
||||
if( bindings == null || bindings.size() == 0 )
|
||||
static protected IBinding resolveAmbiguities( IASTName name, IBinding[] bindings ){
|
||||
bindings = (IBinding[]) ArrayUtil.trim( IBinding.class, bindings );
|
||||
if( bindings == null || bindings.length == 0 )
|
||||
return null;
|
||||
else if( bindings.size() == 1 )
|
||||
return (IBinding) bindings.get( 0 );
|
||||
else if( bindings.length == 1 )
|
||||
return bindings[ 0 ];
|
||||
|
||||
LookupData data = createLookupData( name );
|
||||
data.foundItems = bindings;
|
||||
|
@ -1084,16 +1069,16 @@ public class CPPSemantics {
|
|||
}
|
||||
|
||||
static private IBinding resolveAmbiguities( CPPSemantics.LookupData data, IASTName name ) throws DOMException {
|
||||
if( data.foundItems == null || data.foundItems.size() == 0 )
|
||||
if( data.foundItems == null || data.foundItems.length == 0 )
|
||||
return null;
|
||||
|
||||
IBinding type = null;
|
||||
IBinding obj = null;
|
||||
IBinding temp = null;
|
||||
List fns = null;
|
||||
IFunction[] fns = null;
|
||||
|
||||
for( int i = 0; i < data.foundItems.size(); i++ ){
|
||||
Object o = data.foundItems.get( i );
|
||||
for( int i = 0; i < data.foundItems.length && data.foundItems[i] != null; i++ ){
|
||||
Object o = data.foundItems[i];
|
||||
if( o instanceof IASTName )
|
||||
temp = ((IASTName) o).resolveBinding();
|
||||
else if( o instanceof IBinding ){
|
||||
|
@ -1105,8 +1090,7 @@ public class CPPSemantics {
|
|||
|
||||
if( temp instanceof ICPPCompositeBinding ){
|
||||
IBinding [] bindings = ((ICPPCompositeBinding) temp).getBindings();
|
||||
for( int j = 0; j < bindings.length; j++ )
|
||||
data.foundItems.add( bindings[j] );
|
||||
data.foundItems = ArrayUtil.addAll( Object.class, data.foundItems, bindings );
|
||||
continue;
|
||||
} else if( temp instanceof IType ){
|
||||
if( type == null ){
|
||||
|
@ -1115,9 +1099,7 @@ public class CPPSemantics {
|
|||
return new ProblemBinding( IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
|
||||
}
|
||||
} else if( temp instanceof IFunction ){
|
||||
if( fns == null )
|
||||
fns = new ArrayList(2);
|
||||
fns.add( temp );
|
||||
fns = (IFunction[]) ArrayUtil.append( IFunction.class, fns, temp );
|
||||
} else {
|
||||
if( obj == null )
|
||||
obj = temp;
|
||||
|
@ -1134,8 +1116,8 @@ public class CPPSemantics {
|
|||
if( obj != null && obj.getScope() != typeScope ){
|
||||
return new ProblemBinding( IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
|
||||
} else if( fns != null ){
|
||||
for( int i = 0; i < fns.size(); i++ ){
|
||||
if( ((IBinding)fns.get(i)).getScope() != typeScope )
|
||||
for( int i = 0; i < fns.length && fns[i] != null; i++ ){
|
||||
if( ((IBinding)fns[i]).getScope() != typeScope )
|
||||
return new ProblemBinding( IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name );
|
||||
}
|
||||
}
|
||||
|
@ -1163,7 +1145,10 @@ public class CPPSemantics {
|
|||
return false;
|
||||
}
|
||||
|
||||
static private void reduceToViable( LookupData data, List functions ) throws DOMException{
|
||||
static private void reduceToViable( LookupData data, IBinding[] functions ) throws DOMException{
|
||||
if( functions == null || functions.length == 0 )
|
||||
return;
|
||||
|
||||
Object [] fParams = data.functionParameters;
|
||||
int numParameters = ( fParams != null ) ? fParams.length : 0;
|
||||
int num;
|
||||
|
@ -1171,9 +1156,9 @@ public class CPPSemantics {
|
|||
//Trim the list down to the set of viable functions
|
||||
IFunction fName;
|
||||
ICPPASTFunctionDeclarator function = null;
|
||||
int size = functions.size();
|
||||
for( int i = 0; i < size; i++ ){
|
||||
fName = (IFunction) functions.get(i);
|
||||
int size = functions.length;
|
||||
for( int i = 0; i < size && functions[i] != null; i++ ){
|
||||
fName = (IFunction) functions[i];
|
||||
function = (ICPPASTFunctionDeclarator) ((ICPPBinding)fName).getDefinition();
|
||||
if( function == null ){
|
||||
IASTNode [] nodes = ((ICPPBinding) fName).getDeclarations();
|
||||
|
@ -1192,13 +1177,11 @@ public class CPPSemantics {
|
|||
//are viable
|
||||
if( num == numParameters ){
|
||||
if( data.forDefinition() && !functionHasParameters( fName, (IASTParameterDeclaration[]) data.functionParameters ) ){
|
||||
functions.remove( i-- );
|
||||
size--;
|
||||
functions[i] = null;
|
||||
}
|
||||
continue;
|
||||
} else if( function == null ){
|
||||
functions.remove( i-- );
|
||||
size--;
|
||||
functions[i] = null;
|
||||
continue;
|
||||
}
|
||||
//check for void
|
||||
|
@ -1221,8 +1204,7 @@ public class CPPSemantics {
|
|||
continue;
|
||||
}
|
||||
//not enough parameters, remove it
|
||||
functions.remove( i-- );
|
||||
size--;
|
||||
functions[i] = null;
|
||||
}
|
||||
//a candidate function having more than m parameters is viable only if the (m+1)-st
|
||||
//parameter has a default argument
|
||||
|
@ -1230,7 +1212,7 @@ public class CPPSemantics {
|
|||
IASTParameterDeclaration [] params = function.getParameters();
|
||||
for( int j = num - 1; j > ( numParameters - num); j-- ){
|
||||
if( params[j].getDeclarator().getInitializer() == null ){
|
||||
functions.remove( i-- );
|
||||
functions[i] = null;
|
||||
size--;
|
||||
break;
|
||||
}
|
||||
|
@ -1254,10 +1236,14 @@ public class CPPSemantics {
|
|||
return VOID_TYPE;
|
||||
return null;
|
||||
}
|
||||
static private IBinding resolveFunction( CPPSemantics.LookupData data, List fns ) throws DOMException{
|
||||
static private IBinding resolveFunction( CPPSemantics.LookupData data, IBinding[] fns ) throws DOMException{
|
||||
fns = (IBinding[]) ArrayUtil.trim( IBinding.class, fns );
|
||||
if( fns == null || fns.length == 0 )
|
||||
return null;
|
||||
|
||||
if( data.forUsingDeclaration() ){
|
||||
if( fns.size() == 1 )
|
||||
return (IBinding) fns.get( 0 );
|
||||
if( fns.length == 1 )
|
||||
return fns[ 0 ];
|
||||
return new CPPCompositeBinding( fns );
|
||||
}
|
||||
//reduce our set of candidate functions to only those who have the right number of parameters
|
||||
|
@ -1287,19 +1273,17 @@ public class CPPSemantics {
|
|||
IParameter [] targetBindings = null;
|
||||
int targetLength = 0;
|
||||
|
||||
int numFns = fns.size();
|
||||
int numFns = fns.length;
|
||||
int numSourceParams = ( data.functionParameters != null ) ? data.functionParameters.length : 0;
|
||||
if( data.functionParameters != null && numSourceParams == 0 )
|
||||
numSourceParams = 1;
|
||||
sourceParameters = data.functionParameters;
|
||||
|
||||
for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){
|
||||
currFn = (IFunction) fns.get( fnIdx );
|
||||
currFn = (IFunction) fns[fnIdx];
|
||||
|
||||
if( bestFn != null ){
|
||||
if( bestFn == currFn )
|
||||
continue;
|
||||
}
|
||||
if( currFn == null || bestFn == currFn )
|
||||
continue;
|
||||
|
||||
ICPPASTFunctionDeclarator currDtor = (ICPPASTFunctionDeclarator) ((ICPPBinding)currFn).getDefinition();
|
||||
if( currDtor == null ){
|
||||
|
@ -1479,8 +1463,7 @@ public class CPPSemantics {
|
|||
|
||||
if( constructors.length > 0 ){
|
||||
//the list out of Arrays.asList does not support remove, which we need
|
||||
ArrayList list = new ArrayList( Arrays.asList( constructors ) );
|
||||
constructor = (ICPPConstructor) resolveFunction( data, list );
|
||||
constructor = (ICPPConstructor) resolveFunction( data, constructors );
|
||||
}
|
||||
if( constructor != null && constructor.isExplicit() ){
|
||||
constructor = null;
|
||||
|
@ -1498,7 +1481,8 @@ public class CPPSemantics {
|
|||
|
||||
ICPPScope scope = (ICPPScope) ((ICPPClassType) s).getCompositeScope();
|
||||
data.foundItems = lookupInScope( data, scope, null, null );
|
||||
conversion = (ICPPMethod) ( (data.foundItems != null ) ? resolveFunction( data, data.foundItems ) : null );
|
||||
IBinding [] fns = (IBinding[]) ArrayUtil.append( IBinding.class, null, data.foundItems );
|
||||
conversion = (ICPPMethod) ( (data.foundItems != null ) ? resolveFunction( data, fns ) : null );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
|
@ -129,6 +127,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
|
@ -1480,7 +1479,6 @@ public class CPPVisitor {
|
|||
IType [] pTypes = new IType[ parameters.length ];
|
||||
IType pt = null;
|
||||
|
||||
ArrayList temp = new ArrayList();
|
||||
for( int i = 0; i < parameters.length; i++ ){
|
||||
try {
|
||||
pt = parameters[i].getType();
|
||||
|
@ -1488,7 +1486,8 @@ public class CPPVisitor {
|
|||
pt = e.getProblem();
|
||||
}
|
||||
|
||||
temp.add( pt.clone() );
|
||||
IType [] temp = new IType[] { (IType) pt.clone() };
|
||||
int lastIdx = 0;
|
||||
while( pt instanceof ITypeContainer){
|
||||
try {
|
||||
pt = ((ITypeContainer)pt).getType();
|
||||
|
@ -1497,23 +1496,25 @@ public class CPPVisitor {
|
|||
}
|
||||
if( pt instanceof ITypeContainer && !(pt instanceof ITypedef) ){
|
||||
IType t = (IType) pt.clone();
|
||||
((ITypeContainer) temp.get( temp.size() - 1 )).setType( t );
|
||||
temp.add( t );
|
||||
((ITypeContainer) temp[ lastIdx ]).setType( t );
|
||||
temp = (IType[]) ArrayUtil.append( IType.class, temp, t );
|
||||
lastIdx++;
|
||||
} else {
|
||||
temp.add( pt );
|
||||
temp = (IType[]) ArrayUtil.append( IType.class, temp, pt );
|
||||
lastIdx++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int lastIdx = temp.size() - 1;
|
||||
if( lastIdx > 0 && temp.get( lastIdx - 1 ) instanceof IQualifierType ){
|
||||
temp.remove( --lastIdx );
|
||||
|
||||
if( lastIdx > 0 && temp[ lastIdx - 1 ] instanceof IQualifierType ){
|
||||
temp[lastIdx - 1] = temp[lastIdx--];
|
||||
if( lastIdx > 0 ){
|
||||
ITypeContainer cont = (ITypeContainer) temp.get( lastIdx - 1 );
|
||||
cont.setType( (IType) temp.get( lastIdx ) );
|
||||
ITypeContainer cont = (ITypeContainer) temp[ lastIdx - 1 ];
|
||||
cont.setType( temp[ lastIdx ] );
|
||||
}
|
||||
}
|
||||
|
||||
IType lastType = (IType) temp.get( lastIdx );
|
||||
IType lastType = temp[ 0 ];
|
||||
if( lastType instanceof IArrayType ){
|
||||
try {
|
||||
lastType = new CPPPointerType( ((IArrayType) lastType).getType() );
|
||||
|
@ -1524,8 +1525,7 @@ public class CPPVisitor {
|
|||
lastType = new CPPPointerType( lastType );
|
||||
}
|
||||
|
||||
pTypes[i] = (IType) temp.get( 0 );
|
||||
|
||||
pTypes[i] = lastType;
|
||||
}
|
||||
|
||||
return new CPPFunctionType( returnType, pTypes );
|
||||
|
|
Loading…
Add table
Reference in a new issue