Skip to content

Commit 55a2588

Browse files
authored
Merge pull request #47 from sillydan1/dev
Improvements found during testing
2 parents ac8532f + 08b24cd commit 55a2588

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2409
-104
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ test/**/results.txt
4343
# neovim autogenerated files
4444
compile_commands.json
4545
Debug/
46+
Release/
4647
.cache/
4748

.vscode/launch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"args": [
2020
"-f", "../test/verification/fischer-suite/fischer-2/",
2121
"-q", "../test/verification/fischer-suite/fischer-2/Queries.json",
22-
"-i", ".*\\.ignore.*"
22+
"-i", ".*\\.ignore.*",
23+
"-t", "/dev/null",
24+
"-v", "6"
2325
]
2426
}
2527
]

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
cmake_minimum_required(VERSION 3.16) # 3.16+ because of target_precompiled_header
17-
project(aaltitoad VERSION 1.1.0)
17+
project(aaltitoad VERSION 1.2.0)
1818
set(THREADS_PREFER_PTHREAD_FLAG ON)
1919
set(CMAKE_CXX_STANDARD 20)
2020
set(CXX_STANDARD_REQUIRED ON)

src/cli/verifier/cli_options.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
#ifndef AALTITOAD_CLI_OPTIONS_H
1919
#define AALTITOAD_CLI_OPTIONS_H
20+
#include "arguments.h"
2021
#include <vector>
2122
#include <argvparse.h>
2223
#include <iostream>
@@ -26,21 +27,26 @@
2627

2728
std::vector<option_t> get_options() {
2829
return {
29-
{"input", 'f', argument_requirement::REQUIRE_ARG, "(Required) input folder containing diagram files"},
30-
{"version", 'V', argument_requirement::NO_ARG, "Print version and exit"},
31-
{"verbosity", 'v', argument_requirement::REQUIRE_ARG, "Set verbosity level (6 for max verbosity)"},
32-
{"ignore", 'i', argument_requirement::REQUIRE_ARG, "GNU-style regex for filename(s) to ignore"},
30+
{"input", 'f', argument_requirement::REQUIRE_ARG, "(Required) input folder containing diagram files"},
31+
{"version", 'V', argument_requirement::NO_ARG, "Print version and exit"},
32+
{"verbosity", 'v', argument_requirement::REQUIRE_ARG, "Set verbosity level (6 for max verbosity)"},
33+
{"ignore", 'i', argument_requirement::REQUIRE_ARG, "GNU-style regex for filename(s) to ignore"},
3334

34-
{"parser", 'p', argument_requirement::REQUIRE_ARG, "Which parser to use"},
35-
{"query-file", 'q', argument_requirement::REQUIRE_ARG, "Query definition json file"},
36-
{"query", 'Q', argument_requirement::REQUIRE_ARG, "Add a CTL query to verify"},
35+
{"parser", 'p', argument_requirement::REQUIRE_ARG, "Which parser to use"},
36+
{"query-file", 'q', argument_requirement::REQUIRE_ARG, "Query definition json file"},
37+
{"query", 'Q', argument_requirement::REQUIRE_ARG, "Add a CTL query to verify"},
3738

38-
{"plugin-dir", 'P', argument_requirement::REQUIRE_ARG, "Directories to look for parser plugins"},
39-
{"list-plugins",'L', argument_requirement::NO_ARG, "List found plugins and exit"},
39+
{"pick-strategy", 's', argument_requirement::REQUIRE_ARG, "Waiting list pick strategy [first|last|random]. Default is first"},
4040

41-
{"disable-warn",'w', argument_requirement::REQUIRE_ARG, "Disable a warning"},
42-
{"list-warn", 'W', argument_requirement::NO_ARG, "List all warnings available"},
43-
{"no-warn", 'm', argument_requirement::NO_ARG, "Disable all warnings"},
41+
{"plugin-dir", 'P', argument_requirement::REQUIRE_ARG, "Directories to look for parser plugins"},
42+
{"list-plugins", 'L', argument_requirement::NO_ARG, "List found plugins and exit"},
43+
44+
{"disable-warn", 'w', argument_requirement::REQUIRE_ARG, "Disable a warning"},
45+
{"list-warn", 'W', argument_requirement::NO_ARG, "List all warnings available"},
46+
{"no-warn", 'm', argument_requirement::NO_ARG, "Disable all warnings"},
47+
48+
{"result-file", 't', argument_requirement::REQUIRE_ARG, "Provide file to output results to. Default is stdout"},
49+
{"result-json", 'j', argument_requirement::NO_ARG, "Output results as json. Useful for scripting"},
4450
};
4551
}
4652

