Author Topic: Problem of parsing C++ keyword in a C source code file  (Read 5230 times)

ardorbird

  • Community Member
  • Posts: 7
  • Hero Points: 0
Problem of parsing C++ keyword in a C source code file
« on: June 22, 2008, 01:17:41 pm »
Using Slickedit ver-12.03 needs, I am maintaining some C codes, some structures use C++ keywords as their member variable, for example:

   typedef struct _drmBO
   {
       unsigned desiredTileStride;
       void *virtual;
       void *mapVirtual;
   } drmBO;

The member variable "virtual" will not be correctly recognized by Slickedit as a member of drmBO (in C++, keyword "virtual" is used to define virtual function member of a class), so I cannot get correct symbol reference result if I want to find out who references this member variable; I cannot locate this member variable in the Symbol Browser of Slickedit either (all other member variables are normal). When generating tag files, how can I configure Slickedit to parse these files as standard C source codes (it has .c file extension) instead of always recognizing it as a C++ source codes to get correct symbol parsing result under these situations?

It's urgent, any response will be highly appreciated.

hs2

  • Senior Community Member
  • Posts: 2728
  • Hero Points: 282

ardorbird

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: Problem of parsing C++ keyword in a C source code file
« Reply #2 on: June 22, 2008, 02:53:10 pm »
HS,
Thank you for the information.

The post below described two methods to work around this problem:
1) configure macro variable def_ansic_exts
2) using 2008 new language / file extension management

But neither of them work for me, in ver 12.03 (it's Slickedit 2007), the macro variable def_ansi_exts also obsoleted, and the new lanaguage /file extension management is not available on this version. There is only a File Extension Setup under Tools-Options menu, but you cannot configure what standard to use to parse a specific file extension (like ANSIC).

Any suggestion?

-Bob
------------------------------------------
def_ansic_exts doesn't work because it is obsoleted by the new language / file extension management in SlickEdit 2008.  You can simply configure the "c" extension to use the ANSI-C mode.  Here's what the help says about def_ansic_exts.

_str def_ansic_exts

Space-delimited list of extensions (no dots). These extensions will be overridden with extension settings and options from the 'ansic' extension.

NOTE: This setting is no longer supported as of SlickEdit 2008. You can just refer 'c' to 'ansic'.

Default: ""

Category: Configuration Variables

hs2

  • Senior Community Member
  • Posts: 2728
  • Hero Points: 282
Re: Problem of parsing C++ keyword in a C source code file
« Reply #3 on: June 22, 2008, 03:04:04 pm »
Hmm - maybe you need to load '<SE-install-dir>\macros\ansic.e' manually (Macro>Load Module).
After that def_ansic_exts should be there. It's just an idea... no guarantees.
HS2

ardorbird

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: Problem of parsing C++ keyword in a C source code file
« Reply #4 on: June 22, 2008, 03:17:17 pm »
HS,

Thank you, you are so warmhearted.

I tired your method, macro variable def_ansic_exts can be set now. But after that, I rebuild the project tag files, but the variable virtual is still not listed.

sigh


-Bob

hs2

  • Senior Community Member
  • Posts: 2728
  • Hero Points: 282
Re: Problem of parsing C++ keyword in a C source code file
« Reply #5 on: June 22, 2008, 03:26:19 pm »
Maybe the SlickTeam can give a better advise on Monday. Never give up ;) - HS2

ardorbird

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: Problem of parsing C++ keyword in a C source code file
« Reply #6 on: June 22, 2008, 03:33:26 pm »
Anyway, thank you, HS2.

-Bob

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: Problem of parsing C++ keyword in a C source code file
« Reply #7 on: June 23, 2008, 02:25:43 pm »
In v12.0.3, you should be able to configure an extension to use ANSI-C as follows:
1) Select Tools > Options > File Extension Setup
2) Select the extension you are customizing. In this case, I believe that would be "c".
3) Click on the "Advanced" tab.
4) Select "ansic" from the list under "Lexer name".
5) Click the "OK" button.

Please let us know if this works for you.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2288
  • Hero Points: 295
