Project

General

Profile

« Previous | Next » 

Revision 3826f8cb

Added by Pierre-Loïc Garoche over 9 years ago

Solved bug:
- loading lusi
- loading lib in lusi files: "in m" is now "lib m"

git-svn-id: https://cavale.enseeiht.fr/svn/lustrec/lustre_compiler/trunk@247 041b043f-8d7c-46b2-b46e-ef0dd855326e

View differences:

src/lexer_lustre.mll
72 72
  "div", DIV;
73 73
  "const", CONST;
74 74
  "assert", ASSERT;
75
  "in", IN;
75
  "lib", LIB;
76 76
  "prototype", PROTOTYPE;
77 77
]
78 78

  
src/location.ml
38 38
    Lexing.pos_cnum = 0;
39 39
  }
40 40
      
41
let symbol_rloc () = {
42
  loc_start = Parsing.symbol_start_pos ();
43
  loc_end = Parsing.symbol_end_pos ()
44
}
41
let symbol_rloc () = 
42
  {
43
    loc_start = Parsing.symbol_start_pos ();
44
    loc_end = Parsing.symbol_end_pos ()
45
  }
46
    
45 47

  
46 48
open Format
47 49

  
src/main_lustre_compiler.ml
137 137
      try
138 138
	let basename = (if local then s else Version.prefix ^ "/include/lustrec/" ^ s ) ^ ".lusi" in 
139 139
	report ~level:1 (fun fmt -> fprintf fmt "@[<v 0>Library %s@," basename);
140
	let comp_dep, lusi_type_env, lusi_clock_env = check_lusi (load_lusi false basename) in 
140
	  let comp_dep, lusi_type_env, lusi_clock_env = check_lusi (load_lusi false basename) in 
141 141
	report ~level:1 (fun fmt -> fprintf fmt "@]@ ");
142
	(s, local, comp_dep)::compilation_dep,
143
	Env.overwrite type_env lusi_type_env,
144
	Env.overwrite clock_env lusi_clock_env      
142
	
143
	  (s, local, comp_dep)::compilation_dep,
144
	  Env.overwrite type_env lusi_type_env,
145
	  Env.overwrite clock_env lusi_clock_env      
145 146
      with Sys_error msg -> (
146 147
	Format.eprintf "Failure: impossible to load library %s.@.%s@." s msg;
147 148
	exit 1
......
149 150
    )  ([], Basic_library.type_env, Basic_library.clock_env) dependencies
150 151
  in
151 152
  report ~level:1 (fun fmt -> fprintf fmt "@]@ ");
152
  
153

  
153 154
  (* Unfold consts *)
154 155
  (*let prog = Corelang.prog_unfold_consts prog in*)
155 156

  
......
208 209
      let _ = open_in lusi_name in
209 210
      let header = load_lusi true lusi_name in
210 211
      let _, declared_types_env, declared_clocks_env = check_lusi header in
212

  
211 213
      (* checking type compatibility with computed types*)
212 214
      Typing.check_env_compat header declared_types_env computed_types_env;
213 215
      Typing.uneval_prog_generics prog;
216

  
214 217
      (* checking clocks compatibility with computed clocks*)
215 218
      Clock_calculus.check_env_compat header declared_clocks_env computed_clocks_env;
216 219
      Clock_calculus.uneval_prog_generics prog;
220

  
217 221
      (* checking stateless status compatibility *)
218 222
      Stateless.check_compat header
219 223
    with Sys_error _ -> ( 
src/parser_lustre.mly
42 42
let mkdim_appl f args = mkdim_appl (Location.symbol_rloc ()) f args
43 43
let mkdim_ite i t e = mkdim_ite (Location.symbol_rloc ()) i t e
44 44

  
45
let add_node own msg hashtbl name value =
45
let add_node loc own msg hashtbl name value =
46 46
  try
47 47
    match (Hashtbl.find hashtbl name).top_decl_desc, value.top_decl_desc with
48
    | Node _        , ImportedNode _ when own
49
                        -> ()
50
    | ImportedNode _, _ ->
51
       Hashtbl.add hashtbl name value
52
    | Node _        , _ -> 
53
       raise (Corelang.Error (Location.symbol_rloc (), Corelang.Already_bound_symbol msg))
54
    | _                 -> assert false
48
    | Node _        , ImportedNode _ when own   -> ()
49
    | ImportedNode _, _                         -> Hashtbl.add hashtbl name value
50
    | Node _        , _                         -> raise (Corelang.Error (loc, Corelang.Already_bound_symbol msg))
51
    | _                                         -> assert false
55 52
  with
56
    Not_found ->
57
       Hashtbl.add hashtbl name value
53
    Not_found                                   -> Hashtbl.add hashtbl name value
58 54

  
59
let add_symbol msg hashtbl name value =
55

  
56
let add_symbol loc msg hashtbl name value =
60 57
 if Hashtbl.mem hashtbl name
61
 then raise (Corelang.Error (Location.symbol_rloc (), Corelang.Already_bound_symbol msg))
58
 then raise (Corelang.Error (loc, Corelang.Already_bound_symbol msg))
62 59
 else Hashtbl.add hashtbl name value
63 60

  
64
let check_symbol msg hashtbl name =
61
let check_symbol loc msg hashtbl name =
65 62
 if not (Hashtbl.mem hashtbl name)
66
 then raise (Corelang.Error (Location.symbol_rloc (), Corelang.Unbound_symbol msg))
63
 then raise (Corelang.Error (loc, Corelang.Unbound_symbol msg))
67 64
 else ()
68 65

  
69 66
%}
......
90 87
%token MULT DIV MOD
91 88
%token MINUS PLUS UMINUS
92 89
%token PRE ARROW
93
%token PROTOTYPE IN
90
%token PROTOTYPE LIB
94 91
%token EOF
95 92

  
96 93
%nonassoc COMMA
......
148 145
| NODE { false }
149 146

  
150 147
top_decl_header:
151
| CONST cdecl_list { fun _ -> mktop_decl (Consts (List.rev $2)) }
148
| CONST cdecl_list { let top = mktop_decl (Consts (List.rev $2)) in fun _ -> top }
152 149
| nodespec_list state_annot IDENT LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR  prototype_opt in_lib_opt SCOL
153 150
    {let nd = mktop_decl (ImportedNode
154 151
                            {nodei_id = $3;
......
161 158
			     nodei_prototype = $13;
162 159
			     nodei_in_lib = $14;})
163 160
    in
164
    (fun own -> add_node own ("node " ^ $3) node_table $3 nd; nd) }
