Ejemplo n.º 1
0
        internal static Expression GetVariableExpression(int typeIndex, Oc5ModelState oc5State, ParameterExpression oc5StateParameterExpression)
        {
            var type = (Types)typeIndex;

            switch (type)
            {
            case Types._boolean:
                oc5State.Bools.Add(default(bool));
                var boolIndex = oc5State.Bools.Count - 1;
                oc5State.Mappings.Add(new PositionInOc5State {
                    Type = type, IndexInOc5StateList = boolIndex
                });
                var boolsExpression = Expression.Property(oc5StateParameterExpression, "Bools");
                return(Expression.Property(boolsExpression, "Item", Expression.Constant(boolIndex)));

            case Types._integer:
                oc5State.Ints.Add(default(int));
                var intIndex = oc5State.Ints.Count - 1;
                oc5State.Mappings.Add(new PositionInOc5State {
                    Type = type, IndexInOc5StateList = intIndex
                });
                var intsExpression = Expression.Property(oc5StateParameterExpression, "Ints");
                return(Expression.Property(intsExpression, "Item", Expression.Constant(intIndex)));

            case Types._string:
                oc5State.Strings.Add(default(string));
                var stringIndex = oc5State.Strings.Count - 1;
                oc5State.Mappings.Add(new PositionInOc5State {
                    Type = type, IndexInOc5StateList = stringIndex
                });
                var stringsExpression = Expression.Property(oc5StateParameterExpression, "Strings");
                return(Expression.Property(stringsExpression, "Item", Expression.Constant(stringIndex)));

            case Types._float:
                oc5State.Floats.Add(default(float));
                var floatIndex = oc5State.Floats.Count - 1;
                oc5State.Mappings.Add(new PositionInOc5State {
                    Type = type, IndexInOc5StateList = floatIndex
                });
                var floatsExpression = Expression.Property(oc5StateParameterExpression, "Floats");
                return(Expression.Property(floatsExpression, "Item", Expression.Constant(floatIndex)));

            case Types._double:
                oc5State.Doubles.Add(default(double));
                var doubleIndex = oc5State.Doubles.Count - 1;
                oc5State.Mappings.Add(new PositionInOc5State {
                    Type = type, IndexInOc5StateList = doubleIndex
                });
                var doublesExpression = Expression.Property(oc5StateParameterExpression, "Doubles");
                return(Expression.Property(doublesExpression, "Item", Expression.Constant(doubleIndex)));

            default:
                throw new ArgumentException($"No predefined type with index {typeIndex}!");
            }
        }
Ejemplo n.º 2
0
        public Oc5Runner(string oc5Source)
        {
            Oc5Source = oc5Source;

            var inputStream = new AntlrInputStream(oc5Source);
            var lexer       = new Oc5Lexer(inputStream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new Oc5Parser(tokenStream);

            var ocfileContext = parser.ocfile();

            var visitor = new CompileVisitor(ocfileContext);

            Oc5Model      = visitor.Oc5Model;
            Oc5ModelState = visitor.Oc5ModelState;
        }