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 <wtf/StringExtras.h> 30 31namespace JSC { 32 33IndexingType 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 42IndexingType 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 if (isFullNumberSpeculation(type)) 53 return (indexingType & ~IndexingShapeMask) | DoubleShape; 54 return (indexingType & ~IndexingShapeMask) | ContiguousShape; 55 case ALL_DOUBLE_INDEXING_TYPES: 56 if (isFullNumberSpeculation(type)) 57 return indexingType; 58 return (indexingType & ~IndexingShapeMask) | ContiguousShape; 59 case ALL_CONTIGUOUS_INDEXING_TYPES: 60 case ALL_ARRAY_STORAGE_INDEXING_TYPES: 61 return indexingType; 62 default: 63 CRASH(); 64 return 0; 65 } 66} 67 68IndexingType leastUpperBoundOfIndexingTypeAndValue(IndexingType indexingType, JSValue value) 69{ 70 return leastUpperBoundOfIndexingTypeAndType(indexingType, speculationFromValue(value)); 71} 72 73void dumpIndexingType(PrintStream& out, IndexingType indexingType) 74{ 75 const char* basicName; 76 switch (indexingType & AllArrayTypes) { 77 case NonArray: 78 basicName = "NonArray"; 79 break; 80 case NonArrayWithInt32: 81 basicName = "NonArrayWithInt32"; 82 break; 83 case NonArrayWithDouble: 84 basicName = "NonArrayWithDouble"; 85 break; 86 case NonArrayWithContiguous: 87 basicName = "NonArrayWithContiguous"; 88 break; 89 case NonArrayWithArrayStorage: 90 basicName = "NonArrayWithArrayStorage"; 91 break; 92 case NonArrayWithSlowPutArrayStorage: 93 basicName = "NonArrayWithSlowPutArrayStorage"; 94 break; 95 case ArrayClass: 96 basicName = "ArrayClass"; 97 break; 98 case ArrayWithUndecided: 99 basicName = "ArrayWithUndecided"; 100 break; 101 case ArrayWithInt32: 102 basicName = "ArrayWithInt32"; 103 break; 104 case ArrayWithDouble: 105 basicName = "ArrayWithDouble"; 106 break; 107 case ArrayWithContiguous: 108 basicName = "ArrayWithContiguous"; 109 break; 110 case ArrayWithArrayStorage: 111 basicName = "ArrayWithArrayStorage"; 112 break; 113 case ArrayWithSlowPutArrayStorage: 114 basicName = "ArrayWithSlowPutArrayStorage"; 115 break; 116 default: 117 basicName = "Unknown!"; 118 break; 119 } 120 121 out.printf("%s%s", basicName, (indexingType & MayHaveIndexedAccessors) ? "|MayHaveIndexedAccessors" : ""); 122} 123 124} // namespace JSC 125 126