|
@@ -9,6 +9,8 @@ let type2str = function Funcname _ -> "function" | Varname _ -> "variable"
|
|
|
let mapfind name tbl =
|
|
let mapfind name tbl =
|
|
|
if Hashtbl.mem tbl name then Some (Hashtbl.find tbl name) else None
|
|
if Hashtbl.mem tbl name then Some (Hashtbl.find tbl name) else None
|
|
|
|
|
|
|
|
|
|
+let is_generated name = String.contains name '$'
|
|
|
|
|
+
|
|
|
let check_in_scope name errnode scope =
|
|
let check_in_scope name errnode scope =
|
|
|
let (vars, funs) = scope in
|
|
let (vars, funs) = scope in
|
|
|
let (name, tbl, other_map, desired_type) = match name with
|
|
let (name, tbl, other_map, desired_type) = match name with
|
|
@@ -34,10 +36,16 @@ let add_to_scope name dec depth (vars, funs) =
|
|
|
(* Identifiers of lower depth may be overwritten, but idenetifiers at
|
|
(* Identifiers of lower depth may be overwritten, but idenetifiers at
|
|
|
* the same depth must be unique for consistency *)
|
|
* the same depth must be unique for consistency *)
|
|
|
| Some (orig, orig_depth, _) when orig_depth >= depth ->
|
|
| Some (orig, orig_depth, _) when orig_depth >= depth ->
|
|
|
- let msg = sprintf "Error: cannot redeclare %s \"%s\"" name_type name in
|
|
|
|
|
- prerr_loc_msg (locof dec) msg;
|
|
|
|
|
- prerr_loc_msg (locof orig) "Previously declared here:";
|
|
|
|
|
- raise EmptyError
|
|
|
|
|
|
|
+ (* For generated variables, don't gove an error, since the error variable
|
|
|
|
|
+ * is a derived array dimension of a redefined array, which will yield an
|
|
|
|
|
+ * error later on *)
|
|
|
|
|
+ if is_generated name then
|
|
|
|
|
+ Hashtbl.replace tbl name (dec, depth, name_type)
|
|
|
|
|
+ else
|
|
|
|
|
+ let msg = sprintf "Error: cannot redeclare %s \"%s\"" name_type name in
|
|
|
|
|
+ prerr_loc_msg (locof dec) msg;
|
|
|
|
|
+ prerr_loc_msg (locof orig) "Previously declared here:";
|
|
|
|
|
+ raise EmptyError
|
|
|
| Some _ ->
|
|
| Some _ ->
|
|
|
Hashtbl.replace tbl name (dec, depth, name_type)
|
|
Hashtbl.replace tbl name (dec, depth, name_type)
|
|
|
| None ->
|
|
| None ->
|