Skip to content

Commit

Permalink
Replace Linemap::unknown_location with UNKNOWN_LOCATION
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* rust-linemap.h (Linemap::unknown_location): Remove.
	* ast/rust-ast.cc:
	Replace Linemap::unknown_location with UNKNOWN_LOCATION.
	* ast/rust-path.cc: Likewise.
	* hir/tree/rust-hir.cc: Likewise.
	* metadata/rust-imports.cc: Likewise.
	* parse/rust-parse-impl.h: Likewise.
	* parse/rust-parse.h: Likewise.
	* rust-backend.h: Likewise.
	* rust-diagnostics.cc: Likewise.
	* rust-session-manager.cc: Likewise.
	* typecheck/rust-tyty.cc: Likewise.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 authored and CohenArthur committed Jul 10, 2023
1 parent a06cec1 commit 1fe255e
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 77 deletions.
15 changes: 7 additions & 8 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3610,8 +3610,7 @@ AttributeParser::parse_meta_item_inner ()
new MetaListPaths (ident, ident_locus, std::move (path_items)));
}

rust_error_at (Linemap::unknown_location (),
"failed to parse any meta item inner");
rust_error_at (UNKNOWN_LOCATION, "failed to parse any meta item inner");
return nullptr;
}

Expand Down Expand Up @@ -3905,7 +3904,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const
{
/* HACK: convert vector platform-dependent size_type to string to
* use in printf */
rust_error_at (Linemap::unknown_location (),
rust_error_at (UNKNOWN_LOCATION,
"cfg predicate could not be checked for "
"MetaListNameValueStr with ident of "
"'not' because there are '%s' elements, not '1'",
Expand All @@ -3917,7 +3916,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const
}
else
{
rust_error_at (Linemap::unknown_location (),
rust_error_at (UNKNOWN_LOCATION,
"cfg predicate could not be checked for "
"MetaListNameValueStr with ident of "
"'%s' - ident must be 'all' or 'any'",
Expand Down Expand Up @@ -3953,7 +3952,7 @@ MetaListPaths::check_cfg_predicate (const Session &session) const
{
// HACK: convert vector platform-dependent size_type to string to
// use in printf
rust_error_at (Linemap::unknown_location (),
rust_error_at (UNKNOWN_LOCATION,
"cfg predicate could not be checked for MetaListPaths "
"with ident of 'not' "
"because there are '%s' elements, not '1'",
Expand All @@ -3965,7 +3964,7 @@ MetaListPaths::check_cfg_predicate (const Session &session) const
}
else
{
rust_error_at (Linemap::unknown_location (),
rust_error_at (UNKNOWN_LOCATION,
"cfg predicate could not be checked for "
"MetaListNameValueStr with ident of "
"'%s' - ident must be 'all' or 'any'",
Expand Down Expand Up @@ -4008,7 +4007,7 @@ MetaItemSeq::check_cfg_predicate (const Session &session) const
{
/* HACK: convert vector platform-dependent size_type to string to
* use in printf */
rust_error_at (Linemap::unknown_location (),
rust_error_at (UNKNOWN_LOCATION,
"cfg predicate could not be checked for MetaItemSeq "
"with ident of 'not' "
"because there are '%s' elements, not '1'",
Expand All @@ -4021,7 +4020,7 @@ MetaItemSeq::check_cfg_predicate (const Session &session) const
else
{
rust_error_at (
Linemap::unknown_location (),
UNKNOWN_LOCATION,
"cfg predicate could not be checked for MetaItemSeq with path of "
"'%s' - path must be 'all' or 'any'",
path.as_string ().c_str ());
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/ast/rust-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const
}

// kind of a HACK to get locus depending on opening scope resolution
Location locus = Linemap::unknown_location ();
Location locus = UNKNOWN_LOCATION;
if (with_opening_scope_resolution)
locus = simple_segments[0].get_locus () - 2; // minus 2 chars for ::
else
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/hir/tree/rust-hir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const
}

// kind of a HACK to get locus depending on opening scope resolution
Location locus = Linemap::unknown_location ();
Location locus = UNKNOWN_LOCATION;
if (with_opening_scope_resolution)
{
locus = simple_segments[0].get_locus () - 2; // minus 2 chars for ::
Expand Down
8 changes: 4 additions & 4 deletions gcc/rust/metadata/rust-imports.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Stream_from_file::Stream_from_file (int fd) : fd_ (fd), data_ ()
{
if (lseek (fd, 0, SEEK_SET) != 0)
{
rust_fatal_error (Linemap::unknown_location (), "lseek failed: %m");
rust_fatal_error (UNKNOWN_LOCATION, "lseek failed: %m");
this->set_saw_error ();
}
}
Expand All @@ -399,15 +399,15 @@ Stream_from_file::do_peek (size_t length, const char **bytes)
if (got < 0)
{
if (!this->saw_error ())
rust_fatal_error (Linemap::unknown_location (), "read failed: %m");
rust_fatal_error (UNKNOWN_LOCATION, "read failed: %m");
this->set_saw_error ();
return false;
}

if (lseek (this->fd_, -got, SEEK_CUR) < 0)
{
if (!this->saw_error ())
rust_fatal_error (Linemap::unknown_location (), "lseek failed: %m");
rust_fatal_error (UNKNOWN_LOCATION, "lseek failed: %m");
this->set_saw_error ();
return false;
}
Expand All @@ -427,7 +427,7 @@ Stream_from_file::do_advance (size_t skip)
if (lseek (this->fd_, skip, SEEK_CUR) < 0)
{
if (!this->saw_error ())
rust_fatal_error (Linemap::unknown_location (), "lseek failed: %m");
rust_fatal_error (UNKNOWN_LOCATION, "lseek failed: %m");
this->set_saw_error ();
}
if (!this->data_.empty ())
Expand Down
52 changes: 27 additions & 25 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ AST::SimplePath
Parser<ManagedTokenSource>::parse_simple_path ()
{
bool has_opening_scope_resolution = false;
Location locus = Linemap::unknown_location ();
Location locus = UNKNOWN_LOCATION;

// don't parse anything if not a path upfront
if (!is_simple_path_segment (lexer.peek_token ()->get_id ())
Expand All @@ -628,7 +628,7 @@ Parser<ManagedTokenSource>::parse_simple_path ()
AST::SimplePathSegment segment = parse_simple_path_segment ();

// get location if not gotten already
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
locus = segment.get_locus ();

std::vector<AST::SimplePathSegment> segments;
Expand Down Expand Up @@ -6764,7 +6764,7 @@ template <typename ManagedTokenSource>
AST::PathInExpression
Parser<ManagedTokenSource>::parse_path_in_expression ()
{
Location locus = Linemap::unknown_location ();
Location locus = UNKNOWN_LOCATION;
bool has_opening_scope_resolution = false;
if (lexer.peek_token ()->get_id () == SCOPE_RESOLUTION)
{
Expand All @@ -6778,7 +6778,7 @@ Parser<ManagedTokenSource>::parse_path_in_expression ()
// create segment vector
std::vector<AST::PathExprSegment> segments;

if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
}
Expand Down Expand Up @@ -6949,7 +6949,7 @@ Parser<ManagedTokenSource>::parse_qualified_path_type (
Location locus = pratt_parsed_loc;
/* TODO: should this actually be error? is there anywhere where this could
* be valid? */
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();

Expand Down Expand Up @@ -7381,7 +7381,7 @@ Parser<ManagedTokenSource>::parse_block_expr (AST::AttrVec outer_attrs,
Location pratt_parsed_loc)
{
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
if (!skip_token (LEFT_CURLY))
Expand Down Expand Up @@ -7685,7 +7685,7 @@ Parser<ManagedTokenSource>::parse_return_expr (AST::AttrVec outer_attrs,
Location pratt_parsed_loc)
{
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
skip_token (RETURN_TOK);
Expand All @@ -7710,7 +7710,7 @@ Parser<ManagedTokenSource>::parse_break_expr (AST::AttrVec outer_attrs,
Location pratt_parsed_loc)
{
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
skip_token (BREAK);
Expand Down Expand Up @@ -7741,7 +7741,7 @@ Parser<ManagedTokenSource>::parse_continue_expr (AST::AttrVec outer_attrs,
Location pratt_parsed_loc)
{
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
skip_token (CONTINUE);
Expand Down Expand Up @@ -7792,7 +7792,7 @@ Parser<ManagedTokenSource>::parse_if_expr (AST::AttrVec outer_attrs,
{
// TODO: make having outer attributes an error?
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
if (!skip_token (IF))
Expand Down Expand Up @@ -7950,7 +7950,7 @@ Parser<ManagedTokenSource>::parse_if_let_expr (AST::AttrVec outer_attrs,
{
// TODO: make having outer attributes an error?
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
if (!skip_token (IF))
Expand Down Expand Up @@ -8136,7 +8136,7 @@ Parser<ManagedTokenSource>::parse_loop_expr (AST::AttrVec outer_attrs,
Location pratt_parsed_loc)
{
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
if (label.is_error ())
locus = lexer.peek_token ()->get_locus ();
Expand Down Expand Up @@ -8180,7 +8180,7 @@ Parser<ManagedTokenSource>::parse_while_loop_expr (AST::AttrVec outer_attrs,
Location pratt_parsed_loc)
{
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
if (label.is_error ())
locus = lexer.peek_token ()->get_locus ();
Expand Down Expand Up @@ -8251,7 +8251,7 @@ std::unique_ptr<AST::WhileLetLoopExpr>
Parser<ManagedTokenSource>::parse_while_let_loop_expr (AST::AttrVec outer_attrs,
AST::LoopLabel label)
{
Location locus = Linemap::unknown_location ();
Location locus = UNKNOWN_LOCATION;
if (label.is_error ())
locus = lexer.peek_token ()->get_locus ();
else
Expand Down Expand Up @@ -8325,7 +8325,7 @@ std::unique_ptr<AST::ForLoopExpr>
Parser<ManagedTokenSource>::parse_for_loop_expr (AST::AttrVec outer_attrs,
AST::LoopLabel label)
{
Location locus = Linemap::unknown_location ();
Location locus = UNKNOWN_LOCATION;
if (label.is_error ())
locus = lexer.peek_token ()->get_locus ();
else
Expand Down Expand Up @@ -8456,7 +8456,7 @@ Parser<ManagedTokenSource>::parse_match_expr (AST::AttrVec outer_attrs,
Location pratt_parsed_loc)
{
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
skip_token (MATCH_TOK);
Expand Down Expand Up @@ -8742,7 +8742,7 @@ Parser<ManagedTokenSource>::parse_unsafe_block_expr (AST::AttrVec outer_attrs,
Location pratt_parsed_loc)
{
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
skip_token (UNSAFE);
Expand Down Expand Up @@ -8773,7 +8773,7 @@ Parser<ManagedTokenSource>::parse_array_expr (AST::AttrVec outer_attrs,
Location pratt_parsed_loc)
{
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
skip_token (LEFT_SQUARE);
Expand Down Expand Up @@ -8959,7 +8959,7 @@ Parser<ManagedTokenSource>::parse_grouped_or_tuple_expr (
{
// adjustment to allow Pratt parsing to reuse function without copy-paste
Location locus = pratt_parsed_loc;
if (locus == Linemap::unknown_location ())
if (locus == UNKNOWN_LOCATION)
{
locus = lexer.peek_token ()->get_locus ();
skip_token (LEFT_PAREN);
Expand Down Expand Up @@ -10682,9 +10682,10 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt ()
std::unique_ptr<AST::RangePatternBound> upper_bound
= parse_range_pattern_bound ();

return std::unique_ptr<AST::RangePattern> (new AST::RangePattern (
std::move (lower_bound), std::move (upper_bound),
Linemap::unknown_location (), has_ellipsis_syntax));
return std::unique_ptr<AST::RangePattern> (
new AST::RangePattern (std::move (lower_bound),
std::move (upper_bound),
UNKNOWN_LOCATION, has_ellipsis_syntax));
}
case EXCLAM:
return parse_macro_invocation_partial (std::move (path),
Expand Down Expand Up @@ -11221,9 +11222,10 @@ Parser<ManagedTokenSource>::parse_ident_leading_pattern ()
std::unique_ptr<AST::RangePatternBound> upper_bound
= parse_range_pattern_bound ();

return std::unique_ptr<AST::RangePattern> (new AST::RangePattern (
std::move (lower_bound), std::move (upper_bound),
Linemap::unknown_location (), has_ellipsis_syntax));
return std::unique_ptr<AST::RangePattern> (
new AST::RangePattern (std::move (lower_bound),
std::move (upper_bound), UNKNOWN_LOCATION,
has_ellipsis_syntax));
}
case PATTERN_BIND: {
// only allow on single-segment paths
Expand Down
Loading

0 comments on commit 1fe255e

Please sign in to comment.