Re: Using Semantic for Style Checking

Alex Murray <[email protected]> Thu, 11 Sep 2014 04:56:23 +0000
Newsgroups gmane.emacs.semantic
Message-ID <[email protected]>
> -----Original Message-----
> From: Eric Ludlam [mailto:[email protected]] On Behalf Of Eric M.
> Ludlam
> Sent: Thursday, 11 September 2014 12:28 PM
> 
> On 09/10/2014 03:51 AM, Alex Murray wrote:
> > Hi,
> >
> > I am trying to write a C style checker in Emacs using Semantic - firstly I just
> want to be able to check all variables within a file conform to a particular
> naming scheme.
> >
> > I am wanting to use Semantic to get the tags for all the variables within a
> file at all scopes but I can't seem to do this easily.
> >
> > (semantic-find-tags-by-class) only seems to return the variables in the
> global scope, so I was trying to use (semantic-fetch-tags) but this only returns
> variables within the current and all preceeding scopes - not ALL scopes within
> the buffer. Other than iterating through all positions within the buffer, I can't
> think of a good way to do this with my current understanding of semantic.
> >
> > Can anyone advise if this is possible (ie. to easily get all tags at all scopes
> within a buffer)?
> >
> > Any help would be greatly appreciated.
> 
> Hi,
> 
> The tags are all saved in a hierarchical order.  When scanning the tag lists
> there are 2 kinds of searches:
> 
> semantic-find-tags-by-class - finds all tags at the current level, which is the
> base of the file by default.
> 
> semantic-brute-find-tag-by-class - find all tags at the current level, and all
> tags that are children of some tag.
> 
> The -brute- functions all basically do a depth first search across the provided
> tags table.
> 
> These functions will NOT find local variables, for example:
> 
> int myfcn() {
>     int cantfindme;
> }
> 
> the cantfindme variable won't be found because semantic never parses
> stuff between the { } of the function.   If you want to do that you
> would need to:
> 
> 1) find-tags-by-class 'function
> 2) visit each function (move point there)
> 3) semantic-get-local-variables
> 
Hi Eric

Thanks for the reply - this was what I was planning to do but was
hoping I wouldn't have to - however I am not sure it will be enough.

If I visit each function and call semantic-get-local-variables I think
this will only give the variables in the top-level of the function
scope - ie:

int foo() {
  int bar = 1;

  if (bar) {
    int baz = 0;
  }
}

If I visit foo sobar will be in the list of tags but baz will not be.
So it looks like I need to recursively walk all scopes within the file
(and then do a semantic-get-local-variables at the deepest of each
scope) to get them all - does this sound correct?

Perhaps semantic isn't that well suited to this task of getting all
tags within a buffer / file (I wonder if I could just use a bunch of
regex's to match variable declarations / function definitions?)

Thanks again for your advice,
Alex

This communication may contain confidential or copyright information. If you are not an intended recipient, you must not keep, forward, copy, use, save or rely on this communication, and any such action is unauthorized and prohibited. If you have received this communication in error, please reply to this email to notify the sender of its incorrect delivery and then delete both and your reply.

------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk