diff --git a/src/constructor.cpp b/src/constructor.cpp index dfefc29..eb1e6c7 100644 --- a/src/constructor.cpp +++ b/src/constructor.cpp @@ -57,7 +57,7 @@ namespace riddle } if (auto c = tp->get_constructor(arg_types)) - instance->items.emplace(init.get_name().id, c.value().get().invoke(std::move(arguments))); + instance->items.emplace(init.get_name().id, c->get().invoke(std::move(arguments))); else throw std::runtime_error("Cannot find constructor for class " + init.get_name().id); } @@ -77,7 +77,7 @@ namespace riddle } if (auto c = (*st).get().get_constructor(arg_types)) - instance->items.emplace(init.get_name().id, c.value().get().invoke(std::move(arguments))); + instance->items.emplace(init.get_name().id, c->get().invoke(std::move(arguments))); else throw std::runtime_error("Cannot find supertype " + init.get_name().id + "."); } @@ -104,7 +104,7 @@ namespace riddle else if (auto c_tp = dynamic_cast(&f->get_type())) { if (auto c = c_tp->get_constructor({xpr->get_type()})) - instance->items.emplace(f_name, c.value().get().invoke({xpr})); + instance->items.emplace(f_name, c->get().invoke({xpr})); else throw std::runtime_error("Cannot find constructor for class " + f->get_type().get_name()); } @@ -125,7 +125,7 @@ namespace riddle if (auto c_tp = dynamic_cast(&f->get_type())) { if (auto c = c_tp->get_constructor(arg_types)) - instance->items.emplace(f_name, c.value().get().invoke(std::move(arguments))); + instance->items.emplace(f_name, c->get().invoke(std::move(arguments))); else throw std::runtime_error("Cannot find constructor for class " + f->get_type().get_name()); } diff --git a/src/declaration.cpp b/src/declaration.cpp index 4f19621..ec67b2b 100644 --- a/src/declaration.cpp +++ b/src/declaration.cpp @@ -32,14 +32,14 @@ namespace riddle } void enum_declaration::refine(scope &scp) const { - auto et = static_cast(&scp.get_type(name.id).value().get()); // cast is safe because the type was declared in the same scope + auto et = static_cast(&scp.get_type(name.id)->get()); // cast is safe because the type was declared in the same scope for (const auto &er : enum_refs) { auto t = scp.get_type(er[0].id); if (!t) throw std::invalid_argument("[" + std::to_string(er[0].start_line) + ", " + std::to_string(er[0].start_pos) + "] type `" + er[0].id + "` not found"); for (size_t i = 1; i < er.size(); ++i) - if (auto ct = dynamic_cast(&t.value().get())) + if (auto ct = dynamic_cast(&t->get())) { t = ct->get_type(er[i].id); if (!t) @@ -47,7 +47,7 @@ namespace riddle } else throw std::invalid_argument("[" + std::to_string(er[i].start_line) + ", " + std::to_string(er[i].start_pos) + "] `" + er[i].id + "` is not a component type"); - if (auto c_et = dynamic_cast(&t.value().get())) + if (auto c_et = dynamic_cast(&t->get())) et->enums.emplace_back(*c_et); else throw std::invalid_argument("[" + std::to_string(er[er.size() - 1].start_line) + ", " + std::to_string(er[er.size() - 1].start_pos) + "] `" + er[er.size() - 1].id + "` is not an enum type"); @@ -60,7 +60,7 @@ namespace riddle if (!t) throw std::invalid_argument("[" + std::to_string(type_ids[0].start_line) + ", " + std::to_string(type_ids[0].start_pos) + "] type `" + type_ids[0].id + "` not found"); for (size_t i = 1; i < type_ids.size(); ++i) - if (auto ct = dynamic_cast(&t.value().get())) + if (auto ct = dynamic_cast(&t->get())) { t = ct->get_type(type_ids[i].id); if (!t) @@ -71,7 +71,7 @@ namespace riddle for (const auto &init : inits) { // we create the field and add it to the scope.. - auto f = std::make_unique(t.value().get(), init.get_name().id, init.get_args()); + auto f = std::make_unique(t->get(), init.get_name().id, init.get_args()); if (auto ct = dynamic_cast(&scp)) ct->add_field(std::move(f)); else if (auto cr = dynamic_cast(&scp)) @@ -91,7 +91,7 @@ namespace riddle if (!t) throw std::invalid_argument("[" + std::to_string(tp_ids[0].start_line) + ", " + std::to_string(tp_ids[0].start_pos) + "] type `" + tp_ids[0].id + "` not found"); for (size_t i = 1; i < tp_ids.size(); ++i) - if (auto ct = dynamic_cast(&t.value().get())) + if (auto ct = dynamic_cast(&t->get())) { t = ct->get_type(tp_ids[i].id); if (!t) @@ -99,7 +99,7 @@ namespace riddle } else throw std::invalid_argument("[" + std::to_string(tp_ids[i].start_line) + ", " + std::to_string(tp_ids[i].start_pos) + "] `" + tp_ids[i].id + "` is not a component type"); - args.push_back(std::make_unique(t.value().get(), id.id)); + args.push_back(std::make_unique(t->get(), id.id)); } // we create the constructor and add it to the scope.. @@ -119,7 +119,7 @@ namespace riddle if (!t) throw std::invalid_argument("[" + std::to_string(return_type[0].start_line) + ", " + std::to_string(return_type[0].start_pos) + "] type `" + return_type[0].id + "` not found"); for (size_t i = 1; i < return_type.size(); ++i) - if (auto ct = dynamic_cast(&t.value().get())) + if (auto ct = dynamic_cast(&t->get())) { t = ct->get_type(return_type[i].id); if (!t) @@ -127,7 +127,7 @@ namespace riddle } else throw std::invalid_argument("[" + std::to_string(return_type[i].start_line) + ", " + std::to_string(return_type[i].start_pos) + "] `" + return_type[i].id + "` is not a component type"); - rt = t.value().get(); + rt = t->get(); } std::vector> pars; // the method's arguments @@ -138,7 +138,7 @@ namespace riddle if (!t) throw std::invalid_argument("[" + std::to_string(tp_ids[0].start_line) + ", " + std::to_string(tp_ids[0].start_pos) + "] type `" + tp_ids[0].id + "` not found"); for (size_t i = 1; i < tp_ids.size(); ++i) - if (auto ct = dynamic_cast(&t.value().get())) + if (auto ct = dynamic_cast(&t->get())) { t = ct->get_type(tp_ids[i].id); if (!t) @@ -146,7 +146,7 @@ namespace riddle } else throw std::invalid_argument("[" + std::to_string(tp_ids[i].start_line) + ", " + std::to_string(tp_ids[i].start_pos) + "] `" + tp_ids[i].id + "` is not a component type"); - pars.push_back(std::make_unique(t.value().get(), id.id)); + pars.push_back(std::make_unique(t->get(), id.id)); } auto m = std::make_unique(scp, rt, name.id, std::move(pars), std::move(body)); @@ -170,7 +170,7 @@ namespace riddle } void predicate_declaration::refine(scope &scp) const { - auto p = static_cast(&scp.get_predicate(name.id).value().get()); // cast is safe because the predicate was declared in the same scope + auto p = static_cast(&scp.get_predicate(name.id)->get()); // cast is safe because the predicate was declared in the same scope // the predicate's arguments for (const auto &[tp_ids, id] : parameters) @@ -179,7 +179,7 @@ namespace riddle if (!t) throw std::invalid_argument("[" + std::to_string(tp_ids[0].start_line) + ", " + std::to_string(tp_ids[0].start_pos) + "] type `" + tp_ids[0].id + "` not found"); for (size_t i = 1; i < tp_ids.size(); ++i) - if (auto ct = dynamic_cast(&t.value().get())) + if (auto ct = dynamic_cast(&t->get())) { t = ct->get_type(tp_ids[i].id); if (!t) @@ -187,7 +187,7 @@ namespace riddle } else throw std::invalid_argument("[" + std::to_string(tp_ids[i].start_line) + ", " + std::to_string(tp_ids[i].start_pos) + "] `" + tp_ids[i].id + "` is not a component type"); - p->add_field(std::make_unique(t.value().get(), id.id)); + p->add_field(std::make_unique(t->get(), id.id)); } } @@ -207,7 +207,7 @@ namespace riddle } void class_declaration::refine(scope &scp) const { - auto c_ct = static_cast(&scp.get_type(name.id).value().get()); // cast is safe because the type was declared in the same scope + auto c_ct = static_cast(&scp.get_type(name.id)->get()); // cast is safe because the type was declared in the same scope for (const auto &tp : base_classes) { @@ -215,7 +215,7 @@ namespace riddle if (!t) throw std::invalid_argument("[" + std::to_string(tp[0].start_line) + ", " + std::to_string(tp[0].start_pos) + "] type `" + tp[0].id + "` not found"); for (size_t i = 1; i < tp.size(); ++i) - if (auto ct = dynamic_cast(&t.value().get())) + if (auto ct = dynamic_cast(&t->get())) { t = ct->get_type(tp[i].id); if (!t) @@ -224,7 +224,7 @@ namespace riddle else throw std::invalid_argument("[" + std::to_string(tp[i].start_line) + ", " + std::to_string(tp[i].start_pos) + "] `" + tp[i].id + "` is not a component type"); - if (auto c_ct = dynamic_cast(&t.value().get())) + if (auto c_ct = dynamic_cast(&t->get())) c_ct->parents.emplace_back(*c_ct); else throw std::invalid_argument("[" + std::to_string(tp[tp.size() - 1].start_line) + ", " + std::to_string(tp[tp.size() - 1].start_pos) + "] `" + tp[tp.size() - 1].id + "` is not a component type"); @@ -248,7 +248,7 @@ namespace riddle } void class_declaration::refine_predicates(scope &scp) const { - auto c_ct = static_cast(&scp.get_type(name.id).value().get()); // cast is safe because the type was declared in the same scope + auto c_ct = static_cast(&scp.get_type(name.id)->get()); // cast is safe because the type was declared in the same scope // we refine the predicates.. for (const auto &p : predicates) p->refine(*c_ct); diff --git a/src/expression.cpp b/src/expression.cpp index 791898b..e94d742 100644 --- a/src/expression.cpp +++ b/src/expression.cpp @@ -23,7 +23,7 @@ namespace riddle auto tp_opt = scp.get_type(instance_type.front().id); if (!tp_opt) throw std::runtime_error("Cannot find class " + instance_type.front().id); - auto tp = dynamic_cast(&tp_opt.value().get()); + auto tp = dynamic_cast(&tp_opt->get()); if (!tp) throw std::runtime_error("Class " + instance_type.front().id + " is not a component type"); for (auto it = instance_type.begin() + 1; it != instance_type.end(); it++) @@ -31,7 +31,7 @@ namespace riddle tp_opt = tp->get_type(it->id); if (!tp_opt) throw std::runtime_error("Cannot find class " + it->id); - tp = dynamic_cast(&tp_opt.value().get()); + tp = dynamic_cast(&tp_opt->get()); if (!tp) throw std::runtime_error("Class " + it->id + " is not a component type"); } @@ -47,7 +47,7 @@ namespace riddle } if (auto c = tp->get_constructor(arg_types)) - return c.value().get().invoke(std::move(arguments)); + return c->get().invoke(std::move(arguments)); else throw std::runtime_error("Cannot find constructor for class " + instance_type.front().id); } @@ -88,7 +88,7 @@ namespace riddle if (!method_opt) throw std::runtime_error("Cannot find method " + function_name.id); - return method_opt.value().get().invoke(c_env, std::move(arguments)); + return method_opt->get().invoke(c_env, std::move(arguments)); } std::shared_ptr id_expression::evaluate(const scope &, std::shared_ptr ctx) const diff --git a/src/statement.cpp b/src/statement.cpp index 42de600..8d3e9e0 100644 --- a/src/statement.cpp +++ b/src/statement.cpp @@ -11,7 +11,7 @@ namespace riddle auto tp_opt = scp.get_type(field_type.front().id); if (!tp_opt) throw std::runtime_error("Cannot find class " + field_type.front().id); - auto tp = &tp_opt.value().get(); + auto tp = &tp_opt->get(); if (!tp) throw std::runtime_error("Class " + field_type.front().id + " is not a component type"); for (auto it = field_type.begin() + 1; it != field_type.end(); it++) @@ -20,7 +20,7 @@ namespace riddle tp_opt = cmp_tp->get_type(it->id); if (!tp_opt) throw std::runtime_error("Cannot find class " + it->id); - tp = &tp_opt.value().get(); + tp = &tp_opt->get(); } for (const auto &field : fields) @@ -112,7 +112,7 @@ namespace riddle auto tp_opt = scp.get_type(enum_type.front().id); if (!tp_opt) throw std::runtime_error("Cannot find class " + enum_type.front().id); - auto tp = dynamic_cast(&tp_opt.value().get()); + auto tp = dynamic_cast(&tp_opt->get()); if (!tp) throw std::runtime_error("Class " + enum_type.front().id + " is not a component type"); for (auto it = enum_type.begin() + 1; it != enum_type.end(); it++) @@ -120,7 +120,7 @@ namespace riddle tp_opt = tp->get_type(it->id); if (!tp_opt) throw std::runtime_error("Cannot find class " + it->id); - tp = dynamic_cast(&tp_opt.value().get()); + tp = dynamic_cast(&tp_opt->get()); if (!tp) throw std::runtime_error("Class " + it->id + " is not a component type"); } @@ -165,7 +165,7 @@ namespace riddle if (!pred_opt) throw std::runtime_error("Cannot find predicate " + predicate_name.id); - auto &pred = pred_opt.value().get(); + auto &pred = pred_opt->get(); std::map> args; for (const auto &arg : arguments) @@ -173,7 +173,7 @@ namespace riddle auto tp_opt = pred.get_field(arg.get_id().id); if (!tp_opt) throw std::runtime_error("Cannot find field " + arg.get_id().id); - auto &tp = tp_opt.value().get().get_type(); + auto &tp = tp_opt->get().get_type(); auto val = arg.get_expression()->evaluate(scp, ctx); if (tp.is_assignable_from(val->get_type())) // the target type is a superclass of the assignment.. args.emplace(arg.get_id().id, val);