Author Topic: Clang based CC, new CC interface  (Read 40152 times)

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1506
Clang based CC, new CC interface
« on: January 11, 2014, 01:45:53 am »
I made an attempt to just get clang CC running with the working state of the CC plugin interface redesign.  Code attached.  (This is purely for demonstration, as it currently runs synchronously and does not cache results, so usability is low.)
Only tested under linux, some search directories are hard coded (and may need to be changed), the project directory expects to be extracted into src/plugins/, it may be necessary to disable the main CC plugin to see any results (CCManager will only query one of them because both claim to support the same files).

(For some reason, it appears clang_codeCompleteAt() is simply dumping all tokens that it knows, instead of using any sort of heuristic search/namespace resolution.  I do not know if that is error on my part, or if that is the expected output...)

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1506
Re: Clang based CC, new CC interface
« Reply #1 on: January 12, 2014, 02:22:36 am »
(For some reason, it appears clang_codeCompleteAt() is simply dumping all tokens that it knows, instead of using any sort of heuristic search/namespace resolution.  I do not know if that is error on my part, or if that is the expected output...)
Oops.  User error on my part.  The location I passed for line/column was 0-index based, however, clang was expecting 1-index based.

(I will start a git repository for this plugin soon.)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1575
Re: Clang based CC, new CC interface
« Reply #2 on: January 12, 2014, 02:39:54 am »
Cool! I will give it a try when it makes it to git. Never understood how clang's CC works in terms of finding symbols outside of local file scope. Presumably it already knows how to find std lib stuff, but what about something like wxwidgets?

Btw, when do we get the merge of your cc branch into trunk?

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1506
Re: Clang based CC, new CC interface
« Reply #3 on: January 12, 2014, 11:12:20 pm »
Repository is up.
Code: [Select]
git clone https://github.com/alpha0010/ClangLib.githttps://github.com/alpha0010/ClangLib
Please copy the attached image into src/devel/share/codeblocks/images/codecompletion/ before testing.

Btw, when do we get the merge of your cc branch into trunk?
From what I can tell, it runs as stable as the trunk (I am using the cc_interface branch as my main code editor).  Part of my purpose with testing this Clang plugin is to see if any obvious changes must be made to the interface.
My thoughts are, merge the branch once the interface works without losing any features from the main CC plugin (done), tests from this Clang plugin (in progress...), and the FortranProject (not yet looked at).  If we merge before these are complete, the interface would be likely to change soon after (defeating the purpose of working in a branch).
That said, my ideal target is one/two months (which depends a lot on how easy porting the FortranProject turns out to be).

Never understood how clang's CC works in terms of finding symbols outside of local file scope.
The way it is set up, Clang essentially compiles the file (into memory), so all of the #includes are resolved and expanded.  Searches are done per translation unit, not per file (which does mean I had to do a bit of file trickery in this plugin).
« Last Edit: January 12, 2014, 11:23:12 pm by Alpha »

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1575
Re: Clang based CC, new CC interface
« Reply #4 on: January 15, 2014, 11:03:14 pm »
Repository is up.
Code: [Select]
git clone https://github.com/alpha0010/ClangLib.githttps://github.com/alpha0010/ClangLib

Ubuntu 13.10's clang libs seems to be missing clang-c/Index.h, so I can't build it. Anyone know of a workaround? (Installing clang from source not an option in the near term)

Quote
Please copy the attached image into src/devel/share/codeblocks/images/codecompletion/ before testing.

Why don't you just deploy this file with a post build step in the project settings?

That said, my ideal target is one/two months (which depends a lot on how easy porting the FortranProject turns out to be).

If my python experience is a guide, this should be relatively straightforward. Your code eliminates a lot of the fiddling with cbEditor/wxScintilla.

Has anyone contacted the fortran maintainer? (I think he has the username darmar)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 4909
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Clang based CC, new CC interface
« Reply #5 on: January 15, 2014, 11:13:06 pm »
If I remember correct, index.h and other Clang shared libraries can be copied from CodeLite IDE's code repo.
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: 10061
Re: Clang based CC, new CC interface
« Reply #6 on: January 16, 2014, 01:22:39 am »
dmoore: Have you tried to install clang-dev or -devel?
<debugger plugin maintainer>
(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 Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1506
Re: Clang based CC, new CC interface
« Reply #7 on: January 16, 2014, 01:38:35 am »
Ubuntu 13.10's clang libs seems to be missing clang-c/Index.h, so I can't build it. Anyone know of a workaround? (Installing clang from source not an option in the near term)
The package libclang-3.4-dev has it (libclang-dev also works, but why not use the newer version since it is available?).  (Note that in the project file, the search path for it is currently hard coded, so you may have to adapt it to your computer.)

Why don't you just deploy this file with a post build step in the project settings?
I was planing to have CCManager provide a default set of icons, so I would end up deleting this from the Clang project later... Not really a valid excuse :) .  Just lazy.

Has anyone contacted the fortran maintainer? (I think he has the username darmar)
I have not yet; I will send a PM now.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1575
Re: Clang based CC, new CC interface
« Reply #8 on: January 16, 2014, 02:05:37 am »
dmoore: Have you tried to install clang-dev or -devel?

Yes. No sign of the needed headers. I will try installing 3.4...

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1506
Re: Clang based CC, new CC interface
« Reply #9 on: January 16, 2014, 02:16:41 am »
Yes. No sign of the needed headers. I will try installing 3.4...
Hmm... I found them under /usr/lib/llvm-3.2/include and /usr/lib/llvm-3.4/include respectively.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1575
Re: Clang based CC, new CC interface
« Reply #10 on: January 16, 2014, 03:37:09 am »
Yes. No sign of the needed headers. I will try installing 3.4...
Hmm... I found them under /usr/lib/llvm-3.2/include and /usr/lib/llvm-3.4/include respectively.

Ohh... completely obvious that they would put it there  ::) and who needs pkg-config files these days.  :-\

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1575
Re: Clang based CC, new CC interface
« Reply #11 on: January 16, 2014, 04:33:25 am »
Anyway, I should have looked more closely at your project file and I would have figured this out. doh!

This works really well and as far as I can tell is every bit as quick as our CC plugin. I didn't really do much testing but it seemed to be able to complete most things I tried. (Some things seemingly took a bit of time to populate in whatever DB clang uses so didn't come up first time)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9414
Re: Clang based CC, new CC interface
« Reply #12 on: January 16, 2014, 09:28:43 am »
...did you try that on Windows already?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1506
Re: Clang based CC, new CC interface
« Reply #13 on: January 16, 2014, 06:28:04 pm »
I have it running on Windows now as well.  I will commit the project file once I am done cleaning it up.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Clang based CC, new CC interface
« Reply #14 on: January 16, 2014, 07:51:59 pm »
You got a working Clang on Windows? How so?
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."