mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-06 06:58:46 +00:00
or references, prining improvements, comments now printed, fixes
This commit is contained in:
parent
73263193a9
commit
5e70f0015f
19 changed files with 354 additions and 429 deletions
|
|
@ -73,12 +73,6 @@ private:
|
|||
|
||||
class FunctionDefinition : public Node {
|
||||
public:
|
||||
enum MethodModifier {
|
||||
STATIC,
|
||||
LET,
|
||||
VAR,
|
||||
};
|
||||
|
||||
class Argument {
|
||||
public:
|
||||
Argument(const std::optional<std::string> &annotation, Identifier &&name,
|
||||
|
|
@ -237,16 +231,21 @@ public:
|
|||
|
||||
FunctionDefinition(Node node, SymbolDocs &&docs,
|
||||
std::vector<Constraint> &&constraints,
|
||||
Modifier return_modifier, MethodModifier method_modifier,
|
||||
Modifier return_modifier, bool is_method,
|
||||
const std::optional<Identifier> &name_prefix,
|
||||
const Identifier &name, std::vector<Argument> &&arguments,
|
||||
bool are_annotations_same_to_names,
|
||||
std::optional<ExpressionProxy> expression)
|
||||
: Node(node), docs_(std::move(docs)),
|
||||
constraints_(std::move(constraints)), return_modifier_(return_modifier),
|
||||
method_modifier_(method_modifier), name_(name),
|
||||
is_method_(is_method), name_(name), full_name_(name),
|
||||
arguments_(std::move(arguments)),
|
||||
are_annotations_same_to_names_(are_annotations_same_to_names),
|
||||
expression_(expression) {}
|
||||
expression_(expression) {
|
||||
if (name_prefix.has_value()) {
|
||||
full_name_.append_before(*name_prefix.value().get());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
|
@ -268,7 +267,7 @@ public:
|
|||
|
||||
Modifier get_return_modifier() const { return return_modifier_; }
|
||||
|
||||
MethodModifier get_method_modifier() const { return method_modifier_; }
|
||||
bool is_method() const { return is_method_; }
|
||||
|
||||
//
|
||||
|
||||
|
|
@ -278,6 +277,12 @@ public:
|
|||
|
||||
//
|
||||
|
||||
Identifier *get_full_name() { return &full_name_; }
|
||||
|
||||
const Identifier *get_full_name() const { return &full_name_; }
|
||||
|
||||
//
|
||||
|
||||
size_t get_arguments_size() const { return arguments_.size(); }
|
||||
|
||||
Argument *get_argument(size_t id) { return &arguments_.at(id); }
|
||||
|
|
@ -316,8 +321,9 @@ private:
|
|||
SymbolDocs docs_;
|
||||
std::vector<Constraint> constraints_;
|
||||
Modifier return_modifier_;
|
||||
MethodModifier method_modifier_;
|
||||
bool is_method_;
|
||||
Identifier name_;
|
||||
Identifier full_name_;
|
||||
std::vector<Argument> arguments_;
|
||||
bool are_annotations_same_to_names_; // needed for easier prinitng process
|
||||
std::optional<ExpressionProxy> expression_;
|
||||
|
|
@ -326,16 +332,12 @@ private:
|
|||
class TypeDefinition : public Node {
|
||||
public:
|
||||
TypeDefinition(Node node, SymbolDocs &&docs, bool is_on_heap,
|
||||
const Identifier &name, std::vector<Identifier> &&arguments,
|
||||
std::optional<VariantType> &&type,
|
||||
std::vector<FunctionDefinition> &&methods)
|
||||
const Identifier &name, std::vector<Identifier> &&typeclasses,
|
||||
std::vector<Identifier> &&arguments,
|
||||
std::optional<VariantType> &&type)
|
||||
: 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)) {
|
||||
for (size_t i = 0; i < methods.size(); ++i) {
|
||||
methods_by_name_[*methods_[i].get_name()->get()] = i;
|
||||
}
|
||||
}
|
||||
name_(name), typeclasses_(typeclasses),
|
||||
arguments_(std::move(arguments)), type_(std::move(type)) {}
|
||||
|
||||
//
|
||||
|
||||
|
|
@ -379,13 +381,7 @@ public:
|
|||
|
||||
//
|
||||
|
||||
size_t get_methods_size() const { return methods_.size(); }
|
||||
|
||||
FunctionDefinition *get_method(size_t id) { return &methods_.at(id); }
|
||||
|
||||
const FunctionDefinition *get_method(size_t id) const {
|
||||
return &methods_.at(id);
|
||||
}
|
||||
bool is_typeclass() { return name_.get_type() == Identifier::TYPECLASS; }
|
||||
|
||||
//
|
||||
|
||||
|
|
@ -397,73 +393,9 @@ private:
|
|||
SymbolDocs docs_;
|
||||
bool is_on_heap_;
|
||||
Identifier name_;
|
||||
std::vector<Identifier> typeclasses_;
|
||||
std::vector<Identifier> arguments_;
|
||||
std::optional<VariantType> type_; // TupleType is VariantType with one variant
|
||||
std::unordered_map<std::string, size_t>
|
||||
methods_by_name_; // methods can't be overloaded ??
|
||||
std::vector<FunctionDefinition> methods_;
|
||||
};
|
||||
|
||||
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)) {
|
||||
for (size_t i = 0; i < methods.size(); ++i) {
|
||||
methods_by_name_[*methods_[i].get_name()->get()] = i;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
SymbolDocs *get_docs() { return &docs_; }
|
||||
|
||||
const SymbolDocs *get_docs() const { return &docs_; }
|
||||
|
||||
//
|
||||
|
||||
Identifier *get_name() { return &name_; }
|
||||
|
||||
const Identifier *get_name() const { return &name_; }
|
||||
|
||||
//
|
||||
|
||||
size_t get_base_typeclasses_size() const { return base_typeclasses_.size(); }
|
||||
|
||||
Identifier *get_base_typeclass(size_t id) {
|
||||
return &base_typeclasses_.at(id);
|
||||
}
|
||||
|
||||
const Identifier *get_base_typeclass(size_t id) const {
|
||||
return &base_typeclasses_.at(id);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
size_t get_methods_size() const { return methods_.size(); }
|
||||
|
||||
FunctionDefinition *get_method(size_t id) { return &methods_.at(id); }
|
||||
|
||||
const FunctionDefinition *get_method(size_t id) const {
|
||||
return &methods_.at(id);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
bool is_same_to(const TypeclassDefinition &other_typeclass_definition) const;
|
||||
|
||||
CombineResult combine(TypeclassDefinition &&other_typeclass_definition);
|
||||
|
||||
private:
|
||||
SymbolDocs docs_;
|
||||
Identifier name_;
|
||||
std::vector<Identifier> base_typeclasses_;
|
||||
std::unordered_map<std::string, size_t>
|
||||
methods_by_name_; // methods can't be overloaded ??
|
||||
std::vector<FunctionDefinition> methods_;
|
||||
};
|
||||
|
||||
class Statement {
|
||||
|
|
@ -498,8 +430,7 @@ public:
|
|||
CombineResult combine(Statement &&other_statement);
|
||||
|
||||
private:
|
||||
std::variant<Import, TypeDefinition, FunctionDefinition, TypeclassDefinition,
|
||||
EmptyLines>
|
||||
std::variant<Import, TypeDefinition, FunctionDefinition, Extra, EmptyLines>
|
||||
expression_;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue