blob: 3613da77b34270ba64649985c5854bf3cdbbf67a [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//===----------------------------------------------------------------------===//
Chris Lattnerc960ee32009-04-02 06:07:12 +000013
Douglas Gregor7532dc62009-03-30 22:58:21 +000014#include "clang/AST/TemplateName.h"
15#include "clang/AST/DeclTemplate.h"
16#include "clang/AST/NestedNameSpecifier.h"
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000017#include "clang/AST/PrettyPrinter.h"
Douglas Gregor7532dc62009-03-30 22:58:21 +000018#include "llvm/Support/raw_ostream.h"
Douglas Gregor7532dc62009-03-30 22:58:21 +000019using 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
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000042void
43TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy,
44 bool SuppressNNS) const {
Douglas Gregor7532dc62009-03-30 22:58:21 +000045 if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
46 OS << Template->getIdentifier()->getName();
47 else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) {
Douglas Gregor17343172009-04-01 00:28:59 +000048 if (!SuppressNNS)
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000049 QTN->getQualifier()->print(OS, Policy);
Douglas Gregor7532dc62009-03-30 22:58:21 +000050 if (QTN->hasTemplateKeyword())
51 OS << "template ";
52 OS << QTN->getTemplateDecl()->getIdentifier()->getName();
53 } else if (DependentTemplateName *DTN = getAsDependentTemplateName()) {
Douglas Gregor17343172009-04-01 00:28:59 +000054 if (!SuppressNNS)
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000055 DTN->getQualifier()->print(OS, Policy);
Douglas Gregor7532dc62009-03-30 22:58:21 +000056 OS << "template ";
57 OS << DTN->getName()->getName();
58 }
59}
Douglas Gregorde650ae2009-03-31 18:38:02 +000060
Douglas Gregor9bde7732009-03-31 20:22:05 +000061void TemplateName::dump() const {
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000062 PrintingPolicy Policy;
63 Policy.CPlusPlus = true;
64 print(llvm::errs(), Policy);
Douglas Gregorde650ae2009-03-31 18:38:02 +000065}