~zorba-coders/zorba/bugs-912586-912593-912722

« back to all changes in this revision

Viewing changes to src/compiler/rewriter/tools/dataflow_annotations.cpp

  • Committer: Cezar Andrei
  • Date: 2012-03-28 15:42:12 UTC
  • mfrom: (10606.1.129 zorba)
  • Revision ID: cezar.lp@cezarandrei.com-20120328154212-jh2heq49xcqjppce
Merge from trunck and resolve ChangeLog conflict.

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
  case pi_expr_kind:
216
216
    compute_pi_expr(static_cast<pi_expr *>(e));
217
217
    break;
 
218
 
 
219
#ifdef ZORBA_WITH_JSON
 
220
  case json_pair_expr_kind:
 
221
  case json_object_expr_kind:
 
222
  case json_array_expr_kind:
 
223
  {
 
224
    default_walk(e);
 
225
    SORTED_NODES(e);
 
226
    DISTINCT_NODES(e);
 
227
  }
 
228
#endif
218
229
    
219
230
  case dynamic_function_invocation_expr_kind: // TODO
220
231
  case function_item_expr_kind: // TODO
266
277
bool DataflowAnnotationsComputer::generic_compute(expr* e)
267
278
{
268
279
  xqtref_t rt = e->get_return_type();
269
 
  TypeConstants::quantifier_t quant = TypeOps::quantifier(*rt);
 
280
  TypeConstants::quantifier_t quant = rt->get_quantifier();
270
281
 
271
282
  if (quant == TypeConstants::QUANT_ONE || quant == TypeConstants::QUANT_QUESTION) 
272
283
  {
617
628
  {
618
629
    TypeManager* tm = e->get_type_manager();
619
630
 
620
 
    ulong num_steps = (ulong)e->size();
 
631
    csize num_steps = e->size();
621
632
    bool only_child_axes = true;
622
633
    ulong num_desc_axes = 0;
623
634
    ulong num_following_axes = 0;
624
635
    bool reverse_axes = false;
625
636
 
626
 
    for (ulong i = 1; i < num_steps; ++i) 
 
637
    for (csize i = 1; i < num_steps; ++i) 
627
638
    {
628
639
      axis_step_expr* ase = dynamic_cast<axis_step_expr *>((*e)[i]);
629
640
      assert(ase != NULL);
774
785
 
775
786
SourceFinder::~SourceFinder()
776
787
{
777
 
  UdfSourcesMap::iterator ite = theUdfSourcesMap.begin();
778
 
  UdfSourcesMap::iterator end = theUdfSourcesMap.end();
779
 
  for (; ite != end; ++ite)
780
 
  {
781
 
    delete ite->second;
 
788
  UdfSourcesMap::iterator ite1 = theUdfSourcesMap.begin();
 
789
  UdfSourcesMap::iterator end1 = theUdfSourcesMap.end();
 
790
  for (; ite1 != end1; ++ite1)
 
791
  {
 
792
    delete ite1->second;
 
793
  }
 
794
 
 
795
  VarSourcesMap::iterator ite2 = theVarSourcesMap.begin();
 
796
  VarSourcesMap::iterator end2 = theVarSourcesMap.end();
 
797
  for (; ite2 != end2; ++ite2)
 
798
  {
 
799
    delete ite2->second;
782
800
  }
783
801
}
784
802
 
795
813
    UDFCallChain* udfCaller,
796
814
    std::vector<expr*>& sources)
797
815
{
 
816
  theStartingUdf = NULL;
 
817
 
 
818
  if (udfCaller->theFo)
 
819
    theStartingUdf = static_cast<user_function*>(udfCaller->theFo->get_func());
 
820
 
798
821
  findNodeSourcesRec(node, sources, NULL);
799
822
 
800
823
  for (csize i = 0; i < sources.size(); ++i)
829
852
    {
830
853
      ZORBA_ASSERT(source->get_expr_kind() == doc_expr_kind ||
831
854
                   source->get_expr_kind() == elem_expr_kind);
 
855
 
 
856
      user_function* udf = theSourceUdfMap.find(source)->second;
 
857
 
 
858
      if (udf)
 
859
        udf->invalidatePlan();
832
860
    }
833
861
  }
834
862
}
835
863
 
836
864
 
 
865
/*******************************************************************************
 
866
 
 
867
********************************************************************************/
837
868
void SourceFinder::findNodeSourcesRec(
838
869
    expr* node,
839
870
    std::vector<expr*>& sources,
870
901
    {
871
902
      VarSourcesMap::iterator ite = theVarSourcesMap.find(e);
872
903
 
 
904
      std::vector<expr*>* varSources;
 
905
 
873
906
      if (ite == theVarSourcesMap.end())
874
907
      {
875
 
        std::vector<expr*> varSources;
876
 
        findNodeSourcesRec(e->get_domain_expr(), varSources, currentUdf);
877
 
 
878
 
        ite = (theVarSourcesMap.insert(VarSourcesPair(e, varSources))).first;
879
 
      }
880
 
 
881
 
      std::vector<expr*>::iterator ite2 = (*ite).second.begin();
882
 
      std::vector<expr*>::iterator end2 = (*ite).second.end();
 
908
        varSources = new std::vector<expr*>;
 
909
        theVarSourcesMap.insert(VarSourcesPair(e, varSources));
 
910
 
 
911
        findNodeSourcesRec(e->get_domain_expr(), *varSources, currentUdf);
 
912
      }
 
913
      else
 
914
      {
 
915
        varSources = (*ite).second;
 
916
      }
 
917
 
 
918
      std::vector<expr*>::const_iterator ite2 = (*varSources).begin();
 
919
      std::vector<expr*>::const_iterator end2 = (*varSources).end();
883
920
      for (; ite2 != end2; ++ite2)
884
921
      {
885
922
        if (std::find(sources.begin(), sources.end(), *ite2) == sources.end())
911
948
      if (std::find(sources.begin(), sources.end(), node) == sources.end())
912
949
        sources.push_back(node);
913
950
 
 
951
      std::vector<expr*>* varSources = new std::vector<expr*>;
 
952
      if (theVarSourcesMap.insert(VarSourcesPair(e, varSources)).second == false)
 
953
        delete varSources;
 
954
 
914
955
      return;
915
956
    }
916
957
 
919
960
    {
920
961
      VarSourcesMap::iterator ite = theVarSourcesMap.find(e);
921
962
 
 
963
      std::vector<expr*>* varSources;
 
964
 
922
965
      if (ite == theVarSourcesMap.end())
923
966
      {
924
 
        std::vector<expr*> varSources;
 
967
        varSources = new std::vector<expr*>;;
925
968
        theVarSourcesMap.insert(VarSourcesPair(e, varSources));
926
969
 
927
970
        std::vector<expr*>::const_iterator ite2 = e->setExprsBegin();
934
977
          if (setExpr->get_expr_kind() == var_decl_expr_kind)
935
978
          {
936
979
            findNodeSourcesRec(static_cast<var_decl_expr*>(setExpr)->get_init_expr(),
937
 
                               varSources,
 
980
                               *varSources,
938
981
                               currentUdf);
939
982
          }
940
983
          else
942
985
            assert(setExpr->get_expr_kind() == var_set_expr_kind);
943
986
 
944
987
            findNodeSourcesRec(static_cast<var_set_expr*>(setExpr)->get_expr(),
945
 
                               varSources,
 
988
                               *varSources,
946
989
                               currentUdf);
947
990
          }
948
991
        }
949
 
 
950
 
        ite = theVarSourcesMap.find(e);
951
 
        
952
 
        (*ite).second.insert((*ite).second.end(), varSources.begin(), varSources.end());
953
 
      }
954
 
 
955
 
      sources.insert(sources.end(), (*ite).second.begin(), (*ite).second.end());
 
992
      }
 
993
      else
 
994
      {
 
995
        varSources = (*ite).second;
 
996
      }
 
997
 
 
998
      std::vector<expr*>::const_iterator ite2 = (*varSources).begin();
 
999
      std::vector<expr*>::const_iterator end2 = (*varSources).end();
 
1000
      for (; ite2 != end2; ++ite2)
 
1001
      {
 
1002
        if (std::find(sources.begin(), sources.end(), *ite2) == sources.end())
 
1003
          sources.push_back(*ite2);
 
1004
      }
956
1005
 
957
1006
      return;
958
1007
    }
979
1028
  case elem_expr_kind:
980
1029
  {
981
1030
    if (std::find(sources.begin(), sources.end(), node) == sources.end())
 
1031
    {
982
1032
      sources.push_back(node);
983
1033
 
 
1034
      theSourceUdfMap.
 
1035
      insert(SourceUdfMapPair(node, (currentUdf ? currentUdf : theStartingUdf)));
 
1036
    }
 
1037
 
984
1038
    std::vector<expr*> enclosedExprs;
985
1039
    node->get_fo_exprs_of_kind(FunctionConsts::OP_ENCLOSED_1, false, enclosedExprs);
986
1040