Skip to content

Commit

Permalink
WIP Version 0.0.2 (#3)
Browse files Browse the repository at this point in the history
[v0.0.2] Added support of threading, macOS, fixed few things, added more tests.
  • Loading branch information
DronCode authored Mar 16, 2024
1 parent 6338905 commit 927f677
Show file tree
Hide file tree
Showing 71 changed files with 3,847 additions and 594 deletions.
650 changes: 363 additions & 287 deletions .github/workflows/build.yml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ Extension/dist
Extension/rg3py/rg3py.pyd
Extension/rg3py/rg3py.so
Extension/rg3py/rg3py.pyi
Extension/rg3py.egg-info
Extension/rg3py.egg-info
Tests/PyIntegration/venv
Tests/PyIntegration/.idea
PyBind/rg3py.pyd
PyBind/rg3py.so
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "ThirdParty/googletest"]
path = ThirdParty/googletest
url = https://github.com/google/googletest
[submodule "ThirdParty/fmt"]
path = ThirdParty/fmt
url = https://github.com/fmtlib/fmt
8 changes: 8 additions & 0 deletions CMake/RG3_Config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is auto generated by CMake!

#ifndef __RG3_COMMIT_H__
#define __RG3_COMMIT_H__

#define RG3_BUILD_HASH "@GIT_HASH@"

#endif //__RG3_COMMIT_H__
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ if (UNIX)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif()

add_subdirectory(ThirdParty/fmt)

add_subdirectory(Cpp)
add_subdirectory(LLVM)
add_subdirectory(PyBind)
Expand Down
1 change: 1 addition & 0 deletions Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ file(GLOB_RECURSE GENRY_CXX_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
add_library(RG3_Cpp STATIC ${GENRY_CXX_SOURCES})
add_library(RG3::Cpp ALIAS RG3_Cpp)
target_include_directories(RG3_Cpp PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(RG3_Cpp PRIVATE fmt::fmt)
5 changes: 5 additions & 0 deletions Cpp/include/RG3/Cpp/BuiltinTags.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ namespace rg3::cpp
* Brief - a "doxygen way" to know annotation about entity.
*/
static constexpr std::string_view kBrief { "brief" };

/**
* Property - special tag to override property name. Usually, it has 1 argument - alias for property name
*/
static constexpr std::string_view kProperty { "property" };
};
}
10 changes: 8 additions & 2 deletions Cpp/include/RG3/Cpp/Tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace rg3::cpp
std::int64_t asI64(std::int64_t defValue) const;
std::string asString(const std::string& defValue) const;
TypeReference asTypeRef(const TypeReference& defValue) const;
TypeReference* asTypeRefMutable();
TagArgumentType getHoldedType() const;

TagArgument& operator=(bool val);
Expand Down Expand Up @@ -64,6 +65,7 @@ namespace rg3::cpp

[[nodiscard]] const std::string& getName() const;
[[nodiscard]] const std::vector<TagArgument>& getArguments() const;
[[nodiscard]] std::vector<TagArgument>& getArguments();
[[nodiscard]] bool hasArguments() const;
[[nodiscard]] int getArgumentsCount() const;

Expand All @@ -79,15 +81,19 @@ namespace rg3::cpp

class Tags
{
public:
using Storage_t = std::map<std::string, Tag>;

private:
std::map<std::string, Tag> m_tags;
Storage_t m_tags;

public:
Tags();
explicit Tags(const std::vector<Tag>& tags);

[[nodiscard]] bool hasTag(const std::string& tag) const;
[[nodiscard]] Tag getTag(const std::string& tag) const;
[[nodiscard]] const std::map<std::string, Tag>& getTags() const;
[[nodiscard]] const Storage_t& getTags() const;
[[nodiscard]] Storage_t& getTags();
};
}
36 changes: 36 additions & 0 deletions Cpp/include/RG3/Cpp/TypeAlias.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <RG3/Cpp/TypeBase.h>
#include <RG3/Cpp/TypeStatement.h>


namespace rg3::cpp
{
/**
* @brief This class represents any typedef or using which marked as "runtime". It could be a part of another "record" type (like struct, class)
*/
class TypeAlias : public TypeBase
{
public:
TypeAlias();
TypeAlias(const std::string& name, const std::string& prettyName, const CppNamespace& aNamespace, const DefinitionLocation& aLocation, const Tags& tags, TypeStatement sTargetType);

[[nodiscard]] const TypeReference& getTargetType() const;
[[nodiscard]] TypeReference& getTargetType();

/**
* @note It's better to use getTargetTypeDescription
*/
[[nodiscard]] DefinitionLocation getTargetTypeDefinedAt() const;

bool hasTargetTypeDefinitionLocation() const;

[[nodiscard]] const TypeStatement& getTargetTypeDescription() const;

protected:
bool doAreSame(const TypeBase* pOther) const override;

protected:
TypeStatement m_sTargetType {};
};
}
8 changes: 5 additions & 3 deletions Cpp/include/RG3/Cpp/TypeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ namespace rg3::cpp
TypeBase();
virtual ~TypeBase() noexcept = default;

