Skip to content

Commit d3e2759

Browse files
committed
fix: solve todos
1 parent 4e80daa commit d3e2759

File tree

8 files changed

+45
-24
lines changed

8 files changed

+45
-24
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ option(ENABLE_Z3 "Enables the download and compilation of the expr::z3_driver dr
3434
CPMAddPackage("gh:yalibs/[email protected]")
3535
CPMAddPackage("gh:yalibs/[email protected]")
3636
CPMAddPackage("gh:yalibs/[email protected]")
37+
CPMAddPackage("gh:yalibs/[email protected]")
3738
# demo dependencies
3839
CPMAddPackage("gh:yalibs/[email protected]")
3940
CPMAddPackage("gh:sillydan1/[email protected]")
@@ -66,6 +67,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
6667
${yatimer_SOURCE_DIR}/include
6768
${yaoverload_SOURCE_DIR}/include
6869
${yahashcombine_SOURCE_DIR}/include
70+
${yauuid_SOURCE_DIR}/include
6971
${argvparse_SOURCE_DIR}/include
7072
${z3_SOURCE_DIR}/src/api/c++
7173
${z3_SOURCE_DIR}/include

src/driver/evaluator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace expr {
5353
},
5454
[&](const operator_t& o) {
5555
switch (o.operator_type) {
56-
// FIX: This this does not consider if children().size() > 2
56+
// TODO:: This this does not consider if children().size() > 2
5757
case operator_type_t::minus: return op.sub(evaluate(tree.children()[0]), evaluate(tree.children()[1]));
5858
case operator_type_t::plus: return op.add(evaluate(tree.children()[0]), evaluate(tree.children()[1]));
5959
case operator_type_t::star: return op.mul(evaluate(tree.children()[0]), evaluate(tree.children()[1]));

src/driver/z3/z3-driver.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,22 @@
2121
* SOFTWARE.
2222
*/
2323
#include "z3-driver.h"
24+
#include "implementation/uuid.h"
2425
#include "symbol_table.h"
26+
#include <uuid>
2527

2628
namespace expr {
27-
// TODO: delay_identfier should be randomly generated to avoid known/unknown collissions
29+
auto generate_unique_identifier(const symbol_table_t& env0, const symbol_table_t& env1) -> std::string {
30+
// Reroll until you hit something that hasn't been declared yet.
31+
// (this breaks if the environments declare ALL POSSIBLE UUIDv4 combinations, but that is very unlikely, so I consider that out-of-scope)
32+
auto result = ya::uuid_v4();
33+
while(env0.contains(result) || env1.contains(result))
34+
result = ya::uuid_v4();
35+
return result;
36+
}
37+
2838
z3_driver::z3_driver(const symbol_table_t& known, const symbol_table_t& unknown)
29-
: c{}, s{c}, delay_identifier{"d"}, known{known}, unknown{unknown} {}
39+
: c{}, s{c}, delay_identifier{generate_unique_identifier(known, unknown)}, known{known}, unknown{unknown} {}
3040

3141
auto z3_driver::find_solution(const syntax_tree_t& expression) -> std::optional<symbol_table_t> {
3242
s.add(as_z3(expression)); // NOTE: Only accepts boolean expressions (will throw if not)

src/expr-lang/ast-factory.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,5 @@ namespace expr {
5454
auto ast_factory::build_root(const syntax_tree_t& child) -> syntax_tree_t {
5555
return syntax_tree_t{}.concat(child);
5656
}
57-
58-
auto ast_factory::build_declaration(const std::string &identifier, const syntax_tree_t &tree, const symbol_access_modifier_t& access_modifier) -> syntax_tree_t {
59-
return build_declaration(identifier, tree, symbol_type_name_t::_auto, access_modifier);
60-
}
61-
62-
auto ast_factory::build_declaration(const std::string& identifier, const syntax_tree_t& tree, const symbol_type_name_t& type_name, const symbol_access_modifier_t& access_modifier) -> syntax_tree_t {
63-
// TODO: add the thing to the thing
64-
std::cout << identifier << " " << type_name << " " << access_modifier << ": " << tree << std::endl;
65-
return tree;
66-
}
6757
}
6858

src/expr-lang/ast-factory.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ namespace expr {
3838
virtual auto build_literal(const symbol_value_t& value) -> syntax_tree_t;
3939
virtual auto build_identifier(const std::string& identifier) -> syntax_tree_t;
4040
virtual auto build_root(const syntax_tree_t& child) -> syntax_tree_t;
41-
42-
virtual auto build_declaration(const std::string& identifier, const syntax_tree_t& tree, const symbol_access_modifier_t& access_modifier) -> syntax_tree_t;
43-
virtual auto build_declaration(const std::string& identifier, const syntax_tree_t& tree, const symbol_type_name_t& type_name = symbol_type_name_t::_auto, const symbol_access_modifier_t& access_modifier = symbol_access_modifier_t::_private) -> syntax_tree_t;
4441
};
4542
}
4643

src/expr-lang/expr.y

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,34 @@ lit:
148148
/* ================================================== */
149149

150150
void expr::parser::error(const location_type& l, const std::string& msg) {
151-
// TODO: This assumes that the input string is always 1 line - it will not look good on multiline inputs
151+
// TODO: We should print to the injected stream instead of directly to cerr
152+
// TODO: This should provide a WINDOW to peek into rather than print the entire file/expression
153+
// TODO: This is a mess... I can't use yylineno and l.begin/end.line is always just '1' so this insane code will suffice for now
152154
if(args.expression) {
153-
std::cerr << msg << "\n" << args.expression.value() << "\n";
154-
for(int i = 0; i < l.begin.column - 1; i++)
155-
std::cerr << "_";
156-
std::cerr << "^\n";
155+
std::cerr << msg << " between column " << l.begin.column << " and " << l.end.column << ":\n";
156+
auto& e = args.expression.value();
157+
int i = 0; int offset = 0;
158+
for(; i < l.begin.column - 1; i++, offset++) {
159+
if(e[i] == '\n')
160+
offset = 0;
161+
std::cerr << e[i];
162+
}
163+
for(; i < l.end.column - 1; i++)
164+
std::cerr << e[i];
165+
for(; i < e.size() - 1; i++) {
166+
if(e[i] == '\n')
167+
break;
168+
std::cerr << e[i];
169+
}
170+
std::cerr << "\n";
171+
for(int j = 0; j < offset-1; j++)
172+
std::cerr << "~";
173+
for(int j = l.begin.column - 1; j < l.end.column-1; j++)
174+
std::cerr << "^";
175+
std::cerr << "\n";
176+
for(i++; i < e.size() - 1; i++)
177+
std::cerr << e[i];
178+
std::cerr << "\n";
157179
} else
158180
std::cerr << msg << " at " << l << "\n"; // boring
159181
}

src/expr-lang/language-builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace expr {
3939
}
4040

4141
auto declaration_tree_builder::build() -> result_t {
42-
return result; // TODO: check for proper build
42+
return result;
4343
}
4444
}
4545

src/generic-driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace expr {
9797
parser_args pa{s, &sc, &factory, &builder};
9898
parser p{pa};
9999
if(p.parse() != 0)
100-
throw std::logic_error("unable to parse the expression(s)" + s);
100+
throw std::logic_error("unable to parse the expression(s)");
101101
auto res = builder.build();
102102
for(auto& e : res.declarations)
103103
declarations[e.first] = e.second.tree;
@@ -113,7 +113,7 @@ namespace expr {
113113
parser_args pa{s, &sc, &factory, &builder};
114114
parser p{pa};
115115
if(p.parse() != 0)
116-
throw std::logic_error("unable to parse the expression(s): " + s);
116+
throw std::logic_error("unable to parse the expression(s)");
117117
auto res = builder.build();
118118
symbol_operator op{};
119119
evaluator e{{}, op};

0 commit comments

Comments
 (0)