protected override Expression DoResolve(ResolveContext ec) { if (ec.Target == Target.JavaScript) { type = ec.BuiltinTypes.Dynamic; eclass = ExprClass.Value; return(this); } if (Expr is AsArrayInitializer) { return(Expr.Resolve(ec)); } New newExpr = null; if (Expr is Invocation) { var inv = Expr as Invocation; newExpr = new New(inv.Exp, inv.Arguments, loc); } else if (Expr is ElementAccess) { if (loc.SourceFile != null && !loc.SourceFile.PsExtended) { ec.Report.Error(7103, loc, "Native arrays are only suppored in ASX.'"); return(null); } var elemAcc = Expr as ElementAccess; var exprList = new List <Expression>(); foreach (var arg in elemAcc.Arguments) { exprList.Add(arg.Expr); } // TODO: Handle jagged arrays var arrayCreate = new ArrayCreation((FullNamedExpression)elemAcc.Expr, exprList, new ComposedTypeSpecifier(exprList.Count, loc), null, loc); return(arrayCreate.Resolve(ec)); } else { var resolveExpr = Expr.Resolve(ec); if (resolveExpr == null) { return(null); } if (resolveExpr is TypeOf) { newExpr = new New(((TypeOf)resolveExpr).TypeExpression, new Arguments(0), loc); } else { newExpr = new New(resolveExpr, new Arguments(0), loc); } } return(newExpr.Resolve(ec)); }
public void VisitArrayCreation(ArrayCreation node) { var typeInfo = TypeInference.InferType(node.ContainedType, _context); node.Initializer.Accept(this); _emitter.Emit(OpCodes.Newarr, typeInfo); if (node.IsStatementExpression) { _emitter.Emit(OpCodes.Pop); } }
public override void VisitArrayCreation(ArrayCreation node) { Append("@("); foreach (var item in node.Initializer) { item.Accept(this); Append(","); } // Remove last , Builder.Remove(Builder.Length - 1, 1); Append(")"); }
protected override Expression DoResolve(ResolveContext rc) { // BEN: This won't work because the returned type won't pass Mono's type checkers. // if (rc.Target == Target.JavaScript) { // this.type = rc.Module.PredefinedTypes.AsArray.Resolve(); // this.eclass = ExprClass.Value; // foreach (var elem in Elements) // elem.Resolve (rc); // return this; // } TypeExpression type; if (vectorType != null) // For new <Type> [ initializer ] expressions.. { var elemTypeSpec = vectorType.ResolveAsType(rc); if (elemTypeSpec != null) { type = new TypeExpression( rc.Module.PredefinedTypes.AsVector.Resolve().MakeGenericType(rc, new [] { elemTypeSpec }), Location); } else { type = new TypeExpression(rc.Module.PredefinedTypes.AsArray.Resolve(), Location); } } else { type = new TypeExpression(rc.Module.PredefinedTypes.AsArray.Resolve(), Location); } TypeSpec typeSpec = type.ResolveAsType(rc.MemberContext); if (typeSpec.IsArray) { ArrayCreation arrayCreate = (ArrayCreation) new ArrayCreation(type, this).Resolve(rc); return(arrayCreate); } else { var initElems = new List <Expression>(); foreach (var e in elements) { initElems.Add(new CollectionElementInitializer(e)); } return(new NewInitialize(type, null, new CollectionOrObjectInitializers(initElems, Location), Location).Resolve(rc)); } }
public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args) { Arguments binder_args = new Arguments (member != null ? 5 : 3); bool is_member_access = member is MemberAccess; CSharpBinderFlags call_flags; if (!is_member_access && member is SimpleName) { call_flags = CSharpBinderFlags.InvokeSimpleName; is_member_access = true; } else { call_flags = 0; } binder_args.Add (new Argument (new BinderFlags (call_flags, this))); if (is_member_access) binder_args.Add (new Argument (new StringLiteral (ec.BuiltinTypes, member.Name, member.Location))); if (member != null && member.HasTypeArguments) { TypeArguments ta = member.TypeArguments; if (ta.Resolve (ec)) { var targs = new ArrayInitializer (ta.Count, loc); foreach (TypeSpec t in ta.Arguments) targs.Add (new TypeOf (t, loc)); binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation (targs, loc))); } } else if (is_member_access) { binder_args.Add (new Argument (new NullLiteral (loc))); } binder_args.Add (new Argument (new TypeOf (ec.CurrentType, loc))); Expression real_args; if (args == null) { // Cannot be null because .NET trips over real_args = new ArrayCreation ( new MemberAccess (GetBinderNamespace (loc), "CSharpArgumentInfo", loc), new ArrayInitializer (0, loc), loc); } else { real_args = new ImplicitlyTypedArrayCreation (args.CreateDynamicBinderArguments (ec), loc); } binder_args.Add (new Argument (real_args)); return new Invocation (GetBinder (is_member_access ? "InvokeMember" : "Invoke", loc), binder_args); }
public override void VisitArrayCreation(ArrayCreation node) { Append("new "); Append(node.Type); Append("[] { "); foreach (var element in node.Initializer) { element.Accept(this); Append(", "); } //Remove trailing comma Builder.Remove(Builder.Length - 2, 2); Append(" };"); }
void case_543() #line 4001 "cs-parser.jay" { if (yyVals[0+yyTop] == null) report.Error (1586, GetLocation (yyVals[-3+yyTop]), "Array creation must have array size or array initializer"); yyVal = new ArrayCreation ((FullNamedExpression) yyVals[-2+yyTop], (ComposedTypeSpecifier) yyVals[-1+yyTop], (ArrayInitializer) yyVals[0+yyTop], GetLocation (yyVals[-3+yyTop])); }
void case_542() #line 3993 "cs-parser.jay" { yyVal = new ArrayCreation ((FullNamedExpression) yyVals[-5+yyTop], (List<Expression>) yyVals[-3+yyTop], new ComposedTypeSpecifier (((List<Expression>) yyVals[-3+yyTop]).Count, GetLocation (yyVals[-4+yyTop])) { Next = (ComposedTypeSpecifier) yyVals[-1+yyTop] }, (ArrayInitializer) yyVals[0+yyTop], GetLocation (yyVals[-6+yyTop])); lbag.AddLocation (yyVal, GetLocation (yyVals[-4+yyTop]), GetLocation (yyVals[-2+yyTop])); }
protected override Expression DoResolve (ResolveContext ec) { if (ec.Target == Target.JavaScript) { type = ec.BuiltinTypes.Dynamic; eclass = ExprClass.Value; return this; } if (Expr is AsArrayInitializer) return Expr.Resolve (ec); New newExpr = null; if (Expr is Invocation) { var inv = Expr as Invocation; newExpr = new New(inv.Exp, inv.Arguments, loc); } else if (Expr is ElementAccess) { if (loc.SourceFile != null && !loc.SourceFile.PsExtended) { ec.Report.Error (7103, loc, "Native arrays are only suppored in ASX.'"); return null; } var elemAcc = Expr as ElementAccess; var exprList = new List<Expression>(); foreach (var arg in elemAcc.Arguments) { exprList.Add (arg.Expr); } // TODO: Handle jagged arrays var arrayCreate = new ArrayCreation ((FullNamedExpression) elemAcc.Expr, exprList, new ComposedTypeSpecifier (exprList.Count, loc), null, loc); return arrayCreate.Resolve (ec); } else { var resolveExpr = Expr.Resolve (ec); if (resolveExpr == null) return null; newExpr = new New(resolveExpr, new Arguments (0), loc); } return newExpr.Resolve (ec); }
public virtual object Visit (ArrayCreation arrayCreationExpression) { return null; }
public void VisitArrayCreation(ArrayCreation node) => InferSimpleType(node.ContainedType);
public override object Visit (ArrayCreation arrayCreationExpression) { var result = new ArrayCreateExpression (); var location = LocationsBag.GetLocations (arrayCreationExpression); result.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Location), ArrayCreateExpression.NewKeywordRole), ArrayCreateExpression.NewKeywordRole); if (arrayCreationExpression.TypeExpression != null) result.AddChild (ConvertToType (arrayCreationExpression.TypeExpression), Roles.Type); var next = arrayCreationExpression.Rank; if (arrayCreationExpression.Arguments != null) { // skip first array rank. next = next.Next; if (location != null) result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.LBracket), Roles.LBracket); var commaLocations = LocationsBag.GetLocations (arrayCreationExpression.Arguments); for (int i = 0; i < arrayCreationExpression.Arguments.Count; i++) { result.AddChild ((Expression)arrayCreationExpression.Arguments [i].Accept (this), Roles.Argument); if (commaLocations != null && i < commaLocations.Count) result.AddChild (new CSharpTokenNode (Convert (commaLocations [i]), Roles.Comma), Roles.Comma); } if (location != null && location.Count > 1) result.AddChild (new CSharpTokenNode (Convert (location [1]), Roles.RBracket), Roles.RBracket); } while (next != null) { ArraySpecifier spec = new ArraySpecifier (next.Dimension); var loc = LocationsBag.GetLocations (next); spec.AddChild (new CSharpTokenNode (Convert (next.Location), Roles.LBracket), Roles.LBracket); result.AddChild (spec, ArrayCreateExpression.AdditionalArraySpecifierRole); if (loc != null) result.AddChild (new CSharpTokenNode (Convert (loc [0]), Roles.RBracket), Roles.RBracket); next = next.Next; } if (arrayCreationExpression.Initializers != null) { var initLocation = LocationsBag.GetLocations (arrayCreationExpression.Initializers); ArrayInitializerExpression initializer = new ArrayInitializerExpression (); initializer.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Initializers.Location), Roles.LBrace), Roles.LBrace); var commaLocations = LocationsBag.GetLocations (arrayCreationExpression.Initializers.Elements); for (int i = 0; i < arrayCreationExpression.Initializers.Count; i++) { var init = arrayCreationExpression.Initializers [i]; if (init == null) continue; initializer.AddChild ((Expression)init.Accept (this), Roles.Expression); if (commaLocations != null && i < commaLocations.Count) { initializer.AddChild (new CSharpTokenNode (Convert (commaLocations [i]), Roles.Comma), Roles.Comma); } } if (initLocation != null) { if (initLocation.Count == 2) // optional comma initializer.AddChild (new CSharpTokenNode(Convert(initLocation [0]), Roles.Comma), Roles.Comma); initializer.AddChild (new CSharpTokenNode (Convert (initLocation [initLocation.Count - 1]), Roles.RBrace), Roles.RBrace); } result.AddChild (initializer, ArrayCreateExpression.InitializerRole); } return result; }
void case_545() #line 4015 "cs-parser.jay" { report.Error (178, GetLocation (yyVals[-1+yyTop]), "Invalid rank specifier, expecting `,' or `]'"); yyVal = new ArrayCreation ((FullNamedExpression) yyVals[-5+yyTop], null, GetLocation (yyVals[-6+yyTop])); }
public virtual void VisitArrayCreation(ArrayCreation node) { }
protected override Expression DoResolve(ResolveContext rc) { // BEN: This won't work because the returned type won't pass Mono's type checkers. // if (rc.Target == Target.JavaScript) { // this.type = rc.Module.PredefinedTypes.AsArray.Resolve(); // this.eclass = ExprClass.Value; // foreach (var elem in Elements) // elem.Resolve (rc); // return this; // } // Attempt to build simple const initializer bool is_const_init = false; TypeSpec const_type = null; if (elements.Count > 0) { is_const_init = true; const_type = vectorType != null?vectorType.ResolveAsType(rc) : null; foreach (var elem in elements) { if (elem == null) { is_const_init = false; break; } if (!(elem is Constant) && !(elem is Unary && ((Unary)elem).Expr is Constant)) { is_const_init = false; break; } TypeSpec elemType = elem.Type; if (vectorType == null) { if (elemType == null) { is_const_init = false; break; } if (const_type == null) { const_type = BuiltinTypeSpec.IsPrimitiveType(elemType) ? elemType : rc.BuiltinTypes.Object; } if (const_type != elemType) { if (((const_type == rc.BuiltinTypes.Int || const_type == rc.BuiltinTypes.UInt) && elemType == rc.BuiltinTypes.Double) || (const_type == rc.BuiltinTypes.Double && (elemType == rc.BuiltinTypes.Int || elemType == rc.BuiltinTypes.UInt))) { const_type = rc.BuiltinTypes.Double; } else { const_type = rc.BuiltinTypes.Object; } } } } } TypeExpression type; if (vectorType != null) // For new <Type> [ initializer ] expressions.. { var elemTypeSpec = vectorType.ResolveAsType(rc); if (elemTypeSpec != null) { type = new TypeExpression( rc.Module.PredefinedTypes.AsVector.Resolve().MakeGenericType(rc, new [] { elemTypeSpec }), Location); } else { type = new TypeExpression(rc.Module.PredefinedTypes.AsArray.Resolve(), Location); } } else { type = new TypeExpression(rc.Module.PredefinedTypes.AsArray.Resolve(), Location); } TypeSpec typeSpec = type.ResolveAsType(rc.MemberContext); if (typeSpec.IsArray) { ArrayCreation arrayCreate = (ArrayCreation) new ArrayCreation(type, this).Resolve(rc); return(arrayCreate); } else if (is_const_init) { // If all elements in the initializer list are simple constants, we just pass the elements in a .NET array to the // PS Array initializer. var newArgs = new Arguments(1); newArgs.Add(new Argument(new ArrayCreation(new TypeExpression(const_type, loc), this, loc))); return(new New(type, newArgs, loc).Resolve(rc)); } else { var initElems = new List <Expression>(); foreach (var e in elements) { initElems.Add(new CollectionElementInitializer(e)); } return(new NewInitialize(type, null, new CollectionOrObjectInitializers(initElems, Location), Location).Resolve(rc)); } }
public Expression CreateCallSiteBinder(ResolveContext ec, Arguments args) { Arguments binder_args = new Arguments(member != null ? 5 : 3); MemberAccess binder = GetBinderNamespace(loc); bool is_member_access = member is MemberAccess; string call_flags; if (!is_member_access && member is SimpleName) { call_flags = "SimpleNameCall"; is_member_access = true; } else { call_flags = "None"; } binder_args.Add(new Argument(new MemberAccess(new MemberAccess(binder, "CSharpCallFlags", loc), call_flags, loc))); if (is_member_access) { binder_args.Add(new Argument(new StringLiteral(member.Name, member.Location))); } binder_args.Add(new Argument(new TypeOf(new TypeExpression(ec.CurrentType, loc), loc))); if (member != null && member.HasTypeArguments) { TypeArguments ta = member.TypeArguments; if (ta.Resolve(ec)) { ArrayList targs = new ArrayList(ta.Count); foreach (Type t in ta.Arguments) { targs.Add(new TypeOf(new TypeExpression(t, loc), loc)); } binder_args.Add(new Argument(new ImplicitlyTypedArrayCreation("[]", targs, loc))); } } else if (is_member_access) { binder_args.Add(new Argument(new NullLiteral(loc))); } Expression real_args; if (args == null) { // Cannot be null because .NET trips over real_args = new ArrayCreation(new MemberAccess(binder, "CSharpArgumentInfo", loc), "[]", new ArrayList(0), loc); } else { real_args = new ImplicitlyTypedArrayCreation("[]", args.CreateDynamicBinderArguments(), loc); } binder_args.Add(new Argument(real_args)); return(new New(new MemberAccess(binder, is_member_access ? "CSharpInvokeMemberBinder" : "CSharpInvokeBinder", loc), binder_args, loc)); }
protected override Expression DoResolve(ResolveContext ec) { if (ec.Target == Target.JavaScript) { type = ec.BuiltinTypes.Dynamic; eclass = ExprClass.Value; return(this); } if (Expr is AsArrayInitializer) { return(Expr.Resolve(ec)); } New newExpr = null; if (Expr is Invocation) { var inv = Expr as Invocation; // // Special case for PlayScript scalar types with 1 argument - // just do an assignment. This is required for cosntructs like // // var num:Number = new Number(1.0); // // since the underlying C# types are primitives and don't have // constructors which take arugments. // var sn = inv.Exp as SimpleName; if (sn != null && IsPlayScriptScalarClass(sn.Name) && inv.Arguments != null && inv.Arguments.Count == 1) { Argument arg = inv.Arguments [0].Clone(new CloneContext()); arg.Resolve(ec); if (arg.Expr.Type != null) { if (BuiltinTypeSpec.IsPrimitiveType(arg.Expr.Type) || arg.Expr.Type.BuiltinType == BuiltinTypeSpec.Type.String) { return(arg.Expr); } } // TODO: ActionScript does actually allow this, but its runtime // rules are hard to implement at compile time, and this should // be a rare use case, so I am leaving it as a compiler error for // now. ec.Report.Error(7112, loc, "The type `{0}' does not contain a constructor that takes non-scalar arguments", sn.Name); return(null); } newExpr = new New(inv.Exp, inv.Arguments, loc); } else if (Expr is ElementAccess) { if (loc.SourceFile != null && !loc.SourceFile.PsExtended) { ec.Report.Error(7103, loc, "Native arrays are only suppored in ASX.'"); return(null); } var elemAcc = Expr as ElementAccess; var exprList = new List <Expression>(); foreach (var arg in elemAcc.Arguments) { exprList.Add(arg.Expr); } // TODO: Handle jagged arrays var arrayCreate = new ArrayCreation((FullNamedExpression)elemAcc.Expr, exprList, new ComposedTypeSpecifier(exprList.Count, loc), null, loc); return(arrayCreate.Resolve(ec)); } else { var resolveExpr = Expr.Resolve(ec); if (resolveExpr == null) { return(null); } if (resolveExpr is TypeOf) { newExpr = new New(((TypeOf)resolveExpr).TypeExpression, new Arguments(0), loc); } else { newExpr = new New(resolveExpr, new Arguments(0), loc); } } return(newExpr.Resolve(ec)); }
protected internal Expression VisitArrayCreation(ArrayCreation arrayCreation) { return(arrayCreation.Update(arrayCreation.Initializers, arrayCreation.Bounds)); }
public virtual object Visit(ArrayCreation arrayCreationExpression) { return(null); }
/// <summary> /// IExpressionリスト取得 /// </summary> /// <param name="operation">IOperationインスタンス</param> /// <param name="container">イベントコンテナ</param> /// <returns>IExpressionリスト</returns> public static List <IExpression> GetExpressionList(IOperation operation, EventContainer container) { List <IExpression> result = new List <IExpression>(); AbstractOperation instance = null; switch (operation) { // 式系 case ISimpleAssignmentOperation param: instance = new SimpleAssignment(param, container); break; case IInvocationOperation param: instance = new Invocation(param, container); break; case IBinaryOperation param: instance = new Binary(param, container); break; case IIncrementOrDecrementOperation param: instance = new Increment(param, container); break; case ICompoundAssignmentOperation param: instance = new CompoundAssignment(param, container); break; case IConversionOperation param: result.AddRange(GetExpressionList(param.Operand, container)); break; // 参照系 case IInstanceReferenceOperation param: instance = new InstanceReference(param, container); break; case IFieldReferenceOperation param: instance = new FieldReference(param, container); break; case IPropertyReferenceOperation param: instance = new PropertyReference(param, container); break; case ILocalReferenceOperation param: instance = new LocalReference(param, container); break; case IParameterReferenceOperation param: instance = new ParameterReference(param, container); break; case IArrayElementReferenceOperation param: instance = new ArrayElementReference(param, container); break; case IArgumentOperation param: instance = new Argument(param, container); break; // 生成系 case IObjectCreationOperation param: instance = new ObjectCreation(param, container); break; case IArrayCreationOperation param: instance = new ArrayCreation(param, container); break; case IArrayInitializerOperation param: instance = new ArrayInitializer(param, container); break; case IVariableDeclaratorOperation param: instance = new VariableDeclarator(param, container); break; // 直値 case ILiteralOperation param: instance = new Literal(param, container); break; // Switch Case系 case IDefaultCaseClauseOperation param: instance = new DefalutCase(param, container); break; case IDeclarationPatternOperation param: instance = new DeclarationPattern(param, container); break; //If系 case IIsPatternOperation param: instance = new IsPattern(param, container); break; case IIsTypeOperation param: instance = new IsType(param, container); break; default: Console.Write($" [{operation.Kind} is none] "); break; } // リスト追加 if (instance != null) { result.AddRange(instance.Expressions); } return(result); }