Compare commits

..
Author SHA1 Message Date
bitbybit3d a4ba5dfa10 fix target_compile_definitions misspelling 2022-09-26 20:22:08 +01:00
421 changed files with 43801 additions and 128806 deletions
+56 -65
View File
@@ -44,11 +44,11 @@ jobs:
- name: Test
run: |
cd build && ctest --verbose -j1 .
cd build && ctest -j1 .
linux:
name: Ubuntu Latest GCC
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
fail-fast: true
steps:
@@ -86,11 +86,11 @@ jobs:
- name: Test
run: |
cd build && ctest --verbose -j1 . -C Release
cd build && ctest -j1 . -C Release
linux_clang:
name: Ubuntu Latest Clang
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
fail-fast: true
steps:
@@ -128,7 +128,7 @@ jobs:
- name: Test
run: |
cd build && ctest --verbose -j1 . -C Release
cd build && ctest -j1 . -C Release
osx:
@@ -160,68 +160,62 @@ jobs:
- name: Test
run: |
cd build && ctest --verbose -j1 . -C Release
cd build && ctest -j1 . -C Release
brlcad_linux:
name: BRL-CAD Linux step-g Test
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
fail-fast: true
steps:
- name: Setup - CMake
uses: lukka/get-cmake@latest
- name: Setup - Ninja
uses: seanmiddleditch/gha-setup-ninja@master
- name: Setup - System
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update
sudo apt-get install re2c astyle xsltproc libxml2-utils
sudo apt-get install xserver-xorg-dev libx11-dev libxi-dev libxext-dev libglu1-mesa-dev libfontconfig-dev
sudo apt-get install zlib1g-dev libpng-dev libjpeg-dev libtiff-dev libeigen3-dev libgdal-dev libassimp-dev libopencv-dev
# Install dev tools
sudo apt-get install re2c lemon
sudo apt-get clean
- name: Clone bext
run: |
git clone https://github.com/BRL-CAD/bext.git
cd bext/stepcode
cmake -E rm -r stepcode
git clone --depth 1 https://github.com/stepcode/stepcode.git -b develop
cd ../..
- name: Build bext
run: |
cmake -E make_directory bext_build
cmake -S bext -B bext_build -DCMAKE_BUILD_TYPE=Release -DUSE_GDAL=OFF -DUSE_TCL=OFF -DUSE_QT=OFF -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\bext_output
cmake --build bext_build --config Release -j2
# We only need the build ouputs (bext_output) after this point, so
# clean up to save space for the main BRL-CAD build.
cmake -E rm -rf bext
cmake -E rm -rf bext_build
- name: Checkout
run: |
git clone --depth 1 https://github.com/BRL-CAD/brlcad.git -b main
cd brlcad/src/other/ext && rm -rf stepcode
git clone --depth 1 https://github.com/stepcode/stepcode.git -b develop
# Ordinarily BRL-CAD keeps track of what files are supposed to be
# present in the repository. In this case we're not interested in
# updating the list to the working stepcode filelist, so use an empty
# list instead
echo "set(stepcode_ignore_files)" > stepcode.dist
cd ../../../../
- name: Configure
run: |
cmake -E make_directory brlcad_build
cd brlcad_build
cmake -S ../brlcad -DBRLCAD_EXT_DIR=${{ github.workspace }}\bext_output -DBRLCAD_ENABLE_GDAL=OFF -DBRLCAD_ENABLE_TCL=OFF -DBRLCAD_ENABLE_QT=OFF -G Ninja
export PATH=$ENV{GITHUB_WORKSPACE}:$PATH
cd brlcad
cmake -S . -G Ninja -B build -DENABLE_ALL=ON -DCMAKE_BUILD_TYPE=Release -DEXT_BUILD_VERBOSE=ON
cd ..
- name: Build
run: |
cd brlcad_build
cmake --build . --target step-g
export PATH=$ENV{GITHUB_WORKSPACE}:$PATH
cd brlcad
cmake --build build --config Release --target step-g
cd ..
- name: Test
run: |
cd brlcad_build
./bin/step-g ../brlcad/db/nist/NIST_MBE_PMI_3.stp -o nist3.g
cd ..
export PATH=$ENV{GITHUB_WORKSPACE}:$PATH
cd brlcad/build
./bin/step-g ../db/nist/NIST_MBE_PMI_3.stp -o nist3.g
cd ../..
brlcad_windows:
@@ -233,6 +227,9 @@ jobs:
- name: Setup - CMake
uses: lukka/get-cmake@latest
- name: Setup - Ninja
uses: seanmiddleditch/gha-setup-ninja@master
- name: Add github workspace to path
# https://github.community/t/deprecated-add-path/136621
run: echo "$ENV{GITHUB_WORKSPACE}" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
@@ -243,44 +240,38 @@ jobs:
- name: Add cl.exe to PATH
uses: ilammy/msvc-dev-cmd@v1
- name: Clone bext
run: |
git clone https://github.com/BRL-CAD/bext.git
cd bext/stepcode
cmake -E rm -r stepcode
git clone --depth 1 https://github.com/stepcode/stepcode.git -b develop
cd ../..
- name: Build bext
shell: powershell
run: |
cmake -E make_directory bext_build
cmake -S bext -B bext_build -DCMAKE_BUILD_TYPE=Release -DUSE_GDAL=OFF -DUSE_TCL=OFF -DUSE_QT=OFF -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\bext_output
cmake --build bext_build --config Release -j2
# We only need the build ouputs (bext_output) after this point, so
# clean up to save space for the main BRL-CAD build.
cmake -E rm -rf bext
cmake -E rm -rf bext_build
- name: Checkout
run: |
git clone --depth 1 https://github.com/BRL-CAD/brlcad.git -b main
cd brlcad/src/other/ext
cmake -E rm -r stepcode
git clone --depth 1 https://github.com/stepcode/stepcode.git -b develop
# Ordinarily BRL-CAD keeps track of what files are supposed to be
# present in the repository. In this case we're not interested in
# updating the list to the working stepcode filelist, so use an empty
# list instead
echo "set(stepcode_ignore_files)" > stepcode.dist
cd ../../../../
- name: Configure
run: |
cmake -E make_directory brlcad_build
cmake -S brlcad -B brlcad_build -DCMAKE_BUILD_TYPE=Release -DBRLCAD_EXT_DIR=${{ github.workspace }}\bext_output -DBRLCAD_ENABLE_GDAL=OFF -DBRLCAD_ENABLE_TCL=OFF -DBRLCAD_ENABLE_QT=OFF -G Ninja -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe"
cd brlcad && cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -DSC_ENABLE_TESTING=ON
cd ..
# We do the following in order to help ensure files are "flushed"
# to disk before compilation is attempted
# https://superuser.com/a/1553374/1286142
powershell Write-VolumeCache C
powershell Write-VolumeCache D
- name: Build
run: |
cd brlcad_build
cmake --build . --config Release --target step-g
cd ..
cd brlcad/build
ninja -j1 -v step-g
cd ../..
- name: Test
run: |
cd brlcad_build
./bin/step-g.exe ../brlcad/db/nist/NIST_MBE_PMI_3.stp -o nist3.g
cd ..
cd brlcad/build
./bin/step-g.exe ../db/nist/NIST_MBE_PMI_3.stp -o nist3.g
cd ../..
-4
View File
@@ -1,6 +1,5 @@
# Common build directories used in the source tree
/build
/build-*
/.build
# Temporary files
@@ -20,6 +19,3 @@
# Tool specific patterns
*.kdev4
.kdev_include_paths
# Parser generator intermediate files
*.out
+3 -117
View File
@@ -120,6 +120,7 @@ option(BUILD_STATIC_LIBS "Build static libraries" OFF)
option(SC_PYTHON_GENERATOR "Compile exp2python" ON)
option(SC_CPP_GENERATOR "Compile exp2cxx" ON)
option(SC_MEMMGR_ENABLE_CHECKS "Enable sc_memmgr's memory leak detection" OFF)
option(SC_TRACE_FPRINTF "Enable extra comments in generated code so the code's source in exp2cxx may be located" OFF)
option(SC_ENABLE_COVERAGE "Enable code coverage test" OFF)
@@ -129,18 +130,6 @@ if (SC_ENABLE_COVERAGE AND ${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "-fprofile-arcs -ftest-coverage" CACHE STRING "Extra linker flags required by code coverage" FORCE)
endif (SC_ENABLE_COVERAGE AND ${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
option(SC_ENABLE_ADDRESS_SANITIZER "Enable AddressSanitizer instrumentation" OFF)
option(SC_ENABLE_UNDEFINED_SANITIZER "Enable UndefinedBehaviorSanitizer instrumentation" OFF)
option(SC_ENABLE_THREAD_SANITIZER "Enable ThreadSanitizer instrumentation" OFF)
if(SC_ENABLE_THREAD_SANITIZER AND
(SC_ENABLE_ADDRESS_SANITIZER OR SC_ENABLE_UNDEFINED_SANITIZER))
message(FATAL_ERROR
"SC_ENABLE_THREAD_SANITIZER must use a separate build from "
"AddressSanitizer and UndefinedBehaviorSanitizer"
)
endif()
option(SC_BUILD_EXPRESS_ONLY "Only build express parser." OFF)
mark_as_advanced(SC_BUILD_EXPRESS_ONLY)
@@ -167,111 +156,6 @@ include(SC_Regenerate)
# create config.h header
include(SC_Config_Headers)
# Apply sanitizer instrumentation after configure-time feature tests so their
# try-compile executables do not depend on sanitizer runtime behavior. Keep
# link flags explicit for CMake 3.12 compatibility (add_link_options was added
# in CMake 3.13).
if(SC_ENABLE_ADDRESS_SANITIZER OR
SC_ENABLE_UNDEFINED_SANITIZER OR
SC_ENABLE_THREAD_SANITIZER)
if(MSVC)
message(FATAL_ERROR "STEPcode sanitizer builds are not yet supported with MSVC")
endif()
include(CMakePushCheckState)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
set(_sc_sanitizer_compile_options)
set(_sc_sanitizer_link_options)
function(sc_require_sanitizer FLAG RESULT_PREFIX)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "${FLAG}")
check_c_source_compiles("int main(void) { return 0; }" ${RESULT_PREFIX}_C_SUPPORTED)
check_cxx_source_compiles("int main() { return 0; }" ${RESULT_PREFIX}_CXX_SUPPORTED)
cmake_pop_check_state()
if(NOT ${RESULT_PREFIX}_C_SUPPORTED OR NOT ${RESULT_PREFIX}_CXX_SUPPORTED)
message(FATAL_ERROR
"STEPcode sanitizer mode was requested, but the C/C++ compiler and "
"linker do not support ${FLAG}"
)
endif()
endfunction()
if(SC_ENABLE_ADDRESS_SANITIZER)
sc_require_sanitizer("-fsanitize=address" SC_ASAN)
list(APPEND _sc_sanitizer_compile_options -fsanitize=address)
list(APPEND _sc_sanitizer_link_options -fsanitize=address)
# exp2cxx is executed during the build to generate schema bindings. It
# remains address-instrumented, but leak checking a short-lived build
# tool is both outside the test scope and unsupported under common build
# tracers/sandboxes. Limit this environment to schema generation; CTest
# and installed tools retain the user's normal ASan settings.
set(SC_SCHEMA_GENERATOR_ENVIRONMENT "ASAN_OPTIONS=detect_leaks=0")
endif()
if(SC_ENABLE_UNDEFINED_SANITIZER)
sc_require_sanitizer("-fsanitize=undefined" SC_UBSAN)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-fsanitize=undefined")
list(APPEND CMAKE_REQUIRED_LIBRARIES "-fsanitize=undefined")
check_c_compiler_flag(
"-fno-sanitize-recover=undefined"
SC_UBSAN_C_NO_RECOVER_SUPPORTED
)
check_cxx_compiler_flag(
"-fno-sanitize-recover=undefined"
SC_UBSAN_CXX_NO_RECOVER_SUPPORTED
)
cmake_pop_check_state()
if(NOT SC_UBSAN_C_NO_RECOVER_SUPPORTED OR
NOT SC_UBSAN_CXX_NO_RECOVER_SUPPORTED)
message(FATAL_ERROR
"STEPcode's fail-fast UndefinedBehaviorSanitizer mode was requested, "
"but the C/C++ compiler does not support "
"-fno-sanitize-recover=undefined"
)
endif()
list(APPEND _sc_sanitizer_compile_options
-fsanitize=undefined
-fno-sanitize-recover=undefined
)
list(APPEND _sc_sanitizer_link_options -fsanitize=undefined)
endif()
if(SC_ENABLE_THREAD_SANITIZER)
sc_require_sanitizer("-fsanitize=thread" SC_TSAN)
list(APPEND _sc_sanitizer_compile_options -fsanitize=thread)
list(APPEND _sc_sanitizer_link_options -fsanitize=thread)
endif()
check_c_compiler_flag("-fno-omit-frame-pointer" SC_SANITIZER_C_FRAME_POINTER_SUPPORTED)
check_cxx_compiler_flag("-fno-omit-frame-pointer" SC_SANITIZER_CXX_FRAME_POINTER_SUPPORTED)
if(SC_SANITIZER_C_FRAME_POINTER_SUPPORTED)
list(APPEND _sc_sanitizer_compile_options
$<$<COMPILE_LANGUAGE:C>:-fno-omit-frame-pointer>
)
endif()
if(SC_SANITIZER_CXX_FRAME_POINTER_SUPPORTED)
list(APPEND _sc_sanitizer_compile_options
$<$<COMPILE_LANGUAGE:CXX>:-fno-omit-frame-pointer>
)
endif()
add_compile_options(${_sc_sanitizer_compile_options})
string(JOIN " " _sc_sanitizer_link_flags ${_sc_sanitizer_link_options})
foreach(_sc_link_type EXE SHARED MODULE)
set(
CMAKE_${_sc_link_type}_LINKER_FLAGS
"${CMAKE_${_sc_link_type}_LINKER_FLAGS} ${_sc_sanitizer_link_flags}"
)
endforeach()
endif()
if(NOT DEFINED SC_SDAI_ADDITIONAL_EXES_SRCS)
set(SC_SDAI_ADDITIONAL_EXES_SRCS "" CACHE STRING "Source files for additional executables to be linked with SDAI libs")
endif(NOT DEFINED SC_SDAI_ADDITIONAL_EXES_SRCS)
@@ -305,6 +189,7 @@ include_directories(
${SC_BINARY_DIR}/include
)
add_subdirectory(src/base)
add_subdirectory(src/express)
add_subdirectory(src/exppp)
add_subdirectory(src/exp2cxx)
@@ -347,3 +232,4 @@ endforeach(_msg ${CONFIG_END_MESSAGES})
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
+1 -1
View File
@@ -5,7 +5,7 @@ This repo was moved and renamed in May 2012. Previously, it was at
http://github.com/mpictor/StepClassLibrary
Some are duplicates of changes recorded in the BRL-CAD repo:
https://github.com/BRL-CAD/brlcad/tree/158beae4556d94821938368951546384cba53107/src/other/ext/stepcode
http://brlcad.svn.sourceforge.net/viewvc/brlcad/brlcad/trunk/src/other/step/?view=log
Pre-BRL-CAD changes:
************************************************************************
+1 -7
View File
@@ -51,13 +51,7 @@ Installation
-DSC_BUILD_SCHEMAS=ALL
- Added to make use of ctest easier. If SC_BUILD_SCHEMAS == ALL,
then CMake adds each *.exp file found in data/.
-DSC_EXP2CXX_API_VERSION=2
- opts in to compact descriptor-driven SELECTs and dependency-bounded
entity headers in the generated C++ API.
- clients include the entity headers they use (for example,
entity/SdaiProduct.h); schema.h no longer expands every entity class.
- version 1 remains the default for source compatibility.
-DCMAKE_BUILD_TYPE=Release
-DSC_BUILD_TYPE=Release
- this causes binaries to be built without debugging information
- without this, cmake defaults to a Debug build
+2 -2
View File
@@ -141,7 +141,7 @@ if (LEMON_EXECUTABLE)
# execute lemon
add_custom_command(
OUTPUT ${_out_src_file} ${_basename}.h
OUTPUT ${_out_src_file}
COMMAND ${LEMON_EXECUTABLE} -T${LEMON_TEMPLATE} ${LEMON_EXECUTABLE_opts} ${_in_y_file}
DEPENDS ${Name}_input_cpy
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
@@ -152,7 +152,7 @@ if (LEMON_EXECUTABLE)
add_custom_command(
OUTPUT ${_out_hdr_file}
COMMAND ${CMAKE_COMMAND} ARGS -E rename ${_basename}.h ${_out_hdr_file}
DEPENDS ${_out_src_file} ${_basename}.h
DEPENDS ${_out_src_file}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
+13 -43
View File
@@ -27,29 +27,17 @@ endmacro(P21_TESTS sfile)
# create p21read_sdai_*, lazy_sdai_*, any exes listed in SC_SDAI_ADDITIONAL_EXES_SRCS
macro(SCHEMA_EXES)
RELATIVE_PATH_TO_TOPLEVEL(${CMAKE_CURRENT_SOURCE_DIR} RELATIVE_PATH_COMPONENT)
if(BUILD_SHARED_LIBS)
SC_ADDEXEC(p21read_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/test/p21read/p21read.cc;${RELATIVE_PATH_COMPONENT}/src/test/p21read/sc_benchmark.cc" LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils TESTABLE)
elseif(BUILD_STATIC_LIBS)
SC_ADDEXEC(p21read_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/test/p21read/p21read.cc;${RELATIVE_PATH_COMPONENT}/src/test/p21read/sc_benchmark.cc" LINK_LIBRARIES ${PROJECT_NAME}-static stepeditor-static stepcore-static stepdai-static steputils-static TESTABLE)
endif()
SC_ADDEXEC(p21read_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/test/p21read/p21read.cc" LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils base TESTABLE)
if(NOT WIN32)
if(BUILD_SHARED_LIBS)
SC_ADDEXEC(lazy_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/cllazyfile/lazy_test.cc;${RELATIVE_PATH_COMPONENT}/src/cllazyfile/sc_benchmark.cc" LINK_LIBRARIES ${PROJECT_NAME} steplazyfile stepdai stepcore stepeditor steputils TESTABLE)
elseif(BUILD_STATIC_LIBS)
SC_ADDEXEC(lazy_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/cllazyfile/lazy_test.cc;${RELATIVE_PATH_COMPONENT}/src/cllazyfile/sc_benchmark.cc" LINK_LIBRARIES ${PROJECT_NAME}-static steplazyfile-static stepeditor-static stepcore-static stepdai-static steputils-static TESTABLE)
endif()
SC_ADDEXEC(lazy_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/cllazyfile/lazy_test.cc" LINK_LIBRARIES ${PROJECT_NAME} steplazyfile stepdai stepcore stepeditor steputils base TESTABLE)
endif(NOT WIN32)
#add user-defined executables
foreach(src ${SC_SDAI_ADDITIONAL_EXES_SRCS})
get_filename_component(name ${src} NAME_WE)
get_filename_component(path ${src} ABSOLUTE)
if(BUILD_SHARED_LIBS)
SC_ADDEXEC(${name}_${PROJECT_NAME} SOURCES ${src} LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils TESTABLE)
elseif(BUILD_STATIC_LIBS)
SC_ADDEXEC(${name}_${PROJECT_NAME} SOURCES ${src} LINK_LIBRARIES ${PROJECT_NAME}-static stepcore-static stepdai-static stepeditor-static steputils-static TESTABLE)
SC_ADDEXEC(${name}_${PROJECT_NAME} SOURCES ${src} LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils base TESTABLE)
#set_target_properties(${name}_${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${${PROJECT_NAME}_COMPILE_FLAGS} -I${path}")
endif()
endforeach(src ${SC_SDAI_ADDITIONAL_EXES_SRCS})
ENDMACRO(SCHEMA_EXES)
@@ -89,40 +77,25 @@ macro(SCHEMA_TARGETS expFile schemaName sourceFiles)
# schema scanner comes up with a short schema name for PROJECT() (which sets ${PROJECT_NAME})
message(STATUS "Will generate ${${PROJECT_NAME}_file_count} C++ files for ${PROJECT_NAME}.")
set(_schema_generated_files)
foreach(_schema_source ${sourceFiles})
list(APPEND _schema_generated_files "${CMAKE_CURRENT_SOURCE_DIR}/${_schema_source}")
endforeach()
add_custom_target(generate_cpp_${PROJECT_NAME} DEPENDS exp2cxx ${expFile} ${_schema_generated_files} SOURCES ${_schema_generated_files})
add_custom_target(generate_cpp_${PROJECT_NAME} DEPENDS exp2cxx ${expFile} ${sourceFiles} SOURCES ${sourceFiles})
# this calls a cmake script because it doesn't seem to be possible
# to divert stdout, stderr in cmake except via execute_process
add_custom_command(OUTPUT ${_schema_generated_files}
add_custom_command(OUTPUT ${sourceFiles}
COMMAND ${CMAKE_COMMAND} -DEXE=\"$<TARGET_FILE:exp2cxx>\" -DEXP=\"${expFile}\"
-DONESHOT=\"${SC_GENERATE_CXX_ONESHOT}\" -DSDIR=\"${CMAKE_CURRENT_LIST_DIR}\"
-DCHUNK_SIZE=\"${SC_EXP2CXX_CHUNK_SIZE}\"
-DAPI_VERSION=\"${SC_EXP2CXX_API_VERSION}\"
-DLATE_BOUND=\"${SC_EXP2CXX_LATE_BOUND}\"
-DCOMPAT_NAMES=\"${SC_EXP2CXX_COMPAT_NAMES}\"
-DMETADATA_PROFILE=\"${SC_EXP2CXX_METADATA}\"
-DGENERATOR_ENVIRONMENT=\"${SC_SCHEMA_GENERATOR_ENVIRONMENT}\"
-P ${SC_CMAKE_DIR}/SC_Run_exp2cxx.cmake
DEPENDS exp2cxx ${expFile}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMENT "[exp2cxx] Generating ${${PROJECT_NAME}_file_count} C++ files for ${PROJECT_NAME}."
)
set(_schema_include_dirs
include_directories(
${CMAKE_CURRENT_SOURCE_DIR} ${SC_SOURCE_DIR}/src/cldai ${SC_SOURCE_DIR}/src/cleditor
${SC_SOURCE_DIR}/src/clutils ${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/cllazyfile
${SC_SOURCE_DIR}/src/cllazyfile/judy/src
${SC_SOURCE_DIR}/src/clutils ${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/base
${SC_SOURCE_DIR}/src/base/judy/src
)
# Schema libraries should be installed by default
# if testing is enabled, "TESTABLE" sets property EXCLUDE_FROM_ALL and prevents installation
if(BUILD_SHARED_LIBS)
SC_ADDLIB(${PROJECT_NAME} SHARED SOURCES ${_schema_generated_files} LINK_LIBRARIES stepdai stepcore stepeditor steputils)
SC_ADDLIB(${PROJECT_NAME} SHARED SOURCES ${sourceFiles} LINK_LIBRARIES stepdai stepcore stepeditor steputils base TESTABLE)
add_dependencies(${PROJECT_NAME} generate_cpp_${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${_schema_include_dirs})
if(${PROJECT_NAME}_unity_build)
target_compile_definitions(${PROJECT_NAME} PRIVATE SC_SDAI_UNITY_BUILD)
endif()
if(WIN32)
target_compile_definitions("${PROJECT_NAME}" PRIVATE SC_SCHEMA_DLL_EXPORTS)
if(MSVC)
@@ -137,14 +110,10 @@ macro(SCHEMA_TARGETS expFile schemaName sourceFiles)
endif()
endif()
if(BUILD_STATIC_LIBS)
SC_ADDLIB(${PROJECT_NAME}-static STATIC SOURCES ${_schema_generated_files} LINK_LIBRARIES stepcore-static stepdai-static stepeditor-static steputils-static)
if($CACHE{SC_BUILD_STATIC_LIBS})
SC_ADDLIB(${PROJECT_NAME}-static STATIC SOURCES ${sourceFiles} LINK_LIBRARIES stepdai-static stepcore-static stepeditor-static steputils-static base-static TESTABLE)
add_dependencies(${PROJECT_NAME}-static generate_cpp_${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}-static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${_schema_include_dirs})
target_compile_definitions("${PROJECT_NAME}-static" PRIVATE SC_STATIC)
if(${PROJECT_NAME}_unity_build)
target_compile_definitions(${PROJECT_NAME}-static PRIVATE SC_SDAI_UNITY_BUILD)
endif()
if(MSVC)
target_compile_options("${PROJECT_NAME}-static" PRIVATE "/bigobj")
endif()
@@ -164,3 +133,4 @@ endmacro(SCHEMA_TARGETS expFile schemaName sourceFiles)
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
+2 -17
View File
@@ -1,26 +1,10 @@
# if oneshot is true, don't run exp2cxx if source files exist. if schema.cc exists, assume others do
if(NOT DEFINED API_VERSION OR "${API_VERSION}" STREQUAL "")
set(API_VERSION 1)
endif()
if(NOT DEFINED METADATA_PROFILE OR "${METADATA_PROFILE}" STREQUAL "")
set(METADATA_PROFILE full)
endif()
if(ONESHOT AND EXISTS "${SDIR}/schema.cc")
message("WARNING: SC_GENERATE_CXX_ONESHOT is enabled. If generated code has been modified, it will NOT be rewritten!")
message("This is ONLY for debugging STEPcode internals!")
else()
set(_exp2cxx_mode_args)
if(LATE_BOUND)
list(APPEND _exp2cxx_mode_args --late-bound)
endif()
if(COMPAT_NAMES)
list(APPEND _exp2cxx_mode_args --compat-names)
endif()
list(APPEND _exp2cxx_mode_args --metadata ${METADATA_PROFILE})
execute_process(COMMAND ${CMAKE_COMMAND} -E env ${GENERATOR_ENVIRONMENT}
${EXE} -k ${CHUNK_SIZE} -V ${API_VERSION} ${_exp2cxx_mode_args} ${EXP}
execute_process(COMMAND ${EXE} ${EXP}
WORKING_DIRECTORY ${SDIR}
RESULT_VARIABLE _res
OUTPUT_FILE exp2cxx_stdout.txt
@@ -38,3 +22,4 @@ endif()
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
+9 -21
View File
@@ -10,23 +10,15 @@ macro(SC_ADDEXEC execname)
add_executable(${execname} ${${_arg_prefix}_SOURCES})
if(BUILD_STATIC_LIBS)
target_compile_definitions(${execname} PRIVATE SC_STATIC)
endif()
if(DEFINED "${_arg_prefix}_LINK_LIBRARIES")
foreach(_lib ${${_arg_prefix}_LINK_LIBRARIES})
if($CACHE{SC_STATIC_UTILS})
get_property(_lib_type TARGET ${_lib} PROPERTY TYPE)
if(NOT _lib_type STREQUAL "STATIC_LIBRARY")
if(NOT $<TARGET_PROPERTY:${_lib},TYPE> STREQUAL "STATIC_LIBRARY")
message(SEND_ERROR "SC_ADDEXEC usage error - expected STATIC LINK_LIBRARIES targets (${_lib})")
endif()
endif()
# Executables consume their dependencies but do not publish an
# interface to downstream targets.
target_link_libraries(${execname} PRIVATE ${_lib})
target_link_libraries(${execname} ${_lib})
endforeach()
target_link_libraries(${execname} PRIVATE ${${_arg_prefix}_LINK_LIBRARIES})
endif()
if(NOT ${_arg_prefix}_NO_INSTALL AND NOT ${_arg_prefix}_TESTABLE)
@@ -45,7 +37,7 @@ endmacro()
macro(SC_ADDLIB _addlib_target)
set(_addlib_opts SHARED STATIC NO_INSTALL TESTABLE)
set(_addlib_multikw SOURCES LINK_LIBRARIES)
string(TOUPPER "SC_ADDLIB_${_addlib_target}_ARG" _arg_prefix)
string(TOUPPER "SC_ADDLIB_${libname}_ARG" _arg_prefix)
cmake_parse_arguments(${_arg_prefix} "${_addlib_opts}" "" "${_addlib_multikw}" ${ARGN})
if(NOT DEFINED ${_arg_prefix}_SOURCES)
@@ -72,25 +64,20 @@ macro(SC_ADDLIB _addlib_target)
if(DEFINED ${_arg_prefix}_LINK_LIBRARIES)
foreach(_lib ${${_arg_prefix}_LINK_LIBRARIES})
if(${_arg_prefix}_STATIC AND TARGET ${_lib})
get_property(_libtype TARGET ${_lib} PROPERTY TYPE)
if(NOT ${_libtype} STREQUAL "STATIC_LIBRARY")
message(SEND_ERROR "SC_ADDLIB usage error - expected (static) LINK_LIBRARIES targets (${_lib})")
get_property(_libtype TARGET ${_lib} PROPERTY TYPE)
if(NOT ${_libtype} STREQUAL "STATIC_LIBRARY")
message(SEND_ERROR "SC_ADDLIB usage error - expected (static) LINK_LIBRARIES targets (${_lib})")
endif()
endif()
# Schema libraries are consumed directly by generated test programs.
# Publish their link requirements explicitly; the legacy unscoped
# signature does not reliably provide a transitive interface with
# current CMake versions.
target_link_libraries(${_addlib_target} PUBLIC ${_lib})
target_link_libraries(${_addlib_target} ${_lib})
endforeach()
target_link_libraries(${_addlib_target} ${_lib})
endif()
if(NOT ${_arg_prefix}_NO_INSTALL AND NOT ${_arg_prefix}_TESTABLE)
install(TARGETS ${_addlib_target}
RUNTIME DESTINATION ${BIN_DIR}
LIBRARY DESTINATION ${LIB_DIR}
ARCHIVE DESTINATION ${LIB_DIR}
ARCHIVE DESTINATION ${LIB_DIR}
)
endif()
endmacro()
@@ -101,3 +88,4 @@ endmacro()
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
+2
View File
@@ -16,6 +16,7 @@ set(SC_BINARY_DIR ${SC_BUILDDIR})
include(${CMAKE_CURRENT_SOURCE_DIR}/../SC_Outdirs.cmake)
set(schema_scanner_src
${SC_ROOT}/src/base/sc_mkdir.c
${SC_ROOT}/src/exp2cxx/genCxxFilenames.c
${SC_ROOT}/src/exp2cxx/class_strings.c
${SC_ROOT}/src/express/generated/expparse.c
@@ -51,6 +52,7 @@ include_directories(
${SC_ROOT}/include/
${SC_ROOT}/src/express/
${SC_ROOT}/src/express/generated
${SC_ROOT}/src/base
${SC_ROOT}/src/exp2cxx
${SC_BUILDDIR}/include
)
+27 -120
View File
@@ -14,28 +14,22 @@
*/
extern "C" {
#define _XOPEN_SOURCE /* for S_IFDIR */
# include "expparse.h"
# include "expscan.h"
# include "express/scope.h"
# include "genCxxFilenames.h"
# include "sc_mkdir.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
# include <string.h>
#include "expparse.h"
#include "expscan.h"
#include "express/scope.h"
#include "genCxxFilenames.h"
#include <string.h>
#ifdef _WIN32
# include <direct.h>
# define getcwd _getcwd
#else
# include <unistd.h>
#endif
# ifdef _WIN32
# include <direct.h>
# define getcwd _getcwd
# else
# include <unistd.h>
# endif
}
#include <algorithm>
#include <string>
#include <sstream>
#include <iomanip>
@@ -51,35 +45,6 @@ using std::ofstream;
using std::cerr;
using std::cout;
static unsigned long entityChunkSize = 256;
static unsigned long typeChunkSize = 256;
static bool
parseChunkSizes( const char * value )
{
if( !value || !value[0] ) {
return false;
}
char * end = 0;
const unsigned long entities = strtoul( value, &end, 10 );
if( !end || entities == 0 ) {
return false;
}
unsigned long types = entities;
if( *end == ':' ) {
char * typeEnd = 0;
types = strtoul( end + 1, &typeEnd, 10 );
if( !end[1] || !typeEnd || *typeEnd || types == 0 ) {
return false;
}
} else if( *end ) {
return false;
}
entityChunkSize = entities;
typeChunkSize = types;
return true;
}
/** \return true for types that exp2cxx won't generate code for */
bool notGenerated( const Type t ) {
switch( TYPEget_body( t )->type ) {
@@ -160,30 +125,6 @@ string makeShortName( const char * longName ) {
return filename;
}
/* cross-platform mkdir */
int sc_mkdir( const char * path ) {
#ifdef _WIN32
return mkdir( path );
#else
return mkdir( path, 0777 );
#endif /* _WIN32 */
}
/* return -1 if error, 0 if created, 1 if dir existed already */
static int mkDirIfNone( const char * path ) {
struct stat s;
if( stat( path, &s ) != 0 ) {
if( errno == ENOENT ) {
return sc_mkdir( path );
}
} else if( s.st_mode & S_IFDIR ) {
return 1;
}
/* either stat returned an error other than ENOENT, or 'path' exists but isn't a dir */
return -1;
}
/** write a CMakeLists.txt file for the schema; print its directory to stdout for CMake's add_subdirectory() command */
void writeLists( const char * schemaName, stringstream & eh, stringstream & ei, int ecount,
stringstream & th, stringstream & ti, int tcount ) {
@@ -216,34 +157,20 @@ void writeLists( const char * schemaName, stringstream & eh, stringstream & ei,
cmLists << "# targets, logic, etc are within a set of macros shared by all schemas" << endl;
cmLists << "include(${SC_CMAKE_DIR}/SC_CXX_schema_macros.cmake)" << endl;
const int entityChunks = std::max( 1, ( ecount + static_cast<int>( entityChunkSize ) - 1 ) / static_cast<int>( entityChunkSize ) );
const int typeChunks = std::max( 1, ( tcount + static_cast<int>( typeChunkSize ) - 1 ) / static_cast<int>( typeChunkSize ) );
cmLists << "if(SC_EXP2CXX_LATE_BOUND)" << endl;
cmLists << " set(" << shortName << "_file_count 10)" << endl;
cmLists << "else()" << endl;
cmLists << " set(" << shortName << "_file_count " <<
( ecount + tcount ) * 2 + entityChunks + typeChunks + 14 << ")" << endl;
cmLists << "endif()" << endl << endl;
// * 2 for headers, + 10 other files
cmLists << "set(" << shortName << "_file_count " << ( ( ecount + tcount ) * 2 ) + 10 << ")" << endl << endl;
cmLists << "PROJECT(" << shortName << ")" << endl;
cmLists << "# list headers so they can be installed - entity, type, misc" << endl;
cmLists << "if(SC_EXP2CXX_LATE_BOUND)" << endl;
cmLists << " set(" << shortName << "_entity_hdrs)" << endl;
cmLists << "else()" << endl;
cmLists << " set(" << shortName << "_entity_hdrs" << endl;
cmLists << "set(" << shortName << "_entity_hdrs" << endl;
cmLists << eh.str();
cmLists << " )" << endl;
cmLists << "endif()" << endl << endl;
cmLists << " )" << endl << endl;
cmLists << "if(SC_EXP2CXX_LATE_BOUND)" << endl;
cmLists << " set(" << shortName << "_type_hdrs)" << endl;
cmLists << "else()" << endl;
cmLists << " set(" << shortName << "_type_hdrs" << endl;
cmLists << "set(" << shortName << "_type_hdrs" << endl;
cmLists << th.str();
cmLists << " )" << endl;
cmLists << "endif()" << endl << endl;
cmLists << " )" << endl << endl;
cmLists << "set(" << shortName << "_misc_hdrs" << endl;
cmLists << " Sdaiclasses.h schema.h" << endl;
@@ -268,26 +195,11 @@ void writeLists( const char * schemaName, stringstream & eh, stringstream & ei,
cmLists << "# unity build: #include small .cc files to reduce the number" << endl;
cmLists << "# of translation units that must be compiled" << endl;
cmLists << "if(SC_EXP2CXX_LATE_BOUND)" << endl;
cmLists << " set(" << shortName << "_unity_build FALSE)" << endl;
cmLists << " set(" << shortName << "_entity_impls)" << endl;
cmLists << " set(" << shortName << "_type_impls)" << endl;
cmLists << "elseif(SC_UNITY_BUILD)" << endl;
cmLists << " # bounded compact chunks; definitions are target-local" << endl;
cmLists << " set(" << shortName << "_unity_build TRUE)" << endl;
cmLists << " set(" << shortName << "_entity_impls" << endl;
for( int chunk = 1; chunk <= entityChunks; ++chunk ) {
cmLists << " Sdai" << schema_upper << "_unity_entities_" <<
std::setfill( '0' ) << std::setw( 4 ) << chunk << ".cc" << endl;
}
cmLists << " )" << endl;
cmLists << " set(" << shortName << "_type_impls" << endl;
for( int chunk = 1; chunk <= typeChunks; ++chunk ) {
cmLists << " Sdai" << schema_upper << "_unity_types_" <<
std::setfill( '0' ) << std::setw( 4 ) << chunk << ".cc" << endl;
}
cmLists << " )" << endl;
cmLists << "else()" << endl;
cmLists << "if(SC_UNITY_BUILD)" << endl << " # turns off include statements within type and entity .cc's - the unity T.U.'s include a unity header" << endl;
cmLists << " add_definitions( -DSC_SDAI_UNITY_BUILD)" << endl;
cmLists << " set(" << shortName << "_entity_impls Sdai" << schema_upper << "_unity_entities.cc)" << endl;
cmLists << " set(" << shortName << "_type_impls Sdai" << schema_upper << "_unity_types.cc)" << endl;
cmLists << "else(SC_UNITY_BUILD)" << endl;
cmLists << " set(" << shortName << "_entity_impls" << endl;
cmLists << ei.str();
cmLists << " )" << endl << endl;
@@ -295,13 +207,12 @@ void writeLists( const char * schemaName, stringstream & eh, stringstream & ei,
cmLists << " set(" << shortName << "_type_impls" << endl;
cmLists << ti.str();
cmLists << " )" << endl;
cmLists << "endif()" << endl << endl;
cmLists << "endif(SC_UNITY_BUILD)" << endl << endl;
cmLists << "set( " << shortName << "_misc_impls" << endl;
cmLists << " SdaiAll.cc compstructs.cc schema.cc" << endl;
cmLists << " Sdai" << schema_upper << ".cc" << endl;
cmLists << " Sdai" << schema_upper << ".init.cc" << endl;
cmLists << " Sdai" << schema_upper << ".sources.cmake )" << endl << endl;
cmLists << " Sdai" << schema_upper << ".init.cc )" << endl << endl;
cmLists << "set(schema_target_files ${" << shortName << "_entity_impls} " << "${" << shortName << "_type_impls} " << "${" << shortName << "_misc_impls})" << endl;
cmLists << "SCHEMA_TARGETS(\"" << input_filename << "\" \"" << schemaName << "\"" << endl;
@@ -390,18 +301,14 @@ int main( int argc, char ** argv ) {
DictionaryEntry de;
/* copied from fedex.c */
Express model;
if( ( argc != 2 && argc != 3 ) || ( strlen( argv[1] ) < 1 ) ) {
fprintf( stderr, "\nUsage: %s file.exp [entity-chunk-size[:type-chunk-size]]\nOutput: a CMakeLists.txt to build the schema,", argv[0] );
if( ( argc != 2 ) || ( strlen( argv[1] ) < 1 ) ) {
fprintf( stderr, "\nUsage: %s file.exp\nOutput: a CMakeLists.txt to build the schema,", argv[0] );
fprintf( stderr, " containing file names for entities, types, etc\n" );
fprintf( stderr, "also prints (to stdout) the absolute path to the directory CMakeLists.txt was created in\n" );
exit( EXIT_FAILURE );
}
EXPRESSprogram_name = argv[0];
input_filename = argv[1];
if( argc == 3 && !parseChunkSizes( argv[2] ) ) {
fprintf( stderr, "chunk sizes must be positive integers in N or N:N form\n" );
exit( EXIT_FAILURE );
}
EXPRESSinitialize();
+2 -49
View File
@@ -18,44 +18,6 @@ else(NOT DEFINED SC_UNITY_BUILD)
message( STATUS "Respecting user-defined SC_UNITY_BUILD value of ${SC_UNITY_BUILD}.")
endif(NOT DEFINED SC_UNITY_BUILD)
if(NOT DEFINED SC_EXP2CXX_CHUNK_SIZE)
set(SC_EXP2CXX_CHUNK_SIZE "64:8" CACHE STRING "Maximum entity:type objects in generated unity translation units")
endif()
if(NOT DEFINED SC_EXP2CXX_API_VERSION)
set(SC_EXP2CXX_API_VERSION "1")
endif()
set(SC_EXP2CXX_API_VERSION "${SC_EXP2CXX_API_VERSION}" CACHE STRING "Generated C++ API version (1 or 2)")
set_property(CACHE SC_EXP2CXX_API_VERSION PROPERTY STRINGS 1 2)
if(NOT SC_EXP2CXX_API_VERSION MATCHES "^[12]$")
message(FATAL_ERROR "SC_EXP2CXX_API_VERSION must be 1 or 2")
endif()
option(SC_EXP2CXX_LATE_BOUND "Generate descriptor-backed entities without early-bound C++ entity classes" OFF)
if(SC_EXP2CXX_LATE_BOUND AND NOT SC_EXP2CXX_API_VERSION STREQUAL "2")
message(FATAL_ERROR "SC_EXP2CXX_LATE_BOUND requires SC_EXP2CXX_API_VERSION=2")
endif()
option(SC_EXP2CXX_COMPAT_NAMES "Retain generated entity aliases in late-bound output" OFF)
if(SC_EXP2CXX_COMPAT_NAMES AND NOT SC_EXP2CXX_LATE_BOUND)
message(FATAL_ERROR "SC_EXP2CXX_COMPAT_NAMES requires SC_EXP2CXX_LATE_BOUND=ON")
endif()
if(NOT DEFINED SC_EXP2CXX_METADATA)
set(SC_EXP2CXX_METADATA "full")
endif()
set(SC_EXP2CXX_METADATA "${SC_EXP2CXX_METADATA}" CACHE STRING
"Generated schema metadata profile (full or structural)")
set_property(CACHE SC_EXP2CXX_METADATA PROPERTY STRINGS full structural)
if(NOT SC_EXP2CXX_METADATA MATCHES "^(full|structural)$")
message(FATAL_ERROR "SC_EXP2CXX_METADATA must be full or structural")
endif()
if(SC_EXP2CXX_METADATA STREQUAL "structural" AND
NOT SC_EXP2CXX_LATE_BOUND)
message(FATAL_ERROR
"SC_EXP2CXX_METADATA=structural requires SC_EXP2CXX_LATE_BOUND=ON")
endif()
# --- variables ---
# SC_ROOT: SC root dir
@@ -120,7 +82,7 @@ endif(WIN32)
# SCHEMA_FILE - path to the schema
# TODO should we have a result variable to return schema name(s) found?
macro(SCHEMA_CMLIST SCHEMA_FILE)
execute_process(COMMAND ${SCANNER_OUT_DIR}/schema_scanner ${SCHEMA_FILE} ${SC_EXP2CXX_CHUNK_SIZE}
execute_process(COMMAND ${SCANNER_OUT_DIR}/schema_scanner ${SCHEMA_FILE}
WORKING_DIRECTORY ${SC_BINARY_DIR}/schemas
RESULT_VARIABLE _ss_stat
OUTPUT_VARIABLE _ss_out
@@ -135,16 +97,7 @@ macro(SCHEMA_CMLIST SCHEMA_FILE)
string(STRIP "${_ss_out}" _ss_stripped)
string(REGEX REPLACE "\\\n" ";" _list ${_ss_stripped})
foreach(_dir ${_list})
get_property(_already_added GLOBAL PROPERTY _SC_SCHEMA_DIRS)
list(FIND _already_added "${_dir}" _idx)
if(${_idx} EQUAL -1)
set_property(GLOBAL APPEND PROPERTY _SC_SCHEMA_DIRS "${_dir}")
# Keep generated targets under the top-level binary tree. Passing the
# absolute generated-source path as both arguments creates absolute
# make target names with newer CMake.
get_filename_component(_schema_dir_name "${_dir}" NAME)
add_subdirectory("${_dir}" "${SC_BINARY_DIR}/schema-targets/${_schema_dir_name}")
endif()
add_subdirectory(${_dir} ${_dir}) #specify source and binary dirs as the same
endforeach(_dir ${_ss_out})
# configure_file forces cmake to run again if the schema has been modified
#if multiple schemas in one file, _schema is the last one printed.
+1 -1
View File
@@ -9,7 +9,7 @@ set(CTEST_INITIAL_CACHE "
SITE:STRING=${CTEST_SITE}
BUILDNAME:STRING=${CTEST_BUILD_NAME}
SC_ENABLE_TESTING:BOOL=ON
CMAKE_BUILD_TYPE:STRING=Debug
SC_BUILD_TYPE:STRING=Debug
")
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-62
View File
@@ -1,62 +0,0 @@
# AP242 TREAT Schema File
This directory contains an altered version of the AP242 (ISO 10303-242) schema.
It is corrected to avoid the non-standard parsing requirement of the original
by using explicit TREAT expression for type narrowing
## The Difference
Both files are identical except for a single line at line 34149 in the `styled_item` entity WHERE rule WR3:
**Original (242_mim_lf.exp)**:
```express
QUERY(it <* item | ...)
```
**TREAT version (242_mim_lf_treat.exp)**:
```express
QUERY(it <* TREAT(item AS set_representation_item) | ...)
```
### Historical Context
The original AP242 schema contains a WHERE rule that:
1. Checks if `item` (a SELECT type) is a `SET_REPRESENTATION_ITEM`
2. Then tries to iterate over `item` in a QUERY expression
This pattern requires implicit type narrowing, which is not part of the ISO 10303-11 standard.
### STEPcode's Solution
STEPcode implements **flow-sensitive type narrowing** as an extension:
- Recognizes TYPEOF guard patterns like `'Type' IN TYPEOF(var)` in AND expressions
- Automatically narrows the type for subsequent uses
- Makes the original schema parse successfully
### Standards-Compliant Alternative
The TREAT version uses the ISO 10303-11 TREAT expression:
- `TREAT(item AS set_representation_item)` explicitly narrows the type
- No implicit narrowing needed
- Works in any compliant EXPRESS parser
## Testing
Both versions parse successfully and produce identical output:
```bash
# Run comparison test
./test/compare_ap242_versions.sh
```
Expected output:
```
✓ Both versions parse successfully
✓ Both versions generate the same number of files
```
For detailed comparison, see `doc/ap242-comparison.md`.
## Related Documentation
- `doc/ap242-comparison.md` - Detailed comparison and analysis
- `doc/express-type-unwrapping.md` - TREAT and narrowing documentation
- `src/express/test/README_AP242_BASELINE.md` - Historical PE056 error info
-165
View File
@@ -1,165 +0,0 @@
# AP242 Schema Comparison: Flow-Sensitive Narrowing vs TREAT Expression
## Overview
This document compares two versions of the AP242 schema to demonstrate the difference between STEPcode's non-standard flow-sensitive narrowing extension and the ISO 10303-11 compliant TREAT expression.
## Schema Versions
### 1. Original Version (`242_mim_lf.exp`)
- **Status**: Uses implicit flow-sensitive narrowing (non-standard extension)
- **Location**: `data/ap242/242_mim_lf.exp`
- **Size**: 54,756 lines
- **Problematic code**: Line 34149 in `styled_item` entity, WR3 WHERE rule
### 2. TREAT Version (`242_mim_lf_treat.exp`)
- **Status**: Standards-compliant using TREAT expression
- **Location**: `data/ap242/242_mim_lf_treat.exp`
- **Size**: 54,756 lines
- **Fix applied**: Line 34149 - explicit TREAT expression
## The Problem
In the `styled_item` entity at line ~34148, the WHERE rule WR3 contains:
```express
WR3: ('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.MAPPED_ITEM' IN TYPEOF(item)) OR
('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.GEOMETRIC_REPRESENTATION_ITEM' IN TYPEOF(item)) OR
(('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.SET_REPRESENTATION_ITEM' IN TYPEOF(item)) AND
(SIZEOF(QUERY(it <* item | ...)) = 0));
```
### Issue
- `item` is of type `styled_item_target`, which is a SELECT type
- The SELECT contains `set_representation_item` (which is an aggregate type)
- The code checks `'SET_REPRESENTATION_ITEM' IN TYPEOF(item)` (a TYPEOF guard)
- Then tries to iterate over `item` in a QUERY: `QUERY(it <* item | ...)`
### Why This Was Problematic
According to strict ISO 10303-11 standards, you cannot iterate over a SELECT type directly in a QUERY expression, even if there's a preceding TYPEOF guard. The guard and the QUERY are separate expressions in an AND clause.
## The Solutions
### Solution 1: Flow-Sensitive Narrowing (Non-Standard Extension)
STEPcode implements a **flow-sensitive type narrowing** extension that:
1. Recognizes the pattern `'TypeName' IN TYPEOF(var)` in AND expressions
2. Automatically narrows the type of `var` to `TypeName` for subsequent expressions in the AND
3. Allows `QUERY(it <* item | ...)` to work because `item` is implicitly narrowed to `set_representation_item`
**Code (original, line 34149)**:
```express
QUERY(it <* item | ...)
```
**How it works**:
- The AND expression LHS has the guard: `'SET_REPRESENTATION_ITEM' IN TYPEOF(item)`
- The RHS has the QUERY: `SIZEOF(QUERY(it <* item | ...)) = 0`
- STEPcode's narrowing recognizes the pattern and narrows `item` to `set_representation_item`
- The QUERY can now iterate over the narrowed type
### Solution 2: TREAT Expression (Standards-Compliant)
The ISO 10303-11 standard provides the TREAT expression for explicit type narrowing:
**Code (TREAT version, line 34149)**:
```express
QUERY(it <* TREAT(item AS set_representation_item) | ...)
```
**How it works**:
- `TREAT(item AS set_representation_item)` explicitly narrows the SELECT type to the member type
- The QUERY can iterate over the result of TREAT, which is guaranteed to be `set_representation_item`
- No implicit narrowing needed - the intent is explicit in the code
## The Exact Difference
```diff
--- data/ap242/242_mim_lf.exp
+++ data/ap242/242_mim_lf_treat.exp
@@ -34146,7 +34146,7 @@
('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.GEOMETRIC_REPRESENTATION_ITEM' IN TYPEOF(item)) OR
(('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.SET_REPRESENTATION_ITEM' IN TYPEOF(item)) AND
(SIZEOF(QUERY(it
- <* item
+ <* TREAT(item AS set_representation_item)
| NOT (('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.MAPPED_ITEM' IN TYPEOF(it)) OR
('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.GEOMETRIC_REPRESENTATION_ITEM' IN
TYPEOF(it))))) =
```
**Change**: Single line change from `<* item` to `<* TREAT(item AS set_representation_item)`
## Testing Results
### Original Version (with Flow-Sensitive Narrowing)
```bash
./build/bin/exp2cxx data/ap242/242_mim_lf.exp /tmp/ap242_original_test
```
**Result**: ✅ Parses successfully, generates 5,626 C++ files
### TREAT Version (Standards-Compliant)
```bash
./build/bin/exp2cxx data/ap242/242_mim_lf_treat.exp /tmp/ap242_treat_test
```
**Result**: ✅ Parses successfully, generates 5,626 C++ files
### Output Comparison
Both versions generate identical output:
- Same number of entities
- Same entity relationships
- Same multiple inheritance warnings
- Identical "Finished writing files" status
## Verification
To verify both versions produce consistent output:
```bash
# Parse original version
mkdir -p /tmp/ap242_original
./build/bin/exp2cxx data/ap242/242_mim_lf.exp /tmp/ap242_original
# Parse TREAT version
mkdir -p /tmp/ap242_treat
./build/bin/exp2cxx data/ap242/242_mim_lf_treat.exp /tmp/ap242_treat
# Compare generated headers (should be identical except for file references)
diff /tmp/ap242_original/SdaiAP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.h \
/tmp/ap242_treat/SdaiAP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.h
```
## Implications
### For STEPcode Users
- **Current**: Both versions work due to flow-sensitive narrowing extension
- **Future**: TREAT version is more portable if other EXPRESS parsers are used
- **Recommended**: Use TREAT for new schemas to ensure standards compliance
### For STEPcode Development
- Flow-sensitive narrowing is a valuable usability extension
- TREAT expression provides standards-compliant alternative
- Both should continue to be supported for compatibility
### For Standards Compliance
- Original AP242 schema uses pattern that requires extension
- TREAT version is fully ISO 10303-11 compliant
- TREAT makes intent explicit and improves code clarity
## Related Documentation
- `doc/express-type-unwrapping.md` - Full documentation of TREAT and narrowing features
- `src/express/test/README_AP242_BASELINE.md` - Historical PE056 error documentation
- Test schemas:
- `test/unitary_schemas/flow_narrowing_test.exp` - Flow-sensitive narrowing examples
- `test/unitary_schemas/minimal_treat_test.exp` - TREAT expression examples
## Conclusion
This comparison demonstrates:
1. ✅ STEPcode's flow-sensitive narrowing successfully handles the original AP242 schema
2. ✅ TREAT expression provides the standards-compliant alternative
3. ✅ Both approaches produce identical, correct output
4. ✅ The single-line change makes the code more explicit and portable
The availability of both approaches gives users flexibility while maintaining standards compliance when needed.
-251
View File
@@ -1,251 +0,0 @@
# AP242 API v2 Output Benchmarks
This file records comparable measurements for the staged API v2 output
work. It is intended to make changes in generated output cost visible in
the commits which introduce them.
## Method
The measurements were made on 2026-08-02 with GCC 13.3.0 and C++11.
The schema under test was BRL-CAD's `ap242e4.exp` conversion schema.
The real exchange-file workload was the NIST STC 09 ASME AP242 edition
4 sample, `nist_stc_09_asme1_ap242-e4.stp`.
The generator used `--late-bound`, the default 64-entity and 8-type chunk
limits, and a release STEPcode build. Compilation used `-O2 -fPIC` and two
concurrent compiler processes. Generated-output counts include `.cc`, `.h`,
and `.cmake` files through directory depth two. The baseline is commit
`fa2758c5` before recommendations 1--4.
## Results
| Measurement | Baseline | Recommendations 1--4 | Change |
|---|---:|---:|---:|
| Generated files | 5,719 | 905 | -84.2% |
| Generated lines | 254,220 | 123,552 | -51.4% |
| Generated bytes | 13,942,523 | 9,804,680 | -29.7% |
| Entity leaf files | 4,814 | 0 | -100.0% |
| Generation wall time | 2.74 s | 0.56 s | -79.6% |
| Generation peak RSS | 109,024 KiB | 109,280 KiB | +0.2% |
| Compile/link wall time | 157.68 s | 37.02 s | -76.5% |
| Compile/link user time | 277.75 s | 66.32 s | -76.1% |
| Compile/link peak RSS | 593,320 KiB | 199,156 KiB | -66.4% |
| Schema shared library | 9,956,640 B | 7,716,096 B | -22.5% |
| ELF relocations | 28,843 | 39,719 | +37.7% |
| Function symbols | 15,641 | 13,542 | -13.4% |
| Read/write wall time | 0.26 s | 0.25 s | -3.8% |
| Read/write peak RSS | 88,732 KiB | 85,040 KiB | -4.2% |
The relocation increase is caused by the stable module-ID tables referring
to descriptor slots. It is recorded here because the packed schema image
stage is expected to remove most of that cost.
## Recommendations 1--4
This stage adds stable entity, type, and attribute IDs through `SchemaModule`,
makes compatibility entity names opt-in for late-bound output, moves schema
rules and complex-entity support to runtime-consumed tables, and writes late
entity metadata directly to bounded chunks instead of creating 4,814 leaf
files.
The real AP242 exchange-file check created and validated 10,609 instances
with zero errors and zero warnings. Its 949,685-byte rewritten Part 21 file
matched the baseline apart from the expected `FILE_NAME` timestamp.
## Recommendation 5
This stage resolves each late-bound entity's flattened attribute layout once
after schema initialization. Instance construction then follows descriptor
and index records directly instead of recursively walking supertypes and
repeating attribute-name searches. The cache is external to
`EntityDescriptor`, so its object layout and the API v1 ABI are unchanged.
The construction benchmark uses the 1,531 `DIRECTION` instances in the real
exchange file and repeats that population 1,000 times. This isolates the
work changed by this stage while retaining a type and frequency from the
AP242 workload. Results are the median of three runs.
| Measurement | Recommendations 1--4 | Recommendation 5 | Change |
|---|---:|---:|---:|
| 1,531,000 entity constructions | 0.84 s | 0.63 s | -25.0% |
| Construction user time | 0.82 s | 0.61 s | -25.6% |
| Construction peak RSS | 68,956 KiB | 69,600 KiB | +0.9% |
| 20 full read/write runs | 4.90 s | 4.91 s | no measurable change |
| Full read/write peak RSS | 85,164 KiB | 85,732 KiB | +0.7% |
| `libstepcore` size | 640,936 B | 651,312 B | +1.6% |
The complete exchange-file check still created and validated 10,609
instances with zero errors and zero warnings. Its rewritten file remained
949,685 bytes and differed from the previous stage only in the expected
`FILE_NAME` timestamp. Generated schema file counts, source size, and the
schema shared library are unchanged because this is a shared-runtime change.
## Recommendation 6
This stage replaces the generated `SchemaModuleSlot` pointer arrays with a
16-byte, relocation-free `SchemaModuleImage`. Shared initialization helpers
capture descriptor pointers in stable generated-ID order and transfer those
vectors to `SchemaModule` after initialization. The older slot-based entry
point remains available for existing generated API v2 code.
Source and binary measurements compare recommendation 5 with the packed
image. Compile times use matching clean CMake builds with two compiler
processes. Read/write times are medians from paired 20-run batches.
| Measurement | Recommendation 5 | Recommendation 6 | Change |
|---|---:|---:|---:|
| Generated files | 905 | 905 | unchanged |
| Generated lines | 123,552 | 117,046 | -5.3% |
| Generated bytes | 9,804,680 | 9,060,249 | -7.6% |
| Schema module source | 808,907 B | 64,367 B | -92.0% |
| Schema module source lines | 7,280 | 773 | -89.4% |
| Compile/link wall time | 41.38 s | 41.49 s | no measurable change |
| Compile/link peak RSS | 208,312 KiB | 208,188 KiB | -0.1% |
| Schema shared library | 7,728,384 B | 7,470,304 B | -3.3% |
| ELF relocations | 39,719 | 33,221 | -16.4% |
| 20 full read/write runs | 5.10 s | 5.07 s | -0.6% |
| Full read/write peak RSS | 85,736 KiB | 85,572 KiB | -0.2% |
| `libstepcore` size | 651,312 B | 661,088 B | +1.5% |
The image removes 6,498 per-descriptor pointer relocations. The shared
runtime grows by 9,776 bytes once, while each AP242 schema library is 258,080
bytes smaller. Generated API v1 output and the conventional public entity
classes remain unchanged.
The complete exchange-file check again created and validated 10,609
instances with zero errors and zero warnings. Its 949,685-byte rewrite
differed from recommendation 5 only in the expected `FILE_NAME` timestamp.
## Recommendation 7
This stage replaces the remaining generated descriptor procedures with one
bounded, offset-based schema image. The shared loader validates every array,
string, range, descriptor reference, schema binding, and complex-entity tree
before it changes the registry. It then constructs the descriptor graph with
an explicit per-load context; the process-global capture path remains only for
older generated API v2 code. Complex-entity metadata uses the same packed
representation and validation model.
Source and binary measurements compare recommendation 6 with the complete
descriptor image. Compile times use clean CMake builds with two compiler
processes. Read/write times use matching 20-run batches.
| Measurement | Recommendation 6 | Recommendation 7 | Change |
|---|---:|---:|---:|
| Generated files | 905 | 865 | -4.4% |
| Generated lines | 117,046 | 86,400 | -26.2% |
| Generated bytes | 9,060,249 | 4,865,657 | -46.3% |
| Entity initialization chunks | 38 | 0 | -100.0% |
| Compile/link wall time | 41.49 s | 18.71 s | -54.9% |
| Compile/link peak RSS | 208,188 KiB | 208,528 KiB | +0.2% |
| Schema shared library | 7,470,304 B | 3,503,352 B | -53.1% |
| ELF relocations | 33,221 | 9,620 | -71.0% |
| 20 full read/write runs | 5.07 s | 4.97 s | -2.0% |
| Full read/write peak RSS | 85,572 KiB | 82,916 KiB | -3.1% |
The image removes the 2,407 generated entity initialization functions and
23,601 additional relocations. The generated schema library is 3,966,952
bytes smaller, while its existing typed SELECT and enumeration factories
remain available for this transitional stage.
The complete exchange-file check created and validated 10,609 instances with
zero errors and zero warnings. Its 949,685-byte rewrite retained the same
semantic result as recommendation 6.
## Recommendations 8 and 9
This stage makes the compact late-bound output independent of generated type
classes. Shared descriptor-driven implementations now construct SELECT,
enumeration, and aggregate values, including nested values and BOOLEAN or
LOGICAL aliases. Enumeration elements and renamed USE or REFERENCE items are
retained in the packed image. The conventional early-bound API v1 and API v2
paths still emit their schema-specific type classes.
The generated schema header is now a dependency-bounded consumer interface.
It contains stable entity, type, and attribute IDs plus `SchemaModule` lookup
functions, and includes only `schemaModule.h`. Runtime and model-construction
declarations remain in the internal `schema.h` umbrella.
| Measurement | Recommendation 7 | Recommendations 8--9 | Change |
|---|---:|---:|---:|
| Generated files | 865 | 10 | -98.8% |
| Generated lines | 86,400 | 54,839 | -36.5% |
| Generated bytes | 4,865,657 | 3,303,993 | -32.1% |
| Type leaf files | 802 | 0 | -100.0% |
| Type initialization chunks | 51 | 0 | -100.0% |
| Compile/link wall time | 18.71 s | 1.21 s | -93.5% |
| Compile/link peak RSS | 208,528 KiB | 126,580 KiB | -39.3% |
| Schema shared library | 3,503,352 B | 2,178,296 B | -37.8% |
| ELF relocations | 9,620 | 49 | -99.5% |
| Exported function symbols | 4,647 | 8 | -99.8% |
| Public header preprocessed bytes | 2,384,191 | 635,945 | -73.3% |
| 20 full read/write runs | 4.97 s | 4.91 s | -1.2% |
| Full read/write peak RSS | 82,916 KiB | 82,304 KiB | -0.7% |
The complete exchange-file check again created and validated 10,609
instances with zero errors and zero warnings, and wrote the same 949,685-byte
semantic result. Runtime unit coverage separately exercises generic SELECT,
enumeration, aggregate, malformed-image, and packed rename behavior.
## Recommendation 10
This stage adds an opt-in `structural` metadata profile for late-bound API
version 2. The default `full` profile is unchanged. Structural images keep
the descriptor graph needed to construct, read, write, and inspect entity,
attribute, type, aggregate, enumeration, SELECT, inverse, and renamed values.
They omit EXPRESS descriptions, WHERE and UNIQUE rules, schema rule and
algorithm text, supertype statements, derived expressions, and symbolic
aggregate-bound text.
The source and library measurements below compare matching fresh output from
the two profiles. Compile times use clean CMake builds with one compiler
process; read/write times use matching 20-run batches.
| Measurement | Full metadata | Structural metadata | Change |
|---|---:|---:|---:|
| Generated files | 10 | 10 | unchanged |
| Generated lines | 54,839 | 29,993 | -45.3% |
| Generated bytes | 3,304,007 | 1,525,897 | -53.8% |
| Packed schema source | 2,612,413 B | 834,303 B | -68.1% |
| Generation wall time | 0.48 s | 0.41 s | -14.6% |
| Compile/link wall time | 2.08 s | 2.03 s | -2.4% |
| Compile/link peak RSS | 126,784 KiB | 118,220 KiB | -6.8% |
| Schema shared library | 2,178,296 B | 720,120 B | -66.9% |
| ELF relocations | 49 | 49 | unchanged |
| 20 full read/write runs | 4.76 s | 4.71 s | -1.1% |
| Full read/write peak RSS | 82,276 KiB | 78,900 KiB | -4.1% |
The structural profile created and validated all 10,609 instances in the
real exchange file with zero errors and zero warnings. It wrote the same
949,685-byte semantic result as the full profile.
## Recommendation 11
This stage writes each generated file to a sibling temporary file and replaces
the destination only when its content changes. A compact generated-file
manifest supports safe cleanup when an option change makes old entity, type,
or unity files obsolete; files not named by the previous manifest are left
alone. The manifest itself is also content-stable.
The deterministic-output audit also found that nonliteral aggregate bounds
were being read through the integer member of the expression union. Packed
images now emit those bounds as expression records, eliminating process-address
values from generated AP242 source as well as correcting the metadata kind.
| Measurement after identical AP242 generation | Rewrite all | Stable output | Change |
|---|---:|---:|---:|
| Changed schema source/header timestamps | 10 of 10 | 0 of 10 | -100.0% |
| Changed manifest timestamps | n/a | 0 of 1 | stable |
| Generation wall time | 0.41 s | 0.40 s | no overhead |
| Following CMake build wall time | 2.01 s | 0.06 s | -97.0% |
| Following build peak RSS | 118,108 KiB | 18,432 KiB | -84.4% |
The AP242 manifest is 390 bytes. Switching the focused regression schema
from early-bound API version 2 to compact late-bound output removes all stale
entity, type, and unity files and their empty directories while preserving an
unrelated file in the output directory.
The real exchange-file check still created and validated all 10,609 instances
with zero errors and zero warnings. Its rewritten result remained 949,685
bytes.
-367
View File
@@ -1,367 +0,0 @@
# EXPRESS Type Unwrapping and Narrowing
## Overview
This document describes the type unwrapping and narrowing features implemented in STEPcode's EXPRESS compiler. These features enable proper type checking and semantic analysis for aggregate types and SELECT type narrowing.
**Note:** Some features described here are extensions beyond the ISO 10303-11 standard and are explicitly marked as such.
## Deep Aggregate Unwrapping
### Background
In EXPRESS, aggregate types (ARRAY, LIST, SET, BAG) can be nested and wrapped in type definitions. For semantic analysis and type checking, the compiler often needs to "unwrap" these layers to access the underlying element type.
### Shallow vs Deep Type Checking
#### Shallow Aggregate Check: `TYPEis_aggregate`
The macro `TYPEis_aggregate(t)` performs a **shallow** check by testing if `t->u.type->body->base` is non-NULL. This indicates the type has a base type, which is characteristic of aggregate types.
```c
#define TYPEis_aggregate(t) ((t)->u.type->body->base)
```
**Important:** This is a shallow check and does not follow type definition chains. It returns true if the immediate type structure has a base type.
**Use when:**
- You need a quick check if a type is directly an aggregate
- You're working with the immediate type structure
- Performance is critical and deep unwrapping isn't needed
#### Deep Aggregate Unwrapping: `TYPEget_nonaggregate_base_type`
The function `TYPEget_nonaggregate_base_type(Type t)` performs **deep unwrapping** by iteratively following the chain of aggregate base types until reaching a non-aggregate type.
```express
TYPE int_list = LIST OF INTEGER;
TYPE named_int_list = int_list; -- typedef chain
TYPE set_of_lists = SET OF named_int_list;
```
For `set_of_lists`:
- `TYPEis_aggregate()` → true (immediate check)
- `TYPEget_nonaggregate_base_type()` → INTEGER (unwraps through SET → LIST → INTEGER)
**Use when:**
- Comparing element types across different aggregate wrappers
- Type resolution requires the ultimate element type
- Semantic checking needs to validate deep type compatibility
### Deep Unwrapping Implementation
```c
Type TYPEget_nonaggregate_base_type( Type t ) {
while( TYPEis_aggregate( t ) ) {
t = t->u.type->body->base;
}
return t;
}
```
This function safely handles:
- Nested aggregates (SET OF LIST OF ...)
- Type definition chains
- Mixed aggregate types
### Aggregate Type Comparison: `TYPE_retrieve_aggregate`
For SELECT types containing multiple aggregate members, `TYPE_retrieve_aggregate()` validates that all aggregate members share the same element type.
```express
TYPE item_a = SET OF INTEGER;
TYPE item_b = LIST OF INTEGER;
TYPE my_select = SELECT(item_a, item_b); -- Valid: both have INTEGER elements
```
The function:
1. Iterates through SELECT members
2. Identifies which are aggregates
3. Unwraps typedef chains to find element types
4. Returns common element type or NULL if incompatible
## TREAT Expression Semantics
### ISO 10303-11 Standard Syntax
The TREAT expression is defined in ISO 10303-11 as:
```express
TREAT(expression AS type_identifier)
```
**Purpose:** Explicitly narrow a SELECT type to one of its member types.
### STEPcode Implementation
STEPcode implements TREAT as specified in ISO 10303-11 with the following semantics:
#### Type Resolution
1. **Operand Resolution:** The expression being narrowed is resolved first
```c
EXPresolve( e->e.op1, s, Type_Dont_Care );
operand_type = e->e.op1->return_type;
```
2. **Target Type Lookup:** The target type identifier is resolved via scope lookup
```c
target_type = (Type)SCOPEfind( s, e->symbol.name, SCOPE_FIND_TYPE );
```
3. **Type Compatibility:** The implementation validates that narrowing is semantically valid
- For SELECT operands: Verifies target is a member type
- For other types: Allows permissively (may emit warnings)
4. **Return Type:** The expression's return type becomes the target type
```c
return target_type; /* Not Type_Generic */
```
#### Error Handling
**Clear errors with location information:**
- **Missing operand:** `SYNTAX` error - "TREAT expression missing operand"
- **Missing target type:** `SYNTAX` error - "TREAT expression missing target type"
- **Undefined type:** `UNDEFINED_TYPE` error with the type name
- **Type mismatch:** Currently permissive (no error, future: may warn)
All errors use `ERRORreport_with_symbol()` which provides:
- File name and line number
- Symbol context
- Descriptive error message
#### Example Usage
```express
TYPE attachment = SELECT(nail, screw);
END_TYPE;
FUNCTION get_length(item : attachment) : REAL;
LOCAL
n : nail;
END_LOCAL;
IF ('EXAMPLE.NAIL' IN TYPEOF(item)) THEN
n := TREAT(item AS nail); -- Narrows SELECT to nail
RETURN n.length;
END_IF;
RETURN 0.0;
END_FUNCTION;
```
### Grammar Integration
The TREAT syntax is integrated into the EXPRESS parser grammar as a unary expression:
```yacc
unary_expression ::= TOK_TREAT TOK_LEFT_PAREN expression TOK_AS
TOK_IDENTIFIER TOK_RIGHT_PAREN
```
Key points:
- `TOK_TREAT`: Recognized as a keyword
- Creates unary expression with `OP_TREAT` operator
- Operand stored in `op1`
- Target type name stored in `symbol` field
## Flow-Sensitive SELECT Narrowing
**Extension Status:** This is a **non-standard extension** that enhances type safety for SELECT types.
### Background
EXPRESS WHERE clauses often use TYPEOF guards to check SELECT types before accessing member-specific attributes. Flow-sensitive narrowing automatically narrows SELECT types within the scope of such guards.
### Pattern Recognition
The narrowing system recognizes this pattern:
```express
'TypeName' IN TYPEOF(variable)
```
When this pattern appears in an AND conjunction, the variable is narrowed to `TypeName` for subsequent expressions in the conjunction.
### Implementation Architecture
#### Refinement Context
A **refinement context** tracks active type narrowings during expression resolution:
```c
typedef struct RefinementContext_ {
Refinement refinements; /* Linked list of variable → type mappings */
struct RefinementContext_ *previous; /* Stack of contexts */
} *RefinementContext;
RefinementContext active_refinements = NULL; /* Thread-local global */
```
#### Pattern Matching
The function `match_typeof_guard()` identifies guard patterns:
1. Expression is `IN` operator
2. Left operand is string literal (type name)
3. Right operand is `TYPEOF(identifier)`
4. Identifier resolves to a variable
#### Refinement Collection
The function `collect_refinements_from_conjunction()` recursively walks AND expressions:
1. Recursively descends into AND nodes
2. Matches TYPEOF guard patterns at leaves
3. Validates narrowing is semantically correct:
- Variable must have SELECT type
- Target type must be SELECT member (validated via `is_select_member()`)
4. Returns linked list of valid refinements
#### Application
In `EXPresolve_op_and()`:
```c
Type EXPresolve_op_and(Expression e, Scope s) {
EXPresolve(e->e.op1, s, Type_Dont_Care); /* Resolve LHS normally */
Refinement refs = collect_refinements_from_conjunction(e->e.op1, s);
if (refs) {
/* Create temporary context */
struct RefinementContext_ ctx;
ctx.refinements = refs;
ctx.previous = active_refinements;
active_refinements = &ctx;
EXPresolve(e->e.op2, s, Type_Dont_Care); /* Resolve RHS with narrowing */
/* Restore previous context */
active_refinements = ctx.previous;
free_refinements(refs);
} else {
EXPresolve(e->e.op2, s, Type_Dont_Care);
}
return Type_Logical;
}
```
### Behavior Scope
**What is narrowed:**
- Variables with SELECT type
- Within RHS of AND expressions
- Where LHS contains TYPEOF guard
**What is NOT narrowed:**
- OR expressions (conservative - doesn't extract from disjunction)
- NOT expressions (conservative - doesn't extract from negation)
- Other boolean operators
- Variables not guarded by TYPEOF
**Rationale:** Conservative approach prevents false narrowing in cases where the guard may not hold.
### Limitations
1. **Single-level context:** Only immediate AND RHS is narrowed, not deeply nested scopes
2. **No cross-statement narrowing:** Limited to expression-level scope
3. **AND-only:** Does not propagate through OR/NOT (conservative)
4. **Pattern-based:** Only recognizes exact `'Type' IN TYPEOF(var)` pattern
### Example
```express
ENTITY test_entity;
item : target; -- target is SELECT(set_representation_item, simple_int)
WHERE
wr1: ('SCHEMA.SET_REPRESENTATION_ITEM' IN TYPEOF(item)) AND
(SIZEOF(item) > 0); -- item narrowed to set_representation_item
END_ENTITY;
```
Without narrowing, `SIZEOF(item)` would fail (can't take SIZEOF of SELECT). With narrowing, `item` is known to be an aggregate, so `SIZEOF` is valid.
## Memory Management
### Refinement Lifecycle
1. **Collection:** `collect_refinements_from_conjunction()` allocates refinement nodes
2. **Usage:** Active during RHS expression resolution only
3. **Cleanup:** `free_refinements()` called after RHS resolution completes
### Context Stack Model
The implementation uses a **stack-based context model** rather than deep copying:
- `RefinementContext` has `previous` pointer forming a stack
- New contexts pushed onto stack with `active_refinements = &ctx`
- Restored with `active_refinements = ctx.previous`
- No deep copying of refinement data
**Memory safety:**
- Refinement nodes allocated individually
- Freed immediately after use
- No dangling pointers (stack-local contexts)
- No memory leaks (verified by code inspection)
## Testing
### Test Coverage
**TREAT expression tests:**
- `test/unitary_schemas/minimal_treat_test.exp` - Basic TREAT usage
- `test/unitary_schemas/test_treat_real.exp` - Nested SELECT types
- `test/unitary_schemas/treat_expression.exp` - TREAT in WHERE clauses
**Flow-sensitive narrowing tests:**
- `test/unitary_schemas/flow_narrowing_test.exp` - AND-based narrowing
- `test/unitary_schemas/select_aggregate_test.exp` - SELECT of aggregates
**Production schema comparison:**
- `data/ap242/242_mim_lf.exp` - Original AP242 with flow-sensitive narrowing
- `data/ap242/242_mim_lf_treat.exp` - TREAT-based standards-compliant version
- `test/compare_ap242_versions.sh` - Automated comparison script
See `doc/ap242-comparison.md` for detailed analysis of the AP242 schema comparison.
### AP242 Compatibility
The implementation is validated against the AP242 schema, ensuring:
- Large-scale schema parsing succeeds
- Complex type hierarchies handled correctly
- Production schema compatibility
**AP242 Schema Versions:**
- `data/ap242/242_mim_lf.exp` - Original schema using flow-sensitive narrowing extension
- `data/ap242/242_mim_lf_treat.exp` - Standards-compliant version using TREAT expression
Both versions parse successfully and produce identical output. See `doc/ap242-comparison.md` for detailed analysis.
## Standards Compliance Notes
### ISO 10303-11 Compliance
**Fully compliant:**
- TREAT expression syntax and semantics
- Aggregate type definitions
- SELECT type definitions
- Standard type resolution rules
**Extensions (non-standard):**
- Flow-sensitive type narrowing in AND expressions
- Permissive TREAT type checking (warns vs errors)
### Extension Philosophy
STEPcode's extensions follow these principles:
1. **Conservative:** Only apply when semantically safe
2. **Permissive:** Prefer warnings over errors where reasonable
3. **Explicit:** Document extensions clearly
4. **Compatible:** Don't break standard-compliant schemas
Extensions are designed to enhance usability while maintaining backward compatibility with ISO 10303-11 compliant EXPRESS schemas.
+1 -33
View File
@@ -45,11 +45,6 @@ EXPRESS code into C++ source code. The C++ source code is generated
in files in the directory in which exp2cxx was run. The files are
named according to the schema names in the input EXPRESS file.
Generated files are replaced only when their content changes. exp2cxx records
the files it owns in `.exp2cxx-manifest`; a later run removes obsolete files
from that manifest while leaving unrelated files in the output directory
untouched.
.SH OPTIONS
.TP
.B -s|S
@@ -62,34 +57,6 @@ Generates C++ classes for use with CORBA (Orbix).
.B -l|L
Prints logging code in the generated C++ classes.
.TP
.B -k entity-chunk-size[:type-chunk-size]
Limits the number of generated schema objects in each deterministic unity
translation unit. A single value applies to both entity and type chunks.
.TP
.B -V 1|2, --api-version 1|2
Selects the generated C++ API. Version 1 is the source-compatible default.
Version 2 emits compact SELECT classes, table-driven schema initialization, and
dependency-bounded entity headers backed by shared runtime code. Version 2
clients include the individual entity headers they use; schema.h does not
include every entity class definition.
.TP
.B -T, --late-bound
Selects API version 2 and omits generated early-bound C++ entity classes.
Entity instances are constructed at runtime from schema descriptors. This mode
is intended for conversion and inspection applications which do not require the
conventional generated entity API.
.TP
.B --compat-names
Retains the generated entity-name aliases in late-bound output. Normal
late-bound API v2 output uses schema module IDs instead and omits these aliases.
.TP
.B --metadata full|structural
Selects the generated schema metadata profile. Full is the default and
retains EXPRESS descriptions, constraints, and executable schema text.
Structural is available with late-bound API version 2; it retains the entity,
attribute, type, aggregate, enumeration, SELECT, inverse, and rename graph
needed by conversion tools while omitting descriptive and constraint text.
.TP
.B -v
Produces a version description.
.TP
@@ -194,3 +161,4 @@ appropriate file to download).
.SH BUGS
See fedex(1).
+7 -1
View File
@@ -31,6 +31,7 @@ set(SC_IS_SUBBUILD TRUE)
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif(NOT DEFINED CMAKE_BUILD_TYPE)
set(SC_BUILD_TYPE ${CMAKE_BUILD_TYPE})
# Path to STEPcode
set(STEPCODE_BUILD_DIR ${CMAKE_BINARY_DIR}/sc CACHE PATH "STEPcode build subdir")
@@ -50,13 +51,18 @@ endif(NOT EXISTS ${SCHEMA_FILE})
get_filename_component(SCHEMA_SN ${SCHEMA_FILE} NAME)
string(REGEX REPLACE "\(.*\).[Ee][Xx][Pp]" "sdai_\\1" SCHEMA_LINK_NAME ${SCHEMA_SN})
set(STEPCODE_LIBRARIES stepcore stepeditor stepdai steputils ${SCHEMA_LINK_NAME})
set(STEPCODE_LIBRARIES base stepcore stepeditor stepdai steputils ${SCHEMA_LINK_NAME})
# Add STEPCode project to CMake build.
add_subdirectory(${STEPCODE_ROOT_DIR} "${CMAKE_CURRENT_BINARY_DIR}/sc" EXCLUDE_FROM_ALL)
# Set up STEPcode include directories.
set(STEPCODE_INCLUDE_DIR
${STEPCODE_ROOT_DIR}/src/base
${STEPCODE_ROOT_DIR}/src/clstepcore
${STEPCODE_ROOT_DIR}/src/cldai
${STEPCODE_ROOT_DIR}/src/clutils
${STEPCODE_ROOT_DIR}/src/cleditor
${STEPCODE_BUILD_DIR}/include
${STEPCODE_ROOT_DIR}/include
${CMAKE_BINARY_DIR}
@@ -19,6 +19,7 @@ INCLUDE( External_STEPCode )
IF(NOT WIN32)
set( STEPCODE_LIBRARIES
${STEPCODE_INSTALL_DIR}/lib/libbase.a
${STEPCODE_INSTALL_DIR}/lib/libstepcore.a
${STEPCODE_INSTALL_DIR}/lib/libstepeditor.a
${STEPCODE_INSTALL_DIR}/lib/libstepdai.a
@@ -27,6 +28,7 @@ IF(NOT WIN32)
)
ELSE()
set( STEPCODE_LIBRARIES
${STEPCODE_INSTALL_DIR}/lib/libbase.lib
${STEPCODE_INSTALL_DIR}/lib/libstepcore.lib
${STEPCODE_INSTALL_DIR}/lib/libstepeditor.lib
${STEPCODE_INSTALL_DIR}/lib/libstepdai.lib
@@ -42,6 +44,7 @@ MESSAGE( STATUS "STEPCODE_INSTALL_DIR: " ${STEPCODE_INSTALL_DIR} )
set( STEPCODE_INCLUDE_DIR
${STEPCODE_INSTALL_DIR}/include/stepcode
${STEPCODE_INSTALL_DIR}/include/stepcode/base
${STEPCODE_INSTALL_DIR}/include/stepcode/clstepcore
${STEPCODE_INSTALL_DIR}/include/stepcode/cldai
${STEPCODE_INSTALL_DIR}/include/stepcode/clutils
@@ -4,9 +4,9 @@ ExternalProject_Add( STEPCODE
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_BUILD_TYPE=Debug
-DSC_BUILD_TYPE=Debug
-DSC_BUILD_SCHEMAS=ap203/ap203.exp
-DBUILD_STATIC_LIBS=ON
-DSC_BUILD_STATIC_LIBS=ON
-DSC_PYTHON_GENERATOR=OFF
-DSC_INSTALL_PREFIX:PATH=<INSTALL_DIR>
)
+8 -8
View File
@@ -49,15 +49,15 @@
// $./AP203Minimum
// AP203Minimum outfile.stp
#include <cleditor/STEPfile.h>
#include <clstepcore/sdai.h>
#include <clstepcore/STEPattribute.h>
#include <clstepcore/ExpDict.h>
#include <clstepcore/Registry.h>
#include <clutils/errordesc.h>
#include <STEPfile.h>
#include <sdai.h>
#include <STEPattribute.h>
#include <ExpDict.h>
#include <Registry.h>
#include <errordesc.h>
#include <clstepcore/STEPcomplex.h>
#include <cleditor/SdaiHeaderSchema.h>
#include <STEPcomplex.h>
#include <SdaiHeaderSchema.h>
#include "schema.h"
+1
View File
@@ -15,6 +15,7 @@
#cmakedefine HAVE_IO_H 1
#cmakedefine SC_TRACE_FPRINTF 1
#cmakedefine SC_MEMMGR_ENABLE_CHECKS 1
#cmakedefine HAVE_ABS 1
#cmakedefine HAVE_MEMCPY 1
-6
View File
@@ -37,12 +37,6 @@ install(FILES ordered_attrs.h
install(FILES ${SC_BINARY_DIR}/${INCLUDE_DIR}/config.h
DESTINATION ${INCLUDE_DIR}/stepcode)
add_subdirectory(cldai)
add_subdirectory(cleditor)
add_subdirectory(cllazyfile)
add_subdirectory(clstepcore)
add_subdirectory(clutils)
# Local Variables:
# tab-width: 8
# mode: cmake
-24
View File
@@ -1,24 +0,0 @@
set(DAI_HDRS
sdaiApplication_instance_set.h
sdaiBinary.h
sdaiDaObject.h
sdaiEntity_extent.h
sdaiEntity_extent_set.h
sdaiEnum.h
sdaiModel_contents.h
sdaiModel_contents_list.h
sdaiObject.h
sdaiSession_instance.h
sdaiString.h
)
install(FILES ${DAI_HDRS}
DESTINATION ${INCLUDE_DIR}/stepcode/cldai)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
-20
View File
@@ -1,20 +0,0 @@
set(EDITOR_HDRS
STEPfile.h
cmdmgr.h
editordefines.h
SdaiHeaderSchema.h
SdaiHeaderSchemaClasses.h
SdaiSchemaInit.h
seeinfodefault.h
)
install(FILES ${EDITOR_HDRS}
DESTINATION ${INCLUDE_DIR}/stepcode/cleditor)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
-27
View File
@@ -1,27 +0,0 @@
set(LAZY_HDRS
headerSectionReader.h
lazyFileReader.h
lazyP21DataSectionReader.h
p21HeaderSectionReader.h
lazyDataSectionReader.h
lazyInstMgr.h
lazySupport.h
lazyTypes.h
sectionReader.h
instMgrHelper.h
judy.h
judyL2Array.h
judyLArray.h
judyS2Array.h
judySArray.h
)
install(FILES ${LAZY_HDRS}
DESTINATION ${INCLUDE_DIR}/stepcode/cllazyfile)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
-131
View File
@@ -1,131 +0,0 @@
#ifndef LAZYSUPPORT_H
#define LAZYSUPPORT_H
#include <cstddef>
#include <functional>
#include <iosfwd>
#include <string>
#include <vector>
#include "cllazyfile/lazyTypes.h"
#include "sc_export.h"
class lazyInstMgr;
class SDAI_Application_instance;
enum LazyDiagnosticSeverity {
LAZY_DIAGNOSTIC_INFO,
LAZY_DIAGNOSTIC_WARNING,
LAZY_DIAGNOSTIC_ERROR,
LAZY_DIAGNOSTIC_FATAL
};
struct SC_LAZYFILE_EXPORT LazyDiagnostic {
LazyDiagnosticSeverity severity;
instanceID entity;
std::string type;
lazyFileOffset offset;
uint64_t line;
std::string attribute;
std::string message;
uint64_t occurrences;
LazyDiagnostic(): severity( LAZY_DIAGNOSTIC_INFO ), entity( 0 ), offset( 0 ),
line( 0 ), occurrences( 1 ) {}
};
struct SC_LAZYFILE_EXPORT LazyScanProgress {
fileID file;
lazyFileOffset offset;
lazyFileOffset fileSize;
uint64_t instancesScanned;
LazyScanProgress(): file( 0 ), offset( 0 ), fileSize( 0 ), instancesScanned( 0 ) {}
};
struct SC_LAZYFILE_EXPORT LazyCacheStatistics {
uint64_t instancesScanned;
uint64_t instancesLoaded;
uint64_t instancesPinned;
uint64_t cacheHighWater;
uint64_t cacheHits;
uint64_t cacheMisses;
uint64_t materializations;
uint64_t evictions;
uint64_t activeBatches;
uint64_t dataSections;
uint64_t residentSourceBytes;
uint64_t sourceBytesHighWater;
bool cancelled;
LazyCacheStatistics(): instancesScanned( 0 ), instancesLoaded( 0 ), instancesPinned( 0 ),
cacheHighWater( 0 ), cacheHits( 0 ), cacheMisses( 0 ), materializations( 0 ),
evictions( 0 ), activeBatches( 0 ), dataSections( 0 ), residentSourceBytes( 0 ),
sourceBytesHighWater( 0 ), cancelled( false ) {}
};
typedef std::function<void ( const LazyScanProgress & )> LazyProgressCallback;
typedef std::function<bool ()> LazyCancellationCallback;
typedef std::function<void ( const LazyDiagnostic & )> LazyDiagnosticCallback;
/** A non-owning, zero-copy view of an indexed instance-ID vector.
* The view remains valid until another file is scanned by the manager.
*/
class SC_LAZYFILE_EXPORT LazyInstanceIdView {
public:
typedef instanceRefs::const_iterator const_iterator;
LazyInstanceIdView(): _ids( 0 ) {}
explicit LazyInstanceIdView( const instanceRefs * ids ): _ids( ids ) {}
const_iterator begin() const;
const_iterator end() const;
size_t size() const;
bool empty() const;
instanceID operator[]( size_t index ) const;
private:
const instanceRefs * _ids;
};
/** A dependency closure materialized and pinned for a bounded operation.
* STEPcode parsing remains single-threaded. Detach immutable conversion data
* before releasing the batch or passing work to another thread.
*/
class SC_LAZYFILE_EXPORT LazyInstanceBatch {
public:
LazyInstanceBatch();
~LazyInstanceBatch();
LazyInstanceBatch( LazyInstanceBatch && other );
LazyInstanceBatch & operator=( LazyInstanceBatch && other );
LazyInstanceBatch( const LazyInstanceBatch & ) = delete;
LazyInstanceBatch & operator=( const LazyInstanceBatch & ) = delete;
bool valid() const;
void release();
const std::vector<instanceID> & roots() const;
const std::vector<instanceID> & instances() const;
SDAI_Application_instance * get( instanceID id ) const;
private:
friend class lazyInstMgr;
LazyInstanceBatch( lazyInstMgr * manager, const std::vector<instanceID> & roots,
const std::vector<instanceID> & instances );
lazyInstMgr * _manager;
std::vector<instanceID> _roots;
std::vector<instanceID> _instances;
};
/** Adapter preserving a stream-oriented diagnostic presentation. */
class SC_LAZYFILE_EXPORT LazyTextDiagnosticAdapter {
public:
explicit LazyTextDiagnosticAdapter( std::ostream & stream );
void operator()( const LazyDiagnostic & diagnostic ) const;
private:
std::ostream * _stream;
};
#endif // LAZYSUPPORT_H
-72
View File
@@ -1,72 +0,0 @@
set(CORE_HDRS
aggrTypeDescriptor.h
attrDescriptor.h
attrDescriptorList.h
baseType.h
complexSupport.h
create_Aggr.h
derivedAttribute.h
dictSchema.h
dictdefs.h
dictionaryInstance.h
dispnode.h
dispnodelist.h
entityDescriptor.h
entityDescriptorList.h
enumTypeDescriptor.h
ExpDict.h
explicitItemId.h
globalRule.h
implicitItemId.h
instmgr.h
interfaceSpec.h
interfacedItem.h
inverseAttribute.h
inverseAttributeList.h
mgrnode.h
mgrnodearray.h
mgrnodelist.h
needFunc.h
read_func.h
realTypeDescriptor.h
Registry.h
schRename.h
schemaInit.h
schemaModule.h
sdai.h
sdaiApplication_instance.h
sdaiSelect.h
selectTypeDescriptor.h
SingleLinkList.h
STEPaggregate.h
STEPaggrBinary.h
STEPaggrEntity.h
STEPaggrEnum.h
STEPaggrGeneric.h
STEPaggrInt.h
STEPaggrReal.h
STEPaggrSelect.h
STEPaggrString.h
STEPattribute.h
STEPattributeList.h
STEPcomplex.h
STEPinvAttrList.h
STEPundefined.h
stringTypeDescriptor.h
SubSuperIterators.h
typeDescriptor.h
typeDescriptorList.h
typeOrRuleVar.h
uniquenessRule.h
whereRule.h
)
install(FILES ${CORE_HDRS}
DESTINATION ${INCLUDE_DIR}/stepcode/clstepcore)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
-362
View File
@@ -1,362 +0,0 @@
#ifndef SCHEMAINIT_H
#define SCHEMAINIT_H
#include <stddef.h>
#include "sc_export.h"
#include "clstepcore/attrDescriptor.h"
#include "clstepcore/aggrTypeDescriptor.h"
#include "clstepcore/dictSchema.h"
#include "clstepcore/entityDescriptor.h"
#include "clstepcore/enumTypeDescriptor.h"
#include "clstepcore/selectTypeDescriptor.h"
#include "clstepcore/schemaModule.h"
class Derived_attribute;
class Inverse_attribute;
class ComplexCollect;
class Registry;
/** Compact records used by API v2 generated schema initialization. */
struct SC_CORE_EXPORT SchemaInitRecord {
Schema ** slot;
const char * name;
ModelContentsCreator modelContentsCreator;
};
struct SC_CORE_EXPORT EntityDescriptorInitRecord {
EntityDescriptor ** slot;
const char * name;
Schema ** schemaSlot;
Logical abstractEntity;
Logical externalMapping;
Creator creator;
};
struct SC_CORE_EXPORT EntitySupertypeInitRecord {
EntityDescriptor * supertype;
};
enum TypeDescriptorInitKind {
TypeDescriptorInit_Base,
TypeDescriptorInit_Enum,
TypeDescriptorInit_Select,
TypeDescriptorInit_Aggregate,
TypeDescriptorInit_Array,
TypeDescriptorInit_List,
TypeDescriptorInit_Set,
TypeDescriptorInit_Bag
};
struct SC_CORE_EXPORT TypeDescriptorInitRecord {
void * slot;
TypeDescriptorInitKind kind;
const char * name;
PrimitiveType fundamentalType;
Schema ** schemaSlot;
const char * description;
int uniqueElements;
SelectCreator selectCreator;
EnumCreator enumCreator;
AggregateCreator aggregateCreator;
TypeDescriptorInitRecord( TypeDescriptor ** descriptorSlot,
const char * typeName, PrimitiveType type,
Schema ** schema, const char * typeDescription );
TypeDescriptorInitRecord( EnumTypeDescriptor ** descriptorSlot,
const char * typeName, PrimitiveType type,
Schema ** schema, const char * typeDescription,
EnumCreator creator );
TypeDescriptorInitRecord( SelectTypeDescriptor ** descriptorSlot,
int unique, const char * typeName,
PrimitiveType type, Schema ** schema,
const char * typeDescription,
SelectCreator creator );
TypeDescriptorInitRecord( AggrTypeDescriptor ** descriptorSlot,
const char * typeName, PrimitiveType type,
Schema ** schema, const char * typeDescription,
AggregateCreator creator );
TypeDescriptorInitRecord( ArrayTypeDescriptor ** descriptorSlot,
const char * typeName, PrimitiveType type,
Schema ** schema, const char * typeDescription,
AggregateCreator creator );
TypeDescriptorInitRecord( ListTypeDescriptor ** descriptorSlot,
const char * typeName, PrimitiveType type,
Schema ** schema, const char * typeDescription,
AggregateCreator creator );
TypeDescriptorInitRecord( SetTypeDescriptor ** descriptorSlot,
const char * typeName, PrimitiveType type,
Schema ** schema, const char * typeDescription,
AggregateCreator creator );
TypeDescriptorInitRecord( BagTypeDescriptor ** descriptorSlot,
const char * typeName, PrimitiveType type,
Schema ** schema, const char * typeDescription,
AggregateCreator creator );
};
/**
* Attribute descriptor record. The overloaded constructors preserve the
* concrete type of generated descriptor slots without templates or casts in
* generated translation units.
*/
struct SC_CORE_EXPORT AttributeInitRecord {
AttrDescriptor ** attributeSlot;
Derived_attribute ** derivedSlot;
Inverse_attribute ** inverseSlot;
const char * name;
const TypeDescriptor * domain;
Logical optional;
Logical unique;
AttrType_Enum attrType;
const char * initializer;
const char * invertedAttribute;
const char * invertedEntity;
AttributeInitRecord( AttrDescriptor ** slot, const char * attrName,
const TypeDescriptor * domainType, Logical isOptional,
Logical isUnique, AttrType_Enum type,
const char * init = 0 );
AttributeInitRecord( Derived_attribute ** slot, const char * attrName,
const TypeDescriptor * domainType, Logical isOptional,
Logical isUnique, AttrType_Enum type,
const char * init = 0 );
AttributeInitRecord( Inverse_attribute ** slot, const char * attrName,
const TypeDescriptor * domainType, Logical isOptional,
Logical isUnique, const char * invertedAttr,
const char * invertedEnt );
};
enum ComplexNodeInitKind {
ComplexNodeInit_Simple,
ComplexNodeInit_And,
ComplexNodeInit_Or,
ComplexNodeInit_AndOr
};
struct SC_CORE_EXPORT ComplexNodeInitRecord {
ComplexNodeInitKind kind;
const char * name;
size_t firstChild;
size_t nextSibling;
};
struct SC_CORE_EXPORT ComplexListInitRecord {
size_t rootNode;
};
struct SC_CORE_EXPORT GlobalRuleInitRecord {
const char * name;
const char * text;
};
enum SchemaImageDescriptorRefKind {
SchemaImageRef_None,
SchemaImageRef_Entity,
SchemaImageRef_Type,
SchemaImageRef_Builtin,
SchemaImageRef_Aggregate
};
struct SC_CORE_EXPORT SchemaImageDescriptorRef {
uint32_t kind;
uint32_t schema;
uint32_t index;
};
struct SC_CORE_EXPORT SchemaImageSchemaRecord {
uint32_t name;
uint32_t firstEntity;
uint32_t entityCount;
uint32_t firstType;
uint32_t typeCount;
};
struct SC_CORE_EXPORT SchemaImageEntityRecord {
uint32_t schema;
uint32_t name;
uint32_t flags;
uint32_t supertypeStatement;
uint32_t firstSupertype;
uint32_t supertypeCount;
uint32_t firstAttribute;
uint32_t attributeCount;
uint32_t firstWhereRule;
uint32_t whereRuleCount;
uint32_t firstUniqueRule;
uint32_t uniqueRuleCount;
};
enum SchemaImageEntityFlags {
SchemaImageEntity_Abstract = 1u << 0,
SchemaImageEntity_ExternalMapping = 1u << 1
};
struct SC_CORE_EXPORT SchemaImageTypeRecord {
uint32_t schema;
uint32_t name;
uint32_t description;
uint32_t fundamentalType;
uint32_t descriptorKind;
int32_t uniqueElements;
SchemaImageDescriptorRef referent;
uint32_t aggregate;
uint32_t firstSelectElement;
uint32_t selectElementCount;
uint32_t firstWhereRule;
uint32_t whereRuleCount;
uint32_t firstEnumElement;
uint32_t enumElementCount;
};
struct SC_CORE_EXPORT SchemaImageAttributeRecord {
uint32_t name;
SchemaImageDescriptorRef domain;
uint32_t optional;
uint32_t unique;
uint32_t attrType;
uint32_t initializer;
uint32_t invertedAttribute;
uint32_t invertedEntity;
};
struct SC_CORE_EXPORT SchemaImageAggregateRecord {
uint32_t schema;
uint32_t description;
uint32_t fundamentalType;
SchemaImageDescriptorRef referent;
uint32_t bound1Type;
int32_t bound1;
uint32_t bound1Text;
uint32_t bound2Type;
int32_t bound2;
uint32_t bound2Text;
uint32_t optionalElements;
uint32_t uniqueElements;
};
struct SC_CORE_EXPORT SchemaImageRuleRecord {
uint32_t text;
};
enum SchemaImageSchemaTextKind {
SchemaImageText_GlobalRule,
SchemaImageText_Function,
SchemaImageText_Procedure
};
struct SC_CORE_EXPORT SchemaImageSchemaTextRecord {
uint32_t schema;
uint32_t kind;
uint32_t name;
uint32_t text;
};
struct SC_CORE_EXPORT SchemaImageRenameRecord {
SchemaImageDescriptorRef descriptor;
uint32_t schema;
uint32_t name;
};
struct SC_CORE_EXPORT SchemaImageSchemaBinding {
Schema ** schemaSlot;
ModelContentsCreator modelContentsCreator;
SchemaModule * module;
};
struct SC_CORE_EXPORT SchemaImageTypeBinding {
void * slot;
SelectCreator selectCreator;
EnumCreator enumCreator;
AggregateCreator aggregateCreator;
};
enum SchemaLoadError {
SchemaLoad_Ok,
SchemaLoad_UnsupportedVersion,
SchemaLoad_TruncatedImage,
SchemaLoad_InvalidOffset,
SchemaLoad_InvalidString,
SchemaLoad_InvalidReference,
SchemaLoad_CountMismatch,
SchemaLoad_MissingBinding,
SchemaLoad_ModuleFailure
};
struct SC_CORE_EXPORT SchemaLoadResult {
SchemaLoadError error;
uint32_t record;
bool Succeeded() const {
return error == SchemaLoad_Ok;
}
const char * Message() const;
};
SC_CORE_EXPORT SchemaLoadResult InitializeSchemaFromImage(
Registry & registry, const SchemaModuleImage & image,
const SchemaImageSchemaBinding * schemaBindings,
size_t schemaBindingCount,
const SchemaImageTypeBinding * typeBindings,
size_t typeBindingCount, SchemaLoadContext & context );
enum PackedComplexImageVersion {
PackedComplexImageVersion_1 = 1
};
struct SC_CORE_EXPORT PackedComplexImage {
uint32_t version;
uint32_t byteSize;
uint32_t stringOffset;
uint32_t stringBytes;
uint32_t nodeOffset;
uint32_t nodeCount;
uint32_t listOffset;
uint32_t listCount;
};
struct SC_CORE_EXPORT PackedComplexNode {
uint32_t kind;
uint32_t name;
uint32_t firstChild;
uint32_t nextSibling;
};
struct SC_CORE_EXPORT PackedComplexList {
uint32_t rootNode;
};
SC_CORE_EXPORT ComplexCollect * InitializePackedComplexSupport(
const PackedComplexImage & image, SchemaLoadResult * result = 0 );
SC_CORE_EXPORT void InitializeSchemas( Registry & reg,
const SchemaInitRecord * records,
size_t count );
SC_CORE_EXPORT void InitializeSchemaModuleImages(
const SchemaInitRecord * records, size_t count );
SC_CORE_EXPORT void InitializeEntityDescriptors(
const EntityDescriptorInitRecord * records, size_t count );
SC_CORE_EXPORT void InitializeTypeDescriptors(
const TypeDescriptorInitRecord * records, size_t count );
SC_CORE_EXPORT void InitializeTypeMetadata(
Registry & reg, Schema & schema, TypeDescriptor & type,
const TypeDescriptor * referent,
const TypeDescriptor * const * selectElements, size_t selectElementCount );
SC_CORE_EXPORT void InitializeEntityMetadata(
Registry & reg, EntityDescriptor & entity, Schema & schema,
const EntitySupertypeInitRecord * supertypes, size_t supertypeCount,
const AttributeInitRecord * attributes, size_t attributeCount );
SC_CORE_EXPORT void InitializeWhereRules(
TypeDescriptor & owner, const char * const * rules, size_t count );
SC_CORE_EXPORT void InitializeUniquenessRules(
EntityDescriptor & owner, const char * const * rules, size_t count );
SC_CORE_EXPORT void InitializeGlobalRules(
Schema & schema, const GlobalRuleInitRecord * rules, size_t count );
SC_CORE_EXPORT void InitializeFunctions(
Schema & schema, const char * const * functions, size_t count );
SC_CORE_EXPORT void InitializeProcedures(
Schema & schema, const char * const * procedures, size_t count );
SC_CORE_EXPORT ComplexCollect * InitializeComplexSupport(
const ComplexNodeInitRecord * nodes, size_t nodeCount,
const ComplexListInitRecord * lists, size_t listCount );
#endif
-171
View File
@@ -1,171 +0,0 @@
#ifndef SCHEMAMODULE_H
#define SCHEMAMODULE_H
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "sc_export.h"
class AttrDescriptor;
class EntityDescriptor;
class Schema;
class TypeDescriptor;
enum SchemaModuleSlotKind {
SchemaModuleSlot_Entity,
SchemaModuleSlot_Type,
SchemaModuleSlot_EnumType,
SchemaModuleSlot_SelectType,
SchemaModuleSlot_AggregateType,
SchemaModuleSlot_ArrayType,
SchemaModuleSlot_ListType,
SchemaModuleSlot_SetType,
SchemaModuleSlot_BagType,
SchemaModuleSlot_Attribute,
SchemaModuleSlot_DerivedAttribute,
SchemaModuleSlot_InverseAttribute
};
struct SC_CORE_EXPORT SchemaModuleSlot {
const void * slot;
SchemaModuleSlotKind kind;
};
enum SchemaModuleImageVersion {
SchemaModuleImageVersion_1 = 1,
SchemaModuleImageVersion_2 = 2
};
enum SchemaModuleImageFlags {
SchemaModuleImage_FullMetadata = 0,
SchemaModuleImage_StructuralMetadata = 1u << 0
};
/**
* Relocation-free generated header for a schema module image.
*
* Version 1 records only stable generated-ID counts. Version 2 describes
* one bounded block of offset-based schemas, descriptors, metadata, and
* strings. Runtime loading validates the complete block before constructing
* descriptors or changing a Registry.
*/
struct SC_CORE_EXPORT SchemaModuleImage {
uint32_t version;
uint32_t entityCount;
uint32_t typeCount;
uint32_t attributeCount;
/* Version 2 fields. Version 1 initializers leave these zero. */
uint32_t byteSize;
uint32_t flags;
uint32_t schemaCount;
uint32_t stringBytes;
uint32_t schemaOffset;
uint32_t entityOffset;
uint32_t typeOffset;
uint32_t attributeOffset;
uint32_t aggregateCount;
uint32_t aggregateOffset;
uint32_t referenceCount;
uint32_t referenceOffset;
uint32_t ruleCount;
uint32_t ruleOffset;
uint32_t schemaTextCount;
uint32_t schemaTextOffset;
uint32_t enumElementCount;
uint32_t enumElementOffset;
uint32_t stringOffset;
uint32_t reserved;
uint64_t fingerprint;
uint32_t renameCount;
uint32_t renameOffset;
};
class SchemaModule;
/**
* Per-load descriptor collection used by packed API v2 schema images.
*
* Keeping this state explicit makes independent schema loads reentrant and
* avoids the process-global capture map retained for version-1 images.
*/
class SC_CORE_EXPORT SchemaLoadContext {
class Impl;
Impl * _impl;
SchemaLoadContext( const SchemaLoadContext & );
SchemaLoadContext & operator=( const SchemaLoadContext & );
friend class SchemaModule;
public:
SchemaLoadContext();
~SchemaLoadContext();
void Begin( Schema & schema );
void RecordEntity( Schema & schema, const EntityDescriptor * entity );
void RecordType( Schema & schema, const TypeDescriptor * type );
void RecordAttribute( Schema & schema, const AttrDescriptor * attribute );
};
SC_CORE_EXPORT void RecordSchemaModuleEntity(
Schema & schema, const EntityDescriptor * entity );
SC_CORE_EXPORT void RecordSchemaModuleType(
Schema & schema, const TypeDescriptor * type );
SC_CORE_EXPORT void RecordSchemaModuleAttribute(
Schema & schema, const AttrDescriptor * attribute );
SC_CORE_EXPORT void BeginSchemaModuleImage( Schema & schema );
/**
* Stable API v2 view of a generated schema.
*
* Generated EntityId, TypeId, and AttributeId enumerations are converted to
* indexes before calling this class. Keeping the public lookup API separate
* from generated descriptor globals allows the underlying representation to
* move from C++ objects to packed schema data without another API break.
*/
class SC_CORE_EXPORT SchemaModule {
Schema * _schema;
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4251 )
#endif
std::vector<const EntityDescriptor *> _entities;
std::vector<const TypeDescriptor *> _types;
std::vector<const AttrDescriptor *> _attributes;
uint64_t _fingerprint;
#ifdef _MSC_VER
#pragma warning( pop )
#endif
public:
SchemaModule();
~SchemaModule();
void Initialize(
Schema & schema,
const EntityDescriptor * const * entities, size_t entityCount,
const TypeDescriptor * const * types, size_t typeCount,
const AttrDescriptor * const * attributes, size_t attributeCount );
void InitializeFromSlots(
Schema & schema,
const SchemaModuleSlot * entities, size_t entityCount,
const SchemaModuleSlot * types, size_t typeCount,
const SchemaModuleSlot * attributes, size_t attributeCount );
void InitializeFromImage( Schema & schema,
const SchemaModuleImage & image );
bool InitializeFromContext( Schema & schema, SchemaLoadContext & context,
uint64_t fingerprint );
bool IsInitialized() const;
const Schema & GetSchema() const;
const EntityDescriptor * Entity( size_t id ) const;
const TypeDescriptor * Type( size_t id ) const;
const AttrDescriptor * Attribute( size_t id ) const;
size_t EntityCount() const;
size_t TypeCount() const;
size_t AttributeCount() const;
uint64_t Fingerprint() const;
};
#endif
-20
View File
@@ -1,20 +0,0 @@
set(UTILS_HDRS
dirobj.h
errordesc.h
gennodearray.h
gennode.h
gennodelist.h
sc_hash.h
Str.h
)
install(FILES ${UTILS_HDRS}
DESTINATION ${INCLUDE_DIR}/stepcode/clutils)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
+1
View File
@@ -15,6 +15,7 @@
#cmakedefine HAVE_IO_H 1
#cmakedefine SC_TRACE_FPRINTF 1
#cmakedefine SC_MEMMGR_ENABLE_CHECKS 1
#cmakedefine HAVE_ABS 1
#cmakedefine HAVE_MEMCPY 1
+1 -1
View File
@@ -58,7 +58,7 @@ struct freelist_head {
#endif
};
char * nnew(void);
char * nnew();
#include "error.h"
+2 -4
View File
@@ -93,10 +93,8 @@
/* function pointer types */
/**************************/
typedef void ( *voidFuncptr )(void);
typedef int ( *intFuncptr )(void);
typedef void ( *voidFuncptr )();
typedef int ( *intFuncptr )();
#endif /* BASIC_H */
-1
View File
@@ -108,7 +108,6 @@ extern SC_EXPRESS_EXPORT char * KW_SUPERTYPE;
extern SC_EXPRESS_EXPORT char * KW_TAN;
extern SC_EXPRESS_EXPORT char * KW_THEN;
extern SC_EXPRESS_EXPORT char * KW_TO;
extern SC_EXPRESS_EXPORT char * KW_TREAT;
extern SC_EXPRESS_EXPORT char * KW_TRUE;
extern SC_EXPRESS_EXPORT char * KW_TYPE;
extern SC_EXPRESS_EXPORT char * KW_TYPEOF;
+1 -1
View File
@@ -83,7 +83,7 @@ typedef enum {
OP_MINUS, OP_MOD, OP_NEGATE,
OP_NOT, OP_NOT_EQUAL, OP_OR,
OP_PLUS, OP_REAL_DIV, OP_SUBCOMPONENT,
OP_TIMES, OP_TREAT, OP_XOR, OP_UNKNOWN,
OP_TIMES, OP_XOR, OP_UNKNOWN,
OP_LAST /**< must be last - used only to size tables */
} Op_Code;
+1 -1
View File
@@ -3,6 +3,6 @@
#include "sc_export.h"
SC_EXPRESS_EXPORT void FACTORYinitialize(void);
SC_EXPRESS_EXPORT void FACTORYinitialize();
#endif /* __FACTORY_H_ */
+1 -1
View File
@@ -3,6 +3,6 @@
#include "sc_export.h"
SC_EXPRESS_EXPORT void MEMORYinitialize(void);
SC_EXPRESS_EXPORT void MEMORYinitialize();
#endif // __MEMORY_H
+1 -1
View File
@@ -68,7 +68,7 @@
/***************************/
struct Object {
struct Symbol_ * ( *get_symbol )( void * );
struct Symbol_ * ( *get_symbol )();
char * type; /**< should complete the phrase "X is ..." - i.e., "an entity", "a type", "of unknown type" */
int bits; /**< a bitwise selector of a type, i.e. OBJ_XX_BITS */
};
-19
View File
@@ -47,25 +47,6 @@
extern SC_EXPRESS_EXPORT int print_objects_while_running;
/*************************/
/* Refinement structures */
/*************************/
/* Maximum length for type name lookups */
#define MAX_TYPE_NAME_LENGTH 512
/** Structure to track type refinements from TYPEOF guards in AND expressions */
typedef struct Refinement_ {
Variable variable; /**< the variable being refined */
Type refined_type; /**< the narrowed type */
struct Refinement_ *next; /**< next refinement in the chain */
} *Refinement;
/** Context for passing refinements through expression resolution */
typedef struct RefinementContext_ {
Refinement refinements; /**< linked list of active refinements */
} *RefinementContext;
/* macros */
/* cheaper doing the check here, then inside the function call. Return */
-4
View File
@@ -237,9 +237,6 @@ extern SC_EXPRESS_EXPORT struct freelist_head TYPEBODY_fl;
#define TYPEis_oneof(t) ((t)->u.type->body->type == oneof_)
#define TYPEis_entity(t) ((t)->u.type->body->type == entity_)
#define TYPEis_enumeration(t) ((t)->u.type->body->type == enumeration_)
/** Shallow aggregate check - returns true if type has a base (characteristic of aggregates).
* Does NOT follow type definition chains. For deep unwrapping through typedef chains,
* use TYPEget_nonaggregate_base_type() or TYPEget_aggregate_base(). */
#define TYPEis_aggregate(t) ((t)->u.type->body->base)
#define TYPEis_aggregate_raw(t) ((t)->u.type->body->type == aggregate_)
#define TYPEis_array(t) ((t)->u.type->body->type == array_)
@@ -306,7 +303,6 @@ extern SC_EXPRESS_EXPORT void TYPEcleanup( void );
extern SC_EXPRESS_EXPORT bool TYPEinherits_from( Type, enum type_enum );
extern SC_EXPRESS_EXPORT Type TYPEget_nonaggregate_base_type( Type );
extern SC_EXPRESS_EXPORT Type TYPEget_aggregate_base( Type );
extern SC_EXPRESS_EXPORT Type TYPEcreate_user_defined_type( Type, Scope, struct Symbol_ * );
extern SC_EXPRESS_EXPORT Type TYPEcreate_user_defined_tag( Type, Scope, struct Symbol_ * );
+1 -1
View File
@@ -15,7 +15,7 @@ BUILDNAME:STRING=${CTEST_BUILD_NAME}
SC_ENABLE_TESTING:BOOL=ON
SC_ENABLE_COVERAGE:BOOL=ON
SC_BUILD_SCHEMAS:STRING=ALL
CMAKE_BUILD_TYPE:STRING=Debug
SC_BUILD_TYPE:STRING=Debug
")
set(LCOV_OUT "${CTEST_BINARY_DIRECTORY}/lcov_html")
-10
View File
@@ -1,10 +0,0 @@
#!/bin/bash
find . -type f -path "*/cl*" -not -path "*.git/*" -not -path "*/exp*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include \"$1\"/include \"utils\/$1\"/g" {} \;
find . -type f -path "*/cl*" -not -path "*.git/*" -not -path "*/exp*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include <$1>/include \"utils\/$1\"/g" {} \;
find . -type f -path "*/include*" -not -path "*.git/*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include \"$1\"/include \"utils\/$1\"/g" {} \;
find . -type f -path "*/include*" -not -path "*.git/*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include <$1>/include \"utils\/$1\"/g" {} \;
find . -type f -path "*/test*" -not -path "*.git/*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include \"$1\"/include \"utils\/$1\"/g" {} \;
find . -type f -path "*/test*" -not -path "*.git/*" -regex '.*\(c\|cc\|cpp\|cxx\|h\|hpp\)$' -exec perl -0777 -pi -e "s/include <$1>/include \"utils\/$1\"/g" {} \;
+1 -1
View File
@@ -9,7 +9,7 @@ set(CTEST_INITIAL_CACHE "
SITE:STRING=${CTEST_SITE}
BUILDNAME:STRING=${CTEST_BUILD_NAME}
SC_ENABLE_TESTING:BOOL=ON
CMAKE_BUILD_TYPE:STRING=Debug
SC_BUILD_TYPE:STRING=Debug
")
+72
View File
@@ -0,0 +1,72 @@
set(SC_BASE_SOURCES
sc_memmgr.cc
sc_trace_fprintf.c
sc_getopt.cc
sc_benchmark.cc
sc_mkdir.c
path2str.c
judy/src/judy.c
)
set(SC_BASE_HDRS
sc_benchmark.h
sc_memmgr.h
sc_getopt.h
sc_trace_fprintf.h
sc_mkdir.h
path2str.h
judy/src/judy.h
judy/src/judyLArray.h
judy/src/judyL2Array.h
judy/src/judySArray.h
judy/src/judyS2Array.h
)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/judy/src
)
if($CACHE{SC_MEMMGR_ENABLE_CHECKS})
add_definitions(-DSC_MEMMGR_ENABLE_CHECKS)
endif()
if(BUILD_SHARED_LIBS)
SC_ADDLIB(base SHARED SOURCES ${SC_BASE_SOURCES})
if(WIN32)
target_link_libraries(base psapi)
target_compile_definitions(base PRIVATE SC_BASE_DLL_EXPORTS)
endif()
endif()
if(BUILD_STATIC_LIBS)
SC_ADDLIB(base-static STATIC SOURCES ${SC_BASE_SOURCES})
if(WIN32)
target_link_libraries(base-static psapi)
endif()
endif()
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/judy/src")
message("Judy array source code not found. Downloading (don't sweat, it's public domain)...")
file(DOWNLOAD "http://github.com/mpictor/judy-template/archive/master.tar.gz"
"${CMAKE_CURRENT_SOURCE_DIR}/judy.tar.gz" SHOW_PROGRESS)
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf "${CMAKE_CURRENT_SOURCE_DIR}/judy.tar.gz"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
)
file(RENAME judy-template-master judy)
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/judy.tar.gz")
message("Judy array source code extracted.")
endif(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/judy/src")
install(FILES ${SC_BASE_HDRS}
DESTINATION ${INCLUDE_DIR}/stepcode/base)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
+78
View File
@@ -0,0 +1,78 @@
cmake_minimum_required(VERSION 3.12)
project( JudyTemplates )
if( NOT DEFINED CMAKE_BUILD_TYPE )
# set( CMAKE_BUILD_TYPE "RelWithDebInfo" ) #optimize, but include debug info
set( CMAKE_BUILD_TYPE "Release" )
endif( NOT DEFINED CMAKE_BUILD_TYPE )
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
if( NOT DEFINED JUDY_OPTIMIZE_FLAGS )
if( CMAKE_COMPILER_IS_GNUCC )
set( JUDY_OPTIMIZE_FLAGS "-march=native" )
#test for LTO; this uses an internal variable so it may break
if( DEFINED CMAKE_C_COMPILER_VERSION )
if( ${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 4.7.0 )
set( JUDY_OPTIMIZE_FLAGS "${JUDY_OPTIMIZE_FLAGS} -flto" )
message( " -- GCC version: ${CMAKE_C_COMPILER_VERSION}. Enabling link-time optimization." )
endif( ${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 4.7.0 )
endif( DEFINED CMAKE_C_COMPILER_VERSION )
#elseif( MSVC )
# set( JUDY_OPTIMIZE_FLAGS "..." ) # <--- set MSVC flags here <---
else()
message( "Unrecognized compiler - no optimization flags set. Edit CMakeLists.txt or set JUDY_OPTIMIZE_FLAGS." )
set( JUDY_OPTIMIZE_FLAGS "" )
endif( CMAKE_COMPILER_IS_GNUCC )
endif( NOT DEFINED JUDY_OPTIMIZE_FLAGS )
add_definitions( ${JUDY_OPTIMIZE_FLAGS} )
set( JUDYS_SOURCES src/judy.c src/judy.h )
if( CMAKE_COMPILER_IS_GNUCC )
add_definitions( -pedantic -W -Wall -Wundef -Wfloat-equal -Wshadow -Winline -Wno-long-long )
endif( CMAKE_COMPILER_IS_GNUCC )
add_library( judy_lib STATIC ${JUDYS_SOURCES} )
include_directories( src )
if( ENABLE_TESTING )
include( CTest )
include_directories( test )
enable_testing()
add_executable( pennysort test/pennySort.c test/sort.c ${JUDYS_SOURCES} )
add_executable( hexsort test/hexSort.c test/sort.c ${JUDYS_SOURCES} )
set_target_properties( pennysort hexsort PROPERTIES COMPILE_FLAGS "-DSTANDALONE" )
add_executable( judyLtest test/judyLtest.cc )
target_link_libraries( judyLtest judy_lib )
add_test( judyLtest judyLtest )
add_executable( judyL2test test/judyL2test.cc )
target_link_libraries( judyL2test judy_lib )
add_test( judyL2test judyL2test )
add_executable( judyStest test/judyStest.cc )
target_link_libraries( judyStest judy_lib )
add_test( judyStest judyStest )
add_executable( judyS2test test/judyS2test.cc )
target_link_libraries( judyS2test judy_lib )
add_test( judyS2test judyS2test )
endif( ENABLE_TESTING )
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
+43
View File
@@ -0,0 +1,43 @@
# Judy Array Templates
The Judy Array is a sparse dynamic array. It is a particular kind of trie that is highly efficient in space and time, and does not require tuning.
This uses [Karl Malbrain's implementation](http://code.google.com/p/judyarray/) of the Judy Array. Additional information can be found with Doug Baskins' [original implementation](http://judy.sourceforge.net/) on sourceforge, or on [Wikipedia](http://en.wikipedia.org/wiki/Judy_array).
## The templates
* `judyLArray` - a C++ template wrapper for an int-int Judy Array. JudyKey and JudyValue must be integer types and the same size as a pointer (i.e. 32- or 64-bit)
* `judySArray` - Same as judyLArray, but with string-int mapping. The above restrictions on JudyValue apply here as well.
* **TODO** - single-key, multi-value versions of the above
* **TODO** - single-key, n-value versions of the above *(?)*
## Comparison between this and the versions Karl and Doug wrote
* Doug Baskins' code is licenced under the LGPL. While more permissive than the GPL, it's still not always acceptable. His code is very fast but weighs in at ~20k lines.
* Karl Malbrain's code is ~1250 lines, in a single file containing the judy array and the test code; use requires creating a header.
* Both of the above are written in C, so they don't fit neatly into object-oriented C++.
* Unlike Doug's code, this is ~1250 lines. Unlike Karl's, this is split into several files.
## Files
* `CMakeLists.txt` - CMake build logic. If you don't have CMake, it should be quite easy to write a file for the build system of your choice.
* **src/**
* `judy.c`, `judy.h` - implementation of the Judy Array
* `judyLArray.h` - the judyLArray template
* `judySArray.h` - the judySArray template
* **test/**
* `hexSort.c` - Sorts a file where each line contains 32 hex chars. Compiles to `hexsort`, which is the same executable as compiling Karl's code with `-DHEXSORT -DSTANDALONE`
* `pennySort.c` - Sorts strings; compiles to `pennysort`. Same as compiling Karl's code with `-DSTANDALONE`.
* `sort.c`, `sort.h` - Karl's sorting functions. Only used by `hexsort` and `pennysort`.
* `judyLtest.cc` - an incomplete test of the judyLArray template.
* `judyStest.cc` - an incomplete test of the judySArray template.
## Compiling
* requires C and C++ compilers, CMake.
* from the command line:
* `mkdir build; cd build`
* `cmake .. -DENABLE_TESTING=TRUE`
* `make`
## License
Karl Malbrain's judy array code is public domain; what I've added is public domain as well.
## Contact
mpictor -a-t- gmail
+29
View File
@@ -0,0 +1,29 @@
#astyle config file
#run astyle on one or a few files: use
# astyle --options=misc/astyle.cfg path/to/file
#run astyle on all files: from the root dir, use
# astyle --options=misc/astyle.cfg --recursive "src/*.c" "src/*.h" "test/*.c" "test/*.h"
# in the above line, the double quotes *are* necessary
suffix=none #don't create backup files
style=java #compact bracket style
indent=spaces=4
indent-preprocessor
indent-classes
indent-switches
indent-namespaces
pad-oper #pad (space) around operators
pad-paren-in #pad inside parenthesis
unpad-paren #remove parenthesis padding other than requested above
add-brackets #add brackets on one-line conditionals
convert-tabs #convert all tabs to spaces
align-pointer=middle #char * foo
lineend=linux #lines end with LF (linux), not CRLF (windows)
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
#generates a file of hex keys and runs hexsort on it. No verification is done.
#hex data comes from /dev/urandom, so it isn't all that random.
hexdump -v -e '2/8 "%08x"' -e '"\n"' /dev/urandom |head -n 1000000 >ukeys
#a.out [in-file] [out-file] [keysize] [recordlen] [keyoffset] [mergerecs]
time bin/hexsort ukeys skeys
File diff suppressed because it is too large Load Diff
@@ -60,34 +60,11 @@
# endif
#endif
#include "cllazyfile/judy.h"
#include "judy.h"
#include <string.h>
#include <stdio.h>
/*
* Judy keys are byte-packed: adjacent slots may start at an address that is
* not suitably aligned for judyvalue. Callers are likewise permitted to
* supply byte buffers without judyvalue alignment. Copy through an aligned
* local value rather than dereferencing a cast pointer. Zero-filling any
* bytes not requested also makes partial loads deterministic.
*/
static judyvalue
judy_load_value( const unsigned char * source, unsigned int size )
{
judyvalue value = 0;
memcpy( &value, source, size );
return value;
}
static void
judy_store_value( unsigned char * destination, judyvalue value,
unsigned int size )
{
memcpy( destination, &value, size );
}
#if defined(STANDALONE) || defined(ASKITIS)
extern unsigned int MaxMem;
@@ -336,6 +313,7 @@ void judy_free( Judy * judy, void * block, int type ) {
// assemble key from current path
unsigned int judy_key( Judy * judy, unsigned char * buff, unsigned int max ) {
judyvalue * dest = ( judyvalue * )buff;
unsigned int len = 0, idx = 0, depth;
int slot, off, type;
judyvalue value;
@@ -355,8 +333,7 @@ unsigned int judy_key( Judy * judy, unsigned char * buff, unsigned int max ) {
if( judy->depth )
if( !( len & JUDY_key_mask ) ) {
judy_store_value( buff + depth * JUDY_key_size, 0,
JUDY_key_size );
dest[depth] = 0;
}
switch( type ) {
@@ -373,14 +350,9 @@ unsigned int judy_key( Judy * judy, unsigned char * buff, unsigned int max ) {
base = ( unsigned char * )( judy->stack[idx].next & JUDY_mask );
if( judy->depth ) {
value = judy_load_value( base + slot * keysize,
JUDY_key_size );
value = *( judyvalue * )( base + slot * keysize );
value &= JudyMask[keysize];
value |= judy_load_value( buff + depth * JUDY_key_size,
JUDY_key_size );
judy_store_value( buff + depth * JUDY_key_size, value,
JUDY_key_size );
depth++;
dest[depth++] |= value;
len += keysize;
if( depth < judy->depth ) {
@@ -411,13 +383,7 @@ unsigned int judy_key( Judy * judy, unsigned char * buff, unsigned int max ) {
case JUDY_radix:
if( judy->depth ) {
value = judy_load_value( buff + depth * JUDY_key_size,
JUDY_key_size );
value |= ( judyvalue )slot <<
( ( JUDY_key_size - ++len ) &
JUDY_key_mask ) * 8;
judy_store_value( buff + depth * JUDY_key_size, value,
JUDY_key_size );
dest[depth] |= ( judyvalue )slot << ( JUDY_key_size - ( ++len & JUDY_key_mask ) ) * 8;
if( !( len & JUDY_key_mask ) ) {
depth++;
}
@@ -453,6 +419,7 @@ unsigned int judy_key( Judy * judy, unsigned char * buff, unsigned int max ) {
// find slot & setup cursor
JudySlot * judy_slot( Judy * judy, const unsigned char * buff, unsigned int max ) {
judyvalue * src = ( judyvalue * )buff;
int slot, size, keysize, tst, cnt;
JudySlot next = *judy->root;
judyvalue value, test = 0;
@@ -496,9 +463,7 @@ JudySlot * judy_slot( Judy * judy, const unsigned char * buff, unsigned int max
value = 0;
if( judy->depth ) {
value = judy_load_value( buff + depth * JUDY_key_size,
JUDY_key_size );
depth++;
value = src[depth++];
off |= JUDY_key_mask;
off++;
value &= JudyMask[keysize];
@@ -513,8 +478,7 @@ JudySlot * judy_slot( Judy * judy, const unsigned char * buff, unsigned int max
// find slot > key
while( slot-- ) {
test = judy_load_value( base + slot * keysize,
JUDY_key_size );
test = *( judyvalue * )( base + slot * keysize );
#if BYTE_ORDER == BIG_ENDIAN
test >>= 8 * ( JUDY_key_size - keysize );
#else
@@ -545,9 +509,7 @@ JudySlot * judy_slot( Judy * judy, const unsigned char * buff, unsigned int max
table = ( JudySlot * )( next & JUDY_mask ); // outer radix
if( judy->depth ) {
value = judy_load_value( buff + depth * JUDY_key_size,
JUDY_key_size );
slot = ( value >> ( (( JUDY_key_size - ++off) & JUDY_key_mask ) * 8 ) ) & 0xff;
slot = ( src[depth] >> ( (( JUDY_key_size - ++off) & JUDY_key_mask ) * 8 ) ) & 0xff;
} else if( off < max ) {
slot = buff[off++];
} else {
@@ -1262,9 +1224,10 @@ void judy_splitspan( Judy * judy, JudySlot * next, unsigned char * base ) {
// judy_cell: add string to judy array
JudySlot * judy_cell( Judy * judy, const unsigned char * buff, unsigned int max ) {
judyvalue * src = ( judyvalue * )buff;
int size, idx, slot, cnt, tst;
JudySlot * next = judy->root;
judyvalue test = 0, value;
judyvalue test, value;
unsigned int off = 0, start;
JudySlot * table;
JudySlot * node;
@@ -1298,9 +1261,7 @@ JudySlot * judy_cell( Judy * judy, const unsigned char * buff, unsigned int max
value = 0;
if( judy->depth ) {
value = judy_load_value( buff + depth * JUDY_key_size,
JUDY_key_size );
depth++;
value = src[depth++];
off |= JUDY_key_mask;
off++;
value &= JudyMask[keysize];
@@ -1315,8 +1276,7 @@ JudySlot * judy_cell( Judy * judy, const unsigned char * buff, unsigned int max
// find slot > key
while( slot-- ) {
test = judy_load_value( base + slot * keysize,
JUDY_key_size );
test = *( judyvalue * )( base + slot * keysize );
#if BYTE_ORDER == BIG_ENDIAN
test >>= 8 * ( JUDY_key_size - keysize );
#else
@@ -1418,9 +1378,7 @@ JudySlot * judy_cell( Judy * judy, const unsigned char * buff, unsigned int max
table = ( JudySlot * )( *next & JUDY_mask ); // outer radix
if( judy->depth ) {
value = judy_load_value( buff + depth * JUDY_key_size,
JUDY_key_size );
slot = ( value >> ( ( (JUDY_key_size - ++off) & JUDY_key_mask ) * 8 ) ) & 0xff;
slot = ( src[depth] >> ( ( (JUDY_key_size - ++off) & JUDY_key_mask ) * 8 ) ) & 0xff;
} else if( off < max ) {
slot = buff[off++];
} else {
@@ -1506,8 +1464,7 @@ JudySlot * judy_cell( Judy * judy, const unsigned char * buff, unsigned int max
// fill in slot 0 with bytes of key
if( judy->depth ) {
value = judy_load_value( buff + depth * JUDY_key_size,
JUDY_key_size );
value = src[depth];
#if BYTE_ORDER != BIG_ENDIAN
memcpy( base, &value, keysize ); // copy new key into slot
#else
@@ -1585,9 +1542,7 @@ JudySlot * judy_cell( Judy * judy, const unsigned char * buff, unsigned int max
// fill in slot 0 with bytes of key
value = judy_load_value( buff + depth * JUDY_key_size,
JUDY_key_size );
judy_store_value( base, value, JUDY_key_size );
*( judyvalue * )base = src[depth];
if( judy->level < judy->max ) {
judy->level++;
@@ -1607,3 +1562,4 @@ JudySlot * judy_cell( Judy * judy, const unsigned char * buff, unsigned int max
#endif
return next;
}
@@ -25,8 +25,8 @@ struct judyl2KVpair {
/** A judyL2 array maps JudyKey's to multiple JudyValue's, similar to std::multimap.
* Internally, this is a judyL array of std::vector< JudyValue >.
* The first template parameter must be the same size as a void*
* \tparam JudyKey the type of the key, i.e. uint64_t, etc
* \tparam JudyValue the type of the value, i.e. int, pointer-to-object, etc. With judyL2Array, the size of this value can vary.
* \param JudyKey the type of the key, i.e. uint64_t, etc
* \param JudyValue the type of the value, i.e. int, pointer-to-object, etc. With judyL2Array, the size of this value can vary.
*/
template< typename JudyKey, typename JudyValue >
class judyL2Array {
@@ -24,8 +24,8 @@ struct judylKVpair {
* a JudyValue. Each cell must be set to a non-zero value by the caller.
*
* Both template parameters must be the same size as a void*
* \tparam JudyKey the type of the key, i.e. uint64_t, pointer-to-object, etc
* \tparam JudyValue the type of the value
* \param JudyKey the type of the key, i.e. uint64_t, pointer-to-object, etc
* \param JudyValue the type of the value
*/
template< typename JudyKey, typename JudyValue >
class judyLArray {
@@ -159,8 +159,8 @@ class judyLArray {
* getLastValue() will return the entry before the one that was deleted
* \sa isEmpty()
*/
bool removeEntry( JudyKey key ) {
if( judy_slot( _judyarray, reinterpret_cast<const unsigned char *>( &key ), _depth * JUDY_key_size ) ) {
bool removeEntry( JudyKey * key ) {
if( judy_slot( _judyarray, key, _depth * JUDY_key_size ) ) {
_lastSlot = ( JudyValue * ) judy_del( _judyarray );
return true;
} else {
@@ -25,7 +25,7 @@ struct judys2KVpair {
/** A judyS2 array maps a set of strings to multiple JudyValue's, similar to std::multimap.
* Internally, this is a judyS array of std::vector< JudyValue >.
* \tparam JudyValue the type of the value, i.e. int, pointer-to-object, etc.
* \param JudyValue the type of the value, i.e. int, pointer-to-object, etc.
*/
template< typename JudyValue >
class judyS2Array {
@@ -51,8 +51,8 @@ class judyS2Array {
explicit judyS2Array( const judyS2Array< JudyValue > & other ): _maxKeyLen( other._maxKeyLen ), _success( other._success ) {
_judyarray = judy_clone( other._judyarray );
_buff = new unsigned char[_maxKeyLen];
strncpy( reinterpret_cast< char * >( _buff ), reinterpret_cast< const char * >( other._buff ), _maxKeyLen - 1 );
_buff[ _maxKeyLen - 1 ] = '\0'; //ensure that _buff is null-terminated
strncpy( _buff, other._buff, _maxKeyLen );
_buff[ _maxKeyLen ] = '\0'; //ensure that _buff is null-terminated, since strncpy won't necessarily do so
find( _buff ); //set _lastSlot
}
@@ -39,8 +39,8 @@ class judySArray {
explicit judySArray( const judySArray< JudyValue > & other ): _maxKeyLen( other._maxKeyLen ), _success( other._success ) {
_judyarray = judy_clone( other._judyarray );
_buff = new unsigned char[_maxKeyLen];
strncpy( reinterpret_cast< char * >( _buff ), reinterpret_cast< const char * >( other._buff ), _maxKeyLen - 1 );
_buff[ _maxKeyLen - 1 ] = '\0'; //ensure that _buff is null-terminated
strncpy( _buff, other._buff, _maxKeyLen );
_buff[ _maxKeyLen ] = '\0'; //ensure that _buff is null-terminated, since strncpy won't necessarily do so
find( _buff ); //set _lastSlot
}
+124
View File
@@ -0,0 +1,124 @@
// Judy arrays 13 DEC 2012 (judy64n.c from http://code.google.com/p/judyarray/ )
// This code is public domain.
// Author Karl Malbrain, malbrain AT yahoo.com
// with assistance from Jan Weiss.
// modifications (and any bugs) by Mark Pictor, mpictor at gmail
// Simplified judy arrays for strings and integers
// Adapted from the ideas of Douglas Baskins of HP.
// Map a set of keys to corresponding memory cells (uints).
// Each cell must be set to a non-zero value by the caller.
// Integer mappings are denoted by calling judy_open with the
// Integer depth of the Judy Trie as the second argument.
#ifndef STANDALONE
# error must define STANDALONE while compiling this file and judy64.c
#endif
#include "judy.h"
#include "sort.h"
unsigned int MaxMem = 0;
/**
usage:
a.out [in-file] [out-file]
where all lines of in-file are 32 chars, hexadecimal
On linux, a 1M-line file can be created with the following:
hexdump -v -e '2/8 "%08x"' -e '"\n"' /dev/urandom |head -n 1000000 >in-file
*/
int main( int argc, char ** argv ) {
unsigned char buff[1024];
JudySlot max = 0;
JudySlot * cell;
FILE * in, *out;
void * judy;
unsigned int len;
unsigned int idx;
if( argc > 1 ) {
in = fopen( argv[1], "rb" );
} else {
in = stdin;
}
if( argc > 2 ) {
out = fopen( argv[2], "wb" );
} else {
out = stdout;
}
setvbuf( out, NULL, _IOFBF, 4096 * 1024 );
if( !in ) {
fprintf( stderr, "unable to open input file\n" );
}
if( !out ) {
fprintf( stderr, "unable to open output file\n" );
}
PennyMerge = ( unsigned long long )PennyLine * PennyRecs;
judy = judy_open( 1024, 16 / JUDY_key_size );
while( fgets( ( char * )buff, sizeof( buff ), in ) ) {
judyvalue key[16 / JUDY_key_size];
if( len = strlen( ( const char * )buff ) ) {
buff[--len] = 0; // remove LF
}
#if JUDY_key_size == 4
key[3] = strtoul( buff + 24, NULL, 16 );
buff[24] = 0;
key[2] = strtoul( buff + 16, NULL, 16 );
buff[16] = 0;
key[1] = strtoul( buff + 8, NULL, 16 );
buff[8] = 0;
key[0] = strtoul( buff, NULL, 16 );
#else
key[1] = strtoull( buff + 16, NULL, 16 );
buff[16] = 0;
key[0] = strtoull( buff, NULL, 16 );
#endif
*( judy_cell( judy, ( void * )key, 0 ) ) += 1; // count instances of string
max++;
}
fprintf( stderr, "%" PRIuint " memory used\n", MaxMem );
cell = judy_strt( judy, NULL, 0 );
if( cell ) do {
judyvalue key[16 / JUDY_key_size];
len = judy_key( judy, ( void * )key, 0 );
for( idx = 0; idx < *cell; idx++ ) { // spit out duplicates
#if JUDY_key_size == 4
fprintf( out, "%.8X", key[0] );
fprintf( out, "%.8X", key[1] );
fprintf( out, "%.8X", key[2] );
fprintf( out, "%.8X", key[3] );
#else
fprintf( out, "%.16llX", key[0] );
fprintf( out, "%.16llX", key[1] );
#endif
fputc( '\n', out );
}
} while( cell = judy_nxt( judy ) );
#if 0
// test deletion all the way to an empty tree
if( cell = judy_prv( judy ) )
do {
max -= *cell;
} while( cell = judy_del( judy ) );
assert( max == 0 );
#endif
judy_close( judy );
return 0;
}
+72
View File
@@ -0,0 +1,72 @@
#include <iostream>
#include <stdint.h>
#include <stdlib.h>
#include "judyL2Array.h"
typedef judyL2Array< uint64_t, uint64_t > jl2a;
bool testFind( jl2a & j, uint64_t key, unsigned int count ) {
jl2a::cvector * v = j.find( key );
std::cout << "find: key " << key << " ..." << std::endl;
if( count > 0 ) {
if( !v || !j.success() || ( v->size() != count ) ) {
std::cout << " false negative - v: " << v << " success: " << j.success();
if( v ) {
std::cout << " expected count: " << count << " actual: " << v->size();
}
std::cout << std::endl;
return false;
} else {
// note - this doesn't verify that the right keys are returned, just the right number!
jl2a::vector::const_iterator it = v->begin();
std::cout << " correct number of values -";
for( ; it != v->end(); it++ ) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
} else {
if( v || j.success() ) {
std::cout << " false positive - v: " << v << " success: " << j.success() << std::endl;
return false;
} else {
std::cout << " not found, as expected." << std::endl;
}
}
return true;
}
int main() {
bool pass = true;
jl2a jl;
std::cout.setf( std::ios::boolalpha );
// std::cout << "size of judyL2Array: " << sizeof( jl ) << std::endl;
jl.insert( 5, 12 );
jl.insert( 6, 2 );
jl.insert( 7, 312 );
jl.insert( 11, 412 );
jl.insert( 7, 313 );
jl2a::cpair kv = jl.atOrAfter( 4 );
std::cout << "atOrAfter test ..." << std::endl;
if( kv.value != 0 && jl.success() ) {
std::cout << " key " << kv.key << " value " << kv.value->at( 0 ) << std::endl;
} else {
std::cout << " failed" << std::endl;
pass = false;
}
pass &= testFind( jl, 8, 0 );
pass &= testFind( jl, 11, 1 );
pass &= testFind( jl, 7, 2 );
jl.clear();
//TODO test all of judyL2Array
if( pass ) {
std::cout << "All tests passed." << std::endl;
exit( EXIT_SUCCESS );
} else {
std::cout << "At least one test failed." << std::endl;
exit( EXIT_FAILURE );
}
}
+33
View File
@@ -0,0 +1,33 @@
#include <iostream>
#include <stdint.h>
#include <stdlib.h>
#include "judyLArray.h"
int main() {
std::cout.setf( std::ios::boolalpha );
judyLArray< uint64_t, uint64_t > jl;
std::cout << "size of judyLArray: " << sizeof( jl ) << std::endl;
jl.insert( 5, 12 );
jl.insert( 6, 2 );
jl.insert( 7, 312 );
jl.insert( 8, 412 );
judyLArray< uint64_t, uint64_t >::pair kv = jl.atOrAfter( 4 );
std::cout << "k " << kv.key << " v " << kv.value << std::endl;
long v = jl.find( 11 );
if( v != 0 || jl.success() ) {
std::cout << "find: false positive - v: " << v << " success: " << jl.success() << std::endl;
exit( EXIT_FAILURE );
}
v = jl.find( 7 );
if( v != 312 || !jl.success() ) {
std::cout << "find: false negative - v: " << v << " success: " << jl.success() << std::endl;
exit( EXIT_FAILURE );
}
jl.clear();
//TODO test all of judyLArray
exit( EXIT_SUCCESS );
}
+75
View File
@@ -0,0 +1,75 @@
#include <iostream>
#include <stdint.h>
#include <stdlib.h>
#include "judyS2Array.h"
typedef judyS2Array< uint64_t > js2a;
bool testFind( js2a & j, const char * key, unsigned int count ) {
js2a::cvector * v = j.find( key );
std::cout << "find: key " << key << " ..." << std::endl;
if( count > 0 ) {
if( !v || !j.success() || ( v->size() != count ) ) {
std::cout << " false negative - v: " << v << " success: " << j.success();
if( v ) {
std::cout << " expected count: " << count << " actual: " << v->size();
}
std::cout << std::endl;
return false;
} else {
// note - this doesn't verify that the right keys are returned, just the right number!
js2a::vector::const_iterator it = v->begin();
std::cout << " correct number of values -";
for( ; it != v->end(); it++ ) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
} else {
if( v || j.success() ) {
std::cout << " false positive - v: " << v << " success: " << j.success() << std::endl;
return false;
} else {
std::cout << " not found, as expected." << std::endl;
}
}
return true;
}
int main() {
bool pass = true;
std::cout.setf( std::ios::boolalpha );
js2a js( 255 );
js.insert( "blah", 1234 );
js.insert( "bah", 124 );
js.insert( "blh", 123 );
js.insert( "blh", 4123 );
js.insert( "bla", 134 );
js.insert( "bh", 234 );
js2a::cpair kv = js.atOrAfter( "ab" );
std::cout << "atOrAfter test ..." << std::endl;
if( kv.value != 0 && js.success() ) {
std::cout << " key " << kv.key << " value " << kv.value->at( 0 ) << std::endl;
} else {
std::cout << " failed" << std::endl;
pass = false;
}
pass &= testFind( js, "sdafsd", 0 );
pass &= testFind( js, "bah", 1 );
pass &= testFind( js, "blh", 2 );
js.clear();
//TODO test all of judyS2Array
if( pass ) {
std::cout << "All tests passed." << std::endl;
exit( EXIT_SUCCESS );
} else {
std::cout << "At least one test failed." << std::endl;
exit( EXIT_FAILURE );
}
}
+43
View File
@@ -0,0 +1,43 @@
#include <iostream>
#include <stdint.h>
#include <stdlib.h>
#include "judySArray.h"
int main() {
bool pass = true;
std::cout.setf( std::ios::boolalpha );
judySArray< uint64_t > js( 255 );
js.insert( "blah", 1234 );
js.insert( "bah", 124 );
js.insert( "blh", 123 );
js.insert( "bla", 134 );
js.insert( "bh", 234 );
judySArray< uint64_t >::pair kv = js.atOrAfter( "ab" );
//TODO if()...
std::cout << "k " << kv.key << " v " << kv.value << std::endl;
long v = js.find( "sdafsd" );
if( v != 0 || js.success() ) {
std::cout << "find: false positive - v: " << v << " success: " << js.success() << std::endl;
pass = false;
}
v = js.find( "bah" );
if( v != 124 || !js.success() ) {
std::cout << "find: false negative - v: " << v << " success: " << js.success() << std::endl;
pass = false;
}
//TODO test all of judySArray
if( pass ) {
std::cout << "All tests passed." << std::endl;
exit( EXIT_SUCCESS );
} else {
std::cout << "At least one test failed." << std::endl;
exit( EXIT_FAILURE );
}
}
+236
View File
@@ -0,0 +1,236 @@
// Judy arrays 13 DEC 2012 (judy64n.c from http://code.google.com/p/judyarray/ )
// This code is public domain.
// Author Karl Malbrain, malbrain AT yahoo.com
// with assistance from Jan Weiss.
// modifications (and any bugs) by Mark Pictor, mpictor at gmail
// Simplified judy arrays for strings and integers
// Adapted from the ideas of Douglas Baskins of HP.
// Map a set of keys to corresponding memory cells (uints).
// Each cell must be set to a non-zero value by the caller.
// STANDALONE is defined to compile into a string sorter.
// String mappings are denoted by calling judy_open with zero as
// the second argument.
#ifndef STANDALONE
# error must define STANDALONE while compiling this file and judy64.c
#endif
#include "judy.h"
#include "sort.h"
unsigned int MaxMem = 0;
// usage:
// a.out [in-file] [out-file] [keysize] [recordlen] [keyoffset] [mergerecs]
// where keysize is 10 to indicate pennysort files
// ASKITIS compilation:
// g++ -O3 -fpermissive -fomit-frame-pointer -w -D STANDALONE -D ASKITIS -o judy64n judy64n.c
// ./judy64n [input-file-to-build-judy] e.g. distinct_1 or skew1_1
// note: the judy array is an in-memory data structure. As such, make sure you
// have enough memory to hold the entire input file + data structure, otherwise
// you'll have to break the input file into smaller pieces and load them in
// on-by-one.
// Also, the file to search judy is hardcoded to skew1_1.
int main( int argc, char ** argv ) {
unsigned char buff[1024];
JudySlot max = 0;
JudySlot * cell;
FILE * in, *out;
void * judy;
unsigned int len;
unsigned int idx;
#ifdef ASKITIS
char * askitis;
int prev, off;
float insert_real_time = 0.0;
float search_real_time = 0.0;
int size;
#if !defined(_WIN32)
timer start, stop;
#else
time_t start[1], stop[1];
#endif
#endif
if( argc > 1 ) {
in = fopen( argv[1], "rb" );
} else {
in = stdin;
}
if( argc > 2 ) {
out = fopen( argv[2], "wb" );
} else {
out = stdout;
}
setvbuf( out, NULL, _IOFBF, 4096 * 1024 );
if( !in ) {
fprintf( stderr, "unable to open input file\n" );
}
if( !out ) {
fprintf( stderr, "unable to open output file\n" );
}
if( argc > 6 ) {
PennyRecs = atoi( argv[6] );
}
if( argc > 5 ) {
PennyOff = atoi( argv[5] );
}
if( argc > 4 ) {
PennyLine = atoi( argv[4] );
}
PennyMerge = ( unsigned long long )PennyLine * PennyRecs;
if( argc > 3 ) {
PennyKey = atoi( argv[3] );
sort( in, argv[2] );
return merge( out, argv[2] );
}
#ifdef ASKITIS
judy = judy_open( 1024, 0 );
// build judy array
size = lseek( fileno( in ), 0L, 2 );
askitis = malloc( size );
lseek( fileno( in ), 0L, 0 );
read( fileno( in ), askitis, size );
prev = 0;
// naskitis.com:
// Start the timer.
#if !defined(_WIN32)
gettimeofday( &start, NULL );
#else
time( start );
#endif
for( off = 0; off < size; off++ )
if( askitis[off] == '\n' ) {
*( judy_cell( judy, askitis + prev, off - prev ) ) += 1; // count instances of string
prev = off + 1;
}
// naskitis.com:
// Stop the timer and do some math to compute the time required to insert the strings into the judy array.
#if !defined(_WIN32)
gettimeofday( &stop, NULL );
insert_real_time = 1000.0 * ( stop.tv_sec - start.tv_sec ) + 0.001 * ( stop.tv_usec - start.tv_usec );
insert_real_time = insert_real_time / 1000.0;
#else
time( stop );
insert_real_time = *stop - *start;
#endif
// naskitis.com:
// Free the input buffer used to store the first file. We must do this before we get the process size below.
free( askitis );
fprintf( stderr, "JudyArray@Karl_Malbrain\nDASKITIS option enabled\n-------------------------------\n%-20s %.2f MB\n%-20s %.2f sec\n",
"Judy Array size:", MaxMem / 1000000., "Time to insert:", insert_real_time );
fprintf( stderr, "%-20s %d\n", "Words:", Words );
fprintf( stderr, "%-20s %d\n", "Inserts:", Inserts );
fprintf( stderr, "%-20s %d\n", "Found:", Found );
Words = 0;
Inserts = 0;
Found = 0;
// search judy array
if( in = freopen( "skew1_1", "rb", in ) ) {
size = lseek( fileno( in ), 0L, 2 );
} else {
exit( 0 );
}
askitis = malloc( size );
lseek( fileno( in ), 0L, 0 );
read( fileno( in ), askitis, size );
prev = 0;
#if !defined(_WIN32)
gettimeofday( &start, NULL );
#else
time( start );
#endif
for( off = 0; off < size; off++ )
if( askitis[off] == '\n' ) {
*judy_cell( judy, askitis + prev, off - prev ) += 1;
prev = off + 1;
}
// naskitis.com:
// Stop the timer and do some math to compute the time required to search the judy array.
#if !defined(_WIN32)
gettimeofday( &stop, NULL );
search_real_time = 1000.0 * ( stop.tv_sec - start.tv_sec ) + 0.001
* ( stop.tv_usec - start.tv_usec );
search_real_time = search_real_time / 1000.0;
#else
time( stop );
search_real_time = *stop - *start;
#endif
// naskitis.com:
// To do: report a count on the number of strings found.
fprintf( stderr, "\n%-20s %.2f MB\n%-20s %.2f sec\n",
"Judy Array size:", MaxMem / 1000000., "Time to search:", search_real_time );
fprintf( stderr, "%-20s %d\n", "Words:", Words );
fprintf( stderr, "%-20s %d\n", "Inserts:", Inserts );
fprintf( stderr, "%-20s %d\n", "Found:", Found );
exit( 0 );
#endif
judy = judy_open( 1024, 0 );
while( fgets( ( char * )buff, sizeof( buff ), in ) ) {
if( len = strlen( ( const char * )buff ) ) {
buff[--len] = 0; // remove LF
}
*( judy_cell( judy, buff, len ) ) += 1; // count instances of string
max++;
}
fprintf( stderr, "%" PRIuint " memory used\n", MaxMem );
cell = judy_strt( judy, NULL, 0 );
if( cell ) do {
len = judy_key( judy, buff, sizeof( buff ) );
for( idx = 0; idx < *cell; idx++ ) { // spit out duplicates
fwrite( buff, len, 1, out );
fputc( '\n', out );
}
} while( cell = judy_nxt( judy ) );
#if 0
// test deletion all the way to an empty tree
if( cell = judy_prv( judy ) )
do {
max -= *cell;
} while( cell = judy_del( judy ) );
assert( max == 0 );
#endif
judy_close( judy );
return 0;
}
+233
View File
@@ -0,0 +1,233 @@
// Judy arrays 13 DEC 2012 (judy64n.c from http://code.google.com/p/judyarray/ )
// This code is public domain.
// Author Karl Malbrain, malbrain AT yahoo.com
// with assistance from Jan Weiss.
// modifications (and any bugs) by Mark Pictor, mpictor at gmail
// Simplified judy arrays for strings and integers
// Adapted from the ideas of Douglas Baskins of HP.
// Map a set of keys to corresponding memory cells (uints).
// Each cell must be set to a non-zero value by the caller.
// STANDALONE is defined to compile into a string sorter.
// String mappings are denoted by calling judy_open with zero as
// the second argument. Integer mappings are denoted by calling
// judy_open with the Integer depth of the Judy Trie as the second
// argument.
#include "judy.h"
#include "sort.h"
// memory map input file and sort
// define pennysort parameters
unsigned int PennyRecs = ( 4096 * 400 ); // records to sort to temp files
unsigned int PennyLine = 100; // length of input record
unsigned int PennyKey = 10; // length of input key
unsigned int PennyOff = 0; // key offset in input record
unsigned long long PennyMerge; // PennyRecs * PennyLine = file map length
unsigned int PennyPasses; // number of intermediate files created
unsigned int PennySortTime; // cpu time to run sort
unsigned int PennyMergeTime; // cpu time to run merge
void sort( FILE * infile, char * outname ) {
unsigned long long size, off, offset, part;
int ifd = fileno( infile );
char filename[512];
PennySort * line;
JudySlot * cell;
unsigned char * inbuff;
void * judy;
FILE * out;
#if defined(_WIN32)
HANDLE hndl, fm;
DWORD hiword;
FILETIME dummy[1];
FILETIME user[1];
#else
struct tms buff[1];
#endif
time_t start = time( NULL );
if( PennyOff + PennyKey > PennyLine ) {
fprintf( stderr, "Key Offset + Key Length > Record Length\n" ), exit( 1 );
}
offset = 0;
PennyPasses = 0;
#if defined(_WIN32)
hndl = ( HANDLE )_get_osfhandle( ifd );
size = GetFileSize( hndl, &hiword );
fm = CreateFileMapping( hndl, NULL, PAGE_READONLY, hiword, ( DWORD )size, NULL );
if( !fm ) {
fprintf( stderr, "CreateFileMapping error %d\n", GetLastError() ), exit( 1 );
}
size |= ( unsigned long long )hiword << 32;
#else
size = lseek( ifd, 0L, 2 );
#endif
while( offset < size ) {
#if defined(_WIN32)
part = offset + PennyMerge > size ? size - offset : PennyMerge;
inbuff = MapViewOfFile( fm, FILE_MAP_READ, offset >> 32, offset, part );
if( !inbuff ) {
fprintf( stderr, "MapViewOfFile error %d\n", GetLastError() ), exit( 1 );
}
#else
inbuff = mmap( NULL, PennyMerge, PROT_READ, MAP_SHARED, ifd, offset );
if( inbuff == MAP_FAILED ) {
fprintf( stderr, "mmap error %d\n", errno ), exit( 1 );
}
if( madvise( inbuff, PennyMerge, MADV_WILLNEED | MADV_SEQUENTIAL ) < 0 ) {
fprintf( stderr, "madvise error %d\n", errno );
}
#endif
judy = judy_open( PennyKey, 0 );
off = 0;
// build judy array from mapped input chunk
while( offset + off < size && off < PennyMerge ) {
line = judy_data( judy, sizeof( PennySort ) );
cell = judy_cell( judy, inbuff + off + PennyOff, PennyKey );
line->next = *( void ** )cell;
line->buff = inbuff + off;
*( PennySort ** )cell = line;
off += PennyLine;
}
sprintf( filename, "%s.%d", outname, PennyPasses );
out = fopen( filename, "wb" );
setvbuf( out, NULL, _IOFBF, 4096 * 1024 );
#ifndef _WIN32
if( madvise( inbuff, PennyMerge, MADV_WILLNEED | MADV_RANDOM ) < 0 ) {
fprintf( stderr, "madvise error %d\n", errno );
}
#endif
// write judy array in sorted order to temporary file
cell = judy_strt( judy, NULL, 0 );
if( cell ) do {
line = *( PennySort ** )cell;
do {
fwrite( line->buff, PennyLine, 1, out );
} while( line = line->next );
} while( cell = judy_nxt( judy ) );
#if defined(_WIN32)
UnmapViewOfFile( inbuff );
#else
munmap( inbuff, PennyMerge );
#endif
judy_close( judy );
offset += off;
fflush( out );
fclose( out );
PennyPasses++;
}
fprintf( stderr, "End Sort %llu secs", ( unsigned long long ) time( NULL ) - start );
#if defined(_WIN32)
CloseHandle( fm );
GetProcessTimes( GetCurrentProcess(), dummy, dummy, dummy, user );
PennySortTime = *( unsigned long long * )user / 10000000;
#else
times( buff );
PennySortTime = buff->tms_utime / 100;
#endif
fprintf( stderr, " Cpu %d\n", PennySortTime );
}
int merge( FILE * out, char * outname ) {
time_t start = time( NULL );
char filename[512];
JudySlot * cell;
unsigned int nxt, idx;
unsigned char ** line;
unsigned int * next;
void * judy;
FILE ** in;
next = calloc( PennyPasses + 1, sizeof( unsigned int ) );
line = calloc( PennyPasses, sizeof( void * ) );
in = calloc( PennyPasses, sizeof( void * ) );
judy = judy_open( PennyKey, 0 );
// initialize merge with one record from each temp file
for( idx = 0; idx < PennyPasses; idx++ ) {
sprintf( filename, "%s.%d", outname, idx );
in[idx] = fopen( filename, "rb" );
line[idx] = malloc( PennyLine );
setvbuf( in[idx], NULL, _IOFBF, 4096 * 1024 );
fread( line[idx], PennyLine, 1, in[idx] );
cell = judy_cell( judy, line[idx] + PennyOff, PennyKey );
next[idx + 1] = *( unsigned int * )cell;
*cell = idx + 1;
}
// output records, replacing smallest each time
while( cell = judy_strt( judy, NULL, 0 ) ) {
nxt = *( unsigned int * )cell;
judy_del( judy );
// process duplicates
while( idx = nxt ) {
nxt = next[idx--];
fwrite( line[idx], PennyLine, 1, out );
if( fread( line[idx], PennyLine, 1, in[idx] ) ) {
cell = judy_cell( judy, line[idx] + PennyOff, PennyKey );
next[idx + 1] = *( unsigned int * )cell;
*cell = idx + 1;
} else {
next[idx + 1] = 0;
}
}
}
for( idx = 0; idx < PennyPasses; idx++ ) {
fclose( in[idx] );
free( line[idx] );
}
free( line );
free( next );
free( in );
fprintf( stderr, "End Merge %llu secs", ( unsigned long long ) time( NULL ) - start );
#ifdef _WIN32
{
FILETIME dummy[1];
FILETIME user[1];
GetProcessTimes( GetCurrentProcess(), dummy, dummy, dummy, user );
PennyMergeTime = *( unsigned long long * )user / 10000000;
}
#else
{
struct tms buff[1];
times( buff );
PennyMergeTime = buff->tms_utime / 100;
}
#endif
fprintf( stderr, " Cpu %d\n", PennyMergeTime - PennySortTime );
judy_close( judy );
fflush( out );
fclose( out );
return 0;
}
+58
View File
@@ -0,0 +1,58 @@
#ifndef SORT_H
#define SORT_H
// Judy arrays 13 DEC 2012 (judy64n.c from http://code.google.com/p/judyarray/ )
// This code is public domain.
// Author Karl Malbrain, malbrain AT yahoo.com
// with assistance from Jan Weiss.
// modifications (and any bugs) by Mark Pictor, mpictor at gmail
// Simplified judy arrays for strings and integers
// Adapted from the ideas of Douglas Baskins of HP.
// Map a set of keys to corresponding memory cells (uints).
// Each cell must be set to a non-zero value by the caller.
// STANDALONE is defined to compile into a string sorter.
// String mappings are denoted by calling judy_open with zero as
// the second argument. Integer mappings are denoted by calling
// judy_open with the Integer depth of the Judy Trie as the second
// argument.
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include "judy.h"
#ifdef linux
# include <fcntl.h>
# include <unistd.h>
# include <errno.h>
# include <sys/mman.h>
# include <sys/times.h>
#else
# include <windows.h>
# include <io.h>
#endif
#include <time.h>
#define PRIuint "u"
//these are initialized in penny.c
extern unsigned int PennyRecs;
extern unsigned int PennyLine;
extern unsigned int PennyKey;
extern unsigned int PennyOff;
extern unsigned long long PennyMerge;
typedef struct {
void * buff; // record pointer in input file map
void * next; // duplicate chain
} PennySort;
#endif //SORT_H
+29
View File
@@ -0,0 +1,29 @@
#include "path2str.h"
#include "sc_memmgr.h"
#include <string.h>
/* for windows, rewrite backslashes in paths
* that will be written to generated code
*/
const char * path2str_fn( const char * fileMacro ) {
static char * result = 0;
static size_t rlen = 0;
char * p;
if( rlen < strlen( fileMacro ) ) {
if( result ) {
sc_free( result );
}
rlen = strlen( fileMacro );
result = ( char * )sc_malloc( rlen * sizeof( char ) + 1 );
}
strcpy( result, fileMacro );
p = result;
while( *p ) {
if( *p == '\\' ) {
*p = '/';
}
p++;
}
return result;
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef PATH2STR_H
#define PATH2STR_H
#include <sc_export.h>
/** windows only: rewrite backslashes in paths as forward slashes
* call as path2str(__FILE__) to take advantage of macro
*
* silence "unknown escape sequence" warning when contents of __FILE__
* are fprintf'd into string in generated code
*/
SC_BASE_EXPORT const char * path2str_fn( const char * fileMacro );
#ifdef _WIN32
# define path2str(path) path2str_fn(path)
#else
# define path2str(path) path
#endif
#endif /* PATH2STR_H */
@@ -1,6 +1,7 @@
/// \file sc_benchmark.cc memory info, timers, etc for benchmarking
#include "./sc_benchmark.h"
#include "sc_benchmark.h"
#include "sc_memmgr.h"
#ifdef _WIN32
#include <windows.h>
@@ -2,11 +2,14 @@
#define SC_BENCHMARK_H
/// \file sc_benchmark.h memory info, timers, etc for benchmarking
#include "sc_export.h"
#ifdef __cplusplus
#include <iostream>
#include <iosfwd>
#include <string>
#include "sc_memmgr.h"
extern "C" {
#endif
@@ -20,7 +23,7 @@ extern "C" {
*
* not yet implemented for OSX or Windows.
*/
benchVals getMemAndTime( );
SC_BASE_EXPORT benchVals getMemAndTime( );
#ifdef __cplusplus
}
@@ -36,7 +39,7 @@ extern "C" {
* depends on getMemAndTime() above - may not work on all platforms.
*/
class benchmark {
class SC_BASE_EXPORT benchmark {
protected:
benchVals initialVals, laterVals;
#ifdef _MSC_VER
+214
View File
@@ -0,0 +1,214 @@
/****** RENAMED from xgetopt.cc to sc_getopt.cc ***********/
// XGetopt.cpp Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// Description:
// XGetopt.cpp implements sc_getopt(), a function to parse command lines.
//
// History
// Version 1.2 - 2003 May 17
// - Added Unicode support
//
// Version 1.1 - 2002 March 10
// - Added example to XGetopt.cpp module header
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// if you are using precompiled headers then include this line:
//#include "stdafx.h"
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// if you are not using precompiled headers then include these lines:
//#include <windows.h>
#include <stdio.h>
#include <string.h>
///////////////////////////////////////////////////////////////////////////////
#include "sc_getopt.h"
///////////////////////////////////////////////////////////////////////////////
//
// X G e t o p t . c p p
//
//
// NAME
// sc_getopt -- parse command line options
//
// SYNOPSIS
// int sc_getopt(int argc, char *argv[], char *optstring)
//
// extern char *sc_optarg;
// extern int sc_optind;
//
// DESCRIPTION
// The sc_getopt() function parses the command line arguments. Its
// arguments argc and argv are the argument count and array as
// passed into the application on program invocation. In the case
// of Visual C++ programs, argc and argv are available via the
// variables __argc and __argv (double underscores), respectively.
// sc_getopt returns the next option letter in argv that matches a
// letter in optstring. (Note: Unicode programs should use
// __targv instead of __argv. Also, all character and string
// literals should be enclosed in _T( ) ).
//
// optstring is a string of recognized option letters; if a letter
// is followed by a colon, the option is expected to have an argument
// that may or may not be separated from it by white space. sc_optarg
// is set to point to the start of the option argument on return from
// sc_getopt.
//
// Option letters may be combined, e.g., "-ab" is equivalent to
// "-a -b". Option letters are case sensitive.
//
// sc_getopt places in the external variable sc_optind the argv index
// of the next argument to be processed. sc_optind is initialized
// to 0 before the first call to sc_getopt.
//
// When all options have been processed (i.e., up to the first
// non-option argument), sc_getopt returns EOF, sc_optarg will point
// to the argument, and sc_optind will be set to the argv index of
// the argument. If there are no non-option arguments, sc_optarg
// will be set to NULL.
//
// The special option "--" may be used to delimit the end of the
// options; EOF will be returned, and "--" (and everything after it)
// will be skipped.
//
// RETURN VALUE
// For option letters contained in the string optstring, sc_getopt
// will return the option letter. sc_getopt returns a question mark (?)
// when it encounters an option letter not included in optstring.
// EOF is returned when processing is finished.
//
// BUGS
// 1) Long options are not supported.
// 2) The GNU double-colon extension is not supported.
// 3) The environment variable POSIXLY_CORRECT is not supported.
// 4) The + syntax is not supported.
// 5) The automatic permutation of arguments is not supported.
// 6) This implementation of sc_getopt() returns EOF if an error is
// encountered, instead of -1 as the latest standard requires.
//
// EXAMPLE
// BOOL CMyApp::ProcessCommandLine(int argc, char *argv[])
// {
// int c;
//
// while ((c = sc_getopt(argc, argv, _T("aBn:"))) != EOF)
// {
// switch (c)
// {
// case _T('a'):
// TRACE(_T("option a\n"));
// //
// // set some flag here
// //
// break;
//
// case _T('B'):
// TRACE( _T("option B\n"));
// //
// // set some other flag here
// //
// break;
//
// case _T('n'):
// TRACE(_T("option n: value=%d\n"), atoi(sc_optarg));
// //
// // do something with value here
// //
// break;
//
// case _T('?'):
// TRACE(_T("ERROR: illegal option %s\n"), argv[sc_optind-1]);
// return FALSE;
// break;
//
// default:
// TRACE(_T("WARNING: no handler for option %c\n"), c);
// return FALSE;
// break;
// }
// }
// //
// // check for non-option args here
// //
// return TRUE;
// }
//
///////////////////////////////////////////////////////////////////////////////
char * sc_optarg; // global argument pointer
int sc_optind = 0; // global argv index
int sc_getopt( int argc, char * argv[], char * optstring ) {
static char * next = NULL;
if( sc_optind == 0 ) {
next = NULL;
}
sc_optarg = NULL;
if( next == NULL || *next == '\0' ) {
if( sc_optind == 0 ) {
sc_optind++;
}
if( sc_optind >= argc || argv[sc_optind][0] != '-' || argv[sc_optind][1] == '\0' ) {
sc_optarg = NULL;
if( sc_optind < argc ) {
sc_optarg = argv[sc_optind];
}
return EOF;
}
if( strcmp( argv[sc_optind], "--" ) == 0 ) {
sc_optind++;
sc_optarg = NULL;
if( sc_optind < argc ) {
sc_optarg = argv[sc_optind];
}
return EOF;
}
next = argv[sc_optind];
next++; // skip past -
sc_optind++;
}
char c = *next++;
char * cp = strchr( optstring, c );
if( cp == NULL || c == ':' ) {
return '?';
}
cp++;
if( *cp == ':' ) {
if( *next != '\0' ) {
sc_optarg = next;
next = NULL;
} else if( sc_optind < argc ) {
sc_optarg = argv[sc_optind];
sc_optind++;
} else {
return '?';
}
}
return c;
}
+32
View File
@@ -0,0 +1,32 @@
/** \file sc_getopt.h
* this was xgetopt.h
* XGetopt.h Version 1.2
*
* Author: Hans Dietrich
* hdietrich2@hotmail.com
*
* This software is released into the public domain.
* You are free to use it in any way you like.
*
* This software is provided "as is" with no expressed
* or implied warranty. I accept no liability for any
* damage or loss of business that this software may cause.
*/
#ifndef XGETOPT_H
#define XGETOPT_H
#include "sc_export.h"
#ifdef __cplusplus
extern "C" {
#endif
extern SC_BASE_EXPORT int sc_optind, sc_opterr;
extern SC_BASE_EXPORT char * sc_optarg;
int SC_BASE_EXPORT sc_getopt( int argc, char * argv[], char * optstring );
#ifdef __cplusplus
}
#endif
#endif /* XGETOPT_H */
+405
View File
@@ -0,0 +1,405 @@
#define SC_MEMMGR_CC
#include "config.h"
#include "sc_memmgr.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <set>
#ifdef SC_MEMMGR_ENABLE_CHECKS
/**
sc_memmgr_error definition
*/
class sc_memmgr_error {
private:
std::string _srcfile;
unsigned int _srcline;
unsigned int _occurences;
public:
sc_memmgr_error( const std::string & file, const unsigned int line );
sc_memmgr_error( const sc_memmgr_error & rhs );
~sc_memmgr_error( void );
bool operator<( const sc_memmgr_error & rhs ) const;
std::string getsrcfile( void ) const;
unsigned int getsrcline( void ) const;
unsigned int getoccurences( void ) const;
};
typedef std::set<sc_memmgr_error> sc_memmgr_errors;
typedef std::set<sc_memmgr_error>::iterator sc_memmgr_error_iterator;
/**
sc_memmgr_record definition
*/
class sc_memmgr_record {
private:
void * _addr;
size_t _size;
std::string _srcfile;
unsigned int _srcline;
public:
sc_memmgr_record( void * addr, size_t size, const char * file, const unsigned int line );
sc_memmgr_record( void * addr );
sc_memmgr_record( const sc_memmgr_record & rhs );
~sc_memmgr_record( void );
bool operator<( const sc_memmgr_record & rhs ) const;
void * getaddr( void ) const;
size_t getsize( void ) const;
std::string getsrcfile( void ) const;
unsigned int getsrcline( void ) const;
};
typedef std::set<sc_memmgr_record> sc_memmgr_records;
typedef std::set<sc_memmgr_record>::iterator sc_memmgr_record_iterator;
#endif /* SC_MEMMGR_ENABLE_CHECKS */
/**
sc_memmgr definition
*/
class sc_memmgr {
private:
#ifdef SC_MEMMGR_ENABLE_CHECKS
bool _record_insert_busy, _record_erase_busy;
// memory allocation/reallocation records, inserted at allocation, erased at deallocation.
sc_memmgr_records _records;
// memory stats
unsigned int _allocated; // amount of memory allocated simultaniously
unsigned int _maximum_allocated; // maximum amount of memory allocated simultaniously
unsigned int _allocated_total; // total amount of memory allocated in bytes
unsigned int _reallocated_total; // total amount of memory reallocated in bytes
unsigned int _deallocated_total; // total amount of memory deallocated in bytes
#endif /* SC_MEMMGR_ENABLE_CHECKS */
protected:
public:
sc_memmgr( void );
~sc_memmgr( void );
void * allocate( size_t size, const char * file, const int line );
void * reallocate( void * addr, size_t size, const char * file, const int line );
void deallocate( void * addr, const char * file, const int line );
};
/**
sc_memmgr instance.
There should be one static instance of memmgr.
This instance is automatically destroyed when application exits, so this allows us to add
memory leak detection in it's destructor.
*/
sc_memmgr memmgr;
/**
c memory functions implementation
*/
extern "C" {
void * sc_malloc_fn( unsigned int size, const char * file, const int line ) {
return memmgr.allocate( size, file, line );
}
void * sc_calloc_fn( unsigned int count, unsigned int size, const char * file, const int line ) {
return memmgr.allocate( count * size, file, line );
}
void * sc_realloc_fn( void * addr, unsigned int size, const char * file, const int line ) {
return memmgr.reallocate( addr, size, file, line );
}
void sc_free_fn( void * addr ) {
memmgr.deallocate( addr, "", 0 );
}
}
/**
c++ memory operators implementation
*/
void * sc_operator_new( size_t size, const char * file, const int line ) {
return memmgr.allocate( size, file, line );
}
void sc_operator_delete( void * addr, const char * file, const int line ) {
memmgr.deallocate( addr, file, line );
}
void sc_operator_delete( void * addr ) {
memmgr.deallocate( addr, "", 0 );
}
/**
sc_memmgr implementation
*/
sc_memmgr::sc_memmgr( void ) {
#ifdef SC_MEMMGR_ENABLE_CHECKS
_record_insert_busy = false;
_record_erase_busy = false;
_allocated = 0;
_maximum_allocated = 0;
_allocated_total = 0;
_reallocated_total = 0;
_deallocated_total = 0;
#endif /* SC_MEMMGR_ENABLE_CHECKS */
}
/**
Destructor:
sc_memmgr::~sc_memmgr(void)
Description:
The sc_memmgr destructor is used to check for memory leaks when enabled.
All records still present when sc_memmgr instance is destroyed can be considered as
memory leaks.
*/
sc_memmgr::~sc_memmgr( void ) {
#ifdef SC_MEMMGR_ENABLE_CHECKS
sc_memmgr_record_iterator irecord;
sc_memmgr_errors errors;
sc_memmgr_error_iterator ierror;
// Check if total allocated equals total deallocated
if( _allocated_total != _deallocated_total ) {
// todo: generate warning for possible memory leaks, enable full memory leak checking
fprintf( stderr, "sc_memmgr warning: Possible memory leaks detected (%d of %d bytes)\n", _allocated_total - _deallocated_total, _allocated_total );
}
// Compact leaks into an error list to prevent same leak being reported multiple times.
_record_insert_busy = true;
_record_erase_busy = true;
for( irecord = _records.begin();
irecord != _records.end();
irecord ++ ) {
sc_memmgr_error error( irecord->getsrcfile(), irecord->getsrcline() );
ierror = errors.find( error );
if( ierror == errors.end() ) {
errors.insert( error );
}
//else
// ierror->occurences ++;
}
_record_insert_busy = false;
_record_erase_busy = false;
// Loop through memory leaks to generate/buffer errors
for( ierror = errors.begin();
ierror != errors.end();
ierror ++ ) {
// todo: generate error for memory leak
fprintf( stderr, "sc_memmgr warning: Possible memory leak in %s line %d\n", ierror->getsrcfile().c_str(), ierror->getsrcline() );
}
// Clear remaining records
_record_erase_busy = true;
_records.clear();
errors.clear();
_record_erase_busy = false;
#endif /* SC_MEMMGR_ENABLE_CHECKS */
}
void * sc_memmgr::allocate( size_t size, const char * file, const int line ) {
void * addr;
// Allocate
addr = malloc( size );
if( addr == NULL ) {
// todo: error allocation failed
fprintf( stderr, "sc_memmgr error: Memory allocation failed in %s line %d\n", file, line );
}
// Some stl implementations (for example debian gcc) use the new operator to construct
// new elements when inserting sc_memmgr_record. When this our new operator gets used
// for this operation, this would result in an infinite loop. This is fixed by the
// _record_insert_busy flag.
#ifdef SC_MEMMGR_ENABLE_CHECKS
if( !_record_insert_busy ) {
// Store record for this allocation
_record_insert_busy = true;
_records.insert( sc_memmgr_record( addr, size, file, line ) );
_record_insert_busy = false;
// Update stats
_allocated += size;
if( _allocated > _maximum_allocated ) {
_maximum_allocated = _allocated;
}
_allocated_total += size;
}
#endif /* SC_MEMMGR_ENABLE_CHECKS */
return addr;
}
void * sc_memmgr::reallocate( void * addr, size_t size, const char * file, const int line ) {
#ifdef SC_MEMMGR_ENABLE_CHECKS
sc_memmgr_record_iterator record;
if( !_record_insert_busy ) {
// Find record of previous allocation/reallocation
record = _records.find( sc_memmgr_record( addr ) );
if( record == _records.end() ) {
// todo: error reallocating memory not allocated?
fprintf( stderr, "sc_memmgr warning: Reallocation of not allocated memory at %s line %d\n", file, line );
} else {
// Update stats
_allocated -= record->getsize();
_deallocated_total += record->getsize();
// Erase previous allocation/reallocation
_record_erase_busy = true;
_records.erase( record );
_record_erase_busy = false;
}
}
#endif /* SC_MEMMGR_ENABLE_CHECKS */
// Reallocate
addr = realloc( addr, size );
if( addr == NULL ) {
// todo: error reallocation failed
fprintf( stderr, "sc_memmgr error: Reallocation failed at %s line %d\n", file, line );
}
#ifdef SC_MEMMGR_ENABLE_CHECKS
if( !_record_insert_busy ) {
// Store record for this reallocation
_record_insert_busy = true;
_records.insert( sc_memmgr_record( addr, size, file, line ) );
_record_insert_busy = false;
// Update stats
_allocated += size;
if( _allocated > _maximum_allocated ) {
_maximum_allocated = _allocated;
}
_allocated_total += size;
_reallocated_total += size;
}
#endif /* SC_MEMMGR_ENABLE_CHECKS */
return addr;
}
void sc_memmgr::deallocate( void * addr, const char * file, const int line ) {
#ifdef SC_MEMMGR_ENABLE_CHECKS
sc_memmgr_record_iterator record;
if( !_record_erase_busy ) {
// Find record of previous allocation/reallocation
record = _records.find( sc_memmgr_record( addr ) );
if( record == _records.end() ) {
// todo: error free called for not allocated memory?
fprintf( stderr, "sc_memmgr warning: Deallocate of not allocated memory at %s line %d\n", file, line );
} else {
// Update stats
_allocated -= record->getsize();
_deallocated_total += record->getsize();
// Erase record
_record_erase_busy = true;
_records.erase( record );
_record_erase_busy = false;
}
}
#else
(void) file; // quell unused param warnings
(void) line;
#endif /* SC_MEMMGR_ENABLE_CHECKS */
// Deallocate
free( addr );
}
#ifdef SC_MEMMGR_ENABLE_CHECKS
/**
sc_memmgr_error implementation
*/
sc_memmgr_error::sc_memmgr_error( const std::string & file, const unsigned int line ) {
_srcfile = file;
_srcline = line;
_occurences = 1;
}
sc_memmgr_error::sc_memmgr_error( const sc_memmgr_error & rhs ) {
_srcfile = rhs._srcfile;
_srcline = rhs._srcline;
_occurences = rhs._occurences;
}
sc_memmgr_error::~sc_memmgr_error( void ) {
}
bool sc_memmgr_error::operator<( const sc_memmgr_error & rhs ) const {
if( _srcfile == rhs._srcfile ) {
return _srcline < rhs._srcline;
}
return _srcfile < rhs._srcfile;
}
std::string sc_memmgr_error::getsrcfile( void ) const {
return _srcfile;
}
unsigned int sc_memmgr_error::getsrcline( void ) const {
return _srcline;
}
unsigned int sc_memmgr_error::getoccurences( void ) const {
return _occurences;
}
/**
sc_memmgr_record implementation
*/
sc_memmgr_record::sc_memmgr_record( void * addr, size_t size, const char * file, const unsigned int line ) {
_addr = addr;
_size = size;
_srcfile = file;
_srcline = line;
}
sc_memmgr_record::sc_memmgr_record( void * addr ) {
_addr = addr;
_size = 0;
_srcfile = "";
_srcline = -1;
}
sc_memmgr_record::sc_memmgr_record( const sc_memmgr_record & rhs ) {
_addr = rhs._addr;
_size = rhs._size;
_srcfile = rhs._srcfile;
_srcline = rhs._srcline;
}
sc_memmgr_record::~sc_memmgr_record( void ) {
}
bool sc_memmgr_record::operator<( const sc_memmgr_record & rhs ) const {
return _addr < rhs._addr;
}
void * sc_memmgr_record::getaddr( void ) const {
return _addr;
}
size_t sc_memmgr_record::getsize( void ) const {
return _size;
}
std::string sc_memmgr_record::getsrcfile( void ) const {
return _srcfile;
}
unsigned int sc_memmgr_record::getsrcline( void ) const {
return _srcline;
}
#endif /* SC_MEMMGR_ENABLE_CHECKS */
+79
View File
@@ -0,0 +1,79 @@
#ifndef SC_MEMMGR_H
#define SC_MEMMGR_H
#include <sc_export.h>
#include <stdlib.h>
#if defined(SC_MEMMGR_ENABLE_CHECKS)
#ifdef __cplusplus
#include <stddef.h>
extern "C" {
#endif /* __cplusplus */
SC_BASE_EXPORT void * sc_malloc_fn( unsigned int size, const char * file, const int line );
SC_BASE_EXPORT void * sc_calloc_fn( unsigned int count, unsigned int size, const char * file, const int line );
SC_BASE_EXPORT void * sc_realloc_fn( void * addr, unsigned int size, const char * file, const int line );
SC_BASE_EXPORT void sc_free_fn( void * addr );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#ifdef __cplusplus
SC_BASE_EXPORT void * sc_operator_new( size_t size, const char * file, const int line );
SC_BASE_EXPORT void sc_operator_delete( void * addr, const char * file, const int line );
SC_BASE_EXPORT void sc_operator_delete( void * addr );
#endif /* __cplusplus */
#ifndef SC_MEMMGR_CC
#define sc_malloc(size) sc_malloc_fn(size, __FILE__, __LINE__)
#define sc_calloc(count, size) sc_calloc_fn(count, size, __FILE__, __LINE__)
#define sc_realloc(addr, size) sc_realloc_fn(addr, size, __FILE__, __LINE__)
#define sc_free(addr) sc_free_fn(addr)
#ifdef __cplusplus
#include <new>
inline void * operator new( size_t size, const char * file, const int line ) throw (std::bad_alloc) {
return sc_operator_new( size, file, line );
}
inline void * operator new[]( size_t size, const char * file, const int line ) throw (std::bad_alloc) {
return sc_operator_new( size, file, line );
}
inline void operator delete( void * addr, const char * file, const int line ) throw (std::bad_alloc) {
sc_operator_delete( addr, file, line );
}
inline void operator delete[]( void * addr, const char * file, const int line ) throw (std::bad_alloc) {
sc_operator_delete( addr, file, line );
}
inline void operator delete( void * addr ) throw () {
sc_operator_delete( addr );
}
inline void operator delete[]( void * addr ) throw () {
sc_operator_delete( addr );
}
#define new new(__FILE__, __LINE__)
#endif /* __cplusplus */
#endif /* SC_MEMMGR_CC */
#else
#define sc_malloc(size) malloc(size)
#define sc_calloc(count, size) calloc(count, size)
#define sc_realloc(addr, size) realloc(addr, size)
#define sc_free(addr) free(addr)
#endif /* SC_MEMMGR_ENABLE_CHECKS */
#endif /* SC_MEMMGR_H */
+32
View File
@@ -0,0 +1,32 @@
#define _XOPEN_SOURCE /* for S_IFDIR */
#include "sc_mkdir.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#ifdef _WIN32
# include <direct.h>
#endif /* _WIN32 */
/* cross-platform mkdir */
int sc_mkdir( const char * path ) {
#ifdef _WIN32
return mkdir( path );
#else
return mkdir( path, 0777 );
#endif /* _WIN32 */
}
/* return -1 if error, 0 if created, 1 if dir existed already */
int mkDirIfNone( const char * path ) {
struct stat s;
if( stat( path, &s ) != 0 ) {
if( errno == ENOENT ) {
return sc_mkdir( path );
}
} else if( s.st_mode & S_IFDIR ) {
return 1;
}
/* either stat returned an error other than ENOENT, or 'path' exists but isn't a dir */
return -1;
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef SC_MKDIR
#define SC_MKDIR
#include <sc_export.h>
/** cross-platform mkdir() */
SC_BASE_EXPORT int sc_mkdir( const char * path );
/** create a dir 'path' if 'path' doesn't exist
* \return -1 if error, 0 if created, 1 if dir existed already
* if it returns -1, check errno
*/
SC_BASE_EXPORT int mkDirIfNone( const char * path );
#endif /* SC_MKDIR */
+39
View File
@@ -0,0 +1,39 @@
#ifndef __SC_STDIO_H
#define __SC_STDIO_H
/*
* https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
* (NOTE: MSVC defines va_list as a char*, so this should be safe)
*/
#if defined(_MSC_VER) && _MSC_VER < 1900
#include <stdarg.h>
static __inline int
c99_vsnprintf(char *buffer, size_t sz, const char *format, va_list ap) {
int count = -1;
if (sz != 0)
count = _vsnprintf_s(buffer, sz, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
static __inline int
c99_snprintf(char *buffer, size_t sz, const char *format, ...) {
int count;
va_list ap;
va_start(ap, format);
count = c99_vsnprintf(buffer, sz, format, ap);
va_end(ap);
return count;
}
#endif
#endif /* __SC_STDIO_H */
+11
View File
@@ -0,0 +1,11 @@
#ifndef SC_STRTOULL_H
#define SC_STRTOULL_H
#include <limits.h>
#ifdef _WIN32
# define strtoull _strtoui64
# define ULLONG_MAX _UI64_MAX
#endif
#endif /* SC_STRTOULL_H */
@@ -1,7 +1,8 @@
#include <stdarg.h>
#include <stdio.h>
#include "trace_fprintf.h"
#include "sc_trace_fprintf.h"
void trace_fprintf( char const * sourcefile, int line, FILE * file, const char * format, ... ) {
va_list args;
@@ -1,7 +1,7 @@
#ifndef SC_TRACE_FPRINTF_H
#define SC_TRACE_FPRINTF_H
/** \file trace_fprintf.h
/** \file sc_trace_fprintf.h
* Used to track the source file and line where generated code is printed from
* When enabled, comments are printed into the generated files for every 'fprintf':
* / * source: scl/src/exp2cxx/selects.c:1375 * /
@@ -20,7 +20,7 @@ extern "C" {
/** Used to find where generated c++ originates from in exp2cxx.
* To enable, configure with 'cmake .. -DSC_TRACE_FPRINTF=ON'
*/
void trace_fprintf( char const * sourcefile, int line, FILE * file, const char * format, ... );
SC_BASE_EXPORT void trace_fprintf( char const * sourcefile, int line, FILE * file, const char * format, ... );
#ifdef __cplusplus
}
#endif
+27 -16
View File
@@ -1,4 +1,5 @@
set(DAI_SRCS
set(LIBSTEPDAI_SRCS
sdaiApplication_instance_set.cc
sdaiBinary.cc
sdaiDaObject.cc
@@ -12,33 +13,43 @@ set(DAI_SRCS
sdaiString.cc
)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/include/stepcode
SET(SC_CLDAI_HDRS
sdaiApplication_instance_set.h
sdaiBinary.h
sdaiDaObject.h
sdaiEntity_extent.h
sdaiEntity_extent_set.h
sdaiEnum.h
sdaiModel_contents.h
sdaiModel_contents_list.h
sdaiObject.h
sdaiSession_instance.h
sdaiString.h
)
set(_libdeps steputils)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${SC_SOURCE_DIR}/src/base
${SC_SOURCE_DIR}/src/clstepcore
${SC_SOURCE_DIR}/src/clutils
)
set(_libdeps steputils base)
if(BUILD_SHARED_LIBS)
SC_ADDLIB(stepdai SHARED SOURCES ${DAI_SRCS} LINK_LIBRARIES ${_libdeps})
SC_ADDLIB(stepdai SHARED SOURCES ${LIBSTEPDAI_SRCS} LINK_LIBRARIES ${_libdeps})
if(WIN32)
target_compile_definitions(stepdai PRIVATE SC_DAI_DLL_EXPORTS)
endif()
endif()
if(BUILD_STATIC_LIBS)
# Spell the static dependency names out rather than composing them with a
# generator expression. Since 0b950dd1 SC_ADDLIB publishes LINK_LIBRARIES as
# PUBLIC, so anything given here lands in INTERFACE_LINK_LIBRARIES and is
# re-evaluated in each consumer - where a nested $<JOIN:...> comes back out
# mangled and reaches the linker verbatim.
set(_static_libdeps)
foreach(_libdep ${_libdeps})
list(APPEND _static_libdeps ${_libdep}-static)
endforeach()
SC_ADDLIB(stepdai-static STATIC SOURCES ${DAI_SRCS} LINK_LIBRARIES ${_static_libdeps})
SC_ADDLIB(stepdai-static STATIC SOURCES ${LIBSTEPDAI_SRCS} LINK_LIBRARIES $<JOIN:${_libdeps},-static >-static)
endif()
install(FILES ${SC_CLDAI_HDRS}
DESTINATION ${INCLUDE_DIR}/stepcode/cldai)
# Local Variables:
# tab-width: 8
# mode: cmake
+4 -3
View File
@@ -24,13 +24,14 @@
* UArray implementation.
*/
//#include "cldai/sdaiApplication_instance_set.h"
#include "clstepcore/sdai.h"
//#include <sdaiApplication_instance_set.h>
#include <sdai.h>
#include <memory.h>
#include <math.h>
#include "sc_memmgr.h"
#include "clstepcore/sdaiApplication_instance.h"
#include "sdaiApplication_instance.h"
// to help ObjectCenter
#ifndef HAVE_MEMMOVE
+5 -4
View File
@@ -10,7 +10,8 @@
*/
#include <sstream>
#include "clstepcore/sdai.h"
#include <sdai.h>
#include "sc_memmgr.h"
SDAI_Binary::SDAI_Binary( const char * str, int max ) {
content = std::string( str, max );
@@ -121,17 +122,17 @@ Severity SDAI_Binary::ReadBinary( istream & in, ErrorDescriptor * err, int Assig
if( !validDelimiters ) {
err->GreaterSeverity( SEVERITY_WARNING );
if( needDelims )
snprintf( messageBuf, sizeof(messageBuf),
sprintf( messageBuf,
"Binary value missing double quote delimiters.\n" );
else
snprintf( messageBuf, sizeof(messageBuf),
sprintf( messageBuf,
"Mismatched double quote delimiters for binary.\n" );
err->AppendToDetailMsg( messageBuf );
err->AppendToUserMsg( messageBuf );
}
} else {
err->GreaterSeverity( SEVERITY_WARNING );
snprintf( messageBuf, sizeof(messageBuf), "Invalid binary value.\n" );
sprintf( messageBuf, "Invalid binary value.\n" );
err->AppendToDetailMsg( messageBuf );
err->AppendToUserMsg( messageBuf );
}
+2 -1
View File
@@ -2,7 +2,8 @@
#include <memory.h>
#include <math.h>
#include "clstepcore/sdai.h"
#include <sdai.h>
#include "sc_memmgr.h"
// to help ObjectCenter
#ifndef HAVE_MEMMOVE
@@ -1,9 +1,9 @@
#ifndef SDAIDAOBJECT_H
#define SDAIDAOBJECT_H 1
#include "cldai/sdaiObject.h"
#include "cldai/sdaiString.h"
#include "cldai/sdaiEnum.h"
#include <sdaiObject.h>
#include <sdaiString.h>
#include <sdaiEnum.h>
#include <sc_export.h>
+2 -1
View File
@@ -2,7 +2,8 @@
//#include <EntityExtent.h>
#include "clstepcore/sdai.h"
#include <sdai.h>
#include "sc_memmgr.h"
SDAI_Entity_extent::SDAI_Entity_extent( )
: _definition( 0 ), _definition_name( 0 ), _owned_by( 0 ) {
+2 -1
View File
@@ -26,7 +26,8 @@
#include <memory.h>
#include <math.h>
#include "clstepcore/sdai.h"
#include <sdai.h>
#include "sc_memmgr.h"
/*
#include <EntityExtent.h>
+8 -7
View File
@@ -1,5 +1,6 @@
#include "clstepcore/sdai.h"
#include <sdai.h>
#include "sc_memmgr.h"
/*
* NIST STEP Core Class Library
@@ -211,10 +212,10 @@ Severity SDAI_LOGICAL::ReadEnum( istream & in, ErrorDescriptor * err, int Assign
if( !validDelimiters ) {
err->GreaterSeverity( SEVERITY_WARNING );
if( needDelims )
snprintf( messageBuf, sizeof(messageBuf),
sprintf( messageBuf,
"Enumerated value has invalid period delimiters.\n" );
else
snprintf( messageBuf, sizeof(messageBuf),
sprintf( messageBuf,
"Mismatched period delimiters for enumeration.\n" );
err->AppendToDetailMsg( messageBuf );
err->AppendToUserMsg( messageBuf );
@@ -241,7 +242,7 @@ Severity SDAI_LOGICAL::ReadEnum( istream & in, ErrorDescriptor * err, int Assign
} else {
in.putback( c );
err->GreaterSeverity( SEVERITY_WARNING );
snprintf( messageBuf, sizeof(messageBuf), "Invalid enumeration value.\n" );
sprintf( messageBuf, "Invalid enumeration value.\n" );
err->AppendToDetailMsg( messageBuf );
err->AppendToUserMsg( messageBuf );
}
@@ -489,10 +490,10 @@ Severity SDAI_Enum::ReadEnum( istream & in, ErrorDescriptor * err, int AssignVal
if( !validDelimiters ) {
err->GreaterSeverity( SEVERITY_WARNING );
if( needDelims )
snprintf( messageBuf, sizeof(messageBuf),
sprintf( messageBuf,
"Enumerated value has invalid period delimiters.\n" );
else
snprintf( messageBuf, sizeof(messageBuf),
sprintf( messageBuf,
"Mismatched period delimiters for enumeration.\n" );
err->AppendToDetailMsg( messageBuf );
err->AppendToUserMsg( messageBuf );
@@ -519,7 +520,7 @@ Severity SDAI_Enum::ReadEnum( istream & in, ErrorDescriptor * err, int AssignVal
} else {
in.putback( c );
err->GreaterSeverity( SEVERITY_WARNING );
snprintf( messageBuf, sizeof(messageBuf), "Invalid enumeration value.\n" );
sprintf( messageBuf, "Invalid enumeration value.\n" );
err->AppendToDetailMsg( messageBuf );
err->AppendToUserMsg( messageBuf );
}
+2 -1
View File
@@ -1,5 +1,6 @@
#include "clstepcore/sdai.h"
#include <sdai.h>
#include "sc_memmgr.h"
///////// SDAI_Model_contents_instances
+2 -1
View File
@@ -23,7 +23,8 @@
/*
* UArray implementation.
*/
#include "clstepcore/sdai.h"
#include <sdai.h>
#include "sc_memmgr.h"
// to help ObjectCenter
#ifndef HAVE_MEMMOVE
+2 -1
View File
@@ -1,4 +1,5 @@
#include "clstepcore/sdai.h"
#include <sdai.h>
#include "sc_memmgr.h"
SDAI_sdaiObject::SDAI_sdaiObject() {
}

Some files were not shown because too many files have changed in this diff Show More