Merge branch 'develop' into wip-cppcheck271-part2

This commit is contained in:
g. economou
2024-05-17 11:08:09 +03:00
committed by GitHub
211 changed files with 3167 additions and 2125 deletions

View File

@@ -73,7 +73,7 @@ Component *ComponentAlternation::accept(ComponentVisitor &v) {
}
for (auto i = children.begin(), e = children.end(); i != e; ++i) {
Component *child = i->get();
const Component *child = i->get();
c = (*i)->accept(v);
if (c != child) {
// Child has been replaced (new Component pointer) or we've been
@@ -109,20 +109,20 @@ void ComponentAlternation::append(unique_ptr<Component> component) {
vector<PositionInfo> ComponentAlternation::first() const {
// firsts come from all our subcomponents in position order. This will
// maintain left-to-right priority order.
vector<PositionInfo> firsts, subfirsts;
vector<PositionInfo> firsts;
for (const auto &c : children) {
subfirsts = c->first();
vector<PositionInfo> subfirsts = c->first();
firsts.insert(firsts.end(), subfirsts.begin(), subfirsts.end());
}
return firsts;
}
vector<PositionInfo> ComponentAlternation::last() const {
vector<PositionInfo> lasts, sublasts;
vector<PositionInfo> lasts;
for (const auto &c : children) {
sublasts = c->last();
vector<PositionInfo> sublasts = c->last();
lasts.insert(lasts.end(), sublasts.begin(), sublasts.end());
}
return lasts;

View File

@@ -59,7 +59,7 @@ Component * ComponentAssertion::accept(ComponentVisitor &v) {
}
for (auto i = children.begin(), e = children.end(); i != e; ++i) {
Component *child = i->get();
const Component *child = i->get();
c = (*i)->accept(v);
if (c != child) {
// Child has been replaced (new Component pointer) or we've been

View File

@@ -51,7 +51,7 @@ Component *ComponentAtomicGroup::accept(ComponentVisitor &v) {
}
for (auto i = children.begin(), e = children.end(); i != e; ++i) {
Component *child = i->get();
const Component *child = i->get();
c = (*i)->accept(v);
if (c != child) {
// Child has been replaced (new Component pointer) or we've been

View File

@@ -161,26 +161,26 @@ void ComponentBoundary::buildFollowSet(GlushkovBuildState &,
bool ComponentBoundary::checkEmbeddedStartAnchor(bool at_start) const {
if (at_start) {
return at_start;
return true;
}
if (m_bound == BEGIN_STRING || m_bound == BEGIN_LINE) {
throw ParseError("Embedded start anchors not supported.");
}
return at_start;
return false;
}
bool ComponentBoundary::checkEmbeddedEndAnchor(bool at_end) const {
if (at_end) {
return at_end;
return true;
}
if (m_bound != BEGIN_STRING && m_bound != BEGIN_LINE) {
throw ParseError("Embedded end anchors not supported.");
}
return at_end;
return false;
}
} // namespace

View File

@@ -79,7 +79,7 @@ Component *ComponentCondReference::accept(ComponentVisitor &v) {
}
if (kind == CONDITION_ASSERTION) {
Component *a = assertion.get();
const Component *a = assertion.get();
c = assertion->accept(v);
if (c != a) {
assertion.reset(c);
@@ -87,7 +87,7 @@ Component *ComponentCondReference::accept(ComponentVisitor &v) {
}
for (auto i = children.begin(), e = children.end(); i != e; ++i) {
Component *child = i->get();
const Component *child = i->get();
c = (*i)->accept(v);
if (c != child) {
// Child has been replaced (new Component pointer) or we've been

View File

@@ -110,7 +110,7 @@ void addBase(Position base, vector<PositionInfo> &firsts,
}
static
void checkPositions(vector<PositionInfo> &v, const GlushkovBuildState &bs) {
void checkPositions(const vector<PositionInfo> &v, const GlushkovBuildState &bs) {
const NFABuilder& builder = bs.getBuilder();
for (const auto &e : v) {
// cppcheck-suppress useStlAlgorithm
@@ -133,7 +133,7 @@ void ComponentRepeat::notePositions(GlushkovBuildState &bs) {
posFirst = bs.getBuilder().numVertices();
sub_comp->notePositions(bs);
u32 copies = m_max < NoLimit ? m_max : MAX(m_min, 1);
u32 copies = (m_max < NoLimit) ? m_max : std::max(m_min, 1U);
DEBUG_PRINTF("building %u copies of repeated region\n", copies);
m_firsts.clear();
m_lasts.clear();
@@ -321,8 +321,8 @@ void ComponentRepeat::wireRepeats(GlushkovBuildState &bs) {
}
}
DEBUG_PRINTF("wiring up %d optional repeats\n", copies - m_min);
for (u32 rep = MAX(m_min, 1); rep < copies; rep++) {
DEBUG_PRINTF("wiring up %u optional repeats\n", copies - m_min);
for (u32 rep = std::max(m_min, 1U); rep < copies; rep++) {
vector<PositionInfo> lasts = m_lasts[rep - 1];
if (rep != m_min) {
lasts.insert(lasts.end(), optLasts.begin(), optLasts.end());

View File

@@ -82,7 +82,7 @@ Component *ComponentSequence::accept(ComponentVisitor &v) {
}
for (auto i = children.begin(), e = children.end(); i != e; ++i) {
Component *child = i->get();
const Component *child = i->get();
c = (*i)->accept(v);
if (c != child) {
// Child has been replaced (new Component pointer) or we've been
@@ -157,10 +157,10 @@ void ComponentSequence::finalize() {
}
vector<PositionInfo> ComponentSequence::first() const {
vector<PositionInfo> firsts, subfirsts;
vector<PositionInfo> firsts;
for (const auto &c : children) {
subfirsts = c->first();
vector<PositionInfo> subfirsts = c->first();
replaceEpsilons(firsts, subfirsts);
if (!c->empty()) {
break;
@@ -229,12 +229,12 @@ void applyEpsilonVisits(vector<PositionInfo> &lasts,
}
vector<PositionInfo> ComponentSequence::last() const {
vector<PositionInfo> lasts, sublasts;
vector<PositionInfo> lasts;
vector<eps_info> visits(1);
auto i = children.rbegin(), e = children.rend();
for (; i != e; ++i) {
sublasts = (*i)->last();
vector<PositionInfo> sublasts = (*i)->last();
applyEpsilonVisits(sublasts, visits);
lasts.insert(lasts.end(), sublasts.begin(), sublasts.end());
if ((*i)->empty()) {

View File

@@ -224,7 +224,7 @@ u8 decodeCtrl(char raw) {
static
unichar readUtf8CodePoint2c(const char *s) {
auto *ts = (const u8 *)s;
auto *ts = reinterpret_cast<const u8 *>(s);
assert(ts[0] >= 0xc0 && ts[0] < 0xe0);
assert(ts[1] >= 0x80 && ts[1] < 0xc0);
unichar val = ts[0] & 0x1f;

View File

@@ -243,7 +243,7 @@ Position makeNewlineAssertPos(GlushkovBuildState &bs) {
static
void generateAccepts(GlushkovBuildStateImpl &bs, const PositionInfo &from,
vector<PositionInfo> *tolist) {
NFABuilder &builder = bs.getBuilder();
const NFABuilder &builder = bs.getBuilder();
u32 flags = from.flags;
bool require_eod = flags & POS_FLAG_WIRE_EOD;
@@ -456,11 +456,10 @@ void cleanupPositions(vector<PositionInfo> &a) {
vector<PositionInfo> out;
out.reserve(a.size()); // output should be close to input in size.
for (const auto &p : a) {
if (seen.emplace(p.pos, p.flags).second) {
out.emplace_back(p); // first encounter
}
}
auto seens = [&seen=seen](const PositionInfo &p) {
return (seen.emplace(p.pos, p.flags).second);
};
std::copy_if(begin(a), end(a), std::back_inserter(out), seens);
DEBUG_PRINTF("in %zu; out %zu\n", a.size(), out.size());
a.swap(out);

View File

@@ -260,14 +260,14 @@ void ParsedLogical::parseLogicalCombination(unsigned id, const char *logical,
u32 ekey, u64a min_offset,
u64a max_offset) {
u32 ckey = getCombKey(id);
vector<LogicalOperator> op_stack;
vector<u32> subid_stack;
u32 lkey_start = INVALID_LKEY; // logical operation's lkey
u32 paren = 0; // parentheses
u32 digit = (u32)-1; // digit start offset, invalid offset is -1
u32 subid = (u32)-1;
u32 i;
try {
vector<LogicalOperator> op_stack;
u32 paren = 0; // parentheses
for (i = 0; logical[i]; i++) {
if (isdigit(logical[i])) {
if (digit == (u32)-1) { // new digit start
@@ -284,7 +284,7 @@ void ParsedLogical::parseLogicalCombination(unsigned id, const char *logical,
if (logical[i] == '(') {
paren += 1;
} else if (logical[i] == ')') {
if (paren <= 0) {
if (paren == 0) {
throw LocatedParseError("Not enough left parentheses");
}
paren -= 1;

View File

@@ -34,14 +34,6 @@ using namespace std;
namespace ue2 {
#define UCP_FN(cat) \
CodePointSet getUcp##cat(void) { \
CodePointSet rv; \
for (u32 i = 0; i < ARRAY_LENGTH(ucp_##cat##_def); i += 2) { \
rv.setRange(ucp_##cat##_def[i], ucp_##cat##_def[i + 1]); \
} \
return rv; \
}
struct unicase {
unichar base;

View File

@@ -36,6 +36,15 @@
namespace ue2 {
#define UCP_FN(cat) \
CodePointSet getUcp##cat(void) { \
CodePointSet rv; \
for (u32 i = 0; i < ARRAY_LENGTH(ucp_##cat##_def); i += 2) { \
rv.setRange(ucp_##cat##_def[i], ucp_##cat##_def[i + 1]); \
} \
return rv; \
}
class CodePointSet;
void make_caseless(CodePointSet *cps);
bool flip_case(unichar *c);