Skip to content
This repository
tag: v580
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 133 lines (103 sloc) 4.346 kb
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 126 127 128 129 130 131 132
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(**
This module contains the compilation passes that are executed
in SurfaceAst (the very front end of the compiler)
except the parsing pass (that is available in OpaParser)
*)

open SurfaceAst (* importing code, expr, all the directives types *)

type ('a,'b) env_both_lcodes = {
  lcodeNotUser : ('a,'b) code ;
  (** Source code added automatically *)

  lcodeUser : ('a,'b) code ;
  (** Source code added at the request of the user *)

  lcodeTypeRenaming : (Ident.t * FilePos.pos) StringMap.t ;
  (** the renaming of types for the current package *)

  exported_values_idents : IdentSet.t ;
  (** The set of values identifiers that are exported outside this package.
It contains all toplevel values definitions that are not marked by a
@private directive. *)
  env_bsl : BslLib.env_bsl ;
  (** plugins and bymap *)
}

(**
The result of parsing a file.
*)
type 'a parsed_file = {
  parsedFile_filename : string ;
  (** The full name of the file*)

  parsedFile_lcode : (string,'a) code ;
  (** The surface Ast *)

  parsedFile_content : string ;
  (** The content of the file *)
}


type options = OpaEnv.opa_options

(**
This pass looks for Package declaration of each file, and loads these
dependencies
The node Package is removed from the code and never appears afterwards
*)
val pass_load_objects:
  options:options ->
  (([< SurfaceAst.all_directives > `static_content `static_content_directory `static_resource `static_resource_directory ] as 'b) parsed_file list * 'b parsed_file list) ->
  ((string, 'b) SurfaceAst.code_elt ObjectFiles.parsed_code -> unit) ->
  unit

(**
This pass goes through the whole to transform the syntactic constructions
parsers and xml_parser into real opa code
Parser generation happens in trx_convert.ml
Xml_parser generation happens in xml_pattern.ml

Assumptions: no alpha renaming yet
no directives other than `xml_parser contains an expression in its variant

Directives removed : [\[ `xml_parser _ \]]

Directives added : [\[\]]
*)
val pass_parser_generation :
  options:options ->
  (string,parsing_directive) env_both_lcodes ->
  (string, renaming_directive) env_both_lcodes


(**
This pass alpha renames the whole code
It takes care of renaming types, type variables, and identifiers

Assumptions:
- every identifier that is allowed to be unbound should be given (first argument)
for example, git_version, or release are defined afterwards by the compiler and must be given
in the list
- every type identifier that is allowed to be unbound should given as
a second argument
tuples are a special cases: tuple_%d, where d >= 0 is automatically defined once it is used
afterwards, a mapping from integers to the corresponding tuple identifier can be retrieved
- no directive bind variables in their subexpression, or somehow change the scope
there is of course a few exceptions: SurfaceAst.alpha_renaming_directive
- no variant of a directive contains expressions, patterns, types or anything that should be renamed

Directives removed : [SurfaceAst.alpha_renaming_directive]

Directives added : [\[ `local \]]
*)
val pass_check_duplication :
  string list ->
  string list ->
  options:options ->
  (string, renaming_directive) env_both_lcodes ->
  (Ident.t, dependency_directive) env_both_lcodes


(**
This pass insert the definitions of tuple_%d for every use that was recorded
by the alpha renaming pass

Assumption: alpha renaming has been performed already

Directives removed : [\[\]]

Directives added : [\[\]]
*)
val pass_tuple_types :
  options:options ->
  (Ident.t, 'b) code ->
  (Ident.t, 'b) code
Something went wrong with that request. Please try again.