โซลูชันโอเพ่นซอร์สเต็มรูปแบบสำหรับการดัดแปลงและการสร้างซอร์สโค้ด C ++ ลดจำนวนรหัสหม้อไอน้ำในโครงการ C ++ ของคุณ
repo นี้จะย้ายไปที่ https://github.com/blockspacer/flextool โดยเร็วที่สุด
CXXCTP จะเลิกใช้ ชอบ flextool
CXXCTP เป็น transpiler ที่ขยาย C ++ สำหรับการวิปัสสนาใหม่การสะท้อนและการดำเนินการคอมไพล์เวลา
CXXCTP ไม่ได้มีจุดมุ่งหมายเพื่อสร้างชุดการแปลงซอร์สโค้ดที่กำหนดไว้ล่วงหน้า ผู้ใช้สามารถแบ่งปันสคริปต์ C ++ สำหรับการแปลงซอร์สโค้ด
สมมติว่ามีคนที่ใช้ร่วมกันสคริปต์ที่มีประโยชน์เช่น interface.cxx และ enum_to_json.cxx ไปยังชุมชนโอเพนซอร์ซ คุณสามารถใช้พวกเขาในโครงการของคุณได้เพียงแค่วางไว้ในโฟลเดอร์ ctp_scripts
Metaprogramming เป็น "ศิลปะ" ของโปรแกรมการเขียนเพื่อปฏิบัติต่อโปรแกรมอื่น ๆ เป็นข้อมูลของพวกเขา ซึ่งหมายความว่าโปรแกรมสามารถสร้างอ่านวิเคราะห์และแปลงรหัสหรือแม้แต่ตัวเองเพื่อให้ได้โซลูชันที่แน่นอน
หมายเหตุ: โครงการนี้มีให้เหมือนโดยไม่มีการรับประกันใด ๆ (ดูใบอนุญาต)
ทำไมคุณถึงไม่ขยายเสียงดังกึกก้องเพราะมันยังมีคุณสมบัติการทดลองบางอย่าง (ตัวอย่างเช่นโมดูล)
Clang เป็นคอมไพเลอร์ในขณะที่โครงการนี้เป็น transpiler ซึ่งแปลงรหัสเป็นรหัส C ++ ที่ได้มาตรฐานโดยไม่จำเป็นต้องแก้ไข LLVM/ASSEMBLY
เนื่องจากเอาต์พุตของเครื่องมือคือรหัส C ++ คุณสามารถรวบรวมรหัส transpiled โดยใช้ emscripten ใช้ตัววิเคราะห์รหัสสแตติกวิ่งรหัสภายในการยึด ฯลฯ
CXXCTP ช่วยให้คุณสร้างและแชร์สคริปต์สำหรับ
ในการพัฒนาดูตัวอย่าง ปัจจุบันรองรับ Linux เท่านั้น
โปรดทราบว่าคุณสามารถเรียกใช้คอนเทนเนอร์ Linux ภายใต้ Windows/Mac/etc
// 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 --remoteติดตั้งและกำหนดค่า Docker: https://medium.com/@saniaky/configure-docker-to-use-a-host-proxy-e88bd988c0aa
รหัสโคลน (ดังกล่าวข้างต้น) และ cd เป็นโคลน DIR
หมายเหตุ: คุณอาจต้องการสร้างอิมเมจนักเทียบท่าด้วย --build-arg NO_SSL="False" อ่านความคิดเห็นใน 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 กำหนดค่าพร็อกซี & cacert_path ใน ~/.conan/conan.conf ดู 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=bincraftersหากคุณต้องการตั้งค่า Corp 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.shติดตั้งไลบรารี cxtpl https://github.com/blockspacer/cxtpl
ติดตั้ง cxtpl_tool https://github.com/blockspacer/cxtpl#how-to-build
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.shติดตั้ง deps ใน cxtpl https://github.com/blockspacer/cxtpl#how-to-build
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
เรียกใช้สคริปต์ Bash/install_folly.sh จาก https://github.com/blockspacer/cxtpl หรือ Patch Folly ด้วยตนเองสำหรับการสนับสนุน Clang (แทนที่ folly_use_jemalloc ด้วย folly_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 --pluginsหากคุณติดตั้ง cxxctp_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 และ. so/.dll libs โดย -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 ใช้ตัวเลือก -extra-arg ของ CXXCTP_tool :
-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 โหลดสคริปต์ C ++ ทั้งหมดจากโฟลเดอร์ CTP_Scripts ในลำดับพจนานุกรม
ตัวอย่างเนื้อหาของ ctp_scripts:
Utils ต้องโหลดก่อนสคริปต์ (เกี่ยวข้องกับการยึด) ดังนั้นเราจึงเพิ่ม 1_ , 2_ , ... ก่อนชื่อโฟลเดอร์ (ดูด้านบน)
คุณสามารถใช้ #include ใช้ระบบไฟล์เข้าถึงอินเทอร์เน็ต ฯลฯ ในสคริปต์ C ++
ไดเรกทอรี
ติดตั้งด้วย -DENABLE_CLING=TRUE -DINSTALL_CLING=TRUE และตั้งค่า LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib/: $LD_LIBRARY_PATH
sudo ldconfigคุณสามารถใช้คำอธิบายประกอบ C ++ เพื่อบอก CXXCTP ว่าจะต้องดำเนินการอย่างไร
สมมติว่าเราต้องการ morph คลาสเป็นอินเทอร์เฟซ:
// 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 ว่าจะต้องดำเนินการสคริปต์ 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
ผนวกพา ธ สคริปต์ของคุณไปที่ custom_plugins.cmake ผ่าน add_ctp_plugin :
# 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/cxtplstd::string cxtpl_output ซึ่งจะจัดเก็บผลลัพธ์ของการแสดงผลแม่แบบด้วยอาร์กิวเมนต์บางอย่าง.cxtpl ) ภายในฟังก์ชั่นของคุณ .cxtpl คืออะไร .cxtpl เป็นส่วนขยายไฟล์สำหรับเอ็นจินเทมเพลต C ++ https://github.com/blockspacer/cxtpl
.cxtpl ในเวลาคอมไพล์ (cmake) เพิ่มไฟล์ .cxtpl ของคุณลงใน Codegen_files.cmake
หมายเหตุ: ในโหมด dev (เช่นโหมดยึด) อาจเป็นความคิดที่ดีที่จะสร้างไฟล์จากเทมเพลตโดยใช้ cxtpl_tool https://github.com/blockspacer/cxtpl คุณสามารถเพิ่มกฎการสร้างลงใน Codegen_files.cmake ในภายหลังในการสร้าง
หมายเหตุ: อย่าลืมให้ทั้งไฟล์ .cxtpl และ .cxtpl.h ด้วยกฎ codegen ที่ใช้ร่วมกัน (เพิ่มไปยังระบบควบคุมเวอร์ชัน)
.cxtpl ที่รันไทม์ด้วยการยึดคุณมีสองตัวเลือก:
.cxtpl ของคุณจากนั้นรวมไว้ในสคริปต์ยึด C ++ คล้ายกับการรวบรวมเวลา แต่คุณสามารถสร้างใหม่หรือเปลี่ยนไฟล์โดยไม่ต้องคอมไพล์โปรแกรมใหม่ โปรดทราบว่าเป็นไปได้ที่จะสร้างไฟล์และรวมไว้ในสคริปต์ของคุณ เพียงแยกสคริปต์ออกเป็นหลายรายการรวม.cxtpl ของคุณจากนั้นเรียกใช้ในล่ามที่แยกต่างหาก ในกรณีส่วนใหญ่คุณจะใช้ตัวเลือกแรก .cxtpl กับ cxxctpผ่านข้อมูลการสะท้อนกลับไปยังเอ็นจิ้นเทมเพลต
สร้างไฟล์จากเทมเพลตโดยใช้ 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 pathตัวเลือกที่เกี่ยวข้องกับ cxxctp_tool (ประเภท -help, not -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 เพื่อเปลี่ยนเส้นทางระบบไฟล์ปัจจุบันสำหรับไฟล์เอาต์พุต
ตัวอย่าง (เอาต์พุตแบบกำหนดเอง):
# 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ลบสิ่งประดิษฐ์สร้างเก่าและไฟล์ที่สร้างขึ้น
มัดสคริปต์ของคุณด้วย CXXCTP_tool ผ่าน -DBUNDLE_EXAMPLE_SCRIPTS=TRUE
ตรวจสอบให้แน่ใจว่ามีการเพิ่มสคริปต์ (ปลั๊กอิน) ของคุณลงใน CXXCTP_tool ผ่าน custom_plugins.cmake.example
ปิดการใช้งานสคริปต์ต่อโครงการ -DALLOW_PER_PROJECT_CTP_SCRIPTS=FALSE
ตรวจสอบว่าสคริปต์ของคุณ (ปลั๊กอิน) อยู่ใน build/tool/CXXCTP_tool --plugins
ตรวจสอบว่ารุ่นที่ติดตั้งระบบของ CXXCTP_tool นั้นเหมือนกับ build/tool/CXXCTP_tool (ตามวันที่/ไฟล์แฮช)
เรียกใช้ CXXCTP_tool ด้วยตนเองภายใต้ gdb :
gdb -ex " r " -ex " bt " --args build/tool/CXXCTP_tool ......... ตรวจสอบว่าเส้นทางที่จำเป็นทั้งหมดอยู่ใน -extra-arg=
สร้างบันทึกไปยังไฟล์ในโหมด DBG9 และตรวจสอบไฟล์. .log
CXXCTP ใช้ libtooling เพื่อแยกวิเคราะห์และแก้ไข C ++
Libtooling เป็นห้องสมุดที่สนับสนุนการเขียนเครื่องมือแบบสแตนด์อโลนโดยใช้ Clang
ลิงค์ที่มีประโยชน์:
CXXCTP ใช้การยึดเพื่อดำเนินการ C ++ ในเวลาคอมไพล์
คุณสามารถใช้ cling สำหรับรหัสร้อนโหลด / repl / fast c ++ prototyping / scripting engine / jit / ฯลฯ
ลิงค์ที่มีประโยชน์:
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/โปรดอ่านแนวทางการสนับสนุนของเราก่อนที่จะทำการร้องขอการดึงของคุณ
โปรดทราบว่าโครงการนี้ได้รับการปล่อยตัวด้วยจรรยาบรรณ โดยการเข้าร่วมในโครงการนี้คุณตกลงที่จะปฏิบัติตามข้อกำหนดของมัน
โครงการนั้นเป็นไปได้เนื่องจาก autoprogrammer ของ Flexferrum
บทความเกี่ยวกับ autoprogrammer ของ Flexferrum ในสื่อ:
ส่วนประกอบโอเพ่นซอร์สทั้งหมดใช้ภายใต้ใบอนุญาตโอเพ่นซอร์สที่เกี่ยวข้อง
ส่วนประกอบโอเพ่นซอร์สที่ใช้:
ดูไฟล์ใบอนุญาต
การตรวจสอบสไตล์ CMake Pass สามารถแก้ไขได้โดยเรียกใช้ 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หากต้องการใช้ cmake-format บนไฟล์ cmakelists.txt เฉพาะในบรรทัดคำสั่งรัน
python3 -m cmake_format -c cmake-format.py -i CMakeLists.txtมีส่วนขยาย Visual Studio อย่างเป็นทางการรายละเอียดที่สามารถพบได้ที่นี่
ติดตาม cmake styleguide https://github.com/ruslo/0
.cxtpl