Improve upon r164450 and localize the logic of updating the type of

a function decl inside the ASTNodeImporter::VisitFunctionDecl function.

llvm-svn: 164625
This commit is contained in:
Argyrios Kyrtzidis 2012-09-25 19:26:39 +00:00
parent 511288b2b5
commit 2f45853f2f
1 changed files with 34 additions and 28 deletions

View File

@ -1482,9 +1482,7 @@ ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
T->getExtInfo());
}
static QualType importFunctionProtoType(ASTImporter &Importer,
const FunctionProtoType *T,
bool importExceptionSpecDecls) {
QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
QualType ToResultType = Importer.Import(T->getResultType());
if (ToResultType.isNull())
return QualType();
@ -1522,29 +1520,17 @@ static QualType importFunctionProtoType(ASTImporter &Importer,
ToEPI.NumExceptions = ExceptionTypes.size();
ToEPI.Exceptions = ExceptionTypes.data();
ToEPI.ConsumedArguments = FromEPI.ConsumedArguments;
if (importExceptionSpecDecls) {
ToEPI.ExceptionSpecType = FromEPI.ExceptionSpecType;
ToEPI.NoexceptExpr = Importer.Import(FromEPI.NoexceptExpr);
ToEPI.ExceptionSpecDecl = cast_or_null<FunctionDecl>(
ToEPI.ExceptionSpecType = FromEPI.ExceptionSpecType;
ToEPI.NoexceptExpr = Importer.Import(FromEPI.NoexceptExpr);
ToEPI.ExceptionSpecDecl = cast_or_null<FunctionDecl>(
Importer.Import(FromEPI.ExceptionSpecDecl));
ToEPI.ExceptionSpecTemplate = cast_or_null<FunctionDecl>(
ToEPI.ExceptionSpecTemplate = cast_or_null<FunctionDecl>(
Importer.Import(FromEPI.ExceptionSpecTemplate));
}
return Importer.getToContext().getFunctionType(ToResultType, ArgTypes.data(),
ArgTypes.size(), ToEPI);
}
QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
// FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
// FunctionDecl that we are importing this FunctionProtoType for.
// Update it in ASTNodeImporter::VisitFunctionDecl after the FunctionDecl has
// been created.
return importFunctionProtoType(Importer, T,
/*importExceptionSpecDecls=*/false);
}
QualType ASTNodeImporter::VisitParenType(const ParenType *T) {
QualType ToInnerType = Importer.Import(T->getInnerType());
if (ToInnerType.isNull())
@ -2520,8 +2506,30 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
// Import additional name location/type info.
ImportDeclarationNameLoc(D->getNameInfo(), NameInfo);
QualType FromTy = D->getType();
bool usedDifferentExceptionSpec = false;
if (const FunctionProtoType *
FromFPT = D->getType()->getAs<FunctionProtoType>()) {
FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
// FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
// FunctionDecl that we are importing the FunctionProtoType for.
// To avoid an infinite recursion when importing, create the FunctionDecl
// with a simplified function type and update it afterwards.
if (FromEPI.ExceptionSpecDecl || FromEPI.ExceptionSpecTemplate ||
FromEPI.NoexceptExpr) {
FunctionProtoType::ExtProtoInfo DefaultEPI;
FromTy = Importer.getFromContext().getFunctionType(
FromFPT->getResultType(),
FromFPT->arg_type_begin(),
FromFPT->arg_type_end() - FromFPT->arg_type_begin(),
DefaultEPI);
usedDifferentExceptionSpec = true;
}
}
// Import the type.
QualType T = Importer.Import(D->getType());
QualType T = Importer.Import(FromTy);
if (T.isNull())
return 0;
@ -2601,14 +2609,12 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
}
ToFunction->setParams(Parameters);
// Update FunctionProtoType::ExtProtoInfo.
if (const FunctionProtoType *
FromFPT = D->getType()->getAs<FunctionProtoType>()) {
FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
if (FromEPI.ExceptionSpecDecl || FromEPI.ExceptionSpecTemplate) {
ToFunction->setType(importFunctionProtoType(Importer, FromFPT,
/*importExceptionSpecDecls=*/true));
}
if (usedDifferentExceptionSpec) {
// Update FunctionProtoType::ExtProtoInfo.
QualType T = Importer.Import(D->getType());
if (T.isNull())
return 0;
ToFunction->setType(T);
}
// FIXME: Other bits to merge?