private IClassItem ExtractSimpleItem(SimpleLeafInfo leaf) { string className = TypeDefTranslator.ResolveTypedef(leaf.TypeName); // // Check if it is a c-style array. If it is, then the title will contain // the specification we need to look at for the c-style array bit. This will get // called recursively to parse the actual type after the c-style array bit is stripped off. // if (leaf.Title.Contains("[")) { return(ExtractCArrayInfo(leaf)); } // // Next, if the type is a template, special parse that. // var result = TemplateParser.ParseForTemplates(className); if (result is TemplateParser.TemplateInfo) { return(ExtractTemplateItem(leaf, result as TemplateParser.TemplateInfo)); } /// /// Ok - so it is a single "object" or similar. So we need to look at it and figure /// out how to deal with it. It could be a root object or just an "int" /// var ln = NormalizeLeafName(leaf.Name); IClassItem toAdd = null; if (IsROOTClass(className) && className != "string") { toAdd = new ItemROOTClass(ln, className); } else { toAdd = new ItemSimpleType(ln, className.SimpleCPPTypeToCSharpType()); } if (toAdd == null || toAdd.ItemType == null) { throw new InvalidOperationException("Unknown type - can't translate '" + className + "'."); } return(toAdd); }
/// <summary> /// We extract the class info for a ROOT class that is a template. We properly deal with the class being templatized /// being another crazy class (or just a vector of int, etc.). /// </summary> /// <param name="container"></param> /// <param name="memberName"></param> /// <param name="className"></param> /// <returns></returns> private IEnumerable <ROOTClassShell> ExtractROOTTemplateClass(ROOTClassShell container, string memberName, string className) { /// /// Currently only setup to deal with some very specific types of vectors! /// var parsedMatch = TemplateParser.ParseForTemplates(className) as TemplateParser.TemplateInfo; if (parsedMatch == null) { SimpleLogging.Log("Type '{0}' is a template, but we can't parse it, so '{1}' will be ignored", className, memberName); return(Enumerable.Empty <ROOTClassShell>()); } if (parsedMatch.TemplateName != "vector") { SimpleLogging.Log("We can only deal with the vector type (not '{0}'), so member '{1}' will be ignored", className, memberName); return(Enumerable.Empty <ROOTClassShell>()); } if (!(parsedMatch.Arguments[0] is TemplateParser.RegularDecl)) { SimpleLogging.Log("We can't yet deal with nested templates - '{0}' - so member '{1}' will be ignored", className, memberName); return(Enumerable.Empty <ROOTClassShell>()); } var templateArgClass = (parsedMatch.Arguments[0] as TemplateParser.RegularDecl).Type; // // Now we take a look at the class. // // One case is that it is a simple class, like "Unsigned int" that // isn't known to root at all. That means we hvae no dictionary for vector<unsigned int> - otherwise // we never would have gotten into here. So ignore it. :-) // var classInfo = ROOTNET.NTClass.GetClass(templateArgClass); if (classInfo == null) { return(Enumerable.Empty <ROOTClassShell>()); } // // If this class is known by root then we will have // a very easy time. No new classes are created or defined and there is nothing // extra to do other than making the element. if (!classInfo.IsShellTClass()) { container.Add(new ItemVector(TemplateParser.TranslateToCSharp(parsedMatch), memberName)); return(Enumerable.Empty <ROOTClassShell>()); } // // If the class isn't known by ROOT then we have only one hope - building it out of the // streamer (at this point, where we are in the code path, it is also the case that there // aren't leaf sub-branches here). // var newClassDefs = ExtractUnsplitUnknownClass(classInfo); container.Add(new ItemVector(TemplateParser.TranslateToCSharp(parsedMatch), memberName)); return(newClassDefs); }