Format const in type
This commit is contained in:
parent
8e6980715e
commit
efb4ce85ac
@ -15,6 +15,7 @@ namespace parsing {
|
||||
bool is_const = false;
|
||||
if (inner.peek().type == token::Type::Ident && inner.peek().content == "const") {
|
||||
is_const = true;
|
||||
inner.next();
|
||||
}
|
||||
|
||||
auto token = inner.expect(token::Type::Ident);
|
||||
|
||||
@ -42,18 +42,27 @@ namespace types {
|
||||
}
|
||||
|
||||
std::string FundamentalType::formatted() {
|
||||
std::stringstream out{ "" };
|
||||
if (this->m_const)
|
||||
out << "const ";
|
||||
switch (this->m_ty) {
|
||||
case FundamentalTypeKind::Int:
|
||||
return "Int";
|
||||
out << "Int";
|
||||
break;
|
||||
case FundamentalTypeKind::Bool:
|
||||
return "Bool";
|
||||
out << "Bool";
|
||||
break;
|
||||
case FundamentalTypeKind::Char:
|
||||
return "Char";
|
||||
out << "Char";
|
||||
break;
|
||||
case FundamentalTypeKind::Void:
|
||||
return "Void";
|
||||
out << "Void";
|
||||
break;
|
||||
default:
|
||||
return "Unknown";
|
||||
out << "Unknown";
|
||||
break;
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Type>> Type::return_type() {
|
||||
@ -96,6 +105,9 @@ namespace types {
|
||||
|
||||
std::string FunctionType::formatted() {
|
||||
std::stringstream out{ "" };
|
||||
if (this->m_const)
|
||||
out << "const ";
|
||||
|
||||
out << "(";
|
||||
|
||||
int counter = 0;
|
||||
@ -131,6 +143,9 @@ namespace types {
|
||||
std::string PointerType::formatted() {
|
||||
std::stringstream out{ "" };
|
||||
out << this->m_inner->formatted() << "*";
|
||||
if (this->m_const)
|
||||
out << " const";
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
@ -147,6 +162,9 @@ namespace types {
|
||||
|
||||
std::string ArrayType::formatted() {
|
||||
std::stringstream out{ "" };
|
||||
if (this->m_const)
|
||||
out << "const[] ";
|
||||
|
||||
out << this->m_inner->formatted();
|
||||
out << "[" << this->m_size << "]";
|
||||
return out.str();
|
||||
@ -163,6 +181,9 @@ namespace types {
|
||||
|
||||
std::string StructType::formatted() {
|
||||
std::stringstream out{ "" };
|
||||
if (this->m_const)
|
||||
out << "const ";
|
||||
|
||||
out << "struct(" << this->m_id << ")";
|
||||
if (this->m_is_ref)
|
||||
out << "(ref)";
|
||||
@ -202,22 +223,6 @@ namespace types {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
// std::string StructRef::formatted() {
|
||||
// std::stringstream out{ "" };
|
||||
// out << "struct(ref) " << this->m_name;
|
||||
// return out.str();
|
||||
// }
|
||||
|
||||
// std::pair<llvm::Value*, std::shared_ptr<Type>> StructRef::load(codegen::Builder&, llvm::Value* ptr, codegen::TypeMap&) {
|
||||
// auto self = std::make_shared<StructRef>(*this);
|
||||
// return std::pair(ptr, self);
|
||||
// }
|
||||
|
||||
// uint32_t StructRef::size() {
|
||||
// return this->m_referred->size();
|
||||
// }
|
||||
|
||||
bool types_equal(std::shared_ptr<types::Type> type1, std::shared_ptr<types::Type> type2) {
|
||||
if (type1->m_kind != type2->m_kind)
|
||||
return false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user