Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 183973 - CDT C++ Project does not allow to navigate from C function declaration to implementation
Summary: CDT C++ Project does not allow to navigate from C function declaration to imp...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 4.0 RC2   Edit
Assignee: Markus Schorn CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-25 08:21 EDT by Walter Brunauer CLA
Modified: 2007-06-05 02:53 EDT (History)
2 users (show)

See Also:


Attachments
CDT C++ Project (8.30 KB, application/zip)
2007-04-25 08:22 EDT, Walter Brunauer CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Walter Brunauer CLA 2007-04-25 08:21:50 EDT
Attached simple CDT C++ project shows, that if you try to navigate back and forth between the C function declaration and implementation using F3, it does only work from the .c file to the .h file, but not the other direction.

For the C++ part, this works.
Comment 1 Walter Brunauer CLA 2007-04-25 08:22:25 EDT
Created attachment 64859 [details]
CDT C++ Project
Comment 2 Ravi Sankar CLA 2007-05-16 01:47:33 EDT
Hi,
This is not a issue in a C project which has all .c and .h files. 
This is a issue only in C++ projects containing .c files. The reason is PDOMCPPFunction is the binding given to function declarations in all .h files
( ieven if there is a corresponding .c file with same name). In such cases search in the index is returning null. Hence F3 is not working from .h to .c file but it works fine the otherway. 


Ravi
Comment 3 Markus Schorn CLA 2007-05-23 10:44:57 EDT
The underlying issue of this bug is that the AST computed for a header file does not use the language and scanner configuration of the source-file that includes the header. This is different to what we do in the indexer. There, headers are parsed in the context of a source file, if possible.

The benefit of solving the more general issue is that all clients of the AST would work in the correct language (Content Assist, Open Call Hierarchy, Open Type Hierarchy and others).

To make this happen, we have to change the way ITranslationUnit.getAST(..) and ITranslationUnit.getLanguage(..) work for header files.

Comment 4 Doug Schaefer CLA 2007-05-23 11:34:52 EDT
(In reply to comment #3)
> To make this happen, we have to change the way ITranslationUnit.getAST(..) and
> ITranslationUnit.getLanguage(..) work for header files.

There was a time when we used the project nature for that. I guess that's gone now...
Comment 5 Markus Schorn CLA 2007-05-24 03:31:34 EDT
(In reply to comment #4)
> (In reply to comment #3)
> > To make this happen, we have to change the way ITranslationUnit.getAST(..) and
> > ITranslationUnit.getLanguage(..) work for header files.
> There was a time when we used the project nature for that. I guess that's gone
> now...

That is still working. As stated in comment 2, we only have a problem if there is header file included by a plain-c source-file in a C++-project. The source file is parsed as plain-c. The indexer parses the header in the context of the source file, thus treats is as a plain-C file. However when the header is parsed as a translation unit on its own, it is treated as C++-file.
Comment 6 Markus Schorn CLA 2007-05-24 05:34:37 EDT
Added testcase:
CPPSelectionTestsAnyIndexer.testCNavigationInCppProject_bug183973()

I'll add an additional option that can be used with ITranslationUnit.getAST(...). With that other AST-clients are not affected. 

There is no immediate need to change ITranslationUnit.getLanguage(). The editor will use C++-syntax highlighting for the plain-c header file, which is usually not a problem.
Comment 7 Markus Schorn CLA 2007-05-24 08:37:02 EDT
Fixed as proposed in comment 6.
Comment 8 Doug Schaefer CLA 2007-05-24 10:02:34 EDT
(In reply to comment #5)
> That is still working. As stated in comment 2, we only have a problem if there
> is header file included by a plain-c source-file in a C++-project. The source
> file is parsed as plain-c. The indexer parses the header in the context of the
> source file, thus treats is as a plain-C file. However when the header is
> parsed as a translation unit on its own, it is treated as C++-file.

I guess my point is that C functions, which would be C functions to be parsed properly by a plain C file, should be stored that way in the index. Any references to them from C++ files should link to the those CFunctions.

I think this is a fundamental capability that we're missing from the DOM and it should really should start with how we handle extern "C". Even tougher would be cases like Ada or Fortran that can also link to C functions. Ideally we'd like open declaration to work properly there too (i.e. find the function definition in a C file, or an extern "C" function in a C++ file).
Comment 9 Markus Schorn CLA 2007-05-24 10:32:51 EDT
(In reply to comment #8)
Ok, I see, at this point we don't handle references accross languages. That's a different problem, though.