blob: 3659e2350de61042fccb0da7039916812cc4f5c3 [file] [log] [blame]
Douglas Gregor7532dc62009-03-30 22:58:21 +00001//===--- 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 Gregorde650ae2009-03-31 18:38:02 +000017#include <stdio.h>
Douglas Gregor7532dc62009-03-30 22:58:21 +000018
19using namespace clang;
20
21TemplateDecl *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
31bool 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
42void 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 Gregorde650ae2009-03-31 18:38:02 +000056
57void 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}