mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[interop] emit a parsable C++ header for a module that includes namespace declaration for the module interface
This commit is contained in:
@@ -619,3 +619,15 @@ swift::printModuleContentsAsObjC(raw_ostream &os,
|
|||||||
: AccessLevel::Internal;
|
: AccessLevel::Internal;
|
||||||
ModuleWriter(os, imports, M, requiredAccess).write();
|
ModuleWriter(os, imports, M, requiredAccess).write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void swift::printModuleContentsAsCxx(
|
||||||
|
raw_ostream &os, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
|
||||||
|
ModuleDecl &M) {
|
||||||
|
os << "namespace ";
|
||||||
|
M.ValueDecl::getName().print(os);
|
||||||
|
os << " {\n\n";
|
||||||
|
// TODO (Alex): Emit module contents.
|
||||||
|
os << "\n} // namespace ";
|
||||||
|
M.ValueDecl::getName().print(os);
|
||||||
|
os << "\n\n";
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//===--- ModuleContentsWriter.h - Walk a module to print ObjC ---*- C++ -*-===//
|
//===--- ModuleContentsWriter.h - Walk module to print ObjC/C++ -*- C++ -*-===//
|
||||||
//
|
//
|
||||||
// This source file is part of the Swift.org open source project
|
// This source file is part of the Swift.org open source project
|
||||||
//
|
//
|
||||||
@@ -33,6 +33,12 @@ void printModuleContentsAsObjC(raw_ostream &os,
|
|||||||
llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
|
llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
|
||||||
ModuleDecl &M);
|
ModuleDecl &M);
|
||||||
|
|
||||||
|
/// Prints the declarations of \p M to \p os in C++ language mode and collects
|
||||||
|
/// imports in \p imports along the way.
|
||||||
|
void printModuleContentsAsCxx(raw_ostream &os,
|
||||||
|
llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
|
||||||
|
ModuleDecl &M);
|
||||||
|
|
||||||
} // end namespace swift
|
} // end namespace swift
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
22
lib/PrintAsClang/OutputLanguageMode.h
Normal file
22
lib/PrintAsClang/OutputLanguageMode.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
//===--- OutputLanguageMode.h - Output mode for clang printer ---*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// This source file is part of the Swift.org open source project
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
|
||||||
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
//
|
||||||
|
// See https://swift.org/LICENSE.txt for license information
|
||||||
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef SWIFT_PRINTASCLANG_OUTPUTLANGUAGEMODE_H
|
||||||
|
#define SWIFT_PRINTASCLANG_OUTPUTLANGUAGEMODE_H
|
||||||
|
|
||||||
|
namespace swift {
|
||||||
|
|
||||||
|
enum class OutputLanguageMode { ObjC, Cxx };
|
||||||
|
|
||||||
|
} // end namespace swift
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "swift/PrintAsClang/PrintAsClang.h"
|
#include "swift/PrintAsClang/PrintAsClang.h"
|
||||||
|
|
||||||
#include "ModuleContentsWriter.h"
|
#include "ModuleContentsWriter.h"
|
||||||
|
#include "OutputLanguageMode.h"
|
||||||
|
|
||||||
#include "swift/AST/ASTContext.h"
|
#include "swift/AST/ASTContext.h"
|
||||||
#include "swift/AST/Module.h"
|
#include "swift/AST/Module.h"
|
||||||
@@ -27,12 +28,14 @@
|
|||||||
using namespace swift;
|
using namespace swift;
|
||||||
|
|
||||||
static void writePrologue(raw_ostream &out, ASTContext &ctx,
|
static void writePrologue(raw_ostream &out, ASTContext &ctx,
|
||||||
StringRef macroGuard) {
|
StringRef macroGuard, OutputLanguageMode Lang) {
|
||||||
out << "// Generated by " << version::getSwiftFullVersion(
|
out << "// Generated by "
|
||||||
ctx.LangOpts.EffectiveLanguageVersion) << "\n"
|
<< version::getSwiftFullVersion(ctx.LangOpts.EffectiveLanguageVersion)
|
||||||
// Guard against recursive definition.
|
<< "\n"
|
||||||
<< "#ifndef " << macroGuard << "\n"
|
// Guard against recursive definition.
|
||||||
<< "#define " << macroGuard << "\n"
|
<< "#ifndef " << macroGuard << "\n"
|
||||||
|
<< "#define " << macroGuard
|
||||||
|
<< "\n"
|
||||||
"#pragma clang diagnostic push\n"
|
"#pragma clang diagnostic push\n"
|
||||||
"#pragma clang diagnostic ignored \"-Wgcc-compat\"\n"
|
"#pragma clang diagnostic ignored \"-Wgcc-compat\"\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -53,12 +56,18 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
|
|||||||
"# include <swift/objc-prologue.h>\n"
|
"# include <swift/objc-prologue.h>\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"\n"
|
"\n"
|
||||||
"#pragma clang diagnostic ignored \"-Wauto-import\"\n"
|
"#pragma clang diagnostic ignored \"-Wauto-import\"\n";
|
||||||
"#include <Foundation/Foundation.h>\n"
|
if (Lang == OutputLanguageMode::Cxx) {
|
||||||
"#include <stdint.h>\n"
|
out << "#include <cstdint>\n"
|
||||||
"#include <stddef.h>\n"
|
"#include <cstddef>\n"
|
||||||
"#include <stdbool.h>\n"
|
"#include <cstdbool>\n";
|
||||||
"\n"
|
} else {
|
||||||
|
out << "#include <Foundation/Foundation.h>\n"
|
||||||
|
"#include <stdint.h>\n"
|
||||||
|
"#include <stddef.h>\n"
|
||||||
|
"#include <stdbool.h>\n";
|
||||||
|
}
|
||||||
|
out << "\n"
|
||||||
"#if !defined(SWIFT_TYPEDEFS)\n"
|
"#if !defined(SWIFT_TYPEDEFS)\n"
|
||||||
"# define SWIFT_TYPEDEFS 1\n"
|
"# define SWIFT_TYPEDEFS 1\n"
|
||||||
"# if __has_include(<uchar.h>)\n"
|
"# if __has_include(<uchar.h>)\n"
|
||||||
@@ -95,19 +104,19 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
|
|||||||
"\n"
|
"\n"
|
||||||
"#if __has_attribute(objc_runtime_name)\n"
|
"#if __has_attribute(objc_runtime_name)\n"
|
||||||
"# define SWIFT_RUNTIME_NAME(X) "
|
"# define SWIFT_RUNTIME_NAME(X) "
|
||||||
"__attribute__((objc_runtime_name(X)))\n"
|
"__attribute__((objc_runtime_name(X)))\n"
|
||||||
"#else\n"
|
"#else\n"
|
||||||
"# define SWIFT_RUNTIME_NAME(X)\n"
|
"# define SWIFT_RUNTIME_NAME(X)\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if __has_attribute(swift_name)\n"
|
"#if __has_attribute(swift_name)\n"
|
||||||
"# define SWIFT_COMPILE_NAME(X) "
|
"# define SWIFT_COMPILE_NAME(X) "
|
||||||
"__attribute__((swift_name(X)))\n"
|
"__attribute__((swift_name(X)))\n"
|
||||||
"#else\n"
|
"#else\n"
|
||||||
"# define SWIFT_COMPILE_NAME(X)\n"
|
"# define SWIFT_COMPILE_NAME(X)\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if __has_attribute(objc_method_family)\n"
|
"#if __has_attribute(objc_method_family)\n"
|
||||||
"# define SWIFT_METHOD_FAMILY(X) "
|
"# define SWIFT_METHOD_FAMILY(X) "
|
||||||
"__attribute__((objc_method_family(X)))\n"
|
"__attribute__((objc_method_family(X)))\n"
|
||||||
"#else\n"
|
"#else\n"
|
||||||
"# define SWIFT_METHOD_FAMILY(X)\n"
|
"# define SWIFT_METHOD_FAMILY(X)\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
@@ -122,7 +131,8 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
|
|||||||
"# define SWIFT_RELEASES_ARGUMENT\n"
|
"# define SWIFT_RELEASES_ARGUMENT\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if __has_attribute(warn_unused_result)\n"
|
"#if __has_attribute(warn_unused_result)\n"
|
||||||
"# define SWIFT_WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n"
|
"# define SWIFT_WARN_UNUSED_RESULT "
|
||||||
|
"__attribute__((warn_unused_result))\n"
|
||||||
"#else\n"
|
"#else\n"
|
||||||
"# define SWIFT_WARN_UNUSED_RESULT\n"
|
"# define SWIFT_WARN_UNUSED_RESULT\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
@@ -143,41 +153,41 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
|
|||||||
"#if !defined(SWIFT_CLASS)\n"
|
"#if !defined(SWIFT_CLASS)\n"
|
||||||
"# if __has_attribute(objc_subclassing_restricted)\n"
|
"# if __has_attribute(objc_subclassing_restricted)\n"
|
||||||
"# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) "
|
"# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) "
|
||||||
"__attribute__((objc_subclassing_restricted)) "
|
"__attribute__((objc_subclassing_restricted)) "
|
||||||
"SWIFT_CLASS_EXTRA\n"
|
"SWIFT_CLASS_EXTRA\n"
|
||||||
"# define SWIFT_CLASS_NAMED(SWIFT_NAME) "
|
"# define SWIFT_CLASS_NAMED(SWIFT_NAME) "
|
||||||
"__attribute__((objc_subclassing_restricted)) "
|
"__attribute__((objc_subclassing_restricted)) "
|
||||||
"SWIFT_COMPILE_NAME(SWIFT_NAME) "
|
"SWIFT_COMPILE_NAME(SWIFT_NAME) "
|
||||||
"SWIFT_CLASS_EXTRA\n"
|
"SWIFT_CLASS_EXTRA\n"
|
||||||
"# else\n"
|
"# else\n"
|
||||||
"# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) "
|
"# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) "
|
||||||
"SWIFT_CLASS_EXTRA\n"
|
"SWIFT_CLASS_EXTRA\n"
|
||||||
"# define SWIFT_CLASS_NAMED(SWIFT_NAME) "
|
"# define SWIFT_CLASS_NAMED(SWIFT_NAME) "
|
||||||
"SWIFT_COMPILE_NAME(SWIFT_NAME) "
|
"SWIFT_COMPILE_NAME(SWIFT_NAME) "
|
||||||
"SWIFT_CLASS_EXTRA\n"
|
"SWIFT_CLASS_EXTRA\n"
|
||||||
"# endif\n"
|
"# endif\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if !defined(SWIFT_RESILIENT_CLASS)\n"
|
"#if !defined(SWIFT_RESILIENT_CLASS)\n"
|
||||||
"# if __has_attribute(objc_class_stub)\n"
|
"# if __has_attribute(objc_class_stub)\n"
|
||||||
"# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) SWIFT_CLASS(SWIFT_NAME) "
|
"# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) SWIFT_CLASS(SWIFT_NAME) "
|
||||||
"__attribute__((objc_class_stub))\n"
|
"__attribute__((objc_class_stub))\n"
|
||||||
"# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) "
|
"# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) "
|
||||||
"__attribute__((objc_class_stub)) "
|
"__attribute__((objc_class_stub)) "
|
||||||
"SWIFT_CLASS_NAMED(SWIFT_NAME)\n"
|
"SWIFT_CLASS_NAMED(SWIFT_NAME)\n"
|
||||||
"# else\n"
|
"# else\n"
|
||||||
"# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) "
|
"# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) "
|
||||||
"SWIFT_CLASS(SWIFT_NAME)\n"
|
"SWIFT_CLASS(SWIFT_NAME)\n"
|
||||||
"# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) "
|
"# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) "
|
||||||
"SWIFT_CLASS_NAMED(SWIFT_NAME)\n"
|
"SWIFT_CLASS_NAMED(SWIFT_NAME)\n"
|
||||||
"# endif\n"
|
"# endif\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"\n"
|
"\n"
|
||||||
"#if !defined(SWIFT_PROTOCOL)\n"
|
"#if !defined(SWIFT_PROTOCOL)\n"
|
||||||
"# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) "
|
"# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) "
|
||||||
"SWIFT_PROTOCOL_EXTRA\n"
|
"SWIFT_PROTOCOL_EXTRA\n"
|
||||||
"# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) "
|
"# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) "
|
||||||
"SWIFT_COMPILE_NAME(SWIFT_NAME) "
|
"SWIFT_COMPILE_NAME(SWIFT_NAME) "
|
||||||
"SWIFT_PROTOCOL_EXTRA\n"
|
"SWIFT_PROTOCOL_EXTRA\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"\n"
|
"\n"
|
||||||
"#if !defined(SWIFT_EXTENSION)\n"
|
"#if !defined(SWIFT_EXTENSION)\n"
|
||||||
@@ -187,44 +197,46 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
|
|||||||
"#if !defined(OBJC_DESIGNATED_INITIALIZER)\n"
|
"#if !defined(OBJC_DESIGNATED_INITIALIZER)\n"
|
||||||
"# if __has_attribute(objc_designated_initializer)\n"
|
"# if __has_attribute(objc_designated_initializer)\n"
|
||||||
"# define OBJC_DESIGNATED_INITIALIZER "
|
"# define OBJC_DESIGNATED_INITIALIZER "
|
||||||
"__attribute__((objc_designated_initializer))\n"
|
"__attribute__((objc_designated_initializer))\n"
|
||||||
"# else\n"
|
"# else\n"
|
||||||
"# define OBJC_DESIGNATED_INITIALIZER\n"
|
"# define OBJC_DESIGNATED_INITIALIZER\n"
|
||||||
"# endif\n"
|
"# endif\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if !defined(SWIFT_ENUM_ATTR)\n"
|
"#if !defined(SWIFT_ENUM_ATTR)\n"
|
||||||
"# if defined(__has_attribute) && "
|
"# if defined(__has_attribute) && "
|
||||||
"__has_attribute(enum_extensibility)\n"
|
"__has_attribute(enum_extensibility)\n"
|
||||||
"# define SWIFT_ENUM_ATTR(_extensibility) "
|
"# define SWIFT_ENUM_ATTR(_extensibility) "
|
||||||
"__attribute__((enum_extensibility(_extensibility)))\n"
|
"__attribute__((enum_extensibility(_extensibility)))\n"
|
||||||
"# else\n"
|
"# else\n"
|
||||||
"# define SWIFT_ENUM_ATTR(_extensibility)\n"
|
"# define SWIFT_ENUM_ATTR(_extensibility)\n"
|
||||||
"# endif\n"
|
"# endif\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if !defined(SWIFT_ENUM)\n"
|
"#if !defined(SWIFT_ENUM)\n"
|
||||||
"# define SWIFT_ENUM(_type, _name, _extensibility) "
|
"# define SWIFT_ENUM(_type, _name, _extensibility) "
|
||||||
"enum _name : _type _name; "
|
"enum _name : _type _name; "
|
||||||
"enum SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA "
|
"enum SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA "
|
||||||
"_name : _type\n"
|
"_name : _type\n"
|
||||||
"# if __has_feature(generalized_swift_name)\n"
|
"# if __has_feature(generalized_swift_name)\n"
|
||||||
"# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, "
|
"# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, "
|
||||||
"_extensibility) "
|
"_extensibility) "
|
||||||
"enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); "
|
"enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); "
|
||||||
"enum SWIFT_COMPILE_NAME(SWIFT_NAME) "
|
"enum SWIFT_COMPILE_NAME(SWIFT_NAME) "
|
||||||
"SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name : _type\n"
|
"SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name : _type\n"
|
||||||
"# else\n"
|
"# else\n"
|
||||||
"# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, "
|
"# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, "
|
||||||
"_extensibility) SWIFT_ENUM(_type, _name, _extensibility)\n"
|
"_extensibility) SWIFT_ENUM(_type, _name, _extensibility)\n"
|
||||||
"# endif\n"
|
"# endif\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if !defined(SWIFT_UNAVAILABLE)\n"
|
"#if !defined(SWIFT_UNAVAILABLE)\n"
|
||||||
"# define SWIFT_UNAVAILABLE __attribute__((unavailable))\n"
|
"# define SWIFT_UNAVAILABLE __attribute__((unavailable))\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if !defined(SWIFT_UNAVAILABLE_MSG)\n"
|
"#if !defined(SWIFT_UNAVAILABLE_MSG)\n"
|
||||||
"# define SWIFT_UNAVAILABLE_MSG(msg) __attribute__((unavailable(msg)))\n"
|
"# define SWIFT_UNAVAILABLE_MSG(msg) "
|
||||||
|
"__attribute__((unavailable(msg)))\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if !defined(SWIFT_AVAILABILITY)\n"
|
"#if !defined(SWIFT_AVAILABILITY)\n"
|
||||||
"# define SWIFT_AVAILABILITY(plat, ...) __attribute__((availability(plat, __VA_ARGS__)))\n"
|
"# define SWIFT_AVAILABILITY(plat, ...) "
|
||||||
|
"__attribute__((availability(plat, __VA_ARGS__)))\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if !defined(SWIFT_WEAK_IMPORT)\n"
|
"#if !defined(SWIFT_WEAK_IMPORT)\n"
|
||||||
"# define SWIFT_WEAK_IMPORT __attribute__((weak_import))\n"
|
"# define SWIFT_WEAK_IMPORT __attribute__((weak_import))\n"
|
||||||
@@ -233,24 +245,27 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
|
|||||||
"# define SWIFT_DEPRECATED __attribute__((deprecated))\n"
|
"# define SWIFT_DEPRECATED __attribute__((deprecated))\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if !defined(SWIFT_DEPRECATED_MSG)\n"
|
"#if !defined(SWIFT_DEPRECATED_MSG)\n"
|
||||||
"# define SWIFT_DEPRECATED_MSG(...) __attribute__((deprecated(__VA_ARGS__)))\n"
|
"# define SWIFT_DEPRECATED_MSG(...) "
|
||||||
|
"__attribute__((deprecated(__VA_ARGS__)))\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
"#if __has_feature(attribute_diagnose_if_objc)\n"
|
"#if __has_feature(attribute_diagnose_if_objc)\n"
|
||||||
"# define SWIFT_DEPRECATED_OBJC(Msg) __attribute__((diagnose_if(1, Msg, \"warning\")))\n"
|
"# define SWIFT_DEPRECATED_OBJC(Msg) __attribute__((diagnose_if(1, "
|
||||||
|
"Msg, \"warning\")))\n"
|
||||||
"#else\n"
|
"#else\n"
|
||||||
"# define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg)\n"
|
"# define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg)\n"
|
||||||
"#endif\n"
|
"#endif\n";
|
||||||
"#if !defined(IBSegueAction)\n"
|
if (Lang == OutputLanguageMode::ObjC) {
|
||||||
"# define IBSegueAction\n"
|
out << "#if !defined(IBSegueAction)\n"
|
||||||
"#endif\n"
|
"# define IBSegueAction\n"
|
||||||
"#if !defined(SWIFT_EXTERN)\n"
|
"#endif\n";
|
||||||
|
}
|
||||||
|
out << "#if !defined(SWIFT_EXTERN)\n"
|
||||||
"# if defined(__cplusplus)\n"
|
"# if defined(__cplusplus)\n"
|
||||||
"# define SWIFT_EXTERN extern \"C\"\n"
|
"# define SWIFT_EXTERN extern \"C\"\n"
|
||||||
"# else\n"
|
"# else\n"
|
||||||
"# define SWIFT_EXTERN extern\n"
|
"# define SWIFT_EXTERN extern\n"
|
||||||
"# endif\n"
|
"# endif\n"
|
||||||
"#endif\n"
|
"#endif\n";
|
||||||
;
|
|
||||||
static_assert(SWIFT_MAX_IMPORTED_SIMD_ELEMENTS == 4,
|
static_assert(SWIFT_MAX_IMPORTED_SIMD_ELEMENTS == 4,
|
||||||
"need to add SIMD typedefs here if max elements is increased");
|
"need to add SIMD typedefs here if max elements is increased");
|
||||||
}
|
}
|
||||||
@@ -401,7 +416,8 @@ bool swift::printAsObjC(raw_ostream &os, ModuleDecl *M,
|
|||||||
std::string moduleContentsBuf;
|
std::string moduleContentsBuf;
|
||||||
llvm::raw_string_ostream moduleContents{moduleContentsBuf};
|
llvm::raw_string_ostream moduleContents{moduleContentsBuf};
|
||||||
printModuleContentsAsObjC(moduleContents, imports, *M);
|
printModuleContentsAsObjC(moduleContents, imports, *M);
|
||||||
writePrologue(os, M->getASTContext(), computeMacroGuard(M));
|
writePrologue(os, M->getASTContext(), computeMacroGuard(M),
|
||||||
|
OutputLanguageMode::ObjC);
|
||||||
writeImports(os, imports, *M, bridgingHeader);
|
writeImports(os, imports, *M, bridgingHeader);
|
||||||
writePostImportPrologue(os, *M);
|
writePostImportPrologue(os, *M);
|
||||||
os << moduleContents.str();
|
os << moduleContents.str();
|
||||||
@@ -413,9 +429,14 @@ bool swift::printAsObjC(raw_ostream &os, ModuleDecl *M,
|
|||||||
bool swift::printAsCXX(raw_ostream &os, ModuleDecl *M) {
|
bool swift::printAsCXX(raw_ostream &os, ModuleDecl *M) {
|
||||||
llvm::PrettyStackTraceString trace("While generating C++ header");
|
llvm::PrettyStackTraceString trace("While generating C++ header");
|
||||||
|
|
||||||
writePrologue(os, M->getASTContext(), computeMacroGuard(M));
|
SmallPtrSet<ImportModuleTy, 8> imports;
|
||||||
|
std::string moduleContentsBuf;
|
||||||
|
llvm::raw_string_ostream moduleContents{moduleContentsBuf};
|
||||||
|
printModuleContentsAsCxx(moduleContents, imports, *M);
|
||||||
|
writePrologue(os, M->getASTContext(), computeMacroGuard(M),
|
||||||
|
OutputLanguageMode::Cxx);
|
||||||
writePostImportPrologue(os, *M);
|
writePostImportPrologue(os, *M);
|
||||||
// TODO (Alex): emit module contents.
|
os << moduleContents.str();
|
||||||
writeEpilogue(os);
|
writeEpilogue(os);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -2,7 +2,11 @@
|
|||||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -typecheck -emit-cxx-header-path %t/empty.h
|
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -typecheck -emit-cxx-header-path %t/empty.h
|
||||||
// RUN: %FileCheck %s < %t/empty.h
|
// RUN: %FileCheck %s < %t/empty.h
|
||||||
|
|
||||||
|
// RUN: %check-in-clang++ -std=c++14 %t/empty.h
|
||||||
|
// RUN: %check-in-clang++ -std=c++17 %t/empty.h
|
||||||
|
|
||||||
// CHECK-NOT: @import Swift;
|
// CHECK-NOT: @import Swift;
|
||||||
|
// CHECK-NOT: IBSegueAction
|
||||||
|
|
||||||
// CHECK-LABEL: #ifndef EMPTY_SWIFT_H
|
// CHECK-LABEL: #ifndef EMPTY_SWIFT_H
|
||||||
// CHECK-NEXT: #define EMPTY_SWIFT_H
|
// CHECK-NEXT: #define EMPTY_SWIFT_H
|
||||||
@@ -23,10 +27,9 @@
|
|||||||
// CHECK-NEXT: # define __has_warning(x) 0
|
// CHECK-NEXT: # define __has_warning(x) 0
|
||||||
// CHECK-NEXT: #endif
|
// CHECK-NEXT: #endif
|
||||||
|
|
||||||
// CHECK-LABEL: #include <Foundation/Foundation.h>
|
// CHECK-LABEL: #include <cstdint>
|
||||||
// CHECK: #include <stdint.h>
|
// CHECK: #include <cstddef>
|
||||||
// CHECK: #include <stddef.h>
|
// CHECK: #include <cstdbool>
|
||||||
// CHECK: #include <stdbool.h>
|
|
||||||
|
|
||||||
// CHECK-LABEL: !defined(SWIFT_TYPEDEFS)
|
// CHECK-LABEL: !defined(SWIFT_TYPEDEFS)
|
||||||
// CHECK-NEXT: # define SWIFT_TYPEDEFS 1
|
// CHECK-NEXT: # define SWIFT_TYPEDEFS 1
|
||||||
@@ -51,4 +54,7 @@
|
|||||||
// CHECK: # define SWIFT_EXTENSION(M)
|
// CHECK: # define SWIFT_EXTENSION(M)
|
||||||
// CHECK: # define OBJC_DESIGNATED_INITIALIZER
|
// CHECK: # define OBJC_DESIGNATED_INITIALIZER
|
||||||
|
|
||||||
|
// CHECK-LABEL: namespace empty {
|
||||||
|
// CHECK: } // namespace empty
|
||||||
|
|
||||||
// CHECK-NOT: @
|
// CHECK-NOT: @
|
||||||
|
|||||||
12
test/PrintAsCxx/lit.local.cfg
Normal file
12
test/PrintAsCxx/lit.local.cfg
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Make a local copy of the substitutions.
|
||||||
|
config.substitutions = list(config.substitutions)
|
||||||
|
|
||||||
|
config.substitutions.insert(0, ('%check-in-clang\+\+',
|
||||||
|
'%%clang --driver-mode=g++ -fsyntax-only -x c++-header '
|
||||||
|
'-Weverything -Werror -Wno-unused-macros -Wno-incomplete-module '
|
||||||
|
'-Wno-auto-import -Wno-variadic-macros -Wno-c++98-compat-pedantic '
|
||||||
|
'-Wno-poison-system-directories '
|
||||||
|
'-Wno-unused-command-line-argument ' # for -fmodules-cache-path
|
||||||
|
'-F %%clang-importer-sdk-path/frameworks '
|
||||||
|
'-I %%clang-include-dir '
|
||||||
|
'-isysroot %r/Inputs/clang-importer-sdk' % config.test_source_root) )
|
||||||
Reference in New Issue
Block a user