Skip to content

Commit

Permalink
Removed asserts (26.10 22:13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexlord committed Oct 26, 2020
1 parent 71089ac commit 0258311
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 53 deletions.
16 changes: 8 additions & 8 deletions MetaCPP-CLI/ASTScraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ namespace metacpp {
// cType->dump();
return 0;
case clang::Type::TypeClass::ConstantArray: {
assert(arraySize == 1); // I do not know what to do in this case just yet. Check if this happens for int var[2][2][2] or something.

if (auto arrayType = clang::dyn_cast<clang::ConstantArrayType>(cType)) {
auto elemType = arrayType->getElementType();
auto elemArraySize = arrayType->getSize().getLimitedValue();
auto typeId = ResolveQualType(elemType, elemArraySize).GetTypeID();
if (m_Storage->HasType(typeId)) {
return m_Storage->GetType(typeId);
if(arraySize == 1) {
if (auto arrayType = clang::dyn_cast<clang::ConstantArrayType>(cType)) {
auto elemType = arrayType->getElementType();
auto elemArraySize = arrayType->getSize().getLimitedValue();
auto typeId = ResolveQualType(elemType, elemArraySize).GetTypeID();
if (m_Storage->HasType(typeId)) {
return m_Storage->GetType(typeId);
}
}
}
std::cout << "[Failed to scrape ConstantArray]" << std::endl;
Expand Down
2 changes: 0 additions & 2 deletions MetaCPP/include/MetaCPP/SequentialContainer.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef METACPP_SEQUENTIAL_CONTAINER_HPP
#define METACPP_SEQUENTIAL_CONTAINER_HPP

#include <cassert>

#include "QualifiedType.hpp"
#include "Container.hpp"

Expand Down
82 changes: 41 additions & 41 deletions MetaCPP/src/MetaCPP/JsonSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,42 @@ namespace metacpp {

switch (qtype.GetQualifierOperator()) {
case QualifierOperator::VALUE:
assert(qtype.GetArraySize() == 1);
if (type->GetArraySize() == 1) {
if (IsBasicType(type)) {
return SerializeBasicType(type, ptr, context);
if(qtype.GetArraySize() == 1) {
if (type->GetArraySize() == 1) {
if (IsBasicType(type)) {
return SerializeBasicType(type, ptr, context);
} else {
return SerializeObject(type, ptr, false, pointer_recursion, context);
}
} else {
return SerializeObject(type, ptr, false, pointer_recursion, context);
Value array;
array.SetArray();
auto elemName = type->GetQualifiedName().ElementTypeQualified();
auto elemType = m_Storage->GetType(elemName);
QualifiedType elemQType = QualifiedType(elemType->GetTypeID(), QualifierOperator::VALUE, qtype.IsConst(), 1);
for (size_t index = 0; index < type->GetArraySize(); ++index) {
char* addr = (char*) ptr + elemType->GetSize() * index;
array.PushBack(SerializeType(elemQType, addr, pointer_recursion, context), context.document->GetAllocator());
}
return array;
}
} else {
Value array;
array.SetArray();
auto elemName = type->GetQualifiedName().ElementTypeQualified();
auto elemType = m_Storage->GetType(elemName);
QualifiedType elemQType = QualifiedType(elemType->GetTypeID(), QualifierOperator::VALUE, qtype.IsConst(), 1);
for (size_t index = 0; index < type->GetArraySize(); ++index) {
char* addr = (char*) ptr + elemType->GetSize() * index;
array.PushBack(SerializeType(elemQType, addr, pointer_recursion, context), context.document->GetAllocator());
}
return array;
}
return Value();
case QualifierOperator::POINTER: {
assert(qtype.GetArraySize() == 1);
assert(type->GetArraySize() == 1); // TODO: support array of pointers, maybe?
void* pointee = *((void**) ptr);
if (pointee != 0) {
if (IsBasicType(type))
return SerializeBasicType(type, pointee, context);
else {
auto derived = context.serializer->GetStorage()->ResolveDerivedType(type, pointee);
return SerializeObject(derived.first, derived.second, true, pointer_recursion + 1, context);
if(qtype.GetArraySize() == 1 && type->GetArraySize() == 1) {
void* pointee = *((void**) ptr);
if (pointee != 0) {
if (IsBasicType(type))
return SerializeBasicType(type, pointee, context);
else {
auto derived = context.serializer->GetStorage()->ResolveDerivedType(type, pointee);
return SerializeObject(derived.first, derived.second, true, pointer_recursion + 1, context);
}
}
}
return Value();
}
case QualifierOperator::ARRAY: {
assert(qtype.GetArraySize() > 1);
Value array;
array.SetArray();
QualifiedType elemQType = QualifiedType(type->GetTypeID(), QualifierOperator::VALUE, qtype.IsConst(), 1);
Expand Down Expand Up @@ -284,27 +285,27 @@ namespace metacpp {

switch (qtype.GetQualifierOperator()) {
case QualifierOperator::VALUE: {
assert(qtype.GetArraySize() == 1);
if (type->GetArraySize() == 1) {
DeSerializeValue(value, obj, context, type, id);
} else {
auto elemName = type->GetQualifiedName().ElementTypeQualified();
auto elemType = m_Storage->GetType(elemName);
QualifiedType elemQType = QualifiedType(elemType->GetTypeID(), QualifierOperator::VALUE, qtype.IsConst(), 1);
for (size_t index = 0; index < type->GetArraySize(); ++index) {
char* addr = (char*) obj + elemType->GetSize() * index;
DeSerializeType(elemQType, value[index], addr, context);
if(qtype.GetArraySize() == 1) {
if (type->GetArraySize() == 1) {
DeSerializeValue(value, obj, context, type, id);
} else {
auto elemName = type->GetQualifiedName().ElementTypeQualified();
auto elemType = m_Storage->GetType(elemName);
QualifiedType elemQType = QualifiedType(elemType->GetTypeID(), QualifierOperator::VALUE, qtype.IsConst(), 1);
for (size_t index = 0; index < type->GetArraySize(); ++index) {
char* addr = (char*) obj + elemType->GetSize() * index;
DeSerializeType(elemQType, value[index], addr, context);
}
}
}
break;
}
case QualifierOperator::POINTER:
assert(qtype.GetArraySize() == 1);
assert(type->GetArraySize() == 1); // TODO: support array of pointers, maybe?
DeSerializePointer(type, value, obj, context);
if(qtype.GetArraySize() == 1 && type->GetArraySize() == 1) {
DeSerializePointer(type, value, obj, context);
}
break;
case QualifierOperator::ARRAY: {
assert(qtype.GetArraySize() > 1);
QualifiedType elemQType = QualifiedType(type->GetTypeID(), QualifierOperator::VALUE, qtype.IsConst(), 1);
for (size_t index = 0; index < qtype.GetArraySize(); ++index) {
char* addr = (char*) obj + type->GetSize() * index;
Expand Down Expand Up @@ -360,7 +361,6 @@ namespace metacpp {
break;
}
case QualifierOperator::REFERENCE: {
assert(false);
break;
}
}
Expand Down
2 changes: 0 additions & 2 deletions MetaCPP/src/MetaCPP/QualifiedType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include "MetaCPP/Storage.hpp"
#include "MetaCPP/Type.hpp"

#include <cassert>

namespace metacpp {
QualifiedType::QualifiedType()
: m_Type(0), m_Operator(QualifierOperator::VALUE), m_Const(false), m_ArraySize(1) {
Expand Down

0 comments on commit 0258311

Please sign in to comment.