Polaris: expr_test.cc Source File

expr_test.cc

Go to the documentation of this file.
00001 #include "../cvdl.h"
00002 ///
00003 int main(int argc, char *argv[])
00004 {
00005 ///     IntConstExpr    e;
00006 /// 
00007 ///     e.value(5);
00008 ///     cout << e << endl;
00009 ///     BinaryExpr      b(SUB_OP, INTEGER_TYPE);
00010 /// 
00011 ///     b.left(e);
00012 ///     e.value(6);
00013 ///     b.right(e);
00014 ///     cout << b << endl;      /// ...  5- 6
00015 /// 
00016 ///     Expression     *c = b.clone();
00017 ///     BinaryExpr      b2(b);
00018 /// 
00019 ///     b2.left(b);         /// ...  (5 -6) - 6
00020 /// 
00021 ///     cout << b2 << endl;
00022 ///     b = b2;
00023 ///     cout << b << endl;
00024 ///     cout << *c << endl;
00025 ///     UnaryExpr       e1(U_MINUS_OP, INTEGER_TYPE);
00026 ///     BinaryExpr      e2(EXP_OP, INTEGER_TYPE);
00027 ///     BinaryExpr      e3(DIV_OP, INTEGER_TYPE);
00028 /// 
00029 ///     e3.left(*c);
00030 ///     e3.right(*c);
00031 ///     e2.right(*c);
00032 ///     e2.left(e3);
00033 ///     e1.expr_guarded(e2);
00034 ///     cout << e1 << endl;
00035 /// 
00036     BinStr bin;                                        /// ...  Make empty binstr    
00037     bin.read("/groups/polaris/work/cvdl/base/test/binstrings/TIS.olda.bs"); /// ...  Read binstr          
00038 ///
00039     ProgramUnit pgm("PGM1", bin);                      /// ...  binstr -> pgm        
00040 ///
00041     cout << "Expression construction functions:" << endl;
00042 ///
00043     Expression *new_e, *new_e2, *new_e3, *new_e4;
00044 ///
00045     new_e = add(constant(1), constant(1));
00046     cout << *new_e ;
00047     new_e = simplify(new_e);
00048     cout << " -> " << *new_e << endl;
00049     new_e = sub(constant("1.0"),add(constant(1), constant("1.0d0")));
00050     cout << *new_e ;
00051     new_e = simplify(new_e);
00052     cout << " -> " << *new_e << endl;
00053 ///
00054     new_e = id("NUM", pgm);
00055     cout << *new_e << endl;
00056     new_e2 = eq(add(constant(1), new_e), mul(constant("2.0"), new_e->clone()));
00057     cout << *new_e2 << endl;
00058 ///
00059     new_e = not(eq(add(constant(1), id("NUM", pgm)), mul(constant("2.0"), unary_minus(id("NUM", pgm)))));
00060     cout << *new_e << endl;
00061 ///
00062     new_e = and(constant(".true."), constant(".false."));
00063     cout << *new_e << endl;
00064 ///
00065     new_e = add(new_variable("XXQQ10", make_type(INTEGER_TYPE,4), pgm),constant(2));
00066     cout << *new_e << endl;
00067 ///
00068     new_e = new_array_variable("YYQQ10",
00069                    make_type(INTEGER_TYPE, 4),
00070                    pgm,
00071                    colon(constant(1),constant(10)));
00072     cout << *new_e << endl;
00073 ///
00074     new_e = new_array_variable( "YYQQ20", make_type(REAL_TYPE, 8),
00075                 pgm,
00076                 colon(constant(1),constant(10)),
00077                 colon(constant(1),constant(100)) );
00078     cout << *new_e << endl;
00079 ///
00080     new_e = new_function("addup", make_type(REAL_TYPE, 8), pgm);
00081     new_e2 = function_call(new_e,
00082                comma(constant(6),
00083                  add(id("NUM",pgm),constant(1)),
00084                  exponent(id("NUM", pgm),constant(2))));
00085     cout << *new_e2 << endl;
00086 ///
00087     new_e = div(id("NUM",pgm),paren(add(constant(10),id("NUM",pgm))));
00088     cout << *new_e << endl;
00089 ///
00090     new_e = concat(constant("'hi there'"),constant("'how''re ya doin''?'"));
00091     cout << *new_e << endl;
00092 ///
00093     /// ...  Check out the is_constant routines:
00094 ///
00095     new_e = constant("17.7");
00096     if (is_integer_constant(*new_e)) 
00097     cout << "ERROR: system thinks " << *new_e << " is an integer constant" << endl;
00098     else
00099     cout << "OK: system knows that " << *new_e << " is not an integer constant" << endl;
00100 ///
00101     new_e = constant(5);
00102     if (is_integer_constant(*new_e))
00103     cout << "OK: system knows that " << *new_e << " is an integer constant" << endl;
00104     else
00105     cout << "ERROR: system thinks " << *new_e << " is not an integer constant" << endl;
00106 ///
00107     if (is_integer_zero(*new_e))
00108     cout << "ERROR: system thinks " << *new_e << " is an integer zero" << endl;
00109     else
00110     cout << "OK: system knows that " << *new_e << " is not an integer zero" << endl;
00111 ///
00112     new_e = constant (0);
00113     if (is_integer_zero(*new_e))
00114     cout << "OK: system knows that " << *new_e << " is an integer zero" << endl;
00115     else
00116     cout << "ERROR: system thinks " << *new_e << " is not an integer zero" << endl;
00117 ///
00118     /// ...  Make a list for the comma function
00119 ///
00120 ///    List<Expression> elist;
00121 ///
00122 ///    elist.ins(new_e, 0);
00123 ///    new_e2 = sub(id("NUM", pgm), constant(36));
00124 ///    elist.ins(new_e2, 1);
00125 ///    new_e3 = complex(constant("1.414"), constant("3.14"));
00126 ///    elist.ins(new_e3, 2);
00127 ///    new_e4 = comma(elist);
00128 ///
00129 ///    cout << "CommaExpr: " << *new_e4 << endl;
00130 ///
00131     /// ...  Check out iterate_expressions
00132 ///
00133     Iterator<Statement> li = pgm.iterate_block(pgm.first_stmt_ref(),
00134                            pgm.last_stmt_ref());
00135 ///
00136     for (li.reset(); li.valid(); ++li) {
00137 ///
00138     li.current().fortran_write(cout,0);
00139     cout << endl;
00140 ///
00141     int i = 0;
00142 ///
00143     for (Iterator<Expression> iter=li.current().iterate_expressions();
00144          iter.valid();
00145          ++iter)
00146         {
00147         if (iter.current_valid()) {
00148             cout << "Expression " << i++ << ": " << iter.current() << endl;
00149             cout << endl;
00150         }
00151         }
00152     }
00153 };
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:05:47 2005