15#define H (translation_helper_)
16#define T (type_translator_)
17#define I Isolate::Current()
18#define IG IsolateGroup::Current()
22 parsed_function_(parsed_function),
23 translation_helper_(
Thread::Current()),
24 zone_(translation_helper_.zone()),
25 current_function_scope_(nullptr),
29 needs_expr_temp_(
false),
34 parsed_function->
function().KernelLibraryOffset()),
35 constant_reader_(&helper_, &active_class_),
36 inferred_type_metadata_helper_(&helper_, &constant_reader_),
37 inferred_arg_type_metadata_helper_(
41 procedure_attributes_metadata_helper_(&helper_),
42 type_translator_(&helper_,
48 H.InitFromKernelProgramInfo(kernel_program_info);
49 ASSERT(type_translator_.active_class_ == &active_class_);
53 if (result_ !=
nullptr)
return result_;
55 ASSERT(scope_ ==
nullptr && depth_.loop_ == 0 && depth_.function_ == 0);
79 Type& klass_type =
H.GetDeclarationType(klass);
81 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
85 enclosing_scope =
new (
Z)
LocalScope(
nullptr, 0, 0);
93 current_function_scope_ = scope_ =
new (
Z)
LocalScope(enclosing_scope, 0, 0);
97 if (
function.IsSuspendableFunction()) {
99 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
100 Symbols::SuspendStateVar(), AbstractType::dynamic_type());
110 TokenPosition::kNoSource, TokenPosition::kNoSource,
111 Symbols::FunctionTypeArgumentsVar(), AbstractType::dynamic_type());
134 case UntaggedFunction::kImplicitClosureFunction: {
142 (parent.num_fixed_parameters() !=
target.num_fixed_parameters())) {
143 needs_expr_temp_ =
true;
147 case UntaggedFunction::kClosureFunction:
148 case UntaggedFunction::kRegularFunction:
149 case UntaggedFunction::kGetterFunction:
150 case UntaggedFunction::kSetterFunction:
151 case UntaggedFunction::kConstructor: {
159 needs_expr_temp_ =
true;
161 if (
function.FfiCSignatureContainsHandles()) {
167 FinalizeCatchVariables();
174 needs_expr_temp_ =
true;
179 TokenPosition::kNoSource, TokenPosition::kNoSource,
180 Symbols::ClosureParameter(), AbstractType::dynamic_type());
187 Type& klass_type =
H.GetDeclarationType(klass);
189 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
196 if (tag == kConstructor) {
200 for (intptr_t i = 0; i < class_fields.
Length(); ++i) {
201 class_field ^= class_fields.
At(i);
203 const auto& kernel_data =
205 ASSERT(!kernel_data.IsNull());
208 &helper_.
reader_, &kernel_data, field_offset);
211 Tag initializer_tag =
213 if (initializer_tag == kSomething) {
214 EnterScope(field_offset);
223 TokenPosition::kNoSource, TokenPosition::kNoSource,
224 Symbols::TypeArgumentsParameter(), AbstractType::dynamic_type());
229 ParameterTypeCheckMode type_check_mode =
230 kTypeCheckForNonDynamicallyInvokedMethod;
233 type_check_mode = kTypeCheckForStaticFunction;
234 }
else if (
function.IsImplicitClosureFunction()) {
240 type_check_mode = kTypeCheckForImplicitClosureFunction;
245 AddPositionalAndNamedParameters(
pos, type_check_mode, attrs);
247 if (
function.IsSuspendableFunction()) {
254 if (helper_.
ReadTag() == kSomething) {
262 if (!
function.IsImplicitClosureFunction()) {
264 first_body_token_position_ = TokenPosition::kNoSource;
275 if (first_body_token_position_.
IsReal()) {
284 case UntaggedFunction::kImplicitGetter:
285 case UntaggedFunction::kImplicitSetter: {
287 const bool is_setter =
function.IsImplicitSetterFunction();
288 const bool is_method = !
function.IsStaticFunction();
293 Type& klass_type =
H.GetDeclarationType(klass);
295 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
302 const intptr_t kernel_offset = field.kernel_offset();
306 TokenPosition::kNoSource, TokenPosition::kNoSource,
314 TokenPosition::kNoSource, TokenPosition::kNoSource,
321 if (field.is_covariant()) {
323 }
else if (!field.is_generic_covariant_impl() ||
332 case UntaggedFunction::kImplicitStaticGetter: {
343 case UntaggedFunction::kFieldInitializer: {
347 Type& klass_type =
H.GetDeclarationType(klass);
349 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
357 case UntaggedFunction::kDynamicInvocationForwarder: {
367 needs_expr_temp_ =
true;
370 if (helper_.
PeekTag() == kField) {
374 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
379 if (
target.IsImplicitSetterFunction()) {
381 TokenPosition::kNoSource, TokenPosition::kNoSource,
401 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
406 AddPositionalAndNamedParameters(
407 pos, kTypeCheckEverythingNotCheckedInNonDynamicallyInvokedMethod,
411 case UntaggedFunction::kMethodExtractor: {
416 Type& klass_type =
H.GetDeclarationType(klass);
418 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
424 case UntaggedFunction::kFfiTrampoline: {
425 needs_expr_temp_ =
true;
432 FinalizeCatchVariables();
436 case UntaggedFunction::kInvokeFieldDispatcher: {
437 if (
function.IsDynamicClosureCallDispatcher()) {
440#define ADD_VAR(Name, _, __) scope_->AddVariable(vars->Name);
443 for (
auto const& v :
vars->named_argument_parameter_indices) {
449 case UntaggedFunction::kNoSuchMethodDispatcher: {
450 for (intptr_t i = 0; i <
function.NumParameters(); ++i) {
452 TokenPosition::kNoSource, TokenPosition::kNoSource,
456 : Object::dynamic_type().ptr()));
462 case UntaggedFunction::kRecordFieldGetter: {
463 needs_expr_temp_ =
true;
467 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
472 case UntaggedFunction::kIrregexpFunction:
475 if (needs_expr_temp_) {
498 H.ReportError(script, TokenPosition::kNoSource,
499 "Unexpected tag %d (%s) in %s, expected %s", tag,
504void ScopeBuilder::VisitNode() {
525void ScopeBuilder::VisitConstructor() {
531 ConstructorHelper constructor_helper(&helper_);
538 for (intptr_t i = 0; i < class_fields.Length(); ++i) {
539 class_field ^= class_fields.At(i);
540 if (!class_field.is_static()) {
541 const auto& kernel_data =
543 ASSERT(!kernel_data.IsNull());
544 intptr_t field_offset = class_field.kernel_offset();
545 AlternativeReadingScopeWithNewData alt(&helper_.
reader_, &kernel_data,
547 FieldHelper field_helper(&helper_);
550 if (initializer_tag == kSomething) {
559 intptr_t list_length =
561 for (intptr_t i = 0; i < list_length; i++) {
566void ScopeBuilder::VisitProcedure() {
567 ProcedureHelper procedure_helper(&helper_);
572void ScopeBuilder::VisitField() {
573 FieldHelper field_helper(&helper_);
577 if (tag == kSomething) {
582void ScopeBuilder::VisitFunctionNode() {
583 FunctionNodeHelper function_node_helper(&helper_);
586 intptr_t list_length =
588 for (intptr_t i = 0; i < list_length; ++i) {
589 TypeParameterHelper helper(&helper_);
602 if (helper_.
ReadTag() == kSomething) {
603 PositionScope scope(&helper_.
reader_);
609void ScopeBuilder::VisitInitializer() {
613 case kInvalidInitializer:
615 case kFieldInitializer:
620 case kSuperInitializer:
625 case kRedirectingInitializer:
630 case kLocalInitializer:
631 VisitVariableDeclaration();
633 case kAssertInitializer:
642void ScopeBuilder::VisitExpression() {
646 case kInvalidExpression:
649 if (helper_.
ReadTag() == kSomething) {
655 intptr_t variable_kernel_offset =
659 VisitVariableGet(variable_kernel_offset);
662 case kSpecializedVariableGet: {
664 intptr_t variable_kernel_offset =
666 VisitVariableGet(variable_kernel_offset);
671 intptr_t variable_kernel_offset =
674 LookupVariable(variable_kernel_offset);
678 case kSpecializedVariableSet: {
680 intptr_t variable_kernel_offset =
682 LookupVariable(variable_kernel_offset);
701 case kInstanceTearOff:
710 case kFunctionTearOff:
730 case kAbstractSuperPropertyGet:
735 case kAbstractSuperPropertySet:
740 case kSuperPropertyGet:
741 HandleLoadReceiver();
746 case kSuperPropertySet:
747 HandleLoadReceiver();
762 case kInstanceInvocation:
773 case kDynamicInvocation:
781 case kLocalFunctionInvocation: {
783 intptr_t variable_kernel_offset =
788 VisitVariableGet(variable_kernel_offset);
791 case kFunctionInvocation:
810 case kAbstractSuperMethodInvocation:
815 case kSuperMethodInvocation:
816 HandleLoadReceiver();
823 case kStaticInvocation:
828 case kConstructorInvocation:
841 case kLogicalExpression:
842 needs_expr_temp_ =
true;
848 case kConditionalExpression: {
849 needs_expr_temp_ =
true;
857 case kStringConcatenation: {
859 VisitListOfExpressions();
863 needs_expr_temp_ =
true;
879 case kThisExpression:
880 HandleLoadReceiver();
894 VisitListOfExpressions();
908 for (intptr_t i = 0; i < list_length; ++i) {
916 VisitListOfExpressions();
917 VisitListOfNamedExpressions();
920 case kRecordIndexGet:
932 case kFunctionExpression: {
935 HandleLocalFunction(
offset);
939 PositionScope scope(&helper_.
reader_);
945 VisitVariableDeclaration();
951 case kBlockExpression: {
952 PositionScope scope(&helper_.
reader_);
958 intptr_t list_length =
960 for (intptr_t i = 0; i < list_length; ++i) {
976 case kSpecializedIntLiteral:
979 case kNegativeIntLiteral:
983 case kPositiveIntLiteral:
1000 case kConstantExpression:
1005 case kFileUriConstantExpression:
1011 case kInstantiation: {
1014 const intptr_t list_length =
1016 for (intptr_t i = 0; i < list_length; ++i) {
1022 case kCheckLibraryIsLoaded:
1026 case kAwaitExpression:
1029 if (helper_.
ReadTag() == kSomething) {
1033 case kFileUriExpression:
1038 case kConstStaticInvocation:
1039 case kConstConstructorInvocation:
1040 case kConstListLiteral:
1041 case kConstSetLiteral:
1042 case kConstMapLiteral:
1043 case kSymbolLiteral:
1044 case kListConcatenation:
1045 case kSetConcatenation:
1046 case kMapConcatenation:
1047 case kInstanceCreation:
1048 case kStaticTearOff:
1049 case kSwitchExpression:
1050 case kPatternAssignment:
1059void ScopeBuilder::VisitStatement() {
1062 case kExpressionStatement:
1066 PositionScope scope(&helper_.
reader_);
1072 intptr_t list_length =
1074 for (intptr_t i = 0; i < list_length; ++i) {
1081 case kEmptyStatement:
1084 if (
IG->asserts()) {
1085 PositionScope scope(&helper_.
reader_);
1091 intptr_t list_length =
1093 for (intptr_t i = 0; i < list_length; ++i) {
1103 case kAssertStatement:
1104 if (
IG->asserts()) {
1109 if (tag == kSomething) {
1117 if (tag == kSomething) {
1122 case kLabeledStatement:
1126 case kBreakStatement:
1130 case kWhileStatement:
1144 case kForStatement: {
1145 PositionScope scope(&helper_.
reader_);
1153 intptr_t list_length =
1155 for (intptr_t i = 0; i < list_length; ++i) {
1156 VisitVariableDeclaration();
1160 if (tag == kSomething) {
1163 VisitListOfExpressions();
1170 case kSwitchStatement: {
1171 AddSwitchVariable();
1177 for (intptr_t i = 0; i < case_count; ++i) {
1179 int expression_count =
1181 for (intptr_t j = 0; j < expression_count; ++j) {
1190 case kContinueSwitchStatement:
1200 case kReturnStatement: {
1201 if ((depth_.function_ == 0) && (depth_.finally_ > 0) &&
1203 const String&
name = Symbols::TryFinallyReturnValue();
1204 LocalVariable* variable =
1205 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
1206 name, AbstractType::dynamic_type());
1213 if (tag == kSomething) {
1226 AddCatchVariables();
1229 intptr_t catch_count =
1231 for (intptr_t i = 0; i < catch_count; ++i) {
1232 PositionScope scope(&helper_.
reader_);
1240 if (tag == kSomething) {
1241 VisitVariableDeclaration();
1244 if (tag == kSomething) {
1245 VisitVariableDeclaration();
1253 FinalizeCatchVariables();
1269 AddCatchVariables();
1273 FinalizeCatchVariables();
1278 case kYieldStatement: {
1284 case kVariableDeclaration:
1285 VisitVariableDeclaration();
1290 VisitVariableDeclaration();
1291 HandleLocalFunction(
offset);
1294 case kForInStatement:
1295 case kAsyncForInStatement:
1296 case kIfCaseStatement:
1297 case kPatternSwitchStatement:
1298 case kPatternVariableDeclaration:
1307void ScopeBuilder::VisitListOfExpressions() {
1309 for (intptr_t i = 0; i < list_length; ++i) {
1314void ScopeBuilder::VisitListOfNamedExpressions() {
1316 for (intptr_t i = 0; i < list_length; ++i) {
1322void ScopeBuilder::VisitArguments() {
1327 for (intptr_t i = 0; i < list_length; ++i) {
1331 VisitListOfExpressions();
1332 VisitListOfNamedExpressions();
1335void ScopeBuilder::VisitVariableDeclaration() {
1336 PositionScope scope(&helper_.
reader_);
1338 const intptr_t kernel_offset =
1341 const InferredTypeMetadata inferred_type =
1343 VariableDeclarationHelper helper(&helper_);
1345 const intptr_t annotations_offset = helper_.
ReaderOffset();
1347 AbstractType&
type = BuildAndVisitVariableType();
1349 const String&
name = (
H.StringSize(helper.name_index_) == 0)
1350 ? GenerateName(
":var", name_index_++)
1351 :
H.DartSymbolObfuscate(helper.name_index_);
1355 if (tag == kSomething) {
1362 if (end_position.IsReal()) {
1363 end_position = end_position.
Next();
1365 LocalVariable* variable =
1366 MakeVariable(helper.position_, end_position,
name,
type, kernel_offset,
1367 helper.IsLate(), &inferred_type);
1368 if (helper.annotation_count_ > 0) {
1369 variable->set_annotations_offset(annotations_offset);
1371 if (helper.IsFinal()) {
1372 variable->set_is_final();
1374 if (helper.IsLate()) {
1375 variable->set_is_late();
1376 variable->set_late_init_offset(initializer_offset);
1378 if (helper.IsSynthesized()) {
1379 variable->set_invisible(
true);
1383 result_->
locals.Insert(kernel_offset, variable);
1386AbstractType& ScopeBuilder::BuildAndVisitVariableType() {
1388 AbstractType&
type =
T.BuildType();
1394void ScopeBuilder::VisitDartType() {
1406 case kInterfaceType:
1407 VisitInterfaceType(
false);
1409 case kSimpleInterfaceType:
1410 VisitInterfaceType(
true);
1413 VisitFunctionType(
false);
1415 case kSimpleFunctionType:
1416 VisitFunctionType(
true);
1421 case kTypeParameterType:
1422 VisitTypeParameterType();
1424 case kIntersectionType:
1425 VisitIntersectionType();
1427 case kExtensionType:
1428 VisitExtensionType();
1431 VisitFutureOrType();
1439void ScopeBuilder::VisitInterfaceType(
bool simple) {
1444 for (intptr_t i = 0; i <
length; ++i) {
1450void ScopeBuilder::VisitFunctionType(
bool simple) {
1454 intptr_t list_length =
1456 for (
int i = 0; i < list_length; ++i) {
1457 TypeParameterHelper helper(&helper_);
1460 helper.ReadUntilExcludingAndSetJustRead(
1469 const intptr_t positional_count =
1471 for (intptr_t i = 0; i < positional_count; ++i) {
1476 const intptr_t named_count =
1478 for (intptr_t i = 0; i < named_count; ++i) {
1489void ScopeBuilder::VisitRecordType() {
1491 const intptr_t positional_count =
1493 for (intptr_t i = 0; i < positional_count; ++i) {
1496 const intptr_t named_count =
1498 for (intptr_t i = 0; i < named_count; ++i) {
1505void ScopeBuilder::VisitTypeParameterType() {
1515 intptr_t index = helper_.
ReadUInt();
1517 if (!
function.IsImplicitStaticClosureFunction()) {
1518 while (
function.IsClosureFunction()) {
1526 Symbols::TypeArgumentsParameter(),
1534 if (index < parent_class.NumTypeParameters()) {
1535 HandleLoadReceiver();
1541void ScopeBuilder::VisitIntersectionType() {
1546void ScopeBuilder::VisitExtensionType() {
1554void ScopeBuilder::VisitFutureOrType() {
1559void ScopeBuilder::HandleLocalFunction(intptr_t parent_kernel_offset) {
1563 FunctionNodeHelper function_node_helper(&helper_);
1566 LocalScope* saved_function_scope = current_function_scope_;
1567 DepthState saved_depth_state = depth_;
1568 depth_ = DepthState(depth_.function_ + 1);
1569 EnterScope(parent_kernel_offset);
1570 current_function_scope_ = scope_;
1571 if (depth_.function_ == 1) {
1572 FunctionScope function_scope = {
offset, scope_};
1576 int num_type_params = 0;
1578 AlternativeReadingScope
_(&helper_.
reader_);
1585 TypeTranslator::TypeParameterScope scope(&type_translator_, num_type_params);
1588 function_node_helper.ReadUntilExcluding(
1591 ProcedureAttributesMetadata default_attrs;
1592 AddPositionalAndNamedParameters(0, kTypeCheckForNonDynamicallyInvokedMethod,
1605 VisitFunctionNode();
1615 ExitScope(function_node_helper.position_, function_node_helper.end_position_);
1616 depth_ = saved_depth_state;
1617 current_function_scope_ = saved_function_scope;
1620void ScopeBuilder::EnterScope(intptr_t kernel_offset) {
1621 scope_ =
new (
Z) LocalScope(scope_, depth_.function_, depth_.loop_);
1622 ASSERT(kernel_offset >= 0);
1623 result_->
scopes.Insert(kernel_offset, scope_);
1626void ScopeBuilder::ExitScope(TokenPosition start_position,
1627 TokenPosition end_position) {
1630 scope_ = scope_->
parent();
1633void ScopeBuilder::AddPositionalAndNamedParameters(
1635 ParameterTypeCheckMode type_check_mode ,
1636 const ProcedureAttributesMetadata& attrs) {
1639 for (intptr_t i = 0; i < list_length; ++i) {
1640 AddVariableDeclarationParameter(
pos++, type_check_mode, attrs);
1645 for (intptr_t i = 0; i < list_length; ++i) {
1646 AddVariableDeclarationParameter(
pos++, type_check_mode, attrs);
1650void ScopeBuilder::AddVariableDeclarationParameter(
1652 ParameterTypeCheckMode type_check_mode,
1653 const ProcedureAttributesMetadata& attrs) {
1655 const intptr_t kernel_offset =
1658 const InferredTypeMetadata inferred_type =
1660 const InferredTypeMetadata inferred_arg_type =
1663 VariableDeclarationHelper helper(&helper_);
1665 const intptr_t annotations_offset = helper_.
ReaderOffset();
1667 String&
name =
H.DartSymbolObfuscate(helper.name_index_);
1669 AbstractType&
type = BuildAndVisitVariableType();
1673 LocalVariable* variable = MakeVariable(
1674 helper.position_, helper.position_,
name,
type, kernel_offset,
1675 false, &inferred_type, &inferred_arg_type);
1676 if (helper.annotation_count_ > 0) {
1677 variable->set_annotations_offset(annotations_offset);
1679 if (helper.IsFinal()) {
1680 variable->set_is_final();
1682 if (helper.IsCovariant()) {
1683 variable->set_is_explicit_covariant_parameter();
1686 const bool needs_covariant_check_in_method =
1687 helper.IsCovariant() ||
1688 (helper.IsGenericCovariantImpl() &&
1689 (attrs.has_non_this_uses || attrs.has_tearoff_uses));
1690 if (needs_covariant_check_in_method) {
1691 variable->set_needs_covariant_check_in_method();
1694 switch (type_check_mode) {
1695 case kTypeCheckAllParameters:
1698 case kTypeCheckEverythingNotCheckedInNonDynamicallyInvokedMethod:
1699 if (needs_covariant_check_in_method) {
1707 case kTypeCheckForNonDynamicallyInvokedMethod:
1708 if (needs_covariant_check_in_method) {
1716 case kTypeCheckForImplicitClosureFunction:
1717 if (needs_covariant_check_in_method) {
1727 case kTypeCheckForStaticFunction:
1734 if (inferred_arg_type.IsSkipCheck()) {
1739 result_->
locals.Insert(kernel_offset, variable);
1744 if (tag == kSomething) {
1749LocalVariable* ScopeBuilder::MakeVariable(
1750 TokenPosition declaration_pos,
1751 TokenPosition token_pos,
1753 const AbstractType& static_type,
1754 intptr_t kernel_offset ,
1756 const InferredTypeMetadata* inferred_type_md ,
1757 const InferredTypeMetadata* inferred_arg_type_md ) {
1758 CompileType* inferred_type =
nullptr;
1759 if (inferred_type_md !=
nullptr && !inferred_type_md->IsTrivial()) {
1760 inferred_type =
new (
Z)
1761 CompileType(inferred_type_md->ToCompileType(
Z, &static_type, is_late));
1766 CompileType* inferred_arg_type =
nullptr;
1767 const Object* inferred_arg_value =
nullptr;
1768 if (inferred_arg_type_md !=
nullptr && !inferred_arg_type_md->IsTrivial()) {
1770 new (
Z) CompileType(inferred_arg_type_md->ToCompileType(
Z));
1771 if (inferred_arg_type_md->IsConstant()) {
1772 inferred_arg_value = &inferred_arg_type_md->constant_value;
1775 return new (
Z) LocalVariable(declaration_pos, token_pos,
name, static_type,
1776 kernel_offset, inferred_type, inferred_arg_type,
1777 inferred_arg_value);
1780void ScopeBuilder::AddExceptionVariable(
1781 GrowableArray<LocalVariable*>* variables,
1783 intptr_t nesting_depth) {
1784 LocalVariable* v =
nullptr;
1788 if (depth_.function_ > 0)
return;
1789 if (variables->length() >= nesting_depth)
return;
1794 v = MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
1795 GenerateName(prefix, nesting_depth - 1),
1796 AbstractType::dynamic_type());
1800 v->set_is_forced_stack();
1807void ScopeBuilder::FinalizeExceptionVariable(
1808 GrowableArray<LocalVariable*>* variables,
1809 GrowableArray<LocalVariable*>* raw_variables,
1810 const String& symbol,
1811 intptr_t nesting_depth) {
1814 if (depth_.function_ > 0)
return;
1816 LocalVariable* variable = (*variables)[nesting_depth - 1];
1817 LocalVariable* raw_variable;
1818 if (variable->is_captured()) {
1820 new LocalVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
1821 symbol, AbstractType::dynamic_type());
1822 raw_variable->set_is_forced_stack();
1826 raw_variable = variable;
1828 raw_variables->EnsureLength(nesting_depth,
nullptr);
1829 (*raw_variables)[nesting_depth - 1] = raw_variable;
1832void ScopeBuilder::AddTryVariables() {
1834 ":saved_try_context_var", depth_.try_);
1837void ScopeBuilder::AddCatchVariables() {
1844void ScopeBuilder::FinalizeCatchVariables() {
1846 FinalizeExceptionVariable(
1848 GenerateName(
":raw_exception", unique_id), depth_.catch_);
1849 FinalizeExceptionVariable(
1851 GenerateName(
":raw_stacktrace", unique_id), depth_.catch_);
1854void ScopeBuilder::AddSwitchVariable() {
1855 if ((depth_.function_ == 0) && (result_->
switch_variable ==
nullptr)) {
1856 LocalVariable* variable =
1857 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
1858 Symbols::SwitchExpr(), AbstractType::dynamic_type());
1859 variable->set_is_forced_stack();
1865void ScopeBuilder::VisitVariableGet(intptr_t declaration_binary_offset) {
1866 LocalVariable* variable = LookupVariable(declaration_binary_offset);
1867 if (variable->is_late()) {
1870 AlternativeReadingScope alt(&helper_.
reader_, variable->late_init_offset());
1871 if (helper_.
ReadTag() != kNothing) {
1877LocalVariable* ScopeBuilder::LookupVariable(
1878 intptr_t declaration_binary_offset) {
1879 LocalVariable* variable = result_->
locals.Lookup(declaration_binary_offset);
1880 if (variable ==
nullptr) {
1886 StringIndex var_name = GetNameFromVariableDeclaration(
1890 const String&
name =
H.DartSymbolObfuscate(var_name);
1892 name, declaration_binary_offset,
true);
1893 ASSERT(variable !=
nullptr);
1894 result_->
locals.Insert(declaration_binary_offset, variable);
1897 ASSERT(variable->owner() !=
nullptr);
1898 if (variable->owner()->function_level() < scope_->
function_level()) {
1918StringIndex ScopeBuilder::GetNameFromVariableDeclaration(
1919 intptr_t kernel_offset,
1922 ASSERT(!kernel_data.IsNull());
1925 AlternativeReadingScopeWithNewData alt(&helper_.
reader_, &kernel_data,
1927 VariableDeclarationHelper helper(&helper_);
1929 return helper.name_index_;
1932const String& ScopeBuilder::GenerateName(
const char* prefix, intptr_t suffix) {
1935 return H.DartSymbolObfuscate(
name);
1938void ScopeBuilder::HandleLoadReceiver() {
1940 current_function_scope_->
parent() !=
nullptr) {
1947 if ((current_function_scope_->
parent() !=
nullptr) ||
1958void ScopeBuilder::HandleSpecialLoad(LocalVariable** variable,
1959 const String& symbol,
1960 intptr_t kernel_offset) {
1961 if (current_function_scope_->
parent() !=
nullptr) {
1964 if (*variable ==
nullptr) {
1966 symbol, kernel_offset,
true);
1967 ASSERT(*variable !=
nullptr);
1971 if ((current_function_scope_->
parent() !=
nullptr) ||
static bool ok(int result)
#define RELEASE_ASSERT(cond)
ObjectPtr At(intptr_t index) const
static constexpr bool kCanBeNull
static CompileType FromAbstractType(const AbstractType &type, bool can_be_null, bool can_be_sentinel)
static CompilerState & Current()
intptr_t kernel_offset() const
TypedDataViewPtr KernelLibrary() const
static bool IsDynamicInvocationForwarderName(const String &name)
bool MayHaveUncheckedEntryPoint() const
KernelProgramInfoPtr KernelProgramInfo() const
const char * ToQualifiedCString() const
LocalScope * parent() const
void set_begin_token_pos(TokenPosition value)
void set_end_token_pos(TokenPosition value)
TokenPosition end_token_pos() const
int NumCapturedVariables() const
int function_level() const
static LocalScope * RestoreOuterScope(const ContextScope &context_scope)
LocalVariable * LookupVariable(const String &name, intptr_t kernel_offset, bool test_only)
bool AddVariable(LocalVariable *variable)
void CaptureVariable(LocalVariable *variable)
bool InsertParameterAt(intptr_t pos, LocalVariable *parameter)
void set_context_level(int context_level)
void AddContextVariable(LocalVariable *var)
VariableIndex index() const
void set_is_explicit_covariant_parameter()
void set_type_check_mode(TypeCheckMode mode)
void set_invisible(bool value)
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()
bool has_receiver_var() const
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 int SNPrint(char *str, size_t size, const char *format,...) PRINTF_ATTRIBUTE(3
void ReadUntilExcluding(Field field)
TokenPosition end_position_
static bool IsExpressionTempVarUsedInRecognizedMethodFlowGraph(const Function &function)
static bool IsRecognizedMethodForFlowGraph(const Function &function)
void ReadUntilExcluding(Field field)
void SetOffset(intptr_t offset)
void ReadUntilFunctionNode()
void SkipOptionalDartType()
void SkipListOfDartTypes()
intptr_t data_program_offset_
void SkipConstantReference()
intptr_t ReadListLength()
TokenPosition ReadPosition()
Tag ReadTag(uint8_t *payload=nullptr)
Tag PeekTag(uint8_t *payload=nullptr)
intptr_t ReaderOffset() const
void SkipInterfaceMemberNameReference()
void SkipCanonicalNameReference()
void SkipStringReference()
void SkipBytes(intptr_t skip)
Nullability ReadNullability()
TokenPosition min_position()
TokenPosition max_position()
static const char * TagName(Tag tag)
virtual void ReportUnexpectedTag(const char *variant, Tag tag)
ScopeBuildingResult * BuildScopes()
ScopeBuilder(ParsedFunction *parsed_function)
LocalVariable * type_arguments_variable
LocalVariable * setter_value
IntMap< LocalScope * > scopes
GrowableArray< LocalVariable * > catch_context_variables
GrowableArray< LocalVariable * > stack_trace_variables
GrowableArray< LocalVariable * > raw_exception_variables
intptr_t raw_variable_counter_
LocalVariable * finally_return_variable
LocalVariable * switch_variable
GrowableArray< intptr_t > closure_offsets_without_captures
GrowableArray< LocalVariable * > exception_variables
IntMap< LocalVariable * > locals
GrowableArray< LocalVariable * > raw_stack_trace_variables
GrowableArray< FunctionScope > function_scopes
Dart_NativeFunction function
#define FOR_EACH_DYNAMIC_CLOSURE_CALL_VARIABLE(V)
#define ADD_VAR(Name, _, __)