#ifndef TypeSet_h
#define TypeSet_h
#include "ConcurrentJITLock.h"
#include "RuntimeType.h"
#include "StructureSet.h"
#include <wtf/HashSet.h>
#include <wtf/RefCounted.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/text/WTFString.h>
#include <wtf/Vector.h>
namespace Inspector {
namespace Protocol {
template<typename T> class Array;
namespace Runtime {
class StructureDescription;
class TypeSet;
}
}
}
namespace JSC {
class StructureShape : public RefCounted<StructureShape> {
friend class TypeSet;
public:
StructureShape();
static Ref<StructureShape> create() { return adoptRef(*new StructureShape); }
String propertyHash();
void markAsFinal();
void addProperty(UniquedStringImpl&);
String stringRepresentation();
String toJSONString() const;
Ref<Inspector::Protocol::Runtime::StructureDescription> inspectorRepresentation();
void setConstructorName(String name) { m_constructorName = (name.isEmpty() ? "Object" : name); }
String constructorName() { return m_constructorName; }
void setProto(PassRefPtr<StructureShape> shape) { m_proto = shape; }
void enterDictionaryMode();
private:
static String leastCommonAncestor(const Vector<RefPtr<StructureShape>>);
static PassRefPtr<StructureShape> merge(const PassRefPtr<StructureShape>, const PassRefPtr<StructureShape>);
bool hasSamePrototypeChain(PassRefPtr<StructureShape>);
HashSet<RefPtr<UniquedStringImpl>, IdentifierRepHash> m_fields;
HashSet<RefPtr<UniquedStringImpl>, IdentifierRepHash> m_optionalFields;
RefPtr<StructureShape> m_proto;
std::unique_ptr<String> m_propertyHash;
String m_constructorName;
bool m_final;
bool m_isInDictionaryMode;
};
class TypeSet : public ThreadSafeRefCounted<TypeSet> {
public:
static Ref<TypeSet> create() { return adoptRef(*new TypeSet); }
TypeSet();
void addTypeInformation(RuntimeType, PassRefPtr<StructureShape>, Structure*);
void invalidateCache();
String dumpTypes() const;
String displayName() const;
Ref<Inspector::Protocol::Array<Inspector::Protocol::Runtime::StructureDescription>> allStructureRepresentations() const;
String toJSONString() const;
bool isOverflown() const { return m_isOverflown; }
String leastCommonAncestor() const;
Ref<Inspector::Protocol::Runtime::TypeSet> inspectorTypeSet() const;
bool isEmpty() const { return m_seenTypes == TypeNothing; }
bool doesTypeConformTo(RuntimeTypeMask test) const;
RuntimeTypeMask seenTypes() const { return m_seenTypes; }
StructureSet structureSet(const ConcurrentJITLocker&) const { return m_structureSet; }
ConcurrentJITLock m_lock;
private:
bool m_isOverflown;
RuntimeTypeMask m_seenTypes;
Vector<RefPtr<StructureShape>> m_structureHistory;
StructureSet m_structureSet;
};
}
#endif //TypeSet_h