From 7570254e4c668d962053d9ee40e647a9573c385e Mon Sep 17 00:00:00 2001 From: Elisavet Sakellari Date: Tue, 2 Feb 2016 15:54:10 +0100 Subject: [PATCH] Implemented Function Template Import in the ASTImporter class. --- .../src/tools/clang/lib/AST/ASTImporter.cpp | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/interpreter/llvm/src/tools/clang/lib/AST/ASTImporter.cpp b/interpreter/llvm/src/tools/clang/lib/AST/ASTImporter.cpp index 2442e8ec25f12..80ff3aa12e784 100644 --- a/interpreter/llvm/src/tools/clang/lib/AST/ASTImporter.cpp +++ b/interpreter/llvm/src/tools/clang/lib/AST/ASTImporter.cpp @@ -165,6 +165,7 @@ namespace clang { ClassTemplateSpecializationDecl *D); Decl *VisitVarTemplateDecl(VarTemplateDecl *D); Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); + Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); // Importing statements Stmt *VisitStmt(Stmt *S); @@ -4367,6 +4368,72 @@ Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( return D2; } +Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { + // Import the major distinguishing characteristics of this function. + DeclContext *DC, *LexicalDC; + DeclarationName Name; + SourceLocation Loc; + if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) + return nullptr; + + DeclarationNameInfo NameInfo(Name, Loc); + + QualType FromTy = D->getTemplatedDecl()->getType(); + + // Import the type. + QualType T = Importer.Import(FromTy); + if (T.isNull()) + return nullptr; + + TypeSourceInfo *TInfo + = Importer.Import(D->getTemplatedDecl()->getTypeSourceInfo()); + + // Import the function parameters. + SmallVector Parameters; + TypeLoc ToTypeLoc = TInfo->getTypeLoc(); + unsigned I = 0; + for (auto P : D->getTemplatedDecl()->params()) { + ParmVarDecl *ToP = cast_or_null(Importer.Import(P)); + ToP->setScopeInfo(P->getFunctionScopeDepth(), P->getFunctionScopeIndex()); + if (!ToP) + return nullptr; + + Parameters.push_back(ToP); + + if (FunctionProtoTypeLoc ToProtoLoc + = ToTypeLoc.getAs()) { + ToProtoLoc.setParam(I, Parameters[I]); + I++; + } + } + + FunctionDecl *ToFunction + = FunctionDecl::Create(Importer.getToContext(), DC, + Loc, NameInfo, T, TInfo, + D->getTemplatedDecl()->getStorageClass(), + D->getTemplatedDecl()->isInlineSpecified(), + D->getTemplatedDecl()->hasWrittenPrototype(), + D->getTemplatedDecl()->isConstexpr()); + + // Set the parameters. + for (unsigned I = 0, N = Parameters.size(); I != N; ++I) { + Parameters[I]->setOwningFunction(ToFunction); + ToFunction->addDeclInternal(Parameters[I]); + } + ToFunction->setParams(Parameters); + + FunctionTemplateDecl *ToFunctionTemplate + = FunctionTemplateDecl::Create(Importer.getToContext(), DC, + Loc, Name, + D->getTemplateParameters(), + ToFunction); + + ToFunction->setDescribedFunctionTemplate(ToFunctionTemplate); + + LexicalDC->addDeclInternal(ToFunctionTemplate); + return ToFunctionTemplate; +} + //---------------------------------------------------------------------------- // Import Statements //----------------------------------------------------------------------------