Chromium Code Reviews| Index: src/ast.cc |
| diff --git a/src/ast.cc b/src/ast.cc |
| index 2ee1a0a40d7ddbfd2a11c397e63b85b152c74a02..8bbbfb7d6499c92ac15f2fdeca0b43a0c83f9cab 100644 |
| --- a/src/ast.cc |
| +++ b/src/ast.cc |
| @@ -498,5 +498,97 @@ RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes) |
| } |
| } |
| +// IsPrimitive implementation. IsPrimitive is true if the value of an |
| +// expression is known at compile-time to be any JS type other than Object |
| +// (e.g, it is Undefined, Null, Boolean, String, or Number). |
| + |
| +// The following expression types are never primitive because they express |
| +// Object values. |
| +bool FunctionLiteral::IsPrimitive() { return false; } |
| +bool FunctionBoilerplateLiteral::IsPrimitive() { return false; } |
| +bool RegExpLiteral::IsPrimitive() { return false; } |
| +bool ObjectLiteral::IsPrimitive() { return false; } |
| +bool ArrayLiteral::IsPrimitive() { return false; } |
| +bool CatchExtensionObject::IsPrimitive() { return false; } |
| +bool CallNew::IsPrimitive() { return false; } |
| +bool ThisFunction::IsPrimitive() { return false; } |
| + |
| + |
| +// The following expression types are not always primitive because we do not |
| +// have enough information to conclude that they are. |
| +bool VariableProxy::IsPrimitive() { return false; } |
| +bool Property::IsPrimitive() { return false; } |
| +bool Call::IsPrimitive() { return false; } |
| +bool CallRuntime::IsPrimitive() { return false; } |
| + |
| + |
| +// The value of a conditional is the value of one of the alternatives. It's |
| +// always primitive if both alternatives are always primitive. |
| +bool Conditional::IsPrimitive() { |
| + return then_expression()->IsPrimitive() && else_expression()->IsPrimitive(); |
| +} |
| + |
| + |
| +// A literal is primitive when it is not a JSObject. |
| +bool Literal::IsPrimitive() { return !handle()->IsJSObject(); } |
| + |
| + |
| +// The value of an assignment is the value of its right-hand side. |
| +bool Assignment::IsPrimitive() { |
| + switch (op()) { |
| + case Token::INIT_VAR: |
| + case Token::INIT_CONST: |
| + case Token::ASSIGN: |
| + return value()->IsPrimitive(); |
| + |
| + default: |
| + // {|=, ^=, &=, <<=, >>=, >>>=, +=, -=, *=, /=, %=} |
| + // Arithmetic operations are always primitive. They express Numbers |
| + // with the exception of +, which expresses a Number or a String. |
| + return true; |
| + } |
| +} |
| + |
| + |
| +// Throw does not express a value, so it's trivially always primitive. |
| +bool Throw::IsPrimitive() { return true; } |
| + |
| + |
| +// Unary operations always express primitive values. delete and ! express |
| +// Booleans, void Undefined, typeof String (but host objects are |
|
Mads Ager (chromium)
2010/03/12 12:19:29
Let's remove the comment about host objects being
|
| +// implementation-dependent), +, -, and ~ Numbers. |
| +bool UnaryOperation::IsPrimitive() { return true; } |
| + |
| + |
| +// Count operations (pre- and post-fix increment and decrement) always |
| +// express primitive values (Numbers). See ECMA-262-3, 11.3.1, 11.3.2, |
| +// 11.4.4, ane 11.4.5. |
| +bool CountOperation::IsPrimitive() { return true; } |
| + |
| + |
| +// Binary operations depend on the operator. |
| +bool BinaryOperation::IsPrimitive() { |
| + switch (op()) { |
| + case Token::COMMA: |
| + // Value is the value of the right subexpression. |
| + return right()->IsPrimitive(); |
| + |
| + case Token::OR: |
| + case Token::AND: |
| + // Value is the value one of the subexpressions. |
| + return left()->IsPrimitive() && right()->IsPrimitive(); |
| + |
| + default: |
| + // {|, ^, &, <<, >>, >>>, +, -, *, /, %} |
| + // Arithmetic operations are always primitive. They express Numbers |
| + // with the exception of +, which expresses a Number or a String. |
| + return true; |
| + } |
| +} |
| + |
| + |
| +// Compare operations always express Boolean values. |
| +bool CompareOperation::IsPrimitive() { return true; } |
| + |
| } } // namespace v8::internal |