-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathss_state.h
74 lines (69 loc) · 1.99 KB
/
ss_state.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef _SS_STATE_
#define _SS_STATE_
#include <sstream>
#include "common.h"
using namespace std;
typedef struct {
char* value;
bool typePattern;
bool typeCase;
} CaseStat;
class SwitchStatementState
{
public:
bool initialized;
bool dandlingDefault;
std::stack<CaseStat> sstack;
SwitchStatementState()
{
dandlingDefault=0x0;
initialized=false;
}
char* getCompleteText(char* statements)
{
stringstream ss;
int num = this->sstack.size();
if (num>0)
{
if (this->initialized) {
ss << "else";
} else {
this->initialized=true;
}
ss<<"if ";
bool c_s_first=true;
stringstream condStream;
while(!this->sstack.empty())
{
if(!c_s_first)
{
condStream << " or ";
} else
{
c_s_first=false;
}
if (this->sstack.top().typeCase)
{
condStream<<"( switch_var == "<<this->sstack.top().value<<")";
} else if (this->sstack.top().typePattern)
{
condStream<<"( string.match(switch_var,\""<<this->sstack.top().value<<"\") ~= nil )";
}
this->sstack.pop();
}
if (num>1)
{
ss <<"("<< condStream.str()<<")";
} else {
ss << condStream.str();
}
ss<<" then"<<endl<<statements;
}
if (dandlingDefault)
{
ss<<"else "<<endl<<statements;
}
return alloc_string((char*)ss.str().data());
}
};
#endif