示例#1
0
 internal static MethodCallExpr Bound(Expr e, Symbol sym, Expr self, ArgList args, Expr writeBack = null)
 {
     return(new MethodCallExpr(e, args)
     {
         Symbol = sym, Datatype = sym.Type(), Self = self, WriteBack = writeBack
     });
 }
        internal override Node Bind(Binder b)
        {
            if (Token.Type == TokenType.LPARAMETERS || Token.Type == TokenType.PARAMETERS)
            {
                for (int i = 0; i < VarDecls.Length; i++)
                {
                    var argIdx     = b.Options.ArrayBase + i;
                    var paramArray = IdExpr.Bound((b.Entity as Script).ParamArray);
                    VarDecls[i].Initializer =
                        IifExpr.Bound(
                            BinaryExpr.Bound(ArrayLengthExpr.Bound(paramArray), Token, LiteralExpr.Bound(Constant.Create(i)), BinaryOperatorKind.GreaterThan, b.Options.Binding),
                            ArrayAccessExpr.Bound(paramArray, ArgList.Bound(LiteralExpr.Bound(Constant.Create(argIdx))), b),
                            DefaultExpr.Bound(b, b.ObjectType),
                            b.Options.Binding);
                }
            }

            // TODO: Handle STATIC
            if (Token.Type == TokenType.STATIC)
            {
                throw Error(ErrorCode.NotSupported, "STATIC");
            }

            for (int i = 0; i < VarDecls.Length; i++)
            {
                b.Bind(ref VarDecls[i]);
            }
            return(null);
        }
        internal override Node Bind(Binder b)
        {
            if (Expr != null)
            {
                b.Bind(ref Expr);
                Expr.RequireGetAccess();
            }
            else
            {
                if (b.Options.Dialect == XSharpDialect.FoxPro)
                {
                    Expr = LiteralExpr.Bound(Constant.Create(false));
                }
                else
                {
                    Expr = LiteralExpr.Bound(Constant.CreateDefault(Compilation.Get(NativeType.Usual)));
                }
            }
            var t    = IdExpr.Bound(Compilation.Get(WellKnownTypes.XSharp_Internal_WrappedException));
            var args = ArgList.Bound(Expr);

            Expr = CtorCallExpr.Bound(b, t, args);
            b.Convert(ref Expr, Compilation.Get(NativeType.Object));
            return(null);
        }
示例#4
0
        internal static ArrayAccessExpr Bound(Expr e, ArgList a, Binder b)
        {
            if (e.Datatype.IsUsualOrObject())
            {
                b.Convert(ref e, Compilation.Get(NativeType.Array));
            }
            if (Binder.TypesMatch(e.Datatype, NativeType.Array) || e.Datatype.IsArray)
            {
                b.ConvertArrayBase(a);
            }
            if (e.Datatype.IsArray && e.Datatype.ArrayRank == 1)
            {
                if (a.Args.Count != 1)
                {
                    throw e.Error(ErrorCode.WrongNumberIfIndices);
                }
                return(NativeArrayAccessExpr.Bound(e, a));
            }
            var item = e.Datatype.Lookup(SystemNames.IndexerName);
            var sym  = b.BindArrayAccess(e, item, a);

            return(new ArrayAccessExpr(e, a)
            {
                Self = e, Symbol = sym, Datatype = sym.Type()
            });
        }
示例#5
0
 internal static NativeArrayAccessExpr Bound(Expr e, ArgList a)
 {
     return(new NativeArrayAccessExpr(e, a)
     {
         Self = e, Symbol = e.Symbol, Datatype = e.Symbol.Type().ElementType
     });
 }
示例#6
0
        internal static CtorCallExpr Bound(Binder b, TypeExpr type, ArgList args)
        {
            Expr writeBack;
            var  sym = b.BindCtorCall(type, type.Symbol, args, out writeBack);

            return(new CtorCallExpr(type, args)
            {
                Symbol = sym, Datatype = sym.Type(), WriteBack = writeBack
            });
        }
        internal override Node Bind(Binder b)
        {
            var funcs = Compilation.Get(WellKnownTypes.XSharp_RT_Functions);
            var expr  = IdExpr.Bound(b.Lookup(funcs, QOutName));
            var args  = new ArgList(new List <Arg>(Exprs.Select(x => new Arg(x))));

            b.Bind(ref args);
            Expr self, writeBack;
            var  sym = b.BindMethodCall(expr, expr.Symbol, args, out self, out writeBack);

            if (self != null || writeBack != null)
            {
                throw Error(ErrorCode.Internal);
            }
            QOutCall = MethodCallExpr.Bound(expr, sym, null, args);
            return(null);
        }
