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

Side by Side Diff: vm/parser_test.cc

Issue 10783035: Create frequently used symbols in the vm isolate (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 5
6 #include "vm/ast_printer.h" 6 #include "vm/ast_printer.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/longjump.h" 8 #include "vm/longjump.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/parser.h" 10 #include "vm/parser.h"
11 #include "vm/symbols.h"
11 #include "vm/unit_test.h" 12 #include "vm/unit_test.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 16
16 void DumpFunction(const Library& lib, const char* cname, const char* fname) { 17 void DumpFunction(const Library& lib, const char* cname, const char* fname) {
17 const String& classname = String::Handle(String::NewSymbol(cname)); 18 const String& classname = String::Handle(Symbols::New(cname));
18 Class& cls = Class::Handle(lib.LookupClass(classname)); 19 Class& cls = Class::Handle(lib.LookupClass(classname));
19 EXPECT(!cls.IsNull()); 20 EXPECT(!cls.IsNull());
20 21
21 String& funcname = String::Handle(String::New(fname)); 22 String& funcname = String::Handle(String::New(fname));
22 Function& function = Function::Handle(cls.LookupStaticFunction(funcname)); 23 Function& function = Function::Handle(cls.LookupStaticFunction(funcname));
23 EXPECT(!function.IsNull()); 24 EXPECT(!function.IsNull());
24 25
25 bool retval; 26 bool retval;
26 Isolate* isolate = Isolate::Current(); 27 Isolate* isolate = Isolate::Current();
27 EXPECT(isolate != NULL); 28 EXPECT(isolate != NULL);
(...skipping 13 matching lines...) Expand all
41 EXPECT(retval); 42 EXPECT(retval);
42 isolate->set_long_jump_base(base); 43 isolate->set_long_jump_base(base);
43 } 44 }
44 45
45 46
46 void CheckField(const Library& lib, 47 void CheckField(const Library& lib,
47 const char* class_name, 48 const char* class_name,
48 const char* field_name, 49 const char* field_name,
49 bool expect_static, 50 bool expect_static,
50 bool is_final) { 51 bool is_final) {
51 const String& classname = String::Handle(String::NewSymbol(class_name)); 52 const String& classname = String::Handle(Symbols::New(class_name));
52 Class& cls = Class::Handle(lib.LookupClass(classname)); 53 Class& cls = Class::Handle(lib.LookupClass(classname));
53 EXPECT(!cls.IsNull()); 54 EXPECT(!cls.IsNull());
54 55
55 String& fieldname = String::Handle(String::New(field_name)); 56 String& fieldname = String::Handle(String::New(field_name));
56 String& functionname = String::Handle(); 57 String& functionname = String::Handle();
57 Function& function = Function::Handle(); 58 Function& function = Function::Handle();
58 Field& field = Field::Handle(); 59 Field& field = Field::Handle();
59 if (expect_static) { 60 if (expect_static) {
60 field ^= cls.LookupStaticField(fieldname); 61 field ^= cls.LookupStaticField(fieldname);
61 functionname ^= Field::GetterName(fieldname); 62 functionname ^= Field::GetterName(fieldname);
(...skipping 14 matching lines...) Expand all
76 EXPECT(!field.IsNull()); 77 EXPECT(!field.IsNull());
77 78
78 EXPECT_EQ(field.is_static(), expect_static); 79 EXPECT_EQ(field.is_static(), expect_static);
79 } 80 }
80 81
81 82
82 void CheckFunction(const Library& lib, 83 void CheckFunction(const Library& lib,
83 const char* class_name, 84 const char* class_name,
84 const char* function_name, 85 const char* function_name,
85 bool expect_static) { 86 bool expect_static) {
86 const String& classname = String::Handle(String::NewSymbol(class_name)); 87 const String& classname = String::Handle(Symbols::New(class_name));
87 Class& cls = Class::Handle(lib.LookupClass(classname)); 88 Class& cls = Class::Handle(lib.LookupClass(classname));
88 EXPECT(!cls.IsNull()); 89 EXPECT(!cls.IsNull());
89 90
90 String& functionname = String::Handle(String::New(function_name)); 91 String& functionname = String::Handle(String::New(function_name));
91 Function& function = Function::Handle(); 92 Function& function = Function::Handle();
92 if (expect_static) { 93 if (expect_static) {
93 function ^= cls.LookupStaticFunction(functionname); 94 function ^= cls.LookupStaticFunction(functionname);
94 } else { 95 } else {
95 function ^= cls.LookupDynamicFunction(functionname); 96 function ^= cls.LookupDynamicFunction(functionname);
96 } 97 }
(...skipping 25 matching lines...) Expand all
122 Parser::ParseCompilationUnit(lib, script); 123 Parser::ParseCompilationUnit(lib, script);
123 EXPECT(ClassFinalizer::FinalizePendingClasses()); 124 EXPECT(ClassFinalizer::FinalizePendingClasses());
124 CheckField(lib, "A", "f1", false, false); 125 CheckField(lib, "A", "f1", false, false);
125 CheckField(lib, "A", "f2", false, true); 126 CheckField(lib, "A", "f2", false, true);
126 CheckField(lib, "A", "f3", false, true); 127 CheckField(lib, "A", "f3", false, true);
127 CheckField(lib, "A", "f4", false, true); 128 CheckField(lib, "A", "f4", false, true);
128 CheckField(lib, "A", "s1", true, false); 129 CheckField(lib, "A", "s1", true, false);
129 CheckField(lib, "A", "s2", true, false); 130 CheckField(lib, "A", "s2", true, false);
130 // No field entries are added for static const fields. 131 // No field entries are added for static const fields.
131 String& fieldname = String::Handle(String::New("s3")); 132 String& fieldname = String::Handle(String::New("s3"));
132 const String& classname = String::Handle(String::NewSymbol("A")); 133 const String& classname = String::Handle(Symbols::New("A"));
133 const Class& cls = Class::Handle(lib.LookupClass(classname)); 134 const Class& cls = Class::Handle(lib.LookupClass(classname));
134 const Field& field = Field::Handle(cls.LookupStaticField(fieldname)); 135 const Field& field = Field::Handle(cls.LookupStaticField(fieldname));
135 EXPECT(!field.IsNull()); 136 EXPECT(!field.IsNull());
136 Object& val = Object::Handle(field.value()); 137 Object& val = Object::Handle(field.value());
137 // The static const field initializer is not evaluated and the field 138 // The static const field initializer is not evaluated and the field
138 // value is not initialized until the field is referenced by code that 139 // value is not initialized until the field is referenced by code that
139 // is compiled. 140 // is compiled.
140 EXPECT(val.raw() == Object::sentinel()); 141 EXPECT(val.raw() == Object::sentinel());
141 142
142 CheckFunction(lib, "A", "bar", true); 143 CheckFunction(lib, "A", "bar", true);
(...skipping 23 matching lines...) Expand all
166 Parser::ParseCompilationUnit(lib, script); 167 Parser::ParseCompilationUnit(lib, script);
167 EXPECT(ClassFinalizer::FinalizePendingClasses()); 168 EXPECT(ClassFinalizer::FinalizePendingClasses());
168 169
169 DumpFunction(lib, "A", "foo"); 170 DumpFunction(lib, "A", "foo");
170 DumpFunction(lib, "A", "bar"); 171 DumpFunction(lib, "A", "bar");
171 DumpFunction(lib, "A", "baz"); 172 DumpFunction(lib, "A", "baz");
172 DumpFunction(lib, "B", "bam"); 173 DumpFunction(lib, "B", "bam");
173 } 174 }
174 175
175 } // namespace dart 176 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698