Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: runtime/vm/kernel.cc

Issue 2820363002: Move Kernel strings into the VM's heap. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.h" 5 #include "vm/kernel.h"
6 6
7 #if !defined(DART_PRECOMPILED_RUNTIME) 7 #if !defined(DART_PRECOMPILED_RUNTIME)
8 namespace dart { 8 namespace dart {
9 9
10 namespace kernel { 10 namespace kernel {
11 11
12 12
13 template <typename T> 13 template <typename T>
14 void VisitList(List<T>* list, Visitor* visitor) { 14 void VisitList(List<T>* list, Visitor* visitor) {
15 for (int i = 0; i < list->length(); ++i) { 15 for (int i = 0; i < list->length(); ++i) {
16 (*list)[i]->AcceptVisitor(visitor); 16 (*list)[i]->AcceptVisitor(visitor);
17 } 17 }
18 } 18 }
19 19
20 20
21 Source::~Source() {
22 delete[] uri_;
23 delete[] source_code_;
24 delete[] line_starts_;
25 }
26
27
28 SourceTable::~SourceTable() {
29 delete[] sources_;
30 }
31
32
21 CanonicalName::CanonicalName() : is_referenced_(false) {} 33 CanonicalName::CanonicalName() : is_referenced_(false) {}
22 34
23 35
24 CanonicalName::~CanonicalName() { 36 CanonicalName::~CanonicalName() {
25 for (intptr_t i = 0; i < children_.length(); ++i) { 37 for (intptr_t i = 0; i < children_.length(); ++i) {
26 delete children_[i]; 38 delete children_[i];
27 } 39 }
28 } 40 }
29 41
30 42
31 CanonicalName* CanonicalName::NewRoot() { 43 CanonicalName* CanonicalName::NewRoot() {
32 return new CanonicalName(); 44 return new CanonicalName();
33 } 45 }
34 46
35 47
36 CanonicalName* CanonicalName::AddChild(String* name) { 48 CanonicalName* CanonicalName::AddChild(String* name) {
37 CanonicalName* child = new CanonicalName(); 49 CanonicalName* child = new CanonicalName();
38 child->parent_ = this; 50 child->parent_ = this;
39 child->name_ = name; 51 child->name_ = name;
40 children_.Add(child); 52 children_.Add(child);
41 return child; 53 return child;
42 } 54 }
43 55
44 56
45 bool CanonicalName::IsAdministrative() {
46 // Administrative names start with '@'.
47 return (name()->size() > 0) && (name()->buffer()[0] == '@');
48 }
49
50
51 bool CanonicalName::IsPrivate() {
52 // Private names start with '_'.
53 return (name()->size() > 0) && (name()->buffer()[0] == '_');
54 }
55
56
57 bool CanonicalName::IsRoot() {
58 // The root is the only canonical name with no parent.
59 return parent() == NULL;
60 }
61
62
63 bool CanonicalName::IsLibrary() {
64 // Libraries are the only canonical names with the root as their parent.
65 return !IsRoot() && parent()->IsRoot();
66 }
67
68
69 bool CanonicalName::IsClass() {
70 // Classes have the library as their parent and are not an administrative
71 // name starting with @.
72 return !IsAdministrative() && !IsRoot() && parent()->IsLibrary();
73 }
74
75
76 bool CanonicalName::IsMember() {
77 return IsConstructor() || IsField() || IsProcedure();
78 }
79
80
81 // Note the two occurrences of the parameter 'literal'.
82 #define COMPARE_NAME(canonical_name, literal) \
83 ((canonical_name)->name()->size() == \
84 static_cast<intptr_t>(strlen(literal)) && \
85 memcmp((canonical_name)->name()->buffer(), (literal), strlen(literal)) == \
86 0)
87
88 bool CanonicalName::IsField() {
89 // Fields with private names have the import URI of the library where they are
90 // visible as the parent and the string "@fields" as the parent's parent.
91 // Fields with non-private names have the string "@fields' as the parent.
92 if (IsRoot()) {
93 return false;
94 }
95 CanonicalName* kind = this->parent();
96 if (IsPrivate()) {
97 kind = kind->parent();
98 }
99 return COMPARE_NAME(kind, "@fields");
100 }
101
102
103 bool CanonicalName::IsConstructor() {
104 // Constructors with private names have the import URI of the library where
105 // they are visible as the parent and the string "@constructors" as the
106 // parent's parent. Constructors with non-private names have the string
107 // "@constructors" as the parent.
108 if (IsRoot()) {
109 return false;
110 }
111 CanonicalName* kind = this->parent();
112 if (IsPrivate()) {
113 kind = kind->parent();
114 }
115 return COMPARE_NAME(kind, "@constructors");
116 }
117
118
119 bool CanonicalName::IsProcedure() {
120 return IsMethod() || IsGetter() || IsSetter() || IsFactory();
121 }
122
123
124 bool CanonicalName::IsMethod() {
125 // Methods with private names have the import URI of the library where they
126 // are visible as the parent and the string "@methods" as the parent's parent.
127 // Methods with non-private names have the string "@methods" as the parent.
128 if (IsRoot()) {
129 return false;
130 }
131 CanonicalName* kind = this->parent();
132 if (IsPrivate()) {
133 kind = kind->parent();
134 }
135 return COMPARE_NAME(kind, "@methods");
136 }
137
138
139 bool CanonicalName::IsGetter() {
140 // Getters with private names have the import URI of the library where they
141 // are visible as the parent and the string "@getters" as the parent's parent.
142 // Getters with non-private names have the string "@getters" as the parent.
143 if (IsRoot()) {
144 return false;
145 }
146 CanonicalName* kind = this->parent();
147 if (IsPrivate()) {
148 kind = kind->parent();
149 }
150 return COMPARE_NAME(kind, "@getters");
151 }
152
153
154 bool CanonicalName::IsSetter() {
155 // Setters with private names have the import URI of the library where they
156 // are visible as the parent and the string "@setters" as the parent's parent.
157 // Setters with non-private names have the string "@setters" as the parent.
158 if (IsRoot()) {
159 return false;
160 }
161 CanonicalName* kind = this->parent();
162 if (IsPrivate()) {
163 kind = kind->parent();
164 }
165 return COMPARE_NAME(kind, "@setters");
166 }
167
168
169 bool CanonicalName::IsFactory() {
170 // Factories with private names have the import URI of the library where they
171 // are visible as the parent and the string "@factories" as the parent's
172 // parent. Factories with non-private names have the string "@factories" as
173 // the parent.
174 if (IsRoot()) {
175 return false;
176 }
177 CanonicalName* kind = this->parent();
178 if (IsPrivate()) {
179 kind = kind->parent();
180 }
181 return COMPARE_NAME(kind, "@factories");
182 }
183
184 #undef COMPARE_NAME
185
186
187 CanonicalName* CanonicalName::EnclosingName() {
188 ASSERT(IsField() || IsConstructor() || IsProcedure());
189 CanonicalName* enclosing = parent()->parent();
190 if (IsPrivate()) {
191 enclosing = enclosing->parent();
192 }
193 ASSERT(enclosing->IsLibrary() || enclosing->IsClass());
194 return enclosing;
195 }
196
197
198 Node::~Node() {} 57 Node::~Node() {}
199 58
200 59
201 TreeNode::~TreeNode() {} 60 TreeNode::~TreeNode() {}
202 61
203 62
204 void TreeNode::AcceptVisitor(Visitor* visitor) { 63 void TreeNode::AcceptVisitor(Visitor* visitor) {
205 AcceptTreeVisitor(visitor); 64 AcceptTreeVisitor(visitor);
206 } 65 }
207 66
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 1261
1403 void Program::VisitChildren(Visitor* visitor) { 1262 void Program::VisitChildren(Visitor* visitor) {
1404 VisitList(&libraries(), visitor); 1263 VisitList(&libraries(), visitor);
1405 } 1264 }
1406 1265
1407 1266
1408 } // namespace kernel 1267 } // namespace kernel
1409 1268
1410 } // namespace dart 1269 } // namespace dart
1411 #endif // !defined(DART_PRECOMPILED_RUNTIME) 1270 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel.h ('k') | runtime/vm/kernel_binary.h » ('j') | runtime/vm/kernel_binary.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698