Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/releases/release-110.36/ckit/src/ast-utils/copy/copy-ast.sml
ViewVC logotype

Annotation of /sml/releases/release-110.36/ckit/src/ast-utils/copy/copy-ast.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 930 - (view) (download)

1 : dbm 597 (* Copyright (c) 1998 by Lucent Technologies *)
2 :    
3 :     (* Used to copy Ast structures while preserving unique adornments.
4 :     *)
5 :    
6 :     structure CopyAst : COPYAST =
7 :     struct
8 :    
9 :     open Ast
10 :    
11 :     type aidtab = Tables.aidtab
12 :    
13 :     fun copyOpt copier aidtab NONE = NONE
14 :     | copyOpt copier aidtab (SOME v) = SOME (copier aidtab v)
15 :    
16 :     fun copyAid aidtab oldaid =
17 :     let val newaid = Aid.new ()
18 :     in case Aidtab.find (aidtab,oldaid)
19 :     of NONE => () (* DBM: is this anomalous, should there be a warning? *)
20 :     | SOME ctype => Aidtab.insert (aidtab, newaid, ctype);
21 :     newaid
22 :     end
23 :    
24 :     fun copyAst aidtab extdecls =
25 :     List.map (copyExtDecl aidtab) extdecls
26 :    
27 :     and copyExtDecl aidtab (DECL (coreExtDecl,aid,loc)) =
28 :     let val aid = copyAid aidtab aid
29 :     val coreExtDecl = copyCoreExtDecl aidtab coreExtDecl
30 :     in DECL (coreExtDecl,aid,loc) end
31 :    
32 :     and copyCoreExtDecl aidtab =
33 :     fn ExternalDecl decl => ExternalDecl (copyDecl aidtab decl)
34 :     | FunctionDef (id,ids,stmt) => FunctionDef (id,ids,copyStmt aidtab stmt)
35 :     | ExternalDeclExt ext =>
36 :     ExternalDeclExt(CopyAstExt.copyExtDeclExt (copyExpr,copyStmt,copyExtDecl) aidtab ext)
37 :    
38 :     and copyDecl aidtab =
39 :     fn VarDecl (id,initExprOpt) => VarDecl (id,copyOpt copyInitExpr aidtab initExprOpt)
40 :     | typedecl => typedecl (* TypeDecl *)
41 :    
42 :     and copyStmt aidtab (stmt as STMT (coreStmt,aid,loc)) =
43 :     let val aid = copyAid aidtab aid
44 :     val coreStmt = copyCoreStmt aidtab coreStmt
45 :     in STMT (coreStmt,aid,loc)
46 :     end
47 :    
48 :     and copyCoreStmt aidtab =
49 :     fn Expr exprOpt => Expr (copyOpt copyExpr aidtab exprOpt)
50 :     | Compound (decls,stmts) => Compound (map (copyDecl aidtab) decls, List.map (copyStmt aidtab) stmts)
51 :     | While (expr,stmt) => While (copyExpr aidtab expr, copyStmt aidtab stmt)
52 :     | Do (expr,stmt) => Do (copyExpr aidtab expr, copyStmt aidtab stmt)
53 :     | For (exprOpt0,exprOpt1,exprOpt2,stmt) =>
54 :     For (copyOpt copyExpr aidtab exprOpt0,
55 :     copyOpt copyExpr aidtab exprOpt1,
56 :     copyOpt copyExpr aidtab exprOpt2,
57 :     copyStmt aidtab stmt)
58 :     | Labeled (pid,stmt) => Labeled (pid,copyStmt aidtab stmt)
59 :     | CaseLabel (li,stmt) => CaseLabel (li,copyStmt aidtab stmt)
60 :     | DefaultLabel stmt => DefaultLabel (copyStmt aidtab stmt)
61 :     | Return exprOpt => Return (copyOpt copyExpr aidtab exprOpt)
62 :     | IfThen (expr,stmt) => IfThen (copyExpr aidtab expr,copyStmt aidtab stmt)
63 :     | IfThenElse (expr,stmt0,stmt1) =>
64 :     IfThenElse (copyExpr aidtab expr,copyStmt aidtab stmt0,copyStmt aidtab stmt1)
65 :     | Switch (expr,stmt) => Switch (copyExpr aidtab expr,copyStmt aidtab stmt)
66 :     | StatExt ext =>
67 :     StatExt(CopyAstExt.copyStmtExt (copyExpr,copyStmt,copyExtDecl) aidtab ext)
68 :     | stmt => stmt
69 :    
70 :     and copyExpr aidtab (EXPR (coreExpr,aid,loc)) =
71 :     let val aid = copyAid aidtab aid
72 :     val coreExpr = copyCoreExpr aidtab coreExpr
73 :     in EXPR (coreExpr,aid,loc)
74 :     end
75 :    
76 :     and copyCoreExpr aidtab =
77 :     fn Call (expr,exprs) =>
78 :     Call (copyExpr aidtab expr,List.map (copyExpr aidtab) exprs)
79 :     | QuestionColon (expr0,expr1,expr2) =>
80 :     QuestionColon (copyExpr aidtab expr0,
81 :     copyExpr aidtab expr1,
82 :     copyExpr aidtab expr2)
83 :     | Assign (expr0,expr1) =>
84 :     Assign (copyExpr aidtab expr0, copyExpr aidtab expr1)
85 :     | Comma (expr0,expr1) => Comma (copyExpr aidtab expr0, copyExpr aidtab expr1)
86 :     | Sub (expr0,expr1) => Sub (copyExpr aidtab expr0,copyExpr aidtab expr1)
87 :     | Member (expr,pid) => Member (copyExpr aidtab expr,pid)
88 :     | Arrow (expr,pid) => Arrow (copyExpr aidtab expr,pid)
89 :     | Deref expr => Deref (copyExpr aidtab expr)
90 :     | AddrOf expr => AddrOf (copyExpr aidtab expr)
91 :     | Binop (binop,expr0,expr1) =>
92 :     Binop (binop,copyExpr aidtab expr0, copyExpr aidtab expr1)
93 :     | Unop (unop,expr) => Unop (unop,copyExpr aidtab expr)
94 :     | Cast (ctype,expr) => Cast (ctype,copyExpr aidtab expr)
95 :     | ExprExt ext =>
96 :     ExprExt(CopyAstExt.copyExprExt (copyExpr,copyStmt,copyExtDecl) aidtab ext)
97 :     | expr => expr
98 :    
99 :     and copyInitExpr aidtab =
100 :     fn Simple expr => Simple (copyExpr aidtab expr)
101 :     | Aggregate inits => Aggregate (map (copyInitExpr aidtab) inits)
102 :    
103 :     end (* functor CopyAstFn *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0