| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
// This file is part of GCC. |
| 4 |
|
| 5 |
// GCC is free software; you can redistribute it and/or modify it under |
| 6 |
// the terms of the GNU General Public License as published by the Free |
| 7 |
// Software Foundation; either version 3, or (at your option) any later |
| 8 |
// version. |
| 9 |
|
| 10 |
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
// for more details. |
| 14 |
|
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with GCC; see the file COPYING3. If not see |
| 17 |
// <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
#include "rust-default-resolver.h" |
| 20 |
#include "rust-ast-full.h" |
| 21 |
#include "rust-ast-visitor.h" |
| 22 |
#include "rust-item.h" |
| 23 |
|
| 24 |
namespace Rust { |
| 25 |
namespace Resolver2_0 { |
| 26 |
|
| 27 |
void |
| 28 |
DefaultResolver::visit (AST::BlockExpr &expr) |
| 29 |
{ |
| 30 |
// extracting the lambda from the `scoped` call otherwise the code looks like |
| 31 |
// a hot turd thanks to our .clang-format |
| 32 |
|
| 33 |
auto inner_fn = [this, &expr] () { AST::DefaultASTVisitor::visit (expr); }; |
| 34 |
|
| 35 |
ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), inner_fn); |
| 36 |
} |
| 37 |
|
| 38 |
void |
| 39 |
DefaultResolver::visit (AST::Module &module) |
| 40 |
{ |
| 41 |
auto item_fn = [this, &module] () { AST::DefaultASTVisitor::visit (module); }; |
| 42 |
|
| 43 |
ctx.scoped (Rib::Kind::Module, module.get_node_id (), item_fn, |
| 44 |
module.get_name ()); |
| 45 |
} |
| 46 |
|
| 47 |
void |
| 48 |
DefaultResolver::visit (AST::Function &function) |
| 49 |
{ |
| 50 |
auto def_fn |
| 51 |
= [this, &function] () { AST::DefaultASTVisitor::visit (function); }; |
| 52 |
|
| 53 |
ctx.scoped (Rib::Kind::Function, function.get_node_id (), def_fn); |
| 54 |
} |
| 55 |
|
| 56 |
void |
| 57 |
DefaultResolver::visit (AST::ForLoopExpr &expr) |
| 58 |
{ |
| 59 |
ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), |
| 60 |
[this, &expr] () { AST::DefaultASTVisitor::visit (expr); }); |
| 61 |
} |
| 62 |
|
| 63 |
void |
| 64 |
DefaultResolver::visit (AST::Trait &trait) |
| 65 |
{ |
| 66 |
auto inner_fn = [this, &trait] () { AST::DefaultASTVisitor::visit (trait); }; |
| 67 |
|
| 68 |
ctx.scoped (Rib::Kind::TraitOrImpl, trait.get_node_id (), inner_fn, |
| 69 |
trait.get_identifier () /* FIXME: Is that valid?*/); |
| 70 |
} |
| 71 |
|
| 72 |
void |
| 73 |
DefaultResolver::visit (AST::InherentImpl &impl) |
| 74 |
{ |
| 75 |
auto inner_fn = [this, &impl] () { AST::DefaultASTVisitor::visit (impl); }; |
| 76 |
|
| 77 |
ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn); |
| 78 |
} |
| 79 |
|
| 80 |
void |
| 81 |
DefaultResolver::visit (AST::TraitImpl &impl) |
| 82 |
{ |
| 83 |
auto inner_fn = [this, &impl] () { AST::DefaultASTVisitor::visit (impl); }; |
| 84 |
|
| 85 |
ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn); |
| 86 |
} |
| 87 |
|
| 88 |
void |
| 89 |
DefaultResolver::visit (AST::StructStruct &type) |
| 90 |
{ |
| 91 |
auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); }; |
| 92 |
|
| 93 |
ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (), |
| 94 |
inner_fn, type.get_struct_name ()); |
| 95 |
} |
| 96 |
|
| 97 |
void |
| 98 |
DefaultResolver::visit (AST::TupleStruct &type) |
| 99 |
{ |
| 100 |
auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); }; |
| 101 |
|
| 102 |
ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (), |
| 103 |
inner_fn, type.get_struct_name ()); |
| 104 |
} |
| 105 |
|
| 106 |
void |
| 107 |
DefaultResolver::visit (AST::Enum &type) |
| 108 |
{ |
| 109 |
auto variant_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); }; |
| 110 |
|
| 111 |
ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (), |
| 112 |
variant_fn, type.get_identifier ()); |
| 113 |
} |
| 114 |
|
| 115 |
void |
| 116 |
DefaultResolver::visit (AST::Union &type) |
| 117 |
{ |
| 118 |
auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); }; |
| 119 |
|
| 120 |
ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (), |
| 121 |
inner_fn, type.get_identifier ()); |
| 122 |
} |
| 123 |
|
| 124 |
void |
| 125 |
DefaultResolver::visit (AST::TypeAlias &type) |
| 126 |
{ |
| 127 |
auto inner_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); }; |
| 128 |
|
| 129 |
ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (), |
| 130 |
inner_fn, type.get_new_type_name ()); |
| 131 |
} |
| 132 |
|
| 133 |
void |
| 134 |
DefaultResolver::visit (AST::ClosureExprInner &expr) |
| 135 |
{ |
| 136 |
if (expr.is_marked_for_strip ()) |
| 137 |
return; |
| 138 |
|
| 139 |
AST::DefaultASTVisitor::visit (expr); |
| 140 |
} |
| 141 |
|
| 142 |
void |
| 143 |
DefaultResolver::visit (AST::ClosureExprInnerTyped &expr) |
| 144 |
{ |
| 145 |
if (expr.is_marked_for_strip ()) |
| 146 |
return; |
| 147 |
|
| 148 |
AST::DefaultASTVisitor::visit (expr); |
| 149 |
} |
| 150 |
|
| 151 |
void |
| 152 |
DefaultResolver::visit (AST::MatchExpr &expr) |
| 153 |
{ |
| 154 |
if (expr.is_marked_for_strip ()) |
| 155 |
return; |
| 156 |
|
| 157 |
AST::DefaultASTVisitor::visit (expr); |
| 158 |
} |
| 159 |
|
| 160 |
void |
| 161 |
DefaultResolver::visit (AST::ConstantItem &item) |
| 162 |
{ |
| 163 |
if (item.has_expr ()) |
| 164 |
{ |
| 165 |
auto expr_vis |
| 166 |
= [this, &item] () { AST::DefaultASTVisitor::visit (item); }; |
| 167 |
|
| 168 |
// FIXME: Why do we need a Rib here? |
| 169 |
ctx.scoped (Rib::Kind::ConstantItem, item.get_node_id (), expr_vis); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
void |
| 174 |
DefaultResolver::visit (AST::StaticItem &item) |
| 175 |
{ |
| 176 |
auto expr_vis = [this, &item] () { AST::DefaultASTVisitor::visit (item); }; |
| 177 |
|
| 178 |
// FIXME: Why do we need a Rib here? |
| 179 |
ctx.scoped (Rib::Kind::ConstantItem, item.get_node_id (), expr_vis); |
| 180 |
} |
| 181 |
|
| 182 |
} // namespace Resolver2_0 |
| 183 |
} // namespace Rust |