Author Topic: tag info for a typedef enum  (Read 10540 times)

murali

  • Community Member
  • Posts: 31
  • Hero Points: 0
tag info for a typedef enum
« on: May 04, 2010, 11:19:10 pm »
Hi all,

I have the following enum:
Code: [Select]
typedef enum
{
   SUCCESS,
   FAILED
}Result;

When I place hte cursor in Result and run the following macro, i get the typename as "typedef" and not as "typedef enum". How do I recognize the entity as an enum?

Code: [Select]
_command void Enum_GetTypeInfo() name_info(','VSARG2_EDITORCTL|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
   _UpdateContext(true);
   typeless tag_files=p_window_id.tags_filenamea(p_window_id.p_LangId);

   int context_id = tag_current_context();
   _str tag_name,type_name;
   if (context_id > 0) {
      tag_get_detail2(VS_TAGDETAIL_context_name, context_id, tag_name);
      tag_get_detail2(VS_TAGDETAIL_context_type, context_id, type_name);
   }
   say('Tag_name ='tag_name' Type = 'type_name)
}
Also how do i get all the enumerated values of the enum? I have a similar excercise for structs as well so info on how to access the fields of a struct would be great as well.
For this excercise, I basically have to enumerate each of the enum with a number automatically (not like the gui-enumerate) and I want to automate for the entire header file. Any pointers?

thanks,
Murali

murali

  • Community Member
  • Posts: 31
  • Hero Points: 0
Re: tag info for a typedef enum
« Reply #1 on: May 05, 2010, 02:15:51 am »
Ok. I am making some progress :)

Basically I am using tag_get_browse_info at the cursor. If it is a enum, I am trying to get the children of it by calling "tag_find_in_class". Problem is that it expects a tag database. If I keep my cursor at an enumerated value (enumc), it properly says that the parent is the enum. But tag_find_in_class errors out saying no record found. Is there a way to get this info without expecting a proper tagdb in place?

thanks in advance,
Murali

lambertia

  • Senior Community Member
  • Posts: 382
  • Hero Points: 14
  • I have nothing sufficiently witty to say.
Re: tag info for a typedef enum
« Reply #2 on: May 05, 2010, 05:22:54 am »
If you're C++ing, try:

enum Result
{
    SUCCESS,
    FAILED
};

;)

murali

  • Community Member
  • Posts: 31
  • Hero Points: 0
Re: tag info for a typedef enum
« Reply #3 on: May 05, 2010, 09:06:58 pm »
No go. It looks like it doesnt matter how we define the enum. Unless it is sitting in some tag database, we really can't use the tag apis. So I am wondering how the tree browser is getting this info..

Any ideas on tackling this problem?

thanks

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: tag info for a typedef enum
« Reply #4 on: May 05, 2010, 10:08:45 pm »
Is the question how to call SE tag APIs?
Or is the question why certain symbols aren't getting tagged?
Or both?

murali

  • Community Member
  • Posts: 31
  • Hero Points: 0
Re: tag info for a typedef enum
« Reply #5 on: May 05, 2010, 10:24:24 pm »
Here is an updated macro since last posted [The method to get enumc members was posted somewhere in the web - not mine] :

Code: [Select]
_command void VerifyEnumMembers() name_info(',')
{

   struct VS_TAG_BROWSE_INFO cm;
   _UpdateContext(true);
   int status = tag_get_browse_info("", cm,true);
   if(!status) {
      tag_browse_info_dump(cm,"Enum test",0);
      say('Tag Database is 'cm.tag_database);
   }


   /* if we are in a enum block */
   _str type_name = cm.type_name;
   _str member_name = cm.member_name;
   if(cm.type_name == "typedef") {
      _str temp[];
      split(cm.return_type," ",temp);
      switch(temp[0]) {
      case "struct":
         {
            type_name = "struct";
            break;
         }
      case "enum":
         {
              type_name = "enum";
              break;
         }
      }
      if(temp[1] != cm.member_name) {
         /* Not an anonymous enum */
         member_name = temp[1];
      }
   }
   say(" Type Name is ="type_name)
   switch(type_name) {
   case "enum":
      {
         _str file_name, class_name;
         int line_no, tag_flags;
         typeless tag_files = p_window_id.tags_filenamea(p_window_id.p_LangId);
         int i=0;
         for (;;) {                                           
            _str tf = next_tag_filea(tag_files, i, false, true);
            if (tf == '')
               break;

            int status = tag_find_in_class(member_name);
            say(member_name" 's status is "status);
               while (!status) {

                  tag_get_info(tag_name, type_name, file_name, line_no, class_name, tag_flags);
                  if (type_name == "enumc") {
                     // Only pick up enum members.
                     say('   Enumerated Value : 'tag_name' found at 'line_no);
                     //               enum_members[enum_members._length()] = tag_name;
                  }
                  else
                  {
                     say(' Found :'tag_name' with type 'type_name);
                  }
                  status = tag_next_in_class();
               }
         }
      }
   }
}

