예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
        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);
        }
예제 #6
0
 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);
 }
예제 #7
0
        private IParameter findParameter(IMethodDeclaration methodDeclaration)
        {
            String name = this.Parameter.GetName();

            return(methodDeclaration.getParameters().find(name));
        }
예제 #8
0
 public ParameterList getParameters()
 {
     return(wrapped.getParameters());
 }