示例#8
0
        internal static MethodCallExpr Bound(Binder b, Expr e, string name, ArgList args)
        {
            Expr m = new IdExpr(name);
            Expr self;
            Expr writeBack;
            var  ms = b.BindMemberAccess(ref e, ref m, BindAffinity.Invoke);

            if (!(ms is MethodSymbol))
            {
                throw e.Error(ErrorCode.Internal);
            }
            var expr = new MemberAccessExpr(e, e.Token, m)
            {
                Symbol = ms
            };
            var sym = b.BindMethodCall(expr, ms, ArgList.Empty, out self, out writeBack);

            return(Bound(e, sym, self, ArgList.Empty, writeBack));
        }
示例#9
0
 internal CtorCallExpr(TypeExpr e, ArgList a) : base(e, a)
 {
 }
示例#10
0
 internal MethodCallExpr(Expr e, ArgList a) : base(e?.Token)
 {
     Expr = e; Args = a;
 }
示例#11
0
        internal static MethodCallExpr Bound(Binder b, Expr e, Symbol sym, Expr self, ArgList args)
        {
            Expr boundSelf;
            Expr writeBack;

            if (self != null)
            {
                e = new MemberAccessExpr(self, null, null);
            }
            var m = b.BindMethodCall(e, sym, args, out boundSelf, out writeBack);

            return(new MethodCallExpr(e, args)
            {
                Symbol = m, Datatype = m.Type(), Self = boundSelf, WriteBack = writeBack
            });
        }
示例#12
0
 NativeArrayAccessExpr(Expr e, ArgList a) : base(e, a)
 {
 }
示例#13
0
        internal override Node Bind(Binder b)
        {
            b.OpenScope();
            b.Bind(ref Key);
            Key.RequireGetAccess();
            if (Key.Datatype.IsValueType)
            {
                throw Error(ErrorCode.RequireReferenceType);
            }
            b.Bind(ref Stmt);
            b.CloseScope();

            var k = b.AddLocal(Compilation.Get(NativeType.Object));

            b.Convert(ref Key, Compilation.Get(NativeType.Object));
            var kdecl = DeclStmt.Bound(VarDecl.Bound(k, Key, b.Options.Binding));

            var l     = b.AddLocal(Compilation.Get(NativeType.Boolean));
            var ldecl = DeclStmt.Bound(VarDecl.Bound(l, LiteralExpr.Bound(Constant.Create(false)), b.Options.Binding));

            var enter = ExprStmt.Bound(MethodCallExpr.Bound(b, null, Compilation.Get(WellKnownMembers.System_Threading_Monitor_Enter), null, ArgList.Bound(IdExpr.Bound(k), IdExpr.Bound(l))));
            var exit  = IfStmt.Bound(IdExpr.Bound(l),
                                     ExprStmt.Bound(MethodCallExpr.Bound(b, null, Compilation.Get(WellKnownMembers.System_Threading_Monitor_Exit), null, ArgList.Bound(IdExpr.Bound(k)))),
                                     null);

            return(StmtBlock.Bound(kdecl, ldecl,
                                   TryStmt.Bound(b,
                                                 StmtBlock.Bound(enter, Stmt),
                                                 exit)));
        }
