diff --git a/packages/PEGTL/.appveyor.yml b/packages/PEGTL/.appveyor.yml index 8150fbf6e507bbb55488376dd88bdc72add322fc..c144d3ce133f00bfeea139a24bd12a9d4f0e74d1 100644 --- a/packages/PEGTL/.appveyor.yml +++ b/packages/PEGTL/.appveyor.yml @@ -1,11 +1,7 @@ version: '{branch}-{build}' os: -- Visual Studio 2017 - -configuration: -- Release -- Debug + - Visual Studio 2017 skip_commits: files: @@ -14,10 +10,59 @@ skip_commits: environment: matrix: - GENERATOR: Visual Studio 15 2017 + platform: x86 + configuration: Debug + + - GENERATOR: Visual Studio 15 2017 + platform: x86 + configuration: Release + + - GENERATOR: Visual Studio 15 2017 + platform: x64 + configuration: Debug + + - GENERATOR: Visual Studio 15 2017 + platform: x64 + configuration: Release + + - GENERATOR: Visual Studio 15 2017 Win64 + platform: x86 + configuration: Debug - GENERATOR: Visual Studio 15 2017 Win64 + platform: x86 + configuration: Release + + - GENERATOR: Visual Studio 15 2017 Win64 + platform: x64 + configuration: Debug + + - GENERATOR: Visual Studio 15 2017 Win64 + platform: x64 + configuration: Release + + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + GENERATOR: Visual Studio 16 2019 + platform: x86 + configuration: Debug + + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + GENERATOR: Visual Studio 16 2019 + platform: x86 + configuration: Release + + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + GENERATOR: Visual Studio 16 2019 + platform: x64 + configuration: Debug + + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + GENERATOR: Visual Studio 16 2019 + platform: x64 + configuration: Release - GENERATOR: Visual Studio 15 2017 + configuration: Release CONAN_VISUAL_VERSIONS: 15 PYTHON: "C:\\Python27" PYTHON_VERSION: "2.7.8" @@ -41,5 +86,7 @@ build_script: test_script: - ctest -C "%CONFIGURATION%" --output-on-failure + +after_test: - if defined CONAN (cd ..) - if defined CONAN (python .conan/build.py) diff --git a/packages/PEGTL/.clang-tidy b/packages/PEGTL/.clang-tidy new file mode 100644 index 0000000000000000000000000000000000000000..592618ff6ce98924adc7080d0e838288aec358c4 --- /dev/null +++ b/packages/PEGTL/.clang-tidy @@ -0,0 +1,31 @@ +Checks: >- + bugprone-*, + cppcoreguidelines-slicing, + cppcoreguidelines-special-member-functions, + google-build-explicit-make-pair, + google-build-namespaces, + google-default-arguments, + google-global-names-in-headers, + google-readability-casting, + llvm-*, + -llvm-namespace-comment, + misc-*, + -misc-non-private-member-variables-in-classes, + -misc-unused-alias-decls, + modernize-*, + -modernize-avoid-c-arrays, + -modernize-concat-nested-namespaces, + -modernize-raw-string-literal, + performance-*, + readability-*, + -readability-avoid-const-params-in-decls, + -readability-magic-numbers, + +CheckOptions: + - { key: readability-identifier-naming.ClassCase, value: lower_case } + - { key: readability-identifier-naming.FunctionCase, value: lower_case } + - { key: readability-identifier-naming.ParameterCase, value: lower_case } + - { key: readability-identifier-naming.StructCase, value: aNy_CasE } # PEGTL rules + - { key: readability-identifier-naming.VariableCase, value: lower_case } + +WarningsAsErrors: '*' diff --git a/packages/PEGTL/.conan/test_package/test_package.cpp b/packages/PEGTL/.conan/test_package/test_package.cpp index f16aa23099613b2ab809209ad0c7f32f2f0cf8f2..9e641193a4e874c124c23a512b154de1829310f4 100644 --- a/packages/PEGTL/.conan/test_package/test_package.cpp +++ b/packages/PEGTL/.conan/test_package/test_package.cpp @@ -168,7 +168,7 @@ namespace calculator void insert( const std::string& name, const order p, const std::function< long( long, long ) >& f ) { assert( !name.empty() ); - m_ops.emplace( name, op{ p, f } ); + m_ops.try_emplace( name, op{ p, f } ); } const std::map< std::string, op >& ops() const @@ -182,7 +182,7 @@ namespace calculator // Here the actual grammar starts. - using namespace pegtl; // NOLINT + using namespace pegtl; // Comments are introduced by a '#' and proceed to the end-of-line/file. diff --git a/packages/PEGTL/.gitrepo b/packages/PEGTL/.gitrepo index b7e013522865c8d94d09390f5a9ef3f89c6e6563..2653e92eb6c94afa059fcc8cc82fba259410beab 100644 --- a/packages/PEGTL/.gitrepo +++ b/packages/PEGTL/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = git@github.com:taocpp/PEGTL.git branch = master - commit = 293ef9f549bfde12f78c6117a6d13a1f5b9879d2 - parent = 512de6bdac8531e32026970fcf476a1a1154ae62 + commit = cfd5e55d73a2a64942b42226e0e919dc36ecdce5 + parent = 1f2337bcfdf66482f57fe7648cb2b6bff987a23f cmdver = 0.4.0 method = merge diff --git a/packages/PEGTL/.travis.yml b/packages/PEGTL/.travis.yml index efdead2af923ebf7467ffcff7fd9f9584d6526c9..b127ea3cab5bde286cd3d5c89ab0b32855fbaf9a 100644 --- a/packages/PEGTL/.travis.yml +++ b/packages/PEGTL/.travis.yml @@ -20,6 +20,15 @@ matrix: env: - CXX=g++-8 + - compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['g++-8'] + env: + - CXX=g++-8 + - CPPFLAGS=-fno-rtti + - compiler: gcc addons: apt: @@ -69,6 +78,15 @@ matrix: - CXX=clang++-8 - CPPFLAGS=-fms-extensions + - compiler: clang + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-8'] + packages: ['clang-8', 'g++-8'] + env: + - CXX=clang++-8 + - CPPFLAGS=-fno-rtti + - os: osx osx_image: xcode9.4 compiler: clang @@ -81,6 +99,90 @@ matrix: env: - CXX=clang++ + - compiler: clang + env: + - ANDROID_ABI=armeabi-v7a + - ANDROID_PLATFORM=android-22 + addons: + apt: + packages: + - openjdk-8-jdk + before_install: + - export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 + - wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip + - unzip -qq sdk-tools-linux-4333796.zip -d /opt/android-sdk + - rm sdk-tools-linux-4333796.zip + - echo "y" | /opt/android-sdk/tools/bin/sdkmanager "platform-tools" "system-images;android-24;default;armeabi-v7a" "platforms;android-24" "emulator" "ndk-bundle" "cmake;3.10.2.4988404" > /dev/null + before_script: + - export TERM=dumb + - export _NO_CHECK_SIGNATURE=true + - export ANDROID_SDK_ROOT=/opt/android-sdk + - echo no | /opt/android-sdk/tools/bin/avdmanager create avd -n test -k "system-images;android-24;default;armeabi-v7a" + - /opt/android-sdk/emulator/emulator -avd test -no-audio -no-window -dns-server 8.8.8.8 & + #- android-wait-for-emulator || android-wait-for-emulator + - /opt/android-sdk/platform-tools/adb shell input keyevent 82 & + script: + # Using the ninja build command. Is much faster then make build command. + - /opt/android-sdk/cmake/3.10.2.4988404/bin/cmake -H. -Bcmake-build -GNinja -DANDROID_ABI=armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/opt/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-22 -DCMAKE_MAKE_PROGRAM=/opt/android-sdk/cmake/3.10.2.4988404/bin/ninja -DPEGTL_BUILD_EXAMPLES=OFF + - /opt/android-sdk/cmake/3.10.2.4988404/bin/cmake --build cmake-build --target all + # FIXME android emulator stuck sometimes - cd cmake-build && /opt/android-sdk/cmake/3.10.2.4988404/bin/ctest --output-on-failure + + - compiler: clang + env: + - ANDROID_ABI=armeabi-v7a + - ANDROID_PLATFORM=android-24 + addons: + apt: + packages: + - openjdk-8-jdk + before_install: + - export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 + - wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip + - unzip -qq sdk-tools-linux-4333796.zip -d /opt/android-sdk + - rm sdk-tools-linux-4333796.zip + - echo "y" | /opt/android-sdk/tools/bin/sdkmanager "platform-tools" "system-images;android-24;default;armeabi-v7a" "platforms;android-24" "emulator" "ndk-bundle" "cmake;3.10.2.4988404" > /dev/null + before_script: + - export TERM=dumb + - export _NO_CHECK_SIGNATURE=true + - export ANDROID_SDK_ROOT=/opt/android-sdk + - echo no | /opt/android-sdk/tools/bin/avdmanager create avd -n test -k "system-images;android-24;default;armeabi-v7a" + - /opt/android-sdk/emulator/emulator -avd test -no-audio -no-window -dns-server 8.8.8.8 & + #- android-wait-for-emulator || android-wait-for-emulator + - /opt/android-sdk/platform-tools/adb shell input keyevent 82 & + script: + # Using the ninja build command. Is much faster then make build command. + - /opt/android-sdk/cmake/3.10.2.4988404/bin/cmake -H. -Bcmake-build -GNinja -DANDROID_ABI=armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/opt/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-24 -DCMAKE_MAKE_PROGRAM=/opt/android-sdk/cmake/3.10.2.4988404/bin/ninja -DPEGTL_BUILD_EXAMPLES=OFF + - /opt/android-sdk/cmake/3.10.2.4988404/bin/cmake --build cmake-build --target all + # FIXME android emulator stuck sometimes - cd cmake-build && /opt/android-sdk/cmake/3.10.2.4988404/bin/ctest --output-on-failure + + - compiler: clang + env: + - ANDROID_ABI=arm64-v8a + - ANDROID_PLATFORM=android-24 + addons: + apt: + packages: + - openjdk-8-jdk + before_install: + - export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 + - wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip + - unzip -qq sdk-tools-linux-4333796.zip -d /opt/android-sdk + - rm sdk-tools-linux-4333796.zip + - echo "y" | /opt/android-sdk/tools/bin/sdkmanager "platform-tools" "system-images;android-24;default;arm64-v8a" "platforms;android-24" "emulator" "ndk-bundle" "cmake;3.10.2.4988404" > /dev/null + before_script: + - export TERM=dumb + - export _NO_CHECK_SIGNATURE=true + - export ANDROID_SDK_ROOT=/opt/android-sdk + - echo no | /opt/android-sdk/tools/bin/avdmanager create avd -n test -k "system-images;android-24;default;arm64-v8a" + - /opt/android-sdk/emulator/emulator -avd test -no-audio -no-window -dns-server 8.8.8.8 & + #- android-wait-for-emulator || android-wait-for-emulator + - /opt/android-sdk/platform-tools/adb shell input keyevent 82 & + script: + # Using the ninja build command. Is much faster then make build command. + - /opt/android-sdk/cmake/3.10.2.4988404/bin/cmake -H. -Bcmake-build -GNinja -DANDROID_ABI=arm64-v8a -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/opt/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-24 -DCMAKE_MAKE_PROGRAM=/opt/android-sdk/cmake/3.10.2.4988404/bin/ninja -DPEGTL_BUILD_EXAMPLES=OFF + - /opt/android-sdk/cmake/3.10.2.4988404/bin/cmake --build cmake-build --target all + # FIXME android emulator stuck sometimes- cd cmake-build && /opt/android-sdk/cmake/3.10.2.4988404/bin/ctest --output-on-failure + - compiler: gcc addons: apt: @@ -125,10 +227,8 @@ matrix: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-8'] packages: ['clang-8', 'clang-tidy-8', 'g++-8'] env: - - CXX=clang++-8 - CLANG_TIDY=clang-tidy-8 script: - - "sed -i 's#namespace TAO_PEGTL_NAMESPACE#namespace tao::pegtl#g' $(find . -name '*.[hc]pp')" - make -kj3 clang-tidy - compiler: clang @@ -176,6 +276,15 @@ matrix: script: - python .conan/build.py + - compiler: clang + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-8'] + packages: ['clang-format-8', 'g++-8'] + script: + - clang-format-8 -i -style=file $(find . -name '[^.]*.[hc]pp') + - git diff --exit-code + script: - $CXX --version - make -j3 build/src/test/pegtl/tester diff --git a/packages/PEGTL/Makefile b/packages/PEGTL/Makefile index 983c806fa07b1a5bdd1f68bf5a767f2c6d55cda6..f6c799b565337562121151984e93a94ebccdb68c 100644 --- a/packages/PEGTL/Makefile +++ b/packages/PEGTL/Makefile @@ -39,7 +39,7 @@ SOURCES := $(shell find src -name '*.cpp') DEPENDS := $(SOURCES:%.cpp=build/%.d) BINARIES := $(SOURCES:%.cpp=build/%) -CLANG_TIDY_HEADERS := $(filter-out include/tao/pegtl/internal/endian_win.hpp include/tao/pegtl/internal/file_mapper_win32.hpp,$(HEADER)) $(filter-out src/test/pegtl/main.hpp,$(shell find src -name '*.hpp')) +CLANG_TIDY_HEADERS := $(filter-out include/tao/pegtl/internal/endian_win.hpp include/tao/pegtl/internal/file_mapper_win32.hpp,$(HEADERS)) UNIT_TESTS := $(filter build/src/test/%,$(BINARIES)) @@ -61,8 +61,8 @@ build/%.valgrind: build/% valgrind: $(UNIT_TESTS:%=%.valgrind) @echo "All $(words $(UNIT_TESTS)) valgrind tests passed." -build/%.clang-tidy: % - $(CLANG_TIDY) -extra-arg "-Iinclude" -extra-arg "-std=c++17" -checks=*,-fuchsia-*,-google-runtime-references,-google-runtime-int,-google-readability-todo,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-*-magic-numbers,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-macro-usage,-hicpp-no-array-decay,-hicpp-signed-bitwise,-modernize-raw-string-literal,-misc-sizeof-expression,-misc-non-private-member-variables-in-classes,-bugprone-sizeof-expression,-bugprone-exception-escape -warnings-as-errors=* $< 2>/dev/null +build/%.clang-tidy: % .clang-tidy + $(CLANG_TIDY) -quiet $< -- $(CXXSTD) -Iinclude $(CPPFLAGS) $(CXXFLAGS) 2>/dev/null @mkdir -p $(@D) @touch $@ @@ -72,7 +72,7 @@ clang-tidy: $(CLANG_TIDY_HEADERS:%=build/%.clang-tidy) $(SOURCES:%=build/%.clang .PHONY: clean clean: - @rm -rf build + @rm -rf build/* @find . -name '*~' -delete build/%.d: %.cpp Makefile diff --git a/packages/PEGTL/README.md b/packages/PEGTL/README.md index 08940817946007af1ccd41084d6ecbde7b31cf7b..082f66d75017ba584d03350f17afe3ed7b18c7db 100644 --- a/packages/PEGTL/README.md +++ b/packages/PEGTL/README.md @@ -61,6 +61,7 @@ Each commit is automatically tested with multiple architectures, operating syste * Windows * Visual Studio 2017 (x86, x64) + * Visual Studio 2019 (x86, x64) * macOS (using libc++) @@ -92,6 +93,7 @@ In appreciation of all contributions here are the people that have [directly con [<img alt="irrequietus" src="https://avatars0.githubusercontent.com/u/231192?v=4&s=117" width="117">](https://github.com/irrequietus) [<img alt="jedelbo" src="https://avatars2.githubusercontent.com/u/572755?v=4&s=117" width="117">](https://github.com/jedelbo) [<img alt="joelfrederico" src="https://avatars0.githubusercontent.com/u/458871?v=4&s=117" width="117">](https://github.com/joelfrederico) +[<img alt="johelegp" src="https://avatars3.githubusercontent.com/u/21071787?v=4&s=117" width="117">](https://github.com/johelegp) [<img alt="jovermann" src="https://avatars3.githubusercontent.com/u/6087443?v=4&s=117" width="117">](https://github.com/jovermann) [<img alt="kneth" src="https://avatars0.githubusercontent.com/u/1225363?v=4&s=117" width="117">](https://github.com/kneth) [<img alt="kuzmas" src="https://avatars1.githubusercontent.com/u/1858553?v=4&s=117" width="117">](https://github.com/kuzmas) @@ -100,18 +102,22 @@ In appreciation of all contributions here are the people that have [directly con [<img alt="michael-brade" src="https://avatars0.githubusercontent.com/u/8768950?v=4&s=117" width="117">](https://github.com/michael-brade) [<img alt="mkrupcale" src="https://avatars1.githubusercontent.com/u/13936020?v=4&s=117" width="117">](https://github.com/mkrupcale) [<img alt="NewProggie" src="https://avatars3.githubusercontent.com/u/162319?s=460&v=4?v=4&s=117" width="117">](https://github.com/NewProggie) +[<img alt="ohanar" src="https://avatars0.githubusercontent.com/u/1442822?v=4&s=117" width="117">](https://github.com/ohanar) [<img alt="pauloscustodio" src="https://avatars1.githubusercontent.com/u/70773?v=4&s=117" width="117">](https://github.com/pauloscustodio) [<img alt="pleroux0" src="https://avatars2.githubusercontent.com/u/39619854?v=4&s=117" width="117">](https://github.com/pleroux0) [<img alt="quadfault" src="https://avatars3.githubusercontent.com/u/30195320?v=4&s=117" width="117">](https://github.com/quadfault) +[<img alt="robertcampion" src="https://avatars2.githubusercontent.com/u/4220569?v=4&s=117" width="117">](https://github.com/robertcampion) [<img alt="samhocevar" src="https://avatars2.githubusercontent.com/u/245089?v=4&s=117" width="117">](https://github.com/samhocevar) [<img alt="sanssecours" src="https://avatars2.githubusercontent.com/u/691989?v=4&s=117" width="117">](https://github.com/sanssecours) [<img alt="sgbeal" src="https://avatars1.githubusercontent.com/u/235303?v=4&s=117" width="117">](https://github.com/sgbeal) +[<img alt="skyrich62" src="https://avatars3.githubusercontent.com/u/23705081?v=4&s=117" width="117">](https://github.com/skyrich62) [<img alt="studoot" src="https://avatars1.githubusercontent.com/u/799344?v=4&s=117" width="117">](https://github.com/studoot) [<img alt="SvenJo" src="https://avatars1.githubusercontent.com/u/1538181?s=460&v=4?v=4&s=117" width="117">](https://github.com/SvenJo) [<img alt="wickedmic" src="https://avatars1.githubusercontent.com/u/12001183?v=4&s=117" width="117">](https://github.com/wickedmic) [<img alt="wravery" src="https://avatars0.githubusercontent.com/u/6502881?v=4&s=117" width="117">](https://github.com/wravery) [<img alt="zhihaoy" src="https://avatars2.githubusercontent.com/u/43971430?v=4&s=117" width="117">](https://github.com/zhihaoy) + ## The Art of C++ The PEGTL is part of [The Art of C++](https://taocpp.github.io/). diff --git a/packages/PEGTL/doc/Changelog.md b/packages/PEGTL/doc/Changelog.md index 9fc17ba38b84307c1c64a9aed9a32c748b282549..078aadc896fefff77c8a1d83c2baf886d5f7b5db 100644 --- a/packages/PEGTL/doc/Changelog.md +++ b/packages/PEGTL/doc/Changelog.md @@ -18,12 +18,21 @@ * Removed compatibility uppercase enumerators. * Removed compatibility `peek_byte()` member functions. * Removed compatibility header `changes.hpp` from contrib. +* Refactored demangling. + * Improves generated code to be shorter and more efficient. + * Removes the need for RTTI. + * Some broken/unknown compilers will use RTTI as a fallback, without demangling. +* Refactored parse tree type storage/handling. + * Removes the need for RTTI. ## 2.8.1 -**Not yet released** +Released 2019-08-06 +* Added fallback symbol demangling if RTTI is disabled. * Fixed missing `string_input<>` in amalgamated header. +* Fixed `discard_input*` actions to properly forward the apply mode. +* Fixed contrib HTTP grammar for chunked data. ## 2.8.0 diff --git a/packages/PEGTL/doc/Inputs-and-Parsing.md b/packages/PEGTL/doc/Inputs-and-Parsing.md index 0066d35c62111bca3cc550747b2684f597c356bd..ba7b9d36267a4a4c47eabe281b173d771298bcf6 100644 --- a/packages/PEGTL/doc/Inputs-and-Parsing.md +++ b/packages/PEGTL/doc/Inputs-and-Parsing.md @@ -42,7 +42,7 @@ All classes and functions on this page are in namespace `tao::pegtl`. * [Nested Parsing](#nested-parsing) * [Incremental Input](#incremental-input) * [Buffer Size](#buffer-size) - * [Discard Input](#discard-input) + * [Discard Buffer](#discard-buffer) * [Custom Rules](#custom-rules) * [Custom Readers](#custom-readers) * [Buffer Details](#buffer-details) @@ -389,6 +389,10 @@ To prevent the buffer from overflowing, the `discard()` member function of class **Discarding invalidates all pointers to the input's data and MUST NOT be used where backtracking to before the discard might occur AND/OR nested within a rule for which an action with input can be called.** +Calling `discard()` on a non-buffered input is an empty method and will be optimised away completely. + +Usually you don't call `discard()` manually. Instead, one of the two following methods might be used. + #### Via Rules The [`discard`](Rule-Reference#discard) rule behaves just like the [`success`](Rule-Reference.md#success) rule but calls the discard function on the input before returning `true`. @@ -399,6 +403,7 @@ The `tao::pegtl::discard_input`, `tao::pegtl::discard_input_on_success` and `tao These actions are used in the usual way, by deriving a custom action class template specialisation from them. In the case of `discard_input`, the input is discarded unconditionally after every match attempt of the rule that the action is attached to. +As `discard_input` is based on the `match()` method, it is unaffected by enabling or disabling actions (which only applies to the `apply`/`apply0`-methods). The other two variants behave as implied by their respective names, keeping in mind that "failure" is to be understood as "local failure" (false), no discard is performed on global failure (exception). Similarly "unconditional" is wrt. success or local failure, not global failure. @@ -436,7 +441,7 @@ struct my_action< rep< 4, must< xdigit > > : tao::pegtl::discard_input { template< typename Input > - void apply( const Input& in, /* the states */ ) + static void apply( const Input& in, /* the states */ ) { assert( in.size() == 4 ); // process the 4 xdigits diff --git a/packages/PEGTL/doc/Parse-Tree.md b/packages/PEGTL/doc/Parse-Tree.md index cc1f319239719325fdd0d571fb6d26dce316eb0e..c7486df66c7e4c637b3afa217d01a1ae2836ab2b 100644 --- a/packages/PEGTL/doc/Parse-Tree.md +++ b/packages/PEGTL/doc/Parse-Tree.md @@ -154,18 +154,19 @@ struct basic_node using children_t = std::vector< std::unique_ptr< node_t > >; children_t children; - std::type_index id; + std::string_view type; std::string source; + bool is_root() const noexcept; + template< typename U > - bool is() const noexcept { return id == typeid( U ); } + bool is_type() const noexcept; - bool is_root() const noexcept; + template< typename U > + void set_type() noexcept; // precondition from here on: !is_root() - std::string name() const; - position begin() const; position end() const; diff --git a/packages/PEGTL/doc/README.md b/packages/PEGTL/doc/README.md index 7c9acc81db8ac8f92b8ee3cace061f568045de7b..b5b00b794a2924159f3971ee6745c508df6a9930 100644 --- a/packages/PEGTL/doc/README.md +++ b/packages/PEGTL/doc/README.md @@ -76,7 +76,7 @@ * [Nested Parsing](Inputs-and-Parsing.md#nested-parsing) * [Incremental Input](Inputs-and-Parsing.md#incremental-input) * [Buffer Size](Inputs-and-Parsing.md#buffer-size) - * [Discard Input](Inputs-and-Parsing.md#discard-input) + * [Discard Buffer](Inputs-and-Parsing.md#discard-buffer) * [Custom Rules](Inputs-and-Parsing.md#custom-rules) * [Custom Readers](Inputs-and-Parsing.md#custom-readers) * [Buffer Details](Inputs-and-Parsing.md#buffer-details) diff --git a/packages/PEGTL/doc/Rule-Reference.md b/packages/PEGTL/doc/Rule-Reference.md index 160f743724414f650cd0ff51f711319aefecb590..8ac40c7ebb97b489629d7d052df665838af2d7e0 100644 --- a/packages/PEGTL/doc/Rule-Reference.md +++ b/packages/PEGTL/doc/Rule-Reference.md @@ -640,11 +640,11 @@ Because of the external dependency, the rules are in the contrib-section, and th The ICU-based rules are again available in multiple versions, -* in namespace `tao::pegtl::icu::utf8` for UTF-8 encoded inputs, -* in namespace `tao::pegtl::icu::utf16_be` for big-endian UTF-16 encoded inputs, -* in namespace `tao::pegtl::icu::utf16_le` for little-endian UTF-16 encoded inputs, -* in namespace `tao::pegtl::icu::utf32_be` for big-endian UTF-32 encoded inputs, and -* in namespace `tao::pegtl::icu::utf32_le` for little-endian UTF-32 encoded inputs. +* in namespace `tao::pegtl::utf8::icu` for UTF-8 encoded inputs, +* in namespace `tao::pegtl::utf16_be::icu` for big-endian UTF-16 encoded inputs, +* in namespace `tao::pegtl::utf16_le::icu` for little-endian UTF-16 encoded inputs, +* in namespace `tao::pegtl::utf32_be::icu` for big-endian UTF-32 encoded inputs, and +* in namespace `tao::pegtl::utf32_le::icu` for little-endian UTF-32 encoded inputs. To use these rules it is necessary to provide an include path to the ICU library, to link the application against `libicu`, and to manually include one or more of the following header files: diff --git a/packages/PEGTL/include/tao/pegtl/analysis/analyze_cycles.hpp b/packages/PEGTL/include/tao/pegtl/analysis/analyze_cycles.hpp index 9f7ce5f83b130b1a548f1f098c8c3f7a1b702e44..0b8e60edf67c18247389e565ef5e0a476bc9c252 100644 --- a/packages/PEGTL/include/tao/pegtl/analysis/analyze_cycles.hpp +++ b/packages/PEGTL/include/tao/pegtl/analysis/analyze_cycles.hpp @@ -9,6 +9,7 @@ #include <map> #include <set> #include <stdexcept> +#include <string_view> #include <iostream> #include <utility> @@ -20,7 +21,7 @@ namespace TAO_PEGTL_NAMESPACE::analysis { - class analyze_cycles_impl + struct analyze_cycles_impl { protected: explicit analyze_cycles_impl( const bool verbose ) noexcept @@ -32,18 +33,18 @@ namespace TAO_PEGTL_NAMESPACE::analysis const bool m_verbose; unsigned m_problems; grammar_info m_info; - std::set< std::string > m_stack; - std::map< std::string, bool > m_cache; - std::map< std::string, bool > m_results; + std::set< std::string_view > m_stack; + std::map< std::string_view, bool > m_cache; + std::map< std::string_view, bool > m_results; - [[nodiscard]] std::map< std::string, rule_info >::const_iterator find( const std::string& name ) const noexcept + [[nodiscard]] std::map< std::string_view, rule_info >::const_iterator find( const std::string_view name ) const noexcept { const auto iter = m_info.map.find( name ); assert( iter != m_info.map.end() ); return iter; } - [[nodiscard]] bool work( const std::map< std::string, rule_info >::const_iterator& start, const bool accum ) + [[nodiscard]] bool work( const std::map< std::string_view, rule_info >::const_iterator& start, const bool accum ) { const auto j = m_cache.find( start->first ); @@ -81,7 +82,7 @@ namespace TAO_PEGTL_NAMESPACE::analysis return m_cache[ start->first ] = a; } } - throw std::logic_error( "code should be unreachable: invalid rule_type value" ); // NOLINT, LCOV_EXCL_LINE + throw std::logic_error( "code should be unreachable: invalid rule_type value" ); // LCOV_EXCL_LINE } if( !accum ) { ++m_problems; @@ -94,10 +95,9 @@ namespace TAO_PEGTL_NAMESPACE::analysis }; template< typename Grammar > - class analyze_cycles + struct analyze_cycles : private analyze_cycles_impl { - public: explicit analyze_cycles( const bool verbose ) : analyze_cycles_impl( verbose ) { diff --git a/packages/PEGTL/include/tao/pegtl/analysis/counted.hpp b/packages/PEGTL/include/tao/pegtl/analysis/counted.hpp index 2c1939ca1dc88282d178f373c0243fa89696c0a5..e2ac6fb242d62b16f57d2ce24e8f648ea9ad683b 100644 --- a/packages/PEGTL/include/tao/pegtl/analysis/counted.hpp +++ b/packages/PEGTL/include/tao/pegtl/analysis/counted.hpp @@ -6,11 +6,13 @@ #include "../config.hpp" +#include <cstddef> + #include "generic.hpp" namespace TAO_PEGTL_NAMESPACE::analysis { - template< rule_type Type, unsigned Count, typename... Rules > + template< rule_type Type, std::size_t Count, typename... Rules > struct counted : generic< ( Count != 0 ) ? Type : rule_type::opt, Rules... > { diff --git a/packages/PEGTL/include/tao/pegtl/analysis/generic.hpp b/packages/PEGTL/include/tao/pegtl/analysis/generic.hpp index ae8685ab84b3915a1e8cf3c39666b2138ea7a8df..e41816b98b2ffa740076c5d33a2b2928493f6c27 100644 --- a/packages/PEGTL/include/tao/pegtl/analysis/generic.hpp +++ b/packages/PEGTL/include/tao/pegtl/analysis/generic.hpp @@ -16,7 +16,7 @@ namespace TAO_PEGTL_NAMESPACE::analysis struct generic { template< typename Name > - static std::string insert( grammar_info& g ) + static std::string_view insert( grammar_info& g ) { const auto [ it, success ] = g.insert< Name >( Type ); if( success ) { diff --git a/packages/PEGTL/include/tao/pegtl/analysis/grammar_info.hpp b/packages/PEGTL/include/tao/pegtl/analysis/grammar_info.hpp index a6f63ed68189dc60b69df12e7e415195a7ca0fdb..d25a701d90f45d5ad61598a2e1dd296d6338aee0 100644 --- a/packages/PEGTL/include/tao/pegtl/analysis/grammar_info.hpp +++ b/packages/PEGTL/include/tao/pegtl/analysis/grammar_info.hpp @@ -17,13 +17,13 @@ namespace TAO_PEGTL_NAMESPACE::analysis { struct grammar_info { - using map_t = std::map< std::string, rule_info >; + using map_t = std::map< std::string_view, rule_info >; map_t map; template< typename Name > auto insert( const rule_type type ) { - return map.emplace( internal::demangle< Name >(), rule_info( type ) ); + return map.try_emplace( internal::demangle< Name >(), rule_info( type ) ); } }; diff --git a/packages/PEGTL/include/tao/pegtl/argv_input.hpp b/packages/PEGTL/include/tao/pegtl/argv_input.hpp index c7b1430d02086f3d0f1cb76ba3e72ecbef246f4c..48da349671994312cc9208b2bbbe5fcb3b8acf2b 100644 --- a/packages/PEGTL/include/tao/pegtl/argv_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/argv_input.hpp @@ -29,15 +29,15 @@ namespace TAO_PEGTL_NAMESPACE template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf > struct argv_input - : public memory_input< P, Eol > + : memory_input< P, Eol > { template< typename T > - argv_input( char** argv, const std::size_t argn, T&& in_source ) // NOLINT + argv_input( char** argv, const std::size_t argn, T&& in_source ) : memory_input< P, Eol >( static_cast< const char* >( argv[ argn ] ), std::forward< T >( in_source ) ) { } - argv_input( char** argv, const std::size_t argn ) // NOLINT + argv_input( char** argv, const std::size_t argn ) : argv_input( argv, argn, internal::make_argv_source( argn ) ) { } diff --git a/packages/PEGTL/include/tao/pegtl/buffer_input.hpp b/packages/PEGTL/include/tao/pegtl/buffer_input.hpp index 0487b48ec90344bbc233a0391c33f0236be8ec30..b83af7956856becc460aaaf5ed989d90b1f42e87 100644 --- a/packages/PEGTL/include/tao/pegtl/buffer_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/buffer_input.hpp @@ -201,7 +201,7 @@ namespace TAO_PEGTL_NAMESPACE private: Reader m_reader; std::size_t m_maximum; - std::unique_ptr< char[] > m_buffer; // NOLINT + std::unique_ptr< char[] > m_buffer; iterator_t m_current; char* m_end; const Source m_source; diff --git a/packages/PEGTL/include/tao/pegtl/change_action_and_states.hpp b/packages/PEGTL/include/tao/pegtl/change_action_and_states.hpp index c4fd02eeeafbfc022d499eddbaab42a26fae2cbe..1fb3b3de58b3a72f5710d46068496d9ecfce19d8 100644 --- a/packages/PEGTL/include/tao/pegtl/change_action_and_states.hpp +++ b/packages/PEGTL/include/tao/pegtl/change_action_and_states.hpp @@ -29,7 +29,7 @@ namespace TAO_PEGTL_NAMESPACE std::size_t... Ns, typename Input, typename... States > - [[nodiscard]] static bool match( std::index_sequence< Ns... >, Input& in, States&&... st ) + [[nodiscard]] static bool match( std::index_sequence< Ns... > /*unused*/, Input& in, States&&... st ) { auto t = std::tie( st... ); if( Control< Rule >::template match< A, M, NewAction, Control >( in, std::get< Ns >( t )... ) ) { diff --git a/packages/PEGTL/include/tao/pegtl/change_states.hpp b/packages/PEGTL/include/tao/pegtl/change_states.hpp index 09d49dd10c359f108458fa4d976aa533acd2fb76..2a907356b7bf709d82b36860fb375fb8dfb44d95 100644 --- a/packages/PEGTL/include/tao/pegtl/change_states.hpp +++ b/packages/PEGTL/include/tao/pegtl/change_states.hpp @@ -29,7 +29,7 @@ namespace TAO_PEGTL_NAMESPACE std::size_t... Ns, typename Input, typename... States > - [[nodiscard]] static bool match( std::index_sequence< Ns... >, Input& in, States&&... st ) + [[nodiscard]] static bool match( std::index_sequence< Ns... > /*unused*/, Input& in, States&&... st ) { auto t = std::tie( st... ); if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, std::get< Ns >( t )... ) ) { diff --git a/packages/PEGTL/include/tao/pegtl/config.hpp b/packages/PEGTL/include/tao/pegtl/config.hpp index 4bcdd10353d9d0ffbe3e97059a0fd07b03e8e538..bb63adfc525ee3a60e50f4902849b60b42adf327 100644 --- a/packages/PEGTL/include/tao/pegtl/config.hpp +++ b/packages/PEGTL/include/tao/pegtl/config.hpp @@ -8,8 +8,4 @@ #define TAO_PEGTL_NAMESPACE tao::pegtl #endif -// Enable some improvements to the readability of -// demangled type names under some circumstances. -// #define TAO_PEGTL_PRETTY_DEMANGLE - #endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/alphabet.hpp b/packages/PEGTL/include/tao/pegtl/contrib/alphabet.hpp index e1d3292d562b6358d40d9549bb56ca00357c4d10..942c6e1c1fb54e2ded9c9f5650a76f96c0325875 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/alphabet.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/alphabet.hpp @@ -35,32 +35,32 @@ namespace TAO_PEGTL_NAMESPACE::alphabet static const int y = 'y'; static const int z = 'z'; - static const int A = 'A'; - static const int B = 'B'; - static const int C = 'C'; - static const int D = 'D'; - static const int E = 'E'; - static const int F = 'F'; - static const int G = 'G'; - static const int H = 'H'; - static const int I = 'I'; - static const int J = 'J'; - static const int K = 'K'; - static const int L = 'L'; - static const int M = 'M'; - static const int N = 'N'; - static const int O = 'O'; - static const int P = 'P'; - static const int Q = 'Q'; - static const int R = 'R'; - static const int S = 'S'; - static const int T = 'T'; - static const int U = 'U'; - static const int V = 'V'; - static const int W = 'W'; - static const int X = 'X'; - static const int Y = 'Y'; - static const int Z = 'Z'; + static const int A = 'A'; // NOLINT(readability-identifier-naming) + static const int B = 'B'; // NOLINT(readability-identifier-naming) + static const int C = 'C'; // NOLINT(readability-identifier-naming) + static const int D = 'D'; // NOLINT(readability-identifier-naming) + static const int E = 'E'; // NOLINT(readability-identifier-naming) + static const int F = 'F'; // NOLINT(readability-identifier-naming) + static const int G = 'G'; // NOLINT(readability-identifier-naming) + static const int H = 'H'; // NOLINT(readability-identifier-naming) + static const int I = 'I'; // NOLINT(readability-identifier-naming) + static const int J = 'J'; // NOLINT(readability-identifier-naming) + static const int K = 'K'; // NOLINT(readability-identifier-naming) + static const int L = 'L'; // NOLINT(readability-identifier-naming) + static const int M = 'M'; // NOLINT(readability-identifier-naming) + static const int N = 'N'; // NOLINT(readability-identifier-naming) + static const int O = 'O'; // NOLINT(readability-identifier-naming) + static const int P = 'P'; // NOLINT(readability-identifier-naming) + static const int Q = 'Q'; // NOLINT(readability-identifier-naming) + static const int R = 'R'; // NOLINT(readability-identifier-naming) + static const int S = 'S'; // NOLINT(readability-identifier-naming) + static const int T = 'T'; // NOLINT(readability-identifier-naming) + static const int U = 'U'; // NOLINT(readability-identifier-naming) + static const int V = 'V'; // NOLINT(readability-identifier-naming) + static const int W = 'W'; // NOLINT(readability-identifier-naming) + static const int X = 'X'; // NOLINT(readability-identifier-naming) + static const int Y = 'Y'; // NOLINT(readability-identifier-naming) + static const int Z = 'Z'; // NOLINT(readability-identifier-naming) } // namespace TAO_PEGTL_NAMESPACE::alphabet diff --git a/packages/PEGTL/include/tao/pegtl/contrib/counter.hpp b/packages/PEGTL/include/tao/pegtl/contrib/counter.hpp index fab396f936736fbb5742c00d60231feacef768c3..e3a9e72699ad9b2690144f0136a6185cfee3fc81 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/counter.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/counter.hpp @@ -5,7 +5,7 @@ #define TAO_PEGTL_CONTRIB_COUNTER_HPP #include <map> -#include <string> +#include <string_view> #include "../config.hpp" #include "../normal.hpp" @@ -23,7 +23,7 @@ namespace TAO_PEGTL_NAMESPACE struct counter_state { - std::map< std::string, counter_data > counts; + std::map< std::string_view, counter_data > counts; }; template< typename Rule > diff --git a/packages/PEGTL/include/tao/pegtl/contrib/http.hpp b/packages/PEGTL/include/tao/pegtl/contrib/http.hpp index 3d28f466a10b920119c849452c4ca7d87640400a..329035cacf68416a409ac7eb2482300379c4c35c 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/http.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/http.hpp @@ -6,10 +6,12 @@ #include "../ascii.hpp" #include "../config.hpp" +#include "../nothing.hpp" #include "../rules.hpp" #include "../utf8.hpp" #include "abnf.hpp" +#include "remove_first_state.hpp" #include "uri.hpp" namespace TAO_PEGTL_NAMESPACE::http @@ -120,17 +122,126 @@ namespace TAO_PEGTL_NAMESPACE::http struct partial_URI : seq< uri::relative_part, uri::opt_query > {}; - struct chunk_size : plus< abnf::HEXDIG > {}; + // clang-format on + struct chunk_size + { + using analyze_t = plus< abnf::HEXDIG >::analyze_t; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename Input, + typename... States > + [[nodiscard]] static bool match( Input& in, std::size_t& size, States&&... /*unused*/ ) + { + size = 0; + std::size_t i = 0; + while( in.size( i + 1 ) >= i + 1 ) { + const auto c = in.peek_char( i ); + if( ( '0' <= c ) && ( c <= '9' ) ) { + size <<= 4; + size |= std::size_t( c - '0' ); + ++i; + continue; + } + if( ( 'a' <= c ) && ( c <= 'f' ) ) { + size <<= 4; + size |= std::size_t( c - 'a' + 10 ); + ++i; + continue; + } + if( ( 'A' <= c ) && ( c <= 'F' ) ) { + size <<= 4; + size |= std::size_t( c - 'A' + 10 ); + ++i; + continue; + } + break; + } + in.bump_in_this_line( i ); + return i > 0; + } + }; + // clang-format off struct chunk_ext_name : token {}; struct chunk_ext_val : sor< quoted_string, token > {}; struct chunk_ext : star_must< one< ';' >, chunk_ext_name, if_must< one< '=' >, chunk_ext_val > > {}; - struct chunk_data : until< at< abnf::CRLF >, abnf::OCTET > {}; - - struct chunk : seq< chunk_size, opt< chunk_ext >, abnf::CRLF, chunk_data, abnf::CRLF > {}; + // clang-format on + struct chunk_data + { + using analyze_t = star< abnf::OCTET >::analyze_t; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename Input, + typename... States > + [[nodiscard]] static bool match( Input& in, const std::size_t size, States&&... /*unused*/ ) + { + if( in.size( size ) >= size ) { + in.bump( size ); + return true; + } + return false; + } + }; + + namespace internal::chunk_helper + { + template< typename Rule, template< typename... > class Control > + struct control + : remove_self_and_first_state< Rule, Control > + {}; + + template< template< typename... > class Control > + struct control< chunk_size, Control > + : remove_first_state_after_match< chunk_size, Control > + {}; + + template< template< typename... > class Control > + struct control< chunk_data, Control > + : remove_first_state_after_match< chunk_data, Control > + {}; + + template< template< typename... > class Control > + struct bind + { + template< typename Rule > + using type = control< Rule, Control >; + }; + + } // namespace internal::chunk_helper + + struct chunk + { + using impl = seq< chunk_size, chunk_ext, abnf::CRLF, chunk_data, abnf::CRLF >; + using analyze_t = impl::analyze_t; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename Input, + typename... States > + [[nodiscard]] static bool match( Input& in, States&&... st ) + { + std::size_t size{}; + return impl::template match< A, M, Action, internal::chunk_helper::bind< Control >::template type >( in, size, st... ); + } + }; - struct last_chunk : seq< plus< one< '0' > >, opt< chunk_ext >, abnf::CRLF > {}; + // clang-format off + struct last_chunk : seq< plus< one< '0' > >, not_at< digit >, chunk_ext, abnf::CRLF > {}; struct trailer_part : star< header_field, abnf::CRLF > {}; diff --git a/packages/PEGTL/include/tao/pegtl/contrib/integer.hpp b/packages/PEGTL/include/tao/pegtl/contrib/integer.hpp index 2e9c8edb19b32b33515aaa290c84b8479c2154ef..fe1fd1ee84034da3bcdf025d0caf15884c4d1ead 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/integer.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/integer.hpp @@ -85,8 +85,8 @@ namespace TAO_PEGTL_NAMESPACE::integer { // Assumes input is a non-empty sequence of digits; returns false on overflow. - for( std::size_t i = 0; i < input.size(); ++i ) { - if( !accumulate_digit< Integer, Maximum >( result, input[ i ] ) ) { + for( char c : input ) { + if( !accumulate_digit< Integer, Maximum >( result, c ) ) { return false; } } @@ -194,7 +194,8 @@ namespace TAO_PEGTL_NAMESPACE::integer template< typename Input, typename Unsigned > static auto apply( const Input& in, Unsigned& st ) -> std::enable_if_t< std::is_unsigned_v< Unsigned >, void > { - st = 0; // This function "only" offers basic exception safety. + // This function "only" offers basic exception safety. + st = 0; if( !internal::convert_unsigned( st, in.string_view() ) ) { throw parse_error( "unsigned integer overflow", in ); } @@ -253,7 +254,8 @@ namespace TAO_PEGTL_NAMESPACE::integer typename Unsigned > [[nodiscard]] static auto match( Input& in, Unsigned& st ) -> std::enable_if_t< ( A == apply_mode::action ) && std::is_unsigned_v< Unsigned >, bool > { - st = 0; // This function "only" offers basic exception safety. + // This function "only" offers basic exception safety. + st = 0; return internal::match_and_convert_unsigned_with_maximum( in, st ); // Throws on overflow. } @@ -271,7 +273,8 @@ namespace TAO_PEGTL_NAMESPACE::integer template< typename Input, typename Unsigned2 > static auto apply( const Input& in, Unsigned2& st ) -> std::enable_if_t< std::is_same_v< Unsigned, Unsigned2 >, void > { - st = 0; // This function "only" offers basic exception safety. + // This function "only" offers basic exception safety. + st = 0; if( !internal::convert_unsigned< Unsigned, Maximum >( st, in.string_view() ) ) { throw parse_error( "unsigned integer overflow", in ); } @@ -338,7 +341,8 @@ namespace TAO_PEGTL_NAMESPACE::integer typename Unsigned2 > [[nodiscard]] static auto match( Input& in, Unsigned2& st ) -> std::enable_if_t< ( A == apply_mode::action ) && std::is_same_v< Unsigned, Unsigned2 >, bool > { - st = 0; // This function "only" offers basic exception safety. + // This function "only" offers basic exception safety. + st = 0; return internal::match_and_convert_unsigned_with_maximum< Input, Unsigned, Maximum >( in, st ); // Throws on overflow. } @@ -354,7 +358,8 @@ namespace TAO_PEGTL_NAMESPACE::integer template< typename Input, typename Signed > static auto apply( const Input& in, Signed& st ) -> std::enable_if_t< std::is_signed_v< Signed >, void > { - st = 0; // This function "only" offers basic exception safety. + // This function "only" offers basic exception safety. + st = 0; if( !internal::convert_signed( st, in.string_view() ) ) { throw parse_error( "signed integer overflow", in ); } @@ -379,15 +384,8 @@ namespace TAO_PEGTL_NAMESPACE::integer { using analyze_t = internal::signed_rule_new::analyze_t; - template< apply_mode A, - rewind_mode M, - template< typename... > - class Action, - template< typename... > - class Control, - typename Input, - typename... States > - [[nodiscard]] static bool match( Input& in, States&&... /*unused*/ ) noexcept( noexcept( in.empty() ) ) + template< typename Input > + [[nodiscard]] static bool match( Input& in ) noexcept( noexcept( in.empty() ) ) { return TAO_PEGTL_NAMESPACE::parse< internal::signed_rule_new >( in ); // Does not check for any overflow. } diff --git a/packages/PEGTL/include/tao/pegtl/contrib/json.hpp b/packages/PEGTL/include/tao/pegtl/contrib/json.hpp index a105f0ef810ec60e2ae55f220553808e4fa78289..565f9ee7d184a6ac78bfdffd9410b1ea1dc23aa4 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/json.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/json.hpp @@ -26,14 +26,14 @@ namespace TAO_PEGTL_NAMESPACE::json struct name_separator : pad< one< ':' >, ws > {}; struct value_separator : padr< one< ',' > > {}; - struct false_ : string< 'f', 'a', 'l', 's', 'e' > {}; + struct false_ : string< 'f', 'a', 'l', 's', 'e' > {}; // NOLINT(readability-identifier-naming) struct null : string< 'n', 'u', 'l', 'l' > {}; - struct true_ : string< 't', 'r', 'u', 'e' > {}; + struct true_ : string< 't', 'r', 'u', 'e' > {}; // NOLINT(readability-identifier-naming) struct digits : plus< digit > {}; struct exp : seq< one< 'e', 'E' >, opt< one< '-', '+'> >, must< digits > > {}; struct frac : if_must< one< '.' >, digits > {}; - struct int_ : sor< one< '0' >, digits > {}; + struct int_ : sor< one< '0' >, digits > {}; // NOLINT(readability-identifier-naming) struct number : seq< opt< one< '-' > >, int_, opt< frac >, opt< exp > > {}; struct xdigit : pegtl::xdigit {}; @@ -41,7 +41,7 @@ namespace TAO_PEGTL_NAMESPACE::json struct escaped_char : one< '"', '\\', '/', 'b', 'f', 'n', 'r', 't' > {}; struct escaped : sor< escaped_char, unicode > {}; struct unescaped : utf8::range< 0x20, 0x10FFFF > {}; - struct char_ : if_then_else< one< '\\' >, must< escaped >, unescaped > {}; + struct char_ : if_then_else< one< '\\' >, must< escaped >, unescaped > {}; // NOLINT(readability-identifier-naming) struct string_content : until< at< one< '"' > >, must< char_ > > {}; struct string : seq< one< '"' >, must< string_content >, any > diff --git a/packages/PEGTL/include/tao/pegtl/contrib/parse_tree.hpp b/packages/PEGTL/include/tao/pegtl/contrib/parse_tree.hpp index 61182d770a8748e438a0f033c647c18eb29cb809..222e127fd47c11fa18149b1783d295b6d7c62c5f 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/parse_tree.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/parse_tree.hpp @@ -34,7 +34,7 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree using children_t = std::vector< std::unique_ptr< node_t > >; children_t children; - std::type_index id = typeid( void ); + std::string_view type; std::string source; TAO_PEGTL_NAMESPACE::internal::iterator m_begin; @@ -56,19 +56,19 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree [[nodiscard]] bool is_root() const noexcept { - return id == typeid( void ); + return type.empty(); } template< typename U > - [[nodiscard]] bool is() const noexcept + [[nodiscard]] bool is_type() const noexcept { - return id == typeid( U ); + return type == TAO_PEGTL_NAMESPACE::internal::demangle< U >(); } - [[nodiscard]] std::string name() const + template< typename U > + void set_type() noexcept { - assert( !is_root() ); - return TAO_PEGTL_NAMESPACE::internal::demangle( id.name() ); + type = TAO_PEGTL_NAMESPACE::internal::demangle< U >(); } [[nodiscard]] position begin() const @@ -115,7 +115,7 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree template< typename Rule, typename Input, typename... States > void start( const Input& in, States&&... /*unused*/ ) { - id = typeid( Rule ); + set_type< Rule >(); source = in.source(); m_begin = TAO_PEGTL_NAMESPACE::internal::iterator( in.iterator() ); } @@ -185,9 +185,15 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree { } - // this one, if applicable, is more specialized than the above - template< typename Selector, typename Node, typename... States > - auto transform( std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( Selector::transform( n, st... ) ) ) + template< typename Selector, typename Input, typename Node, typename... States > + auto transform( const Input& in, std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( Selector::transform( in, n, st... ) ) ) + -> decltype( Selector::transform( in, n, st... ), void() ) + { + Selector::transform( in, n, st... ); + } + + template< typename Selector, typename Input, typename Node, typename... States > + auto transform( const Input& /*unused*/, std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( Selector::transform( n, st... ) ) ) -> decltype( Selector::transform( n, st... ), void() ) { Selector::transform( n, st... ); @@ -205,7 +211,7 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree { }; - template< analysis::rule_type Type, unsigned Count, template< typename... > class Selector > + template< analysis::rule_type Type, std::size_t Count, template< typename... > class Selector > struct is_leaf< 0, analysis::counted< Type, Count >, Selector > : std::true_type { @@ -217,7 +223,7 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree { }; - template< analysis::rule_type Type, unsigned Count, typename... Rules, template< typename... > class Selector > + template< analysis::rule_type Type, std::size_t Count, typename... Rules, template< typename... > class Selector > struct is_leaf< 0, analysis::counted< Type, Count, Rules... >, Selector > : std::false_type { @@ -232,7 +238,7 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree { }; - template< unsigned Level, analysis::rule_type Type, unsigned Count, typename... Rules, template< typename... > class Selector > + template< unsigned Level, analysis::rule_type Type, std::size_t Count, typename... Rules, template< typename... > class Selector > struct is_leaf< Level, analysis::counted< Type, Count, Rules... >, Selector > : std::bool_constant< ( is_unselected_leaf< Level - 1, Rules, Selector > && ... ) > { @@ -416,7 +422,7 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree auto n = std::move( state.back() ); state.pop_back(); n->template success< Rule >( in, st... ); - transform< Selector< Rule > >( n, st... ); + transform< Selector< Rule > >( in, n, st... ); if( n ) { state.back()->emplace_back( std::move( n ), st... ); } diff --git a/packages/PEGTL/include/tao/pegtl/contrib/parse_tree_to_dot.hpp b/packages/PEGTL/include/tao/pegtl/contrib/parse_tree_to_dot.hpp index e9f15892f44925b11921313313f1498bfb8f1b91..dc471d5af970f9e81871a0e6d60d4699dddc7165 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/parse_tree_to_dot.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/parse_tree_to_dot.hpp @@ -14,32 +14,88 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree { namespace internal { - void print_dot_node( std::ostream& os, const parse_tree::node& n, const std::string& s ) + inline void escape( std::ostream& os, const std::string_view s ) { - if( n.has_content() ) { - os << " x" << &n << " [ label=\"" << s << "\\n\\\"" << n.string_view() << "\\\"\" ]\n"; + static const char* h = "0123456789abcdef"; + + const char* p = s.data(); + const char* l = p; + const char* const e = s.data() + s.size(); + while( p != e ) { + const unsigned char c = *p; + if( c == '\\' ) { + os.write( l, p - l ); + l = ++p; + os << "\\\\"; + } + else if( c == '"' ) { + os.write( l, p - l ); + l = ++p; + os << "\\\""; + } + else if( c < 32 ) { + os.write( l, p - l ); + l = ++p; + switch( c ) { + case '\b': + os << "\\b"; + break; + case '\f': + os << "\\f"; + break; + case '\n': + os << "\\n"; + break; + case '\r': + os << "\\r"; + break; + case '\t': + os << "\\t"; + break; + default: + os << "\\u00" << h[ ( c & 0xf0 ) >> 4 ] << h[ c & 0x0f ]; + } + } + else if( c == 127 ) { + os.write( l, p - l ); + l = ++p; + os << "\\u007f"; + } + else { + ++p; + } } - else { - os << " x" << &n << " [ label=\"" << s << "\" ]\n"; + os.write( l, p - l ); + } + + template< typename Node > + void print_dot_node( std::ostream& os, const Node& n, const std::string_view s ) + { + os << " x" << &n << " [ label=\""; + escape( os, s ); + if( n.has_content() ) { + os << "\\n"; + escape( os, n.string_view() ); } + os << "\" ]\n"; if( !n.children.empty() ) { os << " x" << &n << " -> { "; for( auto& up : n.children ) { os << "x" << up.get() << ( ( up == n.children.back() ) ? " }\n" : ", " ); } for( auto& up : n.children ) { - print_dot_node( os, *up, up->name() ); + print_dot_node( os, *up, up->type ); } } } } // namespace internal - void print_dot( std::ostream& os, const parse_tree::node& n ) + template< typename Node > + void print_dot( std::ostream& os, const Node& n ) { - assert( n.is_root() ); os << "digraph parse_tree\n{\n"; - internal::print_dot_node( os, n, "ROOT" ); + internal::print_dot_node( os, n, n.is_root() ? "ROOT" : n.type ); os << "}\n"; } diff --git a/packages/PEGTL/include/tao/pegtl/contrib/remove_first_state.hpp b/packages/PEGTL/include/tao/pegtl/contrib/remove_first_state.hpp new file mode 100644 index 0000000000000000000000000000000000000000..df03abfea713dc1be2c004dc1fbeb6bf4d6868b1 --- /dev/null +++ b/packages/PEGTL/include/tao/pegtl/contrib/remove_first_state.hpp @@ -0,0 +1,86 @@ +// Copyright (c) 2019 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAO_PEGTL_CONTRIB_REMOVE_FIRST_STATE_HPP +#define TAO_PEGTL_CONTRIB_REMOVE_FIRST_STATE_HPP + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../rewind_mode.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + // NOTE: The naming of the following classes might still change. + + template< typename Rule, template< typename... > class Control > + struct remove_first_state_after_match + : Control< Rule > + { + template< typename Input, typename State, typename... States > + static void start( const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Control< Rule >::start( in, st... ) ) ) + { + Control< Rule >::start( in, st... ); + } + + template< typename Input, typename State, typename... States > + static void success( const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Control< Rule >::success( in, st... ) ) ) + { + Control< Rule >::success( in, st... ); + } + + template< typename Input, typename State, typename... States > + static void failure( const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Control< Rule >::failure( in, st... ) ) ) + { + Control< Rule >::failure( in, st... ); + } + + template< typename Input, typename State, typename... States > + static void raise( const Input& in, State&& /*unused*/, States&&... st ) + { + Control< Rule >::raise( in, st... ); + } + + template< template< typename... > class Action, + typename Iterator, + typename Input, + typename State, + typename... States > + static auto apply( const Iterator& begin, const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Control< Rule >::template apply< Action >( begin, in, st... ) ) ) + -> decltype( Control< Rule >::template apply< Action >( begin, in, st... ) ) + { + return Control< Rule >::template apply< Action >( begin, in, st... ); + } + + template< template< typename... > class Action, + typename Input, + typename State, + typename... States > + static auto apply0( const Input& in, State&& /*unused*/, States&&... st ) noexcept( noexcept( Control< Rule >::template apply0< Action >( in, st... ) ) ) + -> decltype( Control< Rule >::template apply0< Action >( in, st... ) ) + { + return Control< Rule >::template apply0< Action >( in, st... ); + } + }; + + template< typename Rule, template< typename... > class Control > + struct remove_self_and_first_state + : Control< Rule > + { + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class, + typename Input, + typename State, + typename... States > + [[nodiscard]] static bool match( Input& in, State&& /*unused*/, States&&... st ) + { + return Control< Rule >::template match< A, M, Action, Control >( in, st... ); + } + }; + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/to_string.hpp b/packages/PEGTL/include/tao/pegtl/contrib/to_string.hpp index 122ad57f3e8b805cbcc9a86a84bd0302b1ca624a..0cc8ea6254ba721911cb78db25d59f66e83234bb 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/to_string.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/to_string.hpp @@ -20,7 +20,7 @@ namespace TAO_PEGTL_NAMESPACE { [[nodiscard]] static std::string get() { - const char s[] = { Cs..., 0 }; // NOLINT + const char s[] = { Cs..., 0 }; return std::string( s, sizeof...( Cs ) ); } }; diff --git a/packages/PEGTL/include/tao/pegtl/contrib/unescape.hpp b/packages/PEGTL/include/tao/pegtl/contrib/unescape.hpp index ca3b57bcfbaf5c9b2c5949ca54fb1121e8a0b964..bdd6e1169dd2bf98ff85d19fe8d3070a0a31189d 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/unescape.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/unescape.hpp @@ -22,7 +22,7 @@ namespace TAO_PEGTL_NAMESPACE::unescape return true; } if( utf32 <= 0x7ff ) { - char tmp[] = { char( ( ( utf32 & 0x7c0 ) >> 6 ) | 0xc0 ), // NOLINT + char tmp[] = { char( ( ( utf32 & 0x7c0 ) >> 6 ) | 0xc0 ), char( ( ( utf32 & 0x03f ) ) | 0x80 ) }; string.append( tmp, sizeof( tmp ) ); return true; @@ -32,14 +32,14 @@ namespace TAO_PEGTL_NAMESPACE::unescape // nope, this is a UTF-16 surrogate return false; } - char tmp[] = { char( ( ( utf32 & 0xf000 ) >> 12 ) | 0xe0 ), // NOLINT + char tmp[] = { char( ( ( utf32 & 0xf000 ) >> 12 ) | 0xe0 ), char( ( ( utf32 & 0x0fc0 ) >> 6 ) | 0x80 ), char( ( ( utf32 & 0x003f ) ) | 0x80 ) }; string.append( tmp, sizeof( tmp ) ); return true; } if( utf32 <= 0x10ffff ) { - char tmp[] = { char( ( ( utf32 & 0x1c0000 ) >> 18 ) | 0xf0 ), // NOLINT + char tmp[] = { char( ( ( utf32 & 0x1c0000 ) >> 18 ) | 0xf0 ), char( ( ( utf32 & 0x03f000 ) >> 12 ) | 0x80 ), char( ( ( utf32 & 0x000fc0 ) >> 6 ) | 0x80 ), char( ( ( utf32 & 0x00003f ) ) | 0x80 ) }; @@ -80,7 +80,7 @@ namespace TAO_PEGTL_NAMESPACE::unescape case 'F': return I( c - 'A' + 10 ); default: // LCOV_EXCL_LINE - throw std::runtime_error( "invalid character in unhex" ); // NOLINT, LCOV_EXCL_LINE + throw std::runtime_error( "invalid character in unhex" ); // LCOV_EXCL_LINE } } @@ -133,7 +133,7 @@ namespace TAO_PEGTL_NAMESPACE::unescape return *( r.begin() + i ); } } - throw parse_error( "invalid character in unescape", in ); // NOLINT, LCOV_EXCL_LINE + throw parse_error( "invalid character in unescape", in ); // LCOV_EXCL_LINE } }; diff --git a/packages/PEGTL/include/tao/pegtl/cstream_input.hpp b/packages/PEGTL/include/tao/pegtl/cstream_input.hpp index 5a5aee72b7b5f2f235d9690cf3851333b1593136..d31a3add1082f0c5d078b70da51506f84caed7ad 100644 --- a/packages/PEGTL/include/tao/pegtl/cstream_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/cstream_input.hpp @@ -19,7 +19,7 @@ namespace TAO_PEGTL_NAMESPACE : buffer_input< internal::cstream_reader, Eol, std::string, Chunk > { template< typename T > - cstream_input( std::FILE* in_stream, const std::size_t in_maximum, T&& in_source ) // NOLINT + cstream_input( std::FILE* in_stream, const std::size_t in_maximum, T&& in_source ) : buffer_input< internal::cstream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream ) { } diff --git a/packages/PEGTL/include/tao/pegtl/discard_input.hpp b/packages/PEGTL/include/tao/pegtl/discard_input.hpp index 18d3c996a43fded8677bccd120e7834b499e1db4..d8a652e1348eb4507dacb8333dbe554aebc3f67b 100644 --- a/packages/PEGTL/include/tao/pegtl/discard_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/discard_input.hpp @@ -26,7 +26,7 @@ namespace TAO_PEGTL_NAMESPACE typename... States > [[nodiscard]] static bool match( Input& in, States&&... st ) { - const bool result = TAO_PEGTL_NAMESPACE::match< Rule, apply_mode::nothing, M, Action, Control >( in, st... ); + const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); in.discard(); return result; } diff --git a/packages/PEGTL/include/tao/pegtl/discard_input_on_failure.hpp b/packages/PEGTL/include/tao/pegtl/discard_input_on_failure.hpp index 4f9c99b5e27bdeb4b6bff7b1c1fb5bc1c5d25b27..917ab22d281e59499291b5b3089bb8aa79f8e60c 100644 --- a/packages/PEGTL/include/tao/pegtl/discard_input_on_failure.hpp +++ b/packages/PEGTL/include/tao/pegtl/discard_input_on_failure.hpp @@ -26,7 +26,7 @@ namespace TAO_PEGTL_NAMESPACE typename... States > [[nodiscard]] static bool match( Input& in, States&&... st ) { - const bool result = TAO_PEGTL_NAMESPACE::match< Rule, apply_mode::nothing, M, Action, Control >( in, st... ); + const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); if( !result ) { in.discard(); } diff --git a/packages/PEGTL/include/tao/pegtl/discard_input_on_success.hpp b/packages/PEGTL/include/tao/pegtl/discard_input_on_success.hpp index b373d686033486eef0b39d566c35e1bc0716f0bd..1c2ec0cc9fbe40eb6b933d485cd3cd13790326d9 100644 --- a/packages/PEGTL/include/tao/pegtl/discard_input_on_success.hpp +++ b/packages/PEGTL/include/tao/pegtl/discard_input_on_success.hpp @@ -26,7 +26,7 @@ namespace TAO_PEGTL_NAMESPACE typename... States > [[nodiscard]] static bool match( Input& in, States&&... st ) { - const bool result = TAO_PEGTL_NAMESPACE::match< Rule, apply_mode::nothing, M, Action, Control >( in, st... ); + const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); if( result ) { in.discard(); } diff --git a/packages/PEGTL/include/tao/pegtl/internal/action_input.hpp b/packages/PEGTL/include/tao/pegtl/internal/action_input.hpp index 84a97a3f62031e11c0da6378a3f795c83cde13fc..add66f9c4ac661b8e6ce0da9c982bd84611a1678 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/action_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/action_input.hpp @@ -52,7 +52,7 @@ namespace TAO_PEGTL_NAMESPACE::internal if constexpr( std::is_same_v< iterator_t, const char* > ) { return iterator(); } - else { // NOLINT + else { return iterator().data; } } @@ -74,7 +74,7 @@ namespace TAO_PEGTL_NAMESPACE::internal [[nodiscard]] std::string string() const { - return std::string( begin(), end() ); + return std::string( begin(), size() ); } [[nodiscard]] std::string_view string_view() const noexcept diff --git a/packages/PEGTL/include/tao/pegtl/internal/apply.hpp b/packages/PEGTL/include/tao/pegtl/internal/apply.hpp index 11616fcad9303b497aa5444ca5908f746dc83bea..983ad56f498f348242aa1e565bb85e93b8cd7207 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/apply.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/apply.hpp @@ -35,7 +35,7 @@ namespace TAO_PEGTL_NAMESPACE::internal const action_t i2( in.iterator(), in ); // No data -- range is from begin to begin. return ( apply_single< Actions >::match( i2, st... ) && ... ); } - else { // NOLINT + else { #if defined( _MSC_VER ) (void)in; (void)( (void)st, ... ); diff --git a/packages/PEGTL/include/tao/pegtl/internal/apply0.hpp b/packages/PEGTL/include/tao/pegtl/internal/apply0.hpp index 417ed7a61197440f6e7a2b169e1406ca2c0eeea0..bbc43a18aae58bc80981e823861e4da3d362db55 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/apply0.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/apply0.hpp @@ -33,7 +33,7 @@ namespace TAO_PEGTL_NAMESPACE::internal if constexpr( A == apply_mode::action ) { return ( apply0_single< Actions >::match( st... ) && ... ); } - else { // NOLINT + else { #if defined( _MSC_VER ) (void)( (void)st, ... ); #endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/demangle.hpp b/packages/PEGTL/include/tao/pegtl/internal/demangle.hpp index 07e55b837065e3314fbf168805a29eed39d08310..41a6f3b862aa043fb97a64e800c2fe3526482a0d 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/demangle.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/demangle.hpp @@ -4,25 +4,137 @@ #ifndef TAO_PEGTL_INTERNAL_DEMANGLE_HPP #define TAO_PEGTL_INTERNAL_DEMANGLE_HPP -#include <string> -#include <typeinfo> +#include <ciso646> +#include <string_view> #include "../config.hpp" -#if defined( __GLIBCXX__ ) || ( defined( __has_include ) && __has_include( <cxxabi.h> ) ) -#include "demangle_cxxabi.hpp" +namespace TAO_PEGTL_NAMESPACE::internal +{ +#if defined( __clang__ ) + +#if defined( _LIBCPP_VERSION ) + + template< typename T > + [[nodiscard]] constexpr std::string_view demangle() noexcept + { + constexpr const std::string_view sv = __PRETTY_FUNCTION__; + constexpr const auto begin = sv.find( '=' ); + static_assert( begin != std::string_view::npos ); + return sv.substr( begin + 2, sv.size() - begin - 3 ); + } + #else -#include "demangle_nop.hpp" + + // When using libstdc++ with clang, std::string_view::find is not constexpr :( + template< char C > + constexpr const char* find( const char* p, std::size_t n ) noexcept + { + while( n ) { + if( *p == C ) { + return p; + } + ++p; + --n; + } + return nullptr; + } + + template< typename T > + [[nodiscard]] constexpr std::string_view demangle() noexcept + { + constexpr const std::string_view sv = __PRETTY_FUNCTION__; + constexpr const auto begin = find< '=' >( sv.data(), sv.size() ); + static_assert( begin != nullptr ); + return { begin + 2, sv.end() - begin - 3 }; + } + #endif -namespace TAO_PEGTL_NAMESPACE::internal -{ +#elif defined( __GNUC__ ) + +#if( __GNUC__ == 7 ) + + // GCC 7 wrongly sometimes disallows __PRETTY_FUNCTION__ in constexpr functions, + // therefore we drop the 'constexpr' and hope for the best. + template< typename T > + [[nodiscard]] std::string_view demangle() noexcept + { + const std::string_view sv = __PRETTY_FUNCTION__; + const auto begin = sv.find( '=' ); + const auto tmp = sv.substr( begin + 2 ); + const auto end = tmp.rfind( ';' ); + return tmp.substr( 0, end ); + } + +#elif( __GNUC__ == 9 ) && ( __GNUC_MINOR__ < 3 ) + + // GCC 9.1 and 9.2 have a bug that leads to truncated __PRETTY_FUNCTION__ names, + // see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91155 template< typename T > - [[nodiscard]] std::string demangle() + [[nodiscard]] constexpr std::string_view demangle() noexcept { - return demangle( typeid( T ).name() ); + // fallback: requires RTTI, no demangling + return typeid( T ).name(); } +#else + + template< typename T > + [[nodiscard]] constexpr std::string_view demangle() noexcept + { + constexpr std::string_view sv = __PRETTY_FUNCTION__; + constexpr const auto begin = sv.find( '=' ); + static_assert( begin != std::string_view::npos ); + constexpr const auto tmp = sv.substr( begin + 2 ); + constexpr const auto end = tmp.rfind( ';' ); + static_assert( end != std::string_view::npos ); + return tmp.substr( 0, end ); + } + +#endif + +#elif defined( _MSC_VER ) + +#if( _MSC_VER < 1920 ) + + template< typename T > + [[nodiscard]] constexpr std::string_view demangle() noexcept + { + const std::string_view sv = __FUNCSIG__; + const auto begin = sv.find( "demangle<" ); + const auto tmp = sv.substr( begin + 9 ); + const auto end = tmp.rfind( '>' ); + return tmp.substr( 0, end ); + } + +#else + + template< typename T > + [[nodiscard]] constexpr std::string_view demangle() noexcept + { + constexpr std::string_view sv = __FUNCSIG__; + constexpr auto begin = sv.find( "demangle<" ); + static_assert( begin != std::string_view::npos ); + constexpr auto tmp = sv.substr( begin + 9 ); + constexpr auto end = tmp.rfind( '>' ); + static_assert( end != std::string_view::npos ); + return tmp.substr( 0, end ); + } + +#endif + +#else + + template< typename T > + [[nodiscard]] constexpr std::string_view demangle() noexcept + { + // fallback: requires RTTI, no demangling + return typeid( T ).name(); + } + +#endif + } // namespace TAO_PEGTL_NAMESPACE::internal #endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/demangle_cxxabi.hpp b/packages/PEGTL/include/tao/pegtl/internal/demangle_cxxabi.hpp deleted file mode 100644 index a7e5bc7bb16466c6b3c75bdece882e49a33a2661..0000000000000000000000000000000000000000 --- a/packages/PEGTL/include/tao/pegtl/internal/demangle_cxxabi.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey -// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ - -#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_CXXABI_HPP -#define TAO_PEGTL_INTERNAL_DEMANGLE_CXXABI_HPP - -#include <cstdlib> -#include <cxxabi.h> -#include <memory> -#include <string> - -#include "../config.hpp" - -#include "demangle_sanitise.hpp" - -namespace TAO_PEGTL_NAMESPACE::internal -{ - [[nodiscard]] inline std::string demangle( const char* symbol ) - { - const std::unique_ptr< char, decltype( &std::free ) > demangled( abi::__cxa_demangle( symbol, nullptr, nullptr, nullptr ), &std::free ); - if( !demangled ) { - return symbol; - } - std::string result( demangled.get() ); -#if defined( TAO_PEGTL_PRETTY_DEMANGLE ) - demangle_sanitise_chars( result ); // LCOV_EXCL_LINE -#endif - return result; - } - -} // namespace TAO_PEGTL_NAMESPACE::internal - -#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/demangle_nop.hpp b/packages/PEGTL/include/tao/pegtl/internal/demangle_nop.hpp deleted file mode 100644 index b178f040cae75662b753751ad95dc6580a82391b..0000000000000000000000000000000000000000 --- a/packages/PEGTL/include/tao/pegtl/internal/demangle_nop.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey -// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ - -#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_NOP_HPP -#define TAO_PEGTL_INTERNAL_DEMANGLE_NOP_HPP - -#include <string> - -#include "../config.hpp" - -namespace TAO_PEGTL_NAMESPACE::internal -{ - [[nodiscard]] inline std::string demangle( const char* symbol ) - { - return symbol; - } - -} // namespace TAO_PEGTL_NAMESPACE::internal - -#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/demangle_sanitise.hpp b/packages/PEGTL/include/tao/pegtl/internal/demangle_sanitise.hpp deleted file mode 100644 index 47f7549c6540e32bbb5ef24f01010315885c37f6..0000000000000000000000000000000000000000 --- a/packages/PEGTL/include/tao/pegtl/internal/demangle_sanitise.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2017-2019 Dr. Colin Hirsch and Daniel Frey -// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ - -#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_SANITISE_HPP -#define TAO_PEGTL_INTERNAL_DEMANGLE_SANITISE_HPP - -#include <string> - -#include "../config.hpp" - -namespace TAO_PEGTL_NAMESPACE::internal -{ - inline void demangle_sanitise_chars( std::string& s ) - { - std::string::size_type p; - while( ( p = s.find( "(char)" ) ) != std::string::npos ) { - int c = 0; - std::string::size_type q; - for( q = p + 6; ( q < s.size() ) && ( s[ q ] >= '0' ) && ( s[ q ] <= '9' ); ++q ) { - c *= 10; - c += s[ q ] - '0'; - } - if( c == '\'' ) { - s.replace( p, q - p, "'\\''" ); - } - else if( c == '\\' ) { - s.replace( p, q - p, "'\\\\'" ); - } - else if( ( c < 32 ) || ( c > 126 ) ) { - s.replace( p, 6, std::string() ); - } - else { - s.replace( p, q - p, std::string( 1, '\'' ) + char( c ) + '\'' ); - } - } - } - -} // namespace TAO_PEGTL_NAMESPACE::internal - -#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/duseltronik.hpp b/packages/PEGTL/include/tao/pegtl/internal/duseltronik.hpp index 6f1ca814e076e1d2f5dcf3ecee80622b4ea33059..c5ab5c6fadf0e8f801c3197b3236cf18be98b8b2 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/duseltronik.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/duseltronik.hpp @@ -10,6 +10,11 @@ #include "dusel_mode.hpp" +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4702 ) +#endif + namespace TAO_PEGTL_NAMESPACE::internal { template< typename Rule, @@ -175,4 +180,8 @@ namespace TAO_PEGTL_NAMESPACE::internal } // namespace TAO_PEGTL_NAMESPACE::internal +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + #endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/endian_gcc.hpp b/packages/PEGTL/include/tao/pegtl/internal/endian_gcc.hpp index 0079e3de5bc63251e416015c825a02d4a962525e..cde7368151c6a9eeb4cc6002c7933d1f731eca8c 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/endian_gcc.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/endian_gcc.hpp @@ -13,7 +13,7 @@ namespace TAO_PEGTL_NAMESPACE::internal #error No byte order defined! #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - template< unsigned S > + template< std::size_t S > struct to_and_from_be { template< typename T > @@ -23,7 +23,7 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; - template< unsigned S > + template< std::size_t S > struct to_and_from_le; template<> @@ -45,7 +45,7 @@ namespace TAO_PEGTL_NAMESPACE::internal { [[nodiscard]] static std::int16_t convert( const std::int16_t n ) noexcept { - return __builtin_bswap16( n ); + return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) ); } [[nodiscard]] static std::uint16_t convert( const std::uint16_t n ) noexcept @@ -68,7 +68,7 @@ namespace TAO_PEGTL_NAMESPACE::internal [[nodiscard]] static std::int32_t convert( const std::int32_t n ) noexcept { - return __builtin_bswap32( n ); + return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) ); } [[nodiscard]] static std::uint32_t convert( const std::uint32_t n ) noexcept @@ -91,7 +91,7 @@ namespace TAO_PEGTL_NAMESPACE::internal [[nodiscard]] static std::int64_t convert( const std::int64_t n ) noexcept { - return __builtin_bswap64( n ); + return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) ); } [[nodiscard]] static std::uint64_t convert( const std::uint64_t n ) noexcept @@ -106,7 +106,7 @@ namespace TAO_PEGTL_NAMESPACE::internal #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - template< unsigned S > + template< std::size_t S > struct to_and_from_le { template< typename T > @@ -116,7 +116,7 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; - template< unsigned S > + template< std::size_t S > struct to_and_from_be; template<> @@ -138,7 +138,7 @@ namespace TAO_PEGTL_NAMESPACE::internal { [[nodiscard]] static std::int16_t convert( const std::int16_t n ) noexcept { - return __builtin_bswap16( n ); + return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) ); } [[nodiscard]] static std::uint16_t convert( const std::uint16_t n ) noexcept @@ -161,7 +161,7 @@ namespace TAO_PEGTL_NAMESPACE::internal [[nodiscard]] static std::int32_t convert( const std::int32_t n ) noexcept { - return __builtin_bswap32( n ); + return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) ); } [[nodiscard]] static std::uint32_t convert( const std::uint32_t n ) noexcept @@ -182,12 +182,12 @@ namespace TAO_PEGTL_NAMESPACE::internal return n; } - [[nodiscard]] static std::uint64_t convert( const std::uint64_t n ) noexcept + [[nodiscard]] static std::int64_t convert( const std::int64_t n ) noexcept { - return __builtin_bswap64( n ); + return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) ); } - [[nodiscard]] static std::int64_t convert( const std::int64_t n ) noexcept + [[nodiscard]] static std::uint64_t convert( const std::uint64_t n ) noexcept { return __builtin_bswap64( n ); } diff --git a/packages/PEGTL/include/tao/pegtl/internal/endian_win.hpp b/packages/PEGTL/include/tao/pegtl/internal/endian_win.hpp index 63e92ff2df667aa906679cd8a325fbdf33521250..1a2f1ad4e3c652a94a4793849149901dd0025ab6 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/endian_win.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/endian_win.hpp @@ -10,7 +10,7 @@ namespace TAO_PEGTL_NAMESPACE::internal { - template< unsigned S > + template< std::size_t S > struct to_and_from_le { template< typename T > @@ -20,7 +20,7 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; - template< unsigned S > + template< std::size_t S > struct to_and_from_be; template<> diff --git a/packages/PEGTL/include/tao/pegtl/internal/file_mapper_posix.hpp b/packages/PEGTL/include/tao/pegtl/internal/file_mapper_posix.hpp index b639f052e214ba942a9dd8a58e91d02dd822a65b..af76c4ca5811ef4d5cd4094fcd0e9a873cb696e5 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/file_mapper_posix.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/file_mapper_posix.hpp @@ -39,7 +39,7 @@ namespace TAO_PEGTL_NAMESPACE::internal ~file_mapper() noexcept { // Legacy C interface requires pointer-to-mutable but does not write through the pointer. - ::munmap( const_cast< char* >( m_data ), m_size ); // NOLINT + ::munmap( const_cast< char* >( m_data ), m_size ); } void operator=( const file_mapper& ) = delete; diff --git a/packages/PEGTL/include/tao/pegtl/internal/file_opener.hpp b/packages/PEGTL/include/tao/pegtl/internal/file_opener.hpp index 3ab1be783c3920eadd03513a0268ce58703662d4..f25ae0d1578369aba6d4480c6c2f2a649dbd178e 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/file_opener.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/file_opener.hpp @@ -37,7 +37,7 @@ namespace TAO_PEGTL_NAMESPACE::internal [[nodiscard]] std::size_t size() const { - struct stat st; // NOLINT + struct stat st; errno = 0; if( ::fstat( m_fd, &st ) < 0 ) { const auto ec = errno; @@ -53,7 +53,7 @@ namespace TAO_PEGTL_NAMESPACE::internal [[nodiscard]] int open() const { errno = 0; - const int fd = ::open( m_source, // NOLINT + const int fd = ::open( m_source, O_RDONLY #if defined( O_CLOEXEC ) | O_CLOEXEC diff --git a/packages/PEGTL/include/tao/pegtl/internal/file_reader.hpp b/packages/PEGTL/include/tao/pegtl/internal/file_reader.hpp index 5b48f4bb08b907f797d821c988538ae6adcbe243..b5309f8469359ae6c6dd9631721f25684989b7cd 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/file_reader.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/file_reader.hpp @@ -21,9 +21,9 @@ namespace TAO_PEGTL_NAMESPACE::internal std::FILE* file; if( ::fopen_s( &file, filename, "rb" ) == 0 ) #elif defined( __MINGW32__ ) - if( auto* file = std::fopen( filename, "rb" ) ) // NOLINT(cppcoreguidelines-owning-memory) + if( auto* file = std::fopen( filename, "rb" ) ) #else - if( auto* file = std::fopen( filename, "rbe" ) ) // NOLINT(cppcoreguidelines-owning-memory) + if( auto* file = std::fopen( filename, "rbe" ) ) #endif { return file; @@ -36,7 +36,7 @@ namespace TAO_PEGTL_NAMESPACE::internal { void operator()( FILE* f ) const noexcept { - std::fclose( f ); // NOLINT(cppcoreguidelines-owning-memory) + std::fclose( f ); } }; diff --git a/packages/PEGTL/include/tao/pegtl/internal/if_apply.hpp b/packages/PEGTL/include/tao/pegtl/internal/if_apply.hpp index 342d94447f00ff27bb5e31761cf087cadaeefd17..03f0cf8a04aac1fe34ac153babe4879cd68527dc 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/if_apply.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/if_apply.hpp @@ -39,7 +39,7 @@ namespace TAO_PEGTL_NAMESPACE::internal } return false; } - else { // NOLINT + else { return Control< Rule >::template match< A, M, Action, Control >( in, st... ); } } diff --git a/packages/PEGTL/include/tao/pegtl/internal/istring.hpp b/packages/PEGTL/include/tao/pegtl/internal/istring.hpp index 4e9ce895d0dd1e7cde4e131af89a255fd7d9bde0..3f289a9da4f3c751df0a5b1d22943abd29135c70 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/istring.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/istring.hpp @@ -26,7 +26,7 @@ namespace TAO_PEGTL_NAMESPACE::internal if constexpr( is_alpha< C > ) { return ( C | 0x20 ) == ( c | 0x20 ); } - else { // NOLINT + else { return c == C; } } diff --git a/packages/PEGTL/include/tao/pegtl/internal/one.hpp b/packages/PEGTL/include/tao/pegtl/internal/one.hpp index 451140d036a555e0754d9573098df5f2d42a37e5..1524b1b4ade9ccf3775939627d3773a6590a077c 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/one.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/one.hpp @@ -4,8 +4,7 @@ #ifndef TAO_PEGTL_INTERNAL_ONE_HPP #define TAO_PEGTL_INTERNAL_ONE_HPP -#include <algorithm> -#include <utility> +#include <cstddef> #include "../config.hpp" @@ -17,12 +16,6 @@ namespace TAO_PEGTL_NAMESPACE::internal { - template< typename Char > - [[nodiscard]] bool contains( const Char c, const std::initializer_list< Char >& l ) noexcept - { - return std::find( l.begin(), l.end(), c ) != l.end(); - } - template< result_on_found R, typename Peek, typename Peek::data_t... Cs > struct one { @@ -33,7 +26,7 @@ namespace TAO_PEGTL_NAMESPACE::internal { if( const std::size_t s = in.size( Peek::max_input_size ); s >= Peek::min_input_size ) { if( const auto t = Peek::peek( in, s ) ) { - if( contains( t.data, { Cs... } ) == bool( R ) ) { + if( ( ( t.data == Cs ) || ... ) == bool( R ) ) { bump_help< R, Input, typename Peek::data_t, Cs... >( in, t.size ); return true; } @@ -43,26 +36,6 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; - template< result_on_found R, typename Peek, typename Peek::data_t C > - struct one< R, Peek, C > - { - using analyze_t = analysis::generic< analysis::rule_type::any >; - - template< typename Input > - [[nodiscard]] static bool match( Input& in ) noexcept( noexcept( in.size( Peek::max_input_size ) ) ) - { - if( const std::size_t s = in.size( Peek::max_input_size ); s >= Peek::min_input_size ) { - if( const auto t = Peek::peek( in, s ) ) { - if( ( t.data == C ) == bool( R ) ) { - bump_help< R, Input, typename Peek::data_t, C >( in, t.size ); - return true; - } - } - } - return false; - } - }; - template< result_on_found R, typename Peek, typename Peek::data_t... Cs > inline constexpr bool skip_control< one< R, Peek, Cs... > > = true; diff --git a/packages/PEGTL/include/tao/pegtl/internal/peek_utf32.hpp b/packages/PEGTL/include/tao/pegtl/internal/peek_utf32.hpp index 293d38fbad569e7e9ba32e278ff2aa010d9af3e2..c8da55dc0084b3aa1754d4506b1f4c8548dd1638 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/peek_utf32.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/peek_utf32.hpp @@ -28,7 +28,7 @@ namespace TAO_PEGTL_NAMESPACE::internal [[nodiscard]] static pair_t peek( const Input& in, const std::size_t /*unused*/ ) noexcept { const char32_t t = R::read( in.current() ); - if( ( 0 <= t ) && ( t <= 0x10ffff ) && !( t >= 0xd800 && t <= 0xdfff ) ) { + if( ( t <= 0x10ffff ) && !( t >= 0xd800 && t <= 0xdfff ) ) { return { t, 4 }; } return { 0, 0 }; diff --git a/packages/PEGTL/include/tao/pegtl/internal/pegtl_string.hpp b/packages/PEGTL/include/tao/pegtl/internal/pegtl_string.hpp index b523d66ca77d05182c5aad5f9c6774b96a82a978..babbc2c59ec21213224837cd3c862386a4bf1c48 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/pegtl_string.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/pegtl_string.hpp @@ -51,7 +51,7 @@ namespace TAO_PEGTL_NAMESPACE::internal #define TAO_PEGTL_INTERNAL_EXPAND( ... ) __VA_ARGS__ #define TAO_PEGTL_INTERNAL_STRING_AT( S, x, n ) \ - TAO_PEGTL_NAMESPACE::internal::string_at< S, ( 0##n < sizeof( x ) ) ? ( x )[ 0##n ] : 0, ( 0##n < sizeof( x ) - 1 ) >::type + TAO_PEGTL_NAMESPACE::internal::string_at< S, ( 0##n < ( sizeof( x ) / sizeof( char ) ) ) ? ( x )[ 0##n ] : 0, ( 0##n < ( sizeof( x ) / sizeof( char ) ) - 1 ) >::type #define TAO_PEGTL_INTERNAL_JOIN_8( M, S, x, n ) \ TAO_PEGTL_NAMESPACE::internal::string_join< TAO_PEGTL_INTERNAL_DEFER( M )( S, x, n##0 ), \ diff --git a/packages/PEGTL/include/tao/pegtl/internal/raise.hpp b/packages/PEGTL/include/tao/pegtl/internal/raise.hpp index 356ffcbd7de76f8769bbbb59bc6b02800a0cfc5d..fee7166fb48d689c13bdb7a6f922d797dd2395f7 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/raise.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/raise.hpp @@ -38,7 +38,7 @@ namespace TAO_PEGTL_NAMESPACE::internal [[nodiscard]] static bool match( Input& in, States&&... st ) { Control< T >::raise( static_cast< const Input& >( in ), st... ); - throw std::logic_error( "code should be unreachable: Control< T >::raise() did not throw an exception" ); // NOLINT, LCOV_EXCL_LINE + throw std::logic_error( "code should be unreachable: Control< T >::raise() did not throw an exception" ); // LCOV_EXCL_LINE #if defined( _MSC_VER ) #pragma warning( pop ) #endif diff --git a/packages/PEGTL/include/tao/pegtl/istream_input.hpp b/packages/PEGTL/include/tao/pegtl/istream_input.hpp index 55f559e24c6ce042587899e4549e58bf3e081ae3..975fe0264474a5d48fbddcf6269b6116e22ccad4 100644 --- a/packages/PEGTL/include/tao/pegtl/istream_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/istream_input.hpp @@ -19,7 +19,7 @@ namespace TAO_PEGTL_NAMESPACE : buffer_input< internal::istream_reader, Eol, std::string, Chunk > { template< typename T > - istream_input( std::istream& in_stream, const std::size_t in_maximum, T&& in_source ) // NOLINT + istream_input( std::istream& in_stream, const std::size_t in_maximum, T&& in_source ) : buffer_input< internal::istream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream ) { } diff --git a/packages/PEGTL/include/tao/pegtl/memory_input.hpp b/packages/PEGTL/include/tao/pegtl/memory_input.hpp index 1380d9a7967868b74515b78189a65f482089e22a..71f700535be6f78a411d8b9aa80e72e9dcb676a6 100644 --- a/packages/PEGTL/include/tao/pegtl/memory_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/memory_input.hpp @@ -251,7 +251,7 @@ namespace TAO_PEGTL_NAMESPACE using internal::memory_input_base< P, Eol, Source >::memory_input_base; template< typename T > - memory_input( const char* in_begin, const std::size_t in_size, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) // NOLINT + memory_input( const char* in_begin, const std::size_t in_size, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) : memory_input( in_begin, in_begin + in_size, std::forward< T >( in_source ) ) { } @@ -263,7 +263,7 @@ namespace TAO_PEGTL_NAMESPACE } template< typename T > - memory_input( const std::string_view in_string, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) // NOLINT + memory_input( const std::string_view in_string, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) : memory_input( in_string.data(), in_string.size(), std::forward< T >( in_source ) ) { } @@ -278,7 +278,7 @@ namespace TAO_PEGTL_NAMESPACE } template< typename T > - memory_input( const char* in_begin, const char* in_end, T&& in_source, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_byte_in_line ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) // NOLINT + memory_input( const char* in_begin, const char* in_end, T&& in_source, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_byte_in_line ) noexcept( std::is_nothrow_constructible_v< Source, T&& > ) : memory_input( { in_begin, in_byte, in_line, in_byte_in_line }, in_end, std::forward< T >( in_source ) ) { } diff --git a/packages/PEGTL/include/tao/pegtl/normal.hpp b/packages/PEGTL/include/tao/pegtl/normal.hpp index b7b323534139ce3ea97855b1f5324dd1470a5c12..67122bede14954d856783a37f057cf5a5c114d1d 100644 --- a/packages/PEGTL/include/tao/pegtl/normal.hpp +++ b/packages/PEGTL/include/tao/pegtl/normal.hpp @@ -4,6 +4,7 @@ #ifndef TAO_PEGTL_NORMAL_HPP #define TAO_PEGTL_NORMAL_HPP +#include <string> #include <type_traits> #include <utility> @@ -39,7 +40,7 @@ namespace TAO_PEGTL_NAMESPACE template< typename Input, typename... States > static void raise( const Input& in, States&&... /*unused*/ ) { - throw parse_error( "parse error matching " + internal::demangle< Rule >(), in ); + throw parse_error( "parse error matching " + std::string( internal::demangle< Rule >() ), in ); } template< template< typename... > class Action, @@ -75,7 +76,7 @@ namespace TAO_PEGTL_NAMESPACE if constexpr( internal::has_match_v< Rule, A, M, Action, Control, Input, States... > ) { return Action< Rule >::template match< Rule, A, M, Action, Control >( in, st... ); } - else { // NOLINT + else { return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); } } diff --git a/packages/PEGTL/include/tao/pegtl/parse_error.hpp b/packages/PEGTL/include/tao/pegtl/parse_error.hpp index eee0ec686693a02207a230a0a3683ce0eb1afc99..821316b62b77f69a3b174fca9769af87d1b4b3e9 100644 --- a/packages/PEGTL/include/tao/pegtl/parse_error.hpp +++ b/packages/PEGTL/include/tao/pegtl/parse_error.hpp @@ -17,17 +17,10 @@ namespace TAO_PEGTL_NAMESPACE { struct parse_error - : public std::runtime_error + : std::runtime_error { template< typename Msg > - parse_error( Msg&& msg, const std::vector< position >& in_positions ) - : std::runtime_error( std::forward< Msg >( msg ) ), - positions( in_positions ) - { - } - - template< typename Msg > - parse_error( Msg&& msg, std::vector< position >&& in_positions ) + parse_error( Msg&& msg, std::vector< position > in_positions ) : std::runtime_error( std::forward< Msg >( msg ) ), positions( std::move( in_positions ) ) { diff --git a/packages/PEGTL/include/tao/pegtl/position.hpp b/packages/PEGTL/include/tao/pegtl/position.hpp index c14446f73ed21bb812b403691e2fcb4e2ef0072b..a056909ba01300e601d2f903f9b07aa1919dc514 100644 --- a/packages/PEGTL/include/tao/pegtl/position.hpp +++ b/packages/PEGTL/include/tao/pegtl/position.hpp @@ -18,6 +18,29 @@ namespace TAO_PEGTL_NAMESPACE { struct position { + position() = delete; + + position( position&& p ) noexcept + : byte( p.byte ), + line( p.line ), + byte_in_line( p.byte_in_line ), + source( std::move( p.source ) ) + { + } + + position( const position& ) = default; + + position& operator=( position&& p ) noexcept + { + byte = p.byte; + line = p.line; + byte_in_line = p.byte_in_line; + source = std::move( p.source ); + return *this; + } + + position& operator=( const position& ) = default; + template< typename T > position( const internal::iterator& in_iter, T&& in_source ) : byte( in_iter.byte ), @@ -27,6 +50,8 @@ namespace TAO_PEGTL_NAMESPACE { } + ~position() = default; + std::size_t byte; std::size_t line; std::size_t byte_in_line; diff --git a/packages/PEGTL/include/tao/pegtl/utf16.hpp b/packages/PEGTL/include/tao/pegtl/utf16.hpp index 186d1e8e7c36a6259bc28a7d07d5c9265cbed90b..60a0d4f2a95530452ac18a360463ad7e79426055 100644 --- a/packages/PEGTL/include/tao/pegtl/utf16.hpp +++ b/packages/PEGTL/include/tao/pegtl/utf16.hpp @@ -42,7 +42,7 @@ namespace TAO_PEGTL_NAMESPACE } // namespace utf16_le - namespace utf16 = TAO_PEGTL_NATIVE_UTF16; // NOLINT(misc-unused-alias-decls) + namespace utf16 = TAO_PEGTL_NATIVE_UTF16; } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/include/tao/pegtl/utf32.hpp b/packages/PEGTL/include/tao/pegtl/utf32.hpp index 591a4cd20e4d8886259a61ca43027372613c591e..019b755d1d24b0d49be1342ae01666d7e61de662 100644 --- a/packages/PEGTL/include/tao/pegtl/utf32.hpp +++ b/packages/PEGTL/include/tao/pegtl/utf32.hpp @@ -42,7 +42,7 @@ namespace TAO_PEGTL_NAMESPACE } // namespace utf32_le - namespace utf32 = TAO_PEGTL_NATIVE_UTF32; // NOLINT(misc-unused-alias-decls) + namespace utf32 = TAO_PEGTL_NATIVE_UTF32; } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/example/pegtl/abnf2pegtl.cpp b/packages/PEGTL/src/example/pegtl/abnf2pegtl.cpp index 4e019eccbe1112f79937d291a47627e76e97c585..3f55772a10e757e0e892baee4f71d6b362b37dfe 100644 --- a/packages/PEGTL/src/example/pegtl/abnf2pegtl.cpp +++ b/packages/PEGTL/src/example/pegtl/abnf2pegtl.cpp @@ -34,9 +34,9 @@ namespace TAO_PEGTL_NAMESPACE::abnf namespace { - std::string prefix = "tao::pegtl::"; // NOLINT + std::string prefix = "tao::pegtl::"; - std::set< std::string > keywords = { // NOLINT + std::set< std::string > keywords = { "alignas", "alignof", "and", @@ -124,8 +124,8 @@ namespace TAO_PEGTL_NAMESPACE::abnf }; using rules_t = std::vector< std::string >; - rules_t rules_defined; // NOLINT - rules_t rules; // NOLINT + rules_t rules_defined; + rules_t rules; // clang-format off struct one_tag {}; @@ -278,26 +278,26 @@ namespace TAO_PEGTL_NAMESPACE::abnf } }; - template<> const std::string error_control< comment_cont >::error_message = "unterminated comment"; // NOLINT + template<> const std::string error_control< comment_cont >::error_message = "unterminated comment"; - template<> const std::string error_control< quoted_string_cont >::error_message = "unterminated string (missing '\"')"; // NOLINT - template<> const std::string error_control< prose_val_cont >::error_message = "unterminated prose description (missing '>')"; // NOLINT + template<> const std::string error_control< quoted_string_cont >::error_message = "unterminated string (missing '\"')"; + template<> const std::string error_control< prose_val_cont >::error_message = "unterminated prose description (missing '>')"; - template<> const std::string error_control< hex_val::value >::error_message = "expected hexadecimal value"; // NOLINT - template<> const std::string error_control< dec_val::value >::error_message = "expected decimal value"; // NOLINT - template<> const std::string error_control< bin_val::value >::error_message = "expected binary value"; // NOLINT - template<> const std::string error_control< num_val_choice >::error_message = "expected base specifier (one of 'bBdDxX')"; // NOLINT + template<> const std::string error_control< hex_val::value >::error_message = "expected hexadecimal value"; + template<> const std::string error_control< dec_val::value >::error_message = "expected decimal value"; + template<> const std::string error_control< bin_val::value >::error_message = "expected binary value"; + template<> const std::string error_control< num_val_choice >::error_message = "expected base specifier (one of 'bBdDxX')"; - template<> const std::string error_control< option_close >::error_message = "unterminated option (missing ']')"; // NOLINT - template<> const std::string error_control< group_close >::error_message = "unterminated group (missing ')')"; // NOLINT + template<> const std::string error_control< option_close >::error_message = "unterminated option (missing ']')"; + template<> const std::string error_control< group_close >::error_message = "unterminated group (missing ')')"; - template<> const std::string error_control< repetition >::error_message = "expected element"; // NOLINT - template<> const std::string error_control< concatenation >::error_message = "expected element"; // NOLINT - template<> const std::string error_control< alternation >::error_message = "expected element"; // NOLINT + template<> const std::string error_control< repetition >::error_message = "expected element"; + template<> const std::string error_control< concatenation >::error_message = "expected element"; + template<> const std::string error_control< alternation >::error_message = "expected element"; - template<> const std::string error_control< defined_as >::error_message = "expected '=' or '=/'"; // NOLINT - template<> const std::string error_control< c_nl >::error_message = "unterminated rule"; // NOLINT - template<> const std::string error_control< rule >::error_message = "expected rule"; // NOLINT + template<> const std::string error_control< defined_as >::error_message = "expected '=' or '=/'"; + template<> const std::string error_control< c_nl >::error_message = "unterminated rule"; + template<> const std::string error_control< rule >::error_message = "expected rule"; // clang-format on } // namespace grammar @@ -345,15 +345,15 @@ namespace TAO_PEGTL_NAMESPACE::abnf const auto content = n->string_view(); for( const auto c : content ) { if( std::isalpha( c ) != 0 ) { - n->id = typeid( istring_tag ); + n->set_type< istring_tag >(); return; } } if( content.size() == 1 ) { - n->id = typeid( one_tag ); + n->set_type< one_tag >(); } else { - n->id = typeid( string_tag ); + n->set_type< string_tag >(); } } }; @@ -366,10 +366,10 @@ namespace TAO_PEGTL_NAMESPACE::abnf { n = std::move( n->children.back() ); if( n->string_view().size() == 1 ) { - n->id = typeid( one_tag ); + n->set_type< one_tag >(); } else { - n->id = typeid( string_tag ); + n->set_type< string_tag >(); } } }; @@ -379,7 +379,7 @@ namespace TAO_PEGTL_NAMESPACE::abnf std::string to_string_unwrap_seq( const node_ptr& n ) { - if( n->is< grammar::group >() || n->is< grammar::concatenation >() ) { + if( n->is_type< grammar::group >() || n->is_type< grammar::concatenation >() ) { return to_string( n->children ); } return to_string( n ); @@ -389,7 +389,7 @@ namespace TAO_PEGTL_NAMESPACE::abnf { std::string get_rulename( const node_ptr& n ) { - assert( n->is< grammar::rulename >() ); + assert( n->is_type< grammar::rulename >() ); std::string v = n->string(); std::replace( v.begin(), v.end(), '-', '_' ); return v; @@ -403,7 +403,7 @@ namespace TAO_PEGTL_NAMESPACE::abnf return *it; } if( keywords.count( v ) != 0 || v.find( "__" ) != std::string::npos ) { - throw parse_error( '\'' + n->string() + "' is a reserved rulename", n->begin() ); // NOLINT + throw parse_error( '\'' + n->string() + "' is a reserved rulename", n->begin() ); } if( print_forward_declarations && find_rule( rules_defined, v ) != rules_defined.rend() ) { std::cout << "struct " << v << ";\n"; @@ -416,7 +416,7 @@ namespace TAO_PEGTL_NAMESPACE::abnf std::string gen_val( const node_ptr& n ) { if( n->children.size() == 2 ) { - if( n->children.back()->is< T >() ) { + if( n->children.back()->is_type< T >() ) { return prefix + "range< " + to_string( n->children.front() ) + ", " + to_string( n->children.back()->children.front() ) + " >"; } } @@ -434,7 +434,7 @@ namespace TAO_PEGTL_NAMESPACE::abnf } }; - std::map< std::string, parse_tree::node*, ccmp > previous_rules; // NOLINT + std::map< std::string, parse_tree::node*, ccmp > previous_rules; } // namespace @@ -445,26 +445,26 @@ namespace TAO_PEGTL_NAMESPACE::abnf static void transform( node_ptr& n ) { const auto rname = get_rulename( n->children.front() ); - assert( n->children.at( 1 )->is< grammar::defined_as_op >() ); + assert( n->children.at( 1 )->is_type< grammar::defined_as_op >() ); const auto op = n->children.at( 1 )->string(); // when we insert a normal rule, we need to check for duplicates if( op == "=" ) { - if( !previous_rules.insert( { rname, n.get() } ).second ) { - throw parse_error( "rule '" + rname + "' is already defined", n->begin() ); // NOLINT + if( !previous_rules.try_emplace( rname, n.get() ).second ) { + throw parse_error( "rule '" + rname + "' is already defined", n->begin() ); } } // if it is an "incremental alternation", we need to consolidate the assigned alternations else if( op == "=/" ) { const auto p = previous_rules.find( rname ); if( p == previous_rules.end() ) { - throw parse_error( "incremental alternation '" + rname + "' without previous rule definition", n->begin() ); // NOLINT + throw parse_error( "incremental alternation '" + rname + "' without previous rule definition", n->begin() ); } auto& previous = p->second->children.back(); // if the previous rule does not assign an alternation, create an intermediate alternation and move its assignee into it. - if( !previous->is< abnf::grammar::alternation >() ) { + if( !previous->is_type< abnf::grammar::alternation >() ) { auto s = std::make_unique< parse_tree::node >(); - s->id = typeid( abnf::grammar::alternation ); + s->set_type< abnf::grammar::alternation >(); s->source = previous->source; s->m_begin = previous->m_begin; s->m_end = previous->m_end; @@ -476,7 +476,7 @@ namespace TAO_PEGTL_NAMESPACE::abnf previous->m_end = n->children.back()->m_end; // if the new rule itself contains an alternation, append the individual entries... - if( n->children.back()->is< abnf::grammar::alternation >() ) { + if( n->children.back()->is_type< abnf::grammar::alternation >() ) { for( auto& e : n->children.back()->children ) { previous->children.emplace_back( std::move( e ) ); } @@ -488,7 +488,7 @@ namespace TAO_PEGTL_NAMESPACE::abnf n.reset(); } else { - throw parse_error( "invalid operator '" + op + "', this should not happen!", n->begin() ); // NOLINT + throw parse_error( "invalid operator '" + op + "', this should not happen!", n->begin() ); } } }; @@ -498,17 +498,17 @@ namespace TAO_PEGTL_NAMESPACE::abnf using function_t = std::string ( * )( const node_ptr& n ); function_t default_ = nullptr; - std::map< std::type_index, function_t > map_; + std::map< std::string_view, function_t > map_; template< typename T > void add( const function_t& f ) { - map_.insert( { typeid( T ), f } ); + map_.try_emplace( internal::demangle< T >(), f ); } std::string operator()( const node_ptr& n ) const { - const auto it = map_.find( n->id ); + const auto it = map_.find( n->type ); if( it != map_.end() ) { return it->second( n ); } @@ -520,7 +520,7 @@ namespace TAO_PEGTL_NAMESPACE::abnf { stringifier nrv; nrv.default_ = []( const node_ptr& n ) -> std::string { - throw parse_error( "missing to_string() for " + n->name(), n->begin() ); // NOLINT + throw parse_error( "missing to_string() for " + std::string( n->type ), n->begin() ); }; nrv.add< grammar::rulename >( []( const node_ptr& n ) { return get_rulename( n, true ); } ); @@ -604,14 +604,14 @@ namespace TAO_PEGTL_NAMESPACE::abnf if( star == std::string::npos ) { const auto v = remove_leading_zeroes( rep ); if( v.empty() ) { - throw parse_error( "repetition of zero not allowed", n->begin() ); // NOLINT + throw parse_error( "repetition of zero not allowed", n->begin() ); } return prefix + "rep< " + v + ", " + content + " >"; } const auto min = remove_leading_zeroes( rep.substr( 0, star ) ); const auto max = remove_leading_zeroes( rep.substr( star + 1 ) ); if( ( star != rep.size() - 1 ) && max.empty() ) { - throw parse_error( "repetition maximum of zero not allowed", n->begin() ); // NOLINT + throw parse_error( "repetition maximum of zero not allowed", n->begin() ); } if( min.empty() && max.empty() ) { return prefix + "star< " + content + " >"; @@ -639,7 +639,7 @@ namespace TAO_PEGTL_NAMESPACE::abnf s >> max_val; } if( min_val > max_val ) { - throw parse_error( "repetition minimum which is greater than the repetition maximum not allowed", n->begin() ); // NOLINT + throw parse_error( "repetition minimum which is greater than the repetition maximum not allowed", n->begin() ); } if( ( min_val == 1 ) && ( max_val == 1 ) ) { // note: content can not be used here! @@ -678,9 +678,9 @@ namespace TAO_PEGTL_NAMESPACE::abnf } // namespace TAO_PEGTL_NAMESPACE::abnf -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { - using namespace TAO_PEGTL_NAMESPACE; // NOLINT + using namespace TAO_PEGTL_NAMESPACE; if( argc != 2 ) { std::cerr << "Usage: " << argv[ 0 ] << " SOURCE" << std::endl; diff --git a/packages/PEGTL/src/example/pegtl/analyze.cpp b/packages/PEGTL/src/example/pegtl/analyze.cpp index ecccbef9bd33e1f06b70b0de0e8a5bd4930e921f..6a4efb7e18d6612f0d1f858562fe279f8bd7ae3c 100644 --- a/packages/PEGTL/src/example/pegtl/analyze.cpp +++ b/packages/PEGTL/src/example/pegtl/analyze.cpp @@ -4,7 +4,7 @@ #include <tao/pegtl.hpp> #include <tao/pegtl/analyze.hpp> -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; struct bar; @@ -18,7 +18,7 @@ struct bar { }; -int main( int /*unused*/, char** /*unused*/ ) +int main() // NOLINT(bugprone-exception-escape) { if( analyze< foo >() != 0 ) { std::cout << "there are problems" << std::endl; diff --git a/packages/PEGTL/src/example/pegtl/calculator.cpp b/packages/PEGTL/src/example/pegtl/calculator.cpp index b841e327a3ee5b317f93e2611069588b6a6e337e..1adb21ce8fd1bec3bd4edc95fc0d787ac908ac1f 100644 --- a/packages/PEGTL/src/example/pegtl/calculator.cpp +++ b/packages/PEGTL/src/example/pegtl/calculator.cpp @@ -168,7 +168,7 @@ namespace calculator void insert( const std::string& name, const order p, const std::function< long( long, long ) >& f ) { assert( !name.empty() ); - m_ops.emplace( name, op{ p, f } ); + m_ops.try_emplace( name, op{ p, f } ); } [[nodiscard]] const std::map< std::string, op >& ops() const noexcept @@ -182,7 +182,7 @@ namespace calculator // Here the actual grammar starts. - using namespace tao::pegtl; // NOLINT + using namespace tao::pegtl; // Comments are introduced by a '#' and proceed to the end-of-line/file. @@ -332,7 +332,7 @@ namespace calculator } // namespace calculator -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { // Check the grammar for some possible issues. diff --git a/packages/PEGTL/src/example/pegtl/csv1.cpp b/packages/PEGTL/src/example/pegtl/csv1.cpp index f17c73936b955a099fdf17eb11e4a80d0aefc66d..bda3328a09186acaf6973821944fb1fb707109b4 100644 --- a/packages/PEGTL/src/example/pegtl/csv1.cpp +++ b/packages/PEGTL/src/example/pegtl/csv1.cpp @@ -87,7 +87,7 @@ namespace csv1 } // namespace csv1 -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { pegtl::file_input in( argv[ i ] ); diff --git a/packages/PEGTL/src/example/pegtl/csv2.cpp b/packages/PEGTL/src/example/pegtl/csv2.cpp index dcc2a06a2f4e468b5c19f18acbff92c17300c3f8..ab0da058a5449c03ab3e19ac33d75bea58ce472f 100644 --- a/packages/PEGTL/src/example/pegtl/csv2.cpp +++ b/packages/PEGTL/src/example/pegtl/csv2.cpp @@ -23,7 +23,7 @@ namespace csv2 // aha """,yes, this works // clang-format off - template< int C > struct string_without : pegtl::star< pegtl::not_one< C, 10, 13 > > {}; + template< char C > struct string_without : pegtl::star< pegtl::not_one< C, 10, 13 > > {}; struct plain_value : string_without< ',' > {}; struct quoted_value : pegtl::if_must< pegtl::one< '"' >, string_without< '"' >, pegtl::one< '"' > > {}; struct value : pegtl::sor< quoted_value, plain_value > {}; @@ -168,7 +168,7 @@ namespace csv2 } // namespace csv2 -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { pegtl::file_input in( argv[ i ] ); diff --git a/packages/PEGTL/src/example/pegtl/double.hpp b/packages/PEGTL/src/example/pegtl/double.hpp index 02eb259440154077888dab1de60ed7bf5b6360b5..f92e822bb1817d56285b308f8f2003391546a7a4 100644 --- a/packages/PEGTL/src/example/pegtl/double.hpp +++ b/packages/PEGTL/src/example/pegtl/double.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_DOUBLE_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_DOUBLE_HPP #define TAO_PEGTL_SRC_EXAMPLES_PEGTL_DOUBLE_HPP #include <tao/pegtl.hpp> @@ -11,7 +11,7 @@ namespace double_ // A grammar for doubles suitable for std::stod without locale support. // See also: http://en.cppreference.com/w/cpp/string/basic_string/stof - using namespace TAO_PEGTL_NAMESPACE; // NOLINT + using namespace TAO_PEGTL_NAMESPACE; // clang-format off struct plus_minus : opt< one< '+', '-' > > {}; diff --git a/packages/PEGTL/src/example/pegtl/dynamic_match.cpp b/packages/PEGTL/src/example/pegtl/dynamic_match.cpp index 55495006bd4598093b4986b8d59f549fb43964d4..21670dd015cddebda3ebcaecd28e8c4a452931b9 100644 --- a/packages/PEGTL/src/example/pegtl/dynamic_match.cpp +++ b/packages/PEGTL/src/example/pegtl/dynamic_match.cpp @@ -80,7 +80,7 @@ namespace dynamic } // namespace dynamic -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( argc > 1 ) { std::string id; diff --git a/packages/PEGTL/src/example/pegtl/hello_world.cpp b/packages/PEGTL/src/example/pegtl/hello_world.cpp index 18a6ae2b3b6fb977cba8926e13d433e4e01c2d73..5c007c7962d616e133d3251d9a8ddab1b83c960d 100644 --- a/packages/PEGTL/src/example/pegtl/hello_world.cpp +++ b/packages/PEGTL/src/example/pegtl/hello_world.cpp @@ -32,7 +32,7 @@ namespace hello } // namespace hello -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( argc > 1 ) { std::string name; diff --git a/packages/PEGTL/src/example/pegtl/indent_aware.cpp b/packages/PEGTL/src/example/pegtl/indent_aware.cpp index 1d504a82a54333402746acf422dfd74ebb99b98e..9a20c662f49f3fbd2cabe3b71212af7dc8ca753d 100644 --- a/packages/PEGTL/src/example/pegtl/indent_aware.cpp +++ b/packages/PEGTL/src/example/pegtl/indent_aware.cpp @@ -137,7 +137,7 @@ namespace example { assert( !s.stack.empty() ); if( ( s.stack.back().type != type::if_ ) || ( s.stack.back().indent != s.current_indent ) ) { - throw pegtl::parse_error( "expected previous 'if' on same indent as current 'else'", in ); // NOLINT + throw pegtl::parse_error( "expected previous 'if' on same indent as current 'else'", in ); } s.stack.back().type = type::else_; } @@ -159,7 +159,7 @@ namespace example static void apply( const Input& in, state& s ) { if( s.minimum_indent > 0 ) { - throw pegtl::parse_error( "expected indented block instead of empty line", in ); // NOLINT + throw pegtl::parse_error( "expected indented block instead of empty line", in ); } s.stack.clear(); } @@ -179,12 +179,12 @@ namespace example } if( s.minimum_indent > 0 ) { if( s.current_indent < s.minimum_indent ) { - throw pegtl::parse_error( "expected indented block with more indent", in ); // NOLINT + throw pegtl::parse_error( "expected indented block with more indent", in ); } s.minimum_indent = 0; } else if( ( !s.stack.empty() ) && ( s.current_indent != s.stack.back().indent ) ) { - throw pegtl::parse_error( "indentation mismatch", in ); // NOLINT + throw pegtl::parse_error( "indentation mismatch", in ); } } }; @@ -196,14 +196,14 @@ namespace example static void apply( const Input& in, state& s ) { if( s.minimum_indent > 0 ) { - throw pegtl::parse_error( "expected indented block instead of eof", in ); // NOLINT + throw pegtl::parse_error( "expected indented block instead of eof", in ); } } }; } // namespace example -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { pegtl::file_input in( argv[ i ] ); diff --git a/packages/PEGTL/src/example/pegtl/json_build.cpp b/packages/PEGTL/src/example/pegtl/json_build.cpp index 7d7b9dc7798250eaf168b21ddc7b3cfb09e21c6c..197d26c62e5f79da6e79f333c891c064ff9e8ae1 100644 --- a/packages/PEGTL/src/example/pegtl/json_build.cpp +++ b/packages/PEGTL/src/example/pegtl/json_build.cpp @@ -160,7 +160,7 @@ namespace examples } // namespace examples -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( argc != 2 ) { std::cerr << "usage: " << argv[ 0 ] << " <json>"; diff --git a/packages/PEGTL/src/example/pegtl/json_classes.hpp b/packages/PEGTL/src/example/pegtl/json_classes.hpp index 0e5567e95911cb3e2fe19268762048f30a79c1db..7b9ca3ce63571a990220a5883e36ca084d467934 100644 --- a/packages/PEGTL/src/example/pegtl/json_classes.hpp +++ b/packages/PEGTL/src/example/pegtl/json_classes.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_CLASSES_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_CLASSES_HPP #define TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_CLASSES_HPP #include <iostream> @@ -135,7 +135,7 @@ namespace examples static const char* h = "0123456789abcdef"; - const auto* d = static_cast< const unsigned char* >( static_cast< const void* >( data.data() ) ); + const auto* d = reinterpret_cast< const unsigned char* >( data.data() ); for( std::size_t i = 0; i < data.size(); ++i ) { switch( const auto c = d[ i ] ) { @@ -178,7 +178,7 @@ namespace examples struct string_json : public json_base { - explicit string_json( const std::string& in_data ) // NOLINT + explicit string_json( const std::string& in_data ) : json_base( json_type::string ), data( in_data ) { diff --git a/packages/PEGTL/src/example/pegtl/json_count.cpp b/packages/PEGTL/src/example/pegtl/json_count.cpp index 7b6cd295bab057ff7a770cbbc2bbaed1f5f83548..c7e82698e86c39d1feeee7d0fc0f045ec527a2fe 100644 --- a/packages/PEGTL/src/example/pegtl/json_count.cpp +++ b/packages/PEGTL/src/example/pegtl/json_count.cpp @@ -4,17 +4,15 @@ #include <iomanip> #include <iostream> -#define TAO_PEGTL_PRETTY_DEMANGLE - #include <tao/pegtl.hpp> #include <tao/pegtl/contrib/counter.hpp> #include <tao/pegtl/contrib/json.hpp> #include <tao/pegtl/file_input.hpp> -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; using grammar = must< json::text, eof >; -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { counter_state cs; diff --git a/packages/PEGTL/src/example/pegtl/json_errors.hpp b/packages/PEGTL/src/example/pegtl/json_errors.hpp index 07067cf3e829cf09c95f20317a26b9f60239606a..5b9957f187ea0031e5afbc07bfa690c2b186a302 100644 --- a/packages/PEGTL/src/example/pegtl/json_errors.hpp +++ b/packages/PEGTL/src/example/pegtl/json_errors.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_ERRORS_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_ERRORS_HPP #define TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_ERRORS_HPP #include <tao/pegtl.hpp> @@ -34,23 +34,23 @@ namespace examples // member are then used in the exception messages: // clang-format off - template<> inline const std::string errors< pegtl::json::text >::error_message = "no valid JSON"; // NOLINT + template<> inline const std::string errors< pegtl::json::text >::error_message = "no valid JSON"; - template<> inline const std::string errors< pegtl::json::end_array >::error_message = "incomplete array, expected ']'"; // NOLINT - template<> inline const std::string errors< pegtl::json::end_object >::error_message = "incomplete object, expected '}'"; // NOLINT - template<> inline const std::string errors< pegtl::json::member >::error_message = "expected member"; // NOLINT - template<> inline const std::string errors< pegtl::json::name_separator >::error_message = "expected ':'"; // NOLINT - template<> inline const std::string errors< pegtl::json::array_element >::error_message = "expected value"; // NOLINT - template<> inline const std::string errors< pegtl::json::value >::error_message = "expected value"; // NOLINT + template<> inline const std::string errors< pegtl::json::end_array >::error_message = "incomplete array, expected ']'"; + template<> inline const std::string errors< pegtl::json::end_object >::error_message = "incomplete object, expected '}'"; + template<> inline const std::string errors< pegtl::json::member >::error_message = "expected member"; + template<> inline const std::string errors< pegtl::json::name_separator >::error_message = "expected ':'"; + template<> inline const std::string errors< pegtl::json::array_element >::error_message = "expected value"; + template<> inline const std::string errors< pegtl::json::value >::error_message = "expected value"; - template<> inline const std::string errors< pegtl::json::digits >::error_message = "expected at least one digit"; // NOLINT - template<> inline const std::string errors< pegtl::json::xdigit >::error_message = "incomplete universal character name"; // NOLINT - template<> inline const std::string errors< pegtl::json::escaped >::error_message = "unknown escape sequence"; // NOLINT - template<> inline const std::string errors< pegtl::json::char_ >::error_message = "invalid character in string"; // NOLINT - template<> inline const std::string errors< pegtl::json::string::content >::error_message = "unterminated string"; // NOLINT - template<> inline const std::string errors< pegtl::json::key::content >::error_message = "unterminated key"; // NOLINT + template<> inline const std::string errors< pegtl::json::digits >::error_message = "expected at least one digit"; + template<> inline const std::string errors< pegtl::json::xdigit >::error_message = "incomplete universal character name"; + template<> inline const std::string errors< pegtl::json::escaped >::error_message = "unknown escape sequence"; + template<> inline const std::string errors< pegtl::json::char_ >::error_message = "invalid character in string"; + template<> inline const std::string errors< pegtl::json::string::content >::error_message = "unterminated string"; + template<> inline const std::string errors< pegtl::json::key::content >::error_message = "unterminated key"; - template<> inline const std::string errors< pegtl::eof >::error_message = "unexpected character after JSON value"; // NOLINT + template<> inline const std::string errors< pegtl::eof >::error_message = "unexpected character after JSON value"; // clang-format on // The raise()-function-template is instantiated exactly diff --git a/packages/PEGTL/src/example/pegtl/json_parse.cpp b/packages/PEGTL/src/example/pegtl/json_parse.cpp index 65f62b21a70766fab1369a56dc21119fe912877e..549d735146177e266b3a882527d93681ff8a3683 100644 --- a/packages/PEGTL/src/example/pegtl/json_parse.cpp +++ b/packages/PEGTL/src/example/pegtl/json_parse.cpp @@ -5,10 +5,10 @@ #include "json_errors.hpp" -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; using grammar = must< json::text, eof >; -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { argv_input in( argv, i ); diff --git a/packages/PEGTL/src/example/pegtl/json_unescape.hpp b/packages/PEGTL/src/example/pegtl/json_unescape.hpp index 09be84f2cd6cb1eaccc07b21c23c28c081b341d1..c6a9226742d9502d2556822dd8abfc2a995d6f5a 100644 --- a/packages/PEGTL/src/example/pegtl/json_unescape.hpp +++ b/packages/PEGTL/src/example/pegtl/json_unescape.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_UNESCAPE_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_UNESCAPE_HPP #define TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_UNESCAPE_HPP #include <string> diff --git a/packages/PEGTL/src/example/pegtl/lua53_parse.cpp b/packages/PEGTL/src/example/pegtl/lua53_parse.cpp index 70449f4fef49993aa7f631a3a274530e5f311368..a5d7a30185df94f143a8362568ec1078174291b2 100644 --- a/packages/PEGTL/src/example/pegtl/lua53_parse.cpp +++ b/packages/PEGTL/src/example/pegtl/lua53_parse.cpp @@ -333,7 +333,7 @@ namespace lua53 } // namespace lua53 -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( TAO_PEGTL_NAMESPACE::analyze< lua53::grammar >() != 0 ) { return 1; diff --git a/packages/PEGTL/src/example/pegtl/modulus_match.cpp b/packages/PEGTL/src/example/pegtl/modulus_match.cpp index 76c8394d7b38b4fbe86975c7b7bfa2e0546df8b9..7c3b63d45ddb614e42047835d9b8ca200dab6254 100644 --- a/packages/PEGTL/src/example/pegtl/modulus_match.cpp +++ b/packages/PEGTL/src/example/pegtl/modulus_match.cpp @@ -3,7 +3,7 @@ #include <tao/pegtl.hpp> -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; namespace modulus { @@ -35,7 +35,7 @@ namespace modulus } // namespace modulus -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( argc > 1 ) { argv_input in( argv, 1 ); diff --git a/packages/PEGTL/src/example/pegtl/parse_tree.cpp b/packages/PEGTL/src/example/pegtl/parse_tree.cpp index 3e5f6ee741458d07681cb3e3cefd5094c86ec67f..7a62f1c307aa5cb345e0772e485a1f90fb170975 100644 --- a/packages/PEGTL/src/example/pegtl/parse_tree.cpp +++ b/packages/PEGTL/src/example/pegtl/parse_tree.cpp @@ -9,7 +9,7 @@ #include <tao/pegtl/contrib/parse_tree.hpp> #include <tao/pegtl/contrib/parse_tree_to_dot.hpp> -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; namespace example { diff --git a/packages/PEGTL/src/example/pegtl/parse_tree_user_state.cpp b/packages/PEGTL/src/example/pegtl/parse_tree_user_state.cpp index 6b207c062bda56e21e1519ed356af95c15e60967..f8840738af8473c19a31d8e3c46a5ecf4444c5c3 100644 --- a/packages/PEGTL/src/example/pegtl/parse_tree_user_state.cpp +++ b/packages/PEGTL/src/example/pegtl/parse_tree_user_state.cpp @@ -6,7 +6,7 @@ #include <tao/pegtl.hpp> #include <tao/pegtl/contrib/parse_tree.hpp> -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; template< typename > using selector = std::true_type; diff --git a/packages/PEGTL/src/example/pegtl/proto3.cpp b/packages/PEGTL/src/example/pegtl/proto3.cpp index a1b6f281b68b7c9ad5b17160f86ddc544fc58d23..ed478d79e40913a19d83f4494c7d2dd8f53d10f3 100644 --- a/packages/PEGTL/src/example/pegtl/proto3.cpp +++ b/packages/PEGTL/src/example/pegtl/proto3.cpp @@ -1,8 +1,6 @@ // Copyright (c) 2017-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#define TAO_PEGTL_PRETTY_DEMANGLE 1 - #include <tao/pegtl.hpp> #include <tao/pegtl/analyze.hpp> @@ -98,9 +96,9 @@ namespace TAO_PEGTL_NAMESPACE::proto3 struct enum_value_option : seq< option_name, sps, equ, sps, constant > {}; struct enum_field : seq< ident, sps, equ, sps, int_lit, sps, opt_must< one< '[' >, sps, list_must< enum_value_option, comma, sp >, sps, one< ']' >, sps >, semi > {}; struct enum_body : if_must< one< '{' >, sps, star< sor< option, enum_field, semi >, sps >, one< '}' > > {}; - struct enum_ : if_must< string< 'e', 'n', 'u', 'm' >, sps, enum_name, sps, enum_body > {}; + struct enum_def : if_must< string< 'e', 'n', 'u', 'm' >, sps, enum_name, sps, enum_body > {}; - struct message_thing : sor< field, enum_, message, option, oneof, map_field, reserved, semi > {}; + struct message_thing : sor< field, enum_def, message, option, oneof, map_field, reserved, semi > {}; struct message : if_must< string< 'm', 'e', 's', 's', 'a', 'g', 'e' >, sps, ident, sps, one< '{' >, sps, star< message_thing, sps >, one< '}' >, sps > {}; struct package : if_must< string< 'p', 'a', 'c', 'k', 'a', 'g', 'e' >, sps, full_ident, sps, semi, sps > {}; @@ -115,7 +113,7 @@ namespace TAO_PEGTL_NAMESPACE::proto3 struct service_name : ident {}; struct service : if_must< string< 's', 'e', 'r', 'v', 'i', 'c', 'e' >, sps, service_name, sps, one< '{' >, sps, list_must< sor< option, rpc, semi >, comma, sp >, sps, one< '}' > > {}; - struct body : sor< import, package, option, message, enum_, service, semi > {}; + struct body : sor< import, package, option, message, enum_def, service, semi > {}; struct head : if_must< string< 's', 'y', 'n', 't', 'a', 'x' >, sps, equ, sps, string< '"', 'p', 'r', 'o', 't', 'o', '3', '"' >, sps, semi > {}; struct proto : must< sps, head, sps, star< body, sps >, eof > {}; @@ -124,9 +122,9 @@ namespace TAO_PEGTL_NAMESPACE::proto3 } // namespace TAO_PEGTL_NAMESPACE::proto3 -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { - using namespace TAO_PEGTL_NAMESPACE; // NOLINT + using namespace TAO_PEGTL_NAMESPACE; if( analyze< proto3::proto >() != 0 ) { return 1; diff --git a/packages/PEGTL/src/example/pegtl/recover.cpp b/packages/PEGTL/src/example/pegtl/recover.cpp index c39dcc1179281c3a3049a4e2d25ed3271c61f3d4..24f9c62c485d474be04bbee0bf9a7648fe266bc1 100644 --- a/packages/PEGTL/src/example/pegtl/recover.cpp +++ b/packages/PEGTL/src/example/pegtl/recover.cpp @@ -16,7 +16,7 @@ #include <tao/pegtl.hpp> -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; // clang-format off @@ -104,7 +104,7 @@ struct my_control static void raise( const Input& in, States&&... /*unused*/ ) { std::cout << in.position() << ": Parse error matching " << internal::demangle< Rule >() << std::endl; - throw parse_error( "parse error matching " + internal::demangle< Rule >(), in ); + throw parse_error( "parse error matching " + std::string( internal::demangle< Rule >() ), in ); } }; diff --git a/packages/PEGTL/src/example/pegtl/s_expression.cpp b/packages/PEGTL/src/example/pegtl/s_expression.cpp index c99311f8d89722ad14a3435ba7947e761a692fac..4900c72c421a90cb4b9382640764bc209dfe6233 100644 --- a/packages/PEGTL/src/example/pegtl/s_expression.cpp +++ b/packages/PEGTL/src/example/pegtl/s_expression.cpp @@ -6,7 +6,7 @@ #include <tao/pegtl.hpp> #include <tao/pegtl/analyze.hpp> -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; namespace sexpr { @@ -71,7 +71,7 @@ namespace sexpr } // namespace sexpr -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( analyze< sexpr::main >() != 0 ) { return 1; diff --git a/packages/PEGTL/src/example/pegtl/sum.cpp b/packages/PEGTL/src/example/pegtl/sum.cpp index 25b2484f50bac80a5171fa3f5a9c309dcc5c4007..fd81a54d5d1e94560f1a65f6e05ec9c63f7fc4ec 100644 --- a/packages/PEGTL/src/example/pegtl/sum.cpp +++ b/packages/PEGTL/src/example/pegtl/sum.cpp @@ -8,7 +8,7 @@ #include <tao/pegtl.hpp> -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; #include "double.hpp" diff --git a/packages/PEGTL/src/example/pegtl/symbol_table.cpp b/packages/PEGTL/src/example/pegtl/symbol_table.cpp index fce5d6e1a364d2efdca25c54f68fe8790ed4ff9b..f4b317a0ebc09ffd660994a75eb11b6b8ff6af70 100644 --- a/packages/PEGTL/src/example/pegtl/symbol_table.cpp +++ b/packages/PEGTL/src/example/pegtl/symbol_table.cpp @@ -68,8 +68,8 @@ namespace example template< typename Input > static void apply( const Input& in, state& st ) { - if( !st.symbol_table.emplace( st.temporary, 0 ).second ) { - throw pegtl::parse_error( "duplicate symbol " + st.temporary, in ); // NOLINT + if( !st.symbol_table.try_emplace( st.temporary, 0 ).second ) { + throw pegtl::parse_error( "duplicate symbol " + st.temporary, in ); } } }; @@ -82,7 +82,7 @@ namespace example { const auto i = st.symbol_table.find( st.temporary ); if( i == st.symbol_table.end() ) { - throw pegtl::parse_error( "unknown symbol " + st.temporary, in ); // NOLINT + throw pegtl::parse_error( "unknown symbol " + st.temporary, in ); } i->second = st.converted; } @@ -90,7 +90,7 @@ namespace example } // namespace example -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { pegtl::file_input in( argv[ i ] ); diff --git a/packages/PEGTL/src/example/pegtl/unescape.cpp b/packages/PEGTL/src/example/pegtl/unescape.cpp index 69705ca340ab21c329886285339c98193a0bbec7..cb694473bb6476c55ecfddb0ebf6adf2b277e344 100644 --- a/packages/PEGTL/src/example/pegtl/unescape.cpp +++ b/packages/PEGTL/src/example/pegtl/unescape.cpp @@ -7,7 +7,7 @@ #include <tao/pegtl/contrib/unescape.hpp> -using namespace TAO_PEGTL_NAMESPACE; // NOLINT +using namespace TAO_PEGTL_NAMESPACE; namespace example { @@ -48,7 +48,7 @@ namespace example } // namespace example -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { std::string s; diff --git a/packages/PEGTL/src/example/pegtl/uri_trace.cpp b/packages/PEGTL/src/example/pegtl/uri_trace.cpp index 1d09e9fa5ef9a899575df80bd38e1033122b6c77..2bb9667877e4d7967de37d0dd7e30875f061bdf3 100644 --- a/packages/PEGTL/src/example/pegtl/uri_trace.cpp +++ b/packages/PEGTL/src/example/pegtl/uri_trace.cpp @@ -11,7 +11,7 @@ namespace pegtl = TAO_PEGTL_NAMESPACE; using grammar = pegtl::must< pegtl::uri::URI >; -int main( int argc, char** argv ) +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { std::cout << "Parsing " << argv[ i ] << std::endl; diff --git a/packages/PEGTL/src/test/pegtl/CMakeLists.txt b/packages/PEGTL/src/test/pegtl/CMakeLists.txt index fda805afb0fa5ed505485d9d3ac397fefeb264cb..46408eb066d29048dc1e7e8d133159d4826ecaa0 100644 --- a/packages/PEGTL/src/test/pegtl/CMakeLists.txt +++ b/packages/PEGTL/src/test/pegtl/CMakeLists.txt @@ -25,8 +25,9 @@ set(test_sources change_state.cpp change_states.cpp contrib_alphabet.cpp - contrib_integer.cpp + contrib_http.cpp contrib_if_then.cpp + contrib_integer.cpp contrib_json.cpp contrib_parse_tree.cpp contrib_partial_trace.cpp @@ -125,9 +126,9 @@ foreach(testsourcefile ${test_sources}) target_compile_options(${exename} PRIVATE -pedantic -Wall -Wextra -Wshadow -Werror) endif() if(ANDROID) - add_test(NAME ${exename} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. COMMAND ${CMAKE_COMMAND} -DANDROID_NDK=${ANDROID_NDK} "-DTEST_RESOURCES=src/test/pegtl/data;src/test/pegtl/file_data.txt;Makefile" -DTEST_RESOURCES_DIR=${CMAKE_CURRENT_SOURCE_DIR}/../../.. -DUNITTEST=${CMAKE_CURRENT_BINARY_DIR}/${exename} -DTEST_PARAMETER=-all -P ${CMAKE_CURRENT_SOURCE_DIR}/ExecuteOnAndroid.cmake) + add_test(NAME ${exename} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} "-DANDROID_NDK=${ANDROID_NDK}" "-DTEST_RESOURCES_DIR=${CMAKE_SOURCE_DIR}" "-DTEST_RESOURCES=src/test/pegtl/data;src/test/pegtl/file_data.txt;Makefile" "-DUNITTEST=${exename}" -P ${CMAKE_CURRENT_SOURCE_DIR}/ExecuteOnAndroid.cmake) else() - add_test(NAME ${exename} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. COMMAND ${exename}) + add_test(NAME ${exename} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${exename}) endif() endforeach(testsourcefile) diff --git a/packages/PEGTL/src/test/pegtl/ExecuteOnAndroid.cmake b/packages/PEGTL/src/test/pegtl/ExecuteOnAndroid.cmake index 7f15007d04739e545018fba8b0081f5d38fc36af..e2ccfe97ecc5bb00e5a156e47b52f19761829e2b 100644 --- a/packages/PEGTL/src/test/pegtl/ExecuteOnAndroid.cmake +++ b/packages/PEGTL/src/test/pegtl/ExecuteOnAndroid.cmake @@ -1,4 +1,12 @@ +if("${ANDROID_NDK}" STREQUAL "") + message(FATAL_ERROR "cmake parameter ANDROID_NDK is not set!") +endif() + +if(NOT EXISTS "${ANDROID_NDK}/../platform-tools/adb") + message(FATAL_ERROR "adb is not found in ${ANDROID_NDK}/../platform-tools") +endif() + get_filename_component(UNITTEST_FILENAME ${UNITTEST} NAME) message(STATUS "Cleanup /data/local/tmp ...") execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "rm -r /data/local/tmp/*" OUTPUT_QUIET) @@ -6,24 +14,28 @@ execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "rm -r /data/ foreach(_TEST_DATA IN ITEMS ${TEST_RESOURCES}) get_filename_component(_DIR ${_TEST_DATA} DIRECTORY) message(STATUS "Create /data/local/tmp/${_DIR} directory structure on android ...") - execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "mkdir -p /data/local/tmp/${_DIR}" OUTPUT_QUIET) - message(STATUS "Push ${_TEST_DATA} to android ...") + execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "mkdir -p /data/local/tmp/${_DIR}" OUTPUT_QUIET) + message(STATUS "Push ${_TEST_DATA} from ${TEST_RESOURCES_DIR} to android ...") execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb push ${_TEST_DATA} /data/local/tmp/${_DIR} OUTPUT_QUIET WORKING_DIRECTORY ${TEST_RESOURCES_DIR}) endforeach() if(LIBRARY_DIR) message(STATUS "Push ${LIBRARY_DIR} to android ...") - execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb push ${LIBRARY_DIR} /data/local/tmp/ OUTPUT_QUIET) + execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb push ${LIBRARY_DIR} /data/local/tmp/ OUTPUT_QUIET) endif() message(STATUS "Push ${UNITTEST} to android ...") +if(NOT EXISTS "${UNITTEST}") + message(FATAL_ERROR "${UNITTEST} is not found!") +endif() execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb push ${UNITTEST} /data/local/tmp/ OUTPUT_QUIET) -message(STATUS "Execute ${UNITTEST_FILENAME} ${TEST_PARAMETER} on android ...") +message(STATUS "Execute ${UNITTEST_FILENAME} on android ...") + execute_process( - COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "cd /data/local/tmp;su root sh -c 'LD_LIBRARY_PATH=/data/local/tmp/lib TMPDIR=/data/local/tmp HOME=/data/local/tmp ./${UNITTEST_FILENAME} ${TEST_PARAMETER};echo exit code $?'" + COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "cd /data/local/tmp;su root sh -c 'LD_LIBRARY_PATH=/data/local/tmp/lib TMPDIR=/data/local/tmp HOME=/data/local/tmp ./${UNITTEST_FILENAME};echo exit code $?'" RESULT_VARIABLE _RESULT OUTPUT_VARIABLE _OUT ERROR_VARIABLE _ERR ) - + if(_RESULT) message(FATAL_ERROR "Execution of ${UNITTEST_FILENAME} failed") else() diff --git a/packages/PEGTL/src/test/pegtl/actions_one.cpp b/packages/PEGTL/src/test/pegtl/actions_one.cpp index 9577fae8ac6b2377c4b68680d074d05b81e6476e..8ce31991dccabe38373fdee373a5531460fa0e4f 100644 --- a/packages/PEGTL/src/test/pegtl/actions_one.cpp +++ b/packages/PEGTL/src/test/pegtl/actions_one.cpp @@ -9,7 +9,7 @@ namespace TAO_PEGTL_NAMESPACE { - std::vector< std::pair< std::string, std::string > > applied; // NOLINT + std::vector< std::pair< std::string, std::string > > applied; namespace test1 { diff --git a/packages/PEGTL/src/test/pegtl/argv_input.cpp b/packages/PEGTL/src/test/pegtl/argv_input.cpp index da27be5deae571eec8db4cdd6b7c445f3f9cf884..c9f506f68c049f96ce688629691e4ca9b90ebdeb 100644 --- a/packages/PEGTL/src/test/pegtl/argv_input.cpp +++ b/packages/PEGTL/src/test/pegtl/argv_input.cpp @@ -11,9 +11,9 @@ namespace TAO_PEGTL_NAMESPACE { void unit_test() { - char data[ 12 ]; // NOLINT + char data[ 12 ]; std::memcpy( data, "foo\0bar\0baz", 12 ); - char* argv[] = { data, data + 4, data + 8 }; // NOLINT + char* argv[] = { data, data + 4, data + 8 }; argv_input in( argv, 1 ); TAO_PEGTL_TEST_ASSERT( in.source() == "argv[1]" ); const auto result = parse< string< 'b', 'a', 'r' > >( in ); diff --git a/packages/PEGTL/src/test/pegtl/contrib_http.cpp b/packages/PEGTL/src/test/pegtl/contrib_http.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b18f328922e47fbfab840bad6dadea974685fb84 --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_http.cpp @@ -0,0 +1,95 @@ +// Copyright (c) 2019 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" +#include "verify_analyze.hpp" + +#include <tao/pegtl/contrib/http.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + void test_header() + { + // TODO. + } + + template< typename Rule > + struct chunked_action + : nothing< Rule > + { + }; + + template<> + struct chunked_action< http::chunk_ext > + { + static void apply0( std::string& s ) + { + s += 'a'; + } + }; + + template<> + struct chunked_action< http::chunk_data > + { + static void apply0( std::string& s ) + { + s += 'b'; + } + }; + + void test_chunked() + { + using GRAMMAR = must< http::chunked_body, eof >; + + verify_analyze< GRAMMAR >( __LINE__, __FILE__, true, false ); + { + string_input in( "0\r\n\r\n", __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in ) ); + } + { + std::string dummy; + string_input in( "0\r\n\r\n", __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in, dummy ) ); + } + { + std::string state; + string_input in( "0\r\n\r\n", __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR, chunked_action >( in, state ) ); + TAO_PEGTL_TEST_ASSERT( state == "a" ); + } + { + std::string state; + string_input in( "\r\n\r\n", __FUNCTION__ ); + TAO_PEGTL_TEST_THROWS( parse< GRAMMAR, chunked_action >( in, state ) ); + } + { + std::string state; + string_input in( "1\r\n", __FUNCTION__ ); + TAO_PEGTL_TEST_THROWS( parse< GRAMMAR, chunked_action >( in, state ) ); + } + { + string_input in( "01\r\nX\r\n1a\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n", __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in ) ); + } + { + std::string dummy; + string_input in( "01\r\nX\r\n1a\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n", __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in, dummy ) ); + } + { + std::string state; + string_input in( "01\r\nX\r\n1A\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n", __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR, chunked_action >( in, state ) ); + TAO_PEGTL_TEST_ASSERT( state == "ababa" ); + } + } + + void unit_test() + { + test_header(); + test_chunked(); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_integer.cpp b/packages/PEGTL/src/test/pegtl/contrib_integer.cpp index e819cdc6d27a6d52748bd9c50db963eb9a4878a8..a06d00229e79f3a6955f965a55367e436538b929 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_integer.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_integer.cpp @@ -123,7 +123,8 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( st == s ); } - template< auto M > using max_seq_rule = seq< one< 'a' >, integer::maximum_rule< std::uint64_t, M >, one< 'b' >, eof >; + template< auto M > + using max_seq_rule = seq< one< 'a' >, integer::maximum_rule< std::uint64_t, M >, one< 'b' >, eof >; void unit_test() { diff --git a/packages/PEGTL/src/test/pegtl/contrib_parse_tree.cpp b/packages/PEGTL/src/test/pegtl/contrib_parse_tree.cpp index 2df7a9b301a0abdfa303480549819b6d0b805c9c..2148276aca36cd15af316192b85b81a9c8884986 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_parse_tree.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_parse_tree.cpp @@ -31,11 +31,7 @@ namespace TAO_PEGTL_NAMESPACE const auto& d = r->children.front(); TAO_PEGTL_TEST_ASSERT( !d->is_root() ); - TAO_PEGTL_TEST_ASSERT( d->id == typeid( D ) ); - TAO_PEGTL_TEST_ASSERT( d->is< D >() ); -#if !defined( _MSC_VER ) - TAO_PEGTL_TEST_ASSERT( d->name() == "tao::pegtl::D" ); -#endif + TAO_PEGTL_TEST_ASSERT( d->is_type< D >() ); TAO_PEGTL_TEST_ASSERT( d->has_content() ); TAO_PEGTL_TEST_ASSERT( d->begin().byte == 0 ); @@ -43,8 +39,8 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( d->string_view() == "ac" ); TAO_PEGTL_TEST_ASSERT( d->children.size() == 2 ); - TAO_PEGTL_TEST_ASSERT( d->children.front()->is< A >() ); - TAO_PEGTL_TEST_ASSERT( d->children.back()->is< C >() ); + TAO_PEGTL_TEST_ASSERT( d->children.front()->is_type< A >() ); + TAO_PEGTL_TEST_ASSERT( d->children.back()->is_type< C >() ); memory_input in2( "x", "input" ); const auto r2 = parse_tree::parse< D, selector >( in2 ); diff --git a/packages/PEGTL/src/test/pegtl/contrib_raw_string.cpp b/packages/PEGTL/src/test/pegtl/contrib_raw_string.cpp index 6c41cfca344c520caad90720f106b4e35d1fe9e7..f5872562166521630ff25a095ac1ab13658948dc 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_raw_string.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_raw_string.cpp @@ -8,7 +8,7 @@ namespace TAO_PEGTL_NAMESPACE { - std::string content; // NOLINT + std::string content; using rstring = raw_string< '[', '=', ']' >; using qstring = raw_string< '[', '=', ']', alpha, digit >; @@ -52,7 +52,7 @@ namespace TAO_PEGTL_NAMESPACE }; template< typename Rule, template< typename > class Action, unsigned M, unsigned N > - void verify_data( const std::size_t line, const char* file, const char ( &m )[ M ], const char ( &n )[ N ] ) // NOLINT + void verify_data( const std::size_t line, const char* file, const char ( &m )[ M ], const char ( &n )[ N ] ) { content.clear(); memory_input in( m, m + M - 1, file, 0, line, 0 ); diff --git a/packages/PEGTL/src/test/pegtl/contrib_unescape.cpp b/packages/PEGTL/src/test/pegtl/contrib_unescape.cpp index f31754192121d152193cc0e69f24b2f79c062059..e962074fd26132f97301477e549f4ef79d7e921e 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_unescape.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_unescape.cpp @@ -29,13 +29,13 @@ namespace TAO_PEGTL_NAMESPACE // clang-format on template< unsigned M, unsigned N > - void verify_data( const char ( &m )[ M ], const char ( &n )[ N ] ) // NOLINT + void verify_data( const char ( &m )[ M ], const char ( &n )[ N ] ) { std::string s; memory_input in( m, M - 1, __FUNCTION__ ); parse< unstring, unaction >( in, s ); if( s != std::string( n, N - 1 ) ) { - throw std::runtime_error( "test failed!" ); // NOLINT + throw std::runtime_error( "test failed!" ); } } diff --git a/packages/PEGTL/src/test/pegtl/demangle.cpp b/packages/PEGTL/src/test/pegtl/demangle.cpp index a83296d59454670e22df0fc4665a238134e7972f..3826a8eed8ffeabf4a1edf0b43206fd571400eef 100644 --- a/packages/PEGTL/src/test/pegtl/demangle.cpp +++ b/packages/PEGTL/src/test/pegtl/demangle.cpp @@ -3,31 +3,32 @@ #include "test.hpp" -#include <tao/pegtl/internal/demangle_sanitise.hpp> +#include <tao/pegtl/internal/demangle.hpp> namespace TAO_PEGTL_NAMESPACE { - void test_chars( std::string a, const std::string& b ) + template< typename T > + void test( const std::string& s ) { - internal::demangle_sanitise_chars( a ); - TAO_PEGTL_TEST_ASSERT( a == b ); + TAO_PEGTL_TEST_ASSERT( internal::demangle< T >() == s ); } void unit_test() { - const std::string s = "something that can't be demangled"; - const std::string a = internal::demangle( s.c_str() ); - TAO_PEGTL_TEST_ASSERT( a == s ); - const std::string b = internal::demangle< std::string >(); - (void)b; // Not standardised. - - test_chars( "zzz(char)1xxx", "zzz1xxx" ); - test_chars( "zzz(char)32xxx", "zzz' 'xxx" ); - test_chars( "zzz(char)48xxx", "zzz'0'xxx" ); - test_chars( "zzz(char)39xxx", "zzz'\\''xxx" ); - test_chars( "zzz(char)92xxx", "zzz'\\\\'xxx" ); - test_chars( "frobnicate<> (char)1 (char)32 (char)48 ***", "frobnicate<> 1 ' ' '0' ***" ); - test_chars( "tao::pegtl::internal::until<tao::pegtl::at<tao::pegtl::ascii::one<(char)34> >", "tao::pegtl::internal::until<tao::pegtl::at<tao::pegtl::ascii::one<'\"'> >" ); +#if defined( __GNUC__ ) && ( __GNUC__ == 9 ) || ( __GNUC_MINOR__ == 1 ) + // see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91155 + test< int >( "i" ); + test< double >( "d" ); + test< seq< bytes< 42 >, eof > >( "N3tao5pegtl3seqIJNS0_5bytesILj42EEENS0_3eofEEEE" ); +#elif defined( _MSC_VER ) + test< int >( "int" ); + test< double >( "double" ); + test< seq< bytes< 42 >, eof > >( "struct tao::pegtl::seq<struct tao::pegtl::bytes<42>,struct tao::pegtl::eof>" ); +#else + test< int >( "int" ); + test< double >( "double" ); + test< seq< bytes< 42 >, eof > >( "tao::pegtl::seq<tao::pegtl::bytes<42>, tao::pegtl::eof>" ); +#endif } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/file_cstream.cpp b/packages/PEGTL/src/test/pegtl/file_cstream.cpp index 0560a33e9a8b3ad7b4de3dc13f2f970e38dd53a2..80c0801f8c3e482f896dd1d137450268adc2a8a0 100644 --- a/packages/PEGTL/src/test/pegtl/file_cstream.cpp +++ b/packages/PEGTL/src/test/pegtl/file_cstream.cpp @@ -21,13 +21,13 @@ namespace TAO_PEGTL_NAMESPACE const char* const filename = "src/test/pegtl/file_data.txt"; #if defined( _MSC_VER ) std::FILE* stream; - ::fopen_s( &stream, filename, "rb" ); // NOLINT + ::fopen_s( &stream, filename, "rb" ); #else - std::FILE* stream = std::fopen( filename, "rb" ); // NOLINT + std::FILE* stream = std::fopen( filename, "rb" ); #endif TAO_PEGTL_TEST_ASSERT( stream != nullptr ); TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( cstream_input( stream, 16, filename ) ) ); - std::fclose( stream ); // NOLINT(cppcoreguidelines-owning-memory) + std::fclose( stream ); } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/main.hpp b/packages/PEGTL/src/test/pegtl/main.hpp index c72e13b031452322b40b9e0080ff7cc515aefda8..36d548967718802562d75f340a5027a1cebd2e71 100644 --- a/packages/PEGTL/src/test/pegtl/main.hpp +++ b/packages/PEGTL/src/test/pegtl/main.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_MAIN_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_MAIN_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_MAIN_HPP #include <cstdlib> diff --git a/packages/PEGTL/src/test/pegtl/pegtl_string_t.cpp b/packages/PEGTL/src/test/pegtl/pegtl_string_t.cpp index 0a7c584397bc0429b59633cc8ea9108ca38d2452..6493b5dd531feca222af9c68bc3e6461cbb344e9 100644 --- a/packages/PEGTL/src/test/pegtl/pegtl_string_t.cpp +++ b/packages/PEGTL/src/test/pegtl/pegtl_string_t.cpp @@ -30,7 +30,7 @@ namespace test // The strings currently have a maximum length of 512 characters. - using namespace TAO_PEGTL_NAMESPACE::alphabet; // NOLINT + using namespace TAO_PEGTL_NAMESPACE::alphabet; static_assert( std::is_same_v< TAO_PEGTL_STRING( "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" ), TAO_PEGTL_NAMESPACE::string< a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z > > ); diff --git a/packages/PEGTL/src/test/pegtl/result_type.hpp b/packages/PEGTL/src/test/pegtl/result_type.hpp index 1d5c89c4cbce107a7fc9fcffcd2f03801c7fbf40..7ac9b2cb6cb1de8bfbe1b93052b8d79fded180e9 100644 --- a/packages/PEGTL/src/test/pegtl/result_type.hpp +++ b/packages/PEGTL/src/test/pegtl/result_type.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_RESULT_TYPE_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_RESULT_TYPE_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_RESULT_TYPE_HPP #include <ostream> diff --git a/packages/PEGTL/src/test/pegtl/rule_apply.cpp b/packages/PEGTL/src/test/pegtl/rule_apply.cpp index 4f64066e6b903558b2462d51867d5367623be058..7ecc776ca1e411314a2fe59c759b5271781ce8f0 100644 --- a/packages/PEGTL/src/test/pegtl/rule_apply.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_apply.cpp @@ -84,7 +84,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< apply<> >( __LINE__, __FILE__, "", result_type::success, 0 ); for( char i = 1; i < 127; ++i ) { - char t[] = { i, 0 }; // NOLINT + char t[] = { i, 0 }; verify_rule< apply<> >( __LINE__, __FILE__, std::string( t ), result_type::success, 1 ); } } diff --git a/packages/PEGTL/src/test/pegtl/rule_apply0.cpp b/packages/PEGTL/src/test/pegtl/rule_apply0.cpp index e3b27ee2f70d5a44512b26213c317eeaced3e403..33192af197dbba745688a74d98ed2acd85d523de 100644 --- a/packages/PEGTL/src/test/pegtl/rule_apply0.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_apply0.cpp @@ -79,7 +79,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< apply0<> >( __LINE__, __FILE__, "", result_type::success, 0 ); for( char i = 1; i < 127; ++i ) { - char t[] = { i, 0 }; // NOLINT + char t[] = { i, 0 }; verify_rule< apply0<> >( __LINE__, __FILE__, std::string( t ), result_type::success, 1 ); } } diff --git a/packages/PEGTL/src/test/pegtl/rule_bof.cpp b/packages/PEGTL/src/test/pegtl/rule_bof.cpp index ff44dbef1d1413ba6ad53292673446b866036a0e..3dced0655da24da5827d964f6b21fd67db5f529c 100644 --- a/packages/PEGTL/src/test/pegtl/rule_bof.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_bof.cpp @@ -14,7 +14,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< bof >( __LINE__, __FILE__, "", result_type::success, 0 ); for( char i = 1; i < 127; ++i ) { - const char s[] = { i, 0 }; // NOLINT + const char s[] = { i, 0 }; verify_rule< bof >( __LINE__, __FILE__, s, result_type::success, 1 ); } verify_rule< seq< alpha, bof > >( __LINE__, __FILE__, "a", result_type::local_failure, 1 ); diff --git a/packages/PEGTL/src/test/pegtl/rule_bol.cpp b/packages/PEGTL/src/test/pegtl/rule_bol.cpp index 60852c6d8aedcd1e97e3935733df98b701dcfd5b..e7c8adc3996ab3373641aa2120cc309a661a1b51 100644 --- a/packages/PEGTL/src/test/pegtl/rule_bol.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_bol.cpp @@ -14,7 +14,7 @@ namespace TAO_PEGTL_NAMESPACE verify_only< bol >( __LINE__, __FILE__, "", result_type::success, 0 ); for( char i = 1; i < 127; ++i ) { - const char s[] = { i, 0 }; // NOLINT + const char s[] = { i, 0 }; verify_only< bol >( __LINE__, __FILE__, s, result_type::success, 1 ); } verify_only< seq< alpha, bol > >( __LINE__, __FILE__, "a", result_type::local_failure, 1 ); diff --git a/packages/PEGTL/src/test/pegtl/rule_success.cpp b/packages/PEGTL/src/test/pegtl/rule_success.cpp index 08e4185fc017a87050763cd601b6b73c33636d13..4bd358420475731c9612eaf91f8dd00b443c0378 100644 --- a/packages/PEGTL/src/test/pegtl/rule_success.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_success.cpp @@ -14,7 +14,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< success >( __LINE__, __FILE__, "", result_type::success, 0 ); for( char i = 1; i < 127; ++i ) { - char t[] = { i, 0 }; // NOLINT + char t[] = { i, 0 }; verify_rule< success >( __LINE__, __FILE__, std::string( t ), result_type::success, 1 ); } } diff --git a/packages/PEGTL/src/test/pegtl/test.hpp b/packages/PEGTL/src/test/pegtl/test.hpp index e00d7b47c5537a738f8df99bd571fc25f907cf5f..c0f8b3e20e3741c76d51153a201e7b28dcb4aa6e 100644 --- a/packages/PEGTL/src/test/pegtl/test.hpp +++ b/packages/PEGTL/src/test/pegtl/test.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_TEST_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_TEST_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_TEST_HPP #include <cstddef> @@ -11,7 +11,7 @@ namespace TAO_PEGTL_NAMESPACE { - std::size_t failed = 0; // NOLINT + std::size_t failed = 0; } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/utf16_general.cpp b/packages/PEGTL/src/test/pegtl/utf16_general.cpp index fd84074943d037acb10e80132963e9e6cda23cf7..74a3c6ffdec97e91f152eef1b40c2c96f110acb5 100644 --- a/packages/PEGTL/src/test/pegtl/utf16_general.cpp +++ b/packages/PEGTL/src/test/pegtl/utf16_general.cpp @@ -10,19 +10,19 @@ namespace TAO_PEGTL_NAMESPACE { std::string u16s( const char16_t u ) { - return std::string( static_cast< const char* >( static_cast< const void* >( &u ) ), sizeof( u ) ); + return std::string( reinterpret_cast< const char* >( &u ), sizeof( u ) ); } std::string u16s_be( const char16_t v ) { const std::uint16_t u = internal::h_to_be( std::uint16_t( v ) ); - return std::string( static_cast< const char* >( static_cast< const void* >( &u ) ), sizeof( u ) ); + return std::string( reinterpret_cast< const char* >( &u ), sizeof( u ) ); } std::string u16s_le( const char16_t v ) { const std::uint16_t u = internal::h_to_le( std::uint16_t( v ) ); - return std::string( static_cast< const char* >( static_cast< const void* >( &u ) ), sizeof( u ) ); + return std::string( reinterpret_cast< const char* >( &u ), sizeof( u ) ); } } // namespace diff --git a/packages/PEGTL/src/test/pegtl/utf32_general.cpp b/packages/PEGTL/src/test/pegtl/utf32_general.cpp index d00da771d978885e77ac582da9d0a6a80ea9f007..994275760ff11afd43b6e3e402a99be43e076d50 100644 --- a/packages/PEGTL/src/test/pegtl/utf32_general.cpp +++ b/packages/PEGTL/src/test/pegtl/utf32_general.cpp @@ -10,19 +10,19 @@ namespace TAO_PEGTL_NAMESPACE { std::string u32s( const char32_t u ) { - return std::string( static_cast< const char* >( static_cast< const void* >( &u ) ), sizeof( u ) ); + return std::string( reinterpret_cast< const char* >( &u ), sizeof( u ) ); } std::string u32s_be( const char32_t v ) { const std::uint32_t u = internal::h_to_be( std::uint32_t( v ) ); - return std::string( static_cast< const char* >( static_cast< const void* >( &u ) ), sizeof( u ) ); + return std::string( reinterpret_cast< const char* >( &u ), sizeof( u ) ); } std::string u32s_le( const char32_t v ) { const std::uint32_t u = internal::h_to_le( std::uint32_t( v ) ); - return std::string( static_cast< const char* >( static_cast< const void* >( &u ) ), sizeof( u ) ); + return std::string( reinterpret_cast< const char* >( &u ), sizeof( u ) ); } } // namespace diff --git a/packages/PEGTL/src/test/pegtl/verify_analyze.hpp b/packages/PEGTL/src/test/pegtl/verify_analyze.hpp index 4787e8aff703e485e050ac9b7f903968d5407cde..957184bf59d8bd2f7e8a04a470ccc1515b8fa16e 100644 --- a/packages/PEGTL/src/test/pegtl/verify_analyze.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_analyze.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_ANALYZE_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_ANALYZE_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_ANALYZE_HPP #include <tao/pegtl/analyze.hpp> diff --git a/packages/PEGTL/src/test/pegtl/verify_char.hpp b/packages/PEGTL/src/test/pegtl/verify_char.hpp index 94800209d22e437fe9a78ae89c4478db015f42d2..5129a2fa28b5075a1e2bab4edc5fca58c0b42bdc 100644 --- a/packages/PEGTL/src/test/pegtl/verify_char.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_char.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_CHAR_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_CHAR_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_CHAR_HPP #include <cstdlib> diff --git a/packages/PEGTL/src/test/pegtl/verify_fail.hpp b/packages/PEGTL/src/test/pegtl/verify_fail.hpp index 4ca68eec1a1459ace3f4b2a2154ef8fe7906f9c1..c46b3f424f4e36f00e58666ef30ca66f8aef9a41 100644 --- a/packages/PEGTL/src/test/pegtl/verify_fail.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_fail.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2015-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FAIL_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FAIL_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FAIL_HPP #include <cstddef> diff --git a/packages/PEGTL/src/test/pegtl/verify_file.hpp b/packages/PEGTL/src/test/pegtl/verify_file.hpp index 3b3d4ad429fb42dd9efa83e772e55ffe380feb37..93ba5afde5fce46bcb2984520805b4580c44d935 100644 --- a/packages/PEGTL/src/test/pegtl/verify_file.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_file.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FILE_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FILE_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FILE_HPP #include <tao/pegtl.hpp> diff --git a/packages/PEGTL/src/test/pegtl/verify_ifmt.hpp b/packages/PEGTL/src/test/pegtl/verify_ifmt.hpp index b7ea5e99c1130d1b4ce42c81e3234c8cd0799f1f..b7d107dc763499d88117ca78611704662ff6a1ce 100644 --- a/packages/PEGTL/src/test/pegtl/verify_ifmt.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_ifmt.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IFMT_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IFMT_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IFMT_HPP #include <tao/pegtl.hpp> diff --git a/packages/PEGTL/src/test/pegtl/verify_impl.hpp b/packages/PEGTL/src/test/pegtl/verify_impl.hpp index 59559840665bb6041b0015224f0a8816429211ba..d6cfe56263a7f6275a0f95d429f4688b77ac7da7 100644 --- a/packages/PEGTL/src/test/pegtl/verify_impl.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_impl.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IMPL_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IMPL_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IMPL_HPP #include <cstddef> diff --git a/packages/PEGTL/src/test/pegtl/verify_rule.hpp b/packages/PEGTL/src/test/pegtl/verify_rule.hpp index e8c516f6c90feeefb859f0d125ba4a99eaa98083..65e1ba6d719335aa2bca93114be654e9c034d831 100644 --- a/packages/PEGTL/src/test/pegtl/verify_rule.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_rule.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_RULE_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_RULE_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_RULE_HPP #include <cstdlib> diff --git a/packages/PEGTL/src/test/pegtl/verify_seqs.hpp b/packages/PEGTL/src/test/pegtl/verify_seqs.hpp index 1de8bcf445ccfca9fc10a52c8322334e4b958dd3..e253bef82f703941223c0e953f17d7c5cf21c516 100644 --- a/packages/PEGTL/src/test/pegtl/verify_seqs.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_seqs.hpp @@ -1,7 +1,7 @@ // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_SEQS_HPP // NOLINT +#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_SEQS_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_SEQS_HPP #include <tao/pegtl.hpp> diff --git a/src/language/ASTBuilder.cpp b/src/language/ASTBuilder.cpp index 1ba6bfcec94d69da3491be866c17e0f307f408ad..56ebc43fa7f9d56fb58789a49105a613d3ae2651 100644 --- a/src/language/ASTBuilder.cpp +++ b/src/language/ASTBuilder.cpp @@ -35,21 +35,21 @@ struct ASTBuilder::rearrange : parse_tree::apply<ASTBuilder::rearrange> } // Then we eventually simplify operations { - if (n->is<language::minus_op>()) { + if (n->is_type<language::minus_op>()) { Assert(n->children.size() == 2); auto& rhs = n->children[1]; - if (rhs->is<language::unary_minus>()) { + if (rhs->is_type<language::unary_minus>()) { rhs->remove_content(); - n->id = typeid(language::plus_op); - rhs = std::move(rhs->children[0]); + n->set_type<language::plus_op>(); + rhs = std::move(rhs->children[0]); } - } else if (n->is<language::plus_op>()) { + } else if (n->is_type<language::plus_op>()) { Assert(n->children.size() == 2); auto& rhs = n->children[1]; - if (rhs->is<language::unary_minus>()) { + if (rhs->is_type<language::unary_minus>()) { rhs->remove_content(); - n->id = typeid(language::minus_op); - rhs = std::move(rhs->children[0]); + n->set_type<language::minus_op>(); + rhs = std::move(rhs->children[0]); } } } @@ -64,21 +64,21 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary transform(std::unique_ptr<ASTNode>& n, States&&... st) { if (n->children.size() == 1) { - if (n->is<unary_expression>() or n->is<type_expression>()) { + if (n->is_type<unary_expression>() or n->is_type<type_expression>()) { n->remove_content(); n = std::move(n->children.back()); transform(n, st...); - } else if (n->is<unary_minus>()) { + } else if (n->is_type<unary_minus>()) { auto& child = n->children[0]; - if (child->is<unary_minus>()) { + if (child->is_type<unary_minus>()) { n->remove_content(); child->remove_content(); n = std::move(child->children[0]); transform(n, st...); } - } else if (n->is<unary_not>()) { + } else if (n->is_type<unary_not>()) { auto& child = n->children[0]; - if (child->is<unary_not>()) { + if (child->is_type<unary_not>()) { n->remove_content(); child->remove_content(); n = std::move(child->children[0]); @@ -86,12 +86,13 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary } } } else if (n->children.size() == 2) { - if (n->children[0]->is<language::unary_plus>()) { + if (n->children[0]->is_type<language::unary_plus>()) { n->remove_content(); n = std::move(n->children[1]); transform(n, st...); - } else if (n->children[0]->is<language::unary_minus>() or n->children[0]->is<language::unary_not>() or - n->children[0]->is<language::unary_minusminus>() or n->children[0]->is<language::unary_plusplus>()) { + } else if (n->children[0]->is_type<language::unary_minus>() or n->children[0]->is_type<language::unary_not>() or + n->children[0]->is_type<language::unary_minusminus>() or + n->children[0]->is_type<language::unary_plusplus>()) { n->remove_content(); auto expression = std::move(n->children[1]); auto unary_operator = std::move(n->children[0]); @@ -102,11 +103,11 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary } } - if (n->is<language::unary_expression>()) { + if (n->is_type<language::unary_expression>()) { size_t child_nb = n->children.size(); if (child_nb > 1) { - if (n->children[child_nb - 1]->is<language::post_minusminus>() or - n->children[child_nb - 1]->is<language::post_plusplus>()) { + if (n->children[child_nb - 1]->is_type<language::post_minusminus>() or + n->children[child_nb - 1]->is_type<language::post_plusplus>()) { auto unary_operator = std::move(n->children[child_nb - 1]); n->children.pop_back(); @@ -128,14 +129,13 @@ struct ASTBuilder::simplify_statement_block : parse_tree::apply<ASTBuilder::simp static void transform(std::unique_ptr<ASTNode>& n, States&&... st) { - if ((n->id == typeid(language::statement_block) or n->id == typeid(language::block)) and - (n->children.size() == 1)) { - if (not n->children[0]->is<language::declaration>()) { + if ((n->is_type<language::statement_block>() or n->is_type<language::block>()) and (n->children.size() == 1)) { + if (not n->children[0]->is_type<language::declaration>()) { n->remove_content(); n = std::move(n->children.back()); transform(n, st...); } else { - n->id = typeid(language::block); + n->set_type<language::block>(); } } } @@ -147,8 +147,7 @@ struct ASTBuilder::simplify_for_statement_block : parse_tree::apply<ASTBuilder:: static void transform(std::unique_ptr<ASTNode>& n, States&&... st) { - if ((n->id == typeid(language::for_statement_block) or n->id == typeid(language::block)) and - (n->children.size() == 1)) { + if ((n->is_type<language::for_statement_block>() or n->is_type<language::block>()) and (n->children.size() == 1)) { n->remove_content(); n = std::move(n->children.back()); transform(n, st...); diff --git a/src/language/ASTModulesImporter.cpp b/src/language/ASTModulesImporter.cpp index 1a2e8765c1c36661a0d3a6d0470eca5f2c36a318..12d5bd5c0eb74a6dc1dec0cf2d1de73dd9436da1 100644 --- a/src/language/ASTModulesImporter.cpp +++ b/src/language/ASTModulesImporter.cpp @@ -13,8 +13,8 @@ void ASTModulesImporter::_importModule(ASTNode& import_node) { - Assert(import_node.is<language::import_instruction>()); - Assert(import_node.children[0]->is<language::module_name>()); + Assert(import_node.is_type<language::import_instruction>()); + Assert(import_node.children[0]->is_type<language::module_name>()); ASTNode& module_name_node = *import_node.children[0]; const std::string module_name = module_name_node.string(); @@ -49,7 +49,7 @@ ASTModulesImporter::_importModule(ASTNode& import_node) void ASTModulesImporter::_importAllModules(ASTNode& node) { - if (node.is<language::import_instruction>()) { + if (node.is_type<language::import_instruction>()) { this->_importModule(node); } else { for (auto& child : node.children) { diff --git a/src/language/ASTNode.hpp b/src/language/ASTNode.hpp index 92aeb29e09458c780f112dbc4aa166bb96a14d3d..b92e33c0cf26b132f297d0897f28af57144a618b 100644 --- a/src/language/ASTNode.hpp +++ b/src/language/ASTNode.hpp @@ -24,6 +24,12 @@ struct ASTNode : public parse_tree::basic_node<ASTNode> ASTNodeDataType m_data_type{ASTNodeDataType::undefined_t}; ASTNodeDataVariant m_value; + std::string + name() const noexcept + { + return demangle(std::string{this->type}); + } + PUGS_INLINE void execute(ExecUntilBreakOrContinue& exec_policy) diff --git a/src/language/ASTNodeAffectationExpressionBuilder.cpp b/src/language/ASTNodeAffectationExpressionBuilder.cpp index 22ee9711d214045cb8889b5c1d662942444c73be..c515da24dbd4ebc8bb47f89d5a4266939ccff70a 100644 --- a/src/language/ASTNodeAffectationExpressionBuilder.cpp +++ b/src/language/ASTNodeAffectationExpressionBuilder.cpp @@ -101,15 +101,15 @@ ASTNodeAffectationExpressionBuilder::ASTNodeAffectationExpressionBuilder(ASTNode set_affectation_processor_for_value(n.m_data_type); }; - if (n.is<language::eq_op>()) { + if (n.is_type<language::eq_op>()) { set_affectation_processor(n, language::eq_op{}); - } else if (n.is<language::multiplyeq_op>()) { + } else if (n.is_type<language::multiplyeq_op>()) { set_affectation_processor(n, language::multiplyeq_op{}); - } else if (n.is<language::divideeq_op>()) { + } else if (n.is_type<language::divideeq_op>()) { set_affectation_processor(n, language::divideeq_op{}); - } else if (n.is<language::pluseq_op>()) { + } else if (n.is_type<language::pluseq_op>()) { set_affectation_processor(n, language::pluseq_op{}); - } else if (n.is<language::minuseq_op>()) { + } else if (n.is_type<language::minuseq_op>()) { set_affectation_processor(n, language::minuseq_op{}); } else { throw parse_error("unexpected error: undefined affectation operator", std::vector{n.begin()}); diff --git a/src/language/ASTNodeBinaryOperatorExpressionBuilder.cpp b/src/language/ASTNodeBinaryOperatorExpressionBuilder.cpp index cc38f0f7ec3d73c5813bb3e2494c558814a79785..b472b4a4418b37ee8d3ed70aee0cf0afac2e8429 100644 --- a/src/language/ASTNodeBinaryOperatorExpressionBuilder.cpp +++ b/src/language/ASTNodeBinaryOperatorExpressionBuilder.cpp @@ -106,33 +106,33 @@ ASTNodeBinaryOperatorExpressionBuilder::ASTNodeBinaryOperatorExpressionBuilder(A set_binary_operator_processor_for_data_a(n.children[0]->m_data_type); }; - if (n.is<language::multiply_op>()) { + if (n.is_type<language::multiply_op>()) { set_binary_operator_processor(n, language::multiply_op{}); - } else if (n.is<language::divide_op>()) { + } else if (n.is_type<language::divide_op>()) { set_binary_operator_processor(n, language::divide_op{}); - } else if (n.is<language::plus_op>()) { + } else if (n.is_type<language::plus_op>()) { set_binary_operator_processor(n, language::plus_op{}); - } else if (n.is<language::minus_op>()) { + } else if (n.is_type<language::minus_op>()) { set_binary_operator_processor(n, language::minus_op{}); - } else if (n.is<language::or_op>()) { + } else if (n.is_type<language::or_op>()) { set_binary_operator_processor(n, language::or_op{}); - } else if (n.is<language::and_op>()) { + } else if (n.is_type<language::and_op>()) { set_binary_operator_processor(n, language::and_op{}); - } else if (n.is<language::xor_op>()) { + } else if (n.is_type<language::xor_op>()) { set_binary_operator_processor(n, language::xor_op{}); - } else if (n.is<language::greater_op>()) { + } else if (n.is_type<language::greater_op>()) { set_binary_operator_processor(n, language::greater_op{}); - } else if (n.is<language::greater_or_eq_op>()) { + } else if (n.is_type<language::greater_or_eq_op>()) { set_binary_operator_processor(n, language::greater_or_eq_op{}); - } else if (n.is<language::lesser_op>()) { + } else if (n.is_type<language::lesser_op>()) { set_binary_operator_processor(n, language::lesser_op{}); - } else if (n.is<language::lesser_or_eq_op>()) { + } else if (n.is_type<language::lesser_or_eq_op>()) { set_binary_operator_processor(n, language::lesser_or_eq_op{}); - } else if (n.is<language::eqeq_op>()) { + } else if (n.is_type<language::eqeq_op>()) { set_binary_operator_processor(n, language::eqeq_op{}); - } else if (n.is<language::not_eq_op>()) { + } else if (n.is_type<language::not_eq_op>()) { set_binary_operator_processor(n, language::not_eq_op{}); } else { throw parse_error("unexpected error: undefined binary operator", std::vector{n.begin()}); diff --git a/src/language/ASTNodeCFunctionExpressionBuilder.cpp b/src/language/ASTNodeCFunctionExpressionBuilder.cpp index 4b25a316a203baa5632e6a587434ac870d578743..90bede0313527ad1026b4715d9a4cac2c8921166 100644 --- a/src/language/ASTNodeCFunctionExpressionBuilder.cpp +++ b/src/language/ASTNodeCFunctionExpressionBuilder.cpp @@ -76,7 +76,7 @@ ASTNodeCFunctionExpressionBuilder::_buildArgumentProcessors(ASTNode& node, { ASTNode& argument_nodes = *node.children[1]; - const size_t arguments_number = argument_nodes.is<language::expression_list>() ? argument_nodes.children.size() : 1; + const size_t arguments_number = argument_nodes.is_type<language::expression_list>() ? argument_nodes.children.size() : 1; c_function_processor.setNumberOfArguments(arguments_number); diff --git a/src/language/ASTNodeDataTypeBuilder.cpp b/src/language/ASTNodeDataTypeBuilder.cpp index 20233042ef2bcc0eb38e104ecdb80fdf24ffb1f3..350e22622a1fe16a5fa6b94c056b9a53226fa0bf 100644 --- a/src/language/ASTNodeDataTypeBuilder.cpp +++ b/src/language/ASTNodeDataTypeBuilder.cpp @@ -9,40 +9,40 @@ void ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) { - if (n.is<language::block>() or n.is<language::for_statement>()) { + if (n.is_type<language::block>() or n.is_type<language::for_statement>()) { for (auto& child : n.children) { this->_buildNodeDataTypes(*child); } n.m_data_type = ASTNodeDataType::void_t; } else { if (n.has_content()) { - if (n.is<language::import_instruction>()) { + if (n.is_type<language::import_instruction>()) { n.m_data_type = ASTNodeDataType::void_t; - } else if (n.is<language::module_name>()) { + } else if (n.is_type<language::module_name>()) { n.m_data_type = ASTNodeDataType::string_t; - } else if (n.is<language::true_kw>() or n.is<language::false_kw>()) { + } else if (n.is_type<language::true_kw>() or n.is_type<language::false_kw>()) { n.m_data_type = ASTNodeDataType::bool_t; - } else if (n.is<language::real>()) { + } else if (n.is_type<language::real>()) { n.m_data_type = ASTNodeDataType::double_t; - } else if (n.is<language::integer>()) { + } else if (n.is_type<language::integer>()) { n.m_data_type = ASTNodeDataType::int_t; - } else if (n.is<language::literal>()) { + } else if (n.is_type<language::literal>()) { n.m_data_type = ASTNodeDataType::string_t; - } else if (n.is<language::cout_kw>() or n.is<language::cerr_kw>() or n.is<language::clog_kw>()) { + } else if (n.is_type<language::cout_kw>() or n.is_type<language::cerr_kw>() or n.is_type<language::clog_kw>()) { n.m_data_type = ASTNodeDataType::void_t; - } else if (n.is<language::declaration>()) { + } else if (n.is_type<language::declaration>()) { auto& type_node = *(n.children[0]); ASTNodeDataType data_type{ASTNodeDataType::undefined_t}; - if (type_node.is<language::B_set>()) { + if (type_node.is_type<language::B_set>()) { data_type = ASTNodeDataType::bool_t; - } else if (type_node.is<language::Z_set>()) { + } else if (type_node.is_type<language::Z_set>()) { data_type = ASTNodeDataType::int_t; - } else if (type_node.is<language::N_set>()) { + } else if (type_node.is_type<language::N_set>()) { data_type = ASTNodeDataType::unsigned_int_t; - } else if (type_node.is<language::R_set>()) { + } else if (type_node.is_type<language::R_set>()) { data_type = ASTNodeDataType::double_t; - } else if (type_node.is<language::string_type>()) { + } else if (type_node.is_type<language::string_type>()) { data_type = ASTNodeDataType::string_t; } @@ -58,7 +58,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) Assert(found); i_symbol->attributes().setDataType(data_type); n.m_data_type = data_type; - } else if (n.is<language::let_declaration>()) { + } else if (n.is_type<language::let_declaration>()) { n.children[0]->m_data_type = ASTNodeDataType::function_t; const std::string& symbol = n.children[0]->string(); @@ -99,15 +99,15 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) auto simple_type_allocator = [&](const ASTNode& type_node, ASTNode& symbol_node) { ASTNodeDataType data_type{ASTNodeDataType::undefined_t}; - if (type_node.is<language::B_set>()) { + if (type_node.is_type<language::B_set>()) { data_type = ASTNodeDataType::bool_t; - } else if (type_node.is<language::Z_set>()) { + } else if (type_node.is_type<language::Z_set>()) { data_type = ASTNodeDataType::int_t; - } else if (type_node.is<language::N_set>()) { + } else if (type_node.is_type<language::N_set>()) { data_type = ASTNodeDataType::unsigned_int_t; - } else if (type_node.is<language::R_set>()) { + } else if (type_node.is_type<language::R_set>()) { data_type = ASTNodeDataType::double_t; - } else if (type_node.is<language::string_type>()) { + } else if (type_node.is_type<language::string_type>()) { data_type = ASTNodeDataType::string_t; } @@ -124,7 +124,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) }; if (parameters_domain_node.children.size() == 0) { - if (parameters_name_node.is<language::name_list>()) { + if (parameters_name_node.is_type<language::name_list>()) { simple_type_allocator(parameters_domain_node, *parameters_name_node.children[0]); } else { simple_type_allocator(parameters_domain_node, parameters_name_node); @@ -150,7 +150,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) } n.m_data_type = ASTNodeDataType::void_t; - } else if (n.is<language::name>()) { + } else if (n.is_type<language::name>()) { std::shared_ptr<SymbolTable>& symbol_table = n.m_symbol_table; auto [i_symbol, found] = symbol_table->find(n.string(), n.begin()); @@ -162,20 +162,20 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) this->_buildNodeDataTypes(*child); } - if (n.is<language::break_kw>() or n.is<language::continue_kw>()) { + if (n.is_type<language::break_kw>() or n.is_type<language::continue_kw>()) { n.m_data_type = ASTNodeDataType::void_t; - } else if (n.is<language::eq_op>() or n.is<language::multiplyeq_op>() or n.is<language::divideeq_op>() or - n.is<language::pluseq_op>() or n.is<language::minuseq_op>()) { + } else if (n.is_type<language::eq_op>() or n.is_type<language::multiplyeq_op>() or n.is_type<language::divideeq_op>() or + n.is_type<language::pluseq_op>() or n.is_type<language::minuseq_op>()) { n.m_data_type = n.children[0]->m_data_type; - } else if (n.is<language::type_mapping>() or n.is<language::function_definition>()) { + } else if (n.is_type<language::type_mapping>() or n.is_type<language::function_definition>()) { n.m_data_type = ASTNodeDataType::void_t; - } else if (n.is<language::for_post>() or n.is<language::for_init>() or n.is<language::for_statement_block>()) { + } else if (n.is_type<language::for_post>() or n.is_type<language::for_init>() or n.is_type<language::for_statement_block>()) { n.m_data_type = ASTNodeDataType::void_t; - } else if (n.is<language::for_test>()) { + } else if (n.is_type<language::for_test>()) { n.m_data_type = ASTNodeDataType::bool_t; - } else if (n.is<language::statement_block>()) { + } else if (n.is_type<language::statement_block>()) { n.m_data_type = ASTNodeDataType::void_t; - } else if (n.is<language::if_statement>() or n.is<language::while_statement>()) { + } else if (n.is_type<language::if_statement>() or n.is_type<language::while_statement>()) { n.m_data_type = ASTNodeDataType::void_t; if ((n.children[0]->m_data_type > ASTNodeDataType::double_t) or (n.children[0]->m_data_type < ASTNodeDataType::bool_t)) { @@ -186,7 +186,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) << std::ends; throw parse_error(message.str(), n.children[0]->begin()); } - } else if (n.is<language::do_while_statement>()) { + } else if (n.is_type<language::do_while_statement>()) { n.m_data_type = ASTNodeDataType::void_t; if ((n.children[1]->m_data_type > ASTNodeDataType::double_t) or (n.children[1]->m_data_type < ASTNodeDataType::bool_t)) { @@ -197,12 +197,12 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) << std::ends; throw parse_error(message.str(), n.children[1]->begin()); } - } else if (n.is<language::unary_not>() or n.is<language::lesser_op>() or n.is<language::lesser_or_eq_op>() or - n.is<language::greater_op>() or n.is<language::greater_or_eq_op>() or n.is<language::eqeq_op>() or - n.is<language::not_eq_op>() or n.is<language::and_op>() or n.is<language::or_op>() or - n.is<language::xor_op>()) { + } else if (n.is_type<language::unary_not>() or n.is_type<language::lesser_op>() or n.is_type<language::lesser_or_eq_op>() or + n.is_type<language::greater_op>() or n.is_type<language::greater_or_eq_op>() or n.is_type<language::eqeq_op>() or + n.is_type<language::not_eq_op>() or n.is_type<language::and_op>() or n.is_type<language::or_op>() or + n.is_type<language::xor_op>()) { n.m_data_type = ASTNodeDataType::bool_t; - } else if (n.is<language::unary_minus>()) { + } else if (n.is_type<language::unary_minus>()) { n.m_data_type = n.children[0]->m_data_type; if ((n.children[0]->m_data_type == ASTNodeDataType::unsigned_int_t) or (n.children[0]->m_data_type == ASTNodeDataType::bool_t)) { @@ -210,11 +210,11 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) } else { n.m_data_type = n.children[0]->m_data_type; } - } else if (n.is<language::unary_plusplus>() or n.is<language::unary_minusminus>() or - n.is<language::post_plusplus>() or n.is<language::post_minusminus>()) { + } else if (n.is_type<language::unary_plusplus>() or n.is_type<language::unary_minusminus>() or + n.is_type<language::post_plusplus>() or n.is_type<language::post_minusminus>()) { n.m_data_type = n.children[0]->m_data_type; - } else if (n.is<language::plus_op>() or n.is<language::minus_op>() or n.is<language::multiply_op>() or - n.is<language::divide_op>()) { + } else if (n.is_type<language::plus_op>() or n.is_type<language::minus_op>() or n.is_type<language::multiply_op>() or + n.is_type<language::divide_op>()) { const ASTNodeDataType type_0 = n.children[0]->m_data_type; const ASTNodeDataType type_1 = n.children[1]->m_data_type; if ((type_0 == ASTNodeDataType::bool_t) and (type_1 == ASTNodeDataType::bool_t)) { @@ -229,7 +229,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) << ") and " << n.children[1]->string() << " (" << dataTypeName(type_1) << ')' << std::ends; throw parse_error(message.str(), n.begin()); } - } else if (n.is<language::function_evaluation>()) { + } else if (n.is_type<language::function_evaluation>()) { if (n.children[0]->m_data_type == ASTNodeDataType::function_t) { const std::string& function_name = n.children[0]->string(); auto [i_function_symbol, success] = n.m_symbol_table->find(function_name, n.children[0]->begin()); @@ -248,15 +248,15 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) std::ostringstream message; throw parse_error("compound data type is not implemented yet", image_domain_node.begin()); } else { - if (image_domain_node.is<language::B_set>()) { + if (image_domain_node.is_type<language::B_set>()) { data_type = ASTNodeDataType::bool_t; - } else if (image_domain_node.is<language::Z_set>()) { + } else if (image_domain_node.is_type<language::Z_set>()) { data_type = ASTNodeDataType::int_t; - } else if (image_domain_node.is<language::N_set>()) { + } else if (image_domain_node.is_type<language::N_set>()) { data_type = ASTNodeDataType::unsigned_int_t; - } else if (image_domain_node.is<language::R_set>()) { + } else if (image_domain_node.is_type<language::R_set>()) { data_type = ASTNodeDataType::double_t; - } else if (image_domain_node.is<language::string_type>()) { + } else if (image_domain_node.is_type<language::string_type>()) { data_type = ASTNodeDataType::string_t; } } @@ -283,10 +283,10 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) << ") is not a function!" << std::ends; throw parse_error(message.str(), n.begin()); } - } else if (n.is<language::B_set>() or n.is<language::Z_set>() or n.is<language::N_set>() or - n.is<language::R_set>() or n.is<language::string_type>()) { + } else if (n.is_type<language::B_set>() or n.is_type<language::Z_set>() or n.is_type<language::N_set>() or + n.is_type<language::R_set>() or n.is_type<language::string_type>()) { n.m_data_type = ASTNodeDataType::typename_t; - } else if (n.is<language::name_list>() or n.is<language::expression_list>()) { + } else if (n.is_type<language::name_list>() or n.is_type<language::expression_list>()) { n.m_data_type = ASTNodeDataType::void_t; } } diff --git a/src/language/ASTNodeDeclarationToAffectationConverter.cpp b/src/language/ASTNodeDeclarationToAffectationConverter.cpp index bc641a01c1c4b691e3edc940d479c732c03f2ef7..42160e798627b53d818b131f8ae37943fa04bb64 100644 --- a/src/language/ASTNodeDeclarationToAffectationConverter.cpp +++ b/src/language/ASTNodeDeclarationToAffectationConverter.cpp @@ -6,12 +6,12 @@ void ASTNodeDeclarationToAffectationConverter::_convertNodeDeclaration(ASTNode& n) { - if (n.is<language::declaration>()) { + if (n.is_type<language::declaration>()) { if (n.children.size() == 3) { n.children[0] = std::move(n.children[1]); n.children[1] = std::move(n.children[2]); n.children.resize(2); - n.id = typeid(language::eq_op); + n.set_type<language::eq_op>(); } } else { for (auto& child : n.children) { diff --git a/src/language/ASTNodeEmptyBlockCleaner.cpp b/src/language/ASTNodeEmptyBlockCleaner.cpp index eeb71c0878467b45386d7c529db841a9f57bcc6b..4095555d959a1893c6ef40222370625db90aee49 100644 --- a/src/language/ASTNodeEmptyBlockCleaner.cpp +++ b/src/language/ASTNodeEmptyBlockCleaner.cpp @@ -14,7 +14,7 @@ ASTNodeEmptyBlockCleaner::_removeEmptyBlockNode(ASTNode& n) std::stack<size_t> empty_block_ids; for (size_t i_child = 0; i_child < n.children.size(); ++i_child) { - if (n.children[i_child]->is<language::block>()) { + if (n.children[i_child]->is_type<language::block>()) { if (n.children[i_child]->children.size() == 0) empty_block_ids.push(i_child); } diff --git a/src/language/ASTNodeExpressionBuilder.cpp b/src/language/ASTNodeExpressionBuilder.cpp index 66aab7283864ddb01aa1007a3279fc5c40a1f128..7cf1e8d94e7a0ec76c628af548e0660c16bfbc76 100644 --- a/src/language/ASTNodeExpressionBuilder.cpp +++ b/src/language/ASTNodeExpressionBuilder.cpp @@ -22,79 +22,79 @@ void ASTNodeExpressionBuilder::_buildExpression(ASTNode& n) { - if (n.is<language::block>()) { + if (n.is_type<language::block>()) { n.m_node_processor = std::make_unique<ASTNodeListProcessor>(n); - } else if ((n.is<language::eq_op>() or n.is<language::multiplyeq_op>() or n.is<language::divideeq_op>() or - n.is<language::pluseq_op>() or n.is<language::minuseq_op>())) { + } else if ((n.is_type<language::eq_op>() or n.is_type<language::multiplyeq_op>() or n.is_type<language::divideeq_op>() or + n.is_type<language::pluseq_op>() or n.is_type<language::minuseq_op>())) { ASTNodeAffectationExpressionBuilder{n}; - } else if (n.is<language::function_definition>()) { + } else if (n.is_type<language::function_definition>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::function_evaluation>()) { + } else if (n.is_type<language::function_evaluation>()) { ASTNodeFunctionEvaluationExpressionBuilder{n}; - } else if (n.is<language::real>()) { + } else if (n.is_type<language::real>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::integer>()) { + } else if (n.is_type<language::integer>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::literal>()) { + } else if (n.is_type<language::literal>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::true_kw>()) { + } else if (n.is_type<language::true_kw>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::false_kw>()) { + } else if (n.is_type<language::false_kw>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::expression_list>()) { + } else if (n.is_type<language::expression_list>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::name_list>()) { + } else if (n.is_type<language::name_list>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::name>()) { + } else if (n.is_type<language::name>()) { n.m_node_processor = std::make_unique<NameProcessor>(n); - } else if (n.is<language::unary_minus>() or n.is<language::unary_not>()) { + } else if (n.is_type<language::unary_minus>() or n.is_type<language::unary_not>()) { ASTNodeUnaryOperatorExpressionBuilder{n}; - } else if (n.is<language::unary_minusminus>() or n.is<language::unary_plusplus>() or - n.is<language::post_minusminus>() or n.is<language::post_plusplus>()) { + } else if (n.is_type<language::unary_minusminus>() or n.is_type<language::unary_plusplus>() or + n.is_type<language::post_minusminus>() or n.is_type<language::post_plusplus>()) { ASTNodeIncDecExpressionBuilder{n}; - } else if (n.is<language::multiply_op>() or n.is<language::divide_op>() or n.is<language::plus_op>() or - n.is<language::minus_op>() or n.is<language::or_op>() or n.is<language::and_op>() or - n.is<language::xor_op>() or n.is<language::greater_op>() or n.is<language::greater_or_eq_op>() or - n.is<language::lesser_op>() or n.is<language::lesser_or_eq_op>() or n.is<language::eqeq_op>() or - n.is<language::not_eq_op>()) { + } else if (n.is_type<language::multiply_op>() or n.is_type<language::divide_op>() or n.is_type<language::plus_op>() or + n.is_type<language::minus_op>() or n.is_type<language::or_op>() or n.is_type<language::and_op>() or + n.is_type<language::xor_op>() or n.is_type<language::greater_op>() or n.is_type<language::greater_or_eq_op>() or + n.is_type<language::lesser_op>() or n.is_type<language::lesser_or_eq_op>() or n.is_type<language::eqeq_op>() or + n.is_type<language::not_eq_op>()) { ASTNodeBinaryOperatorExpressionBuilder{n}; - } else if (n.is<language::cout_kw>()) { + } else if (n.is_type<language::cout_kw>()) { n.m_node_processor = std::make_unique<OStreamProcessor>(n, std::cout); - } else if (n.is<language::cerr_kw>()) { + } else if (n.is_type<language::cerr_kw>()) { n.m_node_processor = std::make_unique<OStreamProcessor>(n, std::cerr); - } else if (n.is<language::clog_kw>()) { + } else if (n.is_type<language::clog_kw>()) { n.m_node_processor = std::make_unique<OStreamProcessor>(n, std::clog); - } else if (n.is<language::if_statement>()) { + } else if (n.is_type<language::if_statement>()) { n.m_node_processor = std::make_unique<IfProcessor>(n); - } else if (n.is<language::statement_block>()) { + } else if (n.is_type<language::statement_block>()) { n.m_node_processor = std::make_unique<ASTNodeListProcessor>(n); - } else if (n.is<language::do_while_statement>()) { + } else if (n.is_type<language::do_while_statement>()) { n.m_node_processor = std::make_unique<DoWhileProcessor>(n); - } else if (n.is<language::while_statement>()) { + } else if (n.is_type<language::while_statement>()) { n.m_node_processor = std::make_unique<WhileProcessor>(n); - } else if (n.is<language::for_statement>()) { + } else if (n.is_type<language::for_statement>()) { n.m_node_processor = std::make_unique<ForProcessor>(n); - } else if (n.is<language::for_statement_block>()) { + } else if (n.is_type<language::for_statement_block>()) { n.m_node_processor = std::make_unique<ASTNodeListProcessor>(n); - } else if (n.is<language::for_init>()) { + } else if (n.is_type<language::for_init>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::for_post>()) { + } else if (n.is_type<language::for_post>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::for_test>()) { + } else if (n.is_type<language::for_test>()) { n.m_node_processor = std::make_unique<FakeProcessor>(); - } else if (n.is<language::break_kw>()) { + } else if (n.is_type<language::break_kw>()) { n.m_node_processor = std::make_unique<BreakProcessor>(); - } else if (n.is<language::continue_kw>()) { + } else if (n.is_type<language::continue_kw>()) { n.m_node_processor = std::make_unique<ContinueProcessor>(); } else { std::ostringstream error_message; diff --git a/src/language/ASTNodeFunctionExpressionBuilder.cpp b/src/language/ASTNodeFunctionExpressionBuilder.cpp index 9cf9b18fd4d176767f08f486900ef1fc720996ae..13606cafa36447d465d35ef45561e76cc9f9ce2a 100644 --- a/src/language/ASTNodeFunctionExpressionBuilder.cpp +++ b/src/language/ASTNodeFunctionExpressionBuilder.cpp @@ -61,7 +61,7 @@ ASTNodeFunctionExpressionBuilder::_storeArgumentProcessor(ASTNode& parameter_var ASTNode& argument_node, FunctionProcessor& function_processor) { - Assert(parameter_variable.is<language::name>(), "unexpected parameter type!"); + Assert(parameter_variable.is_type<language::name>(), "unexpected parameter type!"); auto [i_parameter_symbol, found] = parameter_variable.m_symbol_table->find(parameter_variable.string(), parameter_variable.begin()); @@ -81,9 +81,9 @@ ASTNodeFunctionExpressionBuilder::_buildArgumentProcessors(FunctionDescriptor& f ASTNode& argument_nodes = *node.children[1]; - const size_t arguments_number = argument_nodes.is<language::expression_list>() ? argument_nodes.children.size() : 1; + const size_t arguments_number = argument_nodes.is_type<language::expression_list>() ? argument_nodes.children.size() : 1; const size_t parameters_number = - parameter_variables.is<language::name_list>() ? parameter_variables.children.size() : 1; + parameter_variables.is_type<language::name_list>() ? parameter_variables.children.size() : 1; if (arguments_number != parameters_number) { std::ostringstream error_message; @@ -164,7 +164,7 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node FunctionDescriptor& function_descriptor = node.m_symbol_table->functionTable()[function_id]; - if (function_descriptor.definitionNode().children[1]->is<language::expression_list>()) { + if (function_descriptor.definitionNode().children[1]->is_type<language::expression_list>()) { throw parse_error("unexpected error: function expression list is not implemented yet", std::vector{function_descriptor.definitionNode().children[1]->begin()}); } diff --git a/src/language/ASTNodeIncDecExpressionBuilder.cpp b/src/language/ASTNodeIncDecExpressionBuilder.cpp index a76765edbc59d2335d031021050baa0f4e191bdb..91ed39a72dc96a7efe38ffaa7f0b390c3ee64d24 100644 --- a/src/language/ASTNodeIncDecExpressionBuilder.cpp +++ b/src/language/ASTNodeIncDecExpressionBuilder.cpp @@ -27,9 +27,9 @@ ASTNodeIncDecExpressionBuilder::ASTNodeIncDecExpressionBuilder(ASTNode& n) } }; - if (not n.children[0]->is<language::name>()) { - if (n.children[0]->is<language::post_minusminus>() or n.children[0]->is<language::post_plusplus>() or - n.children[0]->is<language::unary_minusminus>() or n.children[0]->is<language::unary_plusplus>()) { + if (not n.children[0]->is_type<language::name>()) { + if (n.children[0]->is_type<language::post_minusminus>() or n.children[0]->is_type<language::post_plusplus>() or + n.children[0]->is_type<language::unary_minusminus>() or n.children[0]->is_type<language::unary_plusplus>()) { throw parse_error("chaining ++ or -- operators is not allowed", std::vector{n.children[0]->begin()}); } else { throw parse_error("invalid operand type for unary operator", std::vector{n.children[0]->begin()}); @@ -39,13 +39,13 @@ ASTNodeIncDecExpressionBuilder::ASTNodeIncDecExpressionBuilder(ASTNode& n) set_inc_dec_processor_for_value(n.m_data_type); }; - if (n.is<language::unary_minusminus>()) { + if (n.is_type<language::unary_minusminus>()) { set_inc_dec_operator_processor(n, language::unary_minusminus{}); - } else if (n.is<language::unary_plusplus>()) { + } else if (n.is_type<language::unary_plusplus>()) { set_inc_dec_operator_processor(n, language::unary_plusplus{}); - } else if (n.is<language::post_minusminus>()) { + } else if (n.is_type<language::post_minusminus>()) { set_inc_dec_operator_processor(n, language::post_minusminus{}); - } else if (n.is<language::post_plusplus>()) { + } else if (n.is_type<language::post_plusplus>()) { set_inc_dec_operator_processor(n, language::post_plusplus{}); } else { throw parse_error("unexpected error: undefined increment/decrement operator", std::vector{n.begin()}); diff --git a/src/language/ASTNodeJumpPlacementChecker.cpp b/src/language/ASTNodeJumpPlacementChecker.cpp index ef1610ec702d06229612f1f7af1eb4cce6a4c29d..f3b5bacae844aaa324f110e1f77f809ce8d1b335 100644 --- a/src/language/ASTNodeJumpPlacementChecker.cpp +++ b/src/language/ASTNodeJumpPlacementChecker.cpp @@ -7,11 +7,11 @@ void ASTNodeJumpPlacementChecker::_checkJumpPlacement(ASTNode& n, bool is_inside_loop) { - if (n.is<language::for_statement>() or n.is<language::do_while_statement>() or n.is<language::while_statement>()) { + if (n.is_type<language::for_statement>() or n.is_type<language::do_while_statement>() or n.is_type<language::while_statement>()) { for (auto& child : n.children) { this->_checkJumpPlacement(*child, true); } - } else if (n.is<language::break_kw>() or n.is<language::continue_kw>()) { + } else if (n.is_type<language::break_kw>() or n.is_type<language::continue_kw>()) { if (not is_inside_loop) { std::ostringstream error_message; error_message << "unexpected '" << rang::fgB::red << n.string() << rang::fg::reset diff --git a/src/language/ASTNodeTypeCleaner.hpp b/src/language/ASTNodeTypeCleaner.hpp index 8521baa2fe3b89c121fcce9a680e623483b7b7b5..7c96b865c2b427437786cde6439e96d9be69df7f 100644 --- a/src/language/ASTNodeTypeCleaner.hpp +++ b/src/language/ASTNodeTypeCleaner.hpp @@ -16,7 +16,7 @@ class ASTNodeTypeCleaner { std::stack<size_t> declaration_ids; for (size_t i_child = 0; i_child < node.children.size(); ++i_child) { - if (node.children[i_child]->is<NodeType>()) { + if (node.children[i_child]->is_type<NodeType>()) { declaration_ids.push(i_child); } } diff --git a/src/language/ASTNodeUnaryOperatorExpressionBuilder.cpp b/src/language/ASTNodeUnaryOperatorExpressionBuilder.cpp index 66a3687d707cb750cb919893ebbd82f145324b17..9db54a77863e73283e83155c98d2ab1209e50722 100644 --- a/src/language/ASTNodeUnaryOperatorExpressionBuilder.cpp +++ b/src/language/ASTNodeUnaryOperatorExpressionBuilder.cpp @@ -57,9 +57,9 @@ ASTNodeUnaryOperatorExpressionBuilder::ASTNodeUnaryOperatorExpressionBuilder(AST set_unary_operator_processor_for_value(n.m_data_type); }; - if (n.is<language::unary_minus>()) { + if (n.is_type<language::unary_minus>()) { set_unary_operator_processor(n, language::unary_minus{}); - } else if (n.is<language::unary_not>()) { + } else if (n.is_type<language::unary_not>()) { set_unary_operator_processor(n, language::unary_not{}); } else { throw parse_error("unexpected error: undefined unary operator", std::vector{n.begin()}); diff --git a/src/language/ASTNodeValueBuilder.cpp b/src/language/ASTNodeValueBuilder.cpp index 4e9c0d445a687f9b10b0b667775139bfb3bbb13b..65d01496007ecc7875244a57e0c9bf61492d32bf 100644 --- a/src/language/ASTNodeValueBuilder.cpp +++ b/src/language/ASTNodeValueBuilder.cpp @@ -11,7 +11,7 @@ void ASTNodeValueBuilder::_buildNodeValue(ASTNode& n) { - if (n.is<language::block>()) { + if (n.is_type<language::block>()) { if (!n.children.empty()) { for (auto& child : n.children) { this->_buildNodeValue(*child); @@ -24,25 +24,25 @@ ASTNodeValueBuilder::_buildNodeValue(ASTNode& n) } if (n.has_content()) { - if (n.is<language::real>()) { + if (n.is_type<language::real>()) { std::stringstream ss(n.string()); double v; ss >> v; n.m_value = v; - } else if (n.is<language::integer>()) { + } else if (n.is_type<language::integer>()) { std::stringstream ss(n.string()); int64_t v; ss >> v; n.m_value = v; - } else if (n.is<language::literal>()) { + } else if (n.is_type<language::literal>()) { n.m_value = unescapeString(n.string()); - } else if (n.is<language::for_test>()) { + } else if (n.is_type<language::for_test>()) { // if AST contains a for_test statement, it means that no test were // given to the for-loop, so its value is always true n.m_value = true; - } else if (n.is<language::true_kw>()) { + } else if (n.is_type<language::true_kw>()) { n.m_value = true; - } else if (n.is<language::false_kw>()) { + } else if (n.is_type<language::false_kw>()) { n.m_value = false; } } diff --git a/src/language/ASTPrinter.cpp b/src/language/ASTPrinter.cpp index 0083dcb5ef0a5bd6f42e2de7e2d8f950e42d3366..6c609e214d4523a38b0922f0dd465db95853b4fe 100644 --- a/src/language/ASTPrinter.cpp +++ b/src/language/ASTPrinter.cpp @@ -14,8 +14,8 @@ ASTPrinter::_print(std::ostream& os, const ASTNode& node) const } os << rang::fg::reset; - if (node.is<language::name>() or node.is<language::literal>() or node.is<language::integer>() or - node.is<language::real>()) { + if (node.is_type<language::name>() or node.is_type<language::literal>() or node.is_type<language::integer>() or + node.is_type<language::real>()) { os << ':' << rang::fgB::green << node.string() << rang::fg::reset; } diff --git a/src/language/ASTSymbolInitializationChecker.cpp b/src/language/ASTSymbolInitializationChecker.cpp index b25286f28648548e2817a6640ec2e01f44b0103d..5e8139a3e99e16cd72b99233781aa7749e754621 100644 --- a/src/language/ASTSymbolInitializationChecker.cpp +++ b/src/language/ASTSymbolInitializationChecker.cpp @@ -7,7 +7,7 @@ void ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) { - if (node.is<language::declaration>()) { + if (node.is_type<language::declaration>()) { const std::string& symbol = node.children[1]->string(); auto [i_symbol, found] = node.m_symbol_table->find(symbol, node.children[1]->begin()); Assert(found, "unexpected error, should have been detected through declaration checking"); @@ -15,7 +15,7 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) this->_checkSymbolInitialization(*node.children[2]); i_symbol->attributes().setIsInitialized(); } - } else if (node.is<language::let_declaration>()) { + } else if (node.is_type<language::let_declaration>()) { const std::string& symbol = node.children[0]->string(); auto [i_symbol, found] = node.m_symbol_table->find(symbol, node.children[0]->begin()); Assert(found, "unexpected error, should have been detected through declaration checking"); @@ -28,9 +28,9 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) auto& function_descriptor = function_table[function_id]; this->_checkSymbolInitialization(function_descriptor.definitionNode()); - } else if (node.is<language::function_definition>()) { + } else if (node.is_type<language::function_definition>()) { this->_checkSymbolInitialization(*node.children[1]); - } else if (node.is<language::eq_op>()) { + } else if (node.is_type<language::eq_op>()) { // first checks for right hand side this->_checkSymbolInitialization(*node.children[1]); // then marks left hand side as initialized @@ -38,7 +38,7 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) auto [i_symbol, found] = node.m_symbol_table->find(symbol, node.children[0]->begin()); Assert(found, "unexpected error, should have been detected through declaration checking"); i_symbol->attributes().setIsInitialized(); - } else if (node.is<language::name>()) { + } else if (node.is_type<language::name>()) { auto [i_symbol, found] = node.m_symbol_table->find(node.string(), node.begin()); Assert(found, "unexpected error, should have been detected through declaration checking"); if (not i_symbol->attributes().isInitialized()) { @@ -48,7 +48,7 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) } } - if (not(node.is<language::declaration>() or node.is<language::let_declaration>() or node.is<language::eq_op>())) { + if (not(node.is_type<language::declaration>() or node.is_type<language::let_declaration>() or node.is_type<language::eq_op>())) { for (auto& child : node.children) { this->_checkSymbolInitialization(*child); } diff --git a/src/language/ASTSymbolTableBuilder.cpp b/src/language/ASTSymbolTableBuilder.cpp index 67fb348c2561049cea11c6dd2bcffa2a23f78eb4..ac3b7a6c00881684bb6624a8d8e002a26c5d58be 100644 --- a/src/language/ASTSymbolTableBuilder.cpp +++ b/src/language/ASTSymbolTableBuilder.cpp @@ -6,7 +6,7 @@ void ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable>& symbol_table) { - if (n.is<language::block>() or (n.is<language::for_statement>())) { + if (n.is_type<language::block>() or (n.is_type<language::for_statement>())) { if (!n.children.empty()) { std::shared_ptr block_symbol_table = std::make_shared<SymbolTable>(symbol_table); n.m_symbol_table = block_symbol_table; @@ -15,7 +15,7 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable> this->buildSymbolTable(*child, block_symbol_table); } } - } else if (n.is<language::let_declaration>()) { + } else if (n.is_type<language::let_declaration>()) { std::shared_ptr local_symbol_table = std::make_shared<SymbolTable>(symbol_table); n.m_symbol_table = local_symbol_table; const std::string& symbol = n.children[0]->string(); @@ -37,7 +37,7 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable> } else { n.m_symbol_table = symbol_table; if (n.has_content()) { - if (n.is<language::declaration>()) { + if (n.is_type<language::declaration>()) { const std::string& symbol = n.children[1]->string(); auto [i_symbol, success] = symbol_table->add(symbol, n.children[1]->begin()); if (not success) { @@ -45,7 +45,7 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable> error_message << "symbol '" << rang::fg::red << symbol << rang::fg::reset << "' was already defined!"; throw parse_error(error_message.str(), std::vector{n.begin()}); } - } else if (n.is<language::function_definition>()) { + } else if (n.is_type<language::function_definition>()) { auto register_symbol = [&](const std::string& symbol) { auto [i_symbol, success] = symbol_table->add(symbol, n.children[0]->begin()); if (not success) { @@ -57,15 +57,15 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable> i_symbol->attributes().setIsInitialized(); }; - if (n.children[0]->is<language::name>()) { + if (n.children[0]->is_type<language::name>()) { register_symbol(n.children[0]->string()); } else { // treats the case of list of parameters - Assert(n.children[0]->is<language::name_list>()); + Assert(n.children[0]->is_type<language::name_list>()); for (auto& child : n.children[0]->children) { register_symbol(child->string()); } } - } else if (n.is<language::name>()) { + } else if (n.is_type<language::name>()) { auto [i_symbol, found] = symbol_table->find(n.string(), n.begin()); if (not found) { std::ostringstream error_message; diff --git a/src/language/PEGGrammar.hpp b/src/language/PEGGrammar.hpp index ca55f2de79bfccdb8621644720a47869d90bdbb7..bac0eb913f101c2b0f55c9aaa37582b9a5e03100 100644 --- a/src/language/PEGGrammar.hpp +++ b/src/language/PEGGrammar.hpp @@ -299,7 +299,7 @@ struct errors : public normal<Rule> }; template <typename Rule> -inline const std::string errors<Rule>::error_message = "parse error matching "+ internal::demangle< Rule >(); +inline const std::string errors<Rule>::error_message = "parse error matching "+ std::string{internal::demangle< Rule >()}; template <> inline const std::string errors<language::module_name>::error_message = "parse error, missing module name"; diff --git a/src/language/node_processor/IncDecExpressionProcessor.hpp b/src/language/node_processor/IncDecExpressionProcessor.hpp index 961adbddcc8e5dd4fff525a2e28c1f4fdea3334d..7eccb590e9122ebf71f490cd61f2e537cccf620a 100644 --- a/src/language/node_processor/IncDecExpressionProcessor.hpp +++ b/src/language/node_processor/IncDecExpressionProcessor.hpp @@ -68,7 +68,7 @@ class IncDecExpressionProcessor final : public INodeProcessor IncDecExpressionProcessor(ASTNode& node) : m_node{node} { - Assert(m_node.children[0]->is<language::name>()); + Assert(m_node.children[0]->is_type<language::name>()); // It is sure at this point that children 0 is a variable name const std::string& symbol = m_node.children[0]->string(); auto [i_symbol, found] = m_node.m_symbol_table->find(symbol, m_node.children[0]->begin()); diff --git a/tests/test_ASTNodeAffectationExpressionBuilder.cpp b/tests/test_ASTNodeAffectationExpressionBuilder.cpp index ea531b67a2c19cf19acac3f311553a75283fe7ce..9758fbbb1ae387a50f62a1ff6c48a7f2de74afb4 100644 --- a/tests/test_ASTNodeAffectationExpressionBuilder.cpp +++ b/tests/test_ASTNodeAffectationExpressionBuilder.cpp @@ -721,7 +721,7 @@ string s="foo"; s/="bar"; SECTION("Invalid lhs") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::eq_op); + ast->set_type<language::eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); REQUIRE_THROWS_WITH(ASTNodeAffectationExpressionBuilder{*ast}, @@ -730,8 +730,8 @@ string s="foo"; s/="bar"; SECTION("Invalid rhs") { - auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::eq_op); + auto ast = std::make_unique<ASTNode>(); + ast->set_type<language::eq_op>(); ast->m_data_type = ASTNodeDataType::int_t; ast->children.emplace_back(std::make_unique<ASTNode>()); @@ -742,8 +742,8 @@ string s="foo"; s/="bar"; SECTION("Invalid string rhs") { - auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::eq_op); + auto ast = std::make_unique<ASTNode>(); + ast->set_type<language::eq_op>(); ast->m_data_type = ASTNodeDataType::string_t; ast->children.emplace_back(std::make_unique<ASTNode>()); diff --git a/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp b/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp index 0aa28cbe68bc1c6950ad86a48da2974739c5ca90..1bff3eb40a8deea19c13160c68556a7687637dbe 100644 --- a/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp +++ b/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp @@ -1212,7 +1212,7 @@ a != 3; SECTION("lhs bad multiply") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::multiply_op); + ast->set_type<language::multiply_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1224,7 +1224,7 @@ a != 3; SECTION("left string multiply") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::multiply_op); + ast->set_type<language::multiply_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1236,7 +1236,7 @@ a != 3; SECTION("right string multiply") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::multiply_op); + ast->set_type<language::multiply_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1248,7 +1248,7 @@ a != 3; SECTION("lhs bad divide") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::divide_op); + ast->set_type<language::divide_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1260,7 +1260,7 @@ a != 3; SECTION("left string divide") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::divide_op); + ast->set_type<language::divide_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1272,7 +1272,7 @@ a != 3; SECTION("right string divide") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::divide_op); + ast->set_type<language::divide_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1284,7 +1284,7 @@ a != 3; SECTION("lhs bad plus") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::plus_op); + ast->set_type<language::plus_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1296,7 +1296,7 @@ a != 3; SECTION("left string plus bad rhs") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::plus_op); + ast->set_type<language::plus_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1308,7 +1308,7 @@ a != 3; SECTION("right string plus") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::plus_op); + ast->set_type<language::plus_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1320,7 +1320,7 @@ a != 3; SECTION("lhs bad minus") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::minus_op); + ast->set_type<language::minus_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1332,7 +1332,7 @@ a != 3; SECTION("left string minus") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::minus_op); + ast->set_type<language::minus_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1344,7 +1344,7 @@ a != 3; SECTION("right string minus") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::minus_op); + ast->set_type<language::minus_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1356,7 +1356,7 @@ a != 3; SECTION("lhs bad or") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::or_op); + ast->set_type<language::or_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1368,7 +1368,7 @@ a != 3; SECTION("left string or") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::or_op); + ast->set_type<language::or_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1380,7 +1380,7 @@ a != 3; SECTION("right string or") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::or_op); + ast->set_type<language::or_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1392,7 +1392,7 @@ a != 3; SECTION("lhs bad and") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::and_op); + ast->set_type<language::and_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1404,7 +1404,7 @@ a != 3; SECTION("left string and") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::and_op); + ast->set_type<language::and_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1416,7 +1416,7 @@ a != 3; SECTION("right string and") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::and_op); + ast->set_type<language::and_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1428,7 +1428,7 @@ a != 3; SECTION("lhs bad xor") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::xor_op); + ast->set_type<language::xor_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1440,7 +1440,7 @@ a != 3; SECTION("left string xor") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::xor_op); + ast->set_type<language::xor_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1452,7 +1452,7 @@ a != 3; SECTION("right string xor") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::xor_op); + ast->set_type<language::xor_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1464,7 +1464,7 @@ a != 3; SECTION("lhs bad >") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::greater_op); + ast->set_type<language::greater_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1476,7 +1476,7 @@ a != 3; SECTION("left string >") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::greater_op); + ast->set_type<language::greater_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1488,7 +1488,7 @@ a != 3; SECTION("right string >") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::greater_op); + ast->set_type<language::greater_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1500,7 +1500,7 @@ a != 3; SECTION("lhs bad <") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::lesser_op); + ast->set_type<language::lesser_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1512,7 +1512,7 @@ a != 3; SECTION("left string <") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::lesser_op); + ast->set_type<language::lesser_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1524,7 +1524,7 @@ a != 3; SECTION("right string <") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::lesser_op); + ast->set_type<language::lesser_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1536,7 +1536,7 @@ a != 3; SECTION("lhs bad >=") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::greater_or_eq_op); + ast->set_type<language::greater_or_eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1548,7 +1548,7 @@ a != 3; SECTION("left string >=") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::greater_or_eq_op); + ast->set_type<language::greater_or_eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1560,7 +1560,7 @@ a != 3; SECTION("right string >=") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::greater_or_eq_op); + ast->set_type<language::greater_or_eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1572,7 +1572,7 @@ a != 3; SECTION("lhs bad <=") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::lesser_or_eq_op); + ast->set_type<language::lesser_or_eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1584,7 +1584,7 @@ a != 3; SECTION("left string <=") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::lesser_or_eq_op); + ast->set_type<language::lesser_or_eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1596,7 +1596,7 @@ a != 3; SECTION("right string <=") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::lesser_or_eq_op); + ast->set_type<language::lesser_or_eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1608,7 +1608,7 @@ a != 3; SECTION("lhs bad ==") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::eqeq_op); + ast->set_type<language::eqeq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1620,7 +1620,7 @@ a != 3; SECTION("left string ==") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::eqeq_op); + ast->set_type<language::eqeq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1632,7 +1632,7 @@ a != 3; SECTION("right string ==") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::eqeq_op); + ast->set_type<language::eqeq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; @@ -1644,7 +1644,7 @@ a != 3; SECTION("lhs bad !=") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::not_eq_op); + ast->set_type<language::not_eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::void_t; @@ -1656,7 +1656,7 @@ a != 3; SECTION("left string ==") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::not_eq_op); + ast->set_type<language::not_eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::string_t; @@ -1668,7 +1668,7 @@ a != 3; SECTION("right string ==") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::not_eq_op); + ast->set_type<language::not_eq_op>(); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children.emplace_back(std::make_unique<ASTNode>()); ast->children[0]->m_data_type = ASTNodeDataType::int_t; diff --git a/tests/test_ASTNodeExpressionBuilder.cpp b/tests/test_ASTNodeExpressionBuilder.cpp index 017f3f39779cbe504e770ea0b64b393c72dde3a9..fbadc0d1ebeb731d7c8de2af772964a751099d7a 100644 --- a/tests/test_ASTNodeExpressionBuilder.cpp +++ b/tests/test_ASTNodeExpressionBuilder.cpp @@ -859,7 +859,7 @@ continue; // One is sure that language::ignored is not treated so its a good candidate // for this test - ast->children[0]->id = typeid(language::ignored); + ast->children[0]->set_type<language::ignored>(); REQUIRE_THROWS_AS(ASTNodeExpressionBuilder{*ast}, parse_error); } } diff --git a/tests/test_ASTNodeIncDecExpressionBuilder.cpp b/tests/test_ASTNodeIncDecExpressionBuilder.cpp index 2a05900e8db3c832a5e9aee2659a29997c00e725..b3a2971c7a767631244c274d081b778776d6900f 100644 --- a/tests/test_ASTNodeIncDecExpressionBuilder.cpp +++ b/tests/test_ASTNodeIncDecExpressionBuilder.cpp @@ -316,8 +316,8 @@ x--; SECTION("Invalid operand type") { - auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::unary_plusplus); + auto ast = std::make_unique<ASTNode>(); + ast->set_type<language::unary_plusplus>(); ast->m_data_type = ASTNodeDataType::undefined_t; ast->children.emplace_back(std::make_unique<ASTNode>()); @@ -328,10 +328,10 @@ x--; SECTION("Invalid data type") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::unary_plusplus); + ast->set_type<language::unary_plusplus>(); ast->children.emplace_back(std::make_unique<ASTNode>()); - ast->children[0]->id = typeid(language::name); + ast->children[0]->set_type<language::name>(); REQUIRE_THROWS_WITH(ASTNodeIncDecExpressionBuilder{*ast}, "unexpected error: undefined data type for unary operator"); diff --git a/tests/test_ASTNodeListProcessor.cpp b/tests/test_ASTNodeListProcessor.cpp index ed0748188e22a12ecadc0459491888a358e70f80..49bc6fe34bd3b1b68c2294a4b4aa0b54a9923910 100644 --- a/tests/test_ASTNodeListProcessor.cpp +++ b/tests/test_ASTNodeListProcessor.cpp @@ -42,9 +42,9 @@ true; ExecUntilBreakOrContinue exec_policy; ast->execute(exec_policy); - REQUIRE(ast->children[0]->id == typeid(language::integer)); - REQUIRE(ast->children[1]->id == typeid(language::true_kw)); - REQUIRE(ast->children[2]->id == typeid(language::real)); + REQUIRE(ast->children[0]->is_type<language::integer>()); + REQUIRE(ast->children[1]->is_type<language::true_kw>()); + REQUIRE(ast->children[2]->is_type<language::real>()); REQUIRE(ast->m_node_processor->typeIdName() == demangle<ASTNodeListProcessor>()); } diff --git a/tests/test_ASTNodeUnaryOperatorExpressionBuilder.cpp b/tests/test_ASTNodeUnaryOperatorExpressionBuilder.cpp index 5ea6a3461391a5dcec9ff433fda664dba241c461..402b9f417f5d839a70f74420c84bdfbec73067ab 100644 --- a/tests/test_ASTNodeUnaryOperatorExpressionBuilder.cpp +++ b/tests/test_ASTNodeUnaryOperatorExpressionBuilder.cpp @@ -203,7 +203,7 @@ not 3.5; SECTION("Invalid value type for unary minus") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::unary_minus); + ast->set_type<language::unary_minus>(); ast->children.emplace_back(std::make_unique<ASTNode>()); REQUIRE_THROWS_WITH(ASTNodeUnaryOperatorExpressionBuilder{*ast}, "undefined value type for unary operator"); @@ -212,7 +212,7 @@ not 3.5; SECTION("Invalid value type for unary not") { auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::unary_not); + ast->set_type<language::unary_not>(); ast->children.emplace_back(std::make_unique<ASTNode>()); REQUIRE_THROWS_WITH(ASTNodeUnaryOperatorExpressionBuilder{*ast}, "undefined value type for unary operator"); @@ -220,8 +220,8 @@ not 3.5; SECTION("Invalid data type for unary operator") { - auto ast = std::make_unique<ASTNode>(); - ast->id = typeid(language::unary_minus); + auto ast = std::make_unique<ASTNode>(); + ast->set_type<language::unary_minus>(); ast->m_data_type = ASTNodeDataType::int_t; ast->children.emplace_back(std::make_unique<ASTNode>()); diff --git a/tests/test_OStreamProcessor.cpp b/tests/test_OStreamProcessor.cpp index 1f135831298c7311da18681dca6f568eb9688672..e217fa107faa3152ec39128fe947a7d10bf52edc 100644 --- a/tests/test_OStreamProcessor.cpp +++ b/tests/test_OStreamProcessor.cpp @@ -27,7 +27,7 @@ void _replaceOStream(ASTNode& node, std::ostringstream& sout) { - if (node.is<language::cout_kw>() or node.is<language::cerr_kw>()) { + if (node.is_type<language::cout_kw>() or node.is_type<language::cerr_kw>()) { node.m_node_processor = std::make_unique<OStreamProcessor>(node, sout); } else { for (auto& child_node : node.children) {