blob: 5b671c111fbfd6b05b1163fe6063472a9921e545 [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"
Chris Lattnere4f21422009-06-30 01:26:17 +000018#include "clang/Basic/LangOptions.h"
Douglas Gregor7532dc62009-03-30 22:58:21 +000019#include "llvm/Support/raw_ostream.h"
Douglas Gregor7532dc62009-03-30 22:58:21 +000020using namespace clang;
21
22TemplateDecl *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
32bool 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 Gregord249e1d1f2009-05-29 20:38:28 +000043void
44TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy,
45 bool SuppressNNS) const {
Douglas Gregor7532dc62009-03-30 22:58:21 +000046 if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
47 OS << Template->getIdentifier()->getName();
48 else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) {
Douglas Gregor17343172009-04-01 00:28:59 +000049 if (!SuppressNNS)
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000050 QTN->getQualifier()->print(OS, Policy);
Douglas Gregor7532dc62009-03-30 22:58:21 +000051 if (QTN->hasTemplateKeyword())
52 OS << "template ";
53 OS << QTN->getTemplateDecl()->getIdentifier()->getName();
54 } else if (DependentTemplateName *DTN = getAsDependentTemplateName()) {
Douglas Gregor17343172009-04-01 00:28:59 +000055 if (!SuppressNNS)
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000056 DTN->getQualifier()->print(OS, Policy);
Douglas Gregor7532dc62009-03-30 22:58:21 +000057 OS << "template ";
58 OS << DTN->getName()->getName();
59 }
60}
Douglas Gregorde650ae2009-03-31 18:38:02 +000061
Douglas Gregor9bde7732009-03-31 20:22:05 +000062void TemplateName::dump() const {
Chris Lattnere4f21422009-06-30 01:26:17 +000063 LangOptions LO; // FIXME!
64 LO.CPlusPlus = true;
65 LO.Bool = true;
66 print(llvm::errs(), PrintingPolicy(LO));
Douglas Gregorde650ae2009-03-31 18:38:02 +000067}