示例#14
0
 internal override Node Bind(Binder b)
 {
     b.OpenScope();
     b.Bind(ref Stmt);
     Stmt = TryStmt.Bound(b,
                          StmtBlock.Bound(
                              ExprStmt.Bound(MethodCallExpr.Bound(null, Compilation.Get(WellKnownMembers.XSharp_Internal_CompilerServices_EnterBeginSequence), null, ArgList.Empty)),
                              Stmt),
                          ExprStmt.Bound(MethodCallExpr.Bound(null, Compilation.Get(WellKnownMembers.XSharp_Internal_CompilerServices_ExitBeginSequence), null, ArgList.Empty))
                          );
     b.CloseScope();
     if (Recover != null)
     {
         b.OpenScope();
         var rv = b.AddLocal(Name.Value, b.ObjectType);
         b.Bind(ref Recover);
         ExVar = b.AddLocal(Compilation.Get(WellKnownTypes.System_Exception));
         Expr rvxw   = MethodCallExpr.Bound(b, TypeCast.Bound(b, IdExpr.Bound(ExVar), Compilation.Get(WellKnownTypes.XSharp_Internal_WrappedException)), "get_Value", ArgList.Empty);
         Expr rvxe   = TypeCast.Bound(b, IdExpr.Bound(ExVar), Compilation.Get(WellKnownTypes.XSharp_Error));
         Expr rvx    = MethodCallExpr.Bound(null, Compilation.Get(WellKnownMembers.XSharp_Error_WrapRawException), null, ArgList.Bound(TypeCast.Bound(b, IdExpr.Bound(ExVar), Compilation.Get(WellKnownTypes.System_Exception))));
         var  rvInit =
             IifExpr.Bound(IsExpr.Bound(IdExpr.Bound(ExVar), IdExpr.Bound(Compilation.Get(WellKnownTypes.XSharp_Internal_WrappedException))), TypeConversion.Bound(b, rvxw, Compilation.Get(NativeType.Usual)),
                           IifExpr.Bound(IsExpr.Bound(IdExpr.Bound(ExVar), IdExpr.Bound(Compilation.Get(WellKnownTypes.XSharp_Error))), TypeConversion.Bound(b, rvxe, Compilation.Get(NativeType.Usual)),
                                         rvx,
                                         b.Options.Binding),
                           b.Options.Binding);
         var rvdecl = DeclStmt.Bound(VarDecl.Bound(rv, rvInit, b.Options.Binding));
         Recover = StmtBlock.Bound(rvdecl, Recover);
         b.CloseScope();
     }
     if (Finally != null)
     {
         bool ar = SaveAllowReturn(b);
         b.OpenScope();
         b.Bind(ref Finally);
         b.CloseScope();
         RestoreAllowReturn(b, ar);
     }
     return(TryStmt.Bound(b, Stmt, CatchBlock.Bound(ExVar, Recover), Finally));
 }
示例#15
0
 internal IntrinsicCallExpr(IdExpr e, ArgList a, IntrinsicCallType t) : base(e, a)
 {
     Kind = t;
 }
示例#16
0
 internal ArrayAccessExpr(Expr e, ArgList a) : base(e, a)
 {
 }
示例#17
0
        internal override Node Bind(Binder b)
        {
            // TODO: Handle IS
            if (IsIsType)
            {
                throw Type.Error(ErrorCode.NotSupported, "IS");
            }

            // TODO: Handle DIM, array sub peroperly (according to full compiler)
            if (IsDim && ArraySub == null)
            {
                throw Error(ErrorCode.Expected, "array specifier");
            }
            bool isDim   = IsDim && ArraySub != null;
            bool isArray = !IsDim && ArraySub != null;

            if (ArraySub != null)
            {
                for (int i = 0; i < ArraySub.Length; i++)
                {
                    b.Bind(ref ArraySub[i]);
                }
            }

            TypeSymbol t = b.ObjectType;

            if (Type != null)
            {
                b.Bind(ref Type, BindAffinity.Type);
                Type.RequireType();
                t = Type.Symbol as TypeSymbol;
            }
            if (isDim)
            {
                t = Binder.ArrayOf(t, ArraySub.Length);
            }
            else if (isArray && Type == null)
            {
                t = Compilation.Get(NativeType.Array);
            }
            Symbol = b.AddLocal(Name, t) ?? throw Error(ErrorCode.LocalSameName, Name);
            if (Initializer != null)
            {
                b.Bind(ref Initializer);
                Initializer.RequireGetAccess();
                if (IsConst)
                {
                    if (!Initializer.IsConstant)
                    {
                        throw Error(ErrorCode.ValueNotConst);
                    }
                    Var.SetConst();
                }
                b.Convert(ref Initializer, Var.Type);
                Initializer = InitExpr.Bound(IdExpr.Bound(Var), Initializer, b.Options.Binding);
            }
            else if (IsConst)
            {
                throw Error(ErrorCode.ConstWithoutInitializer);
            }
            else if (isDim)
            {
                Initializer = InitExpr.Bound(IdExpr.Bound(Var), CtorCallExpr.Bound(b, IdExpr.Bound(t), ArgList.Bound(ArraySub)), b.Options.Binding);
            }
            else if (isArray)
            {
                Initializer = InitExpr.Bound(IdExpr.Bound(Var), MethodCallExpr.Bound(b, null, Compilation.Get(WellKnownMembers.XSharp___Array___ArrayNew), null, ArgList.Bound(ArraySub)), b.Options.Binding);
            }
            return(null);
        }