package FrontC

  1. Overview
  2. Docs
val version : string

* FrontC is an OCAML library providing facilities for parsing source file * in C language. * * Although it is designed for parsing ANSI C, it provides also support for * old K&R C style and for some GCC extensions. * * It provides also a limited degraded mode allowing to parse file although * all type information is not available and preprocessor directives are still * in the source. * *

  • author Hugues Cassé <hugues.casse\@laposte.net>
type parsing_arg =
  1. | FROM_STDIN
    (*

    Parse the standard input.

    *)
  2. | FROM_CHANNEL of in_channel
    (*

    Parse the given channel.

    *)
  3. | FROM_FILE of string
    (*

    Parse the given file.

    *)
  4. | USE_CPP
    (*

    Use the C preprocessor.

    *)
  5. | PREPROC of string
    (*

    Path to the preprocessor.

    *)
  6. | DEF of string
    (*

    Pass this definition to CPP.

    *)
  7. | UNDEF of string
    (*

    Undefine the given symbol for CPP.

    *)
  8. | INCLUDE of string
    (*

    Include the given file by the CPP.

    *)
  9. | INCLUDE_DIR of string
    (*

    Use the given directory for retrieving includes.

    *)
  10. | OPTION of string
    (*

    Pass the given option directl to the CPP.

    *)
  11. | ERROR of out_channel
    (*

    Use the given channel for outputting errors.

    *)
  12. | INTERACTIVE of bool
    (*

    Is this session interactive (from console).

    *)
  13. | GCC_SUPPORT of bool
    (*

    Support some extensions of the GCC compiler (default to true).

    *)
  14. | LINE_RECORD of bool
    (*

    Record line numbers in the C abstract trees (default to false).

    *)

* Parameters for building the reader handler.

type parsing_result =
  1. | PARSING_ERROR
    (*

    Parsing failure. Error outputted.

    *)
  2. | PARSING_OK of Cabs.definition list
    (*

    Success. Return list of read definitions.

    *)

* Result of a parsing.

val trans_old_fun_def : (Cabs.single_name * Cabs.name_group list * Cabs.body) -> Cabs.definition

* Transform an old K&R C function definition into a new ANSI one. *

  • parameter def

    Old function definition. *

    @return

    New function definition. *

    @raise UnconsistentDef

    Raised when an undeclared parameter is found * in the function definition.

val trans_old_fun_defs : Cabs.definition list -> Cabs.definition list

* Transform all old function definition into new ones. *

  • parameter defs

    Defs to transform. *

    @return

    Definitions with all old function definitions transformed. *

    @raise UnconsistentDef

    Raised if some old function definition does not * define the type of a parameter.

val convert_to_xml : Cabs.definition list -> Cxml.document

* Convert the given C file abstract repersentation into XML. *

  • parameter file

    C file to convert. *

    @return

    XML document result of conversion. *

    @raise UnconsistentDef

    Raised if the file contains some old function * definition whose one parameter is not defined.

val parse : parsing_arg list -> parsing_result
val parse_interactive : in_channel -> out_channel -> parsing_result

* Parse the input channel in interactive way, that is, as coming from the * console. Error are displayed in a specific way. *

  • parameter inp

    Input to read the C source from. *

    @param out

    For outputting errors. *

    @return

    Read C definitions.

val parse_console : 'a -> parsing_result

* Parse the C source from the console. It exactly equals to * "parse_interactive stdin stderr". *

  • returns

    Read C definitions.

val parse_channel : in_channel -> out_channel -> parsing_result

* Parse the C source from a non-interactive channel. It may be useful when * the source come from a piped channel from the C preprocessor, for example.* *

  • parameter input

    Input channel to read the source from. *

    @param out

    Output channel to display errors. *

    @return

    Read C definitions.

val parse_file : string -> out_channel -> parsing_result

* Parse a C source passed as a file path. *

  • parameter file_name

    Path of the file to read. *

    @param out

    Channel used for displaying errors. *

    @return

    Read C definitions. * * NOTE: an error during the read of the file returned as a parse failure.

OCaml

Innovation. Community. Security.