Consistent naming for vars and forms

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-08 16:27:47 +07:00
parent 7cb068d1eb
commit 1a9895aec4
5 changed files with 40 additions and 40 deletions

View File

@ -196,20 +196,20 @@ module Var = struct
let loc (t : t) = t.loc
type kind =
| Single of string
| Pair of string * string
| Var of string
| Macro of string * string
let destruct { loc = _ ; name; payload; syntax = _ } =
match payload with
| None -> Single name
| Some p -> Pair (name, p)
| None -> Var name
| Some p -> Macro (name, p)
let name { name; _ } = name
let full_name t =
match destruct t with
| Single s -> s
| Pair (k, v) -> k ^ ":" ^ v
| Var s -> s
| Macro (k, v) -> k ^ ":" ^ v
let to_string = string_of_var
@ -223,7 +223,7 @@ module Var = struct
let with_name t ~name =
{ t with name }
let is_form t = Option.is_some t.payload
let is_macro t = Option.is_some t.payload
end
let partial_expand
@ -278,8 +278,8 @@ let expand t ~mode ~dir ~f =
begin match var.syntax with
| Percent ->
begin match Var.destruct var with
| Single v -> Loc.fail var.loc "unknown variable %S" v
| Pair _ -> Loc.fail var.loc "unknown form %s" (string_of_var var)
| Var v -> Loc.fail var.loc "unknown variable %S" v
| Macro _ -> Loc.fail var.loc "unknown form %s" (string_of_var var)
end
| Dollar_brace
| Dollar_paren -> Some [Value.String (string_of_var var)]

View File

@ -58,8 +58,8 @@ module Var : sig
val full_name : t -> string
type kind =
| Single of string
| Pair of string * string
| Var of string
| Macro of string * string
val destruct : t -> kind
@ -69,7 +69,7 @@ module Var : sig
val with_payload : t -> payload:string option -> t
val is_form : t -> bool
val is_macro : t -> bool
end
val expand

View File

@ -46,7 +46,7 @@ type t =
; stanzas_to_consider_for_install : Installable.t list
; cxx_flags : string list
; vars : Var.Kind.t Var.Map.t
; forms : Var.Form.t Var.Map.t
; macros : Var.Macro.t Var.Map.t
; chdir : (Action.t, Action.t) Build.t
; host : t option
; libs_by_package : (Package.t * Lib.Set.t) Package.Name.Map.t
@ -86,17 +86,17 @@ let find_scope_by_dir t dir = Scope.DB.find_by_dir t.scopes dir
let find_scope_by_name t name = Scope.DB.find_by_name t.scopes name
let expand_vars t ~syntax_version ~var : Var.Kind.t option =
if String_with_vars.Var.is_form var then
Exn.code_error "expand_vars can't expand forms"
if String_with_vars.Var.is_macro var then
Exn.code_error "expand_vars can't expand macros"
[ "var", String_with_vars.Var.sexp_of_t var ]
else
Var.Map.expand t.vars ~syntax_version ~var
let expand_form t ~syntax_version ~var =
if String_with_vars.Var.is_form var then
Var.Map.expand t.forms ~syntax_version ~var
let expand_macro t ~syntax_version ~var =
if String_with_vars.Var.is_macro var then
Var.Map.expand t.macros ~syntax_version ~var
else
Exn.code_error "expand_vars can't expand single variables"
Exn.code_error "expand_macro can't expand variables"
[ "var", String_with_vars.Var.sexp_of_t var ]
let (expand_vars_string, expand_vars_path) =
@ -304,7 +304,7 @@ let create
; artifacts
; cxx_flags
; vars
; forms = Var.Map.forms
; macros = Var.Map.macros
; chdir = Build.arr (fun (action : Action.t) ->
match action with
| Chdir _ -> action
@ -595,8 +595,8 @@ module Action = struct
let expand_form s var syntax_version =
let loc = String_with_vars.Var.loc var in
let key = String_with_vars.Var.full_name var in
begin match expand_form sctx ~syntax_version ~var with
| Some Var.Form.Exe -> Some (path_exp (map_exe (Path.relative dir s)))
begin match expand_macro sctx ~syntax_version ~var with
| Some Var.Macro.Exe -> Some (path_exp (map_exe (Path.relative dir s)))
| Some Dep -> Some (path_exp (Path.relative dir s))
| Some Bin -> begin
let sctx = host sctx in
@ -691,8 +691,8 @@ module Action = struct
let key = String_with_vars.Var.full_name var in
let res =
match String_with_vars.Var.destruct var with
| Pair (_, s) -> expand_form s var syntax_version
| Single var_name ->
| Macro (_, s) -> expand_form s var syntax_version
| Var var_name ->
begin match expand_vars sctx ~syntax_version ~var with
| None -> String.Map.find extra_vars key
| Some Targets ->

View File

@ -17,7 +17,7 @@ module Kind = struct
| Targets -> None
end
module Form = struct
module Macro = struct
type t =
| Exe
| Dep
@ -58,18 +58,18 @@ module Map = struct
; "SCOPE_ROOT", renamed_in ~version:(1, 0) ~new_name:"project_root"
]
let forms =
let form kind = No_info kind in
let open Form in
[ "exe", form Exe
; "bin", form Bin
; "lib", form Lib
; "libexec", form Libexec
; "lib-available", form Lib_available
; "version", form Version
; "read", form Read
; "read-lines", form Read_lines
; "read-strings", form Read_strings
let macros =
let macro kind = No_info kind in
let open Macro in
[ "exe", macro Exe
; "bin", macro Bin
; "lib", macro Lib
; "libexec", macro Libexec
; "lib-available", macro Lib_available
; "version", macro Version
; "read", macro Read
; "read-lines", macro Read_lines
; "read-strings", macro Read_strings
; "dep", since ~version:(1, 0) Dep
@ -152,7 +152,7 @@ module Map = struct
Option.bind (String.Map.find t name) ~f:(fun v ->
let what var =
String_with_vars.Var.to_string (
if String_with_vars.Var.is_form var then
if String_with_vars.Var.is_macro var then
String_with_vars.Var.with_payload var ~payload:(Some "..")
else
var)

View File

@ -9,7 +9,7 @@ module Kind : sig
val to_value_no_deps_or_targets : t -> scope:Scope.t -> Value.t list option
end
module Form : sig
module Macro : sig
type t =
| Exe
| Dep
@ -36,7 +36,7 @@ module Map : sig
val create_vars : context:Context.t -> cxx_flags:string list -> Kind.t t
val forms : Form.t t
val macros : Macro.t t
val static_vars : Kind.t t