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

Side by Side Diff: src/ast.cc

Issue 300103005: Split StringLiteral from Literal. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: number literals Created 6 years, 7 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 | « src/ast.h ('k') | src/full-codegen.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 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 "ast.h" 5 #include "ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 #include "builtins.h" 8 #include "builtins.h"
9 #include "code-stubs.h" 9 #include "code-stubs.h"
10 #include "contexts.h" 10 #include "contexts.h"
(...skipping 16 matching lines...) Expand all
27 void type::Accept(AstVisitor* v) { v->Visit##type(this); } 27 void type::Accept(AstVisitor* v) { v->Visit##type(this); }
28 AST_NODE_LIST(DECL_ACCEPT) 28 AST_NODE_LIST(DECL_ACCEPT)
29 #undef DECL_ACCEPT 29 #undef DECL_ACCEPT
30 30
31 31
32 // ---------------------------------------------------------------------------- 32 // ----------------------------------------------------------------------------
33 // Implementation of other node functionality. 33 // Implementation of other node functionality.
34 34
35 35
36 bool Expression::IsSmiLiteral() const { 36 bool Expression::IsSmiLiteral() const {
37 return AsLiteral() != NULL && AsLiteral()->value()->IsSmi(); 37 return AsNumberLiteral() != NULL && AsNumberLiteral()->value()->IsSmi();
38 }
39
40
41 bool Expression::IsStringLiteral() const {
42 return AsLiteral() != NULL && AsLiteral()->value()->IsString();
43 } 38 }
44 39
45 40
46 bool Expression::IsNullLiteral() const { 41 bool Expression::IsNullLiteral() const {
47 return AsLiteral() != NULL && AsLiteral()->value()->IsNull(); 42 return AsLiteral() != NULL && AsLiteral()->value()->IsNull();
48 } 43 }
49 44
50 45
46 Literal* Expression::AsAnyLiteral() {
47 if (IsStringLiteral()) {
48 return AsStringLiteral();
49 }
50 if (IsNumberLiteral()) {
51 return AsNumberLiteral();
52 }
53 return AsLiteral();
54 }
55
56
51 bool Expression::IsUndefinedLiteral(Isolate* isolate) const { 57 bool Expression::IsUndefinedLiteral(Isolate* isolate) const {
52 const VariableProxy* var_proxy = AsVariableProxy(); 58 const VariableProxy* var_proxy = AsVariableProxy();
53 if (var_proxy == NULL) return false; 59 if (var_proxy == NULL) return false;
54 Variable* var = var_proxy->var(); 60 Variable* var = var_proxy->var();
55 // The global identifier "undefined" is immutable. Everything 61 // The global identifier "undefined" is immutable. Everything
56 // else could be reassigned. 62 // else could be reassigned.
57 return var != NULL && var->location() == Variable::UNALLOCATED && 63 return var != NULL && var->location() == Variable::UNALLOCATED &&
58 String::Equals(var_proxy->name(), 64 String::Equals(var_proxy->name(),
59 isolate->factory()->undefined_string()); 65 isolate->factory()->undefined_string());
60 } 66 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 emit_store_ = true; 191 emit_store_ = true;
186 key_ = key; 192 key_ = key;
187 value_ = value; 193 value_ = value;
188 Handle<Object> k = key->value(); 194 Handle<Object> k = key->value();
189 if (k->IsInternalizedString() && 195 if (k->IsInternalizedString() &&
190 String::Equals(Handle<String>::cast(k), 196 String::Equals(Handle<String>::cast(k),
191 zone->isolate()->factory()->proto_string())) { 197 zone->isolate()->factory()->proto_string())) {
192 kind_ = PROTOTYPE; 198 kind_ = PROTOTYPE;
193 } else if (value_->AsMaterializedLiteral() != NULL) { 199 } else if (value_->AsMaterializedLiteral() != NULL) {
194 kind_ = MATERIALIZED_LITERAL; 200 kind_ = MATERIALIZED_LITERAL;
195 } else if (value_->AsLiteral() != NULL) { 201 } else if (value_->AsAnyLiteral() != NULL) {
196 kind_ = CONSTANT; 202 kind_ = CONSTANT;
197 } else { 203 } else {
198 kind_ = COMPUTED; 204 kind_ = COMPUTED;
199 } 205 }
200 } 206 }
201 207
202 208
203 ObjectLiteralProperty::ObjectLiteralProperty( 209 ObjectLiteralProperty::ObjectLiteralProperty(
204 Zone* zone, bool is_getter, FunctionLiteral* value) { 210 Zone* zone, bool is_getter, FunctionLiteral* value) {
205 emit_store_ = true; 211 emit_store_ = true;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 literals->set(1, *element_values); 389 literals->set(1, *element_values);
384 390
385 constant_elements_ = literals; 391 constant_elements_ = literals;
386 set_is_simple(is_simple); 392 set_is_simple(is_simple);
387 set_depth(depth_acc); 393 set_depth(depth_acc);
388 } 394 }
389 395
390 396
391 Handle<Object> MaterializedLiteral::GetBoilerplateValue(Expression* expression, 397 Handle<Object> MaterializedLiteral::GetBoilerplateValue(Expression* expression,
392 Isolate* isolate) { 398 Isolate* isolate) {
393 if (expression->AsLiteral() != NULL) { 399 if (expression->AsAnyLiteral() != NULL) {
394 return expression->AsLiteral()->value(); 400 return expression->AsAnyLiteral()->value();
395 } 401 }
396 if (CompileTimeValue::IsCompileTimeValue(expression)) { 402 if (CompileTimeValue::IsCompileTimeValue(expression)) {
397 return CompileTimeValue::GetValue(isolate, expression); 403 return CompileTimeValue::GetValue(isolate, expression);
398 } 404 }
399 return isolate->factory()->uninitialized_value(); 405 return isolate->factory()->uninitialized_value();
400 } 406 }
401 407
402 408
403 void MaterializedLiteral::BuildConstants(Isolate* isolate) { 409 void MaterializedLiteral::BuildConstants(Isolate* isolate) {
404 if (IsArrayLiteral()) { 410 if (IsArrayLiteral()) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 480
475 481
476 // Check for the pattern: typeof <expression> equals <string literal>. 482 // Check for the pattern: typeof <expression> equals <string literal>.
477 static bool MatchLiteralCompareTypeof(Expression* left, 483 static bool MatchLiteralCompareTypeof(Expression* left,
478 Token::Value op, 484 Token::Value op,
479 Expression* right, 485 Expression* right,
480 Expression** expr, 486 Expression** expr,
481 Handle<String>* check) { 487 Handle<String>* check) {
482 if (IsTypeof(left) && right->IsStringLiteral() && Token::IsEqualityOp(op)) { 488 if (IsTypeof(left) && right->IsStringLiteral() && Token::IsEqualityOp(op)) {
483 *expr = left->AsUnaryOperation()->expression(); 489 *expr = left->AsUnaryOperation()->expression();
484 *check = Handle<String>::cast(right->AsLiteral()->value()); 490 *check = Handle<String>::cast(right->AsStringLiteral()->value());
485 return true; 491 return true;
486 } 492 }
487 return false; 493 return false;
488 } 494 }
489 495
490 496
491 bool CompareOperation::IsLiteralCompareTypeof(Expression** expr, 497 bool CompareOperation::IsLiteralCompareTypeof(Expression** expr,
492 Handle<String>* check) { 498 Handle<String>* check) {
493 return MatchLiteralCompareTypeof(left_, op_, right_, expr, check) || 499 return MatchLiteralCompareTypeof(left_, op_, right_, expr, check) ||
494 MatchLiteralCompareTypeof(right_, op_, left_, expr, check); 500 MatchLiteralCompareTypeof(right_, op_, left_, expr, check);
495 } 501 }
496 502
497 503
498 static bool IsVoidOfLiteral(Expression* expr) { 504 static bool IsVoidOfLiteral(Expression* expr) {
499 UnaryOperation* maybe_unary = expr->AsUnaryOperation(); 505 UnaryOperation* maybe_unary = expr->AsUnaryOperation();
500 return maybe_unary != NULL && 506 return maybe_unary != NULL && maybe_unary->op() == Token::VOID &&
501 maybe_unary->op() == Token::VOID && 507 maybe_unary->expression()->AsAnyLiteral() != NULL;
502 maybe_unary->expression()->AsLiteral() != NULL;
503 } 508 }
504 509
505 510
506 // Check for the pattern: void <literal> equals <expression> or 511 // Check for the pattern: void <literal> equals <expression> or
507 // undefined equals <expression> 512 // undefined equals <expression>
508 static bool MatchLiteralCompareUndefined(Expression* left, 513 static bool MatchLiteralCompareUndefined(Expression* left,
509 Token::Value op, 514 Token::Value op,
510 Expression* right, 515 Expression* right,
511 Expression** expr, 516 Expression** expr,
512 Isolate* isolate) { 517 Isolate* isolate) {
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 REGULAR_NODE(ExpressionStatement) 1069 REGULAR_NODE(ExpressionStatement)
1065 REGULAR_NODE(EmptyStatement) 1070 REGULAR_NODE(EmptyStatement)
1066 REGULAR_NODE(IfStatement) 1071 REGULAR_NODE(IfStatement)
1067 REGULAR_NODE(ContinueStatement) 1072 REGULAR_NODE(ContinueStatement)
1068 REGULAR_NODE(BreakStatement) 1073 REGULAR_NODE(BreakStatement)
1069 REGULAR_NODE(ReturnStatement) 1074 REGULAR_NODE(ReturnStatement)
1070 REGULAR_NODE(SwitchStatement) 1075 REGULAR_NODE(SwitchStatement)
1071 REGULAR_NODE(CaseClause) 1076 REGULAR_NODE(CaseClause)
1072 REGULAR_NODE(Conditional) 1077 REGULAR_NODE(Conditional)
1073 REGULAR_NODE(Literal) 1078 REGULAR_NODE(Literal)
1079 REGULAR_NODE(StringLiteral)
1080 REGULAR_NODE(NumberLiteral)
1074 REGULAR_NODE(ArrayLiteral) 1081 REGULAR_NODE(ArrayLiteral)
1075 REGULAR_NODE(ObjectLiteral) 1082 REGULAR_NODE(ObjectLiteral)
1076 REGULAR_NODE(RegExpLiteral) 1083 REGULAR_NODE(RegExpLiteral)
1077 REGULAR_NODE(FunctionLiteral) 1084 REGULAR_NODE(FunctionLiteral)
1078 REGULAR_NODE(Assignment) 1085 REGULAR_NODE(Assignment)
1079 REGULAR_NODE(Throw) 1086 REGULAR_NODE(Throw)
1080 REGULAR_NODE(Property) 1087 REGULAR_NODE(Property)
1081 REGULAR_NODE(UnaryOperation) 1088 REGULAR_NODE(UnaryOperation)
1082 REGULAR_NODE(CountOperation) 1089 REGULAR_NODE(CountOperation)
1083 REGULAR_NODE(BinaryOperation) 1090 REGULAR_NODE(BinaryOperation)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 add_flag(kDontInline); 1138 add_flag(kDontInline);
1132 } 1139 }
1133 } 1140 }
1134 1141
1135 #undef REGULAR_NODE 1142 #undef REGULAR_NODE
1136 #undef DONT_OPTIMIZE_NODE 1143 #undef DONT_OPTIMIZE_NODE
1137 #undef DONT_SELFOPTIMIZE_NODE 1144 #undef DONT_SELFOPTIMIZE_NODE
1138 #undef DONT_CACHE_NODE 1145 #undef DONT_CACHE_NODE
1139 1146
1140 1147
1141 Handle<String> Literal::ToString() { 1148 Handle<String> Literal::ToString() const {
1142 if (value_->IsString()) return Handle<String>::cast(value_); 1149 UNREACHABLE();
1150 return Handle<String>();
1151 }
1152
1153
1154 Handle<String> NumberLiteral::ToString() const {
1143 ASSERT(value_->IsNumber()); 1155 ASSERT(value_->IsNumber());
1144 char arr[100]; 1156 char arr[100];
1145 Vector<char> buffer(arr, ARRAY_SIZE(arr)); 1157 Vector<char> buffer(arr, ARRAY_SIZE(arr));
1146 const char* str; 1158 const char* str;
1147 if (value_->IsSmi()) { 1159 if (value_->IsSmi()) {
1148 // Optimization only, the heap number case would subsume this. 1160 // Optimization only, the heap number case would subsume this.
1149 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); 1161 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value());
1150 str = arr; 1162 str = arr;
1151 } else { 1163 } else {
1152 str = DoubleToCString(value_->Number(), buffer); 1164 str = DoubleToCString(value_->Number(), buffer);
1153 } 1165 }
1154 return isolate_->factory()->NewStringFromAsciiChecked(str); 1166 return isolate_->factory()->NewStringFromAsciiChecked(str);
1155 } 1167 }
1156 1168
1157 1169
1158 } } // namespace v8::internal 1170 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/full-codegen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698