-
Notifications
You must be signed in to change notification settings - Fork 6
/
MacroScopeClassifier.h
171 lines (163 loc) · 3.12 KB
/
MacroScopeClassifier.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#ifndef MACROSCOPECLASSIFIER_H
#define MACROSCOPECLASSIFIER_H
// (c) Copyright
// ALL RIGHTS RESERVED
/**
* @file MacroScopeClassifier.h
* @brief defines various classification criteria for macros
* @version 1.0
* @author Aditya Kumar
* @details
* compiles with g++-4.5 or higher,
* for compiling pass -std=c++0x to the compiler
*/
#include<ostream>
/**
* @enum PPOperation
*/
enum class PPOperation
{
define,
undef,
conditional,
includes,
pragma,
warning,
line,
error
};
inline std::ostream& operator<<(std::ostream& os, PPOperation const& oper)
{
switch(oper){
case PPOperation::define:
os<<"define";
break;
case PPOperation::undef:
os<<"undef";
break;
case PPOperation::conditional:
os<<"conditional";
break;
case PPOperation::includes:
os<<"includes";
break;
case PPOperation::pragma:
os<<"pragma";
break;
case PPOperation::warning:
os<<"warning";
break;
case PPOperation::line:
os<<"line";
break;
case PPOperation::error:
os<<"error";
break;
default:
os<<"unknown";
break;
}
return os;
}
/**
* @enum MacroCategory
*/
enum class MacroCategory
{
none,
null_define,//#define X i.e. without replacement_list
object_like,
function_like,
variadic
};
inline std::ostream& operator<<(std::ostream& os, MacroCategory const& m_cat )
{
switch(m_cat){
case MacroCategory::none:
os<<"none";
break;
case MacroCategory::null_define:
os<<"null_define";
break;
case MacroCategory::object_like:
os<<"object_like";
break;
case MacroCategory::function_like:
os<<"function_like";
break;
case MacroCategory::variadic:
os<<"variadic";
break;
}
return os;
}
/**
* @enum MacroScopeCategory
*/
struct MacroScopeCategory
{
MacroScopeCategory()
:predefined(false),
local(true),
inside_function(false),
inside_class(false)
{ }
bool predefined;
bool local;
bool inside_function;
bool inside_class;
};
inline std::ostream& operator<<(std::ostream& os, MacroScopeCategory const& m_cat )
{
if(m_cat.predefined)
os<<"predefined\t";
if(m_cat.local)
os<<"local\t";
if(m_cat.inside_function)
os<<"inside_function\t";
if(m_cat.inside_class)
os<<"inside_class\t";
else
os<<"Not classified\t";
return os;
}
/*
inline std::ostream& operator<<(std::ostream& os, MacroScopeCategory const& m_cat )
{
switch(m_cat){
case MacroScopeCategory::predefined:
os<<"predefine";
break;
case MacroScopeCategory::local:
os<<"local";
break;
case MacroScopeCategory::inside_function:
os<<"inside_function";
break;
case MacroScopeCategory::inside_class:
os<<"inside_class";
break;
}
return os;
}*/
/**
* @enum CondCategory
*/
enum class CondCategory
{
config,
local
};
inline std::ostream& operator<<(std::ostream& os, CondCategory const& c_cat )
{
switch(c_cat){
case CondCategory::config:
os<<"config";
break;
case CondCategory::local:
os<<"local";
break;
}
return os;
}
#endif // MACROSCOPECLASSIFIER_H