Example #1
0
void PrinterVisitor::beginVisit( CtxVarIterator const &i ) {
  thePrinter.startBeginVisit( "CtxVarIterator", ++theId );
  thePrinter.addAttribute( "varid", i.getVarId() );
  thePrinter.addAttribute( "varname", i.getVarName()->getStringValue().str() );
  thePrinter.addAttribute( "varkind", i.isLocal() ? "local" : "global" );
  printCommons( &i, theId );
  thePrinter.endBeginVisit( theId );
}
void PrinterVisitor::beginVisit( CtxVarIterator const &i ) {
  thePrinter.startBeginVisit( "CtxVarIterator", ++theId );
  thePrinter.addIntAttribute( "varid", i.getVarId() );
#ifndef NDEBUG
  if ( !Properties::instance().getNoTreeIDs() &&
       Properties::instance().getStableIteratorIDs() )
    thePrinter.addIntAttribute( "varreference", i.getId() );
#endif
  thePrinter.addAttribute( "varname", i.getVarName()->getStringValue().str() );
  thePrinter.addAttribute( "varkind", i.isLocal() ? "local" : "global" );
  printCommons( &i, theId );
  thePrinter.endBeginVisit( theId );
}
Example #3
0
PlanIter_t op_zorba_sequence_point_access::codegen(
    CompilerCB* /*cb*/,
    static_context* aSctx,
    const QueryLoc& aLoc,
    std::vector<PlanIter_t>& aArgs,
    expr& aAnn) const
{
  fo_expr& subseqExpr = static_cast<fo_expr&>(aAnn);

  const expr* inputExpr = subseqExpr.get_arg(0);

  const expr* posExpr = subseqExpr.get_arg(1);

  LetVarIterator* inputVarIter;
  CtxVarIterator* ctxVarIter;

  if (posExpr->get_expr_kind() == const_expr_kind)
  {
    store::Item* posItem = static_cast<const const_expr*>(posExpr)->get_val();

    xs_integer pos( posItem->getIntegerValue() );

    if (inputExpr->get_expr_kind() == relpath_expr_kind)
    {
      const relpath_expr* pathExpr = static_cast<const relpath_expr*>(inputExpr);

      csize numSteps = pathExpr->numSteps();

      if (pos.sign() > 0 && numSteps == 2)
      {
        xs_long pos2;
        try
        {
          pos2 = posItem->getLongValue();
        }
        catch (std::range_error const&)
        {
          goto done;
        }

        AxisIteratorHelper* input = dynamic_cast<AxisIteratorHelper*>(aArgs[0].getp());
        assert(input != NULL);

        
        if (input->setTargetPos(pos2 - 1))
          return aArgs[0];
        
      }
    }
    else if ((inputVarIter = dynamic_cast<LetVarIterator*>(aArgs[0].getp())) != NULL)
    {
      const var_expr* inputVar = inputExpr->get_var();

      if (inputVar != NULL &&
          (inputVar->get_kind() == var_expr::let_var ||
           inputVar->get_kind() == var_expr::win_var ||
           inputVar->get_kind() == var_expr::non_groupby_var) &&
          inputVarIter->setTargetPos(pos))
      {
        return aArgs[0];
      }
    }
    else if ((ctxVarIter = dynamic_cast<CtxVarIterator*>(aArgs[0].getp())) != NULL)
    {
      if (ctxVarIter->setTargetPos(pos))
        return aArgs[0];
    }
  }
  else if ((inputVarIter = dynamic_cast<LetVarIterator*>(aArgs[0].getp())) != NULL)
  {
    const var_expr* inputVar = inputExpr->get_var();

    if (inputVar != NULL &&
        (inputVar->get_kind() == var_expr::let_var ||
         inputVar->get_kind() == var_expr::win_var ||
         inputVar->get_kind() == var_expr::non_groupby_var) &&
        inputVarIter->setTargetPosIter(aArgs[1]))
    {
      return aArgs[0];
    }
  }
  else if ((ctxVarIter = dynamic_cast<CtxVarIterator*>(aArgs[0].getp())) != NULL)
  {
    if (ctxVarIter->setTargetPosIter(aArgs[1]))
      return aArgs[0];
  }

 done:
  return new SequencePointAccessIterator(aSctx, aLoc, aArgs);
}