Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Feb 17, 2024
1 parent fc20ff9 commit 5cae49d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
project(loki VERSION "0.0.1" LANGUAGES C CXX)

# Compilation flags, some configuration-specific
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -pedantic -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wuninitialized -pedantic -fPIC")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS_DEBUG "-O3 -DDEBUG")

Expand Down
18 changes: 13 additions & 5 deletions include/loki/common/pddl/persistent_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,28 @@ class PersistentFactory {
/// @brief Returns a pointer to an existing object
/// or creates it before if it does not exist.v
template<typename SubType, typename... Args>
[[nodiscard]] HolderType const* get_or_create(Args&&... args) {
[[nodiscard]] HolderType const* get_or_create(Args... args) {
std::lock_guard<std::mutex> hold(m_mutex);
/* Construct and insert the element in persistent memory. */
size_t identifier = m_count;
// Ensure that element with identifier i is stored at position i.
assert((identifier == (m_persistent_vector.size()-1))
|| (identifier == m_persistent_vector.size()));
// Explicitly call the constructor of T to give exclusive access to the factory.
auto element = HolderType(std::move(SubType(identifier, std::forward<Args>(args)...)));
auto element = HolderType(std::move(SubType(identifier, args...)));
bool overwrite_last_element = (identifier == m_persistent_vector.size() - 1);
// The pointer to the location in persistent memory.
const auto* element_ptr = overwrite_last_element
? &(m_persistent_vector[identifier] = std::move(element))
: &(m_persistent_vector.push_back(std::move(element)));
const auto* element_ptr = static_cast<const HolderType*>(nullptr);
if (overwrite_last_element) {
const auto& persistent_element = m_persistent_vector[identifier] = std::move(element);
element_ptr = &persistent_element;
} else {
const auto& persistent_element = m_persistent_vector.push_back(std::move(element));
element_ptr = &persistent_element;
}
if (!element_ptr) {
throw std::runtime_error("element_ptr is nullptr");
}
assert(element_ptr);
/* Test for uniqueness */
auto it = m_uniqueness_set.find(element_ptr);
Expand Down
7 changes: 3 additions & 4 deletions src/domain/pddl/parser/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,16 @@ pddl::ObjectList ConstantListVisitor::operator()(const std::vector<ast::Name>& n
assert(context.scopes.get<pddl::TypeImpl>("object").has_value());
const auto& [type, _position, _error_handler] = context.scopes.get<pddl::TypeImpl>("object").value();
const auto type_list = pddl::TypeList{type};
const auto constant_list = parse_constant_definitions(name_nodes, type_list, context);
return constant_list;
return parse_constant_definitions(name_nodes, type_list, context);
}

pddl::ObjectList ConstantListVisitor::operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node) {
if (!context.requirements->test(pddl::RequirementEnum::TYPING)) {
throw UndefinedRequirementError(pddl::RequirementEnum::TYPING, context.scopes.get_error_handler()(typed_list_of_names_recursively_node, ""));
}
context.references.untrack(pddl::RequirementEnum::TYPING);
const auto type_list = boost::apply_visitor(TypeReferenceTypeVisitor(context),
typed_list_of_names_recursively_node.type);
const auto type_list = boost::apply_visitor(
TypeReferenceTypeVisitor(context), typed_list_of_names_recursively_node.type);
// TypedListOfNamesRecursively has user defined base types
auto constant_list = parse_constant_definitions(typed_list_of_names_recursively_node.names, type_list, context);
// Recursively add objects.
Expand Down

0 comments on commit 5cae49d

Please sign in to comment.