コード例 #1
0
ファイル: functionscope.cs プロジェクト: formist/LinkMe
        internal bool IsReferenced(Dictionary <ActivationObject, ActivationObject> visited)
        {
            // first off, if the parent scope of this scope is a global scope,
            // then we're a global function and referenced by default.
            if (Parent is GlobalScope)
            {
                return(true);
            }

            // if we were passed null, then create a new hash table for us to pass on
            if (visited == null)
            {
                visited = new Dictionary <ActivationObject, ActivationObject>();
            }

            // add our scope to the visited hash
            if (!visited.ContainsKey(this))
            {
                visited.Add(this, this);
            }

            // now we walk the hash of referencing scopes and try to find one that that is
            if (m_refScopes != null)
            {
                foreach (ActivationObject referencingScope in m_refScopes.Keys)
                {
                    // skip any that we've already been to
                    if (!visited.ContainsKey(referencingScope))
                    {
                        // if we are referenced by the global scope, then we are referenced
                        if (referencingScope is GlobalScope)
                        {
                            return(true);
                        }

                        // if this is a function scope, traverse through it
                        FunctionScope functionScope = referencingScope as FunctionScope;
                        if (functionScope != null && functionScope.IsReferenced(visited))
                        {
                            return(true);
                        }
                    }
                }
            }

            // if we get here, then we didn't find any referencing scopes
            // that were referenced
            return(false);
        }
コード例 #2
0
        internal bool IsReferenced(int fieldRefCount)
        {
            // function expressions, getters, and setters are always referenced.
            // for function declarations, if the field refcount is zero, then we know we're not referenced.
            // otherwise, let's check with the scopes to see what's up.
            bool isReferenced = false;

            if (FunctionType != FunctionType.Declaration)
            {
                isReferenced = true;
            }
            else if (fieldRefCount > 0)
            {
                // we are going to visit each referenced scope and ask if any are
                // referenced. If any one is, then we are too. Since this will be a graph,
                // keep a hashtable of visited scopes so we don't get into endless loops.
                isReferenced = m_functionScope.IsReferenced(null);
            }
            return(isReferenced);
        }