private void AssignArray(object value, IScriptContext context)
        {
            object obj = context.GetItem(Identifier, true);

            foreach (ScriptAst node in Modifiers)
            {
                ScriptFunctionCall functionCall = node as ScriptFunctionCall;
                if (functionCall != null)
                {
                    obj = CallFunction(context.GetFunctionDefinition(Identifier), functionCall, context);
                    continue;
                }

                ScriptArrayResolution arrayResolution = node as ScriptArrayResolution;
                if (arrayResolution != null)
                {
                    SetArrayValue(obj, arrayResolution, context, value);
                    continue;
                }

                ScriptGenericsPostfix genericPostfix = node as ScriptGenericsPostfix;
                if (genericPostfix != null)
                {
                    throw new NotSupportedException();
                }
            }
        }
        private void EvaluateFunctionCall(IScriptContext context)
        {
            EvaluateIdentifier(context);

            foreach (ScriptAst node in Modifiers)
            {
                ScriptFunctionCall funcCall = node as ScriptFunctionCall;
                if (funcCall != null)
                {
                    IInvokable function = context.Result as IInvokable;
                    if (function == null)
                    {
                        throw new ScriptException("Is not a function type");
                    }
                    context.Result = CallFunction(function, funcCall, context);
                    continue;
                }

                ScriptArrayResolution arrayResolution = node as ScriptArrayResolution;
                if (arrayResolution != null)
                {
                    GetArrayValue(context.Result, arrayResolution, context);
                    continue;
                }

                ScriptGenericsPostfix genericPostfix = node as ScriptGenericsPostfix;
                if (genericPostfix != null)
                {
                    throw new NotSupportedException();
                    //genericPostfix.Evaluate(Context);
                    //continue;
                }
            }
        }
        private void AssignNamePart(object value, IScriptContext context)
        {
            NamePart.Evaluate(context);
            object obj = context.Result;

            if (Modifiers == null)
            {
                SetMember(context, obj, value);
                return;
            }

            //TODO: Bug, first evaluate get member, see unit test AssignmentToArrayObject
            string localIdentifier = Identifier;

            foreach (ScriptAst node in Modifiers)
            {
                ScriptFunctionCall scriptFunctionCall = node as ScriptFunctionCall;
                if (scriptFunctionCall != null)
                {
                    if (localIdentifier != null)
                    {
                        CallClassMethod(obj, localIdentifier, scriptFunctionCall, null, context);
                        obj             = context.Result;
                        localIdentifier = null;
                    }
                    else
                    {
                        IInvokable funcDef = obj as IInvokable;
                        if (funcDef == null)
                        {
                            throw new ScriptException("Attempt to invoke non IInvokable object.");
                        }
                        obj = CallFunction(funcDef, scriptFunctionCall, context);
                    }

                    continue;
                }

                ScriptArrayResolution scriptArrayResolution = node as ScriptArrayResolution;
                if (scriptArrayResolution != null)
                {
                    if (localIdentifier != null)
                    {
                        obj             = GetMemberValue(obj, localIdentifier);
                        localIdentifier = null;
                    }
                    SetArrayValue(obj, scriptArrayResolution, context, value);
                    continue;
                }
            }
        }
        private void EvaluateNamePart(IScriptContext context)
        {
            NamePart.Evaluate(context);
            object obj = context.Result;

            if (Modifiers == null)
            {
                context.Result = GetMemberValue(obj, Identifier);
                return;
            }

            Type[] genericArguments = null;
            foreach (ScriptAst node in Modifiers)
            {
                //NOTE: Generic modifier should be the first among other modifiers in the list
                ScriptGenericsPostfix generic = node as ScriptGenericsPostfix;
                if (generic != null)
                {
                    if (genericArguments != null)
                    {
                        throw new ScriptException("Wrong modifiers sequence");
                    }

                    generic.Execute(context);
                    genericArguments = (Type[])context.Result;
                    continue;
                }

                ScriptFunctionCall functionCall = node as ScriptFunctionCall;
                if (functionCall != null)
                {
                    CallClassMethod(obj, Identifier, functionCall, genericArguments, context);
                    continue;
                }

                ScriptArrayResolution arrayResolution = node as ScriptArrayResolution;
                if (arrayResolution != null)
                {
                    GetArrayValue(GetMemberValue(obj, Identifier), arrayResolution, context);
                    continue;
                }
            }
        }
 private void CallClassMethod(object obj, string memeberInfo, ScriptFunctionCall scriptFunctionCall, Type[] genericArguments, IScriptContext context)
 {
     scriptFunctionCall.Evaluate(context);
     context.Result = CallAppropriateMethod(context, obj, memeberInfo, genericArguments, (object[])context.Result);
 }
 private static object CallFunction(IInvokable functionDefinition, ScriptFunctionCall scriptFunctionCall, IScriptContext context)
 {
     scriptFunctionCall.Evaluate(context);
     return(functionDefinition.Invoke(context, (object[])context.Result));
 }
 public ScriptTypeConstructor(AstNodeArgs args)
     : base(args)
 {
     typeExpr = ChildNodes[0] as ScriptTypeExpr;
       callExpr = ChildNodes[1] as ScriptFunctionCall;
 }
 private void CallClassMethod(object obj, string memeberInfo, ScriptFunctionCall scriptFunctionCall, Type[] genericArguments, IScriptContext context)
 {
     scriptFunctionCall.Evaluate(context);
       context.Result = CallAppropriateMethod(context, obj, memeberInfo, genericArguments, (object[])context.Result);
 }
 private static object CallFunction(IInvokable functionDefinition, ScriptFunctionCall scriptFunctionCall, IScriptContext context)
 {
     scriptFunctionCall.Evaluate(context);
       return functionDefinition.Invoke(context, (object[])context.Result);
 }
Esempio n. 10
0
 public ScriptTypeConstructor(AstNodeArgs args)
     : base(args)
 {
     typeExpr = ChildNodes[0] as ScriptTypeExpr;
     callExpr = ChildNodes[1] as ScriptFunctionCall;
 }