@@ -177,13 +177,20 @@ def parse_reports(paths):
177177 return combined
178178
179179
180+ # warnings without hash whose message is ignored when matching old and new warnings
181+ # checkersReport: "Active checkers: 176/189 (use --checkers-report=<filename> to see details)"
182+ VARYING_MESSAGE_IDS = {'checkersReport' }
183+
184+
180185def result_key (r ):
181186 """Key used to match warnings between the old and the new report."""
182187 if r ['hash' ]:
183188 return 'h:' + r ['hash' ]
184189 # No hash (e.g. missingInclude). Use a key that does not depend on line numbers.
185190 files = '|' .join (loc ['file' ] for loc in r ['locations' ])
186- return 'k:%s|%s|%s' % (r ['id' ], r ['msg' ], files )
191+ # the message of these changes with the cppcheck version and xml version
192+ msg = '' if r ['id' ] in VARYING_MESSAGE_IDS else r ['msg' ]
193+ return 'k:%s|%s|%s' % (r ['id' ], msg , files )
187194
188195
189196def primary_file (r ):
@@ -1454,77 +1461,76 @@ def main():
14541461 'int8_t int16_t int32_t int64_t uint8_t uint16_t uint32_t uint64_t intptr_t uintptr_t std string vector map set list FILE').split(' '));
14551462const TOK = /(\/\/.*$)|(\/\*)|("(?:\\.|[^"\\])*"?)|('(?:\\.|[^'\\])*'?)|(\b\d[\w.']*|\.\d[\w']*)|([A-Za-z_]\w*)(\s*\()?|([^\w\s"'\/]+|\/|\s+)/y;
14561463
1457- // returns true if the line ends inside a block comment
1458- function scanBlock(line, block) {
1459- let i = 0;
1460- const n = line.length;
1461- while (i < n) {
1462- if (block) {
1463- const e = line.indexOf('*/', i);
1464- if (e < 0) return true;
1465- block = false; i = e + 2;
1466- continue;
1467- }
1468- const c = line.charCodeAt(i);
1469- if (c === 47 /* / */) {
1470- const d = line.charCodeAt(i + 1);
1471- if (d === 47) return false;
1472- if (d === 42) { block = true; i += 2; continue; }
1473- } else if (c === 34 || c === 39) {
1474- i++;
1475- while (i < n && line.charCodeAt(i) !== c) i += line.charCodeAt(i) === 92 ? 2 : 1;
1476- }
1477- i++;
1478- }
1479- return block;
1480- }
1481-
1482- function hl(line, st) {
1483- if (line.length > 3000) return esc(line);
1484- let out = '', pos = 0;
1464+ // Split a line of C/C++ code into tokens and call emit(cls, text) for each token, cls is the
1465+ // t-<cls> css class or '' for plain text. emit can be null to only update the state.
1466+ // st.block is true if the line starts inside a block comment, and is updated for the next line.
1467+ // hl() and scanBlock() both use this so they always agree on where block comments start and end.
1468+ function lexLine(line, st, emit) {
1469+ const put = emit || (() => {});
1470+ let pos = 0;
14851471 if (st.block) {
14861472 const e = line.indexOf('*/');
1487- if (e < 0) return `<span class="t-co">${esc( line)}</span>`;
1488- out += `<span class="t-co">${esc( line.slice(0, e + 2))}</span>` ;
1473+ if (e < 0) { put('co', line); return; }
1474+ put('co', line.slice(0, e + 2));
14891475 pos = e + 2; st.block = false;
14901476 }
14911477 if (pos === 0 && /^\s*#/.test(line)) {
1492- const m = /^(\s*#\s*\w*)(.*)$/.exec(line);
1493- out += `<span class="t-pp">${esc(m[1])}</span>`;
1494- const inc = /^(\s*)(<[^>]*>|"[^"]*")(.*)$/.exec(m[2]);
1495- if (inc) return out + esc(inc[1]) + `<span class="t-st">${esc(inc[2])}</span>` + hlRest(inc[3], st);
1496- return out + hlRest(m[2], st);
1478+ const m = /^(\s*#\s*\w*)([\s\S]*)$/.exec(line);
1479+ put('pp', m[1]);
1480+ const inc = /^(\s*)(<[^>]*>|"[^"]*")([\s\S]*)$/.exec(m[2]);
1481+ if (inc) {
1482+ put('', inc[1]);
1483+ put('st', inc[2]);
1484+ lexRest(inc[3], st, put);
1485+ } else lexRest(m[2], st, put);
1486+ return;
14971487 }
1498- return out + hlRest (line.slice(pos), st);
1488+ lexRest (line.slice(pos), st, put );
14991489}
15001490
1501- function hlRest(s, st) {
1502- let out = '';
1491+ function lexRest(s, st, put) {
15031492 TOK.lastIndex = 0;
15041493 while (TOK.lastIndex < s.length) {
15051494 const start = TOK.lastIndex;
15061495 const m = TOK.exec(s);
1507- if (!m) { out += esc( s.slice(start)); break; }
1508- if (m[1]) out += `<span class="t-co">${esc( m[1])}</span>` ;
1496+ if (!m) { put('', s.slice(start)); break; }
1497+ if (m[1]) put('co', m[1]);
15091498 else if (m[2]) {
15101499 const e = s.indexOf('*/', TOK.lastIndex);
1511- if (e < 0) { out += `<span class="t-co">${esc( s.slice(start))}</span>` ; st.block = true; break; }
1512- out += `<span class="t-co">${esc( s.slice(start, e + 2))}</span>` ;
1500+ if (e < 0) { put('co', s.slice(start)); st.block = true; break; }
1501+ put('co', s.slice(start, e + 2));
15131502 TOK.lastIndex = e + 2;
1514- } else if (m[3] || m[4]) out += `<span class="t-st">${esc( m[3] || m[4])}</span>` ;
1515- else if (m[5]) out += `<span class="t-nu">${esc( m[5])}</span>` ;
1503+ } else if (m[3] || m[4]) put('st', m[3] || m[4]);
1504+ else if (m[5]) put('nu', m[5]);
15161505 else if (m[6]) {
15171506 const w = m[6];
1518- if (KW.has(w)) out += `<span class="t-kw">${w}</span>`;
1519- else if (TY.has(w)) out += `<span class="t-ty">${w}</span>`;
1520- else if (m[7]) out += `<span class="t-fn">${w}</span>`;
1521- else out += w;
1522- if (m[7]) out += esc(m[7]);
1523- } else out += esc(m[8]);
1507+ put(KW.has(w) ? 'kw' : TY.has(w) ? 'ty' : m[7] ? 'fn' : '', w);
1508+ if (m[7]) put('', m[7]);
1509+ } else put('', m[8]);
1510+ }
1511+ }
1512+
1513+ // highlight a line, st.block is updated for the next line
1514+ function hl(line, st) {
1515+ if (line.length > 3000) {
1516+ // too long to highlight, but the comment state is still needed for the next lines
1517+ lexLine(line, st, null);
1518+ return esc(line);
15241519 }
1520+ let out = '';
1521+ lexLine(line, st, (cls, text) => { out += cls ? `<span class="t-${cls}">${esc(text)}</span>` : esc(text); });
15251522 return out;
15261523}
15271524
1525+ // returns true if the line ends inside a block comment
1526+ function scanBlock(line, block) {
1527+ // the state can only change on a line with "/*" (outside a comment) or "*/" (inside one)
1528+ if (line.indexOf(block ? '*/' : '/*') < 0) return block;
1529+ const st = { block };
1530+ lexLine(line, st, null);
1531+ return st.block;
1532+ }
1533+
15281534return { esc, fmt, pct, cap, basename, countBy, highlightMatch, tipInner, tipHtml, niceStep, yAxis, fmtShort, scanBlock, hl };
15291535})();
15301536
0 commit comments