Format types as well
This commit is contained in:
parent
87dceb5b7c
commit
316c3aece6
15
src/ast.cpp
15
src/ast.cpp
@ -19,7 +19,10 @@ namespace AST {
|
||||
|
||||
std::string Function::formatted() {
|
||||
std::stringstream out{ "" };
|
||||
out << "Function() {\n";
|
||||
out << this->m_name;
|
||||
out << "() -> ";
|
||||
out << this->m_return_ty->formatted();
|
||||
out << " {\n";
|
||||
for (auto& statement : this->m_statements) {
|
||||
out << " " << statement->formatted() << "\n";
|
||||
}
|
||||
@ -27,4 +30,14 @@ namespace AST {
|
||||
out << "}";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
std::string FundamentalType::formatted() {
|
||||
switch (this->m_ty) {
|
||||
case FundamentalTypeKind::Int:
|
||||
return "Int";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,10 @@ namespace AST {
|
||||
};
|
||||
|
||||
class Expression : public Node {};
|
||||
class Type {};
|
||||
class Type {
|
||||
public:
|
||||
virtual std::string formatted() = 0;
|
||||
};
|
||||
class Statement : public Node {};
|
||||
|
||||
class IntLiteralExpression : public Expression {
|
||||
@ -63,6 +66,7 @@ namespace AST {
|
||||
FundamentalTypeKind m_ty;
|
||||
public:
|
||||
FundamentalType(FundamentalTypeKind kind) : m_ty{ kind } {}
|
||||
virtual std::string formatted() override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user