Author Topic: class/method browser drop down list (box)  (Read 23750 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
class/method browser drop down list (box)
« on: December 14, 2005, 03:56:44 pm »
As in Dev-Cpp and M$ DevStudio there exits in the toolbar menus a class/method selection.
In there you can select for the Current Project (or is it the current target) from the first drop down list :
 - global functions
 - struct
 - class
And then in the second drop down list you can select the methods of that struct/class/global level.
Upon this method selection an editor is opened (if that file containing the implementation is not open yet) and the cursor is positioned at the start of the implementation of that method (considering the method prototype line being part of the implementation).
Upto this point is what Dev-Cpp delivers.
M$ goes one step further : in the active editor, the drop down list will follow and adjust it's selection (which it shows in the drop down list) according to where the cursor is positioned in the current editor (file).
Certainly this latter functionality is also very interesting : if you are in the middle of a method (for example you got there by clicking on search results) you might have no idea in which method you are : one glance at the top : bingo.

So I am going to try to implement this in CB. All help is welcome, but first let's think this one trough.

The most easy part is probably the first part. I already debugged a minor part of the code which allows you to perform a "goto function" to fix the problem of the return type shown in the function list. This code starts it's parsing the moment the "goto function" command is issued, but only for the current file (active editor).

It is obvious we should extend this to include all files in the project (easy : loop over all the files), for every file we have such a set of functions then. So we can show it in the drop down list.
Help needed here : how do I add such drop down lists to the toolbar menus ??

This is a snapshot, now we enter the problem of adding newly typed in methods. When to upgrade the list (Yiannis can you tell me how you guys did it in dev-cpp ??) :
 - every now and then (what does that mean : fixed period) ?
 - at the moment the 'return' key has been hit ?
 - at the moment the file is saved ?
 - ... ?
Help needed here : how does a plug-in (migth become part of the code completion plug-in later, or maybe better from the start ??) get's informed of the keystrokes from the user (type characters or commands like save ... ) ?

Note to self : namespaces !!! CB does not parse inside the namespaces :-(  ??

Then for the "following" part : again the major question is : when to update.
These updates require parsing : how performance killing might this be (don't know the performance of the CB parsers), we want to keep CB fast and having a good responsiveness to the user.

What do you think ?

Lieven


PS : please only comment on this functionality, don't start discussing things like : oh oh I know another feature I'd like to see implemented ...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: class/method browser drop down list (box)
« Reply #1 on: December 15, 2005, 10:23:50 pm »
 :cry: :cry: :cry: so little feedback

takeshimiya

  • Guest
Re: class/method browser drop down list (box)
« Reply #2 on: December 15, 2005, 10:44:04 pm »
I would like to see all of that.
But first, if the c++ parser of C::B is not improved (or replaced), that will make little sense.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: class/method browser drop down list (box)
« Reply #3 on: December 15, 2005, 10:50:29 pm »
But first, if the c++ parser of C::B is not improved (or replaced)...

8) MUAHAHAHAHAHAHA!

*Goes back to his underground lab*

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: class/method browser drop down list (box)
« Reply #4 on: December 15, 2005, 10:52:38 pm »
But first, if the c++ parser of C::B is not improved (or replaced)...

8) MUAHAHAHAHAHAHA!

*Goes back to his underground lab*

Ehm, what about the parser proposition, I have done some time ago.... :D.

Michael

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: class/method browser drop down list (box)
« Reply #5 on: December 15, 2005, 11:24:47 pm »
Sorry, I forgot, where is it?

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: class/method browser drop down list (box)
« Reply #6 on: December 15, 2005, 11:51:18 pm »
Sorry, I forgot, where is it?

No problem :). It was here.

Tomorrow, I will add some more info about the parser, as the source code may not give an immediate understanding of how the parser works.

Michael
 

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: class/method browser drop down list (box)
« Reply #7 on: December 16, 2005, 12:51:41 am »
Michael: How about making a simple wxwidgets project (with a text input box etc.) that uses this parser?

It'd be a great help for us.

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: class/method browser drop down list (box)
« Reply #8 on: December 16, 2005, 10:42:12 am »
Michael: How about making a simple wxwidgets project (with a text input box etc.) that uses this parser?
It'd be a great help for us.

I will try to do it and get something from the parser.

MichaelĀ 

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: class/method browser drop down list (box)
« Reply #9 on: December 16, 2005, 12:59:57 pm »
Hello,

Rick: I have take advantage of the break at my work to provide a C::B console project of the "Mini C++ interpreter" :). The code is relatively well commented and it could be useful for a first look. Test files are also provided. I have used GNU GCC to compile it, but I think that MS Toolkit 2003 should also work fine.

