| Summary: | error of "Open declaration" : find declaration of function goes wrong | ||
|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | jin huang <derick0320> |
| Component: | cdt-core | Assignee: | Project Inbox <cdt-core-inbox> |
| Status: | RESOLVED INVALID | QA Contact: | Doug Schaefer <cdtdoug> |
| Severity: | major | ||
| Priority: | P3 | ||
| Version: | 7.0.2 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
The tooling is correct 'methodA' resolves to the local variable and the code does not compile because you cannot use it as a function. Also, the search for references of 'methodA' does report the reference in 'method42'. yes, you are right. In a function, the function can not have the same name with a local variable. Just the CDT do not give any tips!! Thanks a lot for your explanation. Even though the program to be analyzed is supposed to be correct, the declaration from "Open declaration" is still be misleading. so I still think that CDT does not give the right tips for its users. No it's not misleading, 'methodA' does denote the local variable and open declaration has to go there. This also gives you the chance to correct your code. |
Build Identifier: eclipse 3.6.0 In a function of c code, when local variable has the same name as another function A called in this function, if we check the method A's declaration by clicking "Open declaration", it show the declaration of the local variable, but not the declaration of function A. Reproducible: Always Steps to Reproduce: when we have the follow source code, in which a local variable has the same name as a function called, ---------------------------------- 1 int methodA(int a, int b){ 2 return a+b; 3 } 4 5 6 int method41(int a, int b){ 7 int methodA = 2; 8 return methodA(a,b); 9 } 10 11 int method42(int a, int b){ 12 return methodA(a,b); 13 } ---------------------------------- if we right click on the function reference "methodA(...)" in line 8, and click "Open declaration" to get its declaration, eclipse will show you the declaration "int methodA = 2" in line 7, which is a error. Then, I use eclipse's "c/c++ search" function 1)search string: "methodA*" 2)search for: Function 3)limitedto: references But I got nothing !! Finally, I download the source code of CDT from svn, write programs as below to get callers of function with name "methodA", I still just got one function reference from function "method42". The function "method41" is missing. ---------------------------------- public void doAnalysis(){ //search callers in each project for(int i=0;i<scope.length;++i){ try { IIndex index = CCorePlugin.getIndexManager().getIndex((ICProject)scope[i], IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT); index.acquireReadLock(); try { IIndexBinding[] callees= index.findBindings(calleeName.toCharArray(), IndexFilter.ALL_DECLARED, new NullProgressMonitor()); // find references for each binding of callee for (IIndexBinding callee : callees) { if (callee instanceof IFunction) { getCallers((ICProject)scope[i], index, callee); } }//for } finally { index.releaseReadLock(); } } catch (InterruptedException e) {} catch (CoreException e) {} System.out.print("End of seach in project : "+ i+ ((ICProject)scope[i]).getElementName() +"\n"); }//for System.out.print("number of callers is : "+this.result.getElements().length+"\n"); }//doAnalysis() void getCallers(ICProject project, IIndex index, IIndexBinding callee) throws CoreException { IIndexName[] callers = index.findReferences(callee); for (int i = 0; i < callers.length; i++) { IIndexName rname = callers[i]; IIndexName caller = rname.getEnclosingDefinition(); if (caller != null) { ICElement elem = IndexUI.getCElementForName(project, index, caller); if (elem != null) { result.add(elem, rname); } } }//for }//getCallers() ----------------------------------