Skip to content

Commit 8de68b8

Browse files
committed
stash
1 parent 563e8ed commit 8de68b8

24 files changed

Lines changed: 472 additions & 143 deletions

gcc/rust/ast/rust-item.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,8 @@ class EnumItemDiscriminant : public EnumItem
20812081

20822082
void accept_vis (ASTVisitor &vis) override;
20832083

2084+
bool has_expr () { return expression != nullptr; }
2085+
20842086
// TODO: is this better? Or is a "vis_block" better?
20852087
std::unique_ptr<Expr> &get_expr ()
20862088
{
@@ -3434,6 +3436,8 @@ class NamedFunctionParam
34343436
* '_'). */
34353437
bool has_name () const { return name != "_" && name != ""; }
34363438

3439+
bool has_type () const { return param_type != nullptr; }
3440+
34373441
bool has_outer_attrs () const { return !outer_attrs.empty (); }
34383442

34393443
// Returns whether the named function parameter is in an error state.

gcc/rust/ast/rust-macro.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ class MacroRulesDefinition : public VisItem
579579

580580
MacroKind get_kind () const { return kind; }
581581

582+
std::unique_ptr<MacroRulesDefinition> clone_macro_rules_def () const
583+
{
584+
return std::unique_ptr<MacroRulesDefinition> (clone_item_impl ());
585+
}
586+
582587
protected:
583588
/* Use covariance to implement clone function as returning this object rather
584589
* than base */

