Ejemplo n.º 1
0
 public override void OnDecimalLiteralExpression(DecimalLiteralExpression node)
 {
     // Invoke Decimal(int lo, int mid, int hi, bool isNegative, byte scale)
     int[] bits = Decimal.GetBits(node.Value);
     _il.Emit(OpCodes.Ldc_I4, bits[0]);
     _il.Emit(OpCodes.Ldc_I4, bits[1]);
     _il.Emit(OpCodes.Ldc_I4, bits[2]);
     _il.Emit(bits[3] < 0 ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); // bool isNegative
     int scale = (bits[3]&0x7FFFFFFF)>>16;
     if (scale<0)
         throw new Exception("unexpected scale less than 0");
     if (scale>28)
         throw new Exception("unexpected scale greater than 28");
     _il.Emit(OpCodes.Ldc_I4_S, scale);
     _il.Emit(OpCodes.Newobj, Decimal_Constructor);
     PushType(TypeSystemServices.DecimalType);
 }
Ejemplo n.º 2
0
 public override void OnDecimalLiteralExpression(DecimalLiteralExpression node)
 {
     BindExpressionType(node, TypeSystemServices.DecimalType);
 }
Ejemplo n.º 3
0
        //throws RecognitionException, TokenStreamException
        protected LiteralExpression double_literal()
        {
            LiteralExpression  rle;

            IToken  neg = null;
            IToken  value = null;
            IToken  single = null;
            IToken  dec = null;

                rle = null;
                string val;

            try {      // for error handling
            switch ( LA(1) )
            {
            case SUBTRACT:
            case DOUBLE:
            {
                {
                    switch ( LA(1) )
                    {
                    case SUBTRACT:
                    {
                        neg = LT(1);
                        match(SUBTRACT);
                        break;
                    }
                    case DOUBLE:
                    {
                        break;
                    }
                    default:
                    {
                        throw new NoViableAltException(LT(1), getFilename());
                    }
                     }
                }
                value = LT(1);
                match(DOUBLE);
                if (0==inputState.guessing)
                {

                            val = value.getText();
                            if (neg != null) val = neg.getText() + val;
                            rle = new DoubleLiteralExpression(ToLexicalInfo(value), PrimitiveParser.ParseDouble(value, val));

                }
                break;
            }
            case FLOAT:
            {
                single = LT(1);
                match(FLOAT);
                if (0==inputState.guessing)
                {

                            val = single.getText();
                            val = val.Substring(0, val.Length-1);
                            if (neg != null) val = neg.getText() + val;
                            rle = new DoubleLiteralExpression(ToLexicalInfo(single), PrimitiveParser.ParseDouble(single, val, true), true);

                }
                break;
            }
            case DECIMAL:
            {
                dec = LT(1);
                match(DECIMAL);
                if (0==inputState.guessing)
                {

                    val = dec.getText();
                    val = val.Substring(0, val.Length-3); // "dec"
                    if (neg != null) val = neg.getText() + val;
                    rle = new DecimalLiteralExpression(ToLexicalInfo(dec), decimal.Parse(val, NumberStyles.Currency, CultureInfo.InvariantCulture));

                }
                break;
            }
            default:
            {
                throw new NoViableAltException(LT(1), getFilename());
            }
             }
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex, "double_literal");
                recover(ex,tokenSet_41_);
            }
            else
            {
                throw ex;
            }
            }
            return rle;
        }