mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 06:58:45 +00:00
visitor, print_visitor and build_visitor fixed
This commit is contained in:
parent
776b6cccc6
commit
4d0b527416
9 changed files with 212 additions and 139 deletions
|
|
@ -20,11 +20,12 @@ private:
|
||||||
// Sources -----------------
|
// Sources -----------------
|
||||||
|
|
||||||
void Visit(SourceFile* node) override;
|
void Visit(SourceFile* node) override;
|
||||||
void Visit(Sources* node) override;
|
|
||||||
|
|
||||||
// Namespaces, partitions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
|
void Visit(PartitionSources* node) override;
|
||||||
void Visit(Partition* node) override;
|
void Visit(Partition* node) override;
|
||||||
|
void Visit(NamespaceSources* node) override;
|
||||||
void Visit(Namespace* node) override;
|
void Visit(Namespace* node) override;
|
||||||
|
|
||||||
// Definitions -----------------
|
// Definitions -----------------
|
||||||
|
|
@ -38,6 +39,8 @@ private:
|
||||||
void Visit(AbstractTypeDefinitionStatement* node) override;
|
void Visit(AbstractTypeDefinitionStatement* node) override;
|
||||||
void Visit(TypeclassDefinitionStatement* node) override;
|
void Visit(TypeclassDefinitionStatement* node) override;
|
||||||
|
|
||||||
|
void Visit(NamespaceStatement& node) override; // variant
|
||||||
|
void Visit(PartitionStatement& node) override; // variant
|
||||||
void Visit(SourceStatement& node) override; // variant
|
void Visit(SourceStatement& node) override; // variant
|
||||||
|
|
||||||
// Definition parts
|
// Definition parts
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,13 @@ using TypeclassIdentifier = std::string;
|
||||||
// Sources -----------------
|
// Sources -----------------
|
||||||
|
|
||||||
struct SourceFile;
|
struct SourceFile;
|
||||||
struct Sources;
|
|
||||||
|
|
||||||
// Namespaces, partitions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
struct Partition;
|
struct Partition;
|
||||||
|
struct PartitionSources;
|
||||||
struct Namespace;
|
struct Namespace;
|
||||||
|
struct NamespaceSources;
|
||||||
|
|
||||||
// Definitions -----------------
|
// Definitions -----------------
|
||||||
|
|
||||||
|
|
@ -43,15 +44,24 @@ struct TypeDefinitionStatement;
|
||||||
struct AbstractTypeDefinitionStatement;
|
struct AbstractTypeDefinitionStatement;
|
||||||
struct TypeclassDefinitionStatement;
|
struct TypeclassDefinitionStatement;
|
||||||
|
|
||||||
using SourceStatement = std::variant<
|
//
|
||||||
std::unique_ptr<ImportStatement>,
|
using NamespaceStatement = std::variant<
|
||||||
std::unique_ptr<AliasDefinitionStatement>,
|
std::unique_ptr<AliasDefinitionStatement>,
|
||||||
std::unique_ptr<FunctionDeclaration>,
|
std::unique_ptr<FunctionDeclaration>,
|
||||||
std::unique_ptr<FunctionDefinitionStatement>,
|
std::unique_ptr<FunctionDefinitionStatement>,
|
||||||
std::unique_ptr<TypeDefinitionStatement>,
|
std::unique_ptr<TypeDefinitionStatement>,
|
||||||
|
std::unique_ptr<Namespace>>;
|
||||||
|
//
|
||||||
|
using PartitionStatement = std::variant<
|
||||||
std::unique_ptr<AbstractTypeDefinitionStatement>,
|
std::unique_ptr<AbstractTypeDefinitionStatement>,
|
||||||
std::unique_ptr<TypeclassDefinitionStatement>,
|
std::unique_ptr<TypeclassDefinitionStatement>,
|
||||||
std::unique_ptr<Namespace>>;
|
std::unique_ptr<NamespaceStatement>>;
|
||||||
|
//
|
||||||
|
using SourceStatement = std::variant<
|
||||||
|
std::unique_ptr<ImportStatement>,
|
||||||
|
std::unique_ptr<Partition>,
|
||||||
|
std::unique_ptr<PartitionStatement>>;
|
||||||
|
//
|
||||||
|
|
||||||
// Definition parts
|
// Definition parts
|
||||||
|
|
||||||
|
|
@ -257,22 +267,13 @@ using Pattern = std::variant<
|
||||||
// ----------------- Sources -----------------
|
// ----------------- Sources -----------------
|
||||||
|
|
||||||
struct SourceFile {
|
struct SourceFile {
|
||||||
std::vector<std::variant<SourceStatement, Partition>> statements;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Sources {
|
|
||||||
std::vector<SourceStatement> statements;
|
std::vector<SourceStatement> statements;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------- Namespaces, partittions -----------------
|
// ----------------- Namespaces, partittions -----------------
|
||||||
|
|
||||||
struct Namespace {
|
struct PartitionSources {
|
||||||
enum Modifier { Const, Var };
|
std::vector<PartitionStatement> statements;
|
||||||
std::optional<Modifier> modifier; // modifier => variable namespace
|
|
||||||
TypeIdentifier type;
|
|
||||||
std::unique_ptr<Sources> scope;
|
|
||||||
|
|
||||||
std::optional<utils::IdType> type_id_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Partition {
|
struct Partition {
|
||||||
|
|
@ -283,7 +284,20 @@ struct Partition {
|
||||||
};
|
};
|
||||||
|
|
||||||
PartitionName name;
|
PartitionName name;
|
||||||
std::unique_ptr<Sources> scope;
|
PartitionSources scope;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NamespaceSources {
|
||||||
|
std::vector<NamespaceStatement> statements;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Namespace {
|
||||||
|
enum Modifier { Const, Var };
|
||||||
|
std::optional<Modifier> modifier; // modifier => variable namespace
|
||||||
|
TypeIdentifier type;
|
||||||
|
NamespaceSources scope;
|
||||||
|
|
||||||
|
std::optional<utils::IdType> type_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------- Definitions -----------------
|
// ----------------- Definitions -----------------
|
||||||
|
|
@ -559,7 +573,6 @@ struct ExtendedScopedAnyType {
|
||||||
// Typeclass -----------------
|
// Typeclass -----------------
|
||||||
|
|
||||||
struct TypeclassExpression {
|
struct TypeclassExpression {
|
||||||
std::vector<TypeSubExpression> path;
|
|
||||||
TypeclassSubExpression typeclass;
|
TypeclassSubExpression typeclass;
|
||||||
|
|
||||||
utils::IdType type_id_;
|
utils::IdType type_id_;
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,11 @@ namespace parser::tokens {
|
||||||
// Sources -----------------
|
// Sources -----------------
|
||||||
|
|
||||||
const std::string SourceFile = "source_file";
|
const std::string SourceFile = "source_file";
|
||||||
const std::string Sources = "sources";
|
|
||||||
const std::string SourceStatement = "source_statement";
|
const std::string SourceStatement = "source_statement";
|
||||||
|
const std::string PartitionSources = "partition_sources";
|
||||||
|
const std::string PartitionStatement = "partition_statement";
|
||||||
|
const std::string NamespaceSources = "namespace_sources";
|
||||||
|
const std::string NamespaceStatement = "namespace_statement";
|
||||||
|
|
||||||
// Namespaces, partitions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,12 @@ private:
|
||||||
// Sources -----------------
|
// Sources -----------------
|
||||||
|
|
||||||
void Visit(SourceFile* node) override;
|
void Visit(SourceFile* node) override;
|
||||||
void Visit(Sources* node) override;
|
|
||||||
|
|
||||||
// Namespaces, partitions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
|
void Visit(PartitionSources* node) override;
|
||||||
void Visit(Partition* node) override;
|
void Visit(Partition* node) override;
|
||||||
|
void Visit(NamespaceSources* node) override;
|
||||||
void Visit(Namespace* node) override;
|
void Visit(Namespace* node) override;
|
||||||
|
|
||||||
// Definitions -----------------
|
// Definitions -----------------
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,12 @@ protected:
|
||||||
// Sources -----------------
|
// Sources -----------------
|
||||||
|
|
||||||
virtual void Visit(SourceFile* node);
|
virtual void Visit(SourceFile* node);
|
||||||
virtual void Visit(Sources* node);
|
|
||||||
|
|
||||||
// Namespaces, partitions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
|
virtual void Visit(PartitionSources* node);
|
||||||
virtual void Visit(Partition* node);
|
virtual void Visit(Partition* node);
|
||||||
|
virtual void Visit(NamespaceSources* node);
|
||||||
virtual void Visit(Namespace* node);
|
virtual void Visit(Namespace* node);
|
||||||
|
|
||||||
// Definitions -----------------
|
// Definitions -----------------
|
||||||
|
|
@ -35,6 +36,8 @@ protected:
|
||||||
virtual void Visit(AbstractTypeDefinitionStatement* node);
|
virtual void Visit(AbstractTypeDefinitionStatement* node);
|
||||||
virtual void Visit(TypeclassDefinitionStatement* node);
|
virtual void Visit(TypeclassDefinitionStatement* node);
|
||||||
|
|
||||||
|
virtual void Visit(NamespaceStatement& node); // variant
|
||||||
|
virtual void Visit(PartitionStatement& node); // variant
|
||||||
virtual void Visit(SourceStatement& node); // variant
|
virtual void Visit(SourceStatement& node); // variant
|
||||||
|
|
||||||
// Definition parts
|
// Definition parts
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 45f05008c60b675e997a144868fd1dd3cc53cd73
|
Subproject commit 8021bf5b433c7b3d5179deba98af60faf47d4457
|
||||||
|
|
@ -16,30 +16,8 @@ void BuildVisitor::Visit(SourceFile* node) {
|
||||||
node->statements.resize(statement_count);
|
node->statements.resize(statement_count);
|
||||||
|
|
||||||
for (size_t i = 0; i < statement_count; ++i) {
|
for (size_t i = 0; i < statement_count; ++i) {
|
||||||
current_node_ = parse_node.NthNamedChild(i);
|
current_node_ = parse_node.NthNamedChild(i);
|
||||||
auto current_node_type = current_node_.GetType();
|
Visit(node->statements[i]);
|
||||||
|
|
||||||
if (current_node_type == parser::tokens::SourceStatement) {
|
|
||||||
node->statements[i].emplace<SourceStatement>();
|
|
||||||
Visit(std::get<SourceStatement>(node->statements[i]));
|
|
||||||
} else if (current_node_type == parser::tokens::Partition) {
|
|
||||||
node->statements[i].emplace<Partition>();
|
|
||||||
Visit(&std::get<Partition>(node->statements[i]) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current_node_ = parse_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildVisitor::Visit(Sources* node) {
|
|
||||||
auto parse_node = current_node_;
|
|
||||||
size_t statement_count = parse_node.NamedChildCount();
|
|
||||||
|
|
||||||
node->statements.resize(statement_count);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < statement_count; ++i) {
|
|
||||||
current_node_ = parse_node.NthNamedChild(i);
|
|
||||||
Visit(node->statements[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current_node_ = parse_node;
|
current_node_ = parse_node;
|
||||||
|
|
@ -47,6 +25,53 @@ void BuildVisitor::Visit(Sources* node) {
|
||||||
|
|
||||||
// Namespaces, partitions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
|
void BuildVisitor::Visit(PartitionSources* node) {
|
||||||
|
auto parse_node = current_node_;
|
||||||
|
size_t statement_count = parse_node.NamedChildCount();
|
||||||
|
|
||||||
|
node->statements.resize(statement_count);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < statement_count; ++i) {
|
||||||
|
current_node_ = parse_node.NthNamedChild(i);
|
||||||
|
Visit(node->statements[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
current_node_ = parse_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildVisitor::Visit(Partition* node) {
|
||||||
|
auto parse_node = current_node_;
|
||||||
|
|
||||||
|
std::string name = parse_node.ChildByFieldName("name").GetValue();
|
||||||
|
|
||||||
|
if (name == "TEST") {
|
||||||
|
node->name = Partition::Test;
|
||||||
|
} else if (name == "INTERFACE") {
|
||||||
|
node->name = Partition::Interface;
|
||||||
|
} else if (name == "CODE") {
|
||||||
|
node->name = Partition::Code;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_node_ = parse_node.ChildByFieldName("scope");
|
||||||
|
Visit(&node->scope);
|
||||||
|
|
||||||
|
current_node_ = parse_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildVisitor::Visit(NamespaceSources* node) {
|
||||||
|
auto parse_node = current_node_;
|
||||||
|
size_t statement_count = parse_node.NamedChildCount();
|
||||||
|
|
||||||
|
node->statements.resize(statement_count);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < statement_count; ++i) {
|
||||||
|
current_node_ = parse_node.NthNamedChild(i);
|
||||||
|
Visit(node->statements[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
current_node_ = parse_node;
|
||||||
|
}
|
||||||
|
|
||||||
void BuildVisitor::Visit(Namespace* node) {
|
void BuildVisitor::Visit(Namespace* node) {
|
||||||
auto parse_node = current_node_;
|
auto parse_node = current_node_;
|
||||||
|
|
||||||
|
|
@ -65,28 +90,7 @@ void BuildVisitor::Visit(Namespace* node) {
|
||||||
Visit(&node->type);
|
Visit(&node->type);
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("scope");
|
current_node_ = parse_node.ChildByFieldName("scope");
|
||||||
node->scope = std::make_unique<Sources>();
|
Visit(&node->scope);
|
||||||
Visit(node->scope.get());
|
|
||||||
|
|
||||||
current_node_ = parse_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildVisitor::Visit(Partition* node) {
|
|
||||||
auto parse_node = current_node_;
|
|
||||||
|
|
||||||
std::string name = parse_node.ChildByFieldName("name").GetValue();
|
|
||||||
|
|
||||||
if (name == "TEST") {
|
|
||||||
node->name = Partition::Test;
|
|
||||||
} else if (name == "INTERFACE") {
|
|
||||||
node->name = Partition::Interface;
|
|
||||||
} else if (name == "CODE") {
|
|
||||||
node->name = Partition::Code;
|
|
||||||
}
|
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("scope");
|
|
||||||
node->scope = std::make_unique<Sources>();
|
|
||||||
Visit(node->scope.get());
|
|
||||||
|
|
||||||
current_node_ = parse_node;
|
current_node_ = parse_node;
|
||||||
}
|
}
|
||||||
|
|
@ -279,17 +283,14 @@ void BuildVisitor::Visit(TypeclassDefinitionStatement* node) {
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
void BuildVisitor::Visit(SourceStatement& node) {
|
void BuildVisitor::Visit(NamespaceStatement& node) {
|
||||||
auto parse_node = current_node_;
|
auto parse_node = current_node_;
|
||||||
|
|
||||||
current_node_ = parse_node.NthNamedChild(0);
|
current_node_ = parse_node.NthNamedChild(0);
|
||||||
|
|
||||||
std::string current_node_type = current_node_.GetType();
|
std::string current_node_type = current_node_.GetType();
|
||||||
|
|
||||||
if (current_node_type == parser::tokens::ImportStatement) { // optimize ??
|
if (current_node_type == parser::tokens::AliasDefinitionStatement) { // optimize ??
|
||||||
node = std::make_unique<ImportStatement>();
|
|
||||||
Visit(std::get<std::unique_ptr<ImportStatement>>(node).get());
|
|
||||||
} else if (current_node_type == parser::tokens::AliasDefinitionStatement) {
|
|
||||||
node = std::make_unique<AliasDefinitionStatement>();
|
node = std::make_unique<AliasDefinitionStatement>();
|
||||||
Visit(std::get<std::unique_ptr<AliasDefinitionStatement>>(node).get());
|
Visit(std::get<std::unique_ptr<AliasDefinitionStatement>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::FunctionDeclaration) {
|
} else if (current_node_type == parser::tokens::FunctionDeclaration) {
|
||||||
|
|
@ -301,15 +302,55 @@ void BuildVisitor::Visit(SourceStatement& node) {
|
||||||
} else if (current_node_type == parser::tokens::TypeDefinitionStatement) {
|
} else if (current_node_type == parser::tokens::TypeDefinitionStatement) {
|
||||||
node = std::make_unique<TypeDefinitionStatement>();
|
node = std::make_unique<TypeDefinitionStatement>();
|
||||||
Visit(std::get<std::unique_ptr<TypeDefinitionStatement>>(node).get());
|
Visit(std::get<std::unique_ptr<TypeDefinitionStatement>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::AbstractTypeDefinitionStatement) {
|
} else if (current_node_type == parser::tokens::Namespace) {
|
||||||
|
node = std::make_unique<Namespace>();
|
||||||
|
Visit(std::get<std::unique_ptr<Namespace>>(node).get());
|
||||||
|
} else {
|
||||||
|
// error
|
||||||
|
}
|
||||||
|
|
||||||
|
current_node_ = parse_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildVisitor::Visit(PartitionStatement& node) {
|
||||||
|
auto parse_node = current_node_;
|
||||||
|
|
||||||
|
current_node_ = parse_node.NthNamedChild(0);
|
||||||
|
|
||||||
|
std::string current_node_type = current_node_.GetType();
|
||||||
|
|
||||||
|
if (current_node_type == parser::tokens::AbstractTypeDefinitionStatement) { // optimize ??
|
||||||
node = std::make_unique<AbstractTypeDefinitionStatement>();
|
node = std::make_unique<AbstractTypeDefinitionStatement>();
|
||||||
Visit(std::get<std::unique_ptr<AbstractTypeDefinitionStatement>>(node).get());
|
Visit(std::get<std::unique_ptr<AbstractTypeDefinitionStatement>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::TypeclassDefinitionStatement) {
|
} else if (current_node_type == parser::tokens::TypeclassDefinitionStatement) {
|
||||||
node = std::make_unique<TypeclassDefinitionStatement>();
|
node = std::make_unique<TypeclassDefinitionStatement>();
|
||||||
Visit(std::get<std::unique_ptr<TypeclassDefinitionStatement>>(node).get());
|
Visit(std::get<std::unique_ptr<TypeclassDefinitionStatement>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::Namespace) {
|
} else if (current_node_type == parser::tokens::NamespaceStatement) {
|
||||||
node = std::make_unique<Namespace>();
|
node = std::make_unique<NamespaceStatement>();
|
||||||
Visit(std::get<std::unique_ptr<Namespace>>(node).get());
|
Visit(*std::get<std::unique_ptr<NamespaceStatement>>(node));
|
||||||
|
} else {
|
||||||
|
// error
|
||||||
|
}
|
||||||
|
|
||||||
|
current_node_ = parse_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildVisitor::Visit(SourceStatement& node) {
|
||||||
|
auto parse_node = current_node_;
|
||||||
|
|
||||||
|
current_node_ = parse_node.NthNamedChild(0);
|
||||||
|
|
||||||
|
std::string current_node_type = current_node_.GetType();
|
||||||
|
|
||||||
|
if (current_node_type == parser::tokens::ImportStatement) { // optimize ??
|
||||||
|
node = std::make_unique<ImportStatement>();
|
||||||
|
Visit(std::get<std::unique_ptr<ImportStatement>>(node).get());
|
||||||
|
} else if (current_node_type == parser::tokens::Partition) {
|
||||||
|
node = std::make_unique<Partition>();
|
||||||
|
Visit(std::get<std::unique_ptr<Partition>>(node).get());
|
||||||
|
} else if (current_node_type == parser::tokens::PartitionStatement) {
|
||||||
|
node = std::make_unique<PartitionStatement>();
|
||||||
|
Visit(*std::get<std::unique_ptr<PartitionStatement>>(node));
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
@ -1330,17 +1371,6 @@ void BuildVisitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
void BuildVisitor::Visit(TypeclassExpression* node) {
|
void BuildVisitor::Visit(TypeclassExpression* node) {
|
||||||
auto parse_node = current_node_;
|
auto parse_node = current_node_;
|
||||||
|
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
|
||||||
|
|
||||||
if (child_count > 1) {
|
|
||||||
node->path.resize(child_count - 1);
|
|
||||||
|
|
||||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
|
||||||
current_node_ = parse_node.NthNamedChild(i);
|
|
||||||
Visit(node->path[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("typeclass");
|
current_node_ = parse_node.ChildByFieldName("typeclass");
|
||||||
Visit(node->typeclass);
|
Visit(node->typeclass);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,27 +8,21 @@ namespace interpreter {
|
||||||
void PrintVisitor::Visit(SourceFile* node) {
|
void PrintVisitor::Visit(SourceFile* node) {
|
||||||
out_ << "[SourceFile] (\n\n";
|
out_ << "[SourceFile] (\n\n";
|
||||||
for (auto& statement : node->statements) {
|
for (auto& statement : node->statements) {
|
||||||
if (std::holds_alternative<Partition>(statement)) {
|
Visitor::Visit(statement);
|
||||||
Visit(&std::get<Partition>(statement));
|
|
||||||
} else if (std::holds_alternative<SourceStatement>(statement)) {
|
|
||||||
Visitor::Visit(std::get<SourceStatement>(statement));
|
|
||||||
} else {
|
|
||||||
// error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
out_ << "\n)\n";
|
out_ << "\n)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintVisitor::Visit(Sources* node) {
|
// Namespaces, partitions -----------------
|
||||||
out_ << "[Sources](\n";
|
|
||||||
|
void PrintVisitor::Visit(PartitionSources* node) {
|
||||||
|
out_ << "[PartitionSources](\n";
|
||||||
for (auto& statement : node->statements) {
|
for (auto& statement : node->statements) {
|
||||||
Visitor::Visit(statement);
|
Visitor::Visit(statement);
|
||||||
}
|
}
|
||||||
out_ << ")\n";
|
out_ << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespaces, partitions -----------------
|
|
||||||
|
|
||||||
void PrintVisitor::Visit(Partition* node) {
|
void PrintVisitor::Visit(Partition* node) {
|
||||||
out_ << "[Partition] ";
|
out_ << "[Partition] ";
|
||||||
switch (node->name) {
|
switch (node->name) {
|
||||||
|
|
@ -43,10 +37,18 @@ void PrintVisitor::Visit(Partition* node) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
out_ << " {\n";
|
out_ << " {\n";
|
||||||
Visit(node->scope.get());
|
Visit(&node->scope);
|
||||||
out_ << "}\n";
|
out_ << "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::Visit(NamespaceSources* node) {
|
||||||
|
out_ << "[NamespaceSources](\n";
|
||||||
|
for (auto& statement : node->statements) {
|
||||||
|
Visitor::Visit(statement);
|
||||||
|
}
|
||||||
|
out_ << ")\n";
|
||||||
|
}
|
||||||
|
|
||||||
void PrintVisitor::Visit(Namespace* node) {
|
void PrintVisitor::Visit(Namespace* node) {
|
||||||
out_ << "[Namespace] ";
|
out_ << "[Namespace] ";
|
||||||
if (node->modifier.has_value()) {
|
if (node->modifier.has_value()) {
|
||||||
|
|
@ -61,7 +63,7 @@ void PrintVisitor::Visit(Namespace* node) {
|
||||||
}
|
}
|
||||||
Visit(&node->type);
|
Visit(&node->type);
|
||||||
out_ << "{\n";
|
out_ << "{\n";
|
||||||
Visit(node->scope.get());
|
Visit(&node->scope);
|
||||||
out_ << "}\n";
|
out_ << "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -658,10 +660,6 @@ void PrintVisitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
|
|
||||||
void PrintVisitor::Visit(TypeclassExpression* node) {
|
void PrintVisitor::Visit(TypeclassExpression* node) {
|
||||||
out_ << "[TypeclassExpression] (";
|
out_ << "[TypeclassExpression] (";
|
||||||
for (auto& type : node->path) {
|
|
||||||
Visitor::Visit(type);
|
|
||||||
out_ << "::";
|
|
||||||
}
|
|
||||||
Visitor::Visit(node->typeclass);
|
Visitor::Visit(node->typeclass);
|
||||||
out_ << ')';
|
out_ << ')';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,31 +5,56 @@ namespace interpreter {
|
||||||
|
|
||||||
// Definitions -----------------
|
// Definitions -----------------
|
||||||
|
|
||||||
|
void Visitor::Visit(NamespaceStatement& node) {
|
||||||
|
switch (node.index()) {
|
||||||
|
case 0:
|
||||||
|
Visit(std::get<std::unique_ptr<AliasDefinitionStatement>>(node).get());
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Visit(std::get<std::unique_ptr<FunctionDeclaration>>(node).get());
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Visit(std::get<std::unique_ptr<FunctionDefinitionStatement>>(node).get());
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
Visit(std::get<std::unique_ptr<TypeDefinitionStatement>>(node).get());
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
Visit(std::get<std::unique_ptr<Namespace>>(node).get());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// error
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Visitor::Visit(PartitionStatement& node) {
|
||||||
|
switch (node.index()) {
|
||||||
|
case 0:
|
||||||
|
Visit(std::get<std::unique_ptr<AbstractTypeDefinitionStatement>>(node).get());
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Visit(std::get<std::unique_ptr<TypeclassDefinitionStatement>>(node).get());
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Visit(*std::get<std::unique_ptr<NamespaceStatement>>(node));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// error
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Visitor::Visit(SourceStatement& node) {
|
void Visitor::Visit(SourceStatement& node) {
|
||||||
switch (node.index()) {
|
switch (node.index()) {
|
||||||
case 0:
|
case 0:
|
||||||
Visit(std::get<std::unique_ptr<ImportStatement>>(node).get());
|
Visit(std::get<std::unique_ptr<ImportStatement>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Visit(std::get<std::unique_ptr<AliasDefinitionStatement>>(node).get());
|
Visit(std::get<std::unique_ptr<Partition>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Visit(std::get<std::unique_ptr<FunctionDeclaration>>(node).get());
|
Visit(*std::get<std::unique_ptr<PartitionStatement>>(node));
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
Visit(std::get<std::unique_ptr<FunctionDefinitionStatement>>(node).get());
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
Visit(std::get<std::unique_ptr<TypeDefinitionStatement>>(node).get());
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
Visit(std::get<std::unique_ptr<AbstractTypeDefinitionStatement>>(node).get());
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
Visit(std::get<std::unique_ptr<TypeclassDefinitionStatement>>(node).get());
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
Visit(std::get<std::unique_ptr<Namespace>>(node).get());
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// error
|
// error
|
||||||
|
|
@ -345,18 +370,6 @@ void Visitor::Visit(Literal& node) {
|
||||||
// Sources -----------------
|
// Sources -----------------
|
||||||
|
|
||||||
void Visitor::Visit(SourceFile* node) {
|
void Visitor::Visit(SourceFile* node) {
|
||||||
for (auto& statement : node->statements) {
|
|
||||||
if (std::holds_alternative<Partition>(statement)) {
|
|
||||||
Visit(&std::get<Partition>(statement));
|
|
||||||
} else if (std::holds_alternative<SourceStatement>(statement)) {
|
|
||||||
Visit(std::get<SourceStatement>(statement));
|
|
||||||
} else {
|
|
||||||
// error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Visitor::Visit(Sources* node) {
|
|
||||||
for (auto& statement : node->statements) {
|
for (auto& statement : node->statements) {
|
||||||
Visit(statement);
|
Visit(statement);
|
||||||
}
|
}
|
||||||
|
|
@ -364,13 +377,25 @@ void Visitor::Visit(Sources* node) {
|
||||||
|
|
||||||
// Namespaces, partitions -----------------
|
// Namespaces, partitions -----------------
|
||||||
|
|
||||||
|
void Visitor::Visit(PartitionSources* node) {
|
||||||
|
for (auto& statement : node->statements) {
|
||||||
|
Visit(statement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Visitor::Visit(Partition* node) {
|
void Visitor::Visit(Partition* node) {
|
||||||
Visit(node->scope.get());
|
Visit(&node->scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Visitor::Visit(NamespaceSources* node) {
|
||||||
|
for (auto& statement : node->statements) {
|
||||||
|
Visit(statement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visitor::Visit(Namespace* node) {
|
void Visitor::Visit(Namespace* node) {
|
||||||
Visit(&node->type);
|
Visit(&node->type);
|
||||||
Visit(node->scope.get());
|
Visit(&node->scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Definitions -----------------
|
// Definitions -----------------
|
||||||
|
|
@ -684,9 +709,6 @@ void Visitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
// Typeclass
|
// Typeclass
|
||||||
|
|
||||||
void Visitor::Visit(TypeclassExpression* node) {
|
void Visitor::Visit(TypeclassExpression* node) {
|
||||||
for (auto& type : node->path) {
|
|
||||||
Visit(type);
|
|
||||||
}
|
|
||||||
Visit(node->typeclass);
|
Visit(node->typeclass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue