Пример #1
0
        /// <summary>
        /// Creates a new declarative scope for use inside a function body.
        /// </summary>
        /// <param name="parentScope"> A reference to the parent scope.  Can not be <c>null</c>. </param>
        /// <param name="functionName"> The name of the function.  Can be empty for an anonymous function. </param>
        /// <param name="argumentNames"> The names of each of the function arguments. </param>
        /// <returns> A new DeclarativeScope instance. </returns>
        internal static DeclarativeScope CreateFunctionScope(Scope parentScope, string functionName, List <ArgVariable> args)
        {
            if (functionName == null)
            {
                throw new ArgumentNullException("functionName");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            DeclarativeScope result = new DeclarativeScope(parentScope, 0);

            if (string.IsNullOrEmpty(functionName) == false)
            {
                result.AddVariable(functionName);
            }

            // At this point, the 'this' keyword is already in args.

            result.AddVariable("arguments");

            foreach (ArgVariable arg in args)
            {
                result.Declare(arg);
                arg.Scope = result;
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Creates a new declarative scope for use inside a catch statement.
        /// </summary>
        /// <param name="parentScope"> A reference to the parent scope.  Can not be <c>null</c>. </param>
        /// <param name="catchVariableName"> The name of the catch variable. </param>
        /// <returns> A new DeclarativeScope instance. </returns>
        internal static DeclarativeScope CreateCatchScope(Scope parentScope, string catchVariableName)
        {
            if (parentScope == null)
            {
                throw new ArgumentNullException("parentScope", "Catch scopes must have a parent scope.");
            }
            if (catchVariableName == null)
            {
                throw new ArgumentNullException("catchVariableName");
            }
            DeclarativeScope result = new DeclarativeScope(parentScope, 0);

            result.AddVariable(catchVariableName);
            result.CanDeclareVariables = false;                 // Only the catch variable can be declared in this scope.
            return(result);
        }