[cfe-commits] r104226 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclTemplate.h lib/AST/Decl.cpp lib/Sema/SemaTemplate.cpp
Abramo Bagnara
abramo.bagnara at gmail.com
Thu May 20 08:32:11 PDT 2010
Author: abramo
Date: Thu May 20 10:32:11 2010
New Revision: 104226
URL: http://llvm.org/viewvc/llvm-project?rev=104226&view=rev
Log:
Added TemplateArgumentListInfo to FunctionTemplateSpecializationInfo.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=104226&r1=104225&r2=104226&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu May 20 10:32:11 2010
@@ -1424,6 +1424,16 @@
/// returns NULL.
const TemplateArgumentList *getTemplateSpecializationArgs() const;
+ /// \brief Retrieve the template argument list as written in the sources,
+ /// if any.
+ ///
+ /// If this function declaration is not a function template specialization
+ /// or if it had no explicit template argument list, returns NULL.
+ /// Note that it an explicit template argument list may be written empty,
+ /// e.g., template<> void foo<>(char* s);
+ const TemplateArgumentListInfo*
+ getTemplateSpecializationArgsAsWritten() const;
+
/// \brief Specify that this function declaration is actually a function
/// template specialization.
///
@@ -1443,7 +1453,8 @@
void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
const TemplateArgumentList *TemplateArgs,
void *InsertPos,
- TemplateSpecializationKind TSK = TSK_ImplicitInstantiation);
+ TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
+ const TemplateArgumentListInfo *TemplateArgsAsWritten = 0);
/// \brief Specifies that this function declaration is actually a
/// dependent function template specialization.
Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=104226&r1=104225&r2=104226&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Thu May 20 10:32:11 2010
@@ -283,6 +283,9 @@
/// specialization from the function template.
const TemplateArgumentList *TemplateArguments;
+ /// \brief The template arguments as written in the sources, if provided.
+ const TemplateArgumentListInfo *TemplateArgumentsAsWritten;
+
/// \brief The point at which this function template specialization was
/// first instantiated.
SourceLocation PointOfInstantiation;
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=104226&r1=104225&r2=104226&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu May 20 10:32:11 2010
@@ -1289,11 +1289,22 @@
return 0;
}
+const TemplateArgumentListInfo *
+FunctionDecl::getTemplateSpecializationArgsAsWritten() const {
+ if (FunctionTemplateSpecializationInfo *Info
+ = TemplateOrSpecialization
+ .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
+ return Info->TemplateArgumentsAsWritten;
+ }
+ return 0;
+}
+
void
FunctionDecl::setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
const TemplateArgumentList *TemplateArgs,
void *InsertPos,
- TemplateSpecializationKind TSK) {
+ TemplateSpecializationKind TSK,
+ const TemplateArgumentListInfo *TemplateArgsAsWritten) {
assert(TSK != TSK_Undeclared &&
"Must specify the type of function template specialization");
FunctionTemplateSpecializationInfo *Info
@@ -1305,6 +1316,7 @@
Info->Template.setPointer(Template);
Info->Template.setInt(TSK - 1);
Info->TemplateArguments = TemplateArgs;
+ Info->TemplateArgumentsAsWritten = TemplateArgsAsWritten;
TemplateOrSpecialization = Info;
// Insert this function template specialization into the set of known
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=104226&r1=104225&r2=104226&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu May 20 10:32:11 2010
@@ -4219,10 +4219,10 @@
return false;
}
-/// \brief Perform semantic analysis for the given function template
+/// \brief Perform semantic analysis for the given function template
/// specialization.
///
-/// This routine performs all of the semantic analysis required for an
+/// This routine performs all of the semantic analysis required for an
/// explicit function template specialization. On successful completion,
/// the function declaration \p FD will become a function template
/// specialization.
@@ -4230,24 +4230,14 @@
/// \param FD the function declaration, which will be updated to become a
/// function template specialization.
///
-/// \param HasExplicitTemplateArgs whether any template arguments were
-/// explicitly provided.
-///
-/// \param LAngleLoc the location of the left angle bracket ('<'), if
-/// template arguments were explicitly provided.
-///
-/// \param ExplicitTemplateArgs the explicitly-provided template arguments,
-/// if any.
-///
-/// \param NumExplicitTemplateArgs the number of explicitly-provided template
-/// arguments. This number may be zero even when HasExplicitTemplateArgs is
-/// true as in, e.g., \c void sort<>(char*, char*);
+/// \param ExplicitTemplateArgs the explicitly-provided template arguments,
+/// if any. Note that this may be valid info even when 0 arguments are
+/// explicitly provided as in, e.g., \c void sort<>(char*, char*);
+/// as it anyway contains info on the angle brackets locations.
///
-/// \param RAngleLoc the location of the right angle bracket ('>'), if
-/// template arguments were explicitly provided.
-///
-/// \param PrevDecl the set of declarations that
-bool
+/// \param PrevDecl the set of declarations that may be specialized by
+/// this function specialization.
+bool
Sema::CheckFunctionTemplateSpecialization(FunctionDecl *FD,
const TemplateArgumentListInfo *ExplicitTemplateArgs,
LookupResult &Previous) {
@@ -4349,12 +4339,16 @@
// Turn the given function declaration into a function template
// specialization, with the template arguments from the previous
// specialization.
+ // Take copies of (semantic and syntactic) template argument lists.
+ const TemplateArgumentList* TemplArgs = new (Context)
+ TemplateArgumentList(Specialization->getTemplateSpecializationArgs());
+ const TemplateArgumentListInfo* TemplArgsAsWritten = ExplicitTemplateArgs
+ ? new (Context) TemplateArgumentListInfo(*ExplicitTemplateArgs) : 0;
FD->setFunctionTemplateSpecialization(Specialization->getPrimaryTemplate(),
- new (Context) TemplateArgumentList(
- Specialization->getTemplateSpecializationArgs()),
- /*InsertPos=*/0,
- SpecInfo->getTemplateSpecializationKind());
-
+ TemplArgs, /*InsertPos=*/0,
+ SpecInfo->getTemplateSpecializationKind(),
+ TemplArgsAsWritten);
+
// The "previous declaration" for this function template specialization is
// the prior function template specialization.
Previous.clear();
More information about the cfe-commits
mailing list