コード例 #1
0
        public static void SerializeClangTidyFile(ClangTidyProperties Props, string ClangTidyFilePath)
        {
            List <string> CommandList = new List <string>();

            SerializeCheckTree(CommandList, Props.GetCheckTree(), TreeLevelOp.Inherit);

            CommandList.Sort((x, y) =>
            {
                bool LeftSub  = x.StartsWith("-");
                bool RightSub = y.StartsWith("-");
                if (LeftSub && !RightSub)
                {
                    return(-1);
                }
                if (RightSub && !LeftSub)
                {
                    return(1);
                }
                return(StringComparer.CurrentCulture.Compare(x, y));
            });

            string ConfigFile = Path.Combine(ClangTidyFilePath, ".clang-tidy");

            using (StreamWriter Writer = new StreamWriter(ConfigFile))
            {
                Serializer    S    = new Serializer(namingConvention: new PascalCaseNamingConvention());
                ClangTidyYaml Yaml = new ClangTidyYaml();
                Yaml.Checks = String.Join(",", CommandList.ToArray());
                S.Serialize(Writer, Yaml);
            }
        }
コード例 #2
0
        public static List <KeyValuePair <string, ClangTidyProperties> > ParseConfigurationChain(string ClangTidyFile)
        {
            List <KeyValuePair <string, ClangTidyProperties> > Result = new List <KeyValuePair <string, ClangTidyProperties> >();

            Result.Add(new KeyValuePair <string, ClangTidyProperties>(null, ClangTidyProperties.RootProperties));

            foreach (string P in Utility.SplitPath(ClangTidyFile).Reverse())
            {
                if (!Utility.HasClangTidyFile(P))
                {
                    continue;
                }

                string ConfigFile = Path.Combine(P, ".clang-tidy");

                using (StreamReader Reader = new StreamReader(ConfigFile))
                {
                    Deserializer        D        = new Deserializer(namingConvention: new PascalCaseNamingConvention());
                    ClangTidyYaml       Y        = D.Deserialize <ClangTidyYaml>(Reader);
                    ClangTidyProperties Parent   = Result[Result.Count - 1].Value;
                    ClangTidyProperties NewProps = new ClangTidyProperties(Parent);
                    SetPropertiesFromYaml(Y, NewProps);
                    Result.Add(new KeyValuePair <string, ClangTidyProperties>(P, NewProps));
                }
            }
            return(Result);
        }
コード例 #3
0
        public static void SerializeClangTidyFile(ClangTidyProperties Props, string ClangTidyFilePath)
        {
            List<string> CommandList = new List<string>();
            SerializeCheckTree(CommandList, Props.GetCheckTree(), TreeLevelOp.Inherit);

            CommandList.Sort((x, y) =>
            {
                bool LeftSub = x.StartsWith("-");
                bool RightSub = y.StartsWith("-");
                if (LeftSub && !RightSub)
                    return -1;
                if (RightSub && !LeftSub)
                    return 1;
                return StringComparer.CurrentCulture.Compare(x, y);
            });

            string ConfigFile = Path.Combine(ClangTidyFilePath, ".clang-tidy");
            using (StreamWriter Writer = new StreamWriter(ConfigFile))
            {
                Serializer S = new Serializer(namingConvention: new PascalCaseNamingConvention());
                ClangTidyYaml Yaml = new ClangTidyYaml();
                Yaml.Checks = String.Join(",", CommandList.ToArray());
                S.Serialize(Writer, Yaml);
            }
        }
コード例 #4
0
        private static void SetPropertiesFromYaml(ClangTidyYaml Yaml, ClangTidyProperties Props)
        {
            string[] CheckCommands = Yaml.Checks.Split(',');
            foreach (string Command in CheckCommands)
            {
                if (Command == null || Command.Length == 0)
                {
                    continue;
                }
                bool   Add     = true;
                string Pattern = Command;
                if (Pattern[0] == '-')
                {
                    Pattern = Pattern.Substring(1);
                    Add     = false;
                }

                foreach (var Match in CheckDatabase.Checks.Where(x => Utility.MatchWildcardString(x.Name, Pattern)))
                {
                    Props.SetDynamicValue(Match.Name, Add);
                }
            }
        }
コード例 #5
0
        private static void SetPropertiesFromYaml(ClangTidyYaml Yaml, ClangTidyProperties Props)
        {
            string[] CheckCommands = Yaml.Checks.Split(',');
            foreach (string Command in CheckCommands)
            {
                if (Command == null || Command.Length == 0)
                    continue;
                bool Add = true;
                string Pattern = Command;
                if (Pattern[0] == '-')
                {
                    Pattern = Pattern.Substring(1);
                    Add = false;
                }

                foreach (var Match in CheckDatabase.Checks.Where(x => Utility.MatchWildcardString(x.Name, Pattern)))
                {
                    Props.SetDynamicValue(Match.Name, Add);
                }
            }
        }