Skip to content

Commit fef8782

Browse files
authored
Merge pull request #75014 from DougGregor/swiftifconfig-build-configuration
2 parents d5d9338 + cfd0a3f commit fef8782

File tree

14 files changed

+703
-93
lines changed

14 files changed

+703
-93
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/Attr.h"
2727
#include "swift/AST/DiagnosticConsumer.h"
2828
#include "swift/AST/DiagnosticEngine.h"
29+
#include "swift/AST/IfConfigClauseRangeInfo.h"
2930
#include "swift/AST/Stmt.h"
3031
#endif
3132

@@ -190,6 +191,75 @@ bool BridgedASTContext_langOptsHasFeature(BridgedASTContext cContext,
190191
SWIFT_NAME("getter:BridgedASTContext.majorLanguageVersion(self:)")
191192
unsigned BridgedASTContext_majorLanguageVersion(BridgedASTContext cContext);
192193

194+
SWIFT_NAME("BridgedASTContext.langOptsCustomConditionSet(self:_:)")
195+
bool BridgedASTContext_langOptsCustomConditionSet(BridgedASTContext cContext,
196+
BridgedStringRef cName);
197+
198+
SWIFT_NAME("BridgedASTContext.langOptsHasFeatureNamed(self:_:)")
199+
bool BridgedASTContext_langOptsHasFeatureNamed(BridgedASTContext cContext,
200+
BridgedStringRef cName);
201+
202+
SWIFT_NAME("BridgedASTContext.langOptsHasAttributeNamed(self:_:)")
203+
bool BridgedASTContext_langOptsHasAttributeNamed(BridgedASTContext cContext,
204+
BridgedStringRef cName);
205+
206+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetOS(self:_:)")
207+
bool BridgedASTContext_langOptsIsActiveTargetOS(BridgedASTContext cContext,
208+
BridgedStringRef cName);
209+
210+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetArchitecture(self:_:)")
211+
bool BridgedASTContext_langOptsIsActiveTargetArchitecture(BridgedASTContext cContext,
212+
BridgedStringRef cName);
213+
214+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetEnvironment(self:_:)")
215+
bool BridgedASTContext_langOptsIsActiveTargetEnvironment(BridgedASTContext cContext,
216+
BridgedStringRef cName);
217+
218+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetRuntime(self:_:)")
219+
bool BridgedASTContext_langOptsIsActiveTargetRuntime(BridgedASTContext cContext,
220+
BridgedStringRef cName);
221+
222+
SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetPtrAuth(self:_:)")
223+
bool BridgedASTContext_langOptsIsActiveTargetPtrAuth(BridgedASTContext cContext,
224+
BridgedStringRef cName);
225+
226+
SWIFT_NAME("getter:BridgedASTContext.langOptsTargetPointerBitWidth(self:)")
227+
unsigned BridgedASTContext_langOptsTargetPointerBitWidth(BridgedASTContext cContext);
228+
229+
SWIFT_NAME("BridgedASTContext.langOptsGetTargetAtomicBitWidths(self:_:)")
230+
SwiftInt BridgedASTContext_langOptsGetTargetAtomicBitWidths(BridgedASTContext cContext,
231+
SwiftInt* _Nullable * _Nonnull cComponents);
232+
233+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedEndianness : size_t {
234+
EndianLittle,
235+
EndianBig,
236+
};
237+
238+
SWIFT_NAME("getter:BridgedASTContext.langOptsTargetEndianness(self:)")
239+
BridgedEndianness BridgedASTContext_langOptsTargetEndianness(BridgedASTContext cContext);
240+
241+
SWIFT_NAME("BridgedASTContext.langOptsGetLanguageVersion(self:_:)")
242+
SwiftInt BridgedASTContext_langOptsGetLanguageVersion(BridgedASTContext cContext,
243+
SwiftInt* _Nullable * _Nonnull cComponents);
244+
245+
SWIFT_NAME("BridgedASTContext.langOptsGetCompilerVersion(self:_:)")
246+
SwiftInt BridgedASTContext_langOptsGetCompilerVersion(BridgedASTContext cContext,
247+
SwiftInt* _Nullable * _Nonnull cComponents);
248+
249+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedCanImportVersion : size_t {
250+
CanImportUnversioned,
251+
CanImportVersion,
252+
CanImportUnderlyingVersion,
253+
};
254+
255+
SWIFT_NAME("BridgedASTContext.canImport(self:importPath:location:versionKind:versionComponents:numVersionComponents:)")
256+
bool BridgedASTContext_canImport(BridgedASTContext cContext,
257+
BridgedStringRef importPath,
258+
BridgedSourceLoc canImportLoc,
259+
BridgedCanImportVersion versionKind,
260+
const SwiftInt * _Nullable versionComponents,
261+
SwiftInt numVersionComponents);
262+
193263
//===----------------------------------------------------------------------===//
194264
// MARK: AST nodes
195265
//===----------------------------------------------------------------------===//
@@ -1844,6 +1914,49 @@ BridgedParameterList BridgedParameterList_createParsed(
18441914
BridgedASTContext cContext, BridgedSourceLoc cLeftParenLoc,
18451915
BridgedArrayRef cParameters, BridgedSourceLoc cRightParenLoc);
18461916

1917+
//===----------------------------------------------------------------------===//
1918+
// MARK: #if handling
1919+
//===----------------------------------------------------------------------===//
1920+
1921+
/// Bridged version of IfConfigClauseRangeInfo::ClauseKind.
1922+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedIfConfigClauseKind : size_t {
1923+
IfConfigActive,
1924+
IfConfigInactive,
1925+
IfConfigEnd
1926+
};
1927+
1928+
/// Bridged version of IfConfigClauseRangeInfo.
1929+
struct BridgedIfConfigClauseRangeInfo {
1930+
BridgedSourceLoc directiveLoc;
1931+
BridgedSourceLoc bodyLoc;
1932+
BridgedSourceLoc endLoc;
1933+
BridgedIfConfigClauseKind kind;
1934+
1935+
#ifdef USED_IN_CPP_SOURCE
1936+
swift::IfConfigClauseRangeInfo unbridged() const {
1937+
swift::IfConfigClauseRangeInfo::ClauseKind clauseKind;
1938+
switch (kind) {
1939+
case IfConfigActive:
1940+
clauseKind = swift::IfConfigClauseRangeInfo::ActiveClause;
1941+
break;
1942+
1943+
case IfConfigInactive:
1944+
clauseKind = swift::IfConfigClauseRangeInfo::InactiveClause;
1945+
break;
1946+
1947+
case IfConfigEnd:
1948+
clauseKind = swift::IfConfigClauseRangeInfo::EndDirective;
1949+
break;
1950+
}
1951+
1952+
return swift::IfConfigClauseRangeInfo(directiveLoc.unbridged(),
1953+
bodyLoc.unbridged(),
1954+
endLoc.unbridged(),
1955+
clauseKind);
1956+
}
1957+
#endif
1958+
};
1959+
18471960
//===----------------------------------------------------------------------===//
18481961
// MARK: Plugins
18491962
//===----------------------------------------------------------------------===//
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//===--- IfConfigClauseRangeInfo.h - header for #if clauses -=====---------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_AST_IFCONFIGCLAUSERANGEINFO_H
14+
#define SWIFT_AST_IFCONFIGCLAUSERANGEINFO_H
15+
16+
#include "swift/Basic/SourceLoc.h"
17+
18+
namespace swift {
19+
20+
class SourceManager;
21+
22+
/// Stores range information for a \c #if block in a SourceFile.
23+
class IfConfigClauseRangeInfo final {
24+
public:
25+
enum ClauseKind {
26+
// Active '#if', '#elseif', or '#else' clause.
27+
ActiveClause,
28+
// Inactive '#if', '#elseif', or '#else' clause.
29+
InactiveClause,
30+
// '#endif' directive.
31+
EndDirective,
32+
};
33+
34+
private:
35+
/// Source location of '#if', '#elseif', etc.
36+
SourceLoc DirectiveLoc;
37+
/// Character source location of body starts.
38+
SourceLoc BodyLoc;
39+
/// Location of the end of the body.
40+
SourceLoc EndLoc;
41+
42+
ClauseKind Kind;
43+
44+
public:
45+
IfConfigClauseRangeInfo(SourceLoc DirectiveLoc, SourceLoc BodyLoc,
46+
SourceLoc EndLoc, ClauseKind Kind)
47+
: DirectiveLoc(DirectiveLoc), BodyLoc(BodyLoc), EndLoc(EndLoc),
48+
Kind(Kind) {
49+
assert(DirectiveLoc.isValid() && BodyLoc.isValid() && EndLoc.isValid());
50+
}
51+
52+
SourceLoc getStartLoc() const { return DirectiveLoc; }
53+
CharSourceRange getDirectiveRange(const SourceManager &SM) const;
54+
CharSourceRange getWholeRange(const SourceManager &SM) const;
55+
CharSourceRange getBodyRange(const SourceManager &SM) const;
56+
57+
ClauseKind getKind() const { return Kind; }
58+
};
59+
60+
}
61+
62+
#endif /* SWIFT_AST_IFCONFIGCLAUSERANGEINFO_H */

include/swift/AST/SourceFile.h

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/AST/ASTNode.h"
1717
#include "swift/AST/FileUnit.h"
18+
#include "swift/AST/IfConfigClauseRangeInfo.h"
1819
#include "swift/AST/Import.h"
1920
#include "swift/AST/SynthesizedFileUnit.h"
2021
#include "swift/Basic/Debug.h"
@@ -48,44 +49,6 @@ enum class RestrictedImportKind {
4849
/// Import that limits the access level of imported entities.
4950
using ImportAccessLevel = std::optional<AttributedImport<ImportedModule>>;
5051

51-
/// Stores range information for a \c #if block in a SourceFile.
52-
class IfConfigClauseRangeInfo final {
53-
public:
54-
enum ClauseKind {
55-
// Active '#if', '#elseif', or '#else' clause.
56-
ActiveClause,
57-
// Inactive '#if', '#elseif', or '#else' clause.
58-
InactiveClause,
59-
// '#endif' directive.
60-
EndDirective,
61-
};
62-
63-
private:
64-
/// Source location of '#if', '#elseif', etc.
65-
SourceLoc DirectiveLoc;
66-
/// Character source location of body starts.
67-
SourceLoc BodyLoc;
68-
/// Location of the end of the body.
69-
SourceLoc EndLoc;
70-
71-
ClauseKind Kind;
72-
73-
public:
74-
IfConfigClauseRangeInfo(SourceLoc DirectiveLoc, SourceLoc BodyLoc,
75-
SourceLoc EndLoc, ClauseKind Kind)
76-
: DirectiveLoc(DirectiveLoc), BodyLoc(BodyLoc), EndLoc(EndLoc),
77-
Kind(Kind) {
78-
assert(DirectiveLoc.isValid() && BodyLoc.isValid() && EndLoc.isValid());
79-
}
80-
81-
SourceLoc getStartLoc() const { return DirectiveLoc; }
82-
CharSourceRange getDirectiveRange(const SourceManager &SM) const;
83-
CharSourceRange getWholeRange(const SourceManager &SM) const;
84-
CharSourceRange getBodyRange(const SourceManager &SM) const;
85-
86-
ClauseKind getKind() const { return Kind; }
87-
};
88-
8952
/// A file containing Swift source code.
9053
///
9154
/// This is a .swift or .sil file (or a virtual file, such as the contents of

include/swift/Basic/LangOptions.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,18 +734,23 @@ namespace swift {
734734
switch (maxWidth) {
735735
case 128:
736736
AtomicBitWidths.emplace_back("_128");
737+
AtomicBitWidthValues.push_back(128);
737738
LLVM_FALLTHROUGH;
738739
case 64:
739740
AtomicBitWidths.emplace_back("_64");
741+
AtomicBitWidthValues.push_back(64);
740742
LLVM_FALLTHROUGH;
741743
case 32:
742744
AtomicBitWidths.emplace_back("_32");
745+
AtomicBitWidthValues.push_back(32);
743746
LLVM_FALLTHROUGH;
744747
case 16:
745748
AtomicBitWidths.emplace_back("_16");
749+
AtomicBitWidthValues.push_back(16);
746750
LLVM_FALLTHROUGH;
747751
case 8:
748752
AtomicBitWidths.emplace_back("_8");
753+
AtomicBitWidthValues.push_back(8);
749754
break;
750755
default:
751756
return;
@@ -755,6 +760,11 @@ namespace swift {
755760
/// Removes all atomic bit widths.
756761
void clearAtomicBitWidths() {
757762
AtomicBitWidths.clear();
763+
AtomicBitWidthValues.clear();
764+
}
765+
766+
llvm::ArrayRef<unsigned> getAtomicBitWidthValues() const {
767+
return AtomicBitWidthValues;
758768
}
759769

760770
/// Returns true if the given platform condition argument represents
@@ -795,6 +805,7 @@ namespace swift {
795805

796806
private:
797807
llvm::SmallVector<std::string, 2> AtomicBitWidths;
808+
llvm::SmallVector<unsigned, 2> AtomicBitWidthValues;
798809
llvm::SmallVector<std::pair<PlatformConditionKind, std::string>, 10>
799810
PlatformConditionValues;
800811
llvm::SmallVector<std::string, 2> CustomConditionalCompilationFlags;

include/swift/Bridging/ASTGen.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ bool swift_ASTGen_parseRegexLiteral(BridgedStringRef inputPtr,
151151
BridgedSourceLoc diagLoc,
152152
BridgedDiagnosticEngine diagEngine);
153153

154+
intptr_t swift_ASTGen_configuredRegions(
155+
BridgedASTContext astContext,
156+
void *_Nonnull sourceFile,
157+
BridgedIfConfigClauseRangeInfo *_Nullable *_Nonnull);
158+
void swift_ASTGen_freeConfiguredRegions(
159+
BridgedIfConfigClauseRangeInfo *_Nullable regions, intptr_t numRegions);
160+
154161
#ifdef __cplusplus
155162
}
156163
#endif

0 commit comments

Comments
 (0)