@@ -60,48 +60,34 @@ namespace {
60
60
// / file scope level so it will be set up correctly for this purpose.
61
61
// /
62
62
// / Creating an instance of this object will cause it to figure out
63
- // / whether we are in the debugger function, whether it needs to swap
63
+ // / whether we are in the debugger function, and whether it needs to swap
64
64
// / the Decl that is currently being parsed.
65
- // / If you have created the object, instead of returning the result
66
- // / with makeParserResult, use the object's fixupParserResult. If
67
- // / no swap has occurred, these methods will work the same.
68
- // / If the decl has been moved, then Parser::markWasHandled will be
69
- // / called on the Decl, and you should call declWasHandledAlready
70
- // / before you consume the Decl to see if you actually need to
71
- // / consume it.
65
+ // /
72
66
// / If you are making one of these objects to address issue 1, call
73
67
// / the constructor that only takes a DeclKind, and it will be moved
74
68
// / unconditionally. Otherwise pass in the Name and DeclKind and the
75
69
// / DebuggerClient will be asked whether to move it or not.
76
70
class DebuggerContextChange {
77
71
protected:
78
72
Parser &P;
79
- Identifier Name;
80
- SourceFile *SF;
81
73
Optional<Parser::ContextChange> CC;
74
+ SourceFile *SF;
82
75
public:
83
- DebuggerContextChange (Parser &P)
84
- : P(P), SF(nullptr ) {
76
+ DebuggerContextChange (Parser &P) : P(P), SF(nullptr ) {
85
77
if (!inDebuggerContext ())
86
78
return ;
87
- else
88
- switchContext ();
79
+
80
+ switchContext ();
89
81
}
90
82
91
- DebuggerContextChange (Parser &P, Identifier & Name, DeclKind Kind)
92
- : P(P), Name(Name ), SF(nullptr ) {
83
+ DebuggerContextChange (Parser &P, Identifier Name, DeclKind Kind)
84
+ : P(P), SF(nullptr ) {
93
85
if (!inDebuggerContext ())
94
86
return ;
95
- bool globalize = false ;
96
-
97
- DebuggerClient *debug_client = getDebuggerClient ();
98
- if (!debug_client)
99
- return ;
100
-
101
- globalize = debug_client->shouldGlobalize (Name, Kind);
102
-
103
- if (globalize)
104
- switchContext ();
87
+
88
+ if (auto *client = getDebuggerClient ())
89
+ if (client->shouldGlobalize (Name, Kind))
90
+ switchContext ();
105
91
}
106
92
107
93
bool movedToTopLevel () {
@@ -118,19 +104,21 @@ namespace {
118
104
template <typename T>
119
105
ParserResult<T>
120
106
fixupParserResult (T *D) {
121
- if (CC.hasValue ()) {
122
- swapDecl (D);
107
+ if (movedToTopLevel ()) {
108
+ D->setHoisted ();
109
+ SF->addHoistedDecl (D);
110
+ getDebuggerClient ()->didGlobalize (D);
123
111
}
124
112
return ParserResult<T>(D);
125
113
}
126
114
127
115
template <typename T>
128
116
ParserResult<T>
129
117
fixupParserResult (ParserStatus Status, T *D) {
130
- if (CC. hasValue () && !Status. isError ()) {
131
- // If there is an error, don't do our splicing trick,
132
- // just return the Decl and the status for reporting.
133
- swapDecl (D);
118
+ if (movedToTopLevel ()) {
119
+ D-> setHoisted ();
120
+ SF-> addHoistedDecl (D);
121
+ getDebuggerClient ()-> didGlobalize (D);
134
122
}
135
123
return makeParserResult (Status, D);
136
124
}
@@ -140,43 +128,29 @@ namespace {
140
128
~DebuggerContextChange () {}
141
129
protected:
142
130
143
- DebuggerClient *getDebuggerClient ()
144
- {
145
- ModuleDecl *PM = P.CurDeclContext ->getParentModule ();
146
- if (!PM)
147
- return nullptr ;
148
- else
149
- return PM->getDebugClient ();
131
+ DebuggerClient *getDebuggerClient () {
132
+ ModuleDecl *M = P.CurDeclContext ->getParentModule ();
133
+ return M->getDebugClient ();
150
134
}
151
135
152
136
bool inDebuggerContext () {
153
137
if (!P.Context .LangOpts .DebuggerSupport )
154
138
return false ;
155
139
if (!P.CurDeclContext )
156
140
return false ;
157
- auto *func_decl = dyn_cast<FuncDecl>(P.CurDeclContext );
158
- if (!func_decl )
141
+ auto *func = dyn_cast<FuncDecl>(P.CurDeclContext );
142
+ if (!func )
159
143
return false ;
160
-
161
- if (!func_decl ->getAttrs ().hasAttribute <LLDBDebuggerFunctionAttr>())
144
+
145
+ if (!func ->getAttrs ().hasAttribute <LLDBDebuggerFunctionAttr>())
162
146
return false ;
163
-
147
+
164
148
return true ;
165
149
}
166
150
167
- void switchContext () {
151
+ void switchContext () {
168
152
SF = P.CurDeclContext ->getParentSourceFile ();
169
- CC.emplace (P, SF);
170
- }
171
-
172
- void swapDecl (Decl *D)
173
- {
174
- assert (SF);
175
- DebuggerClient *debug_client = getDebuggerClient ();
176
- assert (debug_client);
177
- debug_client->didGlobalize (D);
178
- P.ContextSwitchedTopLevelDecls .push_back (D);
179
- P.markWasHandled (D);
153
+ CC.emplace (P, SF);
180
154
}
181
155
};
182
156
} // end anonymous namespace
@@ -225,10 +199,6 @@ void Parser::parseTopLevel(SmallVectorImpl<Decl *> &decls) {
225
199
}
226
200
}
227
201
228
- // First append any decls that LLDB requires be inserted at the top-level.
229
- decls.append (ContextSwitchedTopLevelDecls.begin (),
230
- ContextSwitchedTopLevelDecls.end ());
231
-
232
202
// Then append the top-level decls we parsed.
233
203
for (auto item : items) {
234
204
auto *decl = item.get <Decl *>();
@@ -7726,8 +7696,9 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
7726
7696
SourceLoc precedenceGroupLoc = consumeToken (tok::kw_precedencegroup);
7727
7697
DebuggerContextChange DCC (*this );
7728
7698
7729
- if (!CodeCompletion && !DCC.movedToTopLevel () && !(flags & PD_AllowTopLevel))
7730
- {
7699
+ if (!CodeCompletion &&
7700
+ !DCC.movedToTopLevel () &&
7701
+ !(flags & PD_AllowTopLevel)) {
7731
7702
diagnose (precedenceGroupLoc, diag::decl_inner_scope);
7732
7703
return nullptr ;
7733
7704
}
0 commit comments