type_check_visitor fixes, function_call_expression for typeclasses

This commit is contained in:
ProgramSnail 2023-05-17 15:08:18 +03:00
parent 8e74b3082e
commit 584bdfa54d
6 changed files with 192 additions and 73 deletions

View file

@ -205,6 +205,21 @@ public:
return current_path_;
}
// use only after LinkSymbolsVisitor
std::vector<utils::IdType> GetCurrentPathTypes() {
std::vector<utils::IdType> types;
types.reserve(namespace_stack_.size());
for (auto& namespace_id : namespace_stack_) {
definition::Namespace& namespace_info = global_info_.GetNamespaceInfo(namespace_id);
if (namespace_info.any_node.has_value() && namespace_info.any_node.value()->link_type_id_.has_value()) {
types.push_back(namespace_info.any_node.value()->link_type_id_.value());
}
}
return types;
}
utils::IdType GetCurrentNamespaceId() {
return namespace_stack_.back();
}
@ -341,10 +356,10 @@ public:
std::vector<utils::IdType>
GetAnnotatedTypeTypeclassesVector(interpreter::tokens::AnnotatedType* node);
std::unordered_map<std::string, utils::ClassInternalsModifier>
std::unordered_map<std::string, TypeclassGraph::FunctionInfo*>
GetAnnotatedTypeFunctionsMap(interpreter::tokens::AnnotatedType* node);
std::vector<std::pair<std::string, utils::ClassInternalsModifier>>
std::vector<std::pair<std::string, TypeclassGraph::FunctionInfo*>>
GetAnnotatedTypeFunctionsVector(interpreter::tokens::AnnotatedType* node);
std::unordered_map<std::string, utils::IdType>* ChooseNamespaces(

View file

@ -133,7 +133,7 @@ private:
std::unordered_map<std::string, utils::IdType>& context);
void CollectTypeExpressionContext(const TypeExpression& type_expression,
std::unordered_map<std::string, utils::IdType>& context);
std::unordered_map<std::string, utils::IdType>& context);
utils::IdType TypeInContext(utils::IdType type,
const std::unordered_map<std::string, utils::IdType>& context);
@ -143,14 +143,24 @@ private:
std::optional<FunctionDeclaration*>
FindSubExpressionMethodAndUpdate(FunctionCallExpression* node,
SubExpressionToken* expression_node,
const BaseNode& base_node);
SubExpressionToken* expression_node);
std::optional<FunctionDeclaration*>
FindTypeFunctionAndUpdate(FunctionCallExpression* node,
TypeExpression* type_node,
std::unordered_map<std::string, utils::IdType>& context);
std::optional<FunctionDeclaration*>
FindAbstractTypeTypeclassFunctionAndUpdate(
FunctionCallExpression* node,
info::type::AbstractType* abstract_type,
bool is_method);
std::optional<FunctionDeclaration*>
FindDefinedTypeTypeclassFunctionAndUpdate(
FunctionCallExpression* node,
info::definition::AnyType* defined_type,
bool is_method);
private:
info::GlobalInfo::NamespaceVisitor namespace_visitor_;
info::GlobalInfo& global_info_;

View file

@ -112,12 +112,12 @@ public:
}
// cache ??
std::vector<std::pair<std::string, utils::ClassInternalsModifier>> GetTypeclassFunctions(utils::IdType id) {
std::vector<std::pair<std::string, utils::ClassInternalsModifier>> functions;
std::vector<std::pair<std::string, TypeclassGraph::FunctionInfo*>> GetTypeclassFunctions(utils::IdType id) {
std::vector<std::pair<std::string, TypeclassGraph::FunctionInfo*>> functions;
functions.reserve(typeclasses_.at(id).functions.size());
for (auto& function : typeclasses_[id].functions) {
functions.push_back({function.first, function.second.modifier});
functions.push_back({function.first, &function.second});
}
return functions;