~zorba-coders/zorba/bug900677

« back to all changes in this revision

Viewing changes to src/runtime/numerics/NumericsImpl.cpp

  • Committer: Matthias Brantner
  • Date: 2012-05-11 20:51:10 UTC
  • mfrom: (10618.1.218 zorba)
  • Revision ID: matthias.brantner@28msec.com-20120511205110-vo9yjskbhrnd9w72
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "common/shared_types.h"
19
19
 
20
20
#include "diagnostics/assert.h"
 
21
#include "diagnostics/util_macros.h"
21
22
#include "diagnostics/xquery_diagnostics.h"
22
23
#include "zorbatypes/zorbatypes_decl.h"
23
24
 
42
43
 
43
44
namespace zorba
44
45
{
45
 
SERIALIZABLE_TEMPLATE_VERSIONS(NumArithIterator)
46
 
END_SERIALIZABLE_TEMPLATE_VERSIONS(NumArithIterator)
 
46
 
47
47
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(NumArithIterator, NumArithIterator<AddOperation>, 1)
48
48
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(NumArithIterator, NumArithIterator<SubtractOperation>, 2)
49
49
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(NumArithIterator, NumArithIterator<MultiplyOperation>, 3)
51
51
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(NumArithIterator, NumArithIterator<IntegerDivideOperation>, 5)
52
52
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(NumArithIterator, NumArithIterator<ModOperation>, 6)
53
53
 
54
 
SERIALIZABLE_TEMPLATE_VERSIONS(SpecificNumArithIterator)
55
 
END_SERIALIZABLE_TEMPLATE_VERSIONS(SpecificNumArithIterator)
56
54
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(SpecificNumArithIterator, SpecificNumArithIterator<AddOperation, store::XS_DOUBLE>, 1);
57
55
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(SpecificNumArithIterator, SpecificNumArithIterator<AddOperation, store::XS_FLOAT>, 2);
58
56
SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(SpecificNumArithIterator, SpecificNumArithIterator<AddOperation, store::XS_DECIMAL>, 3);
76
74
 
77
75
 
78
76
SERIALIZABLE_CLASS_VERSIONS(OpNumericUnaryIterator)
79
 
END_SERIALIZABLE_CLASS_VERSIONS(OpNumericUnaryIterator)
80
77
 
81
78
SERIALIZABLE_CLASS_VERSIONS(OpDoubleUnaryIterator)
82
 
END_SERIALIZABLE_CLASS_VERSIONS(OpDoubleUnaryIterator)
 
79
 
83
80
 
84
81
/*******************************************************************************
85
82
  AddOperation (see runtime/core/arithmetic_impl.h/cpp)
441
438
  xs_integer ll0 = i0->getIntegerValue();
442
439
  xs_integer ll1 = i1->getIntegerValue();
443
440
 
444
 
  if ( ll1 == Integer::zero() )
 
441
  if ( ll1.sign() == 0 )
445
442
  {
446
443
    throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
447
444
  }
 
445
 
448
446
  return GENV_ITEMFACTORY->createInteger (result, ll0 / ll1);
449
447
}
450
448
 
492
490
  xs_decimal ld0 = i0->getDecimalValue();
493
491
  xs_decimal ld1 = i1->getDecimalValue();
494
492
 
495
 
  if ( ld1.sign() == 0 )
 
493
  if (ld1.sign() == 0)
496
494
  {
497
 
    throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
 
495
    throw XQUERY_EXCEPTION(err::FOAR0001, ERROR_LOC(loc));
498
496
  }
499
497
  return GENV_ITEMFACTORY->createDecimal(result,  ld0 % ld1);
500
498
}
512
510
  xs_integer ll0 = i0->getIntegerValue();
513
511
  xs_integer ll1 = i1->getIntegerValue();
514
512
 
515
 
  if ( ll1 == Integer::zero() )
 
513
  if (ll1 == Integer::zero())
516
514
  {
517
 
    throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
 
515
    throw XQUERY_EXCEPTION(err::FOAR0001, ERROR_LOC(loc));
518
516
  }
519
517
  return GENV_ITEMFACTORY->createInteger(result, ll0 % ll1);
520
518
}
558
556
                    this->loc,
559
557
                    n0,
560
558
                    n1);
561
 
      
562
 
      if (this->consumeNext(n0, this->theChild0.getp(), planState) ||
563
 
          this->consumeNext(n1, this->theChild1.getp(), planState))
564
 
        throw XQUERY_EXCEPTION(
565
 
          err::XPTY0004, ERROR_PARAMS( ZED( NoSeqAsArithOp ) )
566
 
        );
 
559
 
567
560
      STACK_PUSH(res, state);
568
561
    }
569
562
  }
584
577
}
585
578
 
586
579
 
587
 
 
588
580
template < class Operation >
589
581
bool NumArithIterator<Operation>::compute(
590
582
    store::Item_t& result,
728
720
  PlanIteratorState* state;
729
721
  DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
730
722
 
731
 
  if (this->consumeNext( n0, this->theChild0.getp(), planState ))
 
723
  if (this->consumeNext(n0, this->theChild0.getp(), planState))
732
724
  {
733
 
    if (this->consumeNext( n1, this->theChild1.getp(), planState ))
 
725
    if (this->consumeNext(n1, this->theChild1.getp(), planState))
734
726
    {
735
 
      res = compute(result,
736
 
                    planState.theLocalDynCtx,
737
 
                    this->theSctx->get_typemanager(),
738
 
                    this->loc,
739
 
                    n0.getp(),
740
 
                    n1.getp());
741
 
      
742
 
      if (this->consumeNext(n0, this->theChild0.getp(), planState) ||
743
 
          this->consumeNext(n1, this->theChild1.getp(), planState))
744
 
        throw XQUERY_EXCEPTION(
745
 
          err::XPTY0004, ERROR_PARAMS( ZED( NoSeqAsArithOp ) )
746
 
        );
747
 
      STACK_PUSH ( res, state );
 
727
      assert(n0->isAtomic());
 
728
      assert(n1->isAtomic());
 
729
 
 
730
      res = Operation::template 
 
731
      computeSingleType<Type>(result, NULL, NULL, &this->loc, n0.getp(), n1.getp());
 
732
 
 
733
      STACK_PUSH(res, state);
748
734
    }
749
735
  }
750
 
  STACK_END (state);
 
736
  STACK_END(state);
751
737
}
752
738
 
753
739
 
757
743
    dynamic_context* dctx,
758
744
    const TypeManager* tm,
759
745
    const QueryLoc& aLoc, 
760
 
    store::Item *n0,
761
 
    store::Item *n1)
 
746
    store::Item* n0,
 
747
    store::Item* n1)
762
748
{
763
749
  assert(n0->isAtomic());
764
750
  assert(n1->isAtomic());
765
751
 
766
 
  return Operation::template computeSingleType<Type>(result, dctx, tm, &aLoc, n0, n1 );
 
752
  return Operation::template computeSingleType<Type>(result, dctx, tm, &aLoc, n0, n1);
767
753
}
768
754
 
769
755
  
792
778
/*******************************************************************************
793
779
 
794
780
********************************************************************************/
795
 
OpNumericUnaryIterator::OpNumericUnaryIterator (
 
781
OpNumericUnaryIterator::OpNumericUnaryIterator(
796
782
     static_context* sctx,
797
783
     const QueryLoc& loc,
798
784
     PlanIter_t& theChild,
799
 
     bool aPlus )
 
785
     bool aPlus)
800
786
  :
801
787
  UnaryBaseIterator<OpNumericUnaryIterator, PlanIteratorState>(sctx, loc, theChild),
802
788
  thePlus(aPlus)
860
846
    }
861
847
    else
862
848
    {
863
 
      throw XQUERY_EXCEPTION(
864
 
        err::XPTY0004,
865
 
        ERROR_PARAMS( ZED( BadTypeFor_23 ), type, ZED( UnaryArithOp ) ),
866
 
        ERROR_LOC( loc )
867
 
      );
 
849
      RAISE_ERROR(err::XPTY0004, loc,
 
850
      ERROR_PARAMS(ZED(BadTypeFor_23), type, ZED(UnaryArithOp)));
868
851
    }
869
852
    
870
853
    STACK_PUSH(true, state);