Skip to content

Commit

Permalink
configurator: allow sizeof in C symbols import
Browse files Browse the repository at this point in the history
Fixes #1723

Signed-off-by: Christophe Troestler <Christophe.Troestler@umons.ac.be>
  • Loading branch information
Chris00 committed Dec 31, 2018
1 parent 94f635e commit 6fffdd2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ unreleased
rules that require files outside the build/source directory. (#1708, fixes
#848, @rgrinberg)

- Let `Configurator` handle `sizeof` (in addition to negative numbers).
(#1726, fixes #1723, @Chris00)

1.6.2 (05/12/2018)
------------------

Expand Down
29 changes: 14 additions & 15 deletions src/configurator/v1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,18 @@ module C_define = struct
Option.iter prelude ~f:(pr "%s");
if has_type Type.Int then (
pr {|
#define D0(x) ('0'+(x/1 )%%10)
#define D1(x) ('0'+(x/10 )%%10), D0(x)
#define D2(x) ('0'+(x/100 )%%10), D1(x)
#define D3(x) ('0'+(x/1000 )%%10), D2(x)
#define D4(x) ('0'+(x/10000 )%%10), D3(x)
#define D5(x) ('0'+(x/100000 )%%10), D4(x)
#define D6(x) ('0'+(x/1000000 )%%10), D5(x)
#define D7(x) ('0'+(x/10000000 )%%10), D6(x)
#define D8(x) ('0'+(x/100000000 )%%10), D7(x)
#define D9(x) ('0'+(x/1000000000)%%10), D8(x)
#define DUNE_ABS(x) ((x >= 0)? x: -(x))
#define D0(x) ('0'+(DUNE_ABS(x)/1 )%%10)
#define D1(x) ('0'+(DUNE_ABS(x)/10 )%%10), D0(x)
#define D2(x) ('0'+(DUNE_ABS(x)/100 )%%10), D1(x)
#define D3(x) ('0'+(DUNE_ABS(x)/1000 )%%10), D2(x)
#define D4(x) ('0'+(DUNE_ABS(x)/10000 )%%10), D3(x)
#define D5(x) ('0'+(DUNE_ABS(x)/100000 )%%10), D4(x)
#define D6(x) ('0'+(DUNE_ABS(x)/1000000 )%%10), D5(x)
#define D7(x) ('0'+(DUNE_ABS(x)/10000000 )%%10), D6(x)
#define D8(x) ('0'+(DUNE_ABS(x)/100000000 )%%10), D7(x)
#define D9(x) ('0'+(DUNE_ABS(x)/1000000000)%%10), D8(x)
#define DUNE_SIGN(x) ((x >= 0)? '+': '-')
|}
);
List.iteri vars ~f:(fun i (name, t) ->
Expand All @@ -366,14 +368,11 @@ module C_define = struct
pr {|
const char s%i[] = {
'B', 'E', 'G', 'I', 'N', '-', %s'-',
#if %s >= 0
DUNE_SIGN((%s)),
D9((%s)),
#else
'-', D9((- %s)),
#endif
'-', 'E', 'N', 'D'
};
|} i c_arr_i name name name
|} i c_arr_i name name
| String ->
pr {|const char *s%i = "BEGIN-%i-" %s "-END";|} i i name;
| Switch ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ let () =
let module C_define = Configurator.C_define in
Configurator.main ~name:"c_test" (fun t ->
C_define.import t
~prelude:{|#define CONFIGURATOR_TESTING "foobar"|}
~prelude:"#define CONFIGURATOR_TESTING \"foobar\"\n\
#define CONFIGURATOR_NEG_INT -127\n"
~includes:["caml/config.h"]
[ "CAML_CONFIG_H", C_define.Type.Switch
; "Page_log", C_define.Type.Int
; "CONFIGURATOR_TESTING", C_define.Type.String
; "CONFIGURATOR_NEG_INT", C_define.Type.Int
; "sizeof(char)", C_define.Type.Int
]
|> List.iter (fun (n, v) ->
Printf.printf "%s=%s\n"
Expand Down
2 changes: 2 additions & 0 deletions test/blackbox-tests/test-cases/configurator/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ Importing #define's from code is successful
CAML_CONFIG_H=true
Page_log=12
CONFIGURATOR_TESTING=foobar
CONFIGURATOR_NEG_INT=-127
sizeof(char)=1

0 comments on commit 6fffdd2

Please sign in to comment.