This code works only with the symbols tagged in a database. If I open a new .h file, fill it with an enum and try this, it doesnt work. But the treeview is able to display the symbols from the new .h file correctly. So is there a way I can achieve what I am doing above with or without having the source code tagged?

murali

  • Community Member
  • Posts: 31
  • Hero Points: 0
Re: tag info for a typedef enum
« Reply #6 on: May 07, 2010, 11:24:07 pm »
Anyone?

I am totally stuck at this point  ???

thanks

Graeme

  • Senior Community Member
  • Posts: 2366
  • Hero Points: 313
Re: tag info for a typedef enum
« Reply #7 on: May 07, 2010, 11:58:06 pm »
Anyone?

I am totally stuck at this point  ???

thanks

It's hard to tell what you're trying to do.  Can you try explaining exactly what you're trying to do as clearly as possible.  Also, answer chrisant's questions.

Graeme

murali

  • Community Member
  • Posts: 31
  • Hero Points: 0
Re: tag info for a typedef enum
« Reply #8 on: May 11, 2010, 03:48:32 pm »
Oops, I am sorry. I was actually answering his concern, but after re-reading my post, I might have digressed quite a bit...

Is the question how to call SE tag APIs?
Or is the question why certain symbols aren't getting tagged?
Or both?
[M] The objective is to get the symbol info for a enum structure. It may or may not be in a tagdb. What would be the correct way of getting that information? If the symbol is in tagDB, then the macro I had mentioned above works beautifully. Only when the symbol is not present in the tagDB, I am at a loss. I can see that the tree view gets populated with the symbol info, even when the header file is not tagged. So there must be some way to get the info, just that I dont know how.

thanks,
Murali

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: tag info for a typedef enum
« Reply #9 on: May 11, 2010, 07:59:57 pm »
My understanding is that tags only exist in tag databases.
How are you selecting which tag database to look in?
There are multiple tag databases, perhaps the tree view (which one do you mean, specifically?) macro source code can give you some pointers about how to look in more than one tag database.

murali

  • Community Member
  • Posts: 31
  • Hero Points: 0
Re: tag info for a typedef enum
« Reply #10 on: May 11, 2010, 09:44:24 pm »
I am using this logic (Full macro given in my previous post)
Code: [Select]
_str file_name, class_name;
int line_no, tag_flags;
typeless tag_files = p_window_id.tags_filenamea(p_window_id.p_LangId);
int i=0;
for (;;) { 
 _str tf = next_tag_filea(tag_files, i, false, true);
...snip...
}

This code works when the enum is present in a tagsDB. But I would like to see if I can get the same info when the header file is not tagged.

I tried to refer to the treeview macro but it looks a little overwhelming for me to understand. I was hoping to find if there are APIs that operate on the current file and do the grunt work of getting the info either from tagdb or from the logic treeview implements and presents a simple VS_TAG_BROWSE_INFO structure to the caller.






Graeme

  • Senior Community Member
  • Posts: 2366
  • Hero Points: 313
Re: tag info for a typedef enum
« Reply #11 on: May 12, 2010, 01:34:37 am »
A tag can be found in the current buffer, even if the current buffer is not part of a tag file.  If a header file isn't in the tag file, find_tag doesn't find things in that header file unless it's the current buffer.  Which treeview are you talking about  - the defs toolbar?


Graeme

  • Senior Community Member
  • Posts: 2366
  • Hero Points: 313
Re: tag info for a typedef enum
« Reply #12 on: May 12, 2010, 10:39:51 am »
You could try creating a temporary tag file using AddFilesToTagFile.  It looks like it creates a tag database file for you if it doesn't already exist.

Graeme

murali

  • Community Member
  • Posts: 31
  • Hero Points: 0
Re: tag info for a typedef enum
« Reply #13 on: May 12, 2010, 01:39:27 pm »
A tag can be found in the current buffer, even if the current buffer is not part of a tag file.  If a header file isn't in the tag file, find_tag doesn't find things in that header file unless it's the current buffer.  Which treeview are you talking about  - the defs toolbar?

I see that the tag is present for the current buffer, but there is no linkage. Meaning if I call tag_get_browse_info, I get the information for each element but seems like there is no link between the enum type name and the individual enumerated values...like if I want to iterate on all the enumerated values, for a given enum, I am not able to do so. It is the defs toolbar I was referring to as treeview..

You could try creating a temporary tag file using AddFilesToTagFile.  It looks like it creates a tag database file for you if it doesn't already exist.
Graeme
I will give this a try. Also when I was searching for it, in tags.e I saw that there is another API GetSymbolInfo, that seems to update the tagsdb with the current file...let me try that as well..

thanks,
Murali

hs2

  • Senior Community Member
  • Posts: 2738
  • Hero Points: 288
Re: tag info for a typedef enum
« Reply #14 on: May 12, 2010, 05:49:59 pm »
You could also have a look at this macro.
Especially the function maybe_add_return_type called e.g. by init_tree could be helpful.
The optional return type (see context menu) for enums is their value as provided by the tagging engine.

Good luck, HS2