Example #1
0
 /// <summary>
 /// Initializes a new instance of the ConfigFileAttribute class.
 /// </summary>
 /// <param name="filePath">File path.</param>
 public ConfigFileAttribute(string filePath)
 {
     this.configFile          = new ConfigFileDefinition();
     this.configFile.FilePath = filePath;
 }
Example #2
0
        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(),
            });
        }
    }
Example #3
0
        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));
        }
Example #4
0
        public ConfigurationFileTemplateEx BuildConfigurationFileTemplate(string file, ConfigFileDefinition cf)
        {
            Regex rgIfndef = new Regex("^#ifndef ([^ ]+)");
            Regex rgDefine = new Regex("^#define ([^ ]+)( )([^ ]+)$");

            Regex rgGroup = new Regex("^<h>[ \t]+(.*)");

            List <string> precedingComments = new List <string>();
            List <string> allProperties     = new List <string>();
            string        lastIfndef        = null;

            PropertyList propertyList = new PropertyList {
                PropertyGroups = new List <PropertyGroup>()
            };
            PropertyGroup group = null;

            foreach (var line in File.ReadAllLines(file))
            {
                string previousLineIfndef = lastIfndef;
                lastIfndef = null;
                Match m;
                var   trimmedLine = line.Trim();
                if (trimmedLine == "")
                {
                    continue;
                }

                if (trimmedLine.StartsWith("//"))
                {
                    string comment = trimmedLine.Substring(2).Trim();
                    m = rgGroup.Match(comment);
                    if (m.Success)
                    {
                        if (group != null && group.Properties.Count > 0)
                        {
                            propertyList.PropertyGroups.Add(group);
                        }

                        group = new PropertyGroup {
                            Name = m.Groups[1].Value.Trim()
                        };
                    }
                    else
                    {
                        precedingComments.Add(comment);
                    }
                }
                else if ((m = rgIfndef.Match(trimmedLine)).Success)
                {
                    lastIfndef = m.Groups[1].Value;
                }
                else if ((m = rgDefine.Match(trimmedLine)).Success)
                {
                    if (m.Groups[1].Value == previousLineIfndef)
                    {
                        if (group == null)
                        {
                            group = new PropertyGroup {
                                Name = "Other Properties"
                            }
                        }
                        ;

                        var prop = ParseSingleProperty(m.Groups[1].Value, m.Groups[2].Value, precedingComments);
                        if (prop != null)
                        {
                            group.Properties.Add(prop);
                            allProperties.Add(prop.UniqueID);
                        }
                    }

                    precedingComments.Clear();
                }
                else
                {
                    precedingComments.Clear();
                }
            }

            if (group != null && group.Properties.Count > 0)
            {
                propertyList.PropertyGroups.Add(group);
            }

            return(new ConfigurationFileTemplateEx(new ConfigurationFileTemplate
            {
                PropertyClasses = new ConfigurationFilePropertyClass[]
                {
                    new ConfigurationFilePropertyClass
                    {
                        NormalRegex = new SerializableRegularExpression(rgDefine.ToString()),
                        Template = "#define {0}{1}{2}",
                        Properties = allProperties.ToArray(),
                        NameIndex = 1,
                        IndentIndex = 2,
                        ValueIndex = 3,
                    }
                },
                TargetFileName = Path.GetFileName(file),
                PropertyList = propertyList,
                UserFriendlyName = "nRF5x SDK Configuration",
            }));
        }

        Regex rgMacroDescription = new Regex("<(.)> ([^ ]+)[ ]*-(.*)");
        Regex rgEnumValue        = new Regex("<([0-9]+)=>[ \t]*(.*)");