Re: Problem of parsing C++ keyword in a C source code file
« Reply #8 on: June 23, 2008, 06:47:55 pm »
In 12.0.3, using def_ansic_exts, you could configure color coding and some features to be ANSI-C, but the parsing still used the C/C++ mixed parser.

In 13.0.x, we have a dedicated parser for C and ANSI-C, so if you just configure the ".c" extension to use the ANSI-C language we will indeed be able to parse your sample code with a variable named "virtual".

ardorbird

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: Problem of parsing C++ keyword in a C source code file
« Reply #9 on: June 24, 2008, 03:43:02 am »
In v12.0.3, you should be able to configure an extension to use ANSI-C as follows:
1) Select Tools > Options > File Extension Setup
2) Select the extension you are customizing. In this case, I believe that would be "c".
3) Click on the "Advanced" tab.
4) Select "ansic" from the list under "Lexer name".
5) Click the "OK" button.

Please let us know if this works for you.

Thank you for the information. I followed your steps but it doesn't work. I think this option only works if you want to change the color coding and do not affect the parsing result.

ardorbird

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: Problem of parsing C++ keyword in a C source code file
« Reply #10 on: June 24, 2008, 03:47:21 am »
In 12.0.3, using def_ansic_exts, you could configure color coding and some features to be ANSI-C, but the parsing still used the C/C++ mixed parser.

In 13.0.x, we have a dedicated parser for C and ANSI-C, so if you just configure the ".c" extension to use the ANSI-C language we will indeed be able to parse your sample code with a variable named "virtual".
Does this mean that there is no way to solve my problem on 12.0.3 except making a variable name change in all files?

Graeme

  • Senior Community Member
  • Posts: 2017
  • Hero Points: 236
Re: Problem of parsing C++ keyword in a C source code file
« Reply #11 on: June 24, 2008, 10:43:27 am »
Quote
Does this mean that there is no way to solve my problem on 12.0.3 except making a variable name change in all files?

If Dennis and Scott can't help you any more with the extension setup thing, maybe they could comment on some erratic behaviour that I've  encountered in V12.0.3 hotfix revision 31.

I was experimenting with slick's C preprocessor options and #defines to see if I could get the tagging to work for you with C++ keywords.  With the code you see below, at this very moment, using Ctrl-dot (push-tag) is finding the correct definition for lines *1 to *4 but I have "template" entered in the slick c preprocessor list with the #undef checkbox ticked and I do not have "virtual" in the preprocessor list.  If I now go and untick the #undef for template (and selecting "yes" to rebuild tag file), when I use ctrl-dot on either "template" variable, I get "tag not found" dialog.  Checking #undef for template makes it work again.

Also, at times, using ctrl-dot on the template var in line *1 incorrectly takes me to the struct member instead of the local variable.  For some weird reason, this seems to occur the first time ctrl-dot is used on line 1 immediately after changing the #undef checkbox and rebuilding the tag file.

The behaviour I've described just above seems consistent right now i.e. everything I've said above is currently repeatable.

However, the behaviour of push-tag in relation to "virtual" is confusing me.  If I now add #define virtual cvirtual to the code below and save the file (with retag on save enabled), the first few times I use ctrl-dot on lines 2 or 3, I get taken to the local var or struct member, but then I suddenly get a dialog box asking me to choose between the two definitions, or else it starts jumping to the #define virtual (which is probably what it should do).  At times, it has also been taking me to some weird visual studio file xlocnum that has #define _VIRTUAL virtual, but I'm so confused right now that I can't remember whether that was when I was using slick V13 or V12 (I started out playing with this in V13 then remembered the problem is in 12.0.3).

Probably you're as confused as I am by now.  Why virtual and template should seem to behave differently I have no idea but 12.0.3 seems to be consistently inconsistent  : ).  I tried removing the visual studio tag files to avoid the xlocnum confusion  - slick seemed to do this to start with but next time I opened the tag files dialog (after finding the xlocnum problem was still there) they had come back!  Possibly the xlocnum problem happens when virtual is entered in the slick preprocessor list.

Edit forgot to check if "find references" works  - well it does, but the find symbol toolbar (with context tagging as "look-in") finds only the struct member for template but finds both definitions for virtual.
 
