| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 #ifndef RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 5 #ifndef RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
| 6 #define RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 6 #define RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
| 7 | 7 |
| 8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 kFlags, | 846 kFlags, |
| 847 kParentClassBinaryOffset, | 847 kParentClassBinaryOffset, |
| 848 kName, | 848 kName, |
| 849 kSourceUriIndex, | 849 kSourceUriIndex, |
| 850 kAnnotations, | 850 kAnnotations, |
| 851 kType, | 851 kType, |
| 852 kInitializer, | 852 kInitializer, |
| 853 kEnd | 853 kEnd |
| 854 }; | 854 }; |
| 855 | 855 |
| 856 explicit FieldHelper(StreamingFlowGraphBuilder* builder) { | 856 explicit FieldHelper(StreamingFlowGraphBuilder* builder) |
| 857 builder_ = builder; | 857 : builder_(builder), |
| 858 next_read_ = kStart; | 858 next_read_(kStart), |
| 859 has_function_literal_initializer_(false) {} |
| 860 |
| 861 FieldHelper(StreamingFlowGraphBuilder* builder, intptr_t offset) |
| 862 : builder_(builder), |
| 863 next_read_(kStart), |
| 864 has_function_literal_initializer_(false) { |
| 865 builder_->SetOffset(offset); |
| 859 } | 866 } |
| 860 | 867 |
| 861 void ReadUntilIncluding(Fields field) { | 868 void ReadUntilIncluding(Fields field) { |
| 862 ReadUntilExcluding(static_cast<Fields>(static_cast<int>(field) + 1)); | 869 ReadUntilExcluding(static_cast<Fields>(static_cast<int>(field) + 1)); |
| 863 } | 870 } |
| 864 | 871 |
| 865 void ReadUntilExcluding(Fields field) { | 872 void ReadUntilExcluding(Fields field, |
| 873 bool detect_function_literal_initializer = false) { |
| 866 if (field <= next_read_) return; | 874 if (field <= next_read_) return; |
| 867 | 875 |
| 868 // Ordered with fall-through. | 876 // Ordered with fall-through. |
| 869 switch (next_read_) { | 877 switch (next_read_) { |
| 870 case kStart: { | 878 case kStart: { |
| 871 Tag tag = builder_->ReadTag(); // read tag. | 879 Tag tag = builder_->ReadTag(); // read tag. |
| 872 ASSERT(tag == kField); | 880 ASSERT(tag == kField); |
| 873 if (++next_read_ == field) return; | 881 if (++next_read_ == field) return; |
| 874 } | 882 } |
| 875 case kCanonicalName: | 883 case kCanonicalName: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 902 annotation_count_ = builder_->ReadListLength(); // read list length. | 910 annotation_count_ = builder_->ReadListLength(); // read list length. |
| 903 for (intptr_t i = 0; i < annotation_count_; ++i) { | 911 for (intptr_t i = 0; i < annotation_count_; ++i) { |
| 904 builder_->SkipExpression(); // read ith expression. | 912 builder_->SkipExpression(); // read ith expression. |
| 905 } | 913 } |
| 906 if (++next_read_ == field) return; | 914 if (++next_read_ == field) return; |
| 907 } | 915 } |
| 908 case kType: | 916 case kType: |
| 909 builder_->SkipDartType(); // read type. | 917 builder_->SkipDartType(); // read type. |
| 910 if (++next_read_ == field) return; | 918 if (++next_read_ == field) return; |
| 911 case kInitializer: | 919 case kInitializer: |
| 912 if (builder_->ReadTag() == kSomething) | 920 if (builder_->ReadTag() == kSomething) { |
| 921 if (detect_function_literal_initializer && |
| 922 builder_->PeekTag() == kFunctionExpression) { |
| 923 has_function_literal_initializer_ = true; |
| 924 intptr_t expr_offset = builder_->ReaderOffset(); |
| 925 Tag tag = builder_->ReadTag(); |
| 926 ASSERT(tag == kFunctionExpression); |
| 927 tag = builder_->ReadTag(); |
| 928 ASSERT(tag == kFunctionNode); |
| 929 function_literal_start_ = builder_->ReadPosition(); |
| 930 function_literal_end_ = builder_->ReadPosition(); |
| 931 |
| 932 builder_->SetOffset(expr_offset); |
| 933 } |
| 913 builder_->SkipExpression(); // read initializer. | 934 builder_->SkipExpression(); // read initializer. |
| 935 } |
| 914 if (++next_read_ == field) return; | 936 if (++next_read_ == field) return; |
| 915 case kEnd: | 937 case kEnd: |
| 916 return; | 938 return; |
| 917 } | 939 } |
| 918 } | 940 } |
| 919 | 941 |
| 920 void SetNext(Fields field) { next_read_ = field; } | 942 void SetNext(Fields field) { next_read_ = field; } |
| 921 void SetJustRead(Fields field) { | 943 void SetJustRead(Fields field) { |
| 922 next_read_ = field; | 944 next_read_ = field; |
| 923 ++next_read_; | 945 ++next_read_; |
| 924 } | 946 } |
| 925 | 947 |
| 926 bool IsConst() { return (flags_ & Field::kFlagConst) == Field::kFlagConst; } | 948 bool IsConst() { return (flags_ & Field::kFlagConst) == Field::kFlagConst; } |
| 927 bool IsFinal() { return (flags_ & Field::kFlagFinal) == Field::kFlagFinal; } | 949 bool IsFinal() { return (flags_ & Field::kFlagFinal) == Field::kFlagFinal; } |
| 928 bool IsStatic() { | 950 bool IsStatic() { |
| 929 return (flags_ & Field::kFlagStatic) == Field::kFlagStatic; | 951 return (flags_ & Field::kFlagStatic) == Field::kFlagStatic; |
| 930 } | 952 } |
| 931 | 953 |
| 954 bool FieldHasFunctionLiteralInitializer(TokenPosition* start, |
| 955 TokenPosition* end) { |
| 956 if (has_function_literal_initializer_) { |
| 957 *start = function_literal_start_; |
| 958 *end = function_literal_end_; |
| 959 } |
| 960 return has_function_literal_initializer_; |
| 961 } |
| 962 |
| 932 NameIndex canonical_name_; | 963 NameIndex canonical_name_; |
| 933 TokenPosition position_; | 964 TokenPosition position_; |
| 934 TokenPosition end_position_; | 965 TokenPosition end_position_; |
| 935 word flags_; | 966 word flags_; |
| 936 intptr_t parent_class_binary_offset_; | 967 intptr_t parent_class_binary_offset_; |
| 937 intptr_t source_uri_index_; | 968 intptr_t source_uri_index_; |
| 938 intptr_t annotation_count_; | 969 intptr_t annotation_count_; |
| 939 | 970 |
| 940 private: | 971 private: |
| 941 StreamingFlowGraphBuilder* builder_; | 972 StreamingFlowGraphBuilder* builder_; |
| 942 intptr_t next_read_; | 973 intptr_t next_read_; |
| 974 |
| 975 bool has_function_literal_initializer_; |
| 976 TokenPosition function_literal_start_; |
| 977 TokenPosition function_literal_end_; |
| 943 }; | 978 }; |
| 944 | 979 |
| 945 // Helper class that reads a kernel Procedure from binary. | 980 // Helper class that reads a kernel Procedure from binary. |
| 946 // | 981 // |
| 947 // Use ReadUntilExcluding to read up to but not including a field. | 982 // Use ReadUntilExcluding to read up to but not including a field. |
| 948 // One can then for instance read the field from the call-site (and remember to | 983 // One can then for instance read the field from the call-site (and remember to |
| 949 // call SetAt to inform this helper class), and then use this to read more. | 984 // call SetAt to inform this helper class), and then use this to read more. |
| 950 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. | 985 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. |
| 951 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. | 986 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. |
| 952 class ProcedureHelper { | 987 class ProcedureHelper { |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 private: | 1517 private: |
| 1483 Reader* reader_; | 1518 Reader* reader_; |
| 1484 intptr_t saved_offset_; | 1519 intptr_t saved_offset_; |
| 1485 }; | 1520 }; |
| 1486 | 1521 |
| 1487 } // namespace kernel | 1522 } // namespace kernel |
| 1488 } // namespace dart | 1523 } // namespace dart |
| 1489 | 1524 |
| 1490 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1525 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 1491 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 1526 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
| OLD | NEW |