Ejemplo n.º 1
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)));
        }
Ejemplo n.º 2
0
 internal override Node Bind(Binder b)
 {
     if (Params != null)
     {
         foreach (var p in Params)
         {
             b.AddLocal(p.LookupName, b.ObjectType);
             p.Bind(b);
         }
     }
     ParamArray = b.AddParam(XSharpSpecialNames.ClipperArgs, Binder.ArrayOf(b.ObjectType));
     b.AddConstant(XSharpSpecialNames.ClipperArgCount, Constant.Create(Params?.Count ?? 0));
     PCount = b.AddLocal(XSharpSpecialNames.ClipperPCount, Compilation.Get(NativeType.Int32));
     if (Body != null)
     {
         b.Bind(ref Body);
         if (Body.Datatype.NativeType != NativeType.Void)
         {
             Expr e = Body.Exprs.Last();
             b.Convert(ref e, b.ObjectType);
             Body.Exprs[Body.Exprs.Count - 1] = e;
         }
     }
     Symbol = b.ObjectType;
     return(null);
 }
Ejemplo n.º 3
0
 internal override Node Bind(Binder b)
 {
     // TODO: do not allow multiple unfiltered catch blocks of the same type
     b.OpenScope();
     if (Type != null)
     {
         b.Bind(ref Type, BindAffinity.Type);
         Type.RequireType();
         if (!Compilation.Get(WellKnownTypes.System_Exception).IsAssignableFrom(Type.Symbol as TypeSymbol))
         {
             Type.ThrowError(ErrorCode.TypeMustDeriveFrom, Compilation.Get(WellKnownTypes.System_Exception).FullName);
         }
         ExVar = b.AddLocal(Name.Value, Type.Symbol as TypeSymbol);
     }
     else if (Name != null)
     {
         ExVar = b.AddLocal(Name.Value, Compilation.Get(NativeType.Object));
     }
     else
     {
         ExVar = b.AddLocal(Compilation.Get(NativeType.Object));
     }
     if (When != null)
     {
         // TODO: support filtered exceptions
         b.Bind(ref When);
         When.RequireGetAccess();
         When.ThrowError(ErrorCode.NotSupported, "WHEN");
     }
     b.Bind(ref Stmt);
     b.CloseScope();
     return(null);
 }
Ejemplo n.º 4
0
        internal override Node Bind(Binder b)
        {
            b.OpenScope();

            b.Bind(ref Expr);
            Expr.RequireGetAccess();

            if (Expr.Datatype.IsArray && Expr.Datatype.ArrayRank == 1)
            {
                var array = b.Cache(ref Expr);
                var iter  = b.AddLocal(Compilation.Get(NativeType.Int32));
                IterDecl  = VarDecl.Bound(iter, LiteralExpr.Bound(Constant.Create(b.Options.ArrayBase)), b.Options.Binding);
                WhileExpr = BinaryExpr.Bound(IdExpr.Bound(iter), Token,
                                             MethodCallExpr.Bound(array, Compilation.Get(WellKnownMembers.System_Array_get_Length), array, ArgList.Empty),
                                             b.Options.ArrayZero ? BinaryOperatorKind.LessThan : BinaryOperatorKind.LessThanOrEqual, b.Options.Binding);
                IncrExpr            = AssignOpExpr.Bound(IdExpr.Bound(iter), LiteralExpr.Bound(Constant.Create(1)), BinaryOperatorKind.Addition, b);
                ForDecl.Initializer = ArrayAccessExpr.Bound(array, new ArgList(new List <Arg>(1)
                {
                    new Arg(IdExpr.Bound(iter))
                }), b);
            }
            else
            {
                if (Expr.Datatype.IsUsualOrObject() && b.Options.Binding.HasFlag(BindOptions.AllowDynamic))
                {
                    b.Convert(ref Expr, Compilation.Get(NativeType.Array));
                }
                Expr e          = b.Cache(ref Expr);
                var  getIterSym = e.Datatype.GetEnumeratorGetter() ?? throw Error(ErrorCode.NoSuitableEnumerator);
                var  getIter    = MethodCallExpr.Bound(e, getIterSym, e, ArgList.Empty);
                var  iter       = b.AddLocal(getIter.Datatype);
                IterDecl  = VarDecl.Bound(iter, getIter, b.Options.Binding);
                WhileExpr = MethodCallExpr.Bound(b, IdExpr.Bound(iter), SystemNames.MoveNext, ArgList.Empty);
                b.Convert(ref WhileExpr, Compilation.Get(NativeType.Boolean));
                ForDecl.Initializer = MethodCallExpr.Bound(b, IdExpr.Bound(iter), SystemNames.CurrentGetter, ArgList.Empty);
                Dispose             = Compilation.Get(WellKnownTypes.System_IDisposable).IsAssignableFrom(getIter.Datatype);
                if (Dispose)
                {
                    RequireExceptionHandling = true;
                }
            }

            b.Bind(ref ForDecl);
            InnerDecl = ForDecl;

            Expr Iter;

            Iter = (ForDecl.Initializer as AssignExpr).Left;
            Iter.RequireGetAccess();

            b.Bind(ref Stmt);

            b.CloseScope();
            return(null);
        }
