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

Side by Side Diff: vm/ast.cc

Issue 10632009: Make the parser agnostic to the TokenStream implementation. This is the first step towards compacti… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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
« no previous file with comments | « vm/ast.h ('k') | vm/ast_printer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "vm/ast.h" 5 #include "vm/ast.h"
6 #include "vm/compiler.h" 6 #include "vm/compiler.h"
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 81
82 // TODO(srdjan): Add code for logical negation. 82 // TODO(srdjan): Add code for logical negation.
83 AstNode* LiteralNode::ApplyUnaryOp(Token::Kind unary_op_kind) { 83 AstNode* LiteralNode::ApplyUnaryOp(Token::Kind unary_op_kind) {
84 if (unary_op_kind == Token::kSUB) { 84 if (unary_op_kind == Token::kSUB) {
85 if (literal().IsSmi()) { 85 if (literal().IsSmi()) {
86 Smi& smi = Smi::Handle(); 86 Smi& smi = Smi::Handle();
87 smi ^= literal().raw(); 87 smi ^= literal().raw();
88 const Instance& literal = 88 const Instance& literal =
89 Instance::ZoneHandle(Integer::New(-smi.Value())); 89 Instance::ZoneHandle(Integer::New(-smi.Value()));
90 return new LiteralNode(this->token_index(), literal); 90 return new LiteralNode(this->token_pos(), literal);
91 } 91 }
92 if (literal().IsDouble()) { 92 if (literal().IsDouble()) {
93 Double& dbl = Double::Handle(); 93 Double& dbl = Double::Handle();
94 dbl ^= literal().raw(); 94 dbl ^= literal().raw();
95 // Preserve negative zero. 95 // Preserve negative zero.
96 double new_value = (dbl.value() == 0.0) ? -0.0 : (0.0 - dbl.value()); 96 double new_value = (dbl.value() == 0.0) ? -0.0 : (0.0 - dbl.value());
97 Double& double_instance = 97 Double& double_instance =
98 Double::ZoneHandle(Double::New(new_value, Heap::kOld)); 98 Double::ZoneHandle(Double::New(new_value, Heap::kOld));
99 double_instance ^= double_instance.Canonicalize(); 99 double_instance ^= double_instance.Canonicalize();
100 return new LiteralNode(this->token_index(), double_instance); 100 return new LiteralNode(this->token_pos(), double_instance);
101 } 101 }
102 } 102 }
103 return NULL; 103 return NULL;
104 } 104 }
105 105
106 106
107 bool ComparisonNode::IsKindValid() const { 107 bool ComparisonNode::IsKindValid() const {
108 return Token::IsRelationalOperator(kind_) 108 return Token::IsRelationalOperator(kind_)
109 || Token::IsEqualityOperator(kind_) 109 || Token::IsEqualityOperator(kind_)
110 || Token::IsInstanceofOperator(kind_); 110 || Token::IsInstanceofOperator(kind_);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 243 }
244 return NULL; 244 return NULL;
245 default: 245 default:
246 UNREACHABLE(); 246 UNREACHABLE();
247 return NULL; 247 return NULL;
248 } 248 }
249 return NULL; 249 return NULL;
250 } 250 }
251 251
252 252
253 AstNode* UnaryOpNode::UnaryOpOrLiteral(intptr_t token_index, 253 AstNode* UnaryOpNode::UnaryOpOrLiteral(intptr_t token_pos,
254 Token::Kind kind, 254 Token::Kind kind,
255 AstNode* operand) { 255 AstNode* operand) {
256 AstNode* new_operand = operand->ApplyUnaryOp(kind); 256 AstNode* new_operand = operand->ApplyUnaryOp(kind);
257 if (new_operand != NULL) { 257 if (new_operand != NULL) {
258 return new_operand; 258 return new_operand;
259 } 259 }
260 return new UnaryOpNode(token_index, kind, operand); 260 return new UnaryOpNode(token_pos, kind, operand);
261 } 261 }
262 262
263 263
264 bool UnaryOpNode::IsKindValid() const { 264 bool UnaryOpNode::IsKindValid() const {
265 switch (kind_) { 265 switch (kind_) {
266 case Token::kADD: 266 case Token::kADD:
267 case Token::kSUB: 267 case Token::kSUB:
268 case Token::kNOT: 268 case Token::kNOT:
269 case Token::kBIT_NOT: 269 case Token::kBIT_NOT:
270 return true; 270 return true;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 303 }
304 304
305 305
306 AstNode* LoadLocalNode::MakeAssignmentNode(AstNode* rhs) { 306 AstNode* LoadLocalNode::MakeAssignmentNode(AstNode* rhs) {
307 if (local().is_final()) { 307 if (local().is_final()) {
308 return NULL; 308 return NULL;
309 } 309 }
310 if (HasPseudo()) { 310 if (HasPseudo()) {
311 return NULL; 311 return NULL;
312 } 312 }
313 return new StoreLocalNode(token_index(), local(), rhs); 313 return new StoreLocalNode(token_pos(), local(), rhs);
314 } 314 }
315 315
316 316
317 AstNode* LoadStaticFieldNode::MakeAssignmentNode(AstNode* rhs) { 317 AstNode* LoadStaticFieldNode::MakeAssignmentNode(AstNode* rhs) {
318 return new StoreStaticFieldNode(token_index(), field(), rhs); 318 return new StoreStaticFieldNode(token_pos(), field(), rhs);
319 } 319 }
320 320
321 321
322 AstNode* InstanceGetterNode::MakeAssignmentNode(AstNode* rhs) { 322 AstNode* InstanceGetterNode::MakeAssignmentNode(AstNode* rhs) {
323 return new InstanceSetterNode(token_index(), receiver(), field_name(), rhs); 323 return new InstanceSetterNode(token_pos(), receiver(), field_name(), rhs);
324 } 324 }
325 325
326 326
327 AstNode* LoadIndexedNode::MakeAssignmentNode(AstNode* rhs) { 327 AstNode* LoadIndexedNode::MakeAssignmentNode(AstNode* rhs) {
328 return new StoreIndexedNode(token_index(), array(), index_expr(), rhs); 328 return new StoreIndexedNode(token_pos(), array(), index_expr(), rhs);
329 } 329 }
330 330
331 331
332 AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) { 332 AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) {
333 // If no setter exist, set the field directly. 333 // If no setter exist, set the field directly.
334 const String& setter_name = String::Handle(Field::SetterName(field_name())); 334 const String& setter_name = String::Handle(Field::SetterName(field_name()));
335 const Function& setter = 335 const Function& setter =
336 Function::ZoneHandle(cls().LookupStaticFunction(setter_name)); 336 Function::ZoneHandle(cls().LookupStaticFunction(setter_name));
337 if (setter.IsNull()) { 337 if (setter.IsNull()) {
338 // Access to a lazily initialized static field that has not yet been 338 // Access to a lazily initialized static field that has not yet been
339 // initialized is compiled to a static implicit getter. 339 // initialized is compiled to a static implicit getter.
340 // A setter may not exist for such a field. 340 // A setter may not exist for such a field.
341 #if defined(DEBUG) 341 #if defined(DEBUG)
342 const String& getter_name = String::Handle(Field::GetterName(field_name())); 342 const String& getter_name = String::Handle(Field::GetterName(field_name()));
343 const Function& getter = 343 const Function& getter =
344 Function::ZoneHandle(cls().LookupStaticFunction(getter_name)); 344 Function::ZoneHandle(cls().LookupStaticFunction(getter_name));
345 ASSERT(!getter.IsNull() && 345 ASSERT(!getter.IsNull() &&
346 (getter.kind() == RawFunction::kConstImplicitGetter)); 346 (getter.kind() == RawFunction::kConstImplicitGetter));
347 #endif 347 #endif
348 const Field& field = Field::ZoneHandle( 348 const Field& field = Field::ZoneHandle(
349 cls().LookupStaticField(field_name())); 349 cls().LookupStaticField(field_name()));
350 ASSERT(!field.IsNull()); 350 ASSERT(!field.IsNull());
351 return new StoreStaticFieldNode(token_index(), field, rhs); 351 return new StoreStaticFieldNode(token_pos(), field, rhs);
352 } else { 352 } else {
353 return new StaticSetterNode(token_index(), cls(), field_name(), rhs); 353 return new StaticSetterNode(token_pos(), cls(), field_name(), rhs);
354 } 354 }
355 } 355 }
356 356
357 357
358 const Instance* StaticGetterNode::EvalConstExpr() const { 358 const Instance* StaticGetterNode::EvalConstExpr() const {
359 const String& getter_name = 359 const String& getter_name =
360 String::Handle(Field::GetterName(this->field_name())); 360 String::Handle(Field::GetterName(this->field_name()));
361 const Function& getter_func = 361 const Function& getter_func =
362 Function::Handle(this->cls().LookupStaticFunction(getter_name)); 362 Function::Handle(this->cls().LookupStaticFunction(getter_name));
363 if (getter_func.IsNull() || !getter_func.is_const()) { 363 if (getter_func.IsNull() || !getter_func.is_const()) {
(...skipping 10 matching lines...) Expand all
374 // the Error object directly to the parser. This will involve 374 // the Error object directly to the parser. This will involve
375 // replumbing all of the EvalConstExpr methods. 375 // replumbing all of the EvalConstExpr methods.
376 return NULL; 376 return NULL;
377 } 377 }
378 Instance& field_value = Instance::ZoneHandle(); 378 Instance& field_value = Instance::ZoneHandle();
379 field_value ^= result.raw(); 379 field_value ^= result.raw();
380 return &field_value; 380 return &field_value;
381 } 381 }
382 382
383 } // namespace dart 383 } // namespace dart
OLDNEW
« no previous file with comments | « vm/ast.h ('k') | vm/ast_printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698