mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 06:58:45 +00:00
print visitor fixed
This commit is contained in:
parent
fd047bc517
commit
5bf0c1bf48
3 changed files with 82 additions and 60 deletions
|
|
@ -534,7 +534,9 @@ struct VariantType {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TypeExpression {
|
struct TypeExpression {
|
||||||
std::vector<TypeSubExpression> types;
|
std::vector<TypeSubExpression> path;
|
||||||
|
TypeSubExpression type;
|
||||||
|
|
||||||
std::optional<size_t> array_size; // if array; 0 - dynamic size
|
std::optional<size_t> array_size; // if array; 0 - dynamic size
|
||||||
|
|
||||||
utils::IdType type_id_;
|
utils::IdType type_id_;
|
||||||
|
|
@ -548,7 +550,7 @@ struct ExtendedScopedAnyType {
|
||||||
// Typeclass -----------------
|
// Typeclass -----------------
|
||||||
|
|
||||||
struct TypeclassExpression {
|
struct TypeclassExpression {
|
||||||
std::vector<TypeSubExpression> types;
|
std::vector<TypeSubExpression> path;
|
||||||
TypeclassSubExpression typeclass;
|
TypeclassSubExpression typeclass;
|
||||||
|
|
||||||
utils::IdType type_id_;
|
utils::IdType type_id_;
|
||||||
|
|
|
||||||
|
|
@ -262,18 +262,25 @@ void PrintVisitor::Visit(AnyAnnotatedType* node) {
|
||||||
|
|
||||||
// Flow control -----------------
|
// Flow control -----------------
|
||||||
|
|
||||||
void PrintVisitor::Visit(MatchCase* node) {
|
void PrintVisitor::Visit(TypeConstructorPattern* node) {
|
||||||
out_ << "[MatchCase | ";
|
out_ << "[TypeConstructorPattern ";
|
||||||
Visitor::Visit(node->value);
|
Visit(&node->constructor);
|
||||||
if (node->condition.has_value()) {
|
out_ << "]\n(";
|
||||||
out_ << " ? ";
|
|
||||||
Visitor::Visit(node->condition.value());
|
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_ << ")\n";
|
||||||
out_ << " -> ";
|
|
||||||
Visitor::Visit(node->statement.value());
|
|
||||||
}
|
|
||||||
out_ << "]\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintVisitor::Visit(MatchCase* node) {
|
void PrintVisitor::Visit(MatchCase* node) {
|
||||||
|
|
@ -427,8 +434,20 @@ void PrintVisitor::Visit(AccessExpression* node) {
|
||||||
// Other Expressions
|
// Other Expressions
|
||||||
|
|
||||||
void PrintVisitor::Visit(FunctionCallExpression* node) {
|
void PrintVisitor::Visit(FunctionCallExpression* node) {
|
||||||
out_ << "[FunctionCall ";
|
out_ << "[FunctionCall (";
|
||||||
Visit(node->name.get());
|
|
||||||
|
if (std::holds_alternative<std::unique_ptr<SubExpressionToken>>(node->prefix)) {
|
||||||
|
Visitor::Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->prefix));
|
||||||
|
} else if (std::holds_alternative<std::unique_ptr<TypeExpression>>(node->prefix)) {
|
||||||
|
Visit(std::get<std::unique_ptr<TypeExpression>>(node->prefix).get());
|
||||||
|
} else {
|
||||||
|
// error
|
||||||
|
}
|
||||||
|
|
||||||
|
out_ << ").";
|
||||||
|
|
||||||
|
Visit(&node->name);
|
||||||
|
|
||||||
out_ << "] (";
|
out_ << "] (";
|
||||||
for (auto& argument : node->arguments) {
|
for (auto& argument : node->arguments) {
|
||||||
Visitor::Visit(argument);
|
Visitor::Visit(argument);
|
||||||
|
|
@ -463,7 +482,7 @@ void PrintVisitor::Visit(ReturnExpression* node) {
|
||||||
|
|
||||||
void PrintVisitor::Visit(TypeConstructor* node) {
|
void PrintVisitor::Visit(TypeConstructor* node) {
|
||||||
out_ << "[TypeConstructor ";
|
out_ << "[TypeConstructor ";
|
||||||
Visit(node->type.get());
|
Visit(node->constructor.get());
|
||||||
out_ << "]\n(";
|
out_ << "]\n(";
|
||||||
|
|
||||||
bool is_first = true;
|
bool is_first = true;
|
||||||
|
|
@ -473,16 +492,18 @@ void PrintVisitor::Visit(TypeConstructor* node) {
|
||||||
is_first = false;
|
is_first = false;
|
||||||
}
|
}
|
||||||
out_ << '(';
|
out_ << '(';
|
||||||
Visit(&std::get<0>(parameter));
|
if (parameter.first.has_value()) {
|
||||||
switch (std::get<1>(parameter)) {
|
Visit(¶meter.first.value().first);
|
||||||
case TypeConstructor::Assign:
|
switch (parameter.first.value().second) {
|
||||||
out_ << " = ";
|
case TypeConstructor::Assign:
|
||||||
break;
|
out_ << " = ";
|
||||||
case TypeConstructor::Move:
|
break;
|
||||||
out_ << " <- ";
|
case TypeConstructor::Move:
|
||||||
break;
|
out_ << " <- ";
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Visitor::Visit(std::get<2>(parameter));
|
Visitor::Visit(parameter.second);
|
||||||
}
|
}
|
||||||
out_ << ")\n";
|
out_ << ")\n";
|
||||||
}
|
}
|
||||||
|
|
@ -504,26 +525,22 @@ void PrintVisitor::Visit(LambdaFunction* node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintVisitor::Visit(ArrayExpression* node) {
|
void PrintVisitor::Visit(ArrayExpression* node) {
|
||||||
out_ << "[ArrayExpression] ([";
|
out_ << "[ArrayExpression] ( ,";
|
||||||
for (auto& element : node->elements) {
|
for (auto& element : node->elements) {
|
||||||
Visitor::Visit(element);
|
Visitor::Visit(element);
|
||||||
out_ << ';';
|
out_ << " ,";
|
||||||
}
|
}
|
||||||
out_ << "])";
|
out_ << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
|
|
||||||
void PrintVisitor::Visit(NameExpression* node) {
|
void PrintVisitor::Visit(NameExpression* node) {
|
||||||
out_ << "[NameExpression] (";
|
out_ << "[NameExpression] (";
|
||||||
for (auto& variable_namespace : node->namespaces) {
|
for (size_t i = 0; i < node->names.size(); ++i) {
|
||||||
Visitor::Visit(variable_namespace);
|
Visit(&node->names[i]);
|
||||||
out_ << '.';
|
if (i + 1 < node->names.size()) {
|
||||||
}
|
out_ << "::";
|
||||||
for (size_t i = 0; i < node->expressions.size(); ++i) {
|
|
||||||
Visit(&node->expressions[i]);
|
|
||||||
if (i + 1 < node->expressions.size()) {
|
|
||||||
out_ << '.';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out_ << ')';
|
out_ << ')';
|
||||||
|
|
@ -611,16 +628,6 @@ void PrintVisitor::Visit(VariantType* node) {
|
||||||
out_ << ')';
|
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) {
|
void PrintVisitor::Visit(TypeExpression* node) {
|
||||||
out_ << "[TypeExpression ";
|
out_ << "[TypeExpression ";
|
||||||
|
|
||||||
|
|
@ -629,11 +636,11 @@ void PrintVisitor::Visit(TypeExpression* node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
out_ << "] (";
|
out_ << "] (";
|
||||||
for (auto& type_namespace : node->namespaces) {
|
for (auto& type : node->path) {
|
||||||
Visitor::Visit(type_namespace);
|
Visitor::Visit(type);
|
||||||
out_ << '.';
|
out_ << "::";
|
||||||
}
|
}
|
||||||
Visit(&node->type);
|
Visitor::Visit(node->type);
|
||||||
out_ << ')';
|
out_ << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -656,23 +663,35 @@ void PrintVisitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
|
|
||||||
// Typeclass
|
// 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) {
|
void PrintVisitor::Visit(ParametrizedTypeclass* node) {
|
||||||
out_ << "[ParametrizedTypeclass] (";
|
out_ << "[ParametrizedTypeclass] (";
|
||||||
Visit(node->typeclass_expression.get());
|
Visit(&node->typeclass);
|
||||||
for (auto& parameter : node->parameters) {
|
for (auto& parameter : node->parameters) {
|
||||||
out_ << ' ';
|
out_ << ' ';
|
||||||
Visitor::Visit(parameter);
|
Visit(parameter.get());
|
||||||
}
|
}
|
||||||
out_ << ')';
|
out_ << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintVisitor::Visit(TypeclassExpression* node) {
|
// Typeclass & Type -----------------
|
||||||
out_ << "[TypeclassExpression] (";
|
|
||||||
for (auto& typeclass_namespace : node->namespaces) {
|
void PrintVisitor::Visit(ParametrizedType* node) {
|
||||||
Visitor::Visit(typeclass_namespace);
|
out_ << "[ParametrizedType] (";
|
||||||
out_ << '.';
|
Visit(&node->type);
|
||||||
|
for (auto& parameter : node->parameters) {
|
||||||
|
out_ << ' ';
|
||||||
|
Visit(parameter.get());
|
||||||
}
|
}
|
||||||
Visit(&node->typeclass);
|
|
||||||
out_ << ')';
|
out_ << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -664,9 +664,10 @@ void Visitor::Visit(VariantType* node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visitor::Visit(TypeExpression* node) {
|
void Visitor::Visit(TypeExpression* node) {
|
||||||
for (auto& type : node->types) {
|
for (auto& type : node->path) {
|
||||||
Visit(type);
|
Visit(type);
|
||||||
}
|
}
|
||||||
|
Visit(node->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visitor::Visit(ExtendedScopedAnyType* node) {
|
void Visitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
|
|
@ -676,7 +677,7 @@ void Visitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
// Typeclass
|
// Typeclass
|
||||||
|
|
||||||
void Visitor::Visit(TypeclassExpression* node) {
|
void Visitor::Visit(TypeclassExpression* node) {
|
||||||
for (auto& type : node->types) {
|
for (auto& type : node->path) {
|
||||||
Visit(type);
|
Visit(type);
|
||||||
}
|
}
|
||||||
Visit(node->typeclass);
|
Visit(node->typeclass);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue