Module Clang__.Clang__utils

include sig ... end
include sig ... end
val string_of_language : Clang__.Clang__types.language -> string
val language_of_string : string -> Clang__.Clang__types.language
val language_of_string_opt : string -> Clang__.Clang__types.language option
val suffix_of_language : Clang__.Clang__types.language -> string
val extern_of_language : Clang__.Clang__types.language -> string
val string_of_cxx_access_specifier : Clang__.Clang__bindings.cx_cxxaccessspecifier -> string

Compatibility layer

include sig ... end
val predefined_expr_get_function_name : Clang__.Clang__bindings.cxcursor -> Clang__.Clang__bindings.cxcursor -> string
include sig ... end

Parsing files and strings

val parse_file : ?⁠index:Clang__.Clang__bindings.cxindex -> ?⁠command_line_args:string list -> ?⁠unsaved_files:Clang__.Clang__bindings.cxunsavedfile list -> ?⁠options:Clang__.Clang__bindings.Cxtranslationunit_flags.t -> string -> Clang__.Clang__bindings.cxtranslationunit

parse_file ?index ?command_line_args ?unsaved_files ?options filename parses file filename and returns its translation unit. This function is equivalent to Clang.parse_translation_unit2, with, by default, a fresh index (created by Clang.create_index true true), an empty list for command_line_args and unsaved_files, and default options (obtained by Clang.default_editing_translation_unit_options). See also Clang.Ast.parse_file which returns a pattern-matchable representation of the AST.

val parse_file_res : ?⁠index:Clang__.Clang__bindings.cxindex -> ?⁠command_line_args:string list -> ?⁠unsaved_files:Clang__.Clang__bindings.cxunsavedfile list -> ?⁠options:Clang__.Clang__bindings.Cxtranslationunit_flags.t -> string -> (Clang__.Clang__bindings.cxtranslationunitClang__.Clang__bindings.cxerrorcode) Stdcompat.result

Equivalent to parse_file but returns a result instead of raising Failure _ if parsing fails.

val parse_string : ?⁠index:Clang__.Clang__bindings.cxindex -> ?⁠filename:string -> ?⁠command_line_args:string list -> ?⁠unsaved_files:Clang__.Clang__bindings.cxunsavedfile list -> ?⁠options:Clang__.Clang__bindings.Cxtranslationunit_flags.t -> string -> Clang__.Clang__bindings.cxtranslationunit

parse_string ?index ?filename ?command_line_args ?unsaved_files ?options contents parses string contents and returns its translation unit. This function calls Clang.parse_file with an unsaved file called filename (by default, <string>.c) with contents: this unsaved file is consed to the list unsaved_files (by default, an empty list). Note that filename should have the .cpp suffix to parse C++ code (for instance, <string>.cpp). See also Clang.Ast.parse_string which returns a pattern-matchable representation of the AST.

val parse_string_res : ?⁠index:Clang__.Clang__bindings.cxindex -> ?⁠filename:string -> ?⁠command_line_args:string list -> ?⁠unsaved_files:Clang__.Clang__bindings.cxunsavedfile list -> ?⁠options:Clang__.Clang__bindings.Cxtranslationunit_flags.t -> string -> (Clang__.Clang__bindings.cxtranslationunitClang__.Clang__bindings.cxerrorcode) Stdcompat.result

Equivalent to parse_string but returns a result instead of raising Failure _ if parsing fails.

Iterators

val iter_children : (Clang__.Clang__bindings.cxcursor -> unit) -> Clang__.Clang__bindings.cxcursor -> unit

iter_children f cur calls f over all the direct child nodes of cur.

val list_of_children : Clang__.Clang__bindings.cxcursor -> Clang__.Clang__bindings.cxcursor list

list_of_children cur returns the list of all the direct child nodes of cur.

val iter_type_fields : (Clang__.Clang__bindings.cxcursor -> unit) -> Clang__.Clang__bindings.cxtype -> unit

iter_type_fields f ty calls f over all the declaration nodes of the fields belonging to the record type ty (either a struct or union). See also Clang.Type.iter_fields for a higher-level interface.

val list_of_type_fields : Clang__.Clang__bindings.cxtype -> Clang__.Clang__bindings.cxcursor list

list_of_type_fields f ty returns the list of all the declaration nodes of the fields belonging to the record type ty (either a struct or union).

val iter_decl_context : (Clang__.Clang__bindings.cxcursor -> unit) -> Clang__.Clang__bindings.cxcursor -> unit

iter_decl_context f c calls f over all the declaration nodes of declaration context c.

val list_of_decl_context : Clang__.Clang__bindings.cxcursor -> Clang__.Clang__bindings.cxcursor list

list_of_decl_context f ty returns the list of all the declaration nodes of declaration context c.

