package clangml

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file clang__ast_utils.ml

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
open Clang__bindings

open Clang__ast

open Clang__utils

let string_of_elaborated_type_keyword =
  ext_elaborated_type_get_keyword_spelling

let string_of_unary_operator_kind = ext_unary_operator_get_opcode_spelling

let string_of_binary_operator_kind = ext_binary_operator_get_opcode_spelling

let literal_of_int i = Int i

let int64_of_literal_opt ?signed i =
  match i with
  | Int i -> Some (Int64.of_int i)
  | CXInt i -> int64_of_cxint_opt ?signed i

let int64_of_literal ?signed i =
  match i with
  | Int i -> Int64.of_int i
  | CXInt i -> int64_of_cxint ?signed i

let int_of_literal_opt ?signed i =
  match i with
  | Int i -> Some i
  | CXInt i -> int_of_cxint_opt ?signed i

let int_of_literal ?signed i =
  match i with
  | Int i -> i
  | CXInt i -> int_of_cxint ?signed i

let string_of_integer_literal ?signed i =
  match i with
  | Int i -> string_of_int i
  | CXInt i -> string_of_cxint ?signed i

let print_integer_literal ?signed i =
  match i with
  | Int i -> print_int i
  | CXInt i -> print_string (string_of_cxint ?signed i)

let output_integer_literal ?signed channel i =
  match i with
  | Int i -> output_string channel (string_of_int i)
  | CXInt i -> output_string channel (string_of_cxint ?signed i)

let pp_print_integer_literal ?signed fmt i =
  match i with
  | Int i -> Format.pp_print_int fmt i
  | CXInt i -> Format.pp_print_string fmt (string_of_cxint ?signed i)

let literal_of_float f = Float f

let float_of_literal f =
  match f with
  | Float f -> f
  | CXFloat f -> float_of_cxfloat f

let string_of_floating_literal f =
  match f with
  | Float f -> string_of_float f
  | CXFloat f -> string_of_cxfloat f

let print_floating_literal f =
  match f with
  | Float f -> print_float f
  | CXFloat f -> print_string (string_of_cxfloat f)

let output_floating_literal channel f =
  match f with
  | Float f -> output_string channel (string_of_float f)
  | CXFloat f -> output_string channel (string_of_cxfloat f)

let pp_print_floating_literal fmt f =
  match f with
  | Float f -> Format.pp_print_float fmt f
  | CXFloat f -> Format.pp_print_string fmt (string_of_cxfloat f)

let languages_of_ids e =
  { c = Clang_ext_languageids.(subset c e);
    cxx = Clang_ext_languageids.(subset cxx e) }

let language_of_ids e : Clang__types.language =
  if e = Clang_ext_languageids.c then
    C
  else if e = Clang_ext_languageids.cxx then
    CXX
  else
    invalid_arg (Printf.sprintf "language_of_ids: %d" (Obj.magic e))

let ids_of_languages li =
  Clang_ext_languageids.
    ((if li.c then c else zero) +
     (if li.cxx then cxx else zero))

let ids_of_language (l : Clang__types.language) =
  match l with
  | C -> Clang_ext_languageids.c
  | CXX -> Clang_ext_languageids.cxx
  | _ -> invalid_arg "ids_of_language"

let literal_of_string ?(byte_width = 8) ?(string_kind = Ascii)
    (bytes : string) : string_literal = {
  byte_width;
  bytes;
  string_kind;
}

let concrete_of_source_location kind location =
  match location with
  | Clang location -> concrete_of_cxsourcelocation kind location
  | Concrete location -> location

let pp_source_location ?(options = Clang__types.Display_source_location.default)
    ?(ranges = fun () -> []) fmt source_location =
  pp_concrete_location
    ~ranges:(fun () ->
      List.map (fun (range_start, range_end) ->
        (concrete_of_source_location options.kind range_start,
          concrete_of_source_location options.kind range_end)) (ranges ())) fmt
    (concrete_of_source_location options.kind source_location)
OCaml

Innovation. Community. Security.