Files
iverilog/libmisc/LineInfo.h
T
Lars-Peter Clausen 5f479cbad4 Store lexical positions in LineInfo
Several source and netlist objects inherit `LineInfo` while separately
storing the lexical position associated with the same source location. This
requires callers to copy the file, line, and lexical position independently.

Add the lexical position to `LineInfo`. Have `set_line()` initialize it when
it is unset, so new objects inherit the complete source location while later
diagnostic location updates preserve their established declaration order.
Initialize the field to `UINT_MAX` so zero remains available as a valid
scanner position and missing initialization is distinguishable. Have
`FILE_NAME()` preserve a more precise identifier position.

Remove constructor parameters that duplicate the position supplied through
`FILE_NAME()`. Use the shared field for identifiers, wires, events, event
triggers, nets, and elaborated events. Assign static class property nets
their declaration location since they previously relied on the standalone
`NetNet` position defaulting to zero.

Signed-off-by: Lars-Peter Clausen <[email protected]>
2026-07-26 20:14:20 -07:00

60 lines
2.0 KiB
C++

#ifndef IVL_LineInfo_H
#define IVL_LineInfo_H
/*
* Copyright (c) 1999-2021 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
# include "StringHeap.h"
# include <climits>
# include <string>
/*
* This class holds line information for an internal object.
*
* Note that the file names are C-style strings that are allocated by
* the lexor (which parses the line directives) and are never
* deallocated. We can therefore safely store the pointer and never
* delete the string, even if LineInfo objects are destroyed.
*/
class LineInfo {
public:
LineInfo();
virtual ~LineInfo();
// Get a fully formatted file/lineno
std::string get_fileline() const;
// Set the source location from another LineInfo object.
void set_line(const LineInfo&that);
// Access parts of LineInfo data
void set_file(perm_string f);
void set_lineno(unsigned n);
void lexical_pos(unsigned int n);
perm_string get_file() const { return file_; }
unsigned get_lineno() const { return lineno_; }
unsigned int lexical_pos() const { return lexical_pos_; }
private:
perm_string file_;
unsigned lineno_;
unsigned int lexical_pos_ = UINT_MAX;
};
#endif /* IVL_LineInfo_H */