C ++ 소스 코드의 수정 및 생성을위한 완전히 오픈 소스, 강력한 솔루션. C ++ 프로젝트에서 보일러 플레이트 코드의 양을 줄입니다.
이 repo는 가능한 한 빨리 https://github.com/blockspacer/flextool로 마이그레이션됩니다.
CXXCTP는 더 이상 사용되지 않습니다. Flextool을 선호합니다
CXXCTP는 새로운 내성, 반사 및 컴파일 타임 실행을 위해 C ++를 확장하는 트랜스 필러입니다.
CXXCTP는 사전 정의 된 소스 코드 변환 세트를 생성하는 것을 목표로하지 않습니다. 사용자는 소스 코드 변환을 위해 C ++ 스크립트를 공유 할 수 있습니다.
Open-Source 커뮤니티에 interface.cxx 및 enum_to_json.cxx 와 같은 유용한 스크립트를 공유했다고 가정하십시오. ctp_scripts 폴더에 배치하여 프로젝트에서 사용할 수 있습니다.
Metaprogramming은 다른 프로그램을 데이터로 취급하기위한 프로그램 작성의 "예술"입니다. 이는 프로그램이 코드 또는 심지어 코드 자체를 생성, 읽기, 분석 및 변환하여 특정 솔루션을 달성 할 수 있음을 의미합니다.
참고 :이 프로젝트는 보증없이 그대로 제공됩니다 (라이센스 참조).
Clang을 실험적인 기능 (예 : 모듈)을 제공하기 때문에 왜 Clang을 확장하지 않겠습니까?
Clang은 컴파일러 이며이 프로젝트는 트랜스 필러이며 코드를 LLVM/어셈블리를 수정할 필요없이 표준화 된 C ++ 코드로 변환합니다.
도구의 출력은 C ++ 코드이므로 EMScriptten을 사용하여 변환 된 코드를 컴파일하고 정적 코드 분석기를 사용하고 CLING 내부의 코드를 실행할 수 있습니다.
CXXCTP를 사용하면 스크립트를 만들고 공유 할 수 있습니다
개발 중에 예제를 참조하십시오. 현재 Linux 만 지원합니다.
Windows/Mac 등에서 Linux 컨테이너를 실행할 수 있습니다.
// usage example from ReflShapeKind.hpp
enum class
$apply(
reflect_enum
)
ReflShapeKind0 : uint32_t {
Box = 3 ,
Sphere = 6 ,
}; // Usage example. NOTE: no inheritance & definition outside lib.
// in lib .h
struct drawable {
virtual void draw ( const char * arg1) const noexcept = 0;
};
struct printable {
virtual void print ( const char * arg1, const char * arg2) const noexcept = 0;
};
struct canvas3D {
std::string name3D;
};
struct canvas4D {
std::string name4D;
};
// in app .cpp
void draw<drawable>( const canvas3D& data, const char * arg1){
std::cout << " drawing to canvas3D name = " << data. name3D << std::endl;
}
void draw<drawable>( const canvas4D& data, const char * arg1){
std::cout << " drawing to canvas4D name = " << data. name4D << std::endl;
}
void print<printable>( const canvas3D& data, const char * arg1, const char * arg2){
std::cout << " printing to canvas3D name = " << data. name3D << std::endl;
}
void print<printable>( const canvas4D& data, const char * arg1, const char * arg2){
std::cout << " printing to canvas4D name = " << data. name4D << std::endl;
}
std::vector< _tc_combined_t <drawable>> vec {
canvas3D{},
canvas4D{},
};
_tc_combined_t <drawable, printable> CVS = canvas4D{};
CVS.draw( " " );
CVS.print( " " , " " );
canvas3D cvs3D;
CVS = std::move(cvs3D);
canvas4D cvs4D;
CVS = cvs4D; // copy
CVS = vec.at( 0 ); // <drawable> to <drawable, printable>$ export (
static int resultSomeInt = 2345 ;
)
$eval( " #include <optional> " )
$exec(
printf ( " execkjljlk n " );
printf ( " execasdasd n " );
)
$set_embed( " set_embed103 " ,
printf ( " set_embed101 n " );
printf ( " set_embed102 n " );
)
$embed(
[&clangMatchResult, &clangRewriter, &clangDecl]() {
printf ( " embed01 n " );
printf ( " embed02 n " );
return new llvm::Optional<std::string>{ " embed03 " };
}();
) class
$apply(make_interface;make_removefuncbody;make_reflect)
SomeInterfaceName {
virtual ~SomeInterfaceName () = 0 ;
/* int f ( ) { // {}
int i = 6;
{
// {
// }
}
return i;
}; */
int foo ();
virtual void foobar ( int & arg1) = 0 ;
virtual inline void zoobar ( int & arg2);
// int m_bar;
// int m_bar2 = 2;
};git submodule sync --recursive
git fetch --recurse-submodules
git submodule update --init --recursive --depth 100 --progress
# or
git submodule update --force --recursive --init --remoteDocker를 설치하고 구성하십시오 : https://medium.com/@saniacy/configure-docker-to-us--host-proxy-e88bd988c0aa
클론 코드 (위와 같이)와 cd 복제 된 DIR로 CD.
참고 : --build-arg NO_SSL="False" 로 docker 이미지를 빌드 할 수 있습니다. dockerfile에서 주석을 읽으십시오.
# Give docker the rights to access X-server
sudo -E xhost +local:docker
# build Dockerfile
sudo -E docker build --no-cache
--build-arg GIT_WITH_OPENSSL= " "
--build-arg NO_SSL= " False "
-t cpp-docker-cxxctp .
# Now let’s check if our image has been created.
sudo -E docker images
# Run in container without leaving host terminal
sudo -E docker run -v " $PWD " :/home/u/cxxctp -w /home/u/cxxctp cpp-docker-cxxctp CXXCTP_tool -version --version
# Run a terminal in container
sudo -E docker run --rm -v " $PWD " :/home/u/cxxctp -w /home/u/cxxctp -it -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix cpp-docker-cxxctp
# type in container terminal
CXXCTP_tool -version --version # Run a terminal in container
sudo -E docker run --rm -v " $PWD " :/home/u/cxxctp -w /home/u/cxxctp -it -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix cpp-docker-cxxctp
# An example of how to build (with Makefile generated from cmake) inside the container
# Mounts $PWD to /home/u/cxxctp and runs command
mkdir build
sudo -E docker run --rm -v " $PWD " :/home/u/cxxctp -w /home/u/cxxctp/build cpp-docker-cxxctp cmake -DCONAN_AUTO_INSTALL=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE ..
# Run resulting app in host OS:
# ./build/<app> pip install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org wheel
&&
pip install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org virtualenv
&&
pip install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org conan
&&
pip install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org conan_package_tools
conan profile new default --detect
# conan profile update settings.compiler.libcxx=libstdc++11 default
conan remote list
conan search * boost * -r all ~/.conan/conan.conf 에서 프록시 및 cacert_path를 구성하십시오. https://docs.conan.io/en/latest/reference/config_files/conan.conf.html#proxies를 참조하십시오
Conan Clang 프로파일을 구성하여 -profile clang을 사용하십시오.
/usr/bin/clang-6.0 -v
/usr/bin/clang++-6.0 -v
nano ~ /.conan/profiles/clang
[settings]
# We are building in Ubuntu Linux
os_build=Linux
os=Linux
arch_build=x86_64
arch=x86_64
compiler=clang
compiler.version=6.0
compiler.libcxx=libstdc++11
[env]
CC=/usr/bin/clang-6.0
CXX=/usr/bin/clang++-6.0 그런 다음 conan install ***** --profile clang
/usr/bin/gcc -v
/usr/bin/g++ -v
nano ~ /.conan/profiles/gcc
[settings]
# We are building in Ubuntu Linux
os_build=Linux
os=Linux
arch_build=x86_64
arch=x86_64
compiler=gcc
compiler.version=7
compiler.libcxx=libstdc++11
[env]
CC=/usr/bin/gcc
CXX=/usr/bin/g++SSL을 비활성화하려면 (프록시 등) :
# see https://docs.conan.io/en/latest/reference/commands/misc/remote.html#conan-remote
conan remote update conan-center https://conan.bintray.com False
conan search boost * -r=conan-center
conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
conan remote update bincrafters https://api.bintray.com/conan/bincrafters/public-conan False
conan search boost * -r=bincraftersCorp를 설정하려면 Cacert :
CONAN_CACERT_PATH=/path/to/ca-bundle.crt
file $CONAN_CACERT_PATH유용한 링크 :
종속성 리모컨 목록을 추가하려면 다음 명령을 입력하십시오.
cmake -E time conan config install conan/remotes/
# OR:
# cmake -E time conan config install conan/remotes_disabled_ssl/ # NOTE: don't forget to re-run `conan install` after command below
# NOTE: change `build_type=Debug` to `build_type=Release` in production
cmake -DEXTRA_CONAN_OPTS= " --profile;clang;-s;build_type=Debug;--build;missing " -P tools/buildConanThirdparty.cmakeconan remote add Manu343726 https://api.bintray.com/conan/manu343726/conan-packages False
git clone http://github.com/foonathan/type_safe.git -b v0.2.1
cd type_safe
# NOTE: change `build_type=Debug` to `build_type=Release` in production
CONAN_REVISIONS_ENABLED=1
CONAN_VERBOSE_TRACEBACK=1
CONAN_PRINT_RUN_COMMANDS=1
CONAN_LOGGING_LEVEL=10
GIT_SSL_NO_VERIFY=true
conan create . conan/stable -s build_type=Debug --profile clang --build missing # NOTE: change `build_type=Debug` to `build_type=Release` in production
git clone http://github.com/mosra/corrade.git && cd corrade
CONAN_REVISIONS_ENABLED=1
CONAN_VERBOSE_TRACEBACK=1
CONAN_PRINT_RUN_COMMANDS=1
CONAN_LOGGING_LEVEL=10
GIT_SSL_NO_VERIFY=true
conan create . magnum/stable -s build_type=Debug --profile clang --build missing -tf package/conan/test_packagesudo apt-get install openmpi-bin openmpi-common libopenmpi-devsudo -E apt-get purge -y cmake
bash scripts/install_cmake.shcxtpl 라이브러리 https://github.com/blockspacer/cxtpl을 설치하십시오
cxtpl_tool https://github.com/blockspacer/cxtpl#how-tobuild를 설치하십시오
BEFORE install_cling.sh:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install clang-6.0 libstdc++6 libstdc++-6-dev
sudo update-alternatives --config c++
sudo update-alternatives --config cc
sudo ldconfig
export CC=clang-6.0
export CXX=clang++-6.0 # Build Cling into `cling-build` folder
cd scripts
bash install_cling.shcxtpl https://github.com/blockspacer/cxtpl#how-tobuild에서와 같이 DEP를 설치하십시오
export CC=clang-6.0
export CXX=clang++-6.0
cmake -E remove_directory build
cmake -E make_directory build
cmake -E remove_directory resources/cxtpl/generated
cmake -E make_directory resources/cxtpl/generated
# NOTE: change `build_type=Debug` to `build_type=Release` in production
CONAN_REVISIONS_ENABLED=1
CONAN_VERBOSE_TRACEBACK=1
CONAN_PRINT_RUN_COMMANDS=1
CONAN_LOGGING_LEVEL=10
GIT_SSL_NO_VERIFY=true
cmake -E chdir build
cmake -E time
conan install
-s build_type=Debug
--build=missing
--profile clang
-o enable_tests=False
-o openssl:shared=True
..
cmake -E chdir build cmake -E time cmake -DCONAN_AUTO_INSTALL=OFF -DENABLE_CLING=TRUE -DBUILD_SHARED_LIBS=FALSE -DBUILD_EXAMPLES=FALSE -DALLOW_PER_PROJECT_CTP_SCRIPTS=TRUE -DBUNDLE_EXAMPLE_SCRIPTS=FALSE -DCMAKE_BUILD_TYPE=Debug -DENABLE_CXXCTP=TRUE ..
cmake -E chdir build cmake -E time cmake --build . -- -j6
# you can install CXXCTP_tool:
sudo cmake -E chdir build make install
# NOTE: You can also use the “-p” flag with CMAKE_EXPORT_COMPILE_COMMANDS. See https://variousburglarious.com/2018/02/18/include-paths-for-clang-tools/
# cmake -E chdir build ./tool/CXXCTP_tool -p=../example_compile_commands/
# NOTE: runs CXXCTP_tool on multiple files and adds include paths by `-extra-arg=-I`
cmake -E chdir build ./tool/CXXCTP_tool -L .=DBG9 -extra-arg=-I $PWD /include -extra-arg=-I../resources ../examples/built_in/for_codegen/example_make_reflect.cpp
# check generator output
file build/example_make_reflect.cpp.generated.cpp또는 GDB에 따라 :
rm -rf * generated * ; clear && clear ; gdb ./CXXCTP -ex " run " -ex " bt " -ex " q " 공유 cxxctp_core를 공유 라이브러리로 사용하십시오 -DBUILD_SHARED_LIBS=TRUE .
https://github.com/blockspacer/cxtpl에서 bash scripts/install_folly.sh를 실행하십시오. clang 지원을 위해 수동으로 수동으로 어리석은 폴리 (folly_use_jemalloc를 폴리 _assume_no_jemalloc) Facebook/Folly#976
빌드하기 전에 Clang (GCC가 아님)을 사용하고 -DENABLE_CLING=TRUE :
export CC=clang-6.0
export CXX=clang++-6.0
sudo rm -rf examples/ * /ctp_scripts/ * / * /generated/
cmake -E remove_directory build
cmake -E make_directory build
cmake -E remove_directory resources/cxtpl/generated
cmake -E make_directory resources/cxtpl/generated
# NOTE: clang profile!
# NOTE: change `build_type=Debug` to `build_type=Release` in production
CONAN_REVISIONS_ENABLED=1
CONAN_VERBOSE_TRACEBACK=1
CONAN_PRINT_RUN_COMMANDS=1
CONAN_LOGGING_LEVEL=10
GIT_SSL_NO_VERIFY=true
cmake -E chdir build
cmake -E time
conan install
-s build_type=Debug
--build=missing
--profile clang
-o enable_tests=False
-o openssl:shared=True
..
cmake -E chdir build cmake -E time cmake -DCONAN_AUTO_INSTALL=OFF -DENABLE_CLING=TRUE -DBUILD_SHARED_LIBS=TRUE -DALLOW_PER_PROJECT_CTP_SCRIPTS=TRUE -DBUILD_EXAMPLES=FALSE -DBUNDLE_EXAMPLE_SCRIPTS=FALSE -DCLEAN_CXXCTP_GEN=TRUE -DCMAKE_BUILD_TYPE=Debug -DENABLE_CXXCTP=TRUE ..
# OR cmake -E chdir build cmake -E time cmake -DCONAN_AUTO_INSTALL=OFF -DENABLE_CLING=TRUE -DBUILD_SHARED_LIBS=TRUE -DALLOW_PER_PROJECT_CTP_SCRIPTS=FALSE -DBUILD_EXAMPLES=FALSE -DBUNDLE_EXAMPLE_SCRIPTS=TRUE -DCLEAN_CXXCTP_GEN=TRUE -DCMAKE_BUILD_TYPE=Debug -DENABLE_CXXCTP=TRUE ..
cmake -E chdir build cmake -E time cmake --build . -- -j6
# you can install CXXCTP_tool:
sudo cmake -E chdir build make install
# check supported plugins
/usr/local/bin/CXXCTP_tool --pluginsCXXCTP_TOOL을 설치 한 경우 예제를 실행할 수 있습니다.
# requires CXXCTP_tool
sudo cmake -E chdir build make install
# use -DBUILD_EXAMPLES=TRUE
rm ./build/examples/simple/CXXCTP_tool_for_CXXCTP_example.log
cmake -E chdir build cmake -E time cmake -DCONAN_AUTO_INSTALL=OFF -DENABLE_CLING=TRUE -DBUILD_SHARED_LIBS=TRUE -DBUILD_EXAMPLES=TRUE -DBUNDLE_EXAMPLE_SCRIPTS=FALSE -DALLOW_PER_PROJECT_CTP_SCRIPTS=TRUE -DCMAKE_BUILD_TYPE=Debug -DENABLE_CXXCTP=TRUE ..
cmake -E chdir build cmake -E time cmake --build . -- -j6
cat ./build/examples/simple/CXXCTP_tool_for_CXXCTP_example.log
Check that ` .log ` find doesn ` t contain errors
# run examples
build/bin/CXXCTP_example 집단을 설정하는 것을 잊지 마십시오 -extra-arg=-I$PWD/include 및 -extra-arg=-L$PWD/build 및 .dll libs by -extra-arg=-lCXXCTP_core 의 경로를 포함하는 것을 잊지 마십시오.
# NOTE: runs CXXCTP_tool on multiple files and adds include paths by `-extra-arg=-I`
cmake -E chdir build ./tool/CXXCTP_tool --ctp_scripts_paths= $PWD -L .=DBG9 -extra-arg=-I $PWD /include -extra-arg=-L $PWD /build -extra-arg=-lCXXCTP_core -extra-arg=-I../resources ../resources/ReflShapeKind.hpp ../resources/test_typeclass_base1.hpp ../resources/test_typeclass_instance1.hpp ../resources/test.cpp CXXCTP_tool 의 -extra-arg 옵션을 사용하십시오.
-extra-arg=-I $PWD /include -extra-arg=-I $PWD /include/foo -extra-arg=-DMY_DEFINITION=1 -extra-arg=-DONE_MORE_DEFINITION=1예:
cmake -E chdir build ./tool/CXXCTP_tool --ctp_scripts_paths= $PWD -L .=DBG9 -extra-arg=-I $PWD /include -extra-arg=-I../resources ../resources/ReflShapeKind.hpp ../resources/test_typeclass_base1.hpp ../resources/test_typeclass_instance1.hpp ../resources/test.cpp다음 섹션에서는 CXXCTP의 사용법, 사용자 정의 규칙 및 디버깅을 다룹니다.
소스 코드 변환을 위해 사용자 정의 C ++ 스크립트를 작성하거나 기존 스크립트를 사용할 수 있습니다.
CXXCTP는 CTP_Scripts 폴더의 모든 C ++ 스크립트를 사전 주문으로로드합니다.
ctp_scripts의 내용 :
Utils는 스크립트 전에로드해야합니다 (연결 관련). 따라서 폴더 이름 앞에 1_ , 2_ , ...
C ++ 스크립트에서 #include , 파일 시스템 사용, 인터넷에 액세스 등을 사용할 수 있습니다.
디렉토리`
-DENABLE_CLING=TRUE -DINSTALL_CLING=TRUE 로 설치하고 LD_LIBRARY_PATH 설정하십시오
export LD_LIBRARY_PATH=/usr/local/lib/: $LD_LIBRARY_PATH
sudo ldconfigC ++ 주석을 사용하여 CXXCTP에 어떤 작업을 수행 해야하는지 알려줄 수 있습니다.
클래스를 인터페이스로 변형시키고 싶다고 가정합니다.
// Source
class SomeInterfaceName {
int foo1 () {
// ...
};
int foo ();
virtual void foobar ( int & arg1) = 0;
virtual void zoobar ( int & arg2);
virtual ~SomeInterfaceName () = 0 ;
};
// <== will be changed into ==>
// Result
class SomeInterfaceName {
virtual int foo1 () = 0;
virtual int foo () = 0;
virtual void foobar ( int & arg1) = 0;
virtual void zoobar ( int & arg2) = 0;
virtual ~SomeInterfaceName () = 0 ;
}; funccall 작업을 사용하여 소스 코드 변환을 위해 C ++ 스크립트를 실행할 수 있습니다. 스크립트 이름이 make_interface 및 make_removefuncbody (원하는 이름)라고 가정 해 봅시다.
__attribute__ ((annotate( " {gen};{funccall};make_interface;make_removefuncbody " ))) {gen}; - 모든 CXXCTP 주석에 사용되는 키워드.
{funccall}; -CXXCTP에게 CLING을 사용하여 C ++ 스크립트를 실행 해야하는 키워드.
make_interface;make_removefuncbody CXXCTP가 실행할 두 스크립트.
스크립트는 왼쪽 ( make_interface )에서 오른쪽 ( make_removefuncbody )까지 실행됩니다.
일반적으로 긴 C ++ 주석을 쓸 필요가 없으며 C ++ #define 사용하십시오 (또는 공통 정의가있는 내장 헤더 포함).
# define $apply(...)
__attribute__ ((annotate( " {gen};{funccall}; " #__VA_ARGS__)))
class
$apply(make_interface;
make_removefuncbody)
SomeInterfaceName {
virtual ~SomeInterfaceName () = 0 ;
int foo ();
virtual void foobar ( int & arg1) = 0 ;
virtual void zoobar ( int & arg2);
}; 유사한 접근 방식을 사용하여 동일한 class / struct / 등에 여러 소스 코드 변환 단계를 적용 할 수 있습니다.
ctp_scripts 에서 기능이있는 파일을 만듭니다
custom_plugins.cmake.example custom_plugins.cmake 로 복사하십시오
add_ctp_plugin 통해 스크립트 경로를 custom_plugins.cmake 로 추가하십시오.
# first arg - typeclass_instance - script function name
# second arg - script source file
# third arg - script header file
# last arg - path to CMakeLists.txt used to generate script-related files
add_ctp_plugin(
" typeclass_instance "
${CMAKE_CURRENT_SOURCE_DIR} /examples/simple/ctp_scripts/2_scripts/typeclass_instance/typeclass_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR} /examples/simple/ctp_scripts/2_scripts/typeclass_instance/typeclass_instance.hpp
${CMAKE_CURRENT_SOURCE_DIR} /examples/simple/ctp_scripts/2_scripts/typeclass_instance
) 생성 된 파일 ctp_registry.cpp 에 함수 이름이 존재하는지 확인하십시오 (Cling / dev-mode에서 건너 뛸 수 있음)
코드 변환을위한 함수 서명은 cxxctp_callback 과 호환해야합니다.
typedef std::function< const char *(
const cxxctp::parsed_func& func_with_args,
const clang::ast_matchers::MatchFinder::MatchResult& matchResult,
clang::Rewriter& rewriter,
const clang::Decl* decl,
const std::vector<cxxctp::parsed_func>& all_funcs_with_args)> cxxctp_callback;자세한 기능 서명 :
all_funcs_with_args (아래 참조)parsed_func interface 및 foo_with_args 됩니다. 함수 이름을 __VA_ARGS__ 중 하나로 생각하십시오
# define $apply(...)
__attribute__ ((annotate( " {gen};{funccall}; " #__VA_ARGS__))) 예제 make_interface 및 make_removefuncbody 의 예 - 두 가지 함수 이름 :
$apply(make_interface;
make_removefuncbody)코드 생성이 필요한 경우 :
.cxtpl )을 만듭니다. cxtpl_tool https://github.com/blockspacer/cxtpl을 사용하여 파일을 작성하십시오std::string cxtpl_output 만들면 템플릿 렌더링의 결과를 일부 인수로 저장합니다..cxtpl )에서 파일 생성을 포함시킵니다. .cxtpl 은 무엇입니까? .cxtpl 은 C ++ 템플릿 엔진의 파일 확장자 https://github.com/blockspacer/cxtpl입니다.
.cxtpl 추가하는 방법 .cxtpl 파일을 Codegen_files.cmake 에 추가하십시오
참고 : DEV 모드 (예 : CLING 모드)에서 CXTPL_TOOL https://github.com/blockspacer/cxtpl을 사용하여 템플릿에서 파일을 생성하는 것이 좋습니다. 나중에 릴리스 빌드에서 Codegen_files.cmake 에 생성 규칙을 추가 할 수 있습니다.
참고 : codegen 규칙을 공유하는 .cxtpl 및 .cxtpl.h 파일을 모두 제공하는 것을 잊지 마십시오 (버전 제어 시스템에 추가).
.cxtpl 사용하는 방법두 가지 옵션이 있습니다.
.cxtpl 에서 파일을 생성 한 다음 Cling C ++ 스크립트에 포함시킵니다. 컴파일 타임과 유사하지만 프로그램 재 컴파일없이 파일을 다시 생성하거나 변경할 수 있습니다. 파일을 생성하고 스크립트에 포함시킬 수 있습니다. 스크립트를 여러 포함으로 분할합니다..cxtpl 에서 문자열을 생성 한 다음 별도의 집안서로 실행하십시오. 대부분의 경우 첫 번째 옵션을 사용합니다. .cxtpl 사용하는 방법반사 데이터를 템플릿 엔진으로 전달합니다.
cxtpl_tool https://github.com/blockspacer/cxtpl을 사용하여 템플릿에서 파일을 생성하십시오
CXXCTP 스크립트 ( .cpp )에서 :
// see ReflectAST.cpp
reflection::NamespacesTree m_namespaces;
// `node` from AST parser (libtooling)
reflection::ClassInfoPtr structInfo = reflector.ReflectClass(node, &m_namespaces);
// ...
stuct Arguments {
// any custom arguments here ...
std::string arg1 = " arg1... " ;
std::string arg2 = " arg2... " ;
// reflection data here (ClassInfoPtr) ...
};
// ...
std::map<std::string, std::any> cxtpl_params;
{
cxtpl_params[ " Arguments " ] =
std::make_any<Arguments>(Arguments{});
cxtpl_params[ " generator_path " ] =
std::make_any<std::string>( " enum_gen_hpp.cxtpl " );
cxtpl_params[ " generator_includes " ] =
std::make_any<std::vector<std::string>>(
std::vector<std::string>{});
std::string cxtpl_output;
# include " ../../resources/cxtpl/generated/enum_gen_hpp.cxtpl.cpp "
writeToFile (cxtpl_output, gen_hpp_name);
} .cxtpl 템플릿에서 :
const auto arguments = std::any_cast<Arguments>(cxtpl_params.at( " Arguments " ));
std::cout << arguments.arg1; resources/cxtpl/enum_gen_hpp.cxtpl 예로 참조하십시오.
cxxctp_tool은 libtooling을 랩하여 사용자 정의 명령 줄 옵션을 추가합니다.
libtooling (type -help 또는 -help)과 관련된 옵션 :
Generic Options:
-help - Display available options (-help-hidden for more)
-help-list - Display list of available options (-help-list-hidden for more)
-version - Display the version of this program
Use override options:
-extra-arg= < string > - Additional argument to append to the compiler command line
-extra-arg-before= < string > - Additional argument to prepend to the compiler command line
-p= < string > - Build pathCXXCTP_TOOL 관련 옵션 (-HELP가 아닌 유형 -헬프) :
ctp_scripts_paths 통행료가 ctp_scripts subfolder를 검색하는 경로 목록
참고 : ctp_scripts_paths -DENABLE_CLING=TRUE 필요합니다
-L .=DBG9 형식 https://github.com/facebook/folly/blob/master/folly/logging/docs/config.md 형식의 로그 구성입니다
파일과 콘솔 스트림에 모두 쓰는 로그 구성의 예 :
./build/bin/CXXCTP_tool -L " .:=INFO:default:console; default=file:path=y.log,async=true,sync_level=DBG9;console=stream:stream=stderr " -입력 파일의 현재 파일 시스템 경로를 변경하려면 --srcdir .
-출력 파일의 현재 파일 시스템 경로를 변경하려면 --resdir .
예제 (사용자 정의 출력 dir) :
# Remove old generated files
rm -rf gen
rm -rf build/ * generated *
` --version ` to get tool version
` -version ` to get clang version
# Build files to `gen/out` dir
mkdir -p gen/out
cmake -E chdir gen ../build/bin/CXXCTP_tool --resdir= $PWD /gen/out --ctp_scripts_paths= $PWD -L .=DBG9 -extra-arg=-I $PWD /include -extra-arg=-I../resources ../resources/ReflShapeKind.hpp ../resources/test_typeclass_base1.hpp ../resources/test_typeclass_instance1.hpp ../resources/test.cppctp_scripts 디버그하는 방법오래된 빌드 아티팩트와 생성 된 파일을 제거하십시오.
-DBUNDLE_EXAMPLE_SCRIPTS=TRUE 통해 CXXCTP_tool 사용하여 스크립트를 묶으십시오.
custom_plugins.cmake.example 을 통해 스크립트 (플러그인)가 CXXCTP_tool 에 추가되어 있는지 확인하십시오.
프로젝트 당 스크립트 당 비활성화 -DALLOW_PER_PROJECT_CTP_SCRIPTS=FALSE .
스크립트 (플러그인)가 build/tool/CXXCTP_tool --plugins 에 있는지 확인하십시오
CXXCTP_tool 의 시스템에 설치된 버전이 build/tool/CXXCTP_tool (날짜/파일 해시)과 동일한지 확인하십시오.
gdb 에서 CXXCTP_tool 수동으로 실행하십시오.
gdb -ex " r " -ex " bt " --args build/tool/CXXCTP_tool ......... 필요한 모든 경로가 -extra-arg= 인지 확인하십시오.
DBG9 모드로 파일에 로그를 작성하고 .log 파일을 확인하십시오.
CXXCTP는 libtooling을 사용하여 C ++를 구문 분석하고 수정합니다.
Libtooling은 Clang을 기반으로하는 독립형 도구 작성을 지원하는 도서관입니다.
유용한 링크 :
CXXCTP는 CLING을 사용하여 컴파일 타임에 C ++를 실행합니다.
핫 코드 Reload / Repl / Fast C ++ 프로토 타이핑 / 스크립팅 엔진 / JIT 등에 CLING을 사용할 수 있습니다.
유용한 링크 :
sudo apt install clang-format .clang-format 파일을 기반으로 실행하십시오.
find . -regex ' .*.(cpp|hpp|cu|c|h) ' -exec clang-format -style=file -i {} ;유용한 링크 :
.clang-format 파일 https://leimao.github.io/blog/clang-format-quick-tutorial/ 작성.풀 요청을하기 전에 기고 가이드 라인을 읽으십시오.
이 프로젝트는 행동 강령으로 공개됩니다. 이 프로젝트에 참여함으로써 귀하는 그 용어를 준수하는 데 동의합니다.
Flexferrum의 autoprogrammer 로 인해이 프로젝트가 가능합니다.
미디어에서 Flexferrum의 autoprogrammer 관한 기사 :
모든 오픈 소스 구성 요소는 관련 오픈 소스 라이센스에 따라 사용됩니다.
사용 된 오픈 소스 구성 요소 :
라이센스 파일을 참조하십시오
Cmake 파일 패스 스타일 확인, 저장소의 루트에서 run-cmake-format.py를 실행하여 수정할 수 있습니다. Python 3 및 Cmake_format가 필요합니다 (참고 : 현재 Windows에서는 작동하지 않음).
AutoFormatter cmake-format.py 및 run-cmake-format.py 사용하십시오
pip3 install cmake_format
python3 run-cmake-format.py명령 줄에서 특정 cmakelists.txt 파일에서 cmake-format을 사용하려면
python3 -m cmake_format -c cmake-format.py -i CMakeLists.txt공식 비주얼 스튜디오 확장이 있으며 세부 사항은 여기에서 찾을 수 있습니다.
cmake styleguide https://github.com/ruslo/0을 따르십시오
.cxtpl 사용하는 프로젝트