Skip to content

Commit 808f5ee

Browse files
Adapt to Contour's best code quality & maintenance practice.
Signed-off-by: Christian Parpart <[email protected]>
1 parent 4ae771e commit 808f5ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1397
-3430
lines changed

.github/workflows/build.yml

+14
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ jobs:
215215
cmake -DCMAKE_BUILD_TYPE=Debug -DLIBTERMINAL_BUILD_BENCH_HEADLESS=ON -DCONTOUR_QT_VERSION=6 -S . -B build
216216
cmake --build build/ -j2
217217
./build/src/crispy/crispy_test
218+
./build/src/regex_dfa/regex_dfa_test
218219
./build/src/vtparser/vtparser_test
219220
./build/src/vtbackend/vtbackend_test
220221
rm -rf _deps build
@@ -257,6 +258,8 @@ jobs:
257258
run: cmake --build build/
258259
- name: "test: crispy"
259260
run: ./build/src/crispy/crispy_test
261+
- name: "test: regex_dfa"
262+
run: ./build/src/regex_dfa/regex_dfa_test
260263
- name: "test: vtparser"
261264
run: ./build/src/vtparser/vtparser_test
262265
- name: "test: vtbackend"
@@ -326,6 +329,8 @@ jobs:
326329
run: cmake --build build/ --config Release
327330
- name: "test: crispy"
328331
run: .\build\src\crispy\Release\crispy_test.exe
332+
- name: "test: regex_dfa"
333+
run: .\build\src\regex_dfa\Release\regex_dfa_test.exe
329334
- name: "test: vtparser"
330335
run: .\build\src\vtparser\Release\vtparser_test.exe
331336
- name: "test: vtbackend"
@@ -450,6 +455,8 @@ jobs:
450455
run: cmake --build build/ -- -j3
451456
- name: "test: crispy"
452457
run: ./build/src/crispy/crispy_test
458+
- name: "test: regex_dfa"
459+
run: ./build/src/regex_dfa/regex_dfa_test
453460
- name: "test: vtparser"
454461
run: ./build/src/vtparser/vtparser_test
455462
- name: "test: vtbackend"
@@ -461,6 +468,7 @@ jobs:
461468
name: contour-ubuntu2204-tests
462469
path: |
463470
build/src/crispy/crispy_test
471+
build/src/regex_dfa/regex_dfa_test
464472
build/src/vtparser/vtparser_test
465473
build/src/vtbackend/vtbackend_test
466474
build/src/vtbackend/bench-headless
@@ -516,6 +524,8 @@ jobs:
516524
# run: cmake --build build/ -- -j3
517525
# - name: "test: crispy"
518526
# run: ./build/src/crispy/crispy_test
527+
# - name: "test: regex_dfa"
528+
# run: ./build/src/regex_dfa/regex_dfa_test
519529
# - name: "test: vtparser"
520530
# run: ./build/src/vtparser/vtparser_test
521531
# - name: "test: vtbackend"
@@ -664,6 +674,8 @@ jobs:
664674
run: cmake --build build/ -- -j3
665675
- name: "test: crispy"
666676
run: ./build/src/crispy/crispy_test
677+
- name: "test: regex_dfa"
678+
run: ./build/src/regex_dfa/regex_dfa_test
667679
- name: "test: vtparser"
668680
run: ./build/src/vtparser/vtparser_test
669681
- name: "test: vtbackend"
@@ -728,6 +740,8 @@ jobs:
728740
valgrind
729741
- name: "test: crispy (via valgrind)"
730742
run: valgrind --error-exitcode=64 ./build/src/crispy/crispy_test
743+
- name: "test: regex_dfa"
744+
run: valgrind --error-exitcode=64 ./build/src/regex_dfa/regex_dfa_test
731745
- name: "test: vtparser (via valgrind)"
732746
run: valgrind --error-exitcode=64 ./build/src/vtparser/vtparser_test
733747
- name: "test: vtbackend (via valgrind)"

src/regex_dfa/Alphabet.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ namespace regex_dfa
3232

