Beispiel #1
0
            public static TemplateParameter ParseParameter(LanguageProcessor.ParsedLine line)
            {
                int      minDimensions   = 1;
                int      maxDimensions   = 1;
                bool     pointer         = false;
                bool     isFixed         = false;
                bool     signed          = false;
                int      valueBase       = 16;
                Priority pointedPriority = Priority.none;

                foreach (string flag in line.flags)
                {
                    if (flag.Length != 0)
                    {
                        int num1 = flag.IndexOf(':');
                        if (flag.StartsWith("pointer"))
                        {
                            pointer = true;
                            if (num1 > 0)
                            {
                                string str = flag.Substring(num1 + 1);
                                if (((IEnumerable <string>)Enum.GetNames(typeof(Priority))).Contains <string> (str))
                                {
                                    pointedPriority = (Priority)Enum.Parse(typeof(Priority), str);
                                }
                            }
                        }
                        else if (flag.StartsWith("coordinates") || flag.StartsWith("coordinate"))
                        {
                            if (num1 < 0)
                            {
                                throw new FormatException("No : in option " + flag);
                            }
                            string s = flag.Substring(num1 + 1);
                            if (s.Contains("-"))
                            {
                                string[] strArray = s.Split('-');
                                minDimensions = int.Parse(strArray [0]);
                                maxDimensions = int.Parse(strArray [1]);
                            }
                            else
                            {
                                int num2 = int.Parse(s);
                                minDimensions = num2;
                                maxDimensions = num2;
                            }
                        }
                        else if (flag.StartsWith("preferredBase"))
                        {
                            if (num1 < 0)
                            {
                                throw new FormatException("No : in option " + flag);
                            }
                            valueBase = flag.Substring(num1 + 1).GetValue();
                        }
                        else if (flag.StartsWith("fixed"))
                        {
                            isFixed = true;
                        }
                        else
                        {
                            if (!flag.StartsWith("signed"))
                            {
                                throw new FormatException("Unknown option " + flag + " in parameter " + line.name);
                            }
                            signed = true;
                        }
                    }
                }
                TemplateParameter templateParameter = new TemplateParameter(line.name, line.number1, line.number2, minDimensions, maxDimensions, pointer, pointedPriority, signed, isFixed);

                templateParameter.SetBase(valueBase);
                return(templateParameter);
            }
            public static TemplateParameter ParseParameter(ParsedLine line)
            {
                int minDimensions = 1;
                int maxDimensions = 1;

                bool pointer = false;
                bool isFixed = false;
                bool signed = false;
                int prefBase = 16;
                Priority pointedPriority = Priority.none;

                foreach (string item in line.flags)
                {
                    if (item.Length == 0)
                    {
                        continue;
                    }
                    int index = item.IndexOf(':');
                    if (item.StartsWith("pointer"))
                    {
                        pointer = true;
                        if (index > 0)
                        {
                            string priority = item.Substring(index + 1);
                            if (Enum.GetNames(typeof(Priority)).Contains(priority))
                            {
                                pointedPriority = (Priority)Enum.Parse(typeof(Priority), priority);
                            }
                        }
                    }
                    else if (item.StartsWith("coordinates") || item.StartsWith("coordinate"))
                    {
                        if (index < 0)
                            throw new FormatException("No : in option " + item);
                        string dimensionsS = item.Substring(index + 1);
                        if (dimensionsS.Contains("-"))
                        {
                            string[] dimensionsSS = dimensionsS.Split('-');

                            minDimensions = int.Parse(dimensionsSS[0]);
                            maxDimensions = int.Parse(dimensionsSS[1]);
                        }
                        else
                        {
                            int dimensions = int.Parse(dimensionsS);
                            minDimensions = dimensions;
                            maxDimensions = dimensions;
                        }
                    }
                    else if (item.StartsWith("preferredBase"))
                    {
                        if (index < 0)
                            throw new FormatException("No : in option " + item);
                        string valueS = item.Substring(index + 1);
                        prefBase = valueS.GetValue();
                    }
                    else if (item.StartsWith("fixed"))
                    {
                        isFixed = true;
                    }
                    else if (item.StartsWith("signed"))
                    {
                        signed = true;
                    }
                    else
                    {
                        throw new FormatException("Unknown option " +
                            item + " in parameter " + line.name);
                    }
                }

                TemplateParameter param = new TemplateParameter(line.name, line.number1, line.number2, minDimensions,
                    maxDimensions, pointer, pointedPriority, signed, isFixed);
                param.SetBase(prefBase);
                return param;
            }