From 4ca77877cf0bff4fc015a3ed187a4f2f78536176 Mon Sep 17 00:00:00 2001 From: DronCode Date: Sun, 1 Dec 2024 17:43:02 +0300 Subject: [PATCH] [0.0.23] Added docs & fixed old notes in docs --- Extension/README.md | 47 ++++++++++++++++++++++++++++++++++++++++----- README.md | 38 +++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/Extension/README.md b/Extension/README.md index fe99db4..bc72a1f 100644 --- a/Extension/README.md +++ b/Extension/README.md @@ -12,7 +12,7 @@ Install Make sure that your system has clang (any version): * **macOS**: you need to install XCode (tested on 15.x but should work everywhere) * **Window**: you need to install clang 17.x or later and add it into PATH - * **Linux**: gcc & g++ at least 13 version (temporary limitation, planned to fix at 0.0.4) + * **Linux**: gcc & g++ at least 13 version * **Other platforms & archs**: Contact us in [our GitHub](https://github.com/DronCode/RG3). It's a better way to use RG3 inside virtualenv: @@ -99,16 +99,53 @@ We have a type my::cool::name_space::SomeThirdPartyStruct (TK_STRUCT_OR_CLASS) Function static bool IsGeniusDesc(bool bCanReplace) ``` +Another good use case is `constexpr` evaluation feature: +```python +import rg3py +from typing import Union, List, Dict + +evaluator: rg3py.CodeEvaluator = rg3py.CodeEvaluator.make_from_system_env() + +evaluator.set_compiler_config({ + "cpp_standard" : rg3py.CppStandard.CXX_20 +}) + +result: Union[Dict[str, any], List[rg3py.CppCompilerIssue]] = evaluator.eval(""" + #include + + class Simple {}; + class Base {}; + class Inherited : public Base {}; + + constexpr bool r0 = std::is_base_of_v; + constexpr bool r1 = std::is_base_of_v; + """, ["r0", "r1"]) + +print(result) +``` + +output will be + +```text +{'r1': False, 'r0': True} +``` + +and that's great feature to make some checks like `type should be inherited from A, have some methods and etc...` + +And this is independent of your current environment, only C++ STL library should be found! + + Features --------- * Supported Windows (x86_64), Linux (x86_64) and macOS (x86_64 and ARM64) - * Supported C++03, 11, 14, 17, 20, 23 (26 in theory, need to migrate to next LLVM) + * Supported C++03, 11, 14, 17, 20, 23, 26 * Supported threads in analysis on native side (see Tests/PyIntegration/test.py test: **test_analyzer_context_sample** for example) * Statically linked, no external dependencies (except Clang instance on machine) * Special macro definitions to hide unnecessary code * Template specializations reporting * Anonymous registration without changes in third party code + * Runtime constexpr C++ code evaluation with results extraction Current limitations ------------------- @@ -118,8 +155,8 @@ Project focused on work around C/C++ headers (C++ especially). Feel free to fork Third Party libraries ---------------------- - * LLVM 16.0.4 - our main backend of C++ analysis - * Boost 1.81.0 - python support & process launcher - * FMT - string formatter + * LLVM - our main backend of C++ analysis + * Boost.Python - python support & process launcher + * fmt - string formatter * googletest - for internal unit testing * pytest - for python side unit testing \ No newline at end of file diff --git a/README.md b/README.md index 08ec3ef..45f1e00 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Requirements Windows ------- - * Compiled LLVM (>= 18.1.8) on local machine and environment variables `CLANG_DIR` and `LLVM_DIR` + * Compiled LLVM (>= 19.1.4) on local machine and environment variables `CLANG_DIR` and `LLVM_DIR` * My `Clang_DIR` is `B:/Projects/llvm/build/lib/cmake/clang` * My `LLVM_DIR` is `B:/Projects/llvm/build/lib/cmake/llvm` * Statically compiled Boost (>=1.81.0) with boost python and environment variable `BOOST_ROOT` @@ -98,6 +98,42 @@ and output will be We have a type my::cool::name_space::ECoolEnum (TK_ENUM) ``` + +Another good use case is `constexpr` evaluation feature: +```python +import rg3py +from typing import Union, List, Dict + +evaluator: rg3py.CodeEvaluator = rg3py.CodeEvaluator.make_from_system_env() + +evaluator.set_compiler_config({ + "cpp_standard" : rg3py.CppStandard.CXX_20 +}) + +result: Union[Dict[str, any], List[rg3py.CppCompilerIssue]] = evaluator.eval(""" + #include + + class Simple {}; + class Base {}; + class Inherited : public Base {}; + + constexpr bool r0 = std::is_base_of_v; + constexpr bool r1 = std::is_base_of_v; + """, ["r0", "r1"]) # 1'st argument: code, 2'nd argument: constexpr captures (list of variables which will be exported from AST) + +print(result) # Result maybe a `dict` or `list`. When dict - result is good, when list - list of errors/issues presented +``` + +output will be + +```text +{'r1': False, 'r0': True} +``` + +and that's great feature to make some checks like `type should be inherited from A, have some methods and etc...` + +And this is independent of your current environment, only C++ STL library should be found! + Project state -------------