[cfe-dev] Templates (again)

Andrew Sutton andrew.n.sutton at gmail.com
Wed Dec 31 07:26:23 PST 2008


On Tue, Dec 30, 2008 at 7:27 PM, Andrew Sutton <andrew.n.sutton at gmail.com>wrote:

>
>
>>> Building a patch against svn shouldn't be too much trouble. I'm going try
>>> to finish off the template-template param basics with ast-print support
>>> (hopefully) without introducing any regressions before submitting.
>>>
>>>
>> Okay.
>>
>
> It turns out to be impossible to ast-print template template parameters
> without handling template declarations. This seems so obvious in
> retrospect... So I'm working on AST building for class templates. It's kind
> of working, but I can't seem to get the DeclPrinter to see top-level
> template declarations. Probably some kind of weird name conflict because I'm
> forcing the TemplateDecl to take the same name as its underlying ScopedDecl.
>
> Quick question though. You started building support for depth/position
> stuff for template parameters, but the values aren't handled in Sema. Are
> you envisioning the depth/position as properties of template parameters or
> will they be dealt with elsewhere?
>
> Andrew Sutton
> andrew.n.sutton at gmail.com
>

Here's my incremental patch for template support to date as diff'd against
svn. Here's what I've done:
- Moved all template-related decls into new files DeclTemplate.h and
DeclTemplate.cpp
- Stubbed out the basic TemplateDecl hierarchy with derivatives
ClassTemplateDecl, and FunctionTemplateDecl and integrated this into the
isa/dyncast system (also added names to the getDeclKindName)
- Modified the TemplateParameter classes to include Depth/Position info as
properties, and stubbed out serialization support for all of them.
- Improved Sema support for building template template parameters.
- Create ClassTemplateDecls in ActOnTag when there are template parameters
- Blocked out support for printing template information in DeclPrinter

I never actually got -ast-print to print top-level template declarations.
For some reason, top-level template declarations seem to a) evaporate from
the list of top-level declarations or b) aren't actually being added to that
list.

There's also an interesting case in ActOnTag when a previous declaration
happens to be a class template. My solution is to simply make PrevDecl
reference the TemplatedDecl and temporarily punt on determining if a) the
previous is a forward declaration, or if the current tag is a full or
partial specialization. That logic probably needs to show up when we're
creating the AST nodes.

There are almost certainly some memory leaks and issues with ownership.

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


More information about the cfe-dev mailing list