public static ScopeAccessInformation FromOutermostScope(
            CSharpName outermostScopeWrapperName,
            NonNullImmutableList <ICodeBlock> blocks,
            NonNullImmutableList <NameToken> externalDependencies)
        {
            if (outermostScopeWrapperName == null)
            {
                throw new ArgumentNullException("outermostScopeWrapperName");
            }
            if (blocks == null)
            {
                throw new ArgumentNullException("blocks");
            }
            if (externalDependencies == null)
            {
                throw new ArgumentNullException("externalDependencies");
            }

            // This prepares the empty template for the primary instance..
            var outermostScope = new OutermostScope(outermostScopeWrapperName, blocks);
            var initialScope   = new ScopeAccessInformation(
                outermostScope,                               // parent
                outermostScope,                               // scope-defining parent
                null,                                         // parentReturnValueNameIfAny
                null,                                         // errorRegistrationTokenIfAny
                null,                                         // directedWithReferenceIfAn
                externalDependencies,
                new NonNullImmutableList <ScopedNameToken>(), // classes
                new NonNullImmutableList <ScopedNameToken>(), // functions,
                new NonNullImmutableList <ScopedNameToken>(), // properties,
                new NonNullImmutableList <ScopedNameToken>(), // constants
                new NonNullImmutableList <ScopedNameToken>(), // variables
                new NonNullImmutableList <ExitableNonScopeDefiningConstructDetails>()
                );

            // .. but it needs the classes, functions, properties and variables declared by the code blocks to be registered with it. To do that, this
            // extension method will be used (seems a bit strange since this method is part of the ScopeAccessInformation class and it relies upon an
            // extension method, but that's only because there's no way to define a static extension method, which would have been ideal for this).
            return(initialScope.Extend(outermostScope, blocks));
        }
Esempio n. 2
0
        /// <summary>
        /// This will never be null
        /// </summary>
        public static NonNullImmutableList <NameToken> GetUndeclaredVariablesAccessed(
            this TranslatedStatementContentDetails source,
            ScopeAccessInformation scopeAccessInformation,
            VBScriptNameRewriter nameRewriter)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (scopeAccessInformation == null)
            {
                throw new ArgumentNullException("scopeAccessInformation");
            }
            if (nameRewriter == null)
            {
                throw new ArgumentNullException("nameRewriter");
            }

            return(source.VariablesAccessed
                   .Where(v => !scopeAccessInformation.IsDeclaredReference(v, nameRewriter))
                   .ToNonNullImmutableList());
        }