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

toString methods and generics.

This commit is contained in:
Sergey Prigogin 2008-02-25 00:00:32 +00:00
parent a2f9f9a4eb
commit bd4d1ba488
10 changed files with 558 additions and 552 deletions

View file

@ -25,6 +25,9 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier
private boolean isShort; private boolean isShort;
private boolean isLong; private boolean isLong;
/**
* @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier
*/
public int getType() { public int getType() {
return type; return type;
} }
@ -65,19 +68,19 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier
isShort = value; isShort = value;
} }
public boolean accept( ASTVisitor action ){ public boolean accept(ASTVisitor action) {
if( action.shouldVisitDeclSpecifiers ){ if (action.shouldVisitDeclSpecifiers) {
switch( action.visit( this ) ){ switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
if( action.shouldVisitDeclSpecifiers ){ if (action.shouldVisitDeclSpecifiers) {
switch( action.leave( this ) ){ switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
return true; return true;

View file

@ -29,9 +29,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
* @author jcamelon * @author jcamelon
*/ */
public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, IASTAmbiguityParent { public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, IASTAmbiguityParent {
private IASTName templateName; private IASTName templateName;
private IASTNode[] templateArguments = null;
private IBinding binding = null;
private int fResolutionDepth = 0;
public CPPASTTemplateId() { public CPPASTTemplateId() {
} }
@ -53,7 +54,7 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
} }
public void addTemplateArgument(IASTTypeId typeId) { public void addTemplateArgument(IASTTypeId typeId) {
templateArguments = (IASTNode[]) ArrayUtil.append( IASTNode.class, templateArguments, typeId ); templateArguments = (IASTNode[]) ArrayUtil.append(IASTNode.class, templateArguments, typeId);
if (typeId != null) { if (typeId != null) {
typeId.setParent(this); typeId.setParent(this);
typeId.setPropertyInParent(TEMPLATE_ID_ARGUMENT); typeId.setPropertyInParent(TEMPLATE_ID_ARGUMENT);
@ -61,7 +62,7 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
} }
public void addTemplateArgument(IASTExpression expression) { public void addTemplateArgument(IASTExpression expression) {
templateArguments = (IASTNode[]) ArrayUtil.append( IASTNode.class, templateArguments, expression ); templateArguments = (IASTNode[]) ArrayUtil.append(IASTNode.class, templateArguments, expression);
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
expression.setPropertyInParent(TEMPLATE_ID_ARGUMENT); expression.setPropertyInParent(TEMPLATE_ID_ARGUMENT);
@ -69,22 +70,17 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
} }
public IASTNode[] getTemplateArguments() { public IASTNode[] getTemplateArguments() {
if( templateArguments == null ) return ICPPASTTemplateId.EMPTY_ARG_ARRAY; if (templateArguments == null) return ICPPASTTemplateId.EMPTY_ARG_ARRAY;
return (IASTNode[]) ArrayUtil.trim( IASTNode.class, templateArguments ); return (IASTNode[]) ArrayUtil.trim(IASTNode.class, templateArguments);
} }
private IASTNode [] templateArguments = null;
private IBinding binding = null;
private int fResolutionDepth= 0;
public IBinding resolveBinding() { public IBinding resolveBinding() {
if (binding == null) { if (binding == null) {
// protect for infinite recursion // protect for infinite recursion
if (++fResolutionDepth > CPPASTName.MAX_RESOLUTION_DEPTH) { if (++fResolutionDepth > CPPASTName.MAX_RESOLUTION_DEPTH) {
binding= new CPPASTName.RecursionResolvingBinding(this); binding= new CPPASTName.RecursionResolvingBinding(this);
} } else {
else { binding = CPPTemplates.createBinding(this);
binding = CPPTemplates.createBinding( this );
} }
} }
@ -95,35 +91,35 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
return null; return null;
} }
public char[] toCharArray() { public char[] toCharArray() {
return templateName.toCharArray(); return templateName.toCharArray();
} }
@Override @Override
public String toString() { public String toString() {
return templateName.toString(); return templateName.toString();
} }
@Override @Override
public boolean accept( ASTVisitor action ){ public boolean accept(ASTVisitor action) {
if( action.shouldVisitNames ){ if (action.shouldVisitNames) {
switch( action.visit( this ) ){ switch(action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
if( templateName != null ) if( !templateName.accept( action ) ) return false; if (templateName != null && !templateName.accept(action)) return false;
IASTNode [] nodes = getTemplateArguments(); IASTNode[] nodes = getTemplateArguments();
for ( int i = 0; i < nodes.length; i++ ) { for (int i = 0; i < nodes.length; i++) {
if( !nodes[i].accept( action ) ) return false; if (!nodes[i].accept(action)) return false;
} }
if( action.shouldVisitNames ){ if (action.shouldVisitNames) {
switch( action.leave( this ) ){ switch(action.leave(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default: break;
} }
} }
return true; return true;
@ -138,7 +134,7 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
} }
public int getRoleForName(IASTName n) { public int getRoleForName(IASTName n) {
if( n == templateName ) if (n == templateName)
return r_reference; return r_reference;
return r_unclear; return r_unclear;
} }
@ -149,11 +145,11 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
public void setBinding(IBinding binding) { public void setBinding(IBinding binding) {
this.binding = binding; this.binding = binding;
fResolutionDepth= 0; fResolutionDepth = 0;
} }
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if( templateArguments == null ) return; if (templateArguments == null) return;
for (int i = 0; i < templateArguments.length; ++i) { for (int i = 0; i < templateArguments.length; ++i) {
if (child == templateArguments[i]) { if (child == templateArguments[i]) {
other.setPropertyInParent(child.getPropertyInParent()); other.setPropertyInParent(child.getPropertyInParent());
@ -167,15 +163,14 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
IASTNode parent = getParent(); IASTNode parent = getParent();
if (parent instanceof IASTNameOwner) { if (parent instanceof IASTNameOwner) {
int role = ((IASTNameOwner) parent).getRoleForName(this); int role = ((IASTNameOwner) parent).getRoleForName(this);
if( role == IASTNameOwner.r_definition ) return true; return role == IASTNameOwner.r_definition;
return false;
} }
return false; return false;
} }
public void incResolutionDepth() { public void incResolutionDepth() {
if (binding == null && ++fResolutionDepth > CPPASTName.MAX_RESOLUTION_DEPTH) { if (binding == null && ++fResolutionDepth > CPPASTName.MAX_RESOLUTION_DEPTH) {
binding= new CPPASTName.RecursionResolvingBinding(this); binding = new CPPASTName.RecursionResolvingBinding(this);
} }
} }

View file

@ -79,7 +79,7 @@ public class CPPASTUsingDirective extends CPPASTNode implements
public IBinding[] findBindings(IASTName n, boolean isPrefix) { public IBinding[] findBindings(IASTName n, boolean isPrefix) {
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix); IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
List filtered = new ArrayList(); List<IBinding> filtered = new ArrayList<IBinding>();
for (int i = 0;i < bindings.length; i++) { for (int i = 0;i < bindings.length; i++) {
if (bindings[i] instanceof ICPPNamespace) { if (bindings[i] instanceof ICPPNamespace) {
@ -87,6 +87,6 @@ public class CPPASTUsingDirective extends CPPASTNode implements
} }
} }
return (IBinding[]) filtered.toArray(new IBinding[filtered.size()]); return filtered.toArray(new IBinding[filtered.size()]);
} }
} }

View file

@ -42,8 +42,8 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @param args * @param args
* @param arguments * @param arguments
*/ */
public CPPClassInstance( ICPPScope scope, IBinding decl, ObjectMap argMap, IType[] args ) { public CPPClassInstance(ICPPScope scope, IBinding decl, ObjectMap argMap, IType[] args) {
super( scope, decl, argMap, args ); super(scope, decl, argMap, args);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -51,17 +51,17 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
*/ */
public ICPPBase[] getBases() throws DOMException { public ICPPBase[] getBases() throws DOMException {
ICPPClassType cls = (ICPPClassType) getSpecializedBinding(); ICPPClassType cls = (ICPPClassType) getSpecializedBinding();
if( cls != null ){ if (cls != null) {
ICPPBase[] result = null; ICPPBase[] result = null;
ICPPBase [] bindings = cls.getBases(); ICPPBase[] bindings = cls.getBases();
for (int i = 0; i < bindings.length; i++) { for (int i = 0; i < bindings.length; i++) {
ICPPBase specBinding = (ICPPBase) ((ICPPInternalBase)bindings[i]).clone(); ICPPBase specBinding = (ICPPBase) ((ICPPInternalBase) bindings[i]).clone();
IBinding base = bindings[i].getBaseClass(); IBinding base = bindings[i].getBaseClass();
if (base instanceof IType) { if (base instanceof IType) {
IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap); IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap);
specBase = CPPSemantics.getUltimateType(specBase, false); specBase = CPPSemantics.getUltimateType(specBase, false);
if (specBase instanceof IBinding) { if (specBase instanceof IBinding) {
((ICPPInternalBase)specBinding).setBaseClass((IBinding)specBase); ((ICPPInternalBase) specBinding).setBaseClass((IBinding) specBase);
} }
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBinding); result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBinding);
} }
@ -75,7 +75,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields() * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields()
*/ */
public IField[] getFields() throws DOMException { public IField[] getFields() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -83,7 +82,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String)
*/ */
public IField findField(String name) throws DOMException { public IField findField(String name) throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -91,7 +89,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields()
*/ */
public ICPPField[] getDeclaredFields() throws DOMException { public ICPPField[] getDeclaredFields() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -99,7 +96,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods()
*/ */
public ICPPMethod[] getMethods() throws DOMException { public ICPPMethod[] getMethods() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -107,7 +103,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods()
*/ */
public ICPPMethod[] getAllDeclaredMethods() throws DOMException { public ICPPMethod[] getAllDeclaredMethods() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -115,7 +110,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods()
*/ */
public ICPPMethod[] getDeclaredMethods() throws DOMException { public ICPPMethod[] getDeclaredMethods() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -124,7 +118,7 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
*/ */
public ICPPConstructor[] getConstructors() throws DOMException { public ICPPConstructor[] getConstructors() throws DOMException {
CPPClassSpecializationScope scope = (CPPClassSpecializationScope) getCompositeScope(); CPPClassSpecializationScope scope = (CPPClassSpecializationScope) getCompositeScope();
if( scope.isFullyCached() ) if (scope.isFullyCached())
return scope.getConstructors(); return scope.getConstructors();
return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
} }
@ -133,7 +127,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFriends() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFriends()
*/ */
public IBinding[] getFriends() throws DOMException { public IBinding[] getFriends() throws DOMException {
// TODO Auto-generated method stub
return null; return null;
} }
@ -141,15 +134,15 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey() * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey()
*/ */
public int getKey() throws DOMException { public int getKey() throws DOMException {
return ((ICPPClassType)getSpecializedBinding()).getKey(); return ((ICPPClassType) getSpecializedBinding()).getKey();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope() * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope()
*/ */
public IScope getCompositeScope() { public IScope getCompositeScope() {
if( instanceScope == null ){ if (instanceScope == null) {
instanceScope = new CPPClassSpecializationScope( this ); instanceScope = new CPPClassSpecializationScope(this);
} }
return instanceScope; return instanceScope;
} }
@ -158,35 +151,35 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
* @see java.lang.Object#clone() * @see java.lang.Object#clone()
*/ */
@Override @Override
public Object clone(){ public Object clone() {
// TODO Auto-generated method stub
return this; return this;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/ */
public boolean isSameType( IType type ) { public boolean isSameType(IType type) {
if( type == this ) if (type == this)
return true; return true;
if( type instanceof ITypedef || type instanceof IIndexType ) if (type instanceof ITypedef || type instanceof IIndexType)
return type.isSameType( this ); return type.isSameType(this);
if( type instanceof ICPPDeferredTemplateInstance && type instanceof ICPPClassType ) if (type instanceof ICPPDeferredTemplateInstance && type instanceof ICPPClassType)
return type.isSameType( this ); //the CPPDeferredClassInstance has some fuzziness return type.isSameType(this); // the CPPDeferredClassInstance has some fuzziness
if( type instanceof ICPPTemplateInstance ){ if (type instanceof ICPPTemplateInstance) {
ICPPClassType ct1= (ICPPClassType) getSpecializedBinding(); ICPPClassType ct1= (ICPPClassType) getSpecializedBinding();
ICPPClassType ct2= (ICPPClassType) ((ICPPTemplateInstance)type).getTemplateDefinition(); ICPPClassType ct2= (ICPPClassType) ((ICPPTemplateInstance) type).getTemplateDefinition();
if(!ct1.isSameType(ct2)) if (!ct1.isSameType(ct2))
return false; return false;
ObjectMap m1 = getArgumentMap(), m2 = ((ICPPTemplateInstance)type).getArgumentMap(); ObjectMap m1 = getArgumentMap();
if( m1 == null || m2 == null || m1.size() != m2.size()) ObjectMap m2 = ((ICPPTemplateInstance) type).getArgumentMap();
if (m1 == null || m2 == null || m1.size() != m2.size())
return false; return false;
for( int i = 0; i < m1.size(); i++ ){ for (int i = 0; i < m1.size(); i++) {
IType t1 = (IType) m1.getAt( i ); IType t1 = (IType) m1.getAt(i);
IType t2 = (IType) m2.getAt( i ); IType t2 = (IType) m2.getAt(i);
if( t1 == null || ! t1.isSameType( t2 ) ) if (t1 == null || !t1.isSameType(t2))
return false; return false;
} }
return true; return true;
@ -210,6 +203,6 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj instanceof ICPPClassType ? isSameType((ICPPClassType)obj) : false; return obj instanceof ICPPClassType && isSameType((ICPPClassType) obj);
} }
} }

View file

@ -38,7 +38,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
@ -57,177 +56,177 @@ import org.eclipse.cdt.core.parser.util.ObjectSet;
* @author aniefer * @author aniefer
*/ */
public class CPPClassScope extends CPPScope implements ICPPClassScope { public class CPPClassScope extends CPPScope implements ICPPClassScope {
private static final char [] CONSTRUCTOR_KEY = "!!!CTOR!!!".toCharArray(); //$NON-NLS-1$ private static final char[] CONSTRUCTOR_KEY = "!!!CTOR!!!".toCharArray(); //$NON-NLS-1$
private ICPPMethod[] implicits = null; private ICPPMethod[] implicits = null;
public CPPClassScope( ICPPASTCompositeTypeSpecifier physicalNode ) { public CPPClassScope(ICPPASTCompositeTypeSpecifier physicalNode) {
super( physicalNode ); super(physicalNode);
((CPPASTCompositeTypeSpecifier)physicalNode).setScope( this ); ((CPPASTCompositeTypeSpecifier) physicalNode).setScope(this);
createImplicitMembers(); createImplicitMembers();
} }
// 12.1 The default constructor, copy constructor, copy assignment operator, and destructor are // 12.1 The default constructor, copy constructor, copy assignment operator, and destructor are
//special member functions. The implementation will implicitly declare these member functions //special member functions. The implementation will implicitly declare these member functions
//for a class type when the program does not declare them. //for a class type when the program does not declare them.
private void createImplicitMembers(){ private void createImplicitMembers() {
//create bindings for the implicit members, if the user declared them then those declarations //create bindings for the implicit members, if the user declared them then those declarations
//will resolve to these bindings. //will resolve to these bindings.
ICPPASTCompositeTypeSpecifier compTypeSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compTypeSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName name = compTypeSpec.getName(); IASTName name = compTypeSpec.getName();
if( name instanceof ICPPASTQualifiedName ){ if (name instanceof ICPPASTQualifiedName) {
IASTName [] ns = ((ICPPASTQualifiedName) name).getNames(); IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
name = ns[ ns.length - 1 ]; name = ns[ns.length - 1];
} }
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
if( !(binding instanceof ICPPClassType ) ) if (!(binding instanceof ICPPClassType))
return; return;
ICPPClassType clsType = (ICPPClassType) binding; ICPPClassType clsType = (ICPPClassType) binding;
if( clsType instanceof ICPPClassTemplate ){ if (clsType instanceof ICPPClassTemplate) {
try { try {
IBinding within = CPPTemplates.instantiateWithinClassTemplate( (ICPPClassTemplate) clsType ); IBinding within = CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) clsType);
if (within instanceof ICPPClassType) if (within instanceof ICPPClassType)
clsType = (ICPPClassType)within; clsType = (ICPPClassType)within;
} catch ( DOMException e ) { } catch (DOMException e) {
} }
} }
char [] className = name.toCharArray(); char[] className = name.toCharArray();
IParameter [] voidPs = new IParameter [] { new CPPParameter( CPPSemantics.VOID_TYPE ) }; IParameter[] voidPs = new IParameter[] { new CPPParameter(CPPSemantics.VOID_TYPE) };
IType pType = new CPPReferenceType( new CPPQualifierType( clsType, true, false ) ); IType pType = new CPPReferenceType(new CPPQualifierType(clsType, true, false));
IParameter [] ps = new IParameter [] { new CPPParameter( pType ) }; IParameter[] ps = new IParameter[] { new CPPParameter(pType) };
int i= 0; int i= 0;
ImplicitsAnalysis ia= new ImplicitsAnalysis( compTypeSpec ); ImplicitsAnalysis ia= new ImplicitsAnalysis(compTypeSpec);
implicits= new ICPPMethod[ia.getImplicitsToDeclareCount()]; implicits= new ICPPMethod[ia.getImplicitsToDeclareCount()];
if( !ia.hasUserDeclaredConstructor() ) { if (!ia.hasUserDeclaredConstructor()) {
//default constructor: A(void) //default constructor: A(void)
ICPPMethod m = new CPPImplicitConstructor( this, className, voidPs ); ICPPMethod m = new CPPImplicitConstructor(this, className, voidPs);
implicits[i++]=m; implicits[i++] = m;
addBinding( m ); addBinding(m);
} }
if( !ia.hasUserDeclaredCopyConstructor() ) { if (!ia.hasUserDeclaredCopyConstructor()) {
//copy constructor: A( const A & ) //copy constructor: A(const A &)
ICPPMethod m = new CPPImplicitConstructor( this, className, ps ); ICPPMethod m = new CPPImplicitConstructor(this, className, ps);
implicits[i++]=m; implicits[i++]=m;
addBinding( m ); addBinding(m);
} }
if( !ia.hasUserDeclaredCopyAssignmentOperator() ) { if (!ia.hasUserDeclaredCopyAssignmentOperator()) {
//copy assignment operator: A& operator = ( const A & ) //copy assignment operator: A& operator = (const A &)
IType refType = new CPPReferenceType( clsType ); IType refType = new CPPReferenceType(clsType);
ICPPMethod m = new CPPImplicitMethod( this, OverloadableOperator.ASSIGN.toCharArray(), refType, ps ); ICPPMethod m = new CPPImplicitMethod(this, OverloadableOperator.ASSIGN.toCharArray(), refType, ps);
implicits[i++]=m; implicits[i++] = m;
addBinding( m ); addBinding(m);
} }
if( !ia.hasUserDeclaredDestructor() ) { if (!ia.hasUserDeclaredDestructor()) {
//destructor: ~A() //destructor: ~A()
char [] dtorName = CharArrayUtils.concat( "~".toCharArray(), className ); //$NON-NLS-1$ char[] dtorName = CharArrayUtils.concat("~".toCharArray(), className); //$NON-NLS-1$
ICPPMethod m = new CPPImplicitMethod( this, dtorName, new CPPBasicType( IBasicType.t_unspecified, 0 ), voidPs ); ICPPMethod m = new CPPImplicitMethod(this, dtorName, new CPPBasicType(IBasicType.t_unspecified, 0), voidPs);
implicits[i++]=m; implicits[i++] = m;
addBinding( m ); addBinding(m);
} }
} }
public IScope getParent() { public IScope getParent() {
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName(); IASTName compName = compType.getName();
if( compName instanceof ICPPASTQualifiedName ){ if (compName instanceof ICPPASTQualifiedName) {
IASTName [] ns = ((ICPPASTQualifiedName)compName).getNames(); IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames();
compName = ns[ ns.length - 1 ]; compName = ns[ns.length - 1];
} }
return CPPVisitor.getContainingScope( compName ); return CPPVisitor.getContainingScope(compName);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#addBinding(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#addBinding(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
public void addBinding(IBinding binding) { public void addBinding(IBinding binding) {
if( binding instanceof ICPPConstructor ){ if (binding instanceof ICPPConstructor) {
addConstructor( binding ); addConstructor(binding);
return; return;
} }
super.addBinding(binding); super.addBinding(binding);
} }
public void addName(IASTName name) { public void addName(IASTName name) {
if( name instanceof ICPPASTQualifiedName ) if (name instanceof ICPPASTQualifiedName)
return; return;
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
if( parent instanceof IASTDeclarator ){ if (parent instanceof IASTDeclarator) {
if( CPPVisitor.isConstructor( this, (IASTDeclarator) parent ) ){ if (CPPVisitor.isConstructor(this, (IASTDeclarator) parent)) {
addConstructor( name ); addConstructor(name);
return; return;
} }
} }
super.addName( name ); super.addName(name);
} }
private void addConstructor( Object constructor ){ private void addConstructor(Object constructor) {
if( bindings == null ) if (bindings == null)
bindings = new CharArrayObjectMap(1); bindings = new CharArrayObjectMap(1);
if( constructor instanceof IASTName && ((IASTName)constructor).getBinding() != null ){ if (constructor instanceof IASTName && ((IASTName)constructor).getBinding() != null) {
constructor = ((IASTName)constructor).getBinding(); constructor = ((IASTName)constructor).getBinding();
} }
Object o = bindings.get( CONSTRUCTOR_KEY ); Object o = bindings.get(CONSTRUCTOR_KEY);
if( o != null ){ if (o != null) {
if( o instanceof ObjectSet ){ if (o instanceof ObjectSet) {
((ObjectSet)o).put( constructor ); ((ObjectSet)o).put(constructor);
} else { } else {
ObjectSet set = new ObjectSet(2); ObjectSet set = new ObjectSet(2);
set.put( o ); set.put(o);
set.put( constructor ); set.put(constructor);
bindings.put( CONSTRUCTOR_KEY, set ); bindings.put(CONSTRUCTOR_KEY, set);
} }
} else { } else {
bindings.put( CONSTRUCTOR_KEY, constructor ); bindings.put(CONSTRUCTOR_KEY, constructor);
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getBinding(int, char[]) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getBinding(int, char[])
*/ */
public IBinding getBinding( IASTName name, boolean resolve, IIndexFileSet fileSet ) throws DOMException { public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
char [] c = name.toCharArray(); char[] c = name.toCharArray();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName(); IASTName compName = compType.getName();
if( compName instanceof ICPPASTQualifiedName ){ if (compName instanceof ICPPASTQualifiedName) {
IASTName [] ns = ((ICPPASTQualifiedName)compName).getNames(); IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames();
compName = ns[ ns.length - 1 ]; compName = ns[ns.length - 1];
} }
if( CharArrayUtils.equals( c, compName.toCharArray() ) ){ if (CharArrayUtils.equals(c, compName.toCharArray())) {
if( isConstructorReference( name ) ){ if (isConstructorReference(name)) {
return CPPSemantics.resolveAmbiguities( name, getConstructors( bindings, resolve, name ) ); return CPPSemantics.resolveAmbiguities(name, getConstructors(bindings, resolve, name));
} }
//9.2 ... The class-name is also inserted into the scope of the class itself //9.2 ... The class-name is also inserted into the scope of the class itself
return compName.resolveBinding(); return compName.resolveBinding();
} }
return super.getBinding( name, resolve, fileSet); return super.getBinding(name, resolve, fileSet);
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException { public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
char [] c = name.toCharArray(); char[] c = name.toCharArray();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName(); IASTName compName = compType.getName();
if( compName instanceof ICPPASTQualifiedName ){ if (compName instanceof ICPPASTQualifiedName) {
IASTName [] ns = ((ICPPASTQualifiedName)compName).getNames(); IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames();
compName = ns[ ns.length - 1 ]; compName = ns[ns.length - 1];
} }
IBinding[] result = null; IBinding[] result = null;
if( (!prefixLookup && CharArrayUtils.equals( c, compName.toCharArray() )) if ((!prefixLookup && CharArrayUtils.equals(c, compName.toCharArray()))
|| (prefixLookup && CharArrayUtils.equals(compName.toCharArray(), 0, c.length, c, true)) ){ || (prefixLookup && CharArrayUtils.equals(compName.toCharArray(), 0, c.length, c, true))) {
if( isConstructorReference( name ) ){ if (isConstructorReference(name)) {
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, getConstructors( bindings, resolve, name )); result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, getConstructors(bindings, resolve, name));
} }
//9.2 ... The class-name is also inserted into the scope of the class itself //9.2 ... The class-name is also inserted into the scope of the class itself
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, compName.resolveBinding()); result = (IBinding[]) ArrayUtil.append(IBinding.class, result, compName.resolveBinding());
@ -235,60 +234,61 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
return (IBinding[]) ArrayUtil.trim(IBinding.class, result); return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
} }
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result,
super.getBindings( name, resolve, prefixLookup, fileSet )); super.getBindings(name, resolve, prefixLookup, fileSet));
return (IBinding[]) ArrayUtil.trim(IBinding.class, result); return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
} }
static protected boolean shouldResolve(boolean force, IASTName candidate, IASTName forName) { static protected boolean shouldResolve(boolean force, IASTName candidate, IASTName forName) {
if(!force || candidate == forName) if (!force || candidate == forName)
return false; return false;
if(forName == null) if (forName == null)
return true; return true;
if(!forName.isReference() && !CPPSemantics.declaredBefore(candidate, forName, false)) if (!forName.isReference() && !CPPSemantics.declaredBefore(candidate, forName, false))
return false; return false;
return true; return true;
} }
protected ICPPConstructor [] getConstructors( boolean forceResolve ){ protected ICPPConstructor[] getConstructors(boolean forceResolve) {
return getConstructors( bindings, forceResolve, null );
}
static protected ICPPConstructor [] getConstructors( CharArrayObjectMap bindings, boolean forceResolve ) {
return getConstructors(bindings, forceResolve, null); return getConstructors(bindings, forceResolve, null);
} }
static protected ICPPConstructor [] getConstructors( CharArrayObjectMap bindings, boolean forceResolve, IASTName forName ){ static protected ICPPConstructor[] getConstructors(CharArrayObjectMap bindings, boolean forceResolve) {
if( bindings == null ) return getConstructors(bindings, forceResolve, null);
}
static protected ICPPConstructor[] getConstructors(CharArrayObjectMap bindings, boolean forceResolve, IASTName forName) {
if (bindings == null)
return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
Object o = bindings.get( CONSTRUCTOR_KEY ); Object o = bindings.get(CONSTRUCTOR_KEY);
if( o != null ){ if (o != null) {
IBinding binding = null; IBinding binding = null;
if( o instanceof ObjectSet ) { if (o instanceof ObjectSet) {
ObjectSet set = (ObjectSet) o; ObjectSet set = (ObjectSet) o;
IBinding [] bs = null; IBinding[] bs = null;
for( int i = 0; i < set.size(); i++ ){ for (int i = 0; i < set.size(); i++) {
Object obj = set.keyAt( i ); Object obj = set.keyAt(i);
if( obj instanceof IASTName ){ if (obj instanceof IASTName) {
IASTName n = (IASTName) obj; IASTName n = (IASTName) obj;
binding = shouldResolve(forceResolve, n, forName) ? n.resolveBinding() : n.getBinding(); binding = shouldResolve(forceResolve, n, forName) ? n.resolveBinding() : n.getBinding();
if( binding != null ) { if (binding != null) {
set.remove( n ); set.remove(n);
set.put( binding ); set.put(binding);
i--; i--;
continue; continue;
} }
} else if( obj instanceof ICPPConstructor ) } else if (obj instanceof ICPPConstructor) {
bs = (IBinding[]) ArrayUtil.append( ICPPConstructor.class, bs, obj ); bs = (IBinding[]) ArrayUtil.append(ICPPConstructor.class, bs, obj);
}
} }
return (ICPPConstructor[]) ArrayUtil.trim( ICPPConstructor.class, bs ); return (ICPPConstructor[]) ArrayUtil.trim(ICPPConstructor.class, bs);
} else if( o instanceof IASTName ){ } else if (o instanceof IASTName) {
if( shouldResolve(forceResolve, (IASTName) o, forName) || ((IASTName)o).getBinding() != null ){ if (shouldResolve(forceResolve, (IASTName) o, forName) || ((IASTName)o).getBinding() != null) {
binding = ((IASTName)o).resolveBinding(); binding = ((IASTName)o).resolveBinding();
bindings.put( CONSTRUCTOR_KEY, binding ); bindings.put(CONSTRUCTOR_KEY, binding);
} }
} else if( o instanceof IBinding ){ } else if (o instanceof IBinding) {
binding = (IBinding) o; binding = (IBinding) o;
} }
if( binding != null && binding instanceof ICPPConstructor){ if (binding != null && binding instanceof ICPPConstructor) {
return new ICPPConstructor[] { (ICPPConstructor) binding }; return new ICPPConstructor[] { (ICPPConstructor) binding };
} }
} }
@ -299,36 +299,36 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/ */
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
char [] n = name.toCharArray(); char[] n = name.toCharArray();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName(); IASTName compName = compType.getName();
if( compName instanceof ICPPASTQualifiedName ){ if (compName instanceof ICPPASTQualifiedName) {
IASTName [] ns = ((ICPPASTQualifiedName)compName).getNames(); IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames();
compName = ns[ ns.length - 1 ]; compName = ns[ns.length - 1];
} }
if(CharArrayUtils.equals(compName.toCharArray(), n)) { if (CharArrayUtils.equals(compName.toCharArray(), n)) {
return new IBinding[] {getClassType()}; return new IBinding[] {getClassType()};
} }
return super.find(name); return super.find(name);
} }
public static boolean isConstructorReference( IASTName name ){ public static boolean isConstructorReference(IASTName name) {
if( name.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY ) return false; if (name.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) return false;
IASTNode node = name.getParent(); IASTNode node = name.getParent();
if( node instanceof ICPPASTTemplateId ) if (node instanceof ICPPASTTemplateId)
node = node.getParent(); node = node.getParent();
if( node instanceof ICPPASTQualifiedName ){ if (node instanceof ICPPASTQualifiedName) {
IASTName [] ns = ((ICPPASTQualifiedName)node).getNames(); IASTName[] ns = ((ICPPASTQualifiedName)node).getNames();
if( ns[ ns.length - 1 ] == name ) if (ns[ns.length - 1] == name)
node = node.getParent(); node = node.getParent();
else else
return false; return false;
} }
if( node instanceof IASTDeclSpecifier ){ if (node instanceof IASTDeclSpecifier) {
IASTNode parent = node.getParent(); IASTNode parent = node.getParent();
if( parent instanceof IASTTypeId && parent.getParent() instanceof ICPPASTNewExpression ) if (parent instanceof IASTTypeId && parent.getParent() instanceof ICPPASTNewExpression)
return true; return true;
return false; return false;
} }
@ -344,15 +344,15 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
if (binding instanceof ICPPClassType) if (binding instanceof ICPPClassType)
return (ICPPClassType) binding; return (ICPPClassType) binding;
return new CPPClassType.CPPClassTypeProblem( compSpec.getName(), IProblemBinding.SEMANTIC_BAD_SCOPE, compSpec.getName().toCharArray() ); return new CPPClassType.CPPClassTypeProblem(compSpec.getName(), IProblemBinding.SEMANTIC_BAD_SCOPE, compSpec.getName().toCharArray());
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope#getImplicitMethods() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope#getImplicitMethods()
*/ */
public ICPPMethod[] getImplicitMethods() { public ICPPMethod[] getImplicitMethods() {
if( implicits == null ) if (implicits == null)
implicits = new ICPPMethod[] { new CPPMethod.CPPMethodProblem( null, IProblemBinding.SEMANTIC_INVALID_TYPE, CPPSemantics.EMPTY_NAME_ARRAY ) }; implicits = new ICPPMethod[] { new CPPMethod.CPPMethodProblem(null, IProblemBinding.SEMANTIC_INVALID_TYPE, CPPSemantics.EMPTY_NAME_ARRAY) };
return implicits; return implicits;
} }
@ -361,7 +361,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
*/ */
public IName getScopeName() { public IName getScopeName() {
IASTNode node = getPhysicalNode(); IASTNode node = getPhysicalNode();
if( node instanceof ICPPASTCompositeTypeSpecifier ){ if (node instanceof ICPPASTCompositeTypeSpecifier) {
return ((ICPPASTCompositeTypeSpecifier)node).getName(); return ((ICPPASTCompositeTypeSpecifier)node).getName();
} }
return null; return null;
@ -371,10 +371,10 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
public void removeBinding(IBinding binding) { public void removeBinding(IBinding binding) {
if( binding instanceof ICPPConstructor ){ if (binding instanceof ICPPConstructor) {
removeBinding( CONSTRUCTOR_KEY, binding ); removeBinding(CONSTRUCTOR_KEY, binding);
} else { } else {
removeBinding( binding.getNameCharArray(), binding ); removeBinding(binding.getNameCharArray(), binding);
} }
} }
} }
@ -391,7 +391,7 @@ class ImplicitsAnalysis {
private boolean hasUserDeclaredCopyAssignmentOperator; private boolean hasUserDeclaredCopyAssignmentOperator;
private boolean hasUserDeclaredDestructor; private boolean hasUserDeclaredDestructor;
ImplicitsAnalysis( ICPPASTCompositeTypeSpecifier compSpec ) { ImplicitsAnalysis(ICPPASTCompositeTypeSpecifier compSpec) {
ICPPASTFunctionDeclarator[] ctors= getUserDeclaredCtorOrDtor(compSpec, true); ICPPASTFunctionDeclarator[] ctors= getUserDeclaredCtorOrDtor(compSpec, true);
hasUserDeclaredConstructor= ctors.length> 0; hasUserDeclaredConstructor= ctors.length> 0;
@ -399,14 +399,14 @@ class ImplicitsAnalysis {
hasUserDeclaredCopyAssignmentOperator= false; hasUserDeclaredCopyAssignmentOperator= false;
hasUserDeclaredDestructor= getUserDeclaredCtorOrDtor(compSpec, false).length>0; hasUserDeclaredDestructor= getUserDeclaredCtorOrDtor(compSpec, false).length>0;
outer: for(int i=0; i<ctors.length; i++) { outer: for (int i=0; i<ctors.length; i++) {
ICPPASTFunctionDeclarator dcltor= ctors[i]; ICPPASTFunctionDeclarator dcltor= ctors[i];
IASTParameterDeclaration [] ps = dcltor.getParameters(); IASTParameterDeclaration[] ps = dcltor.getParameters();
if( ps.length >= 1 ){ if (ps.length >= 1) {
if(paramHasTypeReferenceToTheAssociatedClassType(ps[0], compSpec.getName().getRawSignature())) { if (paramHasTypeReferenceToTheAssociatedClassType(ps[0], compSpec.getName().getRawSignature())) {
// and all remaining arguments have initialisers // and all remaining arguments have initializers
for(int j=1; j<ps.length; j++) { for (int j = 1; j < ps.length; j++) {
if( ps[j].getDeclarator().getInitializer() == null ) { if (ps[j].getDeclarator().getInitializer() == null) {
continue outer; continue outer;
} }
} }
@ -426,42 +426,41 @@ class ImplicitsAnalysis {
+ (!hasUserDeclaredCopyAssignmentOperator ? 1 : 0); + (!hasUserDeclaredCopyAssignmentOperator ? 1 : 0);
} }
private static ICPPASTFunctionDeclarator[] getUserDeclaredCtorOrDtor( ICPPASTCompositeTypeSpecifier compSpec, boolean constructor ) { private static ICPPASTFunctionDeclarator[] getUserDeclaredCtorOrDtor(ICPPASTCompositeTypeSpecifier compSpec, boolean constructor) {
List<ICPPASTFunctionDeclarator> result= new ArrayList<ICPPASTFunctionDeclarator>(); List<ICPPASTFunctionDeclarator> result= new ArrayList<ICPPASTFunctionDeclarator>();
IASTDeclaration [] members = compSpec.getMembers(); IASTDeclaration[] members = compSpec.getMembers();
char [] name = compSpec.getName().toCharArray(); char[] name = compSpec.getName().toCharArray();
IASTDeclarator dcltor = null; IASTDeclarator dcltor = null;
IASTDeclSpecifier spec = null; IASTDeclSpecifier spec = null;
for( int i = 0; i < members.length; i++ ){ for (int i = 0; i < members.length; i++) {
if( members[i] instanceof IASTSimpleDeclaration ){ if (members[i] instanceof IASTSimpleDeclaration) {
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators(); IASTDeclarator[] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators();
if( dtors.length == 0 || dtors.length > 1 ) if (dtors.length == 0 || dtors.length > 1)
continue; continue;
dcltor = dtors[0]; dcltor = dtors[0];
spec = ((IASTSimpleDeclaration)members[i]).getDeclSpecifier(); spec = ((IASTSimpleDeclaration)members[i]).getDeclSpecifier();
} else if( members[i] instanceof IASTFunctionDefinition ){ } else if (members[i] instanceof IASTFunctionDefinition) {
dcltor = ((IASTFunctionDefinition)members[i]).getDeclarator(); dcltor = ((IASTFunctionDefinition)members[i]).getDeclarator();
spec = ((IASTFunctionDefinition)members[i]).getDeclSpecifier(); spec = ((IASTFunctionDefinition)members[i]).getDeclSpecifier();
} }
if( !(dcltor instanceof ICPPASTFunctionDeclarator) || !(spec instanceof IASTSimpleDeclSpecifier) || if (!(dcltor instanceof ICPPASTFunctionDeclarator) || !(spec instanceof IASTSimpleDeclSpecifier) ||
((IASTSimpleDeclSpecifier)spec).getType() != IASTSimpleDeclSpecifier.t_unspecified) ((IASTSimpleDeclSpecifier)spec).getType() != IASTSimpleDeclSpecifier.t_unspecified) {
{
continue; continue;
} }
boolean nameEquals= false; boolean nameEquals= false;
if(constructor) { if (constructor) {
nameEquals= CharArrayUtils.equals( dcltor.getName().toCharArray(), name ); nameEquals= CharArrayUtils.equals(dcltor.getName().toCharArray(), name);
} else { } else {
char[] cname= dcltor.getName().toCharArray(); char[] cname= dcltor.getName().toCharArray();
if(cname.length>0 && cname[0]=='~') { if (cname.length > 0 && cname[0] == '~') {
nameEquals= CharArrayUtils.equals( cname, 1, name.length, name ); nameEquals= CharArrayUtils.equals(cname, 1, name.length, name);
} }
} }
if(!nameEquals) if (!nameEquals)
continue; continue;
result.add((ICPPASTFunctionDeclarator) dcltor); result.add((ICPPASTFunctionDeclarator) dcltor);
@ -469,27 +468,27 @@ class ImplicitsAnalysis {
return result.toArray(new ICPPASTFunctionDeclarator[result.size()]); return result.toArray(new ICPPASTFunctionDeclarator[result.size()]);
} }
private static ICPPASTFunctionDeclarator[] getUserDeclaredCopyAssignmentOperators( ICPPASTCompositeTypeSpecifier compSpec ) { private static ICPPASTFunctionDeclarator[] getUserDeclaredCopyAssignmentOperators(ICPPASTCompositeTypeSpecifier compSpec) {
List<ICPPASTFunctionDeclarator> result= new ArrayList<ICPPASTFunctionDeclarator>(); List<ICPPASTFunctionDeclarator> result= new ArrayList<ICPPASTFunctionDeclarator>();
IASTDeclaration [] members = compSpec.getMembers(); IASTDeclaration[] members = compSpec.getMembers();
IASTDeclarator dcltor = null; IASTDeclarator dcltor = null;
for( int i = 0; i < members.length; i++ ){ for (int i = 0; i < members.length; i++) {
if( members[i] instanceof IASTSimpleDeclaration ){ if (members[i] instanceof IASTSimpleDeclaration) {
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators(); IASTDeclarator[] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators();
if( dtors.length == 0 || dtors.length > 1 ) if (dtors.length == 0 || dtors.length > 1)
continue; continue;
dcltor = dtors[0]; dcltor = dtors[0];
} else if( members[i] instanceof IASTFunctionDefinition ){ } else if (members[i] instanceof IASTFunctionDefinition) {
dcltor = ((IASTFunctionDefinition)members[i]).getDeclarator(); dcltor = ((IASTFunctionDefinition)members[i]).getDeclarator();
} }
if( !(dcltor instanceof ICPPASTFunctionDeclarator) || if (!(dcltor instanceof ICPPASTFunctionDeclarator) ||
!CharArrayUtils.equals( dcltor.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray() ) ) !CharArrayUtils.equals(dcltor.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray()))
{ {
continue; continue;
} }
IASTParameterDeclaration [] ps = ((ICPPASTFunctionDeclarator)dcltor).getParameters(); IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator)dcltor).getParameters();
if(ps.length != 1 || !paramHasTypeReferenceToTheAssociatedClassType(ps[0], null)) if (ps.length != 1 || !paramHasTypeReferenceToTheAssociatedClassType(ps[0], null))
continue; continue;
result.add((ICPPASTFunctionDeclarator)dcltor); result.add((ICPPASTFunctionDeclarator)dcltor);
@ -506,10 +505,10 @@ class ImplicitsAnalysis {
private static boolean paramHasTypeReferenceToTheAssociatedClassType(IASTParameterDeclaration dec, String name) { private static boolean paramHasTypeReferenceToTheAssociatedClassType(IASTParameterDeclaration dec, String name) {
boolean result= false; boolean result= false;
IASTDeclarator pdtor= dec.getDeclarator(); IASTDeclarator pdtor= dec.getDeclarator();
if(pdtor.getPointerOperators().length==1 && pdtor.getPointerOperators()[0] instanceof ICPPASTReferenceOperator) { if (pdtor.getPointerOperators().length == 1 && pdtor.getPointerOperators()[0] instanceof ICPPASTReferenceOperator) {
if(dec.getDeclSpecifier() instanceof ICPPASTNamedTypeSpecifier) { if (dec.getDeclSpecifier() instanceof ICPPASTNamedTypeSpecifier) {
ICPPASTNamedTypeSpecifier nts= (ICPPASTNamedTypeSpecifier) dec.getDeclSpecifier(); ICPPASTNamedTypeSpecifier nts= (ICPPASTNamedTypeSpecifier) dec.getDeclSpecifier();
if(name==null || name.equals(nts.getName().getRawSignature())) { if (name == null || name.equals(nts.getName().getRawSignature())) {
result= true; result= true;
} }
} }

View file

@ -40,8 +40,8 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
* @param scope * @param scope
* @param argumentMap * @param argumentMap
*/ */
public CPPClassTemplateSpecialization(IBinding specialized, public CPPClassTemplateSpecialization(IBinding specialized, ICPPScope scope,
ICPPScope scope, ObjectMap argumentMap) { ObjectMap argumentMap) {
super(specialized, scope, argumentMap); super(specialized, scope, argumentMap);
} }
@ -61,31 +61,31 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
} }
public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) { public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) {
if( instances == null ) if (instances == null)
instances = new ObjectMap(2); instances = new ObjectMap(2);
instances.put( arguments, specialization ); instances.put(arguments, specialization);
} }
public ICPPSpecialization getInstance( IType [] arguments ) { public ICPPSpecialization getInstance(IType[] arguments) {
if( instances == null ) if (instances == null)
return null; return null;
int found = -1; int found = -1;
for( int i = 0; i < instances.size(); i++ ){ for (int i = 0; i < instances.size(); i++) {
IType [] args = (IType[]) instances.keyAt( i ); IType[] args = (IType[]) instances.keyAt(i);
if( args.length == arguments.length ){ if (args.length == arguments.length) {
int j = 0; int j = 0;
for(; j < args.length; j++) { for(; j < args.length; j++) {
if( !( args[j].isSameType( arguments[j] ) ) ) if (!(args[j].isSameType(arguments[j])))
break; break;
} }
if( j == args.length ){ if (j == args.length) {
found = i; found = i;
break; break;
} }
} }
} }
if( found != -1 ){ if (found != -1) {
return (ICPPSpecialization) instances.getAt(found); return (ICPPSpecialization) instances.getAt(found);
} }
return null; return null;
@ -95,26 +95,30 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
ICPPTemplateDefinition template = null; ICPPTemplateDefinition template = null;
try { try {
template = CPPTemplates.matchTemplatePartialSpecialization( this, arguments ); template = CPPTemplates.matchTemplatePartialSpecialization(this, arguments);
} catch (DOMException e) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
} }
if( template instanceof IProblemBinding ) if (template instanceof IProblemBinding) {
return template; return template;
if( template != null && template instanceof ICPPClassTemplatePartialSpecialization ){ }
return ((ICPPInternalTemplateInstantiator)template).instantiate( arguments ); if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) {
return ((ICPPInternalTemplateInstantiator) template).instantiate(arguments);
} }
return CPPTemplates.instantiateTemplate( this, arguments, argumentMap ); return CPPTemplates.instantiateTemplate(this, arguments, argumentMap);
} }
public ICPPSpecialization deferredInstance(IType[] arguments) { public ICPPSpecialization deferredInstance(IType[] arguments) {
// TODO Auto-generated method stub
return null; return null;
} }
public void addPartialSpecialization( ICPPClassTemplatePartialSpecialization spec ){ public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) {
//should not occur //should not occur
} }
public String toString() {
return getName();
}
} }

View file

@ -112,7 +112,7 @@ public class CPPTemplates {
// } // }
ICPPASTTemplateDeclaration[] templates = new ICPPASTTemplateDeclaration[] { (ICPPASTTemplateDeclaration) parent }; ICPPASTTemplateDeclaration[] templates = new ICPPASTTemplateDeclaration[] { (ICPPASTTemplateDeclaration) parent };
while(parent.getParent() instanceof ICPPASTTemplateDeclaration) { while (parent.getParent() instanceof ICPPASTTemplateDeclaration) {
parent = parent.getParent(); parent = parent.getParent();
templates = (ICPPASTTemplateDeclaration[]) ArrayUtil.append(ICPPASTTemplateDeclaration.class, templates, parent); templates = (ICPPASTTemplateDeclaration[]) ArrayUtil.append(ICPPASTTemplateDeclaration.class, templates, parent);
} }
@ -570,7 +570,8 @@ public class CPPTemplates {
* @return * @return
* @throws DOMException * @throws DOMException
*/ */
static protected Object[] deduceTemplateFunctionArguments(ICPPFunctionTemplate primaryTemplate, IASTParameterDeclaration[] ps, IASTNode[] specArgs) throws DOMException static protected Object[] deduceTemplateFunctionArguments(ICPPFunctionTemplate primaryTemplate,
IASTParameterDeclaration[] ps, IASTNode[] specArgs) throws DOMException
{ {
ICPPTemplateParameter[] templateParameters = primaryTemplate.getTemplateParameters(); ICPPTemplateParameter[] templateParameters = primaryTemplate.getTemplateParameters();
IType[] arguments = createTypeArray(specArgs); IType[] arguments = createTypeArray(specArgs);
@ -681,7 +682,8 @@ public class CPPTemplates {
} }
} catch (DOMException e) { } catch (DOMException e) {
} }
newType = new CPPFunctionType(ret, params, ((ICPPFunctionType)type).isConst(), ((ICPPFunctionType)type).isVolatile()); newType = new CPPFunctionType(ret, params, ((ICPPFunctionType)type).isConst(),
((ICPPFunctionType)type).isVolatile());
} else if (type instanceof ITypedef) { } else if (type instanceof ITypedef) {
// Typedef requires special treatment (bug 213861). // Typedef requires special treatment (bug 213861).
try { try {
@ -984,7 +986,8 @@ public class CPPTemplates {
return result; return result;
} }
static protected IFunction[] selectTemplateFunctions(ObjectSet templates, Object[] functionArguments, IASTName name) {//IASTNode[] templateArguments) { static protected IFunction[] selectTemplateFunctions(ObjectSet templates,
Object[] functionArguments, IASTName name) {//IASTNode[] templateArguments) {
if (templates == null || templates.size() == 0) if (templates == null || templates.size() == 0)
return null; return null;
@ -1154,7 +1157,7 @@ public class CPPTemplates {
} else if (aType instanceof CPPPointerType) { } else if (aType instanceof CPPPointerType) {
result = ((CPPPointerType)aType).stripQualifiers(); result = ((CPPPointerType)aType).stripQualifiers();
} }
} catch(DOMException e) { } catch (DOMException e) {
result = e.getProblem(); result = e.getProblem();
} }
} }
@ -1576,11 +1579,8 @@ public class CPPTemplates {
return (t instanceof ICPPTemplateParameter); return (t instanceof ICPPTemplateParameter);
} }
public static IBinding instantiateTemplate(ICPPTemplateDefinition template, IType[] arguments, ObjectMap specializedArgs) { public static IBinding instantiateTemplate(ICPPTemplateDefinition template, IType[] arguments,
if (template == null) { ObjectMap specializedArgs) {
template = null;
}
ICPPTemplateParameter[] parameters = null; ICPPTemplateParameter[] parameters = null;
try { try {
parameters = template.getTemplateParameters(); parameters = template.getTemplateParameters();

View file

@ -36,19 +36,19 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
/** /**
* *
*/ */
public CPPUnknownBinding( ICPPScope scope, IBinding scopeBinding, IASTName name ) { public CPPUnknownBinding(ICPPScope scope, IBinding scopeBinding, IASTName name) {
super(); super();
this.scope = scope; this.scope = scope;
this.name = name; this.name = name;
this.scopeBinding = scopeBinding; this.scopeBinding = scopeBinding;
} }
/* (non-Javadoc)``` /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown#getUnknownScope() * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown#getUnknownScope()
*/ */
public ICPPScope getUnknownScope() { public ICPPScope getUnknownScope() {
if( unknownScope == null ){ if (unknownScope == null) {
unknownScope = new CPPUnknownScope( this, name ); unknownScope = new CPPUnknownScope(this, name);
} }
return unknownScope; return unknownScope;
} }
@ -70,33 +70,33 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
*/ */
public void addDefinition( IASTNode node ) { public void addDefinition(IASTNode node) {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
*/ */
public void addDeclaration( IASTNode node ) { public void addDeclaration(IASTNode node) {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#removeDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#removeDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
*/ */
public void removeDeclaration( IASTNode node ) { public void removeDeclaration(IASTNode node) {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
*/ */
public String[] getQualifiedName() { public String[] getQualifiedName() {
return CPPVisitor.getQualifiedName( this ); return CPPVisitor.getQualifiedName(this);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
*/ */
public char[][] getQualifiedNameCharArray() { public char[][] getQualifiedNameCharArray() {
return CPPVisitor.getQualifiedNameCharArray( this ); return CPPVisitor.getQualifiedNameCharArray(this);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -130,19 +130,19 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown#resolveUnknown(org.eclipse.cdt.core.parser.util.ObjectMap) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknown#resolveUnknown(org.eclipse.cdt.core.parser.util.ObjectMap)
*/ */
public IBinding resolveUnknown( ObjectMap argMap ) throws DOMException { public IBinding resolveUnknown(ObjectMap argMap) throws DOMException {
IBinding result = this; IBinding result = this;
if( argMap.containsKey( scopeBinding ) ){ if (argMap.containsKey(scopeBinding)) {
IType t = (IType) argMap.get( scopeBinding ); IType t = (IType) argMap.get(scopeBinding);
t = CPPSemantics.getUltimateType( t, false ); t = CPPSemantics.getUltimateType(t, false);
if( t instanceof ICPPClassType ){ if (t instanceof ICPPClassType) {
IScope s = ((ICPPClassType)t).getCompositeScope(); IScope s = ((ICPPClassType)t).getCompositeScope();
if( s != null && ASTInternal.isFullyCached(s) ) if (s != null && ASTInternal.isFullyCached(s))
result = s.getBinding( name, true ); result = s.getBinding(name, true);
// CPPSemantics.LookupData data = CPPSemantics.createLookupData( name, false ); // CPPSemantics.LookupData data = CPPSemantics.createLookupData(name, false);
// CPPSemantics.lookup( data, s ); // CPPSemantics.lookup(data, s);
// IBinding result = CPPSemantics.resolveAmbiguities( data, name ); // IBinding result = CPPSemantics.resolveAmbiguities(data, name);
return result; return result;
} }
} }
@ -152,4 +152,11 @@ public class CPPUnknownBinding extends PlatformObject implements ICPPInternalUnk
public ILinkage getLinkage() { public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE; return Linkage.CPP_LINKAGE;
} }
/* (non-Javadoc)
* For debug purposes only
*/
public String toString() {
return getName();
}
} }

View file

@ -27,6 +27,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
/** /**
* Represents a C++ class for which we don't yet have a complete declaration.
*
* @author aniefer * @author aniefer
*/ */
public class CPPUnknownClass extends CPPUnknownBinding implements ICPPClassType { public class CPPUnknownClass extends CPPUnknownBinding implements ICPPClassType {
@ -35,8 +37,8 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPClassType
* @param scope * @param scope
* @param name * @param name
*/ */
public CPPUnknownClass( ICPPScope scope, IBinding scopeBinding, IASTName name ) { public CPPUnknownClass(ICPPScope scope, IBinding scopeBinding, IASTName name) {
super( scope, scopeBinding, name ); super(scope, scopeBinding, name);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -56,7 +58,7 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPClassType
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String)
*/ */
public IField findField( String name ) { public IField findField(String name) {
return null; return null;
} }
@ -126,12 +128,11 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPClassType
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/ */
public boolean isSameType( IType type ) { public boolean isSameType(IType type) {
return type == this; return type == this;
} }
public ICPPClassType[] getNestedClasses() { public ICPPClassType[] getNestedClasses() {
return ICPPClassType.EMPTY_CLASS_ARRAY; return ICPPClassType.EMPTY_CLASS_ARRAY;
} }
} }

View file

@ -39,7 +39,7 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
/** /**
* *
*/ */
public CPPUnknownScope( IBinding binding, IASTName name ) { public CPPUnknownScope(IBinding binding, IASTName name) {
super(); super();
this.scopeName = name; this.scopeName = name;
this.binding = binding; this.binding = binding;
@ -62,7 +62,7 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/ */
public IBinding[] find( String name ) { public IBinding[] find(String name) {
return null; return null;
} }
@ -76,15 +76,13 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#addName(org.eclipse.cdt.core.dom.ast.IASTName) * @see org.eclipse.cdt.core.dom.ast.IScope#addName(org.eclipse.cdt.core.dom.ast.IASTName)
*/ */
public void addName( IASTName name ) { public void addName(IASTName name) {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.IScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
public void removeBinding( IBinding binding1 ) { public void removeBinding(IBinding binding) {
} }
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException { public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
@ -98,27 +96,27 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean) * @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
*/ */
public IBinding getBinding( IASTName name, boolean resolve, IIndexFileSet fileSet ) { public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) {
if( map == null ) if (map == null)
map = new CharArrayObjectMap(2); map = new CharArrayObjectMap(2);
char [] c = name.toCharArray(); char[] c = name.toCharArray();
if( map.containsKey( c ) ){ if (map.containsKey(c)) {
return (IBinding) map.get( c ); return (IBinding) map.get(c);
} }
IBinding b = new CPPUnknownClass( this, binding, name ); IBinding b = new CPPUnknownClass(this, binding, name);
name.setBinding( b ); name.setBinding(b);
map.put( c, b ); map.put(c, b);
return b; return b;
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) { public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
if( map == null ) IIndexFileSet fileSet) {
if (map == null)
map = new CharArrayObjectMap(2); map = new CharArrayObjectMap(2);
char [] c = name.toCharArray(); char[] c = name.toCharArray();
IBinding[] result = null; IBinding[] result = null;
if (prefixLookup) { if (prefixLookup) {
@ -130,7 +128,7 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
} }
} }
} else { } else {
result = new IBinding[] { (IBinding) map.get( c ) }; result = new IBinding[] { (IBinding) map.get(c) };
} }
result = (IBinding[]) ArrayUtil.trim(IBinding.class, result); result = (IBinding[]) ArrayUtil.trim(IBinding.class, result);
@ -140,7 +138,7 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#setFullyCached(boolean) * @see org.eclipse.cdt.core.dom.ast.IScope#setFullyCached(boolean)
*/ */
public void setFullyCached( boolean b ) { public void setFullyCached(boolean b) {
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -156,8 +154,14 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
public void flushCache() { public void flushCache() {
} }
public void addBinding(IBinding aBinding) { public void addBinding(IBinding binding) {
// do nothing, this is part of template magic and not a normal scope // do nothing, this is part of template magic and not a normal scope
} }
/* (non-Javadoc)
* For debug purposes only
*/
public String toString() {
return scopeName.toString();
}
} }