[cfe-dev] Templates (again)

Andrew Sutton andrew.n.sutton at gmail.com
Thu Jan 1 08:20:10 PST 2009


> Is the TemplateDecl getting returned all the way through to
> ParseExternalDeclaration? That's how declarations get back to the
>

Knowing that helps a *lot*. Here's iteration n + 1. This starts to add
-ast-print support for class templates, but it doesn't print template
parameters just yet. You'll get "template <...> Read top-level tag...".

Getting this to work is... not very pretty. It's actually pretty tough to
push the TemplateDecl all the way up to ParseExternalDeclaration since,
somewhere in the call sequence, the created declaration node is wrapped in a
DeclSpec (in ParseDeclarationOrFunctionDefinition IIRC) and ActOnTag only
returns a TagDecl. I modified ActOnTag to return *either* a TagDecl or a
TemplateDecl. This has the unfortunate side-effect of requiring you to think
about DeclTy's in the Action interface as either a Tag or Template. It's
easy to get the Tag from the Template, but unfortuntely you still have to
perform the cast (so far only in 3 places). This also means that I'm setting
the TypeRep of a DeclSpec as a TemplateDecl, which may or may not have
unseen consequences down the road.

It's a big patch, but I tried to make it as unintrusive as possible. Best of
all, it doesn't cause any regressions on my system.

Andrew Sutton
andrew.n.sutton at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090101/8b478e91/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: templates.patch
Type: text/x-diff
Size: 61458 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090101/8b478e91/attachment.patch>


More information about the cfe-dev mailing list