| OLD | NEW |
| 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 #include "vm/resolver.h" | 10 #include "vm/resolver.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 void ArrayNode::VisitChildren(AstNodeVisitor* visitor) const { | 76 void ArrayNode::VisitChildren(AstNodeVisitor* visitor) const { |
| 77 for (intptr_t i = 0; i < this->length(); i++) { | 77 for (intptr_t i = 0; i < this->length(); i++) { |
| 78 ElementAt(i)->Visit(visitor); | 78 ElementAt(i)->Visit(visitor); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 // TODO(srdjan): Add code for logical negation. | 83 // TODO(srdjan): Add code for logical negation. |
| 84 AstNode* LiteralNode::ApplyUnaryOp(Token::Kind unary_op_kind) { | 84 AstNode* LiteralNode::ApplyUnaryOp(Token::Kind unary_op_kind) { |
| 85 if (unary_op_kind == Token::kSUB) { | 85 if (unary_op_kind == Token::kNEGATE) { |
| 86 if (literal().IsSmi()) { | 86 if (literal().IsSmi()) { |
| 87 const Smi& smi = Smi::Cast(literal()); | 87 const Smi& smi = Smi::Cast(literal()); |
| 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_pos(), literal); | 90 return new LiteralNode(this->token_pos(), literal); |
| 91 } | 91 } |
| 92 if (literal().IsDouble()) { | 92 if (literal().IsDouble()) { |
| 93 const Double& dbl = Double::Cast(literal()); | 93 const Double& dbl = Double::Cast(literal()); |
| 94 // Preserve negative zero. | 94 // Preserve negative zero. |
| 95 double new_value = (dbl.value() == 0.0) ? -0.0 : (0.0 - dbl.value()); | 95 double new_value = (dbl.value() == 0.0) ? -0.0 : (0.0 - dbl.value()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 if (new_operand != NULL) { | 248 if (new_operand != NULL) { |
| 249 return new_operand; | 249 return new_operand; |
| 250 } | 250 } |
| 251 return new UnaryOpNode(token_pos, kind, operand); | 251 return new UnaryOpNode(token_pos, kind, operand); |
| 252 } | 252 } |
| 253 | 253 |
| 254 | 254 |
| 255 bool UnaryOpNode::IsKindValid() const { | 255 bool UnaryOpNode::IsKindValid() const { |
| 256 switch (kind_) { | 256 switch (kind_) { |
| 257 case Token::kADD: | 257 case Token::kADD: |
| 258 case Token::kSUB: | 258 case Token::kNEGATE: |
| 259 case Token::kNOT: | 259 case Token::kNOT: |
| 260 case Token::kBIT_NOT: | 260 case Token::kBIT_NOT: |
| 261 return true; | 261 return true; |
| 262 default: | 262 default: |
| 263 return false; | 263 return false; |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 | 267 |
| 268 const Instance* UnaryOpNode::EvalConstExpr() const { | 268 const Instance* UnaryOpNode::EvalConstExpr() const { |
| 269 const Instance* val = this->operand()->EvalConstExpr(); | 269 const Instance* val = this->operand()->EvalConstExpr(); |
| 270 if (val == NULL) { | 270 if (val == NULL) { |
| 271 return NULL; | 271 return NULL; |
| 272 } | 272 } |
| 273 switch (kind_) { | 273 switch (kind_) { |
| 274 case Token::kADD: | 274 case Token::kADD: |
| 275 case Token::kSUB: | 275 case Token::kNEGATE: |
| 276 return val->IsNumber() ? val : NULL; | 276 return val->IsNumber() ? val : NULL; |
| 277 case Token::kNOT: | 277 case Token::kNOT: |
| 278 return val->IsBool() ? val : NULL; | 278 return val->IsBool() ? val : NULL; |
| 279 case Token::kBIT_NOT: | 279 case Token::kBIT_NOT: |
| 280 return val->IsInteger() ? val : NULL; | 280 return val->IsInteger() ? val : NULL; |
| 281 default: | 281 default: |
| 282 return NULL; | 282 return NULL; |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 | 285 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 if (result.IsError() || result.IsNull()) { | 420 if (result.IsError() || result.IsNull()) { |
| 421 // TODO(turnidge): We could get better error messages by returning | 421 // TODO(turnidge): We could get better error messages by returning |
| 422 // the Error object directly to the parser. This will involve | 422 // the Error object directly to the parser. This will involve |
| 423 // replumbing all of the EvalConstExpr methods. | 423 // replumbing all of the EvalConstExpr methods. |
| 424 return NULL; | 424 return NULL; |
| 425 } | 425 } |
| 426 return &Instance::ZoneHandle(Instance::Cast(result).raw()); | 426 return &Instance::ZoneHandle(Instance::Cast(result).raw()); |
| 427 } | 427 } |
| 428 | 428 |
| 429 } // namespace dart | 429 } // namespace dart |
| OLD | NEW |