Skip to content

Commit a89ea38

Browse files
committed
[ASTPrinter] Print expressions
Add new `-print-ast-decl` frontend option for only printing declarations, to match existing behavior. Some tests want to print the AST, but don't care about expressions. The existing `-print-ast` option now prints function bodies and expressions. Not all expressions are printed yet, but most common ones are.
1 parent 77f4dfa commit a89ea38

File tree

17 files changed

+695
-30
lines changed

17 files changed

+695
-30
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ struct PrintOptions {
128128
/// Whether to print function definitions.
129129
bool FunctionDefinitions = false;
130130

131+
/// Whether to print expressions.
132+
bool PrintExprs = false;
133+
131134
/// Whether to print '{ get set }' on readwrite computed properties.
132135
bool PrintGetSetOnRWProperties = true;
133136

@@ -644,6 +647,20 @@ struct PrintOptions {
644647
///
645648
/// This is only intended for debug output.
646649
static PrintOptions printEverything() {
650+
PrintOptions result = printVerbose();
651+
result.ExcludeAttrList.clear();
652+
result.ExcludeAttrList.push_back(DAK_FixedLayout);
653+
result.PrintStorageRepresentationAttrs = true;
654+
result.AbstractAccessors = false;
655+
result.PrintAccess = true;
656+
result.SkipEmptyExtensionDecls = false;
657+
result.SkipMissingMemberPlaceholders = false;
658+
result.FunctionDefinitions = true;
659+
result.PrintExprs = true;
660+
return result;
661+
}
662+
663+
static PrintOptions printDeclarations() {
647664
PrintOptions result = printVerbose();
648665
result.ExcludeAttrList.clear();
649666
result.ExcludeAttrList.push_back(DAK_FixedLayout);

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class FrontendOptions {
118118
EmitSyntax, ///< Parse and dump Syntax tree as JSON
119119
DumpAST, ///< Parse, type-check, and dump AST
120120
PrintAST, ///< Parse, type-check, and pretty-print AST
121+
PrintASTDecl, ///< Parse, type-check, and pretty-print AST declarations
121122

122123
/// Parse and dump scope map.
123124
DumpScopeMaps,

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,10 @@ def print_ast : Flag<["-"], "print-ast">,
10511051
HelpText<"Parse and type-check input file(s) and pretty print AST(s)">,
10521052
ModeOpt,
10531053
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
1054+
def print_ast_decl : Flag<["-"], "print-ast-decl">,
1055+
HelpText<"Parse and type-check input file(s) and pretty print declarations from AST(s)">,
1056+
ModeOpt,
1057+
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
10541058
def dump_pcm : Flag<["-"], "dump-pcm">,
10551059
HelpText<"Dump debugging information about a precompiled Clang module">,
10561060
ModeOpt,

0 commit comments

Comments
 (0)