src/cli/verifier/main.cpp

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
#include <aaltitoadpch.h>
1919
#include <ctl_syntax_tree.h>
20+
#include <ios>
2021
#include <ntta/tta.h>
2122
#include <timer>
2223
#include <plugin_system/plugin_system.h>
@@ -27,9 +28,11 @@
2728
#include <expr-lang/expr-scanner.hpp>
2829
#include <expr-lang/expr-parser.hpp>
2930
#include "expr-wrappers/ctl-interpreter.h"
31+
#include "magic_enum.hpp"
3032
#include "query/query_json_loader.h"
3133
#include "spdlog/common.h"
3234
#include "spdlog/spdlog.h"
35+
#include "verification/pick_strategy.h"
3336

3437
auto load_plugins(std::map<std::string, argument_t>& cli_arguments) -> plugin_map_t;
3538
void trace_log_ntta(const aaltitoad::ntta_t& n);
@@ -91,18 +94,44 @@ int main(int argc, char** argv) {
9194
}
9295
spdlog::debug("query parsing took {0}ms", t.milliseconds_elapsed());
9396

97+
auto strategy_s = cli_arguments["pick-strategy"].as_string_or_default("first");
98+
auto strategy = magic_enum::enum_cast<aaltitoad::pick_strategy>(strategy_s).value_or(aaltitoad::pick_strategy::first);
99+
spdlog::debug("using pick strategy '{0}'", magic_enum::enum_name(strategy));
100+
94101
n->add_tocker(std::make_unique<aaltitoad::interesting_tocker>());
95102
spdlog::trace("starting reachability search for {0} queries", queries.size());
96103
t.start();
97-
aaltitoad::forward_reachability_searcher frs{};
104+
aaltitoad::forward_reachability_searcher frs{strategy};
98105
auto results = frs.is_reachable(*n, queries);
99-
spdlog::debug("reachability search took {0}ms", t.milliseconds_elapsed());
100-
101-
// gather and return results
102-
for(auto& result : results) {
103-
std::cout << result.query << ": " << std::boolalpha << result.solution.has_value() << "\n";
104-
if(result.solution.has_value())
105-
std::cout << result.solution.value();
106+
spdlog::info("reachability search took {0}ms", t.milliseconds_elapsed());
107+
108+
// open the results file (std::cout by default)
109+
spdlog::trace("opening results file stream");
110+
auto* trace_stream = &std::cout;
111+
auto trace_file = cli_arguments["trace-file"].as_string_or_default("");
112+
if(trace_file != "")
113+
trace_stream = new std::ofstream{trace_file, std::ios::app};
114+
115+
// write json to results file or non-json if not provided
116+
if(cli_arguments["result-json"]) {
117+
spdlog::trace("gathering results json data");
118+
auto json_results = "[]"_json;
119+
for(auto& result : results) {
120+
nlohmann::json res{};
121+
std::stringstream ss{}; ss << result.query;
122+
res["query"] = ss.str();
123+
if(result.solution.has_value())
124+
res["trace"] = to_json(result.solution.value());
125+
json_results.push_back(res);
126+
}
127+
*trace_stream << json_results << std::endl;
128+
} else {
129+
spdlog::trace("printing resuls data (non-json)");
130+
for(auto& result : results) {
131+
*trace_stream << result.query << ": " << std::boolalpha << result.solution.has_value();
132+
if(result.solution.has_value())
133+
*trace_stream << result.solution.value();
134+
}
106135
}
107136

108137
return 0;

src/cli/verifier/query/query_json_loader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ namespace aaltitoad {
7373
if(v.operator_type == ctl::modal_op_t::E && std::get<ctl::quantifier_t>(c.node).operator_type == ctl::quantifier_op_t::F)
7474
return is_query_trivial(cc);
7575

76-
if(v.operator_type == ctl::modal_op_t::A && std::get<ctl::quantifier_t>(c.node).operator_type == ctl::quantifier_op_t::G)
77-
return is_query_trivial(cc);
76+
if(v.operator_type == ctl::modal_op_t::A && std::get<ctl::quantifier_t>(c.node).operator_type == ctl::quantifier_op_t::G) {
77+
spdlog::debug("safety queries (A G <query>) are not supported yet. See issue #41 if you need this feature");
78+
return false;
79+
}
7880

7981
return false;
8082
},

src/ntta/ntta_state_json.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/ntta/tta.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,28 @@ namespace aaltitoad {
183183
ss << *this;
184184
return ss.str();
185185
}
186+
187+
auto ntta_t::to_json() const -> nlohmann::json {
188+
nlohmann::json result{};
189+
result["locations"] = "[]"_json;
190+
for(auto& component : components) {
191+
auto j = "{}"_json;
192+
j[component.first] = component.second.current_location->first;
193+
result["locations"].push_back(j);
194+
}
195+
result["symbols"] = "{}"_json;
196+
for(auto& symbol : symbols + external_symbols) {
197+
std::visit(ya::overload(
198+
[&result, &symbol](const int& v){ result["symbols"][symbol.first] = v; },
199+
[&result, &symbol](const float& v){ result["symbols"][symbol.first] = v; },
200+
[&result, &symbol](const bool& v){ result["symbols"][symbol.first] = v; },
201+
[&result, &symbol](const std::string& v){ result["symbols"][symbol.first] = v; },
202+
[&result, &symbol](const expr::clock_t& v){ result["symbols"][symbol.first] = v.time_units; },
203+
[&result, &symbol](auto&& v){ result["symbols"][symbol.first] = "undefined"; }
204+
), static_cast<const expr::underlying_symbol_value_t&>(symbol.second));
205+
}
206+
return result;
207+
}
186208
}
187209

