diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java index a8339d57973..4d1893bb8af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java @@ -42,22 +42,22 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal /** * @param instance */ - public CPPClassSpecializationScope( ICPPSpecialization specialization ) { + public CPPClassSpecializationScope(ICPPSpecialization specialization) { this.specialization = specialization; } - private ICPPClassType getOriginalClass(){ + private ICPPClassType getOriginalClass() { return (ICPPClassType) specialization.getSpecializedBinding(); } private IBinding getInstance(IBinding binding) { - if( instanceMap.containsKey( binding ) ) { - return (IBinding) instanceMap.get( binding ); + if (instanceMap.containsKey(binding)) { + return (IBinding) instanceMap.get(binding); } else if (!(binding instanceof ICPPClassTemplatePartialSpecialization)) { - IBinding spec = CPPTemplates.createSpecialization( this, binding, specialization.getArgumentMap() ); - if( instanceMap == ObjectMap.EMPTY_MAP ) + IBinding spec = CPPTemplates.createSpecialization(this, binding, specialization.getArgumentMap()); + if (instanceMap == ObjectMap.EMPTY_MAP) instanceMap = new ObjectMap(2); - instanceMap.put( binding, spec ); + instanceMap.put(binding, spec); return spec; } return null; @@ -71,38 +71,43 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY); } - public IBinding getBinding( IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException { - char [] c = name.toCharArray(); + public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException { + char[] c = name.toCharArray(); - if( CharArrayUtils.equals( c, specialization.getNameCharArray() ) ) - if (!CPPClassScope.isConstructorReference( name )) - return specialization; + if (CharArrayUtils.equals(c, specialization.getNameCharArray()) && + !CPPClassScope.isConstructorReference(name)) { + return specialization; + } ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding(); IScope classScope = specialized.getCompositeScope(); IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, false) : null; - if (bindings == null) return null; + if (bindings == null) + return null; IBinding[] specs = new IBinding[0]; for (int i = 0; i < bindings.length; i++) { specs = (IBinding[]) ArrayUtil.append(IBinding.class, specs, getInstance(bindings[i])); } specs = (IBinding[]) ArrayUtil.trim(IBinding.class, specs); - return CPPSemantics.resolveAmbiguities( name, specs ); + return CPPSemantics.resolveAmbiguities(name, specs); } - public IBinding[] getBindings( IASTName name, boolean forceResolve, boolean prefixLookup, IIndexFileSet fileSet ) throws DOMException { - char [] c = name.toCharArray(); + public IBinding[] getBindings(IASTName name, boolean forceResolve, boolean prefixLookup, + IIndexFileSet fileSet) throws DOMException { + char[] c = name.toCharArray(); IBinding[] result = null; - if( (!prefixLookup && CharArrayUtils.equals( c, specialization.getNameCharArray() )) - || (prefixLookup && CharArrayUtils.equals(specialization.getNameCharArray(), 0, c.length, c, true)) ) + if ((!prefixLookup && CharArrayUtils.equals(c, specialization.getNameCharArray())) || + (prefixLookup && CharArrayUtils.equals(specialization.getNameCharArray(), 0, c.length, c, true))) { result = new IBinding[] { specialization }; + } ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding(); IScope classScope = specialized.getCompositeScope(); - IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null; + IBinding[] bindings = classScope != null ? + classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null; if (bindings != null) { for (int i = 0; i < bindings.length; i++) { @@ -124,7 +129,7 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope#getImplicitMethods() */ public ICPPMethod[] getImplicitMethods() { - //implicit methods shouldn't have implicit specializations + // Implicit methods shouldn't have implicit specializations return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; } @@ -138,7 +143,7 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal return null; } - protected ICPPConstructor [] getConstructors() throws DOMException { + protected ICPPConstructor[] getConstructors() throws DOMException { ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding(); ICPPConstructor[] bindings = specialized.getConstructors(); @@ -175,12 +180,12 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal public IScope getParent() throws DOMException { ICPPClassType cls = getOriginalClass(); ICPPClassScope scope = (ICPPClassScope)cls.getCompositeScope(); - if( scope != null ) + if (scope != null) return scope.getParent(); - if( cls instanceof ICPPInternalBinding ){ - IASTNode [] nds = ((ICPPInternalBinding)cls).getDeclarations(); - if( nds != null && nds.length > 0 ) - return CPPVisitor.getContainingScope( nds[0] ); + if (cls instanceof ICPPInternalBinding) { + IASTNode[] nds = ((ICPPInternalBinding)cls).getDeclarations(); + if (nds != null && nds.length > 0) + return CPPVisitor.getContainingScope(nds[0]); } return null; } @@ -189,7 +194,7 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) */ public IBinding[] find(String name) throws DOMException { - return CPPSemantics.findBindings( this, name, false ); + return CPPSemantics.findBindings(this, name, false); } /* (non-Javadoc) @@ -200,18 +205,24 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal if (!ASTInternal.isFullyCached(origScope)) { CPPSemantics.LookupData data = new CPPSemantics.LookupData(); try { - CPPSemantics.lookupInScope( data, origScope, null ); + CPPSemantics.lookupInScope(data, origScope, null); } catch (DOMException e) { } } return true; } - //this scope does not cache its own names + // This scope does not cache its own names public void setFullyCached(boolean b) {} public void flushCache() {} public void addName(IASTName name) {} - public IASTNode getPhysicalNode() {return null;} + public IASTNode getPhysicalNode() { return null; } public void removeBinding(IBinding binding) {} public void addBinding(IBinding binding) {} + + @Override + public String toString() { + IName name = getScopeName(); + return name != null ? name.toString() : ""; //$NON-NLS-1$ + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java index e5d8c896440..92b51c5c457 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; @@ -35,23 +36,24 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; */ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPPFunction, ICPPInternalFunction { private IFunctionType type = null; - private IParameter [] specializedParams = null; + private IParameter[] specializedParams = null; - public CPPFunctionSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap ) { + public CPPFunctionSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap) { super(orig, scope, argMap); } - private ICPPFunction getFunction(){ + private ICPPFunction getFunction() { return (ICPPFunction) getSpecializedBinding(); } public IParameter[] getParameters() throws DOMException { - if( specializedParams == null ){ + if (specializedParams == null) { ICPPFunction function = (ICPPFunction) getSpecializedBinding(); - IParameter [] params = function.getParameters(); - specializedParams = new IParameter[ params.length]; - for( int i = 0; i < params.length; i++ ){ - specializedParams[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], (ICPPScope) getScope(), argumentMap ); + IParameter[] params = function.getParameters(); + specializedParams = new IParameter[params.length]; + for (int i = 0; i < params.length; i++) { + specializedParams[i] = new CPPParameterSpecialization((ICPPParameter)params[i], + (ICPPScope) getScope(), argumentMap); } } return specializedParams; @@ -59,7 +61,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP public IScope getFunctionScope() { // resolveAllDeclarations(); -// if( definition != null ){ +// if (definition != null) { // return definition.getFunctionScope(); // } // @@ -68,10 +70,10 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP } public IFunctionType getType() throws DOMException { - if( type == null ){ + if (type == null) { ICPPFunction function = (ICPPFunction) getSpecializedBinding(); type = function.getType(); - type = (IFunctionType) CPPTemplates.instantiateType( type, argumentMap ); + type = (IFunctionType) CPPTemplates.instantiateType(type, argumentMap); } return type; @@ -82,9 +84,9 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP } public boolean isInline() throws DOMException { - if( getDefinition() != null ){ + if (getDefinition() != null) { IASTNode def = getDefinition(); - while( !(def instanceof IASTFunctionDefinition) ) + while (!(def instanceof IASTFunctionDefinition)) def = def.getParent(); return ((IASTFunctionDefinition)def).getDeclSpecifier().isInline(); } @@ -104,48 +106,48 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP public boolean isStatic(boolean resolveAll) { //TODO resolveAll IBinding f = getSpecializedBinding(); - if( f instanceof ICPPInternalFunction) - return ((ICPPInternalFunction)f).isStatic( resolveAll); - if( f instanceof IIndexBinding && f instanceof ICPPFunction ) { + if (f instanceof ICPPInternalFunction) + return ((ICPPInternalFunction)f).isStatic(resolveAll); + if (f instanceof IIndexBinding && f instanceof ICPPFunction) { try { return ((ICPPFunction) f).isStatic(); } catch(DOMException de) { /* cannot occur as we query the index */} } - return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_static); + return CPPFunction.hasStorageClass(this, IASTDeclSpecifier.sc_static); } public boolean isExtern() throws DOMException { ICPPFunction f = (ICPPFunction) getSpecializedBinding(); - if( f != null ) + if (f != null) return f.isExtern(); - return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_extern ); + return CPPFunction.hasStorageClass(this, IASTDeclSpecifier.sc_extern); } public boolean isAuto() throws DOMException { ICPPFunction f = (ICPPFunction) getSpecializedBinding(); - if( f != null ) + if (f != null) return f.isAuto(); - return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_auto ); + return CPPFunction.hasStorageClass(this, IASTDeclSpecifier.sc_auto); } public boolean isRegister() throws DOMException { ICPPFunction f = (ICPPFunction) getSpecializedBinding(); - if( f != null ) + if (f != null) return f.isRegister(); - return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_register ); + return CPPFunction.hasStorageClass(this, IASTDeclSpecifier.sc_register); } public boolean takesVarArgs() throws DOMException { ICPPFunction f = (ICPPFunction) getSpecializedBinding(); - if( f != null ) + if (f != null) return f.takesVarArgs(); ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition(); - if( dtor != null ){ + if (dtor != null) { return dtor.takesVarArgs(); } - ICPPASTFunctionDeclarator [] ds = (ICPPASTFunctionDeclarator[]) getDeclarations(); - if( ds != null && ds.length > 0 ){ + ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) getDeclarations(); + if (ds != null && ds.length > 0) { return ds[0].takesVarArgs(); } return false; @@ -154,33 +156,33 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#resolveParameter(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) */ - public IBinding resolveParameter( IASTParameterDeclaration param ) { + public IBinding resolveParameter(IASTParameterDeclaration param) { IASTDeclarator dtor = param.getDeclarator(); - while( dtor.getNestedDeclarator() != null ) + while (dtor.getNestedDeclarator() != null) dtor = dtor.getNestedDeclarator(); IASTName name = dtor.getName(); IBinding binding = name.getBinding(); - if( binding != null ) + if (binding != null) return binding; ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) param.getParent(); - IASTParameterDeclaration [] ps = fdtor.getParameters(); + IASTParameterDeclaration[] ps = fdtor.getParameters(); int i = 0; - for( ; i < ps.length; i++ ){ - if( param == ps[i] ) + for (; i < ps.length; i++) { + if (param == ps[i]) break; } try { - IParameter [] params = getParameters(); - if( i < params.length ){ - name.setBinding( params[i] ); - if( params[i] instanceof ICPPInternalBinding ) - ((ICPPInternalBinding)params[i]).addDeclaration( name ); + IParameter[] params = getParameters(); + if (i < params.length) { + name.setBinding(params[i]); + if (params[i] instanceof ICPPInternalBinding) + ((ICPPInternalBinding)params[i]).addDeclaration(name); return params[i]; } - } catch ( DOMException e ) { + } catch (DOMException e) { return e.getProblem(); } return null; @@ -189,42 +191,61 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP @Override public void addDefinition(IASTNode node) { IASTNode n = node; - while( n instanceof IASTName ) + while (n instanceof IASTName) n = n.getParent(); - if( !(n instanceof ICPPASTFunctionDeclarator) ) + if (!(n instanceof ICPPASTFunctionDeclarator)) return; - updateParameterBindings( (ICPPASTFunctionDeclarator) n ); - super.addDefinition( n ); + updateParameterBindings((ICPPASTFunctionDeclarator) n); + super.addDefinition(n); } + @Override public void addDeclaration(IASTNode node) { IASTNode n = node; - while( n instanceof IASTName ) + while (n instanceof IASTName) n = n.getParent(); - if( !(n instanceof ICPPASTFunctionDeclarator) ) + if (!(n instanceof ICPPASTFunctionDeclarator)) return; - updateParameterBindings( (ICPPASTFunctionDeclarator) n ); - super.addDeclaration( n ); + updateParameterBindings((ICPPASTFunctionDeclarator) n); + super.addDeclaration(n); } - protected void updateParameterBindings( ICPPASTFunctionDeclarator fdtor ){ - IParameter [] params = null; + + protected void updateParameterBindings(ICPPASTFunctionDeclarator fdtor) { + IParameter[] params = null; try { params = getParameters(); - } catch ( DOMException e ) { + } catch (DOMException e) { return; } - IASTParameterDeclaration [] nps = fdtor.getParameters(); - for( int i = 0; i < nps.length; i++ ){ + IASTParameterDeclaration[] nps = fdtor.getParameters(); + for (int i = 0; i < nps.length; i++) { //temp = (CPPParameter) ops[i].getDeclarator().getName().getBinding(); - if( params[i] != null ){ + if (params[i] != null) { IASTDeclarator dtor = nps[i].getDeclarator(); - while( dtor.getNestedDeclarator() != null ) + while (dtor.getNestedDeclarator() != null) dtor = dtor.getNestedDeclarator(); IASTName name = dtor.getName(); - name.setBinding( params[i] ); - if( params[i] instanceof ICPPInternalBinding ) - ((ICPPInternalBinding)params[i]).addDeclaration( name ); + name.setBinding(params[i]); + if (params[i] instanceof ICPPInternalBinding) + ((ICPPInternalBinding) params[i]).addDeclaration(name); } } } + + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + result.append(getName()); + IFunctionType t = null; + try { + t = getType(); + } catch (DOMException e) { + } + result.append(t != null ? ASTTypeUtil.getParameterTypeString(t) : "()"); //$NON-NLS-1$ + if (argumentMap != null) { + result.append(" "); + result.append(argumentMap.toString()); + } + return result.toString(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index d29db456ac1..23ba13c1729 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -51,15 +51,17 @@ import org.eclipse.core.runtime.NullProgressMonitor; */ abstract public class CPPScope implements ICPPScope, IASTInternalScope { private static final IProgressMonitor NPM = new NullProgressMonitor(); + private IASTNode physicalNode; + private boolean isfull = false; + protected CharArrayObjectMap bindings = null; public static class CPPScopeProblem extends ProblemBinding implements ICPPScope { - public CPPScopeProblem( IASTNode node, int id, char[] arg ) { - super( node, id, arg ); + public CPPScopeProblem(IASTNode node, int id, char[] arg) { + super(node, id, arg); } } - private IASTNode physicalNode; - public CPPScope( IASTNode physicalNode ) { + public CPPScope(IASTNode physicalNode) { this.physicalNode = physicalNode; } @@ -67,46 +69,44 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { * @see org.eclipse.cdt.core.dom.ast.IScope#getParent() */ public IScope getParent() throws DOMException { - return CPPVisitor.getContainingScope( physicalNode ); + return CPPVisitor.getContainingScope(physicalNode); } - + public IASTNode getPhysicalNode() { return physicalNode; } - protected CharArrayObjectMap bindings = null; - public void addName(IASTName name) throws DOMException { - if( bindings == null ) + if (bindings == null) bindings = new CharArrayObjectMap(1); char[] c; if (name instanceof ICPPASTQualifiedName) { - if (physicalNode instanceof ICPPASTCompositeTypeSpecifier == false && - physicalNode instanceof ICPPASTNamespaceDefinition == false) + if (!(physicalNode instanceof ICPPASTCompositeTypeSpecifier) && + !(physicalNode instanceof ICPPASTNamespaceDefinition)) { return; + } //name belongs to a different scope, don't add it here except it names this scope final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name; final IASTName[] ns= qname.getNames(); if (!canDenoteScopeMember(qname)) return; - c= ns[ns.length-1].toCharArray(); - } - else { + c= ns[ns.length - 1].toCharArray(); + } else { c= name.toCharArray(); } - Object o = bindings.get( c ); - if( o != null ){ - if( o instanceof ObjectSet ){ - ((ObjectSet)o).put( name ); + Object o = bindings.get(c); + if (o != null) { + if (o instanceof ObjectSet) { + ((ObjectSet)o).put(name); } else { - ObjectSet temp = new ObjectSet( 2 ); - temp.put( o ); - temp.put( name ); - bindings.put( c, temp ); + ObjectSet temp = new ObjectSet(2); + temp.put(o); + temp.put(name); + bindings.put(c, temp); } } else { - bindings.put( c, name ); + bindings.put(c, name); } } @@ -114,7 +114,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { IScope scope= this; IASTName[] na= name.getNames(); try { - for (int i= na.length-2; i >= 0; i++) { + for (int i= na.length - 2; i >= 0; i++) { if (scope == null) return false; IASTName n= na[i]; @@ -141,32 +141,34 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { // Try looking this up in the PDOM if (physicalNode instanceof IASTTranslationUnit) { try { - IBinding[] bindings= index.findBindings(name.toCharArray(), IndexFilter.CPP_DECLARED_OR_IMPLICIT, NPM); + IBinding[] bindings= index.findBindings(name.toCharArray(), + IndexFilter.CPP_DECLARED_OR_IMPLICIT, NPM); if (fileSet != null) { bindings= fileSet.filterFileLocalBindings(bindings); } binding= CPPSemantics.resolveAmbiguities(name, bindings); - if( binding instanceof ICPPUsingDeclaration ){ - binding= CPPSemantics.resolveAmbiguities( name, ((ICPPUsingDeclaration)binding).getDelegates() ); + if (binding instanceof ICPPUsingDeclaration) { + binding= CPPSemantics.resolveAmbiguities(name, + ((ICPPUsingDeclaration)binding).getDelegates()); } } catch (CoreException e) { CCorePlugin.log(e); } - } - else if (physicalNode instanceof ICPPASTNamespaceDefinition) { + } else if (physicalNode instanceof ICPPASTNamespaceDefinition) { ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode; IASTName nsname = nsdef.getName(); IBinding nsbinding= nsname.resolveBinding(); - if(nsbinding instanceof ICPPNamespace) { + if (nsbinding instanceof ICPPNamespace) { ICPPNamespace nsbindingAdapted = (ICPPNamespace) index.adaptBinding(nsbinding); - if(nsbindingAdapted!=null) { + if (nsbindingAdapted!=null) { IBinding[] bindings = nsbindingAdapted.getNamespaceScope().find(name.toString()); if (fileSet != null) { bindings= fileSet.filterFileLocalBindings(bindings); } binding= CPPSemantics.resolveAmbiguities(name, bindings); - if( binding instanceof ICPPUsingDeclaration ){ - binding= CPPSemantics.resolveAmbiguities( name, ((ICPPUsingDeclaration)binding).getDelegates() ); + if (binding instanceof ICPPUsingDeclaration) { + binding= CPPSemantics.resolveAmbiguities(name, + ((ICPPUsingDeclaration)binding).getDelegates()); } } } @@ -175,47 +177,48 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { } return binding; } - + public IBinding getBindingInAST(IASTName name, boolean forceResolve) throws DOMException { - char [] c = name.toCharArray(); + char[] c = name.toCharArray(); //can't look up bindings that don't have a name - if( c.length == 0 ) + if (c.length == 0) return null; - Object obj = bindings != null ? bindings.get( c ) : null; - if( obj != null ){ - if( obj instanceof ObjectSet ) { + Object obj = bindings != null ? bindings.get(c) : null; + if (obj != null) { + if (obj instanceof ObjectSet) { ObjectSet os = (ObjectSet) obj; - if( forceResolve ) - return CPPSemantics.resolveAmbiguities( name, os.keyArray() ); - IBinding [] bs = null; - for( int i = 0; i < os.size(); i++ ){ - Object o = os.keyAt( i ); - if( o instanceof IASTName ){ + if (forceResolve) + return CPPSemantics.resolveAmbiguities(name, os.keyArray()); + IBinding[] bs = null; + for (int i = 0; i < os.size(); i++) { + Object o = os.keyAt(i); + if (o instanceof IASTName) { IASTName n = (IASTName) o; - if( n instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)n).getNames(); - n = ns[ ns.length - 1 ]; + if (n instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)n).getNames(); + n = ns[ns.length - 1]; } - bs = (IBinding[]) ArrayUtil.append( IBinding.class, bs, n.getBinding() ); - } else - bs = (IBinding[]) ArrayUtil.append( IBinding.class, bs, o ); + bs = (IBinding[]) ArrayUtil.append(IBinding.class, bs, n.getBinding()); + } else { + bs = (IBinding[]) ArrayUtil.append(IBinding.class, bs, o); + } } - return CPPSemantics.resolveAmbiguities( name, bs ); - } else if( obj instanceof IASTName ){ + return CPPSemantics.resolveAmbiguities(name, bs); + } else if (obj instanceof IASTName) { IBinding binding = null; - if( forceResolve && obj != name && obj != name.getParent()) + if (forceResolve && obj != name && obj != name.getParent()) { binding = CPPSemantics.resolveAmbiguities(name, new Object[] { obj }); - else { + } else { IASTName n = (IASTName) obj; - if( n instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)n).getNames(); - n = ns[ ns.length - 1 ]; + if (n instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)n).getNames(); + n = ns[ns.length - 1]; } binding = n.getBinding(); } - if( binding instanceof ICPPUsingDeclaration ){ - return CPPSemantics.resolveAmbiguities( name, ((ICPPUsingDeclaration)binding).getDelegates() ); + if (binding instanceof ICPPUsingDeclaration) { + return CPPSemantics.resolveAmbiguities(name, ((ICPPUsingDeclaration)binding).getDelegates()); } return binding; } @@ -224,7 +227,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { return null; } - 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 { IBinding[] result = getBindingsInAST(name, resolve, prefixLookup); final IASTTranslationUnit tu = name.getTranslationUnit(); @@ -263,9 +267,10 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { return (IBinding[]) ArrayUtil.trim(IBinding.class, result); } - - public IBinding[] getBindingsInAST(IASTName name, boolean forceResolve, boolean prefixLookup) throws DOMException { - char [] c = name.toCharArray(); + + public IBinding[] getBindingsInAST(IASTName name, boolean forceResolve, boolean prefixLookup) + throws DOMException { + char[] c = name.toCharArray(); IBinding[] result = null; Object[] obj = null; @@ -278,40 +283,42 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { } } } else { - obj = bindings != null ? new Object[] {bindings.get( c )} : null; + obj = bindings != null ? new Object[] {bindings.get(c)} : null; } obj = ArrayUtil.trim(Object.class, obj); for (int i = 0; i < obj.length; i++) { - if( obj[i] instanceof ObjectSet ) { + if (obj[i] instanceof ObjectSet) { ObjectSet os = (ObjectSet) obj[i]; - for( int j = 0; j < os.size(); j++ ){ - Object o = os.keyAt( j ); - if( o instanceof IASTName ){ + for (int j = 0; j < os.size(); j++) { + Object o = os.keyAt(j); + if (o instanceof IASTName) { IASTName n = (IASTName) o; - if( n instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)n).getNames(); - n = ns[ ns.length - 1 ]; + if (n instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)n).getNames(); + n = ns[ns.length - 1]; } IBinding binding = forceResolve ? n.resolveBinding() : n.getBinding(); - result = (IBinding[]) ArrayUtil.append( IBinding.class, result, binding ); - } else - result = (IBinding[]) ArrayUtil.append( IBinding.class, result, o ); + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, binding); + } else { + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, o); + } } - } else if( obj[i] instanceof IASTName ){ + } else if (obj[i] instanceof IASTName) { IBinding binding = null; - if( forceResolve && obj[i] != name && obj[i] != name.getParent()) + if (forceResolve && obj[i] != name && obj[i] != name.getParent()) { binding = ((IASTName) obj[i]).resolveBinding(); - else { + } else { IASTName n = (IASTName) obj[i]; - if( n instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)n).getNames(); - n = ns[ ns.length - 1 ]; + if (n instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)n).getNames(); + n = ns[ns.length - 1]; } binding = n.getBinding(); } - if( binding instanceof ICPPUsingDeclaration ){ - result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, ((ICPPUsingDeclaration)binding).getDelegates()); + if (binding instanceof ICPPUsingDeclaration) { + result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, + ((ICPPUsingDeclaration)binding).getDelegates()); } result = (IBinding[]) ArrayUtil.append(IBinding.class, result, binding); } else { @@ -320,86 +327,98 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { } return (IBinding[]) ArrayUtil.trim(IBinding.class, result); } - - private boolean isfull = false; - public void setFullyCached( boolean full ){ + + public void setFullyCached(boolean full) { isfull = full; } - - public boolean isFullyCached(){ + + public boolean isFullyCached() { return isfull; } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding) */ public void removeBinding(IBinding binding) { - char [] key = binding.getNameCharArray(); - removeBinding( key, binding ); + char[] key = binding.getNameCharArray(); + removeBinding(key, binding); } - - protected void removeBinding( char [] key, IBinding binding ){ - if( bindings == null || ! bindings.containsKey( key ) ) + + protected void removeBinding(char[] key, IBinding binding) { + if (bindings == null || ! bindings.containsKey(key)) return; - Object obj = bindings.get( key ); - if( obj instanceof ObjectSet ){ + Object obj = bindings.get(key); + if (obj instanceof ObjectSet) { ObjectSet set = (ObjectSet) obj; - for ( int i = set.size() - 1; i > 0; i-- ) { - Object o = set.keyAt( i ); - if( (o instanceof IBinding && o == binding) || - (o instanceof IASTName && ((IASTName)o).getBinding() == binding) ) - { - set.remove( o ); + for (int i = set.size() - 1; i > 0; i--) { + Object o = set.keyAt(i); + if ((o instanceof IBinding && o == binding) || + (o instanceof IASTName && ((IASTName)o).getBinding() == binding)) { + set.remove(o); } } - if( set.size() == 0 ) - bindings.remove( key, 0, key.length ); - } else if( (obj instanceof IBinding && obj == binding) || - (obj instanceof IASTName && ((IASTName)obj).getBinding() == binding) ) - { - bindings.remove( key, 0, key.length ); + if (set.isEmpty()) { + bindings.remove(key, 0, key.length); + } + } else if ((obj instanceof IBinding && obj == binding) || + (obj instanceof IASTName && ((IASTName)obj).getBinding() == binding)) { + bindings.remove(key, 0, key.length); } isfull = false; } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) */ public IBinding[] find(String name) throws DOMException { - return CPPSemantics.findBindings( this, name, false ); + return CPPSemantics.findBindings(this, name, false); } - + public void flushCache() { isfull = false; - if( bindings != null ) + if (bindings != null) bindings.clear(); } public void addBinding(IBinding binding) { - if( bindings == null ) + if (bindings == null) bindings = new CharArrayObjectMap(1); - char [] c = binding.getNameCharArray(); - Object o = bindings.get( c ); - if( o != null ){ - if( o instanceof ObjectSet ){ - ((ObjectSet)o).put( binding ); + char[] c = binding.getNameCharArray(); + Object o = bindings.get(c); + if (o != null) { + if (o instanceof ObjectSet) { + ((ObjectSet)o).put(binding); } else { ObjectSet set = new ObjectSet(2); - set.put( o ); - set.put( binding ); - bindings.put( c, set ); + set.put(o); + set.put(binding); + bindings.put(c, set); } } else { - bindings.put( c, binding ); + bindings.put(c, binding); } } public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException { return getBinding(name, resolve, IIndexFileSet.EMPTY); } - + public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException { return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY); } + + public IName getScopeName() throws DOMException { + return null; + } + + @Override + public String toString() { + IName name = null; + try { + name = getScopeName(); + } catch (DOMException e) { + } + return name != null ? name.toString() : ""; //$NON-NLS-1$ + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java index d557d19c994..d2575445007 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java @@ -46,8 +46,8 @@ public abstract class CPPSpecialization extends PlatformObject this.argumentMap = argumentMap; if (specialized instanceof ICPPInternalBinding) { - definition = ((ICPPInternalBinding)specialized).getDefinition(); - IASTNode[] decls = ((ICPPInternalBinding)specialized).getDeclarations(); + definition = ((ICPPInternalBinding) specialized).getDefinition(); + IASTNode[] decls = ((ICPPInternalBinding) specialized).getDeclarations(); if (decls != null && decls.length > 0) declarations = new IASTNode[] { decls[0] }; } @@ -125,4 +125,14 @@ public abstract class CPPSpecialization extends PlatformObject public ObjectMap getArgumentMap() { return argumentMap; } + + @Override + public String toString() { + StringBuilder result = new StringBuilder(getName()); + if (argumentMap != null) { + result.append(" "); + result.append(argumentMap.toString()); + } + return result.toString(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java index 5821eebd115..b5b04a70095 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java @@ -57,158 +57,163 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC super(node, id, arg); } public ICPPTemplateParameter[] getTemplateParameters() throws DOMException { - throw new DOMException( this ); + throw new DOMException(this); } public ICPPClassTemplatePartialSpecialization[] getTemplateSpecializations() throws DOMException { - throw new DOMException( this ); + throw new DOMException(this); } public String[] getQualifiedName() throws DOMException { - throw new DOMException( this ); + throw new DOMException(this); } public char[][] getQualifiedNameCharArray() throws DOMException { - throw new DOMException( this ); + throw new DOMException(this); } public boolean isGloballyQualified() throws DOMException { - throw new DOMException( this ); + throw new DOMException(this); } } + //private IASTName templateName; - protected IASTName [] declarations = null; - protected IASTName definition = null; + protected IASTName[] declarations; + protected IASTName definition; - private ICPPTemplateParameter [] templateParameters = null; - private ObjectMap instances = null; + private ICPPTemplateParameter[] templateParameters; + private ObjectMap instances; - public CPPTemplateDefinition( IASTName name ) { - if( name != null ){ + public CPPTemplateDefinition(IASTName name) { + if (name != null) { ASTNodeProperty prop = name.getPropertyInParent(); - if( prop == ICPPASTQualifiedName.SEGMENT_NAME ){ + if (prop == ICPPASTQualifiedName.SEGMENT_NAME) { prop = name.getParent().getPropertyInParent(); } - if( prop == IASTCompositeTypeSpecifier.TYPE_NAME ){ + if (prop == IASTCompositeTypeSpecifier.TYPE_NAME) { definition = name; - } else if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME ) { - declarations = new IASTName [] { name }; + } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { + declarations = new IASTName[] { name }; } else { IASTNode parent = name.getParent(); - while( !(parent instanceof IASTDeclaration) ) + while (!(parent instanceof IASTDeclaration)) parent = parent.getParent(); - if( parent instanceof IASTFunctionDefinition ) + if (parent instanceof IASTFunctionDefinition) { definition = name; - else - declarations = new IASTName [] { name }; + } else { + declarations = new IASTName[] { name }; + } } } } - public abstract ICPPSpecialization deferredInstance( IType [] arguments ); + public abstract ICPPSpecialization deferredInstance(IType[] arguments); - public IBinding instantiate(ICPPASTTemplateId templateId ) {//IASTNode[] arguments) { - IASTNode [] args = templateId.getTemplateArguments(); - IType [] types = CPPTemplates.createTypeArray( args ); - return instantiate( types ); + public IBinding instantiate(ICPPASTTemplateId templateId) {//IASTNode[] arguments) { + IASTNode[] args = templateId.getTemplateArguments(); + IType[] types = CPPTemplates.createTypeArray(args); + return instantiate(types); } - public IBinding instantiate( IType [] arguments ){ + public IBinding instantiate(IType[] arguments) { ICPPTemplateDefinition template = null; - if( this instanceof ICPPClassTemplate ){ + if (this instanceof ICPPClassTemplate) { try { - template = CPPTemplates.matchTemplatePartialSpecialization( (ICPPClassTemplate) this, arguments ); + template = CPPTemplates.matchTemplatePartialSpecialization((ICPPClassTemplate) this, arguments); } catch (DOMException e) { return e.getProblem(); } } - if( template instanceof IProblemBinding ) + if (template instanceof IProblemBinding) { 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, null ); + return CPPTemplates.instantiateTemplate(this, arguments, null); } - public ICPPSpecialization getInstance( IType [] arguments ) { - if( instances == null ) + public ICPPSpecialization getInstance(IType[] arguments) { + if (instances == null) return null; int found = -1; - for( int i = 0; i < instances.size(); i++ ){ - IType [] args = (IType[]) instances.keyAt( i ); - if( args.length == arguments.length ){ + for (int i = 0; i < instances.size(); i++) { + IType[] args = (IType[]) instances.keyAt(i); + if (args.length == arguments.length) { int j = 0; - for(; j < args.length; j++) { - if( !( args[j].isSameType( arguments[j] ) ) ) + for (; j < args.length; j++) { + if (!(args[j].isSameType(arguments[j]))) break; } - if( j == args.length ){ + if (j == args.length) { found = i; break; } } } - if( found != -1 ){ + if (found != -1) { return (ICPPSpecialization) instances.getAt(found); } return null; } - public void addSpecialization( IType [] types, ICPPSpecialization spec ){ - if( types == null ) + public void addSpecialization(IType[] types, ICPPSpecialization spec) { + if (types == null) return; - for( int i = 0; i < types.length; i++ ) - if( types[i] == null ) + for (int i = 0; i < types.length; i++) { + if (types[i] == null) return; - if( instances == null ) - instances = new ObjectMap( 2 ); - instances.put( types, spec ); + } + if (instances == null) + instances = new ObjectMap(2); + instances.put(types, spec); } public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) { - IASTName name = CPPTemplates.getTemplateParameterName( templateParameter ); + IASTName name = CPPTemplates.getTemplateParameterName(templateParameter); IBinding binding = name.getBinding(); - if( binding != null ) + if (binding != null) return binding; ICPPASTTemplateDeclaration templateDecl = (ICPPASTTemplateDeclaration) templateParameter.getParent(); - ICPPASTTemplateParameter [] ps = templateDecl.getTemplateParameters(); + ICPPASTTemplateParameter[] ps = templateDecl.getTemplateParameters(); int i = 0; - for( ; i < ps.length; i++ ){ - if( templateParameter == ps[i] ) + for (; i < ps.length; i++) { + if (templateParameter == ps[i]) break; } - if( definition != null || (declarations != null && declarations.length > 0 ) ){ - IASTName templateName = ( definition != null ) ? definition : declarations[0]; - ICPPASTTemplateDeclaration temp = CPPTemplates.getTemplateDeclaration( templateName ); - ICPPASTTemplateParameter [] params = temp.getTemplateParameters(); - if( params.length > i ) { - IASTName paramName = CPPTemplates.getTemplateParameterName( params[i] ); - if( paramName.getBinding() != null ){ + if (definition != null || (declarations != null && declarations.length > 0)) { + IASTName templateName = (definition != null) ? definition : declarations[0]; + ICPPASTTemplateDeclaration temp = CPPTemplates.getTemplateDeclaration(templateName); + ICPPASTTemplateParameter[] params = temp.getTemplateParameters(); + if (params.length > i) { + IASTName paramName = CPPTemplates.getTemplateParameterName(params[i]); + if (paramName.getBinding() != null) { binding = paramName.getBinding(); - name.setBinding( binding ); - if( binding instanceof ICPPInternalBinding ) - ((ICPPInternalBinding)binding).addDeclaration( name ); + name.setBinding(binding); + if(binding instanceof ICPPInternalBinding) + ((ICPPInternalBinding)binding).addDeclaration(name); return binding; } } } //create a new binding and set it for the corresponding parameter in all known decls - if( templateParameter instanceof ICPPASTSimpleTypeTemplateParameter ) - binding = new CPPTemplateTypeParameter( name ); - else if( templateParameter instanceof ICPPASTParameterDeclaration ) - binding = new CPPTemplateNonTypeParameter( name ); - else - binding = new CPPTemplateTemplateParameter( name ); + if (templateParameter instanceof ICPPASTSimpleTypeTemplateParameter) { + binding = new CPPTemplateTypeParameter(name); + } else if (templateParameter instanceof ICPPASTParameterDeclaration) { + binding = new CPPTemplateNonTypeParameter(name); + } else { + binding = new CPPTemplateTemplateParameter(name); + } - int length = ( declarations != null ) ? declarations.length : 0; - int j = ( definition != null ) ? -1 : 0; - for( ; j < length; j++ ){ - ICPPASTTemplateDeclaration template = ( j == -1 ) - ? CPPTemplates.getTemplateDeclaration( definition ) - : CPPTemplates.getTemplateDeclaration( declarations[j] ); - if( template == null ) + int length = (declarations != null) ? declarations.length : 0; + int j = (definition != null) ? -1 : 0; + for (; j < length; j++) { + ICPPASTTemplateDeclaration template = (j == -1) + ? CPPTemplates.getTemplateDeclaration(definition) + : CPPTemplates.getTemplateDeclaration(declarations[j]); + if (template == null) continue; ICPPASTTemplateParameter[] temp = template.getTemplateParameters(); @@ -216,19 +221,20 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC continue; IASTName n = CPPTemplates.getTemplateParameterName(temp[i]); - if( n != null && n != name && n.getBinding() == null ) { - n.setBinding( binding ); - if( binding instanceof ICPPInternalBinding ) - ((ICPPInternalBinding)binding).addDeclaration( n ); + if (n != null && n != name && n.getBinding() == null) { + n.setBinding(binding); + if (binding instanceof ICPPInternalBinding) + ((ICPPInternalBinding)binding).addDeclaration(n); } } return binding; } - public IASTName getTemplateName(){ + public IASTName getTemplateName() { return definition != null ? definition : declarations[0]; } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() */ @@ -247,21 +253,21 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() */ public IScope getScope() { - return CPPVisitor.getContainingScope( getTemplateName() ); + return CPPVisitor.getContainingScope(getTemplateName()); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName() */ public String[] getQualifiedName() { - return CPPVisitor.getQualifiedName( this ); + return CPPVisitor.getQualifiedName(this); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray() */ public char[][] getQualifiedNameCharArray() { - return CPPVisitor.getQualifiedNameCharArray( this ); + return CPPVisitor.getQualifiedNameCharArray(this); } /* (non-Javadoc) @@ -275,27 +281,27 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition#getParameters() */ public ICPPTemplateParameter[] getTemplateParameters() { - if( templateParameters == null ){ - ICPPASTTemplateDeclaration template = CPPTemplates.getTemplateDeclaration( getTemplateName() ); - if( template == null ) + if (templateParameters == null) { + ICPPASTTemplateDeclaration template = CPPTemplates.getTemplateDeclaration(getTemplateName()); + if (template == null) return ICPPTemplateParameter.EMPTY_TEMPLATE_PARAMETER_ARRAY; - ICPPASTTemplateParameter [] params = template.getTemplateParameters(); + ICPPASTTemplateParameter[] params = template.getTemplateParameters(); ICPPTemplateParameter p = null; - ICPPTemplateParameter [] result = null; + ICPPTemplateParameter[] result = null; for (int i = 0; i < params.length; i++) { - if( params[i] instanceof ICPPASTSimpleTypeTemplateParameter ){ - p = (ICPPTemplateParameter) ((ICPPASTSimpleTypeTemplateParameter)params[i]).getName().resolveBinding(); - } else if( params[i] instanceof ICPPASTParameterDeclaration ) { - p = (ICPPTemplateParameter) ((ICPPASTParameterDeclaration)params[i]).getDeclarator().getName().resolveBinding(); - } else if( params[i] instanceof ICPPASTTemplatedTypeTemplateParameter ){ - p = (ICPPTemplateParameter) ((ICPPASTTemplatedTypeTemplateParameter)params[i]).getName().resolveBinding(); + if (params[i] instanceof ICPPASTSimpleTypeTemplateParameter) { + p = (ICPPTemplateParameter) ((ICPPASTSimpleTypeTemplateParameter) params[i]).getName().resolveBinding(); + } else if (params[i] instanceof ICPPASTParameterDeclaration) { + p = (ICPPTemplateParameter) ((ICPPASTParameterDeclaration) params[i]).getDeclarator().getName().resolveBinding(); + } else if (params[i] instanceof ICPPASTTemplatedTypeTemplateParameter) { + p = (ICPPTemplateParameter) ((ICPPASTTemplatedTypeTemplateParameter) params[i]).getName().resolveBinding(); } - if( p != null ){ - result = (ICPPTemplateParameter[]) ArrayUtil.append( ICPPTemplateParameter.class, result, p ); + if (p != null) { + result = (ICPPTemplateParameter[]) ArrayUtil.append(ICPPTemplateParameter.class, result, p); } } - templateParameters = (ICPPTemplateParameter[]) ArrayUtil.trim( ICPPTemplateParameter.class, result ); + templateParameters = (ICPPTemplateParameter[]) ArrayUtil.trim(ICPPTemplateParameter.class, result); } return templateParameters; } @@ -304,16 +310,16 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode) */ public void addDefinition(IASTNode node) { - if( node instanceof ICPPASTCompositeTypeSpecifier ){ + if (node instanceof ICPPASTCompositeTypeSpecifier) { node = ((ICPPASTCompositeTypeSpecifier)node).getName(); - if( node instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)node).getNames(); - node = ns[ ns.length - 1]; + if (node instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)node).getNames(); + node = ns[ns.length - 1]; } } - if( !(node instanceof IASTName) ) + if (!(node instanceof IASTName)) return; - updateTemplateParameterBindings( (IASTName) node ); + updateTemplateParameterBindings((IASTName) node); definition = (IASTName) node; } @@ -321,49 +327,49 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode) */ public void addDeclaration(IASTNode node) { - if( node instanceof ICPPASTElaboratedTypeSpecifier ){ + if (node instanceof ICPPASTElaboratedTypeSpecifier) { node = ((ICPPASTElaboratedTypeSpecifier)node).getName(); - if( node instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)node).getNames(); - node = ns[ ns.length - 1]; + if (node instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)node).getNames(); + node = ns[ns.length - 1]; } } - if( !(node instanceof IASTName) ) + if (!(node instanceof IASTName)) return; IASTName declName = (IASTName) node; - updateTemplateParameterBindings( declName ); - if( declarations == null ) + updateTemplateParameterBindings(declName); + if (declarations == null) { declarations = new IASTName[] { declName }; - else { - //keep the lowest offset declaration in [0] - if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ - declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, declName ); + } else { + // keep the lowest offset declaration in[0] + if (declarations.length > 0 && ((ASTNode) node).getOffset() < ((ASTNode) declarations[0]).getOffset()) { + declarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, declarations, declName); } else { - declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, declName ); + declarations = (IASTName[]) ArrayUtil.append(IASTName.class, declarations, declName); } } } public void removeDeclaration(IASTNode node) { - if( definition == node ){ + if (definition == node) { definition = null; return; } ArrayUtil.remove(declarations, node); } - protected void updateTemplateParameterBindings( IASTName name ){ + protected void updateTemplateParameterBindings(IASTName name) { IASTName orig = definition != null ? definition : declarations[0]; - ICPPASTTemplateDeclaration origTemplate = CPPTemplates.getTemplateDeclaration( orig ); - ICPPASTTemplateDeclaration newTemplate = CPPTemplates.getTemplateDeclaration( name ); - ICPPASTTemplateParameter [] ops = origTemplate.getTemplateParameters(); - ICPPASTTemplateParameter [] nps = newTemplate.getTemplateParameters(); + ICPPASTTemplateDeclaration origTemplate = CPPTemplates.getTemplateDeclaration(orig); + ICPPASTTemplateDeclaration newTemplate = CPPTemplates.getTemplateDeclaration(name); + ICPPASTTemplateParameter[] ops = origTemplate.getTemplateParameters(); + ICPPASTTemplateParameter[] nps = newTemplate.getTemplateParameters(); ICPPInternalBinding temp = null; - for( int i = 0; i < nps.length; i++ ){ - temp = (ICPPInternalBinding) CPPTemplates.getTemplateParameterName( ops[i] ).getBinding(); - if( temp != null ){ - IASTName n = CPPTemplates.getTemplateParameterName( nps[i] ); - n.setBinding( temp ); - temp.addDeclaration( n ); + for (int i = 0; i < nps.length; i++) { + temp = (ICPPInternalBinding) CPPTemplates.getTemplateParameterName(ops[i]).getBinding(); + if (temp != null) { + IASTName n = CPPTemplates.getTemplateParameterName(nps[i]); + n.setBinding(temp); + temp.addDeclaration(n); } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateScope.java index 4fd38294863..fcce1a75090 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateScope.java @@ -46,11 +46,11 @@ public class CPPTemplateScope extends CPPScope implements ICPPTemplateScope { * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope#getTemplateDefinition() */ public ICPPTemplateDefinition getTemplateDefinition() { -// if( primaryDefinition == null ){ -// //primaryDefinition = CPPTemplates.getTemplateDefinition( this ); +// if (primaryDefinition == null) { +// //primaryDefinition = CPPTemplates.getTemplateDefinition(this); // ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) getPhysicalNode(); // IASTDeclaration decl = template.getDeclaration(); -// return new CPPTemplateDefinition( decl ); +// return new CPPTemplateDefinition(decl); // } // return primaryDefinition; return null; @@ -66,42 +66,45 @@ public class CPPTemplateScope extends CPPScope implements ICPPTemplateScope { public IScope getParent() { ICPPASTTemplateDeclaration templateDecl = (ICPPASTTemplateDeclaration) getPhysicalNode(); - IASTName name = CPPTemplates.getTemplateName( templateDecl ); + IASTName name = CPPTemplates.getTemplateName(templateDecl); IASTNode p = name != null ? name.getParent() : null; - if( p instanceof ICPPASTQualifiedName ){ + if (p instanceof ICPPASTQualifiedName) { ICPPASTQualifiedName qual = (ICPPASTQualifiedName) p; - IASTName [] names = qual.getNames(); + IASTName[] names = qual.getNames(); int i = 0; - for( ; i < names.length; i++ ){ - if( names[i] == name ) break; + for (; i < names.length; i++) { + if (names[i] == name) + break; } - if( i > 0 ){ + if (i > 0) { try { IBinding binding = names[i - 1].resolveBinding(); - if( binding instanceof ICPPClassType ){ - return ((ICPPClassType)binding).getCompositeScope(); - } else if( binding instanceof ICPPNamespace ){ - return ((ICPPNamespace)binding).getNamespaceScope(); - } else if( binding instanceof ICPPInternalUnknown ){ - return ((ICPPInternalUnknown)binding).getUnknownScope(); - } else if( binding instanceof IProblemBinding ){ - if( binding instanceof ICPPScope ) + if (binding instanceof ICPPClassType) { + return ((ICPPClassType) binding).getCompositeScope(); + } else if (binding instanceof ICPPNamespace) { + return ((ICPPNamespace) binding).getNamespaceScope(); + } else if (binding instanceof ICPPInternalUnknown) { + return ((ICPPInternalUnknown) binding).getUnknownScope(); + } else if (binding instanceof IProblemBinding) { + if (binding instanceof ICPPScope) return (IScope) binding; - return new CPPScope.CPPScopeProblem( names[i-1], IProblemBinding.SEMANTIC_BAD_SCOPE, names[i-1].toCharArray() ); + return new CPPScope.CPPScopeProblem(names[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE, + names[i - 1].toCharArray()); } - } catch( DOMException e ){ - IScope result= e.getProblem(); + } catch (DOMException e) { + IScope result = e.getProblem(); if (result instanceof ICPPScope) { return result; } - return new CPPScope.CPPScopeProblem( names[i-1], IProblemBinding.SEMANTIC_BAD_SCOPE, names[i-1].toCharArray() ); + return new CPPScope.CPPScopeProblem(names[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE, + names[i - 1].toCharArray()); } - } else if( qual.isFullyQualified() ){ + } else if (qual.isFullyQualified()) { return qual.getTranslationUnit().getScope(); } } - while( templateDecl.getParent() instanceof ICPPASTTemplateDeclaration ) + while (templateDecl.getParent() instanceof ICPPASTTemplateDeclaration) templateDecl = (ICPPASTTemplateDeclaration) templateDecl.getParent(); - return CPPVisitor.getContainingScope( templateDecl ); + return CPPVisitor.getContainingScope(templateDecl); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java index 7b26695fc1e..ebb62b64c0f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java @@ -21,29 +21,28 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; /** * @author aniefer */ -public class CPPTypedefSpecialization extends CPPSpecialization implements - ITypedef, ITypeContainer { - +public class CPPTypedefSpecialization extends CPPSpecialization implements ITypedef, ITypeContainer { private IType type = null; + /** * @param specialized * @param scope * @param argumentMap */ - public CPPTypedefSpecialization( IBinding specialized, ICPPScope scope, - ObjectMap argumentMap ) { - super( specialized, scope, argumentMap ); + public CPPTypedefSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) { + super(specialized, scope, argumentMap); } private ITypedef getTypedef() { return (ITypedef) getSpecializedBinding(); } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.ITypedef#getType() */ public IType getType() throws DOMException { - if( type == null ){ - type = CPPTemplates.instantiateType( getTypedef().getType(), argumentMap ); + if (type == null) { + type = CPPTemplates.instantiateType(getTypedef().getType(), argumentMap); } return type; } @@ -56,8 +55,8 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType t = null; try { t = (IType) super.clone(); - } catch ( CloneNotSupportedException e ) { - //not going to happen + } catch (CloneNotSupportedException e) { + // not going to happen } return t; } @@ -65,24 +64,25 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) */ - public boolean isSameType( IType o ) { - if( o == this ) + public boolean isSameType(IType o) { + if (o == this) return true; - if( o instanceof ITypedef ) + if (o instanceof ITypedef) { try { IType t = getType(); - if( t != null ) - return t.isSameType( ((ITypedef)o).getType()); + if (t != null) + return t.isSameType(((ITypedef) o).getType()); return false; - } catch ( DOMException e ) { + } catch (DOMException e) { return false; } + } try { IType t = getType(); - if( t != null ) - return t.isSameType( o ); - } catch ( DOMException e ) { + if (t != null) + return t.isSameType(o); + } catch (DOMException e) { return false; } return false; @@ -91,5 +91,4 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements public void setType(IType type) { this.type = type; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index b912efc2bae..d7a13d4d5c6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -156,28 +156,28 @@ public class CPPVisitor { public static IBinding createBinding(IASTName name) { IASTNode parent = name.getParent(); IBinding binding = null; - if( parent instanceof IASTNamedTypeSpecifier || - parent instanceof ICPPASTQualifiedName || - parent instanceof ICPPASTBaseSpecifier || - parent instanceof ICPPASTConstructorChainInitializer || - name.getPropertyInParent() == ICPPASTNamespaceAlias.MAPPING_NAME || - parent instanceof ICPPASTTemplateId ) - { - binding = CPPSemantics.resolveBinding( name ); - if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName - && !(parent.getParent() instanceof ICPPASTNamespaceAlias)) - { - final ICPPASTQualifiedName qname= (ICPPASTQualifiedName)parent; - final IASTName[] ns= qname.getNames(); - if (ns[ns.length-1] != name) + if (parent instanceof IASTNamedTypeSpecifier || + parent instanceof ICPPASTQualifiedName || + parent instanceof ICPPASTBaseSpecifier || + parent instanceof ICPPASTConstructorChainInitializer || + name.getPropertyInParent() == ICPPASTNamespaceAlias.MAPPING_NAME || + parent instanceof ICPPASTTemplateId) { + binding = CPPSemantics.resolveBinding(name); + if (binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName && + !(parent.getParent() instanceof ICPPASTNamespaceAlias)) { + final ICPPASTQualifiedName qname = (ICPPASTQualifiedName)parent; + final IASTName[] ns = qname.getNames(); + if (ns[ns.length - 1] != name) return binding; parent = parent.getParent(); - if( ((IProblemBinding)binding).getID() == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND ){ - IASTNode node = getContainingBlockItem( name.getParent() ); + if (((IProblemBinding)binding).getID() == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND) { + IASTNode node = getContainingBlockItem(name.getParent()); ASTNodeProperty prop= node.getPropertyInParent(); - if (prop != IASTCompositeTypeSpecifier.MEMBER_DECLARATION && prop != ICPPASTNamespaceDefinition.OWNED_DECLARATION) + if (prop != IASTCompositeTypeSpecifier.MEMBER_DECLARATION && + prop != ICPPASTNamespaceDefinition.OWNED_DECLARATION) { return binding; + } if (getContainingScope(qname) != getContainingScope(name)) return binding; @@ -186,81 +186,81 @@ public class CPPVisitor { return binding; } } - if( parent instanceof IASTIdExpression ){ - return resolveBinding( parent ); - } else if( parent instanceof ICPPASTFieldReference ){ - return resolveBinding( parent ); - } else if( parent instanceof ICPPASTCompositeTypeSpecifier ){ - return createBinding( (ICPPASTCompositeTypeSpecifier) parent ); - } else if( parent instanceof IASTDeclarator ){ - return createBinding( (IASTDeclarator) parent ); - } else if( parent instanceof ICPPASTElaboratedTypeSpecifier ){ - return createBinding( (ICPPASTElaboratedTypeSpecifier) parent ); - } else if( parent instanceof IASTDeclaration ){ - return createBinding( (IASTDeclaration) parent ); - } else if( parent instanceof IASTEnumerationSpecifier ){ - return createBinding( (IASTEnumerationSpecifier) parent ); - } else if( parent instanceof IASTEnumerator ){ - return createBinding( (IASTEnumerator) parent ); - } else if( parent instanceof IASTGotoStatement ){ - return createBinding( (IASTGotoStatement) parent ); - } else if( parent instanceof IASTLabelStatement ){ - return createBinding( (IASTLabelStatement) parent ); - } else if( parent instanceof ICPPASTTemplateParameter ){ - return CPPTemplates.createBinding( (ICPPASTTemplateParameter) parent ); + if (parent instanceof IASTIdExpression) { + return resolveBinding(parent); + } else if (parent instanceof ICPPASTFieldReference) { + return resolveBinding(parent); + } else if (parent instanceof ICPPASTCompositeTypeSpecifier) { + return createBinding((ICPPASTCompositeTypeSpecifier) parent); + } else if (parent instanceof IASTDeclarator) { + return createBinding((IASTDeclarator) parent); + } else if (parent instanceof ICPPASTElaboratedTypeSpecifier) { + return createBinding((ICPPASTElaboratedTypeSpecifier) parent); + } else if (parent instanceof IASTDeclaration) { + return createBinding((IASTDeclaration) parent); + } else if (parent instanceof IASTEnumerationSpecifier) { + return createBinding((IASTEnumerationSpecifier) parent); + } else if (parent instanceof IASTEnumerator) { + return createBinding((IASTEnumerator) parent); + } else if (parent instanceof IASTGotoStatement) { + return createBinding((IASTGotoStatement) parent); + } else if (parent instanceof IASTLabelStatement) { + return createBinding((IASTLabelStatement) parent); + } else if (parent instanceof ICPPASTTemplateParameter) { + return CPPTemplates.createBinding((ICPPASTTemplateParameter) parent); } - if( name.toCharArray().length > 0 ) + if (name.toCharArray().length > 0) return binding; return null; } - private static IBinding createBinding( IASTGotoStatement gotoStatement ) { - ICPPFunctionScope functionScope = (ICPPFunctionScope) getContainingScope( gotoStatement.getName() ); + private static IBinding createBinding(IASTGotoStatement gotoStatement) { + ICPPFunctionScope functionScope = (ICPPFunctionScope) getContainingScope(gotoStatement.getName()); IASTName name = gotoStatement.getName(); IBinding binding; try { - binding = functionScope.getBinding( name, false ); - if( binding == null || !(binding instanceof ILabel) ){ - binding = new CPPLabel( name ); - ASTInternal.addName( functionScope, name ); + binding = functionScope.getBinding(name, false); + if (binding == null || !(binding instanceof ILabel)) { + binding = new CPPLabel(name); + ASTInternal.addName(functionScope, name); } - } catch ( DOMException e ) { + } catch (DOMException e) { binding = e.getProblem(); } return binding; } - private static IBinding createBinding( IASTLabelStatement labelStatement ) { - ICPPFunctionScope functionScope = (ICPPFunctionScope) getContainingScope( labelStatement.getName() ); + private static IBinding createBinding(IASTLabelStatement labelStatement) { + ICPPFunctionScope functionScope = (ICPPFunctionScope) getContainingScope(labelStatement.getName()); IASTName name = labelStatement.getName(); IBinding binding; try { - binding = functionScope.getBinding( name, false ); - if( binding == null || !(binding instanceof ILabel) ){ - binding = new CPPLabel( name ); - ASTInternal.addName( functionScope, name ); + binding = functionScope.getBinding(name, false); + if (binding == null || !(binding instanceof ILabel)) { + binding = new CPPLabel(name); + ASTInternal.addName(functionScope, name); } else { - ((CPPLabel)binding).setLabelStatement( name ); + ((CPPLabel)binding).setLabelStatement(name); } - } catch ( DOMException e ) { + } catch (DOMException e) { binding = e.getProblem(); } return binding; } - private static IBinding createBinding( IASTEnumerator enumerator ) { - ICPPScope scope = (ICPPScope) getContainingScope( enumerator ); + private static IBinding createBinding(IASTEnumerator enumerator) { + ICPPScope scope = (ICPPScope) getContainingScope(enumerator); IBinding enumtor; try { - enumtor = scope.getBinding( enumerator.getName(), false ); - if( enumtor == null || !( enumtor instanceof IEnumerator ) ){ - enumtor = new CPPEnumerator( enumerator.getName() ); - ASTInternal.addName( scope, enumerator.getName() ); + enumtor = scope.getBinding(enumerator.getName(), false); + if (enumtor == null || !(enumtor instanceof IEnumerator)) { + enumtor = new CPPEnumerator(enumerator.getName()); + ASTInternal.addName(scope, enumerator.getName()); } - } catch ( DOMException e ) { + } catch (DOMException e) { enumtor = e.getProblem(); } @@ -268,65 +268,64 @@ public class CPPVisitor { } - private static IBinding createBinding( IASTEnumerationSpecifier specifier ) { - ICPPScope scope = (ICPPScope) getContainingScope( specifier ); + private static IBinding createBinding(IASTEnumerationSpecifier specifier) { + ICPPScope scope = (ICPPScope) getContainingScope(specifier); IBinding enumeration; try { - enumeration = scope.getBinding( specifier.getName(), false ); - if( enumeration == null || !(enumeration instanceof IEnumeration) ){ - enumeration = new CPPEnumeration( specifier.getName() ); - ASTInternal.addName( scope, specifier.getName() ); + enumeration = scope.getBinding(specifier.getName(), false); + if (enumeration == null || !(enumeration instanceof IEnumeration)) { + enumeration = new CPPEnumeration(specifier.getName()); + ASTInternal.addName(scope, specifier.getName()); } - } catch ( DOMException e ) { + } catch (DOMException e) { enumeration = e.getProblem(); } return enumeration; } - private static IBinding createBinding( final ICPPASTElaboratedTypeSpecifier elabType ){ + private static IBinding createBinding(final ICPPASTElaboratedTypeSpecifier elabType) { final IASTNode parent = elabType.getParent(); IBinding binding = null; boolean mustBeSimple = true; boolean isFriend = false; boolean qualified = false; IASTName name = elabType.getName(); - if( name instanceof ICPPASTQualifiedName ){ + if (name instanceof ICPPASTQualifiedName) { qualified = true; - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - name = ns[ ns.length - 1 ]; + IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ns.length - 1]; } - if( parent instanceof IASTSimpleDeclaration ){ - IASTDeclarator [] dtors = ((IASTSimpleDeclaration)parent).getDeclarators(); + if (parent instanceof IASTSimpleDeclaration) { + IASTDeclarator[] dtors = ((IASTSimpleDeclaration)parent).getDeclarators(); ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)parent).getDeclSpecifier(); isFriend = declSpec.isFriend() && dtors.length == 0; - if( dtors.length > 0 || isFriend ){ - binding = CPPSemantics.resolveBinding( name ); + if (dtors.length > 0 || isFriend) { + binding = CPPSemantics.resolveBinding(name); mustBeSimple = !isFriend; } else { mustBeSimple = false; } - } else if( parent instanceof IASTParameterDeclaration || + } else if (parent instanceof IASTParameterDeclaration || parent instanceof IASTDeclaration || - parent instanceof IASTTypeId ) - { - binding = CPPSemantics.resolveBinding( elabType.getName() ); + parent instanceof IASTTypeId) { + binding = CPPSemantics.resolveBinding(elabType.getName()); } - if( binding != null && - (!(binding instanceof IProblemBinding) ||((IProblemBinding)binding).getID() != IProblemBinding.SEMANTIC_NAME_NOT_FOUND) ) - { + if (binding != null && + (!(binding instanceof IProblemBinding) || + ((IProblemBinding)binding).getID() != IProblemBinding.SEMANTIC_NAME_NOT_FOUND)) { return binding; } //7.1.5.3-2 ... If name lookup does not find a declaration for the name, the elaborated-type-specifier is ill-formed //unless it is of the simple form class-key identifier - if( mustBeSimple && elabType.getName() instanceof ICPPASTQualifiedName ) + if (mustBeSimple && elabType.getName() instanceof ICPPASTQualifiedName) return binding; boolean template = false; - ICPPScope scope = (ICPPScope) getContainingScope( name ); - if( scope instanceof ICPPTemplateScope ){ + ICPPScope scope = (ICPPScope) getContainingScope(name); + if (scope instanceof ICPPTemplateScope) { ICPPScope parentScope = null; try { template = true; @@ -336,53 +335,54 @@ public class CPPVisitor { scope = parentScope; } - if( mustBeSimple ){ + if (mustBeSimple) { //3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains //the declaration - while( scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope ){ + while (scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) { try { scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit()); } catch (DOMException e1) { } } } - if( scope instanceof ICPPClassScope && isFriend && !qualified ){ + if (scope instanceof ICPPClassScope && isFriend && !qualified) { try { - while( scope instanceof ICPPClassScope ) + while (scope instanceof ICPPClassScope) scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit()); - } catch ( DOMException e1 ) { + } catch (DOMException e1) { } } try { if (scope != null) { - binding = scope.getBinding( elabType.getName(), false ); + binding = scope.getBinding(elabType.getName(), false); } - if( !(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType) ){ - if( elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum ){ - if( template ) - binding = new CPPClassTemplate( name ); + if (!(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType)) { + if (elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum) { + if (template) + binding = new CPPClassTemplate(name); else - binding = new CPPClassType( name, binding); - ASTInternal.addName( scope, elabType.getName() ); + binding = new CPPClassType(name, binding); + ASTInternal.addName(scope, elabType.getName()); } } else { - ((ICPPInternalBinding)binding).addDeclaration( elabType ); + ((ICPPInternalBinding)binding).addDeclaration(elabType); } - } catch ( DOMException e ) { + } catch (DOMException e) { binding = e.getProblem(); } return binding; } - private static IBinding createBinding( ICPPASTCompositeTypeSpecifier compType ){ + + private static IBinding createBinding(ICPPASTCompositeTypeSpecifier compType) { IASTName name = compType.getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - name = ns[ ns.length - 1 ]; + if (name instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ns.length - 1]; } - ICPPScope scope = (ICPPScope) getContainingScope( name ); + ICPPScope scope = (ICPPScope) getContainingScope(name); boolean template = false; - if( scope instanceof ICPPTemplateScope ){ + if (scope instanceof ICPPTemplateScope) { template = true; ICPPScope parentScope = null; try { @@ -392,85 +392,90 @@ public class CPPVisitor { scope = parentScope; } IBinding binding = null; - if( name instanceof ICPPASTTemplateId ){ - return CPPTemplates.createClassSpecialization( compType ); + if (name instanceof ICPPASTTemplateId) { + return CPPTemplates.createClassSpecialization(compType); } try { - if( name.toCharArray().length > 0 && scope != null ) //can't lookup anonymous things - binding = scope.getBinding( name, false ); - if( !(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType)){ - if( template ) - binding = new CPPClassTemplate( name ); - else - binding = new CPPClassType( name, binding ); - if( scope != null ) - ASTInternal.addName( scope, compType.getName() ); + if (name.toCharArray().length > 0 && scope != null) //can't lookup anonymous things + binding = scope.getBinding(name, false); + if (!(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType)) { + if (template) { + binding = new CPPClassTemplate(name); + } else { + binding = new CPPClassType(name, binding); + } + if (scope != null) { + ASTInternal.addName(scope, compType.getName()); + } } else { ICPPInternalBinding internal = (ICPPInternalBinding) binding; - if( internal.getDefinition() == null ) - internal.addDefinition( compType ); - else - binding = new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray() ); + if (internal.getDefinition() == null) { + internal.addDefinition(compType); + } else { + binding = new ProblemBinding(name, + IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray()); + } } - } catch ( DOMException e ) { + } catch (DOMException e) { binding = e.getProblem(); } return binding; } - private static IBinding createBinding( IASTDeclaration declaration ){ - if( declaration instanceof ICPPASTNamespaceDefinition ){ + private static IBinding createBinding(IASTDeclaration declaration) { + if (declaration instanceof ICPPASTNamespaceDefinition) { ICPPASTNamespaceDefinition namespaceDef = (ICPPASTNamespaceDefinition) declaration; - ICPPScope scope = (ICPPScope) getContainingScope( namespaceDef ); + ICPPScope scope = (ICPPScope) getContainingScope(namespaceDef); IBinding binding; try { - binding = scope.getBinding( namespaceDef.getName(), false ); - if( !(binding instanceof ICPPInternalBinding) || binding instanceof IProblemBinding - || !(binding instanceof ICPPNamespace)){ - binding = new CPPNamespace( namespaceDef ); - ASTInternal.addName( scope, namespaceDef.getName() ); + binding = scope.getBinding(namespaceDef.getName(), false); + if (!(binding instanceof ICPPInternalBinding) || binding instanceof IProblemBinding + || !(binding instanceof ICPPNamespace)) { + binding = new CPPNamespace(namespaceDef); + ASTInternal.addName(scope, namespaceDef.getName()); } - } catch ( DOMException e ) { + } catch (DOMException e) { binding = e.getProblem(); } return binding; - } else if( declaration instanceof ICPPASTUsingDirective ){ - return CPPSemantics.resolveBinding( ((ICPPASTUsingDirective) declaration).getQualifiedName() ); - } else if( declaration instanceof ICPPASTNamespaceAlias ) { + } else if (declaration instanceof ICPPASTUsingDirective) { + return CPPSemantics.resolveBinding(((ICPPASTUsingDirective) declaration).getQualifiedName()); + } else if (declaration instanceof ICPPASTNamespaceAlias) { ICPPASTNamespaceAlias alias = (ICPPASTNamespaceAlias) declaration; - ICPPScope scope = (ICPPScope) getContainingScope( declaration ); + ICPPScope scope = (ICPPScope) getContainingScope(declaration); IBinding binding; - try{ - binding = scope.getBinding( alias.getAlias(), false ); - if( !(binding instanceof ICPPInternalBinding) ){ + try { + binding = scope.getBinding(alias.getAlias(), false); + if (!(binding instanceof ICPPInternalBinding)) { IBinding namespace = alias.getMappingName().resolveBinding(); - if( namespace instanceof IProblemBinding ){ + if (namespace instanceof IProblemBinding) { IProblemBinding problem = (IProblemBinding) namespace; - namespace = new CPPNamespace.CPPNamespaceProblem( problem.getASTNode(), problem.getID(), alias.getMappingName().toCharArray()); + namespace = new CPPNamespace.CPPNamespaceProblem(problem.getASTNode(), + problem.getID(), alias.getMappingName().toCharArray()); } - if( namespace instanceof ICPPNamespace ) { - binding = new CPPNamespaceAlias( alias.getAlias(), (ICPPNamespace) namespace ); - ASTInternal.addName( scope, alias.getAlias() ); + if (namespace instanceof ICPPNamespace) { + binding = new CPPNamespaceAlias(alias.getAlias(), (ICPPNamespace) namespace); + ASTInternal.addName(scope, alias.getAlias()); } else { - binding = new ProblemBinding( alias.getAlias(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND, alias.getAlias().toCharArray() ); + binding = new ProblemBinding(alias.getAlias(), + IProblemBinding.SEMANTIC_NAME_NOT_FOUND, alias.getAlias().toCharArray()); } } - } catch( DOMException e ){ + } catch(DOMException e) { binding = e.getProblem(); } return binding; } - - + return null; } - private static IBinding createBinding( IASTDeclarator declarator ){ + private static IBinding createBinding(IASTDeclarator declarator) { IASTNode parent = declarator.getParent(); - while( parent instanceof IASTDeclarator ){ + while (parent instanceof IASTDeclarator) { parent = parent.getParent(); } - while( declarator.getNestedDeclarator() != null ) + while (declarator.getNestedDeclarator() != null) declarator = declarator.getNestedDeclarator(); IASTFunctionDeclarator funcDeclarator= null; @@ -489,24 +494,24 @@ public class CPPVisitor { while (tmpNode instanceof IASTDeclarator); IASTName name = declarator.getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - name = ns[ ns.length - 1 ]; + if (name instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ns.length - 1]; } ASTNodeProperty prop = parent.getPropertyInParent(); - if( parent instanceof IASTTypeId ) - return CPPSemantics.resolveBinding( name ); - else if( prop == ICPPASTTemplateSpecialization.OWNED_DECLARATION || - prop == ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION ) - { - return CPPTemplates.createFunctionSpecialization( name ); - } else if( prop == ICPPASTTemplateDeclaration.PARAMETER ) - return CPPTemplates.createBinding( (ICPPASTTemplateParameter) parent ); + if (parent instanceof IASTTypeId) { + return CPPSemantics.resolveBinding(name); + } else if (prop == ICPPASTTemplateSpecialization.OWNED_DECLARATION || + prop == ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION) { + return CPPTemplates.createFunctionSpecialization(name); + } else if (prop == ICPPASTTemplateDeclaration.PARAMETER) { + return CPPTemplates.createBinding((ICPPASTTemplateParameter) parent); + } boolean template = false; - ICPPScope scope = (ICPPScope) getContainingScope( (IASTNode) name ); - if( scope instanceof ICPPTemplateScope ){ + ICPPScope scope = (ICPPScope) getContainingScope((IASTNode) name); + if (scope instanceof ICPPTemplateScope) { ICPPScope parentScope = null; try { template = true; @@ -515,78 +520,79 @@ public class CPPVisitor { } scope = parentScope; } - if( parent instanceof IASTSimpleDeclaration && scope instanceof ICPPClassScope ){ + if (parent instanceof IASTSimpleDeclaration && scope instanceof ICPPClassScope) { ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)parent).getDeclSpecifier(); - if( declSpec.isFriend() ){ + if (declSpec.isFriend()) { try { scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit()); - } catch ( DOMException e1 ) { + } catch (DOMException e1) { } } } IBinding binding; try { - binding = ( scope != null ) ? scope.getBinding( name, false ) : null; - } catch ( DOMException e ) { + binding = (scope != null) ? scope.getBinding(name, false) : null; + } catch (DOMException e) { binding = null; } - IASTSimpleDeclaration simpleDecl = ( parent instanceof IASTSimpleDeclaration ) ? (IASTSimpleDeclaration)parent : null; - if( parent instanceof ICPPASTParameterDeclaration ){ + IASTSimpleDeclaration simpleDecl = (parent instanceof IASTSimpleDeclaration) ? + (IASTSimpleDeclaration)parent : null; + if (parent instanceof ICPPASTParameterDeclaration) { ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration) parent; parent = param.getParent(); - if( parent instanceof IASTStandardFunctionDeclarator ) { + if (parent instanceof IASTStandardFunctionDeclarator) { IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent(); - if( hasNestedPointerOperator(fDtor) ) + if (hasNestedPointerOperator(fDtor)) return null; IBinding temp = fDtor.getName().resolveBinding(); - if( temp instanceof ICPPInternalFunction ){ - binding = ((ICPPInternalFunction) temp).resolveParameter( param ); - } else if( temp instanceof IProblemBinding ){ + if (temp instanceof ICPPInternalFunction) { + binding = ((ICPPInternalFunction) temp).resolveParameter(param); + } else if (temp instanceof IProblemBinding) { //problems with the function, still create binding for the parameter - binding = new CPPParameter( name ); - } else if ( temp instanceof IIndexBinding ) { - binding= new CPPParameter( name ); + binding = new CPPParameter(name); + } else if (temp instanceof IIndexBinding) { + binding= new CPPParameter(name); } - } else if( parent instanceof ICPPASTTemplateDeclaration ) { - return CPPTemplates.createBinding( param ); + } else if (parent instanceof ICPPASTTemplateDeclaration) { + return CPPTemplates.createBinding(param); } - } else if( simpleDecl != null && simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){ - if( binding instanceof ICPPInternalBinding && binding instanceof ITypedef ){ + } else if (simpleDecl != null && + simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) { + if (binding instanceof ICPPInternalBinding && binding instanceof ITypedef) { try { IType t1 = ((ITypedef)binding).getType(); - IType t2 = createType( declarator ); - if( t1 != null && t2 != null && t1.isSameType( t2 ) ){ + IType t2 = createType(declarator); + if (t1 != null && t2 != null && t1.isSameType(t2)) { ICPPInternalBinding internal = (ICPPInternalBinding) binding; internal.addDeclaration(name); return binding; } - } catch ( DOMException e1 ) { + } catch (DOMException e1) { return e1.getProblem(); } - return new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, name.toCharArray() ); + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, name.toCharArray()); } - binding = new CPPTypedef( name ); - } else if( funcDeclarator != null ){ - if( binding instanceof ICPPInternalBinding && binding instanceof IFunction ){ + binding = new CPPTypedef(name); + } else if (funcDeclarator != null) { + if (binding instanceof ICPPInternalBinding && binding instanceof IFunction) { IFunction function = (IFunction) binding; - if( CPPSemantics.isSameFunction( function, funcDeclarator ) ){ + if (CPPSemantics.isSameFunction(function, funcDeclarator)) { ICPPInternalBinding internal = (ICPPInternalBinding) function; - if( parent instanceof IASTSimpleDeclaration ) - internal.addDeclaration( name ); - else { - if( internal.getDefinition() == null ) - internal.addDefinition( name ); - else { - IASTNode def = internal.getDefinition(); - if( def instanceof IASTDeclarator ) - def = ((IASTDeclarator)def).getName(); - if( def != name ) - return new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray() ); - } - - } + if (parent instanceof IASTSimpleDeclaration) { + internal.addDeclaration(name); + } else if (internal.getDefinition() == null) { + internal.addDefinition(name); + } else { + IASTNode def = internal.getDefinition(); + if (def instanceof IASTDeclarator) + def = ((IASTDeclarator)def).getName(); + if (def != name) { + return new ProblemBinding(name, + IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray()); + } + } return function; } @@ -605,44 +611,45 @@ public class CPPVisitor { } } - if( scope instanceof ICPPClassScope ){ - if( isConstructor( scope, funcDeclarator) ) - binding = template ? (ICPPConstructor) new CPPConstructorTemplate( name ) - : new CPPConstructor( (ICPPASTFunctionDeclarator) funcDeclarator ); - else - binding = template ? (ICPPMethod) new CPPMethodTemplate( name ) - : new CPPMethod( (ICPPASTFunctionDeclarator) funcDeclarator ); + if (scope instanceof ICPPClassScope) { + if (isConstructor(scope, funcDeclarator)) { + binding = template ? (ICPPConstructor) new CPPConstructorTemplate(name) + : new CPPConstructor((ICPPASTFunctionDeclarator) funcDeclarator); + } else { + binding = template ? (ICPPMethod) new CPPMethodTemplate(name) + : new CPPMethod((ICPPASTFunctionDeclarator) funcDeclarator); + } } else { - binding = template ? (ICPPFunction) new CPPFunctionTemplate( name ) - : new CPPFunction( (ICPPASTFunctionDeclarator) funcDeclarator ); + binding = template ? (ICPPFunction) new CPPFunctionTemplate(name) + : new CPPFunction((ICPPASTFunctionDeclarator) funcDeclarator); } - } else if( parent instanceof IASTSimpleDeclaration ){ + } else if (parent instanceof IASTSimpleDeclaration) { IType t1 = null, t2 = null; - if( binding != null && binding instanceof IVariable && !(binding instanceof IIndexBinding)){ - t1 = createType( declarator ); + if (binding != null && binding instanceof IVariable && !(binding instanceof IIndexBinding)) { + t1 = createType(declarator); try { t2 = ((IVariable)binding).getType(); - } catch ( DOMException e1 ) { + } catch (DOMException e1) { } } - if( t1 != null && t2 != null ){ - if( t1.isSameType( t2 ) ){ - if( binding instanceof ICPPInternalBinding ) - ((ICPPInternalBinding)binding).addDeclaration( name ); + if (t1 != null && t2 != null) { + if (t1.isSameType(t2)) { + if (binding instanceof ICPPInternalBinding) + ((ICPPInternalBinding)binding).addDeclaration(name); } else { - binding = new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, declarator.getName().toCharArray() ); + binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION, declarator.getName().toCharArray()); } - } else if( simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier ){ - binding = new CPPField( name ); + } else if (simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier) { + binding = new CPPField(name); } else { - binding = new CPPVariable( name ); + binding = new CPPVariable(name); } } - if( scope != null && binding != null ){ + if (scope != null && binding != null) { try { - ASTInternal.addName( scope, name ); - } catch ( DOMException e1 ) { + ASTInternal.addName(scope, name); + } catch (DOMException e1) { } } @@ -660,8 +667,8 @@ public class CPPVisitor { return false; } - public static boolean isConstructor( IScope containingScope, IASTDeclarator declarator ){ - if( containingScope == null || !(containingScope instanceof ICPPClassScope) ) + public static boolean isConstructor(IScope containingScope, IASTDeclarator declarator) { + if (containingScope == null || !(containingScope instanceof ICPPClassScope)) return false; ICPPASTCompositeTypeSpecifier clsTypeSpec; @@ -671,162 +678,164 @@ public class CPPVisitor { clsTypeSpec = (ICPPASTCompositeTypeSpecifier)node; else return false; - } catch ( DOMException e ) { + } catch (DOMException e) { return false; } if (clsTypeSpec == null) return false; IASTName clsName = clsTypeSpec.getName(); - if( clsName instanceof ICPPASTQualifiedName ){ - IASTName [] names = ((ICPPASTQualifiedName)clsName).getNames(); - clsName = names[ names.length - 1 ]; + if (clsName instanceof ICPPASTQualifiedName) { + IASTName[] names = ((ICPPASTQualifiedName)clsName).getNames(); + clsName = names[names.length - 1]; } - return isConstructor( clsName, declarator ); + return isConstructor(clsName, declarator); } - public static boolean isConstructor( IASTName parentName, IASTDeclarator declarator ){ - if( declarator == null || !(declarator instanceof IASTFunctionDeclarator) ) + public static boolean isConstructor(IASTName parentName, IASTDeclarator declarator) { + if (declarator == null || !(declarator instanceof IASTFunctionDeclarator)) return false; IASTName name = declarator.getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] names = ((ICPPASTQualifiedName)name).getNames(); - name = names[ names.length - 1 ]; + if (name instanceof ICPPASTQualifiedName) { + IASTName[] names = ((ICPPASTQualifiedName)name).getNames(); + name = names[names.length - 1]; } - if( !CharArrayUtils.equals( name.toCharArray(), parentName.toCharArray() ) ) + if (!CharArrayUtils.equals(name.toCharArray(), parentName.toCharArray())) return false; IASTDeclSpecifier declSpec = null; IASTNode parent = declarator.getParent(); - if( parent instanceof IASTSimpleDeclaration ){ + if (parent instanceof IASTSimpleDeclaration) { declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); - } else if( parent instanceof IASTFunctionDefinition ){ + } else if (parent instanceof IASTFunctionDefinition) { declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); } - if( declSpec != null && declSpec instanceof IASTSimpleDeclSpecifier ){ - return ( ((IASTSimpleDeclSpecifier)declSpec).getType() == IASTSimpleDeclSpecifier.t_unspecified ); + if (declSpec != null && declSpec instanceof IASTSimpleDeclSpecifier) { + return (((IASTSimpleDeclSpecifier)declSpec).getType() == IASTSimpleDeclSpecifier.t_unspecified); } return false; } - public static IScope getContainingScope( final IASTNode inputNode ){ - if( inputNode == null || inputNode instanceof IASTTranslationUnit) + public static IScope getContainingScope(final IASTNode inputNode) { + if (inputNode == null || inputNode instanceof IASTTranslationUnit) return null; IASTNode node= inputNode; - while( node != null ){ - if( node instanceof IASTName && !( node instanceof ICPPASTQualifiedName ) ){ - return getContainingScope( (IASTName) node ); + while (node != null) { + if (node instanceof IASTName && !(node instanceof ICPPASTQualifiedName)) { + return getContainingScope((IASTName) node); } - if( node instanceof IASTDeclaration ){ + if (node instanceof IASTDeclaration) { IASTNode parent = node.getParent(); - if( parent instanceof IASTTranslationUnit ){ + if (parent instanceof IASTTranslationUnit) { return ((IASTTranslationUnit)parent).getScope(); - } else if( parent instanceof IASTDeclarationStatement ){ - return getContainingScope( (IASTStatement) parent ); - } else if( parent instanceof IASTForStatement ){ + } else if (parent instanceof IASTDeclarationStatement) { + return getContainingScope((IASTStatement) parent); + } else if (parent instanceof IASTForStatement) { return ((IASTForStatement)parent).getScope(); - } else if( parent instanceof IASTCompositeTypeSpecifier ){ + } else if (parent instanceof IASTCompositeTypeSpecifier) { return ((IASTCompositeTypeSpecifier)parent).getScope(); - } else if( parent instanceof ICPPASTNamespaceDefinition ) { + } else if (parent instanceof ICPPASTNamespaceDefinition) { return ((ICPPASTNamespaceDefinition)parent).getScope(); - } else if( parent instanceof ICPPASTSwitchStatement ){ + } else if (parent instanceof ICPPASTSwitchStatement) { return ((ICPPASTSwitchStatement)parent).getScope(); - } else if( parent instanceof ICPPASTIfStatement ){ + } else if (parent instanceof ICPPASTIfStatement) { return ((ICPPASTIfStatement)parent).getScope(); - } else if( parent instanceof ICPPASTWhileStatement ){ + } else if (parent instanceof ICPPASTWhileStatement) { return ((ICPPASTWhileStatement)parent).getScope(); } - } else if( node instanceof IASTStatement ){ - return getContainingScope( (IASTStatement) node ); - } else if( node instanceof IASTTypeId ){ - if( node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ){ - ICPPASTTemplateDeclaration decl = CPPTemplates.getTemplateDeclaration( (IASTName) node.getParent() ); - if( decl == null ){ + } else if (node instanceof IASTStatement) { + return getContainingScope((IASTStatement) node); + } else if (node instanceof IASTTypeId) { + if (node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { + ICPPASTTemplateDeclaration decl = CPPTemplates.getTemplateDeclaration((IASTName) node.getParent()); + if (decl == null) { node = node.getParent(); - while( node instanceof IASTName ) + while (node instanceof IASTName) node = node.getParent(); continue; } } - } else if( node instanceof IASTParameterDeclaration ){ + } else if (node instanceof IASTParameterDeclaration) { IASTNode parent = node.getParent(); - if( parent instanceof ICPPASTFunctionDeclarator ){ + if (parent instanceof ICPPASTFunctionDeclarator) { ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent; - if( dtor.getNestedDeclarator() == null || dtor.getNestedDeclarator().getPointerOperators().length == 0) { - while( parent.getParent() instanceof IASTDeclarator ) + if (dtor.getNestedDeclarator() == null || dtor.getNestedDeclarator().getPointerOperators().length == 0) { + while (parent.getParent() instanceof IASTDeclarator) parent = parent.getParent(); ASTNodeProperty prop = parent.getPropertyInParent(); - if( prop == IASTSimpleDeclaration.DECLARATOR ) + if (prop == IASTSimpleDeclaration.DECLARATOR) return dtor.getFunctionScope(); - else if( prop == IASTFunctionDefinition.DECLARATOR ) + else if (prop == IASTFunctionDefinition.DECLARATOR) return ((IASTCompoundStatement)((IASTFunctionDefinition)parent.getParent()).getBody()).getScope(); } - } else if( parent instanceof ICPPASTTemplateDeclaration ){ - return CPPTemplates.getContainingScope( node ); + } else if (parent instanceof ICPPASTTemplateDeclaration) { + return CPPTemplates.getContainingScope(node); } - } else if( node instanceof IASTInitializerExpression ){ + } else if (node instanceof IASTInitializerExpression) { IASTNode parent = node.getParent(); - while( !(parent instanceof IASTDeclarator) ) + while (!(parent instanceof IASTDeclarator)) parent = parent.getParent(); IASTDeclarator dtor = (IASTDeclarator) parent; IASTName name = dtor.getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - return getContainingScope( ns[ ns.length - 1 ] ); + if (name instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); + return getContainingScope(ns[ns.length - 1]); } - } else if( node instanceof IASTExpression ){ + } else if (node instanceof IASTExpression) { IASTNode parent = node.getParent(); - if( parent instanceof IASTForStatement ){ + if (parent instanceof IASTForStatement) { return ((IASTForStatement)parent).getScope(); - } else if( parent instanceof ICPPASTIfStatement ){ + } else if (parent instanceof ICPPASTIfStatement) { return ((ICPPASTIfStatement)parent).getScope(); - } else if( parent instanceof ICPPASTSwitchStatement ){ + } else if (parent instanceof ICPPASTSwitchStatement) { return ((ICPPASTSwitchStatement)parent).getScope(); - } else if( parent instanceof ICPPASTWhileStatement ){ + } else if (parent instanceof ICPPASTWhileStatement) { return ((ICPPASTWhileStatement)parent).getScope(); - } else if( parent instanceof IASTCompoundStatement ){ + } else if (parent instanceof IASTCompoundStatement) { return ((IASTCompoundStatement)parent).getScope(); - } else if( parent instanceof ICPPASTConstructorChainInitializer ){ - IASTNode temp = getContainingBlockItem( parent.getParent() ); - if( temp instanceof IASTFunctionDefinition ){ + } else if (parent instanceof ICPPASTConstructorChainInitializer) { + IASTNode temp = getContainingBlockItem(parent.getParent()); + if (temp instanceof IASTFunctionDefinition) { IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition)temp).getBody(); return body.getScope(); } - } else if( parent instanceof IASTArrayModifier || parent instanceof IASTInitializer ){ + } else if (parent instanceof IASTArrayModifier || parent instanceof IASTInitializer) { IASTNode d = parent.getParent(); - while( !(d instanceof IASTDeclarator) ) + while (!(d instanceof IASTDeclarator)) d = d.getParent(); IASTDeclarator dtor = (IASTDeclarator) d; - while( dtor.getNestedDeclarator() != null ) + while (dtor.getNestedDeclarator() != null) dtor = dtor.getNestedDeclarator(); IASTName name = dtor.getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - return getContainingScope( ns[ ns.length - 1 ] ); + if (name instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); + return getContainingScope(ns[ns.length - 1]); } } - } else if( node instanceof ICPPASTTemplateParameter ){ - return CPPTemplates.getContainingScope( node ); - } else if( node instanceof ICPPASTBaseSpecifier ) { + } else if (node instanceof ICPPASTTemplateParameter) { + return CPPTemplates.getContainingScope(node); + } else if (node instanceof ICPPASTBaseSpecifier) { ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) node.getParent(); IASTName n = compSpec.getName(); - if( n instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)n).getNames(); - n = ns[ ns.length - 1 ]; + if (n instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)n).getNames(); + n = ns[ns.length - 1]; } - return CPPVisitor.getContainingScope( n ); + return CPPVisitor.getContainingScope(n); } node = node.getParent(); } - return new CPPScope.CPPScopeProblem( inputNode, IProblemBinding.SEMANTIC_BAD_SCOPE, inputNode.getRawSignature().toCharArray() ); + return new CPPScope.CPPScopeProblem(inputNode, IProblemBinding.SEMANTIC_BAD_SCOPE, + inputNode.getRawSignature().toCharArray()); } - public static IScope getContainingScope( IASTName name ){ + public static IScope getContainingScope(IASTName name) { IScope scope= getContainingScopeOrNull(name); if (scope == null) { - return new CPPScope.CPPScopeProblem( name, IProblemBinding.SEMANTIC_BAD_SCOPE, name.toCharArray() ); + return new CPPScope.CPPScopeProblem(name, IProblemBinding.SEMANTIC_BAD_SCOPE, + name.toCharArray()); } return scope; @@ -835,143 +844,141 @@ public class CPPVisitor { private static IScope getContainingScopeOrNull(IASTName name) { IASTNode parent = name.getParent(); try { - if( parent instanceof ICPPASTTemplateId ){ + if (parent instanceof ICPPASTTemplateId) { name = (IASTName) parent; parent = name.getParent(); } - ICPPASTTemplateDeclaration decl = CPPTemplates.getTemplateDeclaration( name ); - if( decl != null ) + ICPPASTTemplateDeclaration decl = CPPTemplates.getTemplateDeclaration(name); + if (decl != null) return decl.getScope(); - if( parent instanceof ICPPASTQualifiedName ){ - IASTName [] names = ((ICPPASTQualifiedName) parent).getNames(); + if (parent instanceof ICPPASTQualifiedName) { + IASTName[] names = ((ICPPASTQualifiedName) parent).getNames(); int i = 0; - for( ; i < names.length; i++ ){ - if( names[i] == name ) break; + for (; i < names.length; i++) { + if (names[i] == name) break; } - if( i > 0 ){ + if (i > 0) { IBinding binding = names[i - 1].resolveBinding(); - while( binding instanceof ITypedef ){ + while (binding instanceof ITypedef) { IType t = ((ITypedef)binding).getType(); - if( t instanceof IBinding ) + if (t instanceof IBinding) binding = (IBinding) t; else break; } boolean done= true; IScope scope= null; - if( binding instanceof ICPPClassType ){ + if (binding instanceof ICPPClassType) { scope= ((ICPPClassType)binding).getCompositeScope(); - } else if( binding instanceof ICPPNamespace ){ + } else if (binding instanceof ICPPNamespace) { scope= ((ICPPNamespace)binding).getNamespaceScope(); - } else if( binding instanceof ICPPInternalUnknown ){ + } else if (binding instanceof ICPPInternalUnknown) { scope= ((ICPPInternalUnknown)binding).getUnknownScope(); - } else if( binding instanceof IProblemBinding ){ - if( binding instanceof ICPPScope ) + } else if (binding instanceof IProblemBinding) { + if (binding instanceof ICPPScope) scope= (IScope) binding; - } - else { + } else { done= false; } if (done) { if (scope == null) { - return new CPPScope.CPPScopeProblem( names[i-1], IProblemBinding.SEMANTIC_BAD_SCOPE, names[i-1].toCharArray() ); + return new CPPScope.CPPScopeProblem(names[i - 1], + IProblemBinding.SEMANTIC_BAD_SCOPE, names[i-1].toCharArray()); } return scope; } } - else if( ((ICPPASTQualifiedName)parent).isFullyQualified() ) + else if (((ICPPASTQualifiedName)parent).isFullyQualified()) { return parent.getTranslationUnit().getScope(); } - } else if( parent instanceof ICPPASTFieldReference ){ + } else if (parent instanceof ICPPASTFieldReference) { final ICPPASTFieldReference fieldReference = (ICPPASTFieldReference)parent; IASTExpression owner = fieldReference.getFieldOwner(); - IType type = getExpressionType( owner ); - if( fieldReference.isPointerDereference() ){ + IType type = getExpressionType(owner); + if (fieldReference.isPointerDereference()) { type= CPPSemantics.getUltimateTypeUptoPointers(type); - if( type instanceof ICPPClassType ){ - ICPPFunction op = CPPSemantics.findOperator( fieldReference, (ICPPClassType) type ); - if( op != null ){ + if (type instanceof ICPPClassType) { + ICPPFunction op = CPPSemantics.findOperator(fieldReference, (ICPPClassType) type); + if (op != null) { type = op.getType().getReturnType(); } } } - type = CPPSemantics.getUltimateType( type, false ); - if( type instanceof ICPPClassType ){ + type = CPPSemantics.getUltimateType(type, false); + if (type instanceof ICPPClassType) { return ((ICPPClassType) type).getCompositeScope(); } - } else if( parent instanceof IASTGotoStatement || parent instanceof IASTLabelStatement ){ - while( !(parent instanceof IASTFunctionDefinition) ){ + } else if (parent instanceof IASTGotoStatement || parent instanceof IASTLabelStatement) { + while (!(parent instanceof IASTFunctionDefinition)) { parent = parent.getParent(); } IASTFunctionDefinition fdef = (IASTFunctionDefinition) parent; return ((ICPPASTFunctionDeclarator)fdef.getDeclarator()).getFunctionScope(); } - } catch( DOMException e ){ + } catch(DOMException e) { IProblemBinding problem = e.getProblem(); - if( problem instanceof ICPPScope ) + if (problem instanceof ICPPScope) return problem; - return new CPPScope.CPPScopeProblem( problem.getASTNode(), problem.getID(), problem.getNameCharArray() ); + return new CPPScope.CPPScopeProblem(problem.getASTNode(), problem.getID(), problem.getNameCharArray()); } - return getContainingScope( parent ); + return getContainingScope(parent); } - public static IScope getContainingScope( IASTStatement statement ){ + public static IScope getContainingScope(IASTStatement statement) { IASTNode parent = statement.getParent(); IScope scope = null; - if( parent instanceof IASTCompoundStatement ){ + if (parent instanceof IASTCompoundStatement) { IASTCompoundStatement compound = (IASTCompoundStatement) parent; scope = compound.getScope(); - } else if( parent instanceof IASTForStatement ){ + } else if (parent instanceof IASTForStatement) { scope = ((IASTForStatement)parent).getScope(); - } else if( parent instanceof ICPPASTSwitchStatement ){ + } else if (parent instanceof ICPPASTSwitchStatement) { scope = ((ICPPASTSwitchStatement)parent).getScope(); - } else if( parent instanceof ICPPASTIfStatement ){ + } else if (parent instanceof ICPPASTIfStatement) { scope = ((ICPPASTIfStatement)parent).getScope(); - } else if( parent instanceof ICPPASTWhileStatement ){ + } else if (parent instanceof ICPPASTWhileStatement) { scope = ((ICPPASTWhileStatement)parent).getScope(); - } else if( parent instanceof IASTStatement ){ - scope = getContainingScope( (IASTStatement)parent ); - } else if( parent instanceof IASTFunctionDefinition ){ - IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent ).getDeclarator(); + } else if (parent instanceof IASTStatement) { + scope = getContainingScope((IASTStatement)parent); + } else if (parent instanceof IASTFunctionDefinition) { + IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator(); IASTName name = fnDeclarator.getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - name = ns [ ns.length -1 ]; + if (name instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ns.length -1]; } - return getContainingScope( name ); + return getContainingScope(name); } - - - if( scope == null ) - return getContainingScope( parent ); + if (scope == null) + return getContainingScope(parent); return scope; } - public static IASTNode getContainingBlockItem( IASTNode node ){ - if( node == null ) return null; - if( node.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY ) return null; + public static IASTNode getContainingBlockItem(IASTNode node) { + if (node == null) return null; + if (node.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) return null; IASTNode parent = node.getParent(); - if( parent == null ) + if (parent == null) return null; - while( parent != null ) { - if( parent instanceof IASTDeclaration ){ + while (parent != null) { + if (parent instanceof IASTDeclaration) { IASTNode p = parent.getParent(); - if( p instanceof IASTDeclarationStatement ) + if (p instanceof IASTDeclarationStatement) return p; return parent; - } else if( parent instanceof IASTExpression ){ + } else if (parent instanceof IASTExpression) { IASTNode p = parent.getParent(); - if( p instanceof IASTForStatement ) + if (p instanceof IASTForStatement) return parent; - if( p instanceof IASTStatement ) + if (p instanceof IASTStatement) return p; - } else if ( parent instanceof IASTStatement || parent instanceof IASTTranslationUnit ) { + } else if (parent instanceof IASTStatement || parent instanceof IASTTranslationUnit) { return parent; - } else if( parent instanceof IASTFunctionDeclarator && node.getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER ){ + } else if (parent instanceof IASTFunctionDeclarator && node.getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER) { return node; - } else if( parent instanceof IASTEnumerationSpecifier.IASTEnumerator ){ + } else if (parent instanceof IASTEnumerationSpecifier.IASTEnumerator) { return parent; } node = parent; @@ -980,28 +987,29 @@ public class CPPVisitor { return null; } - static private IBinding resolveBinding( IASTNode node ){ + static private IBinding resolveBinding(IASTNode node) { IASTName name = null; - while( node != null ) { - if( node instanceof IASTIdExpression ){ + while (node != null) { + if (node instanceof IASTIdExpression) { name = ((IASTIdExpression) node).getName(); break; - } else if( node instanceof ICPPASTFieldReference ){ + } else if (node instanceof ICPPASTFieldReference) { name = ((ICPPASTFieldReference)node).getFieldName(); break; - } else if( node instanceof IASTFunctionCallExpression ){ + } else if (node instanceof IASTFunctionCallExpression) { node = ((IASTFunctionCallExpression)node).getFunctionNameExpression(); - } else if( node instanceof IASTUnaryExpression ){ + } else if (node instanceof IASTUnaryExpression) { node = ((IASTUnaryExpression)node).getOperand(); - } else if( node instanceof IASTBinaryExpression ){ + } else if (node instanceof IASTBinaryExpression) { node = ((IASTBinaryExpression)node).getOperand2(); - } else + } else { node = null; + } } - if( name != null ){ - if( name instanceof ICPPASTQualifiedName ){ - IASTName ns [] = ((ICPPASTQualifiedName)name).getNames(); - name = ns[ ns.length - 1 ]; + if (name != null) { + if (name instanceof ICPPASTQualifiedName) { + IASTName ns[] = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ns.length - 1]; } if (name instanceof CPPASTName) { ((CPPASTName) name).incResolutionDepth(); @@ -1010,11 +1018,11 @@ public class CPPVisitor { ((CPPASTTemplateId) name).incResolutionDepth(); } IBinding binding = name.getBinding(); - if( binding == null ){ - binding = CPPSemantics.resolveBinding( name ); - name.setBinding( binding ); - if( name instanceof ICPPASTTemplateId && binding instanceof ICPPSpecialization ){ - ((ICPPASTTemplateId)name).getTemplateName().setBinding( ((ICPPSpecialization)binding).getSpecializedBinding() ); + if (binding == null) { + binding = CPPSemantics.resolveBinding(name); + name.setBinding(binding); + if (name instanceof ICPPASTTemplateId && binding instanceof ICPPSpecialization) { + ((ICPPASTTemplateId)name).getTemplateName().setBinding(((ICPPSpecialization)binding).getSpecializedBinding()); } } return binding; @@ -1039,11 +1047,10 @@ public class CPPVisitor { } private void addProblem(IASTProblem problem) { - if( problems.length == numFound ) // if the found array is full, then double the array - { - IASTProblem [] old = problems; - problems = new IASTProblem[ old.length * 2 ]; - for( int j = 0; j < old.length; ++j ) + if (problems.length == numFound) { // if the found array is full, then double the array + IASTProblem[] old = problems; + problems = new IASTProblem[old.length * 2]; + for (int j = 0; j < old.length; ++j) problems[j] = old[j]; } problems[numFound++] = problem; @@ -1072,7 +1079,7 @@ public class CPPVisitor { */ @Override public int visit(IASTDeclaration declaration) { - if ( declaration instanceof IASTProblemHolder ) + if (declaration instanceof IASTProblemHolder) addProblem(((IASTProblemHolder)declaration).getProblem()); return PROCESS_CONTINUE; @@ -1082,7 +1089,7 @@ public class CPPVisitor { */ @Override public int visit(IASTExpression expression) { - if ( expression instanceof IASTProblemHolder ) + if (expression instanceof IASTProblemHolder) addProblem(((IASTProblemHolder)expression).getProblem()); return PROCESS_CONTINUE; @@ -1093,7 +1100,7 @@ public class CPPVisitor { */ @Override public int visit(IASTStatement statement) { - if ( statement instanceof IASTProblemHolder ) + if (statement instanceof IASTProblemHolder) addProblem(((IASTProblemHolder)statement).getProblem()); return PROCESS_CONTINUE; @@ -1104,7 +1111,7 @@ public class CPPVisitor { */ @Override public int visit(IASTTypeId typeId) { - if ( typeId instanceof IASTProblemHolder ) + if (typeId instanceof IASTProblemHolder) addProblem(((IASTProblemHolder)typeId).getProblem()); return PROCESS_CONTINUE; @@ -1113,7 +1120,7 @@ public class CPPVisitor { public static class CollectDeclarationsAction extends CPPASTVisitor { private static final int DEFAULT_LIST_SIZE = 8; - private IASTName [] decls; + private IASTName[] decls; private IBinding[] bindings; private int idx = 0; private int kind; @@ -1126,109 +1133,106 @@ public class CPPVisitor { private static final int KIND_TEMPLATE_PARAMETER = 6; - public CollectDeclarationsAction( IBinding binding ){ + public CollectDeclarationsAction(IBinding binding) { shouldVisitNames = true; - this.decls = new IASTName[ DEFAULT_LIST_SIZE ]; + this.decls = new IASTName[DEFAULT_LIST_SIZE]; this.bindings = new IBinding[] {binding}; if (binding instanceof ICPPUsingDeclaration) { this.bindings= ((ICPPUsingDeclaration) binding).getDelegates(); kind= KIND_COMPOSITE; - } - else if( binding instanceof ILabel ) + } else if (binding instanceof ILabel) { kind = KIND_LABEL; - else if( binding instanceof ICPPTemplateParameter ) + } else if (binding instanceof ICPPTemplateParameter) { kind = KIND_TEMPLATE_PARAMETER; - else if( binding instanceof ICompositeType || + } else if (binding instanceof ICompositeType || binding instanceof ITypedef || - binding instanceof IEnumeration) - { + binding instanceof IEnumeration) { kind = KIND_TYPE; - } - else if( binding instanceof ICPPNamespace) { + } else if (binding instanceof ICPPNamespace) { kind = KIND_NAMESPACE; - } - else + } else { kind = KIND_OBJ_FN; + } } @Override - public int visit( IASTName name ){ - if( name instanceof ICPPASTQualifiedName ) return PROCESS_CONTINUE; + public int visit(IASTName name) { + if (name instanceof ICPPASTQualifiedName) return PROCESS_CONTINUE; ASTNodeProperty prop = name.getPropertyInParent(); - if( prop == ICPPASTQualifiedName.SEGMENT_NAME ) + if (prop == ICPPASTQualifiedName.SEGMENT_NAME) prop = name.getParent().getPropertyInParent(); - switch( kind ){ + switch(kind) { case KIND_TEMPLATE_PARAMETER: - if( prop == ICPPASTSimpleTypeTemplateParameter.PARAMETER_NAME || - prop == ICPPASTTemplatedTypeTemplateParameter.PARAMETER_NAME ) - { + if (prop == ICPPASTSimpleTypeTemplateParameter.PARAMETER_NAME || + prop == ICPPASTTemplatedTypeTemplateParameter.PARAMETER_NAME) { break; - } else if( prop == IASTDeclarator.DECLARATOR_NAME ){ + } else if (prop == IASTDeclarator.DECLARATOR_NAME) { IASTNode d = name.getParent(); - while( d.getParent() instanceof IASTDeclarator ) + while (d.getParent() instanceof IASTDeclarator) d = d.getParent(); - if( d.getPropertyInParent() == IASTParameterDeclaration.DECLARATOR ){ + if (d.getPropertyInParent() == IASTParameterDeclaration.DECLARATOR) { break; } } return PROCESS_CONTINUE; + case KIND_LABEL: - if( prop == IASTLabelStatement.NAME ) + if (prop == IASTLabelStatement.NAME) break; return PROCESS_CONTINUE; + case KIND_TYPE: case KIND_COMPOSITE: - if( prop == IASTCompositeTypeSpecifier.TYPE_NAME || - prop == IASTEnumerationSpecifier.ENUMERATION_NAME || - prop == ICPPASTUsingDeclaration.NAME ) - { + if (prop == IASTCompositeTypeSpecifier.TYPE_NAME || + prop == IASTEnumerationSpecifier.ENUMERATION_NAME || + prop == ICPPASTUsingDeclaration.NAME) { break; - } else if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME ){ + } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { IASTNode p = name.getParent().getParent(); - if( p instanceof IASTSimpleDeclaration && - ((IASTSimpleDeclaration)p).getDeclarators().length == 0 ) + if (p instanceof IASTSimpleDeclaration && + ((IASTSimpleDeclaration)p).getDeclarators().length == 0) { break; } - } else if( prop == IASTDeclarator.DECLARATOR_NAME ){ + } else if (prop == IASTDeclarator.DECLARATOR_NAME) { IASTNode p = name.getParent(); while (p instanceof IASTDeclarator) { p= p.getParent(); } - if( p instanceof IASTSimpleDeclaration ){ + if (p instanceof IASTSimpleDeclaration) { IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)p).getDeclSpecifier(); - if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_typedef ) + if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_typedef) break; } } - if( kind == KIND_TYPE ) + if (kind == KIND_TYPE) return PROCESS_CONTINUE; + case KIND_OBJ_FN: - if( prop == IASTDeclarator.DECLARATOR_NAME || - prop == IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_NAME || - prop == ICPPASTUsingDeclaration.NAME ) - { + if (prop == IASTDeclarator.DECLARATOR_NAME || + prop == IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_NAME || + prop == ICPPASTUsingDeclaration.NAME) { break; } return PROCESS_CONTINUE; + case KIND_NAMESPACE: - if( prop == ICPPASTNamespaceDefinition.NAMESPACE_NAME || - prop == ICPPASTNamespaceAlias.ALIAS_NAME ) - { + if (prop == ICPPASTNamespaceDefinition.NAMESPACE_NAME || + prop == ICPPASTNamespaceAlias.ALIAS_NAME) { break; } return PROCESS_CONTINUE; } - if( bindings != null ) { + if (bindings != null) { if (isDeclarationsBinding(name.resolveBinding())) { - if( decls.length == idx ){ - IASTName [] temp = new IASTName[ decls.length * 2 ]; - System.arraycopy( decls, 0, temp, 0, decls.length ); + if (decls.length == idx) { + IASTName[] temp = new IASTName[decls.length * 2]; + System.arraycopy(decls, 0, temp, 0, decls.length); decls = temp; } decls[idx++] = name; @@ -1255,10 +1259,10 @@ public class CPPVisitor { return false; } - public IASTName[] getDeclarations(){ - if( idx < decls.length ){ - IASTName [] temp = new IASTName[ idx ]; - System.arraycopy( decls, 0, temp, 0, idx ); + public IASTName[] getDeclarations() { + if (idx < decls.length) { + IASTName[] temp = new IASTName[idx]; + System.arraycopy(decls, 0, temp, 0, idx); decls = temp; } return decls; @@ -1267,7 +1271,7 @@ public class CPPVisitor { } protected static IBinding unwindBinding(IBinding binding) { - while(true) { + while (true) { if (binding instanceof ICPPSpecialization) { binding= ((ICPPSpecialization) binding).getSpecializedBinding(); } else { @@ -1279,7 +1283,7 @@ public class CPPVisitor { public static class CollectReferencesAction extends CPPASTVisitor { private static final int DEFAULT_LIST_SIZE = 8; - private IASTName [] refs; + private IASTName[] refs; private IBinding[] bindings; private int idx = 0; private int kind; @@ -1291,9 +1295,9 @@ public class CPPVisitor { private static final int KIND_COMPOSITE = 5; - public CollectReferencesAction( IBinding binding ){ + public CollectReferencesAction(IBinding binding) { shouldVisitNames = true; - this.refs = new IASTName[ DEFAULT_LIST_SIZE ]; + this.refs = new IASTName[DEFAULT_LIST_SIZE]; binding = unwindBinding(binding); this.bindings = new IBinding[] {binding}; @@ -1301,15 +1305,15 @@ public class CPPVisitor { if (binding instanceof ICPPUsingDeclaration) { this.bindings= ((ICPPUsingDeclaration) binding).getDelegates(); kind= KIND_COMPOSITE; - } else if( binding instanceof ILabel ) { + } else if (binding instanceof ILabel) { kind = KIND_LABEL; - } else if( binding instanceof ICompositeType || + } else if (binding instanceof ICompositeType || binding instanceof ITypedef || binding instanceof IEnumeration) { kind = KIND_TYPE; - } else if( binding instanceof ICPPNamespace) { + } else if (binding instanceof ICPPNamespace) { kind = KIND_NAMESPACE; - } else if( binding instanceof ICPPTemplateParameter ) { + } else if (binding instanceof ICPPTemplateParameter) { kind = KIND_COMPOSITE; } else { kind = KIND_OBJ_FN; @@ -1317,74 +1321,70 @@ public class CPPVisitor { } @Override - public int visit( IASTName name ){ - if( name instanceof ICPPASTQualifiedName || name instanceof ICPPASTTemplateId ) return PROCESS_CONTINUE; + public int visit(IASTName name) { + if (name instanceof ICPPASTQualifiedName || name instanceof ICPPASTTemplateId) + return PROCESS_CONTINUE; ASTNodeProperty prop = name.getPropertyInParent(); ASTNodeProperty p2 = null; - if( prop == ICPPASTQualifiedName.SEGMENT_NAME ){ + if (prop == ICPPASTQualifiedName.SEGMENT_NAME) { p2 = prop; prop = name.getParent().getPropertyInParent(); } - switch( kind ){ + switch(kind) { case KIND_LABEL: - if( prop == IASTGotoStatement.NAME ) + if (prop == IASTGotoStatement.NAME) break; return PROCESS_CONTINUE; case KIND_TYPE: case KIND_COMPOSITE: - if( prop == IASTNamedTypeSpecifier.NAME || - prop == ICPPASTPointerToMember.NAME || - prop == ICPPASTTypenameExpression.TYPENAME || - prop == ICPPASTUsingDeclaration.NAME || - prop == ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier.NAME || - prop == ICPPASTTemplateId.TEMPLATE_NAME || - p2 == ICPPASTQualifiedName.SEGMENT_NAME ) - { + if (prop == IASTNamedTypeSpecifier.NAME || + prop == ICPPASTPointerToMember.NAME || + prop == ICPPASTTypenameExpression.TYPENAME || + prop == ICPPASTUsingDeclaration.NAME || + prop == ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier.NAME || + prop == ICPPASTTemplateId.TEMPLATE_NAME || + p2 == ICPPASTQualifiedName.SEGMENT_NAME) { break; - } - else if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME ) - { + } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { IASTNode p = name.getParent().getParent(); - if( !(p instanceof IASTSimpleDeclaration) || - ((IASTSimpleDeclaration)p).getDeclarators().length > 0 ) + if (!(p instanceof IASTSimpleDeclaration) || + ((IASTSimpleDeclaration)p).getDeclarators().length > 0) { break; } } - if( kind == KIND_TYPE ) + if (kind == KIND_TYPE) return PROCESS_CONTINUE; case KIND_OBJ_FN: - if( prop == IASTIdExpression.ID_NAME || - prop == IASTFieldReference.FIELD_NAME || - prop == ICPPASTUsingDirective.QUALIFIED_NAME || - prop == ICPPASTUsingDeclaration.NAME || - prop == IASTFunctionCallExpression.FUNCTION_NAME || - prop == ICPPASTUsingDeclaration.NAME || - prop == IASTNamedTypeSpecifier.NAME || - prop == ICPPASTConstructorChainInitializer.MEMBER_ID || - prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ) - { + if (prop == IASTIdExpression.ID_NAME || + prop == IASTFieldReference.FIELD_NAME || + prop == ICPPASTUsingDirective.QUALIFIED_NAME || + prop == ICPPASTUsingDeclaration.NAME || + prop == IASTFunctionCallExpression.FUNCTION_NAME || + prop == ICPPASTUsingDeclaration.NAME || + prop == IASTNamedTypeSpecifier.NAME || + prop == ICPPASTConstructorChainInitializer.MEMBER_ID || + prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { break; } return PROCESS_CONTINUE; case KIND_NAMESPACE: - if( prop == ICPPASTUsingDirective.QUALIFIED_NAME || - prop == ICPPASTNamespaceAlias.MAPPING_NAME || - prop == ICPPASTUsingDeclaration.NAME || - p2 == ICPPASTQualifiedName.SEGMENT_NAME ) - { + if (prop == ICPPASTUsingDirective.QUALIFIED_NAME || + prop == ICPPASTNamespaceAlias.MAPPING_NAME || + prop == ICPPASTUsingDeclaration.NAME || + p2 == ICPPASTQualifiedName.SEGMENT_NAME) { break; } return PROCESS_CONTINUE; } - if( bindings != null ){ + if (bindings != null) { if (isReferenceBinding(name.resolveBinding())) { - if (refs.length == idx){ - IASTName [] temp = new IASTName[ refs.length * 2 ]; - System.arraycopy( refs, 0, temp, 0, refs.length ); + if (refs.length == idx) { + IASTName[] temp = new IASTName[refs.length * 2]; + System.arraycopy(refs, 0, temp, 0, refs.length); refs = temp; } refs[idx++] = name; @@ -1417,10 +1417,10 @@ public class CPPVisitor { return false; } - public IASTName[] getReferences(){ - if( idx < refs.length ){ - IASTName [] temp = new IASTName[ idx ]; - System.arraycopy( refs, 0, temp, 0, idx ); + public IASTName[] getReferences() { + if (idx < refs.length) { + IASTName[] temp = new IASTName[idx]; + System.arraycopy(refs, 0, temp, 0, idx); refs = temp; } return refs; @@ -1435,11 +1435,11 @@ public class CPPVisitor { * @return */ - public static IFunctionType createImplicitFunctionType( IType returnType, IParameter [] parameters ){ - IType [] pTypes = new IType[ parameters.length ]; + public static IFunctionType createImplicitFunctionType(IType returnType, IParameter[] parameters) { + IType[] pTypes = new IType[parameters.length]; IType pt = null; - for( int i = 0; i < parameters.length; i++ ){ + for (int i = 0; i < parameters.length; i++) { try { pt = parameters[i].getType(); @@ -1448,31 +1448,31 @@ public class CPPVisitor { pt= ((IQualifierType) pt).getType(); } - if( pt instanceof IArrayType ){ - pt = new CPPPointerType( ((IArrayType) pt).getType() ); - } else if( pt instanceof IFunctionType ){ - pt = new CPPPointerType( pt ); + if (pt instanceof IArrayType) { + pt = new CPPPointerType(((IArrayType) pt).getType()); + } else if (pt instanceof IFunctionType) { + pt = new CPPPointerType(pt); } - } catch ( DOMException e ) { + } catch (DOMException e) { pt = e.getProblem(); } pTypes[i] = pt; } - return new CPPFunctionType( returnType, pTypes ); + return new CPPFunctionType(returnType, pTypes); } - private static IType createType( IType returnType, ICPPASTFunctionDeclarator fnDtor ) { - IASTParameterDeclaration [] params = fnDtor.getParameters(); - IType [] pTypes = new IType [ params.length ]; + private static IType createType(IType returnType, ICPPASTFunctionDeclarator fnDtor) { + IASTParameterDeclaration[] params = fnDtor.getParameters(); + IType[] pTypes = new IType[params.length]; IType pt = null; - for( int i = 0; i < params.length; i++ ){ + for (int i = 0; i < params.length; i++) { IASTDeclSpecifier pDeclSpec = params[i].getDeclSpecifier(); IASTDeclarator pDtor = params[i].getDeclarator(); - pt = createType( pDeclSpec ); - pt = createType( pt, pDtor ); + pt = createType(pDeclSpec); + pt = createType(pt, pDtor); //8.3.5-3 //Any cv-qualifier modifying a parameter type is deleted. @@ -1485,37 +1485,37 @@ public class CPPVisitor { pt= ((CPPPointerType) pt).stripQualifiers(); } //any parameter of type array of T is adjusted to be pointer to T - if( pt instanceof IArrayType ){ + if (pt instanceof IArrayType) { IArrayType at = (IArrayType) pt; - pt = new CPPPointerType( at.getType() ); + pt = new CPPPointerType(at.getType()); } - } catch ( DOMException e ) { + } catch (DOMException e) { pt = e.getProblem(); } //any parameter to type function returning T is adjusted to be pointer to function - if( pt instanceof IFunctionType ){ - pt = new CPPPointerType( pt ); + if (pt instanceof IFunctionType) { + pt = new CPPPointerType(pt); } pTypes[i] = pt; } IASTName name = fnDtor.getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - name = ns[ ns.length - 1 ]; + if (name instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ns.length - 1]; } - if( name instanceof ICPPASTConversionName ){ - returnType = createType( ((ICPPASTConversionName)name).getTypeId() ); + if (name instanceof ICPPASTConversionName) { + returnType = createType(((ICPPASTConversionName)name).getTypeId()); } else { - returnType = getPointerTypes( returnType, fnDtor ); + returnType = getPointerTypes(returnType, fnDtor); } - IType type = new CPPFunctionType( returnType, pTypes, fnDtor.isConst(), fnDtor.isVolatile() ); + IType type = new CPPFunctionType(returnType, pTypes, fnDtor.isConst(), fnDtor.isVolatile()); IASTDeclarator nested = fnDtor.getNestedDeclarator(); - if( nested != null ) { - return createType( type, nested ); + if (nested != null) { + return createType(type, nested); } return type; } @@ -1525,54 +1525,54 @@ public class CPPVisitor { * @return */ private static IType createType(IType baseType, IASTDeclarator declarator) { - if( declarator instanceof ICPPASTFunctionDeclarator ) - return createType( baseType, (ICPPASTFunctionDeclarator)declarator ); + if (declarator instanceof ICPPASTFunctionDeclarator) + return createType(baseType, (ICPPASTFunctionDeclarator)declarator); IType type = baseType; - type = getPointerTypes( type, declarator ); - if( declarator instanceof IASTArrayDeclarator ) - type = getArrayTypes( type, (IASTArrayDeclarator) declarator ); + type = getPointerTypes(type, declarator); + if (declarator instanceof IASTArrayDeclarator) + type = getArrayTypes(type, (IASTArrayDeclarator) declarator); IASTDeclarator nested = declarator.getNestedDeclarator(); - if( nested != null ) { - return createType( type, nested ); + if (nested != null) { + return createType(type, nested); } return type; } - private static IType getPointerTypes( IType type, IASTDeclarator declarator ){ - IASTPointerOperator [] ptrOps = declarator.getPointerOperators(); - for( int i = 0; i < ptrOps.length; i++ ){ - if( ptrOps[i] instanceof IGPPASTPointerToMember ) - type = new GPPPointerToMemberType( type, (IGPPASTPointerToMember) ptrOps[i] ); - else if( ptrOps[i] instanceof ICPPASTPointerToMember ) - type = new CPPPointerToMemberType( type, (ICPPASTPointerToMember) ptrOps[i] ); - else if( ptrOps[i] instanceof IGPPASTPointer ) - type = new GPPPointerType( type, (IGPPASTPointer) ptrOps[i] ); - else if( ptrOps[i] instanceof IASTPointer ) - type = new CPPPointerType( type, (IASTPointer) ptrOps[i] ); - else if( ptrOps[i] instanceof ICPPASTReferenceOperator ) - type = new CPPReferenceType( type ); + private static IType getPointerTypes(IType type, IASTDeclarator declarator) { + IASTPointerOperator[] ptrOps = declarator.getPointerOperators(); + for (int i = 0; i < ptrOps.length; i++) { + if (ptrOps[i] instanceof IGPPASTPointerToMember) + type = new GPPPointerToMemberType(type, (IGPPASTPointerToMember) ptrOps[i]); + else if (ptrOps[i] instanceof ICPPASTPointerToMember) + type = new CPPPointerToMemberType(type, (ICPPASTPointerToMember) ptrOps[i]); + else if (ptrOps[i] instanceof IGPPASTPointer) + type = new GPPPointerType(type, (IGPPASTPointer) ptrOps[i]); + else if (ptrOps[i] instanceof IASTPointer) + type = new CPPPointerType(type, (IASTPointer) ptrOps[i]); + else if (ptrOps[i] instanceof ICPPASTReferenceOperator) + type = new CPPReferenceType(type); } return type; } - private static IType getArrayTypes( IType type, IASTArrayDeclarator declarator ){ - IASTArrayModifier [] mods = declarator.getArrayModifiers(); - for( int i = 0; i < mods.length; i++ ){ - type = new CPPArrayType( type, mods[i].getConstantExpression() ); + private static IType getArrayTypes(IType type, IASTArrayDeclarator declarator) { + IASTArrayModifier[] mods = declarator.getArrayModifiers(); + for (int i = 0; i < mods.length; i++) { + type = new CPPArrayType(type, mods[i].getConstantExpression()); } return type; } - public static IType createType( IASTNode node ){ - if( node == null ) + public static IType createType(IASTNode node) { + if (node == null) return null; - if( node instanceof IASTExpression ) - return getExpressionType( (IASTExpression) node ); - if( node instanceof IASTTypeId ) - return createType( ((IASTTypeId) node).getAbstractDeclarator() ); - if( node instanceof IASTParameterDeclaration ) - return createType( ((IASTParameterDeclaration)node).getDeclarator() ); + if (node instanceof IASTExpression) + return getExpressionType((IASTExpression) node); + if (node instanceof IASTTypeId) + return createType(((IASTTypeId) node).getAbstractDeclarator()); + if (node instanceof IASTParameterDeclaration) + return createType(((IASTParameterDeclaration)node).getDeclarator()); return null; } /** @@ -1583,86 +1583,86 @@ public class CPPVisitor { IASTDeclSpecifier declSpec = null; IASTNode node = declarator.getParent(); - while( node instanceof IASTDeclarator ){ + while (node instanceof IASTDeclarator) { declarator = (IASTDeclarator) node; node = node.getParent(); } - if( node instanceof IASTParameterDeclaration ) + if (node instanceof IASTParameterDeclaration) declSpec = ((IASTParameterDeclaration) node).getDeclSpecifier(); - else if( node instanceof IASTSimpleDeclaration ) + else if (node instanceof IASTSimpleDeclaration) declSpec = ((IASTSimpleDeclaration)node).getDeclSpecifier(); - else if( node instanceof IASTFunctionDefinition ) + else if (node instanceof IASTFunctionDefinition) declSpec = ((IASTFunctionDefinition)node).getDeclSpecifier(); - else if( node instanceof IASTTypeId ) + else if (node instanceof IASTTypeId) declSpec = ((IASTTypeId)node).getDeclSpecifier(); - IType type = createType( declSpec ); - type = createType( type, declarator ); + IType type = createType(declSpec); + type = createType(type, declarator); return type; } /** * @param declSpec * @return */ - public static IType createType(IASTDeclSpecifier declSpec ) { - IType type = getBaseType( declSpec ); + public static IType createType(IASTDeclSpecifier declSpec) { + IType type = getBaseType(declSpec); - if( type != null && ( declSpec.isConst() || declSpec.isVolatile() ) ){ - type = new CPPQualifierType( type, declSpec.isConst(), declSpec.isVolatile() ); + if (type != null && (declSpec.isConst() || declSpec.isVolatile())) { + type = new CPPQualifierType(type, declSpec.isConst(), declSpec.isVolatile()); } return type; } - private static IType getBaseType( IASTDeclSpecifier declSpec ){ + private static IType getBaseType(IASTDeclSpecifier declSpec) { IType type = null; IASTName name = null; - if( declSpec instanceof ICPPASTCompositeTypeSpecifier ){ + if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { name = ((ICPPASTCompositeTypeSpecifier) declSpec).getName(); - } else if( declSpec instanceof ICPPASTNamedTypeSpecifier ){ + } else if (declSpec instanceof ICPPASTNamedTypeSpecifier) { name = ((ICPPASTNamedTypeSpecifier)declSpec).getName(); - } else if( declSpec instanceof ICPPASTElaboratedTypeSpecifier ){ + } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier) { name = ((ICPPASTElaboratedTypeSpecifier)declSpec).getName(); - } else if( declSpec instanceof IASTEnumerationSpecifier ){ + } else if (declSpec instanceof IASTEnumerationSpecifier) { name = ((IASTEnumerationSpecifier)declSpec).getName(); - } else if( declSpec instanceof ICPPASTSimpleDeclSpecifier ){ + } else if (declSpec instanceof ICPPASTSimpleDeclSpecifier) { ICPPASTSimpleDeclSpecifier spec = (ICPPASTSimpleDeclSpecifier) declSpec; - int bits = ( spec.isLong() ? ICPPBasicType.IS_LONG : 0 ) | - ( spec.isShort() ? ICPPBasicType.IS_SHORT : 0 ) | - ( spec.isSigned() ? ICPPBasicType.IS_SIGNED: 0 ) | - ( spec.isUnsigned() ? ICPPBasicType.IS_UNSIGNED : 0 ); - if( spec instanceof IGPPASTSimpleDeclSpecifier ){ + int bits = (spec.isLong() ? ICPPBasicType.IS_LONG : 0) | + (spec.isShort() ? ICPPBasicType.IS_SHORT : 0) | + (spec.isSigned() ? ICPPBasicType.IS_SIGNED: 0) | + (spec.isUnsigned() ? ICPPBasicType.IS_UNSIGNED : 0); + if (spec instanceof IGPPASTSimpleDeclSpecifier) { IGPPASTSimpleDeclSpecifier gspec = (IGPPASTSimpleDeclSpecifier) spec; - if( gspec.getTypeofExpression() != null ){ - type = getExpressionType( gspec.getTypeofExpression() ); + if (gspec.getTypeofExpression() != null) { + type = getExpressionType(gspec.getTypeofExpression()); } else { - bits |= ( gspec.isLongLong() ? ICPPBasicType.IS_LONG_LONG : 0 ); - type = new GPPBasicType( spec.getType(), bits, getExpressionType(gspec.getTypeofExpression()) ); + bits |= (gspec.isLongLong() ? ICPPBasicType.IS_LONG_LONG : 0); + type = new GPPBasicType(spec.getType(), bits, getExpressionType(gspec.getTypeofExpression())); } } else { - type = new CPPBasicType( spec.getType(), bits ); + type = new CPPBasicType(spec.getType(), bits); } } - if( name != null ){ + if (name != null) { IBinding binding = name.resolveBinding(); - if( binding instanceof ICPPConstructor ){ + if (binding instanceof ICPPConstructor) { try { ICPPClassScope scope = (ICPPClassScope) binding.getScope(); type = scope.getClassType(); - type = new CPPPointerType( type ); + type = new CPPPointerType(type); } catch (DOMException e) { type = e.getProblem(); } - } else if( binding instanceof IType ) { + } else if (binding instanceof IType) { type = (IType) binding; - } else if( binding instanceof ICPPTemplateNonTypeParameter ){ + } else if (binding instanceof ICPPTemplateNonTypeParameter) { //TODO workaround... is there anything better? try { type = ((ICPPTemplateNonTypeParameter)binding).getType(); } catch (DOMException e) { type = e.getProblem(); } - } else if( binding instanceof IVariable ){ + } else if (binding instanceof IVariable) { //this is to help with the ambiguity between typeid & idexpression in template arguments try { type = ((IVariable)binding).getType(); @@ -1674,37 +1674,37 @@ public class CPPVisitor { return type; } - public static IType getThisType( IScope scope ){ + public static IType getThisType(IScope scope) { try { IASTNode node = null; - while( scope != null ){ - if( scope instanceof ICPPBlockScope ){ + while (scope != null) { + if (scope instanceof ICPPBlockScope) { node = ASTInternal.getPhysicalNodeOfScope(scope); - if( node.getParent() instanceof IASTFunctionDefinition ) + if (node.getParent() instanceof IASTFunctionDefinition) break; } scope = scope.getParent(); } - if( node != null && node.getParent() instanceof IASTFunctionDefinition ){ + if (node != null && node.getParent() instanceof IASTFunctionDefinition) { IASTFunctionDefinition def = (IASTFunctionDefinition) node.getParent(); IASTName fName = def.getDeclarator().getName(); - if( fName instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)fName).getNames(); - fName = ns[ ns.length - 1]; + if (fName instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)fName).getNames(); + fName = ns[ns.length - 1]; } - IScope s = getContainingScope( fName ); + IScope s = getContainingScope(fName); ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) def.getDeclarator(); - if( s instanceof ICPPTemplateScope ) + if (s instanceof ICPPTemplateScope) s = getParentScope(s, fName.getTranslationUnit()); - if( s instanceof ICPPClassScope ){ + if (s instanceof ICPPClassScope) { ICPPClassScope cScope = (ICPPClassScope) s; IType type = cScope.getClassType(); - if( type instanceof ICPPClassTemplate ){ - type = (IType) CPPTemplates.instantiateWithinClassTemplate( (ICPPClassTemplate) type ); + if (type instanceof ICPPClassTemplate) { + type = (IType) CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) type); } - if( dtor.isConst() || dtor.isVolatile() ) - type = new CPPQualifierType(type, dtor.isConst(), dtor.isVolatile() ); - type = new CPPPointerType( type ); + if (dtor.isConst() || dtor.isVolatile()) + type = new CPPQualifierType(type, dtor.isConst(), dtor.isVolatile()); + type = new CPPPointerType(type); return type; } } @@ -1719,54 +1719,54 @@ public class CPPVisitor { * @return */ public static IType getExpressionType(IASTExpression expression) { - if( expression == null ) + if (expression == null) return null; - if( expression instanceof IASTIdExpression ){ - IBinding binding = resolveBinding( expression ); + if (expression instanceof IASTIdExpression) { + IBinding binding = resolveBinding(expression); try { - if( binding instanceof IVariable ){ + if (binding instanceof IVariable) { return ((IVariable)binding).getType(); - } else if( binding instanceof IEnumerator ){ + } else if (binding instanceof IEnumerator) { return ((IEnumerator)binding).getType(); - } else if( binding instanceof IProblemBinding ){ + } else if (binding instanceof IProblemBinding) { return (IType) binding; - } else if( binding instanceof IFunction ){ + } else if (binding instanceof IFunction) { return ((IFunction)binding).getType(); - } else if( binding instanceof ICPPTemplateNonTypeParameter ){ + } else if (binding instanceof ICPPTemplateNonTypeParameter) { return ((ICPPTemplateNonTypeParameter)binding).getType(); } - } catch ( DOMException e ){ + } catch (DOMException e) { return e.getProblem(); } - } else if( expression instanceof IASTCastExpression ){ + } else if (expression instanceof IASTCastExpression) { IASTTypeId id = ((IASTCastExpression)expression).getTypeId(); - IType type = createType( id.getDeclSpecifier() ); - return createType( type, id.getAbstractDeclarator() ); - } else if( expression instanceof ICPPASTLiteralExpression ){ - switch( ((ICPPASTLiteralExpression) expression).getKind() ){ + IType type = createType(id.getDeclSpecifier()); + return createType(type, id.getAbstractDeclarator()); + } else if (expression instanceof ICPPASTLiteralExpression) { + switch(((ICPPASTLiteralExpression) expression).getKind()) { case ICPPASTLiteralExpression.lk_this : { - IScope scope = getContainingScope( expression ); - return getThisType( scope ); + IScope scope = getContainingScope(expression); + return getThisType(scope); } case ICPPASTLiteralExpression.lk_true : case ICPPASTLiteralExpression.lk_false: - return new CPPBasicType( ICPPBasicType.t_bool, 0, expression ); + return new CPPBasicType(ICPPBasicType.t_bool, 0, expression); case IASTLiteralExpression.lk_char_constant: - return new CPPBasicType( IBasicType.t_char, 0, expression ); + return new CPPBasicType(IBasicType.t_char, 0, expression); case IASTLiteralExpression.lk_float_constant: - return new CPPBasicType( IBasicType.t_float, 0, expression ); + return new CPPBasicType(IBasicType.t_float, 0, expression); case IASTLiteralExpression.lk_integer_constant: - return new CPPBasicType( IBasicType.t_int, 0, expression ); + return new CPPBasicType(IBasicType.t_int, 0, expression); case IASTLiteralExpression.lk_string_literal: - IType type = new CPPBasicType( IBasicType.t_char, 0, expression ); - type = new CPPQualifierType( type, true, false ); - return new CPPPointerType( type ); + IType type = new CPPBasicType(IBasicType.t_char, 0, expression); + type = new CPPQualifierType(type, true, false); + return new CPPPointerType(type); } - } else if( expression instanceof IASTFunctionCallExpression ){ - IBinding binding = resolveBinding( expression ); - if( binding instanceof ICPPConstructor ){ + } else if (expression instanceof IASTFunctionCallExpression) { + IBinding binding = resolveBinding(expression); + if (binding instanceof ICPPConstructor) { try { IScope scope= binding.getScope(); if (scope instanceof ICPPTemplateScope && ! (scope instanceof ICPPClassScope)) { @@ -1778,50 +1778,51 @@ public class CPPVisitor { } catch (DOMException e) { return e.getProblem(); } - return new ProblemBinding(expression, IProblemBinding.SEMANTIC_BAD_SCOPE, binding.getName().toCharArray()); - } else if( binding instanceof IFunction ){ + return new ProblemBinding(expression, IProblemBinding.SEMANTIC_BAD_SCOPE, + binding.getName().toCharArray()); + } else if (binding instanceof IFunction) { IFunctionType fType; try { fType = ((IFunction)binding).getType(); - if( fType != null ) + if (fType != null) return fType.getReturnType(); - } catch ( DOMException e ) { + } catch (DOMException e) { return e.getProblem(); } - } else if( binding instanceof IVariable ){ + } else if (binding instanceof IVariable) { try { IType t = ((IVariable)binding).getType(); - while( t instanceof ITypedef ){ + while (t instanceof ITypedef) { t = ((ITypedef)t).getType(); } - if( t instanceof IPointerType && ((IPointerType)t).getType() instanceof IFunctionType ){ + if (t instanceof IPointerType && ((IPointerType)t).getType() instanceof IFunctionType) { IFunctionType ftype = (IFunctionType) ((IPointerType)t).getType(); - if( ftype != null ) + if (ftype != null) return ftype.getReturnType(); } - } catch( DOMException e ){ + } catch(DOMException e) { return e.getProblem(); } - } else if( binding instanceof ITypedef ){ + } else if (binding instanceof ITypedef) { try { IType type = ((ITypedef)binding).getType(); - while( type instanceof ITypedef ) + while (type instanceof ITypedef) type = ((ITypedef)type).getType(); - if( type instanceof IFunctionType ){ + if (type instanceof IFunctionType) { return ((IFunctionType)type).getReturnType(); } return type; } catch (DOMException e) { return e.getProblem(); } - } else if( binding instanceof IProblemBinding ){ + } else if (binding instanceof IProblemBinding) { return (IType) binding; } - } else if( expression instanceof IASTBinaryExpression ){ + } else if (expression instanceof IASTBinaryExpression) { IASTBinaryExpression binary = (IASTBinaryExpression) expression; int op = binary.getOperator(); IType result = null; - switch( op ){ + switch(op) { case IASTBinaryExpression.op_lessEqual: case IASTBinaryExpression.op_lessThan: case IASTBinaryExpression.op_greaterEqual: @@ -1830,171 +1831,169 @@ public class CPPVisitor { case IASTBinaryExpression.op_logicalOr: case IASTBinaryExpression.op_equals: case IASTBinaryExpression.op_notequals: - result = new CPPBasicType( ICPPBasicType.t_bool, 0 ); + result = new CPPBasicType(ICPPBasicType.t_bool, 0); break; case IASTBinaryExpression.op_plus: case IASTBinaryExpression.op_minus: - IType t = getExpressionType( ((IASTBinaryExpression) expression).getOperand1() ); - if( t instanceof IPointerType ) + IType t = getExpressionType(((IASTBinaryExpression) expression).getOperand1()); + if (t instanceof IPointerType) result = t; else{ - result = getExpressionType( ((IASTBinaryExpression) expression).getOperand2() ); + result = getExpressionType(((IASTBinaryExpression) expression).getOperand2()); } break; case ICPPASTBinaryExpression.op_pmarrow: case ICPPASTBinaryExpression.op_pmdot: - IType type = getExpressionType( ((IASTBinaryExpression) expression).getOperand2() ); - if( type instanceof ICPPPointerToMemberType ){ + IType type = getExpressionType(((IASTBinaryExpression) expression).getOperand2()); + if (type instanceof ICPPPointerToMemberType) { try { result = ((ICPPPointerToMemberType)type).getType(); - } catch ( DOMException e ) { + } catch (DOMException e) { result = e.getProblem(); } } else { - result = new ProblemBinding( binary, IProblemBinding.SEMANTIC_INVALID_TYPE, new char[0] ); + result = new ProblemBinding(binary, IProblemBinding.SEMANTIC_INVALID_TYPE, new char[0]); } break; default: - result = getExpressionType( ((IASTBinaryExpression) expression).getOperand1() ); + result = getExpressionType(((IASTBinaryExpression) expression).getOperand1()); } - if( result instanceof CPPBasicType ){ - ((CPPBasicType)result).setValue( expression ); + if (result instanceof CPPBasicType) { + ((CPPBasicType)result).setValue(expression); } return result; - } - else if( expression instanceof IASTUnaryExpression ) - { + } else if (expression instanceof IASTUnaryExpression) { int op = ((IASTUnaryExpression)expression).getOperator(); - if( op == IASTUnaryExpression.op_sizeof ){ - IScope scope = getContainingScope( expression ); + if (op == IASTUnaryExpression.op_sizeof) { + IScope scope = getContainingScope(expression); try { - IBinding [] bs = scope.find( SIZE_T ); - if( bs.length > 0 && bs[0] instanceof IType ){ + IBinding[] bs = scope.find(SIZE_T); + if (bs.length > 0 && bs[0] instanceof IType) { return (IType) bs[0]; } } catch (DOMException e) { } - return new CPPBasicType( IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED ); + return new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED); } - IType type = getExpressionType(((IASTUnaryExpression)expression).getOperand() ); - while( type instanceof ITypedef ){ + IType type = getExpressionType(((IASTUnaryExpression)expression).getOperand()); + while (type instanceof ITypedef) { try { type = ((ITypeContainer)type).getType(); } catch (DOMException e) { break; } } - if( op == IASTUnaryExpression.op_star && type instanceof ICPPClassType) { + if (op == IASTUnaryExpression.op_star && type instanceof ICPPClassType) { try { ICPPFunction operator= CPPSemantics.findOperator(expression, (ICPPClassType) type); - if(operator!=null) { + if (operator!=null) { return operator.getType().getReturnType(); } } catch(DOMException de) { return de.getProblem(); } } - if( op == IASTUnaryExpression.op_star && (type instanceof IPointerType || type instanceof IArrayType) ){ + if (op == IASTUnaryExpression.op_star && (type instanceof IPointerType || type instanceof IArrayType)) { try { return ((ITypeContainer)type).getType(); } catch (DOMException e) { return e.getProblem(); } - } else if( op == IASTUnaryExpression.op_amper ){ - if( type instanceof ICPPReferenceType ) + } else if (op == IASTUnaryExpression.op_amper) { + if (type instanceof ICPPReferenceType) try { - return new CPPPointerType( ((ICPPReferenceType)type).getType() ); + return new CPPPointerType(((ICPPReferenceType)type).getType()); } catch (DOMException e) { } - return new CPPPointerType( type ); - } else if ( type instanceof CPPBasicType ){ - ((CPPBasicType)type).setValue( expression ); + return new CPPPointerType(type); + } else if (type instanceof CPPBasicType) { + ((CPPBasicType)type).setValue(expression); } return type; - } else if( expression instanceof ICPPASTFieldReference ){ + } else if (expression instanceof ICPPASTFieldReference) { IASTName name = ((ICPPASTFieldReference)expression).getFieldName(); IBinding binding = name.resolveBinding(); try { - if( binding instanceof IVariable ) + if (binding instanceof IVariable) return ((IVariable)binding).getType(); - else if( binding instanceof IFunction ) + else if (binding instanceof IFunction) return ((IFunction)binding).getType(); - else if( binding instanceof IEnumerator ) + else if (binding instanceof IEnumerator) return ((IEnumerator)binding).getType(); - } catch ( DOMException e ) { + } catch (DOMException e) { return e.getProblem(); } - } else if( expression instanceof IASTExpressionList ){ - IASTExpression [] exps = ((IASTExpressionList)expression).getExpressions(); - return getExpressionType( exps[ exps.length - 1 ] ); - } else if( expression instanceof ICPPASTTypeIdExpression ){ + } else if (expression instanceof IASTExpressionList) { + IASTExpression[] exps = ((IASTExpressionList)expression).getExpressions(); + return getExpressionType(exps[exps.length - 1]); + } else if (expression instanceof ICPPASTTypeIdExpression) { ICPPASTTypeIdExpression typeidExp = (ICPPASTTypeIdExpression) expression; - if( typeidExp.getOperator() == IASTTypeIdExpression.op_sizeof ){ - IScope scope = getContainingScope( typeidExp ); + if (typeidExp.getOperator() == IASTTypeIdExpression.op_sizeof) { + IScope scope = getContainingScope(typeidExp); try { - IBinding [] bs = scope.find( SIZE_T ); - if( bs.length > 0 && bs[0] instanceof IType ){ + IBinding[] bs = scope.find(SIZE_T); + if (bs.length > 0 && bs[0] instanceof IType) { return (IType) bs[0]; } } catch (DOMException e) { } - return new CPPBasicType( IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED ); + return new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED); } - return createType( typeidExp.getTypeId() ); - } else if( expression instanceof IASTArraySubscriptExpression ){ - IType t = getExpressionType( ((IASTArraySubscriptExpression) expression).getArrayExpression() ); + return createType(typeidExp.getTypeId()); + } else if (expression instanceof IASTArraySubscriptExpression) { + IType t = getExpressionType(((IASTArraySubscriptExpression) expression).getArrayExpression()); try { - if( t instanceof ICPPReferenceType ) + if (t instanceof ICPPReferenceType) t = ((ICPPReferenceType)t).getType(); - while( t instanceof ITypedef ){ + while (t instanceof ITypedef) { t = ((ITypedef)t).getType(); } - if( t instanceof ICPPClassType ){ - ICPPFunction op = CPPSemantics.findOperator( expression, (ICPPClassType) t ); - if( op != null ){ + if (t instanceof ICPPClassType) { + ICPPFunction op = CPPSemantics.findOperator(expression, (ICPPClassType) t); + if (op != null) { return op.getType().getReturnType(); } } - if( t instanceof IPointerType ) + if (t instanceof IPointerType) return ((IPointerType)t).getType(); - else if( t instanceof IArrayType ) + else if (t instanceof IArrayType) return ((IArrayType)t).getType(); - } catch( DOMException e ){ + } catch(DOMException e) { } - } else if( expression instanceof IGNUASTCompoundStatementExpression ){ + } else if (expression instanceof IGNUASTCompoundStatementExpression) { IASTCompoundStatement compound = ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement(); - IASTStatement [] statements = compound.getStatements(); - if( statements.length > 0 ){ - IASTStatement st = statements[ statements.length - 1 ]; - if( st instanceof IASTExpressionStatement ) - return getExpressionType( ((IASTExpressionStatement)st).getExpression() ); + IASTStatement[] statements = compound.getStatements(); + if (statements.length > 0) { + IASTStatement st = statements[statements.length - 1]; + if (st instanceof IASTExpressionStatement) + return getExpressionType(((IASTExpressionStatement)st).getExpression()); } - } else if( expression instanceof IASTConditionalExpression ){ + } else if (expression instanceof IASTConditionalExpression) { IASTConditionalExpression conditional = (IASTConditionalExpression) expression; - IType t2 = getExpressionType( conditional.getPositiveResultExpression() ); - IType t3 = getExpressionType( conditional.getNegativeResultExpression() ); - if( t3 instanceof IPointerType || t2 == null ) + IType t2 = getExpressionType(conditional.getPositiveResultExpression()); + IType t3 = getExpressionType(conditional.getNegativeResultExpression()); + if (t3 instanceof IPointerType || t2 == null) return t3; return t2; - } else if( expression instanceof ICPPASTDeleteExpression ){ + } else if (expression instanceof ICPPASTDeleteExpression) { return CPPSemantics.VOID_TYPE; - } else if( expression instanceof ICPPASTTypenameExpression ){ + } else if (expression instanceof ICPPASTTypenameExpression) { IBinding binding = ((ICPPASTTypenameExpression)expression).getName().resolveBinding(); - if( binding instanceof IType ) + if (binding instanceof IType) return (IType) binding; - } else if( expression instanceof ICPPASTNewExpression ) { + } else if (expression instanceof ICPPASTNewExpression) { ICPPASTNewExpression newExp = (ICPPASTNewExpression) expression; - return createType( newExp.getTypeId() ); + return createType(newExp.getTypeId()); } return null; } - public static IASTDeclarator getMostNestedDeclarator( IASTDeclarator dtor ){ - if( dtor == null ) return null; + public static IASTDeclarator getMostNestedDeclarator(IASTDeclarator dtor) { + if (dtor == null) return null; IASTDeclarator nested = null; - while( (nested = dtor.getNestedDeclarator()) != null ){ + while ((nested = dtor.getNestedDeclarator()) != null) { dtor = nested; } return dtor; @@ -2013,30 +2012,30 @@ public class CPPVisitor { * @return */ public static IASTName[] getReferences(IASTTranslationUnit tu, IBinding binding) { - CollectReferencesAction action = new CollectReferencesAction( binding ); - tu.accept( action ); + CollectReferencesAction action = new CollectReferencesAction(binding); + tu.accept(action); return action.getReferences(); } - public static IASTName[] getDeclarations( IASTTranslationUnit tu, IBinding binding ){ - CollectDeclarationsAction action = new CollectDeclarationsAction( binding ); - tu.accept( action ); + public static IASTName[] getDeclarations(IASTTranslationUnit tu, IBinding binding) { + CollectDeclarationsAction action = new CollectDeclarationsAction(binding); + tu.accept(action); - IASTName [] found = action.getDeclarations(); - if( found.length == 0 && binding instanceof ICPPSpecialization && binding instanceof ICPPInternalBinding ){ + IASTName[] found = action.getDeclarations(); + if (found.length == 0 && binding instanceof ICPPSpecialization && binding instanceof ICPPInternalBinding) { IASTNode node = ((ICPPInternalBinding)binding).getDefinition(); - if( node == null ){ - IASTNode [] nds = ((ICPPInternalBinding)binding).getDeclarations(); - if( nds != null && nds.length > 0 ) + if (node == null) { + IASTNode[] nds = ((ICPPInternalBinding)binding).getDeclarations(); + if (nds != null && nds.length > 0) node = nds[0]; } - if( node != null ){ + if (node != null) { IASTName name = null; - if( node instanceof IASTDeclarator ) + if (node instanceof IASTDeclarator) name = ((IASTDeclarator)node).getName(); - else if( node instanceof IASTName ) + else if (node instanceof IASTName) name = (IASTName) node; - if( name != null ) + if (name != null) found = new IASTName[] { name }; } } @@ -2052,77 +2051,77 @@ public class CPPVisitor { */ public static String renderQualifiedName(String[] qn) { StringBuffer result = new StringBuffer(); - for(int i=0; i= 0; i-- ){ - result[ ns.length - i - 1 ] = ns[i].toString(); + ns = (IName[]) ArrayUtil.trim(IName.class, ns); + String[] result = new String[ns.length + 1]; + for (int i = ns.length - 1; i >= 0; i--) { + result[ns.length - i - 1] = ns[i].toString(); } result[ns.length] = binding.getName(); return result; } - public static char [][] getQualifiedNameCharArray( IBinding binding ) { - IName [] ns = null; + public static char[][] getQualifiedNameCharArray(IBinding binding) { + IName[] ns = null; try { ICPPScope scope = (ICPPScope) binding.getScope(); - while( scope != null ){ - if( scope instanceof ICPPTemplateScope ) + while (scope != null) { + if (scope instanceof ICPPTemplateScope) scope = (ICPPScope) scope.getParent(); if (scope == null) break; IName n = scope.getScopeName(); - if( n == null ) + if (n == null) break; - if( scope instanceof ICPPBlockScope || scope instanceof ICPPFunctionScope ) + if (scope instanceof ICPPBlockScope || scope instanceof ICPPFunctionScope) break; - if( scope instanceof ICPPNamespaceScope && scope.getScopeName().toCharArray().length == 0 ) + if (scope instanceof ICPPNamespaceScope && scope.getScopeName().toCharArray().length == 0) break; - ns = (IName[]) ArrayUtil.append( IName.class, ns, n ); + ns = (IName[]) ArrayUtil.append(IName.class, ns, n); scope = (ICPPScope) scope.getParent(); } - } catch ( DOMException e ) { + } catch (DOMException e) { } - ns = (IName[]) ArrayUtil.trim( IName.class, ns ); - char[] [] result = new char[ ns.length + 1 ][]; - for( int i = ns.length - 1; i >= 0; i-- ){ - result[ ns.length - i - 1 ] = ns[i].toCharArray(); + ns = (IName[]) ArrayUtil.trim(IName.class, ns); + char[][] result = new char[ns.length + 1][]; + for (int i = ns.length - 1; i >= 0; i--) { + result[ns.length - i - 1] = ns[i].toCharArray(); } result[ns.length] = binding.getNameCharArray(); return result; } - + private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException { IScope parentScope= scope.getParent(); // the index cannot return the translation unit as parent scope @@ -2131,7 +2130,7 @@ public class CPPVisitor { } return parentScope; } - + public static boolean isExternC(IASTNode node) { while (node != null) { node= node.getParent(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java index 54091f96122..9a3edac1b7d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java @@ -44,8 +44,7 @@ public class TemplateInstanceUtil { if(specd instanceof ICPPTemplateDefinition) { keysToAdapt= ((ICPPTemplateDefinition)specd).getTemplateParameters(); } - final int length= Math.min(keys.length, keysToAdapt.length); - for(int i=0; i