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