Skip to content

Commit

Permalink
[v0.0.3] Initial support of dynamic properties. Fixed crash for incom…
Browse files Browse the repository at this point in the history
…plete definitions.
  • Loading branch information
DronCode committed Mar 19, 2024
1 parent 927f677 commit 917e89e
Show file tree
Hide file tree
Showing 7 changed files with 750 additions and 41 deletions.
28 changes: 28 additions & 0 deletions Cpp/include/RG3/Cpp/BuiltinTags.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,32 @@ 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" };
};
}
21 changes: 21 additions & 0 deletions LLVM/include/RG3/LLVM/Visitors/CxxClassTypeVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <RG3/LLVM/CompilerConfig.h>
#include <RG3/Cpp/TypeClass.h>
#include <functional>
#include <vector>


Expand All @@ -30,6 +31,26 @@ namespace rg3::llvm::visitors
bool bTriviallyConstructible { false };
std::vector<cpp::ClassParent> parentClasses {};

// Extra types
std::vector<rg3::cpp::TypeBasePtr> vFoundExtraTypes {};

public: // Types

struct PropertyDescription
{
std::string propertyRefName {}; // A reference name to property (original)
std::string propertyAliasName {}; // A new name of property (alias)
};

private:
void handleTypeAnnotation(clang::CXXRecordDecl* cxxRecordDecl, clang::AnnotateAttr* pAnnotateAttr);
void handleAndMergeTypedefTypeWithInner(const clang::TypedefType* pType, const std::vector<PropertyDescription>& vKnownProperties, const std::vector<std::string>& vKnownFunctions);
void handleCxxDeclAndOverridePropertiesOwner(const clang::CXXRecordDecl* pCxxDecl,
const rg3::cpp::TypeBase* pNewOwnerType,
CxxClassTypeVisitor& sTypeVisitor,
const std::function<bool(const std::string&)>& propFilter,
const std::function<bool(const std::string&)>& funcFilter);

private:
const CompilerConfig& compilerConfig;
};
Expand Down
6 changes: 6 additions & 0 deletions LLVM/include/RG3/LLVM/Visitors/CxxTypeVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <RG3/Cpp/TypeBase.h>

#include <vector>
#include <set>


namespace rg3::llvm::visitors
Expand All @@ -26,6 +27,11 @@ namespace rg3::llvm::visitors

bool VisitTypeAliasDecl(clang::TypeAliasDecl* typeAliasDecl);

bool VisitTypedefNameDecl(clang::TypedefNameDecl* typedefNameDecl);

private:
bool HandleNamedTypedefDecl(clang::TypedefNameDecl* typedefNameDecl);

private:
template <typename T>
static bool isDeclInsideClassOrStruct(T* pDecl) requires (std::is_base_of_v<clang::Decl, T>)
Expand Down
Loading

0 comments on commit 917e89e

Please sign in to comment.