2014-11-22 16:48:39 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Error handling
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2014-11-22 16:48:39 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2020-01-06 23:05:53 +00:00
|
|
|
// Copyright 2003-2020 by Wilson Snyder. This program is free software; you can
|
2014-11-22 16:48:39 +00:00
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
|
|
|
//
|
|
|
|
// Verilator 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.
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2017-10-18 22:22:58 +00:00
|
|
|
#include "config_build.h"
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
2014-11-22 16:48:39 +00:00
|
|
|
#include "V3Error.h"
|
|
|
|
#include "V3FileLine.h"
|
2019-07-15 01:42:03 +00:00
|
|
|
#include "V3String.h"
|
2014-11-22 16:48:39 +00:00
|
|
|
#ifndef _V3ERROR_NO_GLOBAL_
|
|
|
|
# include "V3Ast.h"
|
|
|
|
# include "V3Global.h"
|
|
|
|
# include "V3Stats.h"
|
|
|
|
# include "V3Config.h"
|
2019-06-29 11:39:17 +00:00
|
|
|
# include "V3File.h"
|
2014-11-22 16:48:39 +00:00
|
|
|
#endif
|
|
|
|
|
2019-07-15 01:42:03 +00:00
|
|
|
#include <algorithm>
|
2018-10-14 17:43:24 +00:00
|
|
|
#include <cstdarg>
|
2019-07-26 16:52:38 +00:00
|
|
|
#include <iomanip>
|
2018-10-14 17:43:24 +00:00
|
|
|
#include VL_INCLUDE_UNORDERED_SET
|
|
|
|
|
2014-11-22 16:48:39 +00:00
|
|
|
//######################################################################
|
|
|
|
// FileLineSingleton class functions
|
|
|
|
|
2018-10-14 22:39:33 +00:00
|
|
|
const string FileLineSingleton::filenameLetters(int fileno) {
|
2014-11-22 16:48:39 +00:00
|
|
|
const int size = 1 + (64 / 4); // Each letter retires more than 4 bits of a > 64 bit number
|
|
|
|
char out[size];
|
|
|
|
char* op = out+size-1;
|
|
|
|
*--op = '\0'; // We build backwards
|
2018-10-14 22:39:33 +00:00
|
|
|
int num = fileno;
|
2014-11-22 16:48:39 +00:00
|
|
|
do {
|
2018-10-14 22:39:33 +00:00
|
|
|
*--op = 'a'+num%26;
|
|
|
|
num /= 26;
|
2014-11-22 16:48:39 +00:00
|
|
|
} while (num);
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Convert filenames to a filenameno
|
|
|
|
|
|
|
|
//! This lets us assign a nice small identifier for debug messages, but more
|
|
|
|
//! importantly lets us use a 4 byte int instead of 8 byte pointer in every
|
|
|
|
//! FileLine.
|
|
|
|
|
|
|
|
//! We associate a language with each source file, so we also set the default
|
|
|
|
//! for this.
|
|
|
|
int FileLineSingleton::nameToNumber(const string& filename) {
|
|
|
|
FileNameNumMap::const_iterator it = m_namemap.find(filename);
|
|
|
|
if (VL_LIKELY(it != m_namemap.end())) return it->second;
|
|
|
|
int num = m_names.size();
|
|
|
|
m_names.push_back(filename);
|
|
|
|
m_languages.push_back(V3LangCode::mostRecent());
|
2019-05-19 20:13:13 +00:00
|
|
|
m_namemap.insert(make_pair(filename, num));
|
2014-11-22 16:48:39 +00:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Support XML output
|
|
|
|
//! Experimental. Updated to also put out the language.
|
2018-02-02 02:24:41 +00:00
|
|
|
void FileLineSingleton::fileNameNumMapDumpXml(std::ostream& os) {
|
2014-11-22 16:48:39 +00:00
|
|
|
os<<"<files>\n";
|
|
|
|
for (FileNameNumMap::const_iterator it = m_namemap.begin(); it != m_namemap.end(); ++it) {
|
2019-05-19 20:13:13 +00:00
|
|
|
os<<"<file id=\""<<filenameLetters(it->second)
|
2019-06-29 11:39:17 +00:00
|
|
|
<<"\" filename=\""<<V3OutFormatter::quoteNameControls(it->first, V3OutFormatter::LA_XML)
|
2019-05-19 20:13:13 +00:00
|
|
|
<<"\" language=\""<<numberToLang(it->second).ascii()<<"\"/>\n";
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
os<<"</files>\n";
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:42:03 +00:00
|
|
|
//######################################################################
|
|
|
|
// VFileContents class functions
|
|
|
|
|
|
|
|
int VFileContent::debug() {
|
|
|
|
static int level = -1;
|
|
|
|
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VFileContent::pushText(const string& text) {
|
|
|
|
if (m_lines.size() == 0) {
|
|
|
|
m_lines.push_back(""); // no such thing as line [0]
|
|
|
|
m_lines.push_back(""); // start with no leftover
|
|
|
|
}
|
|
|
|
|
|
|
|
// Any leftover text is stored on largest line (might be "")
|
|
|
|
string leftover = m_lines.back() + text; m_lines.pop_back();
|
|
|
|
|
|
|
|
// Insert line-by-line
|
|
|
|
string::size_type line_start = 0;
|
|
|
|
while (1) {
|
|
|
|
string::size_type line_end = leftover.find("\n", line_start);
|
|
|
|
if (line_end != string::npos) {
|
|
|
|
string oneline (leftover, line_start, line_end-line_start+1);
|
|
|
|
m_lines.push_back(oneline); // Keeps newline
|
|
|
|
UINFO(9, "PushStream[ct"<<m_id<<"+"<<(m_lines.size()-1)<<"]: "<<oneline);
|
|
|
|
line_start = line_end+1;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Keep leftover for next time
|
|
|
|
m_lines.push_back(string(leftover, line_start)); // Might be ""
|
|
|
|
}
|
|
|
|
|
|
|
|
string VFileContent::getLine(int lineno) const {
|
|
|
|
// Return error text rather than asserting so the user isn't left without a message
|
2020-02-04 04:21:56 +00:00
|
|
|
// cppcheck-suppress negativeContainerIndex
|
2019-07-15 01:42:03 +00:00
|
|
|
if (VL_UNCOVERABLE(lineno < 0 || lineno >= (int)m_lines.size())) {
|
|
|
|
if (debug() || v3Global.opt.debugCheck()) {
|
|
|
|
return ("%Error-internal-contents-bad-ct"+cvtToStr(m_id)
|
|
|
|
+"-ln"+cvtToStr(lineno));
|
|
|
|
} else return "";
|
|
|
|
}
|
|
|
|
string text = m_lines[lineno];
|
|
|
|
UINFO(9, "Get Stream[ct"<<m_id<<"+"<<lineno<<"]: "<<text);
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, VFileContent* contentp) {
|
|
|
|
if (!contentp) os <<"ct0";
|
|
|
|
else os <<contentp->ascii();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2014-11-22 16:48:39 +00:00
|
|
|
//######################################################################
|
|
|
|
// FileLine class functions
|
|
|
|
|
|
|
|
FileLine::FileLine(FileLine::EmptySecret) {
|
|
|
|
// Sort of a singleton
|
2019-07-15 01:42:03 +00:00
|
|
|
m_firstLineno = 0;
|
|
|
|
m_lastLineno = 0;
|
|
|
|
m_firstColumn = 0;
|
|
|
|
m_lastColumn = 0;
|
2019-06-29 11:39:17 +00:00
|
|
|
m_filenameno = singleton().nameToNumber(FileLine::builtInFilename());
|
2019-07-15 01:42:03 +00:00
|
|
|
m_contentp = NULL;
|
|
|
|
m_contentLineno = 0;
|
2019-06-22 21:01:39 +00:00
|
|
|
m_parent = NULL;
|
2014-11-22 16:48:39 +00:00
|
|
|
|
2019-05-19 20:13:13 +00:00
|
|
|
m_warnOn = 0;
|
2014-11-22 16:48:39 +00:00
|
|
|
for (int codei=V3ErrorCode::EC_MIN; codei<V3ErrorCode::_ENUM_MAX; codei++) {
|
2018-10-14 22:39:33 +00:00
|
|
|
V3ErrorCode code = V3ErrorCode(codei);
|
|
|
|
warnOff(code, code.defaultsOff());
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-20 19:08:13 +00:00
|
|
|
const string FileLine::xmlDetailedLocation() const {
|
|
|
|
return "loc=\"" +
|
|
|
|
cvtToStr(filenameLetters()) + "," +
|
|
|
|
cvtToStr(firstLineno()) + "," +
|
|
|
|
cvtToStr(firstColumn()) + "," +
|
|
|
|
cvtToStr(lastLineno()) + "," +
|
|
|
|
cvtToStr(lastColumn()) + "\"";
|
|
|
|
}
|
|
|
|
|
2014-11-22 16:48:39 +00:00
|
|
|
string FileLine::lineDirectiveStrg(int enterExit) const {
|
2019-07-15 01:42:03 +00:00
|
|
|
char numbuf[20]; sprintf(numbuf, "%d", lastLineno());
|
2014-11-22 16:48:39 +00:00
|
|
|
char levelbuf[20]; sprintf(levelbuf, "%d", enterExit);
|
2018-10-14 02:02:39 +00:00
|
|
|
return (string("`line ")+numbuf+" \""+filename()+"\" "+levelbuf+"\n");
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileLine::lineDirective(const char* textp, int& enterExitRef) {
|
|
|
|
// Handle `line directive
|
2019-07-15 01:42:03 +00:00
|
|
|
// Does not parse streamNumber/streamLineno as the next input token
|
|
|
|
// will come from the same stream as the previous line.
|
|
|
|
|
2014-11-22 16:48:39 +00:00
|
|
|
// Skip `line
|
|
|
|
while (*textp && isspace(*textp)) textp++;
|
|
|
|
while (*textp && !isspace(*textp)) textp++;
|
|
|
|
while (*textp && (isspace(*textp) || *textp=='"')) textp++;
|
|
|
|
|
|
|
|
// Grab linenumber
|
2019-11-16 16:59:21 +00:00
|
|
|
bool fail = false;
|
2019-11-10 01:35:12 +00:00
|
|
|
const char* ln = textp;
|
2014-11-22 16:48:39 +00:00
|
|
|
while (*textp && !isspace(*textp)) textp++;
|
|
|
|
if (isdigit(*ln)) {
|
2019-05-19 20:13:13 +00:00
|
|
|
lineno(atoi(ln));
|
2019-11-16 16:59:21 +00:00
|
|
|
} else fail = true;
|
|
|
|
while (*textp && (isspace(*textp))) textp++;
|
|
|
|
if (*textp != '"') fail = true;
|
|
|
|
while (*textp && (isspace(*textp) || *textp == '"')) textp++;
|
2014-11-22 16:48:39 +00:00
|
|
|
|
|
|
|
// Grab filename
|
2019-11-10 01:35:12 +00:00
|
|
|
const char* fn = textp;
|
2014-11-22 16:48:39 +00:00
|
|
|
while (*textp && !(isspace(*textp) || *textp=='"')) textp++;
|
|
|
|
if (textp != fn) {
|
2019-05-19 20:13:13 +00:00
|
|
|
string strfn = fn;
|
|
|
|
strfn = strfn.substr(0, textp-fn);
|
|
|
|
filename(strfn);
|
2019-11-16 16:59:21 +00:00
|
|
|
} else fail = true;
|
2014-11-22 16:48:39 +00:00
|
|
|
|
|
|
|
// Grab level
|
|
|
|
while (*textp && (isspace(*textp) || *textp=='"')) textp++;
|
2019-11-16 16:59:21 +00:00
|
|
|
if (isdigit(*textp)) {
|
|
|
|
enterExitRef = atoi(textp);
|
|
|
|
if (enterExitRef >= 3) fail = true;
|
|
|
|
} else {
|
|
|
|
enterExitRef = 0;
|
|
|
|
fail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fail && v3Global.opt.pedantic()) {
|
|
|
|
v3error("`line was not properly formed with '`line number \"filename\" level'\n");
|
|
|
|
}
|
2014-11-22 16:48:39 +00:00
|
|
|
|
|
|
|
//printf ("PPLINE %d '%s'\n", s_lineno, s_filename.c_str());
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:42:03 +00:00
|
|
|
void FileLine::forwardToken(const char* textp, size_t size, bool trackLines) {
|
|
|
|
for (const char* sp = textp; size && *sp; ++sp, --size) {
|
|
|
|
if (*sp == '\n') {
|
|
|
|
if (trackLines) linenoInc();
|
|
|
|
m_lastColumn = 1;
|
|
|
|
} else if (*sp == '\r') {
|
|
|
|
} else { // Tabs are considered one column; hence column means number of chars
|
|
|
|
++m_lastColumn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-22 16:48:39 +00:00
|
|
|
FileLine* FileLine::copyOrSameFileLine() {
|
|
|
|
// When a fileline is "used" to produce a node, calls this function.
|
|
|
|
// Return this, or a copy of this
|
|
|
|
// There are often more than one token per line, thus we use the
|
|
|
|
// same pointer as long as we're on the same line, file & warn state.
|
|
|
|
#ifndef _V3ERROR_NO_GLOBAL_
|
|
|
|
V3Config::applyIgnores(this); // Toggle warnings based on global config file
|
|
|
|
#endif
|
|
|
|
static FileLine* lastNewp = NULL;
|
|
|
|
if (lastNewp && *lastNewp == *this) { // Compares lineno, filename, etc
|
2019-05-19 20:13:13 +00:00
|
|
|
return lastNewp;
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
FileLine* newp = new FileLine(this);
|
|
|
|
lastNewp = newp;
|
|
|
|
return newp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const string FileLine::filebasename() const {
|
|
|
|
string name = filename();
|
|
|
|
string::size_type pos;
|
2018-10-14 02:28:59 +00:00
|
|
|
if ((pos = name.rfind('/')) != string::npos) {
|
2019-05-19 20:13:13 +00:00
|
|
|
name.erase(0, pos+1);
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const string FileLine::filebasenameNoExt() const {
|
|
|
|
string name = filebasename();
|
|
|
|
string::size_type pos;
|
2018-10-14 02:28:59 +00:00
|
|
|
if ((pos = name.find('.')) != string::npos) {
|
2019-05-19 20:13:13 +00:00
|
|
|
name = name.substr(0, pos);
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const string FileLine::profileFuncname() const {
|
|
|
|
// Return string that is OK as a function name - for profiling
|
|
|
|
string name = filebasenameNoExt();
|
|
|
|
string::size_type pos;
|
|
|
|
while ((pos = name.find_first_not_of("abcdefghijlkmnopqrstuvwxyzABCDEFGHIJLKMNOPQRSTUVWXYZ0123456789_"))
|
2019-05-19 20:13:13 +00:00
|
|
|
!= string::npos) {
|
|
|
|
name.replace(pos, 1, "_");
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
2019-07-15 01:42:03 +00:00
|
|
|
name += "__l"+cvtToStr(lastLineno());
|
2014-11-22 16:48:39 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:42:03 +00:00
|
|
|
string FileLine::asciiLineCol() const {
|
|
|
|
return (cvtToStr(firstLineno())+"-"+cvtToStr(lastLineno())
|
|
|
|
+":"+cvtToStr(firstColumn())+"-"+cvtToStr(lastColumn())
|
|
|
|
+"["+(m_contentp ? m_contentp->ascii() : "ct0")
|
|
|
|
+"+"+cvtToStr(m_contentLineno)+"]");
|
|
|
|
}
|
2014-11-22 16:48:39 +00:00
|
|
|
string FileLine::ascii() const {
|
2019-07-15 01:42:03 +00:00
|
|
|
// For most errors especially in the parser the lastLineno is more accurate than firstLineno
|
2020-03-15 02:02:42 +00:00
|
|
|
return filename() + ":" + cvtToStr(lastLineno()) + ":" + cvtToStr(firstColumn());
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
2018-02-02 02:24:41 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, FileLine* fileline) {
|
|
|
|
os <<fileline->ascii()<<": "<<std::hex;
|
2014-11-22 16:48:39 +00:00
|
|
|
return(os);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileLine::warnOff(const string& msg, bool flag) {
|
|
|
|
V3ErrorCode code (msg.c_str());
|
|
|
|
if (code < V3ErrorCode::EC_FIRST_WARN) {
|
2019-05-19 20:13:13 +00:00
|
|
|
return false;
|
2014-11-22 16:48:39 +00:00
|
|
|
#ifndef _V3ERROR_NO_GLOBAL_
|
2019-05-19 20:13:13 +00:00
|
|
|
} else if (v3Global.opt.lintOnly() // Lint mode is allowed to suppress some errors
|
|
|
|
&& code < V3ErrorCode::EC_MIN) {
|
|
|
|
return false;
|
2014-11-22 16:48:39 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
2019-05-19 20:13:13 +00:00
|
|
|
warnOff(code, flag);
|
|
|
|
return true;
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileLine::warnLintOff(bool flag) {
|
|
|
|
for (int codei=V3ErrorCode::EC_MIN; codei<V3ErrorCode::_ENUM_MAX; codei++) {
|
2018-10-14 22:39:33 +00:00
|
|
|
V3ErrorCode code = V3ErrorCode(codei);
|
|
|
|
if (code.lintError()) warnOff(code, flag);
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileLine::warnStyleOff(bool flag) {
|
|
|
|
for (int codei=V3ErrorCode::EC_MIN; codei<V3ErrorCode::_ENUM_MAX; codei++) {
|
2018-10-14 22:39:33 +00:00
|
|
|
V3ErrorCode code = V3ErrorCode(codei);
|
|
|
|
if (code.styleError()) warnOff(code, flag);
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileLine::warnIsOff(V3ErrorCode code) const {
|
|
|
|
if (!m_warnOn.test(code)) return true;
|
|
|
|
if (!defaultFileLine().m_warnOn.test(code)) return true; // Global overrides local
|
|
|
|
// UNOPTFLAT implies UNOPT
|
|
|
|
if (code==V3ErrorCode::UNOPT && !m_warnOn.test(V3ErrorCode::UNOPTFLAT)) return true;
|
2019-05-19 20:13:13 +00:00
|
|
|
if ((code.lintError() || code.styleError())
|
|
|
|
&& !m_warnOn.test(V3ErrorCode::I_LINT)) return true;
|
2014-11-22 16:48:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileLine::modifyStateInherit(const FileLine* fromp) {
|
|
|
|
// Any warnings that are off in "from", become off in "this".
|
|
|
|
for (int codei=V3ErrorCode::EC_MIN; codei<V3ErrorCode::_ENUM_MAX; codei++) {
|
2018-10-14 22:39:33 +00:00
|
|
|
V3ErrorCode code = V3ErrorCode(codei);
|
|
|
|
if (fromp->warnIsOff(code)) { warnOff(code, true); }
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-26 16:52:38 +00:00
|
|
|
void FileLine::v3errorEnd(std::ostringstream& str, const string& locationStr) {
|
2018-11-17 01:48:57 +00:00
|
|
|
std::ostringstream nsstr;
|
2019-07-15 01:42:03 +00:00
|
|
|
if (lastLineno()) nsstr<<this;
|
2018-11-17 01:48:57 +00:00
|
|
|
nsstr<<str.str();
|
2019-06-22 21:01:39 +00:00
|
|
|
nsstr<<endl;
|
2019-07-26 16:52:38 +00:00
|
|
|
std::ostringstream lstr;
|
|
|
|
if (!locationStr.empty()) {
|
|
|
|
lstr<<std::setw(ascii().length())<<" "<<": "<<locationStr;
|
|
|
|
}
|
2020-01-12 09:03:17 +00:00
|
|
|
if (warnIsOff(V3Error::errorCode())
|
|
|
|
|| V3Config::waive(this, V3Error::errorCode(), str.str())) {
|
|
|
|
V3Error::suppressThisWarning();
|
|
|
|
}
|
2019-06-22 21:01:39 +00:00
|
|
|
else if (!V3Error::errorContexted()) nsstr<<warnContextPrimary();
|
2019-07-26 16:52:38 +00:00
|
|
|
V3Error::v3errorEnd(nsstr, lstr.str());
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string FileLine::warnMore() const {
|
2019-07-15 01:42:03 +00:00
|
|
|
if (lastLineno()) {
|
2019-07-11 23:15:40 +00:00
|
|
|
return V3Error::warnMore()+string(ascii().size(), ' ')+": ";
|
|
|
|
} else {
|
|
|
|
return V3Error::warnMore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
string FileLine::warnOther() const {
|
2019-07-15 01:42:03 +00:00
|
|
|
if (lastLineno()) {
|
2019-05-19 20:13:13 +00:00
|
|
|
return V3Error::warnMore()+ascii()+": ";
|
2014-11-22 16:48:39 +00:00
|
|
|
} else {
|
2019-05-19 20:13:13 +00:00
|
|
|
return V3Error::warnMore();
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:42:03 +00:00
|
|
|
string FileLine::source() const {
|
|
|
|
if (VL_UNCOVERABLE(!m_contentp)) {
|
2020-03-15 01:48:26 +00:00
|
|
|
if (debug() || v3Global.opt.debugCheck()) {
|
|
|
|
return "%Error: internal tracking of file contents failed";
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2019-07-15 01:42:03 +00:00
|
|
|
}
|
|
|
|
return m_contentp->getLine(m_contentLineno);
|
|
|
|
}
|
|
|
|
string FileLine::prettySource() const {
|
|
|
|
string out = source();
|
|
|
|
// Drop ignore trailing newline
|
|
|
|
string::size_type pos = out.find('\n');
|
|
|
|
if (pos != string::npos) out = string(out, 0, pos);
|
|
|
|
// Column tracking counts tabs = 1, so match that when print source
|
|
|
|
return VString::spaceUnprintable(out);
|
|
|
|
}
|
|
|
|
|
2019-06-22 21:01:39 +00:00
|
|
|
string FileLine::warnContext(bool secondary) const {
|
|
|
|
V3Error::errorContexted(true);
|
2019-11-23 15:39:36 +00:00
|
|
|
if (!v3Global.opt.context()) return "";
|
2019-06-22 21:01:39 +00:00
|
|
|
string out = "";
|
2019-07-15 01:42:03 +00:00
|
|
|
if (firstLineno()==lastLineno() && firstColumn()) {
|
|
|
|
string sourceLine = prettySource();
|
|
|
|
// Don't show super-long lines as can fill screen and unlikely to help user
|
|
|
|
if (!sourceLine.empty()
|
|
|
|
&& sourceLine.length() < SHOW_SOURCE_MAX_LENGTH
|
2019-10-01 01:55:31 +00:00
|
|
|
&& sourceLine.length() >= (size_t)(lastColumn()-1)) {
|
2019-07-15 01:42:03 +00:00
|
|
|
out += sourceLine+"\n";
|
|
|
|
out += string((firstColumn()-1), ' ')+'^';
|
|
|
|
// Can't use UASSERT_OBJ used in warnings already inside the error end handler
|
2019-10-17 00:05:29 +00:00
|
|
|
if (lastColumn() > firstColumn()) {
|
|
|
|
// Note lastColumn() can be <= firstColumn() in some weird preproc expansions
|
2019-07-15 01:42:03 +00:00
|
|
|
out += string((lastColumn()-firstColumn()-1), '~');
|
|
|
|
}
|
|
|
|
out += "\n";
|
|
|
|
}
|
|
|
|
}
|
2019-06-22 21:01:39 +00:00
|
|
|
if (!secondary) { // Avoid printing long paths on informational part of error
|
|
|
|
for (FileLine* parentFl = parent(); parentFl; parentFl = parentFl->parent()) {
|
|
|
|
if (parentFl->filenameIsGlobal()) break;
|
2019-07-11 23:15:40 +00:00
|
|
|
out += parentFl->warnOther()+"... note: In file included from "
|
2019-06-22 21:01:39 +00:00
|
|
|
+parentFl->filebasename()+"\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2014-11-22 16:48:39 +00:00
|
|
|
#ifdef VL_LEAK_CHECKS
|
2017-10-18 22:22:58 +00:00
|
|
|
typedef vl_unordered_set<FileLine*> FileLineCheckSet;
|
2014-11-22 16:48:39 +00:00
|
|
|
FileLineCheckSet fileLineLeakChecks;
|
|
|
|
|
|
|
|
void* FileLine::operator new(size_t size) {
|
|
|
|
FileLine* objp = static_cast<FileLine*>(::operator new(size));
|
|
|
|
fileLineLeakChecks.insert(objp);
|
|
|
|
return objp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileLine::operator delete(void* objp, size_t size) {
|
|
|
|
if (!objp) return;
|
|
|
|
FileLine* flp = static_cast<FileLine*>(objp);
|
|
|
|
FileLineCheckSet::iterator it = fileLineLeakChecks.find(flp);
|
|
|
|
if (it != fileLineLeakChecks.end()) {
|
2019-05-19 20:13:13 +00:00
|
|
|
fileLineLeakChecks.erase(it);
|
2014-11-22 16:48:39 +00:00
|
|
|
} else {
|
2019-05-19 20:13:13 +00:00
|
|
|
flp->v3fatalSrc("Deleting FileLine object that was never tracked");
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
::operator delete(objp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void FileLine::deleteAllRemaining() {
|
|
|
|
#ifdef VL_LEAK_CHECKS
|
|
|
|
// FileLines are allocated, but never nicely freed, as it's much faster
|
|
|
|
// that way. Unfortunately this makes our leak checking a big mess, so
|
|
|
|
// only when leak checking we'll track them all and cleanup.
|
|
|
|
while (1) {
|
2019-05-19 20:13:13 +00:00
|
|
|
FileLineCheckSet::iterator it = fileLineLeakChecks.begin();
|
|
|
|
if (it==fileLineLeakChecks.end()) break;
|
|
|
|
delete *it;
|
|
|
|
// Operator delete will remove the iterated object from the list.
|
|
|
|
// Eventually the list will be empty and terminate the loop.
|
2014-11-22 16:48:39 +00:00
|
|
|
}
|
|
|
|
fileLineLeakChecks.clear();
|
|
|
|
singleton().clear();
|
|
|
|
#endif
|
|
|
|
}
|