TypeBase(TypeKind kind, const std::string& name, const CppNamespace& aNamespace, const DefinitionLocation& aLocation, const Tags& tags);
TypeBase(TypeKind kind, const std::string& name, const std::string& prettyName, const CppNamespace& aNamespace, const DefinitionLocation& aLocation, const Tags& tags);

[[nodiscard]] TypeID getID() const;
[[nodiscard]] TypeKind getKind() const;
[[nodiscard]] const std::string& getName() const;
[[nodiscard]] const CppNamespace& getNamespace() const;
[[nodiscard]] std::string getPrettyName() const;
[[nodiscard]] const std::string& getPrettyName() const;
[[nodiscard]] const DefinitionLocation& getDefinition() const;

[[nodiscard]] bool areSame(const TypeBase* pOther) const;

[[nodiscard]] const Tags& getTags() const;
[[nodiscard]] Tags& getTags();

[[nodiscard]] bool operator==(const TypeBase& other) const { return areSame(&other); }
[[nodiscard]] bool operator!=(const TypeBase& other) const { return !areSame(&other); }
Expand All @@ -37,7 +38,8 @@ namespace rg3::cpp

private:
TypeKind m_kind { TypeKind::TK_NONE };
std::string m_name;
std::string m_name; ///< Name of type without namespaces and parent types
std::string m_prettyName; ///< "prettified" name contains full decl
CppNamespace m_nameSpace;
DefinitionLocation m_location;
Tags m_tags;
Expand Down
47 changes: 40 additions & 7 deletions Cpp/include/RG3/Cpp/TypeClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <RG3/Cpp/Tag.h>
#include <RG3/Cpp/TypeBase.h>
#include <RG3/Cpp/TypeReference.h>
#include <RG3/Cpp/TypeStatement.h>
#include <vector>
#include <string>
#include <optional>
Expand All @@ -12,50 +13,82 @@ namespace rg3::cpp
{
enum class ClassEntryVisibility : uint8_t
{
CEV_PRIVATE, ///< Private entry
CEV_PUBLIC, ///< Public entry
CEV_PROTECTED ///< Protected entry
CEV_PUBLIC = 0, ///< Public entry
CEV_PRIVATE = 1, ///< Private entry
CEV_PROTECTED = 2 ///< Protected entry
};

enum class InheritanceVisibility : uint8_t
{
IV_PUBLIC = 0, ///< public inheritance (default for struct)
IV_PRIVATE = 1, ///< private inheritance (default for class)
IV_PROTECTED = 2, ///< protected inheritance
IV_VIRTUAL = 3 ///< virtual inheritance
};

struct ClassProperty
{
std::string sName {};
std::string sAlias {};
TypeReference sTypeName {};
TypeStatement sTypeInfo {};
ClassEntryVisibility eVisibility { ClassEntryVisibility::CEV_PRIVATE };
Tags vTags {};

bool operator==(const ClassProperty& other) const;
bool operator!=(const ClassProperty& other) const;
};

struct FunctionArgument
{
TypeStatement sType {};
std::string sArgumentName {};
bool bHasDefaultValue { false };

bool operator==(const FunctionArgument& other) const;
bool operator!=(const FunctionArgument& other) const;
};

using FunctionArgumentsVector = std::vector<FunctionArgument>;

struct ClassFunction
{
std::string sName {}; /// Name of function
std::string sOwnerClassName {}; /// Owner class name
ClassEntryVisibility eVisibility { ClassEntryVisibility::CEV_PRIVATE }; /// Visibility level of entry
Tags vTags {}; /// List of tags of function decl
TypeStatement sReturnType {}; // Return type of function (or void)
FunctionArgumentsVector vArguments {}; // Function arguments

bool bIsStatic { false }; /// Is static entry
bool bIsConst { false }; /// Is const method (for static method doesn't matter)

bool operator==(const ClassFunction& other) const;
bool operator!=(const ClassFunction& other) const;
};

struct ClassParent
{
TypeReference rParentType {}; /// inherited of what
InheritanceVisibility eModifier { InheritanceVisibility::IV_PRIVATE }; /// modifier mode
};

using ClassPropertyVector = std::vector<ClassProperty>;
using ClassFunctionVector = std::vector<ClassFunction>;

class TypeClass : public TypeBase
{
public:
TypeClass();
TypeClass(const std::string& name, const CppNamespace& aNamespace, const DefinitionLocation& aLocation, const Tags& tags, const ClassPropertyVector& aProperties, const ClassFunctionVector& aFunctions, bool bIsStruct, bool bTrivialConstructible, const std::vector<TypeReference>& parentTypes);
TypeClass(const std::string& name, const std::string& prettyName, const CppNamespace& aNamespace, const DefinitionLocation& aLocation, const Tags& tags, const ClassPropertyVector& aProperties, const ClassFunctionVector& aFunctions, bool bIsStruct, bool bTrivialConstructible, const std::vector<ClassParent>& parentTypes);

[[nodiscard]] const ClassPropertyVector& getProperties() const;
[[nodiscard]] ClassPropertyVector& getProperties();
[[nodiscard]] const ClassFunctionVector& getFunctions() const;
[[nodiscard]] ClassFunctionVector& getFunctions();
[[nodiscard]] bool isStruct() const;
[[nodiscard]] bool isTrivialConstructible() const;
[[nodiscard]] const std::vector<TypeReference>& getParentTypes() const;
[[nodiscard]] const std::vector<ClassParent>& getParentTypes() const;
[[nodiscard]] std::vector<ClassParent>& getParentTypes();

protected:
bool doAreSame(const TypeBase* pOther) const override;
Expand All @@ -65,6 +98,6 @@ namespace rg3::cpp
ClassFunctionVector m_functions {};
bool m_bIsStruct { false };
bool m_bIsTrivialConstructible { false };
std::vector<TypeReference> m_parentTypes {};
std::vector<ClassParent> m_parentTypes {};
};
}
2 changes: 1 addition & 1 deletion Cpp/include/RG3/Cpp/TypeEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace rg3::cpp
{
public:
TypeEnum();
TypeEnum(const std::string& name, const CppNamespace& aNamespace, const DefinitionLocation& aLocation, const Tags& tags, const EnumEntryVector& aValues, bool bIsScoped, TypeReference underlyingType);
TypeEnum(const std::string& name, const std::string& prettyName, const CppNamespace& aNamespace, const DefinitionLocation& aLocation, const Tags& tags, const EnumEntryVector& aValues, bool bIsScoped, TypeReference underlyingType);

[[nodiscard]] const EnumEntryVector& getEntries() const;
[[nodiscard]] bool containsValue(EnumEntry::ValueType value) const;
Expand Down
1 change: 1 addition & 0 deletions Cpp/include/RG3/Cpp/TypeKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace rg3::cpp
TK_TRIVIAL, ///< See TypeBase
TK_ENUM, ///< See TypeEnum
TK_STRUCT_OR_CLASS, ///< See TypeClass
TK_ALIAS, ///< See TypeAlias
TK_TEMPLATE_SPECIALIZATION
};
}
3 changes: 1 addition & 2 deletions Cpp/include/RG3/Cpp/TypeReference.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace rg3::cpp
bool operator==(const TypeReference& other) const;
bool operator!=(const TypeReference& other) const;

