Skip to content
Merged
Show file tree
Hide file tree
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
75 changes: 13 additions & 62 deletions include/swift/AST/ASTBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class IfConfigClauseRangeInfo;
class GenericSignature;
class GenericSignatureImpl;
struct LabeledStmtInfo;
class LangOptions;
class LayoutConstraint;
class LayoutConstraintInfo;
struct LifetimeDescriptor;
Expand All @@ -82,6 +83,7 @@ enum class RequirementReprKind : unsigned;
struct BridgedASTType;
class BridgedCanType;
class BridgedASTContext;
class BridgedLangOptions;
struct BridgedSubstitutionMap;
struct BridgedGenericSignature;
struct BridgedConformance;
Expand Down Expand Up @@ -192,15 +194,11 @@ BridgedDeclNameLoc_createParsed(BridgedASTContext cContext,
swift::SourceLoc moduleSelectorLoc,
swift::SourceLoc baseNameLoc);


//===----------------------------------------------------------------------===//
// MARK: ASTContext
//===----------------------------------------------------------------------===//

enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedEndianness : size_t {
EndianLittle,
EndianBig,
};

class BridgedASTContext {
swift::ASTContext * _Nonnull Ctx;

Expand All @@ -218,16 +216,10 @@ class BridgedASTContext {
unsigned getMajorLanguageVersion() const;

SWIFT_COMPUTED_PROPERTY
unsigned getLangOptsTargetPointerBitWidth() const;

SWIFT_COMPUTED_PROPERTY
bool getLangOptsAttachCommentsToDecls() const;

SWIFT_COMPUTED_PROPERTY
BridgedEndianness getLangOptsTargetEndianness() const;
BridgedAvailabilityMacroMap getAvailabilityMacroMap() const;

SWIFT_COMPUTED_PROPERTY
BridgedAvailabilityMacroMap getAvailabilityMacroMap() const;
BridgedDiagnosticEngine getDiags() const;
};

#define IDENTIFIER_WITH_NAME(Name, _) \
Expand Down Expand Up @@ -259,56 +251,12 @@ SWIFT_NAME("BridgedASTContext.getDollarIdentifier(self:_:)")
swift::Identifier
BridgedASTContext_getDollarIdentifier(BridgedASTContext cContext, size_t idx);

SWIFT_NAME("BridgedASTContext.langOptsHasFeature(self:_:)")
bool BridgedASTContext_langOptsHasFeature(BridgedASTContext cContext,
BridgedFeature feature);

SWIFT_NAME("BridgedASTContext.langOptsCustomConditionSet(self:_:)")
bool BridgedASTContext_langOptsCustomConditionSet(BridgedASTContext cContext,
BridgedStringRef cName);

SWIFT_NAME("BridgedASTContext.langOptsHasFeatureNamed(self:_:)")
bool BridgedASTContext_langOptsHasFeatureNamed(BridgedASTContext cContext,
BridgedStringRef cName);
SWIFT_NAME("getter:BridgedASTContext.langOpts(self:)")
BridgedLangOptions BridgedASTContext_langOpts(BridgedASTContext cContext);

SWIFT_NAME("BridgedASTContext.langOptsHasAttributeNamed(self:_:)")
bool BridgedASTContext_langOptsHasAttributeNamed(BridgedASTContext cContext,
BridgedStringRef cName);

SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetOS(self:_:)")
bool BridgedASTContext_langOptsIsActiveTargetOS(BridgedASTContext cContext,
BridgedStringRef cName);

SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetArchitecture(self:_:)")
bool BridgedASTContext_langOptsIsActiveTargetArchitecture(BridgedASTContext cContext,
BridgedStringRef cName);

SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetEnvironment(self:_:)")
bool BridgedASTContext_langOptsIsActiveTargetEnvironment(BridgedASTContext cContext,
BridgedStringRef cName);

SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetRuntime(self:_:)")
bool BridgedASTContext_langOptsIsActiveTargetRuntime(BridgedASTContext cContext,
BridgedStringRef cName);

SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetPtrAuth(self:_:)")
bool BridgedASTContext_langOptsIsActiveTargetPtrAuth(BridgedASTContext cContext,
BridgedStringRef cName);

SWIFT_NAME("BridgedASTContext.langOptsGetTargetAtomicBitWidths(self:_:)")
SwiftInt BridgedASTContext_langOptsGetTargetAtomicBitWidths(BridgedASTContext cContext,
SwiftInt* _Nullable * _Nonnull cComponents);

SWIFT_NAME("BridgedASTContext.langOptsGetLanguageVersion(self:_:)")
SwiftInt BridgedASTContext_langOptsGetLanguageVersion(BridgedASTContext cContext,
SwiftInt* _Nullable * _Nonnull cComponents);

SWIFT_NAME("BridgedASTContext.langOptsGetCompilerVersion(self:_:)")
SwiftInt BridgedASTContext_langOptsGetCompilerVersion(BridgedASTContext cContext,
SwiftInt* _Nullable * _Nonnull cComponents);

/* Deallocate an array of Swift int values that was allocated in C++. */
void deallocateIntBuffer(SwiftInt * _Nullable cComponents);
SWIFT_NAME("BridgedLangOptions.hasAttributeNamed(self:_:)")
bool BridgedLangOptions_hasAttributeNamed(BridgedLangOptions cLangOpts,
BridgedStringRef cName);

enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedCanImportVersion : size_t {
CanImportUnversioned,
Expand All @@ -324,6 +272,9 @@ bool BridgedASTContext_canImport(BridgedASTContext cContext,
const SwiftInt *_Nullable versionComponents,
SwiftInt numVersionComponents);

SWIFT_NAME("getter:BridgedASTContext.staticBuildConfigurationPtr(self:)")
void * _Nonnull BridgedASTContext_staticBuildConfiguration(BridgedASTContext cContext);

//===----------------------------------------------------------------------===//
// MARK: AST nodes
//===----------------------------------------------------------------------===//
Expand Down
11 changes: 11 additions & 0 deletions include/swift/AST/ASTBridgingImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ swift::DeclNameLoc BridgedDeclNameLoc::unbridged() const {
return swift::DeclNameLoc(LocationInfo, NumArgumentLabels);
}

//===----------------------------------------------------------------------===//
// MARK: BridgedLangOptions
//===----------------------------------------------------------------------===//

BridgedLangOptions::BridgedLangOptions(const swift::LangOptions &langOpts)
: LangOpts(&langOpts) { }

const swift::LangOptions &BridgedLangOptions::unbridged() const {
return *LangOpts;
}

//===----------------------------------------------------------------------===//
// MARK: BridgedASTContext
//===----------------------------------------------------------------------===//
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/ASTContextGlobalCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ struct ASTContext::GlobalCache {
const NormalProtocolConformance *,
std::vector<ConformanceIsolationError>
> conformanceIsolationErrors;

/// The static build configuration. This points to an instance of the Swift
/// StaticBuildConfiguration.
void *StaticBuildConfiguration = nullptr;
};

} // end namespace
79 changes: 79 additions & 0 deletions include/swift/Basic/BasicBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class VersionTuple;
} // end namespace llvm

