mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-06 15:08:48 +00:00
basic printers, type printers, some fixes, part of expression printers
This commit is contained in:
parent
3914ff7d8b
commit
3669084f55
14 changed files with 795 additions and 39 deletions
|
|
@ -177,7 +177,7 @@ public:
|
|||
: Node(node), type_(FOR), expression_(expression), variable_(variable),
|
||||
interval_(interval) {}
|
||||
|
||||
LoopType get_type() { return type_; }
|
||||
LoopType get_type() const { return type_; }
|
||||
|
||||
Expression *get_expression() { return expression_.get(); }
|
||||
|
||||
|
|
@ -234,7 +234,7 @@ public:
|
|||
const std::vector<ExpressionProxy> &expressions)
|
||||
: Node(node), type_(type), expressions_(expressions) {}
|
||||
|
||||
ContainerType get_type() { return type_; }
|
||||
ContainerType get_type() const { return type_; }
|
||||
|
||||
size_t expressions_size() const { return expressions_.size(); }
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ public:
|
|||
Return(Node node, ReturnType type, ExpressionProxy expression)
|
||||
: Node(node), type_(type), expression_(expression) {}
|
||||
|
||||
ReturnType get_type() { return type_; }
|
||||
ReturnType get_type() const { return type_; }
|
||||
|
||||
Expression *get_expression() { return expression_.get(); }
|
||||
|
||||
|
|
@ -287,11 +287,11 @@ public:
|
|||
NameDefinition(Node node, Modifier modifier, const Identifier &name)
|
||||
: Node(node), modifier_(modifier), name_(name) {}
|
||||
|
||||
Modifier get_modifier() { return modifier_; }
|
||||
Modifier get_modifier() const { return modifier_; }
|
||||
|
||||
std::string *get_name() { return name_.get(); }
|
||||
Identifier *get_name() { return &name_; }
|
||||
|
||||
const std::string *get_name() const { return name_.get(); }
|
||||
const Identifier *get_name() const { return &name_; }
|
||||
|
||||
private:
|
||||
Modifier modifier_;
|
||||
|
|
@ -310,7 +310,7 @@ public:
|
|||
ExpressionProxy index)
|
||||
: Node(node), type_(type), value_(value), index_(index) {}
|
||||
|
||||
AccessType get_type() { return type_; }
|
||||
AccessType get_type() const { return type_; }
|
||||
|
||||
Expression *get_value() { return value_.get(); }
|
||||
|
||||
|
|
@ -336,7 +336,7 @@ public:
|
|||
|
||||
LoopControl(Node node, LoopControlType type) : Node(node), type_(type) {}
|
||||
|
||||
LoopControlType get_type() { return type_; }
|
||||
LoopControlType get_type() const { return type_; }
|
||||
|
||||
private:
|
||||
LoopControlType type_;
|
||||
|
|
@ -347,7 +347,7 @@ public:
|
|||
ModifierExpression(Node node, Modifier modifier, ExpressionProxy expression)
|
||||
: Node(node), modifier_(modifier), expression_(expression) {}
|
||||
|
||||
Modifier get_modifier() { return modifier_; }
|
||||
Modifier get_modifier() const { return modifier_; }
|
||||
|
||||
Expression *get_expression() { return expression_.get(); }
|
||||
|
||||
|
|
@ -372,24 +372,26 @@ public:
|
|||
Node node, Identifier &&name,
|
||||
std::vector<std::pair<std::optional<std::string>, ExpressionProxy>>
|
||||
&&arguments,
|
||||
std::optional<TypeProxy> &&prefix, bool is_point_call = false)
|
||||
std::optional<TypeProxy> &&prefix, bool is_point_call = false,
|
||||
bool is_operator_call = false)
|
||||
: Node(node), name_(std::move(name)), arguments_(std::move(arguments)),
|
||||
prefix_(std::move(prefix)), is_point_call_(is_point_call) {}
|
||||
prefix_(std::move(prefix)), is_point_call_(is_point_call),
|
||||
is_operator_call_(is_operator_call) {}
|
||||
|
||||
std::string *get_name() { return name_.get(); }
|
||||
Identifier *get_name() { return &name_; }
|
||||
|
||||
const std::string *get_name() const { return name_.get(); }
|
||||
const Identifier *get_name() const { return &name_; }
|
||||
|
||||
std::optional<TypeProxy> get_prefix() {
|
||||
std::optional<Type *> get_prefix() {
|
||||
if (prefix_.has_value()) {
|
||||
return prefix_.value();
|
||||
return prefix_.value().get();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<const TypeProxy> get_prefix() const {
|
||||
std::optional<const Type *> get_prefix() const {
|
||||
if (prefix_.has_value()) {
|
||||
return prefix_.value();
|
||||
return prefix_.value().get();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
@ -418,7 +420,9 @@ public:
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool is_point_call() { return is_point_call_; }
|
||||
bool is_point_call() const { return is_point_call_; }
|
||||
|
||||
bool is_operator_call() const { return is_operator_call_; }
|
||||
|
||||
private:
|
||||
Identifier name_;
|
||||
|
|
@ -427,7 +431,8 @@ private:
|
|||
arguments_;
|
||||
std::optional<TypeProxy> prefix_;
|
||||
// for static methods
|
||||
bool is_point_call_ = false; // x.f ... or f x ...
|
||||
bool is_point_call_ = false; // x.f ... or f x ...
|
||||
bool is_operator_call_ = false; // ... operator ...
|
||||
};
|
||||
|
||||
class Constructor : public Node {
|
||||
|
|
@ -506,7 +511,8 @@ private:
|
|||
class Expression {
|
||||
public:
|
||||
template <typename T>
|
||||
Expression(T &&expression) : expression_(std::forward<T>(expression)) {}
|
||||
Expression(T &&expression, bool is_scoped)
|
||||
: expression_(std::forward<T>(expression)), is_scoped_(is_scoped) {}
|
||||
|
||||
template <typename T> std::optional<T *> get() {
|
||||
if (std::holds_alternative<T>(expression_)) {
|
||||
|
|
@ -522,6 +528,8 @@ public:
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool is_scoped() const { return is_scoped_; }
|
||||
|
||||
private:
|
||||
std::variant<
|
||||
|
||||
|
|
@ -552,6 +560,8 @@ private:
|
|||
|
||||
>
|
||||
expression_;
|
||||
|
||||
bool is_scoped_ = false;
|
||||
};
|
||||
|
||||
class ExpressionStorage {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue