Пример #1
0
        public override LiteralInteger CastTo(IntegralType type)
        {
            switch (type)
            {
            case IntegralType.Int64:
                return(this);

            case IntegralType.UInt64:
                if (Value < 0)
                {
                    throw new InvalidCastException($"Value '{Value}' cannot be safely cast to 'UInt64'.");
                }
                return(new LiteralUInt64((UInt64)Value));

            case IntegralType.Int32:
                if (Value < Int32.MinValue || Value > Int32.MaxValue)
                {
                    throw new InvalidCastException($"Value '{Value}' cannot be safely cast to 'Int32'.");
                }
                return(new LiteralInt32((Int32)Value));

            case IntegralType.UInt32:
                if (Value < UInt32.MinValue || Value > UInt32.MaxValue)
                {
                    throw new InvalidCastException($"Value '{Value}' cannot be safely cast to 'UInt32'.");
                }
                return(new LiteralUInt32((UInt32)Value));

            case IntegralType.Int16:
                if (Value < Int16.MinValue || Value > Int16.MaxValue)
                {
                    throw new InvalidCastException($"Value '{Value}' cannot be safely cast to 'Int16'.");
                }
                return(new LiteralInt16((Int16)Value));

            case IntegralType.UInt16:
                if (Value < UInt16.MinValue || Value > UInt16.MaxValue)
                {
                    throw new InvalidCastException($"Value '{Value}' cannot be safely cast to 'UInt16'.");
                }
                return(new LiteralUInt16((UInt16)Value));

            case IntegralType.Int8:
                if (Value > SByte.MaxValue || Value < SByte.MinValue)
                {
                    throw new InvalidCastException($"Value '{Value}' cannot be safely cast to 'SInt8'.");
                }
                return(new LiteralInt8((SByte)Value));

            case IntegralType.UInt8:
                if (Value < Byte.MinValue || Value > Byte.MaxValue)
                {
                    throw new InvalidCastException($"Value '{Value}' cannot be safely cast to 'UInt8'.");
                }
                return(new LiteralUInt8((Byte)Value));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Пример #2
0
        private void pushIntegralType(GeneratorAdapter ga, Node node, IntegralType integralType)
        {
            if (node is IntegralTypeNode)
            {
                IntegralTypeNode integralTypeNode = ((IntegralTypeNode)node);
                switch (integralType)
                {
                case com.juliar.nodes.IntegralType.jdouble:
                    //               ga.push(Double.parseDouble(integralTypeNode.getIntegralValue()));
                    break;

                case com.juliar.nodes.IntegralType.jfloat:
                    //               ga.push(Float.parseFloat(integralTypeNode.getIntegralValue()));
                    break;

                case com.juliar.nodes.IntegralType.jinteger:
                    //                ga.push(Integer.parseInt(integralTypeNode.getIntegralValue()));
                    break;

                case com.juliar.nodes.IntegralType.jlong:
                    //                ga.push(Long.parseLong(integralTypeNode.getIntegralValue()));
                    break;

                default:
                    break;
                }
            }
        }
Пример #3
0
        private void debugPrintLine(MethodVisitor mw, IntegralType addType)
        {
            if (isDebug)
            {
                switch (addType)
                {
                case com.juliar.nodes.IntegralType.jdouble:
                    mw.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(D)V", false);
                    break;

                case com.juliar.nodes.IntegralType.jfloat:
                    mw.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(F)V", false);
                    break;

                case com.juliar.nodes.IntegralType.jinteger:
                    mw.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(I)V", false);
                    break;

                case com.juliar.nodes.IntegralType.jlong:
                    mw.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(L)V", false);
                    break;

                default:
                    break;
                }
            }
        }
Пример #4
0
		public IntegralPrimitive(string value, IntegralType integralType, Token relatedToken) : base(relatedToken)
		{
			this.originalString = value;
			this.integralType = integralType;

			switch (integralType)
			{
				case IntegralType.SByte:
				case IntegralType.Byte:
				case IntegralType.Short:
				case IntegralType.Int:
					break;

				case IntegralType.UShort:
					value = value.TrimEnd('U', 'u');
					break;

				case IntegralType.UInt:
					value = value.TrimEnd('U', 'u');
					break;

				case IntegralType.Long:
					value = value.TrimEnd('L', 'l');
					break;

				case IntegralType.ULong:
					value = value.TrimEnd('L', 'l', 'U', 'u');
					value = value.TrimEnd('L', 'l', 'U', 'u');
					break;

				default:
					throw new FormatException("Illegal Integral type");
			}

			int radix = 10;
			NumberStyles style = NumberStyles.Integer;
			if (value.StartsWith("0x", true, CultureInfo.InvariantCulture))
			{
				radix = 16;
				style = NumberStyles.HexNumber;
				value = value.Substring(2, value.Length - 2);
			}
			// negation is wrapped in a unaryNegationNode so no need to account for negative values
			//try
			//{
			this.value = UInt64.Parse(value, style);
			//this.value = Convert.ToUInt64(value, radix);

			//}
			//catch (OverflowException)
			//{
			//    ConsoleWr
			//}
			//catch (FormatException)
			//{
			//}

		}
Пример #5
0
        public IntegralPrimitive(string value, IntegralType integralType, Token relatedToken) : base(relatedToken)
        {
            originalString    = value;
            this.integralType = integralType;

            switch (integralType)
            {
            case IntegralType.SByte:
            case IntegralType.Byte:
            case IntegralType.Short:
            case IntegralType.Int:
                break;

            case IntegralType.UShort:
                value = value.TrimEnd('U', 'u');
                break;

            case IntegralType.UInt:
                value = value.TrimEnd('U', 'u');
                break;

            case IntegralType.Long:
                value = value.TrimEnd('L', 'l');
                break;

            case IntegralType.ULong:
                value = value.TrimEnd('L', 'l', 'U', 'u');
                break;

            default:
                throw new FormatException("Illegal Integral type");
            }

            //int radix = 10;
            NumberStyles style = NumberStyles.Integer;

            if (value.StartsWith("0x", true, CultureInfo.InvariantCulture))
            {
                //radix = 16;
                style = NumberStyles.HexNumber;
                value = value.Substring(2, value.Length - 2);
            }
            // negation is wrapped in a unaryNegationNode so no need to account for negative values
            //try
            //{
            this.value = UInt64.Parse(value, style);
            //this.value = Convert.ToUInt64(value, radix);

            //}
            //catch (OverflowException)
            //{
            //    ConsoleWr
            //}
            //catch (FormatException)
            //{
            //}
        }
Пример #6
0
        private DynamicProperty(SerializationInfo info, StreamingContext context)
        {
            this.name = info.GetString("name");

            var clrTypeName = info.GetString("clrType");

            if (!string.IsNullOrEmpty(clrTypeName))
            {
                this.dataType = IntegralType.Get(clrTypeName);
            }

            this.defaultValue = info.GetValue("defaultValue", this.DataType.CLRType);
        }
Пример #7
0
        public EnumerationDef([NotNull] ITypeScope parent, [NotNull] String name, IntegralType underlyingType, [CanBeNull, ItemNotNull] List <String> comments = null)
            : base(name, comments)
        {
            UnderlyingType = underlyingType;
            Parent         = parent;

            File     = parent.File;
            Members  = new List <EnumerationMemberDef>();
            Type     = new TypeEnumeration(this);
            FullName = parent is FileDef ? Name : $"{((ItemDef) parent).FullName}.{Name}";

            parent.DefinedEnumerations.Add(this);
        }
Пример #8
0
        /// <summary>
        /// Sets the value of the specified property.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        public IPropertyAccessor SetPropertyValue <T>(string propertyName, T value)
        {
            var prop = this.DataType.GetPropertyByName(propertyName);

            if (prop == null)
            {
                // Property not found - create one
                DataType propType = IntegralType.Get(typeof(T));
                if (propType == null)
                {
                    var msg = string.Format("Error setting value on property {0}. Property not found and value is not an integral type. You must explicitly add the data type to the metadata provider.", propertyName);
                    throw new InvalidOperationException(msg);
                }
                prop = this.DataType.AddProperty(propertyName, propType);
            }

            prop.SetValue <T>(this, value);

            return(this);
        }
Пример #9
0
        public override LiteralInteger CastTo(IntegralType type)
        {
            switch (type)
            {
            case IntegralType.Int64:
                return(new LiteralInt64(Value));

            case IntegralType.UInt64:
                return(new LiteralUInt64(Value));

            case IntegralType.Int32:
                return(new LiteralInt32(Value));

            case IntegralType.UInt32:
                return(new LiteralUInt32(Value));

            case IntegralType.Int16:
                return(new LiteralInt16(Value));

            case IntegralType.UInt16:
                return(new LiteralUInt16(Value));

            case IntegralType.Int8:
                if (Value > SByte.MaxValue)
                {
                    throw new InvalidCastException($"Value '{Value}' cannot be safely cast to 'Int8'.");
                }
                return(new LiteralInt8((SByte)Value));

            case IntegralType.UInt8:
                return(this);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Пример #10
0
 public virtual T Visit(IntegralType node)
 {
     return(Visit((ScalarType)node));
 }
Пример #11
0
 public override bool Visit(IntegralType node)
 {
     Visit((ScalarType)node);
     return(true);
 }
Пример #12
0
 public static void Create(IntegralType type)
 {
     Integral.type = type;
 }
Пример #13
0
        private MethodVisitor evaluateExpressions(IList <Node> instructions, MethodVisitor mw, GeneratorAdapter ga, int?stackSize)
        {
            JuliarLogger.log("x");
            foreach (Node instruction in instructions)
            {
                JuliarLogger.log("Instructions");
                if (instruction is FunctionDeclNode)
                {
                    IList <Node> t = instruction.Instructions;
                    evaluateExpressions(t, mw, ga, stackSize);
                }
                if (instruction is PrimitiveNode)
                {
                    string function = ((PrimitiveNode)instruction).PrimitiveName.ToString();
                    JuliarLogger.log(function);

                    function = PrimitivesMap.getFunction(function);
                    mw.visitLdcInsn(((PrimitiveNode)instruction).GetPrimitiveArgument.ToString());
                    mw.visitIntInsn(ASTORE, 0);
                    mw.visitIntInsn(ALOAD, 0);
                    mw.visitMethodInsn(INVOKESTATIC, "com/juliar/pal/Primitives", function, "(Ljava/lang/String;)Ljava/lang/String;", false);


                    if ("printLine".Equals(function))
                    {
                        function = "sysPrintLine";
                        mw.visitLdcInsn(((PrimitiveNode)instruction).GetPrimitiveArgument.ToString());
                        mw.visitIntInsn(ASTORE, 0);
                        mw.visitIntInsn(ALOAD, 0);
                        mw.visitMethodInsn(INVOKESTATIC, "com/juliar/pal/Primitives", function, "(Ljava/lang/String;)V", false);
                    }

                    if ("print".Equals(function))
                    {
                        function = "sysPrint";
                        mw.visitLdcInsn(((PrimitiveNode)instruction).GetPrimitiveArgument.ToString());
                        mw.visitIntInsn(ASTORE, 0);
                        mw.visitIntInsn(ALOAD, 0);
                        mw.visitMethodInsn(INVOKESTATIC, "com/juliar/pal/Primitives", function, "(Ljava/lang/String;)V", false);
                    }
                }


                if (instruction is CompliationUnitNode)
                {
                    //WWLogger.log(((CompliationUnitNode) instructions).getInstructions().toString());

                    /*Logger.og(t.toString());
                     */

                    IList <Node> t = instruction.Instructions;
                    evaluateExpressions(t, mw, ga, stackSize);

                    /*for (List<Node> n : t) {
                     *  Logger.log(n.getNodeName().toString());
                     *  Logger.log("HERE");
                     *  evaluateExpressions(n, mw, ga, stackSize);
                     * }*/
                }

                if (instruction is StatementNode)
                {
                    IList <Node> t = instruction.Instructions;
                    evaluateExpressions(t, mw, ga, stackSize);
                }

                if (instruction is BinaryNode)
                {
                    /*
                     * JuliarLogger.log("BinaryNode");
                     * //Map<IntegralType,Integer> op = CodeGeneratorMap.generateMap(((BinaryNode)instruction).operation().toString());
                     *
                     * BinaryNode b = ((BinaryNode)instruction);
                     * if (isDebug) {
                     *  mw.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
                     * }
                     *
                     * IntegralType addType;
                     * IntegralTypeNode ln = (IntegralTypeNode)b.left();
                     * IntegralTypeNode rn = (IntegralTypeNode)b.right();
                     *
                     * if (ln.getIntegralType() == IntegralType.jdouble || rn.getIntegralType() == IntegralType.jdouble){
                     *  addType = IntegralType.jdouble;
                     * } else if (ln.getIntegralType() == IntegralType.jfloat || rn.getIntegralType() == IntegralType.jfloat){
                     *  addType =  IntegralType.jfloat;
                     * } else if (ln.getIntegralType() == IntegralType.jlong || rn.getIntegralType() == IntegralType.jlong){
                     *  addType = IntegralType.jlong;
                     * } else if (ln.getIntegralType() == IntegralType.jinteger || rn.getIntegralType() == IntegralType.jinteger){
                     *  addType = IntegralType.jinteger;
                     * } else{
                     * addType = null;
                     * }
                     *
                     * pushIntegralType(ga, b.left(),addType);
                     * ga.visitIntInsn(ISTORE, 1);
                     * pushIntegralType(ga, b.right(),addType);
                     * ga.visitIntInsn(ISTORE, 2);
                     * ga.visitIntInsn(ILOAD, 1);
                     * ga.visitIntInsn(ILOAD, 2);
                     * //ga.visitInsn(op.get(addType));
                     *
                     * mw.visitIntInsn(ILOAD, 0);
                     *
                     * debugPrintLine(mw,addType);
                     */
                }

                if (instruction is AggregateNode)
                {
                    JuliarLogger.log("BinaryNode");
                    //Map<IntegralType,Integer> op = CodeGeneratorMap.generateMap(((AggregateNode)instruction).operation().toString());

                    IList <IntegralTypeNode> integralTypeNodes = ((AggregateNode)instruction).data();
                    int addCount = integralTypeNodes.Count - 1;

                    if (isDebug)
                    {
                        mw.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
                    }

                    //Scan Type to typecast correctly
                    IntegralType addType = IntegralType.jinteger;
                    int[]        anArray = new int[5];
                    foreach (IntegralTypeNode integralTypeNode in integralTypeNodes)
                    {
                        switch (integralTypeNode.IntegralType)
                        {
                        case jdouble:
                            anArray[0]++;
                            break;

                        case jfloat:
                            anArray[1]++;
                            break;

                        case jlong:
                            anArray[2]++;
                            break;

                        default:
                            break;
                        }
                    }
                    //
                    if (anArray[0] != 0)
                    {
                        addType = IntegralType.jdouble;
                    }
                    else if (anArray[1] != 0)
                    {
                        addType = IntegralType.jfloat;
                    }
                    else if (anArray[2] != 0)
                    {
                        addType = IntegralType.jlong;
                    }
                    foreach (IntegralTypeNode integralTypeNode in integralTypeNodes)
                    {
                        pushIntegralType(ga, integralTypeNode, addType);
                    }

                    for (int i = 0; i < addCount; i++)
                    {
                        //ga.visitInsn(op.get(addType));
                    }

                    debugPrintLine(mw, addType);
                }
            }


            return(mw);
        }
Пример #14
0
 public PrimitiveType(IntegralType integraltype)
 {
     this.integraltype = integraltype;
 }
Пример #15
0
 public abstract LiteralInteger CastTo(IntegralType type);