diff --git a/.gitignore b/.gitignore index 1c8ac974..9e72ab9b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ parser.tab.* # Build results +src/catch/ + [Dd]ebug/ [Rr]elease/ x64/ diff --git a/CMakeLists.txt b/CMakeLists.txt index f9c14db5..88eccdd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,12 @@ -cmake_minimum_required(VERSION 3.4) +cmake_minimum_required(VERSION 3.4...3.28) +cmake_policy(SET CMP0054 NEW) +cmake_policy(SET CMP0048 NEW) -project(cppparser) +project(cppparser VERSION 0.1.0) enable_testing() -include("../common/cmake/conf.cmake") +include("conf.cmake") set(CMAKE_CXX_STANDARD 17) @@ -17,9 +19,18 @@ add_subdirectory(third_party/btyacc_tp) add_definitions(-DBOOST_AUTO_LINK_NOMANGLE) -add_subdirectory(../common/third_party/boost_tp/cmake ${CMAKE_BINARY_DIR}/boost) +#add_subdirectory(../common/third_party/boost_tp/cmake ${CMAKE_BINARY_DIR}/boost) -include_directories(../common/third_party) +#include_directories(../common/third_party) + +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) +find_package(Boost COMPONENTS filesystem program_options date_time REQUIRED) + +if (NOT EXISTS "${CMAKE_SOURCE_DIR}/src/catch/catch.hpp") + file(DOWNLOAD "https://github.com/catchorg/Catch2/releases/download/v2.13.10/catch.hpp" "${CMAKE_SOURCE_DIR}/src/catch/catch.hpp") +endif() ############################################# ## CppParser @@ -37,9 +48,9 @@ else() message(STATUS "Found 'flex' as ${FLEX}") endif() -set_source_files_properties(src/parser.tab.cpp GENERATED) -set_source_files_properties(src/parser.lex.cpp GENERATED) -set_source_files_properties(src/parser.tab.h GENERATED) +set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}src/parser.tab.cpp GENERATED) +set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}src/parser.lex.cpp GENERATED) +set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}src/parser.tab.h GENERATED) add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.h @@ -72,18 +83,20 @@ set(CPPPARSER_SOURCES ) add_library(cppparser STATIC ${CPPPARSER_SOURCES}) -add_dependencies(cppparser btyacc boost_filesystem boost_program_options) +#add_dependencies(cppparser btyacc boost_filesystem boost_program_options) target_link_libraries(cppparser PUBLIC - boost_filesystem - boost_program_options - boost_system + ${Boost_FILESYSTEM_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Boost_System} ) target_include_directories( cppparser PUBLIC - pub - ../common/third_party/boost_tp + ${Boost_INCLUDE_DIRS} + $ + $ + #../common/third_party/boost_tp PRIVATE hack ) @@ -93,6 +106,82 @@ target_compile_definitions( YY_NO_UNPUT ) +#install(TARGETS cppparser EXPORT cppparser-config) +#export(TARGETS cppparser NAMESPACE cppparser:: FILE "${CMAKE_CURRENT_BINARY_DIR}/cppparser-config.cmake") +#install(DIRECTORY pub/ DESTINATION include/cppparser) +#install(EXPORT cppparser-config DESTINATION cmake) + +# Install rule for headers +install( + DIRECTORY pub/ + DESTINATION ${CPPPARSER_INSTALL_INCLUDE_DIR} + COMPONENT Development +) + +install( + TARGETS cppparser + EXPORT ${export_config_name}Targets + ARCHIVE DESTINATION ${CPPPARSER_INSTALL_LIBRARY_DIR} COMPONENT Development + LIBRARY DESTINATION ${CPPPARSER_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries + RUNTIME DESTINATION ${CPPPARSER_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries +) + +#------------------------------------------------------------------------------ +# Configure ConfigVersion.cmake common to build and install tree +include(CMakePackageConfigHelpers) +set(config_version_file ${PROJECT_BINARY_DIR}/${export_config_name}ConfigVersion.cmake) +write_basic_package_version_file( + ${config_version_file} + VERSION "${CPPPARSER_VERSION}" + COMPATIBILITY ExactVersion +) + +#------------------------------------------------------------------------------ +# Export 'Targets.cmake' for a build tree +export( + EXPORT ${PROJECT_NAME}Targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${export_config_name}Targets.cmake" +) + +# Configure 'Config.cmake' for a build tree +set(build_config ${CMAKE_BINARY_DIR}/${export_config_name}Config.cmake) +configure_package_config_file( + ${export_config_name}Config.cmake.in + ${build_config} + INSTALL_DESTINATION "${PROJECT_BINARY_DIR}" +) + +#------------------------------------------------------------------------------ +# Export 'Targets.cmake' for an install tree +install( + EXPORT ${export_config_name}Targets + FILE ${export_config_name}Targets.cmake + DESTINATION ${CPPPARSER_INSTALL_CONFIG_DIR} +) + +set(install_config ${PROJECT_BINARY_DIR}/CMakeFiles/${export_config_name}Config.cmake) +configure_package_config_file( + ${export_config_name}Config.cmake.in + ${install_config} + INSTALL_DESTINATION ${CPPPARSER_INSTALL_CONFIG_DIR} +) + +# Install config files +install( + FILES ${config_version_file} ${install_config} + DESTINATION "${CPPPARSER_INSTALL_CONFIG_DIR}" +) + + +#include(CMakePackageConfigHelpers) +#write_basic_package_version_file( +# "cppparserConfigVersion.cmake" +# VERSION ${cppparser_VERSION} +# COMPATIBILITY AnyNewerVersion) + +#install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cppparser-config.cmake" DESTINATION lib/cmake/cppparser) +# "${CMAKE_CURRENT_BINARY_DIR}/cppparserConfigVersion.cmake" + ############################################# ## CppParserTest @@ -103,9 +192,9 @@ add_executable(cppparsertest target_link_libraries(cppparsertest PRIVATE cppparser - boost_filesystem - boost_program_options - boost_system + ${Boost_FILESYSTEM_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Boost_System} ) set(E2E_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test/e2e) @@ -145,9 +234,9 @@ target_include_directories(cppparserunittest target_link_libraries(cppparserunittest PRIVATE cppparser - boost_filesystem - boost_program_options - boost_system + ${Boost_FILESYSTEM_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Boost_System} ) set(UNIT_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test/unit) add_test( @@ -175,9 +264,9 @@ target_compile_definitions(cppparserembeddedsnippetvalidity target_link_libraries(cppparserembeddedsnippetvalidity PRIVATE cppparser - boost_filesystem - boost_program_options - boost_system + ${Boost_FILESYSTEM_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Boost_System} ) if(NOT MSVC) diff --git a/README.md b/README.md index c8eea6a7..2e4f3e96 100644 --- a/README.md +++ b/README.md @@ -85,12 +85,47 @@ TEST_CASE("Parsing hello world program") ### Get the source ```sh -git clone https://github.com/satya-das/common.git -git clone https://github.com/satya-das/CppParser.git +git clone https://github.com/agladilin/cpppqqarser.git ``` ## Configure and build +### Windows Visual Studio + +[Install vcpkg](https://vcpkg.io/en/getting-started) to fetch boost + +```powershell +vcpkg install boost-filesystem boost-program-options boost-system boost-date-time +cd cppparser +mkdir build +cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE="[path to vcpkg]/scripts/buildsystems/vcpkg.cmake" +#cd build +#msbuild cppparser.sln +cmake --build build --config Debug +.\build\Debug\cppparsertest.exe +.\build\Debug\cppparserunittest.exe +cmake --build build --config Debug --target install # requires administrator privileges +vcpkg install cppparser --overlay-ports=c:\dev\custom-overlay +``` + +To remove + +```powershell +vcpkg remove cppparser +del $VCPKG_ROOT\buildtrees\cppparser +del $VCPKG_ROOT\packages\cppparser_x64-windows +del $VCPKG_ROOT\downloads\agladilin-cppparser-0.1.0.tar.gz +del C:\Users\\AppData\Local\vcpkg\archives\19 # or whatever corresponding to package ABI hash in install log +``` + +### Linux and others + +*For Ubuntu to fetch boost:* + +```sh +sudo apt install libboost-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev +``` + ```sh cd cppparser mkdir builds diff --git a/conf.cmake b/conf.cmake new file mode 100644 index 00000000..29c2fb9f --- /dev/null +++ b/conf.cmake @@ -0,0 +1,45 @@ + + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") +elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fvisibility=hidden") +else() + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fvisibility=hidden") +endif() + +set(CMAKE_CXX_STANDARD 17) + +# Define DLLEXPORT and DLLIMPORT +if(WIN32 OR CYGWIN ) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(DLLEXPORT "__attribute__((dllexport))") + set(DLLIMPORT "") + else() + set(DLLEXPORT "__declspec(dllexport)") + set(DLLIMPORT "__declspec(dllimport)") + endif() +else() + set(DLLEXPORT "__attribute__((visibility (\"default\")))") + set(DLLIMPORT "") +endif() + +set(export_config_name ${PROJECT_NAME}) + +if(NOT DEFINED CPPPARSER_INSTALL_INCLUDE_DIR) + set(CPPPARSER_INSTALL_INCLUDE_DIR include/cppparser) +endif() + +if(NOT DEFINED CPPPARSER_INSTALL_BIN_DIR) + set(CPPPARSER_INSTALL_BIN_DIR bin) +endif() + +if(NOT DEFINED CPPPARSER_INSTALL_LIBRARY_DIR) + set(CPPPARSER_INSTALL_LIBRARY_DIR lib) +endif() + +if(NOT DEFINED CPPPARSER_INSTALL_CONFIG_DIR) + set(CPPPARSER_INSTALL_CONFIG_DIR ${CPPPARSER_INSTALL_LIBRARY_DIR}/cmake/${export_config_name}) +endif() diff --git a/cppparserConfig.cmake.in b/cppparserConfig.cmake.in new file mode 100644 index 00000000..dab23b1d --- /dev/null +++ b/cppparserConfig.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ + +set(export_config_name "@export_config_name@") + +set_and_check(${export_config_name}_TARGETS "${CMAKE_CURRENT_LIST_DIR}/${export_config_name}Targets.cmake") + +include(${${export_config_name}_TARGETS}) diff --git a/pub/cppwriter.h b/pub/cppwriter.h index 5b9e3a81..e2541d48 100644 --- a/pub/cppwriter.h +++ b/pub/cppwriter.h @@ -66,6 +66,9 @@ class CppWriter virtual void emitUsingDecl(const CppUsingDecl* usingDecl, std::ostream& stm, CppIndent indentation = CppIndent()) const; + virtual void emitUsingNamespaceDecl(const CppUsingNamespaceDecl* usingDecl, + std::ostream& stm, + CppIndent indentation = CppIndent()) const; virtual void emitTypedefList(const CppTypedefList* typedefList, std::ostream& stm, CppIndent indentation = CppIndent()) const; diff --git a/src/README.mdpp b/src/README.mdpp index 1fa6f051..9eec3dd0 100644 --- a/src/README.mdpp +++ b/src/README.mdpp @@ -45,6 +45,26 @@ git clone https://github.com/satya-das/CppParser.git ## Configure and build +### Windows Visual Studio + +[Install vcpkg](https://vcpkg.io/en/getting-started) to fetch boost + +```powershell +vcpkg install boost-filesystem boost-program-options boost-system +cd cppparser +mkdir build +cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE="[path to vcpkg]/scripts/buildsystems/vcpkg.cmake" +cd build +msbuild cppparser.sln +``` + +### Linux and others + +* For Ubuntu to fetch boost: +```sh +sudo apt install libboost-system-dev libboost-filesystem-dev libboost-program-options-dev +``` + ```sh cd cppparser mkdir builds diff --git a/src/cppwriter.cpp b/src/cppwriter.cpp index 89034bcd..2ed6a738 100644 --- a/src/cppwriter.cpp +++ b/src/cppwriter.cpp @@ -106,6 +106,8 @@ void CppWriter::emit(const CppObj* cppObj, std::ostream& stm, CppIndent indentat return emitDocComment((CppDocComment*) cppObj, stm, indentation); case CppObjType::kUsingDecl: return emitUsingDecl((CppUsingDecl*) cppObj, stm, indentation); + case CppObjType::kUsingNamespaceDecl: + return emitUsingNamespaceDecl((CppUsingNamespaceDecl*) cppObj, stm, indentation); case CppObjType::kTypedefName: return emitTypedef((CppTypedefName*) cppObj, stm, indentation); case CppObjType::kTypedefNameList: @@ -411,6 +413,13 @@ void CppWriter::emitUsingDecl(const CppUsingDecl* usingDecl, stm << ";\n"; } +void CppWriter::emitUsingNamespaceDecl(const CppUsingNamespaceDecl* usingDecl, + std::ostream& stm, + CppIndent indentation /* = CppIndent()*/) const +{ + stm << indentation << "using namespace " << usingDecl->name_ << ";\n"; +} + void CppWriter::emitTypedefList(const CppTypedefList* typedefList, std::ostream& stm, CppIndent indentation /* = CppIndent()*/) const diff --git a/src/parser.l b/src/parser.l index 1171b608..c95d60cd 100644 --- a/src/parser.l +++ b/src/parser.l @@ -32,7 +32,7 @@ For this very reason this file does not use any class that are defined in cppast %{ // C++17 causes problem when register is used and flex uses register in generated code -#define register +//#define register #include "cpptoken.h" #include "cppvarinit.h" diff --git a/src/parser.tab.h b/src/parser.tab.h index fd142e8f..7d62a415 100644 --- a/src/parser.tab.h +++ b/src/parser.tab.h @@ -134,7 +134,7 @@ #define DTORDECL 387 #define YYERRCODE 256 -#line 166 "/home/dassat/github/cppparser/src/parser.y" +#line 166 "/home/user/dev/cppparser/src/parser.y" typedef union { CppToken str; CppNtFuncDeclData funcDeclData; diff --git a/test/app/compare.h b/test/app/compare.h index b598ff88..9002a411 100644 --- a/test/app/compare.h +++ b/test/app/compare.h @@ -24,6 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #pragma once #include +#include #include #include diff --git a/test/e2e/test_master/ObjectArxHeaders/AcTc.h b/test/e2e/test_master/ObjectArxHeaders/AcTc.h index 526d8f80..ee3673e7 100644 --- a/test/e2e/test_master/ObjectArxHeaders/AcTc.h +++ b/test/e2e/test_master/ObjectArxHeaders/AcTc.h @@ -167,6 +167,7 @@ namespace AcTc kItemOptionMenuRemoveImage = (0x1 << 4), }; } +using namespace AcTc; struct ACTC_IMAGE_INFO { SIZE mSize; diff --git a/test/e2e/test_master/podofo/podofo.h b/test/e2e/test_master/podofo/podofo.h index 9fc3b24a..da563796 100644 --- a/test/e2e/test_master/podofo/podofo.h +++ b/test/e2e/test_master/podofo/podofo.h @@ -93,5 +93,6 @@ # include "doc/PdfTilingPattern.h" # include "doc/PdfXObject.h" # ifdef _PODOFO_NO_NAMESPACE_ +using namespace PoDoFo; # endif #endif diff --git a/test/e2e/test_master/wxWidgets/include/wx/catch_cppunit.h b/test/e2e/test_master/wxWidgets/include/wx/catch_cppunit.h index 79b0cb58..5ff71d8d 100644 --- a/test/e2e/test_master/wxWidgets/include/wx/catch_cppunit.h +++ b/test/e2e/test_master/wxWidgets/include/wx/catch_cppunit.h @@ -168,6 +168,7 @@ namespace CatchCppUnit }; } } +using namespace CatchCppUnit; // Helpers used in the implementation of the macros below. namespace wxPrivate { diff --git a/test/e2e/test_master/wxWidgets/include/wx/msw/wrapgdip.h b/test/e2e/test_master/wxWidgets/include/wx/msw/wrapgdip.h index f1a0aefd..5e8f9889 100644 --- a/test/e2e/test_master/wxWidgets/include/wx/msw/wrapgdip.h +++ b/test/e2e/test_master/wxWidgets/include/wx/msw/wrapgdip.h @@ -25,6 +25,7 @@ using std::max; # pragma warning(disable:4458) // declaration of 'xxx' hides class member # endif # include +using namespace Gdiplus; # ifdef __VISUALC__ # pragma warning(pop) # endif diff --git a/third_party/btyacc_tp/CMakeLists.txt b/third_party/btyacc_tp/CMakeLists.txt index a1cfa01d..ad19bf07 100644 --- a/third_party/btyacc_tp/CMakeLists.txt +++ b/third_party/btyacc_tp/CMakeLists.txt @@ -1,4 +1,4 @@ -include("../../../common/cmake/conf.cmake") +include("../../conf.cmake") project(btyacc)