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