diff --git a/include/interpreter_tree.hpp b/include/interpreter_tree.hpp index 6ec621d..5cd5598 100644 --- a/include/interpreter_tree.hpp +++ b/include/interpreter_tree.hpp @@ -534,7 +534,9 @@ struct VariantType { }; struct TypeExpression { - std::vector types; + std::vector path; + TypeSubExpression type; + std::optional array_size; // if array; 0 - dynamic size utils::IdType type_id_; @@ -548,7 +550,7 @@ struct ExtendedScopedAnyType { // Typeclass ----------------- struct TypeclassExpression { - std::vector types; + std::vector path; TypeclassSubExpression typeclass; utils::IdType type_id_; diff --git a/src/print_visitor.cpp b/src/print_visitor.cpp index e648c48..8019e16 100644 --- a/src/print_visitor.cpp +++ b/src/print_visitor.cpp @@ -262,18 +262,25 @@ void PrintVisitor::Visit(AnyAnnotatedType* node) { // Flow control ----------------- -void PrintVisitor::Visit(MatchCase* node) { - out_ << "[MatchCase | "; - Visitor::Visit(node->value); - if (node->condition.has_value()) { - out_ << " ? "; - Visitor::Visit(node->condition.value()); +void PrintVisitor::Visit(TypeConstructorPattern* node) { + out_ << "[TypeConstructorPattern "; + Visit(&node->constructor); + out_ << "]\n("; + + bool is_first = true; + for (auto& parameter : node->parameters) { + if (!is_first) { + out_ << ")\n"; + is_first = false; + } + out_ << '('; + if (parameter.first.has_value()) { + Visit(¶meter.first.value()); + out_ << " = "; + } + Visitor::Visit(parameter.second); } - if (node->statement.has_value()) { - out_ << " -> "; - Visitor::Visit(node->statement.value()); - } - out_ << "]\n"; + out_ << ")\n"; } void PrintVisitor::Visit(MatchCase* node) { @@ -427,8 +434,20 @@ void PrintVisitor::Visit(AccessExpression* node) { // Other Expressions void PrintVisitor::Visit(FunctionCallExpression* node) { - out_ << "[FunctionCall "; - Visit(node->name.get()); + out_ << "[FunctionCall ("; + + if (std::holds_alternative>(node->prefix)) { + Visitor::Visit(*std::get>(node->prefix)); + } else if (std::holds_alternative>(node->prefix)) { + Visit(std::get>(node->prefix).get()); + } else { + // error + } + + out_ << ")."; + + Visit(&node->name); + out_ << "] ("; for (auto& argument : node->arguments) { Visitor::Visit(argument); @@ -463,7 +482,7 @@ void PrintVisitor::Visit(ReturnExpression* node) { void PrintVisitor::Visit(TypeConstructor* node) { out_ << "[TypeConstructor "; - Visit(node->type.get()); + Visit(node->constructor.get()); out_ << "]\n("; bool is_first = true; @@ -473,16 +492,18 @@ void PrintVisitor::Visit(TypeConstructor* node) { is_first = false; } out_ << '('; - Visit(&std::get<0>(parameter)); - switch (std::get<1>(parameter)) { - case TypeConstructor::Assign: - out_ << " = "; - break; - case TypeConstructor::Move: - out_ << " <- "; - break; + if (parameter.first.has_value()) { + Visit(¶meter.first.value().first); + switch (parameter.first.value().second) { + case TypeConstructor::Assign: + out_ << " = "; + break; + case TypeConstructor::Move: + out_ << " <- "; + break; + } } - Visitor::Visit(std::get<2>(parameter)); + Visitor::Visit(parameter.second); } out_ << ")\n"; } @@ -504,26 +525,22 @@ void PrintVisitor::Visit(LambdaFunction* node) { } void PrintVisitor::Visit(ArrayExpression* node) { - out_ << "[ArrayExpression] (["; + out_ << "[ArrayExpression] ( ,"; for (auto& element : node->elements) { Visitor::Visit(element); - out_ << ';'; + out_ << " ,"; } - out_ << "])"; + out_ << ")"; } // Name void PrintVisitor::Visit(NameExpression* node) { out_ << "[NameExpression] ("; - for (auto& variable_namespace : node->namespaces) { - Visitor::Visit(variable_namespace); - out_ << '.'; - } - for (size_t i = 0; i < node->expressions.size(); ++i) { - Visit(&node->expressions[i]); - if (i + 1 < node->expressions.size()) { - out_ << '.'; + for (size_t i = 0; i < node->names.size(); ++i) { + Visit(&node->names[i]); + if (i + 1 < node->names.size()) { + out_ << "::"; } } out_ << ')'; @@ -611,16 +628,6 @@ void PrintVisitor::Visit(VariantType* node) { out_ << ')'; } -void PrintVisitor::Visit(ParametrizedType* node) { - out_ << "[ParametrizedType] ("; - Visit(node->type_expression.get()); - for (auto& parameter : node->parameters) { - out_ << ' '; - Visitor::Visit(parameter); - } - out_ << ')'; -} - void PrintVisitor::Visit(TypeExpression* node) { out_ << "[TypeExpression "; @@ -629,11 +636,11 @@ void PrintVisitor::Visit(TypeExpression* node) { } out_ << "] ("; - for (auto& type_namespace : node->namespaces) { - Visitor::Visit(type_namespace); - out_ << '.'; + for (auto& type : node->path) { + Visitor::Visit(type); + out_ << "::"; } - Visit(&node->type); + Visitor::Visit(node->type); out_ << ')'; } @@ -656,23 +663,35 @@ void PrintVisitor::Visit(ExtendedScopedAnyType* node) { // Typeclass +void PrintVisitor::Visit(TypeclassExpression* node) { + out_ << "[TypeclassExpression] ("; + for (auto& type : node->path) { + Visitor::Visit(type); + out_ << "::"; + } + Visitor::Visit(node->typeclass); + out_ << ')'; +} + void PrintVisitor::Visit(ParametrizedTypeclass* node) { out_ << "[ParametrizedTypeclass] ("; - Visit(node->typeclass_expression.get()); + Visit(&node->typeclass); for (auto& parameter : node->parameters) { out_ << ' '; - Visitor::Visit(parameter); + Visit(parameter.get()); } out_ << ')'; } -void PrintVisitor::Visit(TypeclassExpression* node) { - out_ << "[TypeclassExpression] ("; - for (auto& typeclass_namespace : node->namespaces) { - Visitor::Visit(typeclass_namespace); - out_ << '.'; +// Typeclass & Type ----------------- + +void PrintVisitor::Visit(ParametrizedType* node) { + out_ << "[ParametrizedType] ("; + Visit(&node->type); + for (auto& parameter : node->parameters) { + out_ << ' '; + Visit(parameter.get()); } - Visit(&node->typeclass); out_ << ')'; } diff --git a/src/visitor.cpp b/src/visitor.cpp index 772b6c9..25b64dd 100644 --- a/src/visitor.cpp +++ b/src/visitor.cpp @@ -664,9 +664,10 @@ void Visitor::Visit(VariantType* node) { } void Visitor::Visit(TypeExpression* node) { - for (auto& type : node->types) { + for (auto& type : node->path) { Visit(type); } + Visit(node->type); } void Visitor::Visit(ExtendedScopedAnyType* node) { @@ -676,7 +677,7 @@ void Visitor::Visit(ExtendedScopedAnyType* node) { // Typeclass void Visitor::Visit(TypeclassExpression* node) { - for (auto& type : node->types) { + for (auto& type : node->path) { Visit(type); } Visit(node->typeclass);