blob: b56c0cebfa5833bcf78e9b5fbabbe9998cc8a5c3 [file] [log] [blame]
Shih-wei Liaof8fd82b2010-02-10 11:10:31 -08001//===--- 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
14#include "clang/AST/TemplateName.h"
15#include "clang/AST/DeclTemplate.h"
16#include "clang/AST/NestedNameSpecifier.h"
17#include "clang/AST/PrettyPrinter.h"
18#include "clang/Basic/LangOptions.h"
19#include "llvm/Support/raw_ostream.h"
20using 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 return isa<TemplateTemplateParmDecl>(Template) ||
35 Template->getDeclContext()->isDependentContext();
36 }
37
38 assert(!getAsOverloadedTemplate() &&
39 "overloaded templates shouldn't survive to here");
40
41 return true;
42}
43
44void
45TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy,
46 bool SuppressNNS) const {
47 if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
48 OS << Template->getNameAsString();
49 else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) {
50 if (!SuppressNNS)
51 QTN->getQualifier()->print(OS, Policy);
52 if (QTN->hasTemplateKeyword())
53 OS << "template ";
54 OS << QTN->getDecl()->getNameAsString();
55 } else if (DependentTemplateName *DTN = getAsDependentTemplateName()) {
56 if (!SuppressNNS && DTN->getQualifier())
57 DTN->getQualifier()->print(OS, Policy);
58 OS << "template ";
59
60 if (DTN->isIdentifier())
61 OS << DTN->getIdentifier()->getName();
62 else
63 OS << "operator " << getOperatorSpelling(DTN->getOperator());
64 }
65}
66
67void TemplateName::dump() const {
68 LangOptions LO; // FIXME!
69 LO.CPlusPlus = true;
70 LO.Bool = true;
71 print(llvm::errs(), PrintingPolicy(LO));
72}