gcc/rust/expand/rust-macro-builtins.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ std::unordered_map<std::string, AST::MacroTranscriberFunc>
108108
{"test_case", MacroBuiltin::sorry},
109109
{"global_allocator", MacroBuiltin::sorry},
110110
{"cfg_accessible", MacroBuiltin::sorry},
111+
{"rustc_const_stable", MacroBuiltin::sorry},
112+
{"rustc_const_unstable", MacroBuiltin::sorry},
111113
/* Derive builtins do not need a real transcriber, but still need one. It
112114
should however never be called since builtin derive macros get expanded
113115
differently, and benefit from knowing on what kind of items they are

gcc/rust/hir/rust-ast-lower-pattern.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ ASTLoweringPattern::visit (AST::TupleStructPattern &pattern)
7070
= ASTLowerPathInExpression::translate (&pattern.get_path ());
7171

7272
TupleStructItems *lowered = nullptr;
73+
7374
auto &items = pattern.get_items ();
7475
switch (items->get_item_type ())
7576
{

gcc/rust/resolve/rust-default-resolver.cc

Lines changed: 162 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ DefaultResolver::visit (AST::BlockExpr &expr)
4444
void
4545
DefaultResolver::visit (AST::Module &module)
4646
{
47+
// Parse the module's items if they haven't been expanded and the file
48+
// should be parsed (i.e isn't hidden behind an untrue or impossible cfg
49+
// directive
50+
// TODO: make sure this is right
51+
// This was copied from the old early resolver method
52+
// 'accumulate_escaped_macros'
53+
if (module.get_kind () == AST::Module::UNLOADED)
54+
module.load_items ();
55+
4756
auto item_fn = [this, &module] () {
4857
for (auto &item : module.get_items ())
4958
item->accept_vis (*this);
@@ -62,12 +71,14 @@ DefaultResolver::visit (AST::Function &function)
6271
if (p->is_variadic ())
6372
{
6473
auto param = static_cast<AST::VariadicParam *> (p.get ());
65-
param->get_pattern ()->accept_vis (*this);
74+
if (param->has_pattern ())
75+
param->get_pattern ()->accept_vis (*this);
6676
}
6777
else if (p->is_self ())
6878
{
6979
auto param = static_cast<AST::SelfParam *> (p.get ());
70-
param->get_type ()->accept_vis (*this);
80+
if (param->has_type ())
81+
param->get_type ()->accept_vis (*this);
7182
param->get_lifetime ().accept_vis (*this);
7283
}
7384
else
@@ -78,6 +89,9 @@ DefaultResolver::visit (AST::Function &function)
7889
}
7990
}
8091

92+
if (function.has_return_type ())
93+
function.get_return_type ()->accept_vis (*this);
94+
8195
if (function.has_body ())
8296
function.get_definition ().value ()->accept_vis (*this);
8397
};
@@ -154,6 +168,19 @@ DefaultResolver::visit (AST::StructStruct &type)
154168
// FIXME: ???
155169
}
156170

171+
void
172+
DefaultResolver::visit (AST::TupleStruct &type)
173+
{
174+
// do we need to scope anything here? no, right?
175+
176+
// we also can't visit `StructField`s by default, so there's nothing to do -
177+
// correct? or should we do something like
178+
179+
AST::DefaultASTVisitor::visit (type);
180+
181+
// FIXME: ???
182+
}
183+
157184
void
158185
DefaultResolver::visit (AST::Enum &type)
159186
{
@@ -177,12 +204,43 @@ DefaultResolver::visit (AST::StructExprFieldIndexValue &)
177204
{}
178205

179206
void
180-
DefaultResolver::visit (AST::ClosureExprInner &)
181-
{}
207+
DefaultResolver::visit (AST::ClosureExprInner &expr)
208+
{
209+
if (expr.is_marked_for_strip ())
210+
return;
211+
212+
for (auto &param : expr.get_params ())
213+
{
214+
if (param.is_error ())
215+
continue;
216+
217+
param.get_pattern ()->accept_vis (*this);
218+
if (param.has_type_given ())
219+
param.get_type ()->accept_vis (*this);
220+
}
221+
222+
expr.get_definition_expr ()->accept_vis (*this);
223+
}
182224

183225
void
184-
DefaultResolver::visit (AST::ClosureExprInnerTyped &)
185-
{}
226+
DefaultResolver::visit (AST::ClosureExprInnerTyped &expr)
227+
{
228+
if (expr.is_marked_for_strip ())
229+
return;
230+
231+
for (auto &param : expr.get_params ())
232+
{
233+
if (param.is_error ())
234+
continue;
235+
236+
param.get_pattern ()->accept_vis (*this);
237+
if (param.has_type_given ())
238+
param.get_type ()->accept_vis (*this);
239+
}
240+
241+
expr.get_definition_block ()->accept_vis (*this);
242+
expr.get_return_type ()->accept_vis (*this);
243+
}
186244

187245
void
188246
DefaultResolver::visit (AST::ContinueExpr &expr)
@@ -212,6 +270,36 @@ void
212270
DefaultResolver::visit (AST::ReturnExpr &expr)
213271
{}
214272

273+
void
274+
DefaultResolver::visit (AST::CallExpr &expr)
275+
{
276+
expr.get_function_expr ()->accept_vis (*this);
277+
278+
for (auto &param : expr.get_params ())
279+
param->accept_vis (*this);
280+
}
281+
282+
void
283+
DefaultResolver::visit (AST::MethodCallExpr &expr)
284+
{
285+
expr.get_receiver_expr ()->accept_vis (*this);
286+
287+
if (expr.get_method_name ().has_generic_args ())
288+
{
289+
auto &args = expr.get_method_name ().get_generic_args ();
290+
for (auto &arg : args.get_generic_args ())
291+
arg.accept_vis (*this);
292+
for (auto &arg : args.get_binding_args ())
293+
if (!arg.is_error ())
294+
arg.get_type ()->accept_vis (*this);
295+
for (auto &arg : args.get_lifetime_args ())
296+
arg.accept_vis (*this);
297+
}
298+
299+
for (auto &param : expr.get_params ())
300+
param->accept_vis (*this);
301+
}
302+
215303
void
216304
DefaultResolver::visit (AST::UnsafeBlockExpr &expr)
217305
{}
@@ -230,11 +318,18 @@ DefaultResolver::visit (AST::WhileLetLoopExpr &expr)
230318

231319
void
232320
DefaultResolver::visit (AST::IfExpr &expr)
233-
{}
321+
{
322+
expr.get_condition_expr ()->accept_vis (*this);
323+
expr.get_if_block ()->accept_vis (*this);
324+
}
234325

235326
void
236-
DefaultResolver::visit (AST::IfExprConseqElse &)
237-
{}
327+
DefaultResolver::visit (AST::IfExprConseqElse &expr)
328+
{
329+
expr.get_condition_expr ()->accept_vis (*this);
330+
expr.get_if_block ()->accept_vis (*this);
331+
expr.get_else_block ()->accept_vis (*this);
332+
}
238333

239334
void
240335
DefaultResolver::visit (AST::IfLetExpr &expr)
@@ -246,7 +341,20 @@ DefaultResolver::visit (AST::IfLetExprConseqElse &)
246341

247342
void
248343
DefaultResolver::visit (AST::MatchExpr &expr)
249-
{}
344+
{
345+
if (expr.is_marked_for_strip ())
346+
return;
347+
348+
expr.get_scrutinee_expr ()->accept_vis (*this);
349+
for (auto &arm : expr.get_match_cases ())
350+
{
351+
arm.get_expr ()->accept_vis (*this);
352+
for (auto &pat : arm.get_arm ().get_patterns ())
353+
pat->accept_vis (*this);
354+
if (arm.get_arm ().has_match_arm_guard ())
355+
arm.get_arm ().get_guard_expr ()->accept_vis (*this);
356+
}
357+
}
250358

251359
void
252360
DefaultResolver::visit (AST::AwaitExpr &expr)
@@ -277,8 +385,21 @@ DefaultResolver::visit (AST::ConstGenericParam &)
277385
{}
278386

279387
void
280-
DefaultResolver::visit (AST::PathInExpression &)
281-
{}
388+
DefaultResolver::visit (AST::PathInExpression &expr)
389+
{
390+
for (auto &seg : expr.get_segments ())
391+
if (seg.has_generic_args ())
392+
{
393+
auto &args = seg.get_generic_args ();
394+
for (auto &arg : args.get_generic_args ())
395+
arg.accept_vis (*this);
396+
for (auto &arg : args.get_binding_args ())
397+
if (!arg.is_error ())
398+
arg.get_type ()->accept_vis (*this);
399+
for (auto &arg : args.get_lifetime_args ())
400+
arg.accept_vis (*this);
401+
}
402+
}
282403

283404
void
284405
DefaultResolver::visit (AST::TypePathSegmentGeneric &)
@@ -373,24 +494,34 @@ DefaultResolver::visit (AST::EnumItem &)
373494
{}
374495

375496
void
376-
DefaultResolver::visit (AST::EnumItemTuple &)
377-
{}
497+
DefaultResolver::visit (AST::EnumItemTuple &item)
498+
{
499+
for (auto &field : item.get_tuple_fields ())
500+
field.get_field_type ()->accept_vis (*this);
501+
}
378502

379503
void
380-
DefaultResolver::visit (AST::EnumItemStruct &)
381-
{}
504+
DefaultResolver::visit (AST::EnumItemStruct &item)
505+
{
506+
for (auto &field : item.get_struct_fields ())
507+
field.get_field_type ()->accept_vis (*this);
508+
}
382509

383510
void
384-
DefaultResolver::visit (AST::EnumItemDiscriminant &)
385-
{}
511+
DefaultResolver::visit (AST::EnumItemDiscriminant &item)
512+
{
513+
if (item.has_expr ())
514+
item.get_expr ()->accept_vis (*this);
515+
}
386516

387517
void
388518
DefaultResolver::visit (AST::ConstantItem &item)
389519
{
390520
auto expr_vis = [this, &item] () { item.get_expr ()->accept_vis (*this); };
391521

392522
// FIXME: Why do we need a Rib here?
393-
ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);
523+
if (item.has_expr ())
524+
ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);
394525
}
395526

396527
void
@@ -419,8 +550,18 @@ DefaultResolver::visit (AST::ExternalStaticItem &)
419550
{}
420551

421552
void
422-
DefaultResolver::visit (AST::ExternalFunctionItem &)
423-
{}
553+
DefaultResolver::visit (AST::ExternalFunctionItem &function)
554+
{
555+
auto def_fn = [this, &function] () {
556+
for (auto &p : function.get_function_params ())
557+
if (p.has_type ())
558+
p.get_type ()->accept_vis (*this);
559+
if (function.has_return_type ())
560+
function.get_return_type ()->accept_vis (*this);
561+
};
562+
563+
ctx.scoped (Rib::Kind::Function, function.get_node_id (), def_fn);
564+
}
424565

425566
void
426567
DefaultResolver::visit (AST::MacroMatchRepetition &)

gcc/rust/resolve/rust-default-resolver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class DefaultResolver : public AST::DefaultASTVisitor
5353

5454
// type dec nodes, which visit their fields or variants by default
5555
void visit (AST::StructStruct &);
56+
void visit (AST::TupleStruct &);
5657
void visit (AST::Enum &);
5758

5859
// Visitors that visit their expression node(s)
@@ -67,6 +68,8 @@ class DefaultResolver : public AST::DefaultASTVisitor
6768
void visit (AST::RangeFromToInclExpr &);
6869
void visit (AST::RangeToInclExpr &);
6970
void visit (AST::ReturnExpr &);
71+
void visit (AST::CallExpr &);
72+
void visit (AST::MethodCallExpr &);
7073
void visit (AST::UnsafeBlockExpr &);
7174
void visit (AST::LoopExpr &);
7275
void visit (AST::WhileLoopExpr &);

0 commit comments

Comments
 (0)