mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-06 06:58:46 +00:00
function definition class structure changed, corresponding builders and printers fixes, fixes
This commit is contained in:
parent
18d7bdf5c1
commit
b4ce56b5f7
13 changed files with 323 additions and 284 deletions
|
|
@ -66,24 +66,138 @@ public:
|
|||
VAR,
|
||||
};
|
||||
|
||||
class Argument {
|
||||
public:
|
||||
Argument(const std::optional<std::string> &annotation, Identifier &&name,
|
||||
Modifier before_modifier = Modifier::NONE,
|
||||
Modifier after_modifier = Modifier::NONE)
|
||||
: annotation_(annotation), name_(std::move(name)),
|
||||
before_modifier_(before_modifier), after_modifier_(after_modifier) {}
|
||||
|
||||
Argument(const std::optional<std::string> &annotation,
|
||||
const Identifier &name, Modifier before_modifier = Modifier::NONE,
|
||||
Modifier after_modifier = Modifier::NONE)
|
||||
: annotation_(annotation), name_(name),
|
||||
before_modifier_(before_modifier), after_modifier_(after_modifier) {}
|
||||
|
||||
Argument(const std::optional<std::string> &annotation, TypeProxy type,
|
||||
Modifier before_modifier = Modifier::NONE)
|
||||
: annotation_(annotation), type_(type),
|
||||
before_modifier_(before_modifier),
|
||||
after_modifier_(type.get()->get_modifier()) {}
|
||||
|
||||
//
|
||||
|
||||
bool add_type(const std::optional<std::string> &annotation, TypeProxy type,
|
||||
nodes::Modifier before_modifier = Modifier::NONE) {
|
||||
if (annotation_.has_value() &&
|
||||
(!annotation.has_value() ||
|
||||
annotation_.value() != annotation.value())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (before_modifier_ != Modifier::NONE &&
|
||||
before_modifier_ != before_modifier) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (after_modifier_ != Modifier::NONE &&
|
||||
after_modifier_ != type.get()->get_modifier()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
annotation_ = annotation;
|
||||
type_ = type;
|
||||
before_modifier_ = before_modifier;
|
||||
after_modifier_ = type.get()->get_modifier();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool add_annotation(const std::string &annotation) {
|
||||
if (annotation_.has_value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
annotation_ = annotation;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
std::optional<std::string *> get_annotation() {
|
||||
if (annotation_.has_value()) {
|
||||
return &annotation_.value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<const std::string *> get_annotation() const {
|
||||
if (annotation_.has_value()) {
|
||||
return &annotation_.value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
std::optional<Identifier *> get_name() {
|
||||
if (name_.has_value()) {
|
||||
return &name_.value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<const Identifier *> get_name() const {
|
||||
if (name_.has_value()) {
|
||||
return &name_.value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
std::optional<Type *> get_type() {
|
||||
if (type_.has_value()) {
|
||||
return type_.value().get();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<const Type *> get_type() const {
|
||||
if (type_.has_value()) {
|
||||
return type_.value().get();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Modifier get_before_modifier() const { return before_modifier_; }
|
||||
|
||||
Modifier get_after_modifier() const { return after_modifier_; }
|
||||
|
||||
private:
|
||||
std::optional<std::string> annotation_;
|
||||
std::optional<Identifier> name_; // no name for output arguments
|
||||
std::optional<TypeProxy> type_; // no type if it is deduced
|
||||
Modifier before_modifier_ =
|
||||
Modifier::NONE; // in, out, ref, none // sync with type
|
||||
Modifier after_modifier_ =
|
||||
Modifier::NONE; // optional, result, none // sync with type
|
||||
};
|
||||
|
||||
FunctionDefinition(Node node, SymbolDocs &&docs,
|
||||
std::vector<Constraint> &&constraints,
|
||||
ModifierType modifier, const Identifier &name,
|
||||
std::vector<std::optional<std::string>> &&annotations,
|
||||
std::vector<Identifier> &&arguments,
|
||||
std::vector<Modifier> &&reference_types,
|
||||
std::vector<TypeProxy> &&types,
|
||||
std::vector<bool> &&optional_arguments,
|
||||
std::vector<bool> &&result_arguments,
|
||||
bool is_annotations_same_to_names,
|
||||
std::vector<Argument> &&arguments,
|
||||
bool are_annotations_same_to_names,
|
||||
std::optional<ExpressionProxy> expression)
|
||||
: 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)),
|
||||
optional_arguments_(optional_arguments),
|
||||
result_arguments_(result_arguments),
|
||||
is_annotations_same_to_names_(is_annotations_same_to_names),
|
||||
arguments_(std::move(arguments)),
|
||||
are_annotations_same_to_names_(are_annotations_same_to_names),
|
||||
expression_(expression) {}
|
||||
|
||||
//
|
||||
|
|
@ -114,57 +228,11 @@ public:
|
|||
|
||||
//
|
||||
|
||||
std::optional<std::string *> get_argument_annotation(size_t id) {
|
||||
if (annotations_.at(id).has_value()) {
|
||||
return &annotations_[id].value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<const std::string *> get_argument_annotation(size_t id) const {
|
||||
if (annotations_.at(id).has_value()) {
|
||||
return &annotations_[id].value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
size_t get_arguments_size() const { return arguments_.size(); }
|
||||
|
||||
Identifier *get_argument(size_t id) { return &arguments_.at(id); }
|
||||
Argument *get_argument(size_t id) { return &arguments_.at(id); }
|
||||
|
||||
const Identifier *get_argument(size_t id) const { return &arguments_.at(id); }
|
||||
|
||||
//
|
||||
|
||||
Modifier get_argument_reference_type(size_t id) const {
|
||||
return reference_types_.at(id);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
size_t get_argument_types_size() const { return types_.size(); }
|
||||
|
||||
Type *get_argument_type(size_t id) { return types_.at(id).get(); }
|
||||
|
||||
const Type *get_argument_type(size_t id) const { return types_.at(id).get(); }
|
||||
|
||||
//
|
||||
|
||||
bool is_argument_optional(size_t id) const {
|
||||
return optional_arguments_.at(id);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
bool is_argument_result(size_t id) const { return result_arguments_.at(id); }
|
||||
|
||||
//
|
||||
|
||||
bool is_annotations_same_to_names() const {
|
||||
return is_annotations_same_to_names_;
|
||||
}
|
||||
const Argument *get_argument(size_t id) const { return &arguments_.at(id); }
|
||||
|
||||
//
|
||||
|
||||
|
|
@ -182,18 +250,19 @@ public:
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
bool are_annotations_same_to_names() const {
|
||||
return are_annotations_same_to_names_;
|
||||
}
|
||||
|
||||
private:
|
||||
SymbolDocs docs_;
|
||||
std::vector<Constraint> constraints_;
|
||||
ModifierType modifier_;
|
||||
Identifier name_;
|
||||
std::vector<std::optional<std::string>> annotations_;
|
||||
std::vector<Identifier> arguments_;
|
||||
std::vector<Modifier> reference_types_;
|
||||
std::vector<TypeProxy> types_;
|
||||
std::vector<bool> optional_arguments_;
|
||||
std::vector<bool> result_arguments_;
|
||||
bool is_annotations_same_to_names_;
|
||||
std::vector<Argument> arguments_;
|
||||
bool are_annotations_same_to_names_; // needed for easier prinitng process
|
||||
std::optional<ExpressionProxy> expression_;
|
||||
}; // refactor ??
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue