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" |
| 17 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
| 20 | TemplateDecl *TemplateName::getAsTemplateDecl() const { |
| 21 | if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>()) |
| 22 | return Template; |
| 23 | |
| 24 | if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) |
| 25 | return QTN->getTemplateDecl(); |
| 26 | |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | bool TemplateName::isDependent() const { |
| 31 | if (TemplateDecl *Template = getAsTemplateDecl()) { |
| 32 | // FIXME: We don't yet have a notion of dependent |
| 33 | // declarations. When we do, check that. This hack won't last |
| 34 | // long!. |
| 35 | return isa<TemplateTemplateParmDecl>(Template); |
| 36 | } |
| 37 | |
| 38 | return true; |
| 39 | } |
| 40 | |
Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 41 | void TemplateName::print(llvm::raw_ostream &OS, bool SuppressNNS) const { |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 42 | if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>()) |
| 43 | OS << Template->getIdentifier()->getName(); |
| 44 | else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) { |
Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 45 | if (!SuppressNNS) |
| 46 | QTN->getQualifier()->print(OS); |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 47 | if (QTN->hasTemplateKeyword()) |
| 48 | OS << "template "; |
| 49 | OS << QTN->getTemplateDecl()->getIdentifier()->getName(); |
| 50 | } else if (DependentTemplateName *DTN = getAsDependentTemplateName()) { |
Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 51 | if (!SuppressNNS) |
| 52 | DTN->getQualifier()->print(OS); |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 53 | OS << "template "; |
| 54 | OS << DTN->getName()->getName(); |
| 55 | } |
| 56 | } |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 57 | |
Douglas Gregor | 9bde773 | 2009-03-31 20:22:05 +0000 | [diff] [blame] | 58 | void TemplateName::dump() const { |
| 59 | print(llvm::errs()); |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 60 | } |