val list_of_iter : (('a -> unit) -> unit) -> 'a list

list_of_iter iter calls iter f and returns all the values which f has been applied to.

val is_integer : Clang__.Clang__bindings.cxtypekind -> bool

Integer or floating point types

is_integer ty returns true if ty is a built-in integer type.

val is_unsigned_integer : Clang__.Clang__bindings.cxtypekind -> bool

is_unsigned_integer ty returns true if ty is a built-in integer type that is unsigned.

val is_signed_integer : Clang__.Clang__bindings.cxtypekind -> bool

is_signed_integer ty returns true if ty is a built-in integer type that is signed.

val is_floating_point : Clang__.Clang__bindings.cxtypekind -> bool

is_floating_point ty returns true if ty is a built-in floating-point type.

Integer conversions

val int64_of_cxint_opt : ?⁠signed:bool -> Clang__.Clang__bindings.cxint -> Stdcompat.Int64.t option

int64_of_cxint_opt ~signed x returns Some i if x is representable as a 64-bit integer value i, or None otherwise. signed specifies if x is signed (default: true).

val int64_of_cxint : ?⁠signed:bool -> Clang__.Clang__bindings.cxint -> Stdcompat.Int64.t

int64_of_cxint x returns i if x is representable as a 64-bit integer value i, or raises Invalid_argument _ otherwise. signed specifies if x is signed (default: true).

val int_of_cxint_opt : ?⁠signed:bool -> Clang__.Clang__bindings.cxint -> int option

int_of_cxint_opt x returns Some i if x is representable as an integer value i, or None otherwise. signed specifies if x is signed (default: true).

val int_of_cxint : ?⁠signed:bool -> Clang__.Clang__bindings.cxint -> int

int_of_cxint x returns i if x is representable as an integer value i, or raises Invalid_argument _ otherwise. signed specifies if x is signed (default: true).

val string_of_cxint : ?⁠signed:bool -> Clang__.Clang__bindings.cxint -> string

string_of_cxint f is an alias for Clang__bindings.ext_int_to_string, radix 10. signed specifies if x is signed (default: true).

Floating conversions

val float_of_cxfloat_opt : Clang__.Clang__bindings.cxfloat -> float option

float_of_cxfloat_opt x returns Some f if x is a floating-point value with either IEEE single or double semantics, or None otherwise.

val float_of_cxfloat : Clang__.Clang__bindings.cxfloat -> float

float_of_cxfloat x returns f if x is a floating-point value with either IEEE single or double semantics, or raises Invalid_argument _ otherwise.

val string_of_cxfloat : Clang__.Clang__bindings.cxfloat -> string

string_of_cxfloat f is an alias for Clang__bindings.ext_float_to_string.

Error management

val string_of_cxerrorcode : Clang__.Clang__bindings.cxerrorcode -> string

string_of_cxerrorcode ec returns a message describing ec.

val seq_of_diagnostics : Clang__.Clang__bindings.cxtranslationunit -> Clang__.Clang__bindings.cxdiagnostic Stdcompat.Seq.t

seq_of_diagnostics tu returns the diagnostics (notes, warnings, errors, ...) produced for the given translation unit

val concrete_of_cxsourcelocation : Clang__.Clang__types.location_kind -> Clang__.Clang__bindings.cxsourcelocation -> Clang__.Clang__types.concrete_location

concrete_of_cxsourcelocation kind location returns the concrete location associated to location. kind selects whether Clang.get_presumed_location (which ignores # line directive) or Clang.get_expansion_location (which honors # line directive) is called.

val string_of_severity : Clang__.Clang__bindings.cxdiagnosticseverity -> string

string_of_severity severity returns a string describing the severity: this string is used as prefix for the diagnostic in pp_diagnostic.

val pp_diagnostic : ?⁠options:Clang__.Clang__types.Diagnostic_display_options.t -> Stdcompat.Format.formatter -> Clang__.Clang__bindings.cxdiagnostic -> unit

pp_diagnostic ?options fmt diag formats diagnostic diag, mimicking Clang__bindings.format_diagnostic behavior. Clang__types.Display_source_location.t.kind supports various location kinds whereas Clang__bindings.format_diagnostic only displays spelling locations.

val format_diagnostics : ?⁠pp:((Stdcompat.Format.formatter -> unit -> unit) -> Stdcompat.Format.formatter -> unit -> unit) -> ?⁠options:Clang__.Clang__types.Diagnostic_display_options.t -> Clang__.Clang__bindings.cxdiagnosticseverity list -> Stdcompat.Format.formatter -> Clang__.Clang__bindings.cxtranslationunit -> unit

format_diagnostics ?pp severities fmt tu formats the diagnostics produced for the given translation unit. Only the diagnostics, the severity of which is listed in severities are displayed. If there is a printer given in pp, then this printer is called once if and only if there is at least one diagnostic to display, and pp should call the printer passed in its first argument to display the diagnostics. In the case there is no diagnostic to display, nothing is printed.

val error : Clang__.Clang__bindings.cxdiagnosticseverity list

error contains the severities Error and Fatal.

val warning_or_error : Clang__.Clang__bindings.cxdiagnosticseverity list

warning_or_error contains the severities Warning, Error and Fatal.

val not_ignored_diagnostics : Clang__.Clang__bindings.cxdiagnosticseverity list

not_ignored_diagnostics contains the severities Note, Warning, Error and Fatal.

val all_diagnostics : Clang__.Clang__bindings.cxdiagnosticseverity list

all_diagnostics contains the severities Ignored, Note, Warning, Error and Fatal.

val has_severity : Clang__.Clang__bindings.cxdiagnosticseverity list -> Clang__.Clang__bindings.cxtranslationunit -> bool

has_severity l tu returns whether the translation unit tu produced a diagnostic, the severity of which belongs to l.

val cursor_get_translation_unit : Clang__.Clang__bindings.cxcursor -> Clang__.Clang__bindings.cxtranslationunit

cursor_get_translation_unit cursor returns the translation unit associated to cursor.

val sourcelocation_get_translation_unit : Clang__.Clang__bindings.cxsourcelocation -> Clang__.Clang__bindings.cxtranslationunit

sourcelocation_get_translation_unit location returns the translation unit associated to location.

val binary_of_overloaded_operator_kind : Clang__.Clang__bindings.clang_ext_overloadedoperatorkind -> Clang__.Clang__bindings.clang_ext_binaryoperatorkind

General purpose utilities

val extract_prefix_from_list : ('a -> 'b option) -> 'a list -> 'b list * 'a list