Project

General

Profile

Revision f9f06e7d src/modules.ml

View differences:

src/modules.ml
150 150
    raise exc
151 151
  )
152 152

  
153
let rec load_header_rec imported header =
154
  List.fold_left (fun imported decl ->
155
    match decl.top_decl_desc with
156
    | Node nd -> assert false
157
    | ImportedNode ind -> (add_imported_node ind.nodei_id decl; imported)
158
    | Const c -> (add_const true c.const_id decl; imported)
159
    | TypeDef tdef -> (add_type true tdef.tydef_id decl; imported)
160
    | Open (local, dep) ->
161
       let basename = Options_management.name_dependency (local, dep) in
162
       if ISet.mem basename imported then imported else
163
	 let lusic = import_dependency_aux decl.top_decl_loc (local, dep)
164
	 in load_header_rec (ISet.add basename imported) lusic.Lusic.contents
165
  ) imported header
166

  
167
let load_header imported header =
168
  try
169
    load_header_rec imported header
170
  with
171
    Corelang.Error (loc, err) as exc -> (
172
      Format.eprintf "Import error: %a%a@."
173
	Error.pp_error_msg err
174
	Location.pp_loc loc;
175
      raise exc
176
    );;
177 153

  
178
let rec load_program_rec imported program =
154
let rec load_rec ~is_header imported program =
179 155
  List.fold_left (fun imported decl ->
180 156
    match decl.top_decl_desc with
181
    | Node nd -> (add_node nd.node_id decl; imported)
182
    | ImportedNode ind -> assert false
183
    | Const c -> (add_const false c.const_id decl; imported)
184
    | TypeDef tdef -> (add_type false tdef.tydef_id decl; imported)
157
    | Node nd -> if is_header then
158
                   raise (Error(decl.top_decl_loc,
159
                                LoadError ("node " ^ nd.node_id ^ " declared in a header file")))  
160
                 else
161
                   (add_node nd.node_id decl; imported)
162
    | ImportedNode ind ->
163
       if is_header then
164
         (add_imported_node ind.nodei_id decl; imported)
165
       else
166
         raise (Error(decl.top_decl_loc,
167
                      LoadError ("imported node " ^ ind.nodei_id ^ " declared in a regular Lustre file")))  
168
    | Const c -> (add_const is_header c.const_id decl; imported)
169
    | TypeDef tdef -> (add_type is_header tdef.tydef_id decl; imported)
185 170
    | Open (local, dep) ->
186 171
       let basename = Options_management.name_dependency (local, dep) in
187 172
       if ISet.mem basename imported then imported else
188 173
	 let lusic = import_dependency_aux decl.top_decl_loc (local, dep)
189
	 in load_header_rec (ISet.add basename imported) lusic.Lusic.contents
174
	 in load_rec ~is_header:true (ISet.add basename imported) lusic.Lusic.contents
190 175
  ) imported program
191
    
192
let load_program imported program =
176

  
177
(* Iterates through lusi definitions and records them in the hashtbl. Open instructions are evaluated and update these hashtbl as well. node_table/type/table/consts_table *)
178
  
179
let load ~is_header imported program =
193 180
  try
194
    load_program_rec imported program
181
    load_rec ~is_header imported program
195 182
  with
196 183
    Corelang.Error (loc, err) as exc -> (
197 184
      Format.eprintf "Import error: %a%a@."

Also available in: Unified diff