Skip to content

Commit 6272941

Browse files
committed
Rename "build configurations" to "conditional compilation blocks".
...because "build configuration" is already the name of an Xcode feature. - '#if' et al are "conditional compilation directives". - The condition is a "conditional compilation expression", or just "condition" if it's obvious. - The predicates are "platform conditions" (including 'swift(>=...)') - The options set with -D are "custom conditional compilation flags". (Thanks, Kevin!) I left "IfConfigDecl" as is, as well as SourceKit's various "BuildConfig" settings because some of them are part of the SourceKit request format. We can change these in follow-up commits, or not. rdar://problem/19812930
1 parent f7def54 commit 6272941

34 files changed

+328
-298
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ NOTE(opening_angle,none,
5252
ERROR(extra_rbrace,none,
5353
"extraneous '}' at top level", ())
5454

55-
ERROR(unexpected_config_block_terminator,none,
56-
"unexpected configuration block terminator", ())
57-
ERROR(expected_build_configuration_expression,none,
58-
"expected a build configuration expression to follow the #if clause", ())
59-
ERROR(extra_tokens_config_directive,none,
60-
"extra tokens at the end of the build configuration directive", ())
55+
ERROR(unexpected_conditional_compilation_block_terminator,none,
56+
"unexpected conditional compilation block terminator", ())
57+
ERROR(expected_conditional_compilation_expression,none,
58+
"expected a condition to follow %select{#if|#elseif}0", (bool))
59+
ERROR(extra_tokens_conditional_compilation_directive,none,
60+
"extra tokens following conditional compilation directive", ())
6161

6262
ERROR(unexpected_line_directive,none,
6363
"parameterless closing #line directive "
@@ -717,9 +717,9 @@ ERROR(expected_rbrace_in_brace_stmt,none,
717717
"expected '}' at end of brace statement", ())
718718

719719
/// #if Statement
720-
ERROR(expected_close_to_config_stmt,none,
721-
"expected #else or #endif at end of configuration block", ())
722-
ERROR(expected_close_after_else,none,
720+
ERROR(expected_close_to_if_directive,none,
721+
"expected #else or #endif at end of conditional compilation block", ())
722+
ERROR(expected_close_after_else_directive,none,
723723
"further conditions after #else are unreachable", ())
724724

725725
/// Associatedtype Statement
@@ -1216,31 +1216,31 @@ ERROR(late_class_requirement,none,
12161216
"'class' must come first in the requirement list", ())
12171217

12181218
//------------------------------------------------------------------------------
1219-
// Build configuration parsing diagnostics
1219+
// Conditional compilation parsing diagnostics
12201220
//------------------------------------------------------------------------------
1221-
ERROR(unsupported_build_config_binary_expression,none,
1221+
ERROR(unsupported_conditional_compilation_binary_expression,none,
12221222
"expected '&&' or '||' expression", ())
1223-
ERROR(unsupported_build_config_unary_expression,none,
1223+
ERROR(unsupported_conditional_compilation_unary_expression,none,
12241224
"expected unary '!' expression", ())
1225-
ERROR(unsupported_target_config_expression,none,
1226-
"unexpected target configuration expression (expected 'os', 'arch', or 'swift')",
1225+
ERROR(unsupported_platform_condition_expression,none,
1226+
"unexpected platform condition (expected 'os', 'arch', or 'swift')",
12271227
())
1228-
ERROR(target_config_expected_one_argument,none,
1229-
"expected only one argument to target configuration expression",
1228+
ERROR(platform_condition_expected_one_argument,none,
1229+
"expected only one argument to platform condition",
12301230
())
1231-
ERROR(unsupported_target_config_runtime_argument,none,
1232-
"unexpected argument for the '_runtime' target configuration, "
1231+
ERROR(unsupported_platform_runtime_condition_argument,none,
1232+
"unexpected argument for the '_runtime' condition; "
12331233
"expected '_Native' or '_ObjC'", ())
1234-
ERROR(unsupported_target_config_argument,none,
1235-
"unexpected target configuration argument: expected %0",
1234+
ERROR(unsupported_platform_condition_argument,none,
1235+
"unexpected platform condition argument: expected %0",
12361236
(StringRef))
12371237
ERROR(unexpected_version_comparison_operator,none,
12381238
"expected '>=' prefix operator on a version requirement",
12391239
())
1240-
ERROR(unsupported_config_conditional_expression_type,none,
1241-
"unexpected configuration expression type", ())
1242-
ERROR(unsupported_config_integer,none,
1243-
"'%0' is not a valid configuration option, use '%1'",
1240+
ERROR(unsupported_conditional_compilation_expression_type,none,
1241+
"invalid conditional compilation expression", ())
1242+
ERROR(unsupported_conditional_compilation_integer,none,
1243+
"'%0' is not a valid conditional compilation expression, use '%1'",
12441244
(StringRef, StringRef))
12451245
ERROR(version_component_not_number,none,
12461246
"version component contains non-numeric characters", ())
@@ -1255,7 +1255,7 @@ ERROR(compiler_version_component_out_of_range,none,
12551255
(unsigned))
12561256
ERROR(empty_version_string,none,
12571257
"version requirement is empty", ())
1258-
WARNING(unknown_build_config,none,
1258+
WARNING(unknown_platform_condition_argument,none,
12591259
"unknown %0 for build configuration '%1'",
12601260
(StringRef, StringRef))
12611261

include/swift/Basic/LangOptions.h

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ namespace swift {
158158
/// Enable the Swift 3 migration via Fix-Its.
159159
bool Swift3Migration = false;
160160

161-
/// Sets the target we are building for and updates configuration options
161+
/// Sets the target we are building for and updates platform conditions
162162
/// to match.
163163
///
164164
/// \returns A pair - the first element is true if the OS was invalid.
@@ -187,63 +187,58 @@ namespace swift {
187187
return clang::VersionTuple(major, minor, revision);
188188
}
189189

190-
/// Implicit target configuration options. There are currently three
191-
/// supported target configuration values:
192-
/// os - The active os target (OSX or IOS)
193-
/// arch - The active arch target (X64, I386, ARM, ARM64)
194-
/// _runtime - Runtime support (_ObjC or _Native)
195-
void addTargetConfigOption(StringRef Name, StringRef Value) {
190+
/// Sets an implicit platform condition.
191+
///
192+
/// There are currently three supported platform conditions:
193+
/// - os: The active os target (OSX or iOS)
194+
/// - arch: The active arch target (x86_64, i386, arm, arm64)
195+
/// - _runtime: Runtime support (_ObjC or _Native)
196+
void addPlatformConditionValue(StringRef Name, StringRef Value) {
196197
assert(!Name.empty() && !Value.empty());
197-
TargetConfigOptions.push_back(std::make_pair(Name, Value));
198+
PlatformConditionValues.emplace_back(Name, Value);
198199
}
199200

200-
/// Removes all configuration options added with addTargetConfigOption.
201-
void clearAllTargetConfigOptions() {
202-
TargetConfigOptions.clear();
201+
/// Removes all values added with addPlatformConditionValue.
202+
void clearAllPlatformConditionValues() {
203+
PlatformConditionValues.clear();
203204
}
204205

205-
/// Returns the value for the given target configuration or an empty string.
206-
StringRef getTargetConfigOption(StringRef Name) const;
207-
208-
/// Explicit build configuration options, initialized via the '-D'
206+
/// Returns the value for the given platform condition or an empty string.
207+
StringRef getPlatformConditionValue(StringRef Name) const;
208+
209+
/// Explicit conditional compilation flags, initialized via the '-D'
209210
/// compiler flag.
210-
void addBuildConfigOption(StringRef Name) {
211+
void addCustomConditionalCompilationFlag(StringRef Name) {
211212
assert(!Name.empty());
212-
BuildConfigOptions.push_back(Name);
213+
CustomConditionalCompilationFlags.push_back(Name);
213214
}
214215

215-
/// Determines if a given build configuration has been defined.
216-
bool hasBuildConfigOption(StringRef Name) const;
216+
/// Determines if a given conditional compilation flag has been set.
217+
bool isCustomConditionalCompilationFlagSet(StringRef Name) const;
217218

218219
ArrayRef<std::pair<std::string, std::string>>
219-
getTargetConfigOptions() const {
220-
return TargetConfigOptions;
220+
getPlatformConditionValues() const {
221+
return PlatformConditionValues;
221222
}
222223

223-
ArrayRef<std::string> getBuildConfigOptions() const {
224-
return BuildConfigOptions;
224+
ArrayRef<std::string> getCustomConditionalCompilationFlags() const {
225+
return CustomConditionalCompilationFlags;
225226
}
226227

227-
/// The constant list of supported os build configuration arguments.
228-
static const std::vector<std::string> SupportedOSBuildConfigArguments;
229-
230-
/// Returns true if the os build configuration argument represents
228+
/// Returns true if the 'os' platform condition argument represents
231229
/// a supported target operating system.
232-
static bool isOSBuildConfigSupported(StringRef OSName);
233-
234-
/// The constant list of supported arch build configuration arguments.
235-
static const std::vector<std::string> SupportedArchBuildConfigArguments;
230+
static bool isPlatformConditionOSSupported(StringRef OSName);
236231

237-
/// Returns true if the arch build configuration argument represents
232+
/// Returns true if the 'arch' platform condition argument represents
238233
/// a supported target architecture.
239-
static bool isArchBuildConfigSupported(StringRef ArchName);
234+
static bool isPlatformConditionArchSupported(StringRef ArchName);
240235

241236
private:
242-
llvm::SmallVector<std::pair<std::string, std::string>, 2>
243-
TargetConfigOptions;
244-
llvm::SmallVector<std::string, 2> BuildConfigOptions;
237+
llvm::SmallVector<std::pair<std::string, std::string>, 3>
238+
PlatformConditionValues;
239+
llvm::SmallVector<std::string, 2> CustomConditionalCompilationFlags;
245240
};
246241
}
247242

248-
#endif // LLVM_SWIFT_LANGOPTIONS_H
243+
#endif // SWIFT_LANGOPTIONS_H
249244

include/swift/Basic/Version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ class Version {
9090
return Components.empty();
9191
}
9292

93-
/// Parse a _compiler_version build configuration from source code.
93+
/// Parse a version in the form used by the _compiler_version \#if condition.
9494
static Version parseCompilerVersionString(llvm::StringRef VersionString,
95-
SourceLoc Loc,
96-
DiagnosticEngine *Diags);
95+
SourceLoc Loc,
96+
DiagnosticEngine *Diags);
9797

9898
/// Parse a generic version string of the format [0-9]+(.[0-9]+)*
9999
///

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def sdk : Separate<["-"], "sdk">, Flags<[FrontendOption]>,
131131
HelpText<"Compile against <sdk>">, MetaVarName<"<sdk>">;
132132

133133
def D : JoinedOrSeparate<["-"], "D">, Flags<[FrontendOption]>,
134-
HelpText<"Specifies one or more build configuration options">;
134+
HelpText<"Marks a conditional compilation flag as true">;
135135

136136
def F : JoinedOrSeparate<["-"], "F">, Flags<[FrontendOption]>,
137137
HelpText<"Add directory to framework search path">;

include/swift/Parse/Parser.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ namespace swift {
5959
/// The top-level of a file, when in parse-as-library mode.
6060
TopLevelLibrary,
6161
/// The body of the inactive clause of an #if/#else/#endif block
62-
InactiveConfigBlock,
62+
InactiveConditionalBlock,
6363
/// The body of the active clause of an #if/#else/#endif block
64-
ActiveConfigBlock
64+
ActiveConditionalBlock
6565
};
6666

6767

@@ -478,10 +478,10 @@ class Parser {
478478
void skipSingle();
479479

480480
/// \brief Skip until the next '#else', '#endif' or until eof.
481-
void skipUntilConfigBlockClose();
481+
void skipUntilConditionalBlockClose();
482482

483483
/// Parse an #endif.
484-
bool parseConfigEndIf(SourceLoc &Loc);
484+
bool parseEndIfDirective(SourceLoc &Loc);
485485

486486
public:
487487
InFlightDiagnostic diagnose(SourceLoc Loc, Diagnostic Diag) {
@@ -621,7 +621,7 @@ class Parser {
621621
ParserStatus parseBraceItems(SmallVectorImpl<ASTNode> &Decls,
622622
BraceItemListKind Kind =
623623
BraceItemListKind::Brace,
624-
BraceItemListKind ConfigKind =
624+
BraceItemListKind ConditionalBlockKind =
625625
BraceItemListKind::Brace);
626626
ParserResult<BraceStmt> parseBraceItemList(Diag<> ID);
627627

@@ -1088,7 +1088,7 @@ class Parser {
10881088
ParserResult<Expr> parseExprAs();
10891089
ParserResult<Expr> parseExprSequence(Diag<> ID,
10901090
bool isExprBasic,
1091-
bool isConfigCondition = false);
1091+
bool isForConditionalDirective = false);
10921092
ParserResult<Expr> parseExprSequenceElement(Diag<> ID,
10931093
bool isExprBasic);
10941094
ParserResult<Expr> parseExprPostfix(Diag<> ID, bool isExprBasic);
@@ -1204,8 +1204,9 @@ class Parser {
12041204
ParserResult<Stmt> parseStmtSwitch(LabeledStmtInfo LabelInfo);
12051205
ParserResult<CaseStmt> parseStmtCase();
12061206

1207-
/// Evaluate the conditional configuration expression of an #if statement
1208-
ConfigParserState evaluateConfigConditionExpr(Expr *configExpr);
1207+
/// Evaluate the condition of an #if directive.
1208+
ConditionalCompilationExprState
1209+
evaluateConditionalCompilationExpr(Expr *condition);
12091210

12101211
//===--------------------------------------------------------------------===//
12111212
// Generics Parsing

include/swift/Parse/ParserResult.h

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ template <typename T> ParserResult<T>::ParserResult(ParserStatus Status) {
217217
setHasCodeCompletion();
218218
}
219219

220-
enum class ConfigExprKind {
220+
enum class ConditionalCompilationExprKind {
221221
Unknown,
222222
Error,
223223
OS,
@@ -231,17 +231,20 @@ enum class ConfigExprKind {
231231
Integer
232232
};
233233

234-
class ConfigParserState {
234+
class ConditionalCompilationExprState {
235235

236-
unsigned ConditionActive : 1;
237-
ConfigExprKind Kind;
236+
uint8_t ConditionActive : 1;
237+
uint8_t Kind : 7;
238238
public:
239-
friend class ConfigParserState;
240-
241-
ConfigParserState() : ConditionActive(false), Kind(ConfigExprKind::Unknown) {}
239+
ConditionalCompilationExprState() : ConditionActive(false) {
240+
setKind(ConditionalCompilationExprKind::Unknown);
241+
}
242242

243-
ConfigParserState(bool ConditionActive, ConfigExprKind Kind)
244-
: ConditionActive(ConditionActive), Kind(Kind) {}
243+
ConditionalCompilationExprState(bool ConditionActive,
244+
ConditionalCompilationExprKind Kind)
245+
: ConditionActive(ConditionActive) {
246+
setKind(Kind);
247+
}
245248

246249
bool isConditionActive() const {
247250
return ConditionActive;
@@ -251,32 +254,36 @@ class ConfigParserState {
251254
ConditionActive = A;
252255
}
253256

254-
ConfigExprKind getKind() const {
255-
return Kind;
257+
ConditionalCompilationExprKind getKind() const {
258+
return static_cast<ConditionalCompilationExprKind>(Kind);
256259
}
257260

258-
void setKind(ConfigExprKind K) {
259-
Kind = K;
261+
void setKind(ConditionalCompilationExprKind K) {
262+
Kind = static_cast<uint8_t>(K);
263+
assert(getKind() == K);
260264
}
261265

262266
bool shouldParse() const {
263-
if (Kind == ConfigExprKind::Error)
267+
if (getKind() == ConditionalCompilationExprKind::Error)
264268
return true;
265269
return ConditionActive ||
266-
(Kind != ConfigExprKind::CompilerVersion &&
267-
Kind != ConfigExprKind::LanguageVersion);
270+
(getKind() != ConditionalCompilationExprKind::CompilerVersion &&
271+
getKind() != ConditionalCompilationExprKind::LanguageVersion);
268272
}
269273

270-
static ConfigParserState error() {
271-
return ConfigParserState(false, ConfigExprKind::Error);
274+
static ConditionalCompilationExprState error() {
275+
return {false, ConditionalCompilationExprKind::Error};
272276
}
273277
};
274278

275-
ConfigParserState operator&&(const ConfigParserState lhs,
276-
const ConfigParserState rhs);
277-
ConfigParserState operator||(const ConfigParserState lhs,
278-
const ConfigParserState rhs);
279-
ConfigParserState operator!(const ConfigParserState Result);
279+
ConditionalCompilationExprState
280+
operator&&(const ConditionalCompilationExprState lhs,
281+
const ConditionalCompilationExprState rhs);
282+
ConditionalCompilationExprState
283+
operator||(const ConditionalCompilationExprState lhs,
284+
const ConditionalCompilationExprState rhs);
285+
ConditionalCompilationExprState
286+
operator!(const ConditionalCompilationExprState Result);
280287

281288
} // namespace swift
282289

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ StringRef Decl::getDescriptiveKindName(DescriptiveDeclKind K) {
211211
ENTRY(Extension, "extension");
212212
ENTRY(EnumCase, "case");
213213
ENTRY(TopLevelCode, "top-level code");
214-
ENTRY(IfConfig, "if configuration");
214+
ENTRY(IfConfig, "conditional block");
215215
ENTRY(PatternBinding, "pattern binding");
216216
ENTRY(Var, "var");
217217
ENTRY(Param, "parameter");

0 commit comments

Comments
 (0)