Files
carbon-lang/executable_semantics/ast/declaration.cpp
T
Jon Meow ef785bb6e3 Refactor FunctionDefinition towards instance methods (#654)
It felt weird to have a `Make` method in this case.
2021-07-15 14:55:44 -07:00

41 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/declaration.h"
#include <iostream>
namespace Carbon {
void FunctionDeclaration::Print() const { definition.Print(); }
void StructDeclaration::Print() const {
std::cout << "struct " << *definition.name << " {" << std::endl;
for (auto& member : *definition.members) {
PrintMember(member);
}
std::cout << "}" << std::endl;
}
void ChoiceDeclaration::Print() const {
std::cout << "choice " << name << " {" << std::endl;
for (const auto& [name, signature] : alternatives) {
std::cout << "alt " << name << " ";
PrintExp(signature);
std::cout << ";" << std::endl;
}
std::cout << "}" << std::endl;
}
// Print a global variable declaration to standard out.
void VariableDeclaration::Print() const {
std::cout << "var ";
PrintExp(type);
std::cout << " : " << name << " = ";
PrintExp(initializer);
std::cout << std::endl;
}
} // namespace Carbon