class AstBuilder
{
public:
- AstBuilder (Location loc) : loc (loc) {}
+ AstBuilder (location_t loc) : loc (loc) {}
/* Create an identifier expression (`variable`) */
std::unique_ptr<Expr> identifier (std::string name);
/**
* Location of the generated AST nodes
*/
- Location loc;
+ location_t loc;
};
} // namespace AST
loc (UNDEF_LOCATION)
{}
// Create identifier with dummy location
- Identifier (std::string ident, Location loc = UNDEF_LOCATION)
+ Identifier (std::string ident, location_t loc = UNDEF_LOCATION)
: ident (ident), node_id (Analysis::Mappings::get ()->get_next_node_id ()),
loc (loc)
{}
private:
std::string ident;
NodeId node_id;
- Location loc;
+ location_t loc;
};
std::ostream &
virtual ~MacroMatch () {}
virtual std::string as_string () const = 0;
- virtual Location get_match_locus () const = 0;
+ virtual location_t get_match_locus () const = 0;
// Unique pointer custom clone function
std::unique_ptr<MacroMatch> clone_macro_match () const
}
std::string as_string () const override;
- Location get_match_locus () const override { return tok_ref->get_locus (); };
+ location_t get_match_locus () const override
+ {
+ return tok_ref->get_locus ();
+ };
void accept_vis (ASTVisitor &vis) override;
std::vector<Attribute> inner_attrs;
std::vector<std::unique_ptr<Stmt> > statements;
std::unique_ptr<Expr> expr;
- Location start_locus;
- Location end_locus;
+ location_t start_locus;
+ location_t end_locus;
bool marked_for_strip = false;
public:
BlockExpr (std::vector<std::unique_ptr<Stmt> > block_statements,
std::unique_ptr<Expr> block_expr,
std::vector<Attribute> inner_attribs,
- std::vector<Attribute> outer_attribs, Location start_locus,
- Location end_locus)
+ std::vector<Attribute> outer_attribs, location_t start_locus,
+ location_t end_locus)
: outer_attrs (std::move (outer_attribs)),
inner_attrs (std::move (inner_attribs)),
statements (std::move (block_statements)), expr (std::move (block_expr)),
location_t get_locus () const override final { return start_locus; }
- Location get_start_locus () const { return start_locus; }
- Location get_end_locus () const { return end_locus; }
+ location_t get_start_locus () const { return start_locus; }
+ location_t get_end_locus () const { return end_locus; }
void accept_vis (ASTVisitor &vis) override;
{
// as gccrs still doesen't contain a symbol class I have put them as strings
std::string symbol;
- Location loc;
+ location_t loc;
};
struct TupleTemplateStr
// as gccrs still doesen't contain a symbol class I have put them as strings
std::string symbol;
std::string optional_symbol;
- Location loc;
+ location_t loc;
};
// Inline Assembly Node
std::vector<InlineAsmOperand> operands;
TupleClobber clobber_abi;
InlineAsmOptions options;
- std::vector<Location> line_spans;
+ std::vector<location_t> line_spans;
};
} // namespace AST
// Creates a public visibility with no further features/arguments.
// empty?
- static Visibility create_public (Location pub_vis_location)
+ static Visibility create_public (location_t pub_vis_location)
{
return Visibility (PUB, SimplePath::create_empty (), pub_vis_location);
}
// Creates a public visibility with crate-relative paths
- static Visibility create_crate (Location crate_tok_location,
- Location crate_vis_location)
+ static Visibility create_crate (location_t crate_tok_location,
+ location_t crate_vis_location)
{
return Visibility (PUB_CRATE,
SimplePath::from_str ("crate", crate_tok_location),
}
// Creates a public visibility with self-relative paths
- static Visibility create_self (Location self_tok_location,
- Location self_vis_location)
+ static Visibility create_self (location_t self_tok_location,
+ location_t self_vis_location)
{
return Visibility (PUB_SELF,
SimplePath::from_str ("self", self_tok_location),
}
// Creates a public visibility with parent module-relative paths
- static Visibility create_super (Location super_tok_location,
- Location super_vis_location)
+ static Visibility create_super (location_t super_tok_location,
+ location_t super_vis_location)
{
return Visibility (PUB_SUPER,
SimplePath::from_str ("super", super_tok_location),
// Creates a public visibility with a given path or whatever.
static Visibility create_in_path (SimplePath in_path,
- Location in_path_vis_location)
+ location_t in_path_vis_location)
{
return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location);
}
}
std::string as_string () const override;
- Location get_match_locus () const override { return locus; };
+ location_t get_match_locus () const override { return locus; };
void accept_vis (ASTVisitor &vis) override;
MacroMatchRepetition &operator= (MacroMatchRepetition &&other) = default;
std::string as_string () const override;
- Location get_match_locus () const override { return locus; };
+ location_t get_match_locus () const override { return locus; };
void accept_vis (ASTVisitor &vis) override;
// Returns whether MacroMatcher is in an error state.
bool is_error () const { return is_invalid; }
- Location get_match_locus () const override { return locus; }
+ location_t get_match_locus () const override { return locus; }
std::string as_string () const override;
std::vector<MacroRule> rules; // inlined form
location_t locus;
- std::function<Fragment (Location, MacroInvocData &)> associated_transcriber;
+ std::function<Fragment (location_t, MacroInvocData &)> associated_transcriber;
// Since we can't compare std::functions, we need to use an extra boolean
bool is_builtin_rule;
MacroKind kind;
* should make use of the actual rules. If the macro is builtin, then another
* associated transcriber should be used
*/
- static Fragment dummy_builtin (Location, MacroInvocData &)
+ static Fragment dummy_builtin (location_t, MacroInvocData &)
{
rust_unreachable ();
return Fragment::create_error ();
kind (kind)
{}
- MacroRulesDefinition (
- Identifier builtin_name, DelimType delim_type,
- std::function<Fragment (Location, MacroInvocData &)> associated_transcriber,
- MacroKind kind, Visibility vis)
+ MacroRulesDefinition (Identifier builtin_name, DelimType delim_type,
+ std::function<Fragment (location_t, MacroInvocData &)>
+ associated_transcriber,
+ MacroKind kind, Visibility vis)
: VisItem (std::move (vis), std::vector<Attribute> ()),
outer_attrs (std::vector<Attribute> ()), rule_name (builtin_name),
delim_type (delim_type), rules (std::vector<MacroRule> ()),
const std::vector<MacroRule> &get_rules () const { return rules; }
bool is_builtin () const { return is_builtin_rule; }
- const std::function<Fragment (Location, MacroInvocData &)> &
+ const std::function<Fragment (location_t, MacroInvocData &)> &
get_builtin_transcriber () const
{
rust_assert (is_builtin ());
return associated_transcriber;
}
void set_builtin_transcriber (
- std::function<Fragment (Location, MacroInvocData &)> transcriber)
+ std::function<Fragment (location_t, MacroInvocData &)> transcriber)
{
associated_transcriber = transcriber;
is_builtin_rule = true;
class MetaWord : public MetaItem
{
Identifier ident;
- Location ident_locus;
+ location_t ident_locus;
public:
- MetaWord (Identifier ident, Location ident_locus)
+ MetaWord (Identifier ident, location_t ident_locus)
: ident (std::move (ident)), ident_locus (ident_locus)
{}
class MetaNameValueStr : public MetaItem
{
Identifier ident;
- Location ident_locus;
+ location_t ident_locus;
// NOTE: str stored without quotes
std::string str;
- Location str_locus;
+ location_t str_locus;
public:
- MetaNameValueStr (Identifier ident, Location ident_locus, std::string str,
- Location str_locus)
+ MetaNameValueStr (Identifier ident, location_t ident_locus, std::string str,
+ location_t str_locus)
: ident (std::move (ident)), ident_locus (ident_locus),
str (std::move (str)), str_locus (str_locus)
{}
class MetaListPaths : public MetaItem
{
Identifier ident;
- Location ident_locus;
+ location_t ident_locus;
std::vector<SimplePath> paths;
public:
- MetaListPaths (Identifier ident, Location ident_locus,
+ MetaListPaths (Identifier ident, location_t ident_locus,
std::vector<SimplePath> paths)
: ident (std::move (ident)), ident_locus (ident_locus),
paths (std::move (paths))
class MetaListNameValueStr : public MetaItem
{
Identifier ident;
- Location ident_locus;
+ location_t ident_locus;
std::vector<MetaNameValueStr> strs;
public:
- MetaListNameValueStr (Identifier ident, Location ident_locus,
+ MetaListNameValueStr (Identifier ident, location_t ident_locus,
std::vector<MetaNameValueStr> strs)
: ident (std::move (ident)), ident_locus (ident_locus),
strs (std::move (strs))
bool is_error () const { return kind == Kind::Error; }
Kind get_kind () const { return kind; }
- const Location &get_locus () const { return locus; }
+ location_t get_locus () const { return locus; }
void accept_vis (AST::ASTVisitor &visitor)
{
std::vector<std::unique_ptr<Stmt> > statements;
std::unique_ptr<Expr> expr;
bool tail_reachable;
- Location start_locus;
- Location end_locus;
+ location_t start_locus;
+ location_t end_locus;
std::string as_string () const override;
std::vector<std::unique_ptr<Stmt> > block_statements,
std::unique_ptr<Expr> block_expr, bool tail_reachable,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- Location start_locus, Location end_locus)
+ location_t start_locus, location_t end_locus)
: ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
WithInnerAttrs (std::move (inner_attribs)),
statements (std::move (block_statements)), expr (std::move (block_expr)),
location_t get_locus () const override final { return start_locus; }
- Location get_start_locus () const { return start_locus; }
+ location_t get_start_locus () const { return start_locus; }
- Location get_end_locus () const { return end_locus; }
+ location_t get_end_locus () const { return end_locus; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
std::vector<AST::TupleTemplateStr> template_strs;
std::vector<AST::InlineAsmOperand> operands;
AST::InlineAsmOptions options;
- std::vector<Location> line_spans;
+ std::vector<location_t> line_spans;
};
} // namespace HIR
} // namespace Rust
return outer_attrs;
}
- Location get_trait_locus () const override { return get_locus (); }
+ location_t get_trait_locus () const override { return get_locus (); }
protected:
// Clone function implementation as (not pure) virtual method
return outer_attrs;
}
- Location get_trait_locus () const override { return get_locus (); }
+ location_t get_trait_locus () const override { return get_locus (); }
protected:
// Clone function implementation as (not pure) virtual method
return outer_attrs;
}
- Location get_trait_locus () const override { return get_locus (); }
+ location_t get_trait_locus () const override { return get_locus (); }
protected:
// Clone function implementation as (not pure) virtual method
bool is_error () const { return segments.empty (); }
const Analysis::NodeMapping &get_mappings () const { return mappings; }
- const Location &get_locus () const { return locus; }
+ location_t get_locus () const { return locus; }
};
} // namespace HIR
const Analysis::NodeMapping &get_mappings () const { return mappings; }
- virtual Location get_trait_locus () const = 0;
+ virtual location_t get_trait_locus () const = 0;
virtual TraitItemKind get_item_kind () const = 0;
return raw_input_source->is_valid ();
}
-Location
+location_t
Lexer::get_current_location ()
{
if (line_map)
tok = peek_token ();
found_eof |= tok->get_id () == Rust::END_OF_FILE;
- Location loc = tok->get_locus ();
+ location_t loc = tok->get_locus ();
out << "<id=";
out << tok->token_id_to_str ();
// loop to go through multiple characters to build a single token
while (true)
{
- Location loc = get_current_location ();
+ location_t loc = get_current_location ();
current_char = peek_input ();
skip_input ();
// Parses a byte character.
TokenPtr
-Lexer::parse_byte_char (Location loc)
+Lexer::parse_byte_char (location_t loc)
{
skip_input ();
current_column++;
// Parses a byte string.
TokenPtr
-Lexer::parse_byte_string (Location loc)
+Lexer::parse_byte_string (location_t loc)
{
// byte string
// Parses a raw byte string.
TokenPtr
-Lexer::parse_raw_byte_string (Location loc)
+Lexer::parse_raw_byte_string (location_t loc)
{
// raw byte string literals
std::string str;
// Parses a raw identifier.
TokenPtr
-Lexer::parse_raw_identifier (Location loc)
+Lexer::parse_raw_identifier (location_t loc)
{
// raw identifier
std::string str;
// Parses a string.
TokenPtr
-Lexer::parse_string (Location loc)
+Lexer::parse_string (location_t loc)
{
std::string str;
str.reserve (16); // some sensible default
// Parses an identifier or keyword.
TokenPtr
-Lexer::parse_identifier_or_keyword (Location loc)
+Lexer::parse_identifier_or_keyword (location_t loc)
{
std::string str;
str.reserve (16); // default
// Possibly returns a raw string token if it exists - otherwise returns null.
TokenPtr
-Lexer::maybe_parse_raw_string (Location loc)
+Lexer::maybe_parse_raw_string (location_t loc)
{
int peek_index = 0;
while (peek_input (peek_index) == '#')
// Returns a raw string token.
TokenPtr
-Lexer::parse_raw_string (Location loc, int initial_hash_count)
+Lexer::parse_raw_string (location_t loc, int initial_hash_count)
{
// raw string literals
std::string str;
template <typename IsDigitFunc>
TokenPtr
-Lexer::parse_non_decimal_int_literal (Location loc, IsDigitFunc is_digit_func,
+Lexer::parse_non_decimal_int_literal (location_t loc, IsDigitFunc is_digit_func,
std::string existent_str, int base)
{
int length = 1;
// Parses a hex, binary or octal int literal.
TokenPtr
-Lexer::parse_non_decimal_int_literals (Location loc)
+Lexer::parse_non_decimal_int_literals (location_t loc)
{
std::string str;
str.reserve (16); // some sensible default
// Parses a decimal-based int literal or float literal.
TokenPtr
-Lexer::parse_decimal_int_or_float (Location loc)
+Lexer::parse_decimal_int_or_float (location_t loc)
{
std::string str;
str.reserve (16); // some sensible default
}
TokenPtr
-Lexer::parse_char_or_lifetime (Location loc)
+Lexer::parse_char_or_lifetime (location_t loc)
{
int length = 1;
{
/* TODO: assert that this TokenId is a "simple token" like punctuation and not
* like "IDENTIFIER"? */
- Location current_loc = peek_token ()->get_locus ();
+ location_t current_loc = peek_token ()->get_locus ();
TokenPtr new_left_tok = Token::make (new_left, current_loc);
TokenPtr new_right_tok = Token::make (new_right, current_loc + 1);
{
private:
// Request new Location for current column in line_table
- Location get_current_location ();
+ location_t get_current_location ();
// Skips the current input char.
void skip_input ();
void skip_broken_string_input (Codepoint current_char);
- TokenPtr parse_byte_char (Location loc);
- TokenPtr parse_byte_string (Location loc);
- TokenPtr parse_raw_byte_string (Location loc);
- TokenPtr parse_raw_identifier (Location loc);
- TokenPtr parse_string (Location loc);
- TokenPtr maybe_parse_raw_string (Location loc);
- TokenPtr parse_raw_string (Location loc, int initial_hash_count);
- TokenPtr parse_non_decimal_int_literals (Location loc);
- TokenPtr parse_decimal_int_or_float (Location loc);
- TokenPtr parse_char_or_lifetime (Location loc);
- TokenPtr parse_identifier_or_keyword (Location loc);
+ TokenPtr parse_byte_char (location_t loc);
+ TokenPtr parse_byte_string (location_t loc);
+ TokenPtr parse_raw_byte_string (location_t loc);
+ TokenPtr parse_raw_identifier (location_t loc);
+ TokenPtr parse_string (location_t loc);
+ TokenPtr maybe_parse_raw_string (location_t loc);
+ TokenPtr parse_raw_string (location_t loc, int initial_hash_count);
+ TokenPtr parse_non_decimal_int_literals (location_t loc);
+ TokenPtr parse_decimal_int_or_float (location_t loc);
+ TokenPtr parse_char_or_lifetime (location_t loc);
+ TokenPtr parse_identifier_or_keyword (location_t loc);
template <typename IsDigitFunc>
- TokenPtr parse_non_decimal_int_literal (Location loc,
+ TokenPtr parse_non_decimal_int_literal (location_t loc,
IsDigitFunc is_digit_func,
std::string existent_str, int base);