3333
void Alphabet::insert(Symbol ch)
3434
{
35-
if (alphabet_.find(ch) == alphabet_.end())
35+
if (_alphabet.find(ch) == _alphabet.end())
3636
{
3737
DEBUG("Alphabet: insert '{:}'", prettySymbol(ch));
38-
alphabet_.insert(ch);
38+
_alphabet.insert(ch);
3939
}
4040
}
4141

@@ -45,7 +45,7 @@ string Alphabet::to_string() const
4545

4646
sstr << '{';
4747

48-
for (Symbol c: alphabet_)
48+
for (Symbol c: _alphabet)
4949
sstr << prettySymbol(c);
5050

5151
sstr << '}';

src/regex_dfa/Alphabet.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ class Alphabet
2525
using set_type = std::set<Symbol>;
2626
using iterator = set_type::iterator;
2727

28-
size_t size() const noexcept { return alphabet_.size(); }
28+
[[nodiscard]] size_t size() const noexcept { return _alphabet.size(); }
2929

3030
void insert(Symbol ch);
3131

32-
std::string to_string() const;
32+
[[nodiscard]] std::string to_string() const;
3333

34-
const iterator begin() const { return alphabet_.begin(); }
35-
const iterator end() const { return alphabet_.end(); }
34+
[[nodiscard]] iterator begin() const { return _alphabet.begin(); }
35+
[[nodiscard]] iterator end() const { return _alphabet.end(); }
3636

3737
private:
38-
set_type alphabet_;
38+
set_type _alphabet;
3939
};
4040

4141
} // namespace regex_dfa
@@ -54,7 +54,7 @@ struct formatter<regex_dfa::Alphabet>
5454
template <typename FormatContext>
5555
constexpr auto format(const regex_dfa::Alphabet& v, FormatContext& ctx)
5656
{
57-
return format_to(ctx.out(), "{}", v.to_string());
57+
return fmt::format_to(ctx.out(), "{}", v.to_string());
5858
}
5959
};
6060
} // namespace fmt

