Author Topic: Clang CC  (Read 248856 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Clang CC
« Reply #180 on: November 01, 2016, 12:17:40 pm »
i made the clean up, but i can't test it because i am not able to compiler clang probably into a shared monolithic library... Still working on it, but with not much hope...


greetings

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Clang CC
« Reply #181 on: December 09, 2016, 01:30:29 pm »
I pushed a cleanedup version of the codeblocks project for Windows + fixed some path issues for Windows.

Been using the plugin for a while on the windows version and no issues encountered for now.

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Clang CC
« Reply #182 on: December 09, 2016, 09:06:07 pm »
How does this plugin gather and feed the files and flags to clang?
Can it use a compiler database?
(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 yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Clang CC
« Reply #183 on: December 09, 2016, 09:42:33 pm »
Hi Obfuscated,

It gathers the compile command from codeblocks for GCC or clang.
I'm currently working on a new feature to output the 'compiler_commands.json' file so that we can use the clang tools without the need to rebuild this database with external tools.

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Clang CC
« Reply #184 on: December 10, 2016, 12:58:13 am »
I don't have a proper project, but a cmake ninja based one. Cmake can generate the correct database. So it will be useful if the cc plugin can use it to do its parsing.

p.s. it is not a good idea to put the generation of the compile_command.json in the clangcc plugin. It is best done as script when the scripting api is expanded or as another plugin or even as a core feature.
(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 yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Clang CC
« Reply #185 on: December 10, 2016, 08:47:34 am »
Yes I was allready thinking about splitting off this feature since it's not directly using anything from libclang itself, it's currently only recycling some plugin internal utility function. I'm glad you agree.

While using the clang codecompletion I noticed the plugin doesn't handle paths with spaces correctly yet, so that will be fixed soon.

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Clang CC
« Reply #186 on: December 10, 2016, 01:23:08 pm »
How does this plugin gather and feed the files and flags to clang?
Can it use a compiler database?

I guess you are need the compilation flags to come out of the compiler_commands.json that is generated from ninja ?

It can't do that right now, but I can't imagine it's difficult to add.

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Clang CC
« Reply #187 on: December 10, 2016, 02:02:44 pm »
I guess you are need the compilation flags to come out of the compiler_commands.json that is generated from ninja ?
Yes, the cb project generated by cmake doesn't contain flags (it is custom makefile based project), so the cc will have very hard time gathering them.
Probably we can add a field in the project with the path of the compilation database and then the CC could use it.
We can also teach other tools and plugins to use 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 yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Clang CC
« Reply #188 on: December 10, 2016, 05:39:50 pm »
I guess you are need the compilation flags to come out of the compiler_commands.json that is generated from ninja ?
Yes, the cb project generated by cmake doesn't contain flags (it is custom makefile based project), so the cc will have very hard time gathering them.
Probably we can add a field in the project with the path of the compilation database and then the CC could use it.
We can also teach other tools and plugins to use it.
My main job's project is also using a custom makefile. I simply mirror the compiler options enough so that ClangCC is working fine. To change options, i switch from custom makefile to cb, set an option and then toggle the custom makefile option back to 'on'. I'm not sure this is a bug in cb to be able to query the compile options when the custom makefile option is on but it sure is handy for me.

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Clang CC
« Reply #189 on: January 09, 2017, 07:42:50 am »
Pushed a new feature on the 'staging' branch where for each #include, it now adds a warning/error in case the specified header has a warning/error.

I doesn't work (yet) with multiple levels though (a header that includes a header that includes a header that has an error). I specifically didn't do this yet because it should filter out system headers for warnings (passed with -isystem) and the programmer isn't supposed to fix warnings in system headers..

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Clang CC
« Reply #190 on: January 10, 2017, 09:42:57 pm »
I guess you are need the compilation flags to come out of the compiler_commands.json that is generated from ninja ?
Yes, the cb project generated by cmake doesn't contain flags (it is custom makefile based project), so the cc will have very hard time gathering them.
Probably we can add a field in the project with the path of the compilation database and then the CC could use it.
We can also teach other tools and plugins to use it.

FYI next thing I'm implementing is support for this compiler_commands.json file

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Clang CC
« Reply #191 on: January 20, 2017, 07:54:26 am »
I pushed a new feature to support the use of the json file. It is a project-level setting that is compiler-target specific (last tab under project settings, might be hidden by the other tabs so have to scroll to it)

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Clang CC
« Reply #192 on: January 27, 2017, 12:56:29 am »
I was finally able to build the plugin under windows. Here are my steps:
1) Download LLVM from http://releases.llvm.org/3.9.1/LLVM-3.9.1-win32.exe
1.1) Install LLVM
2) Download the "reimp" tool from http://wyw.dcweb.cn/download.asp?path=&file=reimp_new.zip
2.1) Extract reimp
2.2) Build reimp with the terminal by navigating into the src subfolder and typing "mingw32-make.exe -f Makefile"
3) copy reimp.exe to INSTALL_PATH_LLVM\lib
3.1) open terminal in this folder and run "reimp libclang.lib" This should generate a liblibclang.a file.
3.2) Rename liblibclang.a to libclang.a
4) Download the source code of the cclang plugin
5) I had to make the changes to the project file according the patch i attached
6) Open the project file and set the CLANG global variable to the INSTALL_PATH_LLVM set the other global variables accordingly
7) Build target "plugin"
8) Copy the libclang.dll from INSTALL_PATH_LLVM/bin to your codeblocks directory
9) Open Codeblocks Plugins->Manage Plugins
9.1) Disable the code completition plugin
9.2) Install new and select the clanglib.cbplugin
10) Have fun
« Last Edit: January 27, 2017, 12:59:52 am by BlueHazzard »

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Clang CC
« Reply #193 on: January 28, 2017, 11:57:53 am »
Hi BlueHazzard,

Many thanks for this howto!

It looks like you solved the symbols-issue better than I did: I modified the llvm/clang Makefiles to output what I needed, it is certainly simpler and better with the reimp tool.

Any reason why you added a new target? Can't we just update the existing targets?

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Clang CC
« Reply #194 on: January 28, 2017, 12:08:01 pm »
Hi, i tested the plugin a bit and it is really nice.
Here some things i noted in this short period of testing:

1) The name of the binary is somehow unlucky... ClangLib sounds as it is something from clang but not a code completion plugin. I think ccClang or something like this would be a better name..
2) On the start of projects i get the sometimes a error message about some database could not be found? Is this only because i didn't used cclang on this project earlier?
3) I opened the codeblocks project file and it loaded successfully, but the cursor turned in a spinning circle (busy symbol) and never returned from it. I can click everywhere and it works, but the circle does not go away. And this blocks the right klick on the project tree. Also i can't close the project via menu, so it seems that the loading process is not competed?
4) I get plenty of messages like this:
Code
ClangLib: translUnitId == wxNOT_FOUND, cannot complete in file \codeblocks_sf\src\sdk\cbplugin.cpp
Does this mean the parser is not complete on this file?
5) One time the plugin prevented a file to save. I was not able to save the file anymore (a error message appeared that this file could not be saved) I was not able to reproduce this in the debugger, but this seems to be a really bad bug...

thank you all for this great work!
« Last Edit: January 28, 2017, 12:12:12 pm by BlueHazzard »