mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Macros] Add a flag -dump-macro-expansions as a debugging aid.
This commit is contained in:
@@ -528,6 +528,9 @@ namespace swift {
|
||||
/// Enables dumping type witness systems from associated type inference.
|
||||
bool DumpTypeWitnessSystems = false;
|
||||
|
||||
/// Enables dumping macro expansions.
|
||||
bool DumpMacroExpansions = false;
|
||||
|
||||
/// The model of concurrency to be used.
|
||||
ConcurrencyModel ActiveConcurrencyModel = ConcurrencyModel::Standard;
|
||||
|
||||
|
||||
@@ -343,6 +343,9 @@ def dump_requirement_machine : Flag<["-"], "dump-requirement-machine">,
|
||||
def debug_requirement_machine : Joined<["-"], "debug-requirement-machine=">,
|
||||
HelpText<"Fine-grained debug output from the generics implementation">;
|
||||
|
||||
def dump_macro_expansions : Flag<["-"], "dump-macro-expansions">,
|
||||
HelpText<"Dumps the results of each macro expansion">;
|
||||
|
||||
def analyze_requirement_machine : Flag<["-"], "analyze-requirement-machine">,
|
||||
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
|
||||
HelpText<"Print out requirement machine statistics at the end of the compilation job">;
|
||||
|
||||
@@ -1042,6 +1042,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
Opts.AnalyzeRequirementMachine = Args.hasArg(
|
||||
OPT_analyze_requirement_machine);
|
||||
|
||||
Opts.DumpMacroExpansions = Args.hasArg(
|
||||
OPT_dump_macro_expansions);
|
||||
|
||||
if (const Arg *A = Args.getLastArg(OPT_debug_requirement_machine))
|
||||
Opts.DebugRequirementMachine = A->getValue();
|
||||
|
||||
|
||||
@@ -433,6 +433,14 @@ Expr *swift::expandMacroExpr(
|
||||
}
|
||||
}
|
||||
|
||||
// Dump macro expansions to standard output, if requested.
|
||||
if (ctx.LangOpts.DumpMacroExpansions) {
|
||||
llvm::errs() << bufferName << " as " << expandedType.getString()
|
||||
<< "\n------------------------------\n"
|
||||
<< evaluatedSource
|
||||
<< "\n------------------------------\n";
|
||||
}
|
||||
|
||||
// Create a new source buffer with the contents of the expanded macro.
|
||||
auto macroBuffer =
|
||||
llvm::MemoryBuffer::getMemBuffer(evaluatedSource, bufferName);
|
||||
|
||||
Reference in New Issue
Block a user