private:
void resolveTypeRef() const;
void setResolvedType(TypeBase* pType);

private:
std::string m_typeName {};
Expand Down
31 changes: 31 additions & 0 deletions Cpp/include/RG3/Cpp/TypeStatement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <RG3/Cpp/TypeReference.h>
#include <RG3/Cpp/DefinitionLocation.h>

#include <optional>
#include <vector>


namespace rg3::cpp
{
struct TypeStatement
{
TypeReference sTypeRef {};
std::optional<DefinitionLocation> sDefinitionLocation {};
bool bIsConst { false };
bool bIsPointer { false };
bool bIsPtrConst { false };
bool bIsReference { false };
bool bIsTemplateSpecialization { false };

static const TypeStatement g_sVoid; // globally known void type

bool isVoid() const;

bool operator==(const TypeStatement& other) const;
bool operator!=(const TypeStatement& other) const;
};

using TypeStatementVector = std::vector<TypeStatement>;
}
12 changes: 11 additions & 1 deletion Cpp/source/Tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ namespace rg3::cpp
return m_arguments;
}

std::vector<TagArgument>& Tag::getArguments()
{
return m_arguments;
}

bool Tag::hasArguments() const
{
return !m_arguments.empty();
Expand Down Expand Up @@ -174,7 +179,12 @@ namespace rg3::cpp
return g_BadTag;
}

const std::map<std::string, Tag>& Tags::getTags() const
const Tags::Storage_t& Tags::getTags() const
{
return m_tags;
}

Tags::Storage_t& Tags::getTags()
{
return m_tags;
}
Expand Down
4 changes: 4 additions & 0 deletions Cpp/source/TagArgument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ namespace rg3::cpp

#undef RG3_GENERATE_METHOD_IMPL

TypeReference* TagArgument::asTypeRefMutable() {
return std::get_if<TypeReference>(&m_argValue);
}

TagArgumentType TagArgument::getHoldedType() const
{
return m_argType;
Expand Down
Loading

0 comments on commit 927f677

Please sign in to comment.