src/regex_dfa/CMakeLists.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ target_include_directories(regex_dfa PUBLIC ${PROJECT_SOURCE_DIR}/src ${CMAKE_SO
2121
target_link_libraries(regex_dfa PUBLIC fmt::fmt-header-only)
2222

2323
# ----------------------------------------------------------------------------
24-
if(TESTS)
24+
option(REGEX_DFA_TESTING "Enables building of unittests for regex_dfa library [default: ON]" ON)
25+
if(REGEX_DFA_TESTING)
26+
enable_testing()
2527
add_executable(regex_dfa_test
2628
regex_dfa_test.cpp
2729
DFABuilder_test.cpp
@@ -33,9 +35,9 @@ if(TESTS)
3335
State_test.cpp
3436
Symbols_test.cpp
3537
util/iterator_test.cpp
36-
util/testing.cpp
3738
)
3839

3940
target_link_libraries(regex_dfa_test PUBLIC regex_dfa)
41+
target_link_libraries(regex_dfa_test PUBLIC Catch2::Catch2)
4042
target_link_libraries(regex_dfa_test PUBLIC fmt::fmt-header-only)
41-
endif(TESTS)
43+
endif(REGEX_DFA_TESTING)

src/regex_dfa/CharStream.h

+15-15
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,41 @@ class CharStream
2727
class StringStream: public CharStream
2828
{
2929
public:
30-
explicit StringStream(std::string&& s): source_ { std::move(s) } {}
30+
explicit StringStream(std::string&& s): _source { std::move(s) } {}
3131

32-
[[nodiscard]] bool isEof() const noexcept override { return pos_ >= source_.size(); }
33-
char get() override { return source_[pos_++]; }
34-
void rollback(int count) override { pos_ -= count; }
35-
void rewind() override { pos_ = 0; }
32+
[[nodiscard]] bool isEof() const noexcept override { return _pos >= _source.size(); }
33+
char get() override { return _source[_pos++]; }
34+
void rollback(int count) override { _pos -= count; }
35+
void rewind() override { _pos = 0; }
3636

3737
private:
38-
std::string source_;
39-
size_t pos_ = 0;
38+
std::string _source;
39+
size_t _pos = 0;
4040
};
4141

4242
class StandardStream: public CharStream
4343
{
4444
public:
4545
explicit StandardStream(std::istream* source);
4646

47-
[[nodiscard]] bool isEof() const noexcept override { return !source_->good(); }
48-
char get() override { return static_cast<char>(source_->get()); }
47+
[[nodiscard]] bool isEof() const noexcept override { return !_source->good(); }
48+
char get() override { return static_cast<char>(_source->get()); }
4949

5050
void rollback(int count) override
5151
{
52-
source_->clear();
53-
source_->seekg(-count, std::ios::cur);
52+
_source->clear();
53+
_source->seekg(-count, std::ios::cur);
5454
}
5555

5656
void rewind() override
5757
{
58-
source_->clear();
59-
source_->seekg(initialOffset_, std::ios::beg);
58+
_source->clear();
59+
_source->seekg(_initialOffset, std::ios::beg);
6060
}
6161

6262
private:
63-
std::istream* source_;
64-
std::streamoff initialOffset_;
63+
std::istream* _source;
64+
std::streamoff _initialOffset;
6565
};
6666

6767
} // namespace regex_dfa

src/regex_dfa/Compiler.cpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ namespace regex_dfa
2727

2828
void Compiler::parse(string text)
2929
{
30-
parse(make_unique<stringstream>(move(text)));
30+
parse(make_unique<stringstream>(std::move(text)));
3131
}
3232

3333
void Compiler::parse(unique_ptr<istream> stream)
3434
{
35-
declareAll(RuleParser { move(stream) }.parseRules());
35+
declareAll(RuleParser { std::move(stream) }.parseRules());
3636
}
3737

3838
void Compiler::declareAll(RuleList rules)
@@ -81,7 +81,7 @@ void Compiler::declareAll(RuleList rules)
8181
else
8282
names_[rule.tag] = rule.name;
8383

84-
rules_.emplace_back(move(rule));
84+
rules_.emplace_back(std::move(rule));
8585
}
8686
}
8787

@@ -118,7 +118,7 @@ MultiDFA Compiler::compileMultiDFA(OvershadowMap* overshadows)
118118
for (const auto& fa: fa_)
119119
dfaMap[fa.first] = DFABuilder { fa.second.clone() }.construct(overshadows);
120120

121-
return constructMultiDFA(move(dfaMap));
121+
return constructMultiDFA(std::move(dfaMap));
122122
}
123123

124124
DFA Compiler::compileDFA(OvershadowMap* overshadows)
@@ -134,7 +134,7 @@ DFA Compiler::compileMinimalDFA()
134134

135135
LexerDef Compiler::compile()
136136
{
137-
return generateTables(compileMinimalDFA(), containsBeginOfLine_, move(names_));
137+
return generateTables(compileMinimalDFA(), containsBeginOfLine_, std::move(names_));
138138
}
139139

140140
LexerDef Compiler::compileMulti(OvershadowMap* overshadows)
@@ -144,7 +144,7 @@ LexerDef Compiler::compileMulti(OvershadowMap* overshadows)
144144
return generateTables(multiDFA, containsBeginOfLine_, names());
145145
}
146146

147-
LexerDef Compiler::generateTables(const DFA& dfa, bool requiresBeginOfLine, const map<Tag, string>& names)
147+
LexerDef Compiler::generateTables(const DFA& dfa, bool requiresBeginOfLine, map<Tag, string> names)
148148
{
149149
const Alphabet alphabet = dfa.alphabet();
150150
TransitionMap transitionMap;
@@ -161,15 +161,13 @@ LexerDef Compiler::generateTables(const DFA& dfa, bool requiresBeginOfLine, cons
161161
// TODO: many initial states !
162162
return LexerDef { { { "INITIAL", dfa.initialState() } },
163163
requiresBeginOfLine,
164-
move(transitionMap),
165-
move(acceptStates),
164+
std::move(transitionMap),
165+
std::move(acceptStates),
166166
dfa.backtracking(),
167-
move(names) };
167+
std::move(names) };
168168
}
169169

