8
8
import java .util .Stack ;
9
9
10
10
abstract class CPreprocessorParserBase extends Parser {
11
- protected CPreprocessorParserBase (TokenStream input )
12
- {
11
+ protected CPreprocessorParserBase (TokenStream input ) {
13
12
super (input );
14
13
conditions .push (true );
15
14
ConditionalSymbols .add ("DEBUG" );
@@ -19,206 +18,184 @@ protected CPreprocessorParserBase(TokenStream input)
19
18
public HashSet <String > ConditionalSymbols = new HashSet <String >();
20
19
public HashSet <String > IncludeSymbols = new HashSet <String >();
21
20
22
- protected Boolean AllConditions ()
23
- {
24
- for (Boolean condition : conditions )
25
- {
21
+ protected Boolean AllConditions () {
22
+ for (Boolean condition : conditions ) {
26
23
if (!condition )
27
24
return false ;
28
25
}
29
26
return true ;
30
27
}
31
28
32
- protected void OnPreprocessorDirectiveInclude ()
33
- {
29
+ protected void OnPreprocessorDirectiveInclude () {
34
30
ParserRuleContext c = this ._ctx ;
35
31
CPreprocessorParser .PreprocessorIncludeDeclarationContext d = (CPreprocessorParser .PreprocessorIncludeDeclarationContext ) c ;
36
- IncludeSymbols .add (d .getText ());
32
+ IncludeSymbols .add (d .IncludeText (). getText ());
37
33
d .value = AllConditions ();
38
34
}
39
35
40
- protected void OnPreprocessorDirectiveDefine ()
41
- {
36
+ protected void OnPreprocessorDirectiveDefine () {
42
37
ParserRuleContext c = this ._ctx ;
43
- CPreprocessorParser .PreprocessorDeclarationContext d = (CPreprocessorParser .PreprocessorDeclarationContext )c ;
38
+ CPreprocessorParser .PreprocessorDeclarationContext d = (CPreprocessorParser .PreprocessorDeclarationContext ) c ;
44
39
ConditionalSymbols .add (d .CONDITIONAL_SYMBOL ().getText ());
45
40
d .value = AllConditions ();
46
41
}
47
42
48
- protected void OnPreprocessorDirectiveUndef ()
49
- {
43
+ protected void OnPreprocessorDirectiveUndef () {
50
44
ParserRuleContext c = this ._ctx ;
51
- CPreprocessorParser .PreprocessorDeclarationContext d = (CPreprocessorParser .PreprocessorDeclarationContext )c ;
45
+ CPreprocessorParser .PreprocessorDeclarationContext d = (CPreprocessorParser .PreprocessorDeclarationContext ) c ;
52
46
ConditionalSymbols .remove (d .CONDITIONAL_SYMBOL ().getText ());
53
47
d .value = AllConditions ();
54
48
}
55
49
56
- protected void OnPreprocessorDirectiveIf ()
57
- {
50
+ protected void OnPreprocessorDirectiveIf () {
58
51
ParserRuleContext c = this ._ctx ;
59
- CPreprocessorParser .PreprocessorConditionalContext d = (CPreprocessorParser .PreprocessorConditionalContext )c ;
60
- d .value = d .expr .value .equals ("true" ) && AllConditions ();
61
- conditions .push (d .expr .value .equals ("true" ));
52
+ CPreprocessorParser .PreprocessorConditionalContext d = (CPreprocessorParser .PreprocessorConditionalContext ) c ;
53
+ if (d .expr .value != null ) {
54
+ d .value = d .expr .value .equals ("true" ) && AllConditions ();
55
+ conditions .push (d .expr .value .equals ("true" ));
56
+ }
62
57
}
63
58
64
- protected void OnPreprocessorDirectiveIfdef ()
65
- {
59
+ protected void OnPreprocessorDirectiveIfdef () {
66
60
ParserRuleContext c = this ._ctx ;
67
- CPreprocessorParser .PreprocessorDeclarationContext d = (CPreprocessorParser .PreprocessorDeclarationContext )c ;
61
+ CPreprocessorParser .PreprocessorDeclarationContext d = (CPreprocessorParser .PreprocessorDeclarationContext ) c ;
68
62
ConditionalSymbols .add (d .CONDITIONAL_SYMBOL ().getText ());
69
63
d .value = AllConditions ();
70
64
}
71
65
72
- protected void OnPreprocessorDirectiveIfndef ()
73
- {
66
+ protected void OnPreprocessorDirectiveIfndef () {
74
67
ParserRuleContext c = this ._ctx ;
75
- CPreprocessorParser .PreprocessorDeclarationContext d = (CPreprocessorParser .PreprocessorDeclarationContext )c ;
68
+ CPreprocessorParser .PreprocessorDeclarationContext d = (CPreprocessorParser .PreprocessorDeclarationContext ) c ;
76
69
ConditionalSymbols .add (d .CONDITIONAL_SYMBOL ().getText ());
77
70
d .value = AllConditions ();
78
71
}
79
72
80
- protected void OnPreprocessorDirectiveElif ()
81
- {
73
+ protected void OnPreprocessorDirectiveElif () {
82
74
ParserRuleContext c = this ._ctx ;
83
- CPreprocessorParser .PreprocessorConditionalContext d = (CPreprocessorParser .PreprocessorConditionalContext )c ;
84
- if (!conditions .peek ())
85
- {
75
+ CPreprocessorParser .PreprocessorConditionalContext d = (CPreprocessorParser .PreprocessorConditionalContext ) c ;
76
+ if (!conditions .peek ()) {
86
77
conditions .pop ();
87
78
d .value = d .expr .value .equals ("true" ) && AllConditions ();
88
79
conditions .push (d .expr .value .equals ("true" ));
89
- }
90
- else
91
- {
80
+ } else {
92
81
d .value = false ;
93
82
}
94
83
}
95
84
96
- protected void OnPreprocessorDirectiveElse ()
97
- {
85
+ protected void OnPreprocessorDirectiveElse () {
98
86
ParserRuleContext c = this ._ctx ;
99
- CPreprocessorParser .PreprocessorConditionalContext d = (CPreprocessorParser .PreprocessorConditionalContext )c ;
100
- if (!conditions .peek ())
101
- {
102
- conditions .pop ();
103
- d .value = true && AllConditions ();
104
- conditions .push (true );
105
- }
106
- else
107
- {
87
+ CPreprocessorParser .PreprocessorConditionalContext d = (CPreprocessorParser .PreprocessorConditionalContext ) c ;
88
+ if (!conditions .isEmpty ()) {
89
+ if (!conditions .peek ()) {
90
+ conditions .pop ();
91
+ d .value = true && AllConditions ();
92
+ conditions .push (true );
93
+ } else {
94
+ d .value = false ;
95
+ }
96
+ } else {
108
97
d .value = false ;
109
98
}
110
99
}
111
100
112
- protected void OnPreprocessorDirectiveEndif ()
113
- {
101
+ protected void OnPreprocessorDirectiveEndif () {
114
102
ParserRuleContext c = this ._ctx ;
115
- CPreprocessorParser .PreprocessorConditionalContext d = (CPreprocessorParser .PreprocessorConditionalContext )c ;
116
- conditions .pop ();
117
- d .value = conditions .peek ();
103
+ CPreprocessorParser .PreprocessorConditionalContext d = (CPreprocessorParser .PreprocessorConditionalContext ) c ;
104
+ if (!conditions .isEmpty ()) {
105
+ conditions .pop ();
106
+ if (!conditions .isEmpty ()) {
107
+ d .value = conditions .peek ();
108
+ }
109
+ }
118
110
}
119
111
120
- protected void OnPreprocessorDirectiveError ()
121
- {
112
+ protected void OnPreprocessorDirectiveError () {
122
113
ParserRuleContext c = this ._ctx ;
123
- CPreprocessorParser .PreprocessorDiagnosticContext d = (CPreprocessorParser .PreprocessorDiagnosticContext )c ;
114
+ CPreprocessorParser .PreprocessorDiagnosticContext d = (CPreprocessorParser .PreprocessorDiagnosticContext ) c ;
124
115
d .value = AllConditions ();
125
116
}
126
117
127
- protected void OnPreprocessorDirectiveWarning ()
128
- {
118
+ protected void OnPreprocessorDirectiveWarning () {
129
119
ParserRuleContext c = this ._ctx ;
130
- CPreprocessorParser .PreprocessorDiagnosticContext d = (CPreprocessorParser .PreprocessorDiagnosticContext )c ;
120
+ CPreprocessorParser .PreprocessorDiagnosticContext d = (CPreprocessorParser .PreprocessorDiagnosticContext ) c ;
131
121
d .value = AllConditions ();
132
122
}
133
123
134
- protected void OnPreprocessorDirectiveRegion ()
135
- {
124
+ protected void OnPreprocessorDirectiveRegion () {
136
125
ParserRuleContext c = this ._ctx ;
137
- CPreprocessorParser .PreprocessorRegionContext d = (CPreprocessorParser .PreprocessorRegionContext )c ;
126
+ CPreprocessorParser .PreprocessorRegionContext d = (CPreprocessorParser .PreprocessorRegionContext ) c ;
138
127
d .value = AllConditions ();
139
128
}
140
129
141
- protected void OnPreprocessorDirectiveEndregion ()
142
- {
130
+ protected void OnPreprocessorDirectiveEndregion () {
143
131
ParserRuleContext c = this ._ctx ;
144
- CPreprocessorParser .PreprocessorRegionContext d = (CPreprocessorParser .PreprocessorRegionContext )c ;
132
+ CPreprocessorParser .PreprocessorRegionContext d = (CPreprocessorParser .PreprocessorRegionContext ) c ;
145
133
d .value = AllConditions ();
146
134
}
147
135
148
- protected void OnPreprocessorDirectivePragma ()
149
- {
136
+ protected void OnPreprocessorDirectivePragma () {
150
137
ParserRuleContext c = this ._ctx ;
151
- CPreprocessorParser .PreprocessorPragmaContext d = (CPreprocessorParser .PreprocessorPragmaContext )c ;
138
+ CPreprocessorParser .PreprocessorPragmaContext d = (CPreprocessorParser .PreprocessorPragmaContext ) c ;
152
139
d .value = AllConditions ();
153
140
}
154
141
155
- protected void OnPreprocessorDirectiveNullable ()
156
- {
142
+ protected void OnPreprocessorDirectiveNullable () {
157
143
ParserRuleContext c = this ._ctx ;
158
- CPreprocessorParser .PreprocessorNullableContext d = (CPreprocessorParser .PreprocessorNullableContext )c ;
144
+ CPreprocessorParser .PreprocessorNullableContext d = (CPreprocessorParser .PreprocessorNullableContext ) c ;
159
145
d .value = AllConditions ();
160
146
}
161
147
162
- protected void OnPreprocessorExpressionTrue ()
163
- {
148
+ protected void OnPreprocessorExpressionTrue () {
164
149
ParserRuleContext c = this ._ctx ;
165
- CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext )c ;
150
+ CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext ) c ;
166
151
d .value = "true" ;
167
152
}
168
153
169
- protected void OnPreprocessorExpressionFalse ()
170
- {
154
+ protected void OnPreprocessorExpressionFalse () {
171
155
ParserRuleContext c = this ._ctx ;
172
- CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext )c ;
156
+ CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext ) c ;
173
157
d .value = "false" ;
174
158
}
175
159
176
- protected void OnPreprocessorExpressionConditionalSymbol ()
177
- {
160
+ protected void OnPreprocessorExpressionConditionalSymbol () {
178
161
ParserRuleContext c = this ._ctx ;
179
- CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext )c ;
162
+ CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext ) c ;
180
163
d .value = ConditionalSymbols .contains (d .CONDITIONAL_SYMBOL ().getText ()) ? "true" : "false" ;
181
164
}
182
165
183
- protected void OnPreprocessorExpressionConditionalOpenParens ()
184
- {
166
+ protected void OnPreprocessorExpressionConditionalOpenParens () {
185
167
ParserRuleContext c = this ._ctx ;
186
- CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext )c ;
168
+ CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext ) c ;
187
169
d .value = d .expr .value ;
188
170
}
189
171
190
- protected void OnPreprocessorExpressionConditionalBang ()
191
- {
172
+ protected void OnPreprocessorExpressionConditionalBang () {
192
173
ParserRuleContext c = this ._ctx ;
193
- CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext )c ;
174
+ CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext ) c ;
194
175
d .value = d .expr .value .equals ("true" ) ? "false" : "true" ;
195
176
}
196
177
197
- protected void OnPreprocessorExpressionConditionalEq ()
198
- {
178
+ protected void OnPreprocessorExpressionConditionalEq () {
199
179
ParserRuleContext c = this ._ctx ;
200
- CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext )c ;
180
+ CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext ) c ;
201
181
d .value = (d .expr1 .value == d .expr2 .value ? "true" : "false" );
202
182
}
203
183
204
- protected void OnPreprocessorExpressionConditionalNe ()
205
- {
184
+ protected void OnPreprocessorExpressionConditionalNe () {
206
185
ParserRuleContext c = this ._ctx ;
207
- CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext )c ;
186
+ CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext ) c ;
208
187
d .value = (d .expr1 .value != d .expr2 .value ? "true" : "false" );
209
188
}
210
189
211
- protected void OnPreprocessorExpressionConditionalAnd ()
212
- {
190
+ protected void OnPreprocessorExpressionConditionalAnd () {
213
191
ParserRuleContext c = this ._ctx ;
214
- CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext )c ;
192
+ CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext ) c ;
215
193
d .value = (d .expr1 .value .equals ("true" ) && d .expr2 .value .equals ("true" ) ? "true" : "false" );
216
194
}
217
195
218
- protected void OnPreprocessorExpressionConditionalOr ()
219
- {
196
+ protected void OnPreprocessorExpressionConditionalOr () {
220
197
ParserRuleContext c = this ._ctx ;
221
- CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext )c ;
198
+ CPreprocessorParser .Preprocessor_expressionContext d = (CPreprocessorParser .Preprocessor_expressionContext ) c ;
222
199
d .value = (d .expr1 .value .equals ("true" ) || d .expr2 .value .equals ("true" ) ? "true" : "false" );
223
200
}
224
201
}
0 commit comments