|
|
@@ -51,37 +51,45 @@ let rec analyse scope depth args node =
|
|
|
(* Add node reference for this varname to vars map *)
|
|
|
| VarDec (ctype, name, init, ann) ->
|
|
|
let node = match init with
|
|
|
- | Some value -> VarDec (ctype, name, Some (collect value), ann)
|
|
|
- | None -> node
|
|
|
+ | Some value -> VarDec (ctype, name, Some (collect value),
|
|
|
+ Depth depth :: ann)
|
|
|
+ | None -> VarDec (ctype, name, init, Depth depth :: ann)
|
|
|
in
|
|
|
add_to_scope (Varname name) node depth scope;
|
|
|
- VarDec (ctype, name, init, Depth depth :: ann)
|
|
|
+ node
|
|
|
|
|
|
(* For global vars, only the name and array dimensions *)
|
|
|
| GlobalDec (Array (ctype, dims), name, ann) ->
|
|
|
+ let node = GlobalDec (Array (ctype, List.map collect dims), name,
|
|
|
+ Depth depth :: ann) in
|
|
|
add_to_scope (Varname name) node depth scope;
|
|
|
- GlobalDec (Array (ctype, List.map collect dims), name, ann)
|
|
|
+ node
|
|
|
|
|
|
| Dim (name, ann) ->
|
|
|
+ let node = Dim (name, Depth depth :: ann) in
|
|
|
add_to_scope (Varname name) node depth scope;
|
|
|
- Dim (name, Depth depth :: ann)
|
|
|
+ node
|
|
|
|
|
|
| GlobalDec (ctype, name, ann) ->
|
|
|
+ let node = GlobalDec (ctype, name, Depth depth :: ann) in
|
|
|
add_to_scope (Varname name) node depth scope;
|
|
|
- GlobalDec (ctype, name, Depth depth :: ann)
|
|
|
+ node
|
|
|
|
|
|
| GlobalDef (export, ctype, name, init, ann) ->
|
|
|
+ let node = GlobalDef (export, ctype, name, init, Depth depth :: ann) in
|
|
|
add_to_scope (Varname name) node depth scope;
|
|
|
- GlobalDef (export, ctype, name, init, Depth depth :: ann)
|
|
|
+ node
|
|
|
|
|
|
(* Functions are traversed later on, for now only add the name *)
|
|
|
| FunDec (ret_type, name, params, ann) ->
|
|
|
+ let node = FunDec (ret_type, name, params, Depth depth :: ann) in
|
|
|
add_to_scope (Funcname name) node depth scope;
|
|
|
- FunDec (ret_type, name, params, Depth depth :: ann)
|
|
|
+ node
|
|
|
|
|
|
| FunDef (export, ret_type, name, params, body, ann) ->
|
|
|
+ let node = FunDef (export, ret_type, name, params, body, Depth depth :: ann) in
|
|
|
add_to_scope (Funcname name) node depth scope;
|
|
|
- FunDef (export, ret_type, name, params, body, Depth depth :: ann)
|
|
|
+ node
|
|
|
|
|
|
(* For a variable or function call, look for its declaration in the
|
|
|
* current scope and save a its type/depth information *)
|