public List <GenBase> Parse(XmlDocument doc, IEnumerable <string> fixups, string apiLevel, int productVersion) { if (doc == null) { return(null); } try { var apiFixup = new ApiFixup(doc); apiFixup.Process(from fixup in fixups select Load(fixup), apiLevel, productVersion); ApiSource = apiFixup.ApiSource; } catch (XmlException ex) { // BG4200 Report.Error(Report.ErrorParser + 0, ex, "Error during processing metadata fixup: {0}", ex.Message); return(null); } XmlElement root = doc.DocumentElement; if ((root == null) || !root.HasChildNodes) { Report.Warning(0, Report.WarningParser + 1, "No packages found."); return(null); } List <GenBase> gens = new List <GenBase> (); foreach (XmlNode child in root.ChildNodes) { XmlElement elem = child as XmlElement; if (elem == null) { continue; } switch (child.Name) { case "package": gens.AddRange(ParsePackage(elem)); break; case "enum": ISymbol sym = new EnumSymbol(elem.XGetAttribute("name")); SymbolTable.AddType(elem.XGetAttribute("name"), sym); continue; default: Report.Warning(0, Report.WarningParser + 2, "Unexpected child node: {0}.", child.Name); break; } } return(gens); }
public List <GenBase> Parse(XDocument doc, IEnumerable <string> fixups, string apiLevel, int productVersion) { if (doc == null) { return(null); } try { var apiFixup = new ApiFixup(doc); apiFixup.Process(from fixup in fixups select Load(fixup), apiLevel, productVersion); ApiSource = apiFixup.ApiSource; } catch (XmlException ex) { // BG4200 Report.LogCodedError(Report.ErrorFailedToProcessMetadata, ex.Message); return(null); } var root = doc.Root; if ((root == null) || !root.HasElements) { Report.LogCodedWarning(0, Report.WarningNoPackageElements); return(null); } List <GenBase> gens = new List <GenBase> (); foreach (var elem in root.Elements()) { switch (elem.Name.LocalName) { case "package": gens.AddRange(ParsePackage(elem)); break; case "enum": ISymbol sym = new EnumSymbol(elem.XGetAttribute("name")); opt.SymbolTable.AddType(elem.XGetAttribute("name"), sym); continue; default: Report.LogCodedWarning(0, Report.WarningUnexpectedRootChildNode, elem.Name.ToString()); break; } } return(gens); }