4fdf39caabe605546cd5310efc08ae5271534e07
5 (*****************************************************************************)
6 (* Is_xxx, categories *)
7 (*****************************************************************************)
9 let is_space = function
10 | TCommentSpace _
-> true
11 | TCommentNewline _
-> true
14 let is_whitespace = is_space
16 let is_comment_or_space = function
18 | TCommentSpace _
-> true
19 | TCommentNewline _
-> true
21 let is_real_comment = is_comment_or_space
23 let is_just_comment = function
27 let is_comment = function
29 | TCommentSpace _
| TCommentNewline _
31 | TCommentMisc _
-> true
36 let is_fake_comment = function
37 | TCommentCpp _
| TCommentMisc _
41 let is_not_comment x
=
48 let is_cpp_instruction = function
51 | TIfdef _
| TIfdefelse _
| TIfdefelif _
| TEndif _
52 | TIfdefBool _
| TIfdefMisc _
| TIfdefVersion _
54 | TCppDirectiveOther _
59 let is_gcc_token = function
70 let is_opar = function
71 | TOPar _
| TOParDefine _
-> true
74 let is_cpar = function
75 | TCPar _
| TCParEOL _
-> true
79 let is_obrace = function
80 | TOBrace _
| TOBraceDefineInit _
-> true
83 let is_cbrace = function
96 let is_statement = function
97 | Tfor _
| Tdo _
| Tif _
| Twhile _
| Treturn _
98 | Tbreak _
| Telse _
| Tswitch _
| Tcase _
| Tcontinue _
105 (* is_start_of_something is used in parse_c for error recovery, to find
106 * a synchronisation token.
108 * Would like to put TIdent or TDefine, TIfdef but they can be in the
109 * middle of a function, for instance with label:.
111 * Could put Typedefident but fired ? it would work in error recovery
112 * on the already_passed tokens, which has been already gone in the
113 * Parsing_hacks.lookahead machinery, but it will not work on the
114 * "next" tokens. But because the namespace for labels is different
115 * from namespace for ident/typedef, we can use the name for a typedef
116 * for a label and so dangerous to put Typedefident at true here.
118 * Can look in parser_c.output to know what can be at toplevel
119 * at the very beginning.
122 let is_start_of_something = function
123 | Tchar _
| Tshort _
| Tint _
| Tdouble _
| Tfloat _
| Tlong _
124 | Tunsigned _
| Tsigned _
| Tvoid _
125 | Tauto _
| Tregister _
| Textern _
| Tstatic _
126 | Tconst _
| Tvolatile _
128 | Tstruct _
| Tunion _
| Tenum _
134 let is_binary_operator = function
135 | TOrLog _
| TAndLog _
| TOr _
| TXor _
| TAnd _
136 | TEqEq _
| TNotEq _
| TInf _
| TSup _
| TInfEq _
| TSupEq _
138 | TPlus _
| TMinus _
| TMul _
| TDiv _
| TMod _
142 let is_stuff_taking_parenthized = function
151 (*****************************************************************************)
153 (*****************************************************************************)
155 (* Because ocamlyacc force us to do it that way. The ocamlyacc token
156 * cant be a pair of a sum type, it must be directly a sum type.
158 let info_of_tok = function
159 | TString
((string, isWchar
), i
) -> i
160 | TChar
((string, isWchar
), i
) -> i
161 | TFloat
((string, floatType
), i
) -> i
163 | TAssign
(assignOp
, i
) -> i
166 | TypedefIdent
(s
, i
) -> i
171 | TInclude
(includes
, filename
, inifdef
, i1
) -> i1
173 | TUndef
(s
, ii
) -> ii
174 | TCppDirectiveOther
(ii
) -> ii
176 | TIncludeStart
(i1
, inifdef
) -> i1
177 | TIncludeFilename
(s
, i1
) -> i1
180 | TOParDefine
(i1
) -> i1
181 | TIdentDefine
(s
, i
) -> i
182 | TCppEscapedNewline
(ii
) -> ii
183 | TDefParamVariadic
(s
, i1
) -> i1
185 | TOBraceDefineInit
(i1
) -> i1
189 | TMacroAttr
(s
, i
) -> i
190 | TMacroAttrStorage
(s
, i
) -> i
191 | TMacroStmt
(s
, i
) -> i
192 | TMacroString
(s
, i
) -> i
193 | TMacroDecl
(s
, i
) -> i
194 | TMacroStructDecl
(s
, i
) -> i
195 | TMacroDeclConst
(i
) -> i
196 | TMacroIterator
(s
,i
) -> i
197 (* | TMacroTop (s,i) -> i *)
198 | TCParEOL
(i1
) -> i1
203 | TCommentSpace
(i
) -> i
204 | TCommentNewline
(i
) -> i
205 | TCommentCpp
(cppkind
, i
) -> i
206 | TCommentMisc
(i
) -> i
209 | TIfdefelse
(_
, i
) -> i
210 | TIfdefelif
(_
, i
) -> i
212 | TIfdefBool
(b
, _
, i
) -> i
213 | TIfdefMisc
(b
, _
, i
) -> i
214 | TIfdefVersion
(b
, _
, i
) -> i
289 | Tattribute
(i
) -> i
298 (* used by tokens to complete the parse_info with filename, line, col infos *)
299 let visitor_info_of_tok f
= function
300 | TString
((s
, isWchar
), i
) -> TString
((s
, isWchar
), f i
)
301 | TChar
((s
, isWchar
), i
) -> TChar
((s
, isWchar
), f i
)
302 | TFloat
((s
, floatType
), i
) -> TFloat
((s
, floatType
), f i
)
303 | TAssign
(assignOp
, i
) -> TAssign
(assignOp
, f i
)
305 | TIdent
(s
, i
) -> TIdent
(s
, f i
)
306 | TypedefIdent
(s
, i
) -> TypedefIdent
(s
, f i
)
307 | TInt
(s
, i
) -> TInt
(s
, f i
)
309 | TDefine
(i1
) -> TDefine
(f i1
)
311 | TUndef
(s
,i1
) -> TUndef
(s
, f i1
)
312 | TCppDirectiveOther
(i1
) -> TCppDirectiveOther
(f i1
)
314 | TInclude
(includes
, filename
, inifdef
, i1
) ->
315 TInclude
(includes
, filename
, inifdef
, f i1
)
317 | TIncludeStart
(i1
, inifdef
) -> TIncludeStart
(f i1
, inifdef
)
318 | TIncludeFilename
(s
, i1
) -> TIncludeFilename
(s
, f i1
)
320 | TCppEscapedNewline
(i1
) -> TCppEscapedNewline
(f i1
)
321 | TDefEOL
(i1
) -> TDefEOL
(f i1
)
322 | TOParDefine
(i1
) -> TOParDefine
(f i1
)
323 | TIdentDefine
(s
, i
) -> TIdentDefine
(s
, f i
)
325 | TDefParamVariadic
(s
, i1
) -> TDefParamVariadic
(s
, f i1
)
327 | TOBraceDefineInit
(i1
) -> TOBraceDefineInit
(f i1
)
330 | TUnknown
(i
) -> TUnknown
(f i
)
332 | TMacroAttr
(s
, i
) -> TMacroAttr
(s
, f i
)
333 | TMacroAttrStorage
(s
, i
) -> TMacroAttrStorage
(s
, f i
)
334 | TMacroStmt
(s
, i
) -> TMacroStmt
(s
, f i
)
335 | TMacroString
(s
, i
) -> TMacroString
(s
, f i
)
336 | TMacroDecl
(s
, i
) -> TMacroDecl
(s
, f i
)
337 | TMacroStructDecl
(s
, i
) -> TMacroStructDecl
(s
, f i
)
338 | TMacroDeclConst
(i
) -> TMacroDeclConst
(f i
)
339 | TMacroIterator
(s
, i
) -> TMacroIterator
(s
, f i
)
340 (* | TMacroTop (s,i) -> TMacroTop (s,f i) *)
341 | TCParEOL
(i
) -> TCParEOL
(f i
)
344 | TAction
(i
) -> TAction
(f i
)
346 | TComment
(i
) -> TComment
(f i
)
347 | TCommentSpace
(i
) -> TCommentSpace
(f i
)
348 | TCommentNewline
(i
) -> TCommentNewline
(f i
)
349 | TCommentCpp
(cppkind
, i
) -> TCommentCpp
(cppkind
, f i
)
350 | TCommentMisc
(i
) -> TCommentMisc
(f i
)
352 | TIfdef
(t
, i
) -> TIfdef
(t
, f i
)
353 | TIfdefelse
(t
, i
) -> TIfdefelse
(t
, f i
)
354 | TIfdefelif
(t
, i
) -> TIfdefelif
(t
, f i
)
355 | TEndif
(t
, i
) -> TEndif
(t
, f i
)
356 | TIfdefBool
(b
, t
, i
) -> TIfdefBool
(b
, t
, f i
)
357 | TIfdefMisc
(b
, t
, i
) -> TIfdefMisc
(b
, t
, f i
)
358 | TIfdefVersion
(b
, t
, i
) -> TIfdefVersion
(b
, t
, f i
)
360 | TOPar
(i
) -> TOPar
(f i
)
361 | TCPar
(i
) -> TCPar
(f i
)
362 | TOBrace
(i
) -> TOBrace
(f i
)
363 | TCBrace
(i
) -> TCBrace
(f i
)
364 | TOCro
(i
) -> TOCro
(f i
)
365 | TCCro
(i
) -> TCCro
(f i
)
366 | TDot
(i
) -> TDot
(f i
)
367 | TComma
(i
) -> TComma
(f i
)
368 | TPtrOp
(i
) -> TPtrOp
(f i
)
369 | TInc
(i
) -> TInc
(f i
)
370 | TDec
(i
) -> TDec
(f i
)
371 | TEq
(i
) -> TEq
(f i
)
372 | TWhy
(i
) -> TWhy
(f i
)
373 | TTilde
(i
) -> TTilde
(f i
)
374 | TBang
(i
) -> TBang
(f i
)
375 | TEllipsis
(i
) -> TEllipsis
(f i
)
376 | TDotDot
(i
) -> TDotDot
(f i
)
377 | TPtVirg
(i
) -> TPtVirg
(f i
)
378 | TOrLog
(i
) -> TOrLog
(f i
)
379 | TAndLog
(i
) -> TAndLog
(f i
)
380 | TOr
(i
) -> TOr
(f i
)
381 | TXor
(i
) -> TXor
(f i
)
382 | TAnd
(i
) -> TAnd
(f i
)
383 | TEqEq
(i
) -> TEqEq
(f i
)
384 | TNotEq
(i
) -> TNotEq
(f i
)
385 | TInf
(i
) -> TInf
(f i
)
386 | TSup
(i
) -> TSup
(f i
)
387 | TInfEq
(i
) -> TInfEq
(f i
)
388 | TSupEq
(i
) -> TSupEq
(f i
)
389 | TShl
(i
) -> TShl
(f i
)
390 | TShr
(i
) -> TShr
(f i
)
391 | TPlus
(i
) -> TPlus
(f i
)
392 | TMinus
(i
) -> TMinus
(f i
)
393 | TMul
(i
) -> TMul
(f i
)
394 | TDiv
(i
) -> TDiv
(f i
)
395 | TMod
(i
) -> TMod
(f i
)
396 | Tchar
(i
) -> Tchar
(f i
)
397 | Tshort
(i
) -> Tshort
(f i
)
398 | Tint
(i
) -> Tint
(f i
)
399 | Tdouble
(i
) -> Tdouble
(f i
)
400 | Tfloat
(i
) -> Tfloat
(f i
)
401 | Tlong
(i
) -> Tlong
(f i
)
402 | Tunsigned
(i
) -> Tunsigned
(f i
)
403 | Tsigned
(i
) -> Tsigned
(f i
)
404 | Tvoid
(i
) -> Tvoid
(f i
)
405 | Tauto
(i
) -> Tauto
(f i
)
406 | Tregister
(i
) -> Tregister
(f i
)
407 | Textern
(i
) -> Textern
(f i
)
408 | Tstatic
(i
) -> Tstatic
(f i
)
409 | Tconst
(i
) -> Tconst
(f i
)
410 | Tvolatile
(i
) -> Tvolatile
(f i
)
412 | Trestrict
(i
) -> Trestrict
(f i
)
414 | Tstruct
(i
) -> Tstruct
(f i
)
415 | Tenum
(i
) -> Tenum
(f i
)
416 | Ttypedef
(i
) -> Ttypedef
(f i
)
417 | Tunion
(i
) -> Tunion
(f i
)
418 | Tbreak
(i
) -> Tbreak
(f i
)
419 | Telse
(i
) -> Telse
(f i
)
420 | Tswitch
(i
) -> Tswitch
(f i
)
421 | Tcase
(i
) -> Tcase
(f i
)
422 | Tcontinue
(i
) -> Tcontinue
(f i
)
423 | Tfor
(i
) -> Tfor
(f i
)
424 | Tdo
(i
) -> Tdo
(f i
)
425 | Tif
(i
) -> Tif
(f i
)
426 | Twhile
(i
) -> Twhile
(f i
)
427 | Treturn
(i
) -> Treturn
(f i
)
428 | Tgoto
(i
) -> Tgoto
(f i
)
429 | Tdefault
(i
) -> Tdefault
(f i
)
430 | Tsizeof
(i
) -> Tsizeof
(f i
)
431 | Tasm
(i
) -> Tasm
(f i
)
432 | Tattribute
(i
) -> Tattribute
(f i
)
433 | Tinline
(i
) -> Tinline
(f i
)
434 | Ttypeof
(i
) -> Ttypeof
(f i
)
435 | EOF
(i
) -> EOF
(f i
)
438 (*****************************************************************************)
440 (*****************************************************************************)
442 let linecol_of_tok tok
=
443 let info = info_of_tok tok
in
444 Ast_c.line_of_info
info, Ast_c.col_of_info
info
446 let col_of_tok x
= snd
(linecol_of_tok x
)
447 let line_of_tok x
= fst
(linecol_of_tok x
)
448 let pos_of_tok x
= Ast_c.opos_of_info
(info_of_tok x
)
449 let str_of_tok x
= Ast_c.str_of_info
(info_of_tok x
)
450 let file_of_tok x
= Ast_c.file_of_info
(info_of_tok x
)
451 let pinfo_of_tok x
= Ast_c.pinfo_of_info
(info_of_tok x
)
454 match pinfo_of_tok x
with Ast_c.OriginTok _
-> true | _
-> false
456 match pinfo_of_tok x
with Ast_c.ExpandedTok _
-> true | _
-> false
458 match pinfo_of_tok x
with Ast_c.FakeTok _
-> true | _
-> false
460 match pinfo_of_tok x
with Ast_c.AbstractLineTok _
-> true | _
-> false