Skip to content

Rename "build configurations" to "conditional compilation blocks". #1289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
50 changes: 25 additions & 25 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ NOTE(opening_angle,none,
ERROR(extra_rbrace,none,
"extraneous '}' at top level", ())

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

ERROR(unexpected_line_directive,none,
"parameterless closing #line directive "
Expand Down Expand Up @@ -717,9 +717,9 @@ ERROR(expected_rbrace_in_brace_stmt,none,
"expected '}' at end of brace statement", ())

/// #if Statement
ERROR(expected_close_to_config_stmt,none,
"expected #else or #endif at end of configuration block", ())
ERROR(expected_close_after_else,none,
ERROR(expected_close_to_if_directive,none,
"expected #else or #endif at end of conditional compilation block", ())
ERROR(expected_close_after_else_directive,none,
"further conditions after #else are unreachable", ())

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

//------------------------------------------------------------------------------
// Build configuration parsing diagnostics
// Conditional compilation parsing diagnostics
//------------------------------------------------------------------------------
ERROR(unsupported_build_config_binary_expression,none,
ERROR(unsupported_conditional_compilation_binary_expression,none,
"expected '&&' or '||' expression", ())
ERROR(unsupported_build_config_unary_expression,none,
ERROR(unsupported_conditional_compilation_unary_expression,none,
"expected unary '!' expression", ())
ERROR(unsupported_target_config_expression,none,
"unexpected target configuration expression (expected 'os', 'arch', or 'swift')",
ERROR(unsupported_platform_condition_expression,none,
"unexpected platform condition (expected 'os', 'arch', or 'swift')",
())
ERROR(target_config_expected_one_argument,none,
"expected only one argument to target configuration expression",
ERROR(platform_condition_expected_one_argument,none,
"expected only one argument to platform condition",
())
ERROR(unsupported_target_config_runtime_argument,none,
"unexpected argument for the '_runtime' target configuration, "
ERROR(unsupported_platform_runtime_condition_argument,none,
"unexpected argument for the '_runtime' condition; "
"expected '_Native' or '_ObjC'", ())
ERROR(unsupported_target_config_argument,none,
"unexpected target configuration argument: expected %0",
ERROR(unsupported_platform_condition_argument,none,
"unexpected platform condition argument: expected %0",
(StringRef))
ERROR(unexpected_version_comparison_operator,none,
"expected '>=' prefix operator on a version requirement",
())
ERROR(unsupported_config_conditional_expression_type,none,
"unexpected configuration expression type", ())
ERROR(unsupported_config_integer,none,
"'%0' is not a valid configuration option, use '%1'",
ERROR(unsupported_conditional_compilation_expression_type,none,
"invalid conditional compilation expression", ())
ERROR(unsupported_conditional_compilation_integer,none,
"'%0' is not a valid conditional compilation expression, use '%1'",
(StringRef, StringRef))
ERROR(version_component_not_number,none,
"version component contains non-numeric characters", ())
Expand All @@ -1255,7 +1255,7 @@ ERROR(compiler_version_component_out_of_range,none,
(unsigned))
ERROR(empty_version_string,none,
"version requirement is empty", ())
WARNING(unknown_build_config,none,
WARNING(unknown_platform_condition_argument,none,
"unknown %0 for build configuration '%1'",
(StringRef, StringRef))

Expand Down
69 changes: 32 additions & 37 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace swift {
/// Enable the Swift 3 migration via Fix-Its.
bool Swift3Migration = false;

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

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

/// Removes all configuration options added with addTargetConfigOption.
void clearAllTargetConfigOptions() {
TargetConfigOptions.clear();
/// Removes all values added with addPlatformConditionValue.
void clearAllPlatformConditionValues() {
PlatformConditionValues.clear();
}

/// Returns the value for the given target configuration or an empty string.
StringRef getTargetConfigOption(StringRef Name) const;
/// Explicit build configuration options, initialized via the '-D'
/// Returns the value for the given platform condition or an empty string.
StringRef getPlatformConditionValue(StringRef Name) const;

/// Explicit conditional compilation flags, initialized via the '-D'
/// compiler flag.
void addBuildConfigOption(StringRef Name) {
void addCustomConditionalCompilationFlag(StringRef Name) {
assert(!Name.empty());
BuildConfigOptions.push_back(Name);
CustomConditionalCompilationFlags.push_back(Name);
}

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

ArrayRef<std::pair<std::string, std::string>>
getTargetConfigOptions() const {
return TargetConfigOptions;
getPlatformConditionValues() const {
return PlatformConditionValues;
}

ArrayRef<std::string> getBuildConfigOptions() const {
return BuildConfigOptions;
ArrayRef<std::string> getCustomConditionalCompilationFlags() const {
return CustomConditionalCompilationFlags;
}

/// The constant list of supported os build configuration arguments.
static const std::vector<std::string> SupportedOSBuildConfigArguments;

/// Returns true if the os build configuration argument represents
/// Returns true if the 'os' platform condition argument represents
/// a supported target operating system.
static bool isOSBuildConfigSupported(StringRef OSName);

/// The constant list of supported arch build configuration arguments.
static const std::vector<std::string> SupportedArchBuildConfigArguments;
static bool isPlatformConditionOSSupported(StringRef OSName);

/// Returns true if the arch build configuration argument represents
/// Returns true if the 'arch' platform condition argument represents
/// a supported target architecture.
static bool isArchBuildConfigSupported(StringRef ArchName);
static bool isPlatformConditionArchSupported(StringRef ArchName);

private:
llvm::SmallVector<std::pair<std::string, std::string>, 2>
TargetConfigOptions;
llvm::SmallVector<std::string, 2> BuildConfigOptions;
llvm::SmallVector<std::pair<std::string, std::string>, 3>
PlatformConditionValues;
llvm::SmallVector<std::string, 2> CustomConditionalCompilationFlags;
};
}

#endif // LLVM_SWIFT_LANGOPTIONS_H
#endif // SWIFT_LANGOPTIONS_H

6 changes: 3 additions & 3 deletions include/swift/Basic/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ class Version {
return Components.empty();
}

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

/// Parse a generic version string of the format [0-9]+(.[0-9]+)*
///
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def sdk : Separate<["-"], "sdk">, Flags<[FrontendOption]>,
HelpText<"Compile against <sdk>">, MetaVarName<"<sdk>">;

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

def F : JoinedOrSeparate<["-"], "F">, Flags<[FrontendOption]>,
HelpText<"Add directory to framework search path">;
Expand Down
17 changes: 9 additions & 8 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ namespace swift {
/// The top-level of a file, when in parse-as-library mode.
TopLevelLibrary,
/// The body of the inactive clause of an #if/#else/#endif block
InactiveConfigBlock,
InactiveConditionalBlock,
/// The body of the active clause of an #if/#else/#endif block
ActiveConfigBlock
ActiveConditionalBlock
};


Expand Down Expand Up @@ -478,10 +478,10 @@ class Parser {
void skipSingle();

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

/// Parse an #endif.
bool parseConfigEndIf(SourceLoc &Loc);
bool parseEndIfDirective(SourceLoc &Loc);

public:
InFlightDiagnostic diagnose(SourceLoc Loc, Diagnostic Diag) {
Expand Down Expand Up @@ -621,7 +621,7 @@ class Parser {
ParserStatus parseBraceItems(SmallVectorImpl<ASTNode> &Decls,
BraceItemListKind Kind =
BraceItemListKind::Brace,
BraceItemListKind ConfigKind =
BraceItemListKind ConditionalBlockKind =
BraceItemListKind::Brace);
ParserResult<BraceStmt> parseBraceItemList(Diag<> ID);

Expand Down Expand Up @@ -1088,7 +1088,7 @@ class Parser {
ParserResult<Expr> parseExprAs();
ParserResult<Expr> parseExprSequence(Diag<> ID,
bool isExprBasic,
bool isConfigCondition = false);
bool isForConditionalDirective = false);
ParserResult<Expr> parseExprSequenceElement(Diag<> ID,
bool isExprBasic);
ParserResult<Expr> parseExprPostfix(Diag<> ID, bool isExprBasic);
Expand Down Expand Up @@ -1204,8 +1204,9 @@ class Parser {
ParserResult<Stmt> parseStmtSwitch(LabeledStmtInfo LabelInfo);
ParserResult<CaseStmt> parseStmtCase();

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

//===--------------------------------------------------------------------===//
// Generics Parsing
Expand Down
53 changes: 30 additions & 23 deletions include/swift/Parse/ParserResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ template <typename T> ParserResult<T>::ParserResult(ParserStatus Status) {
setHasCodeCompletion();
}

enum class ConfigExprKind {
enum class ConditionalCompilationExprKind {
Unknown,
Error,
OS,
Expand All @@ -231,17 +231,20 @@ enum class ConfigExprKind {
Integer
};

class ConfigParserState {
class ConditionalCompilationExprState {

unsigned ConditionActive : 1;
ConfigExprKind Kind;
uint8_t ConditionActive : 1;
uint8_t Kind : 7;
public:
friend class ConfigParserState;

ConfigParserState() : ConditionActive(false), Kind(ConfigExprKind::Unknown) {}
ConditionalCompilationExprState() : ConditionActive(false) {
setKind(ConditionalCompilationExprKind::Unknown);
}

ConfigParserState(bool ConditionActive, ConfigExprKind Kind)
: ConditionActive(ConditionActive), Kind(Kind) {}
ConditionalCompilationExprState(bool ConditionActive,
ConditionalCompilationExprKind Kind)
: ConditionActive(ConditionActive) {
setKind(Kind);
}

bool isConditionActive() const {
return ConditionActive;
Expand All @@ -251,32 +254,36 @@ class ConfigParserState {
ConditionActive = A;
}

ConfigExprKind getKind() const {
return Kind;
ConditionalCompilationExprKind getKind() const {
return static_cast<ConditionalCompilationExprKind>(Kind);
}

void setKind(ConfigExprKind K) {
Kind = K;
void setKind(ConditionalCompilationExprKind K) {
Kind = static_cast<uint8_t>(K);
assert(getKind() == K);
}

bool shouldParse() const {
if (Kind == ConfigExprKind::Error)
if (getKind() == ConditionalCompilationExprKind::Error)
return true;
return ConditionActive ||
(Kind != ConfigExprKind::CompilerVersion &&
Kind != ConfigExprKind::LanguageVersion);
(getKind() != ConditionalCompilationExprKind::CompilerVersion &&
getKind() != ConditionalCompilationExprKind::LanguageVersion);
}

static ConfigParserState error() {
return ConfigParserState(false, ConfigExprKind::Error);
static ConditionalCompilationExprState error() {
return {false, ConditionalCompilationExprKind::Error};
}
};

ConfigParserState operator&&(const ConfigParserState lhs,
const ConfigParserState rhs);
ConfigParserState operator||(const ConfigParserState lhs,
const ConfigParserState rhs);
ConfigParserState operator!(const ConfigParserState Result);
ConditionalCompilationExprState
operator&&(const ConditionalCompilationExprState lhs,
const ConditionalCompilationExprState rhs);
ConditionalCompilationExprState
operator||(const ConditionalCompilationExprState lhs,
const ConditionalCompilationExprState rhs);
ConditionalCompilationExprState
operator!(const ConditionalCompilationExprState Result);

} // namespace swift

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ StringRef Decl::getDescriptiveKindName(DescriptiveDeclKind K) {
ENTRY(Extension, "extension");
ENTRY(EnumCase, "case");
ENTRY(TopLevelCode, "top-level code");
ENTRY(IfConfig, "if configuration");
ENTRY(IfConfig, "conditional block");
ENTRY(PatternBinding, "pattern binding");
ENTRY(Var, "var");
ENTRY(Param, "parameter");
Expand Down
Loading