Support parsing namespace declarations (#2563)

Initial support for parsing namespace declarations and referring to namespace names. No support for declaring members of namespaces yet.
This commit is contained in:
Richard Smith
2023-01-30 17:25:44 -08:00
committed by GitHub
parent a7916c57fe
commit 60af531f5b
22 changed files with 214 additions and 21 deletions
+9
View File
@@ -15,6 +15,10 @@ Declaration::~Declaration() = default;
void Declaration::Print(llvm::raw_ostream& out) const {
switch (kind()) {
case DeclarationKind::NamespaceDeclaration:
PrintID(out);
out << ";";
break;
case DeclarationKind::InterfaceDeclaration:
case DeclarationKind::ConstraintDeclaration: {
const auto& iface_decl = cast<ConstraintTypeDeclaration>(*this);
@@ -126,6 +130,9 @@ void Declaration::Print(llvm::raw_ostream& out) const {
void Declaration::PrintID(llvm::raw_ostream& out) const {
switch (kind()) {
case DeclarationKind::NamespaceDeclaration:
out << "namespace " << cast<NamespaceDeclaration>(*this).name();
break;
case DeclarationKind::InterfaceDeclaration: {
const auto& iface_decl = cast<InterfaceDeclaration>(*this);
out << "interface " << iface_decl.name();
@@ -221,6 +228,8 @@ void Declaration::PrintID(llvm::raw_ostream& out) const {
auto GetName(const Declaration& declaration)
-> std::optional<std::string_view> {
switch (declaration.kind()) {
case DeclarationKind::NamespaceDeclaration:
return cast<NamespaceDeclaration>(declaration).name();
case DeclarationKind::FunctionDeclaration:
return cast<FunctionDeclaration>(declaration).name();
case DeclarationKind::DestructorDeclaration: