|
|
@@ -47,11 +47,13 @@ let rec analyse scope depth node =
|
|
|
let rec collect node = match node with
|
|
|
(* 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),
|
|
|
- Depth depth :: ann)
|
|
|
- | None -> VarDec (ctype, name, init, Depth depth :: ann)
|
|
|
- in
|
|
|
+ (* Traverse Dim nodes *)
|
|
|
+ let node = VarDec (ctype, name, init, Depth depth :: ann) in
|
|
|
+ add_to_scope (Varname name) node depth scope;
|
|
|
+ node
|
|
|
+
|
|
|
+ | DimDec (name, init, ann) ->
|
|
|
+ let node = DimDec (name, init, Depth depth :: ann) in
|
|
|
add_to_scope (Varname name) node depth scope;
|
|
|
node
|
|
|
|
|
|
@@ -65,11 +67,6 @@ let rec analyse scope depth node =
|
|
|
add_to_scope (Varname name) node depth scope;
|
|
|
node
|
|
|
|
|
|
- | Dim (name, ann) ->
|
|
|
- let node = Dim (name, Depth depth :: ann) in
|
|
|
- add_to_scope (Varname name) node depth scope;
|
|
|
- node
|
|
|
-
|
|
|
| GlobalDef (export, ctype, name, init, ann) ->
|
|
|
let ctype = match ctype with
|
|
|
| Array (ctype, dims) -> Array (ctype, List.map collect dims)
|
|
|
@@ -80,13 +77,9 @@ let rec analyse scope depth node =
|
|
|
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;
|
|
|
- node
|
|
|
-
|
|
|
- | FunDef (export, ret_type, name, params, body, ann) ->
|
|
|
- let node = FunDef (export, ret_type, name, params, body, Depth depth :: ann) in
|
|
|
+ | FunDec (_, name, _, _)
|
|
|
+ | FunDef (_, _, name, _, _, _) ->
|
|
|
+ let node = annotate (Depth depth) node in
|
|
|
add_to_scope (Funcname name) node depth scope;
|
|
|
node
|
|
|
|
|
|
@@ -123,16 +116,18 @@ let rec analyse scope depth node =
|
|
|
let body = analyse local_scope (depth + 1) body in
|
|
|
FunDef (export, ret_type, name, params, body, ann)
|
|
|
|
|
|
- | Param (Array (ctype, dims), name, ann) as node ->
|
|
|
- let _ = List.map (traverse scope depth) dims in
|
|
|
+ | Param (Array (ctype, dims), name, ann) ->
|
|
|
+ let dims = List.map (traverse scope depth) dims in
|
|
|
+ let node = Param (Array (ctype, dims), name, ann) in
|
|
|
add_to_scope (Varname name) node depth scope;
|
|
|
node
|
|
|
|
|
|
- | Dim (name, _) as dim ->
|
|
|
- add_to_scope (Varname name) dim depth scope;
|
|
|
- node
|
|
|
+ (* Prevent Dim nodes from VarDec types from being added twice *)
|
|
|
+ | DimDec _ -> node
|
|
|
|
|
|
+ | Dim (name, _) (* Dim nodes as children of Param nodes *)
|
|
|
| Param (_, name, _) ->
|
|
|
+ let node = annotate (Depth depth) node in
|
|
|
add_to_scope (Varname name) node depth scope;
|
|
|
node
|
|
|
|