Graeme


Code: [Select]
struct hhh {
   int * virtual;
   int * template;
};


hhh hhh2;

void main()
{
   int template;
   int virtual;

   template = 1;  // *1
   virtual = 1;    // *2
   hhh2.virtual = 1;  // *3
   hhh2.template = 1;  // *4
}
« Last Edit: June 24, 2008, 10:52:46 am by Graeme »

ardorbird

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: Problem of parsing C++ keyword in a C source code file
« Reply #12 on: June 24, 2008, 03:23:46 pm »
Quote
Does this mean that there is no way to solve my problem on 12.0.3 except making a variable name change in all files?

If Dennis and Scott can't help you any more with the extension setup thing, maybe they could comment on some erratic behaviour that I've  encountered in V12.0.3 hotfix revision 31.

I was experimenting with slick's C preprocessor options and #defines to see if I could get the tagging to work for you with C++ keywords.  With the code you see below, at this very moment, using Ctrl-dot (push-tag) is finding the correct definition for lines *1 to *4 but I have "template" entered in the slick c preprocessor list with the #undef checkbox ticked and I do not have "virtual" in the preprocessor list.  If I now go and untick the #undef for template (and selecting "yes" to rebuild tag file), when I use ctrl-dot on either "template" variable, I get "tag not found" dialog.  Checking #undef for template makes it work again.

Also, at times, using ctrl-dot on the template var in line *1 incorrectly takes me to the struct member instead of the local variable.  For some weird reason, this seems to occur the first time ctrl-dot is used on line 1 immediately after changing the #undef checkbox and rebuilding the tag file.

The behaviour I've described just above seems consistent right now i.e. everything I've said above is currently repeatable.

However, the behaviour of push-tag in relation to "virtual" is confusing me.  If I now add #define virtual cvirtual to the code below and save the file (with retag on save enabled), the first few times I use ctrl-dot on lines 2 or 3, I get taken to the local var or struct member, but then I suddenly get a dialog box asking me to choose between the two definitions, or else it starts jumping to the #define virtual (which is probably what it should do).  At times, it has also been taking me to some weird visual studio file xlocnum that has #define _VIRTUAL virtual, but I'm so confused right now that I can't remember whether that was when I was using slick V13 or V12 (I started out playing with this in V13 then remembered the problem is in 12.0.3).

Probably you're as confused as I am by now.  Why virtual and template should seem to behave differently I have no idea but 12.0.3 seems to be consistently inconsistent  : ).  I tried removing the visual studio tag files to avoid the xlocnum confusion  - slick seemed to do this to start with but next time I opened the tag files dialog (after finding the xlocnum problem was still there) they had come back!  Possibly the xlocnum problem happens when virtual is entered in the slick preprocessor list.

Edit forgot to check if "find references" works  - well it does, but the find symbol toolbar (with context tagging as "look-in") finds only the struct member for template but finds both definitions for virtual.
 
Graeme


Code: [Select]
struct hhh {
   int * virtual;
   int * template;
};


hhh hhh2;

void main()
{
   int template;
   int virtual;

   template = 1;  // *1
   virtual = 1;    // *2
   hhh2.virtual = 1;  // *3
   hhh2.template = 1;  // *4
}


like you said, I am really confused by your description although at first glance we seem to have very similar problem. Maybe another option for us is to upgrade to Slickedit 2008 (13.0.0)? But not sure if your problem really get solved on that version.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2288
  • Hero Points: 295
Re: Problem of parsing C++ keyword in a C source code file
« Reply #13 on: June 24, 2008, 04:45:40 pm »
Quote
Maybe another option for us is to upgrade to Slickedit 2008 (13.0.0)? But not sure if your problem really get solved on that version.

As I wrote earlier.

Quote
In 13.0.x, we have a dedicated parser for C and ANSI-C, so if you just configure the ".c" extension to use the ANSI-C language we will indeed be able to parse your sample code with a variable named "virtual".

If you do upgrade or get the trial, I recommend getting rid of any preprocessing mods you did to work around the issue.  And remember to configure the ".c" extension to use ANSI-C rather than the default C/C++ language setup.