diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java index f1aa059ac7c..88682a894ad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,7 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.ITypedef; @@ -33,7 +33,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; public class CPPBaseClause implements ICPPBase { static public class CPPBaseProblem extends ProblemBinding implements ICPPBase { private ICPPClassType classProblem = null; - public CPPBaseProblem( IASTName node, int id, char[] arg ) { + public CPPBaseProblem( IASTNode node, int id, char[] arg ) { super( node, id, arg ); } public IBinding getBaseClass() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java index d98e42d81a6..b2ce8163667 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Bryan Wilkinson (QNX) *******************************************************************************/ /* * Created on Mar 28, 2005 @@ -29,14 +30,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.parser.util.ObjectMap; /** * @author aniefer */ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPPInternalBinding { - private CPPClassInstanceScope instanceScope; + private CPPClassSpecializationScope instanceScope; /** * @param decl @@ -53,16 +53,15 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP public ICPPBase[] getBases() throws DOMException { ICPPClassType cls = (ICPPClassType) getSpecializedBinding(); if( cls != null ){ - ICPPBase [] bases = cls.getBases(); - for (int i = 0; i < bases.length; i++) { - IBinding T = bases[i].getBaseClass(); - if( T instanceof ICPPTemplateTypeParameter && argumentMap.containsKey( T ) ){ - IType t = (IType) argumentMap.get( T ); - if( t instanceof ICPPClassType ) - ((CPPBaseClause)bases[i]).setBaseClass( (ICPPClassType) argumentMap.get(T) ); - } + ICPPBase [] bindings = cls.getBases(); + for (int i = 0; i < bindings.length; i++) { + IBinding base = bindings[i].getBaseClass(); + if (base instanceof IType) { + IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap); + ((CPPBaseClause)bindings[i]).setBaseClass((ICPPClassType)specBase); + } } - return bases; + return bindings; } return ICPPBase.EMPTY_BASE_ARRAY; } @@ -119,7 +118,7 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getConstructors() */ public ICPPConstructor[] getConstructors() throws DOMException { - CPPClassInstanceScope scope = (CPPClassInstanceScope) getCompositeScope(); + CPPClassSpecializationScope scope = (CPPClassSpecializationScope) getCompositeScope(); if( scope.isFullyCached() ) return scope.getConstructors(); return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; @@ -145,7 +144,7 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP */ public IScope getCompositeScope() { if( instanceScope == null ){ - instanceScope = new CPPClassInstanceScope( this ); + instanceScope = new CPPClassSpecializationScope( this ); } return instanceScope; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index 60441c3a2fe..65b779b9918 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,7 +7,7 @@ * * Contributors: * IBM - Initial API and implementation - * / + * Bryan Wilkinson (QNX) *******************************************************************************/ /* * Created on Apr 29, 2005 @@ -15,22 +15,32 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ObjectMap; +import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; /** * @author aniefer @@ -39,6 +49,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; public class CPPClassSpecialization extends CPPSpecialization implements ICPPClassType, ICPPInternalClassType { + private IScope specScope; + /** * @param specialized * @param scope @@ -47,24 +59,44 @@ public class CPPClassSpecialization extends CPPSpecialization implements super(specialized, scope, argumentMap); } + private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){ + IASTNode definition = getDefinition(); + if( definition != null ){ + IASTNode node = definition; + while( node instanceof IASTName ) + node = node.getParent(); + if( node instanceof ICPPASTCompositeTypeSpecifier ) + return (ICPPASTCompositeTypeSpecifier)node; + } + return null; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases() */ public ICPPBase[] getBases() throws DOMException { - ICPPClassType cls = (ICPPClassType) getSpecializedBinding(); - if( cls != null ){ - ICPPBase [] bases = cls.getBases(); - for (int i = 0; i < bases.length; i++) { - IBinding T = bases[i].getBaseClass(); - if( T instanceof ICPPTemplateTypeParameter && argumentMap.containsKey( T ) ){ - IType t = (IType) argumentMap.get( T ); - if( t instanceof ICPPClassType ) - ((CPPBaseClause)bases[i]).setBaseClass( (ICPPClassType) argumentMap.get(T) ); + if( getDefinition() == null ){ + IASTNode node = (getDeclarations() != null && getDeclarations().length > 0) ? getDeclarations()[0] : null; + return new ICPPBase [] { new CPPBaseClause.CPPBaseProblem( node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ) }; + } + + ICPPASTBaseSpecifier[] bases = getCompositeTypeSpecifier().getBaseSpecifiers(); + if (bases.length == 0) + return ICPPBase.EMPTY_BASE_ARRAY; + + ICPPBase[] bindings = new ICPPBase[bases.length]; + for (int i = 0; i < bases.length; i++) { + bindings[i] = new CPPBaseClause(bases[i]); + IBinding base = bindings[i].getBaseClass(); + if (base instanceof IType) { + IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap); + if (specBase instanceof ICPPClassType) { + ((CPPBaseClause) bindings[i]).setBaseClass((ICPPClassType) specBase); } } - return bases; } - return ICPPBase.EMPTY_BASE_ARRAY; + return bindings; + } /* (non-Javadoc) @@ -119,8 +151,38 @@ public class CPPClassSpecialization extends CPPSpecialization implements * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getConstructors() */ public ICPPConstructor[] getConstructors() throws DOMException { - // TODO Auto-generated method stub - return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; + if( getDefinition() == null ){ + IASTNode node = (getDeclarations() != null && getDeclarations().length > 0) ? getDeclarations()[0] : null; + return new ICPPConstructor [] { new CPPConstructor.CPPConstructorProblem( node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ) }; + } + + IScope scope = getCompositeScope(); + if (scope instanceof CPPClassSpecializationScope) { + if (ASTInternal.isFullyCached(scope)) + return ((CPPClassSpecializationScope)scope).getConstructors(); + } + + if( ASTInternal.isFullyCached(scope)) + return ((CPPClassScope)scope).getConstructors( true ); + + IASTDeclaration [] members = getCompositeTypeSpecifier().getMembers(); + for( int i = 0; i < members.length; i++ ){ + IASTDeclaration decl = members[i]; + if( decl instanceof ICPPASTTemplateDeclaration ) + decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + if( decl instanceof IASTSimpleDeclaration ){ + IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); + for( int j = 0; j < dtors.length; j++ ){ + if( dtors[j] == null ) break; + ASTInternal.addName(scope, dtors[j].getName() ); + } + } else if( decl instanceof IASTFunctionDefinition ){ + IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator(); + ASTInternal.addName(scope, dtor.getName() ); + } + } + + return ((CPPClassScope)scope).getConstructors( true ); } /* (non-Javadoc) @@ -135,6 +197,9 @@ public class CPPClassSpecialization extends CPPSpecialization implements * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey() */ public int getKey() throws DOMException { + if (getDefinition() != null) + return getCompositeTypeSpecifier().getKey(); + return ((ICPPClassType)getSpecializedBinding()).getKey(); } @@ -142,15 +207,21 @@ public class CPPClassSpecialization extends CPPSpecialization implements * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope() */ public IScope getCompositeScope() throws DOMException { - IASTNode definition = getDefinition(); - if( definition != null ){ - IASTNode node = definition.getParent(); - while( node instanceof IASTName ) - node = node.getParent(); - if( node instanceof ICPPASTCompositeTypeSpecifier ) - return ((ICPPASTCompositeTypeSpecifier)node).getScope(); + if (specScope == null) { + ICPPClassScope scope = null; + if( getDefinition() != null ){ + scope = (ICPPClassScope) getCompositeTypeSpecifier().getScope(); + } + + if (scope != null && scope.getClassType() == this) { + //explicit specialization: can use composite type specifier scope + specScope = scope; + } else if (scope != null) { + //implicit specialization: must specialize bindings in scope + specScope = new CPPClassSpecializationScope(this); + } } - return ((ICPPClassType)getSpecializedBinding()).getCompositeScope(); + return specScope; } /* (non-Javadoc) @@ -164,8 +235,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName) */ public ICPPDelegate createDelegate(IASTName name) { - // TODO Auto-generated method stub - return null; + return new CPPClassType.CPPClassTypeDelegate( name, this ); } public Object clone() { @@ -174,8 +244,64 @@ public class CPPClassSpecialization extends CPPSpecialization implements } public ICPPMethod[] getConversionOperators() { - // TODO Auto-generated method stub - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + if( getDefinition() == null ){ + IASTNode node = (getDeclarations() != null && getDeclarations().length > 0) ? getDeclarations()[0] : null; + return new ICPPMethod[] { new CPPMethod.CPPMethodProblem( node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ) }; + } + try { + ICPPMethod [] result = null; + + IScope scope = getCompositeScope(); + if (scope instanceof CPPClassSpecializationScope) { + if (ASTInternal.isFullyCached(scope)) + result = ((CPPClassSpecializationScope)scope).getConversionOperators(); + } else { + IBinding binding = null; + + IASTDeclaration [] decls = getCompositeTypeSpecifier().getMembers(); + IASTName name = null; + for ( int i = 0; i < decls.length; i++ ) { + if( decls[i] instanceof IASTSimpleDeclaration ){ + IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decls[i]).getDeclarators(); + for ( int j = 0; j < dtors.length; j++ ) { + name = CPPVisitor.getMostNestedDeclarator( dtors[j] ).getName(); + if( name instanceof ICPPASTConversionName ){ + binding = name.resolveBinding(); + if( binding instanceof ICPPMethod) + result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding ); + } + } + } else if( decls[i] instanceof IASTFunctionDefinition ){ + IASTDeclarator dtor = ((IASTFunctionDefinition)decls[i]).getDeclarator(); + name = CPPVisitor.getMostNestedDeclarator( dtor ).getName(); + if( name instanceof ICPPASTConversionName ){ + binding = name.resolveBinding(); + if( binding instanceof ICPPMethod ){ + result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding ); + } + } + } + } + } + + ICPPBase [] bases = getBases(); + for ( int i = 0; i < bases.length; i++ ) { + ICPPClassType cls = null; + try { + IBinding b = bases[i].getBaseClass(); + if( b instanceof ICPPClassType ) + cls = (ICPPClassType) b; + } catch (DOMException e) { + continue; + } + if( cls instanceof ICPPInternalClassType ) + result = (ICPPMethod[]) ArrayUtil.addAll( ICPPMethod.class, result, ((ICPPInternalClassType)cls).getConversionOperators() ); + } + + return (ICPPMethod[]) ArrayUtil.trim( ICPPMethod.class, result ); + } catch (DOMException e) { + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } } public ICPPClassType[] getNestedClasses() throws DOMException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java similarity index 77% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java index f0d7899b063..26c9b6305a1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java @@ -22,13 +22,14 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -40,25 +41,32 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; /** * @author aniefer */ -public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope { +public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternalScope { private static final char[] CONSTRUCTOR_KEY = "!!!CTOR!!!".toCharArray(); //$NON-NLS-1$ private CharArrayObjectMap bindings; private ObjectMap instanceMap = ObjectMap.EMPTY_MAP; - private ICPPTemplateInstance instance; + private ICPPSpecialization specialization; private boolean isFullyCached = false; private boolean doneConstructors = false; /** * @param instance */ - public CPPClassInstanceScope(CPPClassInstance instance ) { - this.instance = instance; + public CPPClassSpecializationScope(CPPClassSpecialization specialization ) { + this.specialization = specialization; + } + + /** + * @param instance + */ + public CPPClassSpecializationScope(CPPClassInstance instance ) { + this.specialization = instance; } private ICPPClassType getOriginalClass(){ - return (ICPPClassType) instance.getTemplateDefinition(); + return (ICPPClassType) specialization.getSpecializedBinding(); } public boolean isFullyCached(){ if( !isFullyCached ){ @@ -76,8 +84,11 @@ public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope if( bindings == null ) return null; - if( CharArrayUtils.equals( c, instance.getNameCharArray() ) && CPPClassScope.isConstructorReference( name ) ){ - c = CONSTRUCTOR_KEY; + if( CharArrayUtils.equals( c, specialization.getNameCharArray() ) ){ + if (CPPClassScope.isConstructorReference( name )) + c = CONSTRUCTOR_KEY; + else + return specialization; } Object cache = bindings.get( c ); @@ -102,7 +113,7 @@ public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope binding = null; } if( binding != null ){ - binding = CPPTemplates.createSpecialization( this, binding, instance.getArgumentMap() ); + binding = CPPTemplates.createSpecialization( this, binding, specialization.getArgumentMap() ); if( instanceMap == ObjectMap.EMPTY_MAP ) instanceMap = new ObjectMap(2); instanceMap.put( n, binding ); @@ -112,7 +123,7 @@ public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope if( instanceMap.containsKey( obj ) ){ binding = (IBinding) instanceMap.get( obj ); } else { - binding = CPPTemplates.createSpecialization( this, (IBinding) obj, instance.getArgumentMap() ); + binding = CPPTemplates.createSpecialization( this, (IBinding) obj, specialization.getArgumentMap() ); if( instanceMap == ObjectMap.EMPTY_MAP ) instanceMap = new ObjectMap(2); instanceMap.put( obj, binding ); @@ -142,7 +153,7 @@ public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope#getClassType() */ public ICPPClassType getClassType() { - return (ICPPClassType) instance; + return (ICPPClassType) specialization; } /* (non-Javadoc) @@ -157,7 +168,7 @@ public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getScopeName() */ public IName getScopeName() { - return (IASTName) ((ICPPInternalBinding)instance).getDefinition(); + return (IASTName) ((ICPPInternalBinding)specialization).getDefinition(); } public void addName(IASTName name) { @@ -194,7 +205,7 @@ public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope if( !doneConstructors ){ ICPPConstructor[] ctors; try { - ctors = ((ICPPClassType)instance.getTemplateDefinition()).getConstructors(); + ctors = ((ICPPClassType)specialization.getSpecializedBinding()).getConstructors(); for (int i = 0; i < ctors.length; i++) { addBinding( ctors[i] ); } @@ -207,7 +218,7 @@ public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope if( instanceMap.containsKey( ctors[i] ) ){ ctors[i] = (ICPPConstructor) instanceMap.get( ctors[i] ); } else { - IBinding b = CPPTemplates.createSpecialization( this, ctors[i], instance.getArgumentMap() ); + IBinding b = CPPTemplates.createSpecialization( this, ctors[i], specialization.getArgumentMap() ); if( instanceMap == ObjectMap.EMPTY_MAP ) instanceMap = new ObjectMap(2); instanceMap.put( ctors[i], b ); @@ -217,6 +228,55 @@ public class CPPClassInstanceScope implements ICPPClassScope, IASTInternalScope return ctors; } + protected ICPPMethod[] getConversionOperators() { + if( bindings == null ) + return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; + + ICPPMethod [] result = null; + + Object[] values = bindings.valueArray(); + for (int i = 0; i < values.length; i++) { + int j = ( values[i] instanceof ObjectSet ) ? 0 : -1; + ObjectSet set = ( values[i] instanceof ObjectSet ) ? (ObjectSet) values[i] : null; + Object obj = ( set != null ) ? set.keyAt( j ) : values[i]; + IBinding binding = null; + while( obj != null ){ + if( obj instanceof IASTName ){ + IASTName n = (IASTName) obj; + if( n instanceof ICPPASTQualifiedName ){ + IASTName [] ns = ((ICPPASTQualifiedName)n).getNames(); + n = ns[ ns.length - 1 ]; + } + + if (n instanceof ICPPASTConversionName) { + if( instanceMap.containsKey( n ) ){ + binding = (IBinding) instanceMap.get( n ); + } else { + binding = n.resolveBinding(); + if( binding != null ){ + binding = CPPTemplates.createSpecialization( this, binding, specialization.getArgumentMap() ); + if( instanceMap == ObjectMap.EMPTY_MAP ) + instanceMap = new ObjectMap(2); + instanceMap.put( n, binding ); + } + } + } + } + if( binding != null ){ + result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding ); + binding = null; + } + if( j != -1 && ++j < set.size() ){ + obj = set.keyAt( j ); + } else { + obj = null; + } + } + } + + return (ICPPMethod[]) ArrayUtil.trim( ICPPMethod.class, result ); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#setFullyCached(boolean) */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java index fadf9736017..4bda14bea14 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java @@ -7,7 +7,7 @@ * * Contributors: * IBM - Initial API and implementation - * / + * Bryan Wilkinson (QNX) *******************************************************************************/ /* * Created on May 2, 2005 @@ -24,7 +24,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; -import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ObjectMap; /** @@ -35,7 +34,6 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization implements ICPPClassTemplate, ICPPInternalClassTemplate { private ObjectMap instances = null; - private ICPPClassTemplatePartialSpecialization [] partialSpecializations = null; /** * @param specialized @@ -50,12 +48,10 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate#getPartialSpecializations() */ - public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { - partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.trim( ICPPClassTemplatePartialSpecialization.class, partialSpecializations ); - return partialSpecializations; + public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException { + return ((ICPPClassTemplate) getSpecializedBinding()).getPartialSpecializations(); } - /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition#getTemplateParameters() */ @@ -119,6 +115,6 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization } public void addPartialSpecialization( ICPPClassTemplatePartialSpecialization spec ){ - partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.append( ICPPClassTemplatePartialSpecialization.class, partialSpecializations, spec ); + //should not occur } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index 5e04791ab03..8346c1f07e9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -39,7 +39,7 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexLinkage; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassInstanceScope; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecializationScope; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.composite.CompositeScope; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -158,23 +158,15 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage return null; } - public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { - PDOMNode node; - + public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { if (type instanceof IPointerType) - node = new PDOMPointerType(pdom, parent, (IPointerType)type); + return new PDOMPointerType(pdom, parent, (IPointerType)type); else if (type instanceof IArrayType) - node= new PDOMArrayType(pdom, parent, (IArrayType) type); + return new PDOMArrayType(pdom, parent, (IArrayType) type); else if (type instanceof IQualifierType) - node = new PDOMQualifierType(pdom, parent, (IQualifierType)type); + return new PDOMQualifierType(pdom, parent, (IQualifierType)type); else - node = null; - - if(node!=null) { - parent.addChild(node); - } - - return node; + return null; } public abstract IBTreeComparator getIndexComparator(); @@ -254,8 +246,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } else { IBinding scopeBinding = null; - if (scope instanceof CPPClassInstanceScope) { - scopeBinding = ((CPPClassInstanceScope)scope).getClassType(); + if (scope instanceof CPPClassSpecializationScope) { + scopeBinding = ((CPPClassSpecializationScope)scope).getClassType(); } else { IName scopeName = scope.getScopeName(); if (scopeName instanceof IASTName) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index 8d11e780c24..2ea7436436e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -54,7 +54,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassInstanceScope; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; @@ -243,7 +243,7 @@ class PDOMCPPLinkage extends PDOMLinkage { } else if (binding instanceof ICPPSpecialization) { try { IScope scope = binding.getScope(); - if (scope instanceof CPPClassInstanceScope) + if (scope instanceof CPPClassSpecializationScope) return true; } catch (DOMException e) { } @@ -284,7 +284,7 @@ class PDOMCPPLinkage extends PDOMLinkage { pdomBinding = new PDOMCPPClassTemplatePartialSpecialization( pdom, parent, (ICPPClassTemplatePartialSpecialization) binding, - (PDOMCPPClassTemplate) pdomSpecialized); + pdomSpecialized); } else if (binding instanceof ICPPField && pdomSpecialized instanceof PDOMCPPField) { pdomBinding = new PDOMCPPFieldSpecialization(pdom, parent, (ICPPField) binding, (PDOMCPPField) pdomSpecialized); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java index bd319c90542..03604ca1270 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IndexLabelProvider.java @@ -10,6 +10,7 @@ * Markus Schorn (Wind River Systems) * IBM Corporation * Andrew Ferguson (Symbian) + * Bryan Wilkinson (QNX) *******************************************************************************/ package org.eclipse.cdt.internal.ui; @@ -33,8 +34,10 @@ import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICProject; @@ -98,6 +101,8 @@ public class IndexLabelProvider extends LabelProvider { PDOMNode parent = ((PDOMNode)element).getParentNode(); PDOMNode grandParent = parent != null ? parent.getParentNode() : null; boolean showArgs = parentOfSpec == null || grandParent == null || !parentOfSpec.equals(grandParent); + showArgs = showArgs && ((element instanceof ICPPClassType || element instanceof ICPPFunction) + && !(element instanceof ICPPTemplateDefinition)); StringBuffer buffer = null; buffer = new StringBuffer("Spec: "); //$NON-NLS-1$ diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java index 8612c258d53..9698797116b 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java @@ -84,18 +84,28 @@ public class CMainTab extends CLaunchConfigurationTab { private final boolean fWantsTerminalOption; protected Button fTerminalButton; + private final boolean dontCheckProgram; + protected static final String EMPTY_STRING = ""; //$NON-NLS-1$ private String filterPlatform = EMPTY_STRING; + public static final int WANTS_TERMINAL = 1; + public static final int DONT_CHECK_PROGRAM = 2; + public CMainTab() { - this(false); + this(0); } public CMainTab(boolean terminalOption) { - fWantsTerminalOption = terminalOption; + this(terminalOption ? WANTS_TERMINAL : 0); } + public CMainTab(int flags) { + fWantsTerminalOption = (flags & WANTS_TERMINAL) != 0; + dontCheckProgram = (flags & DONT_CHECK_PROGRAM) != 0; + } + /* * (non-Javadoc) * @@ -176,7 +186,6 @@ public class CMainTab extends CLaunchConfigurationTab { gd = new GridData(GridData.FILL_HORIZONTAL); fProgText.setLayoutData(gd); fProgText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent evt) { updateLaunchConfigurationDialog(); } @@ -184,7 +193,6 @@ public class CMainTab extends CLaunchConfigurationTab { fSearchButton = createPushButton(mainComp, LaunchMessages.getString("CMainTab.Search..."), null); //$NON-NLS-1$ fSearchButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent evt) { handleSearchButtonSelected(); updateLaunchConfigurationDialog(); @@ -194,7 +202,6 @@ public class CMainTab extends CLaunchConfigurationTab { Button fBrowseForBinaryButton; fBrowseForBinaryButton = createPushButton(mainComp, LaunchMessages.getString("Launch.common.Browse_2"), null); //$NON-NLS-1$ fBrowseForBinaryButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent evt) { handleBinaryBrowseButtonSelected(); updateLaunchConfigurationDialog(); @@ -512,38 +519,40 @@ public class CMainTab extends CLaunchConfigurationTab { return false; } - name = fProgText.getText().trim(); - if (name.length() == 0) { - setErrorMessage(LaunchMessages.getString("CMainTab.Program_not_specified")); //$NON-NLS-1$ - return false; - } - if (name.equals(".") || name.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$ - setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$ - return false; - } - IPath exePath = new Path(name); - if (!exePath.isAbsolute()) { - if (!project.getFile(name).exists()) { + if (!dontCheckProgram) { + name = fProgText.getText().trim(); + if (name.length() == 0) { + setErrorMessage(LaunchMessages.getString("CMainTab.Program_not_specified")); //$NON-NLS-1$ + return false; + } + if (name.equals(".") || name.equals("..")) { //$NON-NLS-1$ //$NON-NLS-2$ setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$ return false; } - exePath = project.getFile(name).getLocation(); - } else { - if (!exePath.toFile().exists()) { - setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$ + IPath exePath = new Path(name); + if (!exePath.isAbsolute()) { + if (!project.getFile(name).exists()) { + setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$ + return false; + } + exePath = project.getFile(name).getLocation(); + } else { + if (!exePath.toFile().exists()) { + setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); //$NON-NLS-1$ + return false; + } + } + try { + if (!isBinary(project, exePath)) { + setErrorMessage(LaunchMessages.getString("CMainTab.Program_is_not_a_recongnized_executable")); //$NON-NLS-1$ + return false; + } + } catch (CoreException e) { + LaunchUIPlugin.log(e); + setErrorMessage(e.getLocalizedMessage()); return false; } } - try { - if (!isBinary(project, exePath)) { - setErrorMessage(LaunchMessages.getString("CMainTab.Program_is_not_a_recongnized_executable")); //$NON-NLS-1$ - return false; - } - } catch (CoreException e) { - LaunchUIPlugin.log(e); - setErrorMessage(e.getLocalizedMessage()); - return false; - } return true; }