Esempio n. 1
0
 public FileScope(string filename, CompilationScope scope)
 {
     this.Name    = filename;
     this.Imports = new HashSet <ImportStatement>();
     this.FileScopeEntityLookup = new FileScopedEntityLookup().SetFileScope(this);
     this.CompilationScope      = scope;
 }
Esempio n. 2
0
 private static FunctionDefinition[] FindFunctionImpl(ParserContext parser, CompilationScope scope, string name)
 {
     return(scope.GetTopLevelEntities()
            .OfType <FunctionDefinition>()
            .Where(fd => fd.NameToken.Value == name)
            .ToArray());
 }
Esempio n. 3
0
        public static void Resolve(ParserContext parser, CompilationScope scope)
        {
            Dictionary <string, TopLevelEntity>             scopeLookup         = new Dictionary <string, TopLevelEntity>();
            Dictionary <string, TopLevelEntity>             depsLookup          = new Dictionary <string, TopLevelEntity>();
            Dictionary <string, NamespaceReferenceTemplate> depsNamespaceLookup = new Dictionary <string, NamespaceReferenceTemplate>();

            // First create a lookup of JUST the libraries that are available to this library.
            // This is localized to the locales that are used by that library.
            foreach (LocalizedAssemblyView depLocView in scope.Dependencies)
            {
                depLocView.Scope.FlattenFullyQualifiedLookupsIntoGlobalLookup(depsLookup, depLocView.Locale);
                Dictionary <string, NamespaceReferenceTemplate> newNamespaces = depLocView.Scope.GetFlattenedNamespaceLookup(depLocView.Locale);
                foreach (string key in newNamespaces.Keys)
                {
                    depsNamespaceLookup[key] = newNamespaces[key];
                }
            }

            scope.FlattenFullyQualifiedLookupsIntoGlobalLookup(scopeLookup, scope.Locale);
            Dictionary <string, NamespaceReferenceTemplate> scopeNamespaceLookup = scope.GetFlattenedNamespaceLookup(scope.Locale);

            TopLevelEntity[] toResolve = scope.GetTopLevelEntities();

            ResolveNames(parser, toResolve, scopeLookup, depsLookup, scopeNamespaceLookup, depsNamespaceLookup);
        }
Esempio n. 4
0
 public ConstantDependencySorter(IEnumerable <ConstDefinition> constants)
 {
     this.consts = constants.ToArray();
     if (this.consts.Length > 0)
     {
         this.currentScope = this.consts[0].CompilationScope;
     }
 }
Esempio n. 5
0
        private static void FindMainFunction(ParserContext parserContext)
        {
            string delegateMainTo = parserContext.DelegateMainTo;

            CompilationScope scope = parserContext.RootScope;

            if (delegateMainTo != null)
            {
                scope = scope.Dependencies
                        .Where(d => d.Name == delegateMainTo)
                        .Select(lav => lav.Scope)
                        .FirstOrDefault();
                if (scope == null)
                {
                    throw new InvalidOperationException("Your build file has its delegateMainTo value set to '" + delegateMainTo + "', but there are no library dependencies by this name. Did you forget to import it?");
                }
            }

            // TODO(localization): this will pose problems when the included scope is not the same locale.
            // The main function needs to be tagged as part of the scope's data when it's parsed.
            FunctionDefinition[] mainFunctions = FindFunctionImpl(
                parserContext,
                scope,
                parserContext.Keywords.MAIN_FUNCTION);

            if (mainFunctions.Length == 0)
            {
                throw new InvalidOperationException("No main(args) function was defined.");
            }
            if (mainFunctions.Length > 1)
            {
                throw new ParserException(mainFunctions[0], "Multiple main methods found.");
            }

            FunctionDefinition mainFunction = mainFunctions[0];

            if (mainFunction.ArgNames.Length > 1)
            {
                throw new ParserException(mainFunctions[0].ArgNames[1], "main function cannot have more than one argument.");
            }

            parserContext.MainFunction       = mainFunction;
            parserContext.MainFunctionHasArg = mainFunction.ArgNames.Length == 1;
        }
Esempio n. 6
0
        public static void Resolve(ParserContext parser, CompilationScope scope)
        {
            Dictionary <string, TopLevelConstruct>          scopeLookup         = new Dictionary <string, TopLevelConstruct>();
            Dictionary <string, TopLevelConstruct>          depsLookup          = new Dictionary <string, TopLevelConstruct>();
            Dictionary <string, NamespaceReferenceTemplate> depsNamespaceLookup = new Dictionary <string, NamespaceReferenceTemplate>();

            // First create a lookup of JUST the libraries that are available to this library.
            // This is localized to the locales that are used by that library.
            foreach (LocalizedLibraryView depLocView in scope.Dependencies)
            {
                depLocView.LibraryScope.FlattenFullyQualifiedLookupsIntoGlobalLookup(depsLookup, depLocView.Locale);
                Util.MergeDictionaryInto(
                    depLocView.LibraryScope.GetFlattenedNamespaceLookup(depLocView.Locale),
                    depsNamespaceLookup);
            }

            scope.FlattenFullyQualifiedLookupsIntoGlobalLookup(scopeLookup, scope.Locale);
            Dictionary <string, NamespaceReferenceTemplate> scopeNamespaceLookup = scope.GetFlattenedNamespaceLookup(scope.Locale);

            TopLevelConstruct[] toResolve = scope.GetTopLevelConstructs();

            ResolveNames(parser, toResolve, scopeLookup, depsLookup, scopeNamespaceLookup, depsNamespaceLookup);
        }
Esempio n. 7
0
 public virtual IScope GetScope()
 {
     if (_scope == null)
         _scope = new CompilationScope(this);
     return _scope;
 }
Esempio n. 8
0
 public CniFunction(CompilationScope compilationUnit, string name, int argCount)
 {
     this.CompilationUnit = compilationUnit;
     this.Name            = name;
     this.ArgCount        = argCount;
 }