TemplateName.cpp revision 900fc6388e803868a34b9483510c345e9b49d7eb
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" 21using namespace clang; 22using namespace llvm; 23 24TemplateDecl *TemplateName::getAsTemplateDecl() const { 25 if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>()) 26 return Template; 27 28 if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) 29 return QTN->getTemplateDecl(); 30 31 return 0; 32} 33 34bool TemplateName::isDependent() const { 35 if (TemplateDecl *Template = getAsTemplateDecl()) { 36 return isa<TemplateTemplateParmDecl>(Template) || 37 Template->getDeclContext()->isDependentContext(); 38 } 39 40 assert(!getAsOverloadedTemplate() && 41 "overloaded templates shouldn't survive to here"); 42 43 return true; 44} 45 46void 47TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy, 48 bool SuppressNNS) const { 49 if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>()) 50 OS << Template; 51 else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) { 52 if (!SuppressNNS) 53 QTN->getQualifier()->print(OS, Policy); 54 if (QTN->hasTemplateKeyword()) 55 OS << "template "; 56 OS << QTN->getDecl(); 57 } else if (DependentTemplateName *DTN = getAsDependentTemplateName()) { 58 if (!SuppressNNS && DTN->getQualifier()) 59 DTN->getQualifier()->print(OS, Policy); 60 OS << "template "; 61 62 if (DTN->isIdentifier()) 63 OS << DTN->getIdentifier()->getName(); 64 else 65 OS << "operator " << getOperatorSpelling(DTN->getOperator()); 66 } 67} 68 69const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, 70 TemplateName N) { 71 std::string NameStr; 72 raw_string_ostream OS(NameStr); 73 LangOptions LO; 74 LO.CPlusPlus = true; 75 LO.Bool = true; 76 N.print(OS, PrintingPolicy(LO)); 77 OS.flush(); 78 return DB << NameStr; 79} 80 81void TemplateName::dump() const { 82 LangOptions LO; // FIXME! 83 LO.CPlusPlus = true; 84 LO.Bool = true; 85 print(llvm::errs(), PrintingPolicy(LO)); 86} 87