@@ -278,7 +278,7 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() {
278
278
TokenPosition::kNoSource , TokenPosition::kNoSource ,
279
279
Symbols::Value (),
280
280
AbstractType::ZoneHandle (Z, function.ParameterTypeAt (pos)),
281
- ¶meter_type);
281
+ LocalVariable:: kNoKernelOffset , ¶meter_type);
282
282
} else {
283
283
result_->setter_value = MakeVariable (
284
284
TokenPosition::kNoSource , TokenPosition::kNoSource ,
@@ -577,12 +577,12 @@ void ScopeBuilder::VisitFunctionNode() {
577
577
// Mark known chained futures such as _Future::timeout()'s _future.
578
578
if (function.recognized_kind () == MethodRecognizer::kFutureTimeout &&
579
579
depth_.function_ == 1 ) {
580
- LocalVariable* future = scope_->LookupVariable (Symbols::_future (), true );
580
+ LocalVariable* future = scope_->LookupVariableByName (Symbols::_future ());
581
581
ASSERT (future != nullptr );
582
582
future->set_is_chained_future ();
583
583
} else if (function.recognized_kind () == MethodRecognizer::kFutureWait &&
584
584
depth_.function_ == 1 ) {
585
- LocalVariable* future = scope_->LookupVariable (Symbols::_future (), true );
585
+ LocalVariable* future = scope_->LookupVariableByName (Symbols::_future ());
586
586
ASSERT (future != nullptr );
587
587
future->set_is_chained_future ();
588
588
}
@@ -1311,7 +1311,8 @@ void ScopeBuilder::VisitArguments() {
1311
1311
void ScopeBuilder::VisitVariableDeclaration () {
1312
1312
PositionScope scope (&helper_.reader_ );
1313
1313
1314
- intptr_t kernel_offset_no_tag = helper_.ReaderOffset ();
1314
+ const intptr_t kernel_offset =
1315
+ helper_.data_program_offset_ + helper_.ReaderOffset ();
1315
1316
VariableDeclarationHelper helper (&helper_);
1316
1317
helper.ReadUntilExcluding (VariableDeclarationHelper::kType );
1317
1318
AbstractType& type = BuildAndVisitVariableType ();
@@ -1336,7 +1337,7 @@ void ScopeBuilder::VisitVariableDeclaration() {
1336
1337
end_position = end_position.Next ();
1337
1338
}
1338
1339
LocalVariable* variable =
1339
- MakeVariable (helper.position_ , end_position, name, type);
1340
+ MakeVariable (helper.position_ , end_position, name, type, kernel_offset );
1340
1341
if (helper.IsFinal ()) {
1341
1342
variable->set_is_final ();
1342
1343
}
@@ -1346,8 +1347,7 @@ void ScopeBuilder::VisitVariableDeclaration() {
1346
1347
}
1347
1348
1348
1349
scope_->AddVariable (variable);
1349
- result_->locals .Insert (helper_.data_program_offset_ + kernel_offset_no_tag,
1350
- variable);
1350
+ result_->locals .Insert (kernel_offset, variable);
1351
1351
}
1352
1352
1353
1353
AbstractType& ScopeBuilder::BuildAndVisitVariableType () {
@@ -1486,7 +1486,8 @@ void ScopeBuilder::VisitTypeParameterType() {
1486
1486
// The type argument vector is passed as the very first argument to the
1487
1487
// factory constructor function.
1488
1488
HandleSpecialLoad (&result_->type_arguments_variable ,
1489
- Symbols::TypeArgumentsParameter ());
1489
+ Symbols::TypeArgumentsParameter (),
1490
+ LocalVariable::kNoKernelOffset );
1490
1491
} else {
1491
1492
// If the type parameter is a parameter to this or an enclosing function,
1492
1493
// we can read it directly from the function type arguments vector later.
@@ -1608,9 +1609,12 @@ void ScopeBuilder::AddVariableDeclarationParameter(
1608
1609
intptr_t pos,
1609
1610
ParameterTypeCheckMode type_check_mode,
1610
1611
const ProcedureAttributesMetadata& attrs) {
1611
- intptr_t kernel_offset = helper_.ReaderOffset (); // no tag.
1612
+ // Convert kernel offset of variable declaration to absolute.
1613
+ const intptr_t kernel_offset =
1614
+ helper_.data_program_offset_ + helper_.ReaderOffset ();
1615
+ // MetadataHelper expects relative offsets and adjusts them internally
1612
1616
const InferredTypeMetadata parameter_type =
1613
- inferred_type_metadata_helper_.GetInferredType (kernel_offset );
1617
+ inferred_type_metadata_helper_.GetInferredType (helper_. ReaderOffset () );
1614
1618
VariableDeclarationHelper helper (&helper_);
1615
1619
helper.ReadUntilExcluding (VariableDeclarationHelper::kType );
1616
1620
String& name = H.DartSymbolObfuscate (helper.name_index_ );
@@ -1619,8 +1623,9 @@ void ScopeBuilder::AddVariableDeclarationParameter(
1619
1623
helper.SetJustRead (VariableDeclarationHelper::kType );
1620
1624
helper.ReadUntilExcluding (VariableDeclarationHelper::kInitializer );
1621
1625
1622
- LocalVariable* variable = MakeVariable (helper.position_ , helper.position_ ,
1623
- name, type, ¶meter_type);
1626
+ LocalVariable* variable =
1627
+ MakeVariable (helper.position_ , helper.position_ , name, type,
1628
+ kernel_offset, ¶meter_type);
1624
1629
if (helper.IsFinal ()) {
1625
1630
variable->set_is_final ();
1626
1631
}
@@ -1681,8 +1686,7 @@ void ScopeBuilder::AddVariableDeclarationParameter(
1681
1686
}
1682
1687
1683
1688
scope_->InsertParameterAt (pos, variable);
1684
- result_->locals .Insert (helper_.data_program_offset_ + kernel_offset,
1685
- variable);
1689
+ result_->locals .Insert (kernel_offset, variable);
1686
1690
1687
1691
// The default value may contain 'let' bindings for which the constant
1688
1692
// evaluator needs scope bindings.
@@ -1697,6 +1701,7 @@ LocalVariable* ScopeBuilder::MakeVariable(
1697
1701
TokenPosition token_pos,
1698
1702
const String& name,
1699
1703
const AbstractType& type,
1704
+ intptr_t kernel_offset,
1700
1705
const InferredTypeMetadata* param_type_md /* = NULL */ ) {
1701
1706
CompileType* param_type = nullptr ;
1702
1707
const Object* param_value = nullptr ;
@@ -1707,7 +1712,7 @@ LocalVariable* ScopeBuilder::MakeVariable(
1707
1712
}
1708
1713
}
1709
1714
return new (Z) LocalVariable (declaration_pos, token_pos, name, type,
1710
- param_type, param_value);
1715
+ kernel_offset, param_type, param_value);
1711
1716
}
1712
1717
1713
1718
void ScopeBuilder::AddExceptionVariable (
@@ -1823,7 +1828,7 @@ void ScopeBuilder::VisitVariableGet(intptr_t declaration_binary_offset) {
1823
1828
LocalVariable* ScopeBuilder::LookupVariable (
1824
1829
intptr_t declaration_binary_offset) {
1825
1830
LocalVariable* variable = result_->locals .Lookup (declaration_binary_offset);
1826
- if (variable == NULL ) {
1831
+ if (variable == nullptr ) {
1827
1832
// We have not seen a declaration of the variable, so it must be the
1828
1833
// case that we are compiling a nested function and the variable is
1829
1834
// declared in an outer scope. In that case, look it up in the scope by
@@ -1834,11 +1839,13 @@ LocalVariable* ScopeBuilder::LookupVariable(
1834
1839
parsed_function_->function ());
1835
1840
1836
1841
const String& name = H.DartSymbolObfuscate (var_name);
1837
- variable = current_function_scope_->parent ()->LookupVariable (name, true );
1838
- ASSERT (variable != NULL );
1842
+ variable = current_function_scope_->parent ()->LookupVariable (
1843
+ name, declaration_binary_offset, true );
1844
+ ASSERT (variable != nullptr );
1839
1845
result_->locals .Insert (declaration_binary_offset, variable);
1840
1846
}
1841
1847
1848
+ ASSERT (variable->owner () != nullptr );
1842
1849
if (variable->owner ()->function_level () < scope_->function_level ()) {
1843
1850
// We call `LocalScope->CaptureVariable(variable)` in two scenarios for two
1844
1851
// different reasons:
@@ -1885,8 +1892,8 @@ void ScopeBuilder::HandleLoadReceiver() {
1885
1892
current_function_scope_->parent () != nullptr ) {
1886
1893
// Lazily populate receiver variable using the parent function scope.
1887
1894
parsed_function_->set_receiver_var (
1888
- current_function_scope_->parent ()->LookupVariable (Symbols::This (),
1889
- true ));
1895
+ current_function_scope_->parent ()->LookupVariable (
1896
+ Symbols::This (), LocalVariable:: kNoKernelOffset , true ));
1890
1897
}
1891
1898
1892
1899
if ((current_function_scope_->parent () != nullptr ) ||
@@ -1899,13 +1906,14 @@ void ScopeBuilder::HandleLoadReceiver() {
1899
1906
}
1900
1907
1901
1908
void ScopeBuilder::HandleSpecialLoad (LocalVariable** variable,
1902
- const String& symbol) {
1909
+ const String& symbol,
1910
+ intptr_t kernel_offset) {
1903
1911
if (current_function_scope_->parent () != NULL ) {
1904
1912
// We are building the scope tree of a closure function and saw [node]. We
1905
1913
// lazily populate the variable using the parent function scope.
1906
1914
if (*variable == NULL ) {
1907
- *variable =
1908
- current_function_scope_-> parent ()-> LookupVariable ( symbol, true );
1915
+ *variable = current_function_scope_-> parent ()-> LookupVariable (
1916
+ symbol, kernel_offset , true );
1909
1917
ASSERT (*variable != NULL );
1910
1918
}
1911
1919
}
@@ -1919,14 +1927,5 @@ void ScopeBuilder::HandleSpecialLoad(LocalVariable** variable,
1919
1927
}
1920
1928
}
1921
1929
1922
- void ScopeBuilder::LookupCapturedVariableByName (LocalVariable** variable,
1923
- const String& name) {
1924
- if (*variable == NULL ) {
1925
- *variable = scope_->LookupVariable (name, true );
1926
- ASSERT (*variable != NULL );
1927
- scope_->CaptureVariable (*variable);
1928
- }
1929
- }
1930
-
1931
1930
} // namespace kernel
1932
1931
} // namespace dart
0 commit comments