public Argument makeArgument(Context context, IMethodDeclaration declaration) { IParameter parameter = Parameter; // when 1st argument, can be unnamed if (parameter == null) { if (declaration.getParameters().Count == 0) { throw new SyntaxError("Method has no argument"); } parameter = declaration.getParameters()[0]; } else { parameter = declaration.getParameters().find(this.GetName()); } if (parameter == null) { throw new SyntaxError("Method has no argument:" + this.GetName()); } IExpression expression = new ContextualExpression(context, this.getExpression()); return(new Argument(parameter, expression)); }
private static ArgumentList buildArguments(IMethodDeclaration method, String cmdLineArgs) { ArgumentList arguments = new ArgumentList(); if (method.getParameters().Count == 1) { String name = method.getParameters()[0].GetName(); IExpression value = parseCmdLineArgs(cmdLineArgs); arguments.Add(new Argument(new UnresolvedParameter(name), value)); } return(arguments); }
public IMethodDeclaration findOperator(Context context, Operator oper, IType type) { String methodName = "operator_" + oper.ToString(); Dictionary <String, IMethodDeclaration> methods = getMemberMethods(context, methodName); if (methods == null) { return(null); } // find best candidate IMethodDeclaration candidate = null; foreach (IMethodDeclaration method in methods.Values) { IType potential = method.getParameters()[0].GetIType(context); if (!potential.isAssignableFrom(context, type)) { continue; } if (candidate == null) { candidate = method; } else { IType currentBest = candidate.getParameters()[0].GetIType(context); if (potential.isAssignableFrom(context, currentBest)) { candidate = method; } } } return(candidate); }
private IValue interpretOperator(Context context, IValue value, Operator oper) { IMethodDeclaration decl = declaration.findOperator(context, oper, value.GetIType()); context = context.newInstanceContext(this, false).newChildContext(); decl.registerParameters(context); IParameter arg = decl.getParameters()[0]; context.setValue(arg.GetName(), value); return(decl.interpret(context)); }
public IExpression resolve(Context context, IMethodDeclaration methodDeclaration, bool checkInstance) { // since we support implicit members, it's time to resolve them IExpression expression = getExpression(); IParameter argument = methodDeclaration.getParameters().find(name); IType required = argument.GetIType(context); IType actual = expression.check((Context)context.getCallingContext()); if (checkInstance && actual is CategoryType) { Object value = expression.interpret((Context)context.getCallingContext()); if (value is IInstance) { actual = ((IInstance)value).getType(); } } if (!required.isAssignableFrom(context, actual) && (actual is CategoryType)) { expression = new MemberSelector(expression, name); } return(expression); }
Score scoreMostSpecific(IMethodDeclaration d1, IMethodDeclaration d2, bool useInstance) { try { Context s1 = context.newLocalContext(); d1.registerParameters(s1); Context s2 = context.newLocalContext(); d2.registerParameters(s2); IEnumerator <Argument> it1 = methodCall.makeArguments(context, d1).GetEnumerator(); IEnumerator <Argument> it2 = methodCall.makeArguments(context, d2).GetEnumerator(); while (it1.MoveNext() && it2.MoveNext()) { Argument as1 = it1.Current; Argument as2 = it2.Current; IParameter ar1 = d1.getParameters().find(as1.GetName()); IParameter ar2 = d2.getParameters().find(as2.GetName()); if (as1.GetName().Equals(as2.GetName())) { // the general case with named arguments IType t1 = ar1.GetIType(s1); IType t2 = ar2.GetIType(s2); // try resolving runtime type if (useInstance && t1 is CategoryType && t2 is CategoryType) { Object value = as1.getExpression().interpret(context); // in the named case as1==as2, so only interpret 1 if (value is IInstance) { CategoryType actual = ((IInstance)value).getType(); Score score = actual.scoreMostSpecific(context, (CategoryType)t1, (CategoryType)t2); if (score != Score.SIMILAR) { return(score); } } } if (t1.isMoreSpecificThan(s2, t2)) { return(Score.BETTER); } if (t2.isMoreSpecificThan(s1, t1)) { return(Score.WORSE); } } else { // specific case for single anonymous argument Specificity?sp1 = d1.computeSpecificity(s1, ar1, as1, useInstance); Specificity?sp2 = d2.computeSpecificity(s2, ar2, as2, useInstance); if (sp1 > sp2) { return(Score.BETTER); } if (sp2 > sp1) { return(Score.WORSE); } } } } catch (PromptoError) { } return(Score.SIMILAR); }
private IParameter findParameter(IMethodDeclaration methodDeclaration) { String name = this.Parameter.GetName(); return(methodDeclaration.getParameters().find(name)); }
public ParameterList getParameters() { return(wrapped.getParameters()); }