4a3630f8decf6d62b619d8abbc1bdf6654b58b68
[bpt/coccinelle.git] / bundles / menhirLib / menhir-20120123 / src / front.ml
1 (**************************************************************************)
2 (* *)
3 (* Menhir *)
4 (* *)
5 (* François Pottier, INRIA Rocquencourt *)
6 (* Yann Régis-Gianas, PPS, Université Paris Diderot *)
7 (* *)
8 (* Copyright 2005-2008 Institut National de Recherche en Informatique *)
9 (* et en Automatique. All rights reserved. This file is distributed *)
10 (* under the terms of the Q Public License version 1.0, with the change *)
11 (* described in file LICENSE. *)
12 (* *)
13 (**************************************************************************)
14
15 (* Start where [PreFront] left off. *)
16
17 let grammar =
18 PreFront.grammar
19
20 (* Perform reachability analysis. *)
21
22 let grammar =
23 Reachability.trim grammar
24
25 let () =
26 Time.tick "Trimming"
27
28 (* If [--depend] was specified on the command line, perform
29 dependency analysis and stop. *)
30
31 let () =
32 match Settings.depend with
33 | Settings.OMRaw
34 | Settings.OMPostprocess ->
35 Infer.depend grammar (* never returns *)
36 | Settings.OMNone ->
37 ()
38
39 (* If [--infer] was specified on the command line, perform
40 type inference and stop. *)
41
42 let grammar =
43 if Settings.infer then
44 let grammar = Infer.infer grammar in
45 Time.tick "Inferring types for nonterminals";
46 grammar
47 else
48 grammar
49
50 (* If [--no-inline] was specified on the command line, skip the
51 inlining of non terminal definitions marked with %inline. *)
52
53 let grammar =
54 if Settings.inline then begin
55 let grammar, inlined =
56 NonTerminalDefinitionInlining.inline grammar
57 in
58 if not Settings.infer && inlined && not Settings.coq then
59 Error.warning []
60 "you are using the standard library and/or the %inline keyword. We\n\
61 recommend switching on --infer in order to avoid obscure type error messages.";
62 Time.tick "Inlining";
63 grammar
64 end
65 else
66 grammar
67
68 (* If [--only-preprocess] or [--only-preprocess-drop] was specified on the
69 command line, print the grammar and stop. Otherwise, continue. *)
70
71 let () =
72 match Settings.preprocess_mode with
73 | Settings.PMOnlyPreprocess mode ->
74 UnparameterizedPrinter.print mode stdout grammar;
75 exit 0
76 | Settings.PMNormal ->
77 ()
78