1 //===--- TemplateName.h - C++ Template Name Representation-------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the TemplateName interface and subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/TemplateName.h"
15 #include "clang/AST/DeclTemplate.h"
16 #include "clang/AST/NestedNameSpecifier.h"
17 #include "clang/AST/PrettyPrinter.h"
18 #include "llvm/Support/raw_ostream.h"
19 using namespace clang;
20 
21 TemplateDecl *TemplateName::getAsTemplateDecl() const {
22   if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
23     return Template;
24 
25   if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
26     return QTN->getTemplateDecl();
27 
28   return 0;
29 }
30 
31 bool TemplateName::isDependent() const {
32   if (TemplateDecl *Template = getAsTemplateDecl()) {
33     // FIXME: We don't yet have a notion of dependent
34     // declarations. When we do, check that. This hack won't last
35     // long!.
36     return isa<TemplateTemplateParmDecl>(Template);
37   }
38 
39   return true;
40 }
41 
42 void
43 TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy,
44                     bool SuppressNNS) const {
45   if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
46     OS << Template->getIdentifier()->getName();
47   else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) {
48     if (!SuppressNNS)
49       QTN->getQualifier()->print(OS, Policy);
50     if (QTN->hasTemplateKeyword())
51       OS << "template ";
52     OS << QTN->getTemplateDecl()->getIdentifier()->getName();
53   } else if (DependentTemplateName *DTN = getAsDependentTemplateName()) {
54     if (!SuppressNNS)
55       DTN->getQualifier()->print(OS, Policy);
56     OS << "template ";
57     OS << DTN->getName()->getName();
58   }
59 }
60 
61 void TemplateName::dump() const {
62   PrintingPolicy Policy;
63   Policy.CPlusPlus = true;
64   print(llvm::errs(), Policy);
65 }
66