~zorba-coders/zorba/no-copy

« back to all changes in this revision

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

  • Committer: Markos Zaharioudakis
  • Date: 2012-10-03 13:24:49 UTC
  • Revision ID: markos_za@yahoo.com-20121003132449-8rrc8a7iny783cji
the target expr of insert and rename exprs is unsafe only if it returns a shared node

Show diffs side-by-side

added added

removed removed

Lines of Context:
870
870
  case replace_expr_kind:
871
871
  {
872
872
    update_expr_base* e = static_cast<update_expr_base*>(node);
 
873
    expr_kind_t kind = e->get_expr_kind();
873
874
 
874
 
    std::vector<expr*> sources;
875
 
    theSourceFinder->findNodeSources(e->getTargetExpr(), &udfCaller, sources);
876
 
    markSources(sources);
 
875
    // The target node cannot be a shared node because the update would be seen
 
876
    // by multiple trees. For updates that delete nodes (delete and replace), the
 
877
    // whole tree must be standalone because we have to sum up the reference
 
878
    // counts of all the nodes in the delete subtree and that won't work if the
 
879
    // deleted subtree contains shared nodes.
 
880
    if (kind == replace_expr_kind || kind == delete_expr_kind)
 
881
    {
 
882
      std::vector<expr*> sources;
 
883
      theSourceFinder->findNodeSources(e->getTargetExpr(), &udfCaller, sources);
 
884
      markSources(sources);
 
885
    }
 
886
    else
 
887
    {
 
888
      markInUnsafeContext(node);
 
889
    }
877
890
 
878
891
    static_context* sctx = e->get_sctx();
879
892
 
 
893
    // TODO: apply no-copy rule to insert and replace updates
880
894
    if (e->getSourceExpr() != NULL &&
881
 
        (e->get_expr_kind() == insert_expr_kind ||
882
 
         (e->get_expr_kind() == replace_expr_kind &&
 
895
        (kind == insert_expr_kind ||
 
896
         (kind == replace_expr_kind &&
883
897
          static_cast<replace_expr*>(e)->getType() == store::UpdateConsts::NODE)) &&
884
 
        (sctx->inherit_mode() != StaticContextConsts::no_inherit_ns ||
885
 
         sctx->preserve_mode() != StaticContextConsts::no_preserve_ns))
 
898
        (sctx->inherit_mode() == StaticContextConsts::inherit_ns &&
 
899
         sctx->preserve_mode() == StaticContextConsts::preserve_ns))
886
900
    {
887
901
      std::vector<expr*> sources;
888
902
      theSourceFinder->findNodeSources(e->getSourceExpr(), &udfCaller, sources);