~paul-lucas/zorba/bug-932374

« back to all changes in this revision

Viewing changes to src/runtime/booleans/BooleanImpl.cpp

  • Committer: Paul J. Lucas
  • Date: 2012-09-21 20:26:47 UTC
  • mfrom: (10819.2.235 zorba)
  • Revision ID: paul@lucasmail.org-20120921202647-fy9n4jduhrnljrnb
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
SERIALIZABLE_CLASS_VERSIONS(CompareIterator)
53
53
 
54
 
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(TypedValueCompareIterator, TypedValueCompareIterator<store::XS_DOUBLE>, 1)
55
 
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(TypedValueCompareIterator, TypedValueCompareIterator<store::XS_FLOAT>, 2)
56
 
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(TypedValueCompareIterator, TypedValueCompareIterator<store::XS_DECIMAL>, 3)
57
 
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(TypedValueCompareIterator, TypedValueCompareIterator<store::XS_INTEGER>, 4)
58
 
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(TypedValueCompareIterator, TypedValueCompareIterator<store::XS_STRING>, 5)
 
54
SERIALIZABLE_TEMPLATE_INSTANCE(TypedValueCompareIterator,
 
55
                               TypedValueCompareIterator<store::XS_DOUBLE>,
 
56
                               1)
 
57
 
 
58
SERIALIZABLE_TEMPLATE_INSTANCE(TypedValueCompareIterator,
 
59
                               TypedValueCompareIterator<store::XS_FLOAT>,
 
60
                               2)
 
61
 
 
62
SERIALIZABLE_TEMPLATE_INSTANCE(TypedValueCompareIterator,
 
63
                               TypedValueCompareIterator<store::XS_DECIMAL>,
 
64
                               3)
 
65
 
 
66
SERIALIZABLE_TEMPLATE_INSTANCE(TypedValueCompareIterator,
 
67
                               TypedValueCompareIterator<store::XS_INTEGER>,
 
68
                               4)
 
69
 
 
70
SERIALIZABLE_TEMPLATE_INSTANCE(TypedValueCompareIterator,
 
71
                               TypedValueCompareIterator<store::XS_STRING>,
 
72
                               5)
59
73
 
60
74
SERIALIZABLE_CLASS_VERSIONS(AtomicValuesEquivalenceIterator)
61
75
 
75
89
}
76
90
 
77
91
 
 
92
void FnBooleanIterator::serialize(::zorba::serialization::Archiver& ar)
 
93
{
 
94
  serialize_baseclass(ar,
 
95
  (UnaryBaseIterator<FnBooleanIterator, PlanIteratorState>*)this);
 
96
 
 
97
  ar & theNegate;
 
98
}
 
99
 
 
100
 
78
101
bool FnBooleanIterator::effectiveBooleanValue(
79
102
    const QueryLoc& loc,
80
103
    PlanState& planState,
97
120
    // node => true
98
121
    result = negate ^ true;
99
122
  }
 
123
#ifdef ZORBA_WITH_JSON
 
124
  else if (item->isJSONItem())
 
125
  {
 
126
    xqtref_t type = tm->create_value_type(item);
 
127
 
 
128
    RAISE_ERROR(err::FORG0006, loc,
 
129
    ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o), *type, "fn:boolean" ));
 
130
  }
 
131
#endif
100
132
  else
101
133
  {
102
134
    store::SchemaTypeCode type = item->getTypeCode();
110
142
         TypeOps::is_subtype(type, store::XS_STRING) ||
111
143
         TypeOps::is_subtype(type, store::XS_ANY_URI) ||
112
144
         type == store::XS_UNTYPED_ATOMIC ||
 
145
         type == store::JS_NULL ||
113
146
         TypeOps::is_numeric(type)))
114
147
    {
115
148
      // atomic type xs_boolean, xs_string, xs_anyURI, xs_untypedAtomic
299
332
}
300
333
 
301
334
 
 
335
CompareIterator::CompareIterator(::zorba::serialization::Archiver& ar)
 
336
  :
 
337
  BinaryBaseIterator<CompareIterator, PlanIteratorState>(ar),
 
338
  theTypeManager(NULL),
 
339
  theTimezone(0),
 
340
  theCollation(NULL)
 
341
{
 
342
}
 
343
 
 
344
 
 
345
void CompareIterator::serialize(::zorba::serialization::Archiver& ar)
 
346
{
 
347
  serialize_baseclass(ar,
 
348
  (BinaryBaseIterator<CompareIterator, PlanIteratorState>*)this);
 
349
 
 
350
  SERIALIZE_ENUM(CompareConsts::CompareType, theCompType)
 
351
  ar & theIsGeneralComparison;
 
352
  SERIALIZE_TYPEMANAGER(TypeManager, theTypeManager);
 
353
  ar & theTimezone;
 
354
  ar & theCollation;
 
355
}
 
