Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Chris Lattner | c960ee3 | 2009-04-02 06:07:12 +0000 | [diff] [blame] | 13 | |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 14 | #include "clang/AST/TemplateName.h" |
| 15 | #include "clang/AST/DeclTemplate.h" |
| 16 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 17 | #include "clang/AST/PrettyPrinter.h" |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame^] | 18 | #include "clang/Basic/LangOptions.h" |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 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 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 43 | void |
| 44 | TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy, |
| 45 | bool SuppressNNS) const { |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 46 | if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>()) |
| 47 | OS << Template->getIdentifier()->getName(); |
| 48 | else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) { |
Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 49 | if (!SuppressNNS) |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 50 | QTN->getQualifier()->print(OS, Policy); |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 51 | if (QTN->hasTemplateKeyword()) |
| 52 | OS << "template "; |
| 53 | OS << QTN->getTemplateDecl()->getIdentifier()->getName(); |
| 54 | } else if (DependentTemplateName *DTN = getAsDependentTemplateName()) { |
Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 55 | if (!SuppressNNS) |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 56 | DTN->getQualifier()->print(OS, Policy); |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 57 | OS << "template "; |
| 58 | OS << DTN->getName()->getName(); |
| 59 | } |
| 60 | } |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 61 | |
Douglas Gregor | 9bde773 | 2009-03-31 20:22:05 +0000 | [diff] [blame] | 62 | void TemplateName::dump() const { |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame^] | 63 | LangOptions LO; // FIXME! |
| 64 | LO.CPlusPlus = true; |
| 65 | LO.Bool = true; |
| 66 | print(llvm::errs(), PrintingPolicy(LO)); |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 67 | } |