]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/AST/TemplateName.cpp
Update to BIND 9.6.3, the latest from ISC on the 9.6 branch.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / AST / TemplateName.cpp
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 "clang/Basic/Diagnostic.h"
19 #include "clang/Basic/LangOptions.h"
20 #include "llvm/Support/raw_ostream.h"
21 using namespace clang;
22 using namespace llvm;
23
24 TemplateName::NameKind TemplateName::getKind() const {
25   if (Storage.is<TemplateDecl *>())
26     return Template;
27   if (Storage.is<OverloadedTemplateStorage *>())
28     return OverloadedTemplate;
29   if (Storage.is<QualifiedTemplateName *>())
30     return QualifiedTemplate;
31   assert(Storage.is<DependentTemplateName *>() && "There's a case unhandled!");
32   return DependentTemplate;
33 }
34
35 TemplateDecl *TemplateName::getAsTemplateDecl() const {
36   if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
37     return Template;
38
39   if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
40     return QTN->getTemplateDecl();
41
42   return 0;
43 }
44
45 bool TemplateName::isDependent() const {
46   if (TemplateDecl *Template = getAsTemplateDecl()) {
47     return isa<TemplateTemplateParmDecl>(Template) ||
48       Template->getDeclContext()->isDependentContext();
49   }
50
51   assert(!getAsOverloadedTemplate() &&
52          "overloaded templates shouldn't survive to here");
53
54   return true;
55 }
56
57 void
58 TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy,
59                     bool SuppressNNS) const {
60   if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
61     OS << Template;
62   else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) {
63     if (!SuppressNNS)
64       QTN->getQualifier()->print(OS, Policy);
65     if (QTN->hasTemplateKeyword())
66       OS << "template ";
67     OS << QTN->getDecl();
68   } else if (DependentTemplateName *DTN = getAsDependentTemplateName()) {
69     if (!SuppressNNS && DTN->getQualifier())
70       DTN->getQualifier()->print(OS, Policy);
71     OS << "template ";
72     
73     if (DTN->isIdentifier())
74       OS << DTN->getIdentifier()->getName();
75     else
76       OS << "operator " << getOperatorSpelling(DTN->getOperator());
77   }
78 }
79
80 const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
81                                            TemplateName N) {
82   std::string NameStr;
83   raw_string_ostream OS(NameStr);
84   LangOptions LO;
85   LO.CPlusPlus = true;
86   LO.Bool = true;
87   N.print(OS, PrintingPolicy(LO));
88   OS.flush();
89   return DB << NameStr;
90 }
91
92 void TemplateName::dump() const {
93   LangOptions LO;  // FIXME!
94   LO.CPlusPlus = true;
95   LO.Bool = true;
96   print(llvm::errs(), PrintingPolicy(LO));
97 }