Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Translate the exploded guy into a C# declaration
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        internal static string TranslateToCSharp(IDecl r)
        {
            if (r is RegularDecl)
            {
                var typ = (r as RegularDecl).Type;
                typ = TypeDefTranslator.ResolveTypedef(typ);

                if (typ == "string")
                {
                    throw new NotImplementedException("Unable to translate the C++ type of string");
                }

                var clsInfo = ROOTNET.NTClass.GetClass(typ);
                if (clsInfo != null)
                {
                    if (!clsInfo.IsShellTClass())
                    {
                        typ = "ROOTNET.Interface.N" + typ;
                    }
                    else
                    {
                        typ = typ.SanitizedName();
                    }
                }
                else
                {
                    typ = typ.SimpleCPPTypeToCSharpType();
                }

                if (typ == null)
                {
                    throw new InvalidOperationException("Don't know how to deal with type '" + (r as RegularDecl).Type + "'.");
                }

                return(typ);
            }

            var t = r as TemplateInfo;

            if (t.TemplateName != "vector")
            {
                throw new NotImplementedException("Don't know how to deal with anything but a vector right now!");
            }

            var argTrans = TranslateToCSharp(t.Arguments[0]);

            return(argTrans + "[]");
        }