~zorba-coders/zorba/trunk

« back to all changes in this revision

Viewing changes to src/compiler/rewriter/rules/index_matching_rule.cpp

  • Committer: Zorba Build Bot
  • Author(s): markos_za at yahoo
  • Date: 2013-05-04 21:54:40 UTC
  • mfrom: (10900.1.197 markos-scratch)
  • Revision ID: chillery+buildbot@lambda.nu-20130504215440-1486xtg6g7wy522h
Apply count optimization after index matching. Approved: Markos Zaharioudakis

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
  RewriteRule(RewriteRule::IndexJoin, "IndexJoin"),
82
82
  theIndexDecl(decl),
83
83
  theViewExpr(NULL),
84
 
  theDoTrace(true)
 
84
  theDoTrace(true),
 
85
  theParentNode(NULL)
85
86
{
86
87
  theViewExpr = decl->getViewExpr();
87
88
 
121
122
********************************************************************************/
122
123
expr* IndexMatchingRule::apply(RewriterContext& rCtx, expr* node, bool& modified)
123
124
{
 
125
  expr* result = node;
124
126
  modified = false;
125
127
 
126
128
  // TODO remove this
135
137
    bool matched = matchIndex();
136
138
 
137
139
    if (matched)
 
140
    {
138
141
      modified = true;
 
142
 
 
143
      flwor_expr* flwor = static_cast<flwor_expr*>(node);
 
144
 
 
145
      if (flwor->get_return_expr()->get_expr_kind() == const_expr_kind &&
 
146
          theParentNode != NULL &&
 
147
          theParentNode->get_expr_kind() == fo_expr_kind)
 
148
      {
 
149
        fo_expr* pnode = static_cast<fo_expr*>(theParentNode);
 
150
 
 
151
        if (pnode->get_func() == BUILTIN_FUNC(FN_COUNT_1) ||
 
152
            pnode->get_func() == BUILTIN_FUNC(FN_EMPTY_1) ||
 
153
            pnode->get_func() == BUILTIN_FUNC(FN_EXISTS_1))
 
154
        {
 
155
          csize pos;
 
156
          if (flwor->is_single_for(pos))
 
157
          {
 
158
            for_clause* fc = static_cast<for_clause*>(flwor->get_clause(pos));
 
159
          
 
160
            result = fc->get_expr();
 
161
          }
 
162
        }
 
163
      }
 
164
    }
139
165
  }
140
166
 
141
167
  ExprIterator iter(node);
145
171
 
146
172
    bool childModified = false;
147
173
 
 
174
    theParentNode = node;
 
175
 
148
176
    expr* newChild = apply(rCtx, currChild, childModified);
149
177
 
150
 
    ZORBA_ASSERT(currChild == newChild);
 
178
    if (currChild != newChild)
 
179
      **iter = newChild;
151
180
 
152
181
    if (childModified)
153
182
      modified = true;
155
184
    iter.next();
156
185
  }
157
186
 
158
 
  return node;
 
187
  return result;
159
188
}
160
189
 
161
190