std::string
source_relative_path (std::string path, Location locus)
{
- std::string compile_fname
- = Session::get_instance ().linemap->location_file (locus);
+ std::string compile_fname = LOCATION_FILE (locus);
auto dir_separator_pos = compile_fname.rfind (file_separator);
AST::Fragment
MacroBuiltin::file_handler (Location invoc_locus, AST::MacroInvocData &)
{
- auto current_file
- = Session::get_instance ().linemap->location_file (invoc_locus);
+ auto current_file = LOCATION_FILE (invoc_locus);
auto file_str = AST::SingleASTNode (make_string (invoc_locus, current_file));
auto str_token
= make_token (Token::make_string (invoc_locus, std::move (current_file)));
AST::Fragment
MacroBuiltin::column_handler (Location invoc_locus, AST::MacroInvocData &)
{
- auto current_column
- = Session::get_instance ().linemap->location_to_column (invoc_locus);
+ auto current_column = LOCATION_COLUMN (invoc_locus);
auto column_tok = make_token (
Token::make_int (invoc_locus, std::to_string (current_column)));
AST::Fragment
MacroBuiltin::line_handler (Location invoc_locus, AST::MacroInvocData &)
{
- auto current_line
- = Session::get_instance ().linemap->location_to_line (invoc_locus);
+ auto current_line = LOCATION_LINE (invoc_locus);
auto line_no = AST::SingleASTNode (std::unique_ptr<AST::Expr> (
new AST::LiteralExpr (std::to_string (current_line), AST::Literal::INT,
std::string to_string (Location);
- std::string location_file (Location);
-
- int location_line (Location);
-
- int location_column (Location);
-
private:
// Whether we are currently reading a file.
bool in_file_;
return ss.str ();
}
-// Return the file name for a given location.
-
-std::string
-Gcc_linemap::location_file (Location loc)
-{
- return LOCATION_FILE (loc);
-}
-
-// Return the line number for a given location.
-
-int
-Gcc_linemap::location_line (Location loc)
-{
- return LOCATION_LINE (loc);
-}
-
-// Return the column number for a given location.
-int
-Gcc_linemap::location_column (Location loc)
-{
- return LOCATION_COLUMN (loc);
-}
-
// Stop getting locations.
void
// unknown locations.
virtual std::string to_string (Location) = 0;
- // Return the file name for a given location.
- virtual std::string location_file (Location) = 0;
-
- // Return the line number for a given location.
- virtual int location_line (Location) = 0;
-
- // Return the column number for a given location.
- virtual int location_column (Location) = 0;
-
protected:
// The single existing instance of Linemap.
static Linemap *instance_;
rust_assert (Linemap::instance_ != NULL);
return Linemap::instance_->to_string (loc);
}
-
- // Return the file name of a location.
- static std::string location_to_file (Location loc)
- {
- rust_assert (Linemap::instance_ != NULL);
- return Linemap::instance_->location_file (loc);
- }
-
- // Return line number of a location.
- static int location_to_line (Location loc)
- {
- rust_assert (Linemap::instance_ != NULL);
- return Linemap::instance_->location_line (loc);
- }
-
- static int location_to_column (Location loc)
- {
- rust_assert (Linemap::instance_ != NULL);
- return Linemap::instance_->location_column (loc);
- }
};
#endif // !defined(RUST_LINEMAP_H)