Information for those who would like to use Clang for codecompletion and code indexer.
There are two ways:
1, using the clang from the command line. this is currently done in vim, Emacs, codelite by calling the clang.exe from command line.
2, directly link to the libraries supplied by libclang. this is done only in Apples Xcode, but it is suggest the better way. You can take the file:
\llvm\tools\clang\tools\c-index-test\c-index-test.c
, this file contains all the information you need.
BTW: to build a release version of clang, the options can be found here:
How To Release LLVM To The PublicBuilding the Release
The build of llvm, llvm-gcc, and clang must be free of errors and warnings in both debug, release+asserts, and release builds. If all builds are clean, then the release passes build qualification.
1. debug: ENABLE_OPTIMIZED=0
2. release+asserts: ENABLE_OPTIMIZED=1
3. release: ENABLE_OPTIMIZED=1 DISABLE_ASSERTIONS=1
Edit:The common feature like "find the definition of a function" or "find the reference" can be found there:
The Index Librarysee below:
index-test tool
Usage
A command-line tool that exercises the libIndex API, useful for testing its features. As input it accepts multiple AST files (representing multiple translation units) and a few options:
-point-at [file:line:column]
Resolves a [file:line:column] triplet into a ASTLocation from the first AST file. If no other option is specified, it prints the ASTLocation. It also prints a declaration's associated doxygen comment, if one is available.
-print-refs
Prints the ASTLocations that reference the declaration that was resolved out of the [file:line:column] triplet
-print-defs
Prints the ASTLocations that define the resolved declaration
-print-decls
Prints the ASTLocations that declare the resolved declaration
Examples
Here's an example of using index-test:
We have 3 files,
foo.h:
extern int global_var;
void foo_func(int param1);
void bar_func(void);
t1.c:
#include "foo.h"
void foo_func(int param1) {
int local_var = global_var;
for (int for_var = 100; for_var < 500; ++for_var) {
local_var = param1 + for_var;
}
bar_func();
}
t2.c:
#include "foo.h"
int global_var = 10;
void bar_func(void) {
global_var += 100;
foo_func(global_var);
}
You first get AST files out of t1.c and t2.c:
$ clang -emit-ast t1.c -o t1.ast
$ clang -emit-ast t2.c -o t2.ast
Find the ASTLocation under this position of t1.c:
[...]
void foo_func(int param1) {
int local_var = global_var;
^
[...]
$ index-test t1.ast -point-at t1.c:4:23
> [Decl: Var local_var | Stmt: DeclRefExpr global_var] <t1.c:4:19, t1.c:4:19>
Find the declaration:
$ index-test t1.ast -point-at t1.c:4:23 -print-decls
> [Decl: Var global_var] <foo.h:1:12, foo.h:1:12>
Find the references:
$ index-test t1.ast t2.ast -point-at t1.c:4:23 -print-refs
> [Decl: Var local_var | Stmt: DeclRefExpr global_var] <t1.c:4:19, t1.c:4:19>
> [Decl: Function bar_func | Stmt: DeclRefExpr global_var] <t2.c:6:3, t2.c:6:3>
> [Decl: Function bar_func | Stmt: DeclRefExpr global_var] <t2.c:7:12, t2.c:7:12>
Find definitions:
$ index-test t1.ast t2.ast -point-at t1.c:4:23 -print-defs
> [Decl: Var global_var] <t2.c:3:5, t2.c:3:18>
All the features was done in the code:
\llvm\tools\clang\tools\c-index-test\c-index-test.c
This is quite GOOD for an IDE!!!!
