-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
88 lines (79 loc) · 1.43 KB
/
test.cpp
File metadata and controls
88 lines (79 loc) · 1.43 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <map>
#include <vector>
#include <string>
#include <iostream>
using std::vector;
using std::string;
using std::map;
using std::cerr;
struct defined
{
enum Type{
OBJ_LIKE,
FUNC_LIKE,
};
const Type t;
vector<string> macro_body;
vector<string> param_list;
defined(Type t):t(t)
{
}
void push_macro(const char* s)
{
macro_body.push_back(s);
}
void push_macro(string& s)
{
macro_body.push_back(s);
}
void push_param(string& s)
{
param_list.push_back(s);
}
~defined()
{
macro_body.clear();
param_list.clear();
}
};
void warning(string s)
{
std::cerr << s << std::endl;
}
struct macro_defined
{
typedef map<string, defined> macros_type;
macros_type macros_map;
void push_defined(string& s, defined& d)
{
// if redefined
if(macros_map.find(s) != macros_map.end())
warning("redefined " + s);
macros_map.insert(macros_type::value_type(s, d));
}
void push_defined(string s)
{
push_defined(s, "1");
}
void push_defined(string s, string v)
{
defined d(defined::OBJ_LIKE);
d.push_macro(v);
push_defined(s, d);
}
string get_defined(string s)
{
string r;
return macros_map.find(s);
}
bool has_defined(string s)
{
return macros_map.find(s) != macros_map.end();
}
};
macro_defined g_macros;
int main(int argc, char ** argv)
{
g_macros.push_defined("X");
g_macros.push_defined("Y", "hello world");
}