diff --git a/src/typeof.cpp b/src/typeof.cpp index 9987419..77c85ae 100644 --- a/src/typeof.cpp +++ b/src/typeof.cpp @@ -14,55 +14,58 @@ #include "dap/typeof.h" +namespace { + +struct NullTI : public dap::TypeInfo { + using null = dap::null; + inline std::string name() const { return "null"; } + inline size_t size() const { return sizeof(null); } + inline size_t alignment() const { return alignof(null); } + inline void construct(void* ptr) const { new (ptr) null(); } + inline void copyConstruct(void* dst, const void* src) const { + new (dst) null(*reinterpret_cast(src)); + } + inline void destruct(void* ptr) const { + reinterpret_cast(ptr)->~null(); + } + inline bool deserialize(const dap::Deserializer*, void*) const { + return true; + } + inline bool serialize(dap::Serializer*, const void*) const { return true; } +}; + +static dap::BasicTypeInfo booleanTI("boolean"); +static dap::BasicTypeInfo stringTI("string"); +static dap::BasicTypeInfo integerTI("integer"); +static dap::BasicTypeInfo numberTI("number"); +static dap::BasicTypeInfo objectTI("object"); +static dap::BasicTypeInfo anyTI("any"); +static NullTI nullTI; + +} // namespace + namespace dap { const TypeInfo* TypeOf::type() { - static BasicTypeInfo typeinfo("boolean"); - return &typeinfo; + return &booleanTI; } - const TypeInfo* TypeOf::type() { - static BasicTypeInfo typeinfo("string"); - return &typeinfo; + return &stringTI; } - const TypeInfo* TypeOf::type() { - static BasicTypeInfo typeinfo("integer"); - return &typeinfo; + return &integerTI; } - const TypeInfo* TypeOf::type() { - static BasicTypeInfo typeinfo("number"); - return &typeinfo; + return &numberTI; } - const TypeInfo* TypeOf::type() { - static BasicTypeInfo typeinfo("object"); - return &typeinfo; + return &objectTI; } - const TypeInfo* TypeOf::type() { - static BasicTypeInfo typeinfo("any"); - return &typeinfo; + return &anyTI; +} +const TypeInfo* TypeOf::type() { + return &nullTI; } -const TypeInfo* TypeOf::type() { - struct TI : public TypeInfo { - inline std::string name() const { return "null"; } - inline size_t size() const { return sizeof(null); } - inline size_t alignment() const { return alignof(null); } - inline void construct(void* ptr) const { new (ptr) null(); } - inline void copyConstruct(void* dst, const void* src) const { - new (dst) null(*reinterpret_cast(src)); - } - inline void destruct(void* ptr) const { - reinterpret_cast(ptr)->~null(); - } - inline bool deserialize(const Deserializer*, void*) const { return true; } - inline bool serialize(Serializer*, const void*) const { return true; } - }; - static TI typeinfo; - return &typeinfo; -} // namespace dap - } // namespace dap