2009-03-31 06:58:21 +08: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-04-02 14:07:12 +08:00
|
|
|
|
2009-03-31 06:58:21 +08:00
|
|
|
#include "clang/AST/TemplateName.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
|
|
|
#include "clang/AST/NestedNameSpecifier.h"
|
2009-05-30 04:38:28 +08:00
|
|
|
#include "clang/AST/PrettyPrinter.h"
|
2010-04-08 08:03:06 +08:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2009-06-30 09:26:17 +08:00
|
|
|
#include "clang/Basic/LangOptions.h"
|
2009-03-31 06:58:21 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace clang;
|
2010-04-08 08:03:06 +08:00
|
|
|
using namespace llvm;
|
2009-03-31 06:58:21 +08:00
|
|
|
|
2010-06-20 03:28:53 +08:00
|
|
|
TemplateName::NameKind TemplateName::getKind() const {
|
|
|
|
if (Storage.is<TemplateDecl *>())
|
|
|
|
return Template;
|
|
|
|
if (Storage.is<OverloadedTemplateStorage *>())
|
|
|
|
return OverloadedTemplate;
|
|
|
|
if (Storage.is<QualifiedTemplateName *>())
|
|
|
|
return QualifiedTemplate;
|
|
|
|
assert(Storage.is<DependentTemplateName *>() && "There's a case unhandled!");
|
|
|
|
return DependentTemplate;
|
|
|
|
}
|
|
|
|
|
2009-03-31 06:58:21 +08:00
|
|
|
TemplateDecl *TemplateName::getAsTemplateDecl() const {
|
|
|
|
if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
|
|
|
|
return Template;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-31 06:58:21 +08:00
|
|
|
if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
|
|
|
|
return QTN->getTemplateDecl();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TemplateName::isDependent() const {
|
|
|
|
if (TemplateDecl *Template = getAsTemplateDecl()) {
|
2010-09-09 03:31:22 +08:00
|
|
|
if (isa<TemplateTemplateParmDecl>(Template))
|
|
|
|
return true;
|
|
|
|
// FIXME: Hack, getDeclContext() can be null if Template is still
|
|
|
|
// initializing due to PCH reading, so we check it before using it.
|
|
|
|
// Should probably modify TemplateSpecializationType to allow constructing
|
|
|
|
// it without the isDependent() checking.
|
|
|
|
return Template->getDeclContext() &&
|
|
|
|
Template->getDeclContext()->isDependentContext();
|
2009-03-31 06:58:21 +08:00
|
|
|
}
|
|
|
|
|
2009-12-02 16:04:21 +08:00
|
|
|
assert(!getAsOverloadedTemplate() &&
|
|
|
|
"overloaded templates shouldn't survive to here");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-31 06:58:21 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Variadic templates: extend Type, NestedNameSpecifier, TemplateName,
and TemplateArgument with an operation that determines whether there
are any unexpanded parameter packs within that construct. Use this
information to diagnose the appearance of the names of parameter packs
that have not been expanded (C++ [temp.variadic]p5). Since this
property is checked often (every declaration, ever expression
statement, etc.), we extend Type and Expr with a bit storing the
result of this computation, rather than walking the AST each time to
determine whether any unexpanded parameter packs occur.
This commit is deficient in several ways, which will be remedied with
future commits:
- Expr has a bit to store the presence of an unexpanded parameter
pack, but it is never set.
- The error messages don't point out where the unexpanded parameter
packs were named in the type/expression, but they should.
- We don't check for unexpanded parameter packs in all of the places
where we should.
- Testing is sparse, pending the resolution of the above three
issues.
llvm-svn: 121724
2010-12-14 06:49:22 +08:00
|
|
|
bool TemplateName::containsUnexpandedParameterPack() const {
|
|
|
|
if (TemplateDecl *Template = getAsTemplateDecl()) {
|
|
|
|
if (TemplateTemplateParmDecl *TTP
|
|
|
|
= dyn_cast<TemplateTemplateParmDecl>(Template))
|
|
|
|
return TTP->isParameterPack();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DependentTemplateName *DTN = getAsDependentTemplateName())
|
|
|
|
return DTN->getQualifier() &&
|
|
|
|
DTN->getQualifier()->containsUnexpandedParameterPack();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void
|
2009-05-30 04:38:28 +08:00
|
|
|
TemplateName::print(llvm::raw_ostream &OS, const PrintingPolicy &Policy,
|
|
|
|
bool SuppressNNS) const {
|
2009-03-31 06:58:21 +08:00
|
|
|
if (TemplateDecl *Template = Storage.dyn_cast<TemplateDecl *>())
|
2010-04-17 17:33:03 +08:00
|
|
|
OS << Template;
|
2009-03-31 06:58:21 +08:00
|
|
|
else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) {
|
2009-04-01 08:28:59 +08:00
|
|
|
if (!SuppressNNS)
|
2009-05-30 04:38:28 +08:00
|
|
|
QTN->getQualifier()->print(OS, Policy);
|
2009-03-31 06:58:21 +08:00
|
|
|
if (QTN->hasTemplateKeyword())
|
|
|
|
OS << "template ";
|
2010-04-17 17:33:03 +08:00
|
|
|
OS << QTN->getDecl();
|
2009-03-31 06:58:21 +08:00
|
|
|
} else if (DependentTemplateName *DTN = getAsDependentTemplateName()) {
|
2009-09-09 08:23:06 +08:00
|
|
|
if (!SuppressNNS && DTN->getQualifier())
|
2009-05-30 04:38:28 +08:00
|
|
|
DTN->getQualifier()->print(OS, Policy);
|
2009-03-31 06:58:21 +08:00
|
|
|
OS << "template ";
|
2009-11-04 08:56:37 +08:00
|
|
|
|
|
|
|
if (DTN->isIdentifier())
|
|
|
|
OS << DTN->getIdentifier()->getName();
|
|
|
|
else
|
|
|
|
OS << "operator " << getOperatorSpelling(DTN->getOperator());
|
2009-03-31 06:58:21 +08:00
|
|
|
}
|
|
|
|
}
|
2009-04-01 02:38:02 +08:00
|
|
|
|
2010-04-08 08:03:06 +08:00
|
|
|
const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
|
|
|
|
TemplateName N) {
|
|
|
|
std::string NameStr;
|
|
|
|
raw_string_ostream OS(NameStr);
|
|
|
|
LangOptions LO;
|
|
|
|
LO.CPlusPlus = true;
|
|
|
|
LO.Bool = true;
|
|
|
|
N.print(OS, PrintingPolicy(LO));
|
|
|
|
OS.flush();
|
|
|
|
return DB << NameStr;
|
|
|
|
}
|
|
|
|
|
2009-04-01 04:22:05 +08:00
|
|
|
void TemplateName::dump() const {
|
2009-06-30 09:26:17 +08:00
|
|
|
LangOptions LO; // FIXME!
|
|
|
|
LO.CPlusPlus = true;
|
|
|
|
LO.Bool = true;
|
|
|
|
print(llvm::errs(), PrintingPolicy(LO));
|
2009-04-01 02:38:02 +08:00
|
|
|
}
|