Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign

Clang command line support for codecompletion

<< < (6/6)

ollydbg:
I have successfully build the clang under msys/mingw with some clang maillist guy's help.



The problem:


--- Quote from: ollydbg on October 26, 2010, 10:45:15 am ---updated:

Today, I have tried the method listed in
http://clang.llvm.org/get_started.html

to build a clang.exe, but no luck, all failed  :( :( :(.

1, one failed method.
under Msys mingw, check out the llvm and clang svn code, and configure. make. but the error occurred when I run the make,  such as:

--- Quote ---$ make
Makefile:130: /Makefile.rules: No such file or directory
make: *** No rule to make target `/Makefile.rules'.  Stop.


--- End quote ---

--- End quote ---

Was solved because I have made a big mistake.

There are two kind of make.exe. One is under mingw/bin, the other is under msys/bin
The error caused because msys use the make.exe under mingw/bin. this was totally wrong, we should use make.exe under msys/bin.
So, you should delete make.exe under mingw/bin or rename it.

The final report:
it takes one hour to compile the total target..( too long..)
it seem the total build file was quite large : 3.5G !!!

and the folder \build\Debug+Asserts is 2.5G.
especially, under the folder: \build\Debug+Asserts\bin

clang++.exe   430M
clang.exe       430M
llc.exe             170M
....

striping the clang++.exe will reduce its size to 21M.

Testing the code-completion feature works fine!!!

infinigon:

--- Quote from: ollydbg on November 05, 2010, 08:00:38 am ---
it seem the total build file was quite large : 3.5G !!!

and the folder \build\Debug+Asserts is 2.5G.
especially, under the folder: \build\Debug+Asserts\bin

clang++.exe   430M
clang.exe       430M
llc.exe             170M
....

striping the clang++.exe will reduce its size to 21M.

--- End quote ---

According to http://llvm.org/docs/MakefileGuide.html#variables you can set ENABLE_OPTIMIZED=1 when make'ing in order to disable debugging symbols and enable optimization (should have no need to strip after this, and clang runs much faster). Also, AFAIK clang.exe and clang++.exe are exactly the same - you only need one copy of it.

Also I tried building clang, but did not realise until too late that if using MSVC to build, then clang would be configured to use the MSVC headers, which it cannot parse. Now I am also trying to build it with MinGW...

ollydbg:

--- Quote from: infinigon on November 06, 2010, 01:32:20 pm ---
--- Quote from: ollydbg on November 05, 2010, 08:00:38 am ---
it seem the total build file was quite large : 3.5G !!!

and the folder \build\Debug+Asserts is 2.5G.
especially, under the folder: \build\Debug+Asserts\bin

clang++.exe   430M
clang.exe       430M
llc.exe             170M
....

striping the clang++.exe will reduce its size to 21M.

--- End quote ---

According to http://llvm.org/docs/MakefileGuide.html#variables you can set ENABLE_OPTIMIZED=1 when make'ing in order to disable debugging symbols and enable optimization (should have no need to strip after this, and clang runs much faster). Also, AFAIK clang.exe and clang++.exe are exactly the same - you only need one copy of it.

Also I tried building clang, but did not realise until too late that if using MSVC to build, then clang would be configured to use the MSVC headers, which it cannot parse. Now I am also trying to build it with MinGW...

--- End quote ---

Hi, thanks for your help. I will try to build a ENABLE_OPTIMIZED=1 version if I have free time.
 currently, not sure how "easy/difficult" to add the clang to codecompletion plugin. or making another codecompletion plugin(difficult too).

ollydbg:
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:

--- Code: ---\llvm\tools\clang\tools\c-index-test\c-index-test.c
--- End code ---
, 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 Public

--- Code: ---Building 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

--- End code ---


Edit:
The common feature like "find the definition of a function" or "find the reference" can be found there:
The Index Library
see below:

--- Quote ---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>


--- End quote ---

All the features was done in the code:

--- Code: ---\llvm\tools\clang\tools\c-index-test\c-index-test.c
--- End code ---

This is quite GOOD for an IDE!!!! :D :D :D

ollydbg:

--- Quote from: eranif on October 26, 2010, 03:38:46 pm ---It also lacks some crucial information (which I could not seem to get an access to, like an exact position of the match), I can probably obtain more information if I will link directly with the clang libraries - but for the POC (prove of concept) it seems too much for me.

--- End quote ---
Hi, eranif, I have just dig into the libclang, especially the c-index-test.c file to see if is fit your desire.

From the latest svn code of clang and llvm, I found that:

F:\llvm_build\llvm\tools\clang\include\clang-c\Index.h


--- Code: ---/**
 * \brief A single result of code completion.
 */
typedef struct {
  /**
   * \brief The kind of entity that this completion refers to.
   *
   * The cursor kind will be a macro, keyword, or a declaration (one of the
   * *Decl cursor kinds), describing the entity that the completion is
   * referring to.
   *
   * \todo In the future, we would like to provide a full cursor, to allow
   * the client to extract additional information from declaration.
   */
  enum CXCursorKind CursorKind;

  /**
   * \brief The code-completion string that describes how to insert this
   * code-completion result into the editing buffer.
   */
  CXCompletionString CompletionString;
} CXCompletionResult;

--- End code ---

You can see, the code completion  result (one entry) only contains two members:
one is the CursorKind. and if it supply a "full Cursor" information, you can get the Location information about this code completion entry.
Maybe, the clang developers will improved this in the future. :D

Navigation

[0] Message Index

[*] Previous page

Go to full version