Пример #1
0
        public void Resolve(ResolveEnvironment environment)
        {
            var visitor = new ResolveSymbolDeclVisitor();

            visitor.Environment = environment;
            Accept(visitor);
        }
Пример #2
0
 public void Resolve(SymbolDecl symbol, ResolveEnvironment environment, bool supressError = false)
 {
     if (this.ReferencingNameKey == null)
     {
         var visitor = new ResolveTypeDeclVisitor()
         {
             Symbol       = symbol,
             Environment  = environment,
             SupressError = supressError,
         };
         Accept(visitor);
     }
 }
Пример #3
0
        internal static List <SymbolDecl> FindSymbolInContent(ResolveEnvironment environment, SymbolDecl symbol, TypeDecl decl, string name, Dictionary <string, List <SymbolDecl> > content, bool typeAndNamespaceOnly, bool addError)
        {
            if (content == null)
            {
                return(null);
            }

            List <SymbolDecl> decls = null;

            if (content.TryGetValue(name, out decls))
            {
                if (typeAndNamespaceOnly)
                {
                    decls = decls
                            .Where(x => !(x is FuncDecl) && !(x is VarDecl) && !(x is EnumDecl))
                            .ToList();
                    if (decls.Count == 0)
                    {
                        return(null);
                    }
                }
                var nameKeys     = decls.Select(x => x.NameKey).Distinct().ToList();
                var overloadKeys = decls.Select(x => x.OverloadKey).Distinct().ToList();
                if (overloadKeys.Count > 0)
                {
                    decl.ReferencingOverloadKeys = overloadKeys;
                }
                if (nameKeys.Count > 1)
                {
                    if (addError)
                    {
                        var printingKeys = overloadKeys.Aggregate("", (a, b) => a + "\r\n" + b);
                        environment.AddError(false, "Found multiple symbols for {0} in {1}: " + printingKeys, name, symbol);
                    }
                    return(null);
                }
                decl.ReferencingNameKey = nameKeys[0];
                return(decls);
            }
            return(null);
        }
