1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

toString methods.

This commit is contained in:
Sergey Prigogin 2008-03-16 04:53:12 +00:00
parent c09235c6d1
commit ce309040bd
9 changed files with 1216 additions and 1149 deletions

View file

@ -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 ))
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() : "<unnamed scope>"; //$NON-NLS-1$
}
}

View file

@ -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();
}
}

View file

@ -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());
}
}
}
@ -177,45 +179,46 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
}
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();
@ -264,8 +268,9 @@ 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 {
@ -321,12 +328,11 @@ 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;
}
@ -334,31 +340,30 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
* @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;
}
@ -367,31 +372,31 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
* @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);
}
}
@ -402,4 +407,18 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
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() : "<unnamed scope>"; //$NON-NLS-1$
}
}

View file

@ -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();
}
}

View file

@ -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 {
declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, declName );
// 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);
}
}
}
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);
}
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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<length; i++) {
for(int i = 0; i < keys.length && i < keysToAdapt.length; i++) {
IType type= (IType) preresult.get(keys[i]);
result.put(
cf.getCompositeBinding((IIndexFragmentBinding)keysToAdapt[i]),