Author Topic: Does any one have interests to build a clang plugin for CC  (Read 22861 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Does any one have interests to build a clang plugin for CC
« on: January 15, 2011, 07:36:58 am »
I just create a simple cb project(console), and modified the c-index-test.c file a little to let it build.
I just added it as the attachment. (I have tested under Loaden's MinGW)

If you would like to try, I think the only thing you need is to adjust the "include search path" and the "lib search path", beside that, every thing should work fine. (sure, you need a llvm+clang lib)

to briefly understand what lib clang can supply, you can see the:
http://llvm.org/devmtg/2010-11/
especially Doug Gregor's PDF and Video.

Linking to libclang's lib is not quite difficult, but the main difficult thing is some need to create a framework for the C::B plugin. so that we  can do simple test on that. (including codecompletion test, find reference test, loop throuth the top level declaration, we can get the symbol tree structure....... clang can give use very precise result, it is amazing)

I personally don't has too much time on it, but if someone can create a frame work, than I think I can add many bricks, especially we can reuse many code snippet from the current CodeCompletion plugin.

any ideas??

thanks.


« Last Edit: January 17, 2011, 07:58:52 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does any one have interests to build a clang plugin for CC
« Reply #1 on: January 17, 2011, 05:54:56 am »
Hi, no body was interested on this topic?? :(

I create a minimal sample, which has a simple interpreter to show how codecompletion works. My project was linked to clang's index.

see https://quexparser.googlecode.com/svn/trunk/clang


Now, here is my test code: (test.cpp)
Code
#include <vector>
using namespace std;




class AAA
{
public:
   int aaa;
   int bbb;
};


int myfunction()
{
  AAA a;
  //a.
  std::vector<AAA> b;
  b[1].
  return 0;
}

and here is the log output:
Quote
code completion demo project with lib clang support!!! asmwarrior
ollydbg from codeblocks forum

it will bydefault open the test.cpp file!
* to show the code completion list, please enter the command
cc line column [ENTER]
* to exit, just enterexit [ENTER]
cc 20 8
ClassDecl:{TypedText AAA}{Text ::} (75)
FieldDecl:{ResultType int}{TypedText aaa} (35)
FieldDecl:{ResultType int}{TypedText bbb} (35)
CXXMethod:{ResultType AAA &}{TypedText operator=}{LeftParen (}{Placeholder const
 AAA &}{RightParen )} (34)
CXXDestructor:{ResultType void}{TypedText ~AAA}{LeftParen (}{RightParen )} (34)


Please note I have use a feature called:
CXTranslationUnit_PrecompiledPreamble

Here is the explanation:
Quote
   

Used to indicate that the translation unit should be built with an implicit precompiled header for the preamble.

An implicit precompiled header is used as an optimization when a particular translation unit is likely to be reparsed many times when the sources aren't changing that often. In this case, an implicit precompiled header will be built containing all of the initial includes at the top of the main file (what we refer to as the "preamble" of the file). In subsequent parses, if the preamble or the files in it have not changed, clang_reparseTranslationUnit() will re-use the implicit precompiled header to improve parsing performance.

see:
clang: clang: Translation unit manipulation

Even you edit the source file, then a implicit PCH will build internally. So, the performance is quite good.

ollydbg/asmwarrior



« Last Edit: January 17, 2011, 07:59:07 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does any one have interests to build a clang plugin for CC
« Reply #2 on: January 20, 2011, 08:07:44 am »
Here is another question:

clang and llvm has a bsd style license, but C::B is under GPL.

So, if we implement a plugin link to clang and llvm library, are there any conflict???

If so, I would choose some other alternative.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Does any one have interests to build a clang plugin for CC
« Reply #3 on: January 20, 2011, 08:57:11 am »
The SDK is LGPL 3.0.
And I think these two licenses are compatible, so you can use BSD libs in GPL/LGPL code.
Because BSD is the less restrictive license, the other way round is not possible (all code becomes GPL'ed).

But you should ask the FSF or some other competent organization. Also read the GPL FAQ.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does any one have interests to build a clang plugin for CC
« Reply #4 on: January 20, 2011, 09:09:32 am »
The SDK is LGPL 3.0.
And I think these two licenses are compatible, so you can use BSD libs in GPL/LGPL code.
Because BSD is the less restrictive license, the other way round is not possible (all code becomes GPL'ed).

But you should ask the FSF or some other competent organization. Also read the GPL FAQ.
thanks.

so the new clang plugin's source code will released under BSD? or GPL?

The big problem is: currently no one was interested on this plugin. :(
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Does any one have interests to build a clang plugin for CC
« Reply #5 on: January 20, 2011, 09:26:27 am »
The big problem is: currently no one was interested on this plugin. :(

Or no one hast the time or skills to work on it.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Does any one have interests to build a clang plugin for CC
« Reply #6 on: January 20, 2011, 09:43:58 am »
Ollydbg: looks like you're interested, so go for it :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does any one have interests to build a clang plugin for CC
« Reply #7 on: January 20, 2011, 10:05:35 am »
Ollydbg: looks like you're interested, so go for it :)
I have  interests, but i am not able to do it alone. There are too many things to build a new cc plugin.

if the new cc can not released under GPL, I  will not do anything.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Does any one have interests to build a clang plugin for CC
« Reply #8 on: January 20, 2011, 10:38:55 am »
Ask the llvm/clang guys, they know for sure...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
« Last Edit: January 21, 2011, 04:35:00 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

vignesh

  • Guest
Re: Does any one have interests to build a clang plugin for CC
« Reply #10 on: February 06, 2011, 12:53:52 pm »
Hi,
 this is pretty interesting.
I would like to help but i have no experience in such work  :(
But if u can direct me i could be of help....

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does any one have interests to build a clang plugin for CC
« Reply #11 on: February 06, 2011, 03:25:55 pm »
I am currently on Chinese new year holiday, i will reply more text when I am back. (from my phone)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does any one have interests to build a clang plugin for CC
« Reply #12 on: February 08, 2011, 03:04:11 am »
Hi,
 this is pretty interesting.
I would like to help but i have no experience in such work  :(
But if u can direct me i could be of help....

The first thing you need to know is the plugin-structure of C::B, You need to supply many event handlers to catch the event you interested. such as: a project is loaded, so you need to start parsing, or a "ctrl+space" key is pressed, which means the user want to show some suggestion list...

You can look at the source code of any plugin in C::B's source.

Then read the basic structure of the current codecompletion plugin, there are briefly introduced here:
Code Completion Design - CodeBlocks
The very basic thing is that the parser just do "syntax analysis" on each source file, and correct enough information.

Then, To use clang, you need to know how to use/build clang library, you can build clang which will produce some support libraries. Then try to use the sample code supplied by me, see my original post, in attachments, I has a sample code to do code completion by clang library.

Note: clang library support more things, like tag indexing, cross reference feature, but from the very beginning, all the above instruction will give a basic introduction.

Fell free to ask any question about this. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.