Пример #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);
        }
Пример #2
0
        /// <summary>
        /// Processes the r node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private bool processRNode(INodeAST node)
        {
            //require available searcher
            if (_searcher == null)
            {
                //new searcher is needed, based on current object
                if (_currentObject == null)
                {
                    //object is needed for searcher creation
                    //in current state - hierarchy has to be continuous
                    return(false);
                }

                _searcher = createMethodSearcher(_currentObject);
            }

            //search within the searcher
            dispatchByNode(_searcher, node, false);

            if (_searcher.HasResults)
            {
                //there are possible overloads for call
                return(setCalledObject(node, false));
            }
            else
            {
                //methods are not available - probably namespace
                //cascade is processed
                return(extendName(node));
            }
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// Sets the called object.
        /// </summary>
        /// <param name="currNode">The curr node.</param>
        /// <param name="dispatchSetter">if set to <c>true</c> [dispatch setter].</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private bool setCalledObject(INodeAST currNode, bool dispatchSetter)
        {
            var resolvedCall = resolveCall(_currentObject, currNode, _searcher.FoundResult);

            if (resolvedCall == null || !setCurrentObject(resolvedCall, currNode, dispatchSetter))
            {
                return(false);
            }

            //old searcher is not needed now
            _searcher = null;
            return(true);
        }
Пример #5
0
        /// <summary>
        /// Dispatch given searcher by node. It means that dispatch
        /// calls on searcher will be called according to node value and structure.
        /// </summary>
        /// <param name="searcher">Searcher which is dispatched.</param>
        /// <param name="node">Node dispatching searcher.</param>
        /// <param name="dispatchSetter">Determine that only setter will be dispatche, otherwise only getter will be dispatched.</param>
        /// <exception cref="System.NotSupportedException">Cannot resolve given node type inside hierarchy</exception>
        private void dispatchByNode(MethodSearcher searcher, INodeAST node, bool dispatchSetter)
        {
            var name = Context.MapGeneric(node.Value);

            switch (node.NodeType)
            {
            case NodeTypes.hierarchy:
                if (dispatchSetter)
                {
                    if (node.Indexer != null)
                    {
                        //indexer setters are handled in different way than getters
                        searcher.Dispatch(Naming.IndexerSetter);
                    }
                    else
                    {
                        searcher.Dispatch(Naming.SetterPrefix + name);
                    }
                }
                else
                {
                    searcher.Dispatch(Naming.GetterPrefix + name);
                }
                break;

            case NodeTypes.call:

                //handle special name conventions
                switch (name)
                {
                case CSharpSyntax.ThisVariable:
                case CSharpSyntax.BaseVariable:
                    name = Naming.CtorName;
                    break;
                }

                //dispatch by name
                searcher.Dispatch(name);
                break;

            default:
                throw new NotSupportedException("Cannot resolve given node type inside hierarchy");
            }
        }