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

Fixes a CCE, bug 203967.

This commit is contained in:
Markus Schorn 2008-04-16 16:32:52 +00:00
parent b7afd7af2c
commit b3256c51da
3 changed files with 63 additions and 62 deletions

View file

@ -50,8 +50,8 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
//first check if we already know it
if( declarations != null ){
for( int i = 0; i < declarations.length; i++ ){
IASTNode parent = declarations[i].getParent();
for (IASTName declaration : declarations) {
IASTNode parent = declaration.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
@ -69,17 +69,17 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
ICPPClassScope clsScope = (ICPPClassScope) scope;
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(clsScope);
IASTDeclaration [] members = compSpec.getMembers();
for( int i = 0; i < members.length; i++ ){
if( members[i] instanceof ICPPASTTemplateDeclaration ){
IASTDeclaration decl = ((ICPPASTTemplateDeclaration)members[i]).getDeclaration();
for (IASTDeclaration member : members) {
if( member instanceof ICPPASTTemplateDeclaration ){
IASTDeclaration decl = ((ICPPASTTemplateDeclaration)member).getDeclaration();
if( decl instanceof IASTSimpleDeclaration ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
for( int j = 0; j < dtors.length; j++ ){
IASTName name = CPPVisitor.getMostNestedDeclarator( dtors[j] ).getName();
for (IASTDeclarator dtor : dtors) {
IASTName name = CPPVisitor.getMostNestedDeclarator( dtor ).getName();
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
return members[i];
return member;
}
}
} else if( decl instanceof IASTFunctionDefinition ){
@ -87,7 +87,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
return members[i];
return member;
}
}
}
@ -99,23 +99,19 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
public int getVisibility() throws DOMException {
IASTDeclaration decl = getPrimaryDeclaration();
if( decl == null ){
IScope scope = getScope();
if( scope instanceof ICPPTemplateScope)
scope = scope.getParent();
if( scope instanceof ICPPClassScope ){
ICPPClassType cls = ((ICPPClassScope)scope).getClassType();
if( cls != null )
return ( cls.getKey() == ICPPClassType.k_class ) ? ICPPASTVisiblityLabel.v_private : ICPPASTVisiblityLabel.v_public;
ICPPClassType cls = getClassOwner();
if (cls != null) {
return ( cls.getKey() == ICPPClassType.k_class ) ? ICPPASTVisiblityLabel.v_private : ICPPASTVisiblityLabel.v_public;
}
return ICPPASTVisiblityLabel.v_private;
}
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
IASTDeclaration [] members = cls.getMembers();
ICPPASTVisiblityLabel vis = null;
for( int i = 0; i < members.length; i++ ){
if( members[i] instanceof ICPPASTVisiblityLabel )
vis = (ICPPASTVisiblityLabel) members[i];
else if( members[i] == decl )
for (IASTDeclaration member : members) {
if( member instanceof ICPPASTVisiblityLabel )
vis = (ICPPASTVisiblityLabel) member;
else if( member == decl )
break;
}
if( vis != null ){
@ -127,8 +123,14 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
}
public ICPPClassType getClassOwner() throws DOMException {
ICPPClassScope scope = (ICPPClassScope)getScope();
return scope.getClassType();
IScope scope= getScope();
while (scope instanceof ICPPTemplateScope) {
scope= scope.getParent();
}
if( scope instanceof ICPPClassScope ){
return ((ICPPClassScope)scope).getClassType();
}
return null;
}
public boolean isVirtual() {

View file

@ -70,6 +70,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
openCallHierarchy(editor);
Tree tree = getCHTreeViewer().getTree();
checkTreeNode(tree, 0, "proto()");
expandTreeItem(tree, 0);
checkTreeNode(tree, 0, 0, "main()");
editor.selectAndReveal(content.indexOf("func"), 2);

View file

@ -64,8 +64,8 @@ public class CHQueries {
if (calleeBinding != null) {
findCalledBy(index, calleeBinding, true, project, result);
IBinding[] overriddenBindings= getOverriddenBindings(index, calleeBinding);
for (int i = 0; i < overriddenBindings.length; i++) {
findCalledBy(index, overriddenBindings[i], false, project, result);
for (IBinding overriddenBinding : overriddenBindings) {
findCalledBy(index, overriddenBinding, false, project, result);
}
}
return cp.createNodes(node, result);
@ -78,20 +78,21 @@ public class CHQueries {
final ICPPMethod m= (ICPPMethod) binding;
final char[] mname= m.getNameCharArray();
final ICPPClassType mcl= m.getClassOwner();
final IFunctionType mft= m.getType();
boolean isVirtual= m.isVirtual();
ICPPMethod[] allMethods= mcl.getMethods();
for (int i = 0; i < allMethods.length; i++) {
ICPPMethod method = allMethods[i];
if (CharArrayUtils.equals(mname, method.getNameCharArray()) && !mcl.isSameType(method.getClassOwner())) {
if (mft.isSameType(method.getType())) {
isVirtual= isVirtual || method.isVirtual();
result.add(method);
if (mcl != null) {
final IFunctionType mft= m.getType();
boolean isVirtual= m.isVirtual();
ICPPMethod[] allMethods= mcl.getMethods();
for (ICPPMethod method : allMethods) {
if (CharArrayUtils.equals(mname, method.getNameCharArray()) && !mcl.isSameType(method.getClassOwner())) {
if (mft.isSameType(method.getType())) {
isVirtual= isVirtual || method.isVirtual();
result.add(method);
}
}
}
}
if (isVirtual) {
return result.toArray(new IBinding[result.size()]);
if (isVirtual) {
return result.toArray(new IBinding[result.size()]);
}
}
} catch (DOMException e) {
// index bindings don't throw DOMExceptions
@ -108,20 +109,20 @@ public class CHQueries {
final ArrayList<ICPPMethod> result= new ArrayList<ICPPMethod>();
final char[] mname= m.getNameCharArray();
final ICPPClassType mcl= m.getClassOwner();
final IFunctionType mft= m.getType();
ICPPClassType[] subclasses= getSubClasses(index, mcl);
for (int i = 0; i < subclasses.length; i++) {
ICPPClassType subClass = subclasses[i];
ICPPMethod[] methods= subClass.getDeclaredMethods();
for (int j = 0; j < methods.length; j++) {
ICPPMethod method = methods[j];
if (CharArrayUtils.equals(mname, method.getNameCharArray()) &&
mft.isSameType(method.getType())) {
result.add(method);
if (mcl != null) {
final IFunctionType mft= m.getType();
ICPPClassType[] subclasses= getSubClasses(index, mcl);
for (ICPPClassType subClass : subclasses) {
ICPPMethod[] methods= subClass.getDeclaredMethods();
for (ICPPMethod method : methods) {
if (CharArrayUtils.equals(mname, method.getNameCharArray()) &&
mft.isSameType(method.getType())) {
result.add(method);
}
}
}
return result.toArray(new IBinding[result.size()]);
}
return result.toArray(new IBinding[result.size()]);
}
} catch (DOMException e) {
// index bindings don't throw DOMExceptions
@ -153,8 +154,7 @@ public class CHQueries {
}
IIndexName[] names= index.findNames(classOrTypedef, IIndex.FIND_REFERENCES | IIndex.FIND_DEFINITIONS);
for (int i = 0; i < names.length; i++) {
IIndexName indexName = names[i];
for (IIndexName indexName : names) {
if (indexName.isBaseSpecifier()) {
IIndexName subClassDef= indexName.getEnclosingDefinition();
if (subClassDef != null) {
@ -174,13 +174,14 @@ public class CHQueries {
}
final char[] mname= m.getNameCharArray();
final ICPPClassType mcl= m.getClassOwner();
final IFunctionType mft= m.getType();
ICPPMethod[] allMethods= mcl.getMethods();
for (int i = 0; i < allMethods.length; i++) {
ICPPMethod method = allMethods[i];
if (CharArrayUtils.equals(mname, method.getNameCharArray()) && mft.isSameType(method.getType())) {
if (method.isVirtual()) {
return true;
if (mcl != null) {
final IFunctionType mft= m.getType();
ICPPMethod[] allMethods= mcl.getMethods();
for (ICPPMethod method : allMethods) {
if (CharArrayUtils.equals(mname, method.getNameCharArray()) && mft.isSameType(method.getType())) {
if (method.isVirtual()) {
return true;
}
}
}
}
@ -193,8 +194,7 @@ public class CHQueries {
private static void findCalledBy(IIndex index, IBinding callee, boolean includeOrdinaryCalls, ICProject project, CalledByResult result)
throws CoreException {
IIndexName[] names= index.findNames(callee, IIndex.FIND_REFERENCES | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
for (int i = 0; i < names.length; i++) {
IIndexName rname = names[i];
for (IIndexName rname : names) {
if (includeOrdinaryCalls || rname.couldBePolymorphicMethodCall()) {
IIndexName caller= rname.getEnclosingDefinition();
if (caller != null) {
@ -217,8 +217,7 @@ public class CHQueries {
IIndexName callerName= IndexUI.elementToName(index, caller);
if (callerName != null) {
IIndexName[] refs= callerName.getEnclosedNames();
for (int i = 0; i < refs.length; i++) {
IIndexName name = refs[i];
for (IIndexName name : refs) {
IBinding binding= index.findBinding(name);
if (CallHierarchyUI.isRelevantForCallHierarchy(binding)) {
IBinding[] virtualOverriders= getOverridingBindings(index, binding);
@ -229,8 +228,7 @@ public class CHQueries {
else {
ArrayList<ICElementHandle> list= new ArrayList<ICElementHandle>();
list.addAll(Arrays.asList(IndexUI.findRepresentative(index, binding)));
for (int j = 0; j < virtualOverriders.length; j++) {
IBinding overrider = virtualOverriders[j];
for (IBinding overrider : virtualOverriders) {
list.addAll(Arrays.asList(IndexUI.findRepresentative(index, overrider)));
}
defs= list.toArray(new ICElement[list.size()]);