mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 08:00:13 +01:00
* global variables * implemented type checking of global variable, added test case * added a comment * improvements based on Dave's suggestions * improvements based on Jon's suggestions * added test cases about global variable ordering
41 lines
1.1 KiB
C++
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 { PrintFunDef(definition); }
|
|
|
|
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 (auto& alternative : alternatives) {
|
|
std::cout << "alt " << alternative.first << " ";
|
|
PrintExp(alternative.second);
|
|
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
|