-
Notifications
You must be signed in to change notification settings - Fork 1
/
thread.cpp
57 lines (47 loc) · 2.5 KB
/
thread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "thread.h"
#include "nfaNode.h"
using namespace std;
using namespace rgx;
rgx::_thread::_thread(const visitor_ptr<_NFA_Node> &pc, unsigned int maxCaptureSlot, unsigned int sp, unsigned int edgeIndex, matchMode m)
: _sp(sp), _nodePtr(pc), _edgeIndex(edgeIndex), _capture(new matchObj(maxCaptureSlot)), _mode(m), _startPosition(m) {
}
rgx::_thread::_thread(const visitor_ptr<_NFA_Node> &pc, unsigned int sp, unsigned int edgeIndex, const stack<unsigned int> &loopstack, unique_ptr<matchObj>&& capture, matchMode m)
: _sp(sp), _nodePtr(pc), _edgeIndex(edgeIndex), _loopTimes(loopstack), _capture(std::move(capture)), _mode(m), _startPosition(m) {
}
rgx::_thread::_thread(const _thread& thread)
: _sp(thread._sp), _nodePtr(thread._nodePtr), _edgeIndex(thread._edgeIndex), _loopTimes(thread._loopTimes), _capture(new matchObj(*thread._capture)), _mode(thread._mode), _startPosition(thread._startPosition) {
}
rgx::_thread::_thread(_thread&& thread)
: _sp(thread._sp), _nodePtr(thread._nodePtr), _edgeIndex(thread._edgeIndex), _loopTimes(thread._loopTimes), _capture(std::move(thread._capture)), _mode(thread._mode), _startPosition(thread._startPosition) {
}
int rgx::_thread::match(const u16string& input, stack<_thread> &threadstack) {
// cout << "\n thread started..\n" << endl;
while (_nodePtr->edges.size() != 0 && _nodePtr->edges[_edgeIndex]->match(input, *this, threadstack) == 0) {
;
}
// cout << "\n thread ended, edgesnumber :" << _nodePtr->edges.size() << endl;
if (_nodePtr->edges.size() == 0) {
//到达结束点
// cout << "zhengquede jieguio" << endl;
// _capture->justToTest("abcaabc");
return 0;
} else {
return -1;
}
}
void rgx::_thread::transTo(const visitor_ptr<_NFA_Node>& pc, const u16string& input, stack<_thread>& threadstack) {
//这里之所以可以按照任意顺序添加,因为在这里的NFA如果出现一个节点发出多条边
//这些边是一定不存在贪婪关系的,因为循环的路径控制不在这里
//将线程状态移动至pc,若pc中有多条边,将其他的边加入线程栈
_edgeIndex = 0;
if (pc->edges.size() <= 1) {
_nodePtr = pc;
} else if (pc->edges.size() > 1) {
_nodePtr = pc;
for (unsigned int i = 1; i < pc->edges.size(); ++i) {
if (pc->edges[i]->lookahead(input, _sp)) {
threadstack.push(_thread(pc, _sp, i, _loopTimes, unique_ptr<matchObj>(new matchObj(*_capture)), _mode));
}
}
}
}