mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-26 16:58:45 +00:00
partition syntax changed, interface modifier added
This commit is contained in:
parent
3fca384446
commit
b1aff1935d
22 changed files with 299 additions and 266 deletions
|
|
@ -32,43 +32,6 @@ void BuildVisitor::Visit(SourceFile* node) {
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void BuildVisitor::Visit(PartitionSources* node) {
|
||||
SetPosition(node->base, current_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) {
|
||||
SetPosition(node->base, current_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) {
|
||||
SetPosition(node->base, current_node_);
|
||||
|
||||
|
|
@ -208,6 +171,13 @@ void BuildVisitor::Visit(FunctionDeclaration* node) {
|
|||
|
||||
auto parse_node = current_node_;
|
||||
|
||||
// ['decl'] ['interface'] name
|
||||
if (parse_node.NthChild(0).GetValue() == "decl") {
|
||||
node->is_in_interface = (parse_node.NthChild(1).GetValue() == "interface");
|
||||
} else {
|
||||
node->is_in_interface = false;
|
||||
}
|
||||
|
||||
node->name.name = parse_node.ChildByFieldName("name").GetValue();
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
|
@ -233,8 +203,6 @@ void BuildVisitor::Visit(FunctionDefinitionStatement* node) {
|
|||
|
||||
auto parse_node = current_node_;
|
||||
|
||||
node->is_inline = (parse_node.NthChild(1).GetValue() == "inline");
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("definition");
|
||||
node->definition = std::make_unique<FunctionDefinition>();
|
||||
Visit(node->definition.get());
|
||||
|
|
@ -257,6 +225,8 @@ void BuildVisitor::Visit(TypeDefinitionStatement* node) {
|
|||
node->modifier = utils::ClassModifier::Struct;
|
||||
}
|
||||
|
||||
node->is_in_interface = (parse_node.NthChild(1).GetValue() == "interface");
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("definition");
|
||||
node->definition = std::make_unique<TypeDefinition>();
|
||||
Visit(node->definition.get());
|
||||
|
|
@ -310,6 +280,30 @@ void BuildVisitor::Visit(TypeclassDefinitionStatement* node) {
|
|||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(PartitionStatement* node) {
|
||||
SetPosition(node->base, current_node_);
|
||||
|
||||
auto parse_node = current_node_;
|
||||
|
||||
std::string partition_modifier = parse_node.NthChild(0).GetValue();
|
||||
|
||||
if (partition_modifier == "exec") {
|
||||
node->modifier = utils::PartitionModifier::Exec;
|
||||
} else if (partition_modifier == "test") {
|
||||
node->modifier = utils::PartitionModifier::Test;
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("name");
|
||||
Visit(&node->name);
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("value");
|
||||
Visit(node->value);
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
void BuildVisitor::Visit(NamespaceStatement& node) {
|
||||
|
|
@ -331,6 +325,9 @@ void BuildVisitor::Visit(NamespaceStatement& node) {
|
|||
} else if (current_node_type == parser::tokens::TypeDefinitionStatement) {
|
||||
node = std::make_unique<TypeDefinitionStatement>();
|
||||
Visit(std::get<std::unique_ptr<TypeDefinitionStatement>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::PartitionStatement) {
|
||||
node = std::make_unique<PartitionStatement>();
|
||||
Visit(std::get<std::unique_ptr<PartitionStatement>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::Namespace) {
|
||||
node = std::make_unique<Namespace>();
|
||||
Visit(std::get<std::unique_ptr<Namespace>>(node).get());
|
||||
|
|
@ -341,29 +338,6 @@ void BuildVisitor::Visit(NamespaceStatement& node) {
|
|||
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>();
|
||||
Visit(std::get<std::unique_ptr<AbstractTypeDefinitionStatement>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::TypeclassDefinitionStatement) {
|
||||
node = std::make_unique<TypeclassDefinitionStatement>();
|
||||
Visit(std::get<std::unique_ptr<TypeclassDefinitionStatement>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::NamespaceStatement) {
|
||||
node = std::make_unique<NamespaceStatement>();
|
||||
Visit(*std::get<std::unique_ptr<NamespaceStatement>>(node));
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(SourceStatement& node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
|
|
@ -374,12 +348,15 @@ void BuildVisitor::Visit(SourceStatement& node) {
|
|||
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 if (current_node_type == parser::tokens::AbstractTypeDefinitionStatement) { // optimize ??
|
||||
node = std::make_unique<AbstractTypeDefinitionStatement>();
|
||||
Visit(std::get<std::unique_ptr<AbstractTypeDefinitionStatement>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::TypeclassDefinitionStatement) {
|
||||
node = std::make_unique<TypeclassDefinitionStatement>();
|
||||
Visit(std::get<std::unique_ptr<TypeclassDefinitionStatement>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::NamespaceStatement) {
|
||||
node = std::make_unique<NamespaceStatement>();
|
||||
Visit(*std::get<std::unique_ptr<NamespaceStatement>>(node));
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
|
@ -1167,6 +1144,25 @@ void BuildVisitor::Visit(LoopControlExpression& node) {
|
|||
|
||||
// Name
|
||||
|
||||
void BuildVisitor::Visit(PartitionName* node) {
|
||||
SetPosition(node->base, 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) {
|
||||
node->path[i] = parse_node.NthNamedChild(i).GetValue();
|
||||
}
|
||||
}
|
||||
|
||||
node->name = parse_node.ChildByFieldName("name").GetValue();
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(NameExpression* node) {
|
||||
SetPosition(node->base, current_node_);
|
||||
|
||||
|
|
@ -1176,8 +1172,8 @@ void BuildVisitor::Visit(NameExpression* node) {
|
|||
|
||||
node->names.resize(child_count);
|
||||
for (size_t i = 0; i < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i);
|
||||
Visit(&node->names[i]);
|
||||
current_node_ = parse_node.NthNamedChild(i);
|
||||
Visit(&node->names[i]);
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
|
|
|
|||
|
|
@ -15,16 +15,6 @@ void ExecuteVisitor::Visit(SourceFile* node) {
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void ExecuteVisitor::Visit(PartitionSources* node) {
|
||||
for (auto& statement : node->statements) {
|
||||
Visitor::Visit(statement);
|
||||
}
|
||||
}
|
||||
|
||||
void ExecuteVisitor::Visit(Partition* node) {
|
||||
Visit(&node->scope);
|
||||
}
|
||||
|
||||
void ExecuteVisitor::Visit(NamespaceSources* node) {
|
||||
for (auto& statement : node->statements) {
|
||||
Visitor::Visit(statement);
|
||||
|
|
@ -83,6 +73,16 @@ void ExecuteVisitor::Visit(TypeclassDefinitionStatement* node) {
|
|||
}
|
||||
}
|
||||
|
||||
void ExecuteVisitor::Visit(ExecutableStatement* node) {
|
||||
Visit(&node->name);
|
||||
Visitor::Visit(node->value);
|
||||
}
|
||||
|
||||
void ExecuteVisitor::Visit(TestStatement* node) {
|
||||
Visit(&node->name);
|
||||
Visitor::Visit(node->value);
|
||||
}
|
||||
|
||||
// Definition parts
|
||||
|
||||
void ExecuteVisitor::Visit(FunctionDefinition* node) {
|
||||
|
|
@ -276,6 +276,14 @@ void ExecuteVisitor::Visit(ArrayExpression* node) {
|
|||
|
||||
// Name
|
||||
|
||||
void ExecuteVisitor::Visit(PartitionName* node) {
|
||||
for (auto& path_namespace : node->path) {
|
||||
Visit(&path_namespace);
|
||||
}
|
||||
|
||||
Visit(&node->name);
|
||||
}
|
||||
|
||||
void ExecuteVisitor::Visit(NameExpression* node) {
|
||||
for (auto& name : node->names) {
|
||||
Visit(&name);
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@ namespace interpreter {
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void FindSymbolsVisitor::Visit(Partition* node) {
|
||||
// TODO: separate partitions
|
||||
Visitor::Visit(&node->scope);
|
||||
}
|
||||
|
||||
void FindSymbolsVisitor::Visit(Namespace* node) {
|
||||
namespace_visitor_.AddEnterNamespace(node->type, node->modifier);
|
||||
Visitor::Visit(&node->scope);
|
||||
|
|
@ -177,6 +172,15 @@ void FindSymbolsVisitor::Visit(TypeclassDefinitionStatement* node) {
|
|||
is_in_statement_ = false;
|
||||
}
|
||||
|
||||
void FindSymbolsVisitor::Visit(PartitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
|
||||
node->executable_id_ = namespace_visitor_.AddPartition(node->name.path, node->name.name, node);
|
||||
// TODO: typecheck error on same tests
|
||||
|
||||
is_in_statement_ = false;
|
||||
}
|
||||
|
||||
// Definition parts
|
||||
|
||||
void FindSymbolsVisitor::Visit(AnyAnnotatedType* node) {
|
||||
|
|
|
|||
|
|
@ -223,6 +223,25 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddConstructor(const std::string& co
|
|||
return 0;
|
||||
}
|
||||
|
||||
utils::IdType GlobalInfo::NamespaceVisitor::AddPartition(const std::vector<std::string>& path,
|
||||
const std::string& name,
|
||||
interpreter::tokens::PartitionStatement* node) {
|
||||
PartitionInfo partition;
|
||||
|
||||
partition.path.reserve(current_path_.size() + path.size());
|
||||
partition.path = current_path_;
|
||||
|
||||
for (auto& path_namespace : path) {
|
||||
partition.path.push_back(path_namespace);
|
||||
}
|
||||
|
||||
partition.name = name;
|
||||
partition.node = node;
|
||||
|
||||
global_info_.partitions_.push_back(partition);
|
||||
return global_info_.partitions_.size() - 1;
|
||||
}
|
||||
|
||||
std::optional<definition::Namespace*> GlobalInfo::NamespaceVisitor::FindNamespace(const std::optional<std::vector<std::string>>& path) {
|
||||
return FindSomething<definition::Namespace*>(path,
|
||||
[] (definition::Namespace* current_namespace) -> std::optional<definition::Namespace*> {
|
||||
|
|
|
|||
|
|
@ -15,32 +15,6 @@ void PrintVisitor::Visit(SourceFile* node) {
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void PrintVisitor::Visit(PartitionSources* node) {
|
||||
out_ << "[PartitionSources](\n";
|
||||
for (auto& statement : node->statements) {
|
||||
Visitor::Visit(statement);
|
||||
}
|
||||
out_ << ")\n";
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(Partition* node) {
|
||||
out_ << "[Partition] ";
|
||||
switch (node->name) {
|
||||
case Partition::Test:
|
||||
out_ << "TEST";
|
||||
break;
|
||||
case Partition::Interface:
|
||||
out_ << "INTERFACE";
|
||||
break;
|
||||
case Partition::Code:
|
||||
out_ << "CODE";
|
||||
break;
|
||||
}
|
||||
out_ << " {\n";
|
||||
Visit(&node->scope);
|
||||
out_ << "}\n";
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(NamespaceSources* node) {
|
||||
out_ << "[NamespaceSources](\n";
|
||||
for (auto& statement : node->statements) {
|
||||
|
|
@ -124,6 +98,9 @@ void PrintVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
|
||||
void PrintVisitor::Visit(FunctionDeclaration* node) {
|
||||
out_ << "[FunctionDeclaration ";
|
||||
if (node->is_in_interface) {
|
||||
out_ << "interface ";
|
||||
}
|
||||
Visit(&node->name);
|
||||
out_ << "] (";
|
||||
for (auto& parameter : node->parameters) {
|
||||
|
|
@ -152,6 +129,9 @@ void PrintVisitor::Visit(TypeDefinitionStatement* node) {
|
|||
out_ << "class";
|
||||
break;
|
||||
}
|
||||
if (node->is_in_interface) {
|
||||
out_ << " interface";
|
||||
}
|
||||
out_ << "] (";
|
||||
Visit(node->definition.get());
|
||||
out_ << ") = (";
|
||||
|
|
@ -188,6 +168,22 @@ void PrintVisitor::Visit(TypeclassDefinitionStatement* node) {
|
|||
out_ << ")\n";
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(PartitionStatement* node) {
|
||||
out_ << "[Partition ";
|
||||
switch (node->modifier) {
|
||||
case utils::PartitionModifier::Exec:
|
||||
out_ << "exec ";
|
||||
break;
|
||||
case utils::PartitionModifier::Test:
|
||||
out_ << "test ";
|
||||
break;
|
||||
}
|
||||
Visit(&node->name);
|
||||
out_ << "] = (";
|
||||
Visitor::Visit(node->value);
|
||||
out_ << ")\n";
|
||||
}
|
||||
|
||||
// Definition parts
|
||||
|
||||
void PrintVisitor::Visit(FunctionDefinition* node) {
|
||||
|
|
@ -556,6 +552,16 @@ void PrintVisitor::Visit(ArrayExpression* node) {
|
|||
|
||||
// Name
|
||||
|
||||
void PrintVisitor::Visit(PartitionName* node) {
|
||||
out_ << "[PartitionName] (";
|
||||
for (auto& path_namespace : node->path) {
|
||||
Visit(&path_namespace);
|
||||
out_ << "::";
|
||||
}
|
||||
Visit(&node->name);
|
||||
out_ << ')';
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(NameExpression* node) {
|
||||
out_ << "[NameExpression] (";
|
||||
for (size_t i = 0; i < node->names.size(); ++i) {
|
||||
|
|
|
|||
|
|
@ -23,22 +23,6 @@ void TypeCheckVisitor::Visit(SourceFile* node) {
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void TypeCheckVisitor::Visit(PartitionSources* node) {
|
||||
for (auto& statement : node->statements) {
|
||||
Visitor::Visit(statement);
|
||||
}
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(Partition* node) {
|
||||
Visit(&node->scope);
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(NamespaceSources* node) {
|
||||
for (auto& statement : node->statements) {
|
||||
Visitor::Visit(statement);
|
||||
|
|
@ -133,7 +117,6 @@ void TypeCheckVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
is_const_definition_ = std::nullopt;
|
||||
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
|
||||
is_in_statement_ = false;
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
|
|
@ -156,7 +139,6 @@ void TypeCheckVisitor::Visit(FunctionDeclaration* node) {
|
|||
}
|
||||
Visit(node->type.get());
|
||||
context_manager_.ExitContext();
|
||||
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
|
||||
if (!was_in_statement) {
|
||||
|
|
@ -168,7 +150,6 @@ void TypeCheckVisitor::Visit(FunctionDeclaration* node) {
|
|||
|
||||
void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
|
||||
context_manager_.EnterContext();
|
||||
|
||||
const info::definition::Function& function_info = namespace_visitor_.GetGlobalInfo()->GetFunctionInfo(node->function_id_);
|
||||
|
|
@ -206,15 +187,13 @@ void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
|||
Visitor::Visit(*declaration.argument_types.back());
|
||||
utils::IdType return_type = current_type_;
|
||||
|
||||
// Visitor::Visit(node->value);
|
||||
Visitor::Visit(node->value);
|
||||
if (!context_manager_.EqualTypes(return_type, current_type_)) {
|
||||
error_handling::HandleTypecheckError("Wrong function return type", node->base);
|
||||
}
|
||||
|
||||
context_manager_.ExitContext();
|
||||
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
|
||||
is_in_statement_ = false;
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
|
|
@ -222,9 +201,7 @@ void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
|||
|
||||
void TypeCheckVisitor::Visit(TypeDefinitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
|
||||
is_in_statement_ = false;
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
|
|
@ -247,7 +224,6 @@ void TypeCheckVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
|||
}
|
||||
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
|
||||
is_in_statement_ = false;
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
|
|
@ -255,9 +231,20 @@ void TypeCheckVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
|||
|
||||
void TypeCheckVisitor::Visit(TypeclassDefinitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
is_in_statement_ = false;
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(PartitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
context_manager_.EnterContext();
|
||||
|
||||
Visitor::Visit(node->value);
|
||||
|
||||
context_manager_.ExitContext();
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
is_in_statement_ = false;
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
|
|
@ -1041,6 +1028,8 @@ void TypeCheckVisitor::Visit(ArrayExpression* node) {
|
|||
|
||||
// Name
|
||||
|
||||
void TypeCheckVisitor::Visit(PartitionName* node) {} // Handled in partition ( executable / test )
|
||||
|
||||
void TypeCheckVisitor::Visit(NameExpression* node) {
|
||||
// TODO: move, etc.
|
||||
if (node->names.size() == 0) {
|
||||
|
|
|
|||
|
|
@ -21,44 +21,6 @@ void TypedPrintVisitor::Visit(SourceFile* node) {
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void TypedPrintVisitor::Visit(PartitionSources* node) {
|
||||
out_ << "[PartitionSources : ";
|
||||
|
||||
if (node->base.type_.has_value()) {
|
||||
out_ << context_manager_.GetAnyType(node->base.type_.value())->GetTypeName();
|
||||
}
|
||||
|
||||
out_ << "](\n";
|
||||
for (auto& statement : node->statements) {
|
||||
Visitor::Visit(statement);
|
||||
}
|
||||
out_ << ")\n";
|
||||
}
|
||||
|
||||
void TypedPrintVisitor::Visit(Partition* node) {
|
||||
out_ << "[Partition : ";
|
||||
|
||||
if (node->base.type_.has_value()) {
|
||||
out_ << context_manager_.GetAnyType(node->base.type_.value())->GetTypeName();
|
||||
}
|
||||
|
||||
out_ << "] ";
|
||||
switch (node->name) {
|
||||
case Partition::Test:
|
||||
out_ << "TEST";
|
||||
break;
|
||||
case Partition::Interface:
|
||||
out_ << "INTERFACE";
|
||||
break;
|
||||
case Partition::Code:
|
||||
out_ << "CODE";
|
||||
break;
|
||||
}
|
||||
out_ << " {\n";
|
||||
Visit(&node->scope);
|
||||
out_ << "}\n";
|
||||
}
|
||||
|
||||
void TypedPrintVisitor::Visit(NamespaceSources* node) {
|
||||
out_ << "[NamespaceSources : ";
|
||||
|
||||
|
|
@ -165,7 +127,11 @@ void TypedPrintVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
}
|
||||
|
||||
void TypedPrintVisitor::Visit(FunctionDeclaration* node) {
|
||||
out_ << "[FunctionDeclaration : (";
|
||||
out_ << "[FunctionDeclaration ";
|
||||
if (node->is_in_interface) {
|
||||
out_ << "interface ";
|
||||
}
|
||||
out_ << ": (";
|
||||
|
||||
if (node->base.type_.has_value()) {
|
||||
out_ << context_manager_.GetAnyType(node->base.type_.value())->GetTypeName();
|
||||
|
|
@ -212,6 +178,9 @@ void TypedPrintVisitor::Visit(TypeDefinitionStatement* node) {
|
|||
out_ << "class";
|
||||
break;
|
||||
}
|
||||
if (node->is_in_interface) {
|
||||
out_ << " interface";
|
||||
}
|
||||
out_ << "] (";
|
||||
Visit(node->definition.get());
|
||||
out_ << ") = (";
|
||||
|
|
@ -260,6 +229,28 @@ void TypedPrintVisitor::Visit(TypeclassDefinitionStatement* node) {
|
|||
out_ << ")\n";
|
||||
}
|
||||
|
||||
void TypedPrintVisitor::Visit(PartitionStatement* node) {
|
||||
out_ << "[Partition : (";
|
||||
|
||||
if (node->base.type_.has_value()) {
|
||||
out_ << context_manager_.GetAnyType(node->base.type_.value())->GetTypeName();
|
||||
}
|
||||
|
||||
out_ << ") ";
|
||||
switch (node->modifier) {
|
||||
case utils::PartitionModifier::Exec:
|
||||
out_ << "exec ";
|
||||
break;
|
||||
case utils::PartitionModifier::Test:
|
||||
out_ << "test ";
|
||||
break;
|
||||
}
|
||||
Visit(&node->name);
|
||||
out_ << "] = (";
|
||||
Visitor::Visit(node->value);
|
||||
out_ << ")\n";
|
||||
}
|
||||
|
||||
// Definition parts
|
||||
|
||||
void TypedPrintVisitor::Visit(FunctionDefinition* node) {
|
||||
|
|
@ -783,6 +774,22 @@ void TypedPrintVisitor::Visit(ArrayExpression* node) {
|
|||
|
||||
// Name
|
||||
|
||||
void TypedPrintVisitor::Visit(PartitionName* node) {
|
||||
out_ << "[PartitionName : ";
|
||||
|
||||
if (node->base.type_.has_value()) {
|
||||
out_ << context_manager_.GetAnyType(node->base.type_.value())->GetTypeName();
|
||||
}
|
||||
|
||||
out_ << "] (";
|
||||
for (auto& path_namespace : node->path) {
|
||||
Visit(&path_namespace);
|
||||
out_ << "::";
|
||||
}
|
||||
Visit(&node->name);
|
||||
out_ << ')';
|
||||
}
|
||||
|
||||
void TypedPrintVisitor::Visit(NameExpression* node) {
|
||||
out_ << "[NameExpression : ";
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ void Visitor::Visit(NamespaceStatement& node) {
|
|||
Visit(std::get<std::unique_ptr<TypeDefinitionStatement>>(node).get());
|
||||
break;
|
||||
case 4:
|
||||
Visit(std::get<std::unique_ptr<PartitionStatement>>(node).get());
|
||||
break;
|
||||
case 5:
|
||||
Visit(std::get<std::unique_ptr<Namespace>>(node).get());
|
||||
break;
|
||||
default:
|
||||
|
|
@ -28,33 +31,19 @@ void Visitor::Visit(NamespaceStatement& node) {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
switch (node.index()) {
|
||||
case 0:
|
||||
Visit(std::get<std::unique_ptr<ImportStatement>>(node).get());
|
||||
break;
|
||||
case 1:
|
||||
Visit(std::get<std::unique_ptr<Partition>>(node).get());
|
||||
Visit(std::get<std::unique_ptr<AbstractTypeDefinitionStatement>>(node).get());
|
||||
break;
|
||||
case 2:
|
||||
Visit(*std::get<std::unique_ptr<PartitionStatement>>(node));
|
||||
Visit(std::get<std::unique_ptr<TypeclassDefinitionStatement>>(node).get());
|
||||
break;
|
||||
case 3:
|
||||
Visit(*std::get<std::unique_ptr<NamespaceStatement>>(node));
|
||||
break;
|
||||
default:
|
||||
// error
|
||||
|
|
@ -315,16 +304,6 @@ void Visitor::Visit(SourceFile* node) {
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void Visitor::Visit(PartitionSources* node) {
|
||||
for (auto& statement : node->statements) {
|
||||
Visit(statement);
|
||||
}
|
||||
}
|
||||
|
||||
void Visitor::Visit(Partition* node) {
|
||||
Visit(&node->scope);
|
||||
}
|
||||
|
||||
void Visitor::Visit(NamespaceSources* node) {
|
||||
for (auto& statement : node->statements) {
|
||||
Visit(statement);
|
||||
|
|
@ -383,6 +362,11 @@ void Visitor::Visit(TypeclassDefinitionStatement* node) {
|
|||
}
|
||||
}
|
||||
|
||||
void Visitor::Visit(PartitionStatement* node) {
|
||||
Visit(&node->name);
|
||||
Visit(node->value);
|
||||
}
|
||||
|
||||
// Definition parts
|
||||
|
||||
void Visitor::Visit(FunctionDefinition* node) {
|
||||
|
|
@ -576,6 +560,13 @@ void Visitor::Visit(ArrayExpression* node) {
|
|||
|
||||
// Name
|
||||
|
||||
void Visitor::Visit(PartitionName* node) {
|
||||
for (auto& path_namespace : node->path) {
|
||||
Visit(&path_namespace);
|
||||
}
|
||||
Visit(&node->name);
|
||||
}
|
||||
|
||||
void Visitor::Visit(NameExpression* node) {
|
||||
for (auto& name : node->names) {
|
||||
Visit(&name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue