mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
extended name removed, dereference added, unary operators removed, fixes
This commit is contained in:
parent
e62144feac
commit
79bd30c1ee
20 changed files with 101 additions and 274 deletions
|
|
@ -79,7 +79,6 @@ private:
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
void Visit(BinaryOperatorExpression* node) override;
|
void Visit(BinaryOperatorExpression* node) override;
|
||||||
void Visit(UnaryOperatorExpression* node) override;
|
|
||||||
void Visit(ReferenceExpression* node) override;
|
void Visit(ReferenceExpression* node) override;
|
||||||
void Visit(AccessExpression* node) override;
|
void Visit(AccessExpression* node) override;
|
||||||
|
|
||||||
|
|
@ -130,8 +129,6 @@ private:
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
void Visit(ExtendedName* node) override;
|
|
||||||
|
|
||||||
// // void Visit(AnyIdentifier* node) override; // std::string
|
// // void Visit(AnyIdentifier* node) override; // std::string
|
||||||
|
|
||||||
void Visit(FloatNumberLiteral* node) override;
|
void Visit(FloatNumberLiteral* node) override;
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,6 @@ private:
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
void Visit(BinaryOperatorExpression* node) override;
|
void Visit(BinaryOperatorExpression* node) override;
|
||||||
void Visit(UnaryOperatorExpression* node) override;
|
|
||||||
void Visit(ReferenceExpression* node) override;
|
void Visit(ReferenceExpression* node) override;
|
||||||
void Visit(AccessExpression* node) override;
|
void Visit(AccessExpression* node) override;
|
||||||
|
|
||||||
|
|
@ -128,8 +127,6 @@ private:
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
// // void Visit(ExtendedName* node) override;
|
|
||||||
|
|
||||||
// // void Visit(std::string* node) override; // std::string
|
// // void Visit(std::string* node) override; // std::string
|
||||||
|
|
||||||
void Visit(FloatNumberLiteral* node) override;
|
void Visit(FloatNumberLiteral* node) override;
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,6 @@ private:
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
// // void Visit(BinaryOperatorExpression* node) override;
|
// // void Visit(BinaryOperatorExpression* node) override;
|
||||||
// // void Visit(UnaryOperatorExpression* node) override;
|
|
||||||
// // void Visit(ReferenceExpression* node) override;
|
// // void Visit(ReferenceExpression* node) override;
|
||||||
// // void Visit(AccessExpression* node) override;
|
// // void Visit(AccessExpression* node) override;
|
||||||
|
|
||||||
|
|
@ -110,8 +109,6 @@ private:
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
// // void Visit(ExtendedName* node) override;
|
|
||||||
|
|
||||||
// // void Visit(std::string* node) override; // std::string
|
// // void Visit(std::string* node) override; // std::string
|
||||||
|
|
||||||
// // void Visit(FloatNumberLiteral* node) override;
|
// // void Visit(FloatNumberLiteral* node) override;
|
||||||
|
|
|
||||||
|
|
@ -151,12 +151,10 @@ using PrefixedExpression = std::variant<
|
||||||
//
|
//
|
||||||
struct LambdaFunction;
|
struct LambdaFunction;
|
||||||
struct TypeConstructor;
|
struct TypeConstructor;
|
||||||
struct UnaryOperatorExpression;
|
|
||||||
using Expression = std::variant<
|
using Expression = std::variant<
|
||||||
std::unique_ptr<LambdaFunction>,
|
std::unique_ptr<LambdaFunction>,
|
||||||
std::unique_ptr<TypeConstructor>,
|
std::unique_ptr<TypeConstructor>,
|
||||||
std::unique_ptr<PrefixedExpression>,
|
std::unique_ptr<PrefixedExpression>,
|
||||||
std::unique_ptr<UnaryOperatorExpression>,
|
|
||||||
std::unique_ptr<SubExpression>>;
|
std::unique_ptr<SubExpression>>;
|
||||||
//
|
//
|
||||||
struct TupleExpression;
|
struct TupleExpression;
|
||||||
|
|
@ -174,7 +172,6 @@ struct ScopedStatement;
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
struct BinaryOperatorExpression;
|
struct BinaryOperatorExpression;
|
||||||
struct UnaryOperatorExpression;
|
|
||||||
struct ReferenceExpression;
|
struct ReferenceExpression;
|
||||||
|
|
||||||
// Other expressions
|
// Other expressions
|
||||||
|
|
@ -246,14 +243,8 @@ struct ParametrizedType;
|
||||||
// Comments [IGNORE] -----------------
|
// Comments [IGNORE] -----------------
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
struct ExtendedName {
|
|
||||||
BaseNode base;
|
|
||||||
|
|
||||||
std::string name;
|
|
||||||
};
|
|
||||||
|
|
||||||
using Pattern = std::variant<
|
using Pattern = std::variant<
|
||||||
std::unique_ptr<ExtendedName>,
|
std::unique_ptr<NameIdentifier>,
|
||||||
std::unique_ptr<Literal>,
|
std::unique_ptr<Literal>,
|
||||||
std::unique_ptr<TypeConstructorPattern>>;
|
std::unique_ptr<TypeConstructorPattern>>;
|
||||||
|
|
||||||
|
|
@ -323,7 +314,7 @@ struct FunctionDeclaration {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
bool is_in_interface = false;
|
bool is_in_interface = false;
|
||||||
ExtendedName name;
|
NameOrOperatorIdentifier name;
|
||||||
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
||||||
std::unique_ptr<FunctionType> type;
|
std::unique_ptr<FunctionType> type;
|
||||||
|
|
||||||
|
|
@ -384,9 +375,8 @@ struct PartitionStatement {
|
||||||
struct FunctionDefinition {
|
struct FunctionDefinition {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
utils::FunctionTypeModifier modifier;
|
NameOrOperatorIdentifier name;
|
||||||
ExtendedName name;
|
std::vector<NameIdentifier> arguments;
|
||||||
std::vector<ExtendedName> arguments;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TypeDefinition {
|
struct TypeDefinition {
|
||||||
|
|
@ -408,7 +398,7 @@ struct AnyAnnotatedType {
|
||||||
struct TypeConstructorPatternParameter {
|
struct TypeConstructorPatternParameter {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
std::optional<ExtendedName> name;
|
std::optional<NameIdentifier> name;
|
||||||
ScopedPattern value;
|
ScopedPattern value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -498,20 +488,12 @@ struct BinaryOperatorExpression {
|
||||||
OperatorIdentifier operator_name;
|
OperatorIdentifier operator_name;
|
||||||
SubExpression left_expression;
|
SubExpression left_expression;
|
||||||
SubExpression right_expression;
|
SubExpression right_expression;
|
||||||
|
size_t precedence = utils::MaxOperatorPrecedence;
|
||||||
|
|
||||||
utils::IdType function_id_;
|
utils::IdType function_id_;
|
||||||
bool is_method_ = false;
|
bool is_method_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UnaryOperatorExpression {
|
|
||||||
BaseNode base;
|
|
||||||
|
|
||||||
OperatorIdentifier operator_name;
|
|
||||||
Expression expression;
|
|
||||||
|
|
||||||
utils::IdType function_id_;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ReferenceExpression {
|
struct ReferenceExpression {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
|
|
@ -533,7 +515,7 @@ struct FunctionCallExpression {
|
||||||
|
|
||||||
std::optional<std::variant<std::unique_ptr<SubExpressionToken>,
|
std::optional<std::variant<std::unique_ptr<SubExpressionToken>,
|
||||||
std::unique_ptr<TypeExpression>>> prefix;
|
std::unique_ptr<TypeExpression>>> prefix;
|
||||||
ExtendedName name;
|
NameOrOperatorIdentifier name;
|
||||||
std::vector<std::unique_ptr<TypeExpression>> parameters;
|
std::vector<std::unique_ptr<TypeExpression>> parameters;
|
||||||
std::vector<SubExpressionToken> arguments;
|
std::vector<SubExpressionToken> arguments;
|
||||||
|
|
||||||
|
|
@ -561,7 +543,7 @@ struct ReturnExpression {
|
||||||
struct TypeConstructorParameter {
|
struct TypeConstructorParameter {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
std::optional<ExtendedName> name;
|
std::optional<NameIdentifier> name;
|
||||||
std::optional<utils::AssignmentModifier> asignment_modifier;
|
std::optional<utils::AssignmentModifier> asignment_modifier;
|
||||||
SubExpression value;
|
SubExpression value;
|
||||||
};
|
};
|
||||||
|
|
@ -577,7 +559,7 @@ struct LambdaFunction {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
||||||
std::vector<ExtendedName> arguments;
|
std::vector<NameIdentifier> arguments;
|
||||||
Expression expression;
|
Expression expression;
|
||||||
|
|
||||||
std::vector<utils::IdType> argument_graph_ids_;
|
std::vector<utils::IdType> argument_graph_ids_;
|
||||||
|
|
@ -595,7 +577,7 @@ struct ArrayExpression {
|
||||||
struct NameExpression {
|
struct NameExpression {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
std::vector<ExtendedName> names;
|
std::vector<NameIdentifier> names;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TupleName {
|
struct TupleName {
|
||||||
|
|
@ -631,7 +613,7 @@ struct TupleType {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
std::optional<Constructor> type;
|
std::optional<Constructor> type;
|
||||||
std::vector<std::pair<std::optional<ExtendedName>, std::unique_ptr<ExtendedScopedAnyType>>> entities;
|
std::vector<std::pair<std::optional<NameIdentifier>, std::unique_ptr<ExtendedScopedAnyType>>> entities;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VariantType {
|
struct VariantType {
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,6 @@ private:
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
// // void Visit(BinaryOperatorExpression* node) override;
|
// // void Visit(BinaryOperatorExpression* node) override;
|
||||||
// // void Visit(UnaryOperatorExpression* node) override;
|
|
||||||
// // void Visit(ReferenceExpression* node) override;
|
// // void Visit(ReferenceExpression* node) override;
|
||||||
// // void Visit(AccessExpression* node) override;
|
// // void Visit(AccessExpression* node) override;
|
||||||
|
|
||||||
|
|
@ -109,8 +108,6 @@ private:
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
// // void Visit(ExtendedName* node) override;
|
|
||||||
|
|
||||||
// // void Visit(std::string* node) override; // std::string
|
// // void Visit(std::string* node) override; // std::string
|
||||||
|
|
||||||
// // void Visit(FloatNumberLiteral* node) override;
|
// // void Visit(FloatNumberLiteral* node) override;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ const std::string ScopedStatement = "scoped_statement";
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
const std::string BinaryOperatorExpression = "binary_operator_expression";
|
const std::string BinaryOperatorExpression = "binary_operator_expression";
|
||||||
const std::string UnaryOperatorExpression = "unary_operator_expression";
|
|
||||||
const std::string ReferenceExpression = "reference_expression";
|
const std::string ReferenceExpression = "reference_expression";
|
||||||
const std::string AccessExpression = "access_expression";
|
const std::string AccessExpression = "access_expression";
|
||||||
|
|
||||||
|
|
@ -115,7 +114,6 @@ const std::string ParametrizedType = "parametrized_type";
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
const std::string ExtendedName = "extended_name";
|
|
||||||
const std::string TypeclassIdentifier = "typeclass_identifier";
|
const std::string TypeclassIdentifier = "typeclass_identifier";
|
||||||
const std::string NameIdentifier = "name_identifier";
|
const std::string NameIdentifier = "name_identifier";
|
||||||
const std::string TypeIdentifier = "type_identifier";
|
const std::string TypeIdentifier = "type_identifier";
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,6 @@ private:
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
void Visit(BinaryOperatorExpression* node) override;
|
void Visit(BinaryOperatorExpression* node) override;
|
||||||
void Visit(UnaryOperatorExpression* node) override;
|
|
||||||
void Visit(ReferenceExpression* node) override;
|
void Visit(ReferenceExpression* node) override;
|
||||||
void Visit(AccessExpression* node) override;
|
void Visit(AccessExpression* node) override;
|
||||||
|
|
||||||
|
|
@ -109,8 +108,6 @@ private:
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
void Visit(ExtendedName* node) override;
|
|
||||||
|
|
||||||
void Visit(std::string* node) override; // std::string
|
void Visit(std::string* node) override; // std::string
|
||||||
|
|
||||||
void Visit(FloatNumberLiteral* node) override;
|
void Visit(FloatNumberLiteral* node) override;
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,6 @@ private:
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
void Visit(BinaryOperatorExpression* node) override;
|
void Visit(BinaryOperatorExpression* node) override;
|
||||||
void Visit(UnaryOperatorExpression* node) override;
|
|
||||||
void Visit(ReferenceExpression* node) override;
|
void Visit(ReferenceExpression* node) override;
|
||||||
void Visit(AccessExpression* node) override;
|
void Visit(AccessExpression* node) override;
|
||||||
|
|
||||||
|
|
@ -114,8 +113,6 @@ private:
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
// // void Visit(ExtendedName* node) override;
|
|
||||||
|
|
||||||
// // void Visit(std::string* node) override; // std::string
|
// // void Visit(std::string* node) override; // std::string
|
||||||
|
|
||||||
void Visit(FloatNumberLiteral* node) override;
|
void Visit(FloatNumberLiteral* node) override;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ private:
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
void Visit(BinaryOperatorExpression* node) override;
|
void Visit(BinaryOperatorExpression* node) override;
|
||||||
void Visit(UnaryOperatorExpression* node) override;
|
|
||||||
void Visit(ReferenceExpression* node) override;
|
void Visit(ReferenceExpression* node) override;
|
||||||
void Visit(AccessExpression* node) override;
|
void Visit(AccessExpression* node) override;
|
||||||
|
|
||||||
|
|
@ -111,8 +110,6 @@ private:
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
void Visit(ExtendedName* node) override;
|
|
||||||
|
|
||||||
void Visit(std::string* node) override; // std::string
|
void Visit(std::string* node) override; // std::string
|
||||||
|
|
||||||
void Visit(FloatNumberLiteral* node) override;
|
void Visit(FloatNumberLiteral* node) override;
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,14 @@ using std::size_t;
|
||||||
using IdType = size_t;
|
using IdType = size_t;
|
||||||
|
|
||||||
const std::string ClassInternalVarName = "self";
|
const std::string ClassInternalVarName = "self";
|
||||||
|
const size_t MaxOperatorPrecedence = 4;
|
||||||
|
|
||||||
enum class ReferenceModifier { Reference = 0, UniqueReference = 1 };
|
enum class ReferenceModifier { Reference = 0, UniqueReference = 1, Dereference = 2 };
|
||||||
enum class IsConstModifier { Const = 0, Var = 1 };
|
enum class IsConstModifier { Const = 0, Var = 1 };
|
||||||
enum class ClassModifier { Struct = 0, Class = 1 };
|
enum class ClassModifier { Struct = 0, Class = 1 };
|
||||||
enum class AssignmentModifier { Assign = 0, Move = 1 };
|
enum class AssignmentModifier { Assign = 0, Move = 1 };
|
||||||
enum class AliasModifier { Alias = 0, Type = 1, Let = 2 };
|
enum class AliasModifier { Alias = 0, Type = 1, Let = 2 };
|
||||||
enum class AbstractTypeModifier { Basic = 0, Abstract = 1 };
|
enum class AbstractTypeModifier { Basic = 0, Abstract = 1 };
|
||||||
enum class FunctionTypeModifier { Function = 0, Operator = 1 };
|
|
||||||
enum class PartitionModifier { Exec = 0, Test = 1 };
|
enum class PartitionModifier { Exec = 0, Test = 1 };
|
||||||
|
|
||||||
enum class ValueType { Const = 0, Var = 1, Tmp = 2 };
|
enum class ValueType { Const = 0, Var = 1, Tmp = 2 };
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,6 @@ protected:
|
||||||
// Operators
|
// Operators
|
||||||
|
|
||||||
virtual void Visit(BinaryOperatorExpression* node);
|
virtual void Visit(BinaryOperatorExpression* node);
|
||||||
virtual void Visit(UnaryOperatorExpression* node);
|
|
||||||
virtual void Visit(ReferenceExpression* node);
|
virtual void Visit(ReferenceExpression* node);
|
||||||
virtual void Visit(AccessExpression* node);
|
virtual void Visit(AccessExpression* node);
|
||||||
|
|
||||||
|
|
@ -127,8 +126,6 @@ protected:
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
virtual void Visit(ExtendedName* node);
|
|
||||||
|
|
||||||
virtual void Visit(AnyIdentifier* node); // std::string
|
virtual void Visit(AnyIdentifier* node); // std::string
|
||||||
|
|
||||||
virtual void Visit(FloatNumberLiteral* node);
|
virtual void Visit(FloatNumberLiteral* node);
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit ca9eac9857bb2e8276408fe4c0460d171485c569
|
Subproject commit 3ffcfa276c80724af4910c8c310b1945c995dc4b
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
// for clangd
|
// for clangd
|
||||||
#include "../include/build_visitor.hpp"
|
#include "../include/build_visitor.hpp"
|
||||||
#include "../include/parse_token_types.hpp"
|
#include "../include/parse_token_types.hpp"
|
||||||
|
#include "../include/error_handling.hpp"
|
||||||
|
|
||||||
namespace interpreter {
|
namespace interpreter {
|
||||||
|
|
||||||
|
|
@ -178,7 +180,7 @@ void BuildVisitor::Visit(FunctionDeclaration* node) {
|
||||||
node->is_in_interface = false;
|
node->is_in_interface = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
node->name.name = parse_node.ChildByFieldName("name").GetValue();
|
node->name = parse_node.ChildByFieldName("name").GetValue();
|
||||||
|
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
size_t child_count = parse_node.NamedChildCount();
|
||||||
|
|
||||||
|
|
@ -371,21 +373,14 @@ void BuildVisitor::Visit(FunctionDefinition* node) {
|
||||||
|
|
||||||
auto parse_node = current_node_;
|
auto parse_node = current_node_;
|
||||||
|
|
||||||
node->name.name = parse_node.ChildByFieldName("name").GetValue();
|
node->name = parse_node.ChildByFieldName("name").GetValue();
|
||||||
|
|
||||||
if (parse_node.NthChild(0).GetValue() == "(") {
|
|
||||||
node->modifier = utils::FunctionTypeModifier::Operator;
|
|
||||||
} else {
|
|
||||||
node->modifier = utils::FunctionTypeModifier::Function;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
size_t child_count = parse_node.NamedChildCount();
|
||||||
|
|
||||||
if (child_count > 1) {
|
if (child_count > 1) {
|
||||||
node->arguments.resize(child_count - 1);
|
node->arguments.resize(child_count - 1);
|
||||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
node->arguments[i] = parse_node.NthNamedChild(i + 1).GetValue();
|
||||||
Visit(&node->arguments[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -446,10 +441,7 @@ void BuildVisitor::Visit(TypeConstructorPatternParameter* node) {
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
size_t child_count = parse_node.NamedChildCount();
|
||||||
|
|
||||||
if (child_count > 1) {
|
if (child_count > 1) {
|
||||||
current_node_ = parse_node.ChildByFieldName("name"),
|
node->name.value() = parse_node.ChildByFieldName("name").GetValue();
|
||||||
|
|
||||||
node->name.emplace();
|
|
||||||
Visit(&node->name.value());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("value"),
|
current_node_ = parse_node.ChildByFieldName("value"),
|
||||||
|
|
@ -489,9 +481,9 @@ void BuildVisitor::Visit(Pattern& node) { // <-> ScopedPattern
|
||||||
|
|
||||||
std::string current_node_type = current_node_.GetType();
|
std::string current_node_type = current_node_.GetType();
|
||||||
|
|
||||||
if (current_node_type == parser::tokens::ExtendedName) { // optimize ??
|
if (current_node_type == parser::tokens::NameIdentifier) { // optimize ??
|
||||||
node = std::make_unique<ExtendedName>();
|
node = std::make_unique<NameIdentifier>(current_node_.GetValue());
|
||||||
Visit(std::get<std::unique_ptr<ExtendedName>>(node).get());
|
// Visit(std::get<std::unique_ptr<NameIdentifier>>(node).get());
|
||||||
} else if (current_node_type == parser::tokens::Literal) {
|
} else if (current_node_type == parser::tokens::Literal) {
|
||||||
node = std::make_unique<Literal>();
|
node = std::make_unique<Literal>();
|
||||||
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||||
|
|
@ -807,9 +799,6 @@ void BuildVisitor::Visit(Expression& node) {
|
||||||
} else if (current_node_type == parser::tokens::PrefixedExpression) {
|
} else if (current_node_type == parser::tokens::PrefixedExpression) {
|
||||||
node = std::make_unique<PrefixedExpression>();
|
node = std::make_unique<PrefixedExpression>();
|
||||||
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node));
|
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node));
|
||||||
} else if (current_node_type == parser::tokens::UnaryOperatorExpression) {
|
|
||||||
node = std::make_unique<UnaryOperatorExpression>();
|
|
||||||
Visit(std::get<std::unique_ptr<UnaryOperatorExpression>>(node).get());
|
|
||||||
} else if (current_node_type == parser::tokens::SubExpression) {
|
} else if (current_node_type == parser::tokens::SubExpression) {
|
||||||
node = std::make_unique<SubExpression>();
|
node = std::make_unique<SubExpression>();
|
||||||
Visit(*std::get<std::unique_ptr<SubExpression>>(node));
|
Visit(*std::get<std::unique_ptr<SubExpression>>(node));
|
||||||
|
|
@ -872,28 +861,29 @@ void BuildVisitor::Visit(BinaryOperatorExpression* node) {
|
||||||
|
|
||||||
node->operator_name = parse_node.ChildByFieldName("operator_name").GetValue();
|
node->operator_name = parse_node.ChildByFieldName("operator_name").GetValue();
|
||||||
|
|
||||||
{ // remove operator prescendence markers
|
{ // remove operator precedence markers
|
||||||
size_t operator_size = 0;
|
size_t operator_size = 0;
|
||||||
for (; operator_size < node->operator_name.size() && node->operator_name[operator_size] != '.'; ++operator_size) {}
|
for (; operator_size < node->operator_name.size() && node->operator_name[operator_size] != '.'; ++operator_size) {}
|
||||||
|
|
||||||
|
node->precedence = utils::MaxOperatorPrecedence - (node->operator_name.size() - operator_size);
|
||||||
|
|
||||||
node->operator_name = node->operator_name.substr(0, operator_size);
|
node->operator_name = node->operator_name.substr(0, operator_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("right_expression");
|
current_node_ = parse_node.ChildByFieldName("right_expression");
|
||||||
Visit(node->right_expression);
|
Visit(node->right_expression);
|
||||||
|
|
||||||
current_node_ = parse_node;
|
// ??
|
||||||
}
|
if (std::holds_alternative<std::unique_ptr<BinaryOperatorExpression>>(node->left_expression)
|
||||||
|
&& std::get<std::unique_ptr<BinaryOperatorExpression>>(node->left_expression)->precedence >= node->precedence) {
|
||||||
|
error_handling::HandleParsingError("Operators can't be chained", node->base.start_position, node->base.end_position);
|
||||||
|
}
|
||||||
|
|
||||||
void BuildVisitor::Visit(UnaryOperatorExpression* node) {
|
// ??
|
||||||
SetPosition(node->base, current_node_);
|
if (std::holds_alternative<std::unique_ptr<BinaryOperatorExpression>>(node->right_expression)
|
||||||
|
&& std::get<std::unique_ptr<BinaryOperatorExpression>>(node->right_expression)->precedence >= node->precedence) {
|
||||||
auto parse_node = current_node_;
|
error_handling::HandleParsingError("Operators can't be chained", node->base.start_position, node->base.end_position);
|
||||||
|
}
|
||||||
node->operator_name = parse_node.ChildByFieldName("operator_name").GetValue();
|
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("expression");
|
|
||||||
Visit(node->expression);
|
|
||||||
|
|
||||||
current_node_ = parse_node;
|
current_node_ = parse_node;
|
||||||
}
|
}
|
||||||
|
|
@ -909,10 +899,10 @@ void BuildVisitor::Visit(ReferenceExpression* node) {
|
||||||
node->references.resize(child_count - 1);
|
node->references.resize(child_count - 1);
|
||||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||||
std::string reference = parse_node.NthChild(i).GetValue();
|
std::string reference = parse_node.NthChild(i).GetValue();
|
||||||
if (reference == "~") {
|
if (reference == "^") {
|
||||||
node->references[i] = utils::ReferenceModifier::Reference;
|
node->references[i] = utils::ReferenceModifier::Reference;
|
||||||
} else if (reference == "@") {
|
} else if (reference == "~") {
|
||||||
node->references[i] = utils::ReferenceModifier::UniqueReference;
|
node->references[i] = utils::ReferenceModifier::Dereference;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -964,8 +954,7 @@ void BuildVisitor::Visit(FunctionCallExpression* node) {
|
||||||
// no prefix
|
// no prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("name");
|
node->name = parse_node.ChildByFieldName("name").GetValue();
|
||||||
Visit(&node->name);
|
|
||||||
++excluded_child_count;
|
++excluded_child_count;
|
||||||
|
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
size_t child_count = parse_node.NamedChildCount();
|
||||||
|
|
@ -1046,9 +1035,7 @@ void BuildVisitor::Visit(TypeConstructorParameter* node) {
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
size_t child_count = parse_node.NamedChildCount();
|
||||||
|
|
||||||
if (child_count > 1) {
|
if (child_count > 1) {
|
||||||
current_node_ = parse_node.ChildByFieldName("name");
|
node->name = parse_node.ChildByFieldName("name").GetValue();
|
||||||
node->name.emplace();
|
|
||||||
Visit(&node->name.value());
|
|
||||||
|
|
||||||
std::string assignment_modifier = current_node_.NextSibling().GetValue();
|
std::string assignment_modifier = current_node_.NextSibling().GetValue();
|
||||||
if (assignment_modifier == "=") {
|
if (assignment_modifier == "=") {
|
||||||
|
|
@ -1109,7 +1096,7 @@ void BuildVisitor::Visit(LambdaFunction* node) {
|
||||||
Visit(node->parameters.back().get());
|
Visit(node->parameters.back().get());
|
||||||
} else {
|
} else {
|
||||||
node->arguments.emplace_back();
|
node->arguments.emplace_back();
|
||||||
Visit(&node->arguments.back());
|
node->arguments.back() = current_node_.GetValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1179,8 +1166,7 @@ void BuildVisitor::Visit(NameExpression* node) {
|
||||||
|
|
||||||
node->names.resize(child_count);
|
node->names.resize(child_count);
|
||||||
for (size_t i = 0; i < child_count; ++i) {
|
for (size_t i = 0; i < child_count; ++i) {
|
||||||
current_node_ = parse_node.NthNamedChild(i);
|
node->names[i] = parse_node.NthNamedChild(i).GetValue();
|
||||||
Visit(&node->names[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current_node_ = parse_node;
|
current_node_ = parse_node;
|
||||||
|
|
@ -1301,9 +1287,8 @@ void BuildVisitor::Visit(TupleType* node) {
|
||||||
while (current_node_n < parse_node.NamedChildCount()) {
|
while (current_node_n < parse_node.NamedChildCount()) {
|
||||||
node->entities.emplace_back();
|
node->entities.emplace_back();
|
||||||
|
|
||||||
if (current_node_.GetType() == parser::tokens::ExtendedName) {
|
if (current_node_.GetType() == parser::tokens::NameIdentifier) {
|
||||||
node->entities.back().first.emplace();
|
node->entities.back().first = current_node_.GetValue();
|
||||||
Visit(&node->entities.back().first.value());
|
|
||||||
|
|
||||||
++current_node_n;
|
++current_node_n;
|
||||||
current_node_ = parse_node.NthNamedChild(current_node_n);
|
current_node_ = parse_node.NthNamedChild(current_node_n);
|
||||||
|
|
@ -1432,7 +1417,7 @@ void BuildVisitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
node->references.resize(child_count - 1);
|
node->references.resize(child_count - 1);
|
||||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||||
std::string reference = parse_node.NthChild(i).GetValue();
|
std::string reference = parse_node.NthChild(i).GetValue();
|
||||||
if (reference == "~") {
|
if (reference == "^") {
|
||||||
node->references[i] = utils::ReferenceModifier::Reference;
|
node->references[i] = utils::ReferenceModifier::Reference;
|
||||||
} else if (reference == "@") {
|
} else if (reference == "@") {
|
||||||
node->references[i] = utils::ReferenceModifier::UniqueReference;
|
node->references[i] = utils::ReferenceModifier::UniqueReference;
|
||||||
|
|
@ -1498,12 +1483,6 @@ void BuildVisitor::Visit(ParametrizedType* node) {
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
void BuildVisitor::Visit(ExtendedName* node) {
|
|
||||||
SetPosition(node->base, current_node_);
|
|
||||||
|
|
||||||
node->name = current_node_.GetValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
// void BuildVisitor::Visit(AnyIdentifier* node) { // std::string
|
// void BuildVisitor::Visit(AnyIdentifier* node) { // std::string
|
||||||
// *node = current_node_.GetValue();
|
// *node = current_node_.GetValue();
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -337,27 +337,6 @@ void ExecuteVisitor::Visit(BinaryOperatorExpression* node) {
|
||||||
context_manager_.ExitContext();
|
context_manager_.ExitContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: methods??
|
|
||||||
void ExecuteVisitor::Visit(UnaryOperatorExpression* node) {
|
|
||||||
context_manager_.EnterContext();
|
|
||||||
|
|
||||||
auto maybe_function_definition = namespace_visitor_.GetGlobalInfo()->GetFunctionInfo(node->function_id_).definition;
|
|
||||||
|
|
||||||
if (maybe_function_definition.has_value()) {
|
|
||||||
Visitor::Visit(node->expression);
|
|
||||||
// TODO: custom argument value types, references, etc.
|
|
||||||
current_value_ = context_manager_.ToModifiedValue(current_value_, utils::ValueType::Const);
|
|
||||||
context_manager_.DefineVariable(maybe_function_definition.value().argument_names[0], current_value_);
|
|
||||||
|
|
||||||
Visit(maybe_function_definition.value().node);
|
|
||||||
} else {
|
|
||||||
// TODO: builtin operators, etc. (imports?)
|
|
||||||
error_handling::HandleRuntimeError("Unary operator definition not found", node->base);
|
|
||||||
}
|
|
||||||
|
|
||||||
context_manager_.ExitContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExecuteVisitor::Visit(ReferenceExpression* node) {
|
void ExecuteVisitor::Visit(ReferenceExpression* node) {
|
||||||
// TODO: check, that there is no references to "Tmp"??
|
// TODO: check, that there is no references to "Tmp"??
|
||||||
Visit(node->expression.get());
|
Visit(node->expression.get());
|
||||||
|
|
@ -495,7 +474,7 @@ void ExecuteVisitor::Visit(TypeConstructor* node) {
|
||||||
Visitor::Visit(parameter.value);
|
Visitor::Visit(parameter.value);
|
||||||
// TODO: copy/move parameters
|
// TODO: copy/move parameters
|
||||||
fields.push_back(
|
fields.push_back(
|
||||||
{ parameter.name.has_value() ? std::optional<std::string>(parameter.name.value().name) : std::nullopt,
|
{ parameter.name.has_value() ? std::optional<std::string>(parameter.name.value()) : std::nullopt,
|
||||||
current_value_ });
|
current_value_ });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -532,7 +511,7 @@ void ExecuteVisitor::Visit(NameExpression* node) { // TODO: check
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<utils::IdType> maybe_variable_value =
|
std::optional<utils::IdType> maybe_variable_value =
|
||||||
context_manager_.GetVariableInfo(node->names[0].name);
|
context_manager_.GetVariableInfo(node->names[0]);
|
||||||
|
|
||||||
if (!maybe_variable_value.has_value()) {
|
if (!maybe_variable_value.has_value()) {
|
||||||
error_handling::HandleRuntimeError("Variable not found", node->base);
|
error_handling::HandleRuntimeError("Variable not found", node->base);
|
||||||
|
|
@ -544,9 +523,9 @@ void ExecuteVisitor::Visit(NameExpression* node) { // TODO: check
|
||||||
utils::ValueType variable_value_type = context_manager_.GetValueType(current_value_);
|
utils::ValueType variable_value_type = context_manager_.GetValueType(current_value_);
|
||||||
|
|
||||||
for (size_t i = 1; i < node->names.size(); ++i) {
|
for (size_t i = 1; i < node->names.size(); ++i) {
|
||||||
std::optional<utils::IdType> maybe_field_value = context_manager_.GetAnyValue(current_value_)->GetFieldValue(node->names[i].name); // TODO
|
std::optional<utils::IdType> maybe_field_value = context_manager_.GetAnyValue(current_value_)->GetFieldValue(node->names[i]); // TODO
|
||||||
if (!maybe_field_value.has_value()) {
|
if (!maybe_field_value.has_value()) {
|
||||||
error_handling::HandleRuntimeError("Variable field not found", node->names[i].base);
|
error_handling::HandleRuntimeError("Variable field not found", node->base);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_value_ = maybe_field_value.value();
|
current_value_ = maybe_field_value.value();
|
||||||
|
|
@ -749,7 +728,7 @@ void ExecuteVisitor::CheckPattern(Pattern& node, const BaseNode& base_node) {
|
||||||
switch (node.index()) {
|
switch (node.index()) {
|
||||||
case 0:
|
case 0:
|
||||||
value = context_manager_.ToModifiedValue(value, utils::ValueType::Const); // ??
|
value = context_manager_.ToModifiedValue(value, utils::ValueType::Const); // ??
|
||||||
if (!context_manager_.DefineVariable(std::get<std::unique_ptr<ExtendedName>>(node)->name,
|
if (!context_manager_.DefineVariable(*std::get<std::unique_ptr<NameIdentifier>>(node),
|
||||||
value)) {
|
value)) {
|
||||||
error_handling::HandleRuntimeError("Can't redifine variable", base_node);
|
error_handling::HandleRuntimeError("Can't redifine variable", base_node);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ void FindSymbolsVisitor::Visit(FunctionDeclaration* node) {
|
||||||
if (was_in_statement) {
|
if (was_in_statement) {
|
||||||
current_info_ = std::move(info);
|
current_info_ = std::move(info);
|
||||||
} else {
|
} else {
|
||||||
node->function_id_ = namespace_visitor_.AddFunctionDeclaration(node->name.name, std::move(info));
|
node->function_id_ = namespace_visitor_.AddFunctionDeclaration(node->name, std::move(info));
|
||||||
is_in_statement_ = false;
|
is_in_statement_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -86,12 +86,12 @@ void FindSymbolsVisitor::Visit(FunctionDefinitionStatement* node) {
|
||||||
|
|
||||||
info.argument_names.resize(definition->arguments.size());
|
info.argument_names.resize(definition->arguments.size());
|
||||||
for (size_t i = 0; i < definition->arguments.size(); ++i) {
|
for (size_t i = 0; i < definition->arguments.size(); ++i) {
|
||||||
info.argument_names[i] = definition->arguments[i].name;
|
info.argument_names[i] = definition->arguments[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
info.node = node;
|
info.node = node;
|
||||||
|
|
||||||
node->function_id_ = namespace_visitor_.AddFunctionDefinition(definition->name.name, std::move(info));
|
node->function_id_ = namespace_visitor_.AddFunctionDefinition(definition->name, std::move(info));
|
||||||
|
|
||||||
is_in_statement_ = false;
|
is_in_statement_ = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,15 +188,6 @@ void PrintVisitor::Visit(PartitionStatement* node) {
|
||||||
|
|
||||||
void PrintVisitor::Visit(FunctionDefinition* node) {
|
void PrintVisitor::Visit(FunctionDefinition* node) {
|
||||||
out_ << "[FunctionDefinition ";
|
out_ << "[FunctionDefinition ";
|
||||||
switch (node->modifier) {
|
|
||||||
case utils::FunctionTypeModifier::Operator:
|
|
||||||
out_ << "operator";
|
|
||||||
break;
|
|
||||||
case utils::FunctionTypeModifier::Function:
|
|
||||||
out_ << "function";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
out_ << ' ';
|
|
||||||
Visit(&node->name);
|
Visit(&node->name);
|
||||||
out_ << "]";
|
out_ << "]";
|
||||||
if (!node->arguments.empty()) {
|
if (!node->arguments.empty()) {
|
||||||
|
|
@ -389,24 +380,19 @@ void PrintVisitor::Visit(BinaryOperatorExpression* node) {
|
||||||
out_ << ')';
|
out_ << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintVisitor::Visit(UnaryOperatorExpression* node) {
|
|
||||||
out_ << "[UnaryOperator ";
|
|
||||||
Visit(&node->operator_name);
|
|
||||||
out_ << "] (";
|
|
||||||
Visitor::Visit(node->expression);
|
|
||||||
out_ << ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintVisitor::Visit(ReferenceExpression* node) {
|
void PrintVisitor::Visit(ReferenceExpression* node) {
|
||||||
out_ << "[ReferenceExpression ";
|
out_ << "[ReferenceExpression ";
|
||||||
for (auto& reference : node->references) {
|
for (auto& reference : node->references) {
|
||||||
switch (reference) {
|
switch (reference) {
|
||||||
case utils::ReferenceModifier::Reference:
|
case utils::ReferenceModifier::Reference:
|
||||||
out_ << '~';
|
out_ << '^';
|
||||||
break;
|
break;
|
||||||
case utils::ReferenceModifier::UniqueReference:
|
case utils::ReferenceModifier::UniqueReference:
|
||||||
out_ << '@';
|
out_ << '@';
|
||||||
break;
|
break;
|
||||||
|
case utils::ReferenceModifier::Dereference:
|
||||||
|
out_ << '~';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out_ << "] (";
|
out_ << "] (";
|
||||||
|
|
@ -676,12 +662,15 @@ void PrintVisitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
out_ << "[ExtendedScopedAnyType ";
|
out_ << "[ExtendedScopedAnyType ";
|
||||||
for (auto& reference : node->references) {
|
for (auto& reference : node->references) {
|
||||||
switch (reference) {
|
switch (reference) {
|
||||||
case utils::ReferenceModifier::Reference:
|
case utils::ReferenceModifier::Reference:
|
||||||
out_ << '~';
|
out_ << '^';
|
||||||
break;
|
break;
|
||||||
case utils::ReferenceModifier::UniqueReference:
|
case utils::ReferenceModifier::UniqueReference:
|
||||||
out_ << '@';
|
out_ << '@';
|
||||||
break;
|
break;
|
||||||
|
case utils::ReferenceModifier::Dereference:
|
||||||
|
out_ << '~';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out_ << "] (";
|
out_ << "] (";
|
||||||
|
|
@ -715,10 +704,6 @@ void PrintVisitor::Visit(ParametrizedType* node) {
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
void PrintVisitor::Visit(ExtendedName* node) {
|
|
||||||
out_ << "[ExtendedName " << node->name << "] ";
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintVisitor::Visit(std::string* node) { // std::string
|
void PrintVisitor::Visit(std::string* node) { // std::string
|
||||||
out_ << "[Identifier " << *node << "] ";
|
out_ << "[Identifier " << *node << "] ";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
||||||
for (size_t i = 0; i < node->definition->arguments.size(); ++i) {
|
for (size_t i = 0; i < node->definition->arguments.size(); ++i) {
|
||||||
Visitor::Visit(*declaration.argument_types[i]);
|
Visitor::Visit(*declaration.argument_types[i]);
|
||||||
current_type_ = context_manager_.ToModifiedValue(current_type_, utils::ValueType::Const); // TODO: var function arguments??
|
current_type_ = context_manager_.ToModifiedValue(current_type_, utils::ValueType::Const); // TODO: var function arguments??
|
||||||
if (!context_manager_.DefineVariable(node->definition->arguments[i].name, current_type_)) { // TODO: watch to reference
|
if (!context_manager_.DefineVariable(node->definition->arguments[i], current_type_)) { // TODO: watch to reference
|
||||||
error_handling::HandleTypecheckError("Can't define function argument variable: name redefinition", node->base);
|
error_handling::HandleTypecheckError("Can't define function argument variable: name redefinition", node->base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -316,7 +316,7 @@ void TypeCheckVisitor::Visit(TypeConstructorPattern* node) { // TODO: match name
|
||||||
for (size_t i = 0; i < node->parameters.size(); ++i) {
|
for (size_t i = 0; i < node->parameters.size(); ++i) {
|
||||||
if (node->parameters[i].name.has_value()) { // TODO: needed??
|
if (node->parameters[i].name.has_value()) { // TODO: needed??
|
||||||
if (!constructor_fields->entities[i].first.has_value()
|
if (!constructor_fields->entities[i].first.has_value()
|
||||||
|| constructor_fields->entities[i].first.value().name != node->parameters[i].name.value().name) {
|
|| constructor_fields->entities[i].first.value() != node->parameters[i].name.value()) {
|
||||||
error_handling::HandleTypecheckError("Type constructor pattern: name of parameter and name in constructor don't match each other", node->base);
|
error_handling::HandleTypecheckError("Type constructor pattern: name of parameter and name in constructor don't match each other", node->base);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -690,53 +690,13 @@ void TypeCheckVisitor::Visit(BinaryOperatorExpression* node) {
|
||||||
node->base.type_ = current_type_;
|
node->base.type_ = current_type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: can be method ??
|
|
||||||
void TypeCheckVisitor::Visit(UnaryOperatorExpression* node) {
|
|
||||||
// TODO: Check, that type is not abstract ??
|
|
||||||
auto maybe_operator_id = namespace_visitor_.FindFunction({}, node->operator_name);
|
|
||||||
|
|
||||||
if (!maybe_operator_id.has_value()) {
|
|
||||||
error_handling::HandleTypecheckError("Operator not found", node->base);
|
|
||||||
}
|
|
||||||
|
|
||||||
const info::definition::Function& operator_info = namespace_visitor_.GetGlobalInfo()->GetFunctionInfo(maybe_operator_id.value());
|
|
||||||
|
|
||||||
if (!operator_info.declaration.has_value()) {
|
|
||||||
error_handling::HandleTypecheckError("Operator declaration not found", node->base);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!operator_info.definition.has_value()) { // TODO: builtin, etc.
|
|
||||||
error_handling::HandleTypecheckError("Operator definition not found", node->base);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (operator_info.argument_count != 2) { // 1 + return type
|
|
||||||
error_handling::HandleTypecheckError("Operator wrong argument count", node->base);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (operator_info.declaration->parameters.size() > 0) {
|
|
||||||
error_handling::HandleTypecheckError("Operator with parameters", node->base);
|
|
||||||
}
|
|
||||||
|
|
||||||
Visitor::Visit(*operator_info.declaration.value().argument_types[0]);
|
|
||||||
utils::IdType expression_type = current_type_;
|
|
||||||
|
|
||||||
Visitor::Visit(node->expression);
|
|
||||||
if (!context_manager_.AddValueRequirement(current_type_, expression_type)) {
|
|
||||||
error_handling::HandleTypecheckError("Operator expression has wrong type", node->base);
|
|
||||||
}
|
|
||||||
|
|
||||||
node->function_id_ = maybe_operator_id.value(); // IMPORTANT
|
|
||||||
|
|
||||||
Visitor::Visit(*operator_info.declaration.value().argument_types.back());
|
|
||||||
|
|
||||||
node->base.type_ = current_type_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TypeCheckVisitor::Visit(ReferenceExpression* node) {
|
void TypeCheckVisitor::Visit(ReferenceExpression* node) {
|
||||||
Visit(node->expression.get());
|
Visit(node->expression.get());
|
||||||
|
|
||||||
current_type_ = context_manager_.AddValue(
|
current_type_ = context_manager_.AddValue(
|
||||||
info::type::ReferenceToType(node->references, current_type_, context_manager_.GetValueManager()),
|
info::type::ReferenceToType(node->references,
|
||||||
|
current_type_,
|
||||||
|
context_manager_.GetValueManager()),
|
||||||
context_manager_.GetValueType(current_type_)); // ??
|
context_manager_.GetValueType(current_type_)); // ??
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -772,7 +732,7 @@ void TypeCheckVisitor::Visit(FunctionCallExpression* node) {
|
||||||
std::unordered_map<std::string, utils::IdType> context;
|
std::unordered_map<std::string, utils::IdType> context;
|
||||||
|
|
||||||
// guaranteed, that name.size() > 0
|
// guaranteed, that name.size() > 0
|
||||||
if (node->name.name[0] == '_') { // TODO: manage pointers to function
|
if (node->name[0] == '_') { // TODO: manage pointers to function
|
||||||
error_handling::HandleInternalError("Builtin functions/methods weren't implemented yet",
|
error_handling::HandleInternalError("Builtin functions/methods weren't implemented yet",
|
||||||
"TypeCheckVisitor.FunctionCallExpresssion");
|
"TypeCheckVisitor.FunctionCallExpresssion");
|
||||||
}
|
}
|
||||||
|
|
@ -797,7 +757,7 @@ void TypeCheckVisitor::Visit(FunctionCallExpression* node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: better decision ??
|
// TODO: better decision ??
|
||||||
std::optional<utils::IdType> maybe_const_function_id = maybe_type_info.value()->parent_namespace->const_namespaces.at(maybe_type_info.value()->type.type).functions[node->name.name];
|
std::optional<utils::IdType> maybe_const_function_id = maybe_type_info.value()->parent_namespace->const_namespaces.at(maybe_type_info.value()->type.type).functions[node->name];
|
||||||
|
|
||||||
utils::ValueType expression_value_type = context_manager_.GetValueType(current_type_);
|
utils::ValueType expression_value_type = context_manager_.GetValueType(current_type_);
|
||||||
|
|
||||||
|
|
@ -808,7 +768,7 @@ void TypeCheckVisitor::Visit(FunctionCallExpression* node) {
|
||||||
|
|
||||||
if (expression_value_type == utils::ValueType::Var || expression_value_type == utils::ValueType::Tmp) {
|
if (expression_value_type == utils::ValueType::Var || expression_value_type == utils::ValueType::Tmp) {
|
||||||
// TODO: choose expression value types
|
// TODO: choose expression value types
|
||||||
maybe_function_id = maybe_type_info.value()->parent_namespace->var_namespaces.at(maybe_type_info.value()->type.type).functions[node->name.name];
|
maybe_function_id = maybe_type_info.value()->parent_namespace->var_namespaces.at(maybe_type_info.value()->type.type).functions[node->name];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maybe_const_function_id.has_value() && maybe_function_id.has_value()) { // TODO: handle on link_types stage
|
if (maybe_const_function_id.has_value() && maybe_function_id.has_value()) { // TODO: handle on link_types stage
|
||||||
|
|
@ -833,14 +793,14 @@ void TypeCheckVisitor::Visit(FunctionCallExpression* node) {
|
||||||
}
|
}
|
||||||
path.push_back(type_expression.type.type);
|
path.push_back(type_expression.type.type);
|
||||||
|
|
||||||
maybe_function_id = namespace_visitor_.FindFunction(path, node->name.name);
|
maybe_function_id = namespace_visitor_.FindFunction(path, node->name);
|
||||||
|
|
||||||
CollectTypeExpressionContext(*std::get<std::unique_ptr<TypeExpression>>(node->prefix.value()), context);
|
CollectTypeExpressionContext(*std::get<std::unique_ptr<TypeExpression>>(node->prefix.value()), context);
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
maybe_function_id = namespace_visitor_.FindFunction(std::nullopt, node->name.name);
|
maybe_function_id = namespace_visitor_.FindFunction(std::nullopt, node->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!maybe_function_id.has_value()) {
|
if (!maybe_function_id.has_value()) {
|
||||||
|
|
@ -979,7 +939,7 @@ void TypeCheckVisitor::Visit(TypeConstructor* node) {
|
||||||
// TODO: remove variable on move
|
// TODO: remove variable on move
|
||||||
if (node->parameters[i].name.has_value()) {
|
if (node->parameters[i].name.has_value()) {
|
||||||
if (!constructor_fields->entities[i].first.has_value()
|
if (!constructor_fields->entities[i].first.has_value()
|
||||||
|| constructor_fields->entities[i].first.value().name != node->parameters[i].name.value().name) {
|
|| constructor_fields->entities[i].first.value() != node->parameters[i].name.value()) {
|
||||||
error_handling::HandleTypecheckError("Type constructor: name of parameter and name in constructor don't match each other", node->base);
|
error_handling::HandleTypecheckError("Type constructor: name of parameter and name in constructor don't match each other", node->base);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1060,10 +1020,10 @@ void TypeCheckVisitor::Visit(NameExpression* node) {
|
||||||
error_handling::HandleInternalError("Name expression with zero names", "TypeCheckVisitor.NameExpression");
|
error_handling::HandleInternalError("Name expression with zero names", "TypeCheckVisitor.NameExpression");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto maybe_variable_type = context_manager_.GetVariableInfo(node->names[0].name);
|
auto maybe_variable_type = context_manager_.GetVariableInfo(node->names[0]);
|
||||||
|
|
||||||
if (!maybe_variable_type.has_value()) {
|
if (!maybe_variable_type.has_value()) {
|
||||||
error_handling::HandleTypecheckError("Variable not found", node->names[0].base);
|
error_handling::HandleTypecheckError("Variable not found", node->base);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_type_ = maybe_variable_type.value();
|
current_type_ = maybe_variable_type.value();
|
||||||
|
|
@ -1072,9 +1032,9 @@ void TypeCheckVisitor::Visit(NameExpression* node) {
|
||||||
utils::ValueType variable_value_type = context_manager_.GetValueType(current_type_);
|
utils::ValueType variable_value_type = context_manager_.GetValueType(current_type_);
|
||||||
|
|
||||||
for (size_t i = 1; i < node->names.size(); ++i) {
|
for (size_t i = 1; i < node->names.size(); ++i) {
|
||||||
std::optional<utils::IdType> maybe_type_value = context_manager_.GetAnyValue(current_type_)->GetFieldType(node->names[i].name);
|
std::optional<utils::IdType> maybe_type_value = context_manager_.GetAnyValue(current_type_)->GetFieldType(node->names[i]);
|
||||||
if (!maybe_type_value.has_value()) {
|
if (!maybe_type_value.has_value()) {
|
||||||
error_handling::HandleTypecheckError("Variable field not found", node->names[i].base);
|
error_handling::HandleTypecheckError("Variable field not found", node->base);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_type_ = maybe_type_value.value();
|
current_type_ = maybe_type_value.value();
|
||||||
|
|
@ -1240,7 +1200,7 @@ void TypeCheckVisitor::Visit(TupleType* node) {
|
||||||
for (auto& entity : node->entities) {
|
for (auto& entity : node->entities) {
|
||||||
Visit(entity.second.get());
|
Visit(entity.second.get());
|
||||||
if (entity.first.has_value()) {
|
if (entity.first.has_value()) {
|
||||||
fields.push_back({entity.first.value().name, current_type_});
|
fields.push_back({entity.first.value(), current_type_});
|
||||||
} else {
|
} else {
|
||||||
fields.push_back({std::nullopt, current_type_});
|
fields.push_back({std::nullopt, current_type_});
|
||||||
}
|
}
|
||||||
|
|
@ -1437,7 +1397,7 @@ void TypeCheckVisitor::CheckPattern(Pattern& node, const BaseNode& base_node) {
|
||||||
switch (node.index()) {
|
switch (node.index()) {
|
||||||
case 0:
|
case 0:
|
||||||
value_type = context_manager_.ToModifiedValue(value_type, utils::ValueType::Const); // ??
|
value_type = context_manager_.ToModifiedValue(value_type, utils::ValueType::Const); // ??
|
||||||
if (!context_manager_.DefineVariable(std::get<std::unique_ptr<ExtendedName>>(node)->name,
|
if (!context_manager_.DefineVariable(*std::get<std::unique_ptr<NameIdentifier>>(node),
|
||||||
value_type)) {
|
value_type)) {
|
||||||
error_handling::HandleTypecheckError("Can't redifine variable", base_node);
|
error_handling::HandleTypecheckError("Can't redifine variable", base_node);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -261,15 +261,6 @@ void TypedPrintVisitor::Visit(FunctionDefinition* node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
out_ << ") ";
|
out_ << ") ";
|
||||||
switch (node->modifier) {
|
|
||||||
case utils::FunctionTypeModifier::Operator:
|
|
||||||
out_ << "operator";
|
|
||||||
break;
|
|
||||||
case utils::FunctionTypeModifier::Function:
|
|
||||||
out_ << "function";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
out_ << ' ';
|
|
||||||
Visit(&node->name);
|
Visit(&node->name);
|
||||||
out_ << "]";
|
out_ << "]";
|
||||||
if (!node->arguments.empty()) {
|
if (!node->arguments.empty()) {
|
||||||
|
|
@ -546,20 +537,6 @@ void TypedPrintVisitor::Visit(BinaryOperatorExpression* node) {
|
||||||
out_ << ')';
|
out_ << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
void TypedPrintVisitor::Visit(UnaryOperatorExpression* node) {
|
|
||||||
out_ << "[UnaryOperator : (";
|
|
||||||
|
|
||||||
if (node->base.type_.has_value()) {
|
|
||||||
out_ << context_manager_.GetAnyValue(node->base.type_.value())->GetTypeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
out_ << ") ";
|
|
||||||
Visit(&node->operator_name);
|
|
||||||
out_ << "] (";
|
|
||||||
Visitor::Visit(node->expression);
|
|
||||||
out_ << ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
void TypedPrintVisitor::Visit(ReferenceExpression* node) {
|
void TypedPrintVisitor::Visit(ReferenceExpression* node) {
|
||||||
out_ << "[ReferenceExpression : (";
|
out_ << "[ReferenceExpression : (";
|
||||||
|
|
||||||
|
|
@ -570,12 +547,15 @@ void TypedPrintVisitor::Visit(ReferenceExpression* node) {
|
||||||
out_ << ") ";
|
out_ << ") ";
|
||||||
for (auto& reference : node->references) {
|
for (auto& reference : node->references) {
|
||||||
switch (reference) {
|
switch (reference) {
|
||||||
case utils::ReferenceModifier::Reference:
|
case utils::ReferenceModifier::Reference:
|
||||||
out_ << '~';
|
out_ << '^';
|
||||||
break;
|
break;
|
||||||
case utils::ReferenceModifier::UniqueReference:
|
case utils::ReferenceModifier::UniqueReference:
|
||||||
out_ << '@';
|
out_ << '@';
|
||||||
break;
|
break;
|
||||||
|
case utils::ReferenceModifier::Dereference:
|
||||||
|
out_ << '~';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out_ << "] (";
|
out_ << "] (";
|
||||||
|
|
@ -957,12 +937,15 @@ void TypedPrintVisitor::Visit(ExtendedScopedAnyType* node) {
|
||||||
out_ << ") ";
|
out_ << ") ";
|
||||||
for (auto& reference : node->references) {
|
for (auto& reference : node->references) {
|
||||||
switch (reference) {
|
switch (reference) {
|
||||||
case utils::ReferenceModifier::Reference:
|
case utils::ReferenceModifier::Reference:
|
||||||
out_ << '~';
|
out_ << '^';
|
||||||
break;
|
break;
|
||||||
case utils::ReferenceModifier::UniqueReference:
|
case utils::ReferenceModifier::UniqueReference:
|
||||||
out_ << '@';
|
out_ << '@';
|
||||||
break;
|
break;
|
||||||
|
case utils::ReferenceModifier::Dereference:
|
||||||
|
out_ << '~';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out_ << "] (";
|
out_ << "] (";
|
||||||
|
|
@ -1002,16 +985,6 @@ void TypedPrintVisitor::Visit(ParametrizedType* node) {
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
void TypedPrintVisitor::Visit(ExtendedName* node) {
|
|
||||||
out_ << "[ExtendedName : (";
|
|
||||||
|
|
||||||
if (node->base.type_.has_value()) {
|
|
||||||
out_ << context_manager_.GetAnyValue(node->base.type_.value())->GetTypeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
out_ << ") " << node->name << "] ";
|
|
||||||
}
|
|
||||||
|
|
||||||
void TypedPrintVisitor::Visit(std::string* node) { // std::string
|
void TypedPrintVisitor::Visit(std::string* node) { // std::string
|
||||||
out_ << "[Identifier " << *node << "] ";
|
out_ << "[Identifier " << *node << "] ";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ void Visitor::Visit(SourceStatement& node) {
|
||||||
void Visitor::Visit(Pattern& node) { // <-> ScopedPattern
|
void Visitor::Visit(Pattern& node) { // <-> ScopedPattern
|
||||||
switch (node.index()) {
|
switch (node.index()) {
|
||||||
case 0:
|
case 0:
|
||||||
Visit(std::get<std::unique_ptr<ExtendedName>>(node).get());
|
Visit(std::get<std::unique_ptr<NameIdentifier>>(node).get());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||||
|
|
@ -189,9 +189,6 @@ void Visitor::Visit(Expression& node) {
|
||||||
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node));
|
Visit(*std::get<std::unique_ptr<PrefixedExpression>>(node));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
Visit(std::get<std::unique_ptr<UnaryOperatorExpression>>(node).get());
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
Visit(*std::get<std::unique_ptr<SubExpression>>(node));
|
Visit(*std::get<std::unique_ptr<SubExpression>>(node));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -477,11 +474,6 @@ void Visitor::Visit(BinaryOperatorExpression* node) {
|
||||||
Visit(node->right_expression);
|
Visit(node->right_expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visitor::Visit(UnaryOperatorExpression* node) {
|
|
||||||
Visit(&node->operator_name);
|
|
||||||
Visit(node->expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Visitor::Visit(ReferenceExpression* node) {
|
void Visitor::Visit(ReferenceExpression* node) {
|
||||||
Visit(node->expression.get());
|
Visit(node->expression.get());
|
||||||
}
|
}
|
||||||
|
|
@ -662,8 +654,6 @@ void Visitor::Visit(ParametrizedType* node) {
|
||||||
|
|
||||||
// Identifiers, constants, etc. -----------------
|
// Identifiers, constants, etc. -----------------
|
||||||
|
|
||||||
void Visitor::Visit(ExtendedName* node) {}
|
|
||||||
|
|
||||||
void Visitor::Visit(std::string* node) {} // std::string
|
void Visitor::Visit(std::string* node) {} // std::string
|
||||||
|
|
||||||
void Visitor::Visit(FloatNumberLiteral* node) {}
|
void Visitor::Visit(FloatNumberLiteral* node) {}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
decl print : String -> Unit
|
decl print : String -> Unit
|
||||||
|
decl ( -- ) : Int -> Int -> Int_0
|
||||||
|
|
||||||
decl func : String -> Int
|
decl func : String -> Int
|
||||||
def func : s = {
|
def func : s = {
|
||||||
; print: s
|
; print: s
|
||||||
return 5
|
return 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exec main {
|
||||||
|
for i in 0--10 do func: "abacaba"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue