public static Expression Getter(this VarAutExpression E, Type T)
        {
            Expression Var;

            if (E.Index == null)
            {
                Var = CurrentScope.GetVarCached(E.Name, T);
            }
            else
            {
                Var = Expression.ArrayIndex(CurrentScope.GetVarCached(E.Name, null), E.Index);
                if (E.UnboxTo != null)
                {
                    Var = Expression.Convert(Var, E.UnboxTo);
                }
                Var = Var.ConvertTo(T);
            }
            return(Var);

            /* OLD
             * Expression Exp = null, Global = null;
             * if (E.Index != null) E.Index = E.Index.Select(x => x.ConvertTo(typeof(int))).ToList();
             * if (E.IsGlobal ?? true)
             * {
             *  Exp = _Get(E.Name, E.Index != null ? null : T);
             *  if (Exp != null && E.Index != null) return E.UnboxTo != null ?
             *      (Expression)Expression.Convert(Expression.ArrayAccess(Exp, E.Index), E.UnboxTo).ConvertTo(T) :
             *      (Expression)Expression.ArrayAccess(Exp, E.Index).ConvertTo(T);
             *  else if (E.Index != null) try
             *      {
             *          return E.UnboxTo != null ?
             *              (Expression)Expression.Convert(Expression.ArrayAccess(_Get(E.Name, null), E.Index), E.UnboxTo).ConvertTo(T) :
             *              (Expression)Expression.ArrayAccess(_Get(E.Name, null), E.Index).ConvertTo(T);
             *      }
             *      catch { }
             *  else if (Exp != null) return Exp;
             *  else if (!GlobalCache) try {return _Get(E.Name, null).ConvertTo(T);} catch{}
             *
             * }
             * if (E.Index != null)
             * {
             *  var e = Expression.ArrayAccess(Scope.Peek().FirstOrDefault(x => x.Name == E.Name), E.Index);
             *  if (E.UnboxTo != null) return Expression.Convert(e, E.UnboxTo).ConvertTo(T ?? E.UnboxTo);
             *  else return e.ConvertTo(T ?? typeof(object));
             * }
             * else if (T == null) return Scope.Peek().FirstOrDefault(x => x.Name == E.Name && OnDateType.Peek()[E].Contains(x.Type));
             * else if (OnDateType.Peek()[E].Contains(T)) return Scope.Peek().FirstOrDefault(x => x.Name == E.Name && x.Type == T);
             *
             * if (Exp != null) Global = Exp;
             * Exp = Scope.Peek().FirstOrDefault(x => x.Name == E.Name && x.Type == T);
             * if (Exp == null) Scope.Peek().Add((ParameterExpression)(Exp = Expression.Parameter(T, E.Name)));
             * else if (Exp.Type == T) return Exp;
             * var Ret = Expression.Block(T,
             *  Expression.Assign(Exp, (Scope.Peek().LastOrDefault(x => x.Name == E.Name && OnDateType.Peek()[E].Contains(x.Type)) ?? Global).ConvertTo(Exp.Type)),
             *  Exp);
             * OnDateType.Peek()[E].Add(T);
             * return Ret;*/
        }
Esempio n. 2
0
        private Expression ParseKeyword_RETURN(string Keyword)
        {
            return(Expression.Block(Contextual.Peek().Type,
                                    VarAutExpression.VariableAccess("Return-store").Setter(ParseBoolean(false).ConvertTo(Contextual.Peek().Type))
                                    , Contextual.Peek()));

            /*VarSynchronisation.Add();
            *  return Contextual.Peek();*/
        }
        public static Expression Generator(this VarAutExpression E)
        {
            Type T;

            if (E.Index == null)
            {
                T = E.UnboxTo ?? typeof(object);
            }
            else
            {
                E.Index = E.Index.Select(x => x.ConvertTo(typeof(int))).ToList();
                if (E.UnboxTo != null)
                {
                    if (E.Index.Count == 1)
                    {
                        T = E.UnboxTo.MakeArrayType();
                    }
                    else
                    {
                        T = E.UnboxTo.MakeArrayType(E.Index.Count);
                    }
                }
                else
                if (E.Index.Count == 1)
                {
                    T = typeof(object[]);
                }
                else
                {
                    T = typeof(object).MakeArrayType(E.Index.Count);
                }
            }

            IScope Sc;

            if (E.IsGlobal ?? false)
            {
                Sc = CurrentScope.Last();
            }
            else
            {
                Sc = CurrentScope;
            }

            Sc.DeclareVar(E.Name, T);
            if (E.Index == null)
            {
                return(null);
            }
            else
            {
                return(Sc.SetVar(E.Name, Expression.NewArrayBounds(T.GetElementType(), E.Index)));
            }
        }
        public static Expression Setter(this VarAutExpression E, Expression T)
        {
            Expression Var;

            if (E.Index == null)
            {
                Var = CurrentScope.SetVarCached(E.Name, T);
            }
            else
            {
                Var = CurrentScope.GetVarCached(E.Name, null);
                Var = Expression.Assign(Expression.ArrayIndex(Var, E.Index), T.ConvertTo(Var.Type.GetElementType()));
            }
            return(Var);

            /* OLD
             * Expression Exp = null;
             *
             *
             * if (E.Index != null) E.Index = E.Index.Select(x => x.ConvertTo(typeof(int))).ToList();
             *
             * if (OnDateType.Peek().Any(x => x.Key.Name == E.Name))
             *  OnDateType.Peek().First(x => x.Key.Name == E.Name).Value.Clear();
             * else if (E.Index == null) OnDateType.Peek().Add(E, new List<Type>());
             *
             * if (E.IsGlobal ?? true)
             * {
             *  Exp = _Get(E.Name, E.Index != null ? null : T.Type);
             *  if (Exp != null && E.Index != null) return E.UnboxTo != null ?
             *      Expression.Assign(Expression.ArrayAccess(Exp, E.Index), T.ConvertTo(E.UnboxTo).ConvertTo(Exp.Type.GetElementType())) :
             *      Expression.Assign(Expression.ArrayAccess(Exp, E.Index), T.ConvertTo(Exp.Type.GetElementType()));
             *  else if (E.Index != null && _Get(E.Name, null) != null) return E.UnboxTo != null ?
             *      Expression.Assign(Expression.ArrayAccess(_Get(E.Name, null), E.Index), T.ConvertTo(E.UnboxTo).ConvertTo(_Get(E.Name, null).Type.GetElementType())) :
             *      Expression.Assign(Expression.ArrayAccess(_Get(E.Name, null), E.Index), T.ConvertTo(_Get(E.Name, null).Type.GetElementType()));
             *  else if (Exp != null) return _Set(E.Name, T);
             *  else if (!GlobalCache) try { return _Set(E.Name, T.ConvertTo(_Get(E.Name, null).Type)); }
             *      catch { }
             * }
             * //else
             * {
             *  if (E.Index == null) OnDateType.Peek()[E].Add(T.Type);
             *  do
             *  {
             *      Exp = Scope.Peek().FirstOrDefault(x => x.Name == E.Name && (x.Type == T.Type || E.Index != null));
             *      if (Exp != null) return Expression.Assign(E.Index != null ? Expression.ArrayAccess(Exp, E.Index) : Exp,
             *          E.Index != null ? (E.UnboxTo != null ? T.ConvertTo(E.UnboxTo).ConvertTo(Exp.Type.GetElementType()) :
             *          T.ConvertTo(Exp.Type.GetElementType())) : T);
             *
             *  } while (true);
             * }
             * Scope.Peek().Add((ParameterExpression)(Exp = Expression.Parameter(T.Type, E.Name)));
             * return Expression.Assign(Exp, T);
             */
        }
Esempio n. 5
0
        public static VarAutExpression VariableAccess(string Name, bool?IsGlobal = null, Type UnboxTo = null, params Expression[] Index)
        {
            var n = new VarAutExpression()
            {
                ExpressionType = (IsGlobal == null) ? AutExpressionType.Variable : IsGlobal ?? true ? AutExpressionType.GlobalVariable : AutExpressionType.LocalVariable,
                Name           = Name,
                Index          = Index.Length <= 0 ? null : Index.ToList(),
                UnboxTo        = UnboxTo
            };

            return(n);
        }
Esempio n. 6
0
        public static VarAutExpression VariableAccess(string Name, bool?IsGlobal = null, Expression Index = null, Type UnboxTo = null)
        {
            var n = new VarAutExpression()
            {
                ExpressionType = (IsGlobal == null) ? AutExpressionType.Variable : IsGlobal ?? true ? AutExpressionType.GlobalVariable : AutExpressionType.LocalVariable,
                Name           = Name,
                Index          = Index == null ? null : new List <Expression>()
                {
                    Index
                },
                UnboxTo = UnboxTo
            };

            return(n);
        }
        private Expression ParseUltraPrimary()
        {
            ConsumeWS();
            char       ch = Read()[0];
            string     szTemp;
            Expression Ret;

            switch (ch)
            {
            case ']':
                throw new AutoitException(AutoitExceptionType.UNBALANCEDSUBSCRIPT, LineNumber, Cursor);

            case '(':
                Ret = ParseBoolean();
                if (Peek() != ")")
                {
                    throw new AutoitException(AutoitExceptionType.UNBALANCEDPAREN, LineNumber, Cursor);
                }
                Consume();
                return(Ret);

            case ')':
                throw new AutoitException(AutoitExceptionType.UNBALANCEDPAREN, LineNumber, Cursor);

            case ';':
                return(null);

            case '$':
                szTemp = Getstr(Reg_AlphaNum);
                Type t;

                if (szTemp == "")
                {
                    throw new AutoitException(AutoitExceptionType.LEXER_BADFORMAT, LineNumber, Cursor);
                }

                List <Expression> SubScript = new List <Expression>();
                while (TryParseSubscript(out Ret))
                {
                    SubScript.Add(Ret);
                }
                TryParseCast(out t);
                ConsumeWS();
                return(VarAutExpression.VariableAccess(szTemp, null, t, SubScript.ToArray()));

            case '@':
                var CPos = Cursor - 1;
                szTemp = Getstr(Reg_AlphaNum);

                if (szTemp == "")
                {
                    throw new AutoitException(AutoitExceptionType.LEXER_BADFORMAT, LineNumber, Cursor);
                }
                return(Expression.Call(BasicMacro.GetMacroInfo, Expression.Constant(szTemp, typeof(string))));

            case '"':
            case '\'':
                SeekRelative(-1);
                return(Expression.Constant(Lexer_CSString(), typeof(string)));

            default:

                SeekRelative(-1);
                szTemp = GetNbr();
                if (szTemp != "")
                {
                    if (szTemp.Contains(".") || Math.Abs(double.Parse(szTemp, CultureInfo.InvariantCulture)) > long.MaxValue)
                    {
                        return(Expression.Constant(double.Parse(szTemp, CultureInfo.InvariantCulture), typeof(double)));
                    }
                    else if (Math.Abs(double.Parse(szTemp, CultureInfo.InvariantCulture)) > int.MaxValue)
                    {
                        return(Expression.Constant(long.Parse(szTemp, CultureInfo.InvariantCulture), typeof(long)));
                    }
                    else
                    {
                        return(Expression.Constant(int.Parse(szTemp, CultureInfo.InvariantCulture), typeof(int)));
                    }
                }
                szTemp = Getstr(Reg_Any);
                if (szTemp != "")
                {
                    if (szTemp.Contains("."))
                    {
                        var AType = Included.SelectMany(x => x.ExportedTypes).Concat(IncludedType).FirstOrDefault(
                            x => {
                            var Nr = x.FullName.ToUpper().Split('.');
                            return(Nr.SequenceEqual(szTemp.ToUpper().Split('.').Take(Nr.Count())));
                        });
                        if (AType != default(Type))
                        {
                            SeekRelative(AType.FullName.Length - szTemp.Length);
                            return(Expression.Constant(null, AType.GetTypeInfo().IsValueType ? typeof(Nullable <>).MakeGenericType(AType) : AType));
                        }
                    }
                    else
                    {
                        return(ParseKeywordOrFunc(szTemp));
                    }
                }
                throw new AutoitException(AutoitExceptionType.LEXER_NOTRECOGNISED, LineNumber, Cursor, "" + ch);
            }
        }
Esempio n. 8
0
        private Expression ParseKeyword_FOR(string Keyword)
        {
            Expression InitVal, LastVal, Step;
            string     ForVarName;

            ForVarName = (ParsePrimary() as VarAutExpression).Name;
            ConsumeWS();
            if (Peek(1).ToUpper() != "=")
            {
                throw new AutoitException(AutoitExceptionType.FORWITHOUTTO, LineNumber, Cursor);
            }
            Consume(); ConsumeWS();
            InitVal = ParseBoolean().ConvertToNumber();
            ConsumeWS();
            if (Peek(2).ToUpper() != "TO")
            {
                throw new AutoitException(AutoitExceptionType.FORWITHOUTTO, LineNumber, Cursor);
            }
            Consume(2); ConsumeWS();
            LastVal = ParseBoolean().ConvertTo(InitVal.Type);
            ConsumeWS();
            if (Peek(4).ToUpper() == "STEP")
            {
                Consume(4); ConsumeWS();
                Step = ParseBoolean().ConvertTo(InitVal.Type);
            }
            else
            {
                Step = Expression.Constant(1, typeof(int)).ConvertTo(InitVal.Type);
            }
            if (!INTERCATIVE)
            {
                var @break    = Expression.Label("break");
                var @continue = Expression.Label("continue");
                var @DownTo   = VarAutExpression.VariableAccess("downto-" + Contextual.Count, false);
                var @LoopVar  = VarAutExpression.VariableAccess(ForVarName, false);
                Contextual.Push(Expression.Goto(@break));
                Contextual.Push(Expression.Goto(@continue));
                List <Expression> Instruction = new List <Expression>();
                if (Step is ConstantExpression)
                {
                    Instruction.Add(@DownTo.Setter((ConstantExpression)Expression.Constant((dynamic)(Step as ConstantExpression).Value < 0, typeof(bool))));
                }
                else
                {
                    Instruction.Add(@DownTo.Setter(Expression.LessThan(Step, Expression.Constant(0, InitVal.Type))));
                }
                Instruction.Add(@LoopVar.Setter(InitVal));
                Instruction.Add(Expression.Label(@continue));
                Instruction.Add(Expression.IfThen(
                                    Expression.OrElse(
                                        Expression.AndAlso(
                                            @DownTo.Getter(typeof(bool)),
                                            Expression.LessThan(@LoopVar.Getter(InitVal.Type), LastVal)),
                                        Expression.AndAlso(
                                            Expression.Not(@DownTo.Getter(typeof(bool))),
                                            Expression.GreaterThan(@LoopVar.Getter(InitVal.Type), LastVal)))
                                    , Expression.Goto(@break)));
                Instruction.AddRange(ParseBlock(true));
                Instruction.Add(Expression.Assign(
                                    @LoopVar.Getter(InitVal.Type),
                                    Expression.Add(@LoopVar.Getter(InitVal.Type), Step)));
                Instruction.Add(Expression.Goto(@continue));
                Instruction.Add(Expression.Label(@break));
                Contextual.Pop();
                Contextual.Pop();
                return(Expression.Block(Instruction.ToArray()));
            }
            else
            {
                throw new AutoitException(AutoitExceptionType.MULTILINEININTERACTIVE, LineNumber, Cursor, Keyword);
            }
        }
Esempio n. 9
0
        public static VarAutExpression VariableAccess(string Name, bool? IsGlobal = null, Type UnboxTo = null, params Expression[] Index)
        {

            var n = new VarAutExpression()
            {
                ExpressionType = (IsGlobal == null) ? AutExpressionType.Variable : IsGlobal ?? true ? AutExpressionType.GlobalVariable : AutExpressionType.LocalVariable,
                Name = Name,
                Index = Index.Length <= 0 ? null : Index.ToList(),
                UnboxTo = UnboxTo
            };
            return n;
        }
Esempio n. 10
0
        public static VarAutExpression VariableAccess(string Name, bool? IsGlobal = null, Expression Index = null, Type UnboxTo = null)
        {

            var n = new VarAutExpression()
            {
                ExpressionType = (IsGlobal == null) ? AutExpressionType.Variable : IsGlobal ?? true ? AutExpressionType.GlobalVariable : AutExpressionType.LocalVariable,
                Name = Name,
                Index = Index == null ? null : new List<Expression>() {Index},
                UnboxTo = UnboxTo
            };
            return n;
        }