OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef V8_AST_COMPILE_TIME_VALUE | 5 #ifndef V8_AST_COMPILE_TIME_VALUE |
6 #define V8_AST_COMPILE_TIME_VALUE | 6 #define V8_AST_COMPILE_TIME_VALUE |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/globals.h" | 9 #include "src/globals.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 class Expression; | 14 class Expression; |
15 | 15 |
16 // Support for handling complex values (array and object literals) that | 16 // Support for handling complex values (array and object literals) that |
17 // can be fully handled at compile time. | 17 // can be fully handled at compile time. |
18 class CompileTimeValue : public AllStatic { | 18 class CompileTimeValue : public AllStatic { |
19 public: | 19 public: |
20 enum LiteralType { | 20 // This is a special marker used to encode array literals. The value has to be |
21 OBJECT_LITERAL_FAST_ELEMENTS, | 21 // different from any value possibly returned by |
22 OBJECT_LITERAL_SLOW_ELEMENTS, | 22 // ObjectLiteral::EncodeLiteralType. |
23 ARRAY_LITERAL | 23 static const int kArrayLiteralFlag = -1; |
24 }; | |
25 | 24 |
26 static bool IsCompileTimeValue(Expression* expression); | 25 static bool IsCompileTimeValue(Expression* expression); |
27 | 26 |
28 // Get the value as a compile time value. | 27 // Get the value as a compile time value. |
29 static Handle<FixedArray> GetValue(Isolate* isolate, Expression* expression); | 28 static Handle<FixedArray> GetValue(Isolate* isolate, Expression* expression); |
30 | 29 |
31 // Get the type of a compile time value returned by GetValue(). | 30 // Get the encoded literal type. This can either be kArrayLiteralFlag or |
32 static LiteralType GetLiteralType(Handle<FixedArray> value); | 31 // encoded properties of an ObjectLiteral returned by |
| 32 // ObjectLiteral::EncodeLiteralType. |
| 33 static int GetLiteralTypeFlags(Handle<FixedArray> value); |
33 | 34 |
34 // Get the elements of a compile time value returned by GetValue(). | 35 // Get the elements of a compile time value returned by GetValue(). |
35 static Handle<HeapObject> GetElements(Handle<FixedArray> value); | 36 static Handle<HeapObject> GetElements(Handle<FixedArray> value); |
36 | 37 |
37 private: | 38 private: |
38 static const int kLiteralTypeSlot = 0; | 39 static const int kLiteralTypeSlot = 0; |
39 static const int kElementsSlot = 1; | 40 static const int kElementsSlot = 1; |
40 }; | 41 }; |
41 | 42 |
42 } // namespace internal | 43 } // namespace internal |
43 } // namespace v8 | 44 } // namespace v8 |
44 | 45 |
45 #endif // V8_AST_COMPILE_TIME_VALUE | 46 #endif // V8_AST_COMPILE_TIME_VALUE |
OLD | NEW |