188210
auto operator<<(std::ostream& os, const aaltitoad::ntta_t& state) -> std::ostream& {

src/ntta/tta.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef AALTITOAD_TTA_H
1919
#define AALTITOAD_TTA_H
2020
#include "expr-wrappers/interpreter.h"
21+
#include <nlohmann/json.hpp>
2122
#include <string>
2223
#include <graph>
2324
#include <symbol_table.h>
@@ -117,6 +118,7 @@ namespace aaltitoad {
117118
void apply(const std::vector<expr::symbol_table_t>& external_symbol_change_list);
118119
void apply_internal(const expr::symbol_table_t& symbol_changes);
119120
auto to_string() const -> std::string;
121+
auto to_json() const -> nlohmann::json;
120122
private:
121123
class tick_resolver {
122124
public:

src/parser/hawk/scoped_template_builder/scoped_template_builder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "scoped_interpreter.h"
2121
#include "spdlog/spdlog.h"
2222
#include "util/string_extensions.h"
23+
#include "util/warnings.h"
2324
#include <ntta/builder/ntta_builder.h>
2425
#include <util/exceptions/parse_error.h>
2526

@@ -89,7 +90,7 @@ namespace aaltitoad::hawk {
8990
auto interpreter = construct_interpreter_from_scope(instance, scoped_name);
9091
auto decls = interpreter.parse_declarations(instance_template.declarations);
9192
if(internal_symbols.is_overlapping(decls))
92-
spdlog::warn("double declaration detected");
93+
warnings::warn(parser_warning, "double declaration detected");
9394
internal_symbols += decls;
9495

9596
call_func_aggregate_errors(instance_template.instances, [this, &scoped_name](auto& template_instance){

0 commit comments

Comments
 (0)