OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #ifndef VM_DIL_READER_H_ | |
6 #define VM_DIL_READER_H_ | |
7 | |
8 #include <map> | |
rmacnak
2016/10/13 00:56:39
We don't use stl in the VM.
Vyacheslav Egorov (Google)
2016/10/13 14:37:58
It's not completely true: assert.h includes sstrea
| |
9 | |
10 #include "vm/dil.h" | |
11 #include "vm/dil_to_il.h" | |
12 #include "vm/object.h" | |
13 | |
14 namespace dart { | |
15 namespace dil { | |
16 | |
17 class DilReader; | |
18 | |
19 class BuildingTranslationHelper : public TranslationHelper { | |
20 public: | |
21 BuildingTranslationHelper(DilReader* reader, dart::Thread* thread, | |
22 dart::Zone* zone, Isolate* isolate) | |
23 : TranslationHelper(thread, zone, isolate), reader_(reader) {} | |
24 virtual ~BuildingTranslationHelper() {} | |
25 | |
26 virtual void SetFinalize(bool finalize); | |
27 | |
28 virtual RawLibrary* LookupLibraryByDilLibrary(Library* library); | |
29 virtual RawClass* LookupClassByDilClass(Class* klass); | |
30 | |
31 private: | |
32 DilReader* reader_; | |
33 }; | |
34 | |
35 template <typename DilType, typename VmType> | |
36 class Mapping { | |
37 public: | |
38 bool Lookup(DilType* node, VmType** handle) { | |
39 typename MapType::iterator value = map_.find(node); | |
40 if (value != map_.end()) { | |
41 *handle = value->second; | |
42 return true; | |
43 } | |
44 return false; | |
45 } | |
46 | |
47 void Insert(DilType* node, VmType* object) { map_[node] = object; } | |
48 | |
49 private: | |
50 typedef typename std::map<DilType*, VmType*> MapType; | |
51 MapType map_; | |
52 }; | |
53 | |
54 class DilReader { | |
55 public: | |
56 DilReader(const uint8_t* buffer, intptr_t len, bool bootstrapping = false) | |
57 : thread_(dart::Thread::Current()), | |
58 zone_(thread_->zone()), | |
59 isolate_(thread_->isolate()), | |
60 translation_helper_(this, thread_, zone_, isolate_), | |
61 type_translator_(&translation_helper_, &active_class_, !bootstrapping), | |
62 bootstrapping_(bootstrapping), | |
63 finalize_(!bootstrapping), | |
64 buffer_(buffer), | |
65 buffer_length_(len) {} | |
66 | |
67 // Returns either a library or a failure object. | |
68 dart::Object& ReadProgram(); | |
69 | |
70 static void SetupFunctionParameters(TranslationHelper translation_helper_, | |
71 DartTypeTranslator type_translator_, | |
72 const dart::Class& owner, | |
73 const dart::Function& function, | |
74 FunctionNode* dil_function, | |
75 bool is_method, bool is_closure); | |
76 | |
77 void ReadLibrary(Library* dil_library); | |
78 | |
79 private: | |
80 friend class BuildingTranslationHelper; | |
81 | |
82 void ReadPreliminaryClass(dart::Class* klass, Class* dil_klass); | |
83 void ReadClass(const dart::Library& library, Class* dil_klass); | |
84 void ReadProcedure(const dart::Library& library, const dart::Class& owner, | |
85 Procedure* procedure, Class* dil_klass = NULL); | |
86 | |
87 void GenerateFieldAccessors(const dart::Class& klass, | |
88 const dart::Field& field, Field* dil_field); | |
89 | |
90 void SetupFieldAccessorFunction(const dart::Class& klass, | |
91 const dart::Function& function); | |
92 | |
93 dart::Library& LookupLibrary(Library* library); | |
94 dart::Class& LookupClass(Class* klass); | |
95 | |
96 dart::RawFunction::Kind GetFunctionType(Procedure* dil_procedure); | |
97 | |
98 dart::Thread* thread_; | |
99 dart::Zone* zone_; | |
100 dart::Isolate* isolate_; | |
101 ActiveClass active_class_; | |
102 BuildingTranslationHelper translation_helper_; | |
103 DartTypeTranslator type_translator_; | |
104 | |
105 bool bootstrapping_; | |
106 | |
107 // Should created classes be finalized when they are created? | |
108 bool finalize_; | |
109 | |
110 const uint8_t* buffer_; | |
111 intptr_t buffer_length_; | |
112 | |
113 Mapping<Library, dart::Library> libraries_; | |
114 Mapping<Class, dart::Class> classes_; | |
115 }; | |
116 | |
117 } // namespace dil | |
118 } // namespace dart | |
119 | |
120 #endif // VM_DIL_READER_H_ | |
OLD | NEW |