// Resolve any dynamic params to the type of the target parameters list (for PlayScript only). public bool AsTryResolveDynamicArgs(ResolveContext ec, System.Collections.IEnumerable candidates) { AParametersCollection parameters = null; foreach (MemberSpec memberSpec in candidates) { AParametersCollection possibleParams = null; int fixedArgsLen = 0; if (memberSpec is MethodSpec) { MethodSpec methodSpec = memberSpec as MethodSpec; possibleParams = methodSpec.Parameters; fixedArgsLen = possibleParams.FixedParameters.Length; if (methodSpec.IsExtensionMethod) { fixedArgsLen--; } } else if (memberSpec is IndexerSpec) { IndexerSpec indexerSpec = memberSpec as IndexerSpec; possibleParams = indexerSpec.Parameters; fixedArgsLen = possibleParams.FixedParameters.Length; } if (fixedArgsLen == args.Count) { if (parameters != null) { parameters = null; // Can't be more than one - or we give up and do a dynamic call.. break; } parameters = possibleParams; } } if (parameters != null) { for (var i = 0; i < args.Count; i++) { var arg = args [i]; var paramType = parameters.Types [i]; if (arg.Expr.Type == ec.BuiltinTypes.Dynamic) { var parCastType = paramType.BuiltinType == BuiltinTypeSpec.Type.Dynamic ? ec.BuiltinTypes.Object : paramType; var new_arg = new Argument(new Cast( new TypeExpression(parCastType, arg.Expr.Location), arg.Expr, arg.Expr.Location), arg.ArgType); new_arg.Resolve(ec); args [i] = new_arg; } } return(true); } return(false); }
public bool AsTryResolveDynamicArgs(ResolveContext ec, MemberSpec memberSpec) { AParametersCollection parameters = null; int fixedArgsLen = 0; if (memberSpec is MethodSpec) { MethodSpec methodSpec = memberSpec as MethodSpec; parameters = methodSpec.Parameters; fixedArgsLen = parameters.FixedParameters.Length; if (methodSpec.IsExtensionMethod) { fixedArgsLen--; } } else if (memberSpec is IndexerSpec) { IndexerSpec indexerSpec = memberSpec as IndexerSpec; parameters = indexerSpec.Parameters; fixedArgsLen = parameters.FixedParameters.Length; } if (parameters == null) { return(false); } if (fixedArgsLen < args.Count) { // too many arguments return(false); } for (var i = 0; i < args.Count; i++) { var arg = args [i]; var paramType = parameters.Types [i]; if (arg.Expr.Type == ec.BuiltinTypes.Dynamic) { var parCastType = paramType.BuiltinType == BuiltinTypeSpec.Type.Dynamic ? ec.BuiltinTypes.Object : paramType; var new_arg = new Argument(new Cast( new TypeExpression(parCastType, arg.Expr.Location), arg.Expr, arg.Expr.Location), arg.ArgType); new_arg.Resolve(ec); args [i] = new_arg; } } return(true); }
// Resolve any dynamic params to the type of the target parameters list (for PlayScript only). public bool AsTryResolveDynamicArgs(ResolveContext ec, System.Collections.IEnumerable candidates) { MethodSpec ms = null; foreach (MethodSpec possibleMs in candidates) { if (possibleMs.Parameters.FixedParameters.Length <= args.Count && possibleMs.Parameters.Count >= args.Count) { if (ms != null) { ms = null; // Can't be more than one - or we give up and do a dynamic call.. break; } ms = possibleMs; } } if (ms != null) { var parameters = ms.Parameters; for (var i = 0; i < args.Count; i++) { var arg = args [i]; var paramType = parameters.Types [i]; if (arg.Expr.Type == ec.BuiltinTypes.Dynamic) { var parCastType = paramType.BuiltinType == BuiltinTypeSpec.Type.Dynamic ? ec.BuiltinTypes.Object : paramType; var new_arg = new Argument(new Cast( new TypeExpression(parCastType, arg.Expr.Location), arg.Expr, arg.Expr.Location), arg.ArgType); new_arg.Resolve(ec); args [i] = new_arg; } } return(true); } return(false); }
// Resolve any dynamic params to the type of the target parameters list (for PlayScript only). public bool AsTryResolveDynamicArgs (ResolveContext ec, System.Collections.IEnumerable candidates) { AParametersCollection parameters = null; foreach (MemberSpec memberSpec in candidates) { AParametersCollection possibleParams = null; int fixedArgsLen = 0; if (memberSpec is MethodSpec) { MethodSpec methodSpec = memberSpec as MethodSpec; possibleParams = methodSpec.Parameters; fixedArgsLen = possibleParams.FixedParameters.Length; if (methodSpec.IsExtensionMethod) fixedArgsLen--; } else if (memberSpec is IndexerSpec) { IndexerSpec indexerSpec = memberSpec as IndexerSpec; possibleParams = indexerSpec.Parameters; fixedArgsLen = possibleParams.FixedParameters.Length; } if (fixedArgsLen == args.Count) { if (parameters != null) { parameters = null; // Can't be more than one - or we give up and do a dynamic call.. break; } parameters = possibleParams; } } if (parameters != null) { for (var i = 0; i < args.Count; i++) { var arg = args [i]; var paramType = parameters.Types [i]; if (arg.Expr.Type == ec.BuiltinTypes.Dynamic) { var parCastType = paramType.BuiltinType == BuiltinTypeSpec.Type.Dynamic ? ec.BuiltinTypes.Object : paramType; var new_arg = new Argument (new Cast ( new TypeExpression (parCastType, arg.Expr.Location), arg.Expr, arg.Expr.Location), arg.ArgType); new_arg.Resolve (ec); args [i] = new_arg; } } return true; } return false; }
// Resolve any dynamic params to the type of the target parameters list (for PlayScript only). public bool AsTryResolveDynamicArgs (ResolveContext ec, System.Collections.IEnumerable candidates) { MethodSpec ms = null; foreach (MethodSpec possibleMs in candidates) { if (possibleMs.Parameters.FixedParameters.Length <= args.Count && possibleMs.Parameters.Count >= args.Count) { if (ms != null) { ms = null; // Can't be more than one - or we give up and do a dynamic call.. break; } ms = possibleMs; } } if (ms != null) { var parameters = ms.Parameters; for (var i = 0; i < args.Count; i++) { var arg = args [i]; var paramType = parameters.Types [i]; if (arg.Expr.Type == ec.BuiltinTypes.Dynamic) { var parCastType = paramType.BuiltinType == BuiltinTypeSpec.Type.Dynamic ? ec.BuiltinTypes.Object : paramType; var new_arg = new Argument (new Cast ( new TypeExpression (parCastType, arg.Expr.Location), arg.Expr, arg.Expr.Location), arg.ArgType); new_arg.Resolve (ec); args [i] = new_arg; } } return true; } return false; }
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)); }
public bool AsTryResolveDynamicArgs (ResolveContext ec, MemberSpec memberSpec) { AParametersCollection parameters = null; int fixedArgsLen = 0; if (memberSpec is MethodSpec) { MethodSpec methodSpec = memberSpec as MethodSpec; parameters = methodSpec.Parameters; fixedArgsLen = parameters.FixedParameters.Length; if (methodSpec.IsExtensionMethod) fixedArgsLen--; } else if (memberSpec is IndexerSpec) { IndexerSpec indexerSpec = memberSpec as IndexerSpec; parameters = indexerSpec.Parameters; fixedArgsLen = parameters.FixedParameters.Length; } if (parameters == null) { return false; } if (fixedArgsLen < args.Count) { // too many arguments return false; } for (var i = 0; i < args.Count; i++) { var arg = args [i]; var paramType = parameters.Types [i]; if (arg.Expr.Type == ec.BuiltinTypes.Dynamic) { var parCastType = paramType.BuiltinType == BuiltinTypeSpec.Type.Dynamic ? ec.BuiltinTypes.Object : paramType; var new_arg = new Argument (new Cast ( new TypeExpression (parCastType, arg.Expr.Location), arg.Expr, arg.Expr.Location), arg.ArgType); new_arg.Resolve (ec); args [i] = new_arg; } } return true; }