Skip to content

Commit 9491ec4

Browse files
committed
Add a swift-ide-test option to not print import declarations.
The import declarations get in the way when looking the results of -enable-omit-needless-words.
1 parent 17d6b19 commit 9491ec4

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ struct PrintOptions {
105105
/// Whether to print destructors.
106106
bool SkipDeinit = false;
107107

108+
/// Whether to skip printing 'import' declarations.
109+
bool SkipImports = false;
110+
108111
/// Whether to print a long attribute like '\@available' on a separate line
109112
/// from the declaration or other attributes.
110113
bool PrintLongAttrsOnSeparateLines = false;

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,10 @@ bool swift::shouldPrint(const Decl *D, PrintOptions &Options) {
678678
return false;
679679
}
680680

681+
if (Options.SkipImports && isa<ImportDecl>(D)) {
682+
return false;
683+
}
684+
681685
if (Options.SkipImplicit && D->isImplicit())
682686
return false;
683687

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ SkipDeinit("skip-deinit",
244244
llvm::cl::desc("Whether to skip printing destructors"),
245245
llvm::cl::init(true));
246246

247+
static llvm::cl::opt<bool>
248+
SkipImports("skip-imports",
249+
llvm::cl::desc("Whether to skip printing import declarations"),
250+
llvm::cl::init(false));
251+
247252
static llvm::cl::opt<bool>
248253
SkipParameterNames("skip-parameter-names",
249254
llvm::cl::desc("Whether to skip parameter names"),
@@ -2545,6 +2550,7 @@ int main(int argc, char *argv[]) {
25452550
PrintOpts.SkipPrivateStdlibDecls = options::SkipPrivateStdlibDecls;
25462551
PrintOpts.SkipUnavailable = options::SkipUnavailable;
25472552
PrintOpts.SkipDeinit = options::SkipDeinit;
2553+
PrintOpts.SkipImports = options::SkipImports;
25482554
if (options::SkipParameterNames) {
25492555
PrintOpts.ArgAndParamPrinting
25502556
= PrintOptions::ArgAndParamPrintingMode::ArgumentOnly;

utils/omit-needless-words.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def help():
116116
sdkroot = subprocess.check_output(['xcrun', '--show-sdk-path', '--sdk', sdk]).rstrip()
117117
print('SDK Root = %s' % (sdkroot))
118118

119-
swift_ide_test_cmd = [swift_ide_test, '-print-module', '-source-filename', source_filename, '-sdk', sdkroot, '-target', target, '-module-print-skip-overlay', '-skip-unavailable', '-module-print-submodules', '-skip-parameter-names', '-module-to-print=%s' % (module)]
119+
swift_ide_test_cmd = [swift_ide_test, '-print-module', '-source-filename', source_filename, '-sdk', sdkroot, '-target', target, '-module-print-skip-overlay', '-skip-unavailable', '-module-print-submodules', '-skip-parameter-names', '-skip-imports', '-module-to-print=%s' % (module)]
120120
omit_needless_words_args = ['-enable-omit-needless-words', '-enable-infer-default-arguments']
121121

122122
# Determine the output files.

0 commit comments

Comments
 (0)