AVR: Make gcc.dg/c23-stdarg-9.c work.
[official-gcc.git] / gcc / rust / rust-linemap.cc
blobfb993b9e9b59327e0982e72c3735aa375d8c53bf
1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 // This file is part of GCC.
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
8 // version.
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 // for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
19 // rust-linemap.cc -- GCC implementation of Linemap.
21 #include "rust-linemap.h"
23 Linemap *Linemap::instance_ = NULL;
25 // Start getting locations from a new file.
27 void
28 Linemap::start_file (const char *file_name, unsigned line_begin)
30 if (this->in_file_)
31 linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
32 linemap_add (line_table, LC_ENTER, 0, file_name, line_begin);
33 this->in_file_ = true;
36 // Stringify a location
38 std::string
39 Linemap::location_to_string (location_t location)
41 const line_map_ordinary *lmo;
42 location_t resolved_location;
44 // Screen out unknown and predeclared locations; produce output
45 // only for simple file:line locations.
46 resolved_location = linemap_resolve_location (line_table, location,
47 LRK_SPELLING_LOCATION, &lmo);
48 if (lmo == NULL || resolved_location < RESERVED_LOCATION_COUNT)
49 return "";
50 const char *path = LINEMAP_FILE (lmo);
51 if (!path)
52 return "";
54 // Strip the source file down to the base file, to reduce clutter.
55 std::stringstream ss;
56 ss << lbasename (path) << ":" << SOURCE_LINE (lmo, location) << ":"
57 << SOURCE_COLUMN (lmo, location);
58 return ss.str ();
61 // Stop getting locations.
63 void
64 Linemap::stop ()
66 linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
67 this->in_file_ = false;
70 // Return the Linemap to use for the gcc backend.
72 Linemap *
73 rust_get_linemap ()
75 return new Linemap;