← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba

 

Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.

Commit message:
cosmetic changes in printout of expr graph

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/132036

cosmetic changes in printout of expr graph
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/132036
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/expression/expr_put.cpp'
--- src/compiler/expression/expr_put.cpp	2012-10-26 07:13:42 +0000
+++ src/compiler/expression/expr_put.cpp	2012-10-30 10:06:25 +0000
@@ -54,42 +54,38 @@
 namespace zorba
 {
 
-#define BEGIN_PUT_NO_LOCATION(LABEL) \
-  os << indent << #LABEL << expr_addr(this) << " [\n" << inc_indent
-
-#define BEGIN_PUT(LABEL) \
-  os << indent << #LABEL << expr_addr(this) \
-     << expr_loc(dynamic_cast<const expr*>(this)) << " [\n" << inc_indent
-
-#define BEGIN_PUT2(STRING) \
-  os << indent << STRING << expr_addr(this) \
-     << expr_loc(dynamic_cast<const expr*>(this)) << " [\n" << inc_indent
-
-#define BEGIN_PUT_NO_EOL(LABEL) \
-  os << indent << #LABEL << expr_addr(this) \
-     << expr_loc(dynamic_cast<const expr*>(this)) << " [ "
-
-#define BEGIN_PUT1(LABEL,S1) \
-  os << indent << #LABEL << ' ' << (S1) << expr_addr(this) \
-     << expr_loc(dynamic_cast<const expr*>(this)) << " [\n" << inc_indent
+#define BEGIN_PUT(LABEL)                          \
+  os << indent << #LABEL << expr_addr(this)       \
+  << " [\n" << inc_indent
+
+#define BEGIN_PUT_NL(LABEL)                       \
+  os << indent << #LABEL << expr_addr(this)       \
+  << std::endl << indent << "[\n" << inc_indent
+
+#define BEGIN_PUT_MSG(MSG)                        \
+  os << indent << MSG << expr_addr(this)          \
+  << " [\n" << inc_indent
+
+#define BEGIN_PUT_NO_EOL(LABEL)                   \
+  os << indent << #LABEL << expr_addr(this)       \
+  << " [ "
 
 #define END_PUT() \
   os << dec_indent << indent << "]\n"; return os;
 
-#define PUT_SUB( LABEL, EXPR ) \
-  if ( !(EXPR) ) ; else { os << indent << (LABEL) << "\n" << inc_indent; (EXPR)->put(os); os << dec_indent; }
-
-
-static inline zstring qname_to_string(store::Item_t qname)
-{
-  zstring result;
-  zstring pfx = qname->getPrefix();
-  zstring ns = qname->getNamespace();
-  if (! ns.empty())
-    result += pfx.str() + "[=" + ns.str() + "]:";
-  result += qname->getLocalName().str();
-  return result;
-}
+#define END_PUT_NO_RET() \
+  os << dec_indent << indent << "]\n";
+
+
+#define PUT_SUB( LABEL, EXPR )                     \
+  if ( !(EXPR) )                                   \
+    ;                                              \
+  else                                             \
+  {                                                \
+    os << indent << (LABEL) << "\n" << inc_indent; \
+    (EXPR)->put(os);                               \
+    os << dec_indent;                              \
+  }
 
 
 static inline ostream& put_qname(store::Item_t qname, ostream& os)
@@ -105,7 +101,7 @@
 
 static inline string expr_addr(const void* e)
 {
-  if (Properties::instance()->noTreeIds ())
+  if (Properties::instance()->noTreeIds())
   {
     return "";
   }
@@ -150,15 +146,11 @@
 std::ostream&
 wrapper_expr::put(std::ostream& os) const
 {
-#ifdef VERBOSE
-  get_expr()->put(os);
-  return os;
-#else
   if (get_input()->get_expr_kind() == var_expr_kind)
   {
     const var_expr* varExpr = static_cast<const var_expr*>(get_input());
 
-    BEGIN_PUT_NO_EOL(var_ref) ;
+    BEGIN_PUT_NO_EOL(vref) ;
     put_qname(varExpr->get_name(), os);
     os << expr_addr(varExpr) << " ]" << endl;
     return os;
@@ -169,21 +161,24 @@
     get_input()->put(os);
     END_PUT();
   }
-#endif
 }
 
 ostream& block_expr::put( ostream& os) const
 {
-  BEGIN_PUT( block_expr );
-  for (checked_vector<expr*>::const_iterator i = this->theArgs.begin ();
-       i != theArgs.end (); i++)
-    (*i)->put (os);
+  BEGIN_PUT_NL(block_expr);
+
+  checked_vector<expr*>::const_iterator i = this->theArgs.begin();
+
+  for (; i != theArgs.end(); i++)
+    (*i)->put(os);
+
   END_PUT();
 }
 
+
 ostream& var_expr::put(ostream& os) const
 {
-  os << indent << "var kind=" << decode_var_kind(get_kind()) << expr_addr(this);
+  os << indent << "var " << decode_var_kind(get_kind()) << expr_addr(this);
   if (theName != NULL)
   {
     os << " name=";
@@ -193,7 +188,7 @@
 #if VERBOSE
   if (theDeclaredType != NULL)
   {
-    os << " type=" << theDeclaredType->toString();
+    os << " type=" << theDeclaredType->toSchemaString();
   }
 #endif
 
@@ -202,7 +197,7 @@
 }
 
 
-ostream& for_clause::put(ostream& os) const
+ostream& forlet_clause::put(ostream& os) const
 {
   if (theKind == flwor_clause::for_clause)
   {
@@ -238,7 +233,7 @@
 
 ostream& window_clause::put(ostream& os) const
 {
-  BEGIN_PUT(WINDOW);
+  BEGIN_PUT_NL(WINDOW);
   theVarExpr->put(os);
   PUT_SUB("IN", theDomainExpr);
   PUT_SUB("START", theWinStartCond);
@@ -249,7 +244,7 @@
 
 ostream& flwor_wincond::vars::put(ostream& os) const
 {
-  BEGIN_PUT_NO_LOCATION( flwor_wincond::vars );
+  BEGIN_PUT(flwor_wincond::vars);
   PUT_SUB( "AT", posvar );
   PUT_SUB( "CURR", curr );
   PUT_SUB( "NEXT", next );
@@ -259,7 +254,7 @@
 
 ostream& flwor_wincond::put(ostream& os) const
 {
-  BEGIN_PUT_NO_LOCATION(flwor_wincond);
+  BEGIN_PUT(flwor_wincond);
   PUT_SUB("IN-VARS", &get_in_vars());
   PUT_SUB("OUT-VARS", &get_out_vars());
   PUT_SUB("WHEN", theCondExpr);
@@ -269,9 +264,7 @@
 
 ostream& group_clause::put(ostream& os) const
 {
-  os << indent << "GROUP-BY" << expr_addr(this) << " ";
-
-  os << endl << indent << "[\n" << inc_indent;
+  BEGIN_PUT_NL(GROUPBY);
 
   os << indent << "GROUPING SPECS";
 
@@ -304,9 +297,7 @@
 
 ostream& orderby_clause::put(ostream& os) const
 {
-  BEGIN_PUT(orderby_clause);
-
-  //os << indent << "ORDER BY ";
+  BEGIN_PUT_NL(ORDERBY);
 
   csize numColumns = num_columns();
 
@@ -314,34 +305,21 @@
   {
     theOrderingExprs[i]->put(os);
   }
-#if 0
-  os << endl;
 
-  os << indent << "VAR REBINDS ";
-  for (unsigned i = 0; i < theRebindList.size (); i++)
-  {
-    os << "$";
-    put_qname(theRebindList[i].first->get_varname(), os);
-    os << " (" << theRebindList[i].first << " -> "
-       << theRebindList[i].second << ") ";
-  }
-  os << endl;
-#endif
   END_PUT();
 }
 
 
 ostream& materialize_clause::put(ostream& os) const
 {
-  BEGIN_PUT(materialize_clause);
-
+  BEGIN_PUT_NL(MATERIALIZE);
   END_PUT();
 }
 
 
 ostream& flwor_expr::put(ostream& os) const
 {
-  BEGIN_PUT(flwor_expr);
+  BEGIN_PUT_NL(flwor_expr);
 
   for (csize i = 0; i < num_clauses(); i++)
   {
@@ -351,7 +329,9 @@
     {
     case flwor_clause::where_clause:
     {
-      PUT_SUB( "WHERE", static_cast<const where_clause *>(&c)->get_expr() );
+      BEGIN_PUT_NL(WHERE);
+      static_cast<const where_clause *>(&c)->get_expr()->put(os);
+      END_PUT_NO_RET();
       break;
     }
     case flwor_clause::count_clause:
@@ -362,13 +342,9 @@
       break;
     }
     case flwor_clause::for_clause:
-    {
-      static_cast<const for_clause *>(&c)->put(os);
-      break;
-    }
     case flwor_clause::let_clause:
     {
-      static_cast<const let_clause *>(&c)->put(os);
+      static_cast<const forlet_clause *>(&c)->put(os);
       break;
     }
     case flwor_clause::window_clause:
@@ -398,7 +374,7 @@
     }
   }
 
-  os << indent << "RETURN\n" << inc_indent;
+  BEGIN_PUT_NL(RETURN);
   if (theReturnExpr == NULL)
   {
     os << indent << "NULL";
@@ -407,7 +383,8 @@
   {
     theReturnExpr->put(os);
   }
-  os << dec_indent;
+  END_PUT_NO_RET();
+
   END_PUT();
 }
 
@@ -505,10 +482,16 @@
 
 ostream& if_expr::put(ostream& os) const
 {
-  BEGIN_PUT(if_expr);
+  BEGIN_PUT_NL(if_expr);
+
   theCondExpr->put(os);
-  PUT_SUB("THEN", theThenExpr);
-  PUT_SUB("ELSE", theElseExpr);
+
+  os << indent << "THEN" << std::endl;
+  theThenExpr->put(os);
+
+  os << indent << "ELSE" << std::endl;
+  theElseExpr->put(os);
+
   END_PUT();
 }
 
@@ -516,12 +499,12 @@
 ostream& fo_expr::put(ostream& os) const
 {
   const store::Item* qname = theFunction->getName();
-  BEGIN_PUT2( qname->getStringValue() << "/" << num_args() );
-  csize numArgs = theArgs.size();
+  BEGIN_PUT_MSG( qname->getStringValue() << "/" << num_args() );
+  csize numArgs = num_args();
 
   for (csize i = 0; i < numArgs; ++i)
   {
-    theArgs[i]->put(os);
+    get_arg(i)->put(os);
   }
 
   END_PUT();
@@ -565,7 +548,7 @@
 
   theExpr->put(os);
 
-  for (ulong i = 0; i < theArgs.size(); ++i)
+  for (csize i = 0; i < theArgs.size(); ++i)
     theArgs[i]->put(os);
 
   END_PUT();
@@ -574,35 +557,35 @@
 
 ostream& instanceof_expr::put( ostream& os) const
 {
-  BEGIN_PUT1( instanceof_expr, theTargetType->toString() );
-  theInput->put(os);
-  END_PUT();
-}
-
-ostream& treat_expr::put( ostream& os) const
-{
-  BEGIN_PUT1( treat_expr, theTargetType->toString() );
-  theInput->put(os);
-  END_PUT();
-}
-
-ostream& castable_expr::put( ostream& os) const
-{
-  BEGIN_PUT1( castable_expr, theTargetType->toString() );
-  theInput->put(os);
-  END_PUT();
-}
-
-ostream& cast_expr::put( ostream& os) const
-{
-  BEGIN_PUT1( cast_expr, theTargetType->toString() );
-  theInput->put(os);
-  END_PUT();
-}
-
-ostream& name_cast_expr::put( ostream& os) const
-{
-  BEGIN_PUT( name_cast_expr );
+  BEGIN_PUT_MSG("instanceof_expr " << theTargetType->toSchemaString());
+  theInput->put(os);
+  END_PUT();
+}
+
+ostream& treat_expr::put(ostream& os) const
+{
+  BEGIN_PUT_MSG("treat_expr " << theTargetType->toSchemaString());
+  theInput->put(os);
+  END_PUT();
+}
+
+ostream& castable_expr::put(ostream& os) const
+{
+  BEGIN_PUT_MSG("castable_expr " << theTargetType->toSchemaString());
+  theInput->put(os);
+  END_PUT();
+}
+
+ostream& cast_expr::put(ostream& os) const
+{
+  BEGIN_PUT_MSG("cast_expr " << theTargetType->toSchemaString());
+  theInput->put(os);
+  END_PUT();
+}
+
+ostream& name_cast_expr::put(ostream& os) const
+{
+  BEGIN_PUT(name_cast_expr);
   theInputExpr->put(os);
   END_PUT();
 }
@@ -610,7 +593,7 @@
 
 ostream& validate_expr::put(ostream& os) const
 {
-  BEGIN_PUT( validate_expr );
+  BEGIN_PUT(validate_expr);
 
   switch (theMode)
   {
@@ -755,15 +738,15 @@
 
 ostream& const_expr::put(ostream& os) const
 {
-  BEGIN_PUT_NO_EOL( const_expr );
+  BEGIN_PUT_NO_EOL(const_expr);
+
   if (theValue->isFunction())
   {
     os << "functrion item [ " << theValue->show() << " ]";
   }
   else
   {
-    os << get_val()->getType()->getStringValue()
-       << " [ " << theValue->show() << " ]";
+    os << " " << theValue->show();
   }
   os << " ]\n";
   return os;
@@ -772,8 +755,7 @@
 
 ostream& order_expr::put(ostream& os) const
 {
-  os << indent << "order_expr" << expr_addr(this) << "\n" << inc_indent
-     << indent << "[ ";
+  BEGIN_PUT(order_expr);
 
   switch (theType)
   {
@@ -782,6 +764,7 @@
   default: os << "??\n";
   }
   theInput->put(os) << endl;
+
   END_PUT();
 }
 
@@ -915,7 +898,7 @@
 
 ostream& copy_clause::put(ostream& os) const
 {
-  BEGIN_PUT_NO_LOCATION(copy);
+  BEGIN_PUT(copy);
   theVar->put(os);
   theExpr->put(os);
   END_PUT();


Follow ups