356
 
 
357
 
302
358
BINARY_ACCEPT(CompareIterator);
303
359
 
304
360
 
432
488
    if (consumeNext(item0, theChild0.getp(), planState) &&
433
489
        consumeNext(item1, theChild1.getp(), planState))
434
490
    {
435
 
      STACK_PUSH(GENV_ITEMFACTORY->
436
 
                 createBoolean(result,
437
 
                               CompareIterator::valueComparison(loc,
438
 
                                                                item0,
439
 
                                                                item1,
440
 
                                                                theCompType,
441
 
                                                                theTypeManager,
442
 
                                                                theTimezone,
443
 
                                                                theCollation)),
444
 
                 state);
445
 
 
446
 
      if (consumeNext(item0, theChild0.getp(), planState) ||
447
 
          consumeNext(item1, theChild1.getp(), planState))
 
491
      if (item0->getTypeCode() != store::JS_NULL &&
 
492
          item1->getTypeCode() != store::JS_NULL)
448
493
      {
449
 
        RAISE_ERROR(err::XPTY0004, loc, ERROR_PARAMS(ZED(NoSeqInValueComp)));
 
494
        STACK_PUSH(GENV_ITEMFACTORY->
 
495
                   createBoolean(result,
 
496
                                 CompareIterator::valueComparison(loc,
 
497
                                                                  item0,
 
498
                                                                  item1,
 
499
                                                                  theCompType,
 
500
                                                                  theTypeManager,
 
501
                                                                  theTimezone,
 
502
                                                                  theCollation)),
 
503
                   state);
 
504
 
 
505
        assert(!consumeNext(item0, theChild0.getp(), planState) &&
 
506
               !consumeNext(item1, theChild1.getp(), planState));
450
507
      }
451
508
    }
452
509
  }
501
558
    }
502
559
    }
503
560
  }
504
 
  catch (ZorbaException const& e)
 
561
  catch (const ZorbaException& e)
505
562
  {
506
563
    if (e.diagnostic() == zerr::ZSTR0041_NAN_COMPARISON)
507
564
      return false;
 
565
 
508
566
    throw;
509
567
  }
510
568
}
631
689
    long timezone,
632
690
    XQPCollator* aCollation)
633
691
{
 
692
  if (aItem0->getTypeCode() == store::JS_NULL ||
 
693
      aItem1->getTypeCode() == store::JS_NULL)
 
694
  {
 
695
    return false;
 
696
  }
634
697
  try
635
698
  {
636
699
    switch(aCompType)
665
728
    }
666
729
    }
667
730
  }
668
 
  catch (ZorbaException const& e)
 
731
  catch (const ZorbaException& e)
669
732
  {
670
733
    if (e.diagnostic() == zerr::ZSTR0041_NAN_COMPARISON)
671
734
      return false;
943
1006
      }
944
1007
    }
945
1008
  }
946
 
  catch(ZorbaException const& e)
 
1009
  catch(const ZorbaException& e)
947
1010
  {
948
1011
    // For example, two QName items do not have an order relationship.
949
1012
    if (e.diagnostic() == zerr::ZSTR0040_TYPE_ERROR)
954
1017
      RAISE_ERROR(err::XPTY0004, loc,
955
1018
      ERROR_PARAMS(ZED(BadType_23o), *type0, ZED(NoCompareWithType_4), *type1));
956
1019
    }
 
1020
 
957
1021
    throw;
958
1022
  }
959
1023
}
965
1029
//                                                                             //
966
1030
/////////////////////////////////////////////////////////////////////////////////
967
1031
 
 
1032
template <store::SchemaTypeCode ATC>
 
1033
void TypedValueCompareIterator<ATC>::serialize(::zorba::serialization::Archiver& ar)
 
1034
{
 
1035
  serialize_baseclass(ar,
 
1036
  (NaryBaseIterator<TypedValueCompareIterator<ATC>, PlanIteratorState>*)this);
 
1037
 
 
1038
  SERIALIZE_ENUM(CompareConsts::CompareType, theCompType);
 
1039
  ar & theTimezone;
 
1040
  ar & theCollation;
 
1041
}
 
1042
 
968
1043
 
969
1044
template <store::SchemaTypeCode ATC>
970
1045
void TypedValueCompareIterator<ATC>::accept(PlanIterVisitor& v) const
1001
1076
  store::Item_t lItem0, lItem1;
1002
1077
  bool bRes;
