Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
powerboat9 committed Feb 27, 2024
1 parent ad28a90 commit 7612f78
Show file tree
Hide file tree
Showing 27 changed files with 508 additions and 165 deletions.
4 changes: 4 additions & 0 deletions gcc/rust/ast/rust-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,8 @@ class EnumItemDiscriminant : public EnumItem

void accept_vis (ASTVisitor &vis) override;

bool has_expr () { return expression != nullptr; }

// TODO: is this better? Or is a "vis_block" better?
std::unique_ptr<Expr> &get_expr ()
{
Expand Down Expand Up @@ -3434,6 +3436,8 @@ class NamedFunctionParam
* '_'). */
bool has_name () const { return name != "_" && name != ""; }

bool has_type () const { return param_type != nullptr; }

bool has_outer_attrs () const { return !outer_attrs.empty (); }

// Returns whether the named function parameter is in an error state.
Expand Down
5 changes: 5 additions & 0 deletions gcc/rust/ast/rust-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,11 @@ class MacroRulesDefinition : public VisItem

MacroKind get_kind () const { return kind; }

std::unique_ptr<MacroRulesDefinition> clone_macro_rules_def () const
{
return std::unique_ptr<MacroRulesDefinition> (clone_item_impl ());
}

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/expand/rust-macro-builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ std::unordered_map<std::string, AST::MacroTranscriberFunc>
{"test_case", MacroBuiltin::sorry},
{"global_allocator", MacroBuiltin::sorry},
{"cfg_accessible", MacroBuiltin::sorry},
{"rustc_const_stable", MacroBuiltin::sorry},
{"rustc_const_unstable", MacroBuiltin::sorry},
/* Derive builtins do not need a real transcriber, but still need one. It
should however never be called since builtin derive macros get expanded
differently, and benefit from knowing on what kind of items they are
Expand Down
49 changes: 29 additions & 20 deletions gcc/rust/hir/rust-ast-lower-pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,39 @@ ASTLoweringPattern::visit (AST::TupleStructPattern &pattern)
= ASTLowerPathInExpression::translate (&pattern.get_path ());

TupleStructItems *lowered = nullptr;
auto &items = pattern.get_items ();
switch (items->get_item_type ())

if (pattern.has_items ())
{
case AST::TupleStructItems::RANGE: {
// TODO
rust_unreachable ();
}
break;
auto &items = pattern.get_items ();
switch (items->get_item_type ())
{
case AST::TupleStructItems::RANGE: {
// TODO
rust_unreachable ();
}
break;

case AST::TupleStructItems::NO_RANGE: {
AST::TupleStructItemsNoRange &items_no_range
= static_cast<AST::TupleStructItemsNoRange &> (*items.get ());
case AST::TupleStructItems::NO_RANGE: {
AST::TupleStructItemsNoRange &items_no_range
= static_cast<AST::TupleStructItemsNoRange &> (*items.get ());

std::vector<std::unique_ptr<HIR::Pattern>> patterns;
for (auto &inner_pattern : items_no_range.get_patterns ())
{
HIR::Pattern *p
= ASTLoweringPattern::translate (inner_pattern.get ());
patterns.push_back (std::unique_ptr<HIR::Pattern> (p));
}
std::vector<std::unique_ptr<HIR::Pattern>> patterns;
for (auto &inner_pattern : items_no_range.get_patterns ())
{
HIR::Pattern *p
= ASTLoweringPattern::translate (inner_pattern.get ());
patterns.push_back (std::unique_ptr<HIR::Pattern> (p));
}

lowered = new HIR::TupleStructItemsNoRange (std::move (patterns));
}
break;
lowered = new HIR::TupleStructItemsNoRange (std::move (patterns));
}
break;
}
}
else
{
std::vector<std::unique_ptr<HIR::Pattern>> patterns;
lowered = new HIR::TupleStructItemsNoRange (std::move (patterns));
}

auto crate_num = mappings->get_current_crate ();
Expand Down
6 changes: 5 additions & 1 deletion gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10635,8 +10635,12 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt ()
if (lexer.peek_token ()->get_id () == RIGHT_PAREN)
{
lexer.skip_token ();
std::unique_ptr<AST::TupleStructItems> items (
new AST::TupleStructItemsNoRange (
std::vector<std::unique_ptr<AST::Pattern>> ()));
return std::unique_ptr<AST::TupleStructPattern> (
new AST::TupleStructPattern (std::move (path), nullptr));
new AST::TupleStructPattern (std::move (path),
std::move (items)));
}

// parse items
Expand Down
3 changes: 3 additions & 0 deletions gcc/rust/resolve/rust-ast-resolve-pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ PatternDeclaration::visit (AST::TupleStructPattern &pattern)
{
ResolvePath::go (&pattern.get_path ());

if (!pattern.has_items ())
return;

std::unique_ptr<AST::TupleStructItems> &items = pattern.get_items ();
switch (items->get_item_type ())
{
Expand Down
Loading

0 comments on commit 7612f78

Please sign in to comment.