mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 10:50:12 +01:00
Note this makes a few cases where the Statement was optional explicit (Block, If, Sequence). I do add a few CHECKs around where statements were optional and assumed but unverified. I switch TypeCheckStmt to not take an optional Statement because I think it makes the call sites clearer in behavior. It's also a smaller change than the converse, because taking an optional Statement means the returned statement would also need to be optional. Arguably a wrapper for optional statements could be added, but this still seems cleaner to me, and there aren't that many cases of an optional statement. Co-authored-by: Geoff Romer <gromer@google.com>
38 lines
914 B
C++
38 lines
914 B
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"
|
|
|
|
namespace Carbon {
|
|
|
|
void FunctionDefinition::PrintDepth(int depth, llvm::raw_ostream& out) const {
|
|
out << "fn " << name << " ";
|
|
if (deduced_parameters.size() > 0) {
|
|
out << "[";
|
|
unsigned int i = 0;
|
|
for (const auto& deduced : deduced_parameters) {
|
|
if (i != 0) {
|
|
out << ", ";
|
|
}
|
|
out << deduced.name << ":! ";
|
|
deduced.type->Print(out);
|
|
++i;
|
|
}
|
|
out << "]";
|
|
}
|
|
out << *param_pattern;
|
|
if (!is_omitted_return_type) {
|
|
out << " -> " << *return_type;
|
|
}
|
|
if (body) {
|
|
out << " {\n";
|
|
(*body)->PrintDepth(depth, out);
|
|
out << "\n}\n";
|
|
} else {
|
|
out << ";\n";
|
|
}
|
|
}
|
|
|
|
} // namespace Carbon
|