Beispiel #1
0
        /// <summary>
        /// Tries to get a resolved (cached) function and module literal for a current Functor.
        /// </summary>
        private bool TryGetFunctionToInvoke(Context context, ModuleLiteral env, out FunctionLikeExpression function, out FileModuleLiteral file)
        {
            // When decorators are supported, no optimizations should be used.
            var qualifierId = env.Qualifier.QualifierId.Id;

            if (context.HasDecorator || qualifierId >= MaxQualifierId)
            {
                function = null;
                file     = null;
                return(false);
            }

            // If the Functor is a regular named function call (i.e. FooBar in <code>function fooBar() {} const x = fooBar();</code>
            // Then we can resolve the function once and cache it, but we have to obtain the 'file literal'
            // that represents the target file for each qualifier.
            // That's why there is a single value for function and an array for module literals.

            file = m_fileLiterals[qualifierId];
            if (file != null)
            {
                // This is only possible when the function was already resolved at least once.
                function = m_functionToInvoke;
                return(function != null);
            }

            // The cache is cold. Resolving the function if possible.
            if (Functor is LocationBasedSymbolReference locationBased)
            {
                locationBased.TryResolveFunction(context, env, out function, out file);

                if (function != null && file != null)
                {
                    m_fileLiterals[qualifierId] = file;
                    m_functionToInvoke          = function;
                    return(true);
                }
            }

            function = null;
            return(false);
        }
 /// <summary>
 /// Resolve a current location-based reference as <see cref="FunctionLikeExpression"/>.
 /// </summary>
 /// <remarks>
 /// This method is used to resolve a function once and use it for all the invocations.
 /// </remarks>
 internal bool TryResolveFunction(Context context, ModuleLiteral env, out FunctionLikeExpression function, out FileModuleLiteral file)
 {
     return(env.TryResolveFunction(context, FilePosition, m_fullSymbol, out function, out file));
 }