basic node builders

This commit is contained in:
ProgramSnail 2023-07-20 14:38:44 +03:00
parent 1b28f41810
commit 696a9c3a1a
11 changed files with 442 additions and 37 deletions

View file

@ -1,6 +1,9 @@
#pragma once
#include "basic_nodes.hpp"
#include "docs.hpp"
#include "expression_nodes.hpp"
#include "type_nodes.hpp"
#include <vector>
@ -8,20 +11,106 @@
namespace nodes {
// IN PROGRESS: add another constructors ??
class Import : public Node {
public:
Import(Node node, const Identifier &import_name,
const Identifier &module_name, std::vector<Identifier> &&symbols = {})
: Node(node), import_name_(import_name), module_name_(module_name),
symbols_(std::move(symbols)) {}
size_t symbols_size() const { return symbols_.size(); }
std::string *get_symbol(size_t id) { return symbols_.at(id).get(); }
const std::string *get_symbol(size_t id) const {
return symbols_.at(id).get();
}
private:
Identifier import_name_;
Identifier module_name_;
std::vector<Identifier> symbols_;
};
class Constraint : public Node {
public:
Constraint(Node node, ExpressionProxy expression)
: Node(node), expression_(expression) {}
Expression *get_expression() { return expression_.get(); }
const Expression *get_expression() const { return expression_.get(); }
private:
ExpressionProxy expression_;
};
class FunctionDefinition : public Node {
public:
enum ModifierType {
STATIC,
LET,
VAR,
};
FunctionDefinition(Node node, SymbolDocs &&docs,
std::vector<Constraint> &&constraints,
ModifierType modifier, const Identifier &name,
std::vector<std::string> &&annotations,
std::vector<Identifier> &&arguments,
std::vector<ReferenceType> &&reference_types,
std::vector<TypeProxy> &&types)
: Node(node), docs_(std::move(docs)),
constraints_(std::move(constraints)), modifier_(modifier), name_(name),
annotations_(std::move(annotations)), arguments_(std::move(arguments)),
reference_types_(std::move(reference_types)), types_(std::move(types)) {
}
private:
SymbolDocs docs_;
std::vector<Constraint> constraints_;
ModifierType modifier_;
Identifier name_;
std::vector<std::string> annotations_;
std::vector<Identifier> arguments_;
std::vector<ReferenceType> reference_types_;
std::vector<TypeProxy> types_;
// std::vector<bool> optional_arguments_; // ??
}; // IN PROGRESS
class Constraint : public Node {}; // IN PROGRESS
class TypeDefinition : public Node {
public:
TypeDefinition(Node node, SymbolDocs &&docs, bool is_on_heap,
const Identifier &name, std::vector<Identifier> &&arguments,
VariantType &&type, std::vector<FunctionDefinition> &&methods)
: Node(node), docs_(std::move(docs)), is_on_heap_(is_on_heap),
name_(name), arguments_(std::move(arguments)), type_(std::move(type)),
methods_(std::move(methods)) {}
class TypeDefinition : public Node {}; // IN PROGRESS
private:
SymbolDocs docs_;
bool is_on_heap_;
Identifier name_;
std::vector<Identifier> arguments_;
VariantType type_; // TupleType is VariantType with one variant
std::vector<FunctionDefinition> methods_;
}; // IN PROGRESS
class FunctionDefinition : public Node {}; // IN PROGRESS
class TypeclassDefinition : public Node {
public:
TypeclassDefinition(Node node, SymbolDocs &&docs, const Identifier &name,
std::vector<Identifier> &&base_typeclasses,
std::vector<FunctionDefinition> &&methods)
: Node(node), docs_(std::move(docs)), name_(name),
base_typeclasses_(std::move(base_typeclasses)),
methods_(std::move(methods)) {}
class TypeclassDefinition : public Node {}; // IN PROGRESS
private:
SymbolDocs docs_;
Identifier name_;
std::vector<Identifier> base_typeclasses_;
std::vector<FunctionDefinition> methods_;
}; // IN PROGRESS
} // namespace nodes