From e17ae812beb44dc302f6e16498383a29ff66fbc4 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sun, 3 Mar 2024 18:21:25 +0800 Subject: [PATCH] feat update --- runtime/test.h | 7 +++++-- src/types/base_type.h | 12 ++++++++++++ src/types/method.cc | 17 +++++++++++------ src/types/method.h | 1 + 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/runtime/test.h b/runtime/test.h index c329ab3..76e4ee2 100644 --- a/runtime/test.h +++ b/runtime/test.h @@ -9,13 +9,15 @@ CLASS(Test) { public: META("Constructor") - Test() : a_(0) {} + Test() : b_(0), a_(0) {} - Test(int a) : a_(a) {} + Test(int a) : b_(0), a_(a) {} META("Test") int GetA() const { return a_; } + int kk(int, void *); + private: struct Void {}; @@ -25,6 +27,7 @@ private: int a; }; + const int b_; int a_; }; diff --git a/src/types/base_type.h b/src/types/base_type.h index 9771e6e..831387a 100644 --- a/src/types/base_type.h +++ b/src/types/base_type.h @@ -19,6 +19,18 @@ public: virtual bool ShouldGenerate() const { return !properties_.empty(); } + bool IsPublic() const { return clang_getCXXAccessSpecifier(cursor_.handle()) == CX_CXXPublic; } + + bool IsPrivate() const + { + return clang_getCXXAccessSpecifier(cursor_.handle()) == CX_CXXPrivate; + } + + bool IsProtected() const + { + return clang_getCXXAccessSpecifier(cursor_.handle()) == CX_CXXProtected; + } + bool HasProperty(const std::string &property) const { return std::find(properties_.begin(), properties_.end(), property) != properties_.end(); diff --git a/src/types/method.cc b/src/types/method.cc index e55b9af..7723173 100644 --- a/src/types/method.cc +++ b/src/types/method.cc @@ -11,11 +11,8 @@ Method::Method(const Cursor &cursor, parent_(parent), return_type_(clang_getResultType(cursor.GetType().handle())) { - unsigned args_num = clang_Cursor_getNumArguments(cursor.handle()); - - for (unsigned i = 0; i < args_num; ++i) { - Cursor arg = clang_Cursor_getArgument(cursor.handle(), i); - arguments_.push_back(arg.GetType()); + for (unsigned i = 0; i < cursor.GetType().GetArgumentCount(); ++i) { + arguments_.push_back(cursor.GetType().GetArgument(i)); } } @@ -29,8 +26,16 @@ Method::ToString() const ss << arguments_[i].GetDisplayName(); if (i < arguments_.size() - 1) { ss << ", "; } } + // get function const ss << ")"; - return ss.str() + " /*" + sled::StrJoin(properties(), ",") + "*/"; + if (IsConst()) { ss << " const"; } + return ss.str() + " /*" + sled::StrJoin(properties(), ",") + "*/;"; } +bool +Method::IsConst() const +{ + return clang_CXXMethod_isConst(cursor_.handle()); +}; + }// namespace meta diff --git a/src/types/method.h b/src/types/method.h index 5ac6f8a..17d6429 100644 --- a/src/types/method.h +++ b/src/types/method.h @@ -12,6 +12,7 @@ public: std::string ToString() const override; + bool IsConst() const; CursorType return_type() const; CursorType argument(unsigned index) const; std::vector arguments() const;