Files
carbon-lang/executable_semantics/ast/function_definition.cpp
T
Jeremy G. Siek bf6bb800c4 improve abstraction for AssocList, fix bug in optional else (#315)
* improve abstraction for AssocList, fix bug in optional else

* add flag for tracing output, clean up code for output

* turned off tracing by default, updated goldens, removed two examples that use pointers, shouldn't have been there yet
2021-03-01 10:00:02 -05:00

38 lines
1.1 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "executable_semantics/ast/function_definition.h"
#include <iostream>
namespace Carbon {
auto MakeFunDef(int line_num, std::string name, Expression* ret_type,
Expression* param_pattern, Statement* body)
-> struct FunctionDefinition* {
auto* f = new struct FunctionDefinition();
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 << " " << *f->param_pattern << " -> "
<< *f->return_type;
if (f->body) {
std::cout << " {" << std::endl;
PrintStatement(f->body, depth);
std::cout << std::endl << "}" << std::endl;
} else {
std::cout << ";" << std::endl;
}
}
void PrintFunDef(const FunctionDefinition* f) { PrintFunDefDepth(f, -1); }
} // namespace Carbon