cparser: annotate AST printing for top-level decls

In order to compare ASTs for appearance/disappearance/modification of
declarations, it is easier to have the annotations obvious to any
external tool for ease of parsing.

Annotations take the form:
"##<decl_type>: <name>", e.g. "##Function: ctzl"

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
This commit is contained in:
Rafal Kolanski 2021-06-17 16:31:03 +10:00 committed by Rafal Kolanski
parent 6f13828560
commit 6095e9ecb2
1 changed files with 20 additions and 1 deletions

View File

@ -378,15 +378,34 @@ end
fun print_ast cse ast = let
open Absyn_Serial
fun decl_header decl
= case decl of
VarDecl (_, s, _, _, _) => "VarDecl: " ^ node s
| StructDecl (s, _) => "StructDecl: " ^ node s
| ExtFnDecl exfn => "ExtFnDecl: " ^ node (#name exfn)
| EnumDecl (soptw, _) =>
case node soptw of
SOME s => "EnumDecl: " ^ s
| NONE => "EnumDecl: Anonymous";
(* TypeDecl is not present in final AST *)
fun serial_defn (FnDefn ((retty,fnm),params,specs,body))
= Nm ("Function", [varspec_serial (retty,fnm),
list_serial varspec_serial params,
list_serial fnspec_serial specs,
list_serial bi_serial (node body)])
| serial_defn (Decl dw) = decl_serial (node dw)
fun defn_lines defn
= case defn of
FnDefn ((_, fnm), _, _, _) => ["##Function: " ^ node fnm] @
lines_serial (serial_defn defn)
| Decl decl => ["##" ^ decl_header (node decl)] @
lines_serial (serial_defn defn)
fun print_lines ss = app print (map (fn s => s ^ "\n") ss)
in
app (print_lines o lines_serial o serial_defn) ast
app (print_lines o defn_lines) ast
end
fun adjusted_complex_fncalls cse ast = let