Chromium Code Reviews| 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/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 4905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4916 str_concat->AddExpr(lit); | 4916 str_concat->AddExpr(lit); |
| 4917 } | 4917 } |
| 4918 } else if (left_operand->IsStringConcatNode()) { | 4918 } else if (left_operand->IsStringConcatNode()) { |
| 4919 str_concat = left_operand->AsStringConcatNode(); | 4919 str_concat = left_operand->AsStringConcatNode(); |
| 4920 } | 4920 } |
| 4921 } | 4921 } |
| 4922 if (str_concat != NULL) { | 4922 if (str_concat != NULL) { |
| 4923 str_concat->AddExpr(right_operand); | 4923 str_concat->AddExpr(right_operand); |
| 4924 left_operand = str_concat; | 4924 left_operand = str_concat; |
| 4925 } else { | 4925 } else { |
| 4926 left_operand = new BinaryOpNode( | 4926 left_operand = OptimizeBinaryOpNode( |
| 4927 op_pos, op_kind, left_operand, right_operand); | 4927 op_pos, op_kind, left_operand, right_operand); |
| 4928 } | 4928 } |
| 4929 } | 4929 } |
| 4930 } | 4930 } |
| 4931 current_preced--; | 4931 current_preced--; |
| 4932 } | 4932 } |
| 4933 return left_operand; | 4933 return left_operand; |
| 4934 } | 4934 } |
| 4935 | 4935 |
| 4936 | 4936 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5029 current_block_->statements->Add(save); | 5029 current_block_->statements->Add(save); |
| 5030 AstNode* load = new LoadLocalNode(token_index, *temp); | 5030 AstNode* load = new LoadLocalNode(token_index, *temp); |
| 5031 getter = new InstanceGetterNode(token_index, load, getter->field_name()); | 5031 getter = new InstanceGetterNode(token_index, load, getter->field_name()); |
| 5032 } | 5032 } |
| 5033 return getter; | 5033 return getter; |
| 5034 } | 5034 } |
| 5035 return node; | 5035 return node; |
| 5036 } | 5036 } |
| 5037 | 5037 |
| 5038 | 5038 |
| 5039 // TODO(srdjan): Implement other optimizations. | |
| 5040 AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos, | |
| 5041 Token::Kind binary_op, | |
| 5042 AstNode* lhs, | |
| 5043 AstNode* rhs) { | |
| 5044 LiteralNode* lhs_literal = lhs->AsLiteralNode(); | |
| 5045 LiteralNode* rhs_literal = rhs->AsLiteralNode(); | |
| 5046 if ((lhs_literal != NULL) && (rhs_literal != NULL)) { | |
| 5047 if (lhs_literal->literal().IsDouble() && | |
| 5048 rhs_literal->literal().IsDouble()) { | |
| 5049 Double& dbl_obj = Double::ZoneHandle(); | |
| 5050 dbl_obj ^= lhs_literal->literal().raw(); | |
| 5051 double left_double = dbl_obj.value(); | |
| 5052 dbl_obj ^= rhs_literal->literal().raw(); | |
| 5053 double right_double = dbl_obj.value(); | |
| 5054 if (binary_op == Token::kDIV) { | |
| 5055 dbl_obj = Double::New(left_double / right_double); | |
|
siva
2011/10/21 00:41:52
what if right_double is 0.0?
Also do you have to d
srdjan
2011/10/21 06:52:59
The division in C++ behaves the same as in Dart (s
| |
| 5056 return new LiteralNode(op_pos, dbl_obj); | |
| 5057 } | |
| 5058 } | |
| 5059 } | |
| 5060 return new BinaryOpNode(op_pos, binary_op, lhs, rhs); | |
| 5061 } | |
| 5062 | |
| 5063 | |
| 5039 AstNode* Parser::ExpandAssignableOp(intptr_t op_pos, | 5064 AstNode* Parser::ExpandAssignableOp(intptr_t op_pos, |
| 5040 Token::Kind assignment_op, | 5065 Token::Kind assignment_op, |
| 5041 AstNode* lhs, | 5066 AstNode* lhs, |
| 5042 AstNode* rhs) { | 5067 AstNode* rhs) { |
| 5043 TRACE_PARSER("ExpandAssignableOp"); | 5068 TRACE_PARSER("ExpandAssignableOp"); |
| 5044 switch (assignment_op) { | 5069 switch (assignment_op) { |
| 5045 case Token::kASSIGN: | 5070 case Token::kASSIGN: |
| 5046 return rhs; | 5071 return rhs; |
| 5047 case Token::kASSIGN_ADD: | 5072 case Token::kASSIGN_ADD: |
| 5048 return new BinaryOpNode(op_pos, Token::kADD, lhs, rhs); | 5073 return new BinaryOpNode(op_pos, Token::kADD, lhs, rhs); |
| (...skipping 1931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6980 } | 7005 } |
| 6981 | 7006 |
| 6982 | 7007 |
| 6983 void Parser::SkipNestedExpr() { | 7008 void Parser::SkipNestedExpr() { |
| 6984 const bool saved_mode = SetAllowFunctionLiterals(true); | 7009 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 6985 SkipExpr(); | 7010 SkipExpr(); |
| 6986 SetAllowFunctionLiterals(saved_mode); | 7011 SetAllowFunctionLiterals(saved_mode); |
| 6987 } | 7012 } |
| 6988 | 7013 |
| 6989 } // namespace dart | 7014 } // namespace dart |
| OLD | NEW |