namespace swift {
class LangOptions;
class SourceLoc;
class SourceRange;
class CharSourceRange;
Expand Down Expand Up @@ -451,6 +452,84 @@ struct BridgedSwiftClosure {
BRIDGED_INLINE void operator()(const void *_Nullable);
};

//===----------------------------------------------------------------------===//
// MARK: LangOptions
//===----------------------------------------------------------------------===//

enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedEndianness : size_t {
EndianLittle,
EndianBig,
};

class BridgedLangOptions {
const swift::LangOptions * _Nonnull LangOpts;

public:
SWIFT_UNAVAILABLE("Use init(raw:) instead")
BRIDGED_INLINE BridgedLangOptions(const swift::LangOptions &langOpts);

SWIFT_UNAVAILABLE("Use '.raw' instead")
BRIDGED_INLINE const swift::LangOptions &unbridged() const;

SWIFT_COMPUTED_PROPERTY
const void *_Nonnull getRaw() const { return LangOpts; }

SWIFT_COMPUTED_PROPERTY
unsigned getMajorLanguageVersion() const;

SWIFT_COMPUTED_PROPERTY
unsigned getTargetPointerBitWidth() const;

SWIFT_COMPUTED_PROPERTY
BridgedEndianness getTargetEndianness() const;

SWIFT_COMPUTED_PROPERTY
bool getAttachCommentsToDecls() const;
};

/// Key used when enumerating build configuration entries to the
/// StaticBuildConfiguration initializer for an ASTContext.
enum ENUM_EXTENSIBILITY_ATTR(closed) BuildConfigurationKey : size_t {
BCKCustomCondition,
BCKFeature,
BCKAttribute,
BCKTargetOSName,
BCKTargetArchitecture,
BCKTargetEnvironment,
BCKTargetRuntime,
BCKTargetPointerAuthenticationScheme,
BCKTargetObjectFileFormat
};

SWIFT_NAME("BridgedLangOptions.hasFeature(self:_:)")
bool BridgedLangOptions_hasFeature(BridgedLangOptions cLangOpts,
BridgedFeature feature);

SWIFT_NAME("BridgedLangOptions.getTargetAtomicBitWidths(self:_:)")
SwiftInt BridgedLangOptions_getTargetAtomicBitWidths(BridgedLangOptions cLangOpts,
SwiftInt* _Nullable * _Nonnull cComponents);

SWIFT_NAME("BridgedLangOptions.getLanguageVersion(self:_:)")
SwiftInt BridgedLangOptions_getLanguageVersion(BridgedLangOptions cLangOpts,
SwiftInt* _Nullable * _Nonnull cComponents);

SWIFT_NAME("BridgedLangOptions.getCompilerVersion(self:_:)")
SwiftInt BridgedLangOptions_getCompilerVersion(BridgedLangOptions cLangOpts,
SwiftInt* _Nullable * _Nonnull cComponents);

/* Deallocate an array of Swift int values that was allocated in C++. */
void deallocateIntBuffer(SwiftInt * _Nullable cComponents);

/// Enumerate all of the key/value pairs for the build configuration by calling
/// the given callback for each one.
SWIFT_NAME("BridgedLangOptions.enumerateBuildConfigurationEntries(self:callbackContext:callback:)")
void BridgedLangOptions_enumerateBuildConfigurationEntries(
BridgedLangOptions cLangOpts,
void * _Nonnull callbackContext,
void (* _Nonnull callback)(
BridgedLangOptions cLangOpts, void * _Nonnull callbackContext,
BuildConfigurationKey key, BridgedStringRef value));

SWIFT_END_NULLABILITY_ANNOTATIONS

#ifndef PURE_BRIDGING_MODE
Expand Down
32 changes: 32 additions & 0 deletions include/swift/Bridging/BasicSwift.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===--- BasicSwift.h -------------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 - 2025 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_BRIDGING_BASICSWIFT_H
#define SWIFT_BRIDGING_BASICSWIFT_H

#include "swift/Basic/BasicBridging.h"

#ifdef __cplusplus
extern "C" {
#endif

/// Create a new static build configuration for the given language options.
void * _Nonnull swift_Basic_createStaticBuildConfiguration(BridgedLangOptions cLangOpts);

/// Free the given static build configuration.
void swift_Basic_freeStaticBuildConfiguration(void * _Nonnull staticBuildConfiguration);

#ifdef __cplusplus
}
#endif

#endif // SWIFT_BRIDGING_BASICSWIFT_H
5 changes: 3 additions & 2 deletions include/swift/Bridging/MacroEvaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define SWIFT_BRIDGING_MACROS_H

#include "swift/Basic/BasicBridging.h"
#include "swift/AST/ASTBridging.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -40,13 +41,13 @@ void swift_Macros_freeExpansionReplacements(
ptrdiff_t *_Nullable replacementsPtr, ptrdiff_t numReplacements);

