| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/kernel_binary_flowgraph.h" | 5 #include "vm/kernel_binary_flowgraph.h" |
| 6 #include "vm/compiler.h" | 6 #include "vm/compiler.h" |
| 7 #include "vm/longjump.h" | 7 #include "vm/longjump.h" |
| 8 #include "vm/object_store.h" | 8 #include "vm/object_store.h" |
| 9 | 9 |
| 10 #if !defined(DART_PRECOMPILED_RUNTIME) | 10 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 namespace kernel { | 13 namespace kernel { |
| 14 | 14 |
| 15 #define Z (zone_) | 15 #define Z (zone_) |
| 16 #define H (translation_helper_) | 16 #define H (translation_helper_) |
| 17 #define T (type_translator_) | 17 #define T (type_translator_) |
| 18 #define I Isolate::Current() | 18 #define I Isolate::Current() |
| 19 | 19 |
| 20 static bool IsStaticInitializer(const Function& function, Zone* zone) { | 20 static bool IsStaticInitializer(const Function& function, Zone* zone) { |
| 21 return (function.kind() == RawFunction::kImplicitStaticFinalGetter) && | 21 return (function.kind() == RawFunction::kImplicitStaticFinalGetter) && |
| 22 dart::String::Handle(zone, function.name()) | 22 dart::String::Handle(zone, function.name()) |
| 23 .StartsWith(Symbols::InitPrefix()); | 23 .StartsWith(Symbols::InitPrefix()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void FunctionNodeHelper::ReadUntilExcluding(Field field) { |
| 27 if (field <= next_read_) return; |
| 28 |
| 29 // Ordered with fall-through. |
| 30 switch (next_read_) { |
| 31 case kStart: { |
| 32 Tag tag = builder_->ReadTag(); // read tag. |
| 33 ASSERT(tag == kFunctionNode); |
| 34 if (++next_read_ == field) return; |
| 35 } |
| 36 case kPosition: |
| 37 position_ = builder_->ReadPosition(); // read position. |
| 38 if (++next_read_ == field) return; |
| 39 case kEndPosition: |
| 40 end_position_ = builder_->ReadPosition(); // read end position. |
| 41 if (++next_read_ == field) return; |
| 42 case kAsyncMarker: |
| 43 async_marker_ = static_cast<FunctionNode::AsyncMarker>( |
| 44 builder_->ReadByte()); // read async marker. |
| 45 if (++next_read_ == field) return; |
| 46 case kDartAsyncMarker: |
| 47 dart_async_marker_ = static_cast<FunctionNode::AsyncMarker>( |
| 48 builder_->ReadByte()); // read dart async marker. |
| 49 if (++next_read_ == field) return; |
| 50 case kTypeParameters: |
| 51 builder_->SkipTypeParametersList(); // read type parameters. |
| 52 if (++next_read_ == field) return; |
| 53 case kTotalParameterCount: |
| 54 total_parameter_count_ = |
| 55 builder_->ReadUInt(); // read total parameter count. |
| 56 if (++next_read_ == field) return; |
| 57 case kRequiredParameterCount: |
| 58 required_parameter_count_ = |
| 59 builder_->ReadUInt(); // read required parameter count. |
| 60 if (++next_read_ == field) return; |
| 61 case kPositionalParameters: |
| 62 builder_->SkipListOfVariableDeclarations(); // read positionals. |
| 63 if (++next_read_ == field) return; |
| 64 case kNamedParameters: |
| 65 builder_->SkipListOfVariableDeclarations(); // read named. |
| 66 if (++next_read_ == field) return; |
| 67 case kReturnType: |
| 68 builder_->SkipDartType(); // read return type. |
| 69 if (++next_read_ == field) return; |
| 70 case kBody: |
| 71 if (builder_->ReadTag() == kSomething) |
| 72 builder_->SkipStatement(); // read body. |
| 73 if (++next_read_ == field) return; |
| 74 case kEnd: |
| 75 return; |
| 76 } |
| 77 } |
| 78 |
| 79 void VariableDeclarationHelper::ReadUntilExcluding(Field field) { |
| 80 if (field <= next_read_) return; |
| 81 |
| 82 // Ordered with fall-through. |
| 83 switch (next_read_) { |
| 84 case kPosition: |
| 85 position_ = builder_->ReadPosition(); // read position. |
| 86 if (++next_read_ == field) return; |
| 87 case kEqualPosition: |
| 88 equals_position_ = builder_->ReadPosition(); // read equals position. |
| 89 if (++next_read_ == field) return; |
| 90 case kFlags: |
| 91 flags_ = builder_->ReadFlags(); // read flags. |
| 92 if (++next_read_ == field) return; |
| 93 case kNameIndex: |
| 94 name_index_ = builder_->ReadStringReference(); // read name index. |
| 95 if (++next_read_ == field) return; |
| 96 case kType: |
| 97 builder_->SkipDartType(); // read type. |
| 98 if (++next_read_ == field) return; |
| 99 case kInitializer: |
| 100 if (builder_->ReadTag() == kSomething) |
| 101 builder_->SkipExpression(); // read initializer. |
| 102 if (++next_read_ == field) return; |
| 103 case kEnd: |
| 104 return; |
| 105 } |
| 106 } |
| 107 |
| 108 void FieldHelper::ReadUntilExcluding(Field field, |
| 109 bool detect_function_literal_initializer) { |
| 110 if (field <= next_read_) return; |
| 111 |
| 112 // Ordered with fall-through. |
| 113 switch (next_read_) { |
| 114 case kStart: { |
| 115 Tag tag = builder_->ReadTag(); // read tag. |
| 116 ASSERT(tag == kField); |
| 117 if (++next_read_ == field) return; |
| 118 } |
| 119 case kCanonicalName: |
| 120 canonical_name_ = |
| 121 builder_->ReadCanonicalNameReference(); // read canonical_name. |
| 122 if (++next_read_ == field) return; |
| 123 case kPosition: |
| 124 position_ = builder_->ReadPosition(false); // read position. |
| 125 if (++next_read_ == field) return; |
| 126 case kEndPosition: |
| 127 end_position_ = builder_->ReadPosition(false); // read end position. |
| 128 if (++next_read_ == field) return; |
| 129 case kFlags: |
| 130 flags_ = builder_->ReadFlags(); // read flags. |
| 131 if (++next_read_ == field) return; |
| 132 case kName: |
| 133 builder_->SkipName(); // read name. |
| 134 if (++next_read_ == field) return; |
| 135 case kSourceUriIndex: |
| 136 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
| 137 builder_->current_script_id_ = source_uri_index_; |
| 138 builder_->record_token_position(position_); |
| 139 builder_->record_token_position(end_position_); |
| 140 if (++next_read_ == field) return; |
| 141 case kDocumentationCommentIndex: |
| 142 builder_->ReadStringReference(); |
| 143 if (++next_read_ == field) return; |
| 144 case kAnnotations: { |
| 145 annotation_count_ = builder_->ReadListLength(); // read list length. |
| 146 for (intptr_t i = 0; i < annotation_count_; ++i) { |
| 147 builder_->SkipExpression(); // read ith expression. |
| 148 } |
| 149 if (++next_read_ == field) return; |
| 150 } |
| 151 case kType: |
| 152 builder_->SkipDartType(); // read type. |
| 153 if (++next_read_ == field) return; |
| 154 case kInitializer: |
| 155 if (builder_->ReadTag() == kSomething) { |
| 156 if (detect_function_literal_initializer && |
| 157 builder_->PeekTag() == kFunctionExpression) { |
| 158 AlternativeReadingScope alt(builder_->reader_); |
| 159 Tag tag = builder_->ReadTag(); |
| 160 ASSERT(tag == kFunctionExpression); |
| 161 builder_->ReadPosition(); // read position. |
| 162 |
| 163 FunctionNodeHelper helper(builder_); |
| 164 helper.ReadUntilIncluding(FunctionNodeHelper::kEndPosition); |
| 165 |
| 166 has_function_literal_initializer_ = true; |
| 167 function_literal_start_ = helper.position_; |
| 168 function_literal_end_ = helper.end_position_; |
| 169 } |
| 170 builder_->SkipExpression(); // read initializer. |
| 171 } |
| 172 if (++next_read_ == field) return; |
| 173 case kEnd: |
| 174 return; |
| 175 } |
| 176 } |
| 177 |
| 178 void ProcedureHelper::ReadUntilExcluding(Field field) { |
| 179 if (field <= next_read_) return; |
| 180 |
| 181 // Ordered with fall-through. |
| 182 switch (next_read_) { |
| 183 case kStart: { |
| 184 Tag tag = builder_->ReadTag(); // read tag. |
| 185 ASSERT(tag == kProcedure); |
| 186 if (++next_read_ == field) return; |
| 187 } |
| 188 case kCanonicalName: |
| 189 canonical_name_ = |
| 190 builder_->ReadCanonicalNameReference(); // read canonical_name. |
| 191 if (++next_read_ == field) return; |
| 192 case kPosition: |
| 193 position_ = builder_->ReadPosition(false); // read position. |
| 194 if (++next_read_ == field) return; |
| 195 case kEndPosition: |
| 196 end_position_ = builder_->ReadPosition(false); // read end position. |
| 197 if (++next_read_ == field) return; |
| 198 case kKind: |
| 199 kind_ = static_cast<Procedure::ProcedureKind>( |
| 200 builder_->ReadByte()); // read kind. |
| 201 if (++next_read_ == field) return; |
| 202 case kFlags: |
| 203 flags_ = builder_->ReadFlags(); // read flags. |
| 204 if (++next_read_ == field) return; |
| 205 case kName: |
| 206 builder_->SkipName(); // read name. |
| 207 if (++next_read_ == field) return; |
| 208 case kSourceUriIndex: |
| 209 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
| 210 builder_->current_script_id_ = source_uri_index_; |
| 211 builder_->record_token_position(position_); |
| 212 builder_->record_token_position(end_position_); |
| 213 if (++next_read_ == field) return; |
| 214 case kDocumentationCommentIndex: |
| 215 builder_->ReadStringReference(); |
| 216 if (++next_read_ == field) return; |
| 217 case kAnnotations: { |
| 218 annotation_count_ = builder_->ReadListLength(); // read list length. |
| 219 for (intptr_t i = 0; i < annotation_count_; ++i) { |
| 220 builder_->SkipExpression(); // read ith expression. |
| 221 } |
| 222 if (++next_read_ == field) return; |
| 223 } |
| 224 case kFunction: |
| 225 if (builder_->ReadTag() == kSomething) |
| 226 builder_->SkipFunctionNode(); // read function node. |
| 227 if (++next_read_ == field) return; |
| 228 case kEnd: |
| 229 return; |
| 230 } |
| 231 } |
| 232 |
| 233 void ConstructorHelper::ReadUntilExcluding(Field field) { |
| 234 if (field <= next_read_) return; |
| 235 |
| 236 // Ordered with fall-through. |
| 237 switch (next_read_) { |
| 238 case kStart: { |
| 239 Tag tag = builder_->ReadTag(); // read tag. |
| 240 ASSERT(tag == kConstructor); |
| 241 if (++next_read_ == field) return; |
| 242 } |
| 243 case kCanonicalName: |
| 244 canonical_name_ = |
| 245 builder_->ReadCanonicalNameReference(); // read canonical_name. |
| 246 if (++next_read_ == field) return; |
| 247 case kPosition: |
| 248 position_ = builder_->ReadPosition(); // read position. |
| 249 if (++next_read_ == field) return; |
| 250 case kEndPosition: |
| 251 end_position_ = builder_->ReadPosition(); // read end position. |
| 252 if (++next_read_ == field) return; |
| 253 case kFlags: |
| 254 flags_ = builder_->ReadFlags(); // read flags. |
| 255 if (++next_read_ == field) return; |
| 256 case kName: |
| 257 builder_->SkipName(); // read name. |
| 258 if (++next_read_ == field) return; |
| 259 case kDocumentationCommentIndex: |
| 260 builder_->ReadStringReference(); |
| 261 if (++next_read_ == field) return; |
| 262 case kAnnotations: { |
| 263 annotation_count_ = builder_->ReadListLength(); // read list length. |
| 264 for (intptr_t i = 0; i < annotation_count_; ++i) { |
| 265 builder_->SkipExpression(); // read ith expression. |
| 266 } |
| 267 if (++next_read_ == field) return; |
| 268 } |
| 269 case kFunction: |
| 270 builder_->SkipFunctionNode(); // read function. |
| 271 if (++next_read_ == field) return; |
| 272 case kInitializers: { |
| 273 intptr_t list_length = |
| 274 builder_->ReadListLength(); // read initializers list length. |
| 275 for (intptr_t i = 0; i < list_length; i++) { |
| 276 Tag tag = builder_->ReadTag(); |
| 277 builder_->ReadByte(); // read isSynthetic. |
| 278 switch (tag) { |
| 279 case kInvalidInitializer: |
| 280 continue; |
| 281 case kFieldInitializer: |
| 282 builder_->SkipCanonicalNameReference(); // read field_reference. |
| 283 builder_->SkipExpression(); // read value. |
| 284 continue; |
| 285 case kSuperInitializer: |
| 286 builder_->SkipCanonicalNameReference(); // read target_reference. |
| 287 builder_->SkipArguments(); // read arguments. |
| 288 continue; |
| 289 case kRedirectingInitializer: |
| 290 builder_->SkipCanonicalNameReference(); // read target_reference. |
| 291 builder_->SkipArguments(); // read arguments. |
| 292 continue; |
| 293 case kLocalInitializer: |
| 294 builder_->SkipVariableDeclaration(); // read variable. |
| 295 continue; |
| 296 default: |
| 297 UNREACHABLE(); |
| 298 } |
| 299 } |
| 300 if (++next_read_ == field) return; |
| 301 } |
| 302 case kEnd: |
| 303 return; |
| 304 } |
| 305 } |
| 306 |
| 307 void ClassHelper::ReadUntilExcluding(Field field) { |
| 308 if (field <= next_read_) return; |
| 309 |
| 310 // Ordered with fall-through. |
| 311 switch (next_read_) { |
| 312 case kStart: { |
| 313 Tag tag = builder_->ReadTag(); // read tag. |
| 314 ASSERT(tag == kClass); |
| 315 if (++next_read_ == field) return; |
| 316 } |
| 317 case kCanonicalName: |
| 318 canonical_name_ = |
| 319 builder_->ReadCanonicalNameReference(); // read canonical_name. |
| 320 if (++next_read_ == field) return; |
| 321 case kPosition: |
| 322 position_ = builder_->ReadPosition(false); // read position. |
| 323 if (++next_read_ == field) return; |
| 324 case kEndPosition: |
| 325 end_position_ = builder_->ReadPosition(); // read end position. |
| 326 if (++next_read_ == field) return; |
| 327 case kIsAbstract: |
| 328 is_abstract_ = builder_->ReadBool(); // read is_abstract. |
| 329 if (++next_read_ == field) return; |
| 330 case kNameIndex: |
| 331 name_index_ = builder_->ReadStringReference(); // read name index. |
| 332 if (++next_read_ == field) return; |
| 333 case kSourceUriIndex: |
| 334 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
| 335 builder_->current_script_id_ = source_uri_index_; |
| 336 builder_->record_token_position(position_); |
| 337 if (++next_read_ == field) return; |
| 338 case kDocumentationCommentIndex: |
| 339 builder_->ReadStringReference(); |
| 340 if (++next_read_ == field) return; |
| 341 case kAnnotations: { |
| 342 annotation_count_ = builder_->ReadListLength(); // read list length. |
| 343 for (intptr_t i = 0; i < annotation_count_; ++i) { |
| 344 builder_->SkipExpression(); // read ith expression. |
| 345 } |
| 346 if (++next_read_ == field) return; |
| 347 } |
| 348 case kTypeParameters: |
| 349 builder_->SkipTypeParametersList(); // read type parameters. |
| 350 if (++next_read_ == field) return; |
| 351 case kSuperClass: { |
| 352 Tag type_tag = builder_->ReadTag(); // read super class type (part 1). |
| 353 if (type_tag == kSomething) { |
| 354 builder_->SkipDartType(); // read super class type (part 2). |
| 355 } |
| 356 if (++next_read_ == field) return; |
| 357 } |
| 358 case kMixinType: { |
| 359 Tag type_tag = builder_->ReadTag(); // read mixin type (part 1). |
| 360 if (type_tag == kSomething) { |
| 361 builder_->SkipDartType(); // read mixin type (part 2). |
| 362 } |
| 363 if (++next_read_ == field) return; |
| 364 } |
| 365 case kImplementedClasses: |
| 366 builder_->SkipListOfDartTypes(); // read implemented_classes. |
| 367 if (++next_read_ == field) return; |
| 368 case kFields: { |
| 369 intptr_t list_length = |
| 370 builder_->ReadListLength(); // read fields list length. |
| 371 for (intptr_t i = 0; i < list_length; i++) { |
| 372 FieldHelper field_helper(builder_); |
| 373 field_helper.ReadUntilExcluding(FieldHelper::kEnd); // read field. |
| 374 } |
| 375 if (++next_read_ == field) return; |
| 376 } |
| 377 case kConstructors: { |
| 378 intptr_t list_length = |
| 379 builder_->ReadListLength(); // read constructors list length. |
| 380 for (intptr_t i = 0; i < list_length; i++) { |
| 381 ConstructorHelper constructor_helper(builder_); |
| 382 constructor_helper.ReadUntilExcluding( |
| 383 ConstructorHelper::kEnd); // read constructor. |
| 384 } |
| 385 if (++next_read_ == field) return; |
| 386 } |
| 387 case kProcedures: { |
| 388 intptr_t list_length = |
| 389 builder_->ReadListLength(); // read procedures list length. |
| 390 for (intptr_t i = 0; i < list_length; i++) { |
| 391 ProcedureHelper procedure_helper(builder_); |
| 392 procedure_helper.ReadUntilExcluding( |
| 393 ProcedureHelper::kEnd); // read procedure. |
| 394 } |
| 395 if (++next_read_ == field) return; |
| 396 } |
| 397 case kEnd: |
| 398 return; |
| 399 } |
| 400 } |
| 401 |
| 402 void LibraryHelper::ReadUntilExcluding(Field field) { |
| 403 if (field <= next_read_) return; |
| 404 |
| 405 // Ordered with fall-through. |
| 406 switch (next_read_) { |
| 407 case kFlags: { |
| 408 word flags = builder_->ReadFlags(); // read flags. |
| 409 ASSERT(flags == 0); // external libraries not supported |
| 410 if (++next_read_ == field) return; |
| 411 } |
| 412 case kCanonicalName: |
| 413 canonical_name_ = |
| 414 builder_->ReadCanonicalNameReference(); // read canonical_name. |
| 415 if (++next_read_ == field) return; |
| 416 case kName: |
| 417 name_index_ = builder_->ReadStringReference(); // read name index. |
| 418 if (++next_read_ == field) return; |
| 419 case kSourceUriIndex: |
| 420 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
| 421 builder_->current_script_id_ = source_uri_index_; |
| 422 if (++next_read_ == field) return; |
| 423 case kAnnotations: |
| 424 builder_->SkipListOfExpressions(); // read annotations. |
| 425 if (++next_read_ == field) return; |
| 426 case kDependencies: { |
| 427 intptr_t dependency_count = builder_->ReadUInt(); // read list length. |
| 428 for (intptr_t i = 0; i < dependency_count; ++i) { |
| 429 builder_->SkipLibraryDependency(); |
| 430 } |
| 431 if (++next_read_ == field) return; |
| 432 } |
| 433 case kParts: { |
| 434 intptr_t part_count = builder_->ReadUInt(); // read list length. |
| 435 for (intptr_t i = 0; i < part_count; ++i) { |
| 436 builder_->SkipLibraryPart(); |
| 437 } |
| 438 if (++next_read_ == field) return; |
| 439 } |
| 440 case kTypedefs: { |
| 441 intptr_t typedef_count = builder_->ReadListLength(); // read list length. |
| 442 for (intptr_t i = 0; i < typedef_count; i++) { |
| 443 builder_->SkipLibraryTypedef(); |
| 444 } |
| 445 if (++next_read_ == field) return; |
| 446 } |
| 447 case kClasses: { |
| 448 int class_count = builder_->ReadListLength(); // read list length. |
| 449 for (intptr_t i = 0; i < class_count; ++i) { |
| 450 ClassHelper class_helper(builder_); |
| 451 class_helper.ReadUntilExcluding(ClassHelper::kEnd); |
| 452 } |
| 453 if (++next_read_ == field) return; |
| 454 } |
| 455 case kToplevelField: { |
| 456 intptr_t field_count = builder_->ReadListLength(); // read list length. |
| 457 for (intptr_t i = 0; i < field_count; ++i) { |
| 458 FieldHelper field_helper(builder_); |
| 459 field_helper.ReadUntilExcluding(FieldHelper::kEnd); |
| 460 } |
| 461 if (++next_read_ == field) return; |
| 462 } |
| 463 case kToplevelProcedures: { |
| 464 intptr_t procedure_count = |
| 465 builder_->ReadListLength(); // read list length. |
| 466 for (intptr_t i = 0; i < procedure_count; ++i) { |
| 467 ProcedureHelper procedure_helper(builder_); |
| 468 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd); |
| 469 } |
| 470 if (++next_read_ == field) return; |
| 471 } |
| 472 case kEnd: |
| 473 return; |
| 474 } |
| 475 } |
| 476 |
| 26 StreamingScopeBuilder::StreamingScopeBuilder(ParsedFunction* parsed_function, | 477 StreamingScopeBuilder::StreamingScopeBuilder(ParsedFunction* parsed_function, |
| 27 intptr_t relative_kernel_offset, | 478 intptr_t relative_kernel_offset, |
| 28 const TypedData& data) | 479 const TypedData& data) |
| 29 : result_(NULL), | 480 : result_(NULL), |
| 30 parsed_function_(parsed_function), | 481 parsed_function_(parsed_function), |
| 31 relative_kernel_offset_(relative_kernel_offset), | 482 relative_kernel_offset_(relative_kernel_offset), |
| 32 translation_helper_(Thread::Current()), | 483 translation_helper_(Thread::Current()), |
| 33 zone_(translation_helper_.zone()), | 484 zone_(translation_helper_.zone()), |
| 34 current_function_scope_(NULL), | 485 current_function_scope_(NULL), |
| 35 scope_(NULL), | 486 scope_(NULL), |
| (...skipping 7291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7327 } | 7778 } |
| 7328 } | 7779 } |
| 7329 | 7780 |
| 7330 return Array::Handle(Array::null()); | 7781 return Array::Handle(Array::null()); |
| 7331 } | 7782 } |
| 7332 | 7783 |
| 7333 } // namespace kernel | 7784 } // namespace kernel |
| 7334 } // namespace dart | 7785 } // namespace dart |
| 7335 | 7786 |
| 7336 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 7787 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |