Beispiel #1
0
 /// <summary>
 ///   Adds the entities.
 /// </summary>
 /// <param name = "entities">The entities.</param>
 public virtual void AddRange(List <BaseEntity> entities)
 {
     foreach (BaseEntity entity in entities)
     {
         EnumerationEntity enumerationEntity = entity as EnumerationEntity;
         if (enumerationEntity != null)
         {
             if (this.Enumerations.Contains(enumerationEntity))
             {
                 continue;
             }
             this.Enumerations.Add(enumerationEntity);
         }
         ConstantEntity constantEntity = entity as ConstantEntity;
         if (constantEntity != null)
         {
             if (this.Constants.Contains(constantEntity))
             {
                 continue;
             }
             this.Constants.Add(constantEntity);
         }
         FunctionEntity functionEntity = entity as FunctionEntity;
         if (functionEntity != null)
         {
             this.Functions.Add(functionEntity);
         }
     }
 }
        public EnumerationEntity Parse(TypedEntity typedEntity, String name, IEnumerable<XElement> elements)
        {
            EnumerationEntity enumerationEntity = new EnumerationEntity ();

            XElement declarationElement = (from el in elements
                                           where el.Name == "div" &&
                el.Attribute ("class") != null &&
                el.Attribute ("class").Value == "declaration_indent"
                                           select el).FirstOrDefault ();

            XElement parameterElement = (from el in elements
                                         where el.Name == "div" &&
                el.Attribute ("class") != null &&
                el.Attribute ("class").Value == "param_indent"
                                         select el).FirstOrDefault ();

            //XElement discussionElement = (from el in elements
            //                              where el.Name == "h5" && el.Value.Trim() == "Discussion"
            //                              select el).FirstOrDefault();

            XElement availabilityElement = (from el in elements
                                            let term = el.Descendants ("dt").FirstOrDefault ()
                                            let definition = el.Descendants ("dd").FirstOrDefault ()
                                            where el.Name == "dl" &&
                term != null &&
                term.Value.Trim () == "Availability"
                                            select definition).FirstOrDefault ();

            String declaration = declarationElement.TrimAll ();
            String type = "NOTYPE";
            String values = String.Empty;

            bool result = this.SplitEnumeration (declaration, ref name, ref type, ref values);
            if (!result) {
                return null;
            }

            enumerationEntity.Name = name;
            enumerationEntity.BaseType = type;
            enumerationEntity.Namespace = "MISSING";

            // Extract abstract
            IEnumerable<XElement> abstractElements = elements.SkipWhile (el => el.Name != "p").TakeWhile (el => el.Name == "p");
            foreach (XElement element in abstractElements) {
                String line = element.TrimAll ();
                if (!String.IsNullOrEmpty (line)) {
                    enumerationEntity.Summary.Add (line);
                }
            }

            //// Extract discussion
            //if (discussionElement != null)
            //{
            //    IEnumerable<XElement> discussionElements = discussionElement.ElementsAfterSelf().TakeWhile(el => el.Name == "p");
            //    foreach (XElement element in discussionElements)
            //    {
            //        String line = element.TrimAll();
            //        if (!String.IsNullOrEmpty(line))
            //        {
            //            enumerationEntity.Summary.Add(line);
            //        }
            //    }
            //}

            // Parse the values
            string[] pairs = values.Split (new []{','}, StringSplitOptions.RemoveEmptyEntries);
            foreach (string pair in pairs) {
                if (String.Equals (pair.TrimAll (), String.Empty)) {
                    continue;
                }

                String key;
                String value = String.Empty;
                if (pair.IndexOf ('=') != -1) {
                    string[] parts = pair.Split (new []{'='}, StringSplitOptions.RemoveEmptyEntries);
                    key = parts [0].Trim ();
                    value = parts [1].Trim ();
                } else {
                    key = pair.Trim ();
                }

                // Add a new value
                EnumerationValueEntity enumerationValueEntity = new EnumerationValueEntity ();
                enumerationValueEntity.Name = key;

                if (value.Length == 6 && value.StartsWith ("'") && value.EndsWith ("'")) {
                    String v = value.Trim ('\'');
                    enumerationValueEntity.Value = "0x" + FourCharToInt (v).ToString ("X8");
                } else {
                    enumerationValueEntity.Value = value;
                }

                enumerationEntity.Values.Add (enumerationValueEntity);
            }

            XElement termList = parameterElement != null ? parameterElement.Descendants ("dl").FirstOrDefault () : null;
            if (termList != null) {
                IEnumerable<XElement> dtList = from el in termList.Elements ("dt") select el;
                IEnumerable<XElement> ddList = from el in termList.Elements ("dd") select el;

                if (dtList.Count () == ddList.Count ()) {
                    // Iterate over definitions
                    for (int i = 0; i < dtList.Count(); i++) {
                        String term = dtList.ElementAt (i).TrimAll ();
                        //String summary = ddList.ElementAt(i).TrimAll();
                        IEnumerable<String> summaries = ddList.ElementAt (i).Elements ("p").Select (p => p.Value.TrimAll ());

                        // Find the parameter
                        EnumerationValueEntity enumerationValueEntity = enumerationEntity.Values.Find (p => String.Equals (p.Name, term));
                        if (enumerationValueEntity != null) {
                            foreach (string sum in summaries) {
                                enumerationValueEntity.Summary.Add (sum);
                            }
                        }
                    }
                }
            }

            // Get the availability
            if (availabilityElement != null) {
                enumerationEntity.MinAvailability = CommentHelper.ExtractAvailability (availabilityElement.TrimAll ());
            }

            return enumerationEntity;
        }
        public EnumerationEntity Parse(TypedEntity typedEntity, XElement enumerationElement)
        {
            EnumerationEntity enumerationEntity = new EnumerationEntity();

            String name = enumerationElement.Element("name").TrimAll();
            enumerationEntity.Name = name.Trim('_');
            enumerationEntity.BaseType = "MISSING";
            enumerationEntity.Namespace = "MISSING";

            // Elements for brief description
            IEnumerable<XElement> abstractElements = enumerationElement.Element("briefdescription").Elements("para");

            // Extract for detailed description
            IEnumerable<XElement> detailsElements = (from el in enumerationElement.Element("detaileddescription").Elements("para")
                                                     where !el.Elements("simplesect").Any()
                                                           && el.Elements("parameterlist").Any()
                                                           && el.Elements("xrefsect").Any()
                                                     select el);

            // Elements for values
            IEnumerable<XElement> enumerationValueElements = enumerationElement.Elements("enumvalue");

            // Add brief description
            foreach (XElement paragraph in abstractElements)
            {
                enumerationEntity.Summary.Add(paragraph.TrimAll());
            }
            foreach (XElement paragraph in detailsElements)
            {
                enumerationEntity.Summary.Add(paragraph.TrimAll());
            }

            // Add each value
            foreach (XElement enumerationValueElement in enumerationValueElements)
            {
                String key = enumerationValueElement.Element("name").TrimAll();
                String value;
                if (enumerationValueElement.Element("initializer") != null)
                {
                    value = enumerationValueElement.Element("initializer").Value;
                    value = value.Replace("=", String.Empty);
                    value = value.TrimAll();
                }
                else
                {
                    value = String.Empty;
                }

                // Add a new value
                EnumerationValueEntity enumerationValueEntity = new EnumerationValueEntity();
                enumerationValueEntity.Name = key;
                enumerationValueEntity.Value = value;
                enumerationEntity.Values.Add(enumerationValueEntity);

                // Elements for brief description
                abstractElements = enumerationValueElement.Element("briefdescription").Elements("para");

                // Add brief description
                foreach (XElement paragraph in abstractElements)
                {
                    enumerationValueEntity.Summary.Add(paragraph.TrimAll());
                }
            }

            /*
            // Get the availability
            if (availabilityElement != null)
            {
                enumerationEntity.MinAvailability = CommentHelper.ExtractAvailability(availabilityElement.TrimAll());
            }
             */

            return enumerationEntity;
        }
        private List<BaseEntity> ExtractEnumeration(XElement constantElement, String name, String summary, String declaration)
        {
            declaration = declaration.Trim (';');

            // Default values
            String type = "NOTYPE";
            String values = String.Empty;

            // Match the enumeration definition
            bool result = this.SplitEnumeration (declaration, ref name, ref type, ref values);
            if (!result) {
                return null;
            }

            if (type == "NOTYPE") {
                type = RefineEnumBaseType(values);
            }

            // Create the enumeration
            EnumerationEntity enumerationEntity = new EnumerationEntity ();
            enumerationEntity.Name = name;
            enumerationEntity.BaseType = type;
            enumerationEntity.Namespace = "MISSING";
            enumerationEntity.Summary.Add (summary);

            // Parse the values
            var pairs = values.Split (new []{'\n'}, StringSplitOptions.RemoveEmptyEntries);
            foreach (string immutablePair in pairs) {
                String key;
                String value = String.Empty;
                String pair = immutablePair.Replace(",","");

                // Handle value assignment
                if (pair.IndexOf ('=') != -1) {
                    string[] parts = pair.Split (new []{'='}, StringSplitOptions.RemoveEmptyEntries);
                    key = parts [0].Trim ();
                    value = parts [1].Trim ();
                } else {
                    key = pair.Trim ();
                }

                // Add a new value
                EnumerationValueEntity enumerationValueEntity = new EnumerationValueEntity ();
                enumerationValueEntity.Name = key;

                if (value.Length == 6 && value.StartsWith ("'") && value.EndsWith ("'")) {
                    String v = value.Trim ('\'');
                    enumerationValueEntity.Value = "0x" + FourCharToInt (v).ToString ("X8");
                } else {
                    enumerationValueEntity.Value = value;
                }

                // Convert number qualifiers from native to managed
                enumerationValueEntity.Value = ConvertNumericQualifier (enumerationValueEntity.Value);

                enumerationEntity.Values.Add (enumerationValueEntity);
            }

            // Get the definitions
            XElement termList = (from el in constantElement.ElementsAfterSelf ("dl")
                                 where (String)el.Attribute ("class") == "termdef"
                                 select el).FirstOrDefault ();
            if (termList != null) {
                IEnumerable<XElement> dtList = termList.Elements ("dt");
                IEnumerable<XElement> ddList = termList.Elements ("dd");

                if (dtList.Count () == ddList.Count ()) {
                    // Iterate over definitions
                    for (int i = 0; i < dtList.Count(); i++) {
                        String term = dtList.ElementAt (i).Value.TrimAll ();
                        IEnumerable<String> summaries = ddList.ElementAt (i).Elements ("p").Select (p => p.Value.TrimAll ());

                        // Find the enumeration value
                        EnumerationValueEntity enumerationValueEntity = enumerationEntity.Values.Find (v => v.Name == term);
                        if (enumerationValueEntity != null) {
                            foreach (string sum in summaries) {
                                if (CommentHelper.IsAvailability (sum)) {
                                    enumerationValueEntity.MinAvailability = CommentHelper.ExtractAvailability (sum);
                                    break;
                                }
                                enumerationValueEntity.Summary.Add (sum);
                            }
                        } else {
                            this.Logger.WriteLine ("Term with no match '" + term + "'");
                        }
                    }
                } else {
                    this.Logger.WriteLine ("MISMATCH in terms");
                }
            }

            // Make sure availability is ok
            enumerationEntity.AdjustAvailability ();

            return new List<BaseEntity> {enumerationEntity};
        }