mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-11 09:28:47 +00:00
some fixes, going to fix function_call_expression typeclass argument types search bug
This commit is contained in:
parent
f2192b5331
commit
0290b5604a
9 changed files with 307 additions and 111 deletions
111
src/types.cpp
111
src/types.cpp
|
|
@ -124,6 +124,21 @@ std::optional<utils::IdType> TupleType::GetFieldType(const std::string& name,
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string TupleType::ToString() {
|
||||
std::string result;
|
||||
|
||||
result += "(";
|
||||
|
||||
for (auto& field : fields_) {
|
||||
result += "& ";
|
||||
result += type_manager_->GetAnyValue(field.second)->ToString();
|
||||
}
|
||||
|
||||
result += ")";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
std::optional<utils::IdType> VariantType::InContext(const std::unordered_map<std::string, utils::IdType>& context) {
|
||||
|
|
@ -174,6 +189,21 @@ std::optional<utils::IdType> VariantType::GetFieldType(const std::string& name,
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string VariantType::ToString() {
|
||||
std::string result;
|
||||
|
||||
result += "(";
|
||||
|
||||
for (auto& constructor : constructors_) {
|
||||
result += "& ";
|
||||
result += constructor.ToString();
|
||||
}
|
||||
|
||||
result += ")";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
std::optional<utils::IdType> OptionalType::InContext(const std::unordered_map<std::string, utils::IdType>& context) {
|
||||
|
|
@ -203,6 +233,10 @@ std::optional<utils::IdType> OptionalType::GetFieldType(const std::string&,
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string OptionalType::ToString() {
|
||||
return "Optional " + type_manager_->GetAnyValue(type_)->ToString();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
std::optional<utils::IdType> ReferenceToType::InContext(const std::unordered_map<std::string, utils::IdType>& context) {
|
||||
|
|
@ -232,6 +266,29 @@ std::optional<utils::IdType> ReferenceToType::GetFieldType(const std::string& na
|
|||
return type_manager_->GetAnyValue(type_)->GetFieldType(name, type_namespaces);
|
||||
}
|
||||
|
||||
|
||||
std::string ReferenceToType::ToString() {
|
||||
std::string result;
|
||||
|
||||
for (auto& reference : references_) {
|
||||
switch (reference) {
|
||||
case utils::ReferenceModifier::Dereference:
|
||||
result += '~';
|
||||
break;
|
||||
case utils::ReferenceModifier::Reference:
|
||||
result += '^';
|
||||
break;
|
||||
case utils::ReferenceModifier::UniqueReference:
|
||||
result += '@';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result += type_manager_->GetAnyValue(type_)->ToString();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
std::optional<utils::IdType> FunctionType::InContext(const std::unordered_map<std::string, utils::IdType>& context) {
|
||||
|
|
@ -284,6 +341,26 @@ std::optional<utils::IdType> FunctionType::GetFieldType(const std::string&,
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string FunctionType::ToString() {
|
||||
std::string result;
|
||||
|
||||
result += "(";
|
||||
|
||||
bool is_first_argument = true;
|
||||
for (auto& argument_type : argument_types_) {
|
||||
if (is_first_argument) {
|
||||
is_first_argument = false;
|
||||
} else {
|
||||
result += " -> ";
|
||||
}
|
||||
result += type_manager_->GetAnyValue(argument_type)->ToString();
|
||||
}
|
||||
|
||||
result += " -> " + type_manager_->GetAnyValue(return_type_)->ToString() + ")";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
std::optional<utils::IdType> ArrayType::InContext(const std::unordered_map<std::string, utils::IdType>& context) {
|
||||
|
|
@ -314,6 +391,10 @@ std::optional<utils::IdType> ArrayType::GetFieldType(const std::string&,
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string ArrayType::ToString() {
|
||||
return "Array (" + std::to_string(size_) + ") " + type_manager_->GetAnyValue(elements_type_)->ToString();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
std::optional<utils::IdType> Type::InContext(const std::unordered_map<std::string, utils::IdType>& context) {
|
||||
|
|
@ -477,5 +558,35 @@ std::string Type::GetTypeName() const {
|
|||
return ""; // ??
|
||||
}
|
||||
|
||||
std::string Type::ToString() {
|
||||
size_t index = type_.index();
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
return std::get<AbstractType>(type_).ToString();
|
||||
case 1:
|
||||
return std::get<DefinedType>(type_).ToString();
|
||||
case 2:
|
||||
return ::info::type::ToString(std::get<InternalType>(type_));
|
||||
case 3:
|
||||
return std::get<TupleType>(type_).ToString();
|
||||
case 4:
|
||||
return std::get<VariantType>(type_).ToString();
|
||||
case 5:
|
||||
return std::get<ReferenceToType>(type_).ToString();
|
||||
case 6:
|
||||
return std::get<FunctionType>(type_).ToString();
|
||||
case 7:
|
||||
return std::get<ArrayType>(type_).ToString();
|
||||
case 8:
|
||||
return std::get<OptionalType>(type_).ToString();
|
||||
default:
|
||||
// error
|
||||
break;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace info::type
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue