opnsense-src/lib/AST/TemplateName.cpp

73 lines
2.3 KiB
C++
Raw Normal View History

2009-06-02 13:58:47 -04:00
//===--- TemplateName.h - C++ Template Name Representation-------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the TemplateName interface and subclasses.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/TemplateName.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/PrettyPrinter.h"
2009-07-04 09:58:54 -04:00
#include "clang/Basic/LangOptions.h"
2009-06-02 13:58:47 -04:00
#include "llvm/Support/raw_ostream.h"
using namespace clang;
TemplateDecl *TemplateName::getAsTemplateDecl() const {
if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
return Template;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
return QTN->getTemplateDecl();
return 0;
}
bool TemplateName::isDependent() const {
if (TemplateDecl *Template = getAsTemplateDecl()) {
2009-10-14 14:03:49 -04:00
return isa<TemplateTemplateParmDecl>(Template) ||
Template->getDeclContext()->isDependentContext();
2009-06-02 13:58:47 -04:00
}
2009-12-15 13:49:47 -05:00
assert(!getAsOverloadedTemplate() &&
"overloaded templates shouldn't survive to here");
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
return true;
}
2009-10-14 14:03:49 -04:00
void
2009-06-02 13:58:47 -04:00
TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy,
bool SuppressNNS) const {
if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
2009-11-04 10:04:32 -05:00
OS << Template->getNameAsString();
2009-06-02 13:58:47 -04:00
else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) {
if (!SuppressNNS)
QTN->getQualifier()->print(OS, Policy);
if (QTN->hasTemplateKeyword())
OS << "template ";
2009-10-14 14:03:49 -04:00
OS << QTN->getDecl()->getNameAsString();
2009-06-02 13:58:47 -04:00
} else if (DependentTemplateName *DTN = getAsDependentTemplateName()) {
2009-10-14 14:03:49 -04:00
if (!SuppressNNS && DTN->getQualifier())
2009-06-02 13:58:47 -04:00
DTN->getQualifier()->print(OS, Policy);
OS << "template ";
2009-11-04 10:04:32 -05:00
if (DTN->isIdentifier())
OS << DTN->getIdentifier()->getName();
else
OS << "operator " << getOperatorSpelling(DTN->getOperator());
2009-06-02 13:58:47 -04:00
}
}
void TemplateName::dump() const {
2009-07-04 09:58:54 -04:00
LangOptions LO; // FIXME!
LO.CPlusPlus = true;
LO.Bool = true;
print(llvm::errs(), PrintingPolicy(LO));
2009-06-02 13:58:47 -04:00
}