Mercurial > hg > CbC > CbC_gcc
diff gcc/input.h @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
line wrap: on
line diff
--- a/gcc/input.h Fri Oct 27 22:46:09 2017 +0900 +++ b/gcc/input.h Thu Oct 25 07:37:49 2018 +0900 @@ -1,6 +1,6 @@ /* Declarations for variables relating to reading the source file. Used by parsers, lexical analyzers, and error message routines. - Copyright (C) 1993-2017 Free Software Foundation, Inc. + Copyright (C) 1993-2018 Free Software Foundation, Inc. This file is part of GCC. @@ -34,15 +34,61 @@ /* line-map.c reserves RESERVED_LOCATION_COUNT to the user. Ensure both UNKNOWN_LOCATION and BUILTINS_LOCATION fit into that. */ -extern char builtins_location_check[(BUILTINS_LOCATION - < RESERVED_LOCATION_COUNT) ? 1 : -1]; +STATIC_ASSERT (BUILTINS_LOCATION < RESERVED_LOCATION_COUNT); extern bool is_location_from_builtin_token (source_location); extern expanded_location expand_location (source_location); -extern const char *location_get_source_line (const char *file_path, int line, - int *line_size); + +/* A class capturing the bounds of a buffer, to allow for run-time + bounds-checking in a checked build. */ + +class char_span +{ + public: + char_span (const char *ptr, size_t n_elts) : m_ptr (ptr), m_n_elts (n_elts) {} + + /* Test for a non-NULL pointer. */ + operator bool() const { return m_ptr; } + + /* Get length, not including any 0-terminator (which may not be, + in fact, present). */ + size_t length () const { return m_n_elts; } + + const char *get_buffer () const { return m_ptr; } + + char operator[] (int idx) const + { + gcc_assert (idx >= 0); + gcc_assert ((size_t)idx < m_n_elts); + return m_ptr[idx]; + } + + char_span subspan (int offset, int n_elts) const + { + gcc_assert (offset >= 0); + gcc_assert (offset < (int)m_n_elts); + gcc_assert (n_elts >= 0); + gcc_assert (offset + n_elts <= (int)m_n_elts); + return char_span (m_ptr + offset, n_elts); + } + + char *xstrdup () const + { + return ::xstrndup (m_ptr, m_n_elts); + } + + private: + const char *m_ptr; + size_t m_n_elts; +}; + +extern char_span location_get_source_line (const char *file_path, int line); + extern bool location_missing_trailing_newline (const char *file_path); -extern expanded_location expand_location_to_spelling_point (source_location); +extern expanded_location +expand_location_to_spelling_point (source_location, + enum location_aspect aspect + = LOCATION_ASPECT_CARET); extern source_location expansion_point_location_if_in_system_header (source_location); extern source_location expansion_point_location (source_location); @@ -73,17 +119,31 @@ Note that this function returns 1 if LOCATION belongs to a token that is part of a macro replacement-list defined in a system header, but expanded in a non-system file. */ -#define in_system_header_at(LOC) \ - (linemap_location_in_system_header_p (line_table, LOC)) -/* Return a positive value if LOCATION is the locus of a token that - comes from a macro expansion, O otherwise. */ -#define from_macro_expansion_at(LOC) \ - ((linemap_location_from_macro_expansion_p (line_table, LOC))) -/* Return a positive value if LOCATION is the locus of a token that comes from - a macro definition, O otherwise. This differs from from_macro_expansion_at + +static inline int +in_system_header_at (location_t loc) +{ + return linemap_location_in_system_header_p (line_table, loc); +} + +/* Return true if LOCATION is the locus of a token that + comes from a macro expansion, false otherwise. */ + +static inline bool +from_macro_expansion_at (location_t loc) +{ + return linemap_location_from_macro_expansion_p (line_table, loc); +} + +/* Return true if LOCATION is the locus of a token that comes from + a macro definition, false otherwise. This differs from from_macro_expansion_at in its treatment of macro arguments, for which this returns false. */ -#define from_macro_definition_at(LOC) \ - ((linemap_location_from_macro_definition_p (line_table, LOC))) + +static inline bool +from_macro_definition_at (location_t loc) +{ + return linemap_location_from_macro_definition_p (line_table, loc); +} static inline location_t get_pure_location (location_t loc)