mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
fixes , modifier enum refacing, type visitor part
This commit is contained in:
parent
b686fe00fb
commit
c4045e292b
9 changed files with 147 additions and 132 deletions
|
|
@ -29,12 +29,12 @@ struct Parameter {
|
|||
};
|
||||
|
||||
struct AbstractType {
|
||||
enum { Basic, Abstract } modifier;
|
||||
utils::AbstractTypeModifier modifier;
|
||||
Parameter type;
|
||||
};
|
||||
|
||||
struct AliasType {
|
||||
enum {Alias, Type, Let} modifier;
|
||||
utils::AliasModifier modifier;
|
||||
std::vector<std::string> parameters;
|
||||
TypeUsage value;
|
||||
interpreter::tokens::AliasDefinitionStatement* node = nullptr;
|
||||
|
|
@ -87,17 +87,17 @@ struct Import {
|
|||
};
|
||||
|
||||
struct Namespace {
|
||||
enum Modifier { Const, Var };
|
||||
|
||||
std::unordered_map<std::string, utils::IdType> types;
|
||||
std::unordered_map<std::string, utils::IdType> functions;
|
||||
std::unordered_map<std::string, utils::IdType> constructors;
|
||||
std::unordered_map<std::string, Namespace> namespaces;
|
||||
std::unordered_map<std::string, Namespace> variable_namespaces;
|
||||
std::unordered_map<std::string, Namespace> var_namespaces;
|
||||
std::unordered_map<std::string, Namespace> const_namespaces;
|
||||
|
||||
Namespace* parent_namespace = nullptr;
|
||||
|
||||
std::optional<Modifier> modifier; // modifier => variable namespace
|
||||
std::optional<utils::IsConstModifier> modifier; // modifier => variable namespace
|
||||
std::string type_name;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public:
|
|||
void AddImport(definition::Import&& import_info, const std::optional<std::string>& name = std::nullopt);
|
||||
|
||||
void AddEnterNamespace(const std::string& name,
|
||||
const std::optional<definition::Namespace::Modifier>& modifier = std::nullopt);
|
||||
std::optional<utils::IsConstModifier> modifier = std::nullopt);
|
||||
|
||||
void EnterNamespace(const std::string& name);
|
||||
|
||||
|
|
@ -41,15 +41,21 @@ public:
|
|||
utils::IdType AddFunctionDefinition(const std::string& name,
|
||||
definition::FunctionDefinition&& function_definition_info);
|
||||
|
||||
utils::IdType AddType(const std::string& type, definition::Type&& type_info);
|
||||
utils::IdType AddType(const std::string& type,
|
||||
definition::Type&& type_info,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
utils::IdType AddAbstractType(const std::string& abstract_type,
|
||||
definition::AbstractType&& abstract_type_info);
|
||||
definition::AbstractType&& abstract_type_info,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
utils::IdType AddTypeclass(const std::string& typeclass, definition::Typeclass&& typeclass_info);
|
||||
utils::IdType AddTypeclass(const std::string& typeclass,
|
||||
definition::Typeclass&& typeclass_info,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
utils::IdType AddConstructor(const std::string& constructor,
|
||||
definition::Constructor&& constructor_info);
|
||||
definition::Constructor&& constructor_info,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
std::optional<definition::Namespace*> FindNamespace(const std::optional<std::vector<std::string>>& path);
|
||||
|
||||
|
|
@ -58,7 +64,8 @@ public:
|
|||
|
||||
std::optional<utils::IdType> FindMethod(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type,
|
||||
const std::string& name);
|
||||
const std::string& name,
|
||||
utils::IsConstModifier modifier);
|
||||
|
||||
std::optional<utils::IdType> FindType(const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type);
|
||||
|
|
@ -92,11 +99,13 @@ public:
|
|||
namespace_stack_({&global_info.global_namespace_}) {}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T> FindSomething(const std::optional<std::vector<std::string>>& path,
|
||||
std::function<std::optional<T>(definition::Namespace*)> search_func);
|
||||
std::optional<T> FindSomething(
|
||||
const std::optional<std::vector<std::string>>& path,
|
||||
std::function<std::optional<T>(definition::Namespace*)> search_func);
|
||||
|
||||
std::optional<definition::Namespace*> FindNamespaceIn(definition::Namespace* current_namespace,
|
||||
const std::vector<std::string>& path);
|
||||
std::optional<definition::Namespace*> FindNamespaceIn(
|
||||
definition::Namespace* current_namespace,
|
||||
const std::vector<std::string>& path);
|
||||
private:
|
||||
std::vector<definition::Namespace*> namespace_stack_;
|
||||
std::vector<std::string> current_path_;
|
||||
|
|
|
|||
|
|
@ -296,8 +296,7 @@ struct NamespaceSources {
|
|||
struct Namespace {
|
||||
BaseNode base;
|
||||
|
||||
enum Modifier { Const, Var };
|
||||
std::optional<Modifier> modifier; // modifier => variable namespace
|
||||
std::optional<utils::IsConstModifier> modifier; // modifier => variable namespace
|
||||
TypeIdentifier type;
|
||||
NamespaceSources scope;
|
||||
|
||||
|
|
@ -318,7 +317,7 @@ struct ImportStatement {
|
|||
struct AliasDefinitionStatement {
|
||||
BaseNode base;
|
||||
|
||||
enum {Alias, Type, Let} modifier;
|
||||
utils::AliasModifier modifier;
|
||||
TypeIdentifier type;
|
||||
std::vector<AbstractTypeIdentifier> parameters;
|
||||
std::unique_ptr<TypeExpression> value;
|
||||
|
|
@ -329,8 +328,8 @@ struct AliasDefinitionStatement {
|
|||
struct VariableDefinitionStatement {
|
||||
BaseNode base;
|
||||
|
||||
enum { Var, Const } modifier;
|
||||
enum { Move, Assign } assignment_modifier;
|
||||
utils::IsConstModifier modifier;
|
||||
utils::AssignmentModifier assignment_modifier;
|
||||
AnyName name;
|
||||
SuperExpression value;
|
||||
};
|
||||
|
|
@ -358,7 +357,7 @@ struct FunctionDefinitionStatement {
|
|||
struct TypeDefinitionStatement {
|
||||
BaseNode base;
|
||||
|
||||
enum { Struct, Class } modifier;
|
||||
utils::ClassModifier modifier;
|
||||
std::unique_ptr<TypeDefinition> definition;
|
||||
AnyType value;
|
||||
|
||||
|
|
@ -368,7 +367,7 @@ struct TypeDefinitionStatement {
|
|||
struct AbstractTypeDefinitionStatement {
|
||||
BaseNode base;
|
||||
|
||||
enum { Basic, Abstract } modifier;
|
||||
utils::AbstractTypeModifier modifier;
|
||||
std::unique_ptr<AnnotatedType> type;
|
||||
|
||||
utils::IdType type_graph_id_;
|
||||
|
|
@ -389,7 +388,7 @@ struct TypeclassDefinitionStatement {
|
|||
struct FunctionDefinition {
|
||||
BaseNode base;
|
||||
|
||||
enum { Operator, Function } modifier;
|
||||
utils::FunctionTypeModifier modifier;
|
||||
ExtendedName name;
|
||||
std::vector<ExtendedName> arguments;
|
||||
};
|
||||
|
|
@ -514,7 +513,7 @@ struct UnaryOperatorExpression {
|
|||
struct ReferenceExpression {
|
||||
BaseNode base;
|
||||
|
||||
std::vector<utils::ReferenceType> references;
|
||||
std::vector<utils::ReferenceModifier> references;
|
||||
std::unique_ptr<ScopedStatement> expression;
|
||||
};
|
||||
|
||||
|
|
@ -558,9 +557,8 @@ struct ReturnExpression {
|
|||
struct TypeConstructorParameter {
|
||||
BaseNode base;
|
||||
|
||||
enum AssignmentModifier { Move, Assign };
|
||||
std::optional<ExtendedName> name;
|
||||
std::optional<AssignmentModifier> asignment_modifier;
|
||||
std::optional<utils::AssignmentModifier> asignment_modifier;
|
||||
SubExpression value;
|
||||
};
|
||||
|
||||
|
|
@ -663,7 +661,7 @@ struct TypeExpression {
|
|||
struct ExtendedScopedAnyType {
|
||||
BaseNode base;
|
||||
|
||||
std::vector<utils::ReferenceType> references;
|
||||
std::vector<utils::ReferenceModifier> references;
|
||||
AnyType type;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@ class TypeManager;
|
|||
class AbstractType { // later will be found in context
|
||||
public:
|
||||
AbstractType() = default;
|
||||
AbstractType(const std::string& name,
|
||||
const std::vector<utils::IdType>& requirements) : name_(name) {
|
||||
AbstractType(utils::AbstractTypeModifier modifier,
|
||||
const std::string& name,
|
||||
const std::vector<utils::IdType>& requirements) : modifier_(modifier), name_(name) {
|
||||
for (auto& typeclass : requirements) {
|
||||
requirements_.insert(typeclass);
|
||||
}
|
||||
|
|
@ -31,6 +32,7 @@ public:
|
|||
bool operator<(const AbstractType& type) const;
|
||||
bool operator>(const AbstractType& type) const;
|
||||
private:
|
||||
utils::AbstractTypeModifier modifier_;
|
||||
std::string name_;
|
||||
std::unordered_set<utils::IdType> requirements_; // TODO: all typeclasses from tree
|
||||
};
|
||||
|
|
@ -135,7 +137,7 @@ private:
|
|||
class ReferenceToType {
|
||||
public:
|
||||
ReferenceToType() = default;
|
||||
ReferenceToType(const std::vector<utils::ReferenceType>& references,
|
||||
ReferenceToType(const std::vector<utils::ReferenceModifier>& references,
|
||||
utils::IdType type,
|
||||
TypeManager* type_manager)
|
||||
: references_(references), type_(type), type_manager_(type_manager) {}
|
||||
|
|
@ -146,7 +148,7 @@ public:
|
|||
bool operator>(const ReferenceToType& type) const;
|
||||
|
||||
private:
|
||||
std::vector<utils::ReferenceType> references_;
|
||||
std::vector<utils::ReferenceModifier> references_;
|
||||
utils::IdType type_;
|
||||
TypeManager* type_manager_ = nullptr;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,13 @@ using std::size_t;
|
|||
|
||||
using IdType = size_t;
|
||||
|
||||
enum class ReferenceType { Reference = 0, UniqueReference = 1 };
|
||||
enum class ReferenceModifier { Reference = 0, UniqueReference = 1 };
|
||||
enum class IsConstModifier { Const = 0, Var = 1 };
|
||||
enum class ClassModifier { Struct = 0, Class = 1 };
|
||||
enum class AssignmentModifier { Assign = 0, Move = 1 };
|
||||
enum class AliasModifier { Alias = 0, Type = 1, Let = 2 };
|
||||
enum class AbstractTypeModifier { Basic = 0, Abstract = 1 };
|
||||
enum class FunctionTypeModifier { Function = 0, Operator = 1 };
|
||||
|
||||
template<typename T>
|
||||
class Storage {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue