|
21 | 21 | #include "swift/AST/ClangModuleLoader.h"
|
22 | 22 | #include "swift/AST/DiagnosticEngine.h"
|
23 | 23 | #include "swift/AST/DiagnosticsClangImporter.h"
|
24 |
| -#include "swift/AST/ImportCache.h" |
| 24 | +#include "swift/AST/DiagnosticsSema.h" |
25 | 25 | #include "swift/AST/IRGenOptions.h"
|
| 26 | +#include "swift/AST/ImportCache.h" |
26 | 27 | #include "swift/AST/LinkLibrary.h"
|
27 | 28 | #include "swift/AST/Module.h"
|
28 | 29 | #include "swift/AST/NameLookup.h"
|
|
35 | 36 | #include "swift/ClangImporter/ClangModule.h"
|
36 | 37 | #include "swift/Config.h"
|
37 | 38 | #include "swift/Demangling/Demangle.h"
|
38 |
| -#include "swift/ClangImporter/ClangModule.h" |
39 |
| -#include "swift/Config.h" |
40 | 39 | #include "swift/Parse/Lexer.h"
|
41 | 40 | #include "swift/Parse/Parser.h"
|
42 | 41 | #include "swift/Strings.h"
|
@@ -4082,3 +4081,32 @@ swift::getModuleCachePathFromClang(const clang::CompilerInstance &Clang) {
|
4082 | 4081 | return llvm::sys::path::parent_path(SpecificModuleCachePath).str();
|
4083 | 4082 | }
|
4084 | 4083 |
|
| 4084 | +clang::FunctionDecl *ClangImporter::instantiateCXXFunctionTemplate( |
| 4085 | + ASTContext &ctx, clang::FunctionTemplateDecl *func, SubstitutionMap subst) { |
| 4086 | + SmallVector<clang::TemplateArgument, 4> templateSubst; |
| 4087 | + std::unique_ptr<TemplateInstantiationError> error = |
| 4088 | + ctx.getClangTemplateArguments(func->getTemplateParameters(), |
| 4089 | + subst.getReplacementTypes(), templateSubst); |
| 4090 | + if (error) { |
| 4091 | + std::string failedTypesStr; |
| 4092 | + llvm::raw_string_ostream failedTypesStrStream(failedTypesStr); |
| 4093 | + llvm::interleaveComma(error->failedTypes, failedTypesStrStream); |
| 4094 | + // TODO: Use the location of the apply here. |
| 4095 | + // TODO: This error message should not reference implementation details. |
| 4096 | + // See: https://github.com/apple/swift/pull/33053#discussion_r477003350 |
| 4097 | + ctx.Diags.diagnose(SourceLoc(), |
| 4098 | + diag::unable_to_convert_generic_swift_types.ID, |
| 4099 | + {func->getName(), StringRef(failedTypesStr)}); |
| 4100 | + // Return a valid FunctionDecl but, we'll never use it. |
| 4101 | + return func->getAsFunction(); |
| 4102 | + } |
| 4103 | + |
| 4104 | + // Instanciate a specialization of this template using the substitution map. |
| 4105 | + auto *templateArgList = clang::TemplateArgumentList::CreateCopy( |
| 4106 | + func->getASTContext(), templateSubst); |
| 4107 | + auto &sema = getClangInstance().getSema(); |
| 4108 | + auto *spec = sema.InstantiateFunctionDeclaration(func, templateArgList, |
| 4109 | + clang::SourceLocation()); |
| 4110 | + sema.InstantiateFunctionDefinition(clang::SourceLocation(), spec); |
| 4111 | + return spec; |
| 4112 | +} |
0 commit comments