Add pointer types
This commit is contained in:
parent
6855360a97
commit
ac7731446e
@ -12,26 +12,37 @@ namespace parsing {
|
|||||||
try {
|
try {
|
||||||
auto token = inner.expect(token::Type::Ident);
|
auto token = inner.expect(token::Type::Ident);
|
||||||
|
|
||||||
stream.m_position = inner.m_position;
|
|
||||||
|
|
||||||
// TODO eventually make this be potentially more than one word
|
// TODO eventually make this be potentially more than one word
|
||||||
std::string type_name = token.content;
|
std::string type_name = token.content;
|
||||||
|
|
||||||
|
std::unique_ptr<types::Type> returned{};
|
||||||
|
|
||||||
if (type_name == "int") {
|
if (type_name == "int") {
|
||||||
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Int };
|
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Int };
|
||||||
return std::unique_ptr<types::Type>{ ty };
|
returned = std::unique_ptr<types::Type>{ ty };
|
||||||
}
|
}
|
||||||
else if (type_name == "char") {
|
else if (type_name == "char") {
|
||||||
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Char };
|
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Char };
|
||||||
return std::unique_ptr<types::Type>{ ty };
|
returned = std::unique_ptr<types::Type>{ ty };
|
||||||
}
|
}
|
||||||
else if (type_name == "void") {
|
else if (type_name == "void") {
|
||||||
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Void };
|
auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Void };
|
||||||
return std::unique_ptr<types::Type>{ ty };
|
returned = std::unique_ptr<types::Type>{ ty };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw std::runtime_error("Expected type name, got " + type_name);
|
throw std::runtime_error("Expected type name, got " + type_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (inner.peek().type == token::Type::Symbol && inner.peek().content == "*") {
|
||||||
|
inner.next();
|
||||||
|
auto ty = new types::PointerType{ std::move(returned) };
|
||||||
|
returned = std::unique_ptr<types::Type>{ ty };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
stream.m_position = inner.m_position;
|
||||||
|
|
||||||
|
return std::move(returned);
|
||||||
}
|
}
|
||||||
catch (std::runtime_error& error) {
|
catch (std::runtime_error& error) {
|
||||||
return std::string{ error.what() };
|
return std::string{ error.what() };
|
||||||
|
|||||||
@ -140,7 +140,7 @@ namespace types {
|
|||||||
|
|
||||||
std::string PointerType::formatted() {
|
std::string PointerType::formatted() {
|
||||||
std::stringstream out{ "" };
|
std::stringstream out{ "" };
|
||||||
out << this->m_inner << "*";
|
out << this->m_inner->formatted() << "*";
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user