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

Side by Side Diff: src/ast.cc

Issue 18429005: Undefined is not a literal. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix comments Created 7 years, 5 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 bool Expression::IsStringLiteral() { 64 bool Expression::IsStringLiteral() {
65 return AsLiteral() != NULL && AsLiteral()->value()->IsString(); 65 return AsLiteral() != NULL && AsLiteral()->value()->IsString();
66 } 66 }
67 67
68 68
69 bool Expression::IsNullLiteral() { 69 bool Expression::IsNullLiteral() {
70 return AsLiteral() != NULL && AsLiteral()->value()->IsNull(); 70 return AsLiteral() != NULL && AsLiteral()->value()->IsNull();
71 } 71 }
72 72
73 73
74 bool Expression::IsUndefinedLiteral() { 74 bool Expression::IsUndefinedLiteral(Isolate* isolate) {
75 return AsLiteral() != NULL && AsLiteral()->value()->IsUndefined(); 75 VariableProxy* var_proxy = AsVariableProxy();
76 if (var_proxy == NULL) return false;
77 Variable* var = var_proxy->var();
78 // The global identifier "undefined" is immutable. Everything
79 // else could be reassigned.
80 return var != NULL && var->location() == Variable::UNALLOCATED &&
81 var_proxy->name()->Equals(isolate->heap()->undefined_string());
76 } 82 }
77 83
78 84
79 VariableProxy::VariableProxy(Isolate* isolate, Variable* var) 85 VariableProxy::VariableProxy(Isolate* isolate, Variable* var)
80 : Expression(isolate), 86 : Expression(isolate),
81 name_(var->name()), 87 name_(var->name()),
82 var_(NULL), // Will be set by the call to BindTo. 88 var_(NULL), // Will be set by the call to BindTo.
83 is_this_(var->is_this()), 89 is_this_(var->is_this()),
84 is_trivial_(false), 90 is_trivial_(false),
85 is_lvalue_(false), 91 is_lvalue_(false),
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 maybe_unary->op() == Token::VOID && 384 maybe_unary->op() == Token::VOID &&
379 maybe_unary->expression()->AsLiteral() != NULL; 385 maybe_unary->expression()->AsLiteral() != NULL;
380 } 386 }
381 387
382 388
383 // Check for the pattern: void <literal> equals <expression> or 389 // Check for the pattern: void <literal> equals <expression> or
384 // undefined equals <expression> 390 // undefined equals <expression>
385 static bool MatchLiteralCompareUndefined(Expression* left, 391 static bool MatchLiteralCompareUndefined(Expression* left,
386 Token::Value op, 392 Token::Value op,
387 Expression* right, 393 Expression* right,
388 Expression** expr) { 394 Expression** expr,
395 Isolate* isolate) {
389 if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) { 396 if (IsVoidOfLiteral(left) && Token::IsEqualityOp(op)) {
390 *expr = right; 397 *expr = right;
391 return true; 398 return true;
392 } 399 }
393 if (left->IsUndefinedLiteral() && Token::IsEqualityOp(op)) { 400 if (left->IsUndefinedLiteral(isolate) && Token::IsEqualityOp(op)) {
394 *expr = right; 401 *expr = right;
395 return true; 402 return true;
396 } 403 }
397 return false; 404 return false;
398 } 405 }
399 406
400 407
401 bool CompareOperation::IsLiteralCompareUndefined(Expression** expr) { 408 bool CompareOperation::IsLiteralCompareUndefined(
402 return MatchLiteralCompareUndefined(left_, op_, right_, expr) || 409 Expression** expr, Isolate* isolate) {
403 MatchLiteralCompareUndefined(right_, op_, left_, expr); 410 return MatchLiteralCompareUndefined(left_, op_, right_, expr, isolate) ||
411 MatchLiteralCompareUndefined(right_, op_, left_, expr, isolate);
404 } 412 }
405 413
406 414
407 // Check for the pattern: null equals <expression> 415 // Check for the pattern: null equals <expression>
408 static bool MatchLiteralCompareNull(Expression* left, 416 static bool MatchLiteralCompareNull(Expression* left,
409 Token::Value op, 417 Token::Value op,
410 Expression* right, 418 Expression* right,
411 Expression** expr) { 419 Expression** expr) {
412 if (left->IsNullLiteral() && Token::IsEqualityOp(op)) { 420 if (left->IsNullLiteral() && Token::IsEqualityOp(op)) {
413 *expr = right; 421 *expr = right;
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); 1195 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value());
1188 str = arr; 1196 str = arr;
1189 } else { 1197 } else {
1190 str = DoubleToCString(value_->Number(), buffer); 1198 str = DoubleToCString(value_->Number(), buffer);
1191 } 1199 }
1192 return factory->NewStringFromAscii(CStrVector(str)); 1200 return factory->NewStringFromAscii(CStrVector(str));
1193 } 1201 }
1194 1202
1195 1203
1196 } } // namespace v8::internal 1204 } } // 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