Ejemplo n.º 5
0
        internal override Node Bind(Binder b)
        {
            b.OpenScope();
            if (Expr != null)
            {
                b.Bind(ref Expr);
                Expr.RequireGetAccess();
            }
            else
            {
                b.Bind(ref Decl);
            }
            b.Bind(ref Stmt);
            b.CloseScope();

            var u     = Decl != null ? Decl.VarDecls[0].Var : b.AddLocal(Expr.Datatype);
            var udecl = Decl ?? DeclStmt.Bound(VarDecl.Bound(u, Expr, b.Options.Binding));

            Expr du = AsTypeExpr.Bound(IdExpr.Bound(u), IdExpr.Bound(Compilation.Get(WellKnownTypes.System_IDisposable)));

            b.Cache(ref du);
            var cond = BinaryExpr.Bound(du, Expr.Token, LiteralExpr.Bound(Constant.Null), BinaryOperatorKind.NotEqual, b.Options.Binding);
            var exit = IfStmt.Bound(cond,
                                    ExprStmt.Bound(MethodCallExpr.Bound(b, null, Compilation.Get(WellKnownMembers.System_IDisposable_Dispose), du, ArgList.Empty)),
                                    null);

            return(StmtBlock.Bound(udecl,
                                   TryStmt.Bound(b,
                                                 Stmt,
                                                 exit)));
        }
Ejemplo n.º 6
0
        internal override Node Bind(Binder b)
        {
            b.OpenScope();
            b.Bind(ref Expr);
            SwitchValue = b.AddLocal(Expr.Datatype);
            bool        hasDefault = false;
            SwitchBlock next       = null;

            for (var i = SwitchBlocks.Length - 1; i >= 0; i--)
            {
                b.Bind(ref SwitchBlocks[i]);
                var sb = SwitchBlocks[i];
                if (!(sb is SwitchBlockExpr) && !(sb is SwitchBlockType))
                {
                    if (hasDefault)
                    {
                        throw Error(ErrorCode.MultipleDefaultInSwitch, sb.Token);
                    }
                    hasDefault = true;
                }
                if (sb.FallThrough)
                {
                    sb.NextBlock = next;
                }
                else
                {
                    next = sb;
                }
            }
            b.CloseScope();
            return(null);
        }
Ejemplo n.º 7
0
 CachedExpr(Binder b, Expr e) : base(e.Token)
 {
     CompilerGenerated = true;
     Expr     = e;
     Local    = b.AddLocal(Expr.Datatype);
     Symbol   = Expr.Symbol;
     Datatype = Expr.Datatype;
 }
Ejemplo n.º 8
0
 internal override Node Bind(Binder b)
 {
     b.Entity = this;
     if (Params != null)
     {
         foreach (var p in Params)
         {
             b.AddLocal(p.LookupName, b.ObjectType, true);
             p.Bind(b);
         }
     }
     ParamArray = b.AddParam(XSharpSpecialNames.ClipperArgs, Binder.ArrayOf(b.ObjectType));
     b.AddConstant(XSharpSpecialNames.ClipperArgCount, Constant.Create(Params?.Count ?? 0));
     PCount = b.AddLocal(XSharpSpecialNames.ClipperPCount, Compilation.Get(NativeType.Int32));
     if (Body != null)
     {
         b.BindStmt(ref Body);
     }
     return(null);
 }
Ejemplo n.º 9
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));
 }
Ejemplo n.º 10
0
        internal override Node Bind(Binder b)
        {
            b.Entity = this;

            ParamArray = b.AddParam(XSharpSpecialNames.ClipperArgs, Binder.ArrayOf(b.ObjectType));
            //b.AddConstant(XSharpSpecialNames.ClipperArgCount, Constant.Create(Params?.Count ?? 0));
            PCount = b.AddLocal(XSharpSpecialNames.ClipperPCount, Compilation.Get(NativeType.Int32));

            Symbol = b.ObjectType;
            if (Body != null)
            {
                b.BindStmt(ref Body);
            }
            return(null);
        }
Ejemplo n.º 11
0
        internal override Node Bind(Binder b)
        {
            b.OpenScope();
            b.Bind(ref Type, BindAffinity.Type);
            Type.RequireType();
            var v = b.AddLocal(Type.Symbol as TypeSymbol);
            var s = b.FindOuter <SwitchStmt>() ?? throw Error(ErrorCode.Internal);

            Cond = IsVarExpr.Bound(IdExpr.Bound(s.SwitchValue), Type, v);
            b.Convert(ref Cond, Compilation.Get(NativeType.Boolean));
            if (When != null)
            {
                b.Bind(ref When);
                When.RequireGetAccess();
                b.Convert(ref When, Compilation.Get(NativeType.Boolean));
            }
            if (Stmt != null)
            {
                b.Bind(ref Stmt);
            }
            b.CloseScope();
            return(null);
        }
Ejemplo n.º 12
0
 internal override Node Bind(Binder b)
 {
     b.Bind(ref Initializer);
     Initializer.RequireGetAccess();
     if (IsConst && Initializer is LiteralExpr c)
     {
         Symbol = b.AddConstant(Name, (Constant)c.Symbol) ?? throw Error(ErrorCode.LocalSameName, Name);
     }
     else
     {
         Symbol = b.AddLocal(Name, Initializer.Datatype) ?? throw Error(ErrorCode.LocalSameName, Name);
         if (IsConst)
         {
             if (Initializer?.IsConstant != true)
             {
                 throw Error(ErrorCode.ValueNotConst);
             }
             Var.SetConst();
         }
         Initializer = InitExpr.Bound(IdExpr.Bound(Var), Initializer, b.Options.Binding);
     }
     return(null);
 }
Ejemplo n.º 13
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);
        }