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

Side by Side Diff: runtime/vm/parser.h

Issue 1965823002: Initial isolate reload support (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 VM_PARSER_H_ 5 #ifndef VM_PARSER_H_
6 #define VM_PARSER_H_ 6 #define VM_PARSER_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "platform/assert.h" 10 #include "platform/assert.h"
11 #include "platform/globals.h" 11 #include "platform/globals.h"
12 #include "lib/invocation_mirror.h" 12 #include "lib/invocation_mirror.h"
13 #include "vm/allocation.h" 13 #include "vm/allocation.h"
14 #include "vm/ast.h" 14 #include "vm/ast.h"
15 #include "vm/class_finalizer.h" 15 #include "vm/class_finalizer.h"
16 #include "vm/compiler_stats.h" 16 #include "vm/compiler_stats.h"
17 #include "vm/hash_table.h"
17 #include "vm/object.h" 18 #include "vm/object.h"
18 #include "vm/raw_object.h" 19 #include "vm/raw_object.h"
19 #include "vm/token.h" 20 #include "vm/token.h"
20 21
21 namespace dart { 22 namespace dart {
22 23
23 // Forward declarations. 24 // Forward declarations.
24 class ArgumentsDescriptor; 25 class ArgumentsDescriptor;
25 class Isolate; 26 class Isolate;
26 class LocalScope; 27 class LocalScope;
27 class LocalVariable; 28 class LocalVariable;
28 struct RegExpCompileData; 29 struct RegExpCompileData;
29 class SourceLabel; 30 class SourceLabel;
30 template <typename T> class GrowableArray; 31 template <typename T> class GrowableArray;
31 class Parser; 32 class Parser;
32 33
33 struct CatchParamDesc; 34 struct CatchParamDesc;
34 class ClassDesc; 35 class ClassDesc;
35 struct MemberDesc; 36 struct MemberDesc;
36 struct ParamList; 37 struct ParamList;
37 struct QualIdent; 38 struct QualIdent;
38 class TopLevel; 39 class TopLevel;
39 class RecursionChecker; 40 class RecursionChecker;
40 41
42 // We cache computed compile-time constants in a map so we can look them
43 // up when the same code gets compiled again. The map key is a pair
44 // (script url, token position) which is encoded in an array with 2
45 // elements:
46 // - key[0] contains the canonicalized url of the script.
47 // - key[1] contains the token position of the constant in the script.
48
49 // ConstantPosKey allows us to look up a constant in the map without
50 // allocating a key pair (array).
51 struct ConstantPosKey : ValueObject {
52 ConstantPosKey(const String& url, TokenPosition pos)
53 : script_url(url), token_pos(pos) { }
54 const String& script_url;
55 TokenPosition token_pos;
56 };
57
58
59 class ConstMapKeyEqualsTraits {
60 public:
61 static const char* Name() { return "ConstMapKeyEqualsTraits"; }
62 static bool ReportStats() { return false; }
63
64 static bool IsMatch(const Object& a, const Object& b) {
65 const Array& key1 = Array::Cast(a);
66 const Array& key2 = Array::Cast(b);
67 // Compare raw strings of script url symbol and raw smi of token positon.
68 return (key1.At(0) == key2.At(0)) && (key1.At(1) == key2.At(1));
69 }
70 static bool IsMatch(const ConstantPosKey& key1, const Object& b) {
71 const Array& key2 = Array::Cast(b);
72 // Compare raw strings of script url symbol and token positon.
73 return (key1.script_url.raw() == key2.At(0))
74 && (key1.token_pos.value() == Smi::Value(Smi::RawCast(key2.At(1))));
75 }
76 static uword Hash(const Object& obj) {
77 const Array& key = Array::Cast(obj);
78 intptr_t url_hash = String::HashRawSymbol(String::RawCast(key.At(0)));
79 intptr_t pos = Smi::Value(Smi::RawCast(key.At(1)));
80 return HashValue(url_hash, pos);
81 }
82 static uword Hash(const ConstantPosKey& key) {
83 return HashValue(String::HashRawSymbol(key.script_url.raw()),
84 key.token_pos.value());
85 }
86 // Used by CachConstantValue if a new constant is added to the map.
87 static RawObject* NewKey(const ConstantPosKey& key) {
88 const Array& key_obj = Array::Handle(Array::New(2));
89 key_obj.SetAt(0, key.script_url);
90 key_obj.SetAt(1, Smi::Handle(Smi::New(key.token_pos.value())));
91 return key_obj.raw();;
92 }
93
94 private:
95 static uword HashValue(intptr_t url_hash, intptr_t pos) {
96 return url_hash * pos % (Smi::kMaxValue - 13);
97 }
98 };
99 typedef UnorderedHashMap<ConstMapKeyEqualsTraits> ConstantsMap;
100
41 // The class ParsedFunction holds the result of parsing a function. 101 // The class ParsedFunction holds the result of parsing a function.
42 class ParsedFunction : public ZoneAllocated { 102 class ParsedFunction : public ZoneAllocated {
43 public: 103 public:
44 ParsedFunction(Thread* thread, const Function& function) 104 ParsedFunction(Thread* thread, const Function& function)
45 : thread_(thread), 105 : thread_(thread),
46 function_(function), 106 function_(function),
47 code_(Code::Handle(zone(), function.unoptimized_code())), 107 code_(Code::Handle(zone(), function.unoptimized_code())),
48 node_sequence_(NULL), 108 node_sequence_(NULL),
49 regexp_compile_data_(NULL), 109 regexp_compile_data_(NULL),
50 instantiator_(NULL), 110 instantiator_(NULL),
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 269
210 // Parse and evaluate the metadata expressions at token_pos in the 270 // Parse and evaluate the metadata expressions at token_pos in the
211 // class namespace of class cls (which can be the implicit toplevel 271 // class namespace of class cls (which can be the implicit toplevel
212 // class if the metadata is at the top-level). 272 // class if the metadata is at the top-level).
213 static RawObject* ParseMetadata(const Field& meta_data); 273 static RawObject* ParseMetadata(const Field& meta_data);
214 274
215 // Build a function containing the initializer expression of the 275 // Build a function containing the initializer expression of the
216 // given static field. 276 // given static field.
217 static ParsedFunction* ParseStaticFieldInitializer(const Field& field); 277 static ParsedFunction* ParseStaticFieldInitializer(const Field& field);
218 278
279 static void InsertCachedConstantValue(const String& url,
280 TokenPosition token_pos,
281 const Instance& value);
282
219 // Parse a function to retrieve parameter information that is not retained in 283 // Parse a function to retrieve parameter information that is not retained in
220 // the dart::Function object. Returns either an error if the parse fails 284 // the dart::Function object. Returns either an error if the parse fails
221 // (which could be the case for local functions), or a flat array of entries 285 // (which could be the case for local functions), or a flat array of entries
222 // for each parameter. Each parameter entry contains: 286 // for each parameter. Each parameter entry contains:
223 // * a Dart bool indicating whether the parameter was declared final 287 // * a Dart bool indicating whether the parameter was declared final
224 // * its default value (or null if none was declared) 288 // * its default value (or null if none was declared)
225 // * an array of metadata (or null if no metadata was declared). 289 // * an array of metadata (or null if no metadata was declared).
226 enum { 290 enum {
227 kParameterIsFinalOffset, 291 kParameterIsFinalOffset,
228 kParameterDefaultValueOffset, 292 kParameterDefaultValueOffset,
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 979
916 intptr_t recursion_counter_; 980 intptr_t recursion_counter_;
917 friend class RecursionChecker; 981 friend class RecursionChecker;
918 982
919 DISALLOW_COPY_AND_ASSIGN(Parser); 983 DISALLOW_COPY_AND_ASSIGN(Parser);
920 }; 984 };
921 985
922 } // namespace dart 986 } // namespace dart
923 987
924 #endif // VM_PARSER_H_ 988 #endif // VM_PARSER_H_
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/pages.cc ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698