Skip to content

Commit

Permalink
v0.0.3 (#5)
Browse files Browse the repository at this point in the history
v0.0.3 finished!
1. Removed type alias. Now RG3 will try to expand whole type as separated (from original type) with all information.
2. Added 'annotations' method to annotate type (like comments but in place where extra comments not available)
3. Refactored global routing system: now logic divided between CxxRouterVisitor (root visitor), CxxClassTypeVisitor (non-templated classes), CxxTemplateSpecializationVisitor (template specialization) and CxxTypeVisitor (trivial, enum types and aliases)
4. Removed template specialization type kind. Now all templates are part of TK_STRUCT_OR_CLASS. NOTE: In future I'll add flag into type base to check is type templated or not.
5. Fixed sOwnerClassName field in class member methods. Now this field contains pretty name of owner class (with template view when it's templated)
6. Added tests to support unsigned enum
7. Expored missing types into python
8. Fixed template extraction code
9. Added example for PyPI package
10. Added environment cache support
  • Loading branch information
DronCode authored Apr 2, 2024
1 parent c49801f commit 9ae833f
Show file tree
Hide file tree
Showing 44 changed files with 2,575 additions and 779 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ jobs:
run: |
brew install pyenv
brew install ninja
brew install [email protected]
pyenv install 3.10-dev -s
echo "Python3_ROOT_DIR=$HOME/.pyenv/versions/3.10-dev" >> $GITHUB_ENV
Expand Down
36 changes: 36 additions & 0 deletions Cpp/include/RG3/Cpp/BuiltinTags.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,40 @@ namespace rg3::cpp
*/
static constexpr std::string_view kProperty { "property" };
};

struct BuiltinAnnotations
{
/**
* @brief Annotation for type which could not be annotated via runtime tag (or any other tag)
*/
static constexpr std::string_view kRegisterRuntime { "RG3_RegisterRuntime" };

/**
* @brief Annotation for type fields. Semantics: RG3_RegisterField[{original_name}:{alias_name}]
* Original name: name of field without class name
* Alias name: [Optional] new name of field. Must be unique for type
*/
static constexpr std::string_view kRegisterField { "RG3_RegisterField" };

/**
* @brief Annotation for type function registration. Semantics: RG3_RegisterFunction[funcName]
* @note Aliasing not supported
*/
static constexpr std::string_view kRegisterFunction { "RG3_RegisterFunction" };

/**
* @brief Annotation for extra tag for type. Semantics: RG3_RegisterTag[@tagName(args)]
* @note Use full semantic because will be used default parser!
* @note Use string escape symbol \" to use strings inside tags inside annotation
*/
static constexpr std::string_view kRegisterTag { "RG3_RegisterTag" };

/**
* @brief Annotation for override final type location place. Semantics: RG3_OverrideLication[new/path]
* @note Path will be marked as 'angled' ie to use as #include <my_path>
* @note Line & column will be always zeroed
* @note Only last annotation will affect final path!
*/
static constexpr std::string_view kOverrideLocation { "RG3_OverrideLocation" };
};
}
2 changes: 2 additions & 0 deletions Cpp/include/RG3/Cpp/CppNamespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace rg3::cpp

const std::string& asString() const { return m_sNamespace; }

bool isEmpty() const { return m_vNamespace.empty(); }

private:
void parseNamespace();

Expand Down
4 changes: 3 additions & 1 deletion Cpp/include/RG3/Cpp/DefinitionLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ namespace rg3::cpp
{
public:
DefinitionLocation();
DefinitionLocation(const std::filesystem::path& location, int line, int offset);
DefinitionLocation(const std::filesystem::path& location, int line, int offset, bool bAngled = false);

[[nodiscard]] const std::filesystem::path& getFsLocation() const;
[[nodiscard]] std::string getPath() const;
[[nodiscard]] int getLine() const;
[[nodiscard]] int getInLineOffset() const;
[[nodiscard]] bool isAngledPath() const;

bool operator==(const DefinitionLocation& other) const;
bool operator!=(const DefinitionLocation& other) const;
Expand All @@ -24,5 +25,6 @@ namespace rg3::cpp
std::filesystem::path m_fsLocation {};
int m_line { 0 };
int m_offset { 0 };
bool m_bAngled { false };
};
}
6 changes: 6 additions & 0 deletions Cpp/include/RG3/Cpp/Tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,11 @@ namespace rg3::cpp
[[nodiscard]] Tag getTag(const std::string& tag) const;
[[nodiscard]] const Storage_t& getTags() const;
[[nodiscard]] Storage_t& getTags();

bool isEmpty() const { return m_tags.empty(); }

Tags& operator+=(const Tags& another);
Tags& operator+=(const Tag& another);
friend Tags operator+(const Tags& a, const Tags& b);
};
}
36 changes: 0 additions & 36 deletions Cpp/include/RG3/Cpp/TypeAlias.h

This file was deleted.

8 changes: 8 additions & 0 deletions Cpp/include/RG3/Cpp/TypeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace rg3::cpp
[[nodiscard]] const CppNamespace& getNamespace() const;
[[nodiscard]] const std::string& getPrettyName() const;
[[nodiscard]] const DefinitionLocation& getDefinition() const;
void setDefinition(DefinitionLocation&& newLoc);

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

Expand All @@ -33,6 +34,13 @@ namespace rg3::cpp
[[nodiscard]] bool operator==(const TypeBase& other) const { return areSame(&other); }
[[nodiscard]] bool operator!=(const TypeBase& other) const { return !areSame(&other); }

