Skip to content

Commit

Permalink
Almost works on clang
Browse files Browse the repository at this point in the history
  • Loading branch information
playmer committed Mar 7, 2017
1 parent 2c6e9d6 commit aa5af4b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
5 changes: 4 additions & 1 deletion Reflection/Attribute.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "Attribute.hpp"

DefineType(Attribute);
DefineType(Attribute)
{

}
12 changes: 5 additions & 7 deletions Reflection/ConstexprString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,23 @@ constexpr size_t GetNumberOfTokens(const char *aString)
template <size_t tConstSize>
struct ConstexprToken
{
public:
constexpr ConstexprToken()
: mData{ '\0' }
{
}

constexpr ConstexprToken(const char *aBegin)
: mData{ '\0' }
{
for (size_t i = 0; i < tConstSize; i++)
{
mData[i] = aBegin[i];
}

mData[tConstSize] = '\0';
mData[tConstSize] = { '\0' };
}

template<size_t tDifferentSize>
constexpr ConstexprToken(const ConstexprToken<tDifferentSize> &aToken)
: mData{ '0' }
{
static_assert(tDifferentSize <= tConstSize, "Trying to copy a ConstexprToken to a ConstexprToken of too small a size.");
for (size_t i = 0; i < tDifferentSize; i++)
Expand All @@ -60,7 +58,6 @@ struct ConstexprToken
constexpr const char* Data() const { return mData; };
constexpr const char* data() const { return mData; };

protected:
char mData[tConstSize + 1];
};

Expand All @@ -76,7 +73,7 @@ struct StringRange

constexpr StringRange(const char *aBegin)
: mBegin(aBegin),
mEnd(aBegin + StringLength(aBegin))
mEnd(aBegin + StringLength(aBegin))
{

}
Expand Down Expand Up @@ -114,7 +111,7 @@ template<size_t tConstSize>
struct ConstexprTokenWriter : public ConstexprToken<tConstSize>
{
constexpr ConstexprTokenWriter()
: mWritingPosition(mData)
: mWritingPosition(this->mData)
{
}

Expand Down Expand Up @@ -168,3 +165,4 @@ constexpr size_t GetFirstInstanceOfCharacter(const char *aString, size_t aSize,

return toReturn;
}

14 changes: 7 additions & 7 deletions Reflection/Reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ constexpr auto GetTypeName()
constexpr const char* functionName = CONSTEXPR_FUNCTION_SIGNATURE;

// TODO: Should also work for GCC.
#if defined(__clang__)
size_t lastSpace = GetLastInstanceOfCharacter(typeName, StringLength(typeName), '=');
size_t typeNameLength = totalLength - lastSpace - GetTypeEnd() - 2;

ConstexprToken<typeNameLength> token{ typeName + lastSpace + 2 };
#elif defined(_MSC_VER)
//#if defined(__clang__)
// size_t lastSpace = GetLastInstanceOfCharacter(typeName, StringLength(typeName), '=');
// size_t typeNameLength = totalLength - lastSpace - GetTypeEnd() - 2;
//
// ConstexprToken<typeNameLength> token{ typeName + lastSpace + 2 };
//#elif defined(_MSC_VER)
constexpr size_t firstArrow = GetFirstInstanceOfCharacter(functionName, StringLength(functionName), '<') + 1;
constexpr size_t lastArrow = GetLastInstanceOfCharacter(functionName, StringLength(functionName), '>');

Expand All @@ -141,7 +141,7 @@ constexpr auto GetTypeName()

totalType.mBegin = token.mEnd;
}
#endif
//#endif

return finalName;
}
16 changes: 11 additions & 5 deletions Reflection/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ inline Type* TypeId()
return TypeIdentification<T>::TypeId();
}

template<typename T>
inline void InitializeType()
{
return TypeInitialization<T>::InitializeType();
}
//template<typename T>
//inline void InitializeType()
//{
// return TypeInitialization<T>::InitializeType();
//}

#define DeclareExternalType(Name) \
template<> \
Expand Down Expand Up @@ -358,6 +358,9 @@ inline Type::Type(Type *aType, Modifier aModifier, T *aNull)
mPointerTo = aType;
break;
}
case Modifier::Normal:
default:
break;
}
}

Expand Down Expand Up @@ -392,6 +395,9 @@ inline Type::Type(Type *aType, Modifier aModifier, T *aNull, bool aFalse)
mPointerTo = aType;
break;
}
case Modifier::Normal:
default:
break;
}
}

Expand Down
14 changes: 8 additions & 6 deletions Reflection/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ int main()
Test::Test2::Animal::InitializeType();
Cat::InitializeType();

char test = -2;

auto char_Type = TypeId<char>();
auto u8_Type = TypeId<u8>();
//auto char_Type = TypeId<char>;
auto i8_Type = TypeId<i8>();
auto u8_Type = TypeId<u8>();
auto i8_Type = TypeId<i8>();
auto const_char = TypeId<const char*>();

(void)char_Type;
(void)u8_Type;
(void)i8_Type;
(void)const_char;

auto animalType = Test::Test2::Animal::GetStaticType();
auto catType = Cat::GetStaticType();
Expand All @@ -124,4 +124,6 @@ int main()
auto fielder = animalType->GetFirstField("Y");
fielder->GetSetter()->Invoke(&animal, 12);
auto j = fielder->GetGetter()->Invoke(&animal).As<int>();
(void)j;
(void)i;
}

0 comments on commit aa5af4b

Please sign in to comment.