This evening when I will have more free time, I will provide a better overview of the parser (wxWidgets project) and post it tomorrow (I do not have Internet at home :().

Michael

PS.: Anyway, the Mini C++ interpreter could also be used as new "compiler" and/or as template (C++ beginners could appreciate it :)).


[attachment deleted by admin]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: class/method browser drop down list (box)
« Reply #10 on: December 16, 2005, 03:39:51 pm »
Question :
 - is there a way (by some wx Class ?) to get the entire content of a file (without doing ourself a file open, go to end, tell, allocate, read , ...) ?

I tried to look int the CB code to see how an cbEditor or EditorBase gets it's content but it seems this is hiding itself frome me (or I am looking in the wrong places ;-) ).

Lieven

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: class/method browser drop down list (box)
« Reply #11 on: December 16, 2005, 04:19:49 pm »
Question :
 - is there a way (by some wx Class ?) to get the entire content of a file (without doing ourself a file open, go to end, tell, allocate, read , ...) ?

I tried to look int the CB code to see how an cbEditor or EditorBase gets it's content but it seems this is hiding itself frome me (or I am looking in the wrong places ;-) ).

Lieven

Code
wxFile f("somefile.txt");
wxString contents;
cbRead(f, contents); // cbRead is in sdk/globals.h
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: class/method browser drop down list (box)
« Reply #12 on: December 16, 2005, 04:22:16 pm »
thanks,
I am starting to suspect you have cloned yourself 20 times. All those 20 you's are doing extremely much work together with providing very fast accurate feedback.  8)

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: class/method browser drop down list (box)
« Reply #13 on: December 16, 2005, 04:28:33 pm »
... to provide a C::B console project of the "Mini C++ interpreter" :). The code is relatively well commented and it could be useful for a first look. ...

nice, thanks !

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: class/method browser drop down list (box)
« Reply #14 on: December 18, 2005, 02:49:30 am »
This evening when I will have more free time, I will provide a better overview of the parser (wxWidgets project) and post it tomorrow (I do not have Internet at home :().

I have worked a bit more in the parser C++ of the Mini C++ interpreter.

The Mini C++ interpreter supports the following features:

  • Parameterized functions with local variables
  • Nested scopes
  • Recursion
  • The if, switch and break statements
  • The do-while, while and for loops
  • Function parameters of type int and char
  • Integer and character constants
  • String constants (limited implementation)
  • The return statement, both with and without a value
  • A handful of standard library functions
  • The operators +,-,*,/,%,<,>,<=,>=,==,!=,++,--,unary - and unary +
  • Functions returning integers
  • /* and // comments
  • Console I/O via cin and cout

Class are not supported. The default statement for the switch is not supported. The targets of if, while, do and for must be blocks of code surrounded by beginning and ending braces.

The (expression) parser for C++ is a recursive-descent parsers and not, as many commercial parser are, a table-driven parser. Table-driven parsers are faster, but also harder to implement. A recursive-descent parser is essentially a collection of mutually recursive functions that process an expression.

The parser for C++ is not implemented as class, but as a set of functions.

The most important function of the parser is the get_token(). The get_token() function returns tokens from the source code. The function begins by skipping over all white space, including carriage and return line feeds and comments. Then the next token in the program is read (each category is handled separately). For example if the next token in the program is a digit, a number is read; if the next character is a letter, an identifier or keyword is obtained and so on.

The string representation of the token is placed into token. Once read, the token's type (as enumerated by the tok_types enumeration) is put into token_type and, if the token is a keyword, its internal representation (as enumerated by token_ireps) is assigned to tok via the look_up() function.

An interesting function implemented in the parser is the eval_exp() which is used to evaluate C++ expression, e.g., 10-3*2.

The main() function (located in the minicpp.cpp file) is also source of useful information :). The main() function begins by allocating memory to hold the program being interpreted. The largest program that can be interpreted is specified by the constant PROG_SIZE (arbitrarily set at 10,000, but can be modified). Next, the program is loaded by calling load_program(). After the program has been loaded, main() performs three actions:

  • It calls prescan(), the interpreter prescanner
  • It readies the interpreter for the call to main() by finding its location in the program
  • It executes call(), which begins the execution of the program at the start of main()

The interpreter prescanner perfoms two important tasks:

  • All global variables must be found and initialized
  • The location of each function defined in the program must be found

I have attached to this post a TestParser.cpp file, which shows how the function get_token() works. I have also provided a new version of the minicpp.cpp file, because some code has to be commented in order to get the TestParser to work.

Michael

[attachment deleted by admin]