diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml new file mode 100644 index 000000000..df96b70db --- /dev/null +++ b/.gitlab/.gitlab-ci.yml @@ -0,0 +1,33 @@ +.job_rules_template: &job_rules + stage: build + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event" + && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"' + - if: '$CI_PIPELINE_SOURCE == "merge_request_event" + && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "upstream"' + +build_in_mac: + tags: + - mac + - shell + <<: *job_rules + script: + - ./build_macos.sh release + +build_in_ubuntu: + image: cmake:3.23 # you can build it with Dockerfile offered in this project + tags: + - ubuntu + - docker + <<: *job_rules + script: + - ./build_linux.sh release + +build_in_windows: + tags: + - windows + - shell + <<: *job_rules + script: + - ./build_windows.bat + diff --git a/.gitlab/Dockerfile b/.gitlab/Dockerfile new file mode 100644 index 000000000..ad951bf2a --- /dev/null +++ b/.gitlab/Dockerfile @@ -0,0 +1,15 @@ +FROM ubuntu:20.04 +RUN apt update +RUN DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai apt install -y \ + libxrandr-dev libxrender-dev libxinerama-dev libxcursor-dev \ + libxi-dev libglvnd-dev libvulkan-dev clang libc++-dev libglew-dev \ + libglfw3-dev vulkan-validationlayers mesa-vulkan-drivers wget \ + build-essential libssl-dev +RUN cd && wget https://cmake.org/files/v3.23/cmake-3.23.1.tar.gz \ + && tar xf cmake-3.23.1.tar.gz \ + && cd cmake-3.23.1 \ + && ./bootstrap \ + && make \ + && make install \ + && ln -s /usr/local/bin/cmake /usr/bin/cmake + diff --git a/CMakeLists.txt b/CMakeLists.txt index fdd31cc19..97474124f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.19 FATAL_ERROR) -project(Pilot VERSION 0.1.0) +project(Piccolo VERSION 0.1.0) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -16,8 +16,8 @@ if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) ) endif() -set(PILOT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -set(CMAKE_INSTALL_PREFIX "${PILOT_ROOT_DIR}/bin") +set(PICCOLO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(CMAKE_INSTALL_PREFIX "${PICCOLO_ROOT_DIR}/bin") set(BINARY_ROOT_DIR "${CMAKE_INSTALL_PREFIX}/") diff --git a/README.md b/README.md index 967d982ff..34dd722c7 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ | Build Type | Status | | :---------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | -| **Build Windows** | [![Build Windows](https://github.com/BoomingTech/Pilot/actions/workflows/build_windows.yml/badge.svg)](https://github.com/BoomingTech/Pilot/actions/workflows/build_windows.yml) | -| **Build Linux** | [![Build Linux](https://github.com/BoomingTech/Pilot/actions/workflows/build_linux.yml/badge.svg)](https://github.com/BoomingTech/Pilot/actions/workflows/build_linux.yml) | -| **Build macOS** | [![Build macOS](https://github.com/BoomingTech/Pilot/actions/workflows/build_macos.yml/badge.svg)](https://github.com/BoomingTech/Pilot/actions/workflows/build_macos.yml) | +| **Build Windows** | [![Build Windows](https://github.com/BoomingTech/Piccolo/actions/workflows/build_windows.yml/badge.svg)](https://github.com/BoomingTech/Piccolo/actions/workflows/build_windows.yml) | +| **Build Linux** | [![Build Linux](https://github.com/BoomingTech/Piccolo/actions/workflows/build_linux.yml/badge.svg)](https://github.com/BoomingTech/Piccolo/actions/workflows/build_linux.yml) | +| **Build macOS** | [![Build macOS](https://github.com/BoomingTech/Piccolo/actions/workflows/build_macos.yml/badge.svg)](https://github.com/BoomingTech/Piccolo/actions/workflows/build_macos.yml) | ## Prerequisites @@ -96,3 +96,14 @@ For Windows: cmake -DCMAKE_TRY_COMPILE_TARGET_TYPE="STATIC_LIBRARY" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S . -B compile_db_temp -G "Unix Makefiles" copy compile_db_temp\compile_commands.json . ``` + +### Using Physics Debug Renderer +Currently Physics Debug Renderer is only available on Windows. You can use the following command to generate the solution with the debugger project. + +``` powershell +cmake -S . -B build -DENABLE_PHYSICS_DEBUG_RENDERER=ON +``` + +Note: +1. Please clean the build directory before regenerating the solution. We've encountered building problems in regenerating directly with previous CMakeCache. +2. Physics Debug Renderer will run when you start PiccoloEditor. We've synced the camera position between both scenes. But the initial camera mode in Physics Debug Renderer is wrong. Scrolling down the mouse wheel once will change the camera of Physics Debug Renderer to the correct mode. diff --git a/cmake/ShaderCompile.cmake b/cmake/ShaderCompile.cmake index 3d5576d8c..7a2b758b1 100644 --- a/cmake/ShaderCompile.cmake +++ b/cmake/ShaderCompile.cmake @@ -29,7 +29,7 @@ function(compile_shader SHADERS TARGET_NAME SHADER_INCLUDE_FOLDER GENERATED_DIR add_custom_command( OUTPUT ${CPP_FILE} COMMAND ${CMAKE_COMMAND} -DPATH=${SPV_FILE} -DHEADER="${CPP_FILE}" - -DGLOBAL="${GLOBAL_SHADER_VAR}" -P "${PILOT_ROOT_DIR}/cmake/GenerateShaderCPPFile.cmake" + -DGLOBAL="${GLOBAL_SHADER_VAR}" -P "${PICCOLO_ROOT_DIR}/cmake/GenerateShaderCPPFile.cmake" DEPENDS ${SPV_FILE} WORKING_DIRECTORY "${working_dir}") diff --git a/engine/.gitignore b/engine/.gitignore index f26e900ad..8a14e1f0b 100644 --- a/engine/.gitignore +++ b/engine/.gitignore @@ -1,2 +1,2 @@ generated/ -!bin/ \ No newline at end of file +bin/ \ No newline at end of file diff --git a/engine/3rdparty/JoltPhysics/Jolt/Core/Memory.cpp b/engine/3rdparty/JoltPhysics/Jolt/Core/Memory.cpp index fd658ff1b..0f3bf057d 100644 --- a/engine/3rdparty/JoltPhysics/Jolt/Core/Memory.cpp +++ b/engine/3rdparty/JoltPhysics/Jolt/Core/Memory.cpp @@ -10,6 +10,10 @@ JPH_SUPPRESS_WARNINGS_STD_BEGIN JPH_SUPPRESS_WARNINGS_STD_END #include +#if defined(__APPLE__) +#include +#endif + JPH_NAMESPACE_BEGIN void *AlignedAlloc(size_t inSize, size_t inAlignment) @@ -19,6 +23,14 @@ void *AlignedAlloc(size_t inSize, size_t inAlignment) return _aligned_malloc(inSize, inAlignment); #elif defined(JPH_PLATFORM_ANDROID) return memalign(inAlignment, AlignUp(inSize, inAlignment)); +#elif defined(__APPLE__) && (defined(MAC_OS_X_VERSION_10_16)) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_16 + // For C++14, usr/include/malloc/_malloc.h declares aligned_alloc()) only + // with the MacOSX11.0 SDK in Xcode 12 (which is what adds + // MAC_OS_X_VERSION_10_16), even though the function is marked + // availabe for 10.15. That's why the preprocessor checks for 10.16 but + // the __builtin_available checks for 10.15. + // People who use C++17 could call aligned_alloc with the 10.15 SDK already. + return aligned_alloc(inAlignment, AlignUp(inSize, inAlignment)); #else return std::aligned_alloc(inAlignment, AlignUp(inSize, inAlignment)); #endif diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 1f79339cd..daf97be37 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -1,5 +1,5 @@ -set(ENGINE_ROOT_DIR "${PILOT_ROOT_DIR}/engine") +set(ENGINE_ROOT_DIR "${PICCOLO_ROOT_DIR}/engine") set(THIRD_PARTY_DIR "${ENGINE_ROOT_DIR}/3rdparty") set(ENGINE_ASSET_DIR "/asset") @@ -22,7 +22,7 @@ endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_compile_options("/MP") - set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT PilotEditor) + set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT PiccoloEditor) endif() set(vulkan_include ${THIRD_PARTY_DIR}/VulkanSDK/include) @@ -30,34 +30,36 @@ set(vulkan_include ${THIRD_PARTY_DIR}/VulkanSDK/include) if(WIN32) set(vulkan_lib ${THIRD_PARTY_DIR}/VulkanSDK/lib/Win32/vulkan-1.lib) set(glslangValidator_executable ${THIRD_PARTY_DIR}/VulkanSDK/bin/Win32/glslangValidator.exe) - add_compile_definitions("PILOT_VK_LAYER_PATH=${THIRD_PARTY_DIR}/VulkanSDK/bin/Win32") + add_compile_definitions("PICCOLO_VK_LAYER_PATH=${THIRD_PARTY_DIR}/VulkanSDK/bin/Win32") elseif(UNIX) if(APPLE) set(vulkan_lib ${THIRD_PARTY_DIR}/VulkanSDK/lib/MacOS/libvulkan.1.dylib) set(glslangValidator_executable ${THIRD_PARTY_DIR}/VulkanSDK/bin/MacOS/glslangValidator) - add_compile_definitions("PILOT_VK_LAYER_PATH=${THIRD_PARTY_DIR}/VulkanSDK/bin/MacOS") - add_compile_definitions("PILOT_VK_ICD_FILENAMES=${THIRD_PARTY_DIR}/VulkanSDK/bin/MacOS/MoltenVK_icd.json") + add_compile_definitions("PICCOLO_VK_LAYER_PATH=${THIRD_PARTY_DIR}/VulkanSDK/bin/MacOS") + add_compile_definitions("PICCOLO_VK_ICD_FILENAMES=${THIRD_PARTY_DIR}/VulkanSDK/bin/MacOS/MoltenVK_icd.json") else() set(vulkan_lib ${THIRD_PARTY_DIR}/VulkanSDK/lib/Linux/libvulkan.so.1) set(glslangValidator_executable ${THIRD_PARTY_DIR}/VulkanSDK/bin/Linux/glslangValidator) - add_compile_definitions("PILOT_VK_LAYER_PATH=${THIRD_PARTY_DIR}/VulkanSDK/bin/Linux") + add_compile_definitions("PICCOLO_VK_LAYER_PATH=${THIRD_PARTY_DIR}/VulkanSDK/bin/Linux") endif() else() message(FATAL_ERROR "Unknown Platform") endif() -set(SHADER_COMPILE_TARGET PilotShaderCompile) +set(SHADER_COMPILE_TARGET PiccoloShaderCompile) add_subdirectory(shader) add_subdirectory(3rdparty) add_subdirectory(source/runtime) add_subdirectory(source/editor) +add_subdirectory(source/meta_parser) #add_subdirectory(source/test) -set(CODEGEN_TARGET "PilotPreCompile") +set(CODEGEN_TARGET "PiccoloPreCompile") include(source/precompile/precompile.cmake) set_target_properties("${CODEGEN_TARGET}" PROPERTIES FOLDER "Engine" ) -add_dependencies(PilotRuntime "${CODEGEN_TARGET}") +add_dependencies(PiccoloRuntime "${CODEGEN_TARGET}") +add_dependencies("${CODEGEN_TARGET}" "PiccoloParser") diff --git a/engine/asset/level/1-1.level.json b/engine/asset/level/1-1.level.json index e8bb5f4fe..23c2ccb25 100644 --- a/engine/asset/level/1-1.level.json +++ b/engine/asset/level/1-1.level.json @@ -1,5 +1,9 @@ { - "gravity": 15, + "gravity": { + "x": 0, + "y": 0, + "z": -15 + }, "character_name": "Player", "objects": [ { diff --git a/engine/asset/objects/character/player/components/mesh/_textures/xiaobairen1k_BaseColor.tga b/engine/asset/objects/character/player/components/mesh/_textures/xiaobairen1k_BaseColor.tga index b968917d1..3f4c9a81c 100644 Binary files a/engine/asset/objects/character/player/components/mesh/_textures/xiaobairen1k_BaseColor.tga and b/engine/asset/objects/character/player/components/mesh/_textures/xiaobairen1k_BaseColor.tga differ diff --git a/engine/asset/objects/character/player/player.object.json b/engine/asset/objects/character/player/player.object.json index 27835ec58..476288ae6 100644 --- a/engine/asset/objects/character/player/player.object.json +++ b/engine/asset/objects/character/player/player.object.json @@ -97,7 +97,7 @@ }, "$typeName": "PhysicsControllerConfig" }, - "jump_height": 0, + "jump_height": 1, "max_move_speed_ratio": 1, "max_sprint_speed_ratio": 2, "move_acceleration": 2, diff --git a/engine/asset/objects/environment/stairs/stairs.object.json b/engine/asset/objects/environment/stairs/stairs.object.json index dd0d153d3..f0fdf1c48 100644 --- a/engine/asset/objects/environment/stairs/stairs.object.json +++ b/engine/asset/objects/environment/stairs/stairs.object.json @@ -1,58 +1,269 @@ { - "components": [ - { - "$context": { - "transform": { - "position": { - "x": 5.8713598251342773, - "y": -1.5180200338363647, - "z": 0 - }, - "rotation": { - "w": 1, - "x": 0, - "y": 0, - "z": 0 - }, - "scale": { - "x": 1, - "y": 1, - "z": 1 - } + "components": [ + { + "$context": { + "transform": { + "position": { + "x": 5.8713598251342773, + "y": -1.5180200338363647, + "z": 0 + }, + "rotation": { + "w": 1, + "x": 0, + "y": 0, + "z": 0 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + } + } + }, + "$typeName": "TransformComponent" + }, + { + "$context": { + "mesh_res": { + "sub_meshes": [ + { + "material": "asset/objects/environment/_material/gold.material.json", + "obj_file_ref": "asset/objects/environment/stairs/components/mesh/stairs.obj", + "transform": { + "position": { + "x": 0, + "y": 0, + "z": 0 + }, + "rotation": { + "w": 1, + "x": 0, + "y": 0, + "z": 0 + }, + "scale": { + "x": 1, + "y": 1, + "z": 1 + } + } + } + ] + } + }, + "$typeName": "MeshComponent" + }, + { + "$typeName": "RigidBodyComponent", + "$context": { + "rigidbody_res": { + "actor_type": 1, + "inverse_mass": 0, + "shapes": [ + { + "geometry": { + "$context": { + "half_extents": { + "x": 0.125, + "y": 1, + "z": 0.125 + } + }, + "$typeName": "Box" + }, + "local_transform": { + "position": { + "x": 0.875, + "y": 0, + "z": 0.125 + }, + "rotate": {}, + "scale": { + "x": 1, + "y": 1, + "z": 1 + } + } + }, + { + "local_transform": { + "position": { + "x": 0.625, + "y": 0, + "z": 0.25 + }, + "rotate": {}, + "scale": { + "x": 1, + "y": 1, + "z": 1 + } + }, + "geometry": { + "$context": { + "half_extents": { + "x": 0.125, + "y": 1, + "z": 0.25 + } + }, + "$typeName": "Box" + } + }, + { + "local_transform": { + "position": { + "x": 0.375, + "y": 0, + "z": 0.375 + }, + "rotate": {}, + "scale": { + "x": 1, + "y": 1, + "z": 1 } + }, + "geometry": { + "$context": { + "half_extents": { + "x": 0.125, + "y": 1, + "z": 0.375 + } + }, + "$typeName": "Box" + } }, - "$typeName": "TransformComponent" - }, - { - "$context": { - "mesh_res": { - "sub_meshes": [ - { - "material": "asset/objects/environment/_material/gold.material.json", - "obj_file_ref": "asset/objects/environment/stairs/components/mesh/stairs.obj", - "transform": { - "position": { - "x": 0, - "y": 0, - "z": 0 - }, - "rotation": { - "w": 1, - "x": 0, - "y": 0, - "z": 0 - }, - "scale": { - "x": 1, - "y": 1, - "z": 1 - } - } - } - ] + { + "local_transform": { + "position": { + "x": 0.125, + "y": 0, + "z": 0.5 + }, + "rotate": {}, + "scale": { + "x": 1, + "y": 1, + "z": 1 } + }, + "geometry": { + "$context": { + "half_extents": { + "x": 0.125, + "y": 1, + "z": 0.5 + } + }, + "$typeName": "Box" + } }, - "$typeName": "MeshComponent" + { + "local_transform": { + "position": { + "x": -0.125, + "y": 0, + "z": 0.625 + }, + "rotate": {}, + "scale": { + "x": 1, + "y": 1, + "z": 1 + } + }, + "geometry": { + "$context": { + "half_extents": { + "x": 0.125, + "y": 1, + "z": 0.625 + } + }, + "$typeName": "Box" + } + }, + { + "local_transform": { + "position": { + "x": -0.375, + "y": 0, + "z": 0.75 + }, + "rotate": {}, + "scale": { + "x": 1, + "y": 1, + "z": 1 + } + }, + "geometry": { + "$context": { + "half_extents": { + "x": 0.125, + "y": 1, + "z": 0.75 + } + }, + "$typeName": "Box" + } + }, + { + "local_transform": { + "position": { + "x": -0.625, + "y": 0, + "z": 0.875 + }, + "rotate": {}, + "scale": { + "x": 1, + "y": 1, + "z": 1 + } + }, + "geometry": { + "$context": { + "half_extents": { + "x": 0.125, + "y": 1, + "z": 0.875 + } + }, + "$typeName": "Box" + } + }, + { + "local_transform": { + "position": { + "x": -0.875, + "y": 0, + "z": 1 + }, + "rotate": {}, + "scale": { + "x": 1, + "y": 1, + "z": 1 + } + }, + "geometry": { + "$context": { + "half_extents": { + "x": 0.125, + "y": 1, + "z": 1 + } + }, + "$typeName": "Box" + } + } + ] } - ] + } + } + ] } \ No newline at end of file diff --git a/engine/bin/.gitignore b/engine/bin/.gitignore deleted file mode 100644 index ae8511d82..000000000 --- a/engine/bin/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -!*.exe -!*.dll -!*.dylib -!x64/ -!macOS/ -!Linux/ -*.json \ No newline at end of file diff --git a/engine/bin/Linux/meta_parser b/engine/bin/Linux/meta_parser deleted file mode 100755 index 0bd7ab19e..000000000 Binary files a/engine/bin/Linux/meta_parser and /dev/null differ diff --git a/engine/bin/Windows/x64/.gitignore b/engine/bin/Windows/x64/.gitignore deleted file mode 100644 index c280db72c..000000000 --- a/engine/bin/Windows/x64/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -!*.exe -!*.dll -!*.dylib diff --git a/engine/bin/Windows/x64/meta_parser.exe b/engine/bin/Windows/x64/meta_parser.exe deleted file mode 100644 index f42e9d56c..000000000 Binary files a/engine/bin/Windows/x64/meta_parser.exe and /dev/null differ diff --git a/engine/bin/macOS/meta_parser b/engine/bin/macOS/meta_parser deleted file mode 100755 index acfdb0610..000000000 Binary files a/engine/bin/macOS/meta_parser and /dev/null differ diff --git a/engine/configs/deployment/PilotEditor.ini b/engine/configs/deployment/PiccoloEditor.ini similarity index 56% rename from engine/configs/deployment/PilotEditor.ini rename to engine/configs/deployment/PiccoloEditor.ini index a021b4566..bc018cf02 100644 --- a/engine/configs/deployment/PilotEditor.ini +++ b/engine/configs/deployment/PiccoloEditor.ini @@ -1,9 +1,9 @@ BinaryRootFolder=. AssetFolder=asset SchemaFolder=schema -BigIconFile=resource/PilotEditorBigIcon.png -SmallIconFile=resource/PilotEditorSmallIcon.png -FontFile=resource/PilotEditorFont.TTF +BigIconFile=resource/PiccoloEditorBigIcon.png +SmallIconFile=resource/PiccoloEditorSmallIcon.png +FontFile=resource/PiccoloEditorFont.TTF DefaultWorld=asset/world/hello.world.json GlobalRenderingRes=asset/global/rendering.global.json JoltAssetFolder=jolt-asset \ No newline at end of file diff --git a/engine/configs/development/PilotEditor.ini b/engine/configs/development/PiccoloEditor.ini similarity index 59% rename from engine/configs/development/PilotEditor.ini rename to engine/configs/development/PiccoloEditor.ini index 5420ea11b..0317efd63 100644 --- a/engine/configs/development/PilotEditor.ini +++ b/engine/configs/development/PiccoloEditor.ini @@ -1,9 +1,9 @@ BinaryRootFolder=../../../../../bin AssetFolder=asset SchemaFolder=schema -BigIconFile=resource/PilotEditorBigIcon.png -SmallIconFile=resource/PilotEditorSmallIcon.png -FontFile=resource/PilotEditorFont.TTF +BigIconFile=resource/PiccoloEditorBigIcon.png +SmallIconFile=resource/PiccoloEditorSmallIcon.png +FontFile=resource/PiccoloEditorFont.TTF DefaultWorld=asset/world/hello.world.json GlobalRenderingRes=asset/global/rendering.global.json JoltAssetFolder=jolt-asset \ No newline at end of file diff --git a/engine/shader/CMakeLists.txt b/engine/shader/CMakeLists.txt index 4581be00e..562c2f987 100644 --- a/engine/shader/CMakeLists.txt +++ b/engine/shader/CMakeLists.txt @@ -26,7 +26,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${GENERATED_SHADER_FOLDER}/spv) file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${GENERATED_SHADER_FOLDER}/spv) endif() -include(${PILOT_ROOT_DIR}/cmake/ShaderCompile.cmake) +include(${PICCOLO_ROOT_DIR}/cmake/ShaderCompile.cmake) compile_shader( "${SHADER_FILES}" @@ -60,7 +60,7 @@ set_target_properties("${TARGET_NAME}" PROPERTIES FOLDER "Engine" ) # set_target_properties(${HEADER_NAME} PROPERTIES FOLDER "Shaders/generated" ) # # Add the custom target like a dependencies of the project -# add_dependencies(${PILOT_NAME} ${HEADER_NAME}) +# add_dependencies(${PICCOLO_NAME} ${HEADER_NAME}) # message(STATUS "Generating build commands for ${SHADER}") # endforeach() diff --git a/engine/source/editor/CMakeLists.txt b/engine/source/editor/CMakeLists.txt index 662dd1e42..460cbf5b0 100644 --- a/engine/source/editor/CMakeLists.txt +++ b/engine/source/editor/CMakeLists.txt @@ -1,26 +1,26 @@ -set(TARGET_NAME PilotEditor) +set(TARGET_NAME PiccoloEditor) file(GLOB EDITOR_HEADERS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) file(GLOB EDITOR_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) -file(GLOB EDITOR_RESOURCE CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/resource/PilotEditor.rc) +file(GLOB EDITOR_RESOURCE CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/resource/PiccoloEditor.rc) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${EDITOR_HEADERS} ${EDITOR_SOURCES} ${EDITOR_RESOURCE}) add_executable(${TARGET_NAME} ${EDITOR_HEADERS} ${EDITOR_SOURCES} ${EDITOR_RESOURCE}) -add_compile_definitions("PILOT_ROOT_DIR=${BINARY_ROOT_DIR}") +add_compile_definitions("PICCOLO_ROOT_DIR=${BINARY_ROOT_DIR}") target_include_directories( ${TARGET_NAME} PUBLIC $ ) -set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD 17 OUTPUT_NAME "PilotEditor") +set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD 17 OUTPUT_NAME "PiccoloEditor") set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Engine") target_compile_options(${TARGET_NAME} PUBLIC "$<$:/WX->") -target_link_libraries(${TARGET_NAME} PilotRuntime) +target_link_libraries(${TARGET_NAME} PiccoloRuntime) set(POST_BUILD_COMMANDS COMMAND ${CMAKE_COMMAND} -E make_directory "${BINARY_ROOT_DIR}" @@ -42,3 +42,7 @@ if(ENABLE_PHYSICS_DEBUG_RENDERER) endif() add_custom_command(TARGET ${TARGET_NAME} ${POST_BUILD_COMMANDS}) + +#precompile +#set global vari used by precompile +set(PICCOLO_EDITOR_HEADS “${EDITOR_HEADERS}” PARENT_SCOPE) diff --git a/engine/source/editor/include/axis.h b/engine/source/editor/include/axis.h index 36a5a64ce..8c9ff662d 100644 --- a/engine/source/editor/include/axis.h +++ b/engine/source/editor/include/axis.h @@ -3,7 +3,7 @@ #include "runtime/function/render/render_entity.h" #include "runtime/function/render/render_type.h" -namespace Pilot +namespace Piccolo { class EditorTranslationAxis : public RenderEntity { @@ -25,4 +25,4 @@ namespace Pilot EditorScaleAxis(); RenderMeshData m_mesh_data; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/include/editor.h b/engine/source/editor/include/editor.h index 19116e9fe..a7ab82f80 100644 --- a/engine/source/editor/include/editor.h +++ b/engine/source/editor/include/editor.h @@ -4,26 +4,26 @@ #include -namespace Pilot +namespace Piccolo { class EditorUI; - class PilotEngine; + class PiccoloEngine; - class PilotEditor + class PiccoloEditor { friend class EditorUI; public: - PilotEditor(); - virtual ~PilotEditor(); + PiccoloEditor(); + virtual ~PiccoloEditor(); - void initialize(PilotEngine* engine_runtime); + void initialize(PiccoloEngine* engine_runtime); void clear(); void run(); protected: std::shared_ptr m_editor_ui; - PilotEngine* m_engine_runtime{ nullptr }; + PiccoloEngine* m_engine_runtime{ nullptr }; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/include/editor_file_service.h b/engine/source/editor/include/editor_file_service.h index 7bbf304cd..949fbe8a9 100644 --- a/engine/source/editor/include/editor_file_service.h +++ b/engine/source/editor/include/editor_file_service.h @@ -4,7 +4,7 @@ #include #include -namespace Pilot +namespace Piccolo { class EditorFileNode; using EditorFileNodeArray = std::vector>; @@ -36,4 +36,4 @@ namespace Pilot void buildEngineFileTree(); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/include/editor_global_context.h b/engine/source/editor/include/editor_global_context.h index dc7a50c01..e57393f70 100644 --- a/engine/source/editor/include/editor_global_context.h +++ b/engine/source/editor/include/editor_global_context.h @@ -1,12 +1,12 @@ #pragma once -namespace Pilot +namespace Piccolo { struct EditorGlobalContextInitInfo { class WindowSystem* window_system; class RenderSystem* render_system; - class PilotEngine* engine_runtime; + class PiccoloEngine* engine_runtime; }; class EditorGlobalContext @@ -16,7 +16,7 @@ namespace Pilot class EditorInputManager* m_input_manager {nullptr}; class RenderSystem* m_render_system {nullptr}; class WindowSystem* m_window_system {nullptr}; - class PilotEngine* m_engine_runtime {nullptr}; + class PiccoloEngine* m_engine_runtime {nullptr}; public: void initialize(const EditorGlobalContextInitInfo& init_info); @@ -24,4 +24,4 @@ namespace Pilot }; extern EditorGlobalContext g_editor_global_context; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/editor/include/editor_input_manager.h b/engine/source/editor/include/editor_input_manager.h index 46934baf0..a2c2e0822 100644 --- a/engine/source/editor/include/editor_input_manager.h +++ b/engine/source/editor/include/editor_input_manager.h @@ -6,9 +6,9 @@ #include -namespace Pilot +namespace Piccolo { - class PilotEditor; + class PiccoloEditor; enum class EditorCommand : unsigned int { @@ -66,4 +66,4 @@ namespace Pilot size_t m_cursor_on_axis {3}; unsigned int m_editor_command {0}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/include/editor_scene_manager.h b/engine/source/editor/include/editor_scene_manager.h index 45abad829..18541b6d9 100644 --- a/engine/source/editor/include/editor_scene_manager.h +++ b/engine/source/editor/include/editor_scene_manager.h @@ -7,9 +7,9 @@ #include -namespace Pilot +namespace Piccolo { - class PilotEditor; + class PiccoloEditor; class RenderCamera; class RenderEntity; diff --git a/engine/source/editor/include/editor_ui.h b/engine/source/editor/include/editor_ui.h index b5e7bedb1..75889963d 100644 --- a/engine/source/editor/include/editor_ui.h +++ b/engine/source/editor/include/editor_ui.h @@ -13,9 +13,9 @@ #include #include -namespace Pilot +namespace Piccolo { - class PilotEditor; + class PiccoloEditor; class WindowSystem; class RenderSystem; @@ -28,7 +28,7 @@ namespace Pilot void onFileContentItemClicked(EditorFileNode* node); void buildEditorFileAssetsUITree(EditorFileNode* node); void drawAxisToggleButton(const char* string_id, bool check_state, int axis_mode); - void createComponentUI(Reflection::ReflectionInstance& instance); + void createClassUI(Reflection::ReflectionInstance& instance); void createLeafNodeUI(Reflection::ReflectionInstance& instance); std::string getLeafUINodeParentLabel(); @@ -59,4 +59,4 @@ namespace Pilot bool m_scene_lights_window_open = true; bool m_scene_lights_data_window_open = true; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/resource/Piccolo.ico b/engine/source/editor/resource/Piccolo.ico new file mode 100644 index 000000000..b4a82c50f Binary files /dev/null and b/engine/source/editor/resource/Piccolo.ico differ diff --git a/engine/source/editor/resource/PiccoloEditor.ico b/engine/source/editor/resource/PiccoloEditor.ico new file mode 100644 index 000000000..134b0dc8e Binary files /dev/null and b/engine/source/editor/resource/PiccoloEditor.ico differ diff --git a/engine/source/editor/resource/PiccoloEditor.rc b/engine/source/editor/resource/PiccoloEditor.rc new file mode 100644 index 000000000..df4a2491e --- /dev/null +++ b/engine/source/editor/resource/PiccoloEditor.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON "PiccoloEditor.ico" \ No newline at end of file diff --git a/engine/source/editor/resource/PiccoloEditorBigIcon.png b/engine/source/editor/resource/PiccoloEditorBigIcon.png new file mode 100644 index 000000000..1b47ea100 Binary files /dev/null and b/engine/source/editor/resource/PiccoloEditorBigIcon.png differ diff --git a/engine/source/editor/resource/PilotEditorFont.TTF b/engine/source/editor/resource/PiccoloEditorFont.TTF similarity index 100% rename from engine/source/editor/resource/PilotEditorFont.TTF rename to engine/source/editor/resource/PiccoloEditorFont.TTF diff --git a/engine/source/editor/resource/PilotEditorSmallIcon.png b/engine/source/editor/resource/PiccoloEditorSmallIcon.png similarity index 81% rename from engine/source/editor/resource/PilotEditorSmallIcon.png rename to engine/source/editor/resource/PiccoloEditorSmallIcon.png index 01128c531..5cfda8411 100644 Binary files a/engine/source/editor/resource/PilotEditorSmallIcon.png and b/engine/source/editor/resource/PiccoloEditorSmallIcon.png differ diff --git a/engine/source/editor/resource/PilotEditor.ico b/engine/source/editor/resource/PilotEditor.ico deleted file mode 100644 index a042e9bd4..000000000 Binary files a/engine/source/editor/resource/PilotEditor.ico and /dev/null differ diff --git a/engine/source/editor/resource/PilotEditor.rc b/engine/source/editor/resource/PilotEditor.rc deleted file mode 100644 index c29007a2f..000000000 --- a/engine/source/editor/resource/PilotEditor.rc +++ /dev/null @@ -1 +0,0 @@ -IDI_ICON1 ICON "PilotEditor.ico" \ No newline at end of file diff --git a/engine/source/editor/resource/PilotEditorBigIcon.png b/engine/source/editor/resource/PilotEditorBigIcon.png deleted file mode 100644 index f77bb704c..000000000 Binary files a/engine/source/editor/resource/PilotEditorBigIcon.png and /dev/null differ diff --git a/engine/source/editor/source/axis.cpp b/engine/source/editor/source/axis.cpp index 86c94ebda..004a7ffdf 100644 --- a/engine/source/editor/source/axis.cpp +++ b/engine/source/editor/source/axis.cpp @@ -1,6 +1,6 @@ #include "editor/include/axis.h" -namespace Pilot +namespace Piccolo { EditorTranslationAxis::EditorTranslationAxis() { @@ -652,4 +652,4 @@ namespace Pilot index_data[start_index + 11 * 3 + 2] = (uint16_t)(start_vertex_index + 2); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/source/editor.cpp b/engine/source/editor/source/editor.cpp index 8912d665a..49194da1b 100644 --- a/engine/source/editor/source/editor.cpp +++ b/engine/source/editor/source/editor.cpp @@ -10,22 +10,22 @@ #include "editor/include/editor_scene_manager.h" #include "editor/include/editor_ui.h" -namespace Pilot +namespace Piccolo { void registerEdtorTickComponent(std::string component_type_name) { g_editor_tick_component_types.insert(component_type_name); } - PilotEditor::PilotEditor() + PiccoloEditor::PiccoloEditor() { registerEdtorTickComponent("TransformComponent"); registerEdtorTickComponent("MeshComponent"); } - PilotEditor::~PilotEditor() {} + PiccoloEditor::~PiccoloEditor() {} - void PilotEditor::initialize(PilotEngine* engine_runtime) + void PiccoloEditor::initialize(PiccoloEngine* engine_runtime) { assert(engine_runtime); @@ -46,9 +46,9 @@ namespace Pilot m_editor_ui->initialize(ui_init_info); } - void PilotEditor::clear() { g_editor_global_context.clear(); } + void PiccoloEditor::clear() { g_editor_global_context.clear(); } - void PilotEditor::run() + void PiccoloEditor::run() { assert(m_engine_runtime); assert(m_editor_ui); @@ -62,4 +62,4 @@ namespace Pilot return; } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/source/editor_file_service.cpp b/engine/source/editor/source/editor_file_service.cpp index f58de9a44..e9bc77b15 100644 --- a/engine/source/editor/source/editor_file_service.cpp +++ b/engine/source/editor/source/editor_file_service.cpp @@ -8,7 +8,7 @@ #include "runtime/function/global/global_context.h" -namespace Pilot +namespace Piccolo { /// helper function: split the input string with separator, and filter the substring std::vector @@ -139,4 +139,4 @@ namespace Pilot } return nullptr; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/source/editor_global_context.cpp b/engine/source/editor/source/editor_global_context.cpp index e883751b7..f4517cab7 100644 --- a/engine/source/editor/source/editor_global_context.cpp +++ b/engine/source/editor/source/editor_global_context.cpp @@ -6,7 +6,7 @@ #include "runtime/function/render/render_system.h" #include "runtime/function/render/window_system.h" -namespace Pilot +namespace Piccolo { EditorGlobalContext g_editor_global_context; @@ -27,4 +27,4 @@ namespace Pilot delete (m_scene_manager); delete (m_input_manager); } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/editor/source/editor_input_manager.cpp b/engine/source/editor/source/editor_input_manager.cpp index 87dc33b8f..e64fd20ce 100644 --- a/engine/source/editor/source/editor_input_manager.cpp +++ b/engine/source/editor/source/editor_input_manager.cpp @@ -14,7 +14,7 @@ #include "runtime/function/render/render_system.h" #include "runtime/function/render/window_system.h" -namespace Pilot +namespace Piccolo { void EditorInputManager::initialize() { registerInput(); } @@ -297,4 +297,4 @@ namespace Pilot { return pos.x <= m_mouse_x && m_mouse_x <= pos.x + size.x && pos.y <= m_mouse_y && m_mouse_y <= pos.y + size.y; } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/editor/source/editor_scene_manager.cpp b/engine/source/editor/source/editor_scene_manager.cpp index 187ece523..18e1bd776 100644 --- a/engine/source/editor/source/editor_scene_manager.cpp +++ b/engine/source/editor/source/editor_scene_manager.cpp @@ -18,7 +18,7 @@ #include "runtime/function/render/render_camera.h" #include "runtime/function/render/render_system.h" -namespace Pilot +namespace Piccolo { void EditorSceneManager::initialize() {} @@ -578,4 +578,4 @@ namespace Pilot { return g_editor_global_context.m_render_system->getGuidOfPickedMesh(picked_uv); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/source/editor_ui.cpp b/engine/source/editor/source/editor_ui.cpp index 7c54e7b88..e230da9c1 100644 --- a/engine/source/editor/source/editor_ui.cpp +++ b/engine/source/editor/source/editor_ui.cpp @@ -28,16 +28,16 @@ #include #include -namespace Pilot +namespace Piccolo { std::vector> g_editor_node_state_array; int g_node_depth = -1; void DrawVecControl(const std::string& label, - Pilot::Vector3& values, + Piccolo::Vector3& values, float resetValue = 0.0f, float columnWidth = 100.0f); void DrawVecControl(const std::string& label, - Pilot::Quaternion& values, + Piccolo::Quaternion& values, float resetValue = 0.0f, float columnWidth = 100.0f); @@ -385,13 +385,13 @@ namespace Pilot ImGui::End(); } - void EditorUI::createComponentUI(Reflection::ReflectionInstance& instance) + void EditorUI::createClassUI(Reflection::ReflectionInstance& instance) { Reflection::ReflectionInstance* reflection_instance; int count = instance.m_meta.getBaseClassReflectionInstanceList(reflection_instance, instance.m_instance); for (int index = 0; index < count; index++) { - createComponentUI(reflection_instance[index]); + createClassUI(reflection_instance[index]); } createLeafNodeUI(instance); @@ -406,17 +406,16 @@ namespace Pilot for (size_t index = 0; index < fields_count; index++) { - auto fields_count = fields[index]; - if (fields_count.isArrayType()) + auto field = fields[index]; + if (field.isArrayType()) { - Reflection::ArrayAccessor array_accessor; - if (Reflection::TypeMeta::newArrayAccessorFromName(fields_count.getFieldTypeName(), array_accessor)) + if (Reflection::TypeMeta::newArrayAccessorFromName(field.getFieldTypeName(), array_accessor)) { - void* field_instance = fields_count.get(instance.m_instance); + void* field_instance = field.get(instance.m_instance); int array_count = array_accessor.getSize(field_instance); m_editor_ui_creator["TreeNodePush"]( - std::string(fields_count.getFieldName()) + "[" + std::to_string(array_count) + "]", nullptr); + std::string(field.getFieldName()) + "[" + std::to_string(array_count) + "]", nullptr); auto item_type_meta_item = Reflection::TypeMeta::newMetaFromName(array_accessor.getElementTypeName()); auto item_ui_creator_iterator = m_editor_ui_creator.find(item_type_meta_item.getTypeName()); @@ -426,9 +425,9 @@ namespace Pilot { m_editor_ui_creator["TreeNodePush"]("[" + std::to_string(index) + "]", nullptr); auto object_instance = Reflection::ReflectionInstance( - Pilot::Reflection::TypeMeta::newMetaFromName(item_type_meta_item.getTypeName().c_str()), + Piccolo::Reflection::TypeMeta::newMetaFromName(item_type_meta_item.getTypeName().c_str()), array_accessor.get(index, field_instance)); - createComponentUI(object_instance); + createClassUI(object_instance); m_editor_ui_creator["TreeNodePop"]("[" + std::to_string(index) + "]", nullptr); } else @@ -441,20 +440,20 @@ namespace Pilot "[" + std::to_string(index) + "]", array_accessor.get(index, field_instance)); } } - m_editor_ui_creator["TreeNodePop"](fields_count.getFieldName(), nullptr); + m_editor_ui_creator["TreeNodePop"](field.getFieldName(), nullptr); } } - auto ui_creator_iterator = m_editor_ui_creator.find(fields_count.getFieldTypeName()); + auto ui_creator_iterator = m_editor_ui_creator.find(field.getFieldTypeName()); if (ui_creator_iterator == m_editor_ui_creator.end()) { Reflection::TypeMeta field_meta = - Reflection::TypeMeta::newMetaFromName(fields_count.getFieldTypeName()); - if (fields_count.getTypeMeta(field_meta)) + Reflection::TypeMeta::newMetaFromName(field.getFieldTypeName()); + if (field.getTypeMeta(field_meta)) { auto child_instance = - Reflection::ReflectionInstance(field_meta, fields_count.get(instance.m_instance)); + Reflection::ReflectionInstance(field_meta, field.get(instance.m_instance)); m_editor_ui_creator["TreeNodePush"](field_meta.getTypeName(), nullptr); - createLeafNodeUI(child_instance); + createClassUI(child_instance); m_editor_ui_creator["TreeNodePop"](field_meta.getTypeName(), nullptr); } else @@ -463,14 +462,14 @@ namespace Pilot { continue; } - m_editor_ui_creator[fields_count.getFieldTypeName()](fields_count.getFieldName(), - fields_count.get(instance.m_instance)); + m_editor_ui_creator[field.getFieldTypeName()](field.getFieldName(), + field.get(instance.m_instance)); } } else { - m_editor_ui_creator[fields_count.getFieldTypeName()](fields_count.getFieldName(), - fields_count.get(instance.m_instance)); + m_editor_ui_creator[field.getFieldTypeName()](field.getFieldName(), + field.get(instance.m_instance)); } } delete[] fields; @@ -513,9 +512,9 @@ namespace Pilot { m_editor_ui_creator["TreeNodePush"](("<" + component_ptr.getTypeName() + ">").c_str(), nullptr); auto object_instance = Reflection::ReflectionInstance( - Pilot::Reflection::TypeMeta::newMetaFromName(component_ptr.getTypeName().c_str()), + Piccolo::Reflection::TypeMeta::newMetaFromName(component_ptr.getTypeName().c_str()), component_ptr.operator->()); - createComponentUI(object_instance); + createClassUI(object_instance); m_editor_ui_creator["TreeNodePop"](("<" + component_ptr.getTypeName() + ">").c_str(), nullptr); } ImGui::End(); @@ -914,7 +913,7 @@ namespace Pilot void EditorUI::preRender() { showEditorUI(); } - void DrawVecControl(const std::string& label, Pilot::Vector3& values, float resetValue, float columnWidth) + void DrawVecControl(const std::string& label, Piccolo::Vector3& values, float resetValue, float columnWidth) { ImGui::PushID(label.c_str()); @@ -970,7 +969,7 @@ namespace Pilot ImGui::PopID(); } - void DrawVecControl(const std::string& label, Pilot::Quaternion& values, float resetValue, float columnWidth) + void DrawVecControl(const std::string& label, Piccolo::Quaternion& values, float resetValue, float columnWidth) { ImGui::PushID(label.c_str()); @@ -1037,4 +1036,4 @@ namespace Pilot ImGui::Columns(1); ImGui::PopID(); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/editor/source/main.cpp b/engine/source/editor/source/main.cpp index 2fe7af270..64e3ea401 100644 --- a/engine/source/editor/source/main.cpp +++ b/engine/source/editor/source/main.cpp @@ -9,20 +9,20 @@ #include "editor/include/editor.h" // https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html -#define PILOT_XSTR(s) PILOT_STR(s) -#define PILOT_STR(s) #s +#define PICCOLO_XSTR(s) PICCOLO_STR(s) +#define PICCOLO_STR(s) #s int main(int argc, char** argv) { std::filesystem::path executable_path(argv[0]); - std::filesystem::path config_file_path = executable_path.parent_path() / "PilotEditor.ini"; + std::filesystem::path config_file_path = executable_path.parent_path() / "PiccoloEditor.ini"; - Pilot::PilotEngine* engine = new Pilot::PilotEngine(); + Piccolo::PiccoloEngine* engine = new Piccolo::PiccoloEngine(); engine->startEngine(config_file_path.generic_string()); engine->initialize(); - Pilot::PilotEditor* editor = new Pilot::PilotEditor(); + Piccolo::PiccoloEditor* editor = new Piccolo::PiccoloEditor(); editor->initialize(engine); editor->run(); diff --git a/engine/source/meta_parser/3rd_party/LLVM/.gitignore b/engine/source/meta_parser/3rd_party/LLVM/.gitignore new file mode 100644 index 000000000..6a5989d00 --- /dev/null +++ b/engine/source/meta_parser/3rd_party/LLVM/.gitignore @@ -0,0 +1,3 @@ +!lib/ +!bin/ +!x64/ diff --git a/engine/bin/Linux/libclang.so.12 b/engine/source/meta_parser/3rd_party/LLVM/bin/Linux/libclang.so.12 similarity index 100% rename from engine/bin/Linux/libclang.so.12 rename to engine/source/meta_parser/3rd_party/LLVM/bin/Linux/libclang.so.12 diff --git a/engine/bin/macOS/libc++.1.dylib b/engine/source/meta_parser/3rd_party/LLVM/bin/macOS/libc++.1.dylib similarity index 100% rename from engine/bin/macOS/libc++.1.dylib rename to engine/source/meta_parser/3rd_party/LLVM/bin/macOS/libc++.1.dylib diff --git a/engine/bin/macOS/libc++abi.1.dylib b/engine/source/meta_parser/3rd_party/LLVM/bin/macOS/libc++abi.1.dylib similarity index 100% rename from engine/bin/macOS/libc++abi.1.dylib rename to engine/source/meta_parser/3rd_party/LLVM/bin/macOS/libc++abi.1.dylib diff --git a/engine/bin/macOS/libclang.dylib b/engine/source/meta_parser/3rd_party/LLVM/bin/macOS/libclang.dylib similarity index 100% rename from engine/bin/macOS/libclang.dylib rename to engine/source/meta_parser/3rd_party/LLVM/bin/macOS/libclang.dylib diff --git a/engine/bin/Windows/x64/libclang.dll b/engine/source/meta_parser/3rd_party/LLVM/bin/x64/libclang.dll similarity index 100% rename from engine/bin/Windows/x64/libclang.dll rename to engine/source/meta_parser/3rd_party/LLVM/bin/x64/libclang.dll diff --git a/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/BuildSystem.h b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/BuildSystem.h new file mode 100644 index 000000000..3cfec3883 --- /dev/null +++ b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/BuildSystem.h @@ -0,0 +1,156 @@ +/*==-- clang-c/BuildSystem.h - Utilities for use by build systems -*- C -*-===*\ +|* *| +|* The LLVM Compiler Infrastructure *| +|* *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This header provides various utilities for use by build systems. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_CLANG_C_BUILDSYSTEM_H +#define LLVM_CLANG_C_BUILDSYSTEM_H + +#include "clang-c/Platform.h" +#include "clang-c/CXErrorCode.h" +#include "clang-c/CXString.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup BUILD_SYSTEM Build system utilities + * @{ + */ + +/** + * Return the timestamp for use with Clang's + * \c -fbuild-session-timestamp= option. + */ +CINDEX_LINKAGE unsigned long long clang_getBuildSessionTimestamp(void); + +/** + * Object encapsulating information about overlaying virtual + * file/directories over the real file system. + */ +typedef struct CXVirtualFileOverlayImpl *CXVirtualFileOverlay; + +/** + * Create a \c CXVirtualFileOverlay object. + * Must be disposed with \c clang_VirtualFileOverlay_dispose(). + * + * \param options is reserved, always pass 0. + */ +CINDEX_LINKAGE CXVirtualFileOverlay +clang_VirtualFileOverlay_create(unsigned options); + +/** + * Map an absolute virtual file path to an absolute real one. + * The virtual path must be canonicalized (not contain "."/".."). + * \returns 0 for success, non-zero to indicate an error. + */ +CINDEX_LINKAGE enum CXErrorCode +clang_VirtualFileOverlay_addFileMapping(CXVirtualFileOverlay, + const char *virtualPath, + const char *realPath); + +/** + * Set the case sensitivity for the \c CXVirtualFileOverlay object. + * The \c CXVirtualFileOverlay object is case-sensitive by default, this + * option can be used to override the default. + * \returns 0 for success, non-zero to indicate an error. + */ +CINDEX_LINKAGE enum CXErrorCode +clang_VirtualFileOverlay_setCaseSensitivity(CXVirtualFileOverlay, + int caseSensitive); + +/** + * Write out the \c CXVirtualFileOverlay object to a char buffer. + * + * \param options is reserved, always pass 0. + * \param out_buffer_ptr pointer to receive the buffer pointer, which should be + * disposed using \c clang_free(). + * \param out_buffer_size pointer to receive the buffer size. + * \returns 0 for success, non-zero to indicate an error. + */ +CINDEX_LINKAGE enum CXErrorCode +clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay, unsigned options, + char **out_buffer_ptr, + unsigned *out_buffer_size); + +/** + * free memory allocated by libclang, such as the buffer returned by + * \c CXVirtualFileOverlay() or \c clang_ModuleMapDescriptor_writeToBuffer(). + * + * \param buffer memory pointer to free. + */ +CINDEX_LINKAGE void clang_free(void *buffer); + +/** + * Dispose a \c CXVirtualFileOverlay object. + */ +CINDEX_LINKAGE void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay); + +/** + * Object encapsulating information about a module.map file. + */ +typedef struct CXModuleMapDescriptorImpl *CXModuleMapDescriptor; + +/** + * Create a \c CXModuleMapDescriptor object. + * Must be disposed with \c clang_ModuleMapDescriptor_dispose(). + * + * \param options is reserved, always pass 0. + */ +CINDEX_LINKAGE CXModuleMapDescriptor +clang_ModuleMapDescriptor_create(unsigned options); + +/** + * Sets the framework module name that the module.map describes. + * \returns 0 for success, non-zero to indicate an error. + */ +CINDEX_LINKAGE enum CXErrorCode +clang_ModuleMapDescriptor_setFrameworkModuleName(CXModuleMapDescriptor, + const char *name); + +/** + * Sets the umbrealla header name that the module.map describes. + * \returns 0 for success, non-zero to indicate an error. + */ +CINDEX_LINKAGE enum CXErrorCode +clang_ModuleMapDescriptor_setUmbrellaHeader(CXModuleMapDescriptor, + const char *name); + +/** + * Write out the \c CXModuleMapDescriptor object to a char buffer. + * + * \param options is reserved, always pass 0. + * \param out_buffer_ptr pointer to receive the buffer pointer, which should be + * disposed using \c clang_free(). + * \param out_buffer_size pointer to receive the buffer size. + * \returns 0 for success, non-zero to indicate an error. + */ +CINDEX_LINKAGE enum CXErrorCode +clang_ModuleMapDescriptor_writeToBuffer(CXModuleMapDescriptor, unsigned options, + char **out_buffer_ptr, + unsigned *out_buffer_size); + +/** + * Dispose a \c CXModuleMapDescriptor object. + */ +CINDEX_LINKAGE void clang_ModuleMapDescriptor_dispose(CXModuleMapDescriptor); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* CLANG_C_BUILD_SYSTEM_H */ + diff --git a/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/CXCompilationDatabase.h b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/CXCompilationDatabase.h new file mode 100644 index 000000000..6f483ee28 --- /dev/null +++ b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/CXCompilationDatabase.h @@ -0,0 +1,176 @@ +/*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\ +|* *| +|* The LLVM Compiler Infrastructure *| +|* *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This header provides a public interface to use CompilationDatabase without *| +|* the full Clang C++ API. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H +#define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H + +#include "clang-c/Platform.h" +#include "clang-c/CXString.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \defgroup COMPILATIONDB CompilationDatabase functions + * \ingroup CINDEX + * + * @{ + */ + +/** + * A compilation database holds all information used to compile files in a + * project. For each file in the database, it can be queried for the working + * directory or the command line used for the compiler invocation. + * + * Must be freed by \c clang_CompilationDatabase_dispose + */ +typedef void * CXCompilationDatabase; + +/** + * Contains the results of a search in the compilation database + * + * When searching for the compile command for a file, the compilation db can + * return several commands, as the file may have been compiled with + * different options in different places of the project. This choice of compile + * commands is wrapped in this opaque data structure. It must be freed by + * \c clang_CompileCommands_dispose. + */ +typedef void * CXCompileCommands; + +/** + * Represents the command line invocation to compile a specific file. + */ +typedef void * CXCompileCommand; + +/** + * Error codes for Compilation Database + */ +typedef enum { + /* + * No error occurred + */ + CXCompilationDatabase_NoError = 0, + + /* + * Database can not be loaded + */ + CXCompilationDatabase_CanNotLoadDatabase = 1 + +} CXCompilationDatabase_Error; + +/** + * Creates a compilation database from the database found in directory + * buildDir. For example, CMake can output a compile_commands.json which can + * be used to build the database. + * + * It must be freed by \c clang_CompilationDatabase_dispose. + */ +CINDEX_LINKAGE CXCompilationDatabase +clang_CompilationDatabase_fromDirectory(const char *BuildDir, + CXCompilationDatabase_Error *ErrorCode); + +/** + * Free the given compilation database + */ +CINDEX_LINKAGE void +clang_CompilationDatabase_dispose(CXCompilationDatabase); + +/** + * Find the compile commands used for a file. The compile commands + * must be freed by \c clang_CompileCommands_dispose. + */ +CINDEX_LINKAGE CXCompileCommands +clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase, + const char *CompleteFileName); + +/** + * Get all the compile commands in the given compilation database. + */ +CINDEX_LINKAGE CXCompileCommands +clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase); + +/** + * Free the given CompileCommands + */ +CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands); + +/** + * Get the number of CompileCommand we have for a file + */ +CINDEX_LINKAGE unsigned +clang_CompileCommands_getSize(CXCompileCommands); + +/** + * Get the I'th CompileCommand for a file + * + * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands) + */ +CINDEX_LINKAGE CXCompileCommand +clang_CompileCommands_getCommand(CXCompileCommands, unsigned I); + +/** + * Get the working directory where the CompileCommand was executed from + */ +CINDEX_LINKAGE CXString +clang_CompileCommand_getDirectory(CXCompileCommand); + +/** + * Get the filename associated with the CompileCommand. + */ +CINDEX_LINKAGE CXString +clang_CompileCommand_getFilename(CXCompileCommand); + +/** + * Get the number of arguments in the compiler invocation. + * + */ +CINDEX_LINKAGE unsigned +clang_CompileCommand_getNumArgs(CXCompileCommand); + +/** + * Get the I'th argument value in the compiler invocations + * + * Invariant : + * - argument 0 is the compiler executable + */ +CINDEX_LINKAGE CXString +clang_CompileCommand_getArg(CXCompileCommand, unsigned I); + +/** + * Get the number of source mappings for the compiler invocation. + */ +CINDEX_LINKAGE unsigned +clang_CompileCommand_getNumMappedSources(CXCompileCommand); + +/** + * Get the I'th mapped source path for the compiler invocation. + */ +CINDEX_LINKAGE CXString +clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I); + +/** + * Get the I'th mapped source content for the compiler invocation. + */ +CINDEX_LINKAGE CXString +clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/CXErrorCode.h b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/CXErrorCode.h new file mode 100644 index 000000000..caee48d76 --- /dev/null +++ b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/CXErrorCode.h @@ -0,0 +1,64 @@ +/*===-- clang-c/CXErrorCode.h - C Index Error Codes --------------*- C -*-===*\ +|* *| +|* The LLVM Compiler Infrastructure *| +|* *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This header provides the CXErrorCode enumerators. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_CLANG_C_CXERRORCODE_H +#define LLVM_CLANG_C_CXERRORCODE_H + +#include "clang-c/Platform.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Error codes returned by libclang routines. + * + * Zero (\c CXError_Success) is the only error code indicating success. Other + * error codes, including not yet assigned non-zero values, indicate errors. + */ +enum CXErrorCode { + /** + * No error. + */ + CXError_Success = 0, + + /** + * A generic error code, no further details are available. + * + * Errors of this kind can get their own specific error codes in future + * libclang versions. + */ + CXError_Failure = 1, + + /** + * libclang crashed while performing the requested operation. + */ + CXError_Crashed = 2, + + /** + * The function detected that the arguments violate the function + * contract. + */ + CXError_InvalidArguments = 3, + + /** + * An AST deserialization error has occurred. + */ + CXError_ASTReadError = 4 +}; + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/CXString.h b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/CXString.h new file mode 100644 index 000000000..76eeda180 --- /dev/null +++ b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/CXString.h @@ -0,0 +1,71 @@ +/*===-- clang-c/CXString.h - C Index strings --------------------*- C -*-===*\ +|* *| +|* The LLVM Compiler Infrastructure *| +|* *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This header provides the interface to C Index strings. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_CLANG_C_CXSTRING_H +#define LLVM_CLANG_C_CXSTRING_H + +#include "clang-c/Platform.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup CINDEX_STRING String manipulation routines + * \ingroup CINDEX + * + * @{ + */ + +/** + * A character string. + * + * The \c CXString type is used to return strings from the interface when + * the ownership of that string might differ from one call to the next. + * Use \c clang_getCString() to retrieve the string data and, once finished + * with the string data, call \c clang_disposeString() to free the string. + */ +typedef struct { + const void *data; + unsigned private_flags; +} CXString; + +typedef struct { + CXString *Strings; + unsigned Count; +} CXStringSet; + +/** + * Retrieve the character data associated with the given string. + */ +CINDEX_LINKAGE const char *clang_getCString(CXString string); + +/** + * Free the given string. + */ +CINDEX_LINKAGE void clang_disposeString(CXString string); + +/** + * Free the given string set. + */ +CINDEX_LINKAGE void clang_disposeStringSet(CXStringSet *set); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/Documentation.h b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/Documentation.h new file mode 100644 index 000000000..58c8af5aa --- /dev/null +++ b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/Documentation.h @@ -0,0 +1,554 @@ +/*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\ +|* *| +|* The LLVM Compiler Infrastructure *| +|* *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This header provides a supplementary interface for inspecting *| +|* documentation comments. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_CLANG_C_DOCUMENTATION_H +#define LLVM_CLANG_C_DOCUMENTATION_H + +#include "clang-c/Index.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup CINDEX_COMMENT Comment introspection + * + * The routines in this group provide access to information in documentation + * comments. These facilities are distinct from the core and may be subject to + * their own schedule of stability and deprecation. + * + * @{ + */ + +/** + * A parsed comment. + */ +typedef struct { + const void *ASTNode; + CXTranslationUnit TranslationUnit; +} CXComment; + +/** + * Given a cursor that represents a documentable entity (e.g., + * declaration), return the associated parsed comment as a + * \c CXComment_FullComment AST node. + */ +CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C); + +/** + * Describes the type of the comment AST node (\c CXComment). A comment + * node can be considered block content (e. g., paragraph), inline content + * (plain text) or neither (the root AST node). + */ +enum CXCommentKind { + /** + * Null comment. No AST node is constructed at the requested location + * because there is no text or a syntax error. + */ + CXComment_Null = 0, + + /** + * Plain text. Inline content. + */ + CXComment_Text = 1, + + /** + * A command with word-like arguments that is considered inline content. + * + * For example: \\c command. + */ + CXComment_InlineCommand = 2, + + /** + * HTML start tag with attributes (name-value pairs). Considered + * inline content. + * + * For example: + * \verbatim + *

+ * \endverbatim + */ + CXComment_HTMLStartTag = 3, + + /** + * HTML end tag. Considered inline content. + * + * For example: + * \verbatim + * + * \endverbatim + */ + CXComment_HTMLEndTag = 4, + + /** + * A paragraph, contains inline comment. The paragraph itself is + * block content. + */ + CXComment_Paragraph = 5, + + /** + * A command that has zero or more word-like arguments (number of + * word-like arguments depends on command name) and a paragraph as an + * argument. Block command is block content. + * + * Paragraph argument is also a child of the block command. + * + * For example: \has 0 word-like arguments and a paragraph argument. + * + * AST nodes of special kinds that parser knows about (e. g., \\param + * command) have their own node kinds. + */ + CXComment_BlockCommand = 6, + + /** + * A \\param or \\arg command that describes the function parameter + * (name, passing direction, description). + * + * For example: \\param [in] ParamName description. + */ + CXComment_ParamCommand = 7, + + /** + * A \\tparam command that describes a template parameter (name and + * description). + * + * For example: \\tparam T description. + */ + CXComment_TParamCommand = 8, + + /** + * A verbatim block command (e. g., preformatted code). Verbatim + * block has an opening and a closing command and contains multiple lines of + * text (\c CXComment_VerbatimBlockLine child nodes). + * + * For example: + * \\verbatim + * aaa + * \\endverbatim + */ + CXComment_VerbatimBlockCommand = 9, + + /** + * A line of text that is contained within a + * CXComment_VerbatimBlockCommand node. + */ + CXComment_VerbatimBlockLine = 10, + + /** + * A verbatim line command. Verbatim line has an opening command, + * a single line of text (up to the newline after the opening command) and + * has no closing command. + */ + CXComment_VerbatimLine = 11, + + /** + * A full comment attached to a declaration, contains block content. + */ + CXComment_FullComment = 12 +}; + +/** + * The most appropriate rendering mode for an inline command, chosen on + * command semantics in Doxygen. + */ +enum CXCommentInlineCommandRenderKind { + /** + * Command argument should be rendered in a normal font. + */ + CXCommentInlineCommandRenderKind_Normal, + + /** + * Command argument should be rendered in a bold font. + */ + CXCommentInlineCommandRenderKind_Bold, + + /** + * Command argument should be rendered in a monospaced font. + */ + CXCommentInlineCommandRenderKind_Monospaced, + + /** + * Command argument should be rendered emphasized (typically italic + * font). + */ + CXCommentInlineCommandRenderKind_Emphasized +}; + +/** + * Describes parameter passing direction for \\param or \\arg command. + */ +enum CXCommentParamPassDirection { + /** + * The parameter is an input parameter. + */ + CXCommentParamPassDirection_In, + + /** + * The parameter is an output parameter. + */ + CXCommentParamPassDirection_Out, + + /** + * The parameter is an input and output parameter. + */ + CXCommentParamPassDirection_InOut +}; + +/** + * \param Comment AST node of any kind. + * + * \returns the type of the AST node. + */ +CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment); + +/** + * \param Comment AST node of any kind. + * + * \returns number of children of the AST node. + */ +CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment); + +/** + * \param Comment AST node of any kind. + * + * \param ChildIdx child index (zero-based). + * + * \returns the specified child of the AST node. + */ +CINDEX_LINKAGE +CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx); + +/** + * A \c CXComment_Paragraph node is considered whitespace if it contains + * only \c CXComment_Text nodes that are empty or whitespace. + * + * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are + * never considered whitespace. + * + * \returns non-zero if \c Comment is whitespace. + */ +CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment); + +/** + * \returns non-zero if \c Comment is inline content and has a newline + * immediately following it in the comment text. Newlines between paragraphs + * do not count. + */ +CINDEX_LINKAGE +unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment); + +/** + * \param Comment a \c CXComment_Text AST node. + * + * \returns text contained in the AST node. + */ +CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment); + +/** + * \param Comment a \c CXComment_InlineCommand AST node. + * + * \returns name of the inline command. + */ +CINDEX_LINKAGE +CXString clang_InlineCommandComment_getCommandName(CXComment Comment); + +/** + * \param Comment a \c CXComment_InlineCommand AST node. + * + * \returns the most appropriate rendering mode, chosen on command + * semantics in Doxygen. + */ +CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind +clang_InlineCommandComment_getRenderKind(CXComment Comment); + +/** + * \param Comment a \c CXComment_InlineCommand AST node. + * + * \returns number of command arguments. + */ +CINDEX_LINKAGE +unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment); + +/** + * \param Comment a \c CXComment_InlineCommand AST node. + * + * \param ArgIdx argument index (zero-based). + * + * \returns text of the specified argument. + */ +CINDEX_LINKAGE +CXString clang_InlineCommandComment_getArgText(CXComment Comment, + unsigned ArgIdx); + +/** + * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST + * node. + * + * \returns HTML tag name. + */ +CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment); + +/** + * \param Comment a \c CXComment_HTMLStartTag AST node. + * + * \returns non-zero if tag is self-closing (for example, <br />). + */ +CINDEX_LINKAGE +unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment); + +/** + * \param Comment a \c CXComment_HTMLStartTag AST node. + * + * \returns number of attributes (name-value pairs) attached to the start tag. + */ +CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment); + +/** + * \param Comment a \c CXComment_HTMLStartTag AST node. + * + * \param AttrIdx attribute index (zero-based). + * + * \returns name of the specified attribute. + */ +CINDEX_LINKAGE +CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx); + +/** + * \param Comment a \c CXComment_HTMLStartTag AST node. + * + * \param AttrIdx attribute index (zero-based). + * + * \returns value of the specified attribute. + */ +CINDEX_LINKAGE +CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx); + +/** + * \param Comment a \c CXComment_BlockCommand AST node. + * + * \returns name of the block command. + */ +CINDEX_LINKAGE +CXString clang_BlockCommandComment_getCommandName(CXComment Comment); + +/** + * \param Comment a \c CXComment_BlockCommand AST node. + * + * \returns number of word-like arguments. + */ +CINDEX_LINKAGE +unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment); + +/** + * \param Comment a \c CXComment_BlockCommand AST node. + * + * \param ArgIdx argument index (zero-based). + * + * \returns text of the specified word-like argument. + */ +CINDEX_LINKAGE +CXString clang_BlockCommandComment_getArgText(CXComment Comment, + unsigned ArgIdx); + +/** + * \param Comment a \c CXComment_BlockCommand or + * \c CXComment_VerbatimBlockCommand AST node. + * + * \returns paragraph argument of the block command. + */ +CINDEX_LINKAGE +CXComment clang_BlockCommandComment_getParagraph(CXComment Comment); + +/** + * \param Comment a \c CXComment_ParamCommand AST node. + * + * \returns parameter name. + */ +CINDEX_LINKAGE +CXString clang_ParamCommandComment_getParamName(CXComment Comment); + +/** + * \param Comment a \c CXComment_ParamCommand AST node. + * + * \returns non-zero if the parameter that this AST node represents was found + * in the function prototype and \c clang_ParamCommandComment_getParamIndex + * function will return a meaningful value. + */ +CINDEX_LINKAGE +unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment); + +/** + * \param Comment a \c CXComment_ParamCommand AST node. + * + * \returns zero-based parameter index in function prototype. + */ +CINDEX_LINKAGE +unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment); + +/** + * \param Comment a \c CXComment_ParamCommand AST node. + * + * \returns non-zero if parameter passing direction was specified explicitly in + * the comment. + */ +CINDEX_LINKAGE +unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment); + +/** + * \param Comment a \c CXComment_ParamCommand AST node. + * + * \returns parameter passing direction. + */ +CINDEX_LINKAGE +enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection( + CXComment Comment); + +/** + * \param Comment a \c CXComment_TParamCommand AST node. + * + * \returns template parameter name. + */ +CINDEX_LINKAGE +CXString clang_TParamCommandComment_getParamName(CXComment Comment); + +/** + * \param Comment a \c CXComment_TParamCommand AST node. + * + * \returns non-zero if the parameter that this AST node represents was found + * in the template parameter list and + * \c clang_TParamCommandComment_getDepth and + * \c clang_TParamCommandComment_getIndex functions will return a meaningful + * value. + */ +CINDEX_LINKAGE +unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment); + +/** + * \param Comment a \c CXComment_TParamCommand AST node. + * + * \returns zero-based nesting depth of this parameter in the template parameter list. + * + * For example, + * \verbatim + * template class TT> + * void test(TT aaa); + * \endverbatim + * for C and TT nesting depth is 0, + * for T nesting depth is 1. + */ +CINDEX_LINKAGE +unsigned clang_TParamCommandComment_getDepth(CXComment Comment); + +/** + * \param Comment a \c CXComment_TParamCommand AST node. + * + * \returns zero-based parameter index in the template parameter list at a + * given nesting depth. + * + * For example, + * \verbatim + * template class TT> + * void test(TT aaa); + * \endverbatim + * for C and TT nesting depth is 0, so we can ask for index at depth 0: + * at depth 0 C's index is 0, TT's index is 1. + * + * For T nesting depth is 1, so we can ask for index at depth 0 and 1: + * at depth 0 T's index is 1 (same as TT's), + * at depth 1 T's index is 0. + */ +CINDEX_LINKAGE +unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth); + +/** + * \param Comment a \c CXComment_VerbatimBlockLine AST node. + * + * \returns text contained in the AST node. + */ +CINDEX_LINKAGE +CXString clang_VerbatimBlockLineComment_getText(CXComment Comment); + +/** + * \param Comment a \c CXComment_VerbatimLine AST node. + * + * \returns text contained in the AST node. + */ +CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment); + +/** + * Convert an HTML tag AST node to string. + * + * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST + * node. + * + * \returns string containing an HTML tag. + */ +CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment); + +/** + * Convert a given full parsed comment to an HTML fragment. + * + * Specific details of HTML layout are subject to change. Don't try to parse + * this HTML back into an AST, use other APIs instead. + * + * Currently the following CSS classes are used: + * \li "para-brief" for \paragraph and equivalent commands; + * \li "para-returns" for \\returns paragraph and equivalent commands; + * \li "word-returns" for the "Returns" word in \\returns paragraph. + * + * Function argument documentation is rendered as a \ list with arguments + * sorted in function prototype order. CSS classes used: + * \li "param-name-index-NUMBER" for parameter name (\); + * \li "param-descr-index-NUMBER" for parameter description (\); + * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if + * parameter index is invalid. + * + * Template parameter documentation is rendered as a \ list with + * parameters sorted in template parameter list order. CSS classes used: + * \li "tparam-name-index-NUMBER" for parameter name (\); + * \li "tparam-descr-index-NUMBER" for parameter description (\); + * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for + * names inside template template parameters; + * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if + * parameter position is invalid. + * + * \param Comment a \c CXComment_FullComment AST node. + * + * \returns string containing an HTML fragment. + */ +CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment); + +/** + * Convert a given full parsed comment to an XML document. + * + * A Relax NG schema for the XML can be found in comment-xml-schema.rng file + * inside clang source tree. + * + * \param Comment a \c CXComment_FullComment AST node. + * + * \returns string containing an XML document. + */ +CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* CLANG_C_DOCUMENTATION_H */ + diff --git a/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/Index.h b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/Index.h new file mode 100644 index 000000000..65dada38b --- /dev/null +++ b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/Index.h @@ -0,0 +1,6584 @@ +/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\ +|* *| +|* The LLVM Compiler Infrastructure *| +|* *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This header provides a public interface to a Clang library for extracting *| +|* high-level symbol information from source files without exposing the full *| +|* Clang C++ API. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_CLANG_C_INDEX_H +#define LLVM_CLANG_C_INDEX_H + +#include + +#include "clang-c/Platform.h" +#include "clang-c/CXErrorCode.h" +#include "clang-c/CXString.h" +#include "clang-c/BuildSystem.h" + +/** + * The version constants for the libclang API. + * CINDEX_VERSION_MINOR should increase when there are API additions. + * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes. + * + * The policy about the libclang API was always to keep it source and ABI + * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. + */ +#define CINDEX_VERSION_MAJOR 0 +#define CINDEX_VERSION_MINOR 49 + +#define CINDEX_VERSION_ENCODE(major, minor) ( \ + ((major) * 10000) \ + + ((minor) * 1)) + +#define CINDEX_VERSION CINDEX_VERSION_ENCODE( \ + CINDEX_VERSION_MAJOR, \ + CINDEX_VERSION_MINOR ) + +#define CINDEX_VERSION_STRINGIZE_(major, minor) \ + #major"."#minor +#define CINDEX_VERSION_STRINGIZE(major, minor) \ + CINDEX_VERSION_STRINGIZE_(major, minor) + +#define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \ + CINDEX_VERSION_MAJOR, \ + CINDEX_VERSION_MINOR) + +#ifdef __cplusplus +extern "C" { +#endif + +/** \defgroup CINDEX libclang: C Interface to Clang + * + * The C Interface to Clang provides a relatively small API that exposes + * facilities for parsing source code into an abstract syntax tree (AST), + * loading already-parsed ASTs, traversing the AST, associating + * physical source locations with elements within the AST, and other + * facilities that support Clang-based development tools. + * + * This C interface to Clang will never provide all of the information + * representation stored in Clang's C++ AST, nor should it: the intent is to + * maintain an API that is relatively stable from one release to the next, + * providing only the basic functionality needed to support development tools. + * + * To avoid namespace pollution, data types are prefixed with "CX" and + * functions are prefixed with "clang_". + * + * @{ + */ + +/** + * An "index" that consists of a set of translation units that would + * typically be linked together into an executable or library. + */ +typedef void *CXIndex; + +/** + * An opaque type representing target information for a given translation + * unit. + */ +typedef struct CXTargetInfoImpl *CXTargetInfo; + +/** + * A single translation unit, which resides in an index. + */ +typedef struct CXTranslationUnitImpl *CXTranslationUnit; + +/** + * Opaque pointer representing client data that will be passed through + * to various callbacks and visitors. + */ +typedef void *CXClientData; + +/** + * Provides the contents of a file that has not yet been saved to disk. + * + * Each CXUnsavedFile instance provides the name of a file on the + * system along with the current contents of that file that have not + * yet been saved to disk. + */ +struct CXUnsavedFile { + /** + * The file whose contents have not yet been saved. + * + * This file must already exist in the file system. + */ + const char *Filename; + + /** + * A buffer containing the unsaved contents of this file. + */ + const char *Contents; + + /** + * The length of the unsaved contents of this buffer. + */ + unsigned long Length; +}; + +/** + * Describes the availability of a particular entity, which indicates + * whether the use of this entity will result in a warning or error due to + * it being deprecated or unavailable. + */ +enum CXAvailabilityKind { + /** + * The entity is available. + */ + CXAvailability_Available, + /** + * The entity is available, but has been deprecated (and its use is + * not recommended). + */ + CXAvailability_Deprecated, + /** + * The entity is not available; any use of it will be an error. + */ + CXAvailability_NotAvailable, + /** + * The entity is available, but not accessible; any use of it will be + * an error. + */ + CXAvailability_NotAccessible +}; + +/** + * Describes a version number of the form major.minor.subminor. + */ +typedef struct CXVersion { + /** + * The major version number, e.g., the '10' in '10.7.3'. A negative + * value indicates that there is no version number at all. + */ + int Major; + /** + * The minor version number, e.g., the '7' in '10.7.3'. This value + * will be negative if no minor version number was provided, e.g., for + * version '10'. + */ + int Minor; + /** + * The subminor version number, e.g., the '3' in '10.7.3'. This value + * will be negative if no minor or subminor version number was provided, + * e.g., in version '10' or '10.7'. + */ + int Subminor; +} CXVersion; + +/** + * Describes the exception specification of a cursor. + * + * A negative value indicates that the cursor is not a function declaration. + */ +enum CXCursor_ExceptionSpecificationKind { + + /** + * The cursor has no exception specification. + */ + CXCursor_ExceptionSpecificationKind_None, + + /** + * The cursor has exception specification throw() + */ + CXCursor_ExceptionSpecificationKind_DynamicNone, + + /** + * The cursor has exception specification throw(T1, T2) + */ + CXCursor_ExceptionSpecificationKind_Dynamic, + + /** + * The cursor has exception specification throw(...). + */ + CXCursor_ExceptionSpecificationKind_MSAny, + + /** + * The cursor has exception specification basic noexcept. + */ + CXCursor_ExceptionSpecificationKind_BasicNoexcept, + + /** + * The cursor has exception specification computed noexcept. + */ + CXCursor_ExceptionSpecificationKind_ComputedNoexcept, + + /** + * The exception specification has not yet been evaluated. + */ + CXCursor_ExceptionSpecificationKind_Unevaluated, + + /** + * The exception specification has not yet been instantiated. + */ + CXCursor_ExceptionSpecificationKind_Uninstantiated, + + /** + * The exception specification has not been parsed yet. + */ + CXCursor_ExceptionSpecificationKind_Unparsed +}; + +/** + * Provides a shared context for creating translation units. + * + * It provides two options: + * + * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" + * declarations (when loading any new translation units). A "local" declaration + * is one that belongs in the translation unit itself and not in a precompiled + * header that was used by the translation unit. If zero, all declarations + * will be enumerated. + * + * Here is an example: + * + * \code + * // excludeDeclsFromPCH = 1, displayDiagnostics=1 + * Idx = clang_createIndex(1, 1); + * + * // IndexTest.pch was produced with the following command: + * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" + * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); + * + * // This will load all the symbols from 'IndexTest.pch' + * clang_visitChildren(clang_getTranslationUnitCursor(TU), + * TranslationUnitVisitor, 0); + * clang_disposeTranslationUnit(TU); + * + * // This will load all the symbols from 'IndexTest.c', excluding symbols + * // from 'IndexTest.pch'. + * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; + * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, + * 0, 0); + * clang_visitChildren(clang_getTranslationUnitCursor(TU), + * TranslationUnitVisitor, 0); + * clang_disposeTranslationUnit(TU); + * \endcode + * + * This process of creating the 'pch', loading it separately, and using it (via + * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks + * (which gives the indexer the same performance benefit as the compiler). + */ +CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, + int displayDiagnostics); + +/** + * Destroy the given index. + * + * The index must not be destroyed until all of the translation units created + * within that index have been destroyed. + */ +CINDEX_LINKAGE void clang_disposeIndex(CXIndex index); + +typedef enum { + /** + * Used to indicate that no special CXIndex options are needed. + */ + CXGlobalOpt_None = 0x0, + + /** + * Used to indicate that threads that libclang creates for indexing + * purposes should use background priority. + * + * Affects #clang_indexSourceFile, #clang_indexTranslationUnit, + * #clang_parseTranslationUnit, #clang_saveTranslationUnit. + */ + CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1, + + /** + * Used to indicate that threads that libclang creates for editing + * purposes should use background priority. + * + * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt, + * #clang_annotateTokens + */ + CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2, + + /** + * Used to indicate that all threads that libclang creates should use + * background priority. + */ + CXGlobalOpt_ThreadBackgroundPriorityForAll = + CXGlobalOpt_ThreadBackgroundPriorityForIndexing | + CXGlobalOpt_ThreadBackgroundPriorityForEditing + +} CXGlobalOptFlags; + +/** + * Sets general options associated with a CXIndex. + * + * For example: + * \code + * CXIndex idx = ...; + * clang_CXIndex_setGlobalOptions(idx, + * clang_CXIndex_getGlobalOptions(idx) | + * CXGlobalOpt_ThreadBackgroundPriorityForIndexing); + * \endcode + * + * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags. + */ +CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options); + +/** + * Gets the general options associated with a CXIndex. + * + * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that + * are associated with the given CXIndex object. + */ +CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex); + +/** + * Sets the invocation emission path option in a CXIndex. + * + * The invocation emission path specifies a path which will contain log + * files for certain libclang invocations. A null value (default) implies that + * libclang invocations are not logged.. + */ +CINDEX_LINKAGE void +clang_CXIndex_setInvocationEmissionPathOption(CXIndex, const char *Path); + +/** + * \defgroup CINDEX_FILES File manipulation routines + * + * @{ + */ + +/** + * A particular source file that is part of a translation unit. + */ +typedef void *CXFile; + +/** + * Retrieve the complete file and path name of the given file. + */ +CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile); + +/** + * Retrieve the last modification time of the given file. + */ +CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); + +/** + * Uniquely identifies a CXFile, that refers to the same underlying file, + * across an indexing session. + */ +typedef struct { + unsigned long long data[3]; +} CXFileUniqueID; + +/** + * Retrieve the unique ID for the given \c file. + * + * \param file the file to get the ID for. + * \param outID stores the returned CXFileUniqueID. + * \returns If there was a failure getting the unique ID, returns non-zero, + * otherwise returns 0. +*/ +CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID); + +/** + * Determine whether the given header is guarded against + * multiple inclusions, either with the conventional + * \#ifndef/\#define/\#endif macro guards or with \#pragma once. + */ +CINDEX_LINKAGE unsigned +clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file); + +/** + * Retrieve a file handle within the given translation unit. + * + * \param tu the translation unit + * + * \param file_name the name of the file. + * + * \returns the file handle for the named file in the translation unit \p tu, + * or a NULL file handle if the file was not a part of this translation unit. + */ +CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, + const char *file_name); + +/** + * Retrieve the buffer associated with the given file. + * + * \param tu the translation unit + * + * \param file the file for which to retrieve the buffer. + * + * \param size [out] if non-NULL, will be set to the size of the buffer. + * + * \returns a pointer to the buffer in memory that holds the contents of + * \p file, or a NULL pointer when the file is not loaded. + */ +CINDEX_LINKAGE const char *clang_getFileContents(CXTranslationUnit tu, + CXFile file, size_t *size); + +/** + * Returns non-zero if the \c file1 and \c file2 point to the same file, + * or they are both NULL. + */ +CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); + +/** + * Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + +/** + * @} + */ + +/** + * \defgroup CINDEX_LOCATIONS Physical source locations + * + * Clang represents physical source locations in its abstract syntax tree in + * great detail, with file, line, and column information for the majority of + * the tokens parsed in the source code. These data types and functions are + * used to represent source location information, either for a particular + * point in the program or for a range of points in the program, and extract + * specific location information from those data types. + * + * @{ + */ + +/** + * Identifies a specific source location within a translation + * unit. + * + * Use clang_getExpansionLocation() or clang_getSpellingLocation() + * to map a source location to a particular file, line, and column. + */ +typedef struct { + const void *ptr_data[2]; + unsigned int_data; +} CXSourceLocation; + +/** + * Identifies a half-open character range in the source code. + * + * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the + * starting and end locations from a source range, respectively. + */ +typedef struct { + const void *ptr_data[2]; + unsigned begin_int_data; + unsigned end_int_data; +} CXSourceRange; + +/** + * Retrieve a NULL (invalid) source location. + */ +CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void); + +/** + * Determine whether two source locations, which must refer into + * the same translation unit, refer to exactly the same point in the source + * code. + * + * \returns non-zero if the source locations refer to the same location, zero + * if they refer to different locations. + */ +CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1, + CXSourceLocation loc2); + +/** + * Retrieves the source location associated with a given file/line/column + * in a particular translation unit. + */ +CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu, + CXFile file, + unsigned line, + unsigned column); +/** + * Retrieves the source location associated with a given character offset + * in a particular translation unit. + */ +CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu, + CXFile file, + unsigned offset); + +/** + * Returns non-zero if the given source location is in a system header. + */ +CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location); + +/** + * Returns non-zero if the given source location is in the main file of + * the corresponding translation unit. + */ +CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location); + +/** + * Retrieve a NULL (invalid) source range. + */ +CINDEX_LINKAGE CXSourceRange clang_getNullRange(void); + +/** + * Retrieve a source range given the beginning and ending source + * locations. + */ +CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, + CXSourceLocation end); + +/** + * Determine whether two ranges are equivalent. + * + * \returns non-zero if the ranges are the same, zero if they differ. + */ +CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1, + CXSourceRange range2); + +/** + * Returns non-zero if \p range is null. + */ +CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range); + +/** + * Retrieve the file, line, column, and offset represented by + * the given source location. + * + * If the location refers into a macro expansion, retrieves the + * location of the macro expansion. + * + * \param location the location within a source file that will be decomposed + * into its parts. + * + * \param file [out] if non-NULL, will be set to the file to which the given + * source location points. + * + * \param line [out] if non-NULL, will be set to the line to which the given + * source location points. + * + * \param column [out] if non-NULL, will be set to the column to which the given + * source location points. + * + * \param offset [out] if non-NULL, will be set to the offset into the + * buffer to which the given source location points. + */ +CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset); + +/** + * Retrieve the file, line and column represented by the given source + * location, as specified in a # line directive. + * + * Example: given the following source code in a file somefile.c + * + * \code + * #123 "dummy.c" 1 + * + * static int func(void) + * { + * return 0; + * } + * \endcode + * + * the location information returned by this function would be + * + * File: dummy.c Line: 124 Column: 12 + * + * whereas clang_getExpansionLocation would have returned + * + * File: somefile.c Line: 3 Column: 12 + * + * \param location the location within a source file that will be decomposed + * into its parts. + * + * \param filename [out] if non-NULL, will be set to the filename of the + * source location. Note that filenames returned will be for "virtual" files, + * which don't necessarily exist on the machine running clang - e.g. when + * parsing preprocessed output obtained from a different environment. If + * a non-NULL value is passed in, remember to dispose of the returned value + * using \c clang_disposeString() once you've finished with it. For an invalid + * source location, an empty string is returned. + * + * \param line [out] if non-NULL, will be set to the line number of the + * source location. For an invalid source location, zero is returned. + * + * \param column [out] if non-NULL, will be set to the column number of the + * source location. For an invalid source location, zero is returned. + */ +CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location, + CXString *filename, + unsigned *line, + unsigned *column); + +/** + * Legacy API to retrieve the file, line, column, and offset represented + * by the given source location. + * + * This interface has been replaced by the newer interface + * #clang_getExpansionLocation(). See that interface's documentation for + * details. + */ +CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset); + +/** + * Retrieve the file, line, column, and offset represented by + * the given source location. + * + * If the location refers into a macro instantiation, return where the + * location was originally spelled in the source file. + * + * \param location the location within a source file that will be decomposed + * into its parts. + * + * \param file [out] if non-NULL, will be set to the file to which the given + * source location points. + * + * \param line [out] if non-NULL, will be set to the line to which the given + * source location points. + * + * \param column [out] if non-NULL, will be set to the column to which the given + * source location points. + * + * \param offset [out] if non-NULL, will be set to the offset into the + * buffer to which the given source location points. + */ +CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset); + +/** + * Retrieve the file, line, column, and offset represented by + * the given source location. + * + * If the location refers into a macro expansion, return where the macro was + * expanded or where the macro argument was written, if the location points at + * a macro argument. + * + * \param location the location within a source file that will be decomposed + * into its parts. + * + * \param file [out] if non-NULL, will be set to the file to which the given + * source location points. + * + * \param line [out] if non-NULL, will be set to the line to which the given + * source location points. + * + * \param column [out] if non-NULL, will be set to the column to which the given + * source location points. + * + * \param offset [out] if non-NULL, will be set to the offset into the + * buffer to which the given source location points. + */ +CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset); + +/** + * Retrieve a source location representing the first character within a + * source range. + */ +CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); + +/** + * Retrieve a source location representing the last character within a + * source range. + */ +CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); + +/** + * Identifies an array of ranges. + */ +typedef struct { + /** The number of ranges in the \c ranges array. */ + unsigned count; + /** + * An array of \c CXSourceRanges. + */ + CXSourceRange *ranges; +} CXSourceRangeList; + +/** + * Retrieve all ranges that were skipped by the preprocessor. + * + * The preprocessor will skip lines when they are surrounded by an + * if/ifdef/ifndef directive whose condition does not evaluate to true. + */ +CINDEX_LINKAGE CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit tu, + CXFile file); + +/** + * Retrieve all ranges from all files that were skipped by the + * preprocessor. + * + * The preprocessor will skip lines when they are surrounded by an + * if/ifdef/ifndef directive whose condition does not evaluate to true. + */ +CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit tu); + +/** + * Destroy the given \c CXSourceRangeList. + */ +CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges); + +/** + * @} + */ + +/** + * \defgroup CINDEX_DIAG Diagnostic reporting + * + * @{ + */ + +/** + * Describes the severity of a particular diagnostic. + */ +enum CXDiagnosticSeverity { + /** + * A diagnostic that has been suppressed, e.g., by a command-line + * option. + */ + CXDiagnostic_Ignored = 0, + + /** + * This diagnostic is a note that should be attached to the + * previous (non-note) diagnostic. + */ + CXDiagnostic_Note = 1, + + /** + * This diagnostic indicates suspicious code that may not be + * wrong. + */ + CXDiagnostic_Warning = 2, + + /** + * This diagnostic indicates that the code is ill-formed. + */ + CXDiagnostic_Error = 3, + + /** + * This diagnostic indicates that the code is ill-formed such + * that future parser recovery is unlikely to produce useful + * results. + */ + CXDiagnostic_Fatal = 4 +}; + +/** + * A single diagnostic, containing the diagnostic's severity, + * location, text, source ranges, and fix-it hints. + */ +typedef void *CXDiagnostic; + +/** + * A group of CXDiagnostics. + */ +typedef void *CXDiagnosticSet; + +/** + * Determine the number of diagnostics in a CXDiagnosticSet. + */ +CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags); + +/** + * Retrieve a diagnostic associated with the given CXDiagnosticSet. + * + * \param Diags the CXDiagnosticSet to query. + * \param Index the zero-based diagnostic number to retrieve. + * + * \returns the requested diagnostic. This diagnostic must be freed + * via a call to \c clang_disposeDiagnostic(). + */ +CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags, + unsigned Index); + +/** + * Describes the kind of error that occurred (if any) in a call to + * \c clang_loadDiagnostics. + */ +enum CXLoadDiag_Error { + /** + * Indicates that no error occurred. + */ + CXLoadDiag_None = 0, + + /** + * Indicates that an unknown error occurred while attempting to + * deserialize diagnostics. + */ + CXLoadDiag_Unknown = 1, + + /** + * Indicates that the file containing the serialized diagnostics + * could not be opened. + */ + CXLoadDiag_CannotLoad = 2, + + /** + * Indicates that the serialized diagnostics file is invalid or + * corrupt. + */ + CXLoadDiag_InvalidFile = 3 +}; + +/** + * Deserialize a set of diagnostics from a Clang diagnostics bitcode + * file. + * + * \param file The name of the file to deserialize. + * \param error A pointer to a enum value recording if there was a problem + * deserializing the diagnostics. + * \param errorString A pointer to a CXString for recording the error string + * if the file was not successfully loaded. + * + * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These + * diagnostics should be released using clang_disposeDiagnosticSet(). + */ +CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file, + enum CXLoadDiag_Error *error, + CXString *errorString); + +/** + * Release a CXDiagnosticSet and all of its contained diagnostics. + */ +CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags); + +/** + * Retrieve the child diagnostics of a CXDiagnostic. + * + * This CXDiagnosticSet does not need to be released by + * clang_disposeDiagnosticSet. + */ +CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D); + +/** + * Determine the number of diagnostics produced for the given + * translation unit. + */ +CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit); + +/** + * Retrieve a diagnostic associated with the given translation unit. + * + * \param Unit the translation unit to query. + * \param Index the zero-based diagnostic number to retrieve. + * + * \returns the requested diagnostic. This diagnostic must be freed + * via a call to \c clang_disposeDiagnostic(). + */ +CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, + unsigned Index); + +/** + * Retrieve the complete set of diagnostics associated with a + * translation unit. + * + * \param Unit the translation unit to query. + */ +CINDEX_LINKAGE CXDiagnosticSet + clang_getDiagnosticSetFromTU(CXTranslationUnit Unit); + +/** + * Destroy a diagnostic. + */ +CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic); + +/** + * Options to control the display of diagnostics. + * + * The values in this enum are meant to be combined to customize the + * behavior of \c clang_formatDiagnostic(). + */ +enum CXDiagnosticDisplayOptions { + /** + * Display the source-location information where the + * diagnostic was located. + * + * When set, diagnostics will be prefixed by the file, line, and + * (optionally) column to which the diagnostic refers. For example, + * + * \code + * test.c:28: warning: extra tokens at end of #endif directive + * \endcode + * + * This option corresponds to the clang flag \c -fshow-source-location. + */ + CXDiagnostic_DisplaySourceLocation = 0x01, + + /** + * If displaying the source-location information of the + * diagnostic, also include the column number. + * + * This option corresponds to the clang flag \c -fshow-column. + */ + CXDiagnostic_DisplayColumn = 0x02, + + /** + * If displaying the source-location information of the + * diagnostic, also include information about source ranges in a + * machine-parsable format. + * + * This option corresponds to the clang flag + * \c -fdiagnostics-print-source-range-info. + */ + CXDiagnostic_DisplaySourceRanges = 0x04, + + /** + * Display the option name associated with this diagnostic, if any. + * + * The option name displayed (e.g., -Wconversion) will be placed in brackets + * after the diagnostic text. This option corresponds to the clang flag + * \c -fdiagnostics-show-option. + */ + CXDiagnostic_DisplayOption = 0x08, + + /** + * Display the category number associated with this diagnostic, if any. + * + * The category number is displayed within brackets after the diagnostic text. + * This option corresponds to the clang flag + * \c -fdiagnostics-show-category=id. + */ + CXDiagnostic_DisplayCategoryId = 0x10, + + /** + * Display the category name associated with this diagnostic, if any. + * + * The category name is displayed within brackets after the diagnostic text. + * This option corresponds to the clang flag + * \c -fdiagnostics-show-category=name. + */ + CXDiagnostic_DisplayCategoryName = 0x20 +}; + +/** + * Format the given diagnostic in a manner that is suitable for display. + * + * This routine will format the given diagnostic to a string, rendering + * the diagnostic according to the various options given. The + * \c clang_defaultDiagnosticDisplayOptions() function returns the set of + * options that most closely mimics the behavior of the clang compiler. + * + * \param Diagnostic The diagnostic to print. + * + * \param Options A set of options that control the diagnostic display, + * created by combining \c CXDiagnosticDisplayOptions values. + * + * \returns A new string containing for formatted diagnostic. + */ +CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, + unsigned Options); + +/** + * Retrieve the set of display options most similar to the + * default behavior of the clang compiler. + * + * \returns A set of display options suitable for use with \c + * clang_formatDiagnostic(). + */ +CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void); + +/** + * Determine the severity of the given diagnostic. + */ +CINDEX_LINKAGE enum CXDiagnosticSeverity +clang_getDiagnosticSeverity(CXDiagnostic); + +/** + * Retrieve the source location of the given diagnostic. + * + * This location is where Clang would print the caret ('^') when + * displaying the diagnostic on the command line. + */ +CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic); + +/** + * Retrieve the text of the given diagnostic. + */ +CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic); + +/** + * Retrieve the name of the command-line option that enabled this + * diagnostic. + * + * \param Diag The diagnostic to be queried. + * + * \param Disable If non-NULL, will be set to the option that disables this + * diagnostic (if any). + * + * \returns A string that contains the command-line option used to enable this + * warning, such as "-Wconversion" or "-pedantic". + */ +CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag, + CXString *Disable); + +/** + * Retrieve the category number for this diagnostic. + * + * Diagnostics can be categorized into groups along with other, related + * diagnostics (e.g., diagnostics under the same warning flag). This routine + * retrieves the category number for the given diagnostic. + * + * \returns The number of the category that contains this diagnostic, or zero + * if this diagnostic is uncategorized. + */ +CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic); + +/** + * Retrieve the name of a particular diagnostic category. This + * is now deprecated. Use clang_getDiagnosticCategoryText() + * instead. + * + * \param Category A diagnostic category number, as returned by + * \c clang_getDiagnosticCategory(). + * + * \returns The name of the given diagnostic category. + */ +CINDEX_DEPRECATED CINDEX_LINKAGE +CXString clang_getDiagnosticCategoryName(unsigned Category); + +/** + * Retrieve the diagnostic category text for a given diagnostic. + * + * \returns The text of the given diagnostic category. + */ +CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic); + +/** + * Determine the number of source ranges associated with the given + * diagnostic. + */ +CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic); + +/** + * Retrieve a source range associated with the diagnostic. + * + * A diagnostic's source ranges highlight important elements in the source + * code. On the command line, Clang displays source ranges by + * underlining them with '~' characters. + * + * \param Diagnostic the diagnostic whose range is being extracted. + * + * \param Range the zero-based index specifying which range to + * + * \returns the requested source range. + */ +CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic, + unsigned Range); + +/** + * Determine the number of fix-it hints associated with the + * given diagnostic. + */ +CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic); + +/** + * Retrieve the replacement information for a given fix-it. + * + * Fix-its are described in terms of a source range whose contents + * should be replaced by a string. This approach generalizes over + * three kinds of operations: removal of source code (the range covers + * the code to be removed and the replacement string is empty), + * replacement of source code (the range covers the code to be + * replaced and the replacement string provides the new code), and + * insertion (both the start and end of the range point at the + * insertion location, and the replacement string provides the text to + * insert). + * + * \param Diagnostic The diagnostic whose fix-its are being queried. + * + * \param FixIt The zero-based index of the fix-it. + * + * \param ReplacementRange The source range whose contents will be + * replaced with the returned replacement string. Note that source + * ranges are half-open ranges [a, b), so the source code should be + * replaced from a and up to (but not including) b. + * + * \returns A string containing text that should be replace the source + * code indicated by the \c ReplacementRange. + */ +CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic, + unsigned FixIt, + CXSourceRange *ReplacementRange); + +/** + * @} + */ + +/** + * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation + * + * The routines in this group provide the ability to create and destroy + * translation units from files, either by parsing the contents of the files or + * by reading in a serialized representation of a translation unit. + * + * @{ + */ + +/** + * Get the original translation unit source file name. + */ +CINDEX_LINKAGE CXString +clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); + +/** + * Return the CXTranslationUnit for a given source file and the provided + * command line arguments one would pass to the compiler. + * + * Note: The 'source_filename' argument is optional. If the caller provides a + * NULL pointer, the name of the source file is expected to reside in the + * specified command line arguments. + * + * Note: When encountered in 'clang_command_line_args', the following options + * are ignored: + * + * '-c' + * '-emit-ast' + * '-fsyntax-only' + * '-o \' (both '-o' and '\' are ignored) + * + * \param CIdx The index object with which the translation unit will be + * associated. + * + * \param source_filename The name of the source file to load, or NULL if the + * source file is included in \p clang_command_line_args. + * + * \param num_clang_command_line_args The number of command-line arguments in + * \p clang_command_line_args. + * + * \param clang_command_line_args The command-line arguments that would be + * passed to the \c clang executable if it were being invoked out-of-process. + * These command-line options will be parsed and will affect how the translation + * unit is parsed. Note that the following options are ignored: '-c', + * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \'. + * + * \param num_unsaved_files the number of unsaved file entries in \p + * unsaved_files. + * + * \param unsaved_files the files that have not yet been saved to disk + * but may be required for code completion, including the contents of + * those files. The contents and name of these files (as specified by + * CXUnsavedFile) are copied when necessary, so the client only needs to + * guarantee their validity until the call to this function returns. + */ +CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( + CXIndex CIdx, + const char *source_filename, + int num_clang_command_line_args, + const char * const *clang_command_line_args, + unsigned num_unsaved_files, + struct CXUnsavedFile *unsaved_files); + +/** + * Same as \c clang_createTranslationUnit2, but returns + * the \c CXTranslationUnit instead of an error code. In case of an error this + * routine returns a \c NULL \c CXTranslationUnit, without further detailed + * error codes. + */ +CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit( + CXIndex CIdx, + const char *ast_filename); + +/** + * Create a translation unit from an AST file (\c -emit-ast). + * + * \param[out] out_TU A non-NULL pointer to store the created + * \c CXTranslationUnit. + * + * \returns Zero on success, otherwise returns an error code. + */ +CINDEX_LINKAGE enum CXErrorCode clang_createTranslationUnit2( + CXIndex CIdx, + const char *ast_filename, + CXTranslationUnit *out_TU); + +/** + * Flags that control the creation of translation units. + * + * The enumerators in this enumeration type are meant to be bitwise + * ORed together to specify which options should be used when + * constructing the translation unit. + */ +enum CXTranslationUnit_Flags { + /** + * Used to indicate that no special translation-unit options are + * needed. + */ + CXTranslationUnit_None = 0x0, + + /** + * Used to indicate that the parser should construct a "detailed" + * preprocessing record, including all macro definitions and instantiations. + * + * Constructing a detailed preprocessing record requires more memory + * and time to parse, since the information contained in the record + * is usually not retained. However, it can be useful for + * applications that require more detailed information about the + * behavior of the preprocessor. + */ + CXTranslationUnit_DetailedPreprocessingRecord = 0x01, + + /** + * Used to indicate that the translation unit is incomplete. + * + * When a translation unit is considered "incomplete", semantic + * analysis that is typically performed at the end of the + * translation unit will be suppressed. For example, this suppresses + * the completion of tentative declarations in C and of + * instantiation of implicitly-instantiation function templates in + * C++. This option is typically used when parsing a header with the + * intent of producing a precompiled header. + */ + CXTranslationUnit_Incomplete = 0x02, + + /** + * Used to indicate that the translation unit should be built with an + * implicit precompiled header for the preamble. + * + * An implicit precompiled header is used as an optimization when a + * particular translation unit is likely to be reparsed many times + * when the sources aren't changing that often. In this case, an + * implicit precompiled header will be built containing all of the + * initial includes at the top of the main file (what we refer to as + * the "preamble" of the file). In subsequent parses, if the + * preamble or the files in it have not changed, \c + * clang_reparseTranslationUnit() will re-use the implicit + * precompiled header to improve parsing performance. + */ + CXTranslationUnit_PrecompiledPreamble = 0x04, + + /** + * Used to indicate that the translation unit should cache some + * code-completion results with each reparse of the source file. + * + * Caching of code-completion results is a performance optimization that + * introduces some overhead to reparsing but improves the performance of + * code-completion operations. + */ + CXTranslationUnit_CacheCompletionResults = 0x08, + + /** + * Used to indicate that the translation unit will be serialized with + * \c clang_saveTranslationUnit. + * + * This option is typically used when parsing a header with the intent of + * producing a precompiled header. + */ + CXTranslationUnit_ForSerialization = 0x10, + + /** + * DEPRECATED: Enabled chained precompiled preambles in C++. + * + * Note: this is a *temporary* option that is available only while + * we are testing C++ precompiled preamble support. It is deprecated. + */ + CXTranslationUnit_CXXChainedPCH = 0x20, + + /** + * Used to indicate that function/method bodies should be skipped while + * parsing. + * + * This option can be used to search for declarations/definitions while + * ignoring the usages. + */ + CXTranslationUnit_SkipFunctionBodies = 0x40, + + /** + * Used to indicate that brief documentation comments should be + * included into the set of code completions returned from this translation + * unit. + */ + CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80, + + /** + * Used to indicate that the precompiled preamble should be created on + * the first parse. Otherwise it will be created on the first reparse. This + * trades runtime on the first parse (serializing the preamble takes time) for + * reduced runtime on the second parse (can now reuse the preamble). + */ + CXTranslationUnit_CreatePreambleOnFirstParse = 0x100, + + /** + * Do not stop processing when fatal errors are encountered. + * + * When fatal errors are encountered while parsing a translation unit, + * semantic analysis is typically stopped early when compiling code. A common + * source for fatal errors are unresolvable include files. For the + * purposes of an IDE, this is undesirable behavior and as much information + * as possible should be reported. Use this flag to enable this behavior. + */ + CXTranslationUnit_KeepGoing = 0x200, + + /** + * Sets the preprocessor in a mode for parsing a single file only. + */ + CXTranslationUnit_SingleFileParse = 0x400, + + /** + * Used in combination with CXTranslationUnit_SkipFunctionBodies to + * constrain the skipping of function bodies to the preamble. + * + * The function bodies of the main file are not skipped. + */ + CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800 +}; + +/** + * Returns the set of flags that is suitable for parsing a translation + * unit that is being edited. + * + * The set of flags returned provide options for \c clang_parseTranslationUnit() + * to indicate that the translation unit is likely to be reparsed many times, + * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly + * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag + * set contains an unspecified set of optimizations (e.g., the precompiled + * preamble) geared toward improving the performance of these routines. The + * set of optimizations enabled may change from one version to the next. + */ +CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void); + +/** + * Same as \c clang_parseTranslationUnit2, but returns + * the \c CXTranslationUnit instead of an error code. In case of an error this + * routine returns a \c NULL \c CXTranslationUnit, without further detailed + * error codes. + */ +CINDEX_LINKAGE CXTranslationUnit +clang_parseTranslationUnit(CXIndex CIdx, + const char *source_filename, + const char *const *command_line_args, + int num_command_line_args, + struct CXUnsavedFile *unsaved_files, + unsigned num_unsaved_files, + unsigned options); + +/** + * Parse the given source file and the translation unit corresponding + * to that file. + * + * This routine is the main entry point for the Clang C API, providing the + * ability to parse a source file into a translation unit that can then be + * queried by other functions in the API. This routine accepts a set of + * command-line arguments so that the compilation can be configured in the same + * way that the compiler is configured on the command line. + * + * \param CIdx The index object with which the translation unit will be + * associated. + * + * \param source_filename The name of the source file to load, or NULL if the + * source file is included in \c command_line_args. + * + * \param command_line_args The command-line arguments that would be + * passed to the \c clang executable if it were being invoked out-of-process. + * These command-line options will be parsed and will affect how the translation + * unit is parsed. Note that the following options are ignored: '-c', + * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \'. + * + * \param num_command_line_args The number of command-line arguments in + * \c command_line_args. + * + * \param unsaved_files the files that have not yet been saved to disk + * but may be required for parsing, including the contents of + * those files. The contents and name of these files (as specified by + * CXUnsavedFile) are copied when necessary, so the client only needs to + * guarantee their validity until the call to this function returns. + * + * \param num_unsaved_files the number of unsaved file entries in \p + * unsaved_files. + * + * \param options A bitmask of options that affects how the translation unit + * is managed but not its compilation. This should be a bitwise OR of the + * CXTranslationUnit_XXX flags. + * + * \param[out] out_TU A non-NULL pointer to store the created + * \c CXTranslationUnit, describing the parsed code and containing any + * diagnostics produced by the compiler. + * + * \returns Zero on success, otherwise returns an error code. + */ +CINDEX_LINKAGE enum CXErrorCode +clang_parseTranslationUnit2(CXIndex CIdx, + const char *source_filename, + const char *const *command_line_args, + int num_command_line_args, + struct CXUnsavedFile *unsaved_files, + unsigned num_unsaved_files, + unsigned options, + CXTranslationUnit *out_TU); + +/** + * Same as clang_parseTranslationUnit2 but requires a full command line + * for \c command_line_args including argv[0]. This is useful if the standard + * library paths are relative to the binary. + */ +CINDEX_LINKAGE enum CXErrorCode clang_parseTranslationUnit2FullArgv( + CXIndex CIdx, const char *source_filename, + const char *const *command_line_args, int num_command_line_args, + struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files, + unsigned options, CXTranslationUnit *out_TU); + +/** + * Flags that control how translation units are saved. + * + * The enumerators in this enumeration type are meant to be bitwise + * ORed together to specify which options should be used when + * saving the translation unit. + */ +enum CXSaveTranslationUnit_Flags { + /** + * Used to indicate that no special saving options are needed. + */ + CXSaveTranslationUnit_None = 0x0 +}; + +/** + * Returns the set of flags that is suitable for saving a translation + * unit. + * + * The set of flags returned provide options for + * \c clang_saveTranslationUnit() by default. The returned flag + * set contains an unspecified set of options that save translation units with + * the most commonly-requested data. + */ +CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU); + +/** + * Describes the kind of error that occurred (if any) in a call to + * \c clang_saveTranslationUnit(). + */ +enum CXSaveError { + /** + * Indicates that no error occurred while saving a translation unit. + */ + CXSaveError_None = 0, + + /** + * Indicates that an unknown error occurred while attempting to save + * the file. + * + * This error typically indicates that file I/O failed when attempting to + * write the file. + */ + CXSaveError_Unknown = 1, + + /** + * Indicates that errors during translation prevented this attempt + * to save the translation unit. + * + * Errors that prevent the translation unit from being saved can be + * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic(). + */ + CXSaveError_TranslationErrors = 2, + + /** + * Indicates that the translation unit to be saved was somehow + * invalid (e.g., NULL). + */ + CXSaveError_InvalidTU = 3 +}; + +/** + * Saves a translation unit into a serialized representation of + * that translation unit on disk. + * + * Any translation unit that was parsed without error can be saved + * into a file. The translation unit can then be deserialized into a + * new \c CXTranslationUnit with \c clang_createTranslationUnit() or, + * if it is an incomplete translation unit that corresponds to a + * header, used as a precompiled header when parsing other translation + * units. + * + * \param TU The translation unit to save. + * + * \param FileName The file to which the translation unit will be saved. + * + * \param options A bitmask of options that affects how the translation unit + * is saved. This should be a bitwise OR of the + * CXSaveTranslationUnit_XXX flags. + * + * \returns A value that will match one of the enumerators of the CXSaveError + * enumeration. Zero (CXSaveError_None) indicates that the translation unit was + * saved successfully, while a non-zero value indicates that a problem occurred. + */ +CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU, + const char *FileName, + unsigned options); + +/** + * Suspend a translation unit in order to free memory associated with it. + * + * A suspended translation unit uses significantly less memory but on the other + * side does not support any other calls than \c clang_reparseTranslationUnit + * to resume it or \c clang_disposeTranslationUnit to dispose it completely. + */ +CINDEX_LINKAGE unsigned clang_suspendTranslationUnit(CXTranslationUnit); + +/** + * Destroy the specified CXTranslationUnit object. + */ +CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); + +/** + * Flags that control the reparsing of translation units. + * + * The enumerators in this enumeration type are meant to be bitwise + * ORed together to specify which options should be used when + * reparsing the translation unit. + */ +enum CXReparse_Flags { + /** + * Used to indicate that no special reparsing options are needed. + */ + CXReparse_None = 0x0 +}; + +/** + * Returns the set of flags that is suitable for reparsing a translation + * unit. + * + * The set of flags returned provide options for + * \c clang_reparseTranslationUnit() by default. The returned flag + * set contains an unspecified set of optimizations geared toward common uses + * of reparsing. The set of optimizations enabled may change from one version + * to the next. + */ +CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU); + +/** + * Reparse the source files that produced this translation unit. + * + * This routine can be used to re-parse the source files that originally + * created the given translation unit, for example because those source files + * have changed (either on disk or as passed via \p unsaved_files). The + * source code will be reparsed with the same command-line options as it + * was originally parsed. + * + * Reparsing a translation unit invalidates all cursors and source locations + * that refer into that translation unit. This makes reparsing a translation + * unit semantically equivalent to destroying the translation unit and then + * creating a new translation unit with the same command-line arguments. + * However, it may be more efficient to reparse a translation + * unit using this routine. + * + * \param TU The translation unit whose contents will be re-parsed. The + * translation unit must originally have been built with + * \c clang_createTranslationUnitFromSourceFile(). + * + * \param num_unsaved_files The number of unsaved file entries in \p + * unsaved_files. + * + * \param unsaved_files The files that have not yet been saved to disk + * but may be required for parsing, including the contents of + * those files. The contents and name of these files (as specified by + * CXUnsavedFile) are copied when necessary, so the client only needs to + * guarantee their validity until the call to this function returns. + * + * \param options A bitset of options composed of the flags in CXReparse_Flags. + * The function \c clang_defaultReparseOptions() produces a default set of + * options recommended for most uses, based on the translation unit. + * + * \returns 0 if the sources could be reparsed. A non-zero error code will be + * returned if reparsing was impossible, such that the translation unit is + * invalid. In such cases, the only valid call for \c TU is + * \c clang_disposeTranslationUnit(TU). The error codes returned by this + * routine are described by the \c CXErrorCode enum. + */ +CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU, + unsigned num_unsaved_files, + struct CXUnsavedFile *unsaved_files, + unsigned options); + +/** + * Categorizes how memory is being used by a translation unit. + */ +enum CXTUResourceUsageKind { + CXTUResourceUsage_AST = 1, + CXTUResourceUsage_Identifiers = 2, + CXTUResourceUsage_Selectors = 3, + CXTUResourceUsage_GlobalCompletionResults = 4, + CXTUResourceUsage_SourceManagerContentCache = 5, + CXTUResourceUsage_AST_SideTables = 6, + CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7, + CXTUResourceUsage_SourceManager_Membuffer_MMap = 8, + CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9, + CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10, + CXTUResourceUsage_Preprocessor = 11, + CXTUResourceUsage_PreprocessingRecord = 12, + CXTUResourceUsage_SourceManager_DataStructures = 13, + CXTUResourceUsage_Preprocessor_HeaderSearch = 14, + CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST, + CXTUResourceUsage_MEMORY_IN_BYTES_END = + CXTUResourceUsage_Preprocessor_HeaderSearch, + + CXTUResourceUsage_First = CXTUResourceUsage_AST, + CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch +}; + +/** + * Returns the human-readable null-terminated C string that represents + * the name of the memory category. This string should never be freed. + */ +CINDEX_LINKAGE +const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind); + +typedef struct CXTUResourceUsageEntry { + /* The memory usage category. */ + enum CXTUResourceUsageKind kind; + /* Amount of resources used. + The units will depend on the resource kind. */ + unsigned long amount; +} CXTUResourceUsageEntry; + +/** + * The memory usage of a CXTranslationUnit, broken into categories. + */ +typedef struct CXTUResourceUsage { + /* Private data member, used for queries. */ + void *data; + + /* The number of entries in the 'entries' array. */ + unsigned numEntries; + + /* An array of key-value pairs, representing the breakdown of memory + usage. */ + CXTUResourceUsageEntry *entries; + +} CXTUResourceUsage; + +/** + * Return the memory usage of a translation unit. This object + * should be released with clang_disposeCXTUResourceUsage(). + */ +CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU); + +CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage); + +/** + * Get target information for this translation unit. + * + * The CXTargetInfo object cannot outlive the CXTranslationUnit object. + */ +CINDEX_LINKAGE CXTargetInfo +clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit); + +/** + * Destroy the CXTargetInfo object. + */ +CINDEX_LINKAGE void +clang_TargetInfo_dispose(CXTargetInfo Info); + +/** + * Get the normalized target triple as a string. + * + * Returns the empty string in case of any error. + */ +CINDEX_LINKAGE CXString +clang_TargetInfo_getTriple(CXTargetInfo Info); + +/** + * Get the pointer width of the target in bits. + * + * Returns -1 in case of error. + */ +CINDEX_LINKAGE int +clang_TargetInfo_getPointerWidth(CXTargetInfo Info); + +/** + * @} + */ + +/** + * Describes the kind of entity that a cursor refers to. + */ +enum CXCursorKind { + /* Declarations */ + /** + * A declaration whose specific kind is not exposed via this + * interface. + * + * Unexposed declarations have the same operations as any other kind + * of declaration; one can extract their location information, + * spelling, find their definitions, etc. However, the specific kind + * of the declaration is not reported. + */ + CXCursor_UnexposedDecl = 1, + /** A C or C++ struct. */ + CXCursor_StructDecl = 2, + /** A C or C++ union. */ + CXCursor_UnionDecl = 3, + /** A C++ class. */ + CXCursor_ClassDecl = 4, + /** An enumeration. */ + CXCursor_EnumDecl = 5, + /** + * A field (in C) or non-static data member (in C++) in a + * struct, union, or C++ class. + */ + CXCursor_FieldDecl = 6, + /** An enumerator constant. */ + CXCursor_EnumConstantDecl = 7, + /** A function. */ + CXCursor_FunctionDecl = 8, + /** A variable. */ + CXCursor_VarDecl = 9, + /** A function or method parameter. */ + CXCursor_ParmDecl = 10, + /** An Objective-C \@interface. */ + CXCursor_ObjCInterfaceDecl = 11, + /** An Objective-C \@interface for a category. */ + CXCursor_ObjCCategoryDecl = 12, + /** An Objective-C \@protocol declaration. */ + CXCursor_ObjCProtocolDecl = 13, + /** An Objective-C \@property declaration. */ + CXCursor_ObjCPropertyDecl = 14, + /** An Objective-C instance variable. */ + CXCursor_ObjCIvarDecl = 15, + /** An Objective-C instance method. */ + CXCursor_ObjCInstanceMethodDecl = 16, + /** An Objective-C class method. */ + CXCursor_ObjCClassMethodDecl = 17, + /** An Objective-C \@implementation. */ + CXCursor_ObjCImplementationDecl = 18, + /** An Objective-C \@implementation for a category. */ + CXCursor_ObjCCategoryImplDecl = 19, + /** A typedef. */ + CXCursor_TypedefDecl = 20, + /** A C++ class method. */ + CXCursor_CXXMethod = 21, + /** A C++ namespace. */ + CXCursor_Namespace = 22, + /** A linkage specification, e.g. 'extern "C"'. */ + CXCursor_LinkageSpec = 23, + /** A C++ constructor. */ + CXCursor_Constructor = 24, + /** A C++ destructor. */ + CXCursor_Destructor = 25, + /** A C++ conversion function. */ + CXCursor_ConversionFunction = 26, + /** A C++ template type parameter. */ + CXCursor_TemplateTypeParameter = 27, + /** A C++ non-type template parameter. */ + CXCursor_NonTypeTemplateParameter = 28, + /** A C++ template template parameter. */ + CXCursor_TemplateTemplateParameter = 29, + /** A C++ function template. */ + CXCursor_FunctionTemplate = 30, + /** A C++ class template. */ + CXCursor_ClassTemplate = 31, + /** A C++ class template partial specialization. */ + CXCursor_ClassTemplatePartialSpecialization = 32, + /** A C++ namespace alias declaration. */ + CXCursor_NamespaceAlias = 33, + /** A C++ using directive. */ + CXCursor_UsingDirective = 34, + /** A C++ using declaration. */ + CXCursor_UsingDeclaration = 35, + /** A C++ alias declaration */ + CXCursor_TypeAliasDecl = 36, + /** An Objective-C \@synthesize definition. */ + CXCursor_ObjCSynthesizeDecl = 37, + /** An Objective-C \@dynamic definition. */ + CXCursor_ObjCDynamicDecl = 38, + /** An access specifier. */ + CXCursor_CXXAccessSpecifier = 39, + + CXCursor_FirstDecl = CXCursor_UnexposedDecl, + CXCursor_LastDecl = CXCursor_CXXAccessSpecifier, + + /* References */ + CXCursor_FirstRef = 40, /* Decl references */ + CXCursor_ObjCSuperClassRef = 40, + CXCursor_ObjCProtocolRef = 41, + CXCursor_ObjCClassRef = 42, + /** + * A reference to a type declaration. + * + * A type reference occurs anywhere where a type is named but not + * declared. For example, given: + * + * \code + * typedef unsigned size_type; + * size_type size; + * \endcode + * + * The typedef is a declaration of size_type (CXCursor_TypedefDecl), + * while the type of the variable "size" is referenced. The cursor + * referenced by the type of size is the typedef for size_type. + */ + CXCursor_TypeRef = 43, + CXCursor_CXXBaseSpecifier = 44, + /** + * A reference to a class template, function template, template + * template parameter, or class template partial specialization. + */ + CXCursor_TemplateRef = 45, + /** + * A reference to a namespace or namespace alias. + */ + CXCursor_NamespaceRef = 46, + /** + * A reference to a member of a struct, union, or class that occurs in + * some non-expression context, e.g., a designated initializer. + */ + CXCursor_MemberRef = 47, + /** + * A reference to a labeled statement. + * + * This cursor kind is used to describe the jump to "start_over" in the + * goto statement in the following example: + * + * \code + * start_over: + * ++counter; + * + * goto start_over; + * \endcode + * + * A label reference cursor refers to a label statement. + */ + CXCursor_LabelRef = 48, + + /** + * A reference to a set of overloaded functions or function templates + * that has not yet been resolved to a specific function or function template. + * + * An overloaded declaration reference cursor occurs in C++ templates where + * a dependent name refers to a function. For example: + * + * \code + * template void swap(T&, T&); + * + * struct X { ... }; + * void swap(X&, X&); + * + * template + * void reverse(T* first, T* last) { + * while (first < last - 1) { + * swap(*first, *--last); + * ++first; + * } + * } + * + * struct Y { }; + * void swap(Y&, Y&); + * \endcode + * + * Here, the identifier "swap" is associated with an overloaded declaration + * reference. In the template definition, "swap" refers to either of the two + * "swap" functions declared above, so both results will be available. At + * instantiation time, "swap" may also refer to other functions found via + * argument-dependent lookup (e.g., the "swap" function at the end of the + * example). + * + * The functions \c clang_getNumOverloadedDecls() and + * \c clang_getOverloadedDecl() can be used to retrieve the definitions + * referenced by this cursor. + */ + CXCursor_OverloadedDeclRef = 49, + + /** + * A reference to a variable that occurs in some non-expression + * context, e.g., a C++ lambda capture list. + */ + CXCursor_VariableRef = 50, + + CXCursor_LastRef = CXCursor_VariableRef, + + /* Error conditions */ + CXCursor_FirstInvalid = 70, + CXCursor_InvalidFile = 70, + CXCursor_NoDeclFound = 71, + CXCursor_NotImplemented = 72, + CXCursor_InvalidCode = 73, + CXCursor_LastInvalid = CXCursor_InvalidCode, + + /* Expressions */ + CXCursor_FirstExpr = 100, + + /** + * An expression whose specific kind is not exposed via this + * interface. + * + * Unexposed expressions have the same operations as any other kind + * of expression; one can extract their location information, + * spelling, children, etc. However, the specific kind of the + * expression is not reported. + */ + CXCursor_UnexposedExpr = 100, + + /** + * An expression that refers to some value declaration, such + * as a function, variable, or enumerator. + */ + CXCursor_DeclRefExpr = 101, + + /** + * An expression that refers to a member of a struct, union, + * class, Objective-C class, etc. + */ + CXCursor_MemberRefExpr = 102, + + /** An expression that calls a function. */ + CXCursor_CallExpr = 103, + + /** An expression that sends a message to an Objective-C + object or class. */ + CXCursor_ObjCMessageExpr = 104, + + /** An expression that represents a block literal. */ + CXCursor_BlockExpr = 105, + + /** An integer literal. + */ + CXCursor_IntegerLiteral = 106, + + /** A floating point number literal. + */ + CXCursor_FloatingLiteral = 107, + + /** An imaginary number literal. + */ + CXCursor_ImaginaryLiteral = 108, + + /** A string literal. + */ + CXCursor_StringLiteral = 109, + + /** A character literal. + */ + CXCursor_CharacterLiteral = 110, + + /** A parenthesized expression, e.g. "(1)". + * + * This AST node is only formed if full location information is requested. + */ + CXCursor_ParenExpr = 111, + + /** This represents the unary-expression's (except sizeof and + * alignof). + */ + CXCursor_UnaryOperator = 112, + + /** [C99 6.5.2.1] Array Subscripting. + */ + CXCursor_ArraySubscriptExpr = 113, + + /** A builtin binary operation expression such as "x + y" or + * "x <= y". + */ + CXCursor_BinaryOperator = 114, + + /** Compound assignment such as "+=". + */ + CXCursor_CompoundAssignOperator = 115, + + /** The ?: ternary operator. + */ + CXCursor_ConditionalOperator = 116, + + /** An explicit cast in C (C99 6.5.4) or a C-style cast in C++ + * (C++ [expr.cast]), which uses the syntax (Type)expr. + * + * For example: (int)f. + */ + CXCursor_CStyleCastExpr = 117, + + /** [C99 6.5.2.5] + */ + CXCursor_CompoundLiteralExpr = 118, + + /** Describes an C or C++ initializer list. + */ + CXCursor_InitListExpr = 119, + + /** The GNU address of label extension, representing &&label. + */ + CXCursor_AddrLabelExpr = 120, + + /** This is the GNU Statement Expression extension: ({int X=4; X;}) + */ + CXCursor_StmtExpr = 121, + + /** Represents a C11 generic selection. + */ + CXCursor_GenericSelectionExpr = 122, + + /** Implements the GNU __null extension, which is a name for a null + * pointer constant that has integral type (e.g., int or long) and is the same + * size and alignment as a pointer. + * + * The __null extension is typically only used by system headers, which define + * NULL as __null in C++ rather than using 0 (which is an integer that may not + * match the size of a pointer). + */ + CXCursor_GNUNullExpr = 123, + + /** C++'s static_cast<> expression. + */ + CXCursor_CXXStaticCastExpr = 124, + + /** C++'s dynamic_cast<> expression. + */ + CXCursor_CXXDynamicCastExpr = 125, + + /** C++'s reinterpret_cast<> expression. + */ + CXCursor_CXXReinterpretCastExpr = 126, + + /** C++'s const_cast<> expression. + */ + CXCursor_CXXConstCastExpr = 127, + + /** Represents an explicit C++ type conversion that uses "functional" + * notion (C++ [expr.type.conv]). + * + * Example: + * \code + * x = int(0.5); + * \endcode + */ + CXCursor_CXXFunctionalCastExpr = 128, + + /** A C++ typeid expression (C++ [expr.typeid]). + */ + CXCursor_CXXTypeidExpr = 129, + + /** [C++ 2.13.5] C++ Boolean Literal. + */ + CXCursor_CXXBoolLiteralExpr = 130, + + /** [C++0x 2.14.7] C++ Pointer Literal. + */ + CXCursor_CXXNullPtrLiteralExpr = 131, + + /** Represents the "this" expression in C++ + */ + CXCursor_CXXThisExpr = 132, + + /** [C++ 15] C++ Throw Expression. + * + * This handles 'throw' and 'throw' assignment-expression. When + * assignment-expression isn't present, Op will be null. + */ + CXCursor_CXXThrowExpr = 133, + + /** A new expression for memory allocation and constructor calls, e.g: + * "new CXXNewExpr(foo)". + */ + CXCursor_CXXNewExpr = 134, + + /** A delete expression for memory deallocation and destructor calls, + * e.g. "delete[] pArray". + */ + CXCursor_CXXDeleteExpr = 135, + + /** A unary expression. (noexcept, sizeof, or other traits) + */ + CXCursor_UnaryExpr = 136, + + /** An Objective-C string literal i.e. @"foo". + */ + CXCursor_ObjCStringLiteral = 137, + + /** An Objective-C \@encode expression. + */ + CXCursor_ObjCEncodeExpr = 138, + + /** An Objective-C \@selector expression. + */ + CXCursor_ObjCSelectorExpr = 139, + + /** An Objective-C \@protocol expression. + */ + CXCursor_ObjCProtocolExpr = 140, + + /** An Objective-C "bridged" cast expression, which casts between + * Objective-C pointers and C pointers, transferring ownership in the process. + * + * \code + * NSString *str = (__bridge_transfer NSString *)CFCreateString(); + * \endcode + */ + CXCursor_ObjCBridgedCastExpr = 141, + + /** Represents a C++0x pack expansion that produces a sequence of + * expressions. + * + * A pack expansion expression contains a pattern (which itself is an + * expression) followed by an ellipsis. For example: + * + * \code + * template + * void forward(F f, Types &&...args) { + * f(static_cast(args)...); + * } + * \endcode + */ + CXCursor_PackExpansionExpr = 142, + + /** Represents an expression that computes the length of a parameter + * pack. + * + * \code + * template + * struct count { + * static const unsigned value = sizeof...(Types); + * }; + * \endcode + */ + CXCursor_SizeOfPackExpr = 143, + + /* Represents a C++ lambda expression that produces a local function + * object. + * + * \code + * void abssort(float *x, unsigned N) { + * std::sort(x, x + N, + * [](float a, float b) { + * return std::abs(a) < std::abs(b); + * }); + * } + * \endcode + */ + CXCursor_LambdaExpr = 144, + + /** Objective-c Boolean Literal. + */ + CXCursor_ObjCBoolLiteralExpr = 145, + + /** Represents the "self" expression in an Objective-C method. + */ + CXCursor_ObjCSelfExpr = 146, + + /** OpenMP 4.0 [2.4, Array Section]. + */ + CXCursor_OMPArraySectionExpr = 147, + + /** Represents an @available(...) check. + */ + CXCursor_ObjCAvailabilityCheckExpr = 148, + + /** + * Fixed point literal + */ + CXCursor_FixedPointLiteral = 149, + + CXCursor_LastExpr = CXCursor_FixedPointLiteral, + + /* Statements */ + CXCursor_FirstStmt = 200, + /** + * A statement whose specific kind is not exposed via this + * interface. + * + * Unexposed statements have the same operations as any other kind of + * statement; one can extract their location information, spelling, + * children, etc. However, the specific kind of the statement is not + * reported. + */ + CXCursor_UnexposedStmt = 200, + + /** A labelled statement in a function. + * + * This cursor kind is used to describe the "start_over:" label statement in + * the following example: + * + * \code + * start_over: + * ++counter; + * \endcode + * + */ + CXCursor_LabelStmt = 201, + + /** A group of statements like { stmt stmt }. + * + * This cursor kind is used to describe compound statements, e.g. function + * bodies. + */ + CXCursor_CompoundStmt = 202, + + /** A case statement. + */ + CXCursor_CaseStmt = 203, + + /** A default statement. + */ + CXCursor_DefaultStmt = 204, + + /** An if statement + */ + CXCursor_IfStmt = 205, + + /** A switch statement. + */ + CXCursor_SwitchStmt = 206, + + /** A while statement. + */ + CXCursor_WhileStmt = 207, + + /** A do statement. + */ + CXCursor_DoStmt = 208, + + /** A for statement. + */ + CXCursor_ForStmt = 209, + + /** A goto statement. + */ + CXCursor_GotoStmt = 210, + + /** An indirect goto statement. + */ + CXCursor_IndirectGotoStmt = 211, + + /** A continue statement. + */ + CXCursor_ContinueStmt = 212, + + /** A break statement. + */ + CXCursor_BreakStmt = 213, + + /** A return statement. + */ + CXCursor_ReturnStmt = 214, + + /** A GCC inline assembly statement extension. + */ + CXCursor_GCCAsmStmt = 215, + CXCursor_AsmStmt = CXCursor_GCCAsmStmt, + + /** Objective-C's overall \@try-\@catch-\@finally statement. + */ + CXCursor_ObjCAtTryStmt = 216, + + /** Objective-C's \@catch statement. + */ + CXCursor_ObjCAtCatchStmt = 217, + + /** Objective-C's \@finally statement. + */ + CXCursor_ObjCAtFinallyStmt = 218, + + /** Objective-C's \@throw statement. + */ + CXCursor_ObjCAtThrowStmt = 219, + + /** Objective-C's \@synchronized statement. + */ + CXCursor_ObjCAtSynchronizedStmt = 220, + + /** Objective-C's autorelease pool statement. + */ + CXCursor_ObjCAutoreleasePoolStmt = 221, + + /** Objective-C's collection statement. + */ + CXCursor_ObjCForCollectionStmt = 222, + + /** C++'s catch statement. + */ + CXCursor_CXXCatchStmt = 223, + + /** C++'s try statement. + */ + CXCursor_CXXTryStmt = 224, + + /** C++'s for (* : *) statement. + */ + CXCursor_CXXForRangeStmt = 225, + + /** Windows Structured Exception Handling's try statement. + */ + CXCursor_SEHTryStmt = 226, + + /** Windows Structured Exception Handling's except statement. + */ + CXCursor_SEHExceptStmt = 227, + + /** Windows Structured Exception Handling's finally statement. + */ + CXCursor_SEHFinallyStmt = 228, + + /** A MS inline assembly statement extension. + */ + CXCursor_MSAsmStmt = 229, + + /** The null statement ";": C99 6.8.3p3. + * + * This cursor kind is used to describe the null statement. + */ + CXCursor_NullStmt = 230, + + /** Adaptor class for mixing declarations with statements and + * expressions. + */ + CXCursor_DeclStmt = 231, + + /** OpenMP parallel directive. + */ + CXCursor_OMPParallelDirective = 232, + + /** OpenMP SIMD directive. + */ + CXCursor_OMPSimdDirective = 233, + + /** OpenMP for directive. + */ + CXCursor_OMPForDirective = 234, + + /** OpenMP sections directive. + */ + CXCursor_OMPSectionsDirective = 235, + + /** OpenMP section directive. + */ + CXCursor_OMPSectionDirective = 236, + + /** OpenMP single directive. + */ + CXCursor_OMPSingleDirective = 237, + + /** OpenMP parallel for directive. + */ + CXCursor_OMPParallelForDirective = 238, + + /** OpenMP parallel sections directive. + */ + CXCursor_OMPParallelSectionsDirective = 239, + + /** OpenMP task directive. + */ + CXCursor_OMPTaskDirective = 240, + + /** OpenMP master directive. + */ + CXCursor_OMPMasterDirective = 241, + + /** OpenMP critical directive. + */ + CXCursor_OMPCriticalDirective = 242, + + /** OpenMP taskyield directive. + */ + CXCursor_OMPTaskyieldDirective = 243, + + /** OpenMP barrier directive. + */ + CXCursor_OMPBarrierDirective = 244, + + /** OpenMP taskwait directive. + */ + CXCursor_OMPTaskwaitDirective = 245, + + /** OpenMP flush directive. + */ + CXCursor_OMPFlushDirective = 246, + + /** Windows Structured Exception Handling's leave statement. + */ + CXCursor_SEHLeaveStmt = 247, + + /** OpenMP ordered directive. + */ + CXCursor_OMPOrderedDirective = 248, + + /** OpenMP atomic directive. + */ + CXCursor_OMPAtomicDirective = 249, + + /** OpenMP for SIMD directive. + */ + CXCursor_OMPForSimdDirective = 250, + + /** OpenMP parallel for SIMD directive. + */ + CXCursor_OMPParallelForSimdDirective = 251, + + /** OpenMP target directive. + */ + CXCursor_OMPTargetDirective = 252, + + /** OpenMP teams directive. + */ + CXCursor_OMPTeamsDirective = 253, + + /** OpenMP taskgroup directive. + */ + CXCursor_OMPTaskgroupDirective = 254, + + /** OpenMP cancellation point directive. + */ + CXCursor_OMPCancellationPointDirective = 255, + + /** OpenMP cancel directive. + */ + CXCursor_OMPCancelDirective = 256, + + /** OpenMP target data directive. + */ + CXCursor_OMPTargetDataDirective = 257, + + /** OpenMP taskloop directive. + */ + CXCursor_OMPTaskLoopDirective = 258, + + /** OpenMP taskloop simd directive. + */ + CXCursor_OMPTaskLoopSimdDirective = 259, + + /** OpenMP distribute directive. + */ + CXCursor_OMPDistributeDirective = 260, + + /** OpenMP target enter data directive. + */ + CXCursor_OMPTargetEnterDataDirective = 261, + + /** OpenMP target exit data directive. + */ + CXCursor_OMPTargetExitDataDirective = 262, + + /** OpenMP target parallel directive. + */ + CXCursor_OMPTargetParallelDirective = 263, + + /** OpenMP target parallel for directive. + */ + CXCursor_OMPTargetParallelForDirective = 264, + + /** OpenMP target update directive. + */ + CXCursor_OMPTargetUpdateDirective = 265, + + /** OpenMP distribute parallel for directive. + */ + CXCursor_OMPDistributeParallelForDirective = 266, + + /** OpenMP distribute parallel for simd directive. + */ + CXCursor_OMPDistributeParallelForSimdDirective = 267, + + /** OpenMP distribute simd directive. + */ + CXCursor_OMPDistributeSimdDirective = 268, + + /** OpenMP target parallel for simd directive. + */ + CXCursor_OMPTargetParallelForSimdDirective = 269, + + /** OpenMP target simd directive. + */ + CXCursor_OMPTargetSimdDirective = 270, + + /** OpenMP teams distribute directive. + */ + CXCursor_OMPTeamsDistributeDirective = 271, + + /** OpenMP teams distribute simd directive. + */ + CXCursor_OMPTeamsDistributeSimdDirective = 272, + + /** OpenMP teams distribute parallel for simd directive. + */ + CXCursor_OMPTeamsDistributeParallelForSimdDirective = 273, + + /** OpenMP teams distribute parallel for directive. + */ + CXCursor_OMPTeamsDistributeParallelForDirective = 274, + + /** OpenMP target teams directive. + */ + CXCursor_OMPTargetTeamsDirective = 275, + + /** OpenMP target teams distribute directive. + */ + CXCursor_OMPTargetTeamsDistributeDirective = 276, + + /** OpenMP target teams distribute parallel for directive. + */ + CXCursor_OMPTargetTeamsDistributeParallelForDirective = 277, + + /** OpenMP target teams distribute parallel for simd directive. + */ + CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective = 278, + + /** OpenMP target teams distribute simd directive. + */ + CXCursor_OMPTargetTeamsDistributeSimdDirective = 279, + + CXCursor_LastStmt = CXCursor_OMPTargetTeamsDistributeSimdDirective, + + /** + * Cursor that represents the translation unit itself. + * + * The translation unit cursor exists primarily to act as the root + * cursor for traversing the contents of a translation unit. + */ + CXCursor_TranslationUnit = 300, + + /* Attributes */ + CXCursor_FirstAttr = 400, + /** + * An attribute whose specific kind is not exposed via this + * interface. + */ + CXCursor_UnexposedAttr = 400, + + CXCursor_IBActionAttr = 401, + CXCursor_IBOutletAttr = 402, + CXCursor_IBOutletCollectionAttr = 403, + CXCursor_CXXFinalAttr = 404, + CXCursor_CXXOverrideAttr = 405, + CXCursor_AnnotateAttr = 406, + CXCursor_AsmLabelAttr = 407, + CXCursor_PackedAttr = 408, + CXCursor_PureAttr = 409, + CXCursor_ConstAttr = 410, + CXCursor_NoDuplicateAttr = 411, + CXCursor_CUDAConstantAttr = 412, + CXCursor_CUDADeviceAttr = 413, + CXCursor_CUDAGlobalAttr = 414, + CXCursor_CUDAHostAttr = 415, + CXCursor_CUDASharedAttr = 416, + CXCursor_VisibilityAttr = 417, + CXCursor_DLLExport = 418, + CXCursor_DLLImport = 419, + CXCursor_LastAttr = CXCursor_DLLImport, + + /* Preprocessing */ + CXCursor_PreprocessingDirective = 500, + CXCursor_MacroDefinition = 501, + CXCursor_MacroExpansion = 502, + CXCursor_MacroInstantiation = CXCursor_MacroExpansion, + CXCursor_InclusionDirective = 503, + CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective, + CXCursor_LastPreprocessing = CXCursor_InclusionDirective, + + /* Extra Declarations */ + /** + * A module import declaration. + */ + CXCursor_ModuleImportDecl = 600, + CXCursor_TypeAliasTemplateDecl = 601, + /** + * A static_assert or _Static_assert node + */ + CXCursor_StaticAssert = 602, + /** + * a friend declaration. + */ + CXCursor_FriendDecl = 603, + CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl, + CXCursor_LastExtraDecl = CXCursor_FriendDecl, + + /** + * A code completion overload candidate. + */ + CXCursor_OverloadCandidate = 700 +}; + +/** + * A cursor representing some element in the abstract syntax tree for + * a translation unit. + * + * The cursor abstraction unifies the different kinds of entities in a + * program--declaration, statements, expressions, references to declarations, + * etc.--under a single "cursor" abstraction with a common set of operations. + * Common operation for a cursor include: getting the physical location in + * a source file where the cursor points, getting the name associated with a + * cursor, and retrieving cursors for any child nodes of a particular cursor. + * + * Cursors can be produced in two specific ways. + * clang_getTranslationUnitCursor() produces a cursor for a translation unit, + * from which one can use clang_visitChildren() to explore the rest of the + * translation unit. clang_getCursor() maps from a physical source location + * to the entity that resides at that location, allowing one to map from the + * source code into the AST. + */ +typedef struct { + enum CXCursorKind kind; + int xdata; + const void *data[3]; +} CXCursor; + +/** + * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations + * + * @{ + */ + +/** + * Retrieve the NULL cursor, which represents no entity. + */ +CINDEX_LINKAGE CXCursor clang_getNullCursor(void); + +/** + * Retrieve the cursor that represents the given translation unit. + * + * The translation unit cursor can be used to start traversing the + * various declarations within the given translation unit. + */ +CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); + +/** + * Determine whether two cursors are equivalent. + */ +CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); + +/** + * Returns non-zero if \p cursor is null. + */ +CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor); + +/** + * Compute a hash value for the given cursor. + */ +CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor); + +/** + * Retrieve the kind of the given cursor. + */ +CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); + +/** + * Determine whether the given cursor kind represents a declaration. + */ +CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); + +/** + * Determine whether the given declaration is invalid. + * + * A declaration is invalid if it could not be parsed successfully. + * + * \returns non-zero if the cursor represents a declaration and it is + * invalid, otherwise NULL. + */ +CINDEX_LINKAGE unsigned clang_isInvalidDeclaration(CXCursor); + +/** + * Determine whether the given cursor kind represents a simple + * reference. + * + * Note that other kinds of cursors (such as expressions) can also refer to + * other cursors. Use clang_getCursorReferenced() to determine whether a + * particular cursor refers to another entity. + */ +CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); + +/** + * Determine whether the given cursor kind represents an expression. + */ +CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); + +/** + * Determine whether the given cursor kind represents a statement. + */ +CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); + +/** + * Determine whether the given cursor kind represents an attribute. + */ +CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind); + +/** + * Determine whether the given cursor has any attributes. + */ +CINDEX_LINKAGE unsigned clang_Cursor_hasAttrs(CXCursor C); + +/** + * Determine whether the given cursor kind represents an invalid + * cursor. + */ +CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); + +/** + * Determine whether the given cursor kind represents a translation + * unit. + */ +CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind); + +/*** + * Determine whether the given cursor represents a preprocessing + * element, such as a preprocessor directive or macro instantiation. + */ +CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind); + +/*** + * Determine whether the given cursor represents a currently + * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt). + */ +CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind); + +/** + * Describe the linkage of the entity referred to by a cursor. + */ +enum CXLinkageKind { + /** This value indicates that no linkage information is available + * for a provided CXCursor. */ + CXLinkage_Invalid, + /** + * This is the linkage for variables, parameters, and so on that + * have automatic storage. This covers normal (non-extern) local variables. + */ + CXLinkage_NoLinkage, + /** This is the linkage for static variables and static functions. */ + CXLinkage_Internal, + /** This is the linkage for entities with external linkage that live + * in C++ anonymous namespaces.*/ + CXLinkage_UniqueExternal, + /** This is the linkage for entities with true, external linkage. */ + CXLinkage_External +}; + +/** + * Determine the linkage of the entity referred to by a given cursor. + */ +CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor); + +enum CXVisibilityKind { + /** This value indicates that no visibility information is available + * for a provided CXCursor. */ + CXVisibility_Invalid, + + /** Symbol not seen by the linker. */ + CXVisibility_Hidden, + /** Symbol seen by the linker but resolves to a symbol inside this object. */ + CXVisibility_Protected, + /** Symbol seen by the linker and acts like a normal symbol. */ + CXVisibility_Default +}; + +/** + * Describe the visibility of the entity referred to by a cursor. + * + * This returns the default visibility if not explicitly specified by + * a visibility attribute. The default visibility may be changed by + * commandline arguments. + * + * \param cursor The cursor to query. + * + * \returns The visibility of the cursor. + */ +CINDEX_LINKAGE enum CXVisibilityKind clang_getCursorVisibility(CXCursor cursor); + +/** + * Determine the availability of the entity that this cursor refers to, + * taking the current target platform into account. + * + * \param cursor The cursor to query. + * + * \returns The availability of the cursor. + */ +CINDEX_LINKAGE enum CXAvailabilityKind +clang_getCursorAvailability(CXCursor cursor); + +/** + * Describes the availability of a given entity on a particular platform, e.g., + * a particular class might only be available on Mac OS 10.7 or newer. + */ +typedef struct CXPlatformAvailability { + /** + * A string that describes the platform for which this structure + * provides availability information. + * + * Possible values are "ios" or "macos". + */ + CXString Platform; + /** + * The version number in which this entity was introduced. + */ + CXVersion Introduced; + /** + * The version number in which this entity was deprecated (but is + * still available). + */ + CXVersion Deprecated; + /** + * The version number in which this entity was obsoleted, and therefore + * is no longer available. + */ + CXVersion Obsoleted; + /** + * Whether the entity is unconditionally unavailable on this platform. + */ + int Unavailable; + /** + * An optional message to provide to a user of this API, e.g., to + * suggest replacement APIs. + */ + CXString Message; +} CXPlatformAvailability; + +/** + * Determine the availability of the entity that this cursor refers to + * on any platforms for which availability information is known. + * + * \param cursor The cursor to query. + * + * \param always_deprecated If non-NULL, will be set to indicate whether the + * entity is deprecated on all platforms. + * + * \param deprecated_message If non-NULL, will be set to the message text + * provided along with the unconditional deprecation of this entity. The client + * is responsible for deallocating this string. + * + * \param always_unavailable If non-NULL, will be set to indicate whether the + * entity is unavailable on all platforms. + * + * \param unavailable_message If non-NULL, will be set to the message text + * provided along with the unconditional unavailability of this entity. The + * client is responsible for deallocating this string. + * + * \param availability If non-NULL, an array of CXPlatformAvailability instances + * that will be populated with platform availability information, up to either + * the number of platforms for which availability information is available (as + * returned by this function) or \c availability_size, whichever is smaller. + * + * \param availability_size The number of elements available in the + * \c availability array. + * + * \returns The number of platforms (N) for which availability information is + * available (which is unrelated to \c availability_size). + * + * Note that the client is responsible for calling + * \c clang_disposeCXPlatformAvailability to free each of the + * platform-availability structures returned. There are + * \c min(N, availability_size) such structures. + */ +CINDEX_LINKAGE int +clang_getCursorPlatformAvailability(CXCursor cursor, + int *always_deprecated, + CXString *deprecated_message, + int *always_unavailable, + CXString *unavailable_message, + CXPlatformAvailability *availability, + int availability_size); + +/** + * Free the memory associated with a \c CXPlatformAvailability structure. + */ +CINDEX_LINKAGE void +clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability); + +/** + * Describe the "language" of the entity referred to by a cursor. + */ +enum CXLanguageKind { + CXLanguage_Invalid = 0, + CXLanguage_C, + CXLanguage_ObjC, + CXLanguage_CPlusPlus +}; + +/** + * Determine the "language" of the entity referred to by a given cursor. + */ +CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor); + +/** + * Describe the "thread-local storage (TLS) kind" of the declaration + * referred to by a cursor. + */ +enum CXTLSKind { + CXTLS_None = 0, + CXTLS_Dynamic, + CXTLS_Static +}; + +/** + * Determine the "thread-local storage (TLS) kind" of the declaration + * referred to by a cursor. + */ +CINDEX_LINKAGE enum CXTLSKind clang_getCursorTLSKind(CXCursor cursor); + +/** + * Returns the translation unit that a cursor originated from. + */ +CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor); + +/** + * A fast container representing a set of CXCursors. + */ +typedef struct CXCursorSetImpl *CXCursorSet; + +/** + * Creates an empty CXCursorSet. + */ +CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void); + +/** + * Disposes a CXCursorSet and releases its associated memory. + */ +CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset); + +/** + * Queries a CXCursorSet to see if it contains a specific CXCursor. + * + * \returns non-zero if the set contains the specified cursor. +*/ +CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset, + CXCursor cursor); + +/** + * Inserts a CXCursor into a CXCursorSet. + * + * \returns zero if the CXCursor was already in the set, and non-zero otherwise. +*/ +CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset, + CXCursor cursor); + +/** + * Determine the semantic parent of the given cursor. + * + * The semantic parent of a cursor is the cursor that semantically contains + * the given \p cursor. For many declarations, the lexical and semantic parents + * are equivalent (the lexical parent is returned by + * \c clang_getCursorLexicalParent()). They diverge when declarations or + * definitions are provided out-of-line. For example: + * + * \code + * class C { + * void f(); + * }; + * + * void C::f() { } + * \endcode + * + * In the out-of-line definition of \c C::f, the semantic parent is + * the class \c C, of which this function is a member. The lexical parent is + * the place where the declaration actually occurs in the source code; in this + * case, the definition occurs in the translation unit. In general, the + * lexical parent for a given entity can change without affecting the semantics + * of the program, and the lexical parent of different declarations of the + * same entity may be different. Changing the semantic parent of a declaration, + * on the other hand, can have a major impact on semantics, and redeclarations + * of a particular entity should all have the same semantic context. + * + * In the example above, both declarations of \c C::f have \c C as their + * semantic context, while the lexical context of the first \c C::f is \c C + * and the lexical context of the second \c C::f is the translation unit. + * + * For global declarations, the semantic parent is the translation unit. + */ +CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor); + +/** + * Determine the lexical parent of the given cursor. + * + * The lexical parent of a cursor is the cursor in which the given \p cursor + * was actually written. For many declarations, the lexical and semantic parents + * are equivalent (the semantic parent is returned by + * \c clang_getCursorSemanticParent()). They diverge when declarations or + * definitions are provided out-of-line. For example: + * + * \code + * class C { + * void f(); + * }; + * + * void C::f() { } + * \endcode + * + * In the out-of-line definition of \c C::f, the semantic parent is + * the class \c C, of which this function is a member. The lexical parent is + * the place where the declaration actually occurs in the source code; in this + * case, the definition occurs in the translation unit. In general, the + * lexical parent for a given entity can change without affecting the semantics + * of the program, and the lexical parent of different declarations of the + * same entity may be different. Changing the semantic parent of a declaration, + * on the other hand, can have a major impact on semantics, and redeclarations + * of a particular entity should all have the same semantic context. + * + * In the example above, both declarations of \c C::f have \c C as their + * semantic context, while the lexical context of the first \c C::f is \c C + * and the lexical context of the second \c C::f is the translation unit. + * + * For declarations written in the global scope, the lexical parent is + * the translation unit. + */ +CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor); + +/** + * Determine the set of methods that are overridden by the given + * method. + * + * In both Objective-C and C++, a method (aka virtual member function, + * in C++) can override a virtual method in a base class. For + * Objective-C, a method is said to override any method in the class's + * base class, its protocols, or its categories' protocols, that has the same + * selector and is of the same kind (class or instance). + * If no such method exists, the search continues to the class's superclass, + * its protocols, and its categories, and so on. A method from an Objective-C + * implementation is considered to override the same methods as its + * corresponding method in the interface. + * + * For C++, a virtual member function overrides any virtual member + * function with the same signature that occurs in its base + * classes. With multiple inheritance, a virtual member function can + * override several virtual member functions coming from different + * base classes. + * + * In all cases, this function determines the immediate overridden + * method, rather than all of the overridden methods. For example, if + * a method is originally declared in a class A, then overridden in B + * (which in inherits from A) and also in C (which inherited from B), + * then the only overridden method returned from this function when + * invoked on C's method will be B's method. The client may then + * invoke this function again, given the previously-found overridden + * methods, to map out the complete method-override set. + * + * \param cursor A cursor representing an Objective-C or C++ + * method. This routine will compute the set of methods that this + * method overrides. + * + * \param overridden A pointer whose pointee will be replaced with a + * pointer to an array of cursors, representing the set of overridden + * methods. If there are no overridden methods, the pointee will be + * set to NULL. The pointee must be freed via a call to + * \c clang_disposeOverriddenCursors(). + * + * \param num_overridden A pointer to the number of overridden + * functions, will be set to the number of overridden functions in the + * array pointed to by \p overridden. + */ +CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor, + CXCursor **overridden, + unsigned *num_overridden); + +/** + * Free the set of overridden cursors returned by \c + * clang_getOverriddenCursors(). + */ +CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden); + +/** + * Retrieve the file that is included by the given inclusion directive + * cursor. + */ +CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor); + +/** + * @} + */ + +/** + * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code + * + * Cursors represent a location within the Abstract Syntax Tree (AST). These + * routines help map between cursors and the physical locations where the + * described entities occur in the source code. The mapping is provided in + * both directions, so one can map from source code to the AST and back. + * + * @{ + */ + +/** + * Map a source location to the cursor that describes the entity at that + * location in the source code. + * + * clang_getCursor() maps an arbitrary source location within a translation + * unit down to the most specific cursor that describes the entity at that + * location. For example, given an expression \c x + y, invoking + * clang_getCursor() with a source location pointing to "x" will return the + * cursor for "x"; similarly for "y". If the cursor points anywhere between + * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() + * will return a cursor referring to the "+" expression. + * + * \returns a cursor representing the entity at the given source location, or + * a NULL cursor if no such entity can be found. + */ +CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); + +/** + * Retrieve the physical location of the source constructor referenced + * by the given cursor. + * + * The location of a declaration is typically the location of the name of that + * declaration, where the name of that declaration would occur if it is + * unnamed, or some keyword that introduces that particular declaration. + * The location of a reference is where that reference occurs within the + * source code. + */ +CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); + +/** + * Retrieve the physical extent of the source construct referenced by + * the given cursor. + * + * The extent of a cursor starts with the file/line/column pointing at the + * first character within the source construct that the cursor refers to and + * ends with the last character within that source construct. For a + * declaration, the extent covers the declaration itself. For a reference, + * the extent covers the location of the reference (e.g., where the referenced + * entity was actually used). + */ +CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); + +/** + * @} + */ + +/** + * \defgroup CINDEX_TYPES Type information for CXCursors + * + * @{ + */ + +/** + * Describes the kind of type + */ +enum CXTypeKind { + /** + * Represents an invalid type (e.g., where no type is available). + */ + CXType_Invalid = 0, + + /** + * A type whose specific kind is not exposed via this + * interface. + */ + CXType_Unexposed = 1, + + /* Builtin types */ + CXType_Void = 2, + CXType_Bool = 3, + CXType_Char_U = 4, + CXType_UChar = 5, + CXType_Char16 = 6, + CXType_Char32 = 7, + CXType_UShort = 8, + CXType_UInt = 9, + CXType_ULong = 10, + CXType_ULongLong = 11, + CXType_UInt128 = 12, + CXType_Char_S = 13, + CXType_SChar = 14, + CXType_WChar = 15, + CXType_Short = 16, + CXType_Int = 17, + CXType_Long = 18, + CXType_LongLong = 19, + CXType_Int128 = 20, + CXType_Float = 21, + CXType_Double = 22, + CXType_LongDouble = 23, + CXType_NullPtr = 24, + CXType_Overload = 25, + CXType_Dependent = 26, + CXType_ObjCId = 27, + CXType_ObjCClass = 28, + CXType_ObjCSel = 29, + CXType_Float128 = 30, + CXType_Half = 31, + CXType_Float16 = 32, + CXType_ShortAccum = 33, + CXType_Accum = 34, + CXType_LongAccum = 35, + CXType_UShortAccum = 36, + CXType_UAccum = 37, + CXType_ULongAccum = 38, + CXType_FirstBuiltin = CXType_Void, + CXType_LastBuiltin = CXType_ULongAccum, + + CXType_Complex = 100, + CXType_Pointer = 101, + CXType_BlockPointer = 102, + CXType_LValueReference = 103, + CXType_RValueReference = 104, + CXType_Record = 105, + CXType_Enum = 106, + CXType_Typedef = 107, + CXType_ObjCInterface = 108, + CXType_ObjCObjectPointer = 109, + CXType_FunctionNoProto = 110, + CXType_FunctionProto = 111, + CXType_ConstantArray = 112, + CXType_Vector = 113, + CXType_IncompleteArray = 114, + CXType_VariableArray = 115, + CXType_DependentSizedArray = 116, + CXType_MemberPointer = 117, + CXType_Auto = 118, + + /** + * Represents a type that was referred to using an elaborated type keyword. + * + * E.g., struct S, or via a qualified name, e.g., N::M::type, or both. + */ + CXType_Elaborated = 119, + + /* OpenCL PipeType. */ + CXType_Pipe = 120, + + /* OpenCL builtin types. */ + CXType_OCLImage1dRO = 121, + CXType_OCLImage1dArrayRO = 122, + CXType_OCLImage1dBufferRO = 123, + CXType_OCLImage2dRO = 124, + CXType_OCLImage2dArrayRO = 125, + CXType_OCLImage2dDepthRO = 126, + CXType_OCLImage2dArrayDepthRO = 127, + CXType_OCLImage2dMSAARO = 128, + CXType_OCLImage2dArrayMSAARO = 129, + CXType_OCLImage2dMSAADepthRO = 130, + CXType_OCLImage2dArrayMSAADepthRO = 131, + CXType_OCLImage3dRO = 132, + CXType_OCLImage1dWO = 133, + CXType_OCLImage1dArrayWO = 134, + CXType_OCLImage1dBufferWO = 135, + CXType_OCLImage2dWO = 136, + CXType_OCLImage2dArrayWO = 137, + CXType_OCLImage2dDepthWO = 138, + CXType_OCLImage2dArrayDepthWO = 139, + CXType_OCLImage2dMSAAWO = 140, + CXType_OCLImage2dArrayMSAAWO = 141, + CXType_OCLImage2dMSAADepthWO = 142, + CXType_OCLImage2dArrayMSAADepthWO = 143, + CXType_OCLImage3dWO = 144, + CXType_OCLImage1dRW = 145, + CXType_OCLImage1dArrayRW = 146, + CXType_OCLImage1dBufferRW = 147, + CXType_OCLImage2dRW = 148, + CXType_OCLImage2dArrayRW = 149, + CXType_OCLImage2dDepthRW = 150, + CXType_OCLImage2dArrayDepthRW = 151, + CXType_OCLImage2dMSAARW = 152, + CXType_OCLImage2dArrayMSAARW = 153, + CXType_OCLImage2dMSAADepthRW = 154, + CXType_OCLImage2dArrayMSAADepthRW = 155, + CXType_OCLImage3dRW = 156, + CXType_OCLSampler = 157, + CXType_OCLEvent = 158, + CXType_OCLQueue = 159, + CXType_OCLReserveID = 160 +}; + +/** + * Describes the calling convention of a function type + */ +enum CXCallingConv { + CXCallingConv_Default = 0, + CXCallingConv_C = 1, + CXCallingConv_X86StdCall = 2, + CXCallingConv_X86FastCall = 3, + CXCallingConv_X86ThisCall = 4, + CXCallingConv_X86Pascal = 5, + CXCallingConv_AAPCS = 6, + CXCallingConv_AAPCS_VFP = 7, + CXCallingConv_X86RegCall = 8, + CXCallingConv_IntelOclBicc = 9, + CXCallingConv_Win64 = 10, + /* Alias for compatibility with older versions of API. */ + CXCallingConv_X86_64Win64 = CXCallingConv_Win64, + CXCallingConv_X86_64SysV = 11, + CXCallingConv_X86VectorCall = 12, + CXCallingConv_Swift = 13, + CXCallingConv_PreserveMost = 14, + CXCallingConv_PreserveAll = 15, + + CXCallingConv_Invalid = 100, + CXCallingConv_Unexposed = 200 +}; + +/** + * The type of an element in the abstract syntax tree. + * + */ +typedef struct { + enum CXTypeKind kind; + void *data[2]; +} CXType; + +/** + * Retrieve the type of a CXCursor (if any). + */ +CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C); + +/** + * Pretty-print the underlying type using the rules of the + * language of the translation unit from which it came. + * + * If the type is invalid, an empty string is returned. + */ +CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT); + +/** + * Retrieve the underlying type of a typedef declaration. + * + * If the cursor does not reference a typedef declaration, an invalid type is + * returned. + */ +CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C); + +/** + * Retrieve the integer type of an enum declaration. + * + * If the cursor does not reference an enum declaration, an invalid type is + * returned. + */ +CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C); + +/** + * Retrieve the integer value of an enum constant declaration as a signed + * long long. + * + * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned. + * Since this is also potentially a valid constant value, the kind of the cursor + * must be verified before calling this function. + */ +CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C); + +/** + * Retrieve the integer value of an enum constant declaration as an unsigned + * long long. + * + * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned. + * Since this is also potentially a valid constant value, the kind of the cursor + * must be verified before calling this function. + */ +CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C); + +/** + * Retrieve the bit width of a bit field declaration as an integer. + * + * If a cursor that is not a bit field declaration is passed in, -1 is returned. + */ +CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C); + +/** + * Retrieve the number of non-variadic arguments associated with a given + * cursor. + * + * The number of arguments can be determined for calls as well as for + * declarations of functions or methods. For other cursors -1 is returned. + */ +CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C); + +/** + * Retrieve the argument cursor of a function or method. + * + * The argument cursor can be determined for calls as well as for declarations + * of functions or methods. For other cursors and for invalid indices, an + * invalid cursor is returned. + */ +CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i); + +/** + * Describes the kind of a template argument. + * + * See the definition of llvm::clang::TemplateArgument::ArgKind for full + * element descriptions. + */ +enum CXTemplateArgumentKind { + CXTemplateArgumentKind_Null, + CXTemplateArgumentKind_Type, + CXTemplateArgumentKind_Declaration, + CXTemplateArgumentKind_NullPtr, + CXTemplateArgumentKind_Integral, + CXTemplateArgumentKind_Template, + CXTemplateArgumentKind_TemplateExpansion, + CXTemplateArgumentKind_Expression, + CXTemplateArgumentKind_Pack, + /* Indicates an error case, preventing the kind from being deduced. */ + CXTemplateArgumentKind_Invalid +}; + +/** + *Returns the number of template args of a function decl representing a + * template specialization. + * + * If the argument cursor cannot be converted into a template function + * declaration, -1 is returned. + * + * For example, for the following declaration and specialization: + * template + * void foo() { ... } + * + * template <> + * void foo(); + * + * The value 3 would be returned from this call. + */ +CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C); + +/** + * Retrieve the kind of the I'th template argument of the CXCursor C. + * + * If the argument CXCursor does not represent a FunctionDecl, an invalid + * template argument kind is returned. + * + * For example, for the following declaration and specialization: + * template + * void foo() { ... } + * + * template <> + * void foo(); + * + * For I = 0, 1, and 2, Type, Integral, and Integral will be returned, + * respectively. + */ +CINDEX_LINKAGE enum CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind( + CXCursor C, unsigned I); + +/** + * Retrieve a CXType representing the type of a TemplateArgument of a + * function decl representing a template specialization. + * + * If the argument CXCursor does not represent a FunctionDecl whose I'th + * template argument has a kind of CXTemplateArgKind_Integral, an invalid type + * is returned. + * + * For example, for the following declaration and specialization: + * template + * void foo() { ... } + * + * template <> + * void foo(); + * + * If called with I = 0, "float", will be returned. + * Invalid types will be returned for I == 1 or 2. + */ +CINDEX_LINKAGE CXType clang_Cursor_getTemplateArgumentType(CXCursor C, + unsigned I); + +/** + * Retrieve the value of an Integral TemplateArgument (of a function + * decl representing a template specialization) as a signed long long. + * + * It is undefined to call this function on a CXCursor that does not represent a + * FunctionDecl or whose I'th template argument is not an integral value. + * + * For example, for the following declaration and specialization: + * template + * void foo() { ... } + * + * template <> + * void foo(); + * + * If called with I = 1 or 2, -7 or true will be returned, respectively. + * For I == 0, this function's behavior is undefined. + */ +CINDEX_LINKAGE long long clang_Cursor_getTemplateArgumentValue(CXCursor C, + unsigned I); + +/** + * Retrieve the value of an Integral TemplateArgument (of a function + * decl representing a template specialization) as an unsigned long long. + * + * It is undefined to call this function on a CXCursor that does not represent a + * FunctionDecl or whose I'th template argument is not an integral value. + * + * For example, for the following declaration and specialization: + * template + * void foo() { ... } + * + * template <> + * void foo(); + * + * If called with I = 1 or 2, 2147483649 or true will be returned, respectively. + * For I == 0, this function's behavior is undefined. + */ +CINDEX_LINKAGE unsigned long long clang_Cursor_getTemplateArgumentUnsignedValue( + CXCursor C, unsigned I); + +/** + * Determine whether two CXTypes represent the same type. + * + * \returns non-zero if the CXTypes represent the same type and + * zero otherwise. + */ +CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B); + +/** + * Return the canonical type for a CXType. + * + * Clang's type system explicitly models typedefs and all the ways + * a specific type can be represented. The canonical type is the underlying + * type with all the "sugar" removed. For example, if 'T' is a typedef + * for 'int', the canonical type for 'T' would be 'int'. + */ +CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T); + +/** + * Determine whether a CXType has the "const" qualifier set, + * without looking through typedefs that may have added "const" at a + * different level. + */ +CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T); + +/** + * Determine whether a CXCursor that is a macro, is + * function like. + */ +CINDEX_LINKAGE unsigned clang_Cursor_isMacroFunctionLike(CXCursor C); + +/** + * Determine whether a CXCursor that is a macro, is a + * builtin one. + */ +CINDEX_LINKAGE unsigned clang_Cursor_isMacroBuiltin(CXCursor C); + +/** + * Determine whether a CXCursor that is a function declaration, is an + * inline declaration. + */ +CINDEX_LINKAGE unsigned clang_Cursor_isFunctionInlined(CXCursor C); + +/** + * Determine whether a CXType has the "volatile" qualifier set, + * without looking through typedefs that may have added "volatile" at + * a different level. + */ +CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T); + +/** + * Determine whether a CXType has the "restrict" qualifier set, + * without looking through typedefs that may have added "restrict" at a + * different level. + */ +CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T); + +/** + * Returns the address space of the given type. + */ +CINDEX_LINKAGE unsigned clang_getAddressSpace(CXType T); + +/** + * Returns the typedef name of the given type. + */ +CINDEX_LINKAGE CXString clang_getTypedefName(CXType CT); + +/** + * For pointer types, returns the type of the pointee. + */ +CINDEX_LINKAGE CXType clang_getPointeeType(CXType T); + +/** + * Return the cursor for the declaration of the given type. + */ +CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T); + +/** + * Returns the Objective-C type encoding for the specified declaration. + */ +CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C); + +/** + * Returns the Objective-C type encoding for the specified CXType. + */ +CINDEX_LINKAGE CXString clang_Type_getObjCEncoding(CXType type); + +/** + * Retrieve the spelling of a given CXTypeKind. + */ +CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K); + +/** + * Retrieve the calling convention associated with a function type. + * + * If a non-function type is passed in, CXCallingConv_Invalid is returned. + */ +CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T); + +/** + * Retrieve the return type associated with a function type. + * + * If a non-function type is passed in, an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_getResultType(CXType T); + +/** + * Retrieve the exception specification type associated with a function type. + * This is a value of type CXCursor_ExceptionSpecificationKind. + * + * If a non-function type is passed in, an error code of -1 is returned. + */ +CINDEX_LINKAGE int clang_getExceptionSpecificationType(CXType T); + +/** + * Retrieve the number of non-variadic parameters associated with a + * function type. + * + * If a non-function type is passed in, -1 is returned. + */ +CINDEX_LINKAGE int clang_getNumArgTypes(CXType T); + +/** + * Retrieve the type of a parameter of a function type. + * + * If a non-function type is passed in or the function does not have enough + * parameters, an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i); + +/** + * Return 1 if the CXType is a variadic function type, and 0 otherwise. + */ +CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T); + +/** + * Retrieve the return type associated with a given cursor. + * + * This only returns a valid type if the cursor refers to a function or method. + */ +CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C); + +/** + * Retrieve the exception specification type associated with a given cursor. + * This is a value of type CXCursor_ExceptionSpecificationKind. + * + * This only returns a valid result if the cursor refers to a function or method. + */ +CINDEX_LINKAGE int clang_getCursorExceptionSpecificationType(CXCursor C); + +/** + * Return 1 if the CXType is a POD (plain old data) type, and 0 + * otherwise. + */ +CINDEX_LINKAGE unsigned clang_isPODType(CXType T); + +/** + * Return the element type of an array, complex, or vector type. + * + * If a type is passed in that is not an array, complex, or vector type, + * an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_getElementType(CXType T); + +/** + * Return the number of elements of an array or vector type. + * + * If a type is passed in that is not an array or vector type, + * -1 is returned. + */ +CINDEX_LINKAGE long long clang_getNumElements(CXType T); + +/** + * Return the element type of an array type. + * + * If a non-array type is passed in, an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T); + +/** + * Return the array size of a constant array. + * + * If a non-array type is passed in, -1 is returned. + */ +CINDEX_LINKAGE long long clang_getArraySize(CXType T); + +/** + * Retrieve the type named by the qualified-id. + * + * If a non-elaborated type is passed in, an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_Type_getNamedType(CXType T); + +/** + * Determine if a typedef is 'transparent' tag. + * + * A typedef is considered 'transparent' if it shares a name and spelling + * location with its underlying tag type, as is the case with the NS_ENUM macro. + * + * \returns non-zero if transparent and zero otherwise. + */ +CINDEX_LINKAGE unsigned clang_Type_isTransparentTagTypedef(CXType T); + +/** + * List the possible error codes for \c clang_Type_getSizeOf, + * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and + * \c clang_Cursor_getOffsetOf. + * + * A value of this enumeration type can be returned if the target type is not + * a valid argument to sizeof, alignof or offsetof. + */ +enum CXTypeLayoutError { + /** + * Type is of kind CXType_Invalid. + */ + CXTypeLayoutError_Invalid = -1, + /** + * The type is an incomplete Type. + */ + CXTypeLayoutError_Incomplete = -2, + /** + * The type is a dependent Type. + */ + CXTypeLayoutError_Dependent = -3, + /** + * The type is not a constant size type. + */ + CXTypeLayoutError_NotConstantSize = -4, + /** + * The Field name is not valid for this record. + */ + CXTypeLayoutError_InvalidFieldName = -5 +}; + +/** + * Return the alignment of a type in bytes as per C++[expr.alignof] + * standard. + * + * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned. + * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete + * is returned. + * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is + * returned. + * If the type declaration is not a constant size type, + * CXTypeLayoutError_NotConstantSize is returned. + */ +CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T); + +/** + * Return the class type of an member pointer type. + * + * If a non-member-pointer type is passed in, an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_Type_getClassType(CXType T); + +/** + * Return the size of a type in bytes as per C++[expr.sizeof] standard. + * + * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned. + * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete + * is returned. + * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is + * returned. + */ +CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T); + +/** + * Return the offset of a field named S in a record of type T in bits + * as it would be returned by __offsetof__ as per C++11[18.2p4] + * + * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid + * is returned. + * If the field's type declaration is an incomplete type, + * CXTypeLayoutError_Incomplete is returned. + * If the field's type declaration is a dependent type, + * CXTypeLayoutError_Dependent is returned. + * If the field's name S is not found, + * CXTypeLayoutError_InvalidFieldName is returned. + */ +CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S); + +/** + * Return the offset of the field represented by the Cursor. + * + * If the cursor is not a field declaration, -1 is returned. + * If the cursor semantic parent is not a record field declaration, + * CXTypeLayoutError_Invalid is returned. + * If the field's type declaration is an incomplete type, + * CXTypeLayoutError_Incomplete is returned. + * If the field's type declaration is a dependent type, + * CXTypeLayoutError_Dependent is returned. + * If the field's name S is not found, + * CXTypeLayoutError_InvalidFieldName is returned. + */ +CINDEX_LINKAGE long long clang_Cursor_getOffsetOfField(CXCursor C); + +/** + * Determine whether the given cursor represents an anonymous record + * declaration. + */ +CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C); + +enum CXRefQualifierKind { + /** No ref-qualifier was provided. */ + CXRefQualifier_None = 0, + /** An lvalue ref-qualifier was provided (\c &). */ + CXRefQualifier_LValue, + /** An rvalue ref-qualifier was provided (\c &&). */ + CXRefQualifier_RValue +}; + +/** + * Returns the number of template arguments for given template + * specialization, or -1 if type \c T is not a template specialization. + */ +CINDEX_LINKAGE int clang_Type_getNumTemplateArguments(CXType T); + +/** + * Returns the type template argument of a template class specialization + * at given index. + * + * This function only returns template type arguments and does not handle + * template template arguments or variadic packs. + */ +CINDEX_LINKAGE CXType clang_Type_getTemplateArgumentAsType(CXType T, unsigned i); + +/** + * Retrieve the ref-qualifier kind of a function or method. + * + * The ref-qualifier is returned for C++ functions or methods. For other types + * or non-C++ declarations, CXRefQualifier_None is returned. + */ +CINDEX_LINKAGE enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T); + +/** + * Returns non-zero if the cursor specifies a Record member that is a + * bitfield. + */ +CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C); + +/** + * Returns 1 if the base class specified by the cursor with kind + * CX_CXXBaseSpecifier is virtual. + */ +CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor); + +/** + * Represents the C++ access control level to a base class for a + * cursor with kind CX_CXXBaseSpecifier. + */ +enum CX_CXXAccessSpecifier { + CX_CXXInvalidAccessSpecifier, + CX_CXXPublic, + CX_CXXProtected, + CX_CXXPrivate +}; + +/** + * Returns the access control level for the referenced object. + * + * If the cursor refers to a C++ declaration, its access control level within its + * parent scope is returned. Otherwise, if the cursor refers to a base specifier or + * access specifier, the specifier itself is returned. + */ +CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor); + +/** + * Represents the storage classes as declared in the source. CX_SC_Invalid + * was added for the case that the passed cursor in not a declaration. + */ +enum CX_StorageClass { + CX_SC_Invalid, + CX_SC_None, + CX_SC_Extern, + CX_SC_Static, + CX_SC_PrivateExtern, + CX_SC_OpenCLWorkGroupLocal, + CX_SC_Auto, + CX_SC_Register +}; + +/** + * Returns the storage class for a function or variable declaration. + * + * If the passed in Cursor is not a function or variable declaration, + * CX_SC_Invalid is returned else the storage class. + */ +CINDEX_LINKAGE enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor); + +/** + * Determine the number of overloaded declarations referenced by a + * \c CXCursor_OverloadedDeclRef cursor. + * + * \param cursor The cursor whose overloaded declarations are being queried. + * + * \returns The number of overloaded declarations referenced by \c cursor. If it + * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0. + */ +CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor); + +/** + * Retrieve a cursor for one of the overloaded declarations referenced + * by a \c CXCursor_OverloadedDeclRef cursor. + * + * \param cursor The cursor whose overloaded declarations are being queried. + * + * \param index The zero-based index into the set of overloaded declarations in + * the cursor. + * + * \returns A cursor representing the declaration referenced by the given + * \c cursor at the specified \c index. If the cursor does not have an + * associated set of overloaded declarations, or if the index is out of bounds, + * returns \c clang_getNullCursor(); + */ +CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor, + unsigned index); + +/** + * @} + */ + +/** + * \defgroup CINDEX_ATTRIBUTES Information for attributes + * + * @{ + */ + +/** + * For cursors representing an iboutletcollection attribute, + * this function returns the collection element type. + * + */ +CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor); + +/** + * @} + */ + +/** + * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors + * + * These routines provide the ability to traverse the abstract syntax tree + * using cursors. + * + * @{ + */ + +/** + * Describes how the traversal of the children of a particular + * cursor should proceed after visiting a particular child cursor. + * + * A value of this enumeration type should be returned by each + * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. + */ +enum CXChildVisitResult { + /** + * Terminates the cursor traversal. + */ + CXChildVisit_Break, + /** + * Continues the cursor traversal with the next sibling of + * the cursor just visited, without visiting its children. + */ + CXChildVisit_Continue, + /** + * Recursively traverse the children of this cursor, using + * the same visitor and client data. + */ + CXChildVisit_Recurse +}; + +/** + * Visitor invoked for each cursor found by a traversal. + * + * This visitor function will be invoked for each cursor found by + * clang_visitCursorChildren(). Its first argument is the cursor being + * visited, its second argument is the parent visitor for that cursor, + * and its third argument is the client data provided to + * clang_visitCursorChildren(). + * + * The visitor should return one of the \c CXChildVisitResult values + * to direct clang_visitCursorChildren(). + */ +typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor, + CXCursor parent, + CXClientData client_data); + +/** + * Visit the children of a particular cursor. + * + * This function visits all the direct children of the given cursor, + * invoking the given \p visitor function with the cursors of each + * visited child. The traversal may be recursive, if the visitor returns + * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if + * the visitor returns \c CXChildVisit_Break. + * + * \param parent the cursor whose child may be visited. All kinds of + * cursors can be visited, including invalid cursors (which, by + * definition, have no children). + * + * \param visitor the visitor function that will be invoked for each + * child of \p parent. + * + * \param client_data pointer data supplied by the client, which will + * be passed to the visitor each time it is invoked. + * + * \returns a non-zero value if the traversal was terminated + * prematurely by the visitor returning \c CXChildVisit_Break. + */ +CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent, + CXCursorVisitor visitor, + CXClientData client_data); +#ifdef __has_feature +# if __has_feature(blocks) +/** + * Visitor invoked for each cursor found by a traversal. + * + * This visitor block will be invoked for each cursor found by + * clang_visitChildrenWithBlock(). Its first argument is the cursor being + * visited, its second argument is the parent visitor for that cursor. + * + * The visitor should return one of the \c CXChildVisitResult values + * to direct clang_visitChildrenWithBlock(). + */ +typedef enum CXChildVisitResult + (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent); + +/** + * Visits the children of a cursor using the specified block. Behaves + * identically to clang_visitChildren() in all other respects. + */ +CINDEX_LINKAGE unsigned clang_visitChildrenWithBlock(CXCursor parent, + CXCursorVisitorBlock block); +# endif +#endif + +/** + * @} + */ + +/** + * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST + * + * These routines provide the ability to determine references within and + * across translation units, by providing the names of the entities referenced + * by cursors, follow reference cursors to the declarations they reference, + * and associate declarations with their definitions. + * + * @{ + */ + +/** + * Retrieve a Unified Symbol Resolution (USR) for the entity referenced + * by the given cursor. + * + * A Unified Symbol Resolution (USR) is a string that identifies a particular + * entity (function, class, variable, etc.) within a program. USRs can be + * compared across translation units to determine, e.g., when references in + * one translation refer to an entity defined in another translation unit. + */ +CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); + +/** + * Construct a USR for a specified Objective-C class. + */ +CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name); + +/** + * Construct a USR for a specified Objective-C category. + */ +CINDEX_LINKAGE CXString + clang_constructUSR_ObjCCategory(const char *class_name, + const char *category_name); + +/** + * Construct a USR for a specified Objective-C protocol. + */ +CINDEX_LINKAGE CXString + clang_constructUSR_ObjCProtocol(const char *protocol_name); + +/** + * Construct a USR for a specified Objective-C instance variable and + * the USR for its containing class. + */ +CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name, + CXString classUSR); + +/** + * Construct a USR for a specified Objective-C method and + * the USR for its containing class. + */ +CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name, + unsigned isInstanceMethod, + CXString classUSR); + +/** + * Construct a USR for a specified Objective-C property and the USR + * for its containing class. + */ +CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property, + CXString classUSR); + +/** + * Retrieve a name for the entity referenced by this cursor. + */ +CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); + +/** + * Retrieve a range for a piece that forms the cursors spelling name. + * Most of the times there is only one range for the complete spelling but for + * Objective-C methods and Objective-C message expressions, there are multiple + * pieces for each selector identifier. + * + * \param pieceIndex the index of the spelling name piece. If this is greater + * than the actual number of pieces, it will return a NULL (invalid) range. + * + * \param options Reserved. + */ +CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor, + unsigned pieceIndex, + unsigned options); + +/** + * Opaque pointer representing a policy that controls pretty printing + * for \c clang_getCursorPrettyPrinted. + */ +typedef void *CXPrintingPolicy; + +/** + * Properties for the printing policy. + * + * See \c clang::PrintingPolicy for more information. + */ +enum CXPrintingPolicyProperty { + CXPrintingPolicy_Indentation, + CXPrintingPolicy_SuppressSpecifiers, + CXPrintingPolicy_SuppressTagKeyword, + CXPrintingPolicy_IncludeTagDefinition, + CXPrintingPolicy_SuppressScope, + CXPrintingPolicy_SuppressUnwrittenScope, + CXPrintingPolicy_SuppressInitializers, + CXPrintingPolicy_ConstantArraySizeAsWritten, + CXPrintingPolicy_AnonymousTagLocations, + CXPrintingPolicy_SuppressStrongLifetime, + CXPrintingPolicy_SuppressLifetimeQualifiers, + CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors, + CXPrintingPolicy_Bool, + CXPrintingPolicy_Restrict, + CXPrintingPolicy_Alignof, + CXPrintingPolicy_UnderscoreAlignof, + CXPrintingPolicy_UseVoidForZeroParams, + CXPrintingPolicy_TerseOutput, + CXPrintingPolicy_PolishForDeclaration, + CXPrintingPolicy_Half, + CXPrintingPolicy_MSWChar, + CXPrintingPolicy_IncludeNewlines, + CXPrintingPolicy_MSVCFormatting, + CXPrintingPolicy_ConstantsAsWritten, + CXPrintingPolicy_SuppressImplicitBase, + CXPrintingPolicy_FullyQualifiedName, + + CXPrintingPolicy_LastProperty = CXPrintingPolicy_FullyQualifiedName +}; + +/** + * Get a property value for the given printing policy. + */ +CINDEX_LINKAGE unsigned +clang_PrintingPolicy_getProperty(CXPrintingPolicy Policy, + enum CXPrintingPolicyProperty Property); + +/** + * Set a property value for the given printing policy. + */ +CINDEX_LINKAGE void clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy, + enum CXPrintingPolicyProperty Property, + unsigned Value); + +/** + * Retrieve the default policy for the cursor. + * + * The policy should be released after use with \c + * clang_PrintingPolicy_dispose. + */ +CINDEX_LINKAGE CXPrintingPolicy clang_getCursorPrintingPolicy(CXCursor); + +/** + * Release a printing policy. + */ +CINDEX_LINKAGE void clang_PrintingPolicy_dispose(CXPrintingPolicy Policy); + +/** + * Pretty print declarations. + * + * \param Cursor The cursor representing a declaration. + * + * \param Policy The policy to control the entities being printed. If + * NULL, a default policy is used. + * + * \returns The pretty printed declaration or the empty string for + * other cursors. + */ +CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, + CXPrintingPolicy Policy); + +/** + * Retrieve the display name for the entity referenced by this cursor. + * + * The display name contains extra information that helps identify the cursor, + * such as the parameters of a function or template or the arguments of a + * class template specialization. + */ +CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor); + +/** For a cursor that is a reference, retrieve a cursor representing the + * entity that it references. + * + * Reference cursors refer to other entities in the AST. For example, an + * Objective-C superclass reference cursor refers to an Objective-C class. + * This function produces the cursor for the Objective-C class from the + * cursor for the superclass reference. If the input cursor is a declaration or + * definition, it returns that declaration or definition unchanged. + * Otherwise, returns the NULL cursor. + */ +CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); + +/** + * For a cursor that is either a reference to or a declaration + * of some entity, retrieve a cursor that describes the definition of + * that entity. + * + * Some entities can be declared multiple times within a translation + * unit, but only one of those declarations can also be a + * definition. For example, given: + * + * \code + * int f(int, int); + * int g(int x, int y) { return f(x, y); } + * int f(int a, int b) { return a + b; } + * int f(int, int); + * \endcode + * + * there are three declarations of the function "f", but only the + * second one is a definition. The clang_getCursorDefinition() + * function will take any cursor pointing to a declaration of "f" + * (the first or fourth lines of the example) or a cursor referenced + * that uses "f" (the call to "f' inside "g") and will return a + * declaration cursor pointing to the definition (the second "f" + * declaration). + * + * If given a cursor for which there is no corresponding definition, + * e.g., because there is no definition of that entity within this + * translation unit, returns a NULL cursor. + */ +CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); + +/** + * Determine whether the declaration pointed to by this cursor + * is also a definition of that entity. + */ +CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); + +/** + * Retrieve the canonical cursor corresponding to the given cursor. + * + * In the C family of languages, many kinds of entities can be declared several + * times within a single translation unit. For example, a structure type can + * be forward-declared (possibly multiple times) and later defined: + * + * \code + * struct X; + * struct X; + * struct X { + * int member; + * }; + * \endcode + * + * The declarations and the definition of \c X are represented by three + * different cursors, all of which are declarations of the same underlying + * entity. One of these cursor is considered the "canonical" cursor, which + * is effectively the representative for the underlying entity. One can + * determine if two cursors are declarations of the same underlying entity by + * comparing their canonical cursors. + * + * \returns The canonical cursor for the entity referred to by the given cursor. + */ +CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor); + +/** + * If the cursor points to a selector identifier in an Objective-C + * method or message expression, this returns the selector index. + * + * After getting a cursor with #clang_getCursor, this can be called to + * determine if the location points to a selector identifier. + * + * \returns The selector index if the cursor is an Objective-C method or message + * expression and the cursor is pointing to a selector identifier, or -1 + * otherwise. + */ +CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor); + +/** + * Given a cursor pointing to a C++ method call or an Objective-C + * message, returns non-zero if the method/message is "dynamic", meaning: + * + * For a C++ method: the call is virtual. + * For an Objective-C message: the receiver is an object instance, not 'super' + * or a specific class. + * + * If the method/message is "static" or the cursor does not point to a + * method/message, it will return zero. + */ +CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C); + +/** + * Given a cursor pointing to an Objective-C message or property + * reference, or C++ method call, returns the CXType of the receiver. + */ +CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C); + +/** + * Property attributes for a \c CXCursor_ObjCPropertyDecl. + */ +typedef enum { + CXObjCPropertyAttr_noattr = 0x00, + CXObjCPropertyAttr_readonly = 0x01, + CXObjCPropertyAttr_getter = 0x02, + CXObjCPropertyAttr_assign = 0x04, + CXObjCPropertyAttr_readwrite = 0x08, + CXObjCPropertyAttr_retain = 0x10, + CXObjCPropertyAttr_copy = 0x20, + CXObjCPropertyAttr_nonatomic = 0x40, + CXObjCPropertyAttr_setter = 0x80, + CXObjCPropertyAttr_atomic = 0x100, + CXObjCPropertyAttr_weak = 0x200, + CXObjCPropertyAttr_strong = 0x400, + CXObjCPropertyAttr_unsafe_unretained = 0x800, + CXObjCPropertyAttr_class = 0x1000 +} CXObjCPropertyAttrKind; + +/** + * Given a cursor that represents a property declaration, return the + * associated property attributes. The bits are formed from + * \c CXObjCPropertyAttrKind. + * + * \param reserved Reserved for future use, pass 0. + */ +CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C, + unsigned reserved); + +/** + * 'Qualifiers' written next to the return and parameter types in + * Objective-C method declarations. + */ +typedef enum { + CXObjCDeclQualifier_None = 0x0, + CXObjCDeclQualifier_In = 0x1, + CXObjCDeclQualifier_Inout = 0x2, + CXObjCDeclQualifier_Out = 0x4, + CXObjCDeclQualifier_Bycopy = 0x8, + CXObjCDeclQualifier_Byref = 0x10, + CXObjCDeclQualifier_Oneway = 0x20 +} CXObjCDeclQualifierKind; + +/** + * Given a cursor that represents an Objective-C method or parameter + * declaration, return the associated Objective-C qualifiers for the return + * type or the parameter respectively. The bits are formed from + * CXObjCDeclQualifierKind. + */ +CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C); + +/** + * Given a cursor that represents an Objective-C method or property + * declaration, return non-zero if the declaration was affected by "\@optional". + * Returns zero if the cursor is not such a declaration or it is "\@required". + */ +CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C); + +/** + * Returns non-zero if the given cursor is a variadic function or method. + */ +CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C); + +/** + * Returns non-zero if the given cursor points to a symbol marked with + * external_source_symbol attribute. + * + * \param language If non-NULL, and the attribute is present, will be set to + * the 'language' string from the attribute. + * + * \param definedIn If non-NULL, and the attribute is present, will be set to + * the 'definedIn' string from the attribute. + * + * \param isGenerated If non-NULL, and the attribute is present, will be set to + * non-zero if the 'generated_declaration' is set in the attribute. + */ +CINDEX_LINKAGE unsigned clang_Cursor_isExternalSymbol(CXCursor C, + CXString *language, CXString *definedIn, + unsigned *isGenerated); + +/** + * Given a cursor that represents a declaration, return the associated + * comment's source range. The range may include multiple consecutive comments + * with whitespace in between. + */ +CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C); + +/** + * Given a cursor that represents a declaration, return the associated + * comment text, including comment markers. + */ +CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C); + +/** + * Given a cursor that represents a documentable entity (e.g., + * declaration), return the associated \paragraph; otherwise return the + * first paragraph. + */ +CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C); + +/** + * @} + */ + +/** \defgroup CINDEX_MANGLE Name Mangling API Functions + * + * @{ + */ + +/** + * Retrieve the CXString representing the mangled name of the cursor. + */ +CINDEX_LINKAGE CXString clang_Cursor_getMangling(CXCursor); + +/** + * Retrieve the CXStrings representing the mangled symbols of the C++ + * constructor or destructor at the cursor. + */ +CINDEX_LINKAGE CXStringSet *clang_Cursor_getCXXManglings(CXCursor); + +/** + * Retrieve the CXStrings representing the mangled symbols of the ObjC + * class interface or implementation at the cursor. + */ +CINDEX_LINKAGE CXStringSet *clang_Cursor_getObjCManglings(CXCursor); + +/** + * @} + */ + +/** + * \defgroup CINDEX_MODULE Module introspection + * + * The functions in this group provide access to information about modules. + * + * @{ + */ + +typedef void *CXModule; + +/** + * Given a CXCursor_ModuleImportDecl cursor, return the associated module. + */ +CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C); + +/** + * Given a CXFile header file, return the module that contains it, if one + * exists. + */ +CINDEX_LINKAGE CXModule clang_getModuleForFile(CXTranslationUnit, CXFile); + +/** + * \param Module a module object. + * + * \returns the module file where the provided module object came from. + */ +CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module); + +/** + * \param Module a module object. + * + * \returns the parent of a sub-module or NULL if the given module is top-level, + * e.g. for 'std.vector' it will return the 'std' module. + */ +CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module); + +/** + * \param Module a module object. + * + * \returns the name of the module, e.g. for the 'std.vector' sub-module it + * will return "vector". + */ +CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module); + +/** + * \param Module a module object. + * + * \returns the full name of the module, e.g. "std.vector". + */ +CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module); + +/** + * \param Module a module object. + * + * \returns non-zero if the module is a system one. + */ +CINDEX_LINKAGE int clang_Module_isSystem(CXModule Module); + +/** + * \param Module a module object. + * + * \returns the number of top level headers associated with this module. + */ +CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit, + CXModule Module); + +/** + * \param Module a module object. + * + * \param Index top level header index (zero-based). + * + * \returns the specified top level header associated with the module. + */ +CINDEX_LINKAGE +CXFile clang_Module_getTopLevelHeader(CXTranslationUnit, + CXModule Module, unsigned Index); + +/** + * @} + */ + +/** + * \defgroup CINDEX_CPP C++ AST introspection + * + * The routines in this group provide access information in the ASTs specific + * to C++ language features. + * + * @{ + */ + +/** + * Determine if a C++ constructor is a converting constructor. + */ +CINDEX_LINKAGE unsigned clang_CXXConstructor_isConvertingConstructor(CXCursor C); + +/** + * Determine if a C++ constructor is a copy constructor. + */ +CINDEX_LINKAGE unsigned clang_CXXConstructor_isCopyConstructor(CXCursor C); + +/** + * Determine if a C++ constructor is the default constructor. + */ +CINDEX_LINKAGE unsigned clang_CXXConstructor_isDefaultConstructor(CXCursor C); + +/** + * Determine if a C++ constructor is a move constructor. + */ +CINDEX_LINKAGE unsigned clang_CXXConstructor_isMoveConstructor(CXCursor C); + +/** + * Determine if a C++ field is declared 'mutable'. + */ +CINDEX_LINKAGE unsigned clang_CXXField_isMutable(CXCursor C); + +/** + * Determine if a C++ method is declared '= default'. + */ +CINDEX_LINKAGE unsigned clang_CXXMethod_isDefaulted(CXCursor C); + +/** + * Determine if a C++ member function or member function template is + * pure virtual. + */ +CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C); + +/** + * Determine if a C++ member function or member function template is + * declared 'static'. + */ +CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C); + +/** + * Determine if a C++ member function or member function template is + * explicitly declared 'virtual' or if it overrides a virtual method from + * one of the base classes. + */ +CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C); + +/** + * Determine if a C++ record is abstract, i.e. whether a class or struct + * has a pure virtual member function. + */ +CINDEX_LINKAGE unsigned clang_CXXRecord_isAbstract(CXCursor C); + +/** + * Determine if an enum declaration refers to a scoped enum. + */ +CINDEX_LINKAGE unsigned clang_EnumDecl_isScoped(CXCursor C); + +/** + * Determine if a C++ member function or member function template is + * declared 'const'. + */ +CINDEX_LINKAGE unsigned clang_CXXMethod_isConst(CXCursor C); + +/** + * Given a cursor that represents a template, determine + * the cursor kind of the specializations would be generated by instantiating + * the template. + * + * This routine can be used to determine what flavor of function template, + * class template, or class template partial specialization is stored in the + * cursor. For example, it can describe whether a class template cursor is + * declared with "struct", "class" or "union". + * + * \param C The cursor to query. This cursor should represent a template + * declaration. + * + * \returns The cursor kind of the specializations that would be generated + * by instantiating the template \p C. If \p C is not a template, returns + * \c CXCursor_NoDeclFound. + */ +CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C); + +/** + * Given a cursor that may represent a specialization or instantiation + * of a template, retrieve the cursor that represents the template that it + * specializes or from which it was instantiated. + * + * This routine determines the template involved both for explicit + * specializations of templates and for implicit instantiations of the template, + * both of which are referred to as "specializations". For a class template + * specialization (e.g., \c std::vector), this routine will return + * either the primary template (\c std::vector) or, if the specialization was + * instantiated from a class template partial specialization, the class template + * partial specialization. For a class template partial specialization and a + * function template specialization (including instantiations), this + * this routine will return the specialized template. + * + * For members of a class template (e.g., member functions, member classes, or + * static data members), returns the specialized or instantiated member. + * Although not strictly "templates" in the C++ language, members of class + * templates have the same notions of specializations and instantiations that + * templates do, so this routine treats them similarly. + * + * \param C A cursor that may be a specialization of a template or a member + * of a template. + * + * \returns If the given cursor is a specialization or instantiation of a + * template or a member thereof, the template or member that it specializes or + * from which it was instantiated. Otherwise, returns a NULL cursor. + */ +CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C); + +/** + * Given a cursor that references something else, return the source range + * covering that reference. + * + * \param C A cursor pointing to a member reference, a declaration reference, or + * an operator call. + * \param NameFlags A bitset with three independent flags: + * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and + * CXNameRange_WantSinglePiece. + * \param PieceIndex For contiguous names or when passing the flag + * CXNameRange_WantSinglePiece, only one piece with index 0 is + * available. When the CXNameRange_WantSinglePiece flag is not passed for a + * non-contiguous names, this index can be used to retrieve the individual + * pieces of the name. See also CXNameRange_WantSinglePiece. + * + * \returns The piece of the name pointed to by the given cursor. If there is no + * name, or if the PieceIndex is out-of-range, a null-cursor will be returned. + */ +CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C, + unsigned NameFlags, + unsigned PieceIndex); + +enum CXNameRefFlags { + /** + * Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the + * range. + */ + CXNameRange_WantQualifier = 0x1, + + /** + * Include the explicit template arguments, e.g. \ in x.f, + * in the range. + */ + CXNameRange_WantTemplateArgs = 0x2, + + /** + * If the name is non-contiguous, return the full spanning range. + * + * Non-contiguous names occur in Objective-C when a selector with two or more + * parameters is used, or in C++ when using an operator: + * \code + * [object doSomething:here withValue:there]; // Objective-C + * return some_vector[1]; // C++ + * \endcode + */ + CXNameRange_WantSinglePiece = 0x4 +}; + +/** + * @} + */ + +/** + * \defgroup CINDEX_LEX Token extraction and manipulation + * + * The routines in this group provide access to the tokens within a + * translation unit, along with a semantic mapping of those tokens to + * their corresponding cursors. + * + * @{ + */ + +/** + * Describes a kind of token. + */ +typedef enum CXTokenKind { + /** + * A token that contains some kind of punctuation. + */ + CXToken_Punctuation, + + /** + * A language keyword. + */ + CXToken_Keyword, + + /** + * An identifier (that is not a keyword). + */ + CXToken_Identifier, + + /** + * A numeric, string, or character literal. + */ + CXToken_Literal, + + /** + * A comment. + */ + CXToken_Comment +} CXTokenKind; + +/** + * Describes a single preprocessing token. + */ +typedef struct { + unsigned int_data[4]; + void *ptr_data; +} CXToken; + +/** + * Get the raw lexical token starting with the given location. + * + * \param TU the translation unit whose text is being tokenized. + * + * \param Location the source location with which the token starts. + * + * \returns The token starting with the given location or NULL if no such token + * exist. The returned pointer must be freed with clang_disposeTokens before the + * translation unit is destroyed. + */ +CINDEX_LINKAGE CXToken *clang_getToken(CXTranslationUnit TU, + CXSourceLocation Location); + +/** + * Determine the kind of the given token. + */ +CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken); + +/** + * Determine the spelling of the given token. + * + * The spelling of a token is the textual representation of that token, e.g., + * the text of an identifier or keyword. + */ +CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); + +/** + * Retrieve the source location of the given token. + */ +CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit, + CXToken); + +/** + * Retrieve a source range that covers the given token. + */ +CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); + +/** + * Tokenize the source code described by the given range into raw + * lexical tokens. + * + * \param TU the translation unit whose text is being tokenized. + * + * \param Range the source range in which text should be tokenized. All of the + * tokens produced by tokenization will fall within this source range, + * + * \param Tokens this pointer will be set to point to the array of tokens + * that occur within the given source range. The returned pointer must be + * freed with clang_disposeTokens() before the translation unit is destroyed. + * + * \param NumTokens will be set to the number of tokens in the \c *Tokens + * array. + * + */ +CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, + CXToken **Tokens, unsigned *NumTokens); + +/** + * Annotate the given set of tokens by providing cursors for each token + * that can be mapped to a specific entity within the abstract syntax tree. + * + * This token-annotation routine is equivalent to invoking + * clang_getCursor() for the source locations of each of the + * tokens. The cursors provided are filtered, so that only those + * cursors that have a direct correspondence to the token are + * accepted. For example, given a function call \c f(x), + * clang_getCursor() would provide the following cursors: + * + * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. + * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. + * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. + * + * Only the first and last of these cursors will occur within the + * annotate, since the tokens "f" and "x' directly refer to a function + * and a variable, respectively, but the parentheses are just a small + * part of the full syntax of the function call expression, which is + * not provided as an annotation. + * + * \param TU the translation unit that owns the given tokens. + * + * \param Tokens the set of tokens to annotate. + * + * \param NumTokens the number of tokens in \p Tokens. + * + * \param Cursors an array of \p NumTokens cursors, whose contents will be + * replaced with the cursors corresponding to each token. + */ +CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU, + CXToken *Tokens, unsigned NumTokens, + CXCursor *Cursors); + +/** + * Free the given set of tokens. + */ +CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, + CXToken *Tokens, unsigned NumTokens); + +/** + * @} + */ + +/** + * \defgroup CINDEX_DEBUG Debugging facilities + * + * These routines are used for testing and debugging, only, and should not + * be relied upon. + * + * @{ + */ + +/* for debug/testing */ +CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind); +CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, + const char **startBuf, + const char **endBuf, + unsigned *startLine, + unsigned *startColumn, + unsigned *endLine, + unsigned *endColumn); +CINDEX_LINKAGE void clang_enableStackTraces(void); +CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data, + unsigned stack_size); + +/** + * @} + */ + +/** + * \defgroup CINDEX_CODE_COMPLET Code completion + * + * Code completion involves taking an (incomplete) source file, along with + * knowledge of where the user is actively editing that file, and suggesting + * syntactically- and semantically-valid constructs that the user might want to + * use at that particular point in the source code. These data structures and + * routines provide support for code completion. + * + * @{ + */ + +/** + * A semantic string that describes a code-completion result. + * + * A semantic string that describes the formatting of a code-completion + * result as a single "template" of text that should be inserted into the + * source buffer when a particular code-completion result is selected. + * Each semantic string is made up of some number of "chunks", each of which + * contains some text along with a description of what that text means, e.g., + * the name of the entity being referenced, whether the text chunk is part of + * the template, or whether it is a "placeholder" that the user should replace + * with actual code,of a specific kind. See \c CXCompletionChunkKind for a + * description of the different kinds of chunks. + */ +typedef void *CXCompletionString; + +/** + * A single result of code completion. + */ +typedef struct { + /** + * The kind of entity that this completion refers to. + * + * The cursor kind will be a macro, keyword, or a declaration (one of the + * *Decl cursor kinds), describing the entity that the completion is + * referring to. + * + * \todo In the future, we would like to provide a full cursor, to allow + * the client to extract additional information from declaration. + */ + enum CXCursorKind CursorKind; + + /** + * The code-completion string that describes how to insert this + * code-completion result into the editing buffer. + */ + CXCompletionString CompletionString; +} CXCompletionResult; + +/** + * Describes a single piece of text within a code-completion string. + * + * Each "chunk" within a code-completion string (\c CXCompletionString) is + * either a piece of text with a specific "kind" that describes how that text + * should be interpreted by the client or is another completion string. + */ +enum CXCompletionChunkKind { + /** + * A code-completion string that describes "optional" text that + * could be a part of the template (but is not required). + * + * The Optional chunk is the only kind of chunk that has a code-completion + * string for its representation, which is accessible via + * \c clang_getCompletionChunkCompletionString(). The code-completion string + * describes an additional part of the template that is completely optional. + * For example, optional chunks can be used to describe the placeholders for + * arguments that match up with defaulted function parameters, e.g. given: + * + * \code + * void f(int x, float y = 3.14, double z = 2.71828); + * \endcode + * + * The code-completion string for this function would contain: + * - a TypedText chunk for "f". + * - a LeftParen chunk for "(". + * - a Placeholder chunk for "int x" + * - an Optional chunk containing the remaining defaulted arguments, e.g., + * - a Comma chunk for "," + * - a Placeholder chunk for "float y" + * - an Optional chunk containing the last defaulted argument: + * - a Comma chunk for "," + * - a Placeholder chunk for "double z" + * - a RightParen chunk for ")" + * + * There are many ways to handle Optional chunks. Two simple approaches are: + * - Completely ignore optional chunks, in which case the template for the + * function "f" would only include the first parameter ("int x"). + * - Fully expand all optional chunks, in which case the template for the + * function "f" would have all of the parameters. + */ + CXCompletionChunk_Optional, + /** + * Text that a user would be expected to type to get this + * code-completion result. + * + * There will be exactly one "typed text" chunk in a semantic string, which + * will typically provide the spelling of a keyword or the name of a + * declaration that could be used at the current code point. Clients are + * expected to filter the code-completion results based on the text in this + * chunk. + */ + CXCompletionChunk_TypedText, + /** + * Text that should be inserted as part of a code-completion result. + * + * A "text" chunk represents text that is part of the template to be + * inserted into user code should this particular code-completion result + * be selected. + */ + CXCompletionChunk_Text, + /** + * Placeholder text that should be replaced by the user. + * + * A "placeholder" chunk marks a place where the user should insert text + * into the code-completion template. For example, placeholders might mark + * the function parameters for a function declaration, to indicate that the + * user should provide arguments for each of those parameters. The actual + * text in a placeholder is a suggestion for the text to display before + * the user replaces the placeholder with real code. + */ + CXCompletionChunk_Placeholder, + /** + * Informative text that should be displayed but never inserted as + * part of the template. + * + * An "informative" chunk contains annotations that can be displayed to + * help the user decide whether a particular code-completion result is the + * right option, but which is not part of the actual template to be inserted + * by code completion. + */ + CXCompletionChunk_Informative, + /** + * Text that describes the current parameter when code-completion is + * referring to function call, message send, or template specialization. + * + * A "current parameter" chunk occurs when code-completion is providing + * information about a parameter corresponding to the argument at the + * code-completion point. For example, given a function + * + * \code + * int add(int x, int y); + * \endcode + * + * and the source code \c add(, where the code-completion point is after the + * "(", the code-completion string will contain a "current parameter" chunk + * for "int x", indicating that the current argument will initialize that + * parameter. After typing further, to \c add(17, (where the code-completion + * point is after the ","), the code-completion string will contain a + * "current parameter" chunk to "int y". + */ + CXCompletionChunk_CurrentParameter, + /** + * A left parenthesis ('('), used to initiate a function call or + * signal the beginning of a function parameter list. + */ + CXCompletionChunk_LeftParen, + /** + * A right parenthesis (')'), used to finish a function call or + * signal the end of a function parameter list. + */ + CXCompletionChunk_RightParen, + /** + * A left bracket ('['). + */ + CXCompletionChunk_LeftBracket, + /** + * A right bracket (']'). + */ + CXCompletionChunk_RightBracket, + /** + * A left brace ('{'). + */ + CXCompletionChunk_LeftBrace, + /** + * A right brace ('}'). + */ + CXCompletionChunk_RightBrace, + /** + * A left angle bracket ('<'). + */ + CXCompletionChunk_LeftAngle, + /** + * A right angle bracket ('>'). + */ + CXCompletionChunk_RightAngle, + /** + * A comma separator (','). + */ + CXCompletionChunk_Comma, + /** + * Text that specifies the result type of a given result. + * + * This special kind of informative chunk is not meant to be inserted into + * the text buffer. Rather, it is meant to illustrate the type that an + * expression using the given completion string would have. + */ + CXCompletionChunk_ResultType, + /** + * A colon (':'). + */ + CXCompletionChunk_Colon, + /** + * A semicolon (';'). + */ + CXCompletionChunk_SemiColon, + /** + * An '=' sign. + */ + CXCompletionChunk_Equal, + /** + * Horizontal space (' '). + */ + CXCompletionChunk_HorizontalSpace, + /** + * Vertical space ('\\n'), after which it is generally a good idea to + * perform indentation. + */ + CXCompletionChunk_VerticalSpace +}; + +/** + * Determine the kind of a particular chunk within a completion string. + * + * \param completion_string the completion string to query. + * + * \param chunk_number the 0-based index of the chunk in the completion string. + * + * \returns the kind of the chunk at the index \c chunk_number. + */ +CINDEX_LINKAGE enum CXCompletionChunkKind +clang_getCompletionChunkKind(CXCompletionString completion_string, + unsigned chunk_number); + +/** + * Retrieve the text associated with a particular chunk within a + * completion string. + * + * \param completion_string the completion string to query. + * + * \param chunk_number the 0-based index of the chunk in the completion string. + * + * \returns the text associated with the chunk at index \c chunk_number. + */ +CINDEX_LINKAGE CXString +clang_getCompletionChunkText(CXCompletionString completion_string, + unsigned chunk_number); + +/** + * Retrieve the completion string associated with a particular chunk + * within a completion string. + * + * \param completion_string the completion string to query. + * + * \param chunk_number the 0-based index of the chunk in the completion string. + * + * \returns the completion string associated with the chunk at index + * \c chunk_number. + */ +CINDEX_LINKAGE CXCompletionString +clang_getCompletionChunkCompletionString(CXCompletionString completion_string, + unsigned chunk_number); + +/** + * Retrieve the number of chunks in the given code-completion string. + */ +CINDEX_LINKAGE unsigned +clang_getNumCompletionChunks(CXCompletionString completion_string); + +/** + * Determine the priority of this code completion. + * + * The priority of a code completion indicates how likely it is that this + * particular completion is the completion that the user will select. The + * priority is selected by various internal heuristics. + * + * \param completion_string The completion string to query. + * + * \returns The priority of this completion string. Smaller values indicate + * higher-priority (more likely) completions. + */ +CINDEX_LINKAGE unsigned +clang_getCompletionPriority(CXCompletionString completion_string); + +/** + * Determine the availability of the entity that this code-completion + * string refers to. + * + * \param completion_string The completion string to query. + * + * \returns The availability of the completion string. + */ +CINDEX_LINKAGE enum CXAvailabilityKind +clang_getCompletionAvailability(CXCompletionString completion_string); + +/** + * Retrieve the number of annotations associated with the given + * completion string. + * + * \param completion_string the completion string to query. + * + * \returns the number of annotations associated with the given completion + * string. + */ +CINDEX_LINKAGE unsigned +clang_getCompletionNumAnnotations(CXCompletionString completion_string); + +/** + * Retrieve the annotation associated with the given completion string. + * + * \param completion_string the completion string to query. + * + * \param annotation_number the 0-based index of the annotation of the + * completion string. + * + * \returns annotation string associated with the completion at index + * \c annotation_number, or a NULL string if that annotation is not available. + */ +CINDEX_LINKAGE CXString +clang_getCompletionAnnotation(CXCompletionString completion_string, + unsigned annotation_number); + +/** + * Retrieve the parent context of the given completion string. + * + * The parent context of a completion string is the semantic parent of + * the declaration (if any) that the code completion represents. For example, + * a code completion for an Objective-C method would have the method's class + * or protocol as its context. + * + * \param completion_string The code completion string whose parent is + * being queried. + * + * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL. + * + * \returns The name of the completion parent, e.g., "NSObject" if + * the completion string represents a method in the NSObject class. + */ +CINDEX_LINKAGE CXString +clang_getCompletionParent(CXCompletionString completion_string, + enum CXCursorKind *kind); + +/** + * Retrieve the brief documentation comment attached to the declaration + * that corresponds to the given completion string. + */ +CINDEX_LINKAGE CXString +clang_getCompletionBriefComment(CXCompletionString completion_string); + +/** + * Retrieve a completion string for an arbitrary declaration or macro + * definition cursor. + * + * \param cursor The cursor to query. + * + * \returns A non-context-sensitive completion string for declaration and macro + * definition cursors, or NULL for other kinds of cursors. + */ +CINDEX_LINKAGE CXCompletionString +clang_getCursorCompletionString(CXCursor cursor); + +/** + * Contains the results of code-completion. + * + * This data structure contains the results of code completion, as + * produced by \c clang_codeCompleteAt(). Its contents must be freed by + * \c clang_disposeCodeCompleteResults. + */ +typedef struct { + /** + * The code-completion results. + */ + CXCompletionResult *Results; + + /** + * The number of code-completion results stored in the + * \c Results array. + */ + unsigned NumResults; +} CXCodeCompleteResults; + +/** + * Retrieve the number of fix-its for the given completion index. + * + * Calling this makes sense only if CXCodeComplete_IncludeCompletionsWithFixIts + * option was set. + * + * \param results The structure keeping all completion results + * + * \param completion_index The index of the completion + * + * \return The number of fix-its which must be applied before the completion at + * completion_index can be applied + */ +CINDEX_LINKAGE unsigned +clang_getCompletionNumFixIts(CXCodeCompleteResults *results, + unsigned completion_index); + +/** + * Fix-its that *must* be applied before inserting the text for the + * corresponding completion. + * + * By default, clang_codeCompleteAt() only returns completions with empty + * fix-its. Extra completions with non-empty fix-its should be explicitly + * requested by setting CXCodeComplete_IncludeCompletionsWithFixIts. + * + * For the clients to be able to compute position of the cursor after applying + * fix-its, the following conditions are guaranteed to hold for + * replacement_range of the stored fix-its: + * - Ranges in the fix-its are guaranteed to never contain the completion + * point (or identifier under completion point, if any) inside them, except + * at the start or at the end of the range. + * - If a fix-it range starts or ends with completion point (or starts or + * ends after the identifier under completion point), it will contain at + * least one character. It allows to unambiguously recompute completion + * point after applying the fix-it. + * + * The intuition is that provided fix-its change code around the identifier we + * complete, but are not allowed to touch the identifier itself or the + * completion point. One example of completions with corrections are the ones + * replacing '.' with '->' and vice versa: + * + * std::unique_ptr> vec_ptr; + * In 'vec_ptr.^', one of the completions is 'push_back', it requires + * replacing '.' with '->'. + * In 'vec_ptr->^', one of the completions is 'release', it requires + * replacing '->' with '.'. + * + * \param results The structure keeping all completion results + * + * \param completion_index The index of the completion + * + * \param fixit_index The index of the fix-it for the completion at + * completion_index + * + * \param replacement_range The fix-it range that must be replaced before the + * completion at completion_index can be applied + * + * \returns The fix-it string that must replace the code at replacement_range + * before the completion at completion_index can be applied + */ +CINDEX_LINKAGE CXString clang_getCompletionFixIt( + CXCodeCompleteResults *results, unsigned completion_index, + unsigned fixit_index, CXSourceRange *replacement_range); + +/** + * Flags that can be passed to \c clang_codeCompleteAt() to + * modify its behavior. + * + * The enumerators in this enumeration can be bitwise-OR'd together to + * provide multiple options to \c clang_codeCompleteAt(). + */ +enum CXCodeComplete_Flags { + /** + * Whether to include macros within the set of code + * completions returned. + */ + CXCodeComplete_IncludeMacros = 0x01, + + /** + * Whether to include code patterns for language constructs + * within the set of code completions, e.g., for loops. + */ + CXCodeComplete_IncludeCodePatterns = 0x02, + + /** + * Whether to include brief documentation within the set of code + * completions returned. + */ + CXCodeComplete_IncludeBriefComments = 0x04, + + /** + * Whether to speed up completion by omitting top- or namespace-level entities + * defined in the preamble. There's no guarantee any particular entity is + * omitted. This may be useful if the headers are indexed externally. + */ + CXCodeComplete_SkipPreamble = 0x08, + + /** + * Whether to include completions with small + * fix-its, e.g. change '.' to '->' on member access, etc. + */ + CXCodeComplete_IncludeCompletionsWithFixIts = 0x10 +}; + +/** + * Bits that represent the context under which completion is occurring. + * + * The enumerators in this enumeration may be bitwise-OR'd together if multiple + * contexts are occurring simultaneously. + */ +enum CXCompletionContext { + /** + * The context for completions is unexposed, as only Clang results + * should be included. (This is equivalent to having no context bits set.) + */ + CXCompletionContext_Unexposed = 0, + + /** + * Completions for any possible type should be included in the results. + */ + CXCompletionContext_AnyType = 1 << 0, + + /** + * Completions for any possible value (variables, function calls, etc.) + * should be included in the results. + */ + CXCompletionContext_AnyValue = 1 << 1, + /** + * Completions for values that resolve to an Objective-C object should + * be included in the results. + */ + CXCompletionContext_ObjCObjectValue = 1 << 2, + /** + * Completions for values that resolve to an Objective-C selector + * should be included in the results. + */ + CXCompletionContext_ObjCSelectorValue = 1 << 3, + /** + * Completions for values that resolve to a C++ class type should be + * included in the results. + */ + CXCompletionContext_CXXClassTypeValue = 1 << 4, + + /** + * Completions for fields of the member being accessed using the dot + * operator should be included in the results. + */ + CXCompletionContext_DotMemberAccess = 1 << 5, + /** + * Completions for fields of the member being accessed using the arrow + * operator should be included in the results. + */ + CXCompletionContext_ArrowMemberAccess = 1 << 6, + /** + * Completions for properties of the Objective-C object being accessed + * using the dot operator should be included in the results. + */ + CXCompletionContext_ObjCPropertyAccess = 1 << 7, + + /** + * Completions for enum tags should be included in the results. + */ + CXCompletionContext_EnumTag = 1 << 8, + /** + * Completions for union tags should be included in the results. + */ + CXCompletionContext_UnionTag = 1 << 9, + /** + * Completions for struct tags should be included in the results. + */ + CXCompletionContext_StructTag = 1 << 10, + + /** + * Completions for C++ class names should be included in the results. + */ + CXCompletionContext_ClassTag = 1 << 11, + /** + * Completions for C++ namespaces and namespace aliases should be + * included in the results. + */ + CXCompletionContext_Namespace = 1 << 12, + /** + * Completions for C++ nested name specifiers should be included in + * the results. + */ + CXCompletionContext_NestedNameSpecifier = 1 << 13, + + /** + * Completions for Objective-C interfaces (classes) should be included + * in the results. + */ + CXCompletionContext_ObjCInterface = 1 << 14, + /** + * Completions for Objective-C protocols should be included in + * the results. + */ + CXCompletionContext_ObjCProtocol = 1 << 15, + /** + * Completions for Objective-C categories should be included in + * the results. + */ + CXCompletionContext_ObjCCategory = 1 << 16, + /** + * Completions for Objective-C instance messages should be included + * in the results. + */ + CXCompletionContext_ObjCInstanceMessage = 1 << 17, + /** + * Completions for Objective-C class messages should be included in + * the results. + */ + CXCompletionContext_ObjCClassMessage = 1 << 18, + /** + * Completions for Objective-C selector names should be included in + * the results. + */ + CXCompletionContext_ObjCSelectorName = 1 << 19, + + /** + * Completions for preprocessor macro names should be included in + * the results. + */ + CXCompletionContext_MacroName = 1 << 20, + + /** + * Natural language completions should be included in the results. + */ + CXCompletionContext_NaturalLanguage = 1 << 21, + + /** + * The current context is unknown, so set all contexts. + */ + CXCompletionContext_Unknown = ((1 << 22) - 1) +}; + +/** + * Returns a default set of code-completion options that can be + * passed to\c clang_codeCompleteAt(). + */ +CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void); + +/** + * Perform code completion at a given location in a translation unit. + * + * This function performs code completion at a particular file, line, and + * column within source code, providing results that suggest potential + * code snippets based on the context of the completion. The basic model + * for code completion is that Clang will parse a complete source file, + * performing syntax checking up to the location where code-completion has + * been requested. At that point, a special code-completion token is passed + * to the parser, which recognizes this token and determines, based on the + * current location in the C/Objective-C/C++ grammar and the state of + * semantic analysis, what completions to provide. These completions are + * returned via a new \c CXCodeCompleteResults structure. + * + * Code completion itself is meant to be triggered by the client when the + * user types punctuation characters or whitespace, at which point the + * code-completion location will coincide with the cursor. For example, if \c p + * is a pointer, code-completion might be triggered after the "-" and then + * after the ">" in \c p->. When the code-completion location is after the ">", + * the completion results will provide, e.g., the members of the struct that + * "p" points to. The client is responsible for placing the cursor at the + * beginning of the token currently being typed, then filtering the results + * based on the contents of the token. For example, when code-completing for + * the expression \c p->get, the client should provide the location just after + * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the + * client can filter the results based on the current token text ("get"), only + * showing those results that start with "get". The intent of this interface + * is to separate the relatively high-latency acquisition of code-completion + * results from the filtering of results on a per-character basis, which must + * have a lower latency. + * + * \param TU The translation unit in which code-completion should + * occur. The source files for this translation unit need not be + * completely up-to-date (and the contents of those source files may + * be overridden via \p unsaved_files). Cursors referring into the + * translation unit may be invalidated by this invocation. + * + * \param complete_filename The name of the source file where code + * completion should be performed. This filename may be any file + * included in the translation unit. + * + * \param complete_line The line at which code-completion should occur. + * + * \param complete_column The column at which code-completion should occur. + * Note that the column should point just after the syntactic construct that + * initiated code completion, and not in the middle of a lexical token. + * + * \param unsaved_files the Files that have not yet been saved to disk + * but may be required for parsing or code completion, including the + * contents of those files. The contents and name of these files (as + * specified by CXUnsavedFile) are copied when necessary, so the + * client only needs to guarantee their validity until the call to + * this function returns. + * + * \param num_unsaved_files The number of unsaved file entries in \p + * unsaved_files. + * + * \param options Extra options that control the behavior of code + * completion, expressed as a bitwise OR of the enumerators of the + * CXCodeComplete_Flags enumeration. The + * \c clang_defaultCodeCompleteOptions() function returns a default set + * of code-completion options. + * + * \returns If successful, a new \c CXCodeCompleteResults structure + * containing code-completion results, which should eventually be + * freed with \c clang_disposeCodeCompleteResults(). If code + * completion fails, returns NULL. + */ +CINDEX_LINKAGE +CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU, + const char *complete_filename, + unsigned complete_line, + unsigned complete_column, + struct CXUnsavedFile *unsaved_files, + unsigned num_unsaved_files, + unsigned options); + +/** + * Sort the code-completion results in case-insensitive alphabetical + * order. + * + * \param Results The set of results to sort. + * \param NumResults The number of results in \p Results. + */ +CINDEX_LINKAGE +void clang_sortCodeCompletionResults(CXCompletionResult *Results, + unsigned NumResults); + +/** + * Free the given set of code-completion results. + */ +CINDEX_LINKAGE +void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); + +/** + * Determine the number of diagnostics produced prior to the + * location where code completion was performed. + */ +CINDEX_LINKAGE +unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results); + +/** + * Retrieve a diagnostic associated with the given code completion. + * + * \param Results the code completion results to query. + * \param Index the zero-based diagnostic number to retrieve. + * + * \returns the requested diagnostic. This diagnostic must be freed + * via a call to \c clang_disposeDiagnostic(). + */ +CINDEX_LINKAGE +CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results, + unsigned Index); + +/** + * Determines what completions are appropriate for the context + * the given code completion. + * + * \param Results the code completion results to query + * + * \returns the kinds of completions that are appropriate for use + * along with the given code completion results. + */ +CINDEX_LINKAGE +unsigned long long clang_codeCompleteGetContexts( + CXCodeCompleteResults *Results); + +/** + * Returns the cursor kind for the container for the current code + * completion context. The container is only guaranteed to be set for + * contexts where a container exists (i.e. member accesses or Objective-C + * message sends); if there is not a container, this function will return + * CXCursor_InvalidCode. + * + * \param Results the code completion results to query + * + * \param IsIncomplete on return, this value will be false if Clang has complete + * information about the container. If Clang does not have complete + * information, this value will be true. + * + * \returns the container kind, or CXCursor_InvalidCode if there is not a + * container + */ +CINDEX_LINKAGE +enum CXCursorKind clang_codeCompleteGetContainerKind( + CXCodeCompleteResults *Results, + unsigned *IsIncomplete); + +/** + * Returns the USR for the container for the current code completion + * context. If there is not a container for the current context, this + * function will return the empty string. + * + * \param Results the code completion results to query + * + * \returns the USR for the container + */ +CINDEX_LINKAGE +CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results); + +/** + * Returns the currently-entered selector for an Objective-C message + * send, formatted like "initWithFoo:bar:". Only guaranteed to return a + * non-empty string for CXCompletionContext_ObjCInstanceMessage and + * CXCompletionContext_ObjCClassMessage. + * + * \param Results the code completion results to query + * + * \returns the selector (or partial selector) that has been entered thus far + * for an Objective-C message send. + */ +CINDEX_LINKAGE +CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results); + +/** + * @} + */ + +/** + * \defgroup CINDEX_MISC Miscellaneous utility functions + * + * @{ + */ + +/** + * Return a version string, suitable for showing to a user, but not + * intended to be parsed (the format is not guaranteed to be stable). + */ +CINDEX_LINKAGE CXString clang_getClangVersion(void); + +/** + * Enable/disable crash recovery. + * + * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero + * value enables crash recovery, while 0 disables it. + */ +CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled); + + /** + * Visitor invoked for each file in a translation unit + * (used with clang_getInclusions()). + * + * This visitor function will be invoked by clang_getInclusions() for each + * file included (either at the top-level or by \#include directives) within + * a translation unit. The first argument is the file being included, and + * the second and third arguments provide the inclusion stack. The + * array is sorted in order of immediate inclusion. For example, + * the first element refers to the location that included 'included_file'. + */ +typedef void (*CXInclusionVisitor)(CXFile included_file, + CXSourceLocation* inclusion_stack, + unsigned include_len, + CXClientData client_data); + +/** + * Visit the set of preprocessor inclusions in a translation unit. + * The visitor function is called with the provided data for every included + * file. This does not include headers included by the PCH file (unless one + * is inspecting the inclusions in the PCH file itself). + */ +CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu, + CXInclusionVisitor visitor, + CXClientData client_data); + +typedef enum { + CXEval_Int = 1 , + CXEval_Float = 2, + CXEval_ObjCStrLiteral = 3, + CXEval_StrLiteral = 4, + CXEval_CFStr = 5, + CXEval_Other = 6, + + CXEval_UnExposed = 0 + +} CXEvalResultKind ; + +/** + * Evaluation result of a cursor + */ +typedef void * CXEvalResult; + +/** + * If cursor is a statement declaration tries to evaluate the + * statement and if its variable, tries to evaluate its initializer, + * into its corresponding type. + */ +CINDEX_LINKAGE CXEvalResult clang_Cursor_Evaluate(CXCursor C); + +/** + * Returns the kind of the evaluated result. + */ +CINDEX_LINKAGE CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E); + +/** + * Returns the evaluation result as integer if the + * kind is Int. + */ +CINDEX_LINKAGE int clang_EvalResult_getAsInt(CXEvalResult E); + +/** + * Returns the evaluation result as a long long integer if the + * kind is Int. This prevents overflows that may happen if the result is + * returned with clang_EvalResult_getAsInt. + */ +CINDEX_LINKAGE long long clang_EvalResult_getAsLongLong(CXEvalResult E); + +/** + * Returns a non-zero value if the kind is Int and the evaluation + * result resulted in an unsigned integer. + */ +CINDEX_LINKAGE unsigned clang_EvalResult_isUnsignedInt(CXEvalResult E); + +/** + * Returns the evaluation result as an unsigned integer if + * the kind is Int and clang_EvalResult_isUnsignedInt is non-zero. + */ +CINDEX_LINKAGE unsigned long long clang_EvalResult_getAsUnsigned(CXEvalResult E); + +/** + * Returns the evaluation result as double if the + * kind is double. + */ +CINDEX_LINKAGE double clang_EvalResult_getAsDouble(CXEvalResult E); + +/** + * Returns the evaluation result as a constant string if the + * kind is other than Int or float. User must not free this pointer, + * instead call clang_EvalResult_dispose on the CXEvalResult returned + * by clang_Cursor_Evaluate. + */ +CINDEX_LINKAGE const char* clang_EvalResult_getAsStr(CXEvalResult E); + +/** + * Disposes the created Eval memory. + */ +CINDEX_LINKAGE void clang_EvalResult_dispose(CXEvalResult E); +/** + * @} + */ + +/** \defgroup CINDEX_REMAPPING Remapping functions + * + * @{ + */ + +/** + * A remapping of original source files and their translated files. + */ +typedef void *CXRemapping; + +/** + * Retrieve a remapping. + * + * \param path the path that contains metadata about remappings. + * + * \returns the requested remapping. This remapping must be freed + * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred. + */ +CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path); + +/** + * Retrieve a remapping. + * + * \param filePaths pointer to an array of file paths containing remapping info. + * + * \param numFiles number of file paths. + * + * \returns the requested remapping. This remapping must be freed + * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred. + */ +CINDEX_LINKAGE +CXRemapping clang_getRemappingsFromFileList(const char **filePaths, + unsigned numFiles); + +/** + * Determine the number of remappings. + */ +CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping); + +/** + * Get the original and the associated filename from the remapping. + * + * \param original If non-NULL, will be set to the original filename. + * + * \param transformed If non-NULL, will be set to the filename that the original + * is associated with. + */ +CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index, + CXString *original, CXString *transformed); + +/** + * Dispose the remapping. + */ +CINDEX_LINKAGE void clang_remap_dispose(CXRemapping); + +/** + * @} + */ + +/** \defgroup CINDEX_HIGH Higher level API functions + * + * @{ + */ + +enum CXVisitorResult { + CXVisit_Break, + CXVisit_Continue +}; + +typedef struct CXCursorAndRangeVisitor { + void *context; + enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange); +} CXCursorAndRangeVisitor; + +typedef enum { + /** + * Function returned successfully. + */ + CXResult_Success = 0, + /** + * One of the parameters was invalid for the function. + */ + CXResult_Invalid = 1, + /** + * The function was terminated by a callback (e.g. it returned + * CXVisit_Break) + */ + CXResult_VisitBreak = 2 + +} CXResult; + +/** + * Find references of a declaration in a specific file. + * + * \param cursor pointing to a declaration or a reference of one. + * + * \param file to search for references. + * + * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for + * each reference found. + * The CXSourceRange will point inside the file; if the reference is inside + * a macro (and not a macro argument) the CXSourceRange will be invalid. + * + * \returns one of the CXResult enumerators. + */ +CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file, + CXCursorAndRangeVisitor visitor); + +/** + * Find #import/#include directives in a specific file. + * + * \param TU translation unit containing the file to query. + * + * \param file to search for #import/#include directives. + * + * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for + * each directive found. + * + * \returns one of the CXResult enumerators. + */ +CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU, + CXFile file, + CXCursorAndRangeVisitor visitor); + +#ifdef __has_feature +# if __has_feature(blocks) + +typedef enum CXVisitorResult + (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange); + +CINDEX_LINKAGE +CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile, + CXCursorAndRangeVisitorBlock); + +CINDEX_LINKAGE +CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile, + CXCursorAndRangeVisitorBlock); + +# endif +#endif + +/** + * The client's data object that is associated with a CXFile. + */ +typedef void *CXIdxClientFile; + +/** + * The client's data object that is associated with a semantic entity. + */ +typedef void *CXIdxClientEntity; + +/** + * The client's data object that is associated with a semantic container + * of entities. + */ +typedef void *CXIdxClientContainer; + +/** + * The client's data object that is associated with an AST file (PCH + * or module). + */ +typedef void *CXIdxClientASTFile; + +/** + * Source location passed to index callbacks. + */ +typedef struct { + void *ptr_data[2]; + unsigned int_data; +} CXIdxLoc; + +/** + * Data for ppIncludedFile callback. + */ +typedef struct { + /** + * Location of '#' in the \#include/\#import directive. + */ + CXIdxLoc hashLoc; + /** + * Filename as written in the \#include/\#import directive. + */ + const char *filename; + /** + * The actual file that the \#include/\#import directive resolved to. + */ + CXFile file; + int isImport; + int isAngled; + /** + * Non-zero if the directive was automatically turned into a module + * import. + */ + int isModuleImport; +} CXIdxIncludedFileInfo; + +/** + * Data for IndexerCallbacks#importedASTFile. + */ +typedef struct { + /** + * Top level AST file containing the imported PCH, module or submodule. + */ + CXFile file; + /** + * The imported module or NULL if the AST file is a PCH. + */ + CXModule module; + /** + * Location where the file is imported. Applicable only for modules. + */ + CXIdxLoc loc; + /** + * Non-zero if an inclusion directive was automatically turned into + * a module import. Applicable only for modules. + */ + int isImplicit; + +} CXIdxImportedASTFileInfo; + +typedef enum { + CXIdxEntity_Unexposed = 0, + CXIdxEntity_Typedef = 1, + CXIdxEntity_Function = 2, + CXIdxEntity_Variable = 3, + CXIdxEntity_Field = 4, + CXIdxEntity_EnumConstant = 5, + + CXIdxEntity_ObjCClass = 6, + CXIdxEntity_ObjCProtocol = 7, + CXIdxEntity_ObjCCategory = 8, + + CXIdxEntity_ObjCInstanceMethod = 9, + CXIdxEntity_ObjCClassMethod = 10, + CXIdxEntity_ObjCProperty = 11, + CXIdxEntity_ObjCIvar = 12, + + CXIdxEntity_Enum = 13, + CXIdxEntity_Struct = 14, + CXIdxEntity_Union = 15, + + CXIdxEntity_CXXClass = 16, + CXIdxEntity_CXXNamespace = 17, + CXIdxEntity_CXXNamespaceAlias = 18, + CXIdxEntity_CXXStaticVariable = 19, + CXIdxEntity_CXXStaticMethod = 20, + CXIdxEntity_CXXInstanceMethod = 21, + CXIdxEntity_CXXConstructor = 22, + CXIdxEntity_CXXDestructor = 23, + CXIdxEntity_CXXConversionFunction = 24, + CXIdxEntity_CXXTypeAlias = 25, + CXIdxEntity_CXXInterface = 26 + +} CXIdxEntityKind; + +typedef enum { + CXIdxEntityLang_None = 0, + CXIdxEntityLang_C = 1, + CXIdxEntityLang_ObjC = 2, + CXIdxEntityLang_CXX = 3, + CXIdxEntityLang_Swift = 4 +} CXIdxEntityLanguage; + +/** + * Extra C++ template information for an entity. This can apply to: + * CXIdxEntity_Function + * CXIdxEntity_CXXClass + * CXIdxEntity_CXXStaticMethod + * CXIdxEntity_CXXInstanceMethod + * CXIdxEntity_CXXConstructor + * CXIdxEntity_CXXConversionFunction + * CXIdxEntity_CXXTypeAlias + */ +typedef enum { + CXIdxEntity_NonTemplate = 0, + CXIdxEntity_Template = 1, + CXIdxEntity_TemplatePartialSpecialization = 2, + CXIdxEntity_TemplateSpecialization = 3 +} CXIdxEntityCXXTemplateKind; + +typedef enum { + CXIdxAttr_Unexposed = 0, + CXIdxAttr_IBAction = 1, + CXIdxAttr_IBOutlet = 2, + CXIdxAttr_IBOutletCollection = 3 +} CXIdxAttrKind; + +typedef struct { + CXIdxAttrKind kind; + CXCursor cursor; + CXIdxLoc loc; +} CXIdxAttrInfo; + +typedef struct { + CXIdxEntityKind kind; + CXIdxEntityCXXTemplateKind templateKind; + CXIdxEntityLanguage lang; + const char *name; + const char *USR; + CXCursor cursor; + const CXIdxAttrInfo *const *attributes; + unsigned numAttributes; +} CXIdxEntityInfo; + +typedef struct { + CXCursor cursor; +} CXIdxContainerInfo; + +typedef struct { + const CXIdxAttrInfo *attrInfo; + const CXIdxEntityInfo *objcClass; + CXCursor classCursor; + CXIdxLoc classLoc; +} CXIdxIBOutletCollectionAttrInfo; + +typedef enum { + CXIdxDeclFlag_Skipped = 0x1 +} CXIdxDeclInfoFlags; + +typedef struct { + const CXIdxEntityInfo *entityInfo; + CXCursor cursor; + CXIdxLoc loc; + const CXIdxContainerInfo *semanticContainer; + /** + * Generally same as #semanticContainer but can be different in + * cases like out-of-line C++ member functions. + */ + const CXIdxContainerInfo *lexicalContainer; + int isRedeclaration; + int isDefinition; + int isContainer; + const CXIdxContainerInfo *declAsContainer; + /** + * Whether the declaration exists in code or was created implicitly + * by the compiler, e.g. implicit Objective-C methods for properties. + */ + int isImplicit; + const CXIdxAttrInfo *const *attributes; + unsigned numAttributes; + + unsigned flags; + +} CXIdxDeclInfo; + +typedef enum { + CXIdxObjCContainer_ForwardRef = 0, + CXIdxObjCContainer_Interface = 1, + CXIdxObjCContainer_Implementation = 2 +} CXIdxObjCContainerKind; + +typedef struct { + const CXIdxDeclInfo *declInfo; + CXIdxObjCContainerKind kind; +} CXIdxObjCContainerDeclInfo; + +typedef struct { + const CXIdxEntityInfo *base; + CXCursor cursor; + CXIdxLoc loc; +} CXIdxBaseClassInfo; + +typedef struct { + const CXIdxEntityInfo *protocol; + CXCursor cursor; + CXIdxLoc loc; +} CXIdxObjCProtocolRefInfo; + +typedef struct { + const CXIdxObjCProtocolRefInfo *const *protocols; + unsigned numProtocols; +} CXIdxObjCProtocolRefListInfo; + +typedef struct { + const CXIdxObjCContainerDeclInfo *containerInfo; + const CXIdxBaseClassInfo *superInfo; + const CXIdxObjCProtocolRefListInfo *protocols; +} CXIdxObjCInterfaceDeclInfo; + +typedef struct { + const CXIdxObjCContainerDeclInfo *containerInfo; + const CXIdxEntityInfo *objcClass; + CXCursor classCursor; + CXIdxLoc classLoc; + const CXIdxObjCProtocolRefListInfo *protocols; +} CXIdxObjCCategoryDeclInfo; + +typedef struct { + const CXIdxDeclInfo *declInfo; + const CXIdxEntityInfo *getter; + const CXIdxEntityInfo *setter; +} CXIdxObjCPropertyDeclInfo; + +typedef struct { + const CXIdxDeclInfo *declInfo; + const CXIdxBaseClassInfo *const *bases; + unsigned numBases; +} CXIdxCXXClassDeclInfo; + +/** + * Data for IndexerCallbacks#indexEntityReference. + * + * This may be deprecated in a future version as this duplicates + * the \c CXSymbolRole_Implicit bit in \c CXSymbolRole. + */ +typedef enum { + /** + * The entity is referenced directly in user's code. + */ + CXIdxEntityRef_Direct = 1, + /** + * An implicit reference, e.g. a reference of an Objective-C method + * via the dot syntax. + */ + CXIdxEntityRef_Implicit = 2 +} CXIdxEntityRefKind; + +/** + * Roles that are attributed to symbol occurrences. + * + * Internal: this currently mirrors low 9 bits of clang::index::SymbolRole with + * higher bits zeroed. These high bits may be exposed in the future. + */ +typedef enum { + CXSymbolRole_None = 0, + CXSymbolRole_Declaration = 1 << 0, + CXSymbolRole_Definition = 1 << 1, + CXSymbolRole_Reference = 1 << 2, + CXSymbolRole_Read = 1 << 3, + CXSymbolRole_Write = 1 << 4, + CXSymbolRole_Call = 1 << 5, + CXSymbolRole_Dynamic = 1 << 6, + CXSymbolRole_AddressOf = 1 << 7, + CXSymbolRole_Implicit = 1 << 8 +} CXSymbolRole; + +/** + * Data for IndexerCallbacks#indexEntityReference. + */ +typedef struct { + CXIdxEntityRefKind kind; + /** + * Reference cursor. + */ + CXCursor cursor; + CXIdxLoc loc; + /** + * The entity that gets referenced. + */ + const CXIdxEntityInfo *referencedEntity; + /** + * Immediate "parent" of the reference. For example: + * + * \code + * Foo *var; + * \endcode + * + * The parent of reference of type 'Foo' is the variable 'var'. + * For references inside statement bodies of functions/methods, + * the parentEntity will be the function/method. + */ + const CXIdxEntityInfo *parentEntity; + /** + * Lexical container context of the reference. + */ + const CXIdxContainerInfo *container; + /** + * Sets of symbol roles of the reference. + */ + CXSymbolRole role; +} CXIdxEntityRefInfo; + +/** + * A group of callbacks used by #clang_indexSourceFile and + * #clang_indexTranslationUnit. + */ +typedef struct { + /** + * Called periodically to check whether indexing should be aborted. + * Should return 0 to continue, and non-zero to abort. + */ + int (*abortQuery)(CXClientData client_data, void *reserved); + + /** + * Called at the end of indexing; passes the complete diagnostic set. + */ + void (*diagnostic)(CXClientData client_data, + CXDiagnosticSet, void *reserved); + + CXIdxClientFile (*enteredMainFile)(CXClientData client_data, + CXFile mainFile, void *reserved); + + /** + * Called when a file gets \#included/\#imported. + */ + CXIdxClientFile (*ppIncludedFile)(CXClientData client_data, + const CXIdxIncludedFileInfo *); + + /** + * Called when a AST file (PCH or module) gets imported. + * + * AST files will not get indexed (there will not be callbacks to index all + * the entities in an AST file). The recommended action is that, if the AST + * file is not already indexed, to initiate a new indexing job specific to + * the AST file. + */ + CXIdxClientASTFile (*importedASTFile)(CXClientData client_data, + const CXIdxImportedASTFileInfo *); + + /** + * Called at the beginning of indexing a translation unit. + */ + CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data, + void *reserved); + + void (*indexDeclaration)(CXClientData client_data, + const CXIdxDeclInfo *); + + /** + * Called to index a reference of an entity. + */ + void (*indexEntityReference)(CXClientData client_data, + const CXIdxEntityRefInfo *); + +} IndexerCallbacks; + +CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind); +CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo * +clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *); + +CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo * +clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *); + +CINDEX_LINKAGE +const CXIdxObjCCategoryDeclInfo * +clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *); + +CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo * +clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *); + +CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo * +clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *); + +CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo * +clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *); + +CINDEX_LINKAGE const CXIdxCXXClassDeclInfo * +clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *); + +/** + * For retrieving a custom CXIdxClientContainer attached to a + * container. + */ +CINDEX_LINKAGE CXIdxClientContainer +clang_index_getClientContainer(const CXIdxContainerInfo *); + +/** + * For setting a custom CXIdxClientContainer attached to a + * container. + */ +CINDEX_LINKAGE void +clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer); + +/** + * For retrieving a custom CXIdxClientEntity attached to an entity. + */ +CINDEX_LINKAGE CXIdxClientEntity +clang_index_getClientEntity(const CXIdxEntityInfo *); + +/** + * For setting a custom CXIdxClientEntity attached to an entity. + */ +CINDEX_LINKAGE void +clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity); + +/** + * An indexing action/session, to be applied to one or multiple + * translation units. + */ +typedef void *CXIndexAction; + +/** + * An indexing action/session, to be applied to one or multiple + * translation units. + * + * \param CIdx The index object with which the index action will be associated. + */ +CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx); + +/** + * Destroy the given index action. + * + * The index action must not be destroyed until all of the translation units + * created within that index action have been destroyed. + */ +CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction); + +typedef enum { + /** + * Used to indicate that no special indexing options are needed. + */ + CXIndexOpt_None = 0x0, + + /** + * Used to indicate that IndexerCallbacks#indexEntityReference should + * be invoked for only one reference of an entity per source file that does + * not also include a declaration/definition of the entity. + */ + CXIndexOpt_SuppressRedundantRefs = 0x1, + + /** + * Function-local symbols should be indexed. If this is not set + * function-local symbols will be ignored. + */ + CXIndexOpt_IndexFunctionLocalSymbols = 0x2, + + /** + * Implicit function/class template instantiations should be indexed. + * If this is not set, implicit instantiations will be ignored. + */ + CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4, + + /** + * Suppress all compiler warnings when parsing for indexing. + */ + CXIndexOpt_SuppressWarnings = 0x8, + + /** + * Skip a function/method body that was already parsed during an + * indexing session associated with a \c CXIndexAction object. + * Bodies in system headers are always skipped. + */ + CXIndexOpt_SkipParsedBodiesInSession = 0x10 + +} CXIndexOptFlags; + +/** + * Index the given source file and the translation unit corresponding + * to that file via callbacks implemented through #IndexerCallbacks. + * + * \param client_data pointer data supplied by the client, which will + * be passed to the invoked callbacks. + * + * \param index_callbacks Pointer to indexing callbacks that the client + * implements. + * + * \param index_callbacks_size Size of #IndexerCallbacks structure that gets + * passed in index_callbacks. + * + * \param index_options A bitmask of options that affects how indexing is + * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags. + * + * \param[out] out_TU pointer to store a \c CXTranslationUnit that can be + * reused after indexing is finished. Set to \c NULL if you do not require it. + * + * \returns 0 on success or if there were errors from which the compiler could + * recover. If there is a failure from which there is no recovery, returns + * a non-zero \c CXErrorCode. + * + * The rest of the parameters are the same as #clang_parseTranslationUnit. + */ +CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction, + CXClientData client_data, + IndexerCallbacks *index_callbacks, + unsigned index_callbacks_size, + unsigned index_options, + const char *source_filename, + const char * const *command_line_args, + int num_command_line_args, + struct CXUnsavedFile *unsaved_files, + unsigned num_unsaved_files, + CXTranslationUnit *out_TU, + unsigned TU_options); + +/** + * Same as clang_indexSourceFile but requires a full command line + * for \c command_line_args including argv[0]. This is useful if the standard + * library paths are relative to the binary. + */ +CINDEX_LINKAGE int clang_indexSourceFileFullArgv( + CXIndexAction, CXClientData client_data, IndexerCallbacks *index_callbacks, + unsigned index_callbacks_size, unsigned index_options, + const char *source_filename, const char *const *command_line_args, + int num_command_line_args, struct CXUnsavedFile *unsaved_files, + unsigned num_unsaved_files, CXTranslationUnit *out_TU, unsigned TU_options); + +/** + * Index the given translation unit via callbacks implemented through + * #IndexerCallbacks. + * + * The order of callback invocations is not guaranteed to be the same as + * when indexing a source file. The high level order will be: + * + * -Preprocessor callbacks invocations + * -Declaration/reference callbacks invocations + * -Diagnostic callback invocations + * + * The parameters are the same as #clang_indexSourceFile. + * + * \returns If there is a failure from which there is no recovery, returns + * non-zero, otherwise returns 0. + */ +CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction, + CXClientData client_data, + IndexerCallbacks *index_callbacks, + unsigned index_callbacks_size, + unsigned index_options, + CXTranslationUnit); + +/** + * Retrieve the CXIdxFile, file, line, column, and offset represented by + * the given CXIdxLoc. + * + * If the location refers into a macro expansion, retrieves the + * location of the macro expansion and if it refers into a macro argument + * retrieves the location of the argument. + */ +CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc, + CXIdxClientFile *indexFile, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset); + +/** + * Retrieve the CXSourceLocation represented by the given CXIdxLoc. + */ +CINDEX_LINKAGE +CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc); + +/** + * Visitor invoked for each field found by a traversal. + * + * This visitor function will be invoked for each field found by + * \c clang_Type_visitFields. Its first argument is the cursor being + * visited, its second argument is the client data provided to + * \c clang_Type_visitFields. + * + * The visitor should return one of the \c CXVisitorResult values + * to direct \c clang_Type_visitFields. + */ +typedef enum CXVisitorResult (*CXFieldVisitor)(CXCursor C, + CXClientData client_data); + +/** + * Visit the fields of a particular type. + * + * This function visits all the direct fields of the given cursor, + * invoking the given \p visitor function with the cursors of each + * visited field. The traversal may be ended prematurely, if + * the visitor returns \c CXFieldVisit_Break. + * + * \param T the record type whose field may be visited. + * + * \param visitor the visitor function that will be invoked for each + * field of \p T. + * + * \param client_data pointer data supplied by the client, which will + * be passed to the visitor each time it is invoked. + * + * \returns a non-zero value if the traversal was terminated + * prematurely by the visitor returning \c CXFieldVisit_Break. + */ +CINDEX_LINKAGE unsigned clang_Type_visitFields(CXType T, + CXFieldVisitor visitor, + CXClientData client_data); + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif diff --git a/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/Platform.h b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/Platform.h new file mode 100644 index 000000000..e2a4dccbd --- /dev/null +++ b/engine/source/meta_parser/3rd_party/LLVM/include/clang-c/Platform.h @@ -0,0 +1,45 @@ +/*===-- clang-c/Platform.h - C Index platform decls -------------*- C -*-===*\ +|* *| +|* The LLVM Compiler Infrastructure *| +|* *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This header provides platform specific macros (dllimport, deprecated, ...) *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_CLANG_C_PLATFORM_H +#define LLVM_CLANG_C_PLATFORM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* MSVC DLL import/export. */ +#ifdef _MSC_VER + #ifdef _CINDEX_LIB_ + #define CINDEX_LINKAGE __declspec(dllexport) + #else + #define CINDEX_LINKAGE __declspec(dllimport) + #endif +#else + #define CINDEX_LINKAGE +#endif + +#ifdef __GNUC__ + #define CINDEX_DEPRECATED __attribute__((deprecated)) +#else + #ifdef _MSC_VER + #define CINDEX_DEPRECATED __declspec(deprecated) + #else + #define CINDEX_DEPRECATED + #endif +#endif + +#ifdef __cplusplus +} +#endif +#endif diff --git a/engine/source/meta_parser/3rd_party/LLVM/include/llvm-c/lto.h b/engine/source/meta_parser/3rd_party/LLVM/include/llvm-c/lto.h new file mode 100644 index 000000000..1acd610f7 --- /dev/null +++ b/engine/source/meta_parser/3rd_party/LLVM/include/llvm-c/lto.h @@ -0,0 +1,849 @@ +/*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\ +|* *| +|* The LLVM Compiler Infrastructure *| +|* *| +|* This file is distributed under the University of Illinois Open Source *| +|* License. See LICENSE.TXT for details. *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This header provides public interface to an abstract link time optimization*| +|* library. LLVM provides an implementation of this interface for use with *| +|* llvm bitcode files. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_C_LTO_H +#define LLVM_C_LTO_H + +#ifdef __cplusplus +#include +#else +#include +#endif +#include + +#ifndef __cplusplus +#if !defined(_MSC_VER) +#include +typedef bool lto_bool_t; +#else +/* MSVC in particular does not have anything like _Bool or bool in C, but we can + at least make sure the type is the same size. The implementation side will + use C++ bool. */ +typedef unsigned char lto_bool_t; +#endif +#else +typedef bool lto_bool_t; +#endif + +/** + * @defgroup LLVMCLTO LTO + * @ingroup LLVMC + * + * @{ + */ + +#define LTO_API_VERSION 22 + +/** + * \since prior to LTO_API_VERSION=3 + */ +typedef enum { + LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */ + LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0, + LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0, + LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0, + LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080, + LTO_SYMBOL_DEFINITION_MASK = 0x00000700, + LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100, + LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200, + LTO_SYMBOL_DEFINITION_WEAK = 0x00000300, + LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400, + LTO_SYMBOL_DEFINITION_WEAKUNDEF = 0x00000500, + LTO_SYMBOL_SCOPE_MASK = 0x00003800, + LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800, + LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000, + LTO_SYMBOL_SCOPE_PROTECTED = 0x00002000, + LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800, + LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800, + LTO_SYMBOL_COMDAT = 0x00004000, + LTO_SYMBOL_ALIAS = 0x00008000 +} lto_symbol_attributes; + +/** + * \since prior to LTO_API_VERSION=3 + */ +typedef enum { + LTO_DEBUG_MODEL_NONE = 0, + LTO_DEBUG_MODEL_DWARF = 1 +} lto_debug_model; + +/** + * \since prior to LTO_API_VERSION=3 + */ +typedef enum { + LTO_CODEGEN_PIC_MODEL_STATIC = 0, + LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, + LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2, + LTO_CODEGEN_PIC_MODEL_DEFAULT = 3 +} lto_codegen_model; + +/** opaque reference to a loaded object module */ +typedef struct LLVMOpaqueLTOModule *lto_module_t; + +/** opaque reference to a code generator */ +typedef struct LLVMOpaqueLTOCodeGenerator *lto_code_gen_t; + +/** opaque reference to a thin code generator */ +typedef struct LLVMOpaqueThinLTOCodeGenerator *thinlto_code_gen_t; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Returns a printable string. + * + * \since prior to LTO_API_VERSION=3 + */ +extern const char* +lto_get_version(void); + +/** + * Returns the last error string or NULL if last operation was successful. + * + * \since prior to LTO_API_VERSION=3 + */ +extern const char* +lto_get_error_message(void); + +/** + * Checks if a file is a loadable object file. + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_bool_t +lto_module_is_object_file(const char* path); + +/** + * Checks if a file is a loadable object compiled for requested target. + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_bool_t +lto_module_is_object_file_for_target(const char* path, + const char* target_triple_prefix); + +/** + * Return true if \p Buffer contains a bitcode file with ObjC code (category + * or class) in it. + * + * \since LTO_API_VERSION=20 + */ +extern lto_bool_t +lto_module_has_objc_category(const void *mem, size_t length); + +/** + * Checks if a buffer is a loadable object file. + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem, + size_t length); + +/** + * Checks if a buffer is a loadable object compiled for requested target. + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_bool_t +lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length, + const char* target_triple_prefix); + +/** + * Loads an object file from disk. + * Returns NULL on error (check lto_get_error_message() for details). + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_module_t +lto_module_create(const char* path); + +/** + * Loads an object file from memory. + * Returns NULL on error (check lto_get_error_message() for details). + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_module_t +lto_module_create_from_memory(const void* mem, size_t length); + +/** + * Loads an object file from memory with an extra path argument. + * Returns NULL on error (check lto_get_error_message() for details). + * + * \since LTO_API_VERSION=9 + */ +extern lto_module_t +lto_module_create_from_memory_with_path(const void* mem, size_t length, + const char *path); + +/** + * Loads an object file in its own context. + * + * Loads an object file in its own LLVMContext. This function call is + * thread-safe. However, modules created this way should not be merged into an + * lto_code_gen_t using \a lto_codegen_add_module(). + * + * Returns NULL on error (check lto_get_error_message() for details). + * + * \since LTO_API_VERSION=11 + */ +extern lto_module_t +lto_module_create_in_local_context(const void *mem, size_t length, + const char *path); + +/** + * Loads an object file in the codegen context. + * + * Loads an object file into the same context as \c cg. The module is safe to + * add using \a lto_codegen_add_module(). + * + * Returns NULL on error (check lto_get_error_message() for details). + * + * \since LTO_API_VERSION=11 + */ +extern lto_module_t +lto_module_create_in_codegen_context(const void *mem, size_t length, + const char *path, lto_code_gen_t cg); + +/** + * Loads an object file from disk. The seek point of fd is not preserved. + * Returns NULL on error (check lto_get_error_message() for details). + * + * \since LTO_API_VERSION=5 + */ +extern lto_module_t +lto_module_create_from_fd(int fd, const char *path, size_t file_size); + +/** + * Loads an object file from disk. The seek point of fd is not preserved. + * Returns NULL on error (check lto_get_error_message() for details). + * + * \since LTO_API_VERSION=5 + */ +extern lto_module_t +lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size, + size_t map_size, off_t offset); + +/** + * Frees all memory internally allocated by the module. + * Upon return the lto_module_t is no longer valid. + * + * \since prior to LTO_API_VERSION=3 + */ +extern void +lto_module_dispose(lto_module_t mod); + +/** + * Returns triple string which the object module was compiled under. + * + * \since prior to LTO_API_VERSION=3 + */ +extern const char* +lto_module_get_target_triple(lto_module_t mod); + +/** + * Sets triple string with which the object will be codegened. + * + * \since LTO_API_VERSION=4 + */ +extern void +lto_module_set_target_triple(lto_module_t mod, const char *triple); + +/** + * Returns the number of symbols in the object module. + * + * \since prior to LTO_API_VERSION=3 + */ +extern unsigned int +lto_module_get_num_symbols(lto_module_t mod); + +/** + * Returns the name of the ith symbol in the object module. + * + * \since prior to LTO_API_VERSION=3 + */ +extern const char* +lto_module_get_symbol_name(lto_module_t mod, unsigned int index); + +/** + * Returns the attributes of the ith symbol in the object module. + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_symbol_attributes +lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index); + +/** + * Returns the module's linker options. + * + * The linker options may consist of multiple flags. It is the linker's + * responsibility to split the flags using a platform-specific mechanism. + * + * \since LTO_API_VERSION=16 + */ +extern const char* +lto_module_get_linkeropts(lto_module_t mod); + +/** + * Diagnostic severity. + * + * \since LTO_API_VERSION=7 + */ +typedef enum { + LTO_DS_ERROR = 0, + LTO_DS_WARNING = 1, + LTO_DS_REMARK = 3, // Added in LTO_API_VERSION=10. + LTO_DS_NOTE = 2 +} lto_codegen_diagnostic_severity_t; + +/** + * Diagnostic handler type. + * \p severity defines the severity. + * \p diag is the actual diagnostic. + * The diagnostic is not prefixed by any of severity keyword, e.g., 'error: '. + * \p ctxt is used to pass the context set with the diagnostic handler. + * + * \since LTO_API_VERSION=7 + */ +typedef void (*lto_diagnostic_handler_t)( + lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt); + +/** + * Set a diagnostic handler and the related context (void *). + * This is more general than lto_get_error_message, as the diagnostic handler + * can be called at anytime within lto. + * + * \since LTO_API_VERSION=7 + */ +extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t, + lto_diagnostic_handler_t, + void *); + +/** + * Instantiates a code generator. + * Returns NULL on error (check lto_get_error_message() for details). + * + * All modules added using \a lto_codegen_add_module() must have been created + * in the same context as the codegen. + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_code_gen_t +lto_codegen_create(void); + +/** + * Instantiate a code generator in its own context. + * + * Instantiates a code generator in its own context. Modules added via \a + * lto_codegen_add_module() must have all been created in the same context, + * using \a lto_module_create_in_codegen_context(). + * + * \since LTO_API_VERSION=11 + */ +extern lto_code_gen_t +lto_codegen_create_in_local_context(void); + +/** + * Frees all code generator and all memory it internally allocated. + * Upon return the lto_code_gen_t is no longer valid. + * + * \since prior to LTO_API_VERSION=3 + */ +extern void +lto_codegen_dispose(lto_code_gen_t); + +/** + * Add an object module to the set of modules for which code will be generated. + * Returns true on error (check lto_get_error_message() for details). + * + * \c cg and \c mod must both be in the same context. See \a + * lto_codegen_create_in_local_context() and \a + * lto_module_create_in_codegen_context(). + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_bool_t +lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod); + +/** + * Sets the object module for code generation. This will transfer the ownership + * of the module to the code generator. + * + * \c cg and \c mod must both be in the same context. + * + * \since LTO_API_VERSION=13 + */ +extern void +lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod); + +/** + * Sets if debug info should be generated. + * Returns true on error (check lto_get_error_message() for details). + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_bool_t +lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model); + +/** + * Sets which PIC code model to generated. + * Returns true on error (check lto_get_error_message() for details). + * + * \since prior to LTO_API_VERSION=3 + */ +extern lto_bool_t +lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model); + +/** + * Sets the cpu to generate code for. + * + * \since LTO_API_VERSION=4 + */ +extern void +lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu); + +/** + * Sets the location of the assembler tool to run. If not set, libLTO + * will use gcc to invoke the assembler. + * + * \since LTO_API_VERSION=3 + */ +extern void +lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path); + +/** + * Sets extra arguments that libLTO should pass to the assembler. + * + * \since LTO_API_VERSION=4 + */ +extern void +lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args, + int nargs); + +/** + * Adds to a list of all global symbols that must exist in the final generated + * code. If a function is not listed there, it might be inlined into every usage + * and optimized away. + * + * \since prior to LTO_API_VERSION=3 + */ +extern void +lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol); + +/** + * Writes a new object file at the specified path that contains the + * merged contents of all modules added so far. + * Returns true on error (check lto_get_error_message() for details). + * + * \since LTO_API_VERSION=5 + */ +extern lto_bool_t +lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path); + +/** + * Generates code for all added modules into one native object file. + * This calls lto_codegen_optimize then lto_codegen_compile_optimized. + * + * On success returns a pointer to a generated mach-o/ELF buffer and + * length set to the buffer size. The buffer is owned by the + * lto_code_gen_t and will be freed when lto_codegen_dispose() + * is called, or lto_codegen_compile() is called again. + * On failure, returns NULL (check lto_get_error_message() for details). + * + * \since prior to LTO_API_VERSION=3 + */ +extern const void* +lto_codegen_compile(lto_code_gen_t cg, size_t* length); + +/** + * Generates code for all added modules into one native object file. + * This calls lto_codegen_optimize then lto_codegen_compile_optimized (instead + * of returning a generated mach-o/ELF buffer, it writes to a file). + * + * The name of the file is written to name. Returns true on error. + * + * \since LTO_API_VERSION=5 + */ +extern lto_bool_t +lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name); + +/** + * Runs optimization for the merged module. Returns true on error. + * + * \since LTO_API_VERSION=12 + */ +extern lto_bool_t +lto_codegen_optimize(lto_code_gen_t cg); + +/** + * Generates code for the optimized merged module into one native object file. + * It will not run any IR optimizations on the merged module. + * + * On success returns a pointer to a generated mach-o/ELF buffer and length set + * to the buffer size. The buffer is owned by the lto_code_gen_t and will be + * freed when lto_codegen_dispose() is called, or + * lto_codegen_compile_optimized() is called again. On failure, returns NULL + * (check lto_get_error_message() for details). + * + * \since LTO_API_VERSION=12 + */ +extern const void* +lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length); + +/** + * Returns the runtime API version. + * + * \since LTO_API_VERSION=12 + */ +extern unsigned int +lto_api_version(void); + +/** + * Sets options to help debug codegen bugs. + * + * \since prior to LTO_API_VERSION=3 + */ +extern void +lto_codegen_debug_options(lto_code_gen_t cg, const char *); + +/** + * Initializes LLVM disassemblers. + * FIXME: This doesn't really belong here. + * + * \since LTO_API_VERSION=5 + */ +extern void +lto_initialize_disassembler(void); + +/** + * Sets if we should run internalize pass during optimization and code + * generation. + * + * \since LTO_API_VERSION=14 + */ +extern void +lto_codegen_set_should_internalize(lto_code_gen_t cg, + lto_bool_t ShouldInternalize); + +/** + * Set whether to embed uselists in bitcode. + * + * Sets whether \a lto_codegen_write_merged_modules() should embed uselists in + * output bitcode. This should be turned on for all -save-temps output. + * + * \since LTO_API_VERSION=15 + */ +extern void +lto_codegen_set_should_embed_uselists(lto_code_gen_t cg, + lto_bool_t ShouldEmbedUselists); + +/** + * @} // endgoup LLVMCLTO + * @defgroup LLVMCTLTO ThinLTO + * @ingroup LLVMC + * + * @{ + */ + +/** + * Type to wrap a single object returned by ThinLTO. + * + * \since LTO_API_VERSION=18 + */ +typedef struct { + const char *Buffer; + size_t Size; +} LTOObjectBuffer; + +/** + * Instantiates a ThinLTO code generator. + * Returns NULL on error (check lto_get_error_message() for details). + * + * + * The ThinLTOCodeGenerator is not intended to be reuse for multiple + * compilation: the model is that the client adds modules to the generator and + * ask to perform the ThinLTO optimizations / codegen, and finally destroys the + * codegenerator. + * + * \since LTO_API_VERSION=18 + */ +extern thinlto_code_gen_t thinlto_create_codegen(void); + +/** + * Frees the generator and all memory it internally allocated. + * Upon return the thinlto_code_gen_t is no longer valid. + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_dispose(thinlto_code_gen_t cg); + +/** + * Add a module to a ThinLTO code generator. Identifier has to be unique among + * all the modules in a code generator. The data buffer stays owned by the + * client, and is expected to be available for the entire lifetime of the + * thinlto_code_gen_t it is added to. + * + * On failure, returns NULL (check lto_get_error_message() for details). + * + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_add_module(thinlto_code_gen_t cg, + const char *identifier, const char *data, + int length); + +/** + * Optimize and codegen all the modules added to the codegenerator using + * ThinLTO. Resulting objects are accessible using thinlto_module_get_object(). + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_process(thinlto_code_gen_t cg); + +/** + * Returns the number of object files produced by the ThinLTO CodeGenerator. + * + * It usually matches the number of input files, but this is not a guarantee of + * the API and may change in future implementation, so the client should not + * assume it. + * + * \since LTO_API_VERSION=18 + */ +extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg); + +/** + * Returns a reference to the ith object file produced by the ThinLTO + * CodeGenerator. + * + * Client should use \p thinlto_module_get_num_objects() to get the number of + * available objects. + * + * \since LTO_API_VERSION=18 + */ +extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg, + unsigned int index); + +/** + * Returns the number of object files produced by the ThinLTO CodeGenerator. + * + * It usually matches the number of input files, but this is not a guarantee of + * the API and may change in future implementation, so the client should not + * assume it. + * + * \since LTO_API_VERSION=21 + */ +unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg); + +/** + * Returns the path to the ith object file produced by the ThinLTO + * CodeGenerator. + * + * Client should use \p thinlto_module_get_num_object_files() to get the number + * of available objects. + * + * \since LTO_API_VERSION=21 + */ +const char *thinlto_module_get_object_file(thinlto_code_gen_t cg, + unsigned int index); + +/** + * Sets which PIC code model to generate. + * Returns true on error (check lto_get_error_message() for details). + * + * \since LTO_API_VERSION=18 + */ +extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg, + lto_codegen_model); + +/** + * Sets the path to a directory to use as a storage for temporary bitcode files. + * The intention is to make the bitcode files available for debugging at various + * stage of the pipeline. + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg, + const char *save_temps_dir); + +/** + * Set the path to a directory where to save generated object files. This + * path can be used by a linker to request on-disk files instead of in-memory + * buffers. When set, results are available through + * thinlto_module_get_object_file() instead of thinlto_module_get_object(). + * + * \since LTO_API_VERSION=21 + */ +void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg, + const char *save_temps_dir); + +/** + * Sets the cpu to generate code for. + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu); + +/** + * Disable CodeGen, only run the stages till codegen and stop. The output will + * be bitcode. + * + * \since LTO_API_VERSION=19 + */ +extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg, + lto_bool_t disable); + +/** + * Perform CodeGen only: disable all other stages. + * + * \since LTO_API_VERSION=19 + */ +extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg, + lto_bool_t codegen_only); + +/** + * Parse -mllvm style debug options. + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_debug_options(const char *const *options, int number); + +/** + * Test if a module has support for ThinLTO linking. + * + * \since LTO_API_VERSION=18 + */ +extern lto_bool_t lto_module_is_thinlto(lto_module_t mod); + +/** + * Adds a symbol to the list of global symbols that must exist in the final + * generated code. If a function is not listed there, it might be inlined into + * every usage and optimized away. For every single module, the functions + * referenced from code outside of the ThinLTO modules need to be added here. + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg, + const char *name, + int length); + +/** + * Adds a symbol to the list of global symbols that are cross-referenced between + * ThinLTO files. If the ThinLTO CodeGenerator can ensure that every + * references from a ThinLTO module to this symbol is optimized away, then + * the symbol can be discarded. + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg, + const char *name, + int length); + +/** + * @} // endgoup LLVMCTLTO + * @defgroup LLVMCTLTO_CACHING ThinLTO Cache Control + * @ingroup LLVMCTLTO + * + * These entry points control the ThinLTO cache. The cache is intended to + * support incremental builds, and thus needs to be persistent across builds. + * The client enables the cache by supplying a path to an existing directory. + * The code generator will use this to store objects files that may be reused + * during a subsequent build. + * To avoid filling the disk space, a few knobs are provided: + * - The pruning interval limits the frequency at which the garbage collector + * will try to scan the cache directory to prune expired entries. + * Setting to a negative number disables the pruning. + * - The pruning expiration time indicates to the garbage collector how old an + * entry needs to be to be removed. + * - Finally, the garbage collector can be instructed to prune the cache until + * the occupied space goes below a threshold. + * @{ + */ + +/** + * Sets the path to a directory to use as a cache storage for incremental build. + * Setting this activates caching. + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg, + const char *cache_dir); + +/** + * Sets the cache pruning interval (in seconds). A negative value disables the + * pruning. An unspecified default value will be applied, and a value of 0 will + * force prunning to occur. + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg, + int interval); + +/** + * Sets the maximum cache size that can be persistent across build, in terms of + * percentage of the available space on the disk. Set to 100 to indicate + * no limit, 50 to indicate that the cache size will not be left over half the + * available space. A value over 100 will be reduced to 100, a value of 0 will + * be ignored. An unspecified default value will be applied. + * + * The formula looks like: + * AvailableSpace = FreeSpace + ExistingCacheSize + * NewCacheSize = AvailableSpace * P/100 + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_set_final_cache_size_relative_to_available_space( + thinlto_code_gen_t cg, unsigned percentage); + +/** + * Sets the expiration (in seconds) for an entry in the cache. An unspecified + * default value will be applied. A value of 0 will be ignored. + * + * \since LTO_API_VERSION=18 + */ +extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg, + unsigned expiration); + +/** + * Sets the maximum size of the cache directory (in bytes). A value over the + * amount of available space on the disk will be reduced to the amount of + * available space. An unspecified default value will be applied. A value of 0 + * will be ignored. + * + * \since LTO_API_VERSION=22 + */ +extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg, + unsigned max_size_bytes); + +/** + * Sets the maximum number of files in the cache directory. An unspecified + * default value will be applied. A value of 0 will be ignored. + * + * \since LTO_API_VERSION=22 + */ +extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg, + unsigned max_size_files); + + + +/** + * @} // endgroup LLVMCTLTO_CACHING + */ + +#ifdef __cplusplus +} +#endif + +#endif /* LLVM_C_LTO_H */ diff --git a/engine/source/meta_parser/3rd_party/LLVM/lib/x64/libclang.lib b/engine/source/meta_parser/3rd_party/LLVM/lib/x64/libclang.lib new file mode 100644 index 000000000..232632324 Binary files /dev/null and b/engine/source/meta_parser/3rd_party/LLVM/lib/x64/libclang.lib differ diff --git a/engine/source/meta_parser/3rd_party/mustache/mustache.hpp b/engine/source/meta_parser/3rd_party/mustache/mustache.hpp new file mode 100644 index 000000000..dbb0b7994 --- /dev/null +++ b/engine/source/meta_parser/3rd_party/mustache/mustache.hpp @@ -0,0 +1,1186 @@ +/* + * Boost Software License - Version 1.0 + * + * Mustache v4.1 + * Copyright 2015-2020 Kevin Wojniak + * + * Permission is hereby granted, free of charge, to any person or organization + * obtaining a copy of the software and accompanying documentation covered by + * this license (the "Software") to use, reproduce, display, distribute, + * execute, and transmit the Software, and to prepare derivative works of the + * Software, and to permit third-parties to whom the Software is furnished to + * do so, all subject to the following: + * + * The copyright notices in the Software and this entire statement, including + * the above license grant, this restriction and the following disclaimer, + * must be included in all copies of the Software, in whole or in part, and + * all derivative works of the Software, unless such copies or derivative + * works are solely in the form of machine-executable object code generated by + * a source language processor. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT + * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE + * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef KAINJOW_MUSTACHE_HPP +#define KAINJOW_MUSTACHE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace kainjow { +namespace mustache { + +template +string_type trim(const string_type& s) { + auto it = s.begin(); + while (it != s.end() && std::isspace(*it)) { + it++; + } + auto rit = s.rbegin(); + while (rit.base() != it && std::isspace(*rit)) { + rit++; + } + return {it, rit.base()}; +} + +template +string_type html_escape(const string_type& s) { + string_type ret; + ret.reserve(s.size()*2); + for (const auto ch : s) { + switch (ch) { + case '&': + ret.append({'&','a','m','p',';'}); + break; + case '<': + ret.append({'&','l','t',';'}); + break; + case '>': + ret.append({'&','g','t',';'}); + break; + case '\"': + ret.append({'&','q','u','o','t',';'}); + break; + case '\'': + ret.append({'&','a','p','o','s',';'}); + break; + default: + ret.append(1, ch); + break; + } + } + return ret; +} + +template +std::vector split(const string_type& s, typename string_type::value_type delim) { + std::vector elems; + std::basic_stringstream ss(s); + string_type item; + while (std::getline(ss, item, delim)) { + elems.push_back(item); + } + return elems; +} + +template +class basic_renderer { +public: + using type1 = std::function; + using type2 = std::function; + + string_type operator()(const string_type& text) const { + return type1_(text); + } + + string_type operator()(const string_type& text, bool escaped) const { + return type2_(text, escaped); + } + +private: + basic_renderer(const type1& t1, const type2& t2) + : type1_(t1) + , type2_(t2) + {} + + const type1& type1_; + const type2& type2_; + + template + friend class basic_mustache; +}; + +template +class basic_lambda_t { +public: + using type1 = std::function; + using type2 = std::function& render)>; + + basic_lambda_t(const type1& t) : type1_(new type1(t)) {} + basic_lambda_t(const type2& t) : type2_(new type2(t)) {} + + bool is_type1() const { return static_cast(type1_); } + bool is_type2() const { return static_cast(type2_); } + + const type1& type1_value() const { return *type1_; } + const type2& type2_value() const { return *type2_; } + + // Copying + basic_lambda_t(const basic_lambda_t& l) { + if (l.type1_) { + type1_.reset(new type1(*l.type1_)); + } else if (l.type2_) { + type2_.reset(new type2(*l.type2_)); + } + } + + string_type operator()(const string_type& text) const { + return (*type1_)(text); + } + + string_type operator()(const string_type& text, const basic_renderer& render) const { + return (*type2_)(text, render); + } + +private: + std::unique_ptr type1_; + std::unique_ptr type2_; +}; + +template +class basic_data; +template +using basic_object = std::unordered_map>; +template +using basic_list = std::vector>; +template +using basic_partial = std::function; +template +using basic_lambda = typename basic_lambda_t::type1; +template +using basic_lambda2 = typename basic_lambda_t::type2; + +template +class basic_data { +public: + enum class type { + object, + string, + list, + bool_true, + bool_false, + partial, + lambda, + lambda2, + invalid, + }; + + // Construction + basic_data() : basic_data(type::object) { + } + basic_data(const string_type& string) : type_{type::string} { + str_.reset(new string_type(string)); + } + basic_data(const typename string_type::value_type* string) : type_{type::string} { + str_.reset(new string_type(string)); + } + basic_data(const basic_object& obj) : type_{type::object} { + obj_.reset(new basic_object(obj)); + } + basic_data(const basic_list& l) : type_{type::list} { + list_.reset(new basic_list(l)); + } + basic_data(type t) : type_{t} { + switch (type_) { + case type::object: + obj_.reset(new basic_object); + break; + case type::string: + str_.reset(new string_type); + break; + case type::list: + list_.reset(new basic_list); + break; + default: + break; + } + } + basic_data(const string_type& name, const basic_data& var) : basic_data{} { + set(name, var); + } + basic_data(const basic_partial& p) : type_{type::partial} { + partial_.reset(new basic_partial(p)); + } + basic_data(const basic_lambda& l) : type_{type::lambda} { + lambda_.reset(new basic_lambda_t(l)); + } + basic_data(const basic_lambda2& l) : type_{type::lambda2} { + lambda_.reset(new basic_lambda_t(l)); + } + basic_data(const basic_lambda_t& l) { + if (l.is_type1()) { + type_ = type::lambda; + } else if (l.is_type2()) { + type_ = type::lambda2; + } + lambda_.reset(new basic_lambda_t(l)); + } + basic_data(bool b) : type_{b ? type::bool_true : type::bool_false} { + } + + // Copying + basic_data(const basic_data& dat) : type_(dat.type_) { + if (dat.obj_) { + obj_.reset(new basic_object(*dat.obj_)); + } else if (dat.str_) { + str_.reset(new string_type(*dat.str_)); + } else if (dat.list_) { + list_.reset(new basic_list(*dat.list_)); + } else if (dat.partial_) { + partial_.reset(new basic_partial(*dat.partial_)); + } else if (dat.lambda_) { + lambda_.reset(new basic_lambda_t(*dat.lambda_)); + } + } + + // Move + basic_data(basic_data&& dat) : type_{dat.type_} { + if (dat.obj_) { + obj_ = std::move(dat.obj_); + } else if (dat.str_) { + str_ = std::move(dat.str_); + } else if (dat.list_) { + list_ = std::move(dat.list_); + } else if (dat.partial_) { + partial_ = std::move(dat.partial_); + } else if (dat.lambda_) { + lambda_ = std::move(dat.lambda_); + } + dat.type_ = type::invalid; + } + basic_data& operator= (basic_data&& dat) { + if (this != &dat) { + obj_.reset(); + str_.reset(); + list_.reset(); + partial_.reset(); + lambda_.reset(); + if (dat.obj_) { + obj_ = std::move(dat.obj_); + } else if (dat.str_) { + str_ = std::move(dat.str_); + } else if (dat.list_) { + list_ = std::move(dat.list_); + } else if (dat.partial_) { + partial_ = std::move(dat.partial_); + } else if (dat.lambda_) { + lambda_ = std::move(dat.lambda_); + } + type_ = dat.type_; + dat.type_ = type::invalid; + } + return *this; + } + + // Type info + bool is_object() const { + return type_ == type::object; + } + bool is_string() const { + return type_ == type::string; + } + bool is_list() const { + return type_ == type::list; + } + bool is_bool() const { + return is_true() || is_false(); + } + bool is_true() const { + return type_ == type::bool_true; + } + bool is_false() const { + return type_ == type::bool_false; + } + bool is_partial() const { + return type_ == type::partial; + } + bool is_lambda() const { + return type_ == type::lambda; + } + bool is_lambda2() const { + return type_ == type::lambda2; + } + bool is_invalid() const { + return type_ == type::invalid; + } + + // Object data + bool is_empty_object() const { + return is_object() && obj_->empty(); + } + bool is_non_empty_object() const { + return is_object() && !obj_->empty(); + } + void set(const string_type& name, const basic_data& var) { + if (is_object()) { + auto it = obj_->find(name); + if (it != obj_->end()) { + obj_->erase(it); + } + obj_->insert(std::pair{name, var}); + } + } + const basic_data* get(const string_type& name) const { + if (!is_object()) { + return nullptr; + } + const auto& it = obj_->find(name); + if (it == obj_->end()) { + return nullptr; + } + return &it->second; + } + + // List data + void push_back(const basic_data& var) { + if (is_list()) { + list_->push_back(var); + } + } + const basic_list& list_value() const { + return *list_; + } + bool is_empty_list() const { + return is_list() && list_->empty(); + } + bool is_non_empty_list() const { + return is_list() && !list_->empty(); + } + basic_data& operator<< (const basic_data& data) { + push_back(data); + return *this; + } + + // String data + const string_type& string_value() const { + return *str_; + } + + basic_data& operator[] (const string_type& key) { + return (*obj_)[key]; + } + + const basic_partial& partial_value() const { + return (*partial_); + } + + const basic_lambda& lambda_value() const { + return lambda_->type1_value(); + } + + const basic_lambda2& lambda2_value() const { + return lambda_->type2_value(); + } + +private: + type type_; + std::unique_ptr> obj_; + std::unique_ptr str_; + std::unique_ptr> list_; + std::unique_ptr> partial_; + std::unique_ptr> lambda_; +}; + +template +class delimiter_set { +public: + string_type begin; + string_type end; + delimiter_set() + : begin(default_begin) + , end(default_end) + {} + bool is_default() const { return begin == default_begin && end == default_end; } + static const string_type default_begin; + static const string_type default_end; +}; + +template +const string_type delimiter_set::default_begin(2, '{'); +template +const string_type delimiter_set::default_end(2, '}'); + +template +class basic_context { +public: + virtual ~basic_context() = default; + virtual void push(const basic_data* data) = 0; + virtual void pop() = 0; + + virtual const basic_data* get(const string_type& name) const = 0; + virtual const basic_data* get_partial(const string_type& name) const = 0; +}; + +template +class context : public basic_context { +public: + context(const basic_data* data) { + push(data); + } + + context() { + } + + virtual void push(const basic_data* data) override { + items_.insert(items_.begin(), data); + } + + virtual void pop() override { + items_.erase(items_.begin()); + } + + virtual const basic_data* get(const string_type& name) const override { + // process {{.}} name + if (name.size() == 1 && name.at(0) == '.') { + return items_.front(); + } + if (name.find('.') == string_type::npos) { + // process normal name without having to split which is slower + for (const auto& item : items_) { + const auto var = item->get(name); + if (var) { + return var; + } + } + return nullptr; + } + // process x.y-like name + const auto names = split(name, '.'); + for (const auto& item : items_) { + auto var = item; + for (const auto& n : names) { + var = var->get(n); + if (!var) { + break; + } + } + if (var) { + return var; + } + } + return nullptr; + } + + virtual const basic_data* get_partial(const string_type& name) const override { + for (const auto& item : items_) { + const auto var = item->get(name); + if (var) { + return var; + } + } + return nullptr; + } + + context(const context&) = delete; + context& operator= (const context&) = delete; + +private: + std::vector*> items_; +}; + +template +class line_buffer_state { +public: + string_type data; + bool contained_section_tag = false; + + bool is_empty_or_contains_only_whitespace() const { + for (const auto ch : data) { + // don't look at newlines + if (ch != ' ' && ch != '\t') { + return false; + } + } + return true; + } + + void clear() { + data.clear(); + contained_section_tag = false; + } +}; + +template +class context_internal { +public: + basic_context& ctx; + delimiter_set delim_set; + line_buffer_state line_buffer; + + context_internal(basic_context& a_ctx) + : ctx(a_ctx) + { + } +}; + +enum class tag_type { + text, + variable, + unescaped_variable, + section_begin, + section_end, + section_begin_inverted, + comment, + partial, + set_delimiter, +}; + +template +class mstch_tag /* gcc doesn't allow "tag tag;" so rename the class :( */ { +public: + string_type name; + tag_type type = tag_type::text; + std::shared_ptr section_text; + std::shared_ptr> delim_set; + bool is_section_begin() const { + return type == tag_type::section_begin || type == tag_type::section_begin_inverted; + } + bool is_section_end() const { + return type == tag_type::section_end; + } +}; + +template +class context_pusher { +public: + context_pusher(context_internal& ctx, const basic_data* data) + : ctx_(ctx) + { + ctx.ctx.push(data); + } + ~context_pusher() { + ctx_.ctx.pop(); + } + context_pusher(const context_pusher&) = delete; + context_pusher& operator= (const context_pusher&) = delete; +private: + context_internal& ctx_; +}; + +template +class component { +private: + using string_size_type = typename string_type::size_type; + +public: + string_type text; + mstch_tag tag; + std::vector children; + string_size_type position = string_type::npos; + + enum class walk_control { + walk, // "continue" is reserved :/ + stop, + skip, + }; + using walk_callback = std::function; + + component() {} + component(const string_type& t, string_size_type p) : text(t), position(p) {} + + bool is_text() const { + return tag.type == tag_type::text; + } + + bool is_newline() const { + return is_text() && ((text.size() == 2 && text[0] == '\r' && text[1] == '\n') || + (text.size() == 1 && (text[0] == '\n' || text[0] == '\r'))); + } + + bool is_non_newline_whitespace() const { + return is_text() && !is_newline() && text.size() == 1 && (text[0] == ' ' || text[0] == '\t'); + } + + void walk_children(const walk_callback& callback) { + for (auto& child : children) { + if (child.walk(callback) != walk_control::walk) { + break; + } + } + } + +private: + walk_control walk(const walk_callback& callback) { + walk_control control{callback(*this)}; + if (control == walk_control::stop) { + return control; + } else if (control == walk_control::skip) { + return walk_control::walk; + } + for (auto& child : children) { + control = child.walk(callback); + if (control == walk_control::stop) { + return control; + } + } + return control; + } +}; + +template +class parser { +public: + parser(const string_type& input, context_internal& ctx, component& root_component, string_type& error_message) + { + parse(input, ctx, root_component, error_message); + } + +private: + void parse(const string_type& input, context_internal& ctx, component& root_component, string_type& error_message) const { + using string_size_type = typename string_type::size_type; + using streamstring = std::basic_ostringstream; + + const string_type brace_delimiter_end_unescaped(3, '}'); + const string_size_type input_size{input.size()}; + + bool current_delimiter_is_brace{ctx.delim_set.is_default()}; + + std::vector*> sections{&root_component}; + std::vector section_starts; + string_type current_text; + string_size_type current_text_position = -1; + + current_text.reserve(input_size); + + const auto process_current_text = [¤t_text, ¤t_text_position, §ions]() { + if (!current_text.empty()) { + const component comp{current_text, current_text_position}; + sections.back()->children.push_back(comp); + current_text.clear(); + current_text_position = -1; + } + }; + + const std::vector whitespace{ + string_type(1, '\r') + string_type(1, '\n'), + string_type(1, '\n'), + string_type(1, '\r'), + string_type(1, ' '), + string_type(1, '\t'), + }; + + for (string_size_type input_position = 0; input_position != input_size;) { + bool parse_tag = false; + + if (input.compare(input_position, ctx.delim_set.begin.size(), ctx.delim_set.begin) == 0) { + process_current_text(); + + // Tag start delimiter + parse_tag = true; + } else { + bool parsed_whitespace = false; + for (const auto& whitespace_text : whitespace) { + if (input.compare(input_position, whitespace_text.size(), whitespace_text) == 0) { + process_current_text(); + + const component comp{whitespace_text, input_position}; + sections.back()->children.push_back(comp); + input_position += whitespace_text.size(); + + parsed_whitespace = true; + break; + } + } + + if (!parsed_whitespace) { + if (current_text.empty()) { + current_text_position = input_position; + } + current_text.append(1, input[input_position]); + input_position++; + } + } + + if (!parse_tag) { + continue; + } + + // Find the next tag start delimiter + const string_size_type tag_location_start = input_position; + + // Find the next tag end delimiter + string_size_type tag_contents_location{tag_location_start + ctx.delim_set.begin.size()}; + const bool tag_is_unescaped_var{current_delimiter_is_brace && tag_location_start != (input_size - 2) && input.at(tag_contents_location) == ctx.delim_set.begin.at(0)}; + const string_type& current_tag_delimiter_end{tag_is_unescaped_var ? brace_delimiter_end_unescaped : ctx.delim_set.end}; + const auto current_tag_delimiter_end_size = current_tag_delimiter_end.size(); + if (tag_is_unescaped_var) { + ++tag_contents_location; + } + const string_size_type tag_location_end{input.find(current_tag_delimiter_end, tag_contents_location)}; + if (tag_location_end == string_type::npos) { + streamstring ss; + ss << "Unclosed tag at " << tag_location_start; + error_message.assign(ss.str()); + return; + } + + // Parse tag + const string_type tag_contents{trim(string_type{input, tag_contents_location, tag_location_end - tag_contents_location})}; + component comp; + if (!tag_contents.empty() && tag_contents[0] == '=') { + if (!parse_set_delimiter_tag(tag_contents, ctx.delim_set)) { + streamstring ss; + ss << "Invalid set delimiter tag at " << tag_location_start; + error_message.assign(ss.str()); + return; + } + current_delimiter_is_brace = ctx.delim_set.is_default(); + comp.tag.type = tag_type::set_delimiter; + comp.tag.delim_set.reset(new delimiter_set(ctx.delim_set)); + } + if (comp.tag.type != tag_type::set_delimiter) { + parse_tag_contents(tag_is_unescaped_var, tag_contents, comp.tag); + } + comp.position = tag_location_start; + sections.back()->children.push_back(comp); + + // Start next search after this tag + input_position = tag_location_end + current_tag_delimiter_end_size; + + // Push or pop sections + if (comp.tag.is_section_begin()) { + sections.push_back(§ions.back()->children.back()); + section_starts.push_back(input_position); + } else if (comp.tag.is_section_end()) { + if (sections.size() == 1) { + streamstring ss; + ss << "Unopened section \"" << comp.tag.name << "\" at " << comp.position; + error_message.assign(ss.str()); + return; + } + sections.back()->tag.section_text.reset(new string_type(input.substr(section_starts.back(), tag_location_start - section_starts.back()))); + sections.pop_back(); + section_starts.pop_back(); + } + } + + process_current_text(); + + // Check for sections without an ending tag + root_component.walk_children([&error_message](component& comp) -> typename component::walk_control { + if (!comp.tag.is_section_begin()) { + return component::walk_control::walk; + } + if (comp.children.empty() || !comp.children.back().tag.is_section_end() || comp.children.back().tag.name != comp.tag.name) { + streamstring ss; + ss << "Unclosed section \"" << comp.tag.name << "\" at " << comp.position; + error_message.assign(ss.str()); + return component::walk_control::stop; + } + comp.children.pop_back(); // remove now useless end section component + return component::walk_control::walk; + }); + if (!error_message.empty()) { + return; + } + } + + bool is_set_delimiter_valid(const string_type& delimiter) const { + // "Custom delimiters may not contain whitespace or the equals sign." + for (const auto ch : delimiter) { + if (ch == '=' || std::isspace(ch)) { + return false; + } + } + return true; + } + + bool parse_set_delimiter_tag(const string_type& contents, delimiter_set& delimiter_set) const { + // Smallest legal tag is "=X X=" + if (contents.size() < 5) { + return false; + } + if (contents.back() != '=') { + return false; + } + const auto contents_substr = trim(contents.substr(1, contents.size() - 2)); + const auto spacepos = contents_substr.find(' '); + if (spacepos == string_type::npos) { + return false; + } + const auto nonspace = contents_substr.find_first_not_of(' ', spacepos + 1); + assert(nonspace != string_type::npos); + const string_type begin = contents_substr.substr(0, spacepos); + const string_type end = contents_substr.substr(nonspace, contents_substr.size() - nonspace); + if (!is_set_delimiter_valid(begin) || !is_set_delimiter_valid(end)) { + return false; + } + delimiter_set.begin = begin; + delimiter_set.end = end; + return true; + } + + void parse_tag_contents(bool is_unescaped_var, const string_type& contents, mstch_tag& tag) const { + if (is_unescaped_var) { + tag.type = tag_type::unescaped_variable; + tag.name = contents; + } else if (contents.empty()) { + tag.type = tag_type::variable; + tag.name.clear(); + } else { + switch (contents.at(0)) { + case '#': + tag.type = tag_type::section_begin; + break; + case '^': + tag.type = tag_type::section_begin_inverted; + break; + case '/': + tag.type = tag_type::section_end; + break; + case '>': + tag.type = tag_type::partial; + break; + case '&': + tag.type = tag_type::unescaped_variable; + break; + case '!': + tag.type = tag_type::comment; + break; + default: + tag.type = tag_type::variable; + break; + } + if (tag.type == tag_type::variable) { + tag.name = contents; + } else { + string_type name{contents}; + name.erase(name.begin()); + tag.name = trim(name); + } + } + } +}; + +template +class basic_mustache { +public: + using string_type = StringType; + + basic_mustache(const string_type& input) + : basic_mustache() { + context ctx; + context_internal context{ctx}; + parser parser{input, context, root_component_, error_message_}; + } + + bool is_valid() const { + return error_message_.empty(); + } + + const string_type& error_message() const { + return error_message_; + } + + using escape_handler = std::function; + void set_custom_escape(const escape_handler& escape_fn) { + escape_ = escape_fn; + } + + template + stream_type& render(const basic_data& data, stream_type& stream) { + render(data, [&stream](const string_type& str) { + stream << str; + }); + return stream; + } + + string_type render(const basic_data& data) { + std::basic_ostringstream ss; + return render(data, ss).str(); + } + + template + stream_type& render(basic_context& ctx, stream_type& stream) { + context_internal context{ctx}; + render([&stream](const string_type& str) { + stream << str; + }, context); + return stream; + } + + string_type render(basic_context& ctx) { + std::basic_ostringstream ss; + return render(ctx, ss).str(); + } + + using render_handler = std::function; + void render(const basic_data& data, const render_handler& handler) { + if (!is_valid()) { + return; + } + context ctx{&data}; + context_internal context{ctx}; + render(handler, context); + } + + basic_mustache() + : escape_(html_escape) + { + } + +private: + using string_size_type = typename string_type::size_type; + + + basic_mustache(const string_type& input, context_internal& ctx) + : basic_mustache() { + parser parser{input, ctx, root_component_, error_message_}; + } + + string_type render(context_internal& ctx) { + std::basic_ostringstream ss; + render([&ss](const string_type& str) { + ss << str; + }, ctx); + return ss.str(); + } + + void render(const render_handler& handler, context_internal& ctx, bool root_renderer = true) { + root_component_.walk_children([&handler, &ctx, this](component& comp) -> typename component::walk_control { + return render_component(handler, ctx, comp); + }); + // process the last line, but only for the top-level renderer + if (root_renderer) { + render_current_line(handler, ctx, nullptr); + } + } + + void render_current_line(const render_handler& handler, context_internal& ctx, const component* comp) const { + // We're at the end of a line, so check the line buffer state to see + // if the line had tags in it, and also if the line is now empty or + // contains whitespace only. if this situation is true, skip the line. + bool output = true; + if (ctx.line_buffer.contained_section_tag && ctx.line_buffer.is_empty_or_contains_only_whitespace()) { + output = false; + } + if (output) { + handler(ctx.line_buffer.data); + if (comp) { + handler(comp->text); + } + } + ctx.line_buffer.clear(); + } + + void render_result(context_internal& ctx, const string_type& text) const { + ctx.line_buffer.data.append(text); + } + + typename component::walk_control render_component(const render_handler& handler, context_internal& ctx, component& comp) { + if (comp.is_text()) { + if (comp.is_newline()) { + render_current_line(handler, ctx, &comp); + } else { + render_result(ctx, comp.text); + } + return component::walk_control::walk; + } + + const mstch_tag& tag{comp.tag}; + const basic_data* var = nullptr; + switch (tag.type) { + case tag_type::variable: + case tag_type::unescaped_variable: + if ((var = ctx.ctx.get(tag.name)) != nullptr) { + if (!render_variable(handler, var, ctx, tag.type == tag_type::variable)) { + return component::walk_control::stop; + } + } + break; + case tag_type::section_begin: + if ((var = ctx.ctx.get(tag.name)) != nullptr) { + if (var->is_lambda() || var->is_lambda2()) { + if (!render_lambda(handler, var, ctx, render_lambda_escape::optional, *comp.tag.section_text, true)) { + return component::walk_control::stop; + } + } else if (!var->is_false() && !var->is_empty_list()) { + render_section(handler, ctx, comp, var); + } + } + return component::walk_control::skip; + case tag_type::section_begin_inverted: + if ((var = ctx.ctx.get(tag.name)) == nullptr || var->is_false() || var->is_empty_list()) { + render_section(handler, ctx, comp, var); + } + return component::walk_control::skip; + case tag_type::partial: + if ((var = ctx.ctx.get_partial(tag.name)) != nullptr && (var->is_partial() || var->is_string())) { + const auto& partial_result = var->is_partial() ? var->partial_value()() : var->string_value(); + basic_mustache tmpl{partial_result}; + tmpl.set_custom_escape(escape_); + if (!tmpl.is_valid()) { + error_message_ = tmpl.error_message(); + } else { + tmpl.render(handler, ctx, false); + if (!tmpl.is_valid()) { + error_message_ = tmpl.error_message(); + } + } + if (!tmpl.is_valid()) { + return component::walk_control::stop; + } + } + break; + case tag_type::set_delimiter: + ctx.delim_set = *comp.tag.delim_set; + break; + default: + break; + } + + return component::walk_control::walk; + } + + enum class render_lambda_escape { + escape, + unescape, + optional, + }; + + bool render_lambda(const render_handler& handler, const basic_data* var, context_internal& ctx, render_lambda_escape escape, const string_type& text, bool parse_with_same_context) { + const typename basic_renderer::type2 render2 = [this, &ctx, parse_with_same_context, escape](const string_type& text, bool escaped) { + const auto process_template = [this, &ctx, escape, escaped](basic_mustache& tmpl) -> string_type { + if (!tmpl.is_valid()) { + error_message_ = tmpl.error_message(); + return {}; + } + context_internal render_ctx{ctx.ctx}; // start a new line_buffer + const auto str = tmpl.render(render_ctx); + if (!tmpl.is_valid()) { + error_message_ = tmpl.error_message(); + return {}; + } + bool do_escape = false; + switch (escape) { + case render_lambda_escape::escape: + do_escape = true; + break; + case render_lambda_escape::unescape: + do_escape = false; + break; + case render_lambda_escape::optional: + do_escape = escaped; + break; + } + return do_escape ? escape_(str) : str; + }; + if (parse_with_same_context) { + basic_mustache tmpl{text, ctx}; + tmpl.set_custom_escape(escape_); + return process_template(tmpl); + } + basic_mustache tmpl{text}; + tmpl.set_custom_escape(escape_); + return process_template(tmpl); + }; + const typename basic_renderer::type1 render = [&render2](const string_type& text) { + return render2(text, false); + }; + if (var->is_lambda2()) { + const basic_renderer renderer{render, render2}; + render_result(ctx, var->lambda2_value()(text, renderer)); + } else { + render_current_line(handler, ctx, nullptr); + render_result(ctx, render(var->lambda_value()(text))); + } + return error_message_.empty(); + } + + bool render_variable(const render_handler& handler, const basic_data* var, context_internal& ctx, bool escaped) { + if (var->is_string()) { + const auto& varstr = var->string_value(); + render_result(ctx, escaped ? escape_(varstr) : varstr); + } else if (var->is_lambda()) { + const render_lambda_escape escape_opt = escaped ? render_lambda_escape::escape : render_lambda_escape::unescape; + return render_lambda(handler, var, ctx, escape_opt, {}, false); + } else if (var->is_lambda2()) { + using streamstring = std::basic_ostringstream; + streamstring ss; + ss << "Lambda with render argument is not allowed for regular variables"; + error_message_ = ss.str(); + return false; + } + return true; + } + + void render_section(const render_handler& handler, context_internal& ctx, component& incomp, const basic_data* var) { + const auto callback = [&handler, &ctx, this](component& comp) -> typename component::walk_control { + return render_component(handler, ctx, comp); + }; + if (var && var->is_non_empty_list()) { + for (const auto& item : var->list_value()) { + // account for the section begin tag + ctx.line_buffer.contained_section_tag = true; + + const context_pusher ctxpusher{ctx, &item}; + incomp.walk_children(callback); + + // ctx may have been cleared. account for the section end tag + ctx.line_buffer.contained_section_tag = true; + } + } else if (var) { + // account for the section begin tag + ctx.line_buffer.contained_section_tag = true; + + const context_pusher ctxpusher{ctx, var}; + incomp.walk_children(callback); + + // ctx may have been cleared. account for the section end tag + ctx.line_buffer.contained_section_tag = true; + } else { + // account for the section begin tag + ctx.line_buffer.contained_section_tag = true; + + incomp.walk_children(callback); + + // ctx may have been cleared. account for the section end tag + ctx.line_buffer.contained_section_tag = true; + } + } + +private: + string_type error_message_; + component root_component_; + escape_handler escape_; +}; + +using mustache = basic_mustache; +using data = basic_data; +using object = basic_object; +using list = basic_list; +using partial = basic_partial; +using renderer = basic_renderer; +using lambda = basic_lambda; +using lambda2 = basic_lambda2; +using lambda_t = basic_lambda_t; + +using mustachew = basic_mustache; +using dataw = basic_data; + +} // namespace mustache +} // namespace kainjow + +#endif // KAINJOW_MUSTACHE_HPP diff --git a/engine/source/meta_parser/CMakeLists.txt b/engine/source/meta_parser/CMakeLists.txt new file mode 100644 index 000000000..520c87b92 --- /dev/null +++ b/engine/source/meta_parser/CMakeLists.txt @@ -0,0 +1,59 @@ +#cmake_policy(SET CMP0074 OLD) +set(TARGET_NAME PiccoloParser) + +#set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../CMake") + +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +file(GLOB_RECURSE HEADERS "*.h") +file(GLOB_RECURSE SOURCES "*.cpp") + +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${HEADERS} ${SOURCES}) + + +set(LLVM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/LLVM/include ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/mustache ${CMAKE_CURRENT_SOURCE_DIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${ENGINE_ROOT_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${ENGINE_ROOT_DIR}/bin) +# add LLVM includes +include_directories(${LLVM_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/parser) + +# header files are superflous, but some IDEs (Visual Studio) don't include +# them in the solution explorer without them being added to the list of sources +add_executable(${TARGET_NAME} ${HEADERS} ${SOURCES}) + +#set_target_properties(meta_parser PROPERTIES FOLDER "generator" ) + +set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD 17) +set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tools") + +if (CMAKE_HOST_WIN32) + set(LLVM_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/LLVM/lib/x64) + set(LLVM_SHARED_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/LLVM/bin/x64) + set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} /O2 /Ob2") + target_link_libraries(${TARGET_NAME} ${LLVM_LIBRARY_DIR}/libclang.lib) +elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux") + set(LLVM_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/LLVM/lib/Linux) + set(LLVM_SHARED_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/LLVM/bin/Linux) + set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O3") + target_link_libraries(${TARGET_NAME} ${LLVM_SHARED_LIBRARY_DIR}/libclang.so.12) +else() + set(LLVM_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/LLVM/lib/macOS) + set(LLVM_SHARED_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/LLVM/bin/macOS) + set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O3") + target_link_libraries(${TARGET_NAME} ${LLVM_SHARED_LIBRARY_DIR}/libclang.dylib) +endif() + +#link_directories(${LLVM_LIBRARY_DIR}) + +# statically link with Boost & LibClang + +add_definitions(-DTIXML_USE_STL) + +# copy resources on post build +add_custom_command(TARGET ${TARGET_NAME} POST_BUILD + # mustache templates directory + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${LLVM_SHARED_LIBRARY_DIR}" + $ +) + diff --git a/engine/source/meta_parser/README.md b/engine/source/meta_parser/README.md new file mode 100644 index 000000000..be7f348f3 --- /dev/null +++ b/engine/source/meta_parser/README.md @@ -0,0 +1,3 @@ +## Copyright Notice + +Part of the codes in `engine/source/metaParser/Parser` is derived from [CPP-Reflection](https://github.com/AustinBrunkHorst/CPP-Reflection) Copyright (c) 2016 Austin BrunkHorst diff --git a/engine/source/meta_parser/parser/common/namespace.h b/engine/source/meta_parser/parser/common/namespace.h new file mode 100644 index 000000000..20e41bd48 --- /dev/null +++ b/engine/source/meta_parser/parser/common/namespace.h @@ -0,0 +1,6 @@ +#pragma once + +#include +#include + +typedef std::vector Namespace; diff --git a/engine/source/meta_parser/parser/common/precompiled.h b/engine/source/meta_parser/parser/common/precompiled.h new file mode 100644 index 000000000..57ed98fe8 --- /dev/null +++ b/engine/source/meta_parser/parser/common/precompiled.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace fs = std::filesystem; + +#include "meta/meta_data_config.h" +#include "meta/meta_utils.h" + +#include "mustache.hpp" + +namespace Mustache = kainjow::mustache; diff --git a/engine/source/meta_parser/parser/common/schema_module.h b/engine/source/meta_parser/parser/common/schema_module.h new file mode 100644 index 000000000..984eb42db --- /dev/null +++ b/engine/source/meta_parser/parser/common/schema_module.h @@ -0,0 +1,14 @@ +#pragma once +#include "precompiled.h" + +class Class; +class Global; +class Function; +class Enum; + +struct SchemaMoudle +{ + std::string name; + + std::vector> classes; +}; \ No newline at end of file diff --git a/engine/source/meta_parser/parser/cursor/cursor.cpp b/engine/source/meta_parser/parser/cursor/cursor.cpp new file mode 100644 index 000000000..7d9dd18df --- /dev/null +++ b/engine/source/meta_parser/parser/cursor/cursor.cpp @@ -0,0 +1,70 @@ +#include "common/precompiled.h" +#include "meta/meta_utils.h" + +#include "cursor.h" + +Cursor::Cursor(const CXCursor& handle) : m_handle(handle) {} + +CXCursorKind Cursor::getKind(void) const { return m_handle.kind; } + +std::string Cursor::getSpelling(void) const +{ + std::string spelling; + + Utils::toString(clang_getCursorSpelling(m_handle), spelling); + + return spelling; +} + +std::string Cursor::getDisplayName(void) const +{ + std::string display_name; + + Utils::toString(clang_getCursorDisplayName(m_handle), display_name); + + return display_name; +} + +std::string Cursor::getSourceFile(void) const +{ + auto range = clang_Cursor_getSpellingNameRange(m_handle, 0, 0); + + auto start = clang_getRangeStart(range); + + CXFile file; + unsigned line, column, offset; + + clang_getFileLocation(start, &file, &line, &column, &offset); + + std::string filename; + + Utils::toString(clang_getFileName(file), filename); + + return filename; +} + +bool Cursor::isDefinition(void) const { return clang_isCursorDefinition(m_handle); } + +CursorType Cursor::getType(void) const { return clang_getCursorType(m_handle); } + +Cursor::List Cursor::getChildren(void) const +{ + List children; + + auto visitor = [](CXCursor cursor, CXCursor parent, CXClientData data) { + auto container = static_cast(data); + + container->emplace_back(cursor); + + if (cursor.kind == CXCursor_LastPreprocessing) + return CXChildVisit_Break; + + return CXChildVisit_Continue; + }; + + clang_visitChildren(m_handle, visitor, &children); + + return children; +} + +void Cursor::visitChildren(Visitor visitor, void* data) { clang_visitChildren(m_handle, visitor, data); } diff --git a/engine/source/meta_parser/parser/cursor/cursor.h b/engine/source/meta_parser/parser/cursor/cursor.h new file mode 100644 index 000000000..57b235ffe --- /dev/null +++ b/engine/source/meta_parser/parser/cursor/cursor.h @@ -0,0 +1,30 @@ +#pragma once + +#include "cursor_type.h" + +class Cursor +{ +public: + typedef std::vector List; + + typedef CXCursorVisitor Visitor; + + Cursor(const CXCursor& handle); + + CXCursorKind getKind(void) const; + + std::string getSpelling(void) const; + std::string getDisplayName(void) const; + + std::string getSourceFile(void) const; + + bool isDefinition(void) const; + + CursorType getType(void) const; + + List getChildren(void) const; + void visitChildren(Visitor visitor, void* data = nullptr); + +private: + CXCursor m_handle; +}; \ No newline at end of file diff --git a/engine/source/meta_parser/parser/cursor/cursor_type.cpp b/engine/source/meta_parser/parser/cursor/cursor_type.cpp new file mode 100644 index 000000000..75092b648 --- /dev/null +++ b/engine/source/meta_parser/parser/cursor/cursor_type.cpp @@ -0,0 +1,27 @@ +#include "common/precompiled.h" + +#include "cursor.h" +#include "cursor_type.h" + +CursorType::CursorType(const CXType& handle) : m_handle(handle) {} + +std::string CursorType::GetDisplayName(void) const +{ + std::string display_name; + + Utils::toString(clang_getTypeSpelling(m_handle), display_name); + + return display_name; +} + +int CursorType::GetArgumentCount(void) const { return clang_getNumArgTypes(m_handle); } + +CursorType CursorType::GetArgument(unsigned index) const { return clang_getArgType(m_handle, index); } + +CursorType CursorType::GetCanonicalType(void) const { return clang_getCanonicalType(m_handle); } + +Cursor CursorType::GetDeclaration(void) const { return clang_getTypeDeclaration(m_handle); } + +CXTypeKind CursorType::GetKind(void) const { return m_handle.kind; } + +bool CursorType::IsConst(void) const { return clang_isConstQualifiedType(m_handle) ? true : false; } \ No newline at end of file diff --git a/engine/source/meta_parser/parser/cursor/cursor_type.h b/engine/source/meta_parser/parser/cursor/cursor_type.h new file mode 100644 index 000000000..262c52725 --- /dev/null +++ b/engine/source/meta_parser/parser/cursor/cursor_type.h @@ -0,0 +1,26 @@ +#pragma once + +class Cursor; + +class CursorType +{ +public: + CursorType(const CXType& handle); + + std::string GetDisplayName(void) const; + + int GetArgumentCount(void) const; + + CursorType GetArgument(unsigned index) const; + + CursorType GetCanonicalType(void) const; + + Cursor GetDeclaration(void) const; + + CXTypeKind GetKind(void) const; + + bool IsConst(void) const; + +private: + CXType m_handle; +}; \ No newline at end of file diff --git a/engine/source/meta_parser/parser/generator/generator.cpp b/engine/source/meta_parser/parser/generator/generator.cpp new file mode 100644 index 000000000..e7d62035b --- /dev/null +++ b/engine/source/meta_parser/parser/generator/generator.cpp @@ -0,0 +1,57 @@ +#include "common/precompiled.h" + +#include "generator/generator.h" +#include "language_types/class.h" + +namespace Generator +{ + void GeneratorInterface::prepareStatus(std::string path) + { + if (!fs::exists(path)) + { + fs::create_directories(path); + } + } + void GeneratorInterface::genClassRenderData(std::shared_ptr class_temp, Mustache::data& class_def) + { + class_def.set("class_name", class_temp->getClassName()); + class_def.set("class_base_class_size", std::to_string(class_temp->m_base_classes.size())); + class_def.set("class_need_register", true); + + if (class_temp->m_base_classes.size() > 0) + { + Mustache::data class_base_class_defines(Mustache::data::type::list); + class_def.set("class_has_base", true); + for (int index = 0; index < class_temp->m_base_classes.size(); ++index) + { + Mustache::data class_base_class_def; + class_base_class_def.set("class_base_class_name", class_temp->m_base_classes[index]->name); + class_base_class_def.set("class_base_class_index", std::to_string(index)); + class_base_class_defines.push_back(class_base_class_def); + } + class_def.set("class_base_class_defines", class_base_class_defines); + } + + Mustache::data class_field_defines = Mustache::data::type::list; + genClassFieldRenderData(class_temp, class_field_defines); + class_def.set("class_field_defines", class_field_defines); + } + void GeneratorInterface::genClassFieldRenderData(std::shared_ptr class_temp, Mustache::data& feild_defs) + { + static const std::string vector_prefix = "std::vector<"; + + for (auto& field : class_temp->m_fields) + { + if (!field->shouldCompile()) + continue; + Mustache::data filed_define; + + filed_define.set("class_field_name", field->m_name); + filed_define.set("class_field_type", field->m_type); + filed_define.set("class_field_display_name", field->m_display_name); + bool is_vector = field->m_type.find(vector_prefix) == 0; + filed_define.set("class_field_is_vector", is_vector); + feild_defs.push_back(filed_define); + } + } +} // namespace Generator diff --git a/engine/source/meta_parser/parser/generator/generator.h b/engine/source/meta_parser/parser/generator/generator.h new file mode 100644 index 000000000..40ba9e5a8 --- /dev/null +++ b/engine/source/meta_parser/parser/generator/generator.h @@ -0,0 +1,32 @@ +#pragma once +#include "common/schema_module.h" + +#include +#include +namespace Generator +{ + class GeneratorInterface + { + public: + GeneratorInterface(std::string out_path, + std::string root_path, + std::function get_include_func) : + m_out_path(out_path), + m_root_path(root_path), m_get_include_func(get_include_func) + {} + virtual int generate(std::string path, SchemaMoudle schema) = 0; + virtual void finish() {}; + + virtual ~GeneratorInterface() {}; + + protected: + virtual void prepareStatus(std::string path); + virtual void genClassRenderData(std::shared_ptr class_temp, Mustache::data& class_def); + virtual void genClassFieldRenderData(std::shared_ptr class_temp, Mustache::data& feild_defs); + virtual std::string processFileName(std::string path) = 0; + + std::string m_out_path {"gen_src"}; + std::string m_root_path; + std::function m_get_include_func; + }; +} // namespace Generator diff --git a/engine/source/meta_parser/parser/generator/reflection_generator.cpp b/engine/source/meta_parser/parser/generator/reflection_generator.cpp new file mode 100644 index 000000000..771c96e88 --- /dev/null +++ b/engine/source/meta_parser/parser/generator/reflection_generator.cpp @@ -0,0 +1,138 @@ +#include "common/precompiled.h" + +#include "generator/reflection_generator.h" + +#include "language_types/class.h" +#include "template_manager/template_manager.h" + +#include +#include + +namespace Generator +{ + ReflectionGenerator::ReflectionGenerator(std::string source_directory, + std::function get_include_function) : + GeneratorInterface(source_directory + "/_generated/reflection", source_directory, get_include_function) + { + prepareStatus(m_out_path); + } + void ReflectionGenerator::prepareStatus(std::string path) + { + GeneratorInterface::prepareStatus(path); + TemplateManager::getInstance()->loadTemplates(m_root_path, "commonReflectionFile"); + TemplateManager::getInstance()->loadTemplates(m_root_path, "allReflectionFile"); + return; + } + + std::string ReflectionGenerator::processFileName(std::string path) + { + auto relativeDir = fs::path(path).filename().replace_extension("reflection.gen.h").string(); + return m_out_path + "/" + relativeDir; + } + int ReflectionGenerator::generate(std::string path, SchemaMoudle schema) + { + static const std::string vector_prefix = "std::vector<"; + + std::string file_path = processFileName(path); + Mustache::data mustache_data; + Mustache::data include_headfiles(Mustache::data::type::list); + Mustache::data class_defines(Mustache::data::type::list); + + include_headfiles.push_back( + Mustache::data("headfile_name", Utils::makeRelativePath(m_root_path, path).string())); + + std::map class_names; + // class defs + for (auto class_temp : schema.classes) + { + if (!class_temp->shouldCompileFilds()) + continue; + + class_names.insert_or_assign(class_temp->getClassName(), false); + class_names[class_temp->getClassName()] = true; + + std::vector field_names; + std::map> vector_map; + + Mustache::data class_def; + Mustache::data vector_defines(Mustache::data::type::list); + + genClassRenderData(class_temp, class_def); + for (auto field : class_temp->m_fields) + { + if (!field->shouldCompile()) + continue; + field_names.emplace_back(field->m_name); + bool is_array = field->m_type.find(vector_prefix) == 0; + if (is_array) + { + std::string array_useful_name = field->m_type; + + Utils::formatQualifiedName(array_useful_name); + + std::string item_type = field->m_type; + + item_type = Utils::getNameWithoutContainer(item_type); + + vector_map[field->m_type] = std::make_pair(array_useful_name, item_type); + } + } + + if (vector_map.size() > 0) + { + if (nullptr == class_def.get("vector_exist")) + { + class_def.set("vector_exist", true); + } + for (auto vector_item : vector_map) + { + std::string array_useful_name = vector_item.second.first; + std::string item_type = vector_item.second.second; + Mustache::data vector_define; + vector_define.set("vector_useful_name", array_useful_name); + vector_define.set("vector_type_name", vector_item.first); + vector_define.set("vector_element_type_name", item_type); + vector_defines.push_back(vector_define); + } + } + class_def.set("vector_defines", vector_defines); + class_defines.push_back(class_def); + } + + mustache_data.set("class_defines", class_defines); + mustache_data.set("include_headfiles", include_headfiles); + std::string render_string = + TemplateManager::getInstance()->renderByTemplate("commonReflectionFile", mustache_data); + Utils::saveFile(render_string, file_path); + + for (auto class_item : class_names) + { + m_type_list.emplace_back(class_item.first); + } + + m_head_file_list.emplace_back(Utils::makeRelativePath(m_root_path, file_path).string()); + return 0; + } + void ReflectionGenerator::finish() + { + Mustache::data mustache_data; + Mustache::data include_headfiles = Mustache::data::type::list; + Mustache::data class_defines = Mustache::data::type::list; + + for (auto& head_file : m_head_file_list) + { + include_headfiles.push_back(Mustache::data("headfile_name", head_file)); + } + for (auto& class_name : m_type_list) + { + class_defines.push_back(Mustache::data("class_name", class_name)); + } + mustache_data.set("include_headfiles", include_headfiles); + mustache_data.set("class_defines", class_defines); + std::string render_string = + TemplateManager::getInstance()->renderByTemplate("allReflectionFile", mustache_data); + Utils::saveFile(render_string, m_out_path + "/all_reflection.h"); + } + + ReflectionGenerator::~ReflectionGenerator() {} +} // namespace Generator \ No newline at end of file diff --git a/engine/source/meta_parser/parser/generator/reflection_generator.h b/engine/source/meta_parser/parser/generator/reflection_generator.h new file mode 100644 index 000000000..7dd256713 --- /dev/null +++ b/engine/source/meta_parser/parser/generator/reflection_generator.h @@ -0,0 +1,22 @@ +#pragma once +#include "generator/generator.h" +namespace Generator +{ + class ReflectionGenerator : public GeneratorInterface + { + public: + ReflectionGenerator() = delete; + ReflectionGenerator(std::string source_directory, std::function get_include_function); + virtual int generate(std::string path, SchemaMoudle schema) override; + virtual void finish() override; + virtual ~ReflectionGenerator() override; + + protected: + virtual void prepareStatus(std::string path) override; + virtual std::string processFileName(std::string path) override; + + private: + std::vector m_head_file_list; + std::vector m_type_list; + }; +} // namespace Generator diff --git a/engine/source/meta_parser/parser/generator/serializer_generator.cpp b/engine/source/meta_parser/parser/generator/serializer_generator.cpp new file mode 100644 index 000000000..3019c2aa8 --- /dev/null +++ b/engine/source/meta_parser/parser/generator/serializer_generator.cpp @@ -0,0 +1,108 @@ +#include "generator/serializer_generator.h" +#include "common/precompiled.h" +#include "language_types/class.h" + +namespace Generator +{ + SerializerGenerator::SerializerGenerator(std::string source_directory, + std::function get_include_function) : + GeneratorInterface(source_directory + "/_generated/serializer", source_directory, get_include_function) + { + prepareStatus(m_out_path); + } + + void SerializerGenerator::prepareStatus(std::string path) + { + GeneratorInterface::prepareStatus(path); + TemplateManager::getInstance()->loadTemplates(m_root_path, "allSerializer.h"); + TemplateManager::getInstance()->loadTemplates(m_root_path, "allSerializer.ipp"); + TemplateManager::getInstance()->loadTemplates(m_root_path, "commonSerializerGenFile"); + return; + } + + std::string SerializerGenerator::processFileName(std::string path) + { + auto relativeDir = fs::path(path).filename().replace_extension("serializer.gen.h").string(); + return m_out_path + "/" + relativeDir; + } + int SerializerGenerator::generate(std::string path, SchemaMoudle schema) + { + std::string file_path = processFileName(path); + + Mustache::data muatache_data; + Mustache::data include_headfiles(Mustache::data::type::list); + Mustache::data class_defines(Mustache::data::type::list); + + include_headfiles.push_back( + Mustache::data("headfile_name", Utils::makeRelativePath(m_root_path, path).string())); + for (auto class_temp : schema.classes) + { + if (!class_temp->shouldCompileFilds()) + continue; + + Mustache::data class_def; + genClassRenderData(class_temp, class_def); + + // deal base class + for (int index = 0; index < class_temp->m_base_classes.size(); ++index) + { + auto include_file = m_get_include_func(class_temp->m_base_classes[index]->name); + if (!include_file.empty()) + { + auto include_file_base = processFileName(include_file); + if (file_path != include_file_base) + { + include_headfiles.push_back(Mustache::data( + "headfile_name", Utils::makeRelativePath(m_root_path, include_file_base).string())); + } + } + } + for (auto field : class_temp->m_fields) + { + if (!field->shouldCompile()) + continue; + // deal vector + if (field->m_type.find("std::vector") == 0) + { + auto include_file = m_get_include_func(field->m_name); + if (!include_file.empty()) + { + auto include_file_base = processFileName(include_file); + if (file_path != include_file_base) + { + include_headfiles.push_back(Mustache::data( + "headfile_name", Utils::makeRelativePath(m_root_path, include_file_base).string())); + } + } + } + // deal normal + } + class_defines.push_back(class_def); + m_class_defines.push_back(class_def); + } + + muatache_data.set("class_defines", class_defines); + muatache_data.set("include_headfiles", include_headfiles); + std::string render_string = + TemplateManager::getInstance()->renderByTemplate("commonSerializerGenFile", muatache_data); + Utils::saveFile(render_string, file_path); + + m_include_headfiles.push_back( + Mustache::data("headfile_name", Utils::makeRelativePath(m_root_path, file_path).string())); + return 0; + } + + void SerializerGenerator::finish() + { + Mustache::data mustache_data; + mustache_data.set("class_defines", m_class_defines); + mustache_data.set("include_headfiles", m_include_headfiles); + + std::string render_string = TemplateManager::getInstance()->renderByTemplate("allSerializer.h", mustache_data); + Utils::saveFile(render_string, m_out_path + "/all_serializer.h"); + render_string = TemplateManager::getInstance()->renderByTemplate("allSerializer.ipp", mustache_data); + Utils::saveFile(render_string, m_out_path + "/all_serializer.ipp"); + } + + SerializerGenerator::~SerializerGenerator() {} +} // namespace Generator diff --git a/engine/source/meta_parser/parser/generator/serializer_generator.h b/engine/source/meta_parser/parser/generator/serializer_generator.h new file mode 100644 index 000000000..206f7bb81 --- /dev/null +++ b/engine/source/meta_parser/parser/generator/serializer_generator.h @@ -0,0 +1,26 @@ +#pragma once +#include "generator/generator.h" +namespace Generator +{ + class SerializerGenerator : public GeneratorInterface + { + public: + SerializerGenerator() = delete; + SerializerGenerator(std::string source_directory, std::function get_include_function); + + virtual int generate(std::string path, SchemaMoudle schema) override; + + virtual void finish() override; + + virtual ~SerializerGenerator() override; + + protected: + virtual void prepareStatus(std::string path) override; + + virtual std::string processFileName(std::string path) override; + + private: + Mustache::data m_class_defines {Mustache::data::type::list}; + Mustache::data m_include_headfiles {Mustache::data::type::list}; + }; +} // namespace Generator diff --git a/engine/source/meta_parser/parser/language_types/class.cpp b/engine/source/meta_parser/parser/language_types/class.cpp new file mode 100644 index 000000000..59a18c745 --- /dev/null +++ b/engine/source/meta_parser/parser/language_types/class.cpp @@ -0,0 +1,45 @@ +#include "common/precompiled.h" + +#include "class.h" + +BaseClass::BaseClass(const Cursor& cursor) : name(Utils::getTypeNameWithoutNamespace(cursor.getType())) {} + +Class::Class(const Cursor& cursor, const Namespace& current_namespace) : + TypeInfo(cursor, current_namespace), m_name(cursor.getDisplayName()), + m_qualified_name(Utils::getTypeNameWithoutNamespace(cursor.getType())), + m_display_name(Utils::getNameWithoutFirstM(m_qualified_name)) +{ + Utils::replaceAll(m_name, " ", ""); + Utils::replaceAll(m_name, "Piccolo::", ""); + + for (auto& child : cursor.getChildren()) + { + switch (child.getKind()) + { + case CXCursor_CXXBaseSpecifier: { + auto base_class = new BaseClass(child); + + m_base_classes.emplace_back(base_class); + } + break; + // field + case CXCursor_FieldDecl: + m_fields.emplace_back(new Field(child, current_namespace, this)); + break; + default: + break; + } + } +} + +bool Class::shouldCompile(void) const { return shouldCompileFilds(); } + +bool Class::shouldCompileFilds(void) const +{ + return m_meta_data.getFlag(NativeProperty::All) || m_meta_data.getFlag(NativeProperty::Fields) || + m_meta_data.getFlag(NativeProperty::WhiteListFields); +} + +std::string Class::getClassName(void) { return m_name; } + +bool Class::isAccessible(void) const { return m_enabled; } \ No newline at end of file diff --git a/engine/source/meta_parser/parser/language_types/class.h b/engine/source/meta_parser/parser/language_types/class.h new file mode 100644 index 000000000..c2902002e --- /dev/null +++ b/engine/source/meta_parser/parser/language_types/class.h @@ -0,0 +1,44 @@ +#pragma once + +#include "type_info.h" + +#include "field.h" + +struct BaseClass +{ + BaseClass(const Cursor& cursor); + + std::string name; +}; + +class Class : public TypeInfo +{ + // to access m_qualifiedName + friend class Field; + friend class MetaParser; + +public: + Class(const Cursor& cursor, const Namespace& current_namespace); + + virtual bool shouldCompile(void) const; + + bool shouldCompileFilds(void) const; + + template + using SharedPtrVector = std::vector>; + + std::string getClassName(void); + + SharedPtrVector m_base_classes; + +public: + std::string m_name; + + std::string m_qualified_name; + + SharedPtrVector m_fields; + + std::string m_display_name; + + bool isAccessible(void) const; +}; diff --git a/engine/source/meta_parser/parser/language_types/field.cpp b/engine/source/meta_parser/parser/language_types/field.cpp new file mode 100644 index 000000000..7a6bb5a65 --- /dev/null +++ b/engine/source/meta_parser/parser/language_types/field.cpp @@ -0,0 +1,27 @@ +#include "common/precompiled.h" + +#include "class.h" +#include "field.h" + +Field::Field(const Cursor& cursor, const Namespace& current_namespace, Class* parent) : + TypeInfo(cursor, current_namespace), m_is_const(cursor.getType().IsConst()), m_parent(parent), + m_name(cursor.getSpelling()), m_display_name(Utils::getNameWithoutFirstM(m_name)), + m_type(Utils::getTypeNameWithoutNamespace(cursor.getType())) +{ + Utils::replaceAll(m_type, " ", ""); + Utils::replaceAll(m_type, "Piccolo::", ""); + + auto ret_string = Utils::getStringWithoutQuot(m_meta_data.getProperty("default")); + m_default = ret_string; +} + +bool Field::shouldCompile(void) const { return isAccessible(); } + +bool Field::isAccessible(void) const +{ + return ((m_parent->m_meta_data.getFlag(NativeProperty::Fields) || + m_parent->m_meta_data.getFlag(NativeProperty::All)) && + !m_meta_data.getFlag(NativeProperty::Disable)) || + (m_parent->m_meta_data.getFlag(NativeProperty::WhiteListFields) && + m_meta_data.getFlag(NativeProperty::Enable)); +} diff --git a/engine/source/meta_parser/parser/language_types/field.h b/engine/source/meta_parser/parser/language_types/field.h new file mode 100644 index 000000000..6f2c8185a --- /dev/null +++ b/engine/source/meta_parser/parser/language_types/field.h @@ -0,0 +1,29 @@ +#pragma once + +#include "type_info.h" + +class Class; + +class Field : public TypeInfo +{ + +public: + Field(const Cursor& cursor, const Namespace& current_namespace, Class* parent = nullptr); + + virtual ~Field(void) {} + + bool shouldCompile(void) const; + +public: + bool m_is_const; + + Class* m_parent; + + std::string m_name; + std::string m_display_name; + std::string m_type; + + std::string m_default; + + bool isAccessible(void) const; +}; \ No newline at end of file diff --git a/engine/source/meta_parser/parser/language_types/type_info.cpp b/engine/source/meta_parser/parser/language_types/type_info.cpp new file mode 100644 index 000000000..5f5bf1eb2 --- /dev/null +++ b/engine/source/meta_parser/parser/language_types/type_info.cpp @@ -0,0 +1,16 @@ +#include "common/precompiled.h" + +#include "type_info.h" + +TypeInfo::TypeInfo(const Cursor& cursor, const Namespace& current_namespace) : + m_meta_data(cursor), m_enabled(m_meta_data.getFlag(NativeProperty::Enable)), m_root_cursor(cursor), + m_namespace(current_namespace) +{} + +const MetaInfo& TypeInfo::getMetaData(void) const { return m_meta_data; } + +std::string TypeInfo::getSourceFile(void) const { return m_root_cursor.getSourceFile(); } + +Namespace TypeInfo::getCurrentNamespace() const { return m_namespace; } + +Cursor& TypeInfo::getCurosr() { return m_root_cursor; } diff --git a/engine/source/meta_parser/parser/language_types/type_info.h b/engine/source/meta_parser/parser/language_types/type_info.h new file mode 100644 index 000000000..e9d234f5e --- /dev/null +++ b/engine/source/meta_parser/parser/language_types/type_info.h @@ -0,0 +1,35 @@ +#pragma once +#include "common/namespace.h" + +#include "cursor/cursor.h" + +#include "meta/meta_info.h" +#include "parser/parser.h" + +class TypeInfo +{ +public: + TypeInfo(const Cursor& cursor, const Namespace& current_namespace); + virtual ~TypeInfo(void) {} + + const MetaInfo& getMetaData(void) const; + + std::string getSourceFile(void) const; + + Namespace getCurrentNamespace() const; + + Cursor& getCurosr(); + +protected: + MetaInfo m_meta_data; + + bool m_enabled; + + std::string m_alias_cn; + + Namespace m_namespace; + +private: + // cursor that represents the root of this language type + Cursor m_root_cursor; +}; \ No newline at end of file diff --git a/engine/source/meta_parser/parser/main.cpp b/engine/source/meta_parser/parser/main.cpp new file mode 100644 index 000000000..853085467 --- /dev/null +++ b/engine/source/meta_parser/parser/main.cpp @@ -0,0 +1,68 @@ +#include "common/precompiled.h" +#include "parser/parser.h" + +int parse(std::string project_file_name, + std::string source_include_file_name, + std::string include_path, + std::string sys_include, + std::string module_name, + std::string show_errors); + +int main(int argc, char* argv[]) +{ + auto start_time = std::chrono::system_clock::now(); + int result = 0; + + if (argv[1] != nullptr && argv[2] != nullptr && argv[3] != nullptr && argv[4] != nullptr && argv[5] != nullptr && + argv[6] != nullptr) + { + MetaParser::prepare(); + + result = parse(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); + + auto duration_time = std::chrono::system_clock::now() - start_time; + std::cout << "Completed in " << std::chrono::duration_cast(duration_time).count() + << "ms" << std::endl; + return result; + } + else + { + std::cerr << "Arguments parse error!" << std::endl + << "Please call the tool like this:" << std::endl + << "meta_parser project_file_name include_file_name_to_generate project_base_directory " + "sys_include_directory module_name showErrors(0 or 1)" + << std::endl + << std::endl; + return -1; + } + + return 0; +} + +int parse(std::string project_input_file_name, + std::string source_include_file_name, + std::string include_path, + std::string sys_include, + std::string module_name, + std::string show_errors) +{ + std::cout << std::endl; + std::cout << "Parsing meta data for target \"" << module_name << "\"" << std::endl; + std::fstream input_file; + + bool is_show_errors = "0" != show_errors; + + MetaParser parser( + project_input_file_name, source_include_file_name, include_path, sys_include, module_name, is_show_errors); + + std::cout << "Parsing in " << include_path << std::endl; + int result = parser.parse(); + if (0 != result) + { + return result; + } + + parser.generateFiles(); + + return 0; +} diff --git a/engine/source/meta_parser/parser/meta/meta_data_config.h b/engine/source/meta_parser/parser/meta/meta_data_config.h new file mode 100644 index 000000000..329816374 --- /dev/null +++ b/engine/source/meta_parser/parser/meta/meta_data_config.h @@ -0,0 +1,14 @@ +#pragma once + +namespace NativeProperty +{ + const auto All = "All"; + + const auto Fields = "Fields"; + + const auto Enable = "Enable"; + const auto Disable = "Disable"; + + const auto WhiteListFields = "WhiteListFields"; + +} // namespace NativeProperty diff --git a/engine/source/meta_parser/parser/meta/meta_info.cpp b/engine/source/meta_parser/parser/meta/meta_info.cpp new file mode 100644 index 000000000..8e6f0d8f4 --- /dev/null +++ b/engine/source/meta_parser/parser/meta/meta_info.cpp @@ -0,0 +1,52 @@ +#include "common/precompiled.h" + +#include "parser/parser.h" + +#include "meta_info.h" + +MetaInfo::MetaInfo(const Cursor& cursor) +{ + for (auto& child : cursor.getChildren()) + { + + if (child.getKind() != CXCursor_AnnotateAttr) + continue; + + for (auto& prop : extractProperties(child)) + m_properties[prop.first] = prop.second; + } +} + +std::string MetaInfo::getProperty(const std::string& key) const +{ + auto search = m_properties.find(key); + + // use an empty string by default + return search == m_properties.end() ? "" : search->second; +} + +bool MetaInfo::getFlag(const std::string& key) const { return m_properties.find(key) != m_properties.end(); } + +std::vector MetaInfo::extractProperties(const Cursor& cursor) const +{ + std::vector ret_list; + + auto propertyList = cursor.getDisplayName(); + + auto&& properties = Utils::split(propertyList, ","); + + static const std::string white_space_string = " \t\r\n"; + + for (auto& property_item : properties) + { + auto&& item_details = Utils::split(property_item, ":"); + auto&& temp_string = Utils::trim(item_details[0], white_space_string); + if (temp_string.empty()) + { + continue; + } + ret_list.emplace_back(temp_string, + item_details.size() > 1 ? Utils::trim(item_details[1], white_space_string) : ""); + } + return ret_list; +} diff --git a/engine/source/meta_parser/parser/meta/meta_info.h b/engine/source/meta_parser/parser/meta/meta_info.h new file mode 100644 index 000000000..3c4da59c1 --- /dev/null +++ b/engine/source/meta_parser/parser/meta/meta_info.h @@ -0,0 +1,21 @@ +#pragma once + +#include "cursor/cursor.h" + +class MetaInfo +{ +public: + MetaInfo(const Cursor& cursor); + + std::string getProperty(const std::string& key) const; + + bool getFlag(const std::string& key) const; + +private: + typedef std::pair Property; + + std::unordered_map m_properties; + +private: + std::vector extractProperties(const Cursor& cursor) const; +}; \ No newline at end of file diff --git a/engine/source/meta_parser/parser/meta/meta_utils.cpp b/engine/source/meta_parser/parser/meta/meta_utils.cpp new file mode 100644 index 000000000..6cce2db9a --- /dev/null +++ b/engine/source/meta_parser/parser/meta/meta_utils.cpp @@ -0,0 +1,326 @@ +#include "common/precompiled.h" + +#include "meta_utils.h" + +static int parse_flag = 0; +namespace Utils +{ + + void toString(const CXString& str, std::string& output) + { + auto cstr = clang_getCString(str); + + output = cstr; + + clang_disposeString(str); + } + + std::string getQualifiedName(const CursorType& type) { return type.GetDisplayName(); } + + std::string getTypeNameWithoutNamespace(const CursorType& type) + { + std::string&& type_name = type.GetDisplayName(); + return type_name; + } + + std::string getQualifiedName(const std::string& display_name, const Namespace& current_namespace) + { + std::string name = ""; + for (auto& iter_string : current_namespace) + { + name += (iter_string + "::"); + } + + name += display_name; + + return name; + } + + std::string getQualifiedName(const Cursor& cursor, const Namespace& current_namespace) + { + return getQualifiedName(cursor.getSpelling(), current_namespace); + } + + std::string formatQualifiedName(std::string& source_string) + { + Utils::replace(source_string, '<', 'L'); + Utils::replace(source_string, ':', 'S'); + Utils::replace(source_string, '>', 'R'); + Utils::replace(source_string, '*', 'P'); + return source_string; + } + + /// + /// + /// + /// + /// + /// + fs::path makeRelativePath(const fs::path& from, const fs::path& to) + { + // Start at the root path and while they are the same then do nothing then when they first + // diverge take the remainder of the two path and replace the entire from path with ".." + // segments. + std::string form_complete_string; + std::string to_complete_string; + + /*remove ".." and "."*/ + (void)formatPathString(from.string(), form_complete_string); + (void)formatPathString(to.string(), to_complete_string); + + fs::path form_complete = form_complete_string; + fs::path to_complete = to_complete_string; + + auto iter_from = form_complete.begin(); + auto iter_to = to_complete.begin(); + + // Loop through both + while (iter_from != form_complete.end() && iter_to != to_complete.end() && (*iter_to) == (*iter_from)) + { + ++iter_to; + ++iter_from; + } + + fs::path final_path; + while (iter_from != form_complete.end()) + { + final_path /= ".."; + + ++iter_from; + } + + while (iter_to != to_complete.end()) + { + final_path /= *iter_to; + + ++iter_to; + } + + return final_path; + } + + void fatalError(const std::string& error) + { + std::cerr << "Error: " << error << std::endl; + + exit(EXIT_FAILURE); + } + + std::vector split(std::string input, std::string pat) + { + std::vector ret_list; + while (true) + { + size_t index = input.find(pat); + std::string sub_list = input.substr(0, index); + if (!sub_list.empty()) + { + + ret_list.push_back(sub_list); + } + input.erase(0, index + pat.size()); + if (index == -1) + { + break; + } + } + return ret_list; + } + + std::string getFileName(std::string path) + { + if (path.size() < 1) + { + return std::string(); + } + std::vector result = split(path, "/"); + if (result.size() < 1) + { + return std::string(); + } + return result[result.size() - 1]; + } + + std::string getNameWithoutFirstM(std::string& name) + { + std::string result = name; + if (name.size() > 2 && name[0] == 'm' && name[1] == '_') + { + result = name.substr(2); + } + return result; + } + + std::string getNameWithoutContainer(std::string name) + { + + size_t left = name.find_first_of('<') + 1; + size_t right = name.find_last_of('>'); + if (left > 0 && right < name.size() && left < right) + { + return name.substr(left, right - left); + } + else + { + return nullptr; + } + } + + std::string getStringWithoutQuot(std::string input) + { + size_t left = input.find_first_of('\"') + 1; + size_t right = input.find_last_of('\"'); + if (left > 0 && right < input.size() && left < right) + { + return input.substr(left, right - left); + } + else + { + return input; + } + } + + std::string trim(const std::string& context) + { + + std::string ret_string = context; + + ret_string = ret_string.erase(0, ret_string.find_first_not_of(" ")); + ret_string = ret_string.erase(ret_string.find_last_not_of(" ") + 1); + + return ret_string; + } + + std::string replace(std::string& source_string, std::string sub_string, const std::string new_string) + { + std::string::size_type pos = 0; + while ((pos = source_string.find(sub_string)) != std::string::npos) + { + source_string.replace(pos, sub_string.length(), new_string); + } + return source_string; + } + + std::string replace(std::string& source_string, char taget_char, const char new_char) + { + std::replace(source_string.begin(), source_string.end(), taget_char, new_char); + return source_string; + } + + std::string toUpper(std::string& source_string) + { + transform(source_string.begin(), source_string.end(), source_string.begin(), ::toupper); + return source_string; + } + + std::string join(std::vector context_list, std::string separator) + { + std::string ret_string; + if (context_list.size() == 0) + { + return ret_string; + } + ret_string = context_list[0]; + for (int index = 1; index < context_list.size(); ++index) + { + ret_string += separator + context_list[index]; + } + + return ret_string; + } + + std::string trim(std::string& source_string, const std::string trim_chars) + { + size_t left_pos = source_string.find_first_not_of(trim_chars); + if (left_pos == std::string::npos) + { + source_string = std::string(); + } + else + { + size_t right_pos = source_string.find_last_not_of(trim_chars); + source_string = source_string.substr(left_pos, right_pos - left_pos + 1); + } + return source_string; + } + + std::string loadFile(std::string path) + { + std::ifstream iFile(path); + std::string line_string; + std::ostringstream template_stream; + if (false == iFile.is_open()) + { + iFile.close(); + return ""; + } + while (std::getline(iFile, line_string)) + { + template_stream << line_string << std::endl; + } + iFile.close(); + + return template_stream.str(); + } + + void saveFile(const std::string& outpu_string, const std::string& output_file) + { + fs::path out_path(output_file); + + if (!fs::exists(out_path.parent_path())) + { + fs::create_directories(out_path.parent_path()); + } + std::fstream output_file_stream(output_file, std::ios_base::out); + + output_file_stream << outpu_string << std::endl; + output_file_stream.flush(); + output_file_stream.close(); + return; + } + + void replaceAll(std::string& resource_str, std::string sub_str, std::string new_str) + { + std::string::size_type pos = 0; + while ((pos = resource_str.find(sub_str)) != std::string::npos) + { + resource_str = resource_str.replace(pos, sub_str.length(), new_str); + } + return; + } + + unsigned long formatPathString(const std::string& path_string, std::string& out_string) + { + unsigned int ulRet = 0; + auto local_path_string = path_string; + fs::path local_path; + + local_path = local_path_string; + if (local_path.is_relative()) + { + local_path_string = fs::current_path().string() + "/" + local_path_string; + } + + replaceAll(local_path_string, "\\", "/"); + std::vector subString = split(local_path_string, "/"); + std::vector out_sub_string; + for (auto p : subString) + { + if (p == "..") + { + out_sub_string.pop_back(); + } + else if (p != ".") + { + out_sub_string.push_back(p); + } + } + for (int i = 0; i < out_sub_string.size() - 1; i++) + { + out_string.append(out_sub_string[i] + "/"); + } + out_string.append(out_sub_string[out_sub_string.size() - 1]); + return 0; + } + +} // namespace Utils diff --git a/engine/source/meta_parser/parser/meta/meta_utils.h b/engine/source/meta_parser/parser/meta/meta_utils.h new file mode 100644 index 000000000..646fae357 --- /dev/null +++ b/engine/source/meta_parser/parser/meta/meta_utils.h @@ -0,0 +1,57 @@ +#pragma once + +#include "common/namespace.h" +#include "cursor/cursor.h" + +namespace Utils +{ + + void toString(const CXString& str, std::string& output); + + std::string getQualifiedName(const CursorType& type); + + std::string getQualifiedName(const std::string& display_name, const Namespace& current_namespace); + + std::string getQualifiedName(const Cursor& cursor, const Namespace& current_namespace); + + std::string formatQualifiedName(std::string& source_string); + + fs::path makeRelativePath(const fs::path& from, const fs::path& to); + + void fatalError(const std::string& error); + + template + bool rangeEqual(A startA, A endA, B startB, B endB); + + std::vector split(std::string input, std::string pat); + + std::string getFileName(std::string path); + + std::string getNameWithoutFirstM(std::string& name); + + std::string getTypeNameWithoutNamespace(const CursorType& type); + + std::string getNameWithoutContainer(std::string name); + + std::string getStringWithoutQuot(std::string input); + + std::string replace(std::string& source_string, std::string sub_string, const std::string new_string); + + std::string replace(std::string& source_string, char taget_char, const char new_char); + + std::string toUpper(std::string& source_string); + + std::string join(std::vector context_list, std::string separator); + + std::string trim(std::string& source_string, const std::string trim_chars); + + std::string loadFile(std::string path); + + void saveFile(const std::string& outpu_string, const std::string& output_file); + + void replaceAll(std::string& resource_str, std::string sub_str, std::string new_str); + + unsigned long formatPathString(const std::string& path_string, std::string& out_string); +} // namespace Utils + +#include "meta_utils.hpp" \ No newline at end of file diff --git a/engine/source/meta_parser/parser/meta/meta_utils.hpp b/engine/source/meta_parser/parser/meta/meta_utils.hpp new file mode 100644 index 000000000..6706785e0 --- /dev/null +++ b/engine/source/meta_parser/parser/meta/meta_utils.hpp @@ -0,0 +1,17 @@ +namespace Utils +{ + template + bool rangeEqual(A startA, A endA, B startB, B endB) + { + while (startA != endA && startB != endB) + { + if (*startA != *startB) + return false; + + ++startA; + ++startB; + } + + return (startA == endA) && (startB == endB); + } +} \ No newline at end of file diff --git a/engine/source/meta_parser/parser/parser/parser.cpp b/engine/source/meta_parser/parser/parser/parser.cpp new file mode 100644 index 000000000..5bca6b0cc --- /dev/null +++ b/engine/source/meta_parser/parser/parser/parser.cpp @@ -0,0 +1,220 @@ +#include "common/precompiled.h" + +#include "language_types/class.h" + +#include "generator/reflection_generator.h" +#include "generator/serializer_generator.h" + +#include "parser.h" + +#define RECURSE_NAMESPACES(kind, cursor, method, namespaces) \ + { \ + if (kind == CXCursor_Namespace) \ + { \ + auto display_name = cursor.getDisplayName(); \ + if (!display_name.empty()) \ + { \ + namespaces.emplace_back(display_name); \ + method(cursor, namespaces); \ + namespaces.pop_back(); \ + } \ + } \ + } + +#define TRY_ADD_LANGUAGE_TYPE(handle, container) \ + { \ + if (handle->shouldCompile()) \ + { \ + auto file = handle->getSourceFile(); \ + m_schema_modules[file].container.emplace_back(handle); \ + m_type_table[handle->m_display_name] = file; \ + } \ + } + +void MetaParser::prepare(void) {} + +std::string MetaParser::getIncludeFile(std::string name) +{ + auto iter = m_type_table.find(name); + return iter == m_type_table.end() ? std::string() : iter->second; +} + +MetaParser::MetaParser(const std::string project_input_file, + const std::string include_file_path, + const std::string include_path, + const std::string sys_include, + const std::string module_name, + bool is_show_errors) : + m_project_input_file(project_input_file), + m_source_include_file_name(include_file_path), m_index(nullptr), m_translation_unit(nullptr), + m_sys_include(sys_include), m_module_name(module_name), m_is_show_errors(is_show_errors) +{ + m_work_paths = Utils::split(include_path, ";"); + + m_generators.emplace_back(new Generator::SerializerGenerator( + m_work_paths[0], std::bind(&MetaParser::getIncludeFile, this, std::placeholders::_1))); + m_generators.emplace_back(new Generator::ReflectionGenerator( + m_work_paths[0], std::bind(&MetaParser::getIncludeFile, this, std::placeholders::_1))); +} + +MetaParser::~MetaParser(void) +{ + for (auto item : m_generators) + { + delete item; + } + m_generators.clear(); + + if (m_translation_unit) + clang_disposeTranslationUnit(m_translation_unit); + + if (m_index) + clang_disposeIndex(m_index); +} + +void MetaParser::finish(void) +{ + for (auto generator_iter : m_generators) + { + generator_iter->finish(); + } +} + +bool MetaParser::parseProject() +{ + bool result = true; + std::cout << "Parsing project file: " << m_project_input_file << std::endl; + + std::fstream include_txt_file(m_project_input_file, std::ios::in); + + if (include_txt_file.fail()) + { + std::cout << "Could not load file: " << m_project_input_file << std::endl; + return false; + } + + std::stringstream buffer; + buffer << include_txt_file.rdbuf(); + + std::string context = buffer.str(); + + auto inlcude_files = Utils::split(context, ";"); + std::fstream include_file; + + include_file.open(m_source_include_file_name, std::ios::out); + if (!include_file.is_open()) + { + std::cout << "Could not open the Source Include file: " << m_source_include_file_name << std::endl; + return false; + } + + std::cout << "Generating the Source Include file: " << m_source_include_file_name << std::endl; + + std::string output_filename = Utils::getFileName(m_source_include_file_name); + + if (output_filename.empty()) + { + output_filename = "META_INPUT_HEADER_H"; + } + else + { + Utils::replace(output_filename, ".", "_"); + Utils::replace(output_filename, " ", "_"); + Utils::toUpper(output_filename); + } + include_file << "#ifndef __" << output_filename << "__" << std::endl; + include_file << "#define __" << output_filename << "__" << std::endl; + + for (auto include_item : inlcude_files) + { + std::string temp_string(include_item); + Utils::replace(temp_string, '\\', '/'); + include_file << "#include \"" << temp_string << "\"" << std::endl; + } + + include_file << "#endif" << std::endl; + include_file.close(); + return result; +} + +int MetaParser::parse(void) +{ + bool parse_include_ = parseProject(); + if (!parse_include_) + { + std::cerr << "Parsing project file error! " << std::endl; + return -1; + } + + std::cerr << "Parsing the whole project..." << std::endl; + int is_show_errors = m_is_show_errors ? 1 : 0; + m_index = clang_createIndex(true, is_show_errors); + std::string pre_include = "-I"; + std::string sys_include_temp; + if (!(m_sys_include == "*")) + { + sys_include_temp = pre_include + m_sys_include; + arguments.emplace_back(sys_include_temp.c_str()); + } + + auto paths = m_work_paths; + for (int index = 0; index < paths.size(); ++index) + { + paths[index] = pre_include + paths[index]; + + arguments.emplace_back(paths[index].c_str()); + } + + fs::path input_path(m_source_include_file_name); + if (!fs::exists(input_path)) + { + std::cerr << input_path << " is not exist" << std::endl; + return -2; + } + + m_translation_unit = clang_createTranslationUnitFromSourceFile( + m_index, m_source_include_file_name.c_str(), static_cast(arguments.size()), arguments.data(), 0, nullptr); + auto cursor = clang_getTranslationUnitCursor(m_translation_unit); + + Namespace temp_namespace; + + buildClassAST(cursor, temp_namespace); + + temp_namespace.clear(); + + return 0; +} + +void MetaParser::generateFiles(void) +{ + std::cerr << "Start generate runtime schemas(" << m_schema_modules.size() << ")..." << std::endl; + for (auto& schema : m_schema_modules) + { + for (auto& generator_iter : m_generators) + { + generator_iter->generate(schema.first, schema.second); + } + } + + finish(); +} + +void MetaParser::buildClassAST(const Cursor& cursor, Namespace& current_namespace) +{ + for (auto& child : cursor.getChildren()) + { + auto kind = child.getKind(); + + // actual definition and a class or struct + if (child.isDefinition() && (kind == CXCursor_ClassDecl || kind == CXCursor_StructDecl)) + { + auto class_ptr = std::make_shared(child, current_namespace); + + TRY_ADD_LANGUAGE_TYPE(class_ptr, classes); + } + else + { + RECURSE_NAMESPACES(kind, child, buildClassAST, current_namespace); + } + } +} diff --git a/engine/source/meta_parser/parser/parser/parser.h b/engine/source/meta_parser/parser/parser/parser.h new file mode 100644 index 000000000..88622b4a8 --- /dev/null +++ b/engine/source/meta_parser/parser/parser/parser.h @@ -0,0 +1,64 @@ +#pragma once + +#include "common/precompiled.h" + +#include "common/namespace.h" +#include "common/schema_module.h" + +#include "cursor/cursor.h" + +#include "generator/generator.h" +#include "template_manager/template_manager.h" + +class Class; + +class MetaParser +{ +public: + static void prepare(void); + + MetaParser(const std::string project_input_file, + const std::string include_file_path, + const std::string include_path, + const std::string include_sys, + const std::string module_name, + bool is_show_errors); + ~MetaParser(void); + void finish(void); + int parse(void); + void generateFiles(void); + +private: + std::string m_project_input_file; + + std::vector m_work_paths; + std::string m_module_name; + std::string m_sys_include; + std::string m_source_include_file_name; + + CXIndex m_index; + CXTranslationUnit m_translation_unit; + + std::unordered_map m_type_table; + std::unordered_map m_schema_modules; + + std::vector arguments = {{"-x", + "c++", + "-std=c++11", + "-D__REFLECTION_PARSER__", + "-DNDEBUG", + "-D__clang__", + "-w", + "-MG", + "-M", + "-ferror-limit=0", + "-o clangLog.txt"}}; + std::vector m_generators; + + bool m_is_show_errors; + +private: + bool parseProject(void); + void buildClassAST(const Cursor& cursor, Namespace& current_namespace); + std::string getIncludeFile(std::string name); +}; diff --git a/engine/source/meta_parser/parser/template_manager/template_manager.cpp b/engine/source/meta_parser/parser/template_manager/template_manager.cpp new file mode 100644 index 000000000..87519ca0d --- /dev/null +++ b/engine/source/meta_parser/parser/template_manager/template_manager.cpp @@ -0,0 +1,18 @@ + +#include "template_manager.h" + +void TemplateManager::loadTemplates(std::string path, std::string template_name) +{ + m_template_pool.insert_or_assign(template_name, + Utils::loadFile(path + "/../template/" + template_name + ".mustache")); +} + +std::string TemplateManager::renderByTemplate(std::string template_name, Mustache::data& template_data) +{ + if (m_template_pool.end() == m_template_pool.find(template_name)) + { + return ""; + } + Mustache::mustache tmpl(m_template_pool[template_name]); + return tmpl.render(template_data); +} diff --git a/engine/source/meta_parser/parser/template_manager/template_manager.h b/engine/source/meta_parser/parser/template_manager/template_manager.h new file mode 100644 index 000000000..481a0a9a6 --- /dev/null +++ b/engine/source/meta_parser/parser/template_manager/template_manager.h @@ -0,0 +1,22 @@ +#pragma once +#include "common/precompiled.h" +class TemplateManager +{ +public: + static TemplateManager* getInstance() + { + static TemplateManager* m_pInstance; + if (nullptr == m_pInstance) + m_pInstance = new TemplateManager(); + return m_pInstance; + } + void loadTemplates(std::string path, std::string template_name); + + std::string renderByTemplate(std::string template_name, Mustache::data& template_data); + +private: + TemplateManager() {} + TemplateManager(const TemplateManager&); + TemplateManager& operator=(const TemplateManager&); + std::unordered_map m_template_pool; +}; diff --git a/engine/source/precompile/precompile.cmake b/engine/source/precompile/precompile.cmake index b56208baf..2068be504 100644 --- a/engine/source/precompile/precompile.cmake +++ b/engine/source/precompile/precompile.cmake @@ -1,20 +1,18 @@ # set(PRECOMPILE_TOOLS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/bin") -set(PILOT_PRECOMPILE_PARAMS_IN_PATH "${CMAKE_CURRENT_SOURCE_DIR}/source/precompile/precompile.json.in") -set(PILOT_PRECOMPILE_PARAMS_PATH "${PRECOMPILE_TOOLS_PATH}/precompile.json") -configure_file(${PILOT_PRECOMPILE_PARAMS_IN_PATH} ${PILOT_PRECOMPILE_PARAMS_PATH}) - -#usr/include/c++/v1 +set(PICCOLO_PRECOMPILE_PARAMS_IN_PATH "${CMAKE_CURRENT_SOURCE_DIR}/source/precompile/precompile.json.in") +set(PICCOLO_PRECOMPILE_PARAMS_PATH "${PRECOMPILE_TOOLS_PATH}/precompile.json") +configure_file(${PICCOLO_PRECOMPILE_PARAMS_IN_PATH} ${PICCOLO_PRECOMPILE_PARAMS_PATH}) # # use wine for linux if (CMAKE_HOST_WIN32) set(PRECOMPILE_PRE_EXE) - set(PRECOMPILE_PARSER ${PRECOMPILE_TOOLS_PATH}/Windows/x64/meta_parser.exe) + set(PRECOMPILE_PARSER ${PRECOMPILE_TOOLS_PATH}/PiccoloParser.exe) set(sys_include "*") elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux" ) set(PRECOMPILE_PRE_EXE) - set(PRECOMPILE_PARSER ${PRECOMPILE_TOOLS_PATH}/Linux/meta_parser) + set(PRECOMPILE_PARSER ${PRECOMPILE_TOOLS_PATH}/PiccoloParser) set(sys_include "/usr/include/c++/9/") #execute_process(COMMAND chmod a+x ${PRECOMPILE_PARSER} WORKING_DIRECTORY ${PRECOMPILE_TOOLS_PATH}) elseif(CMAKE_HOST_APPLE) @@ -30,13 +28,13 @@ elseif(CMAKE_HOST_APPLE) ) set(PRECOMPILE_PRE_EXE) - set(PRECOMPILE_PARSER ${PRECOMPILE_TOOLS_PATH}/macOS/meta_parser) + set(PRECOMPILE_PARSER ${PRECOMPILE_TOOLS_PATH}/PiccoloParser) set(sys_include "${osx_sdk_platform_path_test}/../../Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1") endif() set (PARSER_INPUT ${CMAKE_BINARY_DIR}/parser_header.h) ### BUILDING ==================================================================================== -set(PRECOMPILE_TARGET "PilotPreCompile") +set(PRECOMPILE_TARGET "PiccoloPreCompile") # Called first time when building target add_custom_target(${PRECOMPILE_TARGET} ALL @@ -54,7 +52,7 @@ COMMAND ${CMAKE_COMMAND} -E echo "************************************************************* " COMMAND - ${PRECOMPILE_PARSER} "${PILOT_PRECOMPILE_PARAMS_PATH}" "${PARSER_INPUT}" "${ENGINE_ROOT_DIR}/source" ${sys_include} "Pilot" S 0 0 1 + ${PRECOMPILE_PARSER} "${PICCOLO_PRECOMPILE_PARAMS_PATH}" "${PARSER_INPUT}" "${ENGINE_ROOT_DIR}/source" ${sys_include} "Piccolo" 0 ### BUILDING ==================================================================================== COMMAND ${CMAKE_COMMAND} -E echo "+++ Precompile finished +++" diff --git a/engine/source/precompile/precompile.json.in b/engine/source/precompile/precompile.json.in index cb84bbb91..4cf1a98e9 100644 --- a/engine/source/precompile/precompile.json.in +++ b/engine/source/precompile/precompile.json.in @@ -1 +1 @@ -@PILOT_RUNTIME_HEADS@ \ No newline at end of file +@PICCOLO_RUNTIME_HEADS@,@PICCOLO_EDITOR_HEADS@ \ No newline at end of file diff --git a/engine/source/runtime/CMakeLists.txt b/engine/source/runtime/CMakeLists.txt index 61d48cc3c..e1ea5d6cf 100644 --- a/engine/source/runtime/CMakeLists.txt +++ b/engine/source/runtime/CMakeLists.txt @@ -1,6 +1,6 @@ # PackageProject.cmake will be used to make our target installable -set(TARGET_NAME PilotRuntime) +set(TARGET_NAME PiccoloRuntime) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -106,4 +106,4 @@ string(TOLOWER ${TARGET_NAME}/version.h VERSION_HEADER_LOCATION) ### precompile # set global vari used by precompile -set(PILOT_RUNTIME_HEADS "${HEADER_FILES}" PARENT_SCOPE) +set(PICCOLO_RUNTIME_HEADS "${HEADER_FILES}" PARENT_SCOPE) diff --git a/engine/source/runtime/core/color/color.h b/engine/source/runtime/core/color/color.h index 1539d7c62..15dd4cf41 100644 --- a/engine/source/runtime/core/color/color.h +++ b/engine/source/runtime/core/color/color.h @@ -3,7 +3,7 @@ #include "runtime/core/math/vector3.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(Color) CLASS(Color, Fields) diff --git a/engine/source/runtime/core/log/log_system.cpp b/engine/source/runtime/core/log/log_system.cpp index 00d10e6f0..5e6c66c4f 100644 --- a/engine/source/runtime/core/log/log_system.cpp +++ b/engine/source/runtime/core/log/log_system.cpp @@ -5,7 +5,7 @@ #include #include -namespace Pilot +namespace Piccolo { LogSystem::LogSystem() { @@ -33,4 +33,4 @@ namespace Pilot spdlog::drop_all(); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/log/log_system.h b/engine/source/runtime/core/log/log_system.h index a2a2ae903..3dfa93589 100644 --- a/engine/source/runtime/core/log/log_system.h +++ b/engine/source/runtime/core/log/log_system.h @@ -5,7 +5,7 @@ #include #include -namespace Pilot +namespace Piccolo { class LogSystem final @@ -61,4 +61,4 @@ namespace Pilot std::shared_ptr m_logger; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/core/math/axis_aligned.cpp b/engine/source/runtime/core/math/axis_aligned.cpp index efb8a5955..a89330426 100644 --- a/engine/source/runtime/core/math/axis_aligned.cpp +++ b/engine/source/runtime/core/math/axis_aligned.cpp @@ -1,6 +1,6 @@ #include "runtime/core/math/axis_aligned.h" -namespace Pilot +namespace Piccolo { AxisAlignedBox::AxisAlignedBox(const Vector3& center, const Vector3& half_extent) { update(center, half_extent); } @@ -21,4 +21,4 @@ namespace Pilot m_max_corner = center + half_extent; } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/core/math/axis_aligned.h b/engine/source/runtime/core/math/axis_aligned.h index 8902d6fb4..a67fde6cd 100644 --- a/engine/source/runtime/core/math/axis_aligned.h +++ b/engine/source/runtime/core/math/axis_aligned.h @@ -4,7 +4,7 @@ #include "runtime/core/meta/reflection/reflection.h" #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(AxisAlignedBox) CLASS(AxisAlignedBox, Fields) @@ -31,4 +31,4 @@ namespace Pilot Vector3 m_max_corner { -std::numeric_limits::max(), -std::numeric_limits::max(), -std::numeric_limits::max()}; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/core/math/math.cpp b/engine/source/runtime/core/math/math.cpp index ddcb81895..40333b45d 100644 --- a/engine/source/runtime/core/math/math.cpp +++ b/engine/source/runtime/core/math/math.cpp @@ -1,7 +1,7 @@ #include "runtime/core/math/math.h" #include "runtime/core/math/matrix4.h" -namespace Pilot +namespace Piccolo { Math::AngleUnit Math::k_AngleUnit; @@ -192,4 +192,4 @@ namespace Pilot return proj_matrix; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/math.h b/engine/source/runtime/core/math/math.h index ceea100dd..4a0cc3491 100644 --- a/engine/source/runtime/core/math/math.h +++ b/engine/source/runtime/core/math/math.h @@ -8,7 +8,7 @@ #define CMP(x, y) (fabsf(x - y) < FLT_EPSILON * fmaxf(1.0f, fmaxf(fabsf(x), fabsf(y)))) -namespace Pilot +namespace Piccolo { static const float Math_POS_INFINITY = std::numeric_limits::infinity(); static const float Math_NEG_INFINITY = -std::numeric_limits::infinity(); @@ -307,4 +307,4 @@ namespace Pilot inline Degree operator*(float a, const Degree& b) { return Degree(a * b.valueDegrees()); } inline Degree operator/(float a, const Degree& b) { return Degree(a / b.valueDegrees()); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/math_headers.h b/engine/source/runtime/core/math/math_headers.h index 23a6fb041..d44fb1a0f 100644 --- a/engine/source/runtime/core/math/math_headers.h +++ b/engine/source/runtime/core/math/math_headers.h @@ -12,5 +12,5 @@ #include "runtime/core/math/vector3.h" #include "runtime/core/math/vector4.h" -namespace Pilot -{} // namespace Pilot +namespace Piccolo +{} // namespace Piccolo diff --git a/engine/source/runtime/core/math/math_marcos.h b/engine/source/runtime/core/math/math_marcos.h index 0b80d3c63..43affa502 100644 --- a/engine/source/runtime/core/math/math_marcos.h +++ b/engine/source/runtime/core/math/math_marcos.h @@ -1,10 +1,10 @@ #pragma once -#define PILOT_MIN(x, y) (((x) < (y)) ? (x) : (y)) -#define PILOT_MAX(x, y) (((x) > (y)) ? (x) : (y)) -#define PILOT_PIN(a, min_value, max_value) PILOT_MIN(max_value, PILOT_MAX(a, min_value)) +#define PICCOLO_MIN(x, y) (((x) < (y)) ? (x) : (y)) +#define PICCOLO_MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define PICCOLO_PIN(a, min_value, max_value) PICCOLO_MIN(max_value, PICCOLO_MAX(a, min_value)) -#define PILOT_VALID_INDEX(idx, range) (((idx) >= 0) && ((idx) < (range))) -#define PILOT_PIN_INDEX(idx, range) PILOT_PIN(idx, 0, (range)-1) +#define PICCOLO_VALID_INDEX(idx, range) (((idx) >= 0) && ((idx) < (range))) +#define PICCOLO_PIN_INDEX(idx, range) PICCOLO_PIN(idx, 0, (range)-1) -#define PILOT_SIGN(x) ((((x) > 0.0f) ? 1.0f : 0.0f) + (((x) < 0.0f) ? -1.0f : 0.0f)) +#define PICCOLO_SIGN(x) ((((x) > 0.0f) ? 1.0f : 0.0f) + (((x) < 0.0f) ? -1.0f : 0.0f)) diff --git a/engine/source/runtime/core/math/matrix3.cpp b/engine/source/runtime/core/math/matrix3.cpp index 0eb5b4c91..67e657605 100644 --- a/engine/source/runtime/core/math/matrix3.cpp +++ b/engine/source/runtime/core/math/matrix3.cpp @@ -1,6 +1,6 @@ #include "runtime/core/math/matrix3.h" -namespace Pilot +namespace Piccolo { const Matrix3x3 Matrix3x3::ZERO(0, 0, 0, 0, 0, 0, 0, 0, 0); const Matrix3x3 Matrix3x3::IDENTITY(1, 0, 0, 0, 1, 0, 0, 0, 1); @@ -237,4 +237,4 @@ namespace Pilot m_mat[2][1] = yzm + x_sin_v; m_mat[2][2] = z2 * one_minus_cos + cos_v; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/matrix3.h b/engine/source/runtime/core/math/matrix3.h index 75a2a7fe6..8e257fa4b 100644 --- a/engine/source/runtime/core/math/matrix3.h +++ b/engine/source/runtime/core/math/matrix3.h @@ -24,7 +24,7 @@ // 0 0 1 // where t > 0 indicates a counterclockwise rotation in the xy-plane. -namespace Pilot +namespace Piccolo { /** A 3x3 matrix which can represent rotations around axes. @note @@ -365,4 +365,4 @@ namespace Pilot static const Matrix3x3 ZERO; static const Matrix3x3 IDENTITY; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/matrix4.cpp b/engine/source/runtime/core/math/matrix4.cpp index 4e57a1424..f940341e1 100644 --- a/engine/source/runtime/core/math/matrix4.cpp +++ b/engine/source/runtime/core/math/matrix4.cpp @@ -1,7 +1,7 @@ #include "runtime/core/math/matrix4.h" -namespace Pilot +namespace Piccolo { const Matrix4x4 Matrix4x4::ZERO(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); @@ -187,4 +187,4 @@ namespace Pilot v.x * mat[0][2] + v.y * mat[1][2] + v.z * mat[2][2] + v.w * mat[3][2], v.x * mat[0][3] + v.y * mat[1][3] + v.z * mat[2][3] + v.w * mat[3][3]); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/matrix4.h b/engine/source/runtime/core/math/matrix4.h index 0360a9c79..500ae22a0 100644 --- a/engine/source/runtime/core/math/matrix4.h +++ b/engine/source/runtime/core/math/matrix4.h @@ -6,7 +6,7 @@ #include "runtime/core/math/vector3.h" #include "runtime/core/math/vector4.h" -namespace Pilot +namespace Piccolo { /** Class encapsulating a standard 4x4 homogeneous matrix. @remarks @@ -972,4 +972,4 @@ namespace Pilot }; Vector4 operator*(const Vector4& v, const Matrix4x4& mat); -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/quaternion.cpp b/engine/source/runtime/core/math/quaternion.cpp index a224f9b4d..2ae0dc989 100644 --- a/engine/source/runtime/core/math/quaternion.cpp +++ b/engine/source/runtime/core/math/quaternion.cpp @@ -2,7 +2,7 @@ #include "runtime/core/math/matrix3.h" #include "runtime/core/math/vector3.h" -namespace Pilot +namespace Piccolo { const Quaternion Quaternion::ZERO(0, 0, 0, 0); const Quaternion Quaternion::IDENTITY(1, 0, 0, 0); @@ -369,4 +369,4 @@ namespace Pilot result.normalise(); return result; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/quaternion.h b/engine/source/runtime/core/math/quaternion.h index 2c340e0b7..5dc99587c 100644 --- a/engine/source/runtime/core/math/quaternion.h +++ b/engine/source/runtime/core/math/quaternion.h @@ -5,7 +5,7 @@ #include -namespace Pilot +namespace Piccolo { class Matrix3x3; class Vector3; @@ -215,4 +215,4 @@ namespace Pilot static const float k_epsilon; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/random.h b/engine/source/runtime/core/math/random.h index b353b35f8..c826a874c 100644 --- a/engine/source/runtime/core/math/random.h +++ b/engine/source/runtime/core/math/random.h @@ -4,7 +4,7 @@ #include #include -namespace Pilot +namespace Piccolo { template using uniform_distribution = typename std::conditional::value, diff --git a/engine/source/runtime/core/math/transform.h b/engine/source/runtime/core/math/transform.h index 973888995..71bc51ea8 100644 --- a/engine/source/runtime/core/math/transform.h +++ b/engine/source/runtime/core/math/transform.h @@ -4,7 +4,7 @@ #include "runtime/core/math/vector3.h" #include "runtime/core/meta/reflection/reflection.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(Transform) CLASS(Transform, Fields) @@ -28,4 +28,4 @@ namespace Pilot return temp; } }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/vector2.cpp b/engine/source/runtime/core/math/vector2.cpp index 60e6423ba..b0141be48 100644 --- a/engine/source/runtime/core/math/vector2.cpp +++ b/engine/source/runtime/core/math/vector2.cpp @@ -1,6 +1,6 @@ #include "runtime/core/math/vector2.h" -namespace Pilot +namespace Piccolo { const Vector2 Vector2::ZERO(0, 0); const Vector2 Vector2::UNIT_X(1, 0); @@ -9,4 +9,4 @@ namespace Pilot const Vector2 Vector2::NEGATIVE_UNIT_Y(0, -1); const Vector2 Vector2::UNIT_SCALE(1, 1); -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/vector2.h b/engine/source/runtime/core/math/vector2.h index aa1160add..388dc3dcf 100644 --- a/engine/source/runtime/core/math/vector2.h +++ b/engine/source/runtime/core/math/vector2.h @@ -6,7 +6,7 @@ #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(Vector2) CLASS(Vector2, Fields) @@ -341,4 +341,4 @@ namespace Pilot static const Vector2 UNIT_SCALE; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/vector3.cpp b/engine/source/runtime/core/math/vector3.cpp index b444c65a8..6154a7a2f 100644 --- a/engine/source/runtime/core/math/vector3.cpp +++ b/engine/source/runtime/core/math/vector3.cpp @@ -1,6 +1,6 @@ #include "runtime/core/math/vector3.h" -namespace Pilot +namespace Piccolo { const Vector3 Vector3::ZERO(0, 0, 0); const Vector3 Vector3::UNIT_X(1, 0, 0); @@ -10,4 +10,4 @@ namespace Pilot const Vector3 Vector3::NEGATIVE_UNIT_Y(0, -1, 0); const Vector3 Vector3::NEGATIVE_UNIT_Z(0, 0, -1); const Vector3 Vector3::UNIT_SCALE(1, 1, 1); -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/vector3.h b/engine/source/runtime/core/math/vector3.h index d4d2fa11e..1c4812c3a 100644 --- a/engine/source/runtime/core/math/vector3.h +++ b/engine/source/runtime/core/math/vector3.h @@ -6,7 +6,7 @@ #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(Vector3) CLASS(Vector3, Fields) @@ -450,4 +450,4 @@ namespace Pilot static const Vector3 NEGATIVE_UNIT_Z; static const Vector3 UNIT_SCALE; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/vector4.cpp b/engine/source/runtime/core/math/vector4.cpp index b7d76aa1f..3f69391b5 100644 --- a/engine/source/runtime/core/math/vector4.cpp +++ b/engine/source/runtime/core/math/vector4.cpp @@ -1,8 +1,8 @@ #include "runtime/core/math/vector4.h" -namespace Pilot +namespace Piccolo { const Vector4 Vector4::ZERO(0, 0, 0, 0); const Vector4 Vector4::UNIT_SCALE(1.0f, 1.0f, 1.0f, 1.0f); -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/math/vector4.h b/engine/source/runtime/core/math/vector4.h index a571f0bf8..b2306ef8f 100644 --- a/engine/source/runtime/core/math/vector4.h +++ b/engine/source/runtime/core/math/vector4.h @@ -4,7 +4,7 @@ #include "runtime/core/math/vector3.h" #include "runtime/core/meta/reflection/reflection.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(Vector4) CLASS(Vector4, Fields) @@ -194,4 +194,4 @@ namespace Pilot static const Vector4 UNIT_SCALE; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/meta/meta_example.cpp b/engine/source/runtime/core/meta/meta_example.cpp index 65b094516..a0829c59a 100644 --- a/engine/source/runtime/core/meta/meta_example.cpp +++ b/engine/source/runtime/core/meta/meta_example.cpp @@ -6,7 +6,7 @@ #include #include #include -namespace Pilot +namespace Piccolo { void metaExample() { @@ -77,4 +77,4 @@ namespace Pilot } } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/meta/meta_example.h b/engine/source/runtime/core/meta/meta_example.h index 4d2f0a29b..10a0d48ed 100644 --- a/engine/source/runtime/core/meta/meta_example.h +++ b/engine/source/runtime/core/meta/meta_example.h @@ -2,7 +2,7 @@ #include "runtime/core/meta/reflection/reflection.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(BaseTest) CLASS(BaseTest, Fields) @@ -32,4 +32,4 @@ namespace Pilot public: std::vector> m_test_base_array; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/meta/reflection/reflection.cpp b/engine/source/runtime/core/meta/reflection/reflection.cpp index f3d82a436..60c281fac 100644 --- a/engine/source/runtime/core/meta/reflection/reflection.cpp +++ b/engine/source/runtime/core/meta/reflection/reflection.cpp @@ -2,7 +2,7 @@ #include #include -namespace Pilot +namespace Piccolo { namespace Reflection { @@ -313,4 +313,4 @@ namespace Pilot return *this; } } // namespace Reflection -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/core/meta/reflection/reflection.h b/engine/source/runtime/core/meta/reflection/reflection.h index bc61c2cda..0c685c0f5 100644 --- a/engine/source/runtime/core/meta/reflection/reflection.h +++ b/engine/source/runtime/core/meta/reflection/reflection.h @@ -7,7 +7,7 @@ #include #include -namespace Pilot +namespace Piccolo { #if defined(__REFLECTION_PARSER__) @@ -41,21 +41,21 @@ namespace Pilot #define REGISTER_ARRAY_TO_MAP(name, value) TypeMetaRegisterinterface::registerToArrayMap(name, value); #define UNREGISTER_ALL TypeMetaRegisterinterface::unregisterAll(); -#define PILOT_REFLECTION_NEW(name, ...) Reflection::ReflectionPtr(#name, new name(__VA_ARGS__)); -#define PILOT_REFLECTION_DELETE(value) \ +#define PICCOLO_REFLECTION_NEW(name, ...) Reflection::ReflectionPtr(#name, new name(__VA_ARGS__)); +#define PICCOLO_REFLECTION_DELETE(value) \ if (value) \ { \ delete value.operator->(); \ value.getPtrReference() = nullptr; \ } -#define PILOT_REFLECTION_DEEP_COPY(type, dst_ptr, src_ptr) \ +#define PICCOLO_REFLECTION_DEEP_COPY(type, dst_ptr, src_ptr) \ *static_cast(dst_ptr) = *static_cast(src_ptr.getPtr()); #define TypeMetaDef(class_name, ptr) \ - Pilot::Reflection::ReflectionInstance(Pilot::Reflection::TypeMeta::newMetaFromName(#class_name), (class_name*)ptr) + Piccolo::Reflection::ReflectionInstance(Piccolo::Reflection::TypeMeta::newMetaFromName(#class_name), (class_name*)ptr) #define TypeMetaDefPtr(class_name, ptr) \ - new Pilot::Reflection::ReflectionInstance(Pilot::Reflection::TypeMeta::newMetaFromName(#class_name), \ + new Piccolo::Reflection::ReflectionInstance(Piccolo::Reflection::TypeMeta::newMetaFromName(#class_name), \ (class_name*)ptr) template @@ -342,4 +342,4 @@ namespace Pilot } // namespace Reflection -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/meta/reflection/reflection_register.cpp b/engine/source/runtime/core/meta/reflection/reflection_register.cpp index 73335cc53..d4b6a9858 100644 --- a/engine/source/runtime/core/meta/reflection/reflection_register.cpp +++ b/engine/source/runtime/core/meta/reflection/reflection_register.cpp @@ -8,10 +8,10 @@ #include "_generated/reflection/all_reflection.h" #include "_generated/serializer/all_serializer.ipp" -namespace Pilot +namespace Piccolo { namespace Reflection { void TypeMetaRegister::Unregister() { TypeMetaRegisterinterface::unregisterAll(); } } // namespace Reflection -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/core/meta/reflection/reflection_register.h b/engine/source/runtime/core/meta/reflection/reflection_register.h index 6b89e733f..ef45dc1de 100644 --- a/engine/source/runtime/core/meta/reflection/reflection_register.h +++ b/engine/source/runtime/core/meta/reflection/reflection_register.h @@ -1,5 +1,5 @@ #pragma once -namespace Pilot +namespace Piccolo { namespace Reflection { @@ -10,4 +10,4 @@ namespace Pilot static void Unregister(); }; } // namespace Reflection -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/core/meta/serializer/serializer.cpp b/engine/source/runtime/core/meta/serializer/serializer.cpp index b47ca5f01..ed4c09ac6 100644 --- a/engine/source/runtime/core/meta/serializer/serializer.cpp +++ b/engine/source/runtime/core/meta/serializer/serializer.cpp @@ -1,6 +1,6 @@ #include "serializer.h" #include -namespace Pilot +namespace Piccolo { template<> @@ -149,4 +149,4 @@ namespace Pilot }*/ //////////////////////////////////// -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/core/meta/serializer/serializer.h b/engine/source/runtime/core/meta/serializer/serializer.h index df0e082e1..c63645c27 100644 --- a/engine/source/runtime/core/meta/serializer/serializer.h +++ b/engine/source/runtime/core/meta/serializer/serializer.h @@ -4,7 +4,7 @@ #include -namespace Pilot +namespace Piccolo { template inline constexpr bool always_false = false; @@ -166,4 +166,4 @@ namespace Pilot // //////////////////////////////////// -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/engine.cpp b/engine/source/runtime/engine.cpp index 340500b2c..afa92df67 100644 --- a/engine/source/runtime/engine.cpp +++ b/engine/source/runtime/engine.cpp @@ -10,12 +10,12 @@ #include "runtime/function/render/render_system.h" #include "runtime/function/render/window_system.h" -namespace Pilot +namespace Piccolo { bool g_is_editor_mode {false}; std::unordered_set g_editor_tick_component_types {}; - void PilotEngine::startEngine(const std::string& config_file_path) + void PiccoloEngine::startEngine(const std::string& config_file_path) { Reflection::TypeMetaRegister::Register(); @@ -24,7 +24,7 @@ namespace Pilot LOG_INFO("engine start"); } - void PilotEngine::shutdownEngine() + void PiccoloEngine::shutdownEngine() { LOG_INFO("engine shutdown"); @@ -33,10 +33,10 @@ namespace Pilot Reflection::TypeMetaRegister::Unregister(); } - void PilotEngine::initialize() {} - void PilotEngine::clear() {} + void PiccoloEngine::initialize() {} + void PiccoloEngine::clear() {} - void PilotEngine::run() + void PiccoloEngine::run() { std::shared_ptr window_system = g_runtime_global_context.m_window_system; ASSERT(window_system); @@ -48,7 +48,7 @@ namespace Pilot } } - float PilotEngine::calculateDeltaTime() + float PiccoloEngine::calculateDeltaTime() { float delta_time; { @@ -63,7 +63,7 @@ namespace Pilot return delta_time; } - bool PilotEngine::tickOneFrame(float delta_time) + bool PiccoloEngine::tickOneFrame(float delta_time) { logicalTick(delta_time); calculateFPS(delta_time); @@ -82,26 +82,26 @@ namespace Pilot g_runtime_global_context.m_window_system->setTile( - std::string("Pilot - " + std::to_string(getFPS()) + " FPS").c_str()); + std::string("Piccolo - " + std::to_string(getFPS()) + " FPS").c_str()); const bool should_window_close = g_runtime_global_context.m_window_system->shouldClose(); return !should_window_close; } - void PilotEngine::logicalTick(float delta_time) + void PiccoloEngine::logicalTick(float delta_time) { g_runtime_global_context.m_world_manager->tick(delta_time); g_runtime_global_context.m_input_system->tick(); } - bool PilotEngine::rendererTick() + bool PiccoloEngine::rendererTick() { g_runtime_global_context.m_render_system->tick(); return true; } - const float PilotEngine::k_fps_alpha = 1.f / 100; - void PilotEngine::calculateFPS(float delta_time) + const float PiccoloEngine::k_fps_alpha = 1.f / 100; + void PiccoloEngine::calculateFPS(float delta_time) { m_frame_count++; @@ -116,4 +116,4 @@ namespace Pilot m_fps = static_cast(1.f / m_average_duration); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/engine.h b/engine/source/runtime/engine.h index 1ce20e7b6..eec030af8 100644 --- a/engine/source/runtime/engine.h +++ b/engine/source/runtime/engine.h @@ -6,14 +6,14 @@ #include #include -namespace Pilot +namespace Piccolo { extern bool g_is_editor_mode; extern std::unordered_set g_editor_tick_component_types; - class PilotEngine + class PiccoloEngine { - friend class PilotEditor; + friend class PiccoloEditor; static const float k_fps_alpha; @@ -51,4 +51,4 @@ namespace Pilot int m_fps {0}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/animation/animation_loader.cpp b/engine/source/runtime/function/animation/animation_loader.cpp index 9090bc874..885c5bfca 100644 --- a/engine/source/runtime/function/animation/animation_loader.cpp +++ b/engine/source/runtime/function/animation/animation_loader.cpp @@ -10,7 +10,7 @@ #include "_generated/serializer/all_serializer.h" -namespace Pilot +namespace Piccolo { namespace { @@ -21,7 +21,7 @@ namespace Pilot RawBone raw_bone; raw_bone.index = skeleton_data->bones_map.size(); raw_bone.parent_index = parent_index; - std::shared_ptr bone_ptr = std::make_shared(); + std::shared_ptr bone_ptr = std::make_shared(); *bone_ptr = raw_bone; skeleton_data->bones_map.push_back(*bone_ptr); return bone_ptr; @@ -71,32 +71,32 @@ namespace Pilot } } // namespace - std::shared_ptr AnimationLoader::loadAnimationClipData(std::string animation_clip_url) + std::shared_ptr AnimationLoader::loadAnimationClipData(std::string animation_clip_url) { AnimationAsset animation_clip; g_runtime_global_context.m_asset_manager->loadAsset(animation_clip_url, animation_clip); - return std::make_shared(animation_clip.clip_data); + return std::make_shared(animation_clip.clip_data); } - std::shared_ptr AnimationLoader::loadSkeletonData(std::string skeleton_data_url) + std::shared_ptr AnimationLoader::loadSkeletonData(std::string skeleton_data_url) { SkeletonData data; g_runtime_global_context.m_asset_manager->loadAsset(skeleton_data_url, data); - return std::make_shared(data); + return std::make_shared(data); } - std::shared_ptr AnimationLoader::loadAnimSkelMap(std::string anim_skel_map_url) + std::shared_ptr AnimationLoader::loadAnimSkelMap(std::string anim_skel_map_url) { AnimSkelMap data; g_runtime_global_context.m_asset_manager->loadAsset(anim_skel_map_url, data); - return std::make_shared(data); + return std::make_shared(data); } - std::shared_ptr AnimationLoader::loadSkeletonMask(std::string skeleton_mask_file_url) + std::shared_ptr AnimationLoader::loadSkeletonMask(std::string skeleton_mask_file_url) { BoneBlendMask data; g_runtime_global_context.m_asset_manager->loadAsset(skeleton_mask_file_url, data); - return std::make_shared(data); + return std::make_shared(data); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/animation/animation_loader.h b/engine/source/runtime/function/animation/animation_loader.h index d342539d8..c9aa77792 100644 --- a/engine/source/runtime/function/animation/animation_loader.h +++ b/engine/source/runtime/function/animation/animation_loader.h @@ -8,7 +8,7 @@ #include #include -namespace Pilot +namespace Piccolo { class AnimationLoader { @@ -18,4 +18,4 @@ namespace Pilot std::shared_ptr loadAnimSkelMap(std::string anim_skel_map_url); std::shared_ptr loadSkeletonMask(std::string skeleton_mask_file_url); }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/animation/animation_system.cpp b/engine/source/runtime/function/animation/animation_system.cpp index 4ca6dfdb7..016dcf061 100644 --- a/engine/source/runtime/function/animation/animation_system.cpp +++ b/engine/source/runtime/function/animation/animation_system.cpp @@ -5,7 +5,7 @@ #include "runtime/function/animation/animation_loader.h" #include "runtime/function/animation/skeleton.h" -namespace Pilot +namespace Piccolo { std::map> AnimationManager::m_skeleton_definition_cache; std::map> AnimationManager::m_animation_data_cache; @@ -149,4 +149,4 @@ namespace Pilot } return blend_state_with_clip_data; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/animation/animation_system.h b/engine/source/runtime/function/animation/animation_system.h index b66f854b3..778b610f9 100644 --- a/engine/source/runtime/function/animation/animation_system.h +++ b/engine/source/runtime/function/animation/animation_system.h @@ -10,7 +10,7 @@ #include #include -namespace Pilot +namespace Piccolo { class AnimationManager { @@ -30,4 +30,4 @@ namespace Pilot AnimationManager() = default; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/animation/node.cpp b/engine/source/runtime/function/animation/node.cpp index 632235e11..322d6102f 100644 --- a/engine/source/runtime/function/animation/node.cpp +++ b/engine/source/runtime/function/animation/node.cpp @@ -2,7 +2,7 @@ #include "runtime/core/math/math.h" -namespace Pilot +namespace Piccolo { //----------------------------------------------------------------------- Node::Node(const std::string name) { m_name = name; } @@ -242,4 +242,4 @@ namespace Pilot } return std::numeric_limits().max(); } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/animation/node.h b/engine/source/runtime/function/animation/node.h index 7dba955e1..e532942a1 100644 --- a/engine/source/runtime/function/animation/node.h +++ b/engine/source/runtime/function/animation/node.h @@ -5,7 +5,7 @@ #include "runtime/resource/res_type/data/skeleton_data.h" -namespace Pilot +namespace Piccolo { class Node { @@ -113,4 +113,4 @@ namespace Pilot size_t getID(void) const; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/animation/skeleton.cpp b/engine/source/runtime/function/animation/skeleton.cpp index b96453fbf..a0b70f938 100644 --- a/engine/source/runtime/function/animation/skeleton.cpp +++ b/engine/source/runtime/function/animation/skeleton.cpp @@ -4,7 +4,7 @@ #include "runtime/function/animation/utilities.h" -namespace Pilot +namespace Piccolo { Skeleton::~Skeleton() { delete[] m_bones; } @@ -154,4 +154,4 @@ namespace Pilot } return animation_result; } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/animation/skeleton.h b/engine/source/runtime/function/animation/skeleton.h index ba1b664a9..8b17e0b32 100644 --- a/engine/source/runtime/function/animation/skeleton.h +++ b/engine/source/runtime/function/animation/skeleton.h @@ -4,7 +4,7 @@ #include "runtime/function/animation/node.h" -namespace Pilot +namespace Piccolo { class SkeletonData; class BlendStateWithClipData; @@ -24,4 +24,4 @@ namespace Pilot AnimationResult outputAnimationResult(); void resetSkeleton(); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/animation/utilities.cpp b/engine/source/runtime/function/animation/utilities.cpp index ffe61ed95..67d66ec46 100644 --- a/engine/source/runtime/function/animation/utilities.cpp +++ b/engine/source/runtime/function/animation/utilities.cpp @@ -2,7 +2,7 @@ #include "runtime/function/animation/node.h" -namespace Pilot +namespace Piccolo { Bone* find_by_index(Bone* bones, int key, int size, bool is_flat) { @@ -51,4 +51,4 @@ namespace Pilot return it->index; return std::numeric_limits::max(); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/animation/utilities.h b/engine/source/runtime/function/animation/utilities.h index f65c40129..c730733ca 100644 --- a/engine/source/runtime/function/animation/utilities.h +++ b/engine/source/runtime/function/animation/utilities.h @@ -5,7 +5,7 @@ #include #include -namespace Pilot +namespace Piccolo { class Bone; class RawBone; @@ -26,4 +26,4 @@ namespace Pilot Bone* find_by_index(Bone* bones, int key, int size, bool is_flat = false); std::shared_ptr find_by_index(std::vector>& bones, int key, bool is_flat = false); int find_index_by_name(const SkeletonData& skeleton, const std::string& name); -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/character/character.cpp b/engine/source/runtime/function/character/character.cpp index 3c8c9c7da..b190f629a 100644 --- a/engine/source/runtime/function/character/character.cpp +++ b/engine/source/runtime/function/character/character.cpp @@ -5,7 +5,7 @@ #include "runtime/function/framework/component/transform/transform_component.h" #include "runtime/function/input/input_system.h" -namespace Pilot +namespace Piccolo { Character::Character(std::shared_ptr character_object) { setObject(character_object); } @@ -75,4 +75,4 @@ namespace Pilot //m_position = // (m_position * (k_camera_blend_time - frame_length) + new_position * frame_length) / k_camera_blend_time; } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/character/character.h b/engine/source/runtime/function/character/character.h index 40830fcb8..fa6593f00 100644 --- a/engine/source/runtime/function/character/character.h +++ b/engine/source/runtime/function/character/character.h @@ -6,7 +6,7 @@ #include -namespace Pilot +namespace Piccolo { class Character { @@ -36,4 +36,4 @@ namespace Pilot Quaternion m_rotation_buffer; bool m_rotation_dirty; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/controller/character_controller.cpp b/engine/source/runtime/function/controller/character_controller.cpp index d7cf46b6a..663687285 100644 --- a/engine/source/runtime/function/controller/character_controller.cpp +++ b/engine/source/runtime/function/controller/character_controller.cpp @@ -1,25 +1,44 @@ #include "runtime/function/controller/character_controller.h" +#include "runtime/core/base/macro.h" + #include "runtime/function/framework/component/motor/motor_component.h" +#include "runtime/function/framework/world/world_manager.h" #include "runtime/function/global/global_context.h" -#include "runtime/function/physics/physics_system.h" +#include "runtime/function/physics/physics_scene.h" -namespace Pilot +namespace Piccolo { + CharacterController::CharacterController(const Capsule& capsule) : m_capsule(capsule) + { + m_rigidbody_shape = RigidBodyShape(); + m_rigidbody_shape.m_geometry = PICCOLO_REFLECTION_NEW(Capsule); + *static_cast(m_rigidbody_shape.m_geometry) = m_capsule; + + m_rigidbody_shape.m_type = RigidBodyShapeType::capsule; + + Quaternion orientation; + orientation.fromAngleAxis(Radian(Degree(90.f)), Vector3::UNIT_X); + + m_rigidbody_shape.m_local_transform = + Transform(Vector3(0, 0, capsule.m_half_height + capsule.m_radius), orientation, Vector3::UNIT_SCALE); + } + Vector3 CharacterController::move(const Vector3& current_position, const Vector3& displacement) { - const float gap = 0.1f; + std::shared_ptr physics_scene = + g_runtime_global_context.m_world_manager->getCurrentActivePhysicsScene().lock(); + ASSERT(physics_scene); + + Vector3 final_position = current_position + displacement; - Capsule test_capsule; - test_capsule.m_half_height = m_capsule.m_half_height - gap; - test_capsule.m_radius = m_capsule.m_radius - gap; + Transform final_transform = Transform(final_position, Quaternion::IDENTITY, Vector3::UNIT_SCALE); - Vector3 desired_position = current_position + displacement; - if (g_runtime_global_context.m_legacy_physics_system->overlapByCapsule(desired_position, test_capsule)) + if (physics_scene->isOverlap(m_rigidbody_shape, final_transform.getMatrix())) { - desired_position = current_position; + final_position = current_position; } - return desired_position; + return final_position; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/controller/character_controller.h b/engine/source/runtime/function/controller/character_controller.h index dbb564c10..4c4045fc6 100644 --- a/engine/source/runtime/function/controller/character_controller.h +++ b/engine/source/runtime/function/controller/character_controller.h @@ -1,9 +1,10 @@ #pragma once #include "runtime/core/math/vector3.h" +#include "runtime/resource/res_type/components/rigid_body.h" #include "runtime/resource/res_type/data/basic_shape.h" -namespace Pilot +namespace Piccolo { enum SweepPass { @@ -24,11 +25,13 @@ namespace Pilot class CharacterController : public Controller { public: - CharacterController(const Capsule& capsule) : m_capsule(capsule) {} + CharacterController(const Capsule& capsule); + ~CharacterController() = default; Vector3 move(const Vector3& current_position, const Vector3& displacement) override; private: - Capsule m_capsule; + Capsule m_capsule; + RigidBodyShape m_rigidbody_shape; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/animation/animation_component.cpp b/engine/source/runtime/function/framework/component/animation/animation_component.cpp index 35fb42836..f1505cd8e 100644 --- a/engine/source/runtime/function/framework/component/animation/animation_component.cpp +++ b/engine/source/runtime/function/framework/component/animation/animation_component.cpp @@ -3,7 +3,7 @@ #include "runtime/function/animation/animation_system.h" #include "runtime/function/framework/object/object.h" -namespace Pilot +namespace Piccolo { void AnimationComponent::postLoadResource(std::weak_ptr parent_object) { @@ -25,4 +25,4 @@ namespace Pilot } const AnimationResult& AnimationComponent::getResult() const { return m_animation_res.animation_result; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/animation/animation_component.h b/engine/source/runtime/function/framework/component/animation/animation_component.h index d968f1446..7e8b437b3 100644 --- a/engine/source/runtime/function/framework/component/animation/animation_component.h +++ b/engine/source/runtime/function/framework/component/animation/animation_component.h @@ -4,7 +4,7 @@ #include "runtime/function/framework/component/component.h" #include "runtime/resource/res_type/components/animation.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(AnimationComponent) CLASS(AnimationComponent : public Component, WhiteListFields) @@ -26,4 +26,4 @@ namespace Pilot Skeleton m_skeleton; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/camera/camera_component.cpp b/engine/source/runtime/function/framework/component/camera/camera_component.cpp index 5bce415c9..b8c40efe4 100644 --- a/engine/source/runtime/function/framework/component/camera/camera_component.cpp +++ b/engine/source/runtime/function/framework/component/camera/camera_component.cpp @@ -15,7 +15,7 @@ #include "runtime/function/render/render_swap_context.h" #include "runtime/function/render/render_system.h" -namespace Pilot +namespace Piccolo { void CameraComponent::postLoadResource(std::weak_ptr parent_object) { @@ -143,4 +143,4 @@ namespace Pilot camera_swap_data.m_view_matrix = desired_mat; swap_context.getLogicSwapData().m_camera_swap_data = camera_swap_data; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/camera/camera_component.h b/engine/source/runtime/function/framework/component/camera/camera_component.h index 075f5aa4e..abaeb6013 100644 --- a/engine/source/runtime/function/framework/component/camera/camera_component.h +++ b/engine/source/runtime/function/framework/component/camera/camera_component.h @@ -6,7 +6,7 @@ #include "runtime/function/framework/component/component.h" -namespace Pilot +namespace Piccolo { class RenderCamera; @@ -44,4 +44,4 @@ namespace Pilot Vector3 m_up {Vector3::UNIT_Z}; Vector3 m_left {Vector3::UNIT_X}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/component.h b/engine/source/runtime/function/framework/component/component.h index 6f82478fc..eb3258ca5 100644 --- a/engine/source/runtime/function/framework/component/component.h +++ b/engine/source/runtime/function/framework/component/component.h @@ -1,7 +1,7 @@ #pragma once #include "runtime/core/meta/reflection/reflection.h" -namespace Pilot +namespace Piccolo { class GObject; // Component @@ -29,4 +29,4 @@ namespace Pilot bool m_tick_in_editor_mode {false}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/mesh/mesh_component.cpp b/engine/source/runtime/function/framework/component/mesh/mesh_component.cpp index 943af8acd..b43547956 100644 --- a/engine/source/runtime/function/framework/component/mesh/mesh_component.cpp +++ b/engine/source/runtime/function/framework/component/mesh/mesh_component.cpp @@ -11,7 +11,7 @@ #include "runtime/function/render/render_swap_context.h" #include "runtime/function/render/render_system.h" -namespace Pilot +namespace Piccolo { void MeshComponent::postLoadResource(std::weak_ptr parent_object) { @@ -102,4 +102,4 @@ namespace Pilot transform_component->setDirtyFlag(false); } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/mesh/mesh_component.h b/engine/source/runtime/function/framework/component/mesh/mesh_component.h index 5a77011ea..6c48f78f6 100644 --- a/engine/source/runtime/function/framework/component/mesh/mesh_component.h +++ b/engine/source/runtime/function/framework/component/mesh/mesh_component.h @@ -8,7 +8,7 @@ #include -namespace Pilot +namespace Piccolo { class RenderSwapContext; @@ -31,4 +31,4 @@ namespace Pilot std::vector m_raw_meshes; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/mesh/raw_mesh.h b/engine/source/runtime/function/framework/component/mesh/raw_mesh.h index 88bd29f4d..fc7e6fbc5 100644 --- a/engine/source/runtime/function/framework/component/mesh/raw_mesh.h +++ b/engine/source/runtime/function/framework/component/mesh/raw_mesh.h @@ -4,7 +4,7 @@ #include #include -namespace Pilot +namespace Piccolo { enum class PrimitiveType { @@ -43,4 +43,4 @@ namespace Pilot RawIndexBuffer index_buffer; MaterialTexture material_texture; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/motor/motor_component.cpp b/engine/source/runtime/function/framework/component/motor/motor_component.cpp index d5eec21b8..1ea15b523 100644 --- a/engine/source/runtime/function/framework/component/motor/motor_component.cpp +++ b/engine/source/runtime/function/framework/component/motor/motor_component.cpp @@ -12,8 +12,9 @@ #include "runtime/function/framework/world/world_manager.h" #include "runtime/function/global/global_context.h" #include "runtime/function/input/input_system.h" +#include "runtime/function/physics/physics_scene.h" -namespace Pilot +namespace Piccolo { void MotorComponent::postLoadResource(std::weak_ptr parent_object) { @@ -53,7 +54,7 @@ namespace Pilot if (!m_parent_object.lock()) return; - std::shared_ptr current_level = g_runtime_global_context.m_world_manager->getCurrentActiveLevel().lock(); + std::shared_ptr current_level = g_runtime_global_context.m_world_manager->getCurrentActiveLevel().lock(); std::shared_ptr current_character = current_level->getCurrentActiveCharacter().lock(); if (current_character == nullptr) return; @@ -114,7 +115,39 @@ namespace Pilot m_move_speed_ratio = std::clamp(m_move_speed_ratio, min_speed_ratio, max_speed_ratio); } - void MotorComponent::calculatedDesiredVerticalMoveSpeed(unsigned int command, float delta_time) {} + void MotorComponent::calculatedDesiredVerticalMoveSpeed(unsigned int command, float delta_time) + { + std::shared_ptr physics_scene = + g_runtime_global_context.m_world_manager->getCurrentActivePhysicsScene().lock(); + ASSERT(physics_scene); + + if (m_motor_res.m_jump_height == 0.f) + return; + + const float gravity = physics_scene->getGravity().length(); + + if (m_jump_state == JumpState::idle) + { + if ((unsigned int)GameCommand::jump & command) + { + m_jump_state = JumpState::rising; + m_vertical_move_speed = Math::sqrt(m_motor_res.m_jump_height * 2 * gravity); + m_jump_horizontal_speed_ratio = m_move_speed_ratio; + } + else + { + m_vertical_move_speed = 0.f; + } + } + else if (m_jump_state == JumpState::rising || m_jump_state == JumpState::falling) + { + m_vertical_move_speed -= gravity * delta_time; + if (m_vertical_move_speed <= 0.f) + { + m_jump_state = JumpState::falling; + } + } + } void MotorComponent::calculatedDesiredMoveDirection(unsigned int command, const Quaternion& object_rotation) { @@ -163,22 +196,23 @@ namespace Pilot void MotorComponent::calculateTargetPosition(const Vector3&& current_position) { - Vector3 final_position = current_position; + Vector3 final_position; switch (m_controller_type) { case ControllerType::none: - final_position += m_desired_displacement; + final_position = current_position + m_desired_displacement; break; case ControllerType::physics: - final_position = m_controller->move(final_position, m_desired_displacement); + final_position = m_controller->move(current_position, m_desired_displacement); break; default: + final_position = current_position; break; } - // Pilot-hack: motor level simulating jump, character always above z-plane - if (m_jump_state == JumpState::falling && m_target_position.z <= 0.f) + // Piccolo-hack: motor level simulating jump, character always above z-plane + if (m_jump_state == JumpState::falling && final_position.z + m_desired_displacement.z <= 0.f) { final_position.z = 0.f; m_jump_state = JumpState::idle; @@ -188,4 +222,4 @@ namespace Pilot m_target_position = final_position; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/motor/motor_component.h b/engine/source/runtime/function/framework/component/motor/motor_component.h index ff1237f31..6cd0a8804 100644 --- a/engine/source/runtime/function/framework/component/motor/motor_component.h +++ b/engine/source/runtime/function/framework/component/motor/motor_component.h @@ -5,7 +5,7 @@ #include "runtime/function/controller/character_controller.h" #include "runtime/function/framework/component/component.h" -namespace Pilot +namespace Piccolo { enum class MotorState : unsigned char { @@ -66,4 +66,4 @@ namespace Pilot bool m_is_moving {false}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/rigidbody/rigidbody_component.cpp b/engine/source/runtime/function/framework/component/rigidbody/rigidbody_component.cpp index 5e5f3f235..714f40c36 100644 --- a/engine/source/runtime/function/framework/component/rigidbody/rigidbody_component.cpp +++ b/engine/source/runtime/function/framework/component/rigidbody/rigidbody_component.cpp @@ -9,7 +9,7 @@ #include "runtime/function/physics/physics_scene.h" #include "runtime/function/physics/physics_system.h" -namespace Pilot +namespace Piccolo { void RigidBodyComponent::postLoadResource(std::weak_ptr parent_object) { @@ -53,6 +53,15 @@ namespace Pilot void RigidBodyComponent::updateGlobalTransform(const Transform& transform) { m_physics_actor->setGlobalTransform(transform); + + // these code intended to fix transform of rigid bodies, but + // in JoltPhysics it removes local transform of shapes... + // so currently rigid bodies cannot be transformed + //std::shared_ptr physics_scene = + // g_runtime_global_context.m_world_manager->getCurrentActivePhysicsScene().lock(); + //ASSERT(physics_scene); + + //physics_scene->updateRigidBodyGlobalTransform(m_physics_actor->getBodyID(), transform); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/rigidbody/rigidbody_component.h b/engine/source/runtime/function/framework/component/rigidbody/rigidbody_component.h index e5cb9e8ad..3d9ad5c70 100644 --- a/engine/source/runtime/function/framework/component/rigidbody/rigidbody_component.h +++ b/engine/source/runtime/function/framework/component/rigidbody/rigidbody_component.h @@ -5,7 +5,7 @@ #include "runtime/function/framework/component/component.h" #include "runtime/function/physics/physics_actor.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(RigidBodyComponent) CLASS(RigidBodyComponent : public Component, WhiteListFields) @@ -26,4 +26,4 @@ namespace Pilot PhysicsActor* m_physics_actor {nullptr}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/component/transform/transform_component.cpp b/engine/source/runtime/function/framework/component/transform/transform_component.cpp index 771a6d4fa..febafaf03 100644 --- a/engine/source/runtime/function/framework/component/transform/transform_component.cpp +++ b/engine/source/runtime/function/framework/component/transform/transform_component.cpp @@ -3,7 +3,7 @@ #include "runtime/engine.h" #include "runtime/function/framework/component/rigidbody/rigidbody_component.h" -namespace Pilot +namespace Piccolo { void TransformComponent::postLoadResource(std::weak_ptr parent_gobject) { @@ -62,4 +62,4 @@ namespace Pilot } } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/framework/component/transform/transform_component.h b/engine/source/runtime/function/framework/component/transform/transform_component.h index 7b2478723..56ab0374a 100644 --- a/engine/source/runtime/function/framework/component/transform/transform_component.h +++ b/engine/source/runtime/function/framework/component/transform/transform_component.h @@ -6,7 +6,7 @@ #include "runtime/function/framework/component/component.h" #include "runtime/function/framework/object/object.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(TransformComponent) CLASS(TransformComponent : public Component, WhiteListFields) @@ -45,4 +45,4 @@ namespace Pilot size_t m_current_index {0}; size_t m_next_index {1}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/level/level.cpp b/engine/source/runtime/function/framework/level/level.cpp index e7c94eff6..aaa18c4a8 100644 --- a/engine/source/runtime/function/framework/level/level.cpp +++ b/engine/source/runtime/function/framework/level/level.cpp @@ -13,7 +13,7 @@ #include -namespace Pilot +namespace Piccolo { Level::~Level() { clear(); } @@ -68,7 +68,7 @@ namespace Pilot } ASSERT(g_runtime_global_context.m_physics_manager); - m_physics_scene = g_runtime_global_context.m_physics_manager->createPhysicsScene(); + m_physics_scene = g_runtime_global_context.m_physics_manager->createPhysicsScene(level_res.m_gravity); for (const ObjectInstanceRes& object_instance_res : level_res.m_objects) { @@ -192,4 +192,4 @@ namespace Pilot m_gobjects.erase(go_id); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/level/level.h b/engine/source/runtime/function/framework/level/level.h index 80c501aa3..d674b1e90 100644 --- a/engine/source/runtime/function/framework/level/level.h +++ b/engine/source/runtime/function/framework/level/level.h @@ -6,7 +6,7 @@ #include #include -namespace Pilot +namespace Piccolo { class Character; class GObject; @@ -53,4 +53,4 @@ namespace Pilot std::weak_ptr m_physics_scene; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/object/object.cpp b/engine/source/runtime/function/framework/object/object.cpp index 357fcf73b..5380fc76a 100644 --- a/engine/source/runtime/function/framework/object/object.cpp +++ b/engine/source/runtime/function/framework/object/object.cpp @@ -15,7 +15,7 @@ #include "_generated/serializer/all_serializer.h" -namespace Pilot +namespace Piccolo { bool shouldComponentTick(std::string component_type_name) { @@ -33,7 +33,7 @@ namespace Pilot { for (auto& component : m_components) { - PILOT_REFLECTION_DELETE(component); + PICCOLO_REFLECTION_DELETE(component); } m_components.clear(); } @@ -109,4 +109,4 @@ namespace Pilot out_object_instance_res.m_instanced_components = m_components; } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/framework/object/object.h b/engine/source/runtime/function/framework/object/object.h index 6962ae856..6d7571918 100644 --- a/engine/source/runtime/function/framework/object/object.h +++ b/engine/source/runtime/function/framework/object/object.h @@ -10,7 +10,7 @@ #include #include -namespace Pilot +namespace Piccolo { /// GObject : Game Object base class class GObject : public std::enable_shared_from_this @@ -74,4 +74,4 @@ namespace Pilot // in editor, and it's polymorphism std::vector> m_components; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/object/object_id_allocator.cpp b/engine/source/runtime/function/framework/object/object_id_allocator.cpp index 8c11abeef..9d5b80b0d 100644 --- a/engine/source/runtime/function/framework/object/object_id_allocator.cpp +++ b/engine/source/runtime/function/framework/object/object_id_allocator.cpp @@ -2,7 +2,7 @@ #include "core/base/macro.h" -namespace Pilot +namespace Piccolo { std::atomic ObjectIDAllocator::m_next_id {0}; @@ -18,4 +18,4 @@ namespace Pilot return new_object_ret; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/object/object_id_allocator.h b/engine/source/runtime/function/framework/object/object_id_allocator.h index 55e643b1b..bd7ffbe36 100644 --- a/engine/source/runtime/function/framework/object/object_id_allocator.h +++ b/engine/source/runtime/function/framework/object/object_id_allocator.h @@ -3,7 +3,7 @@ #include #include -namespace Pilot +namespace Piccolo { using GObjectID = std::size_t; @@ -17,4 +17,4 @@ namespace Pilot private: static std::atomic m_next_id; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/world/world_manager.cpp b/engine/source/runtime/function/framework/world/world_manager.cpp index 25172338f..dc819430b 100644 --- a/engine/source/runtime/function/framework/world/world_manager.cpp +++ b/engine/source/runtime/function/framework/world/world_manager.cpp @@ -10,7 +10,7 @@ #include "_generated/serializer/all_serializer.h" -namespace Pilot +namespace Piccolo { WorldManager::~WorldManager() { clear(); } @@ -151,4 +151,4 @@ namespace Pilot active_level->save(); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/framework/world/world_manager.h b/engine/source/runtime/function/framework/world/world_manager.h index 5ce72b892..ccbc43581 100644 --- a/engine/source/runtime/function/framework/world/world_manager.h +++ b/engine/source/runtime/function/framework/world/world_manager.h @@ -5,7 +5,7 @@ #include #include -namespace Pilot +namespace Piccolo { class Level; class PhysicsScene; @@ -41,4 +41,4 @@ namespace Pilot // active level, currently we just support one active level std::weak_ptr m_current_active_level; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/global/global_context.cpp b/engine/source/runtime/function/global/global_context.cpp index 83c47ff54..594aa9dfa 100644 --- a/engine/source/runtime/function/global/global_context.cpp +++ b/engine/source/runtime/function/global/global_context.cpp @@ -17,7 +17,7 @@ #include "runtime/function/render/render_system.h" #include "runtime/function/render/window_system.h" -namespace Pilot +namespace Piccolo { RuntimeGlobalContext g_runtime_global_context; @@ -79,4 +79,4 @@ namespace Pilot m_config_manager.reset(); } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/global/global_context.h b/engine/source/runtime/function/global/global_context.h index c30f31f5d..bbed5ff86 100644 --- a/engine/source/runtime/function/global/global_context.h +++ b/engine/source/runtime/function/global/global_context.h @@ -3,7 +3,7 @@ #include #include -namespace Pilot +namespace Piccolo { class LogSystem; class InputSystem; @@ -41,4 +41,4 @@ namespace Pilot }; extern RuntimeGlobalContext g_runtime_global_context; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/input/input_system.cpp b/engine/source/runtime/function/input/input_system.cpp index 6f8d82a68..ba15534b5 100644 --- a/engine/source/runtime/function/input/input_system.cpp +++ b/engine/source/runtime/function/input/input_system.cpp @@ -10,7 +10,7 @@ #include -namespace Pilot +namespace Piccolo { unsigned int k_complement_control_command = 0xFFFFFFFF; @@ -24,6 +24,8 @@ namespace Pilot void InputSystem::onKeyInGameMode(int key, int scancode, int action, int mods) { + m_game_command &= (k_complement_control_command ^ (unsigned int)GameCommand::jump); + if (action == GLFW_PRESS) { switch (key) @@ -45,6 +47,9 @@ namespace Pilot case GLFW_KEY_D: m_game_command |= (unsigned int)GameCommand::right; break; + case GLFW_KEY_SPACE: + m_game_command |= (unsigned int)GameCommand::jump; + break; case GLFW_KEY_LEFT_CONTROL: m_game_command |= (unsigned int)GameCommand::squat; break; @@ -159,4 +164,4 @@ namespace Pilot m_game_command |= (unsigned int)GameCommand::invalid; } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/input/input_system.h b/engine/source/runtime/function/input/input_system.h index f567a9af7..edea5df8e 100644 --- a/engine/source/runtime/function/input/input_system.h +++ b/engine/source/runtime/function/input/input_system.h @@ -2,7 +2,7 @@ #include "runtime/core/math/math.h" -namespace Pilot +namespace Piccolo { enum class GameCommand : unsigned int { @@ -10,7 +10,7 @@ namespace Pilot backward = 1 << 1, // S left = 1 << 2, // A right = 1 << 3, // D - jump = 1 << 4, // not implemented yet + jump = 1 << 4, // SPACE squat = 1 << 5, // not implemented yet sprint = 1 << 6, // LEFT SHIFT fire = 1 << 7, // not implemented yet @@ -19,7 +19,7 @@ namespace Pilot extern unsigned int k_complement_control_command; - class InputSystem + class InputSystem { public: @@ -36,7 +36,7 @@ namespace Pilot Radian m_cursor_delta_yaw {0}; Radian m_cursor_delta_pitch {0}; - void resetGameCommand() { m_game_command = 0; } + void resetGameCommand() { m_game_command = 0; } unsigned int getGameCommand() const { return m_game_command; } private: @@ -49,4 +49,4 @@ namespace Pilot int m_last_cursor_x {0}; int m_last_cursor_y {0}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/physics/collision_detection.cpp b/engine/source/runtime/function/physics/collision_detection.cpp index 857f87c21..3e93a0d50 100644 --- a/engine/source/runtime/function/physics/collision_detection.cpp +++ b/engine/source/runtime/function/physics/collision_detection.cpp @@ -1,6 +1,6 @@ #include "runtime/function/physics/collision_detection.h" -namespace Pilot +namespace Piccolo { CollisionDetection::CollisionDetection() {} @@ -560,4 +560,4 @@ namespace Pilot return true; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/physics/collision_detection.h b/engine/source/runtime/function/physics/collision_detection.h index 53dd15c81..2a23a0663 100644 --- a/engine/source/runtime/function/physics/collision_detection.h +++ b/engine/source/runtime/function/physics/collision_detection.h @@ -6,7 +6,7 @@ #include "runtime/function/physics/physics_actor.h" #include "runtime/function/physics/ray.h" -namespace Pilot +namespace Piccolo { struct ContactPoint { @@ -109,4 +109,4 @@ namespace Pilot float sphere_radius, RayCollision& collision); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/physics/jolt/utils.cpp b/engine/source/runtime/function/physics/jolt/utils.cpp index 8a72de0ef..67ad36409 100644 --- a/engine/source/runtime/function/physics/jolt/utils.cpp +++ b/engine/source/runtime/function/physics/jolt/utils.cpp @@ -7,7 +7,7 @@ #include "Jolt/Physics/Collision/Shape/SphereShape.h" #include "Jolt/Physics/Collision/Shape/StaticCompoundShape.h" -namespace Pilot +namespace Piccolo { BPLayerInterfaceImpl::BPLayerInterfaceImpl() { @@ -154,4 +154,4 @@ namespace Pilot return jph_shape; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/physics/jolt/utils.h b/engine/source/runtime/function/physics/jolt/utils.h index 5174bbd4d..238bba561 100644 --- a/engine/source/runtime/function/physics/jolt/utils.h +++ b/engine/source/runtime/function/physics/jolt/utils.h @@ -14,7 +14,7 @@ namespace JPH class Shape; } -namespace Pilot +namespace Piccolo { class RigidBodyShape; @@ -86,4 +86,4 @@ namespace Pilot JPH::Shape* toShape(const RigidBodyShape& shape, const Vector3& scale); -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/physics/physics_aabb_shape.h b/engine/source/runtime/function/physics/physics_aabb_shape.h index 655092d34..9c377c4a1 100644 --- a/engine/source/runtime/function/physics/physics_aabb_shape.h +++ b/engine/source/runtime/function/physics/physics_aabb_shape.h @@ -4,7 +4,7 @@ #include "runtime/function/physics/physics_shape_base.h" -namespace Pilot +namespace Piccolo { class PhysicsAABBShape : public PhysicsShapeBase { @@ -20,4 +20,4 @@ namespace Pilot private: Vector3 m_half_dimensions; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/physics/physics_actor.cpp b/engine/source/runtime/function/physics/physics_actor.cpp index 6c228ce36..c1b3718bb 100644 --- a/engine/source/runtime/function/physics/physics_actor.cpp +++ b/engine/source/runtime/function/physics/physics_actor.cpp @@ -5,7 +5,7 @@ #include "runtime/function/framework/component/transform/transform_component.h" #include "runtime/function/framework/object/object.h" -namespace Pilot +namespace Piccolo { PhysicsActor::PhysicsActor(std::weak_ptr gobject, const Transform& global_transform) : m_parent_object {gobject}, m_global_transform {global_transform} @@ -143,4 +143,4 @@ namespace Pilot } } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/physics/physics_actor.h b/engine/source/runtime/function/physics/physics_actor.h index 0fbd3cd07..47630ab7a 100644 --- a/engine/source/runtime/function/physics/physics_actor.h +++ b/engine/source/runtime/function/physics/physics_actor.h @@ -8,7 +8,7 @@ #include -namespace Pilot +namespace Piccolo { class GObject; class PhysicsActor @@ -81,4 +81,4 @@ namespace Pilot uint32_t m_body_id{0xffffffff}; }; -}; // namespace Pilot +}; // namespace Piccolo diff --git a/engine/source/runtime/function/physics/physics_config.h b/engine/source/runtime/function/physics/physics_config.h index ee25f0aa8..8ae4f021c 100644 --- a/engine/source/runtime/function/physics/physics_config.h +++ b/engine/source/runtime/function/physics/physics_config.h @@ -4,7 +4,7 @@ #include "core/math/vector3.h" -namespace Pilot +namespace Piccolo { class PhysicsConfig { @@ -24,4 +24,4 @@ namespace Pilot float m_update_frequency {60.f}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/physics/physics_manager.cpp b/engine/source/runtime/function/physics/physics_manager.cpp index d025a69cd..0a72065e0 100644 --- a/engine/source/runtime/function/physics/physics_manager.cpp +++ b/engine/source/runtime/function/physics/physics_manager.cpp @@ -17,7 +17,7 @@ #include "TestFramework/Utils/Log.h" #endif -namespace Pilot +namespace Piccolo { void PhysicsManager::initialize() { @@ -48,10 +48,9 @@ namespace Pilot #endif } - std::weak_ptr PhysicsManager::createPhysicsScene() + std::weak_ptr PhysicsManager::createPhysicsScene(const Vector3& gravity) { - - std::shared_ptr physics_scene = std::make_shared(); + std::shared_ptr physics_scene = std::make_shared(gravity); m_scenes.push_back(physics_scene); @@ -118,4 +117,4 @@ namespace Pilot m_renderer->EndFrame(); } #endif -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/physics/physics_manager.h b/engine/source/runtime/function/physics/physics_manager.h index 4091e9169..c61a1d14d 100644 --- a/engine/source/runtime/function/physics/physics_manager.h +++ b/engine/source/runtime/function/physics/physics_manager.h @@ -1,5 +1,7 @@ #pragma once +#include "runtime/core/math/vector3.h" + #include #include @@ -13,7 +15,7 @@ namespace JPH } #endif -namespace Pilot +namespace Piccolo { class PhysicsScene; @@ -23,14 +25,13 @@ namespace Pilot void initialize(); void clear(); - std::weak_ptr createPhysicsScene(); + std::weak_ptr createPhysicsScene(const Vector3& gravity); void deletePhysicsScene(std::weak_ptr physics_scene); #ifdef ENABLE_PHYSICS_DEBUG_RENDERER void renderPhysicsWorld(float delta_time); #endif - protected: std::vector> m_scenes; @@ -40,6 +41,5 @@ namespace Pilot JPH::DebugRenderer* m_debug_renderer {nullptr}; #endif - }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/physics/physics_obb_shape.h b/engine/source/runtime/function/physics/physics_obb_shape.h index 340b4db4f..c5c30d8f7 100644 --- a/engine/source/runtime/function/physics/physics_obb_shape.h +++ b/engine/source/runtime/function/physics/physics_obb_shape.h @@ -4,7 +4,7 @@ #include "runtime/core/math/vector3.h" -namespace Pilot +namespace Piccolo { class PhysicsOBBShape : public PhysicsShapeBase { @@ -19,4 +19,4 @@ namespace Pilot private: Vector3 m_half_dimensions; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/physics/physics_scene.cpp b/engine/source/runtime/function/physics/physics_scene.cpp index 9d81b8c64..5d35724a0 100644 --- a/engine/source/runtime/function/physics/physics_scene.cpp +++ b/engine/source/runtime/function/physics/physics_scene.cpp @@ -22,15 +22,16 @@ #include "Jolt/Physics/Collision/NarrowPhaseQuery.h" #include "Jolt/Physics/Collision/RayCast.h" #include "Jolt/Physics/Collision/Shape/BoxShape.h" +#include "Jolt/Physics/Collision/Shape/CapsuleShape.h" +#include "Jolt/Physics/Collision/Shape/SphereShape.h" #include "Jolt/Physics/Collision/Shape/StaticCompoundShape.h" #include "Jolt/Physics/Collision/ShapeCast.h" #include "Jolt/Physics/PhysicsSystem.h" -namespace Pilot +namespace Piccolo { - PhysicsScene::PhysicsScene() + PhysicsScene::PhysicsScene(const Vector3& gravity) { - static_assert(k_invalid_rigidbody_id == JPH::BodyID::cInvalidBodyID); JPH::Factory::sInstance = new JPH::Factory(); @@ -57,8 +58,8 @@ namespace Pilot // use the default setting m_physics.m_jolt_physics_system->SetPhysicsSettings(JPH::PhysicsSettings()); - m_physics.m_jolt_physics_system->SetGravity( - JPH::Vec3(m_config.m_gravity.x, m_config.m_gravity.y, m_config.m_gravity.z)); + m_physics.m_jolt_physics_system->SetGravity(toVec3(gravity)); + m_config.m_gravity = gravity; } PhysicsScene::~PhysicsScene() @@ -164,6 +165,16 @@ namespace Pilot void PhysicsScene::removeRigidBody(uint32_t body_id) { m_pending_remove_bodies.push_back(body_id); } + void PhysicsScene::updateRigidBodyGlobalTransform(uint32_t body_id, const Transform& global_transform) + { + JPH::BodyInterface& body_interface = m_physics.m_jolt_physics_system->GetBodyInterface(); + + body_interface.SetPositionAndRotation(JPH::BodyID(body_id), + toVec3(global_transform.m_position), + toQuat(global_transform.m_rotation), + JPH::EActivation::Activate); + } + void PhysicsScene::tick(float delta_time) { const float time_step = 1.f / m_config.m_update_frequency; @@ -282,7 +293,7 @@ namespace Pilot PhysicsHitInfo& hit = out_hits[index]; hit.hit_position = toVec3(sweep_result.mContactPointOn2); hit.hit_normal = toVec3(sweep_result.mPenetrationAxis.Normalized()); - hit.hit_distance = (hit.hit_position - global_position).length(); + hit.hit_distance = sweep_result.mFraction * sweep_length; hit.body_id = sweep_result.mBodyID2.GetIndexAndSequenceNumber(); } @@ -307,11 +318,14 @@ namespace Pilot return false; } - JPH::AllHitCollisionCollector collector; - scene_query.CollideShape( - jph_shape, JPH::Vec3::sReplicate(1.0f), toMat44(global_transform), JPH::CollideShapeSettings(), collector); + JPH::AnyHitCollisionCollector collector; + scene_query.CollideShape(jph_shape, + JPH::Vec3::sReplicate(1.0f), + toMat44(shape_global_transform), + JPH::CollideShapeSettings(), + collector); - return !collector.mHits.empty(); + return collector.HadHit(); } #ifdef ENABLE_PHYSICS_DEBUG_RENDERER @@ -324,4 +338,4 @@ namespace Pilot } #endif -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/physics/physics_scene.h b/engine/source/runtime/function/physics/physics_scene.h index 000146357..404dc7f12 100644 --- a/engine/source/runtime/function/physics/physics_scene.h +++ b/engine/source/runtime/function/physics/physics_scene.h @@ -13,7 +13,7 @@ namespace JPH #endif } // namespace JPH -namespace Pilot +namespace Piccolo { class Transform; class RigidBodyComponentRes; @@ -43,33 +43,37 @@ namespace Pilot }; public: - PhysicsScene(); + PhysicsScene(const Vector3& gravity); virtual ~PhysicsScene(); + const Vector3& getGravity() const { return m_config.m_gravity; } + uint32_t createRigidBody(const Transform& global_transform, const RigidBodyComponentRes& rigidbody_actor_res); void removeRigidBody(uint32_t body_id); + void updateRigidBodyGlobalTransform(uint32_t body_id, const Transform& global_transform); + void tick(float delta_time); /// cast a ray and find the hits /// @ray_origin: origin of ray - /// @ray_directory: ray directory + /// @ray_direction: ray direction /// @ray_length: ray length, anything beyond this length will not be reported as a hit /// @out_hits: the found hits, sorted by distance /// @return: true if any hits found, else false bool - raycast(Vector3 ray_origin, Vector3 ray_directory, float ray_length, std::vector& out_hits); + raycast(Vector3 ray_origin, Vector3 ray_direction, float ray_length, std::vector& out_hits); /// cast a shape and find the hits /// @shape: the casted rigidbody shape /// @shape_transform: the initial global transform of the casted shape - /// @sweep_directory: sweep directory + /// @sweep_direction: sweep direction /// @sweep_length: sweep length, anything beyond this length will not be reported as a hit /// @out_hits: the found hits, sorted by distance /// @return: true if any hits found, else false bool sweep(const RigidBodyShape& shape, const Matrix4x4& shape_transform, - Vector3 sweep_directory, + Vector3 sweep_direction, float sweep_length, std::vector& out_hits); @@ -90,4 +94,4 @@ namespace Pilot std::vector m_pending_remove_bodies; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/physics/physics_shape_base.h b/engine/source/runtime/function/physics/physics_shape_base.h index 08045b875..01a37cc65 100644 --- a/engine/source/runtime/function/physics/physics_shape_base.h +++ b/engine/source/runtime/function/physics/physics_shape_base.h @@ -2,7 +2,7 @@ #include "runtime/core/math/transform.h" -namespace Pilot +namespace Piccolo { enum class ShapeType { @@ -28,4 +28,4 @@ namespace Pilot ShapeType m_type {ShapeType::invalid}; Transform m_local_transform ; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/physics/physics_sphere_shape.h b/engine/source/runtime/function/physics/physics_sphere_shape.h index 7e3551fe2..815f7eb56 100644 --- a/engine/source/runtime/function/physics/physics_sphere_shape.h +++ b/engine/source/runtime/function/physics/physics_sphere_shape.h @@ -2,7 +2,7 @@ #include "runtime/function/physics/physics_shape_base.h" -namespace Pilot +namespace Piccolo { class PhysicsSphereShape : public PhysicsShapeBase { @@ -18,4 +18,4 @@ namespace Pilot private: float m_radius {0.f}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/physics/physics_system.cpp b/engine/source/runtime/function/physics/physics_system.cpp index f1985e2fd..32db24f50 100644 --- a/engine/source/runtime/function/physics/physics_system.cpp +++ b/engine/source/runtime/function/physics/physics_system.cpp @@ -7,7 +7,7 @@ #include -namespace Pilot +namespace Piccolo { void PhysicsSystem::tick(float delta_time) { @@ -298,4 +298,4 @@ namespace Pilot actor_a.applyAngularImpulse(relative_a.crossProduct(-fullImpulse)); actor_b.applyAngularImpulse(relative_b.crossProduct(fullImpulse)); } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/physics/physics_system.h b/engine/source/runtime/function/physics/physics_system.h index c6a06ca6c..d9e13f873 100644 --- a/engine/source/runtime/function/physics/physics_system.h +++ b/engine/source/runtime/function/physics/physics_system.h @@ -9,7 +9,7 @@ #include -namespace Pilot +namespace Piccolo { /// This Physics System is legacy, will be removed lated class PhysicsSystem @@ -55,4 +55,4 @@ namespace Pilot Vector3 m_gravity {0.0f, 0.0f, -9.8f}; bool m_is_use_gravity {true}; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/physics/ray.cpp b/engine/source/runtime/function/physics/ray.cpp index 741711813..364d71750 100644 --- a/engine/source/runtime/function/physics/ray.cpp +++ b/engine/source/runtime/function/physics/ray.cpp @@ -1,6 +1,6 @@ #include "runtime/function/physics/ray.h" -namespace Pilot +namespace Piccolo { Ray::Ray(Vector3 start_point, Vector3 direction) { @@ -14,4 +14,4 @@ namespace Pilot Vector3 Ray::getDirection() const { return m_direction; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/physics/ray.h b/engine/source/runtime/function/physics/ray.h index 40ed89719..73211240c 100644 --- a/engine/source/runtime/function/physics/ray.h +++ b/engine/source/runtime/function/physics/ray.h @@ -2,7 +2,7 @@ #include "runtime/core/math/vector3.h" -namespace Pilot +namespace Piccolo { struct RayCollision { @@ -37,4 +37,4 @@ namespace Pilot Vector3 m_start_point; Vector3 m_direction; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/render/glm_wrapper.h b/engine/source/runtime/function/render/glm_wrapper.h index b7fcfd052..b75c74654 100644 --- a/engine/source/runtime/function/render/glm_wrapper.h +++ b/engine/source/runtime/function/render/glm_wrapper.h @@ -13,7 +13,7 @@ #include #include -namespace Pilot +namespace Piccolo { class GLMUtil { @@ -70,4 +70,4 @@ namespace Pilot m[2][3], m[3][3]}; } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/render/light.h b/engine/source/runtime/function/render/light.h index 30ac03564..eb9abbaae 100644 --- a/engine/source/runtime/function/render/light.h +++ b/engine/source/runtime/function/render/light.h @@ -6,7 +6,7 @@ #include -namespace Pilot +namespace Piccolo { struct PointLight { @@ -68,4 +68,4 @@ namespace Pilot std::shared_ptr m_buffer; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/render/passes/color_grading_pass.cpp b/engine/source/runtime/function/render/passes/color_grading_pass.cpp index d3269adc9..22ffad59d 100644 --- a/engine/source/runtime/function/render/passes/color_grading_pass.cpp +++ b/engine/source/runtime/function/render/passes/color_grading_pass.cpp @@ -8,7 +8,7 @@ #include -namespace Pilot +namespace Piccolo { void ColorGradingPass::initialize(const RenderPassInitInfo* init_info) { @@ -287,4 +287,4 @@ namespace Pilot m_vulkan_rhi->m_vk_cmd_end_debug_utils_label_ext(m_vulkan_rhi->m_current_command_buffer); } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/color_grading_pass.h b/engine/source/runtime/function/render/passes/color_grading_pass.h index 44447a0de..0ec4b54f6 100644 --- a/engine/source/runtime/function/render/passes/color_grading_pass.h +++ b/engine/source/runtime/function/render/passes/color_grading_pass.h @@ -2,7 +2,7 @@ #include "runtime/function/render/render_pass.h" -namespace Pilot +namespace Piccolo { struct ColorGradingPassInitInfo : RenderPassInitInfo { @@ -23,4 +23,4 @@ namespace Pilot void setupPipelines(); void setupDescriptorSet(); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/combine_ui_pass.cpp b/engine/source/runtime/function/render/passes/combine_ui_pass.cpp index 4494cd334..44ff90442 100644 --- a/engine/source/runtime/function/render/passes/combine_ui_pass.cpp +++ b/engine/source/runtime/function/render/passes/combine_ui_pass.cpp @@ -8,7 +8,7 @@ #include -namespace Pilot +namespace Piccolo { void CombineUIPass::initialize(const RenderPassInitInfo* init_info) { @@ -295,4 +295,4 @@ namespace Pilot m_vulkan_rhi->m_vk_cmd_end_debug_utils_label_ext(m_vulkan_rhi->m_current_command_buffer); } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/combine_ui_pass.h b/engine/source/runtime/function/render/passes/combine_ui_pass.h index d0558b7e6..61464f6dc 100644 --- a/engine/source/runtime/function/render/passes/combine_ui_pass.h +++ b/engine/source/runtime/function/render/passes/combine_ui_pass.h @@ -2,7 +2,7 @@ #include "runtime/function/render/render_pass.h" -namespace Pilot +namespace Piccolo { struct CombineUIPassInitInfo : RenderPassInitInfo { @@ -24,4 +24,4 @@ namespace Pilot void setupPipelines(); void setupDescriptorSet(); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/directional_light_pass.cpp b/engine/source/runtime/function/render/passes/directional_light_pass.cpp index fefa33c5d..c99e02232 100644 --- a/engine/source/runtime/function/render/passes/directional_light_pass.cpp +++ b/engine/source/runtime/function/render/passes/directional_light_pass.cpp @@ -10,7 +10,7 @@ #include -namespace Pilot +namespace Piccolo { void DirectionalLightShadowPass::initialize(const RenderPassInitInfo* init_info) { @@ -733,4 +733,4 @@ namespace Pilot m_vulkan_rhi->m_vk_cmd_end_render_pass(m_vulkan_rhi->m_current_command_buffer); } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/directional_light_pass.h b/engine/source/runtime/function/render/passes/directional_light_pass.h index a0020ad6f..504b9a9c1 100644 --- a/engine/source/runtime/function/render/passes/directional_light_pass.h +++ b/engine/source/runtime/function/render/passes/directional_light_pass.h @@ -2,7 +2,7 @@ #include "runtime/function/render/render_pass.h" -namespace Pilot +namespace Piccolo { class RenderResourceBase; @@ -30,4 +30,4 @@ namespace Pilot MeshDirectionalLightShadowPerframeStorageBufferObject m_mesh_directional_light_shadow_perframe_storage_buffer_object; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/fxaa_pass.cpp b/engine/source/runtime/function/render/passes/fxaa_pass.cpp index 164d77e9a..b8ad2186a 100644 --- a/engine/source/runtime/function/render/passes/fxaa_pass.cpp +++ b/engine/source/runtime/function/render/passes/fxaa_pass.cpp @@ -13,7 +13,7 @@ #include #include -namespace Pilot +namespace Piccolo { void FXAAPass::initialize(const RenderPassInitInfo* init_info) { @@ -283,4 +283,4 @@ namespace Pilot } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/fxaa_pass.h b/engine/source/runtime/function/render/passes/fxaa_pass.h index 0f00ac344..f351fe8c2 100644 --- a/engine/source/runtime/function/render/passes/fxaa_pass.h +++ b/engine/source/runtime/function/render/passes/fxaa_pass.h @@ -2,7 +2,7 @@ #include "runtime/function/render/render_pass.h" -namespace Pilot +namespace Piccolo { class WindowUI; @@ -25,4 +25,4 @@ namespace Pilot void setupPipelines(); void setupDescriptorSet(); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/main_camera_pass.cpp b/engine/source/runtime/function/render/passes/main_camera_pass.cpp index 9e756945f..25fdd96ad 100644 --- a/engine/source/runtime/function/render/passes/main_camera_pass.cpp +++ b/engine/source/runtime/function/render/passes/main_camera_pass.cpp @@ -21,7 +21,7 @@ #include #include -namespace Pilot +namespace Piccolo { void MainCameraPass::initialize(const RenderPassInitInfo* init_info) { @@ -3163,4 +3163,4 @@ namespace Pilot m_vulkan_rhi->m_vk_cmd_end_debug_utils_label_ext(m_vulkan_rhi->m_current_command_buffer); } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/main_camera_pass.h b/engine/source/runtime/function/render/passes/main_camera_pass.h index 9a3debd33..69bee84ca 100644 --- a/engine/source/runtime/function/render/passes/main_camera_pass.h +++ b/engine/source/runtime/function/render/passes/main_camera_pass.h @@ -8,7 +8,7 @@ #include "runtime/function/render/passes/tone_mapping_pass.h" #include "runtime/function/render/passes/ui_pass.h" -namespace Pilot +namespace Piccolo { class RenderResourceBase; @@ -109,4 +109,4 @@ namespace Pilot private: std::vector m_swapchain_framebuffers; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/pick_pass.cpp b/engine/source/runtime/function/render/passes/pick_pass.cpp index a802f3dac..f43d9fa47 100644 --- a/engine/source/runtime/function/render/passes/pick_pass.cpp +++ b/engine/source/runtime/function/render/passes/pick_pass.cpp @@ -15,7 +15,7 @@ #include #include -namespace Pilot +namespace Piccolo { void PickPass::initialize(const RenderPassInitInfo* init_info) { @@ -852,4 +852,4 @@ namespace Pilot return node_id; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/pick_pass.h b/engine/source/runtime/function/render/passes/pick_pass.h index 9f5d59b10..c05f4d2f3 100644 --- a/engine/source/runtime/function/render/passes/pick_pass.h +++ b/engine/source/runtime/function/render/passes/pick_pass.h @@ -3,7 +3,7 @@ #include "runtime/core/math/vector2.h" #include "runtime/function/render/render_pass.h" -namespace Pilot +namespace Piccolo { class RenderResourceBase; @@ -40,4 +40,4 @@ namespace Pilot VkDescriptorSetLayout _per_mesh_layout {VK_NULL_HANDLE}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/point_light_pass.cpp b/engine/source/runtime/function/render/passes/point_light_pass.cpp index d7a0b8e48..42f2baac2 100644 --- a/engine/source/runtime/function/render/passes/point_light_pass.cpp +++ b/engine/source/runtime/function/render/passes/point_light_pass.cpp @@ -13,7 +13,7 @@ #include #include -namespace Pilot +namespace Piccolo { void PointLightShadowPass::initialize(const RenderPassInitInfo* init_info) { @@ -741,4 +741,4 @@ namespace Pilot m_vulkan_rhi->m_vk_cmd_end_render_pass(m_vulkan_rhi->m_current_command_buffer); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/point_light_pass.h b/engine/source/runtime/function/render/passes/point_light_pass.h index b4533b64c..381727b5a 100644 --- a/engine/source/runtime/function/render/passes/point_light_pass.h +++ b/engine/source/runtime/function/render/passes/point_light_pass.h @@ -2,7 +2,7 @@ #include "runtime/function/render/render_pass.h" -namespace Pilot +namespace Piccolo { class RenderResourceBase; @@ -29,4 +29,4 @@ namespace Pilot VkDescriptorSetLayout m_per_mesh_layout; MeshPointLightShadowPerframeStorageBufferObject m_mesh_point_light_shadow_perframe_storage_buffer_object; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/tone_mapping_pass.cpp b/engine/source/runtime/function/render/passes/tone_mapping_pass.cpp index 643f94fac..a972b16a0 100644 --- a/engine/source/runtime/function/render/passes/tone_mapping_pass.cpp +++ b/engine/source/runtime/function/render/passes/tone_mapping_pass.cpp @@ -8,7 +8,7 @@ #include -namespace Pilot +namespace Piccolo { void ToneMappingPass::initialize(const RenderPassInitInfo* init_info) { @@ -262,4 +262,4 @@ namespace Pilot m_vulkan_rhi->m_vk_cmd_end_debug_utils_label_ext(m_vulkan_rhi->m_current_command_buffer); } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/tone_mapping_pass.h b/engine/source/runtime/function/render/passes/tone_mapping_pass.h index 873172f6f..bbc0e5a72 100644 --- a/engine/source/runtime/function/render/passes/tone_mapping_pass.h +++ b/engine/source/runtime/function/render/passes/tone_mapping_pass.h @@ -2,7 +2,7 @@ #include "runtime/function/render/render_pass.h" -namespace Pilot +namespace Piccolo { struct ToneMappingPassInitInfo : RenderPassInitInfo { @@ -23,4 +23,4 @@ namespace Pilot void setupPipelines(); void setupDescriptorSet(); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/ui_pass.cpp b/engine/source/runtime/function/render/passes/ui_pass.cpp index f703ff374..f7d94ac17 100644 --- a/engine/source/runtime/function/render/passes/ui_pass.cpp +++ b/engine/source/runtime/function/render/passes/ui_pass.cpp @@ -11,7 +11,7 @@ #include -namespace Pilot +namespace Piccolo { void UIPass::initialize(const RenderPassInitInfo* init_info) { @@ -113,4 +113,4 @@ namespace Pilot } } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/passes/ui_pass.h b/engine/source/runtime/function/render/passes/ui_pass.h index 439fef027..7a8f37ced 100644 --- a/engine/source/runtime/function/render/passes/ui_pass.h +++ b/engine/source/runtime/function/render/passes/ui_pass.h @@ -2,7 +2,7 @@ #include "runtime/function/render/render_pass.h" -namespace Pilot +namespace Piccolo { class WindowUI; @@ -24,4 +24,4 @@ namespace Pilot private: WindowUI* m_window_ui; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_camera.cpp b/engine/source/runtime/function/render/render_camera.cpp index 94cfd410a..5066138f2 100644 --- a/engine/source/runtime/function/render/render_camera.cpp +++ b/engine/source/runtime/function/render/render_camera.cpp @@ -1,6 +1,6 @@ #include "runtime/function/render/render_camera.h" -namespace Pilot +namespace Piccolo { void RenderCamera::setCurrentCameraType(RenderCameraType type) { @@ -110,4 +110,4 @@ namespace Pilot m_fovy = Radian(Math::atan(Math::tan(Radian(Degree(m_fovx) * 0.5f)) / m_aspect) * 2.0f).valueDegrees(); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_camera.h b/engine/source/runtime/function/render/render_camera.h index cf68e0e03..e9b5acc28 100644 --- a/engine/source/runtime/function/render/render_camera.h +++ b/engine/source/runtime/function/render/render_camera.h @@ -4,7 +4,7 @@ #include -namespace Pilot +namespace Piccolo { enum class RenderCameraType : int { @@ -67,4 +67,4 @@ namespace Pilot inline const Vector3 RenderCamera::Y = {0.0f, 1.0f, 0.0f}; inline const Vector3 RenderCamera::Z = {0.0f, 0.0f, 1.0f}; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/render/render_common.h b/engine/source/runtime/function/render/render_common.h index 6ddd0a744..9c16beb77 100644 --- a/engine/source/runtime/function/render/render_common.h +++ b/engine/source/runtime/function/render/render_common.h @@ -17,7 +17,7 @@ #include #include -namespace Pilot +namespace Piccolo { static const uint32_t m_point_light_shadow_map_dimension = 2048; static const uint32_t m_directional_light_shadow_map_dimension = 4096; @@ -252,23 +252,23 @@ namespace Pilot void* base_color_image_pixels; uint32_t base_color_image_width; uint32_t base_color_image_height; - PILOT_PIXEL_FORMAT base_color_image_format; + PICCOLO_PIXEL_FORMAT base_color_image_format; void* metallic_roughness_image_pixels; uint32_t metallic_roughness_image_width; uint32_t metallic_roughness_image_height; - PILOT_PIXEL_FORMAT metallic_roughness_image_format; + PICCOLO_PIXEL_FORMAT metallic_roughness_image_format; void* normal_roughness_image_pixels; uint32_t normal_roughness_image_width; uint32_t normal_roughness_image_height; - PILOT_PIXEL_FORMAT normal_roughness_image_format; + PICCOLO_PIXEL_FORMAT normal_roughness_image_format; void* occlusion_image_pixels; uint32_t occlusion_image_width; uint32_t occlusion_image_height; - PILOT_PIXEL_FORMAT occlusion_image_format; + PICCOLO_PIXEL_FORMAT occlusion_image_format; void* emissive_image_pixels; uint32_t emissive_image_width; uint32_t emissive_image_height; - PILOT_PIXEL_FORMAT emissive_image_format; + PICCOLO_PIXEL_FORMAT emissive_image_format; VulkanPBRMaterial* now_material; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_entity.h b/engine/source/runtime/function/render/render_entity.h index aa34ed4dd..b58bbb53c 100644 --- a/engine/source/runtime/function/render/render_entity.h +++ b/engine/source/runtime/function/render/render_entity.h @@ -6,7 +6,7 @@ #include #include -namespace Pilot +namespace Piccolo { class RenderEntity { @@ -31,4 +31,4 @@ namespace Pilot float m_occlusion_strength {1.0f}; Vector3 m_emissive_factor {0.0f, 0.0f, 0.0f}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_guid_allocator.h b/engine/source/runtime/function/render/render_guid_allocator.h index 82cbcac30..812e25057 100644 --- a/engine/source/runtime/function/render/render_guid_allocator.h +++ b/engine/source/runtime/function/render/render_guid_allocator.h @@ -2,7 +2,7 @@ #include -namespace Pilot +namespace Piccolo { static const size_t k_invalid_guid = 0; @@ -101,4 +101,4 @@ namespace Pilot std::unordered_map m_guid_elements_map; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_helper.cpp b/engine/source/runtime/function/render/render_helper.cpp index 50d776679..fba9d105f 100644 --- a/engine/source/runtime/function/render/render_helper.cpp +++ b/engine/source/runtime/function/render/render_helper.cpp @@ -3,7 +3,7 @@ #include "runtime/function/render/render_camera.h" #include "runtime/function/render/render_scene.h" -namespace Pilot +namespace Piccolo { ClusterFrustum CreateClusterFrustumFromMatrix(glm::mat4 mat, float x_left, @@ -350,4 +350,4 @@ namespace Pilot glm::mat4 light_proj_view = (light_proj * light_view); return light_proj_view; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_helper.h b/engine/source/runtime/function/render/render_helper.h index eaacf5315..2c4dee84c 100644 --- a/engine/source/runtime/function/render/render_helper.h +++ b/engine/source/runtime/function/render/render_helper.h @@ -12,7 +12,7 @@ #include -namespace Pilot +namespace Piccolo { class RenderScene; class RenderCamera; @@ -91,4 +91,4 @@ namespace Pilot bool BoxIntersectsWithSphere(BoundingBox const& b, BoundingSphere const& s); glm::mat4 CalculateDirectionalLightCamera(RenderScene& scene, RenderCamera& camera); -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_mesh.h b/engine/source/runtime/function/render/render_mesh.h index c1bae9b54..d619c5b71 100644 --- a/engine/source/runtime/function/render/render_mesh.h +++ b/engine/source/runtime/function/render/render_mesh.h @@ -14,7 +14,7 @@ #include #include -namespace Pilot +namespace Piccolo { struct MeshVertex { @@ -88,4 +88,4 @@ namespace Pilot return attribute_descriptions; } }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_object.h b/engine/source/runtime/function/render/render_object.h index 02b0dcaba..b32fdaf26 100644 --- a/engine/source/runtime/function/render/render_object.h +++ b/engine/source/runtime/function/render/render_object.h @@ -6,7 +6,7 @@ #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(GameObjectMeshDesc) STRUCT(GameObjectMeshDesc, Fields) @@ -94,10 +94,10 @@ namespace Pilot GObjectID m_go_id {k_invalid_gobject_id}; std::vector m_object_parts; }; -} // namespace Pilot +} // namespace Piccolo template<> -struct std::hash +struct std::hash { - size_t operator()(const Pilot::GameObjectPartId& rhs) const noexcept { return rhs.getHashValue(); } + size_t operator()(const Piccolo::GameObjectPartId& rhs) const noexcept { return rhs.getHashValue(); } }; diff --git a/engine/source/runtime/function/render/render_pass.cpp b/engine/source/runtime/function/render/render_pass.cpp index 322898ee2..11af73b7e 100644 --- a/engine/source/runtime/function/render/render_pass.cpp +++ b/engine/source/runtime/function/render/render_pass.cpp @@ -5,9 +5,9 @@ #include "runtime/function/render/render_resource.h" #include "runtime/function/render/rhi/vulkan/vulkan_rhi.h" -Pilot::VisiableNodes Pilot::RenderPass::m_visiable_nodes; +Piccolo::VisiableNodes Piccolo::RenderPass::m_visiable_nodes; -namespace Pilot +namespace Piccolo { void RenderPass::initialize(const RenderPassInitInfo* init_info) { @@ -40,4 +40,4 @@ namespace Pilot } return layouts; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_pass.h b/engine/source/runtime/function/render/render_pass.h index b4562835f..bd8499ec2 100644 --- a/engine/source/runtime/function/render/render_pass.h +++ b/engine/source/runtime/function/render/render_pass.h @@ -9,7 +9,7 @@ #include #include -namespace Pilot +namespace Piccolo { class VulkanRHI; @@ -104,4 +104,4 @@ namespace Pilot private: }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_pass_base.cpp b/engine/source/runtime/function/render/render_pass_base.cpp index 0ccb973aa..d8f1f9ef1 100644 --- a/engine/source/runtime/function/render/render_pass_base.cpp +++ b/engine/source/runtime/function/render/render_pass_base.cpp @@ -2,7 +2,7 @@ #include "runtime/core/base/macro.h" -namespace Pilot +namespace Piccolo { void RenderPassBase::postInitialize() {} void RenderPassBase::setCommonInfo(RenderPassCommonInfo common_info) @@ -12,4 +12,4 @@ namespace Pilot } void RenderPassBase::preparePassData(std::shared_ptr render_resource) {} void RenderPassBase::initializeUIRenderBackend(WindowUI* window_ui) {} -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_pass_base.h b/engine/source/runtime/function/render/render_pass_base.h index 878235a26..709973ac2 100644 --- a/engine/source/runtime/function/render/render_pass_base.h +++ b/engine/source/runtime/function/render/render_pass_base.h @@ -2,7 +2,7 @@ #include "runtime/function/render/rhi.h" -namespace Pilot +namespace Piccolo { class RHI; class RenderResourceBase; @@ -30,4 +30,4 @@ namespace Pilot std::shared_ptr m_rhi; std::shared_ptr m_render_resource; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_pipeline.cpp b/engine/source/runtime/function/render/render_pipeline.cpp index 946cce81c..4d598b5f1 100644 --- a/engine/source/runtime/function/render/render_pipeline.cpp +++ b/engine/source/runtime/function/render/render_pipeline.cpp @@ -12,7 +12,7 @@ #include "runtime/core/base/macro.h" -namespace Pilot +namespace Piccolo { void RenderPipeline::initialize(RenderPipelineInitInfo init_info) { @@ -215,4 +215,4 @@ namespace Pilot MainCameraPass& main_camera_pass = *(static_cast(m_main_camera_pass.get())); main_camera_pass.m_selected_axis = selected_axis; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_pipeline.h b/engine/source/runtime/function/render/render_pipeline.h index 135e1f22e..aa338d9e6 100644 --- a/engine/source/runtime/function/render/render_pipeline.h +++ b/engine/source/runtime/function/render/render_pipeline.h @@ -2,7 +2,7 @@ #include "runtime/function/render/render_pipeline_base.h" -namespace Pilot +namespace Piccolo { class RenderPipeline : public RenderPipelineBase { @@ -23,4 +23,4 @@ namespace Pilot void setSelectedAxis(size_t selected_axis); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_pipeline_base.cpp b/engine/source/runtime/function/render/render_pipeline_base.cpp index 0c2657feb..89ec6dd89 100644 --- a/engine/source/runtime/function/render/render_pipeline_base.cpp +++ b/engine/source/runtime/function/render/render_pipeline_base.cpp @@ -2,7 +2,7 @@ #include "runtime/core/base/macro.h" -namespace Pilot +namespace Piccolo { void RenderPipelineBase::preparePassData(std::shared_ptr render_resource) { @@ -21,4 +21,4 @@ namespace Pilot { m_ui_pass->initializeUIRenderBackend(window_ui); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_pipeline_base.h b/engine/source/runtime/function/render/render_pipeline_base.h index 4111ab350..2822ca7e5 100644 --- a/engine/source/runtime/function/render/render_pipeline_base.h +++ b/engine/source/runtime/function/render/render_pipeline_base.h @@ -6,7 +6,7 @@ #include #include -namespace Pilot +namespace Piccolo { class RHI; class RenderResourceBase; @@ -47,4 +47,4 @@ namespace Pilot std::shared_ptr m_combine_ui_pass; std::shared_ptr m_pick_pass; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_resource.cpp b/engine/source/runtime/function/render/render_resource.cpp index 149a5943e..10ba2672f 100644 --- a/engine/source/runtime/function/render/render_resource.cpp +++ b/engine/source/runtime/function/render/render_resource.cpp @@ -13,7 +13,7 @@ #include -namespace Pilot +namespace Piccolo { void RenderResource::uploadGlobalRenderResource(std::shared_ptr rhi, LevelResourceDesc level_resource_desc) { @@ -354,7 +354,7 @@ namespace Pilot void* base_color_image_pixels = empty_image; uint32_t base_color_image_width = 1; uint32_t base_color_image_height = 1; - PILOT_PIXEL_FORMAT base_color_image_format = PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_SRGB; + PICCOLO_PIXEL_FORMAT base_color_image_format = PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_SRGB; if (material_data.m_base_color_texture) { base_color_image_pixels = material_data.m_base_color_texture->m_pixels; @@ -366,7 +366,7 @@ namespace Pilot void* metallic_roughness_image_pixels = empty_image; uint32_t metallic_roughness_width = 1; uint32_t metallic_roughness_height = 1; - PILOT_PIXEL_FORMAT metallic_roughness_format = PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_UNORM; + PICCOLO_PIXEL_FORMAT metallic_roughness_format = PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_UNORM; if (material_data.m_metallic_roughness_texture) { metallic_roughness_image_pixels = material_data.m_metallic_roughness_texture->m_pixels; @@ -378,7 +378,7 @@ namespace Pilot void* normal_roughness_image_pixels = empty_image; uint32_t normal_roughness_width = 1; uint32_t normal_roughness_height = 1; - PILOT_PIXEL_FORMAT normal_roughness_format = PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_UNORM; + PICCOLO_PIXEL_FORMAT normal_roughness_format = PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_UNORM; if (material_data.m_normal_texture) { normal_roughness_image_pixels = material_data.m_normal_texture->m_pixels; @@ -390,7 +390,7 @@ namespace Pilot void* occlusion_image_pixels = empty_image; uint32_t occlusion_image_width = 1; uint32_t occlusion_image_height = 1; - PILOT_PIXEL_FORMAT occlusion_image_format = PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_UNORM; + PICCOLO_PIXEL_FORMAT occlusion_image_format = PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_UNORM; if (material_data.m_occlusion_texture) { occlusion_image_pixels = material_data.m_occlusion_texture->m_pixels; @@ -402,7 +402,7 @@ namespace Pilot void* emissive_image_pixels = empty_image; uint32_t emissive_image_width = 1; uint32_t emissive_image_height = 1; - PILOT_PIXEL_FORMAT emissive_image_format = PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_UNORM; + PICCOLO_PIXEL_FORMAT emissive_image_format = PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_UNORM; if (material_data.m_emissive_texture) { emissive_image_pixels = material_data.m_emissive_texture->m_pixels; @@ -1243,4 +1243,4 @@ namespace Pilot static_assert(64 >= sizeof(MeshVertex::VulkanMeshVertexJointBinding), ""); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_resource.h b/engine/source/runtime/function/render/render_resource.h index e32826ef6..9cbb5c8b4 100644 --- a/engine/source/runtime/function/render/render_resource.h +++ b/engine/source/runtime/function/render/render_resource.h @@ -14,7 +14,7 @@ #include #include -namespace Pilot +namespace Piccolo { class RHI; class RenderPassBase; @@ -43,15 +43,15 @@ namespace Pilot void* _brdfLUT_texture_image_pixels; uint32_t _brdfLUT_texture_image_width; uint32_t _brdfLUT_texture_image_height; - PILOT_PIXEL_FORMAT _brdfLUT_texture_image_format; + PICCOLO_PIXEL_FORMAT _brdfLUT_texture_image_format; std::array _irradiance_texture_image_pixels; uint32_t _irradiance_texture_image_width; uint32_t _irradiance_texture_image_height; - PILOT_PIXEL_FORMAT _irradiance_texture_image_format; + PICCOLO_PIXEL_FORMAT _irradiance_texture_image_format; std::array _specular_texture_image_pixels; uint32_t _specular_texture_image_width; uint32_t _specular_texture_image_height; - PILOT_PIXEL_FORMAT _specular_texture_image_format; + PICCOLO_PIXEL_FORMAT _specular_texture_image_format; }; struct ColorGradingResource @@ -66,7 +66,7 @@ namespace Pilot void* _color_grading_LUT_texture_image_pixels; uint32_t _color_grading_LUT_texture_image_width; uint32_t _color_grading_LUT_texture_image_height; - PILOT_PIXEL_FORMAT _color_grading_LUT_texture_image_format; + PICCOLO_PIXEL_FORMAT _color_grading_LUT_texture_image_format; }; struct StorageBuffer @@ -183,4 +183,4 @@ namespace Pilot VulkanMesh& now_mesh); void updateTextureImageData(std::shared_ptr rhi, const TextureDataToUpdate& texture_data); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_resource_base.cpp b/engine/source/runtime/function/render/render_resource_base.cpp index 4442a7516..685be0e86 100644 --- a/engine/source/runtime/function/render/render_resource_base.cpp +++ b/engine/source/runtime/function/render/render_resource_base.cpp @@ -18,7 +18,7 @@ #include #include -namespace Pilot +namespace Piccolo { std::shared_ptr RenderResourceBase::loadTextureHDR(std::string file, int desired_channels) { @@ -39,10 +39,10 @@ namespace Pilot switch (desired_channels) { case 2: - texture->m_format = PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R32G32_FLOAT; + texture->m_format = PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R32G32_FLOAT; break; case 4: - texture->m_format = PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R32G32B32A32_FLOAT; + texture->m_format = PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R32G32B32A32_FLOAT; break; default: // three component format is not supported in some vulkan driver implementations @@ -52,7 +52,7 @@ namespace Pilot texture->m_depth = 1; texture->m_array_layers = 1; texture->m_mip_levels = 1; - texture->m_type = PILOT_IMAGE_TYPE::PILOT_IMAGE_TYPE_2D; + texture->m_type = PICCOLO_IMAGE_TYPE::PICCOLO_IMAGE_TYPE_2D; return texture; } @@ -72,12 +72,12 @@ namespace Pilot texture->m_width = iw; texture->m_height = ih; - texture->m_format = (is_srgb) ? PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_SRGB : - PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_UNORM; + texture->m_format = (is_srgb) ? PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_SRGB : + PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_UNORM; texture->m_depth = 1; texture->m_array_layers = 1; texture->m_mip_levels = 1; - texture->m_type = PILOT_IMAGE_TYPE::PILOT_IMAGE_TYPE_2D; + texture->m_type = PICCOLO_IMAGE_TYPE::PICCOLO_IMAGE_TYPE_2D; return texture; } @@ -340,4 +340,4 @@ namespace Pilot return mesh_data; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_resource_base.h b/engine/source/runtime/function/render/render_resource_base.h index b7216a21c..5b52a0a48 100644 --- a/engine/source/runtime/function/render/render_resource_base.h +++ b/engine/source/runtime/function/render/render_resource_base.h @@ -8,7 +8,7 @@ #include #include -namespace Pilot +namespace Piccolo { class RHI; class RenderScene; @@ -49,4 +49,4 @@ namespace Pilot std::unordered_map m_bounding_box_cache_map; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_scene.cpp b/engine/source/runtime/function/render/render_scene.cpp index f7d2771f1..0a64363c8 100644 --- a/engine/source/runtime/function/render/render_scene.cpp +++ b/engine/source/runtime/function/render/render_scene.cpp @@ -4,7 +4,7 @@ #include "runtime/function/render/render_pass.h" #include "runtime/function/render/render_resource.h" -namespace Pilot +namespace Piccolo { void RenderScene::updateVisibleObjects(std::shared_ptr render_resource, std::shared_ptr camera) @@ -244,4 +244,4 @@ namespace Pilot // TODO m_main_camera_visible_particlebillboard_nodes.clear(); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_scene.h b/engine/source/runtime/function/render/render_scene.h index e1480a384..d8627c854 100644 --- a/engine/source/runtime/function/render/render_scene.h +++ b/engine/source/runtime/function/render/render_scene.h @@ -11,7 +11,7 @@ #include #include -namespace Pilot +namespace Piccolo { class RenderResource; class RenderCamera; @@ -69,4 +69,4 @@ namespace Pilot void updateVisibleObjectsAxis(std::shared_ptr render_resource); void updateVisibleObjectsParticle(std::shared_ptr render_resource); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_swap_context.cpp b/engine/source/runtime/function/render/render_swap_context.cpp index 3ebd19de5..da770ac01 100644 --- a/engine/source/runtime/function/render/render_swap_context.cpp +++ b/engine/source/runtime/function/render/render_swap_context.cpp @@ -2,7 +2,7 @@ #include -namespace Pilot +namespace Piccolo { void GameObjectResourceDesc::add(GameObjectDesc desc) { m_game_object_descs.push_back(desc); } @@ -95,4 +95,4 @@ namespace Pilot m_game_object_to_delete = go_descs; } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_swap_context.h b/engine/source/runtime/function/render/render_swap_context.h index 5df55de5a..45823f627 100644 --- a/engine/source/runtime/function/render/render_swap_context.h +++ b/engine/source/runtime/function/render/render_swap_context.h @@ -9,7 +9,7 @@ #include #include -namespace Pilot +namespace Piccolo { struct LevelIBLResourceDesc { @@ -83,4 +83,4 @@ namespace Pilot bool isReadyToSwap() const; void swap(); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_system.cpp b/engine/source/runtime/function/render/render_system.cpp index b18e8c6c6..8e47b1388 100644 --- a/engine/source/runtime/function/render/render_system.cpp +++ b/engine/source/runtime/function/render/render_system.cpp @@ -17,7 +17,7 @@ #include "runtime/function/render/rhi/vulkan/vulkan_rhi.h" -namespace Pilot +namespace Piccolo { RenderSystem::~RenderSystem() {} @@ -370,4 +370,4 @@ namespace Pilot m_swap_context.resetCameraSwapData(); } } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_system.h b/engine/source/runtime/function/render/render_system.h index 5bf1ad317..7c0fbd7c8 100644 --- a/engine/source/runtime/function/render/render_system.h +++ b/engine/source/runtime/function/render/render_system.h @@ -9,7 +9,7 @@ #include #include -namespace Pilot +namespace Piccolo { class WindowSystem; class RHI; @@ -74,4 +74,4 @@ namespace Pilot void processSwapData(); }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/render_type.h b/engine/source/runtime/function/render/render_type.h index 8352558c6..66689c941 100644 --- a/engine/source/runtime/function/render/render_type.h +++ b/engine/source/runtime/function/render/render_type.h @@ -4,24 +4,24 @@ #include #include -namespace Pilot +namespace Piccolo { - enum class PILOT_PIXEL_FORMAT : uint8_t + enum class PICCOLO_PIXEL_FORMAT : uint8_t { - PILOT_PIXEL_FORMAT_UNKNOWN = 0, - PILOT_PIXEL_FORMAT_R8G8B8_UNORM, - PILOT_PIXEL_FORMAT_R8G8B8_SRGB, - PILOT_PIXEL_FORMAT_R8G8B8A8_UNORM, - PILOT_PIXEL_FORMAT_R8G8B8A8_SRGB, - PILOT_PIXEL_FORMAT_R32G32_FLOAT, - PILOT_PIXEL_FORMAT_R32G32B32_FLOAT, - PILOT_PIXEL_FORMAT_R32G32B32A32_FLOAT + PICCOLO_PIXEL_FORMAT_UNKNOWN = 0, + PICCOLO_PIXEL_FORMAT_R8G8B8_UNORM, + PICCOLO_PIXEL_FORMAT_R8G8B8_SRGB, + PICCOLO_PIXEL_FORMAT_R8G8B8A8_UNORM, + PICCOLO_PIXEL_FORMAT_R8G8B8A8_SRGB, + PICCOLO_PIXEL_FORMAT_R32G32_FLOAT, + PICCOLO_PIXEL_FORMAT_R32G32B32_FLOAT, + PICCOLO_PIXEL_FORMAT_R32G32B32A32_FLOAT }; - enum class PILOT_IMAGE_TYPE : uint8_t + enum class PICCOLO_IMAGE_TYPE : uint8_t { - PILOT_IMAGE_TYPE_UNKNOWM = 0, - PILOT_IMAGE_TYPE_2D + PICCOLO_IMAGE_TYPE_UNKNOWM = 0, + PICCOLO_IMAGE_TYPE_2D }; enum class RENDER_PIPELINE_TYPE : uint8_t @@ -63,8 +63,8 @@ namespace Pilot uint32_t m_array_layers {0}; void* m_pixels {nullptr}; - PILOT_PIXEL_FORMAT m_format {PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_UNKNOWN}; - PILOT_IMAGE_TYPE m_type {PILOT_IMAGE_TYPE::PILOT_IMAGE_TYPE_UNKNOWM}; + PICCOLO_PIXEL_FORMAT m_format {PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_UNKNOWN}; + PICCOLO_IMAGE_TYPE m_type {PICCOLO_IMAGE_TYPE::PICCOLO_IMAGE_TYPE_UNKNOWM}; TextureData() = default; ~TextureData() @@ -151,15 +151,15 @@ namespace Pilot std::shared_ptr m_occlusion_texture; std::shared_ptr m_emissive_texture; }; -} // namespace Pilot +} // namespace Piccolo template<> -struct std::hash +struct std::hash { - size_t operator()(const Pilot::MeshSourceDesc& rhs) const noexcept { return rhs.getHashValue(); } + size_t operator()(const Piccolo::MeshSourceDesc& rhs) const noexcept { return rhs.getHashValue(); } }; template<> -struct std::hash +struct std::hash { - size_t operator()(const Pilot::MaterialSourceDesc& rhs) const noexcept { return rhs.getHashValue(); } + size_t operator()(const Piccolo::MaterialSourceDesc& rhs) const noexcept { return rhs.getHashValue(); } }; diff --git a/engine/source/runtime/function/render/rhi.cpp b/engine/source/runtime/function/render/rhi.cpp index 29ff87512..cc5fe4231 100644 --- a/engine/source/runtime/function/render/rhi.cpp +++ b/engine/source/runtime/function/render/rhi.cpp @@ -1,4 +1,4 @@ #include "runtime/function/render/rhi.h" -namespace Pilot +namespace Piccolo {} \ No newline at end of file diff --git a/engine/source/runtime/function/render/rhi.h b/engine/source/runtime/function/render/rhi.h index b700013d7..d937ccedc 100644 --- a/engine/source/runtime/function/render/rhi.h +++ b/engine/source/runtime/function/render/rhi.h @@ -5,7 +5,7 @@ #include -namespace Pilot +namespace Piccolo { class WindowSystem; @@ -38,4 +38,4 @@ namespace Pilot }; inline RHI::~RHI() = default; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/rhi/vulkan/vulkan_rhi.cpp b/engine/source/runtime/function/render/rhi/vulkan/vulkan_rhi.cpp index cba6c27e0..e1502fb99 100644 --- a/engine/source/runtime/function/render/rhi/vulkan/vulkan_rhi.cpp +++ b/engine/source/runtime/function/render/rhi/vulkan/vulkan_rhi.cpp @@ -7,8 +7,8 @@ #include // https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html -#define PILOT_XSTR(s) PILOT_STR(s) -#define PILOT_STR(s) #s +#define PICCOLO_XSTR(s) PICCOLO_STR(s) +#define PICCOLO_STR(s) #s #if defined(__GNUC__) // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html @@ -73,7 +73,7 @@ #include #include -namespace Pilot +namespace Piccolo { VulkanRHI::~VulkanRHI() { @@ -106,12 +106,12 @@ namespace Pilot #if defined(__GNUC__) // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html #if defined(__linux__) - char const* vk_layer_path = PILOT_XSTR(PILOT_VK_LAYER_PATH); + char const* vk_layer_path = PICCOLO_XSTR(PICCOLO_VK_LAYER_PATH); setenv("VK_LAYER_PATH", vk_layer_path, 1); #elif defined(__MACH__) // https://developer.apple.com/library/archive/documentation/Porting/Conceptual/PortingUnix/compiling/compiling.html - char const* vk_layer_path = PILOT_XSTR(PILOT_VK_LAYER_PATH); - char const* vk_icd_filenames = PILOT_XSTR(PILOT_VK_ICD_FILENAMES); + char const* vk_layer_path = PICCOLO_XSTR(PICCOLO_VK_LAYER_PATH); + char const* vk_icd_filenames = PICCOLO_XSTR(PICCOLO_VK_ICD_FILENAMES); setenv("VK_LAYER_PATH", vk_layer_path, 1); setenv("VK_ICD_FILENAMES", vk_icd_filenames, 1); #else @@ -119,7 +119,7 @@ namespace Pilot #endif #elif defined(_MSC_VER) // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros - char const* vk_layer_path = PILOT_XSTR(PILOT_VK_LAYER_PATH); + char const* vk_layer_path = PICCOLO_XSTR(PICCOLO_VK_LAYER_PATH); SetEnvironmentVariableA("VK_LAYER_PATH", vk_layer_path); SetEnvironmentVariableA("DISABLE_LAYER_AMD_SWITCHABLE_GRAPHICS_1", "1"); #else @@ -419,7 +419,7 @@ namespace Pilot appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; appInfo.pApplicationName = "pilot_renderer"; appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); - appInfo.pEngineName = "Pilot"; + appInfo.pEngineName = "Piccolo"; appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); appInfo.apiVersion = m_vulkan_api_version; @@ -917,7 +917,7 @@ namespace Pilot } } - Pilot::QueueFamilyIndices VulkanRHI::findQueueFamilies(VkPhysicalDevice physical_device) // for device and surface + Piccolo::QueueFamilyIndices VulkanRHI::findQueueFamilies(VkPhysicalDevice physical_device) // for device and surface { QueueFamilyIndices indices; uint32_t queue_family_count = 0; @@ -992,7 +992,7 @@ namespace Pilot return true; } - Pilot::SwapChainSupportDetails VulkanRHI::querySwapChainSupport(VkPhysicalDevice physical_device) + Piccolo::SwapChainSupportDetails VulkanRHI::querySwapChainSupport(VkPhysicalDevice physical_device) { SwapChainSupportDetails details_result; @@ -1103,4 +1103,4 @@ namespace Pilot } } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/function/render/rhi/vulkan/vulkan_rhi.h b/engine/source/runtime/function/render/rhi/vulkan/vulkan_rhi.h index c7fc2fddb..f5a7926d8 100644 --- a/engine/source/runtime/function/render/rhi/vulkan/vulkan_rhi.h +++ b/engine/source/runtime/function/render/rhi/vulkan/vulkan_rhi.h @@ -9,7 +9,7 @@ #include #include -namespace Pilot +namespace Piccolo { struct QueueFamilyIndices { @@ -178,4 +178,4 @@ namespace Pilot VkDebugUtilsMessengerEXT m_debug_messenger {VK_NULL_HANDLE}; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/rhi/vulkan/vulkan_util.cpp b/engine/source/runtime/function/render/rhi/vulkan/vulkan_util.cpp index 00e762b58..5b00ac532 100644 --- a/engine/source/runtime/function/render/rhi/vulkan/vulkan_util.cpp +++ b/engine/source/runtime/function/render/rhi/vulkan/vulkan_util.cpp @@ -7,7 +7,7 @@ #include #include -namespace Pilot +namespace Piccolo { std::unordered_map VulkanUtil::m_mipmap_sampler_map; VkSampler VulkanUtil::m_nearest_sampler = VK_NULL_HANDLE; @@ -188,7 +188,7 @@ namespace Pilot uint32_t texture_image_width, uint32_t texture_image_height, void* texture_image_pixels, - PILOT_PIXEL_FORMAT texture_image_format, + PICCOLO_PIXEL_FORMAT texture_image_format, uint32_t miplevels) { if (!texture_image_pixels) @@ -200,31 +200,31 @@ namespace Pilot VkFormat vulkan_image_format; switch (texture_image_format) { - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8_UNORM: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8_UNORM: texture_byte_size = texture_image_width * texture_image_height * 3; vulkan_image_format = VK_FORMAT_R8G8B8_UNORM; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8_SRGB: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8_SRGB: texture_byte_size = texture_image_width * texture_image_height * 3; vulkan_image_format = VK_FORMAT_R8G8B8_SRGB; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_UNORM: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_UNORM: texture_byte_size = texture_image_width * texture_image_height * 4; vulkan_image_format = VK_FORMAT_R8G8B8A8_UNORM; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_SRGB: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_SRGB: texture_byte_size = texture_image_width * texture_image_height * 4; vulkan_image_format = VK_FORMAT_R8G8B8A8_SRGB; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R32G32_FLOAT: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R32G32_FLOAT: texture_byte_size = texture_image_width * texture_image_height * 4 * 2; vulkan_image_format = VK_FORMAT_R32G32_SFLOAT; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R32G32B32_FLOAT: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R32G32B32_FLOAT: texture_byte_size = texture_image_width * texture_image_height * 4 * 3; vulkan_image_format = VK_FORMAT_R32G32B32_SFLOAT; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R32G32B32A32_FLOAT: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R32G32B32A32_FLOAT: texture_byte_size = texture_image_width * texture_image_height * 4 * 4; vulkan_image_format = VK_FORMAT_R32G32B32A32_SFLOAT; break; @@ -323,7 +323,7 @@ namespace Pilot uint32_t texture_image_width, uint32_t texture_image_height, std::array texture_image_pixels, - PILOT_PIXEL_FORMAT texture_image_format, + PICCOLO_PIXEL_FORMAT texture_image_format, uint32_t miplevels) { VkDeviceSize texture_layer_byte_size; @@ -332,31 +332,31 @@ namespace Pilot switch (texture_image_format) { - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8_UNORM: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8_UNORM: texture_layer_byte_size = texture_image_width * texture_image_height * 3; vulkan_image_format = VK_FORMAT_R8G8B8_UNORM; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8_SRGB: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8_SRGB: texture_layer_byte_size = texture_image_width * texture_image_height * 3; vulkan_image_format = VK_FORMAT_R8G8B8_SRGB; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_UNORM: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_UNORM: texture_layer_byte_size = texture_image_width * texture_image_height * 4; vulkan_image_format = VK_FORMAT_R8G8B8A8_UNORM; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R8G8B8A8_SRGB: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R8G8B8A8_SRGB: texture_layer_byte_size = texture_image_width * texture_image_height * 4; vulkan_image_format = VK_FORMAT_R8G8B8A8_SRGB; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R32G32_FLOAT: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R32G32_FLOAT: texture_layer_byte_size = texture_image_width * texture_image_height * 4 * 2; vulkan_image_format = VK_FORMAT_R32G32_SFLOAT; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R32G32B32_FLOAT: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R32G32B32_FLOAT: texture_layer_byte_size = texture_image_width * texture_image_height * 4 * 3; vulkan_image_format = VK_FORMAT_R32G32B32_SFLOAT; break; - case PILOT_PIXEL_FORMAT::PILOT_PIXEL_FORMAT_R32G32B32A32_FLOAT: + case PICCOLO_PIXEL_FORMAT::PICCOLO_PIXEL_FORMAT_R32G32B32A32_FLOAT: texture_layer_byte_size = texture_image_width * texture_image_height * 4 * 4; vulkan_image_format = VK_FORMAT_R32G32B32A32_SFLOAT; break; @@ -923,4 +923,4 @@ namespace Pilot vkDestroySampler(device, m_linear_sampler, nullptr); m_linear_sampler = VK_NULL_HANDLE; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/rhi/vulkan/vulkan_util.h b/engine/source/runtime/function/render/rhi/vulkan/vulkan_util.h index 1b103a399..cbef44baf 100644 --- a/engine/source/runtime/function/render/rhi/vulkan/vulkan_util.h +++ b/engine/source/runtime/function/render/rhi/vulkan/vulkan_util.h @@ -10,7 +10,7 @@ #include #include -namespace Pilot +namespace Piccolo { class VulkanUtil { @@ -58,7 +58,7 @@ namespace Pilot uint32_t texture_image_width, uint32_t texture_image_height, void* texture_image_pixels, - PILOT_PIXEL_FORMAT texture_image_format, + PICCOLO_PIXEL_FORMAT texture_image_format, uint32_t miplevels = 0); static void createCubeMap(RHI* rhi, VkImage& image, @@ -67,7 +67,7 @@ namespace Pilot uint32_t texture_image_width, uint32_t texture_image_height, std::array texture_image_pixels, - PILOT_PIXEL_FORMAT texture_image_format, + PICCOLO_PIXEL_FORMAT texture_image_format, uint32_t miplevels); static void generateTextureMipMaps(RHI* rhi, VkImage image, @@ -104,4 +104,4 @@ namespace Pilot static VkSampler m_nearest_sampler; static VkSampler m_linear_sampler; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/window_system.cpp b/engine/source/runtime/function/render/window_system.cpp index 4bdc7efd1..c35fa552f 100644 --- a/engine/source/runtime/function/render/window_system.cpp +++ b/engine/source/runtime/function/render/window_system.cpp @@ -2,7 +2,7 @@ #include "runtime/core/base/macro.h" -namespace Pilot +namespace Piccolo { WindowSystem::~WindowSystem() { @@ -61,4 +61,4 @@ namespace Pilot m_is_focus_mode = mode; glfwSetInputMode(m_window, GLFW_CURSOR, m_is_focus_mode ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL); } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/render/window_system.h b/engine/source/runtime/function/render/window_system.h index 7d80677a6..03eb26d97 100644 --- a/engine/source/runtime/function/render/window_system.h +++ b/engine/source/runtime/function/render/window_system.h @@ -7,13 +7,13 @@ #include #include -namespace Pilot +namespace Piccolo { struct WindowCreateInfo { int width {1280}; int height {720}; - const char* title {"Pilot"}; + const char* title {"Piccolo"}; bool is_fullscreen {false}; }; @@ -213,4 +213,4 @@ namespace Pilot }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/function/ui/window_ui.cpp b/engine/source/runtime/function/ui/window_ui.cpp index 9d65e4593..4736ecf5f 100644 --- a/engine/source/runtime/function/ui/window_ui.cpp +++ b/engine/source/runtime/function/ui/window_ui.cpp @@ -1,4 +1,4 @@ #include "runtime/function/ui/window_ui.h" -namespace Pilot +namespace Piccolo {} \ No newline at end of file diff --git a/engine/source/runtime/function/ui/window_ui.h b/engine/source/runtime/function/ui/window_ui.h index adbdfd165..be05eb5a3 100644 --- a/engine/source/runtime/function/ui/window_ui.h +++ b/engine/source/runtime/function/ui/window_ui.h @@ -2,7 +2,7 @@ #include -namespace Pilot +namespace Piccolo { class WindowSystem; class RenderSystem; @@ -19,4 +19,4 @@ namespace Pilot virtual void initialize(WindowUIInitInfo init_info) = 0; virtual void preRender() = 0; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/platform/file_service/file_service.cpp b/engine/source/runtime/platform/file_service/file_service.cpp index 5e2680f55..ba2e4718e 100644 --- a/engine/source/runtime/platform/file_service/file_service.cpp +++ b/engine/source/runtime/platform/file_service/file_service.cpp @@ -2,7 +2,7 @@ using namespace std; -namespace Pilot +namespace Piccolo { vector FileSystem::getFiles(const filesystem::path& directory) { @@ -16,4 +16,4 @@ namespace Pilot } return files; } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/platform/file_service/file_service.h b/engine/source/runtime/platform/file_service/file_service.h index bb816eedd..605da7b9c 100644 --- a/engine/source/runtime/platform/file_service/file_service.h +++ b/engine/source/runtime/platform/file_service/file_service.h @@ -3,11 +3,11 @@ #include #include -namespace Pilot +namespace Piccolo { class FileSystem { public: std::vector getFiles(const std::filesystem::path& directory); }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/platform/path/path.cpp b/engine/source/runtime/platform/path/path.cpp index 389c19f2d..a9dd909b5 100644 --- a/engine/source/runtime/platform/path/path.cpp +++ b/engine/source/runtime/platform/path/path.cpp @@ -2,7 +2,7 @@ using namespace std; -namespace Pilot +namespace Piccolo { const filesystem::path Path::getRelativePath(const filesystem::path& directory, const filesystem::path& file_path) @@ -38,4 +38,4 @@ namespace Pilot return file_pure_name; } -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/platform/path/path.h b/engine/source/runtime/platform/path/path.h index 97d99be0f..cf26f505c 100644 --- a/engine/source/runtime/platform/path/path.h +++ b/engine/source/runtime/platform/path/path.h @@ -5,7 +5,7 @@ #include #include -namespace Pilot +namespace Piccolo { class Path { @@ -20,4 +20,4 @@ namespace Pilot static const std::string getFilePureName(const std::string); }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/asset_manager/asset_manager.cpp b/engine/source/runtime/resource/asset_manager/asset_manager.cpp index ffb7e7419..14b9e3248 100644 --- a/engine/source/runtime/resource/asset_manager/asset_manager.cpp +++ b/engine/source/runtime/resource/asset_manager/asset_manager.cpp @@ -6,10 +6,10 @@ #include -namespace Pilot +namespace Piccolo { std::filesystem::path AssetManager::getFullPath(const std::string& relative_path) const { return std::filesystem::absolute(g_runtime_global_context.m_config_manager->getRootFolder() / relative_path); } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/asset_manager/asset_manager.h b/engine/source/runtime/resource/asset_manager/asset_manager.h index 45d0bd294..03eb1f828 100644 --- a/engine/source/runtime/resource/asset_manager/asset_manager.h +++ b/engine/source/runtime/resource/asset_manager/asset_manager.h @@ -11,7 +11,7 @@ #include "_generated/serializer/all_serializer.h" -namespace Pilot +namespace Piccolo { class AssetManager { @@ -69,4 +69,4 @@ namespace Pilot std::filesystem::path getFullPath(const std::string& relative_path) const; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/resource/config_manager/config_manager.cpp b/engine/source/runtime/resource/config_manager/config_manager.cpp index 4f26bfad1..261eb2873 100644 --- a/engine/source/runtime/resource/config_manager/config_manager.cpp +++ b/engine/source/runtime/resource/config_manager/config_manager.cpp @@ -6,7 +6,7 @@ #include #include -namespace Pilot +namespace Piccolo { void ConfigManager::initialize(const std::filesystem::path& config_file_path) { @@ -82,4 +82,4 @@ namespace Pilot const std::filesystem::path& ConfigManager::getJoltPhysicsAssetFolder() const { return m_jolt_physics_asset_folder; } #endif -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/resource/config_manager/config_manager.h b/engine/source/runtime/resource/config_manager/config_manager.h index fa1f460ac..0a5b5fa3b 100644 --- a/engine/source/runtime/resource/config_manager/config_manager.h +++ b/engine/source/runtime/resource/config_manager/config_manager.h @@ -2,7 +2,7 @@ #include -namespace Pilot +namespace Piccolo { struct EngineInitParams; @@ -40,4 +40,4 @@ namespace Pilot std::string m_default_world_url; std::string m_global_rendering_res_url; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/resource/res_type/common/level.h b/engine/source/runtime/resource/res_type/common/level.h index 299066921..5868f3f9d 100644 --- a/engine/source/runtime/resource/res_type/common/level.h +++ b/engine/source/runtime/resource/res_type/common/level.h @@ -3,7 +3,7 @@ #include "runtime/resource/res_type/common/object.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(LevelRes) CLASS(LevelRes, Fields) @@ -11,9 +11,9 @@ namespace Pilot REFLECTION_BODY(LevelRes); public: - float m_gravity {9.8f}; + Vector3 m_gravity {0.f, 0.f, -9.8f}; std::string m_character_name; std::vector m_objects; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/common/object.h b/engine/source/runtime/resource/res_type/common/object.h index 9ba493c9b..6ed3fee91 100644 --- a/engine/source/runtime/resource/res_type/common/object.h +++ b/engine/source/runtime/resource/res_type/common/object.h @@ -5,7 +5,7 @@ #include #include -namespace Pilot +namespace Piccolo { class Component; @@ -39,4 +39,4 @@ namespace Pilot std::vector> m_instanced_components; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/resource/res_type/common/world.h b/engine/source/runtime/resource/res_type/common/world.h index 2238dd83b..fabe0020b 100644 --- a/engine/source/runtime/resource/res_type/common/world.h +++ b/engine/source/runtime/resource/res_type/common/world.h @@ -2,7 +2,7 @@ #include "runtime/core/meta/reflection/reflection.h" #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(WorldRes) CLASS(WorldRes, Fields) @@ -19,4 +19,4 @@ namespace Pilot // the default level for this world, which should be first loading level std::string m_default_level_url; }; -} // namespace Pilot +} // namespace Piccolo diff --git a/engine/source/runtime/resource/res_type/components/animation.h b/engine/source/runtime/resource/res_type/components/animation.h index 17bb22418..15380e48f 100644 --- a/engine/source/runtime/resource/res_type/components/animation.h +++ b/engine/source/runtime/resource/res_type/components/animation.h @@ -6,7 +6,7 @@ #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(AnimationResultElement) @@ -43,4 +43,4 @@ namespace Pilot AnimationResult animation_result; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/components/camera.cpp b/engine/source/runtime/resource/res_type/components/camera.cpp index 8ed7df523..5feaa8491 100644 --- a/engine/source/runtime/resource/res_type/components/camera.cpp +++ b/engine/source/runtime/resource/res_type/components/camera.cpp @@ -2,25 +2,25 @@ #include "runtime/core/base/macro.h" -namespace Pilot +namespace Piccolo { CameraComponentRes::CameraComponentRes(const CameraComponentRes& res) { const std::string& camera_type_name = res.m_parameter.getTypeName(); if (camera_type_name == "FirstPersonCameraParameter") { - m_parameter = PILOT_REFLECTION_NEW(FirstPersonCameraParameter); - PILOT_REFLECTION_DEEP_COPY(FirstPersonCameraParameter, m_parameter, res.m_parameter); + m_parameter = PICCOLO_REFLECTION_NEW(FirstPersonCameraParameter); + PICCOLO_REFLECTION_DEEP_COPY(FirstPersonCameraParameter, m_parameter, res.m_parameter); } else if (camera_type_name == "ThirdPersonCameraParameter") { - m_parameter = PILOT_REFLECTION_NEW(ThirdPersonCameraParameter); - PILOT_REFLECTION_DEEP_COPY(ThirdPersonCameraParameter, m_parameter, res.m_parameter); + m_parameter = PICCOLO_REFLECTION_NEW(ThirdPersonCameraParameter); + PICCOLO_REFLECTION_DEEP_COPY(ThirdPersonCameraParameter, m_parameter, res.m_parameter); } else if (camera_type_name == "FreeCameraParameter") { - m_parameter = PILOT_REFLECTION_NEW(FreeCameraParameter); - PILOT_REFLECTION_DEEP_COPY(FreeCameraParameter, m_parameter, res.m_parameter); + m_parameter = PICCOLO_REFLECTION_NEW(FreeCameraParameter); + PICCOLO_REFLECTION_DEEP_COPY(FreeCameraParameter, m_parameter, res.m_parameter); } else { @@ -28,5 +28,5 @@ namespace Pilot } } - CameraComponentRes::~CameraComponentRes() { PILOT_REFLECTION_DELETE(m_parameter); } -} // namespace Pilot \ No newline at end of file + CameraComponentRes::~CameraComponentRes() { PICCOLO_REFLECTION_DELETE(m_parameter); } +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/components/camera.h b/engine/source/runtime/resource/res_type/components/camera.h index f64b8e11f..d28d7553b 100644 --- a/engine/source/runtime/resource/res_type/components/camera.h +++ b/engine/source/runtime/resource/res_type/components/camera.h @@ -2,7 +2,7 @@ #include "runtime/core/math/quaternion.h" #include "runtime/core/meta/reflection/reflection.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(CameraParameter) CLASS(CameraParameter, Fields) @@ -60,4 +60,4 @@ namespace Pilot ~CameraComponentRes(); }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/components/mesh.h b/engine/source/runtime/resource/res_type/components/mesh.h index 47f2dfd19..0c2f5ac8e 100644 --- a/engine/source/runtime/resource/res_type/components/mesh.h +++ b/engine/source/runtime/resource/res_type/components/mesh.h @@ -2,7 +2,7 @@ #include "runtime/core/math/transform.h" #include "runtime/core/meta/reflection/reflection.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(SubMeshRes) CLASS(SubMeshRes, Fields) @@ -23,4 +23,4 @@ namespace Pilot public: std::vector m_sub_meshes; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/components/motor.cpp b/engine/source/runtime/resource/res_type/components/motor.cpp index e3a95fb1f..89ca16379 100644 --- a/engine/source/runtime/resource/res_type/components/motor.cpp +++ b/engine/source/runtime/resource/res_type/components/motor.cpp @@ -2,7 +2,7 @@ #include "runtime/core/base/macro.h" -namespace Pilot +namespace Piccolo { MotorComponentRes::~MotorComponentRes() { } -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/components/motor.h b/engine/source/runtime/resource/res_type/components/motor.h index 1ece20260..f7d52cffe 100644 --- a/engine/source/runtime/resource/res_type/components/motor.h +++ b/engine/source/runtime/resource/res_type/components/motor.h @@ -4,7 +4,7 @@ #include "runtime/core/meta/reflection/reflection.h" #include "runtime/resource/res_type/data/basic_shape.h" -namespace Pilot +namespace Piccolo { enum class ControllerType : unsigned char { @@ -51,4 +51,4 @@ namespace Pilot Reflection::ReflectionPtr m_controller_config; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/components/rigid_body.cpp b/engine/source/runtime/resource/res_type/components/rigid_body.cpp index cf72ecf30..1b56ae807 100644 --- a/engine/source/runtime/resource/res_type/components/rigid_body.cpp +++ b/engine/source/runtime/resource/res_type/components/rigid_body.cpp @@ -2,15 +2,16 @@ #include "runtime/core/base/macro.h" -namespace Pilot +namespace Piccolo { RigidBodyShape::RigidBodyShape(const RigidBodyShape& res) : m_local_transform(res.m_local_transform) { if (res.m_geometry.getTypeName() == "Box") { - m_geometry = PILOT_REFLECTION_NEW(Box); - PILOT_REFLECTION_DEEP_COPY(Box, m_geometry, res.m_geometry); + m_type = RigidBodyShapeType::box; + m_geometry = PICCOLO_REFLECTION_NEW(Box); + PICCOLO_REFLECTION_DEEP_COPY(Box, m_geometry, res.m_geometry); } else { @@ -20,6 +21,6 @@ namespace Pilot RigidBodyShape::~RigidBodyShape() { - PILOT_REFLECTION_DELETE(m_geometry); + PICCOLO_REFLECTION_DELETE(m_geometry); } -} \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/components/rigid_body.h b/engine/source/runtime/resource/res_type/components/rigid_body.h index 6781dc6cc..eeafcf661 100644 --- a/engine/source/runtime/resource/res_type/components/rigid_body.h +++ b/engine/source/runtime/resource/res_type/components/rigid_body.h @@ -6,7 +6,7 @@ #include "runtime/core/math/transform.h" #include "runtime/core/meta/reflection/reflection.h" -namespace Pilot +namespace Piccolo { enum class RigidBodyShapeType : unsigned char { @@ -47,4 +47,4 @@ namespace Pilot float m_inverse_mass; int m_actor_type; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/data/animation_clip.h b/engine/source/runtime/resource/res_type/data/animation_clip.h index 8bd928197..800a947a7 100644 --- a/engine/source/runtime/resource/res_type/data/animation_clip.h +++ b/engine/source/runtime/resource/res_type/data/animation_clip.h @@ -3,7 +3,7 @@ #include "runtime/core/meta/reflection/reflection.h" #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(AnimNodeMap) @@ -49,4 +49,4 @@ namespace Pilot std::string skeleton_file_path; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/data/animation_skeleton_node_map.h b/engine/source/runtime/resource/res_type/data/animation_skeleton_node_map.h index 8f547ba74..0840662af 100644 --- a/engine/source/runtime/resource/res_type/data/animation_skeleton_node_map.h +++ b/engine/source/runtime/resource/res_type/data/animation_skeleton_node_map.h @@ -3,7 +3,7 @@ #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(AnimSkelMap) @@ -15,4 +15,4 @@ namespace Pilot std::vector convert; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/data/basic_shape.h b/engine/source/runtime/resource/res_type/data/basic_shape.h index ddde3be96..8557c18b8 100644 --- a/engine/source/runtime/resource/res_type/data/basic_shape.h +++ b/engine/source/runtime/resource/res_type/data/basic_shape.h @@ -2,7 +2,7 @@ #include "runtime/core/math/vector3.h" #include "runtime/core/meta/reflection/reflection.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(Geometry) CLASS(Geometry, Fields) @@ -44,4 +44,4 @@ namespace Pilot float m_radius {0.3f}; float m_half_height {0.7f}; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/data/blend_state.h b/engine/source/runtime/resource/res_type/data/blend_state.h index 078731aea..2ef2002ea 100644 --- a/engine/source/runtime/resource/res_type/data/blend_state.h +++ b/engine/source/runtime/resource/res_type/data/blend_state.h @@ -4,7 +4,7 @@ #include "runtime/resource/res_type/data/animation_skeleton_node_map.h" #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(BoneBlendWeight) @@ -44,4 +44,4 @@ namespace Pilot std::vector blend_ratio; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/data/camera_config.h b/engine/source/runtime/resource/res_type/data/camera_config.h index 23fea6070..faf81a575 100644 --- a/engine/source/runtime/resource/res_type/data/camera_config.h +++ b/engine/source/runtime/resource/res_type/data/camera_config.h @@ -4,7 +4,7 @@ #include "runtime/core/math/vector2.h" #include "runtime/core/math/vector3.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(CameraPose) CLASS(CameraPose, Fields) @@ -28,4 +28,4 @@ namespace Pilot float m_z_far; float m_z_near; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/data/material.h b/engine/source/runtime/resource/res_type/data/material.h index f9d15370d..06f50dc27 100644 --- a/engine/source/runtime/resource/res_type/data/material.h +++ b/engine/source/runtime/resource/res_type/data/material.h @@ -1,7 +1,7 @@ #pragma once #include "runtime/core/meta/reflection/reflection.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(MaterialRes) CLASS(MaterialRes, Fields) @@ -15,4 +15,4 @@ namespace Pilot std::string m_occlusion_texture_file; std::string m_emissive_texture_file; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/data/mesh_data.h b/engine/source/runtime/resource/res_type/data/mesh_data.h index f2281b3fe..b733cb2e2 100644 --- a/engine/source/runtime/resource/res_type/data/mesh_data.h +++ b/engine/source/runtime/resource/res_type/data/mesh_data.h @@ -3,7 +3,7 @@ #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(Vertex) @@ -51,4 +51,4 @@ namespace Pilot std::vector bind; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/data/skeleton_data.h b/engine/source/runtime/resource/res_type/data/skeleton_data.h index c5e03f8e4..4523d2169 100644 --- a/engine/source/runtime/resource/res_type/data/skeleton_data.h +++ b/engine/source/runtime/resource/res_type/data/skeleton_data.h @@ -4,7 +4,7 @@ #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(RawBone) @@ -33,4 +33,4 @@ namespace Pilot // build process }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/data/skeleton_mask.h b/engine/source/runtime/resource/res_type/data/skeleton_mask.h index 80b901eef..1ad601f25 100644 --- a/engine/source/runtime/resource/res_type/data/skeleton_mask.h +++ b/engine/source/runtime/resource/res_type/data/skeleton_mask.h @@ -2,7 +2,7 @@ #include "runtime/core/meta/reflection/reflection.h" #include #include -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(BoneBlendMask) @@ -15,4 +15,4 @@ namespace Pilot std::vector enabled; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/source/runtime/resource/res_type/global/global_rendering.h b/engine/source/runtime/resource/res_type/global/global_rendering.h index 2f959994c..70cc8e289 100644 --- a/engine/source/runtime/resource/res_type/global/global_rendering.h +++ b/engine/source/runtime/resource/res_type/global/global_rendering.h @@ -6,7 +6,7 @@ #include "runtime/resource/res_type/data/camera_config.h" -namespace Pilot +namespace Piccolo { REFLECTION_TYPE(SkyBoxIrradianceMap) CLASS(SkyBoxIrradianceMap, Fields) @@ -63,4 +63,4 @@ namespace Pilot CameraConfig m_camera_config; DirectionalLight m_directional_light; }; -} // namespace Pilot \ No newline at end of file +} // namespace Piccolo \ No newline at end of file diff --git a/engine/template/allReflectionFile.mustache b/engine/template/allReflectionFile.mustache new file mode 100644 index 000000000..972b3b15c --- /dev/null +++ b/engine/template/allReflectionFile.mustache @@ -0,0 +1,15 @@ +#pragma once +#include "runtime/core/meta/reflection/reflection.h" +#include "_generated/serializer/all_serializer.h" +{{#include_headfiles}} +#include "{{headfile_name}}" +{{/include_headfiles}} + +namespace Piccolo{ +namespace Reflection{ + void TypeMetaRegister::Register(){ + {{#class_defines}}TypeWrappersRegister::{{class_name}}(); + {{/class_defines}} + } +} +} \ No newline at end of file diff --git a/engine/template/allSerializer.h.mustache b/engine/template/allSerializer.h.mustache new file mode 100644 index 000000000..121c429d8 --- /dev/null +++ b/engine/template/allSerializer.h.mustache @@ -0,0 +1,5 @@ +#pragma once +#include "runtime/core/meta/serializer/serializer.h" +{{#include_headfiles}} +#include "{{headfile_name}}" +{{/include_headfiles}} \ No newline at end of file diff --git a/engine/template/allSerializer.ipp.mustache b/engine/template/allSerializer.ipp.mustache new file mode 100644 index 000000000..4db60cb61 --- /dev/null +++ b/engine/template/allSerializer.ipp.mustache @@ -0,0 +1,39 @@ +#pragma once +{{#include_headfiles}} +#include "{{headfile_name}}" +{{/include_headfiles}} +namespace Piccolo{ + {{#class_defines}} + template<> + PJson PSerializer::write(const {{class_name}}& instance){ + PJson::object ret_context; + {{#class_base_class_defines}}auto&& json_context_{{class_base_class_index}} = PSerializer::write(*({{class_base_class_name}}*)&instance); + assert(json_context_{{class_base_class_index}}.is_object()); + auto&& json_context_map_{{class_base_class_index}} = json_context_{{class_base_class_index}}.object_items(); + ret_context.insert(json_context_map_{{class_base_class_index}}.begin() , json_context_map_{{class_base_class_index}}.end());{{/class_base_class_defines}} + {{#class_field_defines}}{{#class_field_is_vector}}PJson::array {{class_field_name}}_json; + for (auto& item : instance.{{class_field_name}}){ + {{class_field_name}}_json.emplace_back(PSerializer::write(item)); + } + ret_context.insert_or_assign("{{class_field_display_name}}",{{class_field_name}}_json);{{/class_field_is_vector}} + {{^class_field_is_vector}}ret_context.insert_or_assign("{{class_field_display_name}}", PSerializer::write(instance.{{class_field_name}}));{{/class_field_is_vector}} + {{/class_field_defines}} + return PJson(ret_context); + } + template<> + {{class_name}}& PSerializer::read(const PJson& json_context, {{class_name}}& instance){ + assert(json_context.is_object()); + {{#class_base_class_defines}}PSerializer::read(json_context,*({{class_base_class_name}}*)&instance);{{/class_base_class_defines}} + {{#class_field_defines}} + if(!json_context["{{class_field_display_name}}"].is_null()){ + {{#class_field_is_vector}}assert(json_context["{{class_field_display_name}}"].is_array()); + PJson::array array_{{class_field_name}} = json_context["{{class_field_display_name}}"].array_items(); + instance.{{class_field_name}}.resize(array_{{class_field_name}}.size()); + for (size_t index=0; index < array_{{class_field_name}}.size();++index){ + PSerializer::read(array_{{class_field_name}}[index], instance.{{class_field_name}}[index]); + }{{/class_field_is_vector}}{{^class_field_is_vector}}PSerializer::read(json_context["{{class_field_display_name}}"], instance.{{class_field_name}});{{/class_field_is_vector}} + }{{/class_field_defines}} + return instance; + }{{/class_defines}} + +} diff --git a/engine/template/commonReflectionFile.mustache b/engine/template/commonReflectionFile.mustache new file mode 100644 index 000000000..b00d0a37b --- /dev/null +++ b/engine/template/commonReflectionFile.mustache @@ -0,0 +1,99 @@ +#pragma once +{{#include_headfiles}} +#include "{{headfile_name}}" +{{/include_headfiles}} + +namespace Piccolo{ + {{#class_defines}}class {{class_name}}; + {{/class_defines}} +namespace Reflection{ +{{#class_defines}}namespace TypeFieldReflectionOparator{ + class Type{{class_name}}Operator{ + public: + static const char* getClassName(){ return "{{class_name}}";} + static void* constructorWithJson(const PJson& json_context){ + {{class_name}}* ret_instance= new {{class_name}}; + PSerializer::read(json_context, *ret_instance); + return ret_instance; + } + static PJson writeByName(void* instance){ + return PSerializer::write(*({{class_name}}*)instance); + } + // base class + static int get{{class_name}}BaseClassReflectionInstanceList(ReflectionInstance* &out_list, void* instance){ + int count = {{class_base_class_size}}; + {{#class_has_base}}out_list = new ReflectionInstance[count]; + for (int i=0;i(instance)); + {{/class_base_class_defines}} + }{{/class_has_base}} + return count; + } + // fields + {{#class_field_defines}}static const char* getFieldName_{{class_field_name}}(){ return "{{class_field_name}}";} + static const char* getFieldTypeName_{{class_field_name}}(){ return "{{{class_field_type}}}";} + static void set_{{class_field_name}}(void* instance, void* field_value){ static_cast<{{class_name}}*>(instance)->{{class_field_name}} = *static_cast<{{{class_field_type}}}*>(field_value);} + static void* get_{{class_field_name}}(void* instance){ return static_cast(&(static_cast<{{class_name}}*>(instance)->{{class_field_name}}));} + static bool isArray_{{class_field_name}}(){ {{#class_field_is_vector}}return true;{{/class_field_is_vector}}{{^class_field_is_vector}}return false;{{/class_field_is_vector}} } + {{/class_field_defines}} + }; +}//namespace TypeFieldReflectionOparator +{{#vector_exist}}namespace ArrayReflectionOperator{ +{{#vector_defines}}#ifndef Array{{vector_useful_name}}OperatorMACRO +#define Array{{vector_useful_name}}OperatorMACRO + class Array{{vector_useful_name}}Operator{ + public: + static const char* getArrayTypeName(){ return "{{{vector_type_name}}}";} + static const char* getElementTypeName(){ return "{{{vector_element_type_name}}}";} + static int getSize(void* instance){ + //todo: should check validation + return static_cast(static_cast<{{{vector_type_name}}}*>(instance)->size()); + } + static void* get(int index,void* instance){ + //todo: should check validation + return static_cast(&((*static_cast<{{{vector_type_name}}}*>(instance))[index])); + } + static void set(int index, void* instance, void* element_value){ + //todo: should check validation + (*static_cast<{{{vector_type_name}}}*>(instance))[index] = *static_cast<{{{vector_element_type_name}}}*>(element_value); + } + }; +#endif //Array{{vector_useful_name}}Operator +{{/vector_defines}} +}//namespace ArrayReflectionOperator{{/vector_exist}} + + void TypeWrapperRegister_{{class_name}}(){ + {{#class_field_defines}}FieldFunctionTuple* f_field_function_tuple_{{class_field_name}}=new FieldFunctionTuple( + &TypeFieldReflectionOparator::Type{{class_name}}Operator::set_{{class_field_name}}, + &TypeFieldReflectionOparator::Type{{class_name}}Operator::get_{{class_field_name}}, + &TypeFieldReflectionOparator::Type{{class_name}}Operator::getClassName, + &TypeFieldReflectionOparator::Type{{class_name}}Operator::getFieldName_{{class_field_name}}, + &TypeFieldReflectionOparator::Type{{class_name}}Operator::getFieldTypeName_{{class_field_name}}, + &TypeFieldReflectionOparator::Type{{class_name}}Operator::isArray_{{class_field_name}}); + REGISTER_FIELD_TO_MAP("{{class_name}}", f_field_function_tuple_{{class_field_name}}); + {{/class_field_defines}} + + {{#vector_exist}}{{#vector_defines}}ArrayFunctionTuple* f_array_tuple_{{vector_useful_name}} = new ArrayFunctionTuple( + &ArrayReflectionOperator::Array{{vector_useful_name}}Operator::set, + &ArrayReflectionOperator::Array{{vector_useful_name}}Operator::get, + &ArrayReflectionOperator::Array{{vector_useful_name}}Operator::getSize, + &ArrayReflectionOperator::Array{{vector_useful_name}}Operator::getArrayTypeName, + &ArrayReflectionOperator::Array{{vector_useful_name}}Operator::getElementTypeName); + REGISTER_ARRAY_TO_MAP("{{{vector_type_name}}}", f_array_tuple_{{vector_useful_name}}); + {{/vector_defines}}{{/vector_exist}} + {{#class_need_register}}ClassFunctionTuple* f_class_function_tuple_{{class_name}}=new ClassFunctionTuple( + &TypeFieldReflectionOparator::Type{{class_name}}Operator::get{{class_name}}BaseClassReflectionInstanceList, + &TypeFieldReflectionOparator::Type{{class_name}}Operator::constructorWithJson, + &TypeFieldReflectionOparator::Type{{class_name}}Operator::writeByName); + REGISTER_BASE_CLASS_TO_MAP("{{class_name}}", f_class_function_tuple_{{class_name}}); + {{/class_need_register}} + }{{/class_defines}} +namespace TypeWrappersRegister{ + {{#class_defines}} + void {{class_name}}(){ TypeWrapperRegister_{{class_name}}();} + {{/class_defines}} +}//namespace TypeWrappersRegister + +}//namespace Reflection +}//namespace Piccolo diff --git a/engine/template/commonSerializerGenFile.mustache b/engine/template/commonSerializerGenFile.mustache new file mode 100644 index 000000000..84e336030 --- /dev/null +++ b/engine/template/commonSerializerGenFile.mustache @@ -0,0 +1,12 @@ +#pragma once +{{#include_headfiles}} +#include "{{headfile_name}}" +{{/include_headfiles}} + +namespace Piccolo{ + {{#class_defines}}template<> + PJson PSerializer::write(const {{class_name}}& instance); + template<> + {{class_name}}& PSerializer::read(const PJson& json_context, {{class_name}}& instance); + {{/class_defines}} +}//namespace