1003
1078
  bool neq = false;
1004
 
  bool nonempty = false;
1005
1079
  long cmp;
1006
1080
 
1007
1081
  PlanIteratorState* state;
1009
1083
 
1010
1084
  if (CONSUME(lItem0, 0) && CONSUME(lItem1, 1))
1011
1085
  {
1012
 
    nonempty = true;
1013
 
 
1014
1086
    switch (theCompType)
1015
1087
    {
1016
1088
    case CompareConsts::VALUE_NOT_EQUAL:
1027
1099
 
1028
1100
    default:
1029
1101
    {
1030
 
      cmp = lItem0->compare(lItem1, theTimezone, theCollation);
 
1102
      try
 
1103
      {
 
1104
        cmp = lItem0->compare(lItem1, theTimezone, theCollation);
1031
1105
 
1032
 
      switch (theCompType)
 
1106
        switch (theCompType)
 
1107
        {
 
1108
        case CompareConsts::VALUE_LESS:
 
1109
          bRes = (cmp < 0);
 
1110
          break;
 
1111
        case CompareConsts::VALUE_GREATER:
 
1112
          bRes = (cmp > 0);
 
1113
          break;
 
1114
        case CompareConsts::VALUE_LESS_EQUAL:
 
1115
          bRes = (cmp <= 0);
 
1116
          break;
 
1117
        case CompareConsts::VALUE_GREATER_EQUAL:
 
1118
          bRes = (cmp >= 0);
 
1119
          break;
 
1120
        default:
 
1121
          ZORBA_ASSERT(false);
 
1122
        } // switch (theCompType)
 
1123
      }
 
1124
      catch (const ZorbaException& e)
1033
1125
      {
1034
 
      case CompareConsts::VALUE_LESS:
1035
 
        bRes = (cmp < 0);
1036
 
        break;
1037
 
      case CompareConsts::VALUE_GREATER:
1038
 
        bRes = (cmp > 0);
1039
 
        break;
1040
 
      case CompareConsts::VALUE_LESS_EQUAL:
1041
 
        bRes = (cmp <= 0);
1042
 
        break;
1043
 
      case CompareConsts::VALUE_GREATER_EQUAL:
1044
 
        bRes = (cmp >= 0);
1045
 
        break;
1046
 
      default:
1047
 
        ZORBA_ASSERT(false);
1048
 
      } // switch (theCompType)
 
1126
        if (e.diagnostic() == zerr::ZSTR0041_NAN_COMPARISON)
 
1127
          bRes = false;
 
1128
        else
 
1129
          throw;
 
1130
      }
1049
1131
    } // default
1050
1132
    } // switch (theCompType)
1051
1133
 
1052
 
    if (nonempty)
1053
 
      STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, bRes), state);
 
1134
    STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, bRes), state);
1054
1135
 
1055
 
    if (CONSUME(lItem0, 0) || CONSUME(lItem1, 1))
1056
 
    {
1057
 
      throw XQUERY_EXCEPTION(
1058
 
        err::XPTY0004,
1059
 
        ERROR_PARAMS( ZED( NoSeqInValueComp ) ),
1060
 
        ERROR_LOC( this->loc )
1061
 
      );
1062
 
    }
 
1136
    assert(!CONSUME(lItem0, 0) && !CONSUME(lItem1, 1));
1063
1137
  }
1064
1138
 
1065
1139
  STACK_END(state);
1096
1170
}
1097
1171
 
1098
1172
 
 
1173
AtomicValuesEquivalenceIterator::AtomicValuesEquivalenceIterator(
 
1174
    ::zorba::serialization::Archiver& ar)
 
1175
  :
 
1176
  BinaryBaseIterator<AtomicValuesEquivalenceIterator, PlanIteratorState>(ar),
 
1177
  theTypeManager(NULL),
 
1178
  theTimezone(0),
 
1179
  theCollation(NULL)
 
1180
{
 
1181
}
 
1182
 
 
1183
 
 
1184
void AtomicValuesEquivalenceIterator::serialize(::zorba::serialization::Archiver& ar)
 
1185
{
 
1186
  serialize_baseclass(ar,
 
1187
  (BinaryBaseIterator<AtomicValuesEquivalenceIterator, PlanIteratorState>*)this);
 
1188
 
 
1189
  SERIALIZE_TYPEMANAGER(TypeManager, theTypeManager);
 
1190
  ar & theTimezone;
 
1191
  ar & theCollation;
 
1192
}
 
1193
 
 
1194
 
1099
1195
BINARY_ACCEPT(AtomicValuesEquivalenceIterator);
1100
1196
 
1101
1197