| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/ast.h" | 5 #include "src/ast.h" |
| 6 | 6 |
| 7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
| 8 #include "src/builtins.h" | 8 #include "src/builtins.h" |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/contexts.h" | 10 #include "src/contexts.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 return var != NULL && var->location() == Variable::UNALLOCATED && | 57 return var != NULL && var->location() == Variable::UNALLOCATED && |
| 58 var_proxy->raw_name()->IsOneByteEqualTo("undefined"); | 58 var_proxy->raw_name()->IsOneByteEqualTo("undefined"); |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 VariableProxy::VariableProxy(Zone* zone, Variable* var, int position) | 62 VariableProxy::VariableProxy(Zone* zone, Variable* var, int position) |
| 63 : Expression(zone, position), | 63 : Expression(zone, position), |
| 64 name_(var->raw_name()), | 64 name_(var->raw_name()), |
| 65 var_(NULL), // Will be set by the call to BindTo. | 65 var_(NULL), // Will be set by the call to BindTo. |
| 66 is_this_(var->is_this()), | 66 is_this_(var->is_this()), |
| 67 is_assigned_(false), | 67 is_trivial_(false), |
| 68 is_lvalue_(false), |
| 68 interface_(var->interface()) { | 69 interface_(var->interface()) { |
| 69 BindTo(var); | 70 BindTo(var); |
| 70 } | 71 } |
| 71 | 72 |
| 72 | 73 |
| 73 VariableProxy::VariableProxy(Zone* zone, | 74 VariableProxy::VariableProxy(Zone* zone, |
| 74 const AstRawString* name, | 75 const AstRawString* name, |
| 75 bool is_this, | 76 bool is_this, |
| 76 Interface* interface, | 77 Interface* interface, |
| 77 int position) | 78 int position) |
| 78 : Expression(zone, position), | 79 : Expression(zone, position), |
| 79 name_(name), | 80 name_(name), |
| 80 var_(NULL), | 81 var_(NULL), |
| 81 is_this_(is_this), | 82 is_this_(is_this), |
| 82 is_assigned_(false), | 83 is_trivial_(false), |
| 84 is_lvalue_(false), |
| 83 interface_(interface) { | 85 interface_(interface) { |
| 84 } | 86 } |
| 85 | 87 |
| 86 | 88 |
| 87 void VariableProxy::BindTo(Variable* var) { | 89 void VariableProxy::BindTo(Variable* var) { |
| 88 ASSERT(var_ == NULL); // must be bound only once | 90 ASSERT(var_ == NULL); // must be bound only once |
| 89 ASSERT(var != NULL); // must bind | 91 ASSERT(var != NULL); // must bind |
| 90 ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface())); | 92 ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface())); |
| 91 ASSERT((is_this() && var->is_this()) || name_ == var->raw_name()); | 93 ASSERT((is_this() && var->is_this()) || name_ == var->raw_name()); |
| 92 // Ideally CONST-ness should match. However, this is very hard to achieve | 94 // Ideally CONST-ness should match. However, this is very hard to achieve |
| 93 // because we don't know the exact semantics of conflicting (const and | 95 // because we don't know the exact semantics of conflicting (const and |
| 94 // non-const) multiple variable declarations, const vars introduced via | 96 // non-const) multiple variable declarations, const vars introduced via |
| 95 // eval() etc. Const-ness and variable declarations are a complete mess | 97 // eval() etc. Const-ness and variable declarations are a complete mess |
| 96 // in JS. Sigh... | 98 // in JS. Sigh... |
| 97 var_ = var; | 99 var_ = var; |
| 98 var->set_is_used(); | 100 var->set_is_used(true); |
| 99 } | 101 } |
| 100 | 102 |
| 101 | 103 |
| 102 Assignment::Assignment(Zone* zone, | 104 Assignment::Assignment(Zone* zone, |
| 103 Token::Value op, | 105 Token::Value op, |
| 104 Expression* target, | 106 Expression* target, |
| 105 Expression* value, | 107 Expression* value, |
| 106 int pos) | 108 int pos) |
| 107 : Expression(zone, pos), | 109 : Expression(zone, pos), |
| 108 op_(op), | 110 op_(op), |
| (...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 DONT_CACHE_NODE(ModuleLiteral) | 1110 DONT_CACHE_NODE(ModuleLiteral) |
| 1109 | 1111 |
| 1110 | 1112 |
| 1111 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { | 1113 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { |
| 1112 increase_node_count(); | 1114 increase_node_count(); |
| 1113 if (node->is_jsruntime()) { | 1115 if (node->is_jsruntime()) { |
| 1114 // Don't try to inline JS runtime calls because we don't (currently) even | 1116 // Don't try to inline JS runtime calls because we don't (currently) even |
| 1115 // optimize them. | 1117 // optimize them. |
| 1116 add_flag(kDontInline); | 1118 add_flag(kDontInline); |
| 1117 } else if (node->function()->intrinsic_type == Runtime::INLINE && | 1119 } else if (node->function()->intrinsic_type == Runtime::INLINE && |
| 1118 node->raw_name()->IsOneByteEqualTo("_Arguments")) { | 1120 (node->raw_name()->IsOneByteEqualTo("_ArgumentsLength") || |
| 1119 // Don't inline the %_Arguments because it's implementation will not work. | 1121 node->raw_name()->IsOneByteEqualTo("_Arguments"))) { |
| 1120 // There is no stack frame to get them from. | 1122 // Don't inline the %_ArgumentsLength or %_Arguments because their |
| 1123 // implementation will not work. There is no stack frame to get them |
| 1124 // from. |
| 1121 add_flag(kDontInline); | 1125 add_flag(kDontInline); |
| 1122 } | 1126 } |
| 1123 } | 1127 } |
| 1124 | 1128 |
| 1125 #undef REGULAR_NODE | 1129 #undef REGULAR_NODE |
| 1126 #undef DONT_OPTIMIZE_NODE | 1130 #undef DONT_OPTIMIZE_NODE |
| 1127 #undef DONT_SELFOPTIMIZE_NODE | 1131 #undef DONT_SELFOPTIMIZE_NODE |
| 1128 #undef DONT_CACHE_NODE | 1132 #undef DONT_CACHE_NODE |
| 1129 | 1133 |
| 1130 | 1134 |
| 1131 Handle<String> Literal::ToString() { | 1135 Handle<String> Literal::ToString() { |
| 1132 if (value_->IsString()) return value_->AsString()->string(); | 1136 if (value_->IsString()) return value_->AsString()->string(); |
| 1133 ASSERT(value_->IsNumber()); | 1137 ASSERT(value_->IsNumber()); |
| 1134 char arr[100]; | 1138 char arr[100]; |
| 1135 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 1139 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
| 1136 const char* str; | 1140 const char* str; |
| 1137 if (value()->IsSmi()) { | 1141 if (value()->IsSmi()) { |
| 1138 // Optimization only, the heap number case would subsume this. | 1142 // Optimization only, the heap number case would subsume this. |
| 1139 SNPrintF(buffer, "%d", Smi::cast(*value())->value()); | 1143 SNPrintF(buffer, "%d", Smi::cast(*value())->value()); |
| 1140 str = arr; | 1144 str = arr; |
| 1141 } else { | 1145 } else { |
| 1142 str = DoubleToCString(value()->Number(), buffer); | 1146 str = DoubleToCString(value()->Number(), buffer); |
| 1143 } | 1147 } |
| 1144 return isolate_->factory()->NewStringFromAsciiChecked(str); | 1148 return isolate_->factory()->NewStringFromAsciiChecked(str); |
| 1145 } | 1149 } |
| 1146 | 1150 |
| 1147 | 1151 |
| 1148 } } // namespace v8::internal | 1152 } } // namespace v8::internal |
| OLD | NEW |