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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ElementAt(i)->Visit(visitor); | 112 ElementAt(i)->Visit(visitor); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 bool LiteralNode::IsPotentiallyConst() const { | 117 bool LiteralNode::IsPotentiallyConst() const { |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 // TODO(srdjan): Add code for logical negation. | |
123 AstNode* LiteralNode::ApplyUnaryOp(Token::Kind unary_op_kind) { | 122 AstNode* LiteralNode::ApplyUnaryOp(Token::Kind unary_op_kind) { |
124 if (unary_op_kind == Token::kNEGATE) { | 123 if (unary_op_kind == Token::kNEGATE) { |
125 if (literal().IsSmi()) { | 124 if (literal().IsSmi()) { |
126 const Smi& smi = Smi::Cast(literal()); | 125 const Smi& smi = Smi::Cast(literal()); |
127 const Instance& literal = | 126 const Instance& literal = |
128 Instance::ZoneHandle(Integer::New(-smi.Value())); | 127 Instance::ZoneHandle(Integer::New(-smi.Value(), Heap::kOld)); |
| 128 return new LiteralNode(this->token_pos(), literal); |
| 129 } |
| 130 if (literal().IsMint()) { |
| 131 const Mint& mint = Mint::Cast(literal()); |
| 132 const Instance& literal = |
| 133 Instance::ZoneHandle(Integer::New(-mint.value(), Heap::kOld)); |
129 return new LiteralNode(this->token_pos(), literal); | 134 return new LiteralNode(this->token_pos(), literal); |
130 } | 135 } |
131 if (literal().IsDouble()) { | 136 if (literal().IsDouble()) { |
132 const Double& dbl = Double::Cast(literal()); | 137 const Double& dbl = Double::Cast(literal()); |
133 // Preserve negative zero. | 138 // Preserve negative zero. |
134 double new_value = (dbl.value() == 0.0) ? -0.0 : (0.0 - dbl.value()); | 139 double new_value = (dbl.value() == 0.0) ? -0.0 : (0.0 - dbl.value()); |
135 const Double& double_instance = | 140 const Double& double_instance = |
136 Double::ZoneHandle(Double::NewCanonical(new_value)); | 141 Double::ZoneHandle(Double::NewCanonical(new_value)); |
137 return new LiteralNode(this->token_pos(), double_instance); | 142 return new LiteralNode(this->token_pos(), double_instance); |
138 } | 143 } |
| 144 } else if (unary_op_kind == Token::kBIT_NOT) { |
| 145 if (literal().IsSmi()) { |
| 146 const Smi& smi = Smi::Cast(literal()); |
| 147 const Instance& literal = |
| 148 Instance::ZoneHandle(Integer::New(~smi.Value(), Heap::kOld)); |
| 149 return new LiteralNode(this->token_pos(), literal); |
| 150 } |
| 151 if (literal().IsMint()) { |
| 152 const Mint& mint = Mint::Cast(literal()); |
| 153 const Instance& literal = |
| 154 Instance::ZoneHandle(Integer::New(~mint.value(), Heap::kOld)); |
| 155 return new LiteralNode(this->token_pos(), literal); |
| 156 } |
| 157 } else if (unary_op_kind == Token::kNOT) { |
| 158 if (literal().IsBool()) { |
| 159 const Bool& boolean = Bool::Cast(literal()); |
| 160 return new LiteralNode(this->token_pos(), Bool::Get(!boolean.value())); |
| 161 } |
139 } | 162 } |
140 return NULL; | 163 return NULL; |
141 } | 164 } |
142 | 165 |
143 | 166 |
144 const char* TypeNode::TypeName() const { | 167 const char* TypeNode::TypeName() const { |
145 return String::Handle(type().UserVisibleName()).ToCString(); | 168 return String::Handle(type().UserVisibleName()).ToCString(); |
146 } | 169 } |
147 | 170 |
148 | 171 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 if (result.IsError() || result.IsNull()) { | 616 if (result.IsError() || result.IsNull()) { |
594 // TODO(turnidge): We could get better error messages by returning | 617 // TODO(turnidge): We could get better error messages by returning |
595 // the Error object directly to the parser. This will involve | 618 // the Error object directly to the parser. This will involve |
596 // replumbing all of the EvalConstExpr methods. | 619 // replumbing all of the EvalConstExpr methods. |
597 return NULL; | 620 return NULL; |
598 } | 621 } |
599 return &Instance::ZoneHandle(Instance::Cast(result).raw()); | 622 return &Instance::ZoneHandle(Instance::Cast(result).raw()); |
600 } | 623 } |
601 | 624 |
602 } // namespace dart | 625 } // namespace dart |
OLD | NEW |