170-
LexerDef Compiler::generateTables(const MultiDFA& multiDFA,
171-
bool requiresBeginOfLine,
172-
const map<Tag, string>& names)
170+
LexerDef Compiler::generateTables(const MultiDFA& multiDFA, bool requiresBeginOfLine, map<Tag, string> names)
173171
{
174172
const Alphabet alphabet = multiDFA.dfa.alphabet();
175173
TransitionMap transitionMap;
@@ -184,8 +182,8 @@ LexerDef Compiler::generateTables(const MultiDFA& multiDFA,
184182
acceptStates.emplace(s, *multiDFA.dfa.acceptTag(s));
185183

186184
// TODO: many initial states !
187-
return LexerDef { multiDFA.initialStates, requiresBeginOfLine, move(transitionMap),
188-
move(acceptStates), multiDFA.dfa.backtracking(), move(names) };
185+
return LexerDef { multiDFA.initialStates, requiresBeginOfLine, std::move(transitionMap),
186+
std::move(acceptStates), multiDFA.dfa.backtracking(), std::move(names) };
189187
}
190188

191189
} // namespace regex_dfa

src/regex_dfa/Compiler.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class Compiler
4848
*/
4949
void declareAll(RuleList rules);
5050

51-
const RuleList& rules() const noexcept { return rules_; }
52-
const TagNameMap& names() const noexcept { return names_; }
53-
size_t size() const;
51+
[[nodiscard]] const RuleList& rules() const noexcept { return rules_; }
52+
[[nodiscard]] const TagNameMap& names() const noexcept { return names_; }
53+
[[nodiscard]] size_t size() const;
5454

5555
/**
5656
* Compiles all previousely parsed rules into a DFA.
@@ -81,12 +81,12 @@ class Compiler
8181
*
8282
* @see Lexer
8383
*/
84-
static LexerDef generateTables(const DFA& dfa, bool requiresBeginOfLine, const TagNameMap& names);
85-
static LexerDef generateTables(const MultiDFA& dfa, bool requiresBeginOfLine, const TagNameMap& names);
84+
static LexerDef generateTables(const DFA& dfa, bool requiresBeginOfLine, TagNameMap names);
85+
static LexerDef generateTables(const MultiDFA& dfa, bool requiresBeginOfLine, TagNameMap names);
8686

87-
const std::map<std::string, NFA>& automata() const { return fa_; }
87+
[[nodiscard]] const std::map<std::string, NFA>& automata() const { return fa_; }
8888

89-
bool containsBeginOfLine() const noexcept { return containsBeginOfLine_; }
89+
[[nodiscard]] bool containsBeginOfLine() const noexcept { return containsBeginOfLine_; }
9090

9191
private:
9292
/**

src/regex_dfa/DFA.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Alphabet DFA::alphabet() const
3737
{
3838
Alphabet alphabet;
3939
for (const State& state: states_)
40-
for (const pair<Symbol, StateId>& t: state.transitions)
40+
for (pair<Symbol, StateId> const t: state.transitions)
4141
alphabet.insert(t.first);
4242

4343
return alphabet;
@@ -118,12 +118,12 @@ void DFA::prepareStateIds(StateId baseId, StateId q0)
118118
AcceptMap remapped;
119119
for (auto& a: acceptTags_)
120120
remapped[transformId(a.first)] = a.second;
121-
acceptTags_ = move(remapped);
121+
acceptTags_ = std::move(remapped);
122122

123123
BacktrackingMap backtracking;
124124
for (const auto& bt: backtrackStates_)
125125
backtracking[transformId(bt.first)] = transformId(bt.second);
126-
backtrackStates_ = move(backtracking);
126+
backtrackStates_ = std::move(backtracking);
127127

128128
initialState_ = q0;
129129
}

0 commit comments

Comments
 (0)