10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
- #ifndef SWIFT_SYNTAX_PARSING_CONTEXT_H
14
- #define SWIFT_SYNTAX_PARSING_CONTEXT_H
13
+ #ifndef SWIFT_PARSE_SYNTAXPARSINGCONTEXT_H
14
+ #define SWIFT_PARSE_SYNTAXPARSINGCONTEXT_H
15
15
16
16
#include " llvm/ADT/PointerUnion.h"
17
17
#include " swift/Basic/SourceLoc.h"
18
18
#include " swift/Syntax/Syntax.h"
19
19
#include " swift/Syntax/TokenSyntax.h"
20
20
21
21
namespace swift {
22
- class SourceLoc ;
23
22
class SourceFile ;
24
23
class Token ;
25
24
class DiagnosticEngine ;
26
25
27
26
namespace syntax {
28
27
class RawSyntax ;
29
28
enum class SyntaxKind ;
29
+ }
30
+
31
+ using namespace swift ::syntax;
30
32
31
33
enum class SyntaxContextKind {
32
34
Decl,
@@ -39,53 +41,6 @@ enum class SyntaxContextKind {
39
41
40
42
constexpr size_t SyntaxAlignInBits = 3 ;
41
43
42
- // / Indicates what action should be performed on the destruction of
43
- // / SyntaxParsingContext
44
- enum class AccumulationMode {
45
- // Coerece the result to one of ContextKind.
46
- // E.g. for ContextKind::Expr, passthroug if the result is CallExpr, whereas
47
- // <UnknownExpr><SomeDecl /></UnknownDecl> for non Exprs.
48
- CoerceKind,
49
-
50
- // Construct a result Syntax with specified SyntaxKind.
51
- CreateSyntax,
52
-
53
- // Pass through all parts to the parent context.
54
- Transparent,
55
-
56
- // Discard all parts in the context.
57
- Discard,
58
-
59
- // Construct SourceFile syntax to the specified SF.
60
- Root,
61
-
62
- // Invalid.
63
- NotSet,
64
- };
65
-
66
- // / The shared data for all syntax parsing contexts with the same root.
67
- // / This should be accessible from the root context only.
68
- struct alignas (1 << SyntaxAlignInBits) RootContextData {
69
- // The source file under parsing.
70
- SourceFile &SF;
71
-
72
- // Where to issue diagnostics.
73
- DiagnosticEngine &Diags;
74
-
75
- SourceManager &SourceMgr;
76
-
77
- unsigned BufferID;
78
-
79
- // Storage for Collected parts.
80
- std::vector<RC<RawSyntax>> Storage;
81
-
82
- RootContextData (SourceFile &SF,
83
- DiagnosticEngine &Diags,
84
- SourceManager &SourceMgr,
85
- unsigned BufferID): SF (SF), Diags (Diags),
86
- SourceMgr (SourceMgr), BufferID (BufferID) {}
87
- };
88
-
89
44
// / RAII object which receive RawSyntax parts. On destruction, this constructs
90
45
// / a specified syntax node from received parts and propagate it to the parent
91
46
// / context.
@@ -102,6 +57,53 @@ struct alignas(1 << SyntaxAlignInBits) RootContextData {
102
57
// / // From these parts, it creates ParenExpr node and add it to the parent.
103
58
// / }
104
59
class alignas (1 << SyntaxAlignInBits) SyntaxParsingContext {
60
+ public:
61
+ // / The shared data for all syntax parsing contexts with the same root.
62
+ // / This should be accessible from the root context only.
63
+ struct alignas (1 << SyntaxAlignInBits) RootContextData {
64
+ // The source file under parsing.
65
+ SourceFile &SF;
66
+
67
+ // Where to issue diagnostics.
68
+ DiagnosticEngine &Diags;
69
+
70
+ SourceManager &SourceMgr;
71
+
72
+ unsigned BufferID;
73
+
74
+ // Storage for Collected parts.
75
+ std::vector<RC<RawSyntax>> Storage;
76
+
77
+ RootContextData (SourceFile &SF, DiagnosticEngine &Diags,
78
+ SourceManager &SourceMgr, unsigned BufferID)
79
+ : SF (SF), Diags (Diags), SourceMgr (SourceMgr), BufferID (BufferID) {}
80
+ };
81
+
82
+ private:
83
+ // / Indicates what action should be performed on the destruction of
84
+ // / SyntaxParsingContext
85
+ enum class AccumulationMode {
86
+ // Coerece the result to one of ContextKind.
87
+ // E.g. for ContextKind::Expr, passthroug if the result is CallExpr, whereas
88
+ // <UnknownExpr><SomeDecl /></UnknownDecl> for non Exprs.
89
+ CoerceKind,
90
+
91
+ // Construct a result Syntax with specified SyntaxKind.
92
+ CreateSyntax,
93
+
94
+ // Pass through all parts to the parent context.
95
+ Transparent,
96
+
97
+ // Discard all parts in the context.
98
+ Discard,
99
+
100
+ // Construct SourceFile syntax to the specified SF.
101
+ Root,
102
+
103
+ // Invalid.
104
+ NotSet,
105
+ };
106
+
105
107
// When this context is a root, this points to an instance of RootContextData;
106
108
// When this context isn't a root, this points to the parent context.
107
109
const llvm::PointerUnion<RootContextData *, SyntaxParsingContext *>
@@ -255,6 +257,5 @@ class alignas(1 << SyntaxAlignInBits) SyntaxParsingContext {
255
257
256
258
};
257
259
258
- } // namespace syntax
259
260
} // namespace swift
260
261
#endif // SWIFT_SYNTAX_PARSING_CONTEXT_H
0 commit comments