mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Add ZCG cpp domain classes
This commit is contained in:
parent
584492d1ef
commit
65cf1ef9c2
@ -1,3 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define STR(x) #x
|
#define STR(x) #x
|
||||||
|
|
||||||
|
#if defined(_MSVC_LANG)
|
||||||
|
#define _CPP_VERSION _MSVC_LANG
|
||||||
|
#elif defined(__cplusplus)
|
||||||
|
#define _CPP_VERSION __cplusplus
|
||||||
|
#else
|
||||||
|
#define _CPP_VERSION 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if _CPP_VERSION >= 201703L
|
||||||
|
#define _NO_DISCARD [[nodiscard]]
|
||||||
|
#else
|
||||||
|
#define _NO_DISCARD
|
||||||
|
#endif
|
@ -0,0 +1,6 @@
|
|||||||
|
#include "ArrayDeclarationModifier.h"
|
||||||
|
|
||||||
|
DeclarationModifierType ArrayDeclarationModifier::GetType()
|
||||||
|
{
|
||||||
|
return DeclarationModifierType::ARRAY;
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "DeclarationModifier.h"
|
||||||
|
#include "Domain/Evaluation/IEvaluation.h"
|
||||||
|
|
||||||
|
class ArrayDeclarationModifier final : public DeclarationModifier
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int m_size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief The array size is not actually given by \c m_size but instead is dynamic.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<IEvaluation> m_dynamic_size_evaluation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief The array has a size that is given by \c m_size but only a certain dynamic amount is handled by generated count.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<IEvaluation> m_dynamic_count_evaluation;
|
||||||
|
|
||||||
|
DeclarationModifierType GetType() override;
|
||||||
|
};
|
@ -0,0 +1,60 @@
|
|||||||
|
#include "BaseTypeDefinition.h"
|
||||||
|
|
||||||
|
BaseTypeDefinition::BaseTypeDefinition(std::string name, const unsigned size)
|
||||||
|
: DataDefinition("", std::move(name)),
|
||||||
|
m_size(size)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDefinitionType BaseTypeDefinition::GetType() const
|
||||||
|
{
|
||||||
|
return DataDefinitionType::BASE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned BaseTypeDefinition::GetAlignment() const
|
||||||
|
{
|
||||||
|
// Since this type has no members the alignment is always equal to the size.
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BaseTypeDefinition::GetForceAlignment() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned BaseTypeDefinition::GetSize() const
|
||||||
|
{
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::FLOAT = new BaseTypeDefinition("float", 4);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::DOUBLE = new BaseTypeDefinition("double", 8);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::BOOL = new BaseTypeDefinition("bool", 1);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::CHAR = new BaseTypeDefinition("char", 1);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::UNSIGNED_CHAR = new BaseTypeDefinition("unsigned char", 1);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::SHORT = new BaseTypeDefinition("short", 2);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::UNSIGNED_SHORT = new BaseTypeDefinition("unsigned short", 2);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::INT = new BaseTypeDefinition("int", 4);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::UNSIGNED_INT = new BaseTypeDefinition("unsigned int", 4);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::LONG = new BaseTypeDefinition("long", 4);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::UNSIGNED_LONG = new BaseTypeDefinition("unsigned long", 4);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::LONG_LONG = new BaseTypeDefinition("long long", 8);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::UNSIGNED_LONG_LONG = new BaseTypeDefinition("unsigned long long", 8);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::VOID = new BaseTypeDefinition("void", 0);
|
||||||
|
const BaseTypeDefinition* const BaseTypeDefinition::ALL_BASE_TYPES[]
|
||||||
|
{
|
||||||
|
FLOAT,
|
||||||
|
DOUBLE,
|
||||||
|
BOOL,
|
||||||
|
CHAR,
|
||||||
|
UNSIGNED_CHAR,
|
||||||
|
SHORT,
|
||||||
|
UNSIGNED_SHORT,
|
||||||
|
INT,
|
||||||
|
UNSIGNED_INT,
|
||||||
|
LONG,
|
||||||
|
UNSIGNED_LONG,
|
||||||
|
LONG_LONG,
|
||||||
|
UNSIGNED_LONG_LONG,
|
||||||
|
VOID
|
||||||
|
};
|
@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DataDefinition.h"
|
||||||
|
|
||||||
|
class BaseTypeDefinition final : public DataDefinition
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const unsigned m_size;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BaseTypeDefinition(std::string name, unsigned size);
|
||||||
|
|
||||||
|
public:
|
||||||
|
_NODISCARD DataDefinitionType GetType() const override;
|
||||||
|
_NODISCARD unsigned GetAlignment() const override;
|
||||||
|
_NODISCARD bool GetForceAlignment() const override;
|
||||||
|
_NODISCARD unsigned GetSize() const override;
|
||||||
|
|
||||||
|
static const BaseTypeDefinition* const FLOAT;
|
||||||
|
static const BaseTypeDefinition* const DOUBLE;
|
||||||
|
static const BaseTypeDefinition* const BOOL;
|
||||||
|
static const BaseTypeDefinition* const CHAR;
|
||||||
|
static const BaseTypeDefinition* const UNSIGNED_CHAR;
|
||||||
|
static const BaseTypeDefinition* const SHORT;
|
||||||
|
static const BaseTypeDefinition* const UNSIGNED_SHORT;
|
||||||
|
static const BaseTypeDefinition* const INT;
|
||||||
|
static const BaseTypeDefinition* const UNSIGNED_INT;
|
||||||
|
static const BaseTypeDefinition* const LONG;
|
||||||
|
static const BaseTypeDefinition* const UNSIGNED_LONG;
|
||||||
|
static const BaseTypeDefinition* const LONG_LONG;
|
||||||
|
static const BaseTypeDefinition* const UNSIGNED_LONG_LONG;
|
||||||
|
static const BaseTypeDefinition* const VOID;
|
||||||
|
|
||||||
|
static const BaseTypeDefinition* const ALL_BASE_TYPES[];
|
||||||
|
};
|
@ -0,0 +1,20 @@
|
|||||||
|
#include "DataDefinition.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
DataDefinition::DataDefinition(std::string _namespace, std::string name)
|
||||||
|
: m_namespace(std::move(_namespace)),
|
||||||
|
m_name(std::move(name))
|
||||||
|
{
|
||||||
|
assert(!m_name.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DataDefinition::GetFullName() const
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << m_namespace << "::" << m_name;
|
||||||
|
|
||||||
|
return str.str();
|
||||||
|
}
|
37
src/ZoneCodeGeneratorNew/Domain/Definition/DataDefinition.h
Normal file
37
src/ZoneCodeGeneratorNew/Domain/Definition/DataDefinition.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
|
|
||||||
|
enum class DataDefinitionType
|
||||||
|
{
|
||||||
|
STRUCT,
|
||||||
|
UNION,
|
||||||
|
ENUM,
|
||||||
|
TYPEDEF,
|
||||||
|
BASE_TYPE,
|
||||||
|
FORWARD_DECLARATION
|
||||||
|
};
|
||||||
|
|
||||||
|
class DataDefinition
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataDefinition() = default;
|
||||||
|
DataDefinition(std::string _namespace, std::string name);
|
||||||
|
|
||||||
|
virtual ~DataDefinition() = default;
|
||||||
|
DataDefinition(const DataDefinition& other) = default;
|
||||||
|
DataDefinition(DataDefinition&& other) noexcept = default;
|
||||||
|
DataDefinition& operator=(const DataDefinition& other) = default;
|
||||||
|
DataDefinition& operator=(DataDefinition&& other) noexcept = default;
|
||||||
|
|
||||||
|
std::string m_namespace;
|
||||||
|
std::string m_name;
|
||||||
|
|
||||||
|
_NO_DISCARD virtual DataDefinitionType GetType() const = 0;
|
||||||
|
_NO_DISCARD virtual unsigned GetAlignment() = 0;
|
||||||
|
_NO_DISCARD virtual bool GetForceAlignment() = 0;
|
||||||
|
_NO_DISCARD virtual unsigned GetSize() = 0;
|
||||||
|
|
||||||
|
_NO_DISCARD std::string GetFullName() const;
|
||||||
|
};
|
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum class DeclarationModifierType
|
||||||
|
{
|
||||||
|
POINTER,
|
||||||
|
ARRAY
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeclarationModifier
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DeclarationModifier() = default;
|
||||||
|
virtual ~DeclarationModifier() = default;
|
||||||
|
|
||||||
|
virtual DeclarationModifierType GetType() = 0;
|
||||||
|
};
|
@ -0,0 +1,57 @@
|
|||||||
|
#include "DefinitionWithMembers.h"
|
||||||
|
|
||||||
|
DefinitionWithMembers::DefinitionWithMembers(std::string _namespace, std::string name, const unsigned pack)
|
||||||
|
: DataDefinition(std::move(_namespace), std::move(name)),
|
||||||
|
m_flags(0),
|
||||||
|
m_size(0),
|
||||||
|
m_alignment(0),
|
||||||
|
m_has_alignment_override(false),
|
||||||
|
m_anonymous(false),
|
||||||
|
m_pack(pack),
|
||||||
|
m_alignment_override(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DefinitionWithMembers::CalculateAlignment()
|
||||||
|
{
|
||||||
|
if (m_has_alignment_override)
|
||||||
|
{
|
||||||
|
m_flags |= FLAG_ALIGNMENT_FORCED;
|
||||||
|
m_alignment = m_alignment_override;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_alignment = 0;
|
||||||
|
for (const auto& member : m_members)
|
||||||
|
{
|
||||||
|
const auto memberAlignment = member->GetAlignment();
|
||||||
|
if (memberAlignment > m_alignment)
|
||||||
|
m_alignment = memberAlignment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_flags |= FLAG_ALIGNMENT_CALCULATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned DefinitionWithMembers::GetAlignment()
|
||||||
|
{
|
||||||
|
if ((m_flags & FLAG_ALIGNMENT_CALCULATED) == 0)
|
||||||
|
CalculateAlignment();
|
||||||
|
|
||||||
|
return m_alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DefinitionWithMembers::GetForceAlignment()
|
||||||
|
{
|
||||||
|
if ((m_flags & FLAG_ALIGNMENT_CALCULATED) == 0)
|
||||||
|
CalculateAlignment();
|
||||||
|
|
||||||
|
return m_flags & FLAG_ALIGNMENT_FORCED;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned DefinitionWithMembers::GetSize()
|
||||||
|
{
|
||||||
|
if ((m_flags & FLAG_SIZE_CALCULATED) == 0)
|
||||||
|
CalculateSize();
|
||||||
|
|
||||||
|
return m_size;
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "DataDefinition.h"
|
||||||
|
#include "Variable.h"
|
||||||
|
|
||||||
|
class DefinitionWithMembers : public DataDefinition
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
static constexpr int FLAG_SIZE_CALCULATED = 1 << 0;
|
||||||
|
static constexpr int FLAG_ALIGNMENT_CALCULATED = 1 << 1;
|
||||||
|
static constexpr int FLAG_ALIGNMENT_FORCED = 1 << 2;
|
||||||
|
|
||||||
|
unsigned m_flags;
|
||||||
|
unsigned m_size;
|
||||||
|
unsigned m_alignment;
|
||||||
|
|
||||||
|
virtual void CalculateSize() = 0;
|
||||||
|
void CalculateAlignment();
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool m_has_alignment_override;
|
||||||
|
bool m_anonymous;
|
||||||
|
|
||||||
|
const unsigned m_pack;
|
||||||
|
unsigned m_alignment_override;
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<Variable>> m_members;
|
||||||
|
|
||||||
|
DefinitionWithMembers(std::string _namespace, std::string name, unsigned pack);
|
||||||
|
|
||||||
|
_NODISCARD unsigned GetAlignment() override;
|
||||||
|
_NODISCARD bool GetForceAlignment() override;
|
||||||
|
_NODISCARD unsigned GetSize() override;
|
||||||
|
};
|
@ -0,0 +1,35 @@
|
|||||||
|
#include "EnumDefinition.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
EnumDefinition::EnumDefinition(std::string _namespace, std::string name, const BaseTypeDefinition* parentType)
|
||||||
|
: DataDefinition(std::move(_namespace), std::move(name)),
|
||||||
|
m_parent_type(parentType)
|
||||||
|
{
|
||||||
|
assert(parentType != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDefinitionType EnumDefinition::GetType() const
|
||||||
|
{
|
||||||
|
return DataDefinitionType::ENUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned EnumDefinition::GetAlignment() const
|
||||||
|
{
|
||||||
|
return m_parent_type->GetAlignment();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EnumDefinition::GetForceAlignment() const
|
||||||
|
{
|
||||||
|
return m_parent_type->GetForceAlignment();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned EnumDefinition::GetSize() const
|
||||||
|
{
|
||||||
|
return m_parent_type->GetSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnumDefinition::AddEnumMember(EnumMember enumMember)
|
||||||
|
{
|
||||||
|
m_members.emplace_back(std::make_unique<EnumMember>(std::move(enumMember)));
|
||||||
|
}
|
24
src/ZoneCodeGeneratorNew/Domain/Definition/EnumDefinition.h
Normal file
24
src/ZoneCodeGeneratorNew/Domain/Definition/EnumDefinition.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "BaseTypeDefinition.h"
|
||||||
|
#include "DataDefinition.h"
|
||||||
|
#include "EnumMember.h"
|
||||||
|
|
||||||
|
class EnumDefinition final : public DataDefinition
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const BaseTypeDefinition* m_parent_type;
|
||||||
|
std::vector<std::unique_ptr<EnumMember>> m_members;
|
||||||
|
|
||||||
|
EnumDefinition(std::string _namespace, std::string name, const BaseTypeDefinition* parentType);
|
||||||
|
|
||||||
|
_NODISCARD DataDefinitionType GetType() const override;
|
||||||
|
_NODISCARD unsigned GetAlignment() const override;
|
||||||
|
_NODISCARD bool GetForceAlignment() const override;
|
||||||
|
_NODISCARD unsigned GetSize() const override;
|
||||||
|
|
||||||
|
void AddEnumMember(EnumMember enumMember);
|
||||||
|
};
|
12
src/ZoneCodeGeneratorNew/Domain/Definition/EnumMember.cpp
Normal file
12
src/ZoneCodeGeneratorNew/Domain/Definition/EnumMember.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "EnumMember.h"
|
||||||
|
|
||||||
|
EnumMember::EnumMember()
|
||||||
|
: m_value(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EnumMember::EnumMember(std::string name, const long long value)
|
||||||
|
: m_name(std::move(name)),
|
||||||
|
m_value(value)
|
||||||
|
{
|
||||||
|
}
|
13
src/ZoneCodeGeneratorNew/Domain/Definition/EnumMember.h
Normal file
13
src/ZoneCodeGeneratorNew/Domain/Definition/EnumMember.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class EnumMember
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string m_name;
|
||||||
|
long long m_value;
|
||||||
|
|
||||||
|
EnumMember();
|
||||||
|
EnumMember(std::string name, long long value);
|
||||||
|
};
|
@ -0,0 +1,28 @@
|
|||||||
|
#include "ForwardDeclaration.h"
|
||||||
|
|
||||||
|
ForwardDeclaration::ForwardDeclaration(std::string _namespace, std::string name, DataDefinitionType type)
|
||||||
|
: DataDefinition(std::move(_namespace), std::move(name)),
|
||||||
|
m_forwarded_type(type),
|
||||||
|
m_definition(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDefinitionType ForwardDeclaration::GetType() const
|
||||||
|
{
|
||||||
|
return DataDefinitionType::FORWARD_DECLARATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned ForwardDeclaration::GetAlignment() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ForwardDeclaration::GetForceAlignment() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned ForwardDeclaration::GetSize() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "DataDefinition.h"
|
||||||
|
|
||||||
|
class ForwardDeclaration final : public DataDefinition
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const DataDefinitionType m_forwarded_type;
|
||||||
|
DataDefinition* m_definition;
|
||||||
|
|
||||||
|
ForwardDeclaration(std::string _namespace, std::string name, DataDefinitionType type);
|
||||||
|
|
||||||
|
_NODISCARD DataDefinitionType GetType() const override;
|
||||||
|
_NODISCARD unsigned GetAlignment() const override;
|
||||||
|
_NODISCARD bool GetForceAlignment() const override;
|
||||||
|
_NODISCARD unsigned GetSize() const override;
|
||||||
|
};
|
@ -0,0 +1,6 @@
|
|||||||
|
#include "PointerDeclarationModifier.h"
|
||||||
|
|
||||||
|
DeclarationModifierType PointerDeclarationModifier::GetType()
|
||||||
|
{
|
||||||
|
return DeclarationModifierType::POINTER;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeclarationModifier.h"
|
||||||
|
|
||||||
|
class PointerDeclarationModifier final : public DeclarationModifier
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DeclarationModifierType GetType() override;
|
||||||
|
};
|
@ -0,0 +1,49 @@
|
|||||||
|
#include "StructDefinition.h"
|
||||||
|
|
||||||
|
#include "Utils/AlignmentUtils.h"
|
||||||
|
|
||||||
|
void StructDefinition::CalculateSize()
|
||||||
|
{
|
||||||
|
m_size = 0;
|
||||||
|
auto currentBitOffset = 0u;
|
||||||
|
|
||||||
|
for(const auto& member : m_members)
|
||||||
|
{
|
||||||
|
if(member->m_type_declaration->m_has_custom_bit_size)
|
||||||
|
{
|
||||||
|
currentBitOffset += member->m_type_declaration->m_custom_bit_size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (currentBitOffset > 0)
|
||||||
|
{
|
||||||
|
currentBitOffset = AlignmentUtils::Align(currentBitOffset, 8u);
|
||||||
|
m_size += currentBitOffset / 8;
|
||||||
|
currentBitOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_size = AlignmentUtils::Align(m_size, member->GetForceAlignment() ? member->GetAlignment() : std::min(member->GetAlignment(), m_pack));
|
||||||
|
m_size += member->m_type_declaration->GetSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentBitOffset > 0)
|
||||||
|
{
|
||||||
|
currentBitOffset = AlignmentUtils::Align(currentBitOffset, 8u);
|
||||||
|
m_size += currentBitOffset / 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_size = AlignmentUtils::Align(m_size, GetAlignment());
|
||||||
|
|
||||||
|
m_flags |= FLAG_SIZE_CALCULATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
StructDefinition::StructDefinition(std::string _namespace, std::string name, const int pack)
|
||||||
|
: DefinitionWithMembers(std::move(_namespace), std::move(name), pack)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDefinitionType StructDefinition::GetType() const
|
||||||
|
{
|
||||||
|
return DataDefinitionType::STRUCT;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "DefinitionWithMembers.h"
|
||||||
|
|
||||||
|
class StructDefinition final : public DefinitionWithMembers
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
void CalculateSize() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
StructDefinition(std::string _namespace, std::string name, int pack);
|
||||||
|
|
||||||
|
_NODISCARD DataDefinitionType GetType() const override;
|
||||||
|
};
|
@ -0,0 +1,90 @@
|
|||||||
|
#include "TypeDeclaration.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "ArrayDeclarationModifier.h"
|
||||||
|
|
||||||
|
TypeDeclaration::TypeDeclaration(DataDefinition* type)
|
||||||
|
: m_flags(0),
|
||||||
|
m_size(0),
|
||||||
|
m_alignment(0),
|
||||||
|
m_is_const(false),
|
||||||
|
m_has_custom_bit_size(false),
|
||||||
|
m_type(type),
|
||||||
|
m_custom_bit_size(0)
|
||||||
|
{
|
||||||
|
assert(m_type != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TypeDeclaration::CalculateSize()
|
||||||
|
{
|
||||||
|
auto currentSize = m_type->GetSize();
|
||||||
|
|
||||||
|
for(auto i = m_declaration_modifiers.size(); i > 0; i--)
|
||||||
|
{
|
||||||
|
const auto& declarationModifier = m_declaration_modifiers[i - 1];
|
||||||
|
|
||||||
|
switch(declarationModifier->GetType())
|
||||||
|
{
|
||||||
|
case DeclarationModifierType::POINTER:
|
||||||
|
currentSize = POINTER_SIZE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DeclarationModifierType::ARRAY:
|
||||||
|
currentSize *= dynamic_cast<ArrayDeclarationModifier*>(declarationModifier.get())->m_size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_flags |= FLAG_SIZE_CALCULATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TypeDeclaration::CalculateAlignment()
|
||||||
|
{
|
||||||
|
auto hasPointerModifier = false;
|
||||||
|
for (const auto& declarationModifier : m_declaration_modifiers)
|
||||||
|
{
|
||||||
|
if (declarationModifier->GetType() == DeclarationModifierType::POINTER)
|
||||||
|
{
|
||||||
|
hasPointerModifier = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasPointerModifier)
|
||||||
|
{
|
||||||
|
m_alignment = POINTER_SIZE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_alignment = m_type->GetAlignment();
|
||||||
|
if (m_type->GetForceAlignment())
|
||||||
|
m_flags |= FLAG_ALIGNMENT_FORCED;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_flags |= FLAG_ALIGNMENT_CALCULATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned TypeDeclaration::GetSize()
|
||||||
|
{
|
||||||
|
if ((m_flags & FLAG_SIZE_CALCULATED) == 0)
|
||||||
|
CalculateSize();
|
||||||
|
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned TypeDeclaration::GetAlignment()
|
||||||
|
{
|
||||||
|
if ((m_flags & FLAG_ALIGNMENT_CALCULATED) == 0)
|
||||||
|
CalculateAlignment();
|
||||||
|
|
||||||
|
return m_alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TypeDeclaration::GetForceAlignment()
|
||||||
|
{
|
||||||
|
if ((m_flags & FLAG_ALIGNMENT_CALCULATED) == 0)
|
||||||
|
CalculateAlignment();
|
||||||
|
|
||||||
|
return m_flags & FLAG_ALIGNMENT_FORCED;
|
||||||
|
}
|
37
src/ZoneCodeGeneratorNew/Domain/Definition/TypeDeclaration.h
Normal file
37
src/ZoneCodeGeneratorNew/Domain/Definition/TypeDeclaration.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "DataDefinition.h"
|
||||||
|
#include "DeclarationModifier.h"
|
||||||
|
|
||||||
|
class TypeDeclaration
|
||||||
|
{
|
||||||
|
static constexpr unsigned POINTER_SIZE = sizeof(uint32_t); // TODO: Change this to support 64bit
|
||||||
|
static constexpr int FLAG_SIZE_CALCULATED = 1 << 0;
|
||||||
|
static constexpr int FLAG_ALIGNMENT_CALCULATED = 1 << 1;
|
||||||
|
static constexpr int FLAG_ALIGNMENT_FORCED = 1 << 2;
|
||||||
|
|
||||||
|
unsigned m_flags;
|
||||||
|
unsigned m_size;
|
||||||
|
unsigned m_alignment;
|
||||||
|
|
||||||
|
void CalculateSize();
|
||||||
|
void CalculateAlignment();
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TypeDeclaration(DataDefinition* type);
|
||||||
|
|
||||||
|
bool m_is_const;
|
||||||
|
bool m_has_custom_bit_size;
|
||||||
|
|
||||||
|
DataDefinition* m_type;
|
||||||
|
unsigned m_custom_bit_size;
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<DeclarationModifier>> m_declaration_modifiers;
|
||||||
|
|
||||||
|
unsigned GetSize();
|
||||||
|
unsigned GetAlignment();
|
||||||
|
bool GetForceAlignment();
|
||||||
|
};
|
@ -0,0 +1,33 @@
|
|||||||
|
#include "TypedefDefinition.h"
|
||||||
|
|
||||||
|
TypedefDefinition::TypedefDefinition(std::string _namespace, std::string name, std::unique_ptr<TypeDeclaration> typeDeclaration)
|
||||||
|
: DataDefinition(std::move(_namespace), std::move(name)),
|
||||||
|
m_has_alignment_override(false),
|
||||||
|
m_alignment_override(0),
|
||||||
|
m_type_declaration(std::move(typeDeclaration))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDefinitionType TypedefDefinition::GetType() const
|
||||||
|
{
|
||||||
|
return DataDefinitionType::TYPEDEF;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned TypedefDefinition::GetAlignment()
|
||||||
|
{
|
||||||
|
if (m_has_alignment_override)
|
||||||
|
{
|
||||||
|
return m_alignment_override;
|
||||||
|
}
|
||||||
|
return m_type_declaration->GetAlignment();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TypedefDefinition::GetForceAlignment()
|
||||||
|
{
|
||||||
|
return m_has_alignment_override || m_type_declaration->GetForceAlignment();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned TypedefDefinition::GetSize()
|
||||||
|
{
|
||||||
|
return m_type_declaration->GetSize();
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "DataDefinition.h"
|
||||||
|
#include "TypeDeclaration.h"
|
||||||
|
|
||||||
|
class TypedefDefinition final : public DataDefinition
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool m_has_alignment_override;
|
||||||
|
unsigned m_alignment_override;
|
||||||
|
std::unique_ptr<TypeDeclaration> m_type_declaration;
|
||||||
|
|
||||||
|
TypedefDefinition(std::string _namespace, std::string name, std::unique_ptr<TypeDeclaration> typeDeclaration);
|
||||||
|
|
||||||
|
_NODISCARD DataDefinitionType GetType() const override;
|
||||||
|
_NODISCARD unsigned GetAlignment() override;
|
||||||
|
_NODISCARD bool GetForceAlignment() override;
|
||||||
|
_NODISCARD unsigned GetSize() override;
|
||||||
|
};
|
@ -0,0 +1,29 @@
|
|||||||
|
#include "UnionDefinition.h"
|
||||||
|
|
||||||
|
#include "Utils/AlignmentUtils.h"
|
||||||
|
|
||||||
|
void UnionDefinition::CalculateSize()
|
||||||
|
{
|
||||||
|
m_size = 0;
|
||||||
|
|
||||||
|
for(const auto& member : m_members)
|
||||||
|
{
|
||||||
|
const auto memberSize = member->m_type_declaration->GetSize();
|
||||||
|
if (memberSize > m_size)
|
||||||
|
m_size = memberSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_size = AlignmentUtils::Align(m_size, GetAlignment());
|
||||||
|
|
||||||
|
m_flags |= FLAG_SIZE_CALCULATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnionDefinition::UnionDefinition(std::string _namespace, std::string name, const int pack)
|
||||||
|
: DefinitionWithMembers(std::move(_namespace), std::move(name), pack)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDefinitionType UnionDefinition::GetType() const
|
||||||
|
{
|
||||||
|
return DataDefinitionType::UNION;
|
||||||
|
}
|
14
src/ZoneCodeGeneratorNew/Domain/Definition/UnionDefinition.h
Normal file
14
src/ZoneCodeGeneratorNew/Domain/Definition/UnionDefinition.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "DefinitionWithMembers.h"
|
||||||
|
|
||||||
|
class UnionDefinition final : public DefinitionWithMembers
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
void CalculateSize() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UnionDefinition(std::string _namespace, std::string name, int pack);
|
||||||
|
|
||||||
|
_NODISCARD DataDefinitionType GetType() const override;
|
||||||
|
};
|
14
src/ZoneCodeGeneratorNew/Domain/Definition/Variable.cpp
Normal file
14
src/ZoneCodeGeneratorNew/Domain/Definition/Variable.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "Variable.h"
|
||||||
|
|
||||||
|
unsigned Variable::GetAlignment()
|
||||||
|
{
|
||||||
|
if (m_has_alignment_override)
|
||||||
|
return m_alignment_override;
|
||||||
|
|
||||||
|
return m_type_declaration->GetAlignment();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Variable::GetForceAlignment()
|
||||||
|
{
|
||||||
|
return m_has_alignment_override || m_type_declaration->GetForceAlignment();
|
||||||
|
}
|
18
src/ZoneCodeGeneratorNew/Domain/Definition/Variable.h
Normal file
18
src/ZoneCodeGeneratorNew/Domain/Definition/Variable.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "TypeDeclaration.h"
|
||||||
|
|
||||||
|
class Variable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string m_name;
|
||||||
|
bool m_has_alignment_override;
|
||||||
|
unsigned m_alignment_override;
|
||||||
|
std::unique_ptr<TypeDeclaration> m_type_declaration;
|
||||||
|
|
||||||
|
unsigned GetAlignment();
|
||||||
|
bool GetForceAlignment();
|
||||||
|
};
|
24
src/ZoneCodeGeneratorNew/Domain/Evaluation/IEvaluation.h
Normal file
24
src/ZoneCodeGeneratorNew/Domain/Evaluation/IEvaluation.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum class EvaluationType
|
||||||
|
{
|
||||||
|
OPERAND_DYNAMIC,
|
||||||
|
OPERAND_STATIC,
|
||||||
|
OPERATION
|
||||||
|
};
|
||||||
|
|
||||||
|
class IEvaluation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IEvaluation() = default;
|
||||||
|
virtual ~IEvaluation() = default;
|
||||||
|
|
||||||
|
IEvaluation(const IEvaluation& other) = default;
|
||||||
|
IEvaluation(IEvaluation&& other) noexcept = default;
|
||||||
|
IEvaluation& operator=(const IEvaluation& other) = default;
|
||||||
|
IEvaluation& operator=(IEvaluation&& other) noexcept = default;
|
||||||
|
|
||||||
|
virtual EvaluationType GetType() = 0;
|
||||||
|
virtual bool IsStatic() = 0;
|
||||||
|
virtual int EvaluateNumeric() = 0;
|
||||||
|
};
|
@ -0,0 +1,24 @@
|
|||||||
|
#include "OperandDynamic.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
OperandDynamic::OperandDynamic(StructureInformation* structure)
|
||||||
|
: m_structure(structure)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EvaluationType OperandDynamic::GetType()
|
||||||
|
{
|
||||||
|
return EvaluationType::OPERAND_DYNAMIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OperandDynamic::IsStatic()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int OperandDynamic::EvaluateNumeric()
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
return 0;
|
||||||
|
}
|
21
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperandDynamic.h
Normal file
21
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperandDynamic.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "IEvaluation.h"
|
||||||
|
#include "Domain/Information/MemberInformation.h"
|
||||||
|
#include "Domain/Information/StructureInformation.h"
|
||||||
|
|
||||||
|
class OperandDynamic final : public IEvaluation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StructureInformation* const m_structure;
|
||||||
|
std::vector<MemberInformation*> m_referenced_member_chain;
|
||||||
|
std::vector<std::unique_ptr<IEvaluation>> m_array_indices;
|
||||||
|
|
||||||
|
explicit OperandDynamic(StructureInformation* structure);
|
||||||
|
|
||||||
|
EvaluationType GetType() override;
|
||||||
|
bool IsStatic() override;
|
||||||
|
int EvaluateNumeric() override;
|
||||||
|
};
|
28
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperandStatic.cpp
Normal file
28
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperandStatic.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "OperandStatic.h"
|
||||||
|
|
||||||
|
OperandStatic::OperandStatic(const int value)
|
||||||
|
: m_value(value),
|
||||||
|
m_enum_member(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
OperandStatic::OperandStatic(const int value, EnumMember* enumMember)
|
||||||
|
: m_value(value),
|
||||||
|
m_enum_member(enumMember)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EvaluationType OperandStatic::GetType()
|
||||||
|
{
|
||||||
|
return EvaluationType::OPERAND_STATIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OperandStatic::IsStatic()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int OperandStatic::EvaluateNumeric()
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
18
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperandStatic.h
Normal file
18
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperandStatic.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IEvaluation.h"
|
||||||
|
#include "Domain/Definition/EnumMember.h"
|
||||||
|
|
||||||
|
class OperandStatic final : public IEvaluation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const int m_value;
|
||||||
|
EnumMember* const m_enum_member;
|
||||||
|
|
||||||
|
explicit OperandStatic(int value);
|
||||||
|
OperandStatic(int value, EnumMember* enumMember);
|
||||||
|
|
||||||
|
EvaluationType GetType() override;
|
||||||
|
bool IsStatic() override;
|
||||||
|
int EvaluateNumeric() override;
|
||||||
|
};
|
33
src/ZoneCodeGeneratorNew/Domain/Evaluation/Operation.cpp
Normal file
33
src/ZoneCodeGeneratorNew/Domain/Evaluation/Operation.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "Operation.h"
|
||||||
|
|
||||||
|
Operation::Operation(const OperationType* type)
|
||||||
|
: m_operation_type(type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
EvaluationType Operation::GetType()
|
||||||
|
{
|
||||||
|
return EvaluationType::OPERATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Operation::IsStatic()
|
||||||
|
{
|
||||||
|
return m_operand1->IsStatic() && m_operand2->IsStatic();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Operation::EvaluateNumeric()
|
||||||
|
{
|
||||||
|
return m_operation_type->m_evaluation_function(m_operand1->EvaluateNumeric(), m_operand2->EvaluateNumeric());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Operation::Operand1NeedsParenthesis() const
|
||||||
|
{
|
||||||
|
return m_operand1->GetType() == EvaluationType::OPERATION
|
||||||
|
&& dynamic_cast<Operation*>(m_operand1.get())->m_operation_type->m_precedence > m_operation_type->m_precedence;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Operation::Operand2NeedsParenthesis() const
|
||||||
|
{
|
||||||
|
return m_operand2->GetType() == EvaluationType::OPERATION
|
||||||
|
&& dynamic_cast<Operation*>(m_operand2.get())->m_operation_type->m_precedence > m_operation_type->m_precedence;
|
||||||
|
}
|
24
src/ZoneCodeGeneratorNew/Domain/Evaluation/Operation.h
Normal file
24
src/ZoneCodeGeneratorNew/Domain/Evaluation/Operation.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
|
#include "IEvaluation.h"
|
||||||
|
#include "OperationType.h"
|
||||||
|
|
||||||
|
class Operation final : public IEvaluation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const OperationType* const m_operation_type;
|
||||||
|
std::unique_ptr<IEvaluation> m_operand1;
|
||||||
|
std::unique_ptr<IEvaluation> m_operand2;
|
||||||
|
|
||||||
|
explicit Operation(const OperationType* type);
|
||||||
|
|
||||||
|
EvaluationType GetType() override;
|
||||||
|
bool IsStatic() override;
|
||||||
|
int EvaluateNumeric() override;
|
||||||
|
|
||||||
|
_NODISCARD bool Operand1NeedsParenthesis() const;
|
||||||
|
_NODISCARD bool Operand2NeedsParenthesis() const;
|
||||||
|
};
|
139
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperationType.cpp
Normal file
139
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperationType.cpp
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
#include "OperationType.h"
|
||||||
|
|
||||||
|
OperationType::OperationType(std::string syntax, const OperationPrecedence precedence, std::function<int(int, int)> evaluationFunction)
|
||||||
|
: m_syntax(std::move(syntax)),
|
||||||
|
m_precedence(precedence),
|
||||||
|
m_evaluation_function(std::move(evaluationFunction))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_ADD
|
||||||
|
= new OperationType("+", OperationPrecedence::ADDITION_SUBTRACTION, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 + op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_SUBTRACT
|
||||||
|
= new OperationType("-", OperationPrecedence::ADDITION_SUBTRACTION, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 - op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_MULTIPLY
|
||||||
|
= new OperationType("*", OperationPrecedence::MULTIPLICATION_DIVISION_REMAINDER, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 * op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_DIVIDE
|
||||||
|
= new OperationType("/", OperationPrecedence::MULTIPLICATION_DIVISION_REMAINDER, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 / op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_REMAINDER
|
||||||
|
= new OperationType("%", OperationPrecedence::MULTIPLICATION_DIVISION_REMAINDER, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 % op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_BITWISE_AND
|
||||||
|
= new OperationType("&", OperationPrecedence::BITWISE_AND, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 & op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_BITWISE_XOR
|
||||||
|
= new OperationType("^", OperationPrecedence::BITWISE_XOR, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 ^ op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_BITWISE_OR
|
||||||
|
= new OperationType("|", OperationPrecedence::BITWISE_OR, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 | op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_SHIFT_LEFT
|
||||||
|
= new OperationType("<<", OperationPrecedence::BITWISE_SHIFT, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 << op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_SHIFT_RIGHT
|
||||||
|
= new OperationType(">>", OperationPrecedence::BITWISE_SHIFT, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 >> op2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_GREATER_THAN
|
||||||
|
= new OperationType(">", OperationPrecedence::RELATIONAL_GREATER_LESS_THAN, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 > op2 ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_GREATER_EQUALS_THAN
|
||||||
|
= new OperationType(">=", OperationPrecedence::RELATIONAL_GREATER_LESS_THAN, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 >= op2 ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_LESS_THAN
|
||||||
|
= new OperationType("<", OperationPrecedence::RELATIONAL_GREATER_LESS_THAN, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 < op2 ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_LESS_EQUALS_THAN
|
||||||
|
= new OperationType("<=", OperationPrecedence::RELATIONAL_GREATER_LESS_THAN, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 <= op2 ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_EQUALS
|
||||||
|
= new OperationType("==", OperationPrecedence::RELATIONAL_EQUALS, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 == op2 ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_NOT_EQUALS
|
||||||
|
= new OperationType("!=", OperationPrecedence::RELATIONAL_EQUALS, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 != op2 ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_AND
|
||||||
|
= new OperationType("&&", OperationPrecedence::LOGICAL_AND, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 > 0 && op2 > 0 ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const OperationType* const OperationType::OPERATION_OR
|
||||||
|
= new OperationType("||", OperationPrecedence::LOGICAL_OR, [](auto op1, auto op2)
|
||||||
|
{
|
||||||
|
return op1 > 0 || op2 > 0 ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const OperationType* const OperationType::ALL_OPERATION_TYPES[]
|
||||||
|
{
|
||||||
|
OPERATION_ADD,
|
||||||
|
OPERATION_SUBTRACT,
|
||||||
|
OPERATION_MULTIPLY,
|
||||||
|
OPERATION_DIVIDE,
|
||||||
|
OPERATION_REMAINDER,
|
||||||
|
OPERATION_BITWISE_AND,
|
||||||
|
OPERATION_BITWISE_XOR,
|
||||||
|
OPERATION_BITWISE_OR,
|
||||||
|
OPERATION_SHIFT_LEFT,
|
||||||
|
OPERATION_SHIFT_RIGHT,
|
||||||
|
OPERATION_GREATER_THAN,
|
||||||
|
OPERATION_GREATER_EQUALS_THAN,
|
||||||
|
OPERATION_LESS_THAN,
|
||||||
|
OPERATION_LESS_EQUALS_THAN,
|
||||||
|
OPERATION_EQUALS,
|
||||||
|
OPERATION_NOT_EQUALS,
|
||||||
|
OPERATION_AND,
|
||||||
|
OPERATION_OR
|
||||||
|
};
|
52
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperationType.h
Normal file
52
src/ZoneCodeGeneratorNew/Domain/Evaluation/OperationType.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// https://en.cppreference.com/w/cpp/language/operator_precedence
|
||||||
|
enum class OperationPrecedence
|
||||||
|
{
|
||||||
|
MULTIPLICATION_DIVISION_REMAINDER = 1,
|
||||||
|
ADDITION_SUBTRACTION = 2,
|
||||||
|
BITWISE_SHIFT = 3,
|
||||||
|
RELATIONAL_GREATER_LESS_THAN = 4,
|
||||||
|
RELATIONAL_EQUALS = 5,
|
||||||
|
BITWISE_AND = 6,
|
||||||
|
BITWISE_XOR = 7,
|
||||||
|
BITWISE_OR = 8,
|
||||||
|
LOGICAL_AND = 9,
|
||||||
|
LOGICAL_OR = 10
|
||||||
|
};
|
||||||
|
|
||||||
|
class OperationType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string m_syntax;
|
||||||
|
OperationPrecedence m_precedence;
|
||||||
|
std::function<int(int operand1, int operand2)> m_evaluation_function;
|
||||||
|
|
||||||
|
private:
|
||||||
|
OperationType(std::string syntax, OperationPrecedence precedence, std::function<int(int, int)> evaluationFunction);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static const OperationType* const OPERATION_ADD;
|
||||||
|
static const OperationType* const OPERATION_SUBTRACT;
|
||||||
|
static const OperationType* const OPERATION_MULTIPLY;
|
||||||
|
static const OperationType* const OPERATION_DIVIDE;
|
||||||
|
static const OperationType* const OPERATION_REMAINDER;
|
||||||
|
static const OperationType* const OPERATION_BITWISE_AND;
|
||||||
|
static const OperationType* const OPERATION_BITWISE_XOR;
|
||||||
|
static const OperationType* const OPERATION_BITWISE_OR;
|
||||||
|
static const OperationType* const OPERATION_SHIFT_LEFT;
|
||||||
|
static const OperationType* const OPERATION_SHIFT_RIGHT;
|
||||||
|
static const OperationType* const OPERATION_GREATER_THAN;
|
||||||
|
static const OperationType* const OPERATION_GREATER_EQUALS_THAN;
|
||||||
|
static const OperationType* const OPERATION_LESS_THAN;
|
||||||
|
static const OperationType* const OPERATION_LESS_EQUALS_THAN;
|
||||||
|
static const OperationType* const OPERATION_EQUALS;
|
||||||
|
static const OperationType* const OPERATION_NOT_EQUALS;
|
||||||
|
static const OperationType* const OPERATION_AND;
|
||||||
|
static const OperationType* const OPERATION_OR;
|
||||||
|
|
||||||
|
static const OperationType* const ALL_OPERATION_TYPES[];
|
||||||
|
};
|
@ -0,0 +1,9 @@
|
|||||||
|
#include "FastFileBlock.h"
|
||||||
|
|
||||||
|
FastFileBlock::FastFileBlock(std::string name, const unsigned index, const FastFileBlockType type, const bool isDefault)
|
||||||
|
: m_name(std::move(name)),
|
||||||
|
m_index(index),
|
||||||
|
m_type(type),
|
||||||
|
m_is_default(isDefault)
|
||||||
|
{
|
||||||
|
}
|
22
src/ZoneCodeGeneratorNew/Domain/FastFile/FastFileBlock.h
Normal file
22
src/ZoneCodeGeneratorNew/Domain/FastFile/FastFileBlock.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
enum class FastFileBlockType
|
||||||
|
{
|
||||||
|
TEMP,
|
||||||
|
RUNTIME,
|
||||||
|
DELAY,
|
||||||
|
NORMAL
|
||||||
|
};
|
||||||
|
|
||||||
|
class FastFileBlock
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string m_name;
|
||||||
|
unsigned m_index;
|
||||||
|
FastFileBlockType m_type;
|
||||||
|
bool m_is_default;
|
||||||
|
|
||||||
|
FastFileBlock(std::string name, unsigned index, FastFileBlockType type, bool isDefault);
|
||||||
|
};
|
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class MemberInformation
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class StructureInformation
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
@ -1,7 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class IDataRepository
|
class IDataRepository
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IDataRepository() = default;
|
virtual ~IDataRepository() = default;
|
||||||
};
|
|
||||||
|
/*
|
||||||
|
* IEnumerable<DataTypeEnum> GetAllEnums();
|
||||||
|
IEnumerable<DataTypeStruct> GetAllStructs();
|
||||||
|
IEnumerable<DataTypeUnion> GetAllUnions();
|
||||||
|
IEnumerable<DataTypeTypedef> GetAllTypedefs();
|
||||||
|
IEnumerable<StructureInformation> GetAllStructureInformation();
|
||||||
|
IEnumerable<FastFileBlock> GetAllFastFileBlocks();
|
||||||
|
*/
|
||||||
|
const std::vector<>&
|
||||||
|
};
|
||||||
|
11
src/ZoneCodeGeneratorNew/Utils/AlignmentUtils.h
Normal file
11
src/ZoneCodeGeneratorNew/Utils/AlignmentUtils.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class AlignmentUtils
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template<typename T>
|
||||||
|
static T Align(T number, T alignmentValue)
|
||||||
|
{
|
||||||
|
return (number + (alignmentValue - 1)) / alignmentValue * alignmentValue;
|
||||||
|
}
|
||||||
|
};
|
39
src/ZoneCodeGeneratorNew/Utils/NamespaceBuilder.cpp
Normal file
39
src/ZoneCodeGeneratorNew/Utils/NamespaceBuilder.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "NamespaceBuilder.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
std::string NamespaceBuilder::Combine(const std::string& _namespace, const std::string& name)
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
str << _namespace << "::" << name;
|
||||||
|
|
||||||
|
return str.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NamespaceBuilder::Push(std::string element)
|
||||||
|
{
|
||||||
|
m_elements.emplace_back(std::move(element));
|
||||||
|
}
|
||||||
|
|
||||||
|
void NamespaceBuilder::Pop()
|
||||||
|
{
|
||||||
|
m_elements.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string NamespaceBuilder::ToString()
|
||||||
|
{
|
||||||
|
std::ostringstream str;
|
||||||
|
auto first = true;
|
||||||
|
|
||||||
|
for(const auto& element : m_elements)
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
first = false;
|
||||||
|
else
|
||||||
|
str << "::";
|
||||||
|
|
||||||
|
str << element;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str.str();
|
||||||
|
}
|
16
src/ZoneCodeGeneratorNew/Utils/NamespaceBuilder.h
Normal file
16
src/ZoneCodeGeneratorNew/Utils/NamespaceBuilder.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class NamespaceBuilder
|
||||||
|
{
|
||||||
|
std::vector<std::string> m_elements;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static std::string Combine(const std::string& _namespace, const std::string& name);
|
||||||
|
|
||||||
|
void Push(std::string element);
|
||||||
|
void Pop();
|
||||||
|
std::string ToString();
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user