gcc config
[prop.git] / prop-src / setl-ast.pcc
blob6a94868818a9d4d1279485495ecb61cc50bf6ddb
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 //  This file implements the basic routines on definitions and statements
4 //  ASTs.
5 //
6 ///////////////////////////////////////////////////////////////////////////////
8 #include <istd::ostream.h>
9 #include "ir.h"
10 #include "ast.ph"
11 #include "setl-ast.ph"
13 ///////////////////////////////////////////////////////////////////////////////
15 //  Instantiate the AST datatypes.
17 ///////////////////////////////////////////////////////////////////////////////
18 instantiate datatype Def, Sig, Stmt,
19                      List<Def>, List<Sig>, List<LabSig>,
20                      List<Stmt>;
22 ///////////////////////////////////////////////////////////////////////////////
24 //  The rest of pretty printing functions for definitions and statements
26 ///////////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////////////
30 //  Pretty print a signature
32 ///////////////////////////////////////////////////////////////////////////////
33 std::ostream& operator << (std::ostream& f, Sig s)
34 {  match (s)
35    {  NOsig:           { f << "none"; }
36    |  IDsig id:        { f << id; }
37    |  DOTsig (s,id):   { f << s << '.' << id; }
38    |  APPsig (s,ss):   { f << s << '(' << ss << ')'; }
39    |  DEFsig def:      { f << "<def>"; }
40    |  LAMBDAsig (_,_): { f << "<lambda>"; }
41    }
42    return f;
45 ///////////////////////////////////////////////////////////////////////////////
47 //  Pretty print a signature list
49 ///////////////////////////////////////////////////////////////////////////////
50 std::ostream& operator << (std::ostream& f, Sigs ss)
51 {  match while (ss)
52    {  #[one]:          { f << one; ss = #[]; }
53    |  #[one ... rest]: { f << one << ", "; ss = rest; }
54    }
55    return f;
58 ///////////////////////////////////////////////////////////////////////////////
60 //  Pretty print a statement
62 ///////////////////////////////////////////////////////////////////////////////
63 std::ostream& operator << (std::ostream& f, Stmt s)
65    match (s)
66    {  NOstmt:                   { f << "skip;"; }
67    |  ASSIGNstmt  (a, b):       { f << a << " := " << b << ';'; }
68    |  BLOCKstmt   (_, stmts):   { f << stmts; }
69    |  WHILEstmt   (e, s):    
70         { f << "while " << e <<  " loop " << s << " end loop"; }
71    |  IFstmt      (e, y, n): 
72         { f << "if " << e << " then " << y << " else " << n << "end if"; }
73    |  FORALLstmt  (bs, s):   
74         { f << "forall " << bs << " loop " << s << "end loop"; }
75    |  RETURNstmt e:
76         { f << "return " << e << ';'; }
77    |  MATCHstmt m:
78         { f << "match ..."; }
79    |  REWRITEstmt m:
80         { f << "rewrite ..."; }
81    |  REPLACEMENTstmt m:
82         { f << "rewrite ..."; }
83    }
84    return f;
87 ///////////////////////////////////////////////////////////////////////////////
89 //  Pretty print a list of statements
91 ///////////////////////////////////////////////////////////////////////////////
92 std::ostream& operator << (std::ostream& f, Stmts s)
93 {  match while (s)
94    {  #[one]:     { f << one; s = #[]; }
95    |  #[h ... t]: { f << h << " "; s = t; }
96    }
97    return f;
100 ///////////////////////////////////////////////////////////////////////////////
102 //  Pretty print a generator expression
104 ///////////////////////////////////////////////////////////////////////////////
105 std::ostream& operator << (std::ostream& f, Generator b)
106 {  match (b)
107    {  GENERATOR{ pat,guard,exp }:
108       {  f << pat;
109          if (guard != NOexp) f << " | " << guard;
110          f << " <- " << exp;
111       }
112    }
113    return f;
116 ///////////////////////////////////////////////////////////////////////////////
118 //  Pretty print a list of generator expressions
120 ///////////////////////////////////////////////////////////////////////////////
121 std::ostream& operator << (std::ostream& f, Generators b)
122 {  match while (b)
123    {  #[one]:     { f << one; b = #[]; }
124    |  #[h ... t]: { f << h << ", "; b = t; }
125    }
126    return f;