public ConfigFileAnalyzer(string clang, string dir, string cFile, string rspFile, string configFile, ConfigurationFileTemplateEx template) { _Clang = clang; _Dir = dir; _CFile = cFile; _RSPFile = rspFile; _ConfigFile = configFile; _Template = template.Template; foreach (var p in template.TestableParameters) { _CurrentConfig[p.Name] = p.EnabledValue; } ApplyCurrentConfig(); }
public ConfigurationFileTemplateEx BuildConfigurationFileTemplate(string file, ConfigFileDefinition cf) { Regex rgIfndef = new Regex("^#ifndef ([^ ]+)"); DefineClass valuelessDefine = new DefineClass(@"#define ([^ ]+)( *)$", "#define {name}{g2: }", @"^/\* *#define ([^ ]+)( *)\*/$", "/* #define {name} */"); DefineClass defineWithValue = MakeRegularDefineClass(); Regex rgGroup = new Regex(@" */\* #+ ([^#]*) #+ \*/"); Regex rgHalModuleMacro = new Regex("HAL_(.*)MODULE_ENABLED"); PropertyList propertyList = new PropertyList { PropertyGroups = new List <PropertyGroup>() }; PropertyGroup group = null; string lastIfndef = null; List <TestableConfigurationFileParameter> testableParameters = new List <TestableConfigurationFileParameter>(); foreach (var line in File.ReadAllLines(file)) { string previousLineIfndef = lastIfndef; lastIfndef = null; Match m; bool isInverse; if (line.Trim() == "") { continue; } if ((m = rgGroup.Match(line)).Success) { if (group != null && group.Properties.Count > 0) { propertyList.PropertyGroups.Add(group); } group = new PropertyGroup { Name = m.Groups[1].Value.Trim() }; } else if ((m = rgIfndef.Match(line)).Success) { lastIfndef = m.Groups[1].Value; } else { PropertyEntry prop = null; if (valuelessDefine.IsMatch(line, out m, out isInverse)) { var macro = m.Groups[valuelessDefine.MacroNameGroup].Value; if (macro.EndsWith("HAL_CONF_H")) { continue; } valuelessDefine.FoundDefines.Add(macro); string userFriendlyName = macro; if ((m = rgHalModuleMacro.Match(macro)).Success) { string moduleName = m.Groups[1].Value; if (moduleName == "") { userFriendlyName = "Enable the HAL framework"; } else { userFriendlyName = $"Enable the {moduleName.TrimEnd('_')} module"; } } prop = new PropertyEntry.Boolean { Name = userFriendlyName, ValueForTrue = "1", ValueForFalse = "", UniqueID = macro, DefaultValue = !isInverse }; if (macro != "HAL_MODULE_ENABLED") { testableParameters.Add(new TestableConfigurationFileParameter { Name = macro, DisabledValue = "", EnabledValue = "1" }); } } else if (defineWithValue.IsMatch(line, out m, out isInverse)) { var macro = m.Groups[defineWithValue.MacroNameGroup].Value; var value = m.Groups[defineWithValue.ValueGroup].Value; var text = m.Groups[defineWithValue.CommentGroup].Value.Trim('*', '/', '!', '<', ' '); if (text == "") { text = null; } else { text = $"{text} ({macro})"; } defineWithValue.FoundDefines.Add(macro); if ((macro.StartsWith("USE_") || macro.EndsWith("_ENABLED")) && (value == "0" || value == "1" || value == "0x1")) { prop = new PropertyEntry.Boolean { Name = text ?? macro, UniqueID = macro, ValueForTrue = "1", ValueForFalse = "0", DefaultValue = value != "0" }; } else if (int.TryParse(value, out var intValue) || (value.StartsWith("0x") && int.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out intValue))) { prop = new PropertyEntry.Integral { Name = text ?? macro, UniqueID = macro, DefaultValue = intValue } } ; else { prop = new PropertyEntry.String { Name = text ?? macro, UniqueID = macro, DefaultValue = value } }; } if (prop != null) { if (group == null) { throw new Exception("Property group could not be parsed. Please double-check " + file); } group.Properties.Add(prop); } } } var template = new ConfigurationFileTemplate { PropertyClasses = new[] { valuelessDefine, defineWithValue }.Select(d => d.ToPropertyClass()).ToArray(), TargetFileName = Path.GetFileName(file), PropertyList = propertyList, UserFriendlyName = "STM32 HAL Configuration", }; return(new ConfigurationFileTemplateEx(template) { TestableHeaderFiles = cf.TestableHeaderFiles, TestableParameters = testableParameters.ToArray(), }); } }
public ConfigurationFileTemplateEx BuildConfigurationFileTemplate(string file, ConfigFileDefinition cf) { PropertyGroup group = new PropertyGroup { Name = "FreeRTOS Configuration" }; PropertyGroup functionGroup = new PropertyGroup { Name = "Optional FreeRTOS Functions" }; PropertyList propertyList = new PropertyList { PropertyGroups = new List <PropertyGroup> { group, functionGroup } }; var defClass = MakeRegularDefineClass(); const string namePrefix = "config"; const string includePrefix = "INCLUDE_"; HashSet <string> processedNames = new HashSet <string>(); foreach (var line in File.ReadAllLines(file)) { if (defClass.IsMatch(line, out var m, out var unused)) { string name = m.Groups[defClass.MacroNameGroup].Value; if (processedNames.Contains(name)) { continue; } if (name == "configASSERT") { continue; //configASSERT is a function-like macro, not a regular constant-like definition. } processedNames.Add(name); if (name.StartsWith("configUSE_")) { group.Properties.Add(new PropertyEntry.Boolean { Name = name.Substring(namePrefix.Length), UniqueID = name, ValueForTrue = "1", ValueForFalse = "0" }); } else if (name.StartsWith(namePrefix)) { group.Properties.Add(new PropertyEntry.String { Name = name.Substring(namePrefix.Length), UniqueID = name }); } else if (name.StartsWith(includePrefix)) { functionGroup.Properties.Add(new PropertyEntry.Boolean { Name = name.Substring(includePrefix.Length), UniqueID = name, ValueForTrue = "1", ValueForFalse = "0" }); } else { continue; } defClass.FoundDefines.Add(name); } } var template = new ConfigurationFileTemplate { PropertyClasses = new ConfigurationFilePropertyClass[] { defClass.ToPropertyClass() }, TargetFileName = Path.GetFileName(file), PropertyList = propertyList, UserFriendlyName = "FreeRTOS Configuration", }; return(new ConfigurationFileTemplateEx(template)); }
public ConfigurationFileTemplateEx(ConfigurationFileTemplate template) { Template = template; }