Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Function Template Import in the ASTImporter class. #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions interpreter/llvm/src/tools/clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<ParmVarDecl *, 8> Parameters;
TypeLoc ToTypeLoc = TInfo->getTypeLoc();
unsigned I = 0;
for (auto P : D->getTemplatedDecl()->params()) {
ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P));
ToP->setScopeInfo(P->getFunctionScopeDepth(), P->getFunctionScopeIndex());
if (!ToP)
return nullptr;

Parameters.push_back(ToP);

if (FunctionProtoTypeLoc ToProtoLoc
= ToTypeLoc.getAs<FunctionProtoTypeLoc>()) {
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
//----------------------------------------------------------------------------
Expand Down