ptrdiff_t swift_Macros_expandFreestandingMacro(
void *_Nonnull diagEngine, const void *_Nonnull macro,
BridgedASTContext cContext, const void *_Nonnull macro,
const char *_Nonnull discriminator, uint8_t rawMacroRole,
void *_Nonnull sourceFile, const void *_Nullable sourceLocation,
BridgedStringRef *_Nonnull evaluatedSourceOut);

ptrdiff_t swift_Macros_expandAttachedMacro(
void *_Nonnull diagEngine, const void *_Nonnull macro,
BridgedASTContext cContext, const void *_Nonnull macro,
const char *_Nonnull discriminator, const char *_Nonnull qualifiedType,
const char *_Nonnull conformances, uint8_t rawMacroRole,
void *_Nonnull customAttrSourceFile,
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ class FrontendOptions {
/// exit.
bool PrintTargetInfo = false;

/// Indicates that the frontend should print the static build configuration
/// information as JSON.
bool PrintBuildConfig = false;

/// Indicates that the frontend should print the supported features and then
/// exit.
bool PrintSupportedFeatures = false;
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,9 @@ def target_legacy_spelling : Joined<["--"], "target=">,
def print_target_info : Flag<["-"], "print-target-info">,
Flags<[FrontendOption]>,
HelpText<"Print target information for the given target <triple>, such as x86_64-apple-macos10.9">, MetaVarName<"<triple>">;
def print_static_build_config : Flag<["-"], "print-static-build-config">,
Flags<[FrontendOption]>,
HelpText<"Print static build configuration that can be used to evaluate #ifs in Swift source code">;

def print_supported_features : Flag<["-"], "print-supported-features">,
Flags<[FrontendOption]>,
Expand Down
Loading