Beispiel #1
0
        private void ResolveImports()
        {
            this.Imports = new List <IASTNode>();
            var imports = Generator.AST.FindAll(n => n is ASTImport).ToList();

            imports.ForEach(node =>
            {
                ASTImport import = (ASTImport)node;
                var ast          = this.Project.GetAstForModule(import.Name);
                if (!import.Imports.Any())
                {
                    var copies = ast
                                 .FindAll(a => a is ASTType || a is ASTAlias || a is ASTData || a is ASTChoice)
                                 .Select(a => {
                        return(a switch
                        {
                            ASTType t => t.Clone() as IASTNode,
                            ASTAlias t => t.Clone() as IASTNode,
                            ASTData t => t.Clone() as IASTNode,
                            ASTChoice t => t.Clone() as IASTNode,
                            _ => throw new Exception("Can only serialize real AST nodes.")
                        });
                    })
                                 .ToList();
                    this.Imports.AddRange(copies);
                }
        public static List <IASTNode> ResolveImports(ASTGenerator generator)
        {
            var imports  = new List <IASTNode>();
            var _imports = generator.AST.FindAll(n => n is ASTImport).ToList();

            _imports.ForEach(node =>
            {
                var import = (ASTImport)node;
                var ast    = ProjectContext.Instance?.GetAstForModule(import.ModuleName);
                if (!import.Imports.Any())
                {
                    var copies = ast?
                                 .FindAll(a => a is ASTType || a is ASTAlias || a is ASTData || a is ASTChoice || a is ASTView)
                                 .Select(a =>
                    {
                        return(a switch
                        {
                            ASTType t => t.Clone() as IASTNode,
                            ASTAlias t => t.Clone() as IASTNode,
                            ASTData t => t.Clone() as IASTNode,
                            ASTChoice t => t.Clone() as IASTNode,
                            ASTView t => t.Clone() as IASTNode,
                            _ => null
                        });
                    })
                                 .ToList()
                                 .Where(n => n != null)
                                 .OfType <IASTNode>()
                                 .ToList() ?? Enumerable.Empty <IASTNode>();

                    // For some reason the compiler cannot find that I filter out all of the
                    // null's from the list and so I will only have a list of reference types
                    // of type IASTNode...

#pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
                    imports.AddRange(copies);
#pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
                }