fixes, internal type is now abstract type

This commit is contained in:
ProgramSnail 2023-05-22 10:58:50 +03:00
parent 0290b5604a
commit 3af0772da6
7 changed files with 148 additions and 89 deletions

View file

@ -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;
};

View file

@ -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;

View file

@ -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,

View file

@ -111,7 +111,7 @@ void FindSymbolsVisitor::Visit(TypeDefinitionStatement* node) {
current_info_.reset();
}
any_type_info.value = &node->value;
any_type_info.node = node;
any_type_info.parent_namespace = namespace_visitor_.GetCurrentNamespaceId();
any_type_info.modifier = node->modifier;
@ -133,6 +133,7 @@ void FindSymbolsVisitor::Visit(AbstractTypeDefinitionStatement* node) {
current_info_.reset();
info.modifier = node->modifier;
info.node = node;
std::string type = info.type.type;

View file

@ -176,8 +176,8 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
}
definition::AnyType& any_type_info = std::get<definition::AnyType>(moved_type_info.type);
if (std::holds_alternative<std::unique_ptr<interpreter::tokens::VariantType>>(*any_type_info.value)) {
interpreter::tokens::VariantType& variant_type_info = *std::get<std::unique_ptr<interpreter::tokens::VariantType>>(*any_type_info.value);
if (std::holds_alternative<std::unique_ptr<interpreter::tokens::VariantType>>(any_type_info.node->value)) {
interpreter::tokens::VariantType& variant_type_info = *std::get<std::unique_ptr<interpreter::tokens::VariantType>>(any_type_info.node->value);
for (size_t i = 0; i < variant_type_info.constructors.size(); ++i) {
std::string constructor_name;
definition::Constructor constructor_info;
@ -209,12 +209,12 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
AddConstructor(constructor_name, std::move(constructor_info), base_node);
}
} else if (std::holds_alternative<std::unique_ptr<interpreter::tokens::TupleType>>(*any_type_info.value)) {
} else if (std::holds_alternative<std::unique_ptr<interpreter::tokens::TupleType>>(any_type_info.node->value)) {
definition::Constructor constructor_info;
constructor_info.type_id = id;
// constructor_info.order = std::nullopt;
constructor_info.name = type;
constructor_info.constructor_tuple_node = std::get<std::unique_ptr<interpreter::tokens::TupleType>>(*any_type_info.value).get();
constructor_info.constructor_tuple_node = std::get<std::unique_ptr<interpreter::tokens::TupleType>>(any_type_info.node->value).get();
AddConstructor(type, std::move(constructor_info), base_node);
} else {

View file

@ -17,7 +17,7 @@ void TypeCheckVisitor::Visit(SourceFile* node) {
for (auto& statement : node->statements) {
Visitor::Visit(statement);
}
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
node->base.type_ = current_type_;
}
@ -28,7 +28,7 @@ void TypeCheckVisitor::Visit(NamespaceSources* node) {
for (auto& statement : node->statements) {
Visitor::Visit(statement);
}
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
node->base.type_ = current_type_;
}
@ -37,24 +37,18 @@ void TypeCheckVisitor::Visit(Namespace* node) {
if (node->link_typeclass_id_.has_value()) {
utils::IdType graph_id = global_info_.GetTypeclassInfo(node->link_typeclass_id_.value()).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,
node->type,
requirement_graph_ids),
ClassInternalsModifierToValueType(node->modifier));
context_manager_.EnterContext();
utils::IdType abstract_type = AddGraphIdLocalAbstractTypes(graph_id);
abstract_type = context_manager_.ToModifiedValue(abstract_type,
ClassInternalsModifierToValueType(node->modifier));
if (node->modifier != utils::ClassInternalsModifier::Static) {
context_manager_.EnterVariableContext(utils::ClassInternalVarName,
abstract_type);
} else {
context_manager_.EnterContext();
context_manager_.DefineVariable(utils::ClassInternalVarName,
abstract_type);
}
abstract_type = context_manager_.ToModifiedValue(abstract_type, utils::ValueType::Tmp); // ??
AddGraphIdLocalTypes(graph_id, abstract_type);
AddGraphIdLocalAbstractTypes(graph_id);
} else if (node->link_type_id_.has_value()) {
auto maybe_type_info = global_info_.GetTypeInfo<info::definition::AnyType>(node->link_type_id_.value());
@ -64,7 +58,7 @@ void TypeCheckVisitor::Visit(Namespace* node) {
info::definition::AnyType* type_info = maybe_type_info.value();
Visitor::Visit(*type_info->value);
Visitor::Visit(type_info->node->value);
utils::IdType type = context_manager_.AddValue(
info::type::DefinedType(node->link_type_id_.value(),
current_type_,
@ -92,7 +86,7 @@ void TypeCheckVisitor::Visit(Namespace* node) {
namespace_visitor_.ExitNamespace();
context_manager_.ExitContext();
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
if (node->link_type_id_.has_value()) {
type_namespaces_.erase(node->link_type_id_.value());
@ -127,7 +121,7 @@ void TypeCheckVisitor::Visit(VariableDefinitionStatement* node) {
Visitor::Visit(node->name);
is_const_definition_ = std::nullopt;
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
is_in_statement_ = false;
node->base.type_ = current_type_;
@ -158,7 +152,7 @@ void TypeCheckVisitor::Visit(FunctionDeclaration* node) {
}
Visit(node->type.get());
context_manager_.ExitContext();
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
if (!was_in_statement) {
is_in_statement_ = false;
@ -270,7 +264,7 @@ void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
context_manager_.ExitContext();
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
is_in_statement_ = false;
node->base.type_ = current_type_;
@ -301,7 +295,7 @@ void TypeCheckVisitor::Visit(TypeDefinitionStatement* node) {
}
}
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
is_in_statement_ = false;
node->base.type_ = current_type_;
@ -310,22 +304,36 @@ void TypeCheckVisitor::Visit(TypeDefinitionStatement* node) {
void TypeCheckVisitor::Visit(AbstractTypeDefinitionStatement* node) {
is_in_statement_ = true;
auto maybe_internal_type = info::type::ToInternalType(node->type->type);
if (maybe_internal_type.has_value()
&& internal_to_abstract_type_.count(maybe_internal_type.value()) != 0) {
return;
}
auto requirements = typeclass_graph_.GetDependenciesSet(node->type->graph_id_);
current_type_ = context_manager_.AddValue(info::type::AbstractType(node->modifier, node->type->type, requirements),
utils::ValueType::Tmp);
utils::ValueType::Tmp);
if (maybe_internal_type.has_value()) {
internal_to_abstract_type_[maybe_internal_type.value()] = current_type_;
}
if (!context_manager_.DefineLocalType(node->type->type, current_type_)) {
error_handling::HandleTypecheckError("Can't define basic / abstract type: abstract type redefinition", node->base);
}
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
is_in_statement_ = false;
node->base.type_ = current_type_;
// --- can't work always, because "visit" can be called for internal types
// current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
// node->base.type_ = current_type_;
}
void TypeCheckVisitor::Visit(TypeclassDefinitionStatement* node) {
is_in_statement_ = true;
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
is_in_statement_ = false;
node->base.type_ = current_type_;
@ -338,7 +346,7 @@ void TypeCheckVisitor::Visit(PartitionStatement* node) {
Visitor::Visit(node->value);
context_manager_.ExitContext();
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
is_in_statement_ = false;
node->base.type_ = current_type_;
@ -347,19 +355,19 @@ void TypeCheckVisitor::Visit(PartitionStatement* node) {
// Definition parts
void TypeCheckVisitor::Visit(FunctionDefinition* node) {
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
node->base.type_ = current_type_;
}
void TypeCheckVisitor::Visit(TypeDefinition* node) {
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
node->base.type_ = current_type_;
}
void TypeCheckVisitor::Visit(AnyAnnotatedType* node) {
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
node->base.type_ = current_type_;
}
@ -433,7 +441,7 @@ void TypeCheckVisitor::Visit(TypeConstructorPattern* node) { // TODO: match name
}
}
Visitor::Visit(*type_info.value);
Visitor::Visit(type_info.node->value);
current_type_ = TypeInContext(current_type_, context);
current_type_ = context_manager_.ToModifiedValue(current_type_, utils::ValueType::Tmp);
@ -455,7 +463,7 @@ void TypeCheckVisitor::Visit(MatchCase* node) {
Visitor::Visit(node->condition.value());
}
if (!context_manager_.EqualValues(
context_manager_.AddValue(info::type::InternalType::Bool, utils::ValueType::Tmp),
internal_to_abstract_type_.at(info::type::InternalType::Bool),
current_type_)) {
error_handling::HandleTypecheckError("Match case condition is not bool expression", node->base);
}
@ -510,7 +518,7 @@ void TypeCheckVisitor::Visit(Match* node) { // TODO: move value to match
if (!is_type_found) {
error_handling::HandleTypecheckError("Can't find match expression type", node->base);
// type = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
// type = internal_to_abstract_type_.at(info::type::InternalType::Unit);
}
current_type_ = type;
@ -535,7 +543,7 @@ void TypeCheckVisitor::Visit(Condition* node) {
ResetReturnedAndBroughtTypes();
Visitor::Visit(node->conditions[i]);
if (!context_manager_.EqualValues(context_manager_.AddValue(info::type::InternalType::Bool, utils::ValueType::Tmp), current_type_)) {
if (!context_manager_.EqualValues(internal_to_abstract_type_.at(info::type::InternalType::Bool), current_type_)) {
error_handling::HandleTypecheckError("Condition statement condition is not bool expression", node->base);
}
@ -574,7 +582,7 @@ void TypeCheckVisitor::Visit(DoWhileLoop* node) {
context_manager_.EnterContext();
Visitor::Visit(node->condition);
if (!context_manager_.EqualValues(context_manager_.AddValue(info::type::InternalType::Bool, utils::ValueType::Tmp), current_type_)) {
if (!context_manager_.EqualValues(internal_to_abstract_type_.at(info::type::InternalType::Bool), current_type_)) {
error_handling::HandleTypecheckError("Do while loop statement condition is not bool expression", node->base);
}
@ -593,7 +601,7 @@ void TypeCheckVisitor::Visit(WhileLoop* node) {
context_manager_.EnterContext();
Visitor::Visit(node->condition);
if (!context_manager_.EqualValues(context_manager_.AddValue(info::type::InternalType::Bool, utils::ValueType::Tmp), current_type_)) {
if (!context_manager_.EqualValues(internal_to_abstract_type_.at(info::type::InternalType::Bool), current_type_)) {
error_handling::HandleTypecheckError("While loop statement condition is not bool expression", node->base);
}
@ -671,7 +679,7 @@ void TypeCheckVisitor::Visit(Block* node) {
if (brought_type_.has_value()) {
current_type_ = brought_type_.value();
} else {
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
}
brought_type_ = std::nullopt;
@ -687,7 +695,7 @@ void TypeCheckVisitor::Visit(ScopedStatement* node) {
}
void TypeCheckVisitor::Visit(LoopControlExpression&) { // enum
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
}
// Operators
@ -704,7 +712,7 @@ void TypeCheckVisitor::Visit(ReferenceExpression* node) {
void TypeCheckVisitor::Visit(AccessExpression* node) {
Visitor::Visit(node->id);
if (!context_manager_.EqualValues(context_manager_.AddValue(info::type::InternalType::Int, utils::ValueType::Tmp), current_type_)) {
if (!context_manager_.EqualValues(internal_to_abstract_type_.at(info::type::InternalType::Int), current_type_)) {
error_handling::HandleTypecheckError("Access index has wrong type (not Int)", node->base);
}
@ -892,7 +900,7 @@ void TypeCheckVisitor::Visit(ReturnExpression* node) {
all_branches_brought_value_ = true;
}
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
node->base.type_ = current_type_;
}
@ -969,7 +977,7 @@ void TypeCheckVisitor::Visit(TypeConstructor* node) {
}
}
Visitor::Visit(*type_info.value);
Visitor::Visit(type_info.node->value);
std::optional<info::type::VariantType*> maybe_variant_type =
context_manager_.GetValue<info::type::VariantType>(current_type_);
@ -1151,7 +1159,7 @@ void TypeCheckVisitor::Visit(VariantName* node) {
if (type_value->GetConstructors()[i].GetFields().empty()) {
current_type_ = context_manager_.AddValue(
info::type::OptionalType(
context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp),
internal_to_abstract_type_.at(info::type::InternalType::Unit),
context_manager_.GetValueManager()),
utils::IsConstModifierToValueType(is_const_definition_.value())); // TODO ??
} else {
@ -1274,21 +1282,20 @@ void TypeCheckVisitor::Visit(VariantType* node) {
node->base.type_ = current_type_;
}
// TODO: better function design
// TODO handle local abstract types, abstract types, aliases, etc.
void TypeCheckVisitor::Visit(TypeExpression* node) {
std::unordered_map<std::string, utils::IdType> context;
CollectTypeExpressionContext(*node, context);
auto maybe_internal_type = info::type::ToInternalType(node->type.type);
if (maybe_internal_type.has_value()) { // TODO: ???
// checks made in link_symbols_visitor
current_type_ =
context_manager_.AddValue<info::type::InternalType>(
maybe_internal_type.value(),
utils::ValueType::Tmp);
} else {
// TODO: -------- remove, unneeded ------
// auto maybe_internal_type = info::type::ToInternalType(node->type.type);
//
// if (maybe_internal_type.has_value()) { // TODO: ???
// // checks made in link_symbols_visitor
// current_type_ =
// context_manager_.AddValue<info::type::InternalType>(
// maybe_internal_type.value(),
// utils::ValueType::Tmp);
// } else {
std::optional<utils::IdType> maybe_local_abstract_type =
context_manager_.FindLocalType(node->type.type);
if (node->path.empty() && maybe_local_abstract_type.has_value()) {
@ -1303,18 +1310,11 @@ void TypeCheckVisitor::Visit(TypeExpression* node) {
&node->base);
}
Visitor::Visit(*maybe_type_info.value()->value);
current_type_ = TypeInContext(current_type_, context);
current_type_ =
context_manager_.AddValue(info::type::DefinedType(node->type_id_.value(),
current_type_,
maybe_type_info.value()->modifier,
context_manager_.GetValueManager()),
utils::ValueType::Tmp);
VisitDefinedType(maybe_type_info.value(), context);
} else {
error_handling::HandleTypecheckError("Type not found", node->base);
}
}
// }
if (node->array_size.has_value()) {
current_type_ = context_manager_.AddValue(
@ -1356,37 +1356,37 @@ void TypeCheckVisitor::Visit(ParametrizedType*) {} // Handled in TypeExpression
// Identifiers, constants, etc. -----------------
void TypeCheckVisitor::Visit(FloatNumberLiteral* node) {
current_type_ = context_manager_.AddValue(info::type::InternalType::Float, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Float);
node->base.type_ = current_type_;
}
void TypeCheckVisitor::Visit(NumberLiteral* node) {
current_type_ = context_manager_.AddValue(info::type::InternalType::Int, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Int);
node->base.type_ = current_type_;
}
void TypeCheckVisitor::Visit(StringLiteral* node) {
current_type_ = context_manager_.AddValue(info::type::InternalType::String, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::String);
node->base.type_ = current_type_;
}
void TypeCheckVisitor::Visit(CharLiteral* node) {
current_type_ = context_manager_.AddValue(info::type::InternalType::Char, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Char);
node->base.type_ = current_type_;
}
void TypeCheckVisitor::Visit(UnitLiteral* node) {
current_type_ = context_manager_.AddValue(info::type::InternalType::Unit, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
node->base.type_ = current_type_;
}
void TypeCheckVisitor::Visit(BoolLiteral* node) {
current_type_ = context_manager_.AddValue(info::type::InternalType::Bool, utils::ValueType::Tmp);
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Bool);
node->base.type_ = current_type_;
}
@ -1474,17 +1474,18 @@ std::optional<FunctionDeclaration*>
utils::IdType expression_type) {
std::optional<FunctionDeclaration*> maybe_function_declaration;
auto maybe_internal_type_info = context_manager_.GetValue<info::type::InternalType>(expression_type);
if (maybe_internal_type_info.has_value()) {
auto maybe_abstract_type_id = context_manager_.FindLocalType(info::type::ToString(*maybe_internal_type_info.value()));
if (maybe_abstract_type_id.has_value()) {
expression_type = maybe_abstract_type_id.value();
} else {
error_handling::HandleInternalError("InternalType local abstract type not found",
"TypeCheckVisitor.FindExpressionMethodAndUpdate",
&node->base);
}
}
// TODO: -------- remove, unneeded -------
// auto maybe_internal_type_info = context_manager_.GetValue<info::type::InternalType>(expression_type);
// if (maybe_internal_type_info.has_value()) {
// auto maybe_abstract_type_id = context_manager_.FindLocalType(info::type::ToString(*maybe_internal_type_info.value()));
// if (maybe_abstract_type_id.has_value()) {
// expression_type = maybe_abstract_type_id.value();
// } else {
// error_handling::HandleInternalError("InternalType local abstract type not found",
// "TypeCheckVisitor.FindExpressionMethodAndUpdate",
// &node->base);
// }
// }
auto maybe_abstract_type_info = context_manager_.GetValue<info::type::AbstractType>(expression_type);
@ -1509,6 +1510,7 @@ std::optional<FunctionDeclaration*>
maybe_function_declaration = FindDefinedTypeFunctionAndUpdate(node,
type_info,
expression_type,
true);
}
return maybe_function_declaration;
@ -1560,9 +1562,12 @@ std::optional<FunctionDeclaration*>
&node->base);
}
maybe_function_declaration = FindDefinedTypeFunctionAndUpdate(node,
maybe_type_info.value(),
false);
VisitDefinedType(maybe_type_info.value(), context);
maybe_function_declaration =
FindDefinedTypeFunctionAndUpdate(node,
maybe_type_info.value(),
current_type_,
false);
} else {
std::optional<utils::IdType> maybe_function_id = namespace_visitor_.FindFunctionId(path, node->name);
@ -1585,6 +1590,7 @@ std::optional<FunctionDeclaration*>
std::optional<FunctionDeclaration*> TypeCheckVisitor::FindFunctionAndUpdate(FunctionCallExpression* node) {
std::optional<FunctionDeclaration*> maybe_function_declaration;
const std::vector<utils::IdType>& path_namespaces = namespace_visitor_.GetCurrentPathNamespaces();
auto path_types = namespace_visitor_.GetCurrentPathTypes();
for (ssize_t i = (ssize_t)path_types.size() - 1; i >= 0; --i) { // optimize ??
@ -1596,9 +1602,11 @@ std::optional<FunctionDeclaration*> TypeCheckVisitor::FindFunctionAndUpdate(Func
&node->base);
}
VisitDefinedType(maybe_type_info.value(), {}); // TODO: context ??
maybe_function_declaration =
FindDefinedTypeFunctionAndUpdate(node,
maybe_type_info.value(),
current_type_,
false);
} else if (global_info_.GetNamespaceInfo(path_namespaces[i]).modifier == utils::ClassInternalsModifier::Static) {
auto function_iter = global_info_.GetNamespaceInfo(path_namespaces[i]).functions.find(node->name);
@ -1659,6 +1667,7 @@ std::optional<FunctionDeclaration*>
}
node->graph_id_ = maybe_typeclass_graph_id;
AddGraphIdLocalAbstractTypes(node->graph_id_.value()); // check
node->abstract_type_name_ = abstract_type_info->GetName();
maybe_function_declaration = maybe_typeclass_function_info.value()->declaration;
@ -1670,6 +1679,7 @@ std::optional<FunctionDeclaration*>
TypeCheckVisitor::FindDefinedTypeFunctionAndUpdate(
FunctionCallExpression* node,
info::definition::AnyType* defined_type,
utils::IdType type,
bool is_method) {
std::optional<FunctionDeclaration*> maybe_function_declaration;
@ -1687,6 +1697,9 @@ std::optional<FunctionDeclaration*>
node->graph_id_ = defined_type->type.node->graph_id_;
AddGraphIdLocalTypes(node->graph_id_.value(), type);
// type defined -> abstract type name not needed
maybe_function_declaration = maybe_type_function_info.value()->declaration;

View file

@ -1,5 +1,6 @@
// for clangd
#include "../include/types.hpp"
#include <variant>
namespace info::type {