Skip to content

Commit

Permalink
update CPM, Glue and remove lambda for default callback (#49)
Browse files Browse the repository at this point in the history
* update CPM, Glue and remove lambda for default callback

* update version
  • Loading branch information
TheLartians authored Oct 21, 2019
1 parent c41fdfb commit 18213ca
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
# ---- Project ----

project(LarsParser
VERSION 1.10
VERSION 1.11
LANGUAGES CXX
)

Expand Down Expand Up @@ -35,8 +35,8 @@ if(${LARS_PARSER_BUILD_GLUE_ELEMENT})
CPMAddPackage(
NAME Glue
GIT_REPOSITORY https://github.com/TheLartians/Glue.git
VERSION 0.9.5-n
GIT_TAG cc1ad543ac09988c67f8f9eec069a0f208b8f5a6
VERSION 0.9.6-a
GIT_TAG 1c77bce7a4fd97749caba8ac79d50af165a0a600
)
endif()

Expand Down
46 changes: 42 additions & 4 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

set(CURRENT_CPM_VERSION 0.12)
set(CURRENT_CPM_VERSION 0.14)

if(CPM_DIRECTORY)
if(NOT ${CPM_DIRECTORY} MATCHES ${CMAKE_CURRENT_LIST_DIR})
Expand All @@ -47,6 +47,13 @@ set(CPM_DRY_RUN OFF CACHE INTERNAL "Don't download or configure dependencies (fo
option(CPM_USE_LOCAL_PACKAGES "Use locally installed packages (find_package)" OFF)
option(CPM_LOCAL_PACKAGES_ONLY "Use only locally installed packages" OFF)

if(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE})
else()
set(CPM_SOURCE_CACHE_DEFAULT OFF)
endif()

set(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE_DEFAULT} CACHE PATH "Directory to downlaod CPM dependencies")

include(FetchContent)
include(CMakeParseArguments)
Expand All @@ -66,6 +73,8 @@ function(CPMAddPackage)
DOWNLOAD_ONLY
GITHUB_REPOSITORY
GITLAB_REPOSITORY
SOURCE_DIR
DOWNLOAD_COMMAND
)

set(multiValueArgs
Expand Down Expand Up @@ -150,16 +159,45 @@ function(CPMAddPackage)
endforeach()
endif()

CPM_DECLARE_PACKAGE(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} ${CPM_ARGS_GIT_TAG} "${CPM_ARGS_UNPARSED_ARGUMENTS}")
set(FETCH_CONTENT_DECLARE_EXTRA_OPTS "")

if (DEFINED CPM_ARGS_GIT_TAG)
set(PACKAGE_INFO "${CPM_ARGS_GIT_TAG}")
else()
set(PACKAGE_INFO "${CPM_ARGS_VERSION}")
endif()

if (DEFINED CPM_ARGS_DOWNLOAD_COMMAND)
set(FETCH_CONTENT_DECLARE_EXTRA_OPTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
else()
if (CPM_SOURCE_CACHE AND NOT DEFINED CPM_ARGS_SOURCE_DIR)
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
list(SORT origin_parameters)
string(SHA1 origin_hash "${origin_parameters}")
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS SOURCE_DIR ${download_directory})
if (EXISTS ${download_directory})
list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS DOWNLOAD_COMMAND ":")
set(PACKAGE_INFO "${download_directory}")
else()
# remove timestamps so CMake will re-download the dependency
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/_deps/${lower_case_name}-subbuild)
set(PACKAGE_INFO "${PACKAGE_INFO} -> ${download_directory}")
endif()
endif()
endif()

CPM_DECLARE_PACKAGE(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} ${PACKAGE_INFO} "${CPM_ARGS_UNPARSED_ARGUMENTS}" ${FETCH_CONTENT_DECLARE_EXTRA_OPTS})
CPM_FETCH_PACKAGE(${CPM_ARGS_NAME} ${DOWNLOAD_ONLY})
CPMGetProperties(${CPM_ARGS_NAME})
SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}" PARENT_SCOPE)
SET(${CPM_ARGS_NAME}_BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}" PARENT_SCOPE)
SET(${CPM_ARGS_NAME}_ADDED YES PARENT_SCOPE)
endfunction()

function (CPM_DECLARE_PACKAGE PACKAGE VERSION GIT_TAG)
message(STATUS "${CPM_INDENT} adding package ${PACKAGE}@${VERSION} (${GIT_TAG})")
function (CPM_DECLARE_PACKAGE PACKAGE VERSION INFO)
message(STATUS "${CPM_INDENT} adding package ${PACKAGE}@${VERSION} (${INFO})")

if (${CPM_DRY_RUN})
message(STATUS "${CPM_INDENT} package not declared (dry run)")
Expand Down
12 changes: 7 additions & 5 deletions include/lars/parser/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ namespace lars {
private:
std::unordered_map<peg::Rule *, Callback> evaluators;

public:

Callback defaultEvaluator = [](const Expression &e, Args... args){
static R __defaultEvaluator(const Expression &e, Args... args) {
size_t N = e.size();
if (N > 0) {
for(size_t i=0; i<N-1; ++i) { e[i].evaluate(args...); }
return e[N-1].evaluate(args...);
for(size_t i=0; i<N-1; ++i) { e[i].evaluate(std::forward<Args>(args)...); }
return e[N-1].evaluate(std::forward<Args>(args)...);
}
if (!std::is_same<R, void>::value) { throw InterpreterError(e.syntax()); }
};

public:

Callback defaultEvaluator = __defaultEvaluator;

std::shared_ptr<peg::Rule> makeRule(const std::string_view &name, const peg::GrammarNode::Shared &node, const Callback &callback){
auto rule = std::make_shared<peg::Rule>(name, node);
setEvaluator(rule, callback);
Expand Down

0 comments on commit 18213ca

Please sign in to comment.