fixes, new examples

This commit is contained in:
ProgramSnail 2023-05-23 11:54:15 +03:00
parent 823fa30fa8
commit 7f4266821c
15 changed files with 322 additions and 74 deletions

View file

@ -498,7 +498,7 @@ struct ReferenceExpression {
BaseNode base;
utils::ReferenceModifier reference;
std::unique_ptr<ScopedStatement> expression;
SubExpressionToken expression;
};
struct AccessExpression {

View file

@ -210,7 +210,10 @@ private:
}
void VisitDefinedType(info::definition::AnyType* defined_type,
const std::unordered_map<std::string, utils::IdType>& context) {
const std::unordered_map<std::string, utils::IdType>& context,
utils::ValueType modifier) {
context_manager_.EnterContext();
AddTypeParameterLocalTypes(defined_type);
Visitor::Visit(defined_type->node->value);
current_type_ = TypeInContext(current_type_, context);
current_type_ =
@ -218,7 +221,20 @@ private:
current_type_,
defined_type->modifier,
context_manager_.GetValueManager()),
utils::ValueType::Tmp);
modifier);
context_manager_.ExitContext();
}
void AddTypeParameterLocalTypes(info::definition::AnyType* type_info) {
for (auto& parameter : type_info->node->definition->parameters) {
context_manager_.DefineLocalType(
parameter->type,
context_manager_.AddValue(
info::type::AbstractType(utils::AbstractTypeModifier::Abstract,
parameter->graph_id_,
typeclass_graph_),
utils::ValueType::Tmp));
}
}
private:

View file

@ -43,7 +43,7 @@ public:
return graph_id == graph_id_ || typeclass_graph_.GetDependenciesSet(graph_id_).count(graph_id) != 0;
}
std::string ToString() {
std::string ToString() const {
return "Abstract " + std::to_string(graph_id_);
}
private:
@ -81,7 +81,7 @@ public:
return class_modifier_;
}
std::string ToString() {
std::string ToString() const {
return "Defined";
}
private:
@ -178,7 +178,7 @@ public:
return fields_;
}
std::string ToString();
std::string ToString() const;
private:
std::optional<std::string> name_;
std::vector<std::pair<std::optional<std::string>, utils::IdType>> fields_;
@ -209,7 +209,7 @@ public:
current_constructor_ = constructor;
}
std::string ToString();
std::string ToString() const;
private:
std::optional<std::string> name_;
std::vector<TupleType> constructors_;
@ -231,7 +231,7 @@ public:
std::optional<utils::IdType> GetFieldType(const std::string& name,
const std::unordered_set<utils::IdType>& type_namespaces) const;
std::string ToString();
std::string ToString() const;
private:
utils::IdType type_;
TypeManager* type_manager_ = nullptr;
@ -243,7 +243,11 @@ public:
ReferenceToType(const std::vector<utils::ReferenceModifier>& references,
utils::IdType type,
TypeManager* type_manager)
: references_(references), type_(type), type_manager_(type_manager) {}
: references_(references), type_(type), type_manager_(type_manager) {
if (references.empty()) {
error_handling::HandleInternalError("ReferenceToType with 0 references", "Type.ReferenceToType", std::nullopt);
}
}
std::optional<utils::IdType> InContext(const std::unordered_map<std::string, utils::IdType>& context);
bool Same(const ReferenceToType& type) const;
@ -253,7 +257,7 @@ public:
std::optional<utils::IdType> GetFieldType(const std::string& name,
const std::unordered_set<utils::IdType>& type_namespaces) const;
std::string ToString();
std::string ToString() const;
private:
std::vector<utils::ReferenceModifier> references_;
utils::IdType type_;
@ -278,7 +282,7 @@ public:
std::optional<utils::IdType> GetFieldType(const std::string& name,
const std::unordered_set<utils::IdType>& type_namespaces) const;
std::string ToString();
std::string ToString() const;
private:
std::vector<utils::IdType> argument_types_;
utils::IdType return_type_;
@ -305,7 +309,7 @@ public:
return elements_type_;
}
std::string ToString();
std::string ToString() const;
private:
size_t size_; // = 0 for dynamic
utils::IdType elements_type_;
@ -339,7 +343,7 @@ public:
return type_;
}
std::string ToString();
std::string ToString() const;
private:
std::variant<AbstractType,
DefinedType,