Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore ast tree delegate #3297

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions gcc/rust/ast/rust-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -3197,19 +3197,18 @@ class TraitImpl : public Impl
trait_path (std::move (trait_path)), impl_items (std::move (impl_items))
{}

// Helper constructor with a typepath
// Delegating constructor for TypePath
TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam,
std::vector<std::unique_ptr<AssociatedItem>> impl_items,
std::vector<std::unique_ptr<GenericParam>> generic_params,
std::unique_ptr<Type> trait_type, WhereClause where_clause,
Visibility vis, std::vector<Attribute> inner_attrs,
std::vector<Attribute> outer_attrs, location_t locus)
: Impl (std::move (generic_params), std::move (trait_type),
std::move (where_clause), std::move (vis), std::move (inner_attrs),
std::move (outer_attrs), locus),
has_unsafe (is_unsafe), has_exclam (has_exclam),
trait_path (std::unique_ptr<TypePath> (new TypePath (trait_path))),
impl_items (std::move (impl_items))
: TraitImpl (std::unique_ptr<Path> (new TypePath (trait_path)), is_unsafe,
has_exclam, std::move (impl_items), std::move (generic_params),
std::move (trait_type), std::move (where_clause),
std::move (vis), std::move (inner_attrs),
std::move (outer_attrs), locus)
{}

// Copy constructor with vector clone
Expand Down
17 changes: 17 additions & 0 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12023,6 +12023,11 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power,
if (restrictions.expr_can_be_null)
{
TokenId id = current_token->get_id ();
if (restrictions.stop_on_token && (id == MATCH_ARROW || id == COMMA))
{
rust_debug ("Stopping Parsing at special token");
return nullptr;
}
if (id == SEMICOLON || id == RIGHT_PAREN || id == RIGHT_CURLY
|| id == RIGHT_SQUARE || id == COMMA || id == LEFT_CURLY)
return nullptr;
Expand Down Expand Up @@ -12078,6 +12083,12 @@ Parser<ManagedTokenSource>::left_denotations (std::unique_ptr<AST::Expr> expr,
while (right_binding_power < left_binding_power (current_token))
{
lexer.skip_token ();
if (restrictions.stop_on_token
&& (current_token->get_id() == MATCH_ARROW || current_token->get_id() == COMMA))
{
rust_debug ("Stopping parsing at restricted token in left_denotations");
return expr;
}

// FIXME attributes should generally be applied to the null denotation.
expr = left_denotation (current_token, std::move (expr),
Expand Down Expand Up @@ -12115,6 +12126,12 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
{
/* note: tok is previous character in input stream, not current one, as
* parse_expr skips it before passing it in */

if (restrictions.stop_on_token && (tok->get_id() == MATCH_ARROW || tok->get_id() == COMMA))
{
rust_debug("Stopping parsing at restricted token in null_denotation");
return nullptr;
}

/* as a Pratt parser (which works by decomposing expressions into a null
* denotation and then a left denotation), null denotations handle primaries
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/parse/rust-parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct ParseRestrictions
bool entered_from_unary = false;
bool expr_can_be_null = false;
bool expr_can_be_stmt = false;
bool stop_on_token = false; // This is for stopping parsing at a specific token
bool consume_semi = true;
/* Macro invocations that are statements can expand without a semicolon after
* the final statement, if it's an expression statement. */
Expand Down
Loading