Пример #4
0
        static void Main(string[] args)
        {
            var input = new Dictionary<string, GlobalDecl>();
            for (int i = 0; i < args.Length / 2; i++)
            {
                var tag = args[i * 2];
                var fileName = args[i * 2 + 1];
                Console.WriteLine("Reading " + fileName + " ...");
                var xml = XDocument.Load(fileName);
                var decl = (GlobalDecl)SymbolDecl.Deserialize(xml.Root);
                decl.BuildSymbolTree(null, tag);
                input.Add(tag, decl);
            }

            Console.WriteLine("De-duplicating ...");
            var symbolGroup = new Dictionary<string, List<SymbolDecl>>();
            GroupSymbolsByOverloadKey(input.Values, symbolGroup);
            foreach (var pair in symbolGroup)
            {
                var groups = pair.Value
                    .GroupBy(x => x.ContentKey)
                    .ToArray();
                foreach (var group in groups)
                {
                    var decls = group.ToArray();
                    var tags = decls
                        .Select(x => x.Tags)
                        .OrderBy(x => x)
                        .Aggregate((a, b) => a + ";" + b);
                    foreach (var decl in decls)
                    {
                        decl.Tags = tags;
                    }
                }
            }

            Console.WriteLine("Resolving Symbols ...");
            var symbolResolving = symbolGroup
                .SelectMany(x => x.Value)
                .ToArray();
            var environment = new ResolveEnvironment(input.Values);
            foreach (var symbol in symbolResolving)
            {
                symbol.Resolve(environment);
            }

            var output = args[args.Length - 1];
            var xmlErrors = environment.Errors.Where(x => x.StartsWith("(Xml)")).ToArray();
            var warnings = environment.Errors.Where(x => x.StartsWith("(Warning)")).ToArray();
            var errors = environment.Errors.Where(x => x.StartsWith("(Error)")).ToArray();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Xml Errors: " + xmlErrors.Length);
            Console.WriteLine("Warnings: " + warnings.Length);
            Console.WriteLine("Errors: " + errors.Length);
            Console.ResetColor();

            using (var writer = new StreamWriter(output + ".errors.txt", false, Encoding.UTF8))
            {
                writer.WriteLine("=======================XML ERROR=======================");
                foreach (var message in xmlErrors)
                {
                    writer.WriteLine(message);
                }
                writer.WriteLine();

                writer.WriteLine("========================WARNING========================");
                foreach (var message in warnings)
                {
                    writer.WriteLine(message);
                }

                writer.WriteLine();
                writer.WriteLine("=========================ERROR=========================");
                foreach (var message in errors)
                {
                    writer.WriteLine(message);
                }
            }

            Console.WriteLine("Saving ...");
            var symbolSaving = symbolGroup
                .ToDictionary(
                    x => x.Key,
                    x => x.Value
                        .GroupBy(y => y.Tags)
                        .Select(y => y.First())
                        .Select(y =>
                        {
                            var templateDecl = y.Parent as TemplateDecl;
                            return templateDecl == null ? y : templateDecl;
                        })
                        .Where(y => y.Parent is NamespaceDecl || y.Parent is GlobalDecl)
                        .ToArray()
                    )
                .Where(x => x.Value.Length > 0)
                .GroupBy(x => x.Value.First().Parent)
                .ToDictionary(
                    x => x.Key,
                    x => x.ToDictionary(
                        y => y.Key,
                        y => y.Value
                        )
                    )
                ;
            var outputXml = new XDocument(
                new XElement("CppXmlDocument",
                    symbolSaving.Select(x => new XElement("Namespace",
                        new XAttribute("Name", x.Key is GlobalDecl ? "" : (x.Key as NamespaceDecl).NameKey),
                        x.Value.Select(y => new XElement("Symbol",
                            new XAttribute("OverloadKey", y.Key),
                            y.Value
                                .Select(z => z.Parent is TemplateDecl ? z.Parent : z)
                                .Select(z => z.Serialize())
                            ))
                        ))
                    )
                );
            outputXml.Save(output);
        }
Пример #5
0
 public void Resolve(SymbolDecl symbol, ResolveEnvironment environment, bool supressError = false)
 {
     if (this.ReferencingNameKey == null)
     {
         var visitor = new ResolveTypeDeclVisitor()
         {
             Symbol = symbol,
             Environment = environment,
             SupressError = supressError,
         };
         Accept(visitor);
     }
 }
Пример #6
0
 public void Resolve(ResolveEnvironment environment)
 {
     var visitor = new ResolveSymbolDeclVisitor();
     visitor.Environment = environment;
     Accept(visitor);
 }
Пример #7
0
        internal static List<SymbolDecl> FindSymbolInContent(ResolveEnvironment environment, SymbolDecl symbol, TypeDecl decl, string name, Dictionary<string, List<SymbolDecl>> content, bool typeAndNamespaceOnly, bool addError)
        {
            if (content == null)
            {
                return null;
            }

            List<SymbolDecl> decls = null;
            if (content.TryGetValue(name, out decls))
            {
                if (typeAndNamespaceOnly)
                {
                    decls = decls
                        .Where(x => !(x is FuncDecl) && !(x is VarDecl) && !(x is EnumDecl))
                        .ToList();
                    if (decls.Count == 0)
                    {
                        return null;
                    }
                }
                var nameKeys = decls.Select(x => x.NameKey).Distinct().ToList();
                var overloadKeys = decls.Select(x => x.OverloadKey).Distinct().ToList();
                if (overloadKeys.Count > 0)
                {
                    decl.ReferencingOverloadKeys = overloadKeys;
                }
                if (nameKeys.Count > 1)
                {
                    if (addError)
                    {
                        var printingKeys = overloadKeys.Aggregate("", (a, b) => a + "\r\n" + b);
                        environment.AddError(false, "Found multiple symbols for {0} in {1}: " + printingKeys, name, symbol);
                    }
                    return null;
                }
                decl.ReferencingNameKey = nameKeys[0];
                return decls;
            }
            return null;
        }