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); }
private void ConvertElements(TypeSymbol et, TypeSymbol dt = null) { for (int i = 0; i < Values.Exprs.Count; i++) { var v = Values.Exprs[i]; Binder.Convert(ref v, et, BindOptions.Default); Values.Exprs[i] = v; } Symbol = et; Datatype = dt ?? Binder.ArrayOf(et); }
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); }
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); }
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); }