[cfe-dev] Templates (again)

Douglas Gregor dgregor at apple.com
Mon Dec 29 12:40:38 PST 2008


On Dec 29, 2008, at 10:14 AM, Andrew Sutton wrote:

>
> Aside from the move to DeclTemplate.h/.cpp, I'm having a hard time  
> determining what else has changed here. Is there something specific  
> I can look at?
>
> I think I've gotten AST construction for template template  
> parameters mostly done in that the parser now builds decl nodes that  
> include their template parameter lists. Default values aren't  
> plugged into that just yet. I think I did the right thing with the  
> layering/casting of TemplateParameterLists through the Action  
> interface by re-casting it as a TemplateParamsTy*.

I have some comments below.

> I'm also not entirely sure how to go about verifying that this does  
> what I think it does. I can probably make -ast-print dump template  
> information. That would probably help.

-ast-print might be the only way you can do this now, since we don't  
yet have the ability to turn a template-id into a type.

>
> Changes are pushed here https://www.bitbucket.org/danchr/clang/. The  
> branch name is still asutton/templates-3 although this also seems to  
> also be tagged "tip" (which it probably shouldn't be).


I browsed through a few of these. I'm not a Mercurial user, so when  
you think part of this is ready to go into the main tree I'll need a  
traditional patch.

In isTemplateName:

   // FIXME: Do we need to look up Ordinary | Tag since templates seem  
to
   // exist in both namespaces?
Just IDNS_Ordinary is fine. We ask LookupDecl which namespace to look  
in, and some entities can be found in multiple namespaces.
Deprecating the FunctionDecl/isDependentType hack below this code  
probably breaks some of the regression tests. I'd suggest leaving it  
as-is for now.
In TemplateDecl:

  static bool classof(const Decl *D)
   { return D->getKind() >= TemplateFirst && D->getKind() <=  
TemplateLast; }
   static bool classof(const TemplateDecl *D)
   { return true; }
You'll want to add

   static bool classof(const FunctionTemplateDecl *) { return true; }

and so on for the other TemplateDecl subclasses.

- FunctionDecl* getTemplatedFunction() const {
+  FunctionDecl *getFunctionDecl() const {
     return static_cast<FunctionDecl*>(TemplatedDecl);
   }

I think it'd be best for these functions to keep the same name  
"getTemplatedDecl" as in TemplateDecl. When we're in one of its  
subclasses, we get more a more-specific type.

The handling of TemplateParmsTy* in ActOnTemplateTemplateParameter  
looks fine to me.

	- Doug



More information about the cfe-dev mailing list