Author Topic: NEW PLUGIN: Code Browser  (Read 14779 times)

Joren7

  • Guest
NEW PLUGIN: Code Browser
« on: July 12, 2007, 06:19:35 pm »
Hi guys, I have used CodeBlocks from 2005, and my attention goes to something missing...a Code Browser plugin!
I'm thinking of a plugin that draw some diagrams (maybe UML) of the code (function or methods) that you are browsing...
As example, think that you want to know which methods are called inside a function, or maybe only in a part of it...
Or maybe you want to know all the part of the code that access a particular variables...
This is my idea...I think it could be useful for everyone.
When I code I write many papers with UML diagrams, either to project or to undestand some part that I am working to.
When I have to modify something, I begin studying the code and drawing diagrams using pen and paper...

What do you think about it?

Let me know if it is something useless...

Thank's to all!


/Joren

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: NEW PLUGIN: Code Browser
« Reply #1 on: July 12, 2007, 06:50:10 pm »
Is a great idea :D

It will help some of us that are lost in road.

Offline lubos

  • Almost regular
  • **
  • Posts: 131
Re: NEW PLUGIN: Code Browser
« Reply #2 on: July 12, 2007, 08:47:23 pm »
i would love you for that plugin  :P

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: NEW PLUGIN: Code Browser
« Reply #3 on: July 12, 2007, 09:01:58 pm »
Actually making a UML diagram from CodeCompletion is pretty straightforward since you already have the tokens at hand. Now, the HARD PART would be to add / edit methods from UML and generate the C++ code, because our parser isn't C++ complete. But yeah, it would still be useful to look at the UML.

Joren7

  • Guest
Re: NEW PLUGIN: Code Browser
« Reply #4 on: July 13, 2007, 12:06:21 am »
Well...my idea is to develop a plugin that might you select what to see using these tokens...
Say that you want to know what methods are called from within another method. You choose the start method, and then click on an hypotetic menu voice "code flows". Then it will appear a diagram of what functions are called...
This is the starting point, the road continue with another function like "variable access", in which you see a diagram with all the pieces of code
that use the selected variables...this is my idea...

I'll hope to begin soon the development, now I begin the project phase!
Where do you suggest me to start with? The tokens of the code completion may be a good start...

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: NEW PLUGIN: Code Browser
« Reply #5 on: July 13, 2007, 05:40:39 am »
OK here are some hints.

Function (and method) tokens have the starting and ending line, so you know where to search.
Also, you might need to use regular expressions to find calls to existing functions. Anything which has ( ... ) will do. Or perhaps [A-Za-z_][A-Za-z_0-9]+\( or something. Also try to search for full words for "word1 word2;" or  "word1 word2 = " or "word1 word2," where word1 is the type (class, typedef, etc) you're looking for. (That's without taking into account the pointers).

After that, search if your existing tokens match one of those words. Then start making a dependency tree. But be careful, if you do it wrong you might end up making an endless loop.

Offline eckard_klotz

  • Almost regular
  • **
  • Posts: 198
Re: NEW PLUGIN: Code Browser
« Reply #6 on: July 13, 2007, 05:41:53 am »
Hello Everybody.

Perhaps it is easier to implement it as a doxygen plug-in. Doxygen itself  (http://www.stack.nl/~dimitri/doxygen/) is a terminal-application for win32, linux and some other systems to generate the diagrams you need out of the original source. It is also possible to generate a xml-output that is a good database for other statistics and diagrams. I use it to generate nassi-shneiderman diagrams (http://sourceforge.net/projects/moritz).

The idea is to save the function that should be analysed in a single file by the plug-in. This single file will be analysed by doxygen. And than the plug-in shows the result.

Kind Regards,
                 Eckard Klotz.
 

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: NEW PLUGIN: Code Browser
« Reply #7 on: July 13, 2007, 09:55:51 am »
Hi !

If you use this one
Quote
[A-Za-z_][A-Za-z_0-9]+\(
, don't forget to add unnecessary blanks before parenthesis.

Dje

Offline szczepan

  • Multiple posting newcomer
  • *
  • Posts: 42
Re: NEW PLUGIN: Code Browser
« Reply #8 on: July 13, 2007, 10:46:38 am »

Now, the HARD PART would be to add / edit methods from UML and generate the C++ code, because our parser isn't C++ complete.

I've been playing with Eclipse CDT recently and I must say that, contrary to my prior intuition, a complete C++ parser seems feasible. CDT's full parser, which is written in Java, achieves parsing times that would be just about acceptable when divided by Java's "honey factor" :)


Offline jaxon

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: NEW PLUGIN: Code Browser
« Reply #9 on: July 13, 2007, 02:28:14 pm »
Hi all! I want to ask a really stuped question... I understand.

gcc/g++ is open source and it has a complete c++ parser... I think. So, why not to use in in code completion? it seems fast enuogh being able to use precompiled headers...

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: NEW PLUGIN: Code Browser
« Reply #10 on: July 13, 2007, 02:47:10 pm »
GCC is an excellent parser, but remember we're dealing with different compilers. Besides, it can't give out the info. I think the best choice would be using the CTAGS parser.

Offline jaxon

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: NEW PLUGIN: Code Browser
« Reply #11 on: July 13, 2007, 03:05:59 pm »
CTAGS... looked at there page on sourceforge it seems to be a powerfull tool... and they say it's easy to use there parser in software! what is the reason to use another parser? or it is just historical?:)

P.S. we want to move completly to codeblocks it's build system is excelent!!! but we want cc to parse comments and show popup descriptions for symbols under mouse...

Joren7

  • Guest
Re: NEW PLUGIN: Code Browser
« Reply #12 on: July 17, 2007, 04:54:35 pm »
Ok...I'll use CTags as Parser. All I want to do (as code flows, function calls, function and type hierarchy...) is not so simple, and my ideas were realized in Eclipse's CDT extension  :(
I don't know it CTags is a good C++ parser, I think I'll have to work also with Lex and Yacc!
Is there in project to release a new parser for codeblocks?

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: NEW PLUGIN: Code Browser
« Reply #13 on: July 17, 2007, 06:25:28 pm »
I'm planning to make a new recursive descent parser for CodeCompletion, but I won't start until v1.0 is released.

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: NEW PLUGIN: Code Browser
« Reply #14 on: July 17, 2007, 07:07:58 pm »
Couple of weeks ago, I re-wrote my CC library (CodeLite), in the following manner:

- ctags is used to create a symbol table
- In addition, and to complete the parser, I wrote 4 yacc grammars to parse the following:
1. scope
2. variables
3. functions
4. expressions

the scope parser:
this parser returns the given scope name at the end of the string, for example:
Code
namespace a {
class B{

the above code, given to the scope parser will return a::B

the variable parser:
this parser can locate any member variable in a given scope (needed for the Ctrl+Space functionality), it usuaully used to parse the local scope.

the function parser:
since ctags does not return the function return value, I wrote this parser. It accepts the pattern from ctags (stored in the database) and returns its return value, this in turn can be searched in the symbol table (sqlite based table) for matching tokens.

the expression parser:
the complicated parser of the four, which evaluates expressions.
for example, assuming the following code:
Code
class MyClass {
wxString m_name;
public:
wxString getName(){return m_name;};
}

Now, lets say user type the following:
Code
MyClass cls;
cls.getName().

the last expression, is evaluated into wxString, which now CodeLite can suggest proper completion based on the symbol table, by performing simple SQL query.

these 4 parsers combined with CTAGS & Sqlite are working very nice together.

Eran