Skip to content

Commit c5f0200

Browse files
authored
Merge pull request #79059 from allevato/json-ast-followups
[ASTDumper] Some followups from the initial JSON PR and macro dumping improvements.
2 parents 360e2ab + 0d9467e commit c5f0200

21 files changed

+312
-124
lines changed

include/swift/AST/ASTDumper.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===--- ASTDumper.h - Swift AST Dumper flags -------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines types that are used to control the level of detail printed
14+
// by the AST dumper.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_AST_AST_DUMPER_H
19+
#define SWIFT_AST_AST_DUMPER_H
20+
21+
namespace swift {
22+
23+
/// Describes the nature of requests that should be kicked off, if any, to
24+
/// compute members and top-level decls when dumping an AST.
25+
enum class ASTDumpMemberLoading {
26+
/// Dump cached members if available; if they are not, do not kick off any
27+
/// parsing or type-checking requests.
28+
None,
29+
30+
/// Dump parsed members, kicking off a parsing request if necessary to compute
31+
/// them, but not performing additional type-checking.
32+
Parsed,
33+
34+
/// Dump all fully-type checked members, kicking off any requests necessary to
35+
/// compute them.
36+
TypeChecked,
37+
};
38+
39+
} // namespace swift
40+
41+
#endif // SWIFT_AST_AST_DUMPER_H

include/swift/AST/SourceFile.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
#ifndef SWIFT_AST_SOURCEFILE_H
1414
#define SWIFT_AST_SOURCEFILE_H
1515

16+
#include "swift/AST/ASTDumper.h"
1617
#include "swift/AST/ASTNode.h"
1718
#include "swift/AST/FileUnit.h"
1819
#include "swift/AST/IfConfigClauseRangeInfo.h"
1920
#include "swift/AST/Import.h"
2021
#include "swift/AST/SynthesizedFileUnit.h"
2122
#include "swift/Basic/Debug.h"
2223
#include "llvm/ADT/Hashing.h"
24+
#include "llvm/ADT/STLExtras.h"
2325
#include "llvm/ADT/SetVector.h"
2426
#include "llvm/ADT/SmallPtrSet.h"
25-
#include "llvm/ADT/STLExtras.h"
2627

2728
namespace swift {
2829
class ASTScope;
@@ -689,10 +690,12 @@ class SourceFile final : public FileUnit {
689690
}
690691

691692
SWIFT_DEBUG_DUMP;
692-
void dump(raw_ostream &os, bool parseIfNeeded = false) const;
693+
void
694+
dump(raw_ostream &os,
695+
ASTDumpMemberLoading memberLoading = ASTDumpMemberLoading::None) const;
693696

694697
/// Dumps this source file's AST in JSON format to the given output stream.
695-
void dumpJSON(raw_ostream &os) const;
698+
void dumpJSON(raw_ostream &os, ASTDumpMemberLoading memberLoading) const;
696699

697700
/// Pretty-print the contents of this source file.
698701
///

0 commit comments

Comments
 (0)