mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
fixes, internal type is now abstract type
This commit is contained in:
parent
0290b5604a
commit
3af0772da6
7 changed files with 148 additions and 89 deletions
|
|
@ -33,6 +33,7 @@ struct Parameter {
|
|||
struct AbstractType {
|
||||
utils::AbstractTypeModifier modifier;
|
||||
Parameter type;
|
||||
interpreter::tokens::AbstractTypeDefinitionStatement* node = nullptr;
|
||||
};
|
||||
|
||||
struct AliasType {
|
||||
|
|
@ -45,8 +46,8 @@ struct AliasType {
|
|||
struct AnyType {
|
||||
Parameter type;
|
||||
std::vector<Parameter> parameters;
|
||||
interpreter::tokens::AnyType* value;
|
||||
utils::ClassModifier modifier;
|
||||
interpreter::tokens::TypeDefinitionStatement* node = nullptr;
|
||||
|
||||
utils::IdType parent_namespace = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,6 +23,16 @@ public:
|
|||
typeclass_graph_(*global_info.GetTypeclassGraph()),
|
||||
context_manager_(context_manager) {}
|
||||
|
||||
void VisitSourceFile(SourceFile* source_file) override {
|
||||
// init internal type abstrac types
|
||||
for (size_t i = 0; i < info::type::InternalTypesCount; ++i) {
|
||||
info::type::InternalType type = static_cast<info::type::InternalType>(i);
|
||||
Visit(namespace_visitor_.FindAbstractType(info::type::ToString(type)).value()->node);
|
||||
}
|
||||
|
||||
Visit(source_file);
|
||||
}
|
||||
|
||||
private:
|
||||
// Sources -----------------
|
||||
|
||||
|
|
@ -161,6 +171,7 @@ private:
|
|||
FindDefinedTypeFunctionAndUpdate(
|
||||
FunctionCallExpression* node,
|
||||
info::definition::AnyType* defined_type,
|
||||
utils::IdType type,
|
||||
bool is_method);
|
||||
|
||||
void ResetReturnedAndBroughtTypes() {
|
||||
|
|
@ -181,6 +192,35 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
utils::IdType AddGraphIdLocalAbstractTypes(utils::IdType graph_id) {
|
||||
std::unordered_set<utils::IdType> requirement_graph_ids = typeclass_graph_.GetDependenciesSet(graph_id);
|
||||
requirement_graph_ids.insert(graph_id);
|
||||
|
||||
utils::IdType abstract_type = context_manager_.AddValue(
|
||||
info::type::AbstractType(utils::AbstractTypeModifier::Abstract,
|
||||
typeclass_graph_.GetVertex(graph_id).name,
|
||||
requirement_graph_ids),
|
||||
utils::ValueType::Tmp);
|
||||
|
||||
for (auto& requirement_graph_id : requirement_graph_ids) {
|
||||
context_manager_.DefineLocalType(typeclass_graph_.GetVertex(requirement_graph_id).name, abstract_type);
|
||||
}
|
||||
|
||||
return abstract_type;
|
||||
}
|
||||
|
||||
void VisitDefinedType(info::definition::AnyType* defined_type,
|
||||
const std::unordered_map<std::string, utils::IdType>& context) {
|
||||
Visitor::Visit(defined_type->node->value);
|
||||
current_type_ = TypeInContext(current_type_, context);
|
||||
current_type_ =
|
||||
context_manager_.AddValue(info::type::DefinedType(defined_type->node->type_id_,
|
||||
current_type_,
|
||||
defined_type->modifier,
|
||||
context_manager_.GetValueManager()),
|
||||
utils::ValueType::Tmp);
|
||||
}
|
||||
|
||||
private:
|
||||
info::GlobalInfo::NamespaceVisitor namespace_visitor_;
|
||||
info::GlobalInfo& global_info_;
|
||||
|
|
@ -196,6 +236,8 @@ private:
|
|||
std::optional<utils::IdType> brought_type_;
|
||||
bool all_branches_brought_value_ = true;
|
||||
|
||||
std::unordered_map<info::type::InternalType, utils::IdType> internal_to_abstract_type_;
|
||||
|
||||
std::optional<utils::IsConstModifier> is_const_definition_;
|
||||
|
||||
bool is_in_statement_ = false;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public:
|
|||
}
|
||||
|
||||
std::string ToString() {
|
||||
return "Abstract";
|
||||
return "Abstract " + name_;
|
||||
}
|
||||
private:
|
||||
utils::AbstractTypeModifier modifier_;
|
||||
|
|
@ -101,6 +101,7 @@ private:
|
|||
TypeManager* type_manager_ = nullptr;
|
||||
};
|
||||
|
||||
const size_t InternalTypesCount = 6;
|
||||
enum class InternalType {
|
||||
Float = 0,
|
||||
Int = 1,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue