diff --git a/src/parsing.cpp b/src/parsing.cpp index c58aae0..fe9ab2f 100644 --- a/src/parsing.cpp +++ b/src/parsing.cpp @@ -12,26 +12,37 @@ namespace parsing { try { auto token = inner.expect(token::Type::Ident); - stream.m_position = inner.m_position; - // TODO eventually make this be potentially more than one word std::string type_name = token.content; + std::unique_ptr returned{}; + if (type_name == "int") { auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Int }; - return std::unique_ptr{ ty }; + returned = std::unique_ptr{ ty }; } else if (type_name == "char") { auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Char }; - return std::unique_ptr{ ty }; + returned = std::unique_ptr{ ty }; } else if (type_name == "void") { auto ty = new types::FundamentalType{ types::FundamentalTypeKind::Void }; - return std::unique_ptr{ ty }; + returned = std::unique_ptr{ ty }; } else { 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{ ty }; + } + + + stream.m_position = inner.m_position; + + return std::move(returned); } catch (std::runtime_error& error) { return std::string{ error.what() }; diff --git a/src/types.cpp b/src/types.cpp index 0f8194b..3c7928c 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -140,7 +140,7 @@ namespace types { std::string PointerType::formatted() { std::stringstream out{ "" }; - out << this->m_inner << "*"; + out << this->m_inner->formatted() << "*"; return out.str(); } diff --git a/test.c b/test.c index cbfc826..20838a3 100644 --- a/test.c +++ b/test.c @@ -1,4 +1,4 @@ -void printf(char b); +void printf(char* b); int fibonacci(int n) { if (n < 2)