mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Teach the frontend how to parse TypeCheckerOptions
This commit is contained in:
@@ -83,6 +83,7 @@ struct ModuleBuffers {
|
|||||||
/// which manages the actual compiler execution.
|
/// which manages the actual compiler execution.
|
||||||
class CompilerInvocation {
|
class CompilerInvocation {
|
||||||
LangOptions LangOpts;
|
LangOptions LangOpts;
|
||||||
|
TypeCheckerOptions TypeCheckerOpts;
|
||||||
FrontendOptions FrontendOpts;
|
FrontendOptions FrontendOpts;
|
||||||
ClangImporterOptions ClangImporterOpts;
|
ClangImporterOptions ClangImporterOpts;
|
||||||
SearchPathOptions SearchPathOpts;
|
SearchPathOptions SearchPathOpts;
|
||||||
@@ -215,6 +216,11 @@ public:
|
|||||||
return LangOpts;
|
return LangOpts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TypeCheckerOptions &getTypeCheckerOptions() { return TypeCheckerOpts; }
|
||||||
|
const TypeCheckerOptions &getTypeCheckerOptions() const {
|
||||||
|
return TypeCheckerOpts;
|
||||||
|
}
|
||||||
|
|
||||||
FrontendOptions &getFrontendOptions() { return FrontendOpts; }
|
FrontendOptions &getFrontendOptions() { return FrontendOpts; }
|
||||||
const FrontendOptions &getFrontendOptions() const { return FrontendOpts; }
|
const FrontendOptions &getFrontendOptions() const { return FrontendOpts; }
|
||||||
|
|
||||||
@@ -648,14 +654,11 @@ private:
|
|||||||
bool
|
bool
|
||||||
parsePartialModulesAndLibraryFiles(const ImplicitImports &implicitImports);
|
parsePartialModulesAndLibraryFiles(const ImplicitImports &implicitImports);
|
||||||
|
|
||||||
OptionSet<TypeCheckingFlags> computeTypeCheckingOptions();
|
|
||||||
|
|
||||||
void forEachFileToTypeCheck(llvm::function_ref<void(SourceFile &)> fn);
|
void forEachFileToTypeCheck(llvm::function_ref<void(SourceFile &)> fn);
|
||||||
|
|
||||||
void parseAndTypeCheckMainFileUpTo(SourceFile::ASTStage_t LimitStage,
|
void parseAndTypeCheckMainFileUpTo(SourceFile::ASTStage_t LimitStage);
|
||||||
OptionSet<TypeCheckingFlags> TypeCheckOptions);
|
|
||||||
|
|
||||||
void finishTypeChecking(OptionSet<TypeCheckingFlags> TypeCheckOptions);
|
void finishTypeChecking();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const PrimarySpecificPaths &
|
const PrimarySpecificPaths &
|
||||||
|
|||||||
@@ -90,15 +90,6 @@ bool ArgsToFrontendOptionsConverter::convert(
|
|||||||
computeDebugTimeOptions();
|
computeDebugTimeOptions();
|
||||||
computeTBDOptions();
|
computeTBDOptions();
|
||||||
|
|
||||||
setUnsignedIntegerArgument(OPT_warn_long_function_bodies, 10,
|
|
||||||
Opts.WarnLongFunctionBodies);
|
|
||||||
setUnsignedIntegerArgument(OPT_warn_long_expression_type_checking, 10,
|
|
||||||
Opts.WarnLongExpressionTypeChecking);
|
|
||||||
setUnsignedIntegerArgument(OPT_solver_expression_time_threshold_EQ, 10,
|
|
||||||
Opts.SolverExpressionTimeThreshold);
|
|
||||||
setUnsignedIntegerArgument(OPT_switch_checking_invocation_threshold_EQ, 10,
|
|
||||||
Opts.SwitchCheckingInvocationThreshold);
|
|
||||||
|
|
||||||
Opts.CheckOnoneSupportCompleteness = Args.hasArg(OPT_check_onone_completeness);
|
Opts.CheckOnoneSupportCompleteness = Args.hasArg(OPT_check_onone_completeness);
|
||||||
|
|
||||||
Opts.DebuggerTestingTransform = Args.hasArg(OPT_debugger_testing_transform);
|
Opts.DebuggerTestingTransform = Args.hasArg(OPT_debugger_testing_transform);
|
||||||
@@ -163,7 +154,7 @@ bool ArgsToFrontendOptionsConverter::convert(
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (FrontendOptions::doesActionGenerateIR(Opts.RequestedAction)
|
if (FrontendOptions::doesActionGenerateIR(Opts.RequestedAction)
|
||||||
&& Opts.SkipNonInlinableFunctionBodies) {
|
&& Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies)) {
|
||||||
Diags.diagnose(SourceLoc(), diag::cannot_emit_ir_skipping_function_bodies);
|
Diags.diagnose(SourceLoc(), diag::cannot_emit_ir_skipping_function_bodies);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -222,17 +213,7 @@ void ArgsToFrontendOptionsConverter::computePrintStatsOptions() {
|
|||||||
|
|
||||||
void ArgsToFrontendOptionsConverter::computeDebugTimeOptions() {
|
void ArgsToFrontendOptionsConverter::computeDebugTimeOptions() {
|
||||||
using namespace options;
|
using namespace options;
|
||||||
Opts.DebugTimeFunctionBodies |= Args.hasArg(OPT_debug_time_function_bodies);
|
|
||||||
Opts.DebugTimeExpressionTypeChecking |=
|
|
||||||
Args.hasArg(OPT_debug_time_expression_type_checking);
|
|
||||||
Opts.DebugTimeCompilation |= Args.hasArg(OPT_debug_time_compilation);
|
Opts.DebugTimeCompilation |= Args.hasArg(OPT_debug_time_compilation);
|
||||||
Opts.SkipNonInlinableFunctionBodies |=
|
|
||||||
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies);
|
|
||||||
|
|
||||||
// If asked to perform InstallAPI, go ahead and enable non-inlinable function
|
|
||||||
// body skipping.
|
|
||||||
Opts.SkipNonInlinableFunctionBodies |=
|
|
||||||
Args.hasArg(OPT_tbd_is_installapi);
|
|
||||||
|
|
||||||
if (const Arg *A = Args.getLastArg(OPT_stats_output_dir)) {
|
if (const Arg *A = Args.getLastArg(OPT_stats_output_dir)) {
|
||||||
Opts.StatsOutputDir = A->getValue();
|
Opts.StatsOutputDir = A->getValue();
|
||||||
@@ -266,19 +247,6 @@ void ArgsToFrontendOptionsConverter::computeTBDOptions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsToFrontendOptionsConverter::setUnsignedIntegerArgument(
|
|
||||||
options::ID optionID, unsigned radix, unsigned &valueToSet) {
|
|
||||||
if (const Arg *A = Args.getLastArg(optionID)) {
|
|
||||||
unsigned attempt;
|
|
||||||
if (StringRef(A->getValue()).getAsInteger(radix, attempt)) {
|
|
||||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
|
||||||
A->getAsString(Args), A->getValue());
|
|
||||||
} else {
|
|
||||||
valueToSet = attempt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArgsToFrontendOptionsConverter::computePlaygroundOptions() {
|
void ArgsToFrontendOptionsConverter::computePlaygroundOptions() {
|
||||||
using namespace options;
|
using namespace options;
|
||||||
Opts.PlaygroundTransform |= Args.hasArg(OPT_playground);
|
Opts.PlaygroundTransform |= Args.hasArg(OPT_playground);
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ private:
|
|||||||
void computePrintStatsOptions();
|
void computePrintStatsOptions();
|
||||||
void computeTBDOptions();
|
void computeTBDOptions();
|
||||||
|
|
||||||
void setUnsignedIntegerArgument(options::ID optionID, unsigned radix,
|
|
||||||
unsigned &valueToSet);
|
|
||||||
|
|
||||||
bool setUpInputKindAndImmediateArgs();
|
bool setUpInputKindAndImmediateArgs();
|
||||||
|
|
||||||
bool checkUnusedSupplementaryOutputPaths() const;
|
bool checkUnusedSupplementaryOutputPaths() const;
|
||||||
|
|||||||
@@ -552,6 +552,46 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
|||||||
return HadError || UnsupportedOS || UnsupportedArch;
|
return HadError || UnsupportedOS || UnsupportedArch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
|
||||||
|
DiagnosticEngine &Diags,
|
||||||
|
const FrontendOptions &FrontendOpts) {
|
||||||
|
using namespace options;
|
||||||
|
|
||||||
|
auto setUnsignedIntegerArgument = [&Args, &Diags](
|
||||||
|
options::ID optionID, unsigned radix, unsigned &valueToSet) {
|
||||||
|
if (const Arg *A = Args.getLastArg(optionID)) {
|
||||||
|
unsigned attempt;
|
||||||
|
if (StringRef(A->getValue()).getAsInteger(radix, attempt)) {
|
||||||
|
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||||
|
A->getAsString(Args), A->getValue());
|
||||||
|
} else {
|
||||||
|
valueToSet = attempt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setUnsignedIntegerArgument(OPT_warn_long_function_bodies, 10,
|
||||||
|
Opts.WarnLongFunctionBodies);
|
||||||
|
setUnsignedIntegerArgument(OPT_warn_long_expression_type_checking, 10,
|
||||||
|
Opts.WarnLongExpressionTypeChecking);
|
||||||
|
setUnsignedIntegerArgument(OPT_solver_expression_time_threshold_EQ, 10,
|
||||||
|
Opts.ExpressionTimeoutThreshold);
|
||||||
|
setUnsignedIntegerArgument(OPT_switch_checking_invocation_threshold_EQ, 10,
|
||||||
|
Opts.SwitchCheckingInvocationThreshold);
|
||||||
|
|
||||||
|
Opts.DebugTimeFunctionBodies |= Args.hasArg(OPT_debug_time_function_bodies);
|
||||||
|
Opts.DebugTimeExpressions |=
|
||||||
|
Args.hasArg(OPT_debug_time_expression_type_checking);
|
||||||
|
Opts.SkipNonInlinableFunctionBodies |=
|
||||||
|
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies);
|
||||||
|
|
||||||
|
// If asked to perform InstallAPI, go ahead and enable non-inlinable function
|
||||||
|
// body skipping.
|
||||||
|
Opts.SkipNonInlinableFunctionBodies |= Args.hasArg(OPT_tbd_is_installapi);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
|
static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
|
||||||
ArgList &Args,
|
ArgList &Args,
|
||||||
DiagnosticEngine &Diags,
|
DiagnosticEngine &Diags,
|
||||||
@@ -1384,6 +1424,10 @@ bool CompilerInvocation::parseArgs(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ParseTypeCheckerArgs(TypeCheckerOpts, ParsedArgs, Diags, FrontendOpts)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (ParseClangImporterArgs(ClangImporterOpts, ParsedArgs, Diags,
|
if (ParseClangImporterArgs(ClangImporterOpts, ParsedArgs, Diags,
|
||||||
workingDirectory)) {
|
workingDirectory)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user