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/LangOptions.h" 19 #include "llvm/Support/raw_ostream.h" 20 using namespace clang; 21 22 TemplateDecl *TemplateName::getAsTemplateDecl() const { 23 if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>()) 24 return Template; 25 26 if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) 27 return QTN->getTemplateDecl(); 28 29 return 0; 30 } 31 32 bool TemplateName::isDependent() const { 33 if (TemplateDecl *Template = getAsTemplateDecl()) { 34 // FIXME: We don't yet have a notion of dependent 35 // declarations. When we do, check that. This hack won't last 36 // long!. 37 return isa<TemplateTemplateParmDecl>(Template); 38 } 39 40 return true; 41 } 42 43 void 44 TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy, 45 bool SuppressNNS) const { 46 if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>()) 47 OS << Template->getIdentifier()->getName(); 48 else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) { 49 if (!SuppressNNS) 50 QTN->getQualifier()->print(OS, Policy); 51 if (QTN->hasTemplateKeyword()) 52 OS << "template "; 53 OS << QTN->getTemplateDecl()->getIdentifier()->getName(); 54 } else if (DependentTemplateName *DTN = getAsDependentTemplateName()) { 55 if (!SuppressNNS) 56 DTN->getQualifier()->print(OS, Policy); 57 OS << "template "; 58 OS << DTN->getName()->getName(); 59 } 60 } 61 62 void TemplateName::dump() const { 63 LangOptions LO; // FIXME! 64 LO.CPlusPlus = true; 65 LO.Bool = true; 66 print(llvm::errs(), PrintingPolicy(LO)); 67 } 68