161
    (let loc = Location.symbol_rloc () in 
162
     fun own -> add_node loc own ("node " ^ $3) node_table $3 nd; nd) }
165 163

  
166 164
prototype_opt:
167 165
 { None }
......
169 167

  
170 168
in_lib_opt:
171 169
{ None }
172
| IN IDENT {Some $2} 
170
| LIB IDENT {Some $2} 
173 171

  
174 172
top_decl:
175 173
| CONST cdecl_list { mktop_decl (Consts (List.rev $2)) }
......
190 188
			     node_stateless = None;
191 189
			     node_spec = $1;
192 190
			     node_annot = match annots with [] -> None | _ -> Some annots})
193
    in
194
    add_node true ("node " ^ $3) node_table $3 nd; nd}
191
     in
192
     let loc = Location.symbol_rloc () in
193
     add_node loc true ("node " ^ $3) node_table $3 nd; nd}
195 194

  
196 195
nodespec_list:
197 196
 { None }
......
204 203
typ_def:
205 204
  TYPE IDENT EQ typeconst {
206 205
    try
207
      add_symbol ("type " ^ $2) type_table (Tydec_const $2) (Corelang.get_repr_type $4)
206
      let loc = Location.symbol_rloc () in
207
      add_symbol loc ("type " ^ $2) type_table (Tydec_const $2) (Corelang.get_repr_type $4)
208 208
    with Not_found-> assert false }
209 209
| TYPE IDENT EQ ENUM LCUR tag_list RCUR { Hashtbl.add type_table (Tydec_const $2) (Tydec_enum ($6 (Tydec_const $2))) }
210 210
| TYPE IDENT EQ STRUCT LCUR field_list RCUR { Hashtbl.add type_table (Tydec_const $2) (Tydec_struct ($6 (Tydec_const $2))) }
......
218 218
| TBOOL array_typ_decl { $2 Tydec_bool  }
219 219
| TREAL array_typ_decl { $2 Tydec_real  }
220 220
| TFLOAT array_typ_decl { $2 Tydec_float }
221
| IDENT array_typ_decl { check_symbol ("type " ^ $1) type_table (Tydec_const $1); $2 (Tydec_const $1) }
221
| IDENT array_typ_decl { 
222
        let loc = Location.symbol_rloc () in
223
	check_symbol loc ("type " ^ $1) type_table (Tydec_const $1); $2 (Tydec_const $1) }
222 224
| TBOOL TCLOCK  { Tydec_clock Tydec_bool }
223 225
| IDENT TCLOCK  { Tydec_clock (Tydec_const $1) }
224 226

  
225 227
tag_list:
226 228
  IDENT
227
  { (fun t -> add_symbol ("tag " ^ $1) tag_table $1 t; $1 :: []) }
229
  { let loc = Location.symbol_rloc () in 
230
    (fun t -> 
231
      add_symbol loc ("tag " ^ $1) tag_table $1 t; $1 :: []) }
228 232
| tag_list COMMA IDENT
229
  { (fun t -> add_symbol ("tag " ^ $3)tag_table $3 t; $3 :: ($1 t)) }
230

  
233
      {       
234
	let loc = Location.symbol_rloc () in
235
	(fun t -> add_symbol loc ("tag " ^ $3)tag_table $3 t; $3 :: ($1 t)) 
236
      }
237
      
231 238
field_list:
232 239
  { (fun t -> []) }
233 240
| field_list IDENT COL typeconst SCOL
234
  { (fun t -> add_symbol ("field " ^ $2) field_table $2 t; ($1 t) @ [ ($2, $4) ]) }
235

  
241
      {
242
	let loc = Location.symbol_rloc () in
243
	(fun t -> add_symbol loc ("field " ^ $2) field_table $2 t; ($1 t) @ [ ($2, $4) ]) }
244
      
236 245
eq_list:
237 246
  { [], [], [] }
238 247
| eq eq_list {let eql, assertl, annotl = $2 in ($1::eql), assertl, annotl}

Also available in: Unified diff