public static CheckTree Build(ClangTidyProperties Config)
        {
            // Since some check names contain dashes in them, it doesn't make sense to
            // simply split all check names by dash and construct a huge tree.  For
            // example, in the check called google-runtime-member-string-references,
            // we don't need each of those to be a different subgroup.  So instead we
            // explicitly specify the common breaking points at which a user might want
            // to use a -* and everything else falls as a leaf under one of these
            // categories.
            // FIXME: This should be configurable without recompilation
            CheckTree Root = new CheckTree();

            string[][] Groups = new string[][] {
                new string[] { "boost" },
                new string[] { "cert" },
                new string[] { "clang", "diagnostic" },
                new string[] { "cppcoreguidelines", "interfaces" },
                new string[] { "cppcoreguidelines", "pro", "bounds" },
                new string[] { "cppcoreguidelines", "pro", "type" },
                new string[] { "google", "build" },
                new string[] { "google", "readability" },
                new string[] { "google", "runtime" },
                new string[] { "llvm" },
                new string[] { "misc" },
            };

            foreach (string[] Group in Groups)
            {
                CheckTree Subgroup = Root;
                foreach (string Component in Group)
                {
                    Subgroup = Subgroup.AddOrCreateSubgroup(Component);
                }
            }

            var Props = Config.GetProperties()
                        .Cast <PropertyDescriptor>()
                        .OfType <DynamicPropertyDescriptor <bool> >()
                        .Where(x => x.Attributes.OfType <ClangTidyCheckAttribute>().Count() > 0)
                        .Select(x => new KeyValuePair <DynamicPropertyDescriptor <bool>, string>(
                                    x, x.Attributes.OfType <ClangTidyCheckAttribute>().First().CheckName));
            var PropArray = Props.ToArray();

            foreach (var CheckInfo in PropArray)
            {
                string    LeafName = null;
                CheckTree Tree     = Root.LocateCheckLeafGroup(CheckInfo.Value, out LeafName);
                Tree.AddLeaf(LeafName, CheckInfo.Key);
            }
            return(Root);
        }
        private CheckTree LocateCheckLeafGroup(string Check, out string LeafName)
        {
            string[] Components     = Check.Split('-');
            string   FirstComponent = Components.FirstOrDefault();

            if (FirstComponent == null)
            {
                LeafName = Check;
                return(this);
            }

            CheckTreeNode Subgroup = null;

            if (!Children_.TryGetValue(FirstComponent, out Subgroup))
            {
                LeafName = Check;
                return(this);
            }
            System.Diagnostics.Debug.Assert(Subgroup is CheckTree);
            CheckTree Child     = (CheckTree)Subgroup;
            string    ChildName = Check.Substring(FirstComponent.Length + 1);

            return(Child.LocateCheckLeafGroup(ChildName, out LeafName));
        }
Esempio n. 3
0
        public static CheckTree Build(ClangTidyProperties Config)
        {
            // Since some check names contain dashes in them, it doesn't make sense to
            // simply split all check names by dash and construct a huge tree.  For
            // example, in the check called google-runtime-member-string-references,
            // we don't need each of those to be a different subgroup.  So instead we
            // explicitly specify the common breaking points at which a user might want
            // to use a -* and everything else falls as a leaf under one of these
            // categories.
            // FIXME: This should be configurable without recompilation
            CheckTree Root = new CheckTree();
            string[][] Groups = new string[][] {
                new string[] {"boost"},
                new string[] {"cert"},
                new string[] {"clang", "diagnostic"},
                new string[] {"cppcoreguidelines", "interfaces"},
                new string[] {"cppcoreguidelines", "pro", "bounds"},
                new string[] {"cppcoreguidelines", "pro", "type"},
                new string[] {"google", "build"},
                new string[] {"google", "readability"},
                new string[] {"google", "runtime"},
                new string[] {"llvm"},
                new string[] {"misc"},
            };

            foreach (string[] Group in Groups)
            {
                CheckTree Subgroup = Root;
                foreach (string Component in Group)
                    Subgroup = Subgroup.AddOrCreateSubgroup(Component);
            }

            var Props = Config.GetProperties()
                              .Cast<PropertyDescriptor>()
                              .OfType<DynamicPropertyDescriptor<bool>>()
                              .Where(x => x.Attributes.OfType<ClangTidyCheckAttribute>().Count() > 0)
                              .Select(x => new KeyValuePair<DynamicPropertyDescriptor<bool>, string>(
                                            x, x.Attributes.OfType<ClangTidyCheckAttribute>().First().CheckName));
            var PropArray = Props.ToArray();
            foreach (var CheckInfo in PropArray)
            {
                string LeafName = null;
                CheckTree Tree = Root.LocateCheckLeafGroup(CheckInfo.Value, out LeafName);
                Tree.AddLeaf(LeafName, CheckInfo.Key);
            }
            return Root;
        }