After realizing how the lexer code generation works, I went back and made my changes to json.hpp.re2c as I should have.

Tests back to green, with no direct edits to json.hpp
This commit is contained in:
Cameron T. Druyor 2016-04-29 20:44:51 -04:00
parent faa5a4d0f8
commit 8468750409
3 changed files with 586 additions and 821 deletions

306
Makefile
View File

@ -1,98 +1,226 @@
.PHONY: pretty clean ChangeLog.md # CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.5
# used programs # Default target executed when no arguments are given to make.
RE2C = re2c default_target: all
SED = sed
# main target .PHONY : default_target
all: json_unit
# clean up # Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.1/bin/cmake
# The command to remove a file.
RM = /usr/local/Cellar/cmake/3.5.1/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /Users/cameron/Projects/json
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /Users/cameron/Projects/json
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/local/Cellar/cmake/3.5.1/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# Special rule for the target list_install_components
list_install_components:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
.PHONY : list_install_components
# Special rule for the target list_install_components
list_install_components/fast: list_install_components
.PHONY : list_install_components/fast
# Special rule for the target install
install: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
/usr/local/Cellar/cmake/3.5.1/bin/cmake -P cmake_install.cmake
.PHONY : install
# Special rule for the target install
install/fast: preinstall/fast
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
/usr/local/Cellar/cmake/3.5.1/bin/cmake -P cmake_install.cmake
.PHONY : install/fast
# Special rule for the target install/strip
install/strip: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
/usr/local/Cellar/cmake/3.5.1/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
.PHONY : install/strip
# Special rule for the target install/strip
install/strip/fast: install/strip
.PHONY : install/strip/fast
# Special rule for the target install/local
install/local: preinstall
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
/usr/local/Cellar/cmake/3.5.1/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
.PHONY : install/local
# Special rule for the target install/local
install/local/fast: install/local
.PHONY : install/local/fast
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/local/Cellar/cmake/3.5.1/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /Users/cameron/Projects/json/CMakeFiles /Users/cameron/Projects/json/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /Users/cameron/Projects/json/CMakeFiles 0
.PHONY : all
# The main clean target
clean: clean:
rm -fr json_unit json_benchmarks fuzz fuzz-testing *.dSYM $(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
# clear depends
depend:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
#=============================================================================
# Target rules for targets named json_unit
# Build rule for target.
json_unit: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 json_unit
.PHONY : json_unit
# fast build rule for target.
json_unit/fast:
$(MAKE) -f CMakeFiles/json_unit.dir/build.make CMakeFiles/json_unit.dir/build
.PHONY : json_unit/fast
test/unit.o: test/unit.cpp.o
.PHONY : test/unit.o
# target to build an object file
test/unit.cpp.o:
$(MAKE) -f CMakeFiles/json_unit.dir/build.make CMakeFiles/json_unit.dir/test/unit.cpp.o
.PHONY : test/unit.cpp.o
test/unit.i: test/unit.cpp.i
.PHONY : test/unit.i
# target to preprocess a source file
test/unit.cpp.i:
$(MAKE) -f CMakeFiles/json_unit.dir/build.make CMakeFiles/json_unit.dir/test/unit.cpp.i
.PHONY : test/unit.cpp.i
test/unit.s: test/unit.cpp.s
.PHONY : test/unit.s
# target to generate assembly for a file
test/unit.cpp.s:
$(MAKE) -f CMakeFiles/json_unit.dir/build.make CMakeFiles/json_unit.dir/test/unit.cpp.s
.PHONY : test/unit.cpp.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... rebuild_cache"
@echo "... list_install_components"
@echo "... install"
@echo "... install/strip"
@echo "... install/local"
@echo "... edit_cache"
@echo "... json_unit"
@echo "... test/unit.o"
@echo "... test/unit.i"
@echo "... test/unit.s"
.PHONY : help
##########################################################################
# unit tests
##########################################################################
# additional flags #=============================================================================
FLAGS = -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder -Wdeprecated -Wfloat-equal # Special targets to cleanup operation of make.
# build unit tests # Special rule to run CMake to check the build system integrity.
json_unit: test/unit.cpp src/json.hpp test/catch.hpp # No rule that depends on this can have commands that come from listfiles
$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src -I test $< $(LDFLAGS) -o $@ # because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system
##########################################################################
# documentation tests
##########################################################################
# compile example files and check output
doctest:
make check_output -C doc
##########################################################################
# fuzzing
##########################################################################
# the overall fuzz testing target
fuzz_testing:
rm -fr fuzz-testing
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
$(MAKE) fuzz CXX=afl-clang++
mv fuzz fuzz-testing
find test/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzz"
# the fuzzer binary
fuzz: test/fuzz.cpp src/json.hpp
$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src $< $(LDFLAGS) -o $@
##########################################################################
# static analyzer
##########################################################################
# call cppcheck on the main header file
cppcheck:
cppcheck --enable=all --inconclusive --std=c++11 src/json.hpp
##########################################################################
# maintainer targets
##########################################################################
# create scanner with re2c
re2c: src/json.hpp.re2c
$(RE2C) --bit-vectors --nested-ifs --no-debug-info $< | $(SED) '1d' > src/json.hpp
# pretty printer
pretty:
astyle --style=allman --indent=spaces=4 --indent-modifiers \
--indent-switches --indent-preproc-block --indent-preproc-define \
--indent-col1-comments --pad-oper --pad-header --align-pointer=type \
--align-reference=type --add-brackets --convert-tabs --close-templates \
--lineend=linux --preserve-date --suffix=none --formatted \
src/json.hpp src/json.hpp.re2c test/unit.cpp test/fuzz.cpp benchmarks/benchmarks.cpp doc/examples/*.cpp
##########################################################################
# benchmarks
##########################################################################
# benchmarks
json_benchmarks: benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp src/json.hpp
$(CXX) -std=c++11 $(CXXFLAGS) -O3 -flto -I src -I benchmarks $< $(LDFLAGS) -o $@
./json_benchmarks
##########################################################################
# changelog
##########################################################################
ChangeLog.md:
github_changelog_generator -o ChangeLog.md --simple-list --release-url https://github.com/nlohmann/json/releases/tag/%s
gsed -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md
gsed -i '2i All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).' ChangeLog.md

File diff suppressed because it is too large Load Diff

View File

@ -7848,9 +7848,8 @@ class basic_json
result.m_type.bits.parsed = true; result.m_type.bits.parsed = true;
// 'found_radix_point' will be set to 0xFF upon finding a radix // 'found_radix_point' will be set to 0xFF upon finding a radix
// point and later used to mask in/out the precision depending // point. if it is not found, then the precision will be updated
// whether a radix is found i.e. 'precision &= found_radix_point' bool found_radix_point = false;
uint8_t found_radix_point = 0;
uint8_t precision = 0; uint8_t precision = 0;
// accumulate the integer conversion result (unsigned for now) // accumulate the integer conversion result (unsigned for now)
@ -7892,7 +7891,7 @@ class basic_json
// reset precision count // reset precision count
precision = 0; precision = 0;
found_radix_point = 0xFF; found_radix_point = true;
continue; continue;
} }
// assume exponent (if not then will fail parse): change to // assume exponent (if not then will fail parse): change to
@ -7930,8 +7929,23 @@ class basic_json
} }
// If no radix point was found then precision would now be set to // If no radix point was found then precision would now be set to
// the number of digits, which is wrong - clear it. // the number of digits, which is wrong - decrement it to sig figs - 1
result.m_type.bits.precision = precision & found_radix_point; if(not found_radix_point)
{
int trailing_zeros = 0;
for (int j = precision-1;j>=0;--j)
{
auto c = *(m_start+j);
if(c == '0')
++trailing_zeros;
else if(c > '0' and c <= '9' or c == '-')
break;
else
throw std::logic_error("unexpected character: "+std::to_string(c));
}
precision -= (trailing_zeros + 1);
}
result.m_type.bits.precision = precision;
// save the value (if not a float) // save the value (if not a float)
if (type == value_t::number_unsigned) if (type == value_t::number_unsigned)