Author Topic: Some parser-related questions  (Read 13647 times)

junior07

  • Guest
Some parser-related questions
« on: February 04, 2006, 11:59:16 am »
Hi all !
I am playing a little with C::B as I am looking for a free C++ IDE (free means no money of course, but open source is even better  :D)

Well, back to technical stuff.
I was testing the code completion feature as it is a key functionality for me. I find it useful as a reminder, in particular for structure and class members.
But I notice a few problems :
- structures defined with the "typedef" keyword are not handled properly
- classes with several "public" areas are not handled properly.

So I went to the SVN source codes and have a look at the ParserThread code.
I noticed that "typedef" was voluntarily not taken into account. Why does this behavior have been designed ? When I comment out references to "typedef" (in fact "kw_typedef" so that the parser ignore it), the parser seems to run better. What's wrong with this ?

Concerning classes, I have not looked at it yet, but it seems there are problems when handling nested public/protected/private portions in class definitions. Any remarks on it ?

Have a nice WE
Junior

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Some parser-related questions
« Reply #1 on: February 04, 2006, 04:52:00 pm »
it's not that typedef was taken out. It's that it was NEVER implemented :P

About public / private etc., I really don't know... could you post an example?

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Some parser-related questions
« Reply #2 on: February 04, 2006, 05:00:19 pm »
If you want to spend time on the codecompletion plugin you might want to take a stab at integrating the CTags based parser here: Eranfs CTags Based Parser.  It supports templates, typedefs, and hopefully is a little more stable on Linux, but that will have to be tested.

Rickg22-  Thanks for all the work on the CodeCompletion plugin, it has proved much in the last month.

junior07

  • Guest
Re: Some parser-related questions
« Reply #3 on: February 04, 2006, 09:51:14 pm »
it's not that typedef was taken out. It's that it was NEVER implemented :P

About public / private etc., I really don't know... could you post an example?

I don't understand why you say it has never been implemented because it appears in the file parserthread.cpp used for parsing :

Code
const wxString kw_typedef(_T("typedef"));

Code
else if (token==ParserConsts::kw_typedef
||
token==ParserConsts::colon)
{
SkipToOneOfChars(ParserConsts::semicolonclbrace, true);
m_Str.Clear();
}

Code
else if (token==ParserConsts::kw_typedef ||
token==ParserConsts::kw_return ||
token==ParserConsts::colon)
{
SkipToOneOfChars(ParserConsts::semicolonclbrace, true);
m_Str.Clear();
}

So, to my mind, typedef seems to be taken into account. But I wonder how those who originally wrote this code were thinking they should deal with this statement. It seems they ignore it.

For the second point (public/protected/private sections handling), I'm trying to reproduce the behavior I noticed this morning, but can't get it yet. Maybe was dreaming. I have experimented lots of code tuning.

Anyway, keep on this wonderful work guys, I learn to be able to help in a near future !

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Some parser-related questions
« Reply #4 on: February 04, 2006, 09:56:30 pm »
Quote
I don't understand why you say it has never been implemented because it appears in the file parserthread.cpp used for parsing
It is parsed like all keywords, but its semantics are not implemented.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

junior07

  • Guest
Re: Some parser-related questions
« Reply #5 on: February 04, 2006, 10:01:30 pm »
Excuse me, I don't understand what you mean.
When I comment out the references to typedef in the code I give above, the parser seems to behaves correctly. For example, it copes with a "typedef struct" correctly, allowing the use of the code completion whereas it was not possible with the typedef references uncommented.

Can you explain more ?
Thanks

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Some parser-related questions
« Reply #6 on: February 04, 2006, 10:13:26 pm »
If you comment out the "typedef" code, then
Code
StructTypename::

will probably display the code completion menu.

But if something like
Code
StructTypename a;
a.

really works, then I should be very, very surprised, as there is no code that handles this (to my knowledge).
I may of course be wrong... did not write the parser in the first place :lol:
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

junior07

  • Guest
Re: Some parser-related questions
« Reply #7 on: February 05, 2006, 08:19:57 pm »
You're right !
I realize this morning I was using the "original" name of the struct on which I was using typedef and not the new defined one. Am I understandable ? I think I'm a bit tired !
Well, I may take the time to study the internals of the code completion plugin to help to make it evolve.