52 {
53 if (result_ != nullptr) return result_;
54
55 ASSERT(scope_ ==
nullptr && depth_.loop_ == 0 && depth_.function_ == 0);
56 result_ =
new (
Z) ScopeBuildingResult();
57
59
60
61
63
64 Function& outermost_function =
66
67 ActiveClassScope active_class_scope(&active_class_, &klass);
68 ActiveMemberScope active_member(&active_class_, &outermost_function);
70 ActiveTypeParametersScope active_type_params(&active_class_,
function,
72
73 LocalScope* enclosing_scope = nullptr;
75
76
77
79 Type& klass_type =
H.GetDeclarationType(klass);
80 LocalVariable* receiver_variable =
81 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
84 receiver_variable->set_is_captured();
85 enclosing_scope =
new (
Z) LocalScope(
nullptr, 0, 0);
86 enclosing_scope->set_context_level(0);
87 enclosing_scope->AddVariable(receiver_variable);
88 enclosing_scope->AddContextVariable(receiver_variable);
92 }
93 current_function_scope_ = scope_ =
new (
Z) LocalScope(enclosing_scope, 0, 0);
96
97 if (
function.IsSuspendableFunction()) {
98 LocalVariable* suspend_state_var =
99 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
100 Symbols::SuspendStateVar(), AbstractType::dynamic_type());
101 suspend_state_var->set_is_forced_stack();
102 suspend_state_var->set_invisible(true);
105 }
106
107
109 LocalVariable* type_args_var = MakeVariable(
110 TokenPosition::kNoSource, TokenPosition::kNoSource,
111 Symbols::FunctionTypeArgumentsVar(), AbstractType::dynamic_type());
114 }
115
118 }
119
123
125
127
128 FunctionNodeHelper function_node_helper(&helper_);
129 const ProcedureAttributesMetadata attrs =
132
134 case UntaggedFunction::kImplicitClosureFunction: {
138
139
140
142 (parent.num_fixed_parameters() !=
target.num_fixed_parameters())) {
143 needs_expr_temp_ = true;
144 }
145 }
147 case UntaggedFunction::kClosureFunction:
148 case UntaggedFunction::kRegularFunction:
149 case UntaggedFunction::kGetterFunction:
150 case UntaggedFunction::kSetterFunction:
151 case UntaggedFunction::kConstructor: {
154 function_node_helper.ReadUntilExcluding(
156
157
159 needs_expr_temp_ = true;
160
161 if (
function.FfiCSignatureContainsHandles()) {
162 ++depth_.try_;
163 AddTryVariables();
164 --depth_.try_;
165 ++depth_.catch_;
166 AddCatchVariables();
167 FinalizeCatchVariables();
168 --depth_.catch_;
169 }
170 }
174 needs_expr_temp_ = true;
175 }
178 LocalVariable* closure_parameter = MakeVariable(
179 TokenPosition::kNoSource, TokenPosition::kNoSource,
180 Symbols::ClosureParameter(), AbstractType::dynamic_type());
181 closure_parameter->set_is_forced_stack();
184
185
187 Type& klass_type =
H.GetDeclarationType(klass);
188 LocalVariable* variable =
189 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
193
194
195
196 if (tag == kConstructor) {
200 for (intptr_t
i = 0;
i < class_fields.Length(); ++
i) {
201 class_field ^= class_fields.At(
i);
202 if (!class_field.is_static()) {
203 const auto& kernel_data =
205 ASSERT(!kernel_data.IsNull());
206 intptr_t field_offset = class_field.kernel_offset();
207 AlternativeReadingScopeWithNewData alt(
208 &helper_.
reader_, &kernel_data, field_offset);
209 FieldHelper field_helper(&helper_);
211 Tag initializer_tag =
213 if (initializer_tag == kSomething) {
214 EnterScope(field_offset);
215 VisitExpression();
216 ExitScope(field_helper.position_, field_helper.end_position_);
217 }
218 }
219 }
220 }
222 LocalVariable* variable = MakeVariable(
223 TokenPosition::kNoSource, TokenPosition::kNoSource,
224 Symbols::TypeArgumentsParameter(), AbstractType::dynamic_type());
227 }
228
229 ParameterTypeCheckMode type_check_mode =
230 kTypeCheckForNonDynamicallyInvokedMethod;
232
233 type_check_mode = kTypeCheckForStaticFunction;
234 }
else if (
function.IsImplicitClosureFunction()) {
235
236
237
238
239
240 type_check_mode = kTypeCheckForImplicitClosureFunction;
241 }
242
243
244
245 AddPositionalAndNamedParameters(
pos, type_check_mode, attrs);
246
247 if (
function.IsSuspendableFunction()) {
248
249
250
251 VisitDartType();
252
253
254 if (helper_.
ReadTag() == kSomething) {
255 VisitDartType();
256 }
257 }
258
259
260
261
262 if (!
function.IsImplicitClosureFunction()) {
264 first_body_token_position_ = TokenPosition::kNoSource;
265 VisitNode();
266
267
268
269
270
271
272
273
274
275 if (first_body_token_position_.
IsReal()) {
277 }
280 }
281 }
282 break;
283 }
284 case UntaggedFunction::kImplicitGetter:
285 case UntaggedFunction::kImplicitSetter: {
287 const bool is_setter =
function.IsImplicitSetterFunction();
288 const bool is_method = !
function.IsStaticFunction();
291 if (is_method) {
293 Type& klass_type =
H.GetDeclarationType(klass);
294 LocalVariable* variable =
295 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
299 }
300 if (is_setter) {
302 const intptr_t kernel_offset = field.kernel_offset();
303 const InferredTypeMetadata parameter_type =
306 TokenPosition::kNoSource, TokenPosition::kNoSource,
307 Symbols::Value(),
310 nullptr,
311 ¶meter_type);
312 } else {
314 TokenPosition::kNoSource, TokenPosition::kNoSource,
315 Symbols::Value(),
317 }
319
320 if (is_method) {
321 if (field.is_covariant()) {
323 } else if (!field.is_generic_covariant_impl() ||
324 (!attrs.has_non_this_uses && !attrs.has_tearoff_uses)) {
327 }
328 }
329 }
330 break;
331 }
332 case UntaggedFunction::kImplicitStaticGetter: {
335
336
337
339 VisitNode();
340 }
341 break;
342 }
343 case UntaggedFunction::kFieldInitializer: {
347 Type& klass_type =
H.GetDeclarationType(klass);
348 LocalVariable* variable =
349 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
353 }
354 VisitNode();
355 break;
356 }
357 case UntaggedFunction::kDynamicInvocationForwarder: {
360
363
367 needs_expr_temp_ = true;
368 }
369
370 if (helper_.
PeekTag() == kField) {
371
374 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
377
378
379 if (
target.IsImplicitSetterFunction()) {
381 TokenPosition::kNoSource, TokenPosition::kNoSource,
382 Symbols::Value(),
385 }
386 break;
387 }
388
389
390
392
394 function_node_helper.ReadUntilExcluding(
396
397
401 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
404
405
406 AddPositionalAndNamedParameters(
407 pos, kTypeCheckEverythingNotCheckedInNonDynamicallyInvokedMethod,
408 attrs);
409 break;
410 }
411 case UntaggedFunction::kMethodExtractor: {
412
413
414
416 Type& klass_type =
H.GetDeclarationType(klass);
417 LocalVariable* variable =
418 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
422 break;
423 }
424 case UntaggedFunction::kFfiTrampoline: {
425 needs_expr_temp_ = true;
426
427 ++depth_.try_;
428 AddTryVariables();
429 --depth_.try_;
430 ++depth_.catch_;
431 AddCatchVariables();
432 FinalizeCatchVariables();
433 --depth_.catch_;
435 }
436 case UntaggedFunction::kInvokeFieldDispatcher: {
437 if (
function.IsDynamicClosureCallDispatcher()) {
440#define ADD_VAR(Name, _, __) scope_->AddVariable(vars->Name);
442#undef ADD_VAR
443 for (
auto const& v :
vars->named_argument_parameter_indices) {
445 }
446 }
447 }
449 case UntaggedFunction::kNoSuchMethodDispatcher: {
450 for (intptr_t
i = 0;
i <
function.NumParameters(); ++
i) {
451 LocalVariable* variable = MakeVariable(
452 TokenPosition::kNoSource, TokenPosition::kNoSource,
456 : Object::dynamic_type().ptr()));
459 }
460 break;
461 }
462 case UntaggedFunction::kRecordFieldGetter: {
463 needs_expr_temp_ = true;
464
467 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
470 break;
471 }
472 case UntaggedFunction::kIrregexpFunction:
474 }
475 if (needs_expr_temp_) {
477 }
480 }
483 }
484
486
487
488
492
493 return result_;
494}
#define RELEASE_ASSERT(cond)
static CompilerState & Current()
static bool IsDynamicInvocationForwarderName(const String &name)
bool MayHaveUncheckedEntryPoint() const
void set_begin_token_pos(TokenPosition value)
void set_end_token_pos(TokenPosition value)
TokenPosition end_token_pos() const
static LocalScope * RestoreOuterScope(const ContextScope &context_scope)
bool AddVariable(LocalVariable *variable)
bool InsertParameterAt(intptr_t pos, LocalVariable *parameter)
VariableIndex index() const
void set_is_explicit_covariant_parameter()
void set_type_check_mode(TypeCheckMode mode)
static constexpr intptr_t kNoKernelOffset
void set_is_forced_stack()
static Object & ZoneHandle()
void set_function_type_arguments(LocalVariable *function_type_arguments)
LocalVariable * expression_temp_var() const
const Function & function() const
LocalVariable * EnsureExpressionTemp()
LocalVariable * EnsureEntryPointsTemp()
LocalVariable * arg_desc_var() const
bool has_arg_desc_var() const
void set_receiver_var(LocalVariable *value)
void set_scope(LocalScope *scope)
LocalVariable * current_context_var() const
LocalVariable * suspend_state_var() const
LocalVariable * receiver_var() const
bool has_expression_temp_var() const
void set_suspend_state_var(LocalVariable *suspend_state_var)
DynamicClosureCallVars * EnsureDynamicClosureCallVars()
static constexpr intptr_t kSuspendStateVarIndex
static const String & This()
static bool IsExpressionTempVarUsedInRecognizedMethodFlowGraph(const Function &function)
static bool IsRecognizedMethodForFlowGraph(const Function &function)
void SetOffset(intptr_t offset)
void ReadUntilFunctionNode()
Tag ReadTag(uint8_t *payload=nullptr)
Tag PeekTag(uint8_t *payload=nullptr)
LocalVariable * type_arguments_variable
LocalVariable * setter_value
Dart_NativeFunction function
#define FOR_EACH_DYNAMIC_CLOSURE_CALL_VARIABLE(V)
#define ADD_VAR(Name, _, __)