Skip to content

Commit

Permalink
Remove optional template with cpp_entity
Browse files Browse the repository at this point in the history
Sam was having issues getting this to compile. I had similar issues once
I tried to compile in CentOS 7. The errors are related to cpp_entity
being a virtual base class that can't be inside a template.
  • Loading branch information
Brandon committed Mar 4, 2019
1 parent 4bc58bf commit ad7751f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/asgn2/buildlist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
#define __CSE3150_TESTING_BUILDLIST_H

#include <algorithm>
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_function.hpp>
#include <cppast/cpp_template.hpp>
#include <cppast/cpp_type.hpp>
#include <cppast/libclang_parser.hpp>
#include <cppast/visitor.hpp>
#include <optional.hpp>

tl::optional<const cppast::cpp_entity&> find_build_list_fn(const cppast::cpp_file& file) {
tl::optional<const cppast::cpp_entity&> result = tl::nullopt;
// It'd be better to return an optional cpp_entity, but this breaks on some
// compilers.
const cppast::cpp_entity* find_build_list_fn(const cppast::cpp_file& file) {
const cppast::cpp_entity* result = nullptr;

cppast::visit(file, [&](const cppast::cpp_entity& e, cppast::visitor_info info) {
const auto is_function = e.kind() == cppast::cpp_entity_kind::function_t;
const auto correct_name = e.name() == "buildList";

if (is_function && correct_name) {
result = e;
result = &e;
}

// Stop visiting further nodes if we found the one we're looking for.
const auto should_keep_looking = result == tl::nullopt;
const auto should_keep_looking = result == nullptr;
return should_keep_looking;
});

Expand Down
4 changes: 2 additions & 2 deletions src/asgn2/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ TEST_CASE("Assignment 2") {
}

const auto build_list = find_build_list_fn(*w_list_file);
if (!build_list.has_value()) {
if (build_list == nullptr) {
FAIL("Make sure the \"buildList\" function exists in \"asgn2/q1/WList.cpp\"");
}

// Ew... casting. (The first-party example uses it too, so this may be
// required by the cppast API design.)
auto& build_list_fn = static_cast<const cppast::cpp_function&>(*build_list);
auto& build_list_fn = *static_cast<const cppast::cpp_function*>(build_list);

if (question.id == "q1" || question.id == "q3") {
INFO("\"buildList\" needs to take an \"std::list\" as a reference for q1.\"");
Expand Down

0 comments on commit ad7751f

Please sign in to comment.