Commit | Line | Data |
---|---|---|
0708f913 | 1 | (* Yoann Padioleau |
ae4735db C |
2 | * |
3 | * Copyright (C) 2010, University of Copenhagen DIKU and INRIA. | |
0708f913 C |
4 | * Copyright (C) 2007, 2008 Ecole des Mines de Nantes |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License (GPL) | |
8 | * version 2 as published by the Free Software Foundation. | |
ae4735db | 9 | * |
0708f913 C |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * file license.txt for more details. | |
14 | *) | |
15 | ||
16 | ||
34e49164 C |
17 | open Common |
18 | ||
19 | open Parser_c | |
20 | ||
21 | (*****************************************************************************) | |
22 | (* Is_xxx, categories *) | |
23 | (*****************************************************************************) | |
24 | ||
ae4735db | 25 | (* could define a type token_class = Comment | Ident | Operator | ... |
0708f913 | 26 | * update: now token_c can maybe do that. |
ae4735db | 27 | * but still, sometimes tokens belon to multiple classes. Could maybe |
0708f913 | 28 | * return then a set of classes. |
91eba41f C |
29 | *) |
30 | ||
34e49164 C |
31 | let is_space = function |
32 | | TCommentSpace _ -> true | |
485bce71 | 33 | | TCommentNewline _ -> true |
34e49164 C |
34 | | _ -> false |
35 | ||
485bce71 C |
36 | let is_whitespace = is_space |
37 | ||
0708f913 | 38 | let is_just_comment_or_space = function |
34e49164 C |
39 | | TComment _ -> true |
40 | | TCommentSpace _ -> true | |
485bce71 | 41 | | TCommentNewline _ -> true |
34e49164 | 42 | | _ -> false |
0708f913 | 43 | let is_real_comment = is_just_comment_or_space |
34e49164 C |
44 | |
45 | let is_just_comment = function | |
46 | | TComment _ -> true | |
47 | | _ -> false | |
48 | ||
0708f913 C |
49 | |
50 | ||
51 | ||
34e49164 | 52 | let is_comment = function |
ae4735db C |
53 | | TComment _ |
54 | | TCommentSpace _ | TCommentNewline _ | |
55 | | TCommentCpp _ | |
34e49164 C |
56 | | TCommentMisc _ -> true |
57 | | _ -> false | |
58 | ||
0708f913 C |
59 | (* coupling with comment_annotater_c.ml. |
60 | * In fact more tokens than comments are not in the ast, but | |
ae4735db | 61 | * they were usually temporally created by ocamllex and removed |
0708f913 C |
62 | * in parsing_hacks. |
63 | *) | |
64 | let is_not_in_ast = is_comment | |
34e49164 C |
65 | |
66 | let is_fake_comment = function | |
ae4735db | 67 | | TCommentCpp _ | TCommentMisc _ |
34e49164 C |
68 | -> true |
69 | | _ -> false | |
70 | ||
ae4735db | 71 | let is_not_comment x = |
34e49164 C |
72 | not (is_comment x) |
73 | ||
74 | ||
0708f913 | 75 | (* ---------------------------------------------------------------------- *) |
485bce71 | 76 | |
34e49164 | 77 | let is_cpp_instruction = function |
ae4735db | 78 | | TInclude _ |
485bce71 | 79 | | TDefine _ |
ae4735db | 80 | | TIfdef _ | TIfdefelse _ | TIfdefelif _ | TEndif _ |
34e49164 | 81 | | TIfdefBool _ | TIfdefMisc _ | TIfdefVersion _ |
ae4735db | 82 | | TUndef _ |
485bce71 C |
83 | | TCppDirectiveOther _ |
84 | -> true | |
85 | | _ -> false | |
86 | ||
87 | ||
88 | let is_gcc_token = function | |
ae4735db C |
89 | | Tasm _ |
90 | | Tinline _ | |
91 | | Tattribute _ | |
92 | | Ttypeof _ | |
34e49164 C |
93 | -> true |
94 | | _ -> false | |
95 | ||
96 | ||
97 | ||
98 | ||
0708f913 | 99 | (* ---------------------------------------------------------------------- *) |
34e49164 C |
100 | let is_opar = function |
101 | | TOPar _ | TOParDefine _ -> true | |
102 | | _ -> false | |
103 | ||
104 | let is_cpar = function | |
105 | | TCPar _ | TCParEOL _ -> true | |
106 | | _ -> false | |
107 | ||
485bce71 C |
108 | |
109 | let is_obrace = function | |
110 | | TOBrace _ | TOBraceDefineInit _ -> true | |
111 | | _ -> false | |
112 | ||
113 | let is_cbrace = function | |
114 | | TCBrace _ -> true | |
ae4735db | 115 | | _ -> false |
485bce71 C |
116 | |
117 | ||
118 | ||
119 | ||
0708f913 | 120 | (* ---------------------------------------------------------------------- *) |
708f4980 C |
121 | |
122 | (* end of file *) | |
34e49164 C |
123 | let is_eof = function |
124 | | EOF x -> true | |
125 | | _ -> false | |
126 | ||
485bce71 | 127 | |
708f4980 C |
128 | (* end of macro *) |
129 | let is_eom = function | |
130 | | TDefEOL _ -> true | |
131 | | _ -> false | |
485bce71 | 132 | |
34e49164 | 133 | let is_statement = function |
ae4735db | 134 | | Tfor _ | Tdo _ | Tif _ | Twhile _ | Treturn _ |
34e49164 | 135 | | Tbreak _ | Telse _ | Tswitch _ | Tcase _ | Tcontinue _ |
ae4735db | 136 | | Tgoto _ |
34e49164 C |
137 | | TPtVirg _ |
138 | | TMacroIterator _ | |
139 | -> true | |
140 | | _ -> false | |
141 | ||
142 | (* is_start_of_something is used in parse_c for error recovery, to find | |
143 | * a synchronisation token. | |
ae4735db | 144 | * |
34e49164 C |
145 | * Would like to put TIdent or TDefine, TIfdef but they can be in the |
146 | * middle of a function, for instance with label:. | |
ae4735db | 147 | * |
34e49164 C |
148 | * Could put Typedefident but fired ? it would work in error recovery |
149 | * on the already_passed tokens, which has been already gone in the | |
150 | * Parsing_hacks.lookahead machinery, but it will not work on the | |
151 | * "next" tokens. But because the namespace for labels is different | |
152 | * from namespace for ident/typedef, we can use the name for a typedef | |
ae4735db C |
153 | * for a label and so dangerous to put Typedefident at true here. |
154 | * | |
34e49164 C |
155 | * Can look in parser_c.output to know what can be at toplevel |
156 | * at the very beginning. | |
157 | *) | |
158 | ||
159 | let is_start_of_something = function | |
ae4735db | 160 | | Tchar _ | Tshort _ | Tint _ | Tdouble _ | Tfloat _ | Tlong _ |
1eddfd50 | 161 | | Tunsigned _ | Tsigned _ | Tvoid _ | Tsize_t _ | Tssize_t _ | Tptrdiff_t _ |
34e49164 C |
162 | | Tauto _ | Tregister _ | Textern _ | Tstatic _ |
163 | | Tconst _ | Tvolatile _ | |
164 | | Ttypedef _ | |
ae4735db | 165 | | Tstruct _ | Tunion _ | Tenum _ |
34e49164 C |
166 | -> true |
167 | | _ -> false | |
168 | ||
169 | ||
170 | ||
171 | let is_binary_operator = function | |
ae4735db C |
172 | | TOrLog _ | TAndLog _ | TOr _ | TXor _ | TAnd _ |
173 | | TEqEq _ | TNotEq _ | TInf _ | TSup _ | TInfEq _ | TSupEq _ | |
174 | | TShl _ | TShr _ | |
175 | | TPlus _ | TMinus _ | TMul _ | TDiv _ | TMod _ | |
34e49164 | 176 | -> true |
ae4735db | 177 | | _ -> false |
34e49164 C |
178 | |
179 | let is_stuff_taking_parenthized = function | |
ae4735db C |
180 | | Tif _ |
181 | | Twhile _ | |
34e49164 C |
182 | | Tswitch _ |
183 | | Ttypeof _ | |
184 | | TMacroIterator _ | |
ae4735db | 185 | -> true |
34e49164 C |
186 | | _ -> false |
187 | ||
91eba41f | 188 | |
0708f913 | 189 | (* used in the algorithms for "10 most problematic errors" *) |
91eba41f C |
190 | let is_ident_like = function |
191 | | TIdent _ | |
192 | | TypedefIdent _ | |
193 | | TIdentDefine _ | |
194 | | TDefParamVariadic _ | |
195 | ||
196 | | TUnknown _ | |
197 | ||
198 | | TMacroAttr _ | |
199 | | TMacroAttrStorage _ | |
200 | | TMacroStmt _ | |
201 | | TMacroString _ | |
202 | | TMacroDecl _ | |
91eba41f C |
203 | | TMacroDeclConst _ |
204 | | TMacroIterator _ | |
205 | -> true | |
206 | ||
ae4735db | 207 | | _ -> false |
91eba41f C |
208 | |
209 | ||
34e49164 C |
210 | (*****************************************************************************) |
211 | (* Visitors *) | |
212 | (*****************************************************************************) | |
213 | ||
ae4735db | 214 | (* Because ocamlyacc force us to do it that way. The ocamlyacc token |
34e49164 C |
215 | * cant be a pair of a sum type, it must be directly a sum type. |
216 | *) | |
217 | let info_of_tok = function | |
218 | | TString ((string, isWchar), i) -> i | |
219 | | TChar ((string, isWchar), i) -> i | |
220 | | TFloat ((string, floatType), i) -> i | |
221 | ||
222 | | TAssign (assignOp, i) -> i | |
223 | ||
224 | | TIdent (s, i) -> i | |
225 | | TypedefIdent (s, i) -> i | |
226 | ||
227 | | TInt (s, i) -> i | |
228 | ||
ae4735db | 229 | | TDefine (ii) -> ii |
34e49164 C |
230 | | TInclude (includes, filename, inifdef, i1) -> i1 |
231 | ||
485bce71 C |
232 | | TUndef (s, ii) -> ii |
233 | | TCppDirectiveOther (ii) -> ii | |
234 | ||
34e49164 C |
235 | | TIncludeStart (i1, inifdef) -> i1 |
236 | | TIncludeFilename (s, i1) -> i1 | |
237 | ||
238 | | TDefEOL (i1) -> i1 | |
239 | | TOParDefine (i1) -> i1 | |
240 | | TIdentDefine (s, i) -> i | |
241 | | TCppEscapedNewline (ii) -> ii | |
242 | | TDefParamVariadic (s, i1) -> i1 | |
243 | ||
b1b2de81 C |
244 | | TCppConcatOp (ii) -> ii |
245 | ||
485bce71 C |
246 | | TOBraceDefineInit (i1) -> i1 |
247 | ||
34e49164 C |
248 | | TUnknown (i) -> i |
249 | ||
b1b2de81 | 250 | | TMacroIdentBuilder (s, i) -> i |
485bce71 C |
251 | | TMacroAttr (s, i) -> i |
252 | | TMacroAttrStorage (s, i) -> i | |
253 | | TMacroStmt (s, i) -> i | |
254 | | TMacroString (s, i) -> i | |
34e49164 C |
255 | | TMacroDecl (s, i) -> i |
256 | | TMacroDeclConst (i) -> i | |
257 | | TMacroIterator (s,i) -> i | |
258 | (* | TMacroTop (s,i) -> i *) | |
259 | | TCParEOL (i1) -> i1 | |
260 | ||
261 | | TAction (i) -> i | |
262 | ||
263 | | TComment (i) -> i | |
264 | | TCommentSpace (i) -> i | |
265 | | TCommentNewline (i) -> i | |
266 | | TCommentCpp (cppkind, i) -> i | |
267 | | TCommentMisc (i) -> i | |
268 | ||
0708f913 C |
269 | | TCommentSkipTagStart (i) -> i |
270 | | TCommentSkipTagEnd (i) -> i | |
271 | ||
485bce71 C |
272 | | TIfdef (_, i) -> i |
273 | | TIfdefelse (_, i) -> i | |
274 | | TIfdefelif (_, i) -> i | |
275 | | TEndif (_, i) -> i | |
276 | | TIfdefBool (b, _, i) -> i | |
277 | | TIfdefMisc (b, _, i) -> i | |
278 | | TIfdefVersion (b, _, i) -> i | |
34e49164 C |
279 | |
280 | | TOPar (i) -> i | |
281 | | TCPar (i) -> i | |
282 | | TOBrace (i) -> i | |
283 | | TCBrace (i) -> i | |
284 | | TOCro (i) -> i | |
285 | | TCCro (i) -> i | |
286 | | TDot (i) -> i | |
287 | | TComma (i) -> i | |
288 | | TPtrOp (i) -> i | |
289 | | TInc (i) -> i | |
290 | | TDec (i) -> i | |
291 | | TEq (i) -> i | |
292 | | TWhy (i) -> i | |
293 | | TTilde (i) -> i | |
294 | | TBang (i) -> i | |
295 | | TEllipsis (i) -> i | |
296 | | TDotDot (i) -> i | |
297 | | TPtVirg (i) -> i | |
298 | | TOrLog (i) -> i | |
299 | | TAndLog (i) -> i | |
300 | | TOr (i) -> i | |
301 | | TXor (i) -> i | |
302 | | TAnd (i) -> i | |
303 | | TEqEq (i) -> i | |
304 | | TNotEq (i) -> i | |
305 | | TInf (i) -> i | |
306 | | TSup (i) -> i | |
307 | | TInfEq (i) -> i | |
308 | | TSupEq (i) -> i | |
309 | | TShl (i) -> i | |
310 | | TShr (i) -> i | |
311 | | TPlus (i) -> i | |
312 | | TMinus (i) -> i | |
313 | | TMul (i) -> i | |
314 | | TDiv (i) -> i | |
315 | | TMod (i) -> i | |
316 | ||
317 | | Tchar (i) -> i | |
318 | | Tshort (i) -> i | |
319 | | Tint (i) -> i | |
320 | | Tdouble (i) -> i | |
321 | | Tfloat (i) -> i | |
322 | | Tlong (i) -> i | |
323 | | Tunsigned (i) -> i | |
324 | | Tsigned (i) -> i | |
325 | | Tvoid (i) -> i | |
1eddfd50 C |
326 | | Tsize_t (i) -> i |
327 | | Tssize_t (i) -> i | |
328 | | Tptrdiff_t (i) -> i | |
34e49164 C |
329 | | Tauto (i) -> i |
330 | | Tregister (i) -> i | |
331 | | Textern (i) -> i | |
332 | | Tstatic (i) -> i | |
333 | | Tconst (i) -> i | |
334 | | Tvolatile (i) -> i | |
485bce71 C |
335 | |
336 | | Trestrict (i) -> i | |
337 | ||
34e49164 C |
338 | | Tstruct (i) -> i |
339 | | Tenum (i) -> i | |
340 | | Ttypedef (i) -> i | |
341 | | Tunion (i) -> i | |
342 | | Tbreak (i) -> i | |
343 | | Telse (i) -> i | |
344 | | Tswitch (i) -> i | |
345 | | Tcase (i) -> i | |
346 | | Tcontinue (i) -> i | |
347 | | Tfor (i) -> i | |
348 | | Tdo (i) -> i | |
349 | | Tif (i) -> i | |
350 | | Twhile (i) -> i | |
351 | | Treturn (i) -> i | |
352 | | Tgoto (i) -> i | |
353 | | Tdefault (i) -> i | |
354 | | Tsizeof (i) -> i | |
355 | | Tasm (i) -> i | |
356 | | Tattribute (i) -> i | |
978fd7e5 | 357 | | TattributeNoarg (i) -> i |
34e49164 C |
358 | | Tinline (i) -> i |
359 | | Ttypeof (i) -> i | |
360 | ||
361 | | EOF (i) -> i | |
ae4735db | 362 | |
34e49164 C |
363 | |
364 | ||
485bce71 | 365 | |
34e49164 C |
366 | (* used by tokens to complete the parse_info with filename, line, col infos *) |
367 | let visitor_info_of_tok f = function | |
ae4735db C |
368 | | TString ((s, isWchar), i) -> TString ((s, isWchar), f i) |
369 | | TChar ((s, isWchar), i) -> TChar ((s, isWchar), f i) | |
370 | | TFloat ((s, floatType), i) -> TFloat ((s, floatType), f i) | |
371 | | TAssign (assignOp, i) -> TAssign (assignOp, f i) | |
34e49164 | 372 | |
ae4735db C |
373 | | TIdent (s, i) -> TIdent (s, f i) |
374 | | TypedefIdent (s, i) -> TypedefIdent (s, f i) | |
375 | | TInt (s, i) -> TInt (s, f i) | |
34e49164 | 376 | |
ae4735db | 377 | | TDefine (i1) -> TDefine(f i1) |
34e49164 | 378 | |
ae4735db C |
379 | | TUndef (s,i1) -> TUndef(s, f i1) |
380 | | TCppDirectiveOther (i1) -> TCppDirectiveOther(f i1) | |
485bce71 | 381 | |
ae4735db | 382 | | TInclude (includes, filename, inifdef, i1) -> |
34e49164 C |
383 | TInclude (includes, filename, inifdef, f i1) |
384 | ||
385 | | TIncludeStart (i1, inifdef) -> TIncludeStart (f i1, inifdef) | |
386 | | TIncludeFilename (s, i1) -> TIncludeFilename (s, f i1) | |
387 | ||
388 | | TCppEscapedNewline (i1) -> TCppEscapedNewline (f i1) | |
389 | | TDefEOL (i1) -> TDefEOL (f i1) | |
b1b2de81 C |
390 | |
391 | | TCppConcatOp (ii) -> TCppConcatOp (f ii) | |
392 | ||
34e49164 C |
393 | | TOParDefine (i1) -> TOParDefine (f i1) |
394 | | TIdentDefine (s, i) -> TIdentDefine (s, f i) | |
395 | ||
396 | | TDefParamVariadic (s, i1) -> TDefParamVariadic (s, f i1) | |
397 | ||
485bce71 C |
398 | | TOBraceDefineInit (i1) -> TOBraceDefineInit (f i1) |
399 | ||
34e49164 C |
400 | |
401 | | TUnknown (i) -> TUnknown (f i) | |
402 | ||
b1b2de81 | 403 | | TMacroIdentBuilder (s, i) -> TMacroIdentBuilder (s, f i) |
485bce71 C |
404 | | TMacroAttr (s, i) -> TMacroAttr (s, f i) |
405 | | TMacroAttrStorage (s, i) -> TMacroAttrStorage (s, f i) | |
406 | | TMacroStmt (s, i) -> TMacroStmt (s, f i) | |
407 | | TMacroString (s, i) -> TMacroString (s, f i) | |
408 | | TMacroDecl (s, i) -> TMacroDecl (s, f i) | |
34e49164 | 409 | | TMacroDeclConst (i) -> TMacroDeclConst (f i) |
485bce71 | 410 | | TMacroIterator (s, i) -> TMacroIterator (s, f i) |
34e49164 C |
411 | (* | TMacroTop (s,i) -> TMacroTop (s,f i) *) |
412 | | TCParEOL (i) -> TCParEOL (f i) | |
413 | ||
414 | ||
415 | | TAction (i) -> TAction (f i) | |
416 | ||
ae4735db C |
417 | | TComment (i) -> TComment (f i) |
418 | | TCommentSpace (i) -> TCommentSpace (f i) | |
419 | | TCommentNewline (i) -> TCommentNewline (f i) | |
420 | | TCommentCpp (cppkind, i) -> TCommentCpp (cppkind, f i) | |
421 | | TCommentMisc (i) -> TCommentMisc (f i) | |
422 | ||
423 | | TCommentSkipTagStart (i) -> TCommentSkipTagStart (f i) | |
424 | | TCommentSkipTagEnd (i) -> TCommentSkipTagEnd (f i) | |
425 | ||
426 | | TIfdef (t, i) -> TIfdef (t, f i) | |
427 | | TIfdefelse (t, i) -> TIfdefelse (t, f i) | |
428 | | TIfdefelif (t, i) -> TIfdefelif (t, f i) | |
429 | | TEndif (t, i) -> TEndif (t, f i) | |
430 | | TIfdefBool (b, t, i) -> TIfdefBool (b, t, f i) | |
431 | | TIfdefMisc (b, t, i) -> TIfdefMisc (b, t, f i) | |
432 | | TIfdefVersion (b, t, i) -> TIfdefVersion (b, t, f i) | |
433 | ||
434 | | TOPar (i) -> TOPar (f i) | |
435 | | TCPar (i) -> TCPar (f i) | |
436 | | TOBrace (i) -> TOBrace (f i) | |
437 | | TCBrace (i) -> TCBrace (f i) | |
438 | | TOCro (i) -> TOCro (f i) | |
439 | | TCCro (i) -> TCCro (f i) | |
440 | | TDot (i) -> TDot (f i) | |
441 | | TComma (i) -> TComma (f i) | |
442 | | TPtrOp (i) -> TPtrOp (f i) | |
443 | | TInc (i) -> TInc (f i) | |
444 | | TDec (i) -> TDec (f i) | |
445 | | TEq (i) -> TEq (f i) | |
446 | | TWhy (i) -> TWhy (f i) | |
447 | | TTilde (i) -> TTilde (f i) | |
448 | | TBang (i) -> TBang (f i) | |
449 | | TEllipsis (i) -> TEllipsis (f i) | |
450 | | TDotDot (i) -> TDotDot (f i) | |
451 | | TPtVirg (i) -> TPtVirg (f i) | |
452 | | TOrLog (i) -> TOrLog (f i) | |
453 | | TAndLog (i) -> TAndLog (f i) | |
454 | | TOr (i) -> TOr (f i) | |
455 | | TXor (i) -> TXor (f i) | |
456 | | TAnd (i) -> TAnd (f i) | |
457 | | TEqEq (i) -> TEqEq (f i) | |
458 | | TNotEq (i) -> TNotEq (f i) | |
459 | | TInf (i) -> TInf (f i) | |
460 | | TSup (i) -> TSup (f i) | |
461 | | TInfEq (i) -> TInfEq (f i) | |
462 | | TSupEq (i) -> TSupEq (f i) | |
463 | | TShl (i) -> TShl (f i) | |
464 | | TShr (i) -> TShr (f i) | |
465 | | TPlus (i) -> TPlus (f i) | |
466 | | TMinus (i) -> TMinus (f i) | |
467 | | TMul (i) -> TMul (f i) | |
468 | | TDiv (i) -> TDiv (f i) | |
469 | | TMod (i) -> TMod (f i) | |
470 | | Tchar (i) -> Tchar (f i) | |
471 | | Tshort (i) -> Tshort (f i) | |
472 | | Tint (i) -> Tint (f i) | |
473 | | Tdouble (i) -> Tdouble (f i) | |
474 | | Tfloat (i) -> Tfloat (f i) | |
475 | | Tlong (i) -> Tlong (f i) | |
476 | | Tunsigned (i) -> Tunsigned (f i) | |
477 | | Tsigned (i) -> Tsigned (f i) | |
478 | | Tvoid (i) -> Tvoid (f i) | |
1eddfd50 C |
479 | | Tsize_t (i) -> Tsize_t (f i) |
480 | | Tssize_t (i) -> Tssize_t (f i) | |
481 | | Tptrdiff_t (i) -> Tptrdiff_t (f i) | |
ae4735db C |
482 | | Tauto (i) -> Tauto (f i) |
483 | | Tregister (i) -> Tregister (f i) | |
484 | | Textern (i) -> Textern (f i) | |
485 | | Tstatic (i) -> Tstatic (f i) | |
486 | | Tconst (i) -> Tconst (f i) | |
487 | | Tvolatile (i) -> Tvolatile (f i) | |
488 | ||
489 | | Trestrict (i) -> Trestrict (f i) | |
490 | ||
491 | | Tstruct (i) -> Tstruct (f i) | |
492 | | Tenum (i) -> Tenum (f i) | |
493 | | Ttypedef (i) -> Ttypedef (f i) | |
494 | | Tunion (i) -> Tunion (f i) | |
495 | | Tbreak (i) -> Tbreak (f i) | |
496 | | Telse (i) -> Telse (f i) | |
497 | | Tswitch (i) -> Tswitch (f i) | |
498 | | Tcase (i) -> Tcase (f i) | |
499 | | Tcontinue (i) -> Tcontinue (f i) | |
500 | | Tfor (i) -> Tfor (f i) | |
501 | | Tdo (i) -> Tdo (f i) | |
502 | | Tif (i) -> Tif (f i) | |
503 | | Twhile (i) -> Twhile (f i) | |
504 | | Treturn (i) -> Treturn (f i) | |
505 | | Tgoto (i) -> Tgoto (f i) | |
506 | | Tdefault (i) -> Tdefault (f i) | |
507 | | Tsizeof (i) -> Tsizeof (f i) | |
508 | | Tasm (i) -> Tasm (f i) | |
509 | | Tattribute (i) -> Tattribute (f i) | |
510 | | TattributeNoarg (i) -> TattributeNoarg (f i) | |
511 | | Tinline (i) -> Tinline (f i) | |
512 | | Ttypeof (i) -> Ttypeof (f i) | |
513 | | EOF (i) -> EOF (f i) | |
514 | ||
34e49164 C |
515 | |
516 | (*****************************************************************************) | |
517 | (* Accessors *) | |
518 | (*****************************************************************************) | |
519 | ||
520 | let linecol_of_tok tok = | |
521 | let info = info_of_tok tok in | |
522 | Ast_c.line_of_info info, Ast_c.col_of_info info | |
523 | ||
524 | let col_of_tok x = snd (linecol_of_tok x) | |
525 | let line_of_tok x = fst (linecol_of_tok x) | |
526 | let pos_of_tok x = Ast_c.opos_of_info (info_of_tok x) | |
527 | let str_of_tok x = Ast_c.str_of_info (info_of_tok x) | |
528 | let file_of_tok x = Ast_c.file_of_info (info_of_tok x) | |
529 | let pinfo_of_tok x = Ast_c.pinfo_of_info (info_of_tok x) | |
530 | ||
531 | let is_origin x = | |
532 | match pinfo_of_tok x with Ast_c.OriginTok _ -> true | _ -> false | |
533 | let is_expanded x = | |
534 | match pinfo_of_tok x with Ast_c.ExpandedTok _ -> true | _ -> false | |
535 | let is_fake x = | |
536 | match pinfo_of_tok x with Ast_c.FakeTok _ -> true | _ -> false | |
537 | let is_abstract x = | |
538 | match pinfo_of_tok x with Ast_c.AbstractLineTok _ -> true | _ -> false | |
91eba41f C |
539 | |
540 | (*****************************************************************************) | |
541 | (* Helpers *) | |
542 | (*****************************************************************************) | |
ae4735db C |
543 | let is_same_line_or_close line tok = |
544 | line_of_tok tok =|= line || | |
b1b2de81 C |
545 | line_of_tok tok =|= line - 1 || |
546 | line_of_tok tok =|= line - 2 | |
0708f913 | 547 |