Exemplo n.º 1
0
        /// <summary>
        /// Sets the current object.
        /// </summary>
        /// <param name="calledObject">The called object.</param>
        /// <param name="currNode">The curr node.</param>
        /// <param name="dispatchSetter">if set to <c>true</c> [dispatch setter].</param>
        /// <returns><c>true</c> if current object is correctly set, <c>false</c> otherwise.</returns>
        private bool setCurrentObject(RValueProvider calledObject, INodeAST currNode, bool dispatchSetter)
        {
            if (calledObject != null && currNode != null && currNode.Indexer != null)
            {
                if (dispatchSetter)
                {
                    //nothing to do here - setters are created in LNode value processing
                }
                else
                {
                    var searcher = createMethodSearcher(calledObject);
                    searcher.Dispatch(Naming.IndexerGetter);
                    calledObject = resolveCall(calledObject, currNode, searcher.FoundResult);
                    if (calledObject == null)
                    {
                        //indexer hasn't been found
                        return(false);
                    }

                    //reset searcher, because object has been found
                    _searcher = null;
                }
            }

            _currentObject = calledObject;
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Try to get call hierarchy (chained calls, properties, indexes, namespaces and statit classes).
        /// </summary>
        /// <param name="call">Result representation of call hierarchy.</param>
        /// <param name="calledObject">Object on which call hierarchy starts if any.</param>
        /// <returns><c>true</c> if call hierarchy is recognized, <c>false</c> otherwise.</returns>
        internal bool TryGetSetter(out LValueProvider call, RValueProvider calledObject)
        {
            var currNode = initializeCallSearch(calledObject, _entryNode.Child == null);

            while (currNode != null)
            {
                if (currNode.Child == null)
                {
                    //setter could be only the last child in hierarchy
                    call = processLNode(currNode);
                    return(call != null);
                }

                if (!processRNode(currNode))
                {
                    break;
                }

                currNode = currNode.Child;

                //there is indexer on last child - get it as rvalue
                if (currNode.Child == null && currNode.Indexer != null && !processRNode(currNode))
                {
                    //indexer setters are handled in
                    //different way than getters
                    break;
                }
            }

            //setter hasnt been found
            call = null;
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Resolves the call.
        /// </summary>
        /// <param name="calledObject">The called object.</param>
        /// <param name="currNode">The curr node.</param>
        /// <param name="overloads">The overloads.</param>
        /// <returns>CallValue.</returns>
        private CallValue resolveCall(RValueProvider calledObject, INodeAST currNode, IEnumerable <TypeMethodInfo> overloads)
        {
            var callActivation = _compiler.CreateCallActivation(calledObject, currNode, overloads);

            if (callActivation == null)
            {
                //overloads doesnt match to arguments
                return(null);
            }

            return(new CallValue(callActivation, Context));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes the call search.
        /// </summary>
        /// <param name="calledObject">The called object.</param>
        /// <param name="dispatchSetter">if set to <c>true</c> [dispatch setter].</param>
        /// <returns>INodeAST.</returns>
        private INodeAST initializeCallSearch(RValueProvider calledObject, bool dispatchSetter)
        {
            _searcher = createMethodSearcher(calledObject);
            setCurrentObject(calledObject, _entryNode, dispatchSetter && _entryNode.Child == null);

            var isCallNode    = _entryNode.NodeType == NodeTypes.call;
            var needEntryNode = calledObject == null || dispatchSetter || isCallNode;
            //if there is a called object, entry node has been already used for it
            var currNode = needEntryNode ? _entryNode : _entryNode.Child;

            return(currNode);
        }
Exemplo n.º 5
0
        public SetterLValue(TypeMethodInfo setter, RValueProvider thisObject, IEnumerable <Argument> positionalArguments, CompilationContext context)
            : base(context)
        {
            _setter    = setter;
            _thisObjet = thisObject;
            //defensive copy
            _positionArguments = positionalArguments.ToArray();

            if (!_setter.IsStatic && thisObject == null)
            {
                throw new ArgumentNullException("thisObject");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Try to get call hierarchy (chained calls, properties, indexes, namespaces and statit classes).
        /// </summary>
        /// <param name="call">Result representation of call hierarchy.</param>
        /// <param name="calledObject">Object on which call hierarchy starts if any.</param>
        /// <returns><c>true</c> if call hierarchy is recognized, <c>false</c> otherwise.</returns>
        internal bool TryGetCall(out RValueProvider call, RValueProvider calledObject)
        {
            var currNode = initializeCallSearch(calledObject, false);

            while (currNode != null)
            {
                if (!processRNode(currNode))
                {
                    break;
                }

                currNode = currNode.Child;
            }

            call = _currentObject;

            //if searcher is null, it means that there are no
            //buffered nodes left within the searcher
            return(_searcher == null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create method searcher filled with valid namespaces according to calledObject.
        /// </summary>
        /// <param name="calledObject">The called object.</param>
        /// <returns>Created <see cref="MethodSearcher" />.</returns>
        private MethodSearcher createMethodSearcher(RValueProvider calledObject)
        {
            //x without base can resolve to:
            //[this namespace].this.get_x /this.set_x
            //[this namespace].[static class x]
            //[this namespace].[namespace x]
            //[imported namespaces].[static class x]
            //[imported namespaces].[namespace x]

            var searcher = Context.CreateSearcher();

            if (calledObject == null)
            {
                searcher.ExtendName(_compiler.Namespaces.ToArray());
            }
            else
            {
                var calledObjectInfo = calledObject.Type;
                searcher.SetCalledObject(calledObjectInfo);
            }
            return(searcher);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Add call argument into current activation.
 /// <remarks>Ordering of arguments is considered</remarks>
 /// </summary>
 /// <param name="arg">Added argument</param>
 internal void AddArgument(RValueProvider arg)
 {
     _arguments.Add(arg);
 }
Exemplo n.º 9
0
 public ImplicitCastRValue(RValueProvider castedValue, TypeDescriptor castedType, CompilationContext context)
     : base(context)
 {
     _castedValue = castedValue;
     CastedType   = castedType;
 }
Exemplo n.º 10
0
 internal void SetCtor(RValueProvider ctorCall)
 {
     _ctorCall = ctorCall;
 }
Exemplo n.º 11
0
 internal Argument(RValueProvider value)
 {
     Value = value;
     Name  = null;
 }