void overrideTypeData(const std::string& name, const std::string& prettyName);
void overrideTypeData(const std::string& name, const std::string& prettyName, const CppNamespace& aNamespace);
void overrideTypeData(const std::string& name, const std::string& prettyName, const CppNamespace& aNamespace, const DefinitionLocation& aLocation);
void overrideTypeData(const std::string& name, const std::string& prettyName, const CppNamespace& aNamespace, const DefinitionLocation& aLocation, const Tags& tags);

void addTags(const Tags& vTags);

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

Expand Down
2 changes: 0 additions & 2 deletions Cpp/include/RG3/Cpp/TypeKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ namespace rg3::cpp
TK_TRIVIAL, ///< See TypeBase
TK_ENUM, ///< See TypeEnum
TK_STRUCT_OR_CLASS, ///< See TypeClass
TK_ALIAS, ///< See TypeAlias
TK_TEMPLATE_SPECIALIZATION
};
}
10 changes: 8 additions & 2 deletions Cpp/source/DefinitionLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
namespace rg3::cpp
{
DefinitionLocation::DefinitionLocation() = default;
DefinitionLocation::DefinitionLocation(const std::filesystem::path& location, int line, int offset)
DefinitionLocation::DefinitionLocation(const std::filesystem::path& location, int line, int offset, bool bAngled)
: m_fsLocation(location)
, m_line(line)
, m_offset(offset)
, m_bAngled(bAngled)
{
}

Expand All @@ -31,9 +32,14 @@ namespace rg3::cpp
return m_offset;
}

bool DefinitionLocation::isAngledPath() const
{
return m_bAngled;
}

bool DefinitionLocation::operator==(const DefinitionLocation& other) const
{
return m_fsLocation == other.m_fsLocation && m_line == other.m_line && m_offset == other.m_offset;
return m_fsLocation == other.m_fsLocation && m_line == other.m_line && m_offset == other.m_offset && m_bAngled == other.m_bAngled;
}

bool DefinitionLocation::operator!=(const DefinitionLocation& other) const
Expand Down
45 changes: 44 additions & 1 deletion Cpp/source/Tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace rg3::cpp
Tags Tag::parseFromCommentString(std::string_view commentText)
{
std::vector<Tag> tags;
std::regex tagRegex("@([a-zA-Z_]+)(\\([^)]*\\))?");
std::regex tagRegex("@([a-zA-Z_.]+)(\\([^)]*\\))?");
std::smatch tagMatch;

auto commentBegin = std::cregex_iterator(commentText.data(), commentText.data() + commentText.size(), tagRegex);
Expand Down Expand Up @@ -96,6 +96,14 @@ namespace rg3::cpp
while (!argumentString.empty() && argumentString[0] == ' ')
argumentString.erase(0, 1);

// Remove escape symbols
auto it = argumentString.find('\"');
while (it != std::string::npos)
{
argumentString.erase(it, 1);
it = argumentString.find('\"');
}

if (argumentString.empty())
continue;

Expand Down Expand Up @@ -188,4 +196,39 @@ namespace rg3::cpp
{
return m_tags;
}
Tags operator+(const Tags& a, const Tags& b)
{
Tags result = a;

for (const auto& [name, tag] : b.getTags())
{
// DronCode: maybe we need to avoid of override keys here?
result.getTags()[name] = tag;
}

return result;
}

Tags& Tags::operator+=(const Tags& another)
{
for (const auto& [name, tag] : another.getTags())
{
if (m_tags.contains(name))
continue;

m_tags[name] = tag;
}

return *this;
}

Tags& Tags::operator+=(const Tag& another)
{
if (!m_tags.contains(another.getName()))
{
m_tags[another.getName()] = another;
}

return *this;
}
}
48 changes: 0 additions & 48 deletions Cpp/source/TypeAlias.cpp

This file was deleted.

40 changes: 40 additions & 0 deletions Cpp/source/TypeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ namespace rg3::cpp
return m_location;
}

void TypeBase::setDefinition(rg3::cpp::DefinitionLocation&& newLoc)
{
m_location = std::move(newLoc);
}

bool TypeBase::areSame(const TypeBase* pOther) const
{
if (!pOther)
Expand All @@ -62,6 +67,41 @@ namespace rg3::cpp
return m_tags;
}

void TypeBase::overrideTypeData(const std::string& name, const std::string& prettyName)
{
m_name = name;
m_prettyName = prettyName;
}

void TypeBase::overrideTypeData(const std::string& name, const std::string& prettyName, const rg3::cpp::CppNamespace& aNamespace)
{
m_name = name;
m_prettyName = prettyName;
m_nameSpace = aNamespace;
}

void TypeBase::overrideTypeData(const std::string& name, const std::string& prettyName, const rg3::cpp::CppNamespace& aNamespace, const rg3::cpp::DefinitionLocation& aLocation)
{
m_name = name;
m_prettyName = prettyName;
m_nameSpace = aNamespace;
m_location = aLocation;
}

void TypeBase::overrideTypeData(const std::string& name, const std::string& prettyName, const CppNamespace& aNamespace, const DefinitionLocation& aLocation, const Tags& tags)
{
m_name = name;
m_prettyName = prettyName;
m_nameSpace = aNamespace;
m_location = aLocation;
m_tags = tags;
}

void TypeBase::addTags(const Tags& vTags)
{
m_tags += vTags;
}

bool TypeBase::doAreSame(const TypeBase* pOther) const
{
return
Expand Down
Loading

0 comments on commit 9ae833f

Please sign in to comment.