mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-07 15:38:49 +00:00
type structure change, part done
This commit is contained in:
parent
78c696b99a
commit
522dd16f79
13 changed files with 386 additions and 218 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include "name_tree.hpp"
|
||||
#include "statement_nodes.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace types {
|
||||
|
|
@ -30,11 +31,8 @@ private:
|
|||
|
||||
class Defined {
|
||||
public:
|
||||
Defined(nodes::Modifier modifier,
|
||||
names::StatementProxy<nodes::TypeDefinition> definition)
|
||||
: modifier_(modifier), definition_(definition) {}
|
||||
|
||||
nodes::Modifier get_modifier() const { return modifier_; }
|
||||
Defined(names::StatementProxy<nodes::TypeDefinition> definition)
|
||||
: definition_(definition) {}
|
||||
|
||||
nodes::TypeDefinition *get_definition() { return definition_.get(); }
|
||||
|
||||
|
|
@ -43,10 +41,64 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
nodes::Modifier modifier_;
|
||||
names::StatementProxy<nodes::TypeDefinition> definition_;
|
||||
};
|
||||
|
||||
class Abstract {
|
||||
public:
|
||||
Abstract(std::optional<std::string> name,
|
||||
std::vector<std::string> typeclasses)
|
||||
: name_(name), typeclasses_(typeclasses) {}
|
||||
|
||||
//
|
||||
|
||||
std::optional<std::string *> get_name() {
|
||||
if (name_.has_value()) {
|
||||
return &name_.value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<const std::string *> get_name() const {
|
||||
if (name_.has_value()) {
|
||||
return &name_.value();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
size_t typeclasses_size() const { return typeclasses_.size(); }
|
||||
|
||||
std::string *get_typeclass(size_t id) { return &typeclasses_.at(id); }
|
||||
|
||||
const std::string *get_typeclass(size_t id) const {
|
||||
return &typeclasses_.at(id);
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<std::string> name_;
|
||||
std::vector<std::string> typeclasses_;
|
||||
};
|
||||
|
||||
class Modified {
|
||||
public:
|
||||
Modified(nodes::Modifier modifier, TypeProxy type)
|
||||
: modifier_(modifier), type_(type) {}
|
||||
|
||||
nodes::Modifier get_modifier() const { return modifier_; }
|
||||
|
||||
Type *get_type() { return type_.get(); }
|
||||
|
||||
const Type *get_type() const { return type_.get(); }
|
||||
|
||||
const TypeProxy &get_type_proxy() const { return type_; }
|
||||
|
||||
private:
|
||||
nodes::Modifier modifier_;
|
||||
TypeProxy type_;
|
||||
};
|
||||
|
||||
class Container {
|
||||
public:
|
||||
enum ContainerType {
|
||||
|
|
@ -72,6 +124,8 @@ public:
|
|||
|
||||
const Type *get_field(size_t id) const { return fields_.at(id).get(); }
|
||||
|
||||
const TypeProxy &get_field_proxy(size_t id) const { return fields_.at(id); }
|
||||
|
||||
private:
|
||||
ContainerType type_;
|
||||
std::vector<TypeProxy> fields_; // or constructors
|
||||
|
|
@ -105,7 +159,7 @@ public:
|
|||
auto get_any() const { return &type_; }
|
||||
|
||||
private:
|
||||
std::variant<Defined, Container> type_;
|
||||
std::variant<Defined, Abstract, Modified, Container> type_;
|
||||
};
|
||||
|
||||
class TypeStorage {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue