[cfe-dev] [clang-tidy] Some possible contributions

Richard via cfe-dev cfe-dev at lists.llvm.org
Mon Dec 14 12:42:20 PST 2015

[Please reply *only* to the list and do not include my email directly
in the To: or Cc: of your reply; otherwise I will not see your reply.

In article <CAOsfVvk=ZYrJF+N9R=SqyT-zzVZMguxKQur88X9=-Bs3kWUJ-Q at mail.gmail.com>,
    Manuel Klimek via cfe-dev <cfe-dev at lists.llvm.org> writes:

> On Sun, Dec 13, 2015 at 6:15 PM Piotr Dziwinski via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:

> > long int a, *b, c[10];
> >
> > I want to obtain the necessary source locations from AST so that I can
> > parse this declaration into four component strings:
> >   - type identifier: "long int"
> >   - first variable declaration: "a"
> >   - second variable declaration: "*b"
> >   - third variable declaration: "c[10]"
> I believe you'll need to whip out the lexer for this currently.

IMO, the proper place to fix this is in the AST itself.  I would like
to see the AST node should provide an iterator API that allows you to
walk over all the identifiers (SourceLocation begin/end for each
identifier) in a single declaration and obtain their actual types:

a -> long int
b -> long int *
c -> long int[10]

This is really important information for working with declarations and
should be available from the tooling infrastructure.

At one point I tried to look into how declarations were parsed, but
not being that familiar with the parser code, I couldn't quickly find
where such information could be stashed off for latery querying.  It
seems to me that during parsing we must already have this information,
but it isn't directly encoded in the resulting AST.
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>

More information about the cfe-dev mailing list