#include "config.h"
#include "IndexingType.h"
#include <wtf/StringExtras.h>
namespace JSC {
IndexingType leastUpperBoundOfIndexingTypes(IndexingType a, IndexingType b)
{
ASSERT((a & IsArray) == (b & IsArray));
return std::max(a, b);
}
IndexingType leastUpperBoundOfIndexingTypeAndType(IndexingType indexingType, SpeculatedType type)
{
if (!type)
return indexingType;
switch (indexingType) {
case ALL_BLANK_INDEXING_TYPES:
case ALL_UNDECIDED_INDEXING_TYPES:
case ALL_INT32_INDEXING_TYPES:
if (isInt32Speculation(type))
return (indexingType & ~IndexingShapeMask) | Int32Shape;
if (isFullNumberSpeculation(type))
return (indexingType & ~IndexingShapeMask) | DoubleShape;
return (indexingType & ~IndexingShapeMask) | ContiguousShape;
case ALL_DOUBLE_INDEXING_TYPES:
if (isFullNumberSpeculation(type))
return indexingType;
return (indexingType & ~IndexingShapeMask) | ContiguousShape;
case ALL_CONTIGUOUS_INDEXING_TYPES:
case ALL_ARRAY_STORAGE_INDEXING_TYPES:
return indexingType;
default:
CRASH();
return 0;
}
}
IndexingType leastUpperBoundOfIndexingTypeAndValue(IndexingType indexingType, JSValue value)
{
return leastUpperBoundOfIndexingTypeAndType(indexingType, speculationFromValue(value));
}
void dumpIndexingType(PrintStream& out, IndexingType indexingType)
{
const char* basicName;
switch (indexingType & AllArrayTypes) {
case NonArray:
basicName = "NonArray";
break;
case NonArrayWithInt32:
basicName = "NonArrayWithInt32";
break;
case NonArrayWithDouble:
basicName = "NonArrayWithDouble";
break;
case NonArrayWithContiguous:
basicName = "NonArrayWithContiguous";
break;
case NonArrayWithArrayStorage:
basicName = "NonArrayWithArrayStorage";
break;
case NonArrayWithSlowPutArrayStorage:
basicName = "NonArrayWithSlowPutArrayStorage";
break;
case ArrayClass:
basicName = "ArrayClass";
break;
case ArrayWithUndecided:
basicName = "ArrayWithUndecided";
break;
case ArrayWithInt32:
basicName = "ArrayWithInt32";
break;
case ArrayWithDouble:
basicName = "ArrayWithDouble";
break;
case ArrayWithContiguous:
basicName = "ArrayWithContiguous";
break;
case ArrayWithArrayStorage:
basicName = "ArrayWithArrayStorage";
break;
case ArrayWithSlowPutArrayStorage:
basicName = "ArrayWithSlowPutArrayStorage";
break;
default:
basicName = "Unknown!";
break;
}
out.printf("%s%s", basicName, (indexingType & MayHaveIndexedAccessors) ? "|MayHaveIndexedAccessors" : "");
}
}