mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 11:50:13 +01:00
Refactor FunctionDefinition towards instance methods (#654)
It felt weird to have a `Make` method in this case.
This commit is contained in:
@@ -8,32 +8,18 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto MakeFunDef(int line_num, std::string name, const Expression* ret_type,
|
||||
const Expression* param_pattern, const Statement* body)
|
||||
-> FunctionDefinition {
|
||||
FunctionDefinition f;
|
||||
f.line_num = line_num;
|
||||
f.name = std::move(name);
|
||||
f.return_type = ret_type;
|
||||
f.param_pattern = param_pattern;
|
||||
f.body = body;
|
||||
return f;
|
||||
}
|
||||
|
||||
void PrintFunDefDepth(const FunctionDefinition& f, int depth) {
|
||||
std::cout << "fn " << f.name << " ";
|
||||
PrintExp(f.param_pattern);
|
||||
void FunctionDefinition::PrintDepth(int depth) const {
|
||||
std::cout << "fn " << name << " ";
|
||||
PrintExp(param_pattern);
|
||||
std::cout << " -> ";
|
||||
PrintExp(f.return_type);
|
||||
if (f.body) {
|
||||
PrintExp(return_type);
|
||||
if (body) {
|
||||
std::cout << " {" << std::endl;
|
||||
PrintStatement(f.body, depth);
|
||||
PrintStatement(body, depth);
|
||||
std::cout << std::endl << "}" << std::endl;
|
||||
} else {
|
||||
std::cout << ";" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void PrintFunDef(const FunctionDefinition& f) { PrintFunDefDepth(f, -1); }
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user