1 | /* |
2 | * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "IndexingType.h" |
28 | |
29 | #include "JSCInlines.h" |
30 | |
31 | namespace JSC { |
32 | |
33 | IndexingType leastUpperBoundOfIndexingTypes(IndexingType a, IndexingType b) |
34 | { |
35 | // It doesn't make sense to LUB something that is an array with something that isn't. |
36 | ASSERT((a & IsArray) == (b & IsArray)); |
37 | |
38 | // Boy, this sure is easy right now. |
39 | return std::max(a, b); |
40 | } |
41 | |
42 | IndexingType leastUpperBoundOfIndexingTypeAndType(IndexingType indexingType, SpeculatedType type) |
43 | { |
44 | if (!type) |
45 | return indexingType; |
46 | switch (indexingType) { |
47 | case ALL_BLANK_INDEXING_TYPES: |
48 | case ALL_UNDECIDED_INDEXING_TYPES: |
49 | case ALL_INT32_INDEXING_TYPES: |
50 | if (isInt32Speculation(type)) |
51 | return (indexingType & ~IndexingShapeMask) | Int32Shape; |
52 | // FIXME: Should this really say that it wants a double for NaNs. |
53 | if (isFullNumberSpeculation(type)) |
54 | return (indexingType & ~IndexingShapeMask) | DoubleShape; |
55 | return (indexingType & ~IndexingShapeMask) | ContiguousShape; |
56 | case ALL_DOUBLE_INDEXING_TYPES: |
57 | // FIXME: Should this really say that it wants a double for NaNs. |
58 | if (isFullNumberSpeculation(type)) |
59 | return indexingType; |
60 | return (indexingType & ~IndexingShapeMask) | ContiguousShape; |
61 | case ALL_CONTIGUOUS_INDEXING_TYPES: |
62 | case ALL_ARRAY_STORAGE_INDEXING_TYPES: |
63 | return indexingType; |
64 | default: |
65 | CRASH(); |
66 | return 0; |
67 | } |
68 | } |
69 | |
70 | IndexingType leastUpperBoundOfIndexingTypeAndValue(IndexingType indexingType, JSValue value) |
71 | { |
72 | return leastUpperBoundOfIndexingTypes(indexingType, indexingTypeForValue(value) | (indexingType & IsArray)); |
73 | } |
74 | |
75 | void dumpIndexingType(PrintStream& out, IndexingType indexingType) |
76 | { |
77 | const char* basicName; |
78 | switch (indexingType & AllArrayTypes) { |
79 | case NonArray: |
80 | basicName = "NonArray" ; |
81 | break; |
82 | case NonArrayWithInt32: |
83 | basicName = "NonArrayWithInt32" ; |
84 | break; |
85 | case NonArrayWithDouble: |
86 | basicName = "NonArrayWithDouble" ; |
87 | break; |
88 | case NonArrayWithContiguous: |
89 | basicName = "NonArrayWithContiguous" ; |
90 | break; |
91 | case NonArrayWithArrayStorage: |
92 | basicName = "NonArrayWithArrayStorage" ; |
93 | break; |
94 | case NonArrayWithSlowPutArrayStorage: |
95 | basicName = "NonArrayWithSlowPutArrayStorage" ; |
96 | break; |
97 | case ArrayClass: |
98 | basicName = "ArrayClass" ; |
99 | break; |
100 | case ArrayWithUndecided: |
101 | basicName = "ArrayWithUndecided" ; |
102 | break; |
103 | case ArrayWithInt32: |
104 | basicName = "ArrayWithInt32" ; |
105 | break; |
106 | case ArrayWithDouble: |
107 | basicName = "ArrayWithDouble" ; |
108 | break; |
109 | case ArrayWithContiguous: |
110 | basicName = "ArrayWithContiguous" ; |
111 | break; |
112 | case ArrayWithArrayStorage: |
113 | basicName = "ArrayWithArrayStorage" ; |
114 | break; |
115 | case ArrayWithSlowPutArrayStorage: |
116 | basicName = "ArrayWithSlowPutArrayStorage" ; |
117 | break; |
118 | case CopyOnWriteArrayWithInt32: |
119 | basicName = "CopyOnWriteArrayWithInt32" ; |
120 | break; |
121 | case CopyOnWriteArrayWithDouble: |
122 | basicName = "CopyOnWriteArrayWithDouble" ; |
123 | break; |
124 | case CopyOnWriteArrayWithContiguous: |
125 | basicName = "CopyOnWriteArrayWithContiguous" ; |
126 | break; |
127 | default: |
128 | basicName = "Unknown!" ; |
129 | break; |
130 | } |
131 | |
132 | out.printf("%s%s" , basicName, (indexingType & MayHaveIndexedAccessors) ? "|MayHaveIndexedAccessors" : "" ); |
133 | } |
134 | |
135 | } // namespace JSC |
136 | |
137 | |