Пример #1
0
        /// <summary>
        /// Correctly extract the leaf name. If it is an array, then it might not be what we are expecting here...
        /// </summary>
        /// <param name="leaf"></param>
        /// <returns></returns>
        private string ExtractVarName(SimpleLeafInfo leaf)
        {
            var m = _arrParser.Match(leaf.Title);

            if (!m.Success)
            {
                return(leaf.Name);
            }

            return(m.Groups["vname"].Value);
        }
Пример #2
0
 /// <summary>
 /// We are going to deal with a template of some sort for a simple item. At the moment we can deal only
 /// with simple STL's...
 /// </summary>
 /// <param name="leaf"></param>
 /// <param name="templateInfo"></param>
 /// <returns></returns>
 private IClassItem ExtractTemplateItem(SimpleLeafInfo leaf, TemplateParser.TemplateInfo templateInfo)
 {
     if (templateInfo.TemplateName == "vector")
     {
         return(new ItemVector(TemplateParser.TranslateToCSharp(templateInfo), ExtractVarName(leaf).SanitizedName()));
     }
     else
     {
         throw new NotImplementedException("We rae not able to handle template classes other than vector: '" + templateInfo.TemplateName + "'");
     }
 }
Пример #3
0
        /// <summary>
        /// This looks like a C style array - that is "[" and "]" are being used, and in the title. Extract the index in it
        /// and pass it along.
        /// </summary>
        /// <param name="leaf"></param>
        /// <returns></returns>
        private IClassItem ExtractCArrayInfo(SimpleLeafInfo leaf)
        {
            //
            // Grab the name first.
            //

            var m = _arrParser.Match(leaf.Title);

            if (!m.Success)
            {
                return(null);
            }

            var vname = m.Groups["vname"].Value;

            //
            // Next job is to parse the remaining type into a simple item that we can use...
            // this allows for "arbitrary" items that are C-style arrays.
            //

            var baseItem = ExtractSimpleItem(new SimpleLeafInfo()
            {
                Title = vname, Name = vname, TypeName = leaf.TypeName
            });

            //
            // Great! And then the new type will be whatever the type is of this base item, but indexed...
            //

            var tname = baseItem.ItemType;

            for (int i = 0; i < m.Groups["iname"].Captures.Count; i++)
            {
                tname += "[]";
            }
            var arr = new ItemCStyleArray(tname, baseItem);

            //
            // Now, loop through and grab all the indicies we can find.
            //

            int index = 0;

            foreach (var indexBound in m.Groups["iname"].Captures.Cast <Capture>())
            {
                index++;
                var  iname   = indexBound.Value;
                bool isConst = iname.All(char.IsDigit);
                arr.Add(0, iname, isConst);
            }
            return(arr);
        }
Пример #4
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);
        }
Пример #5
0
 public SimpleLeafInfo(SimpleLeafInfo old)
 {
     Name     = old.Name;
     Title    = old.Title;
     TypeName = old.TypeName;
 }
Пример #6
0
        /// <summary>
        /// Correctly extract the leaf name. If it is an array, then it might not be what we are expecting here...
        /// </summary>
        /// <param name="leaf"></param>
        /// <returns></returns>
        private string ExtractVarName(SimpleLeafInfo leaf)
        {
            var m = _arrParser.Match(leaf.Title);
            if (!m.Success)
                return leaf.Name;

            return m.Groups["vname"].Value;
        }
Пример #7
0
 /// <summary>
 /// We are going to deal with a template of some sort for a simple item. At the moment we can deal only
 /// with simple STL's...
 /// </summary>
 /// <param name="leaf"></param>
 /// <param name="templateInfo"></param>
 /// <returns></returns>
 private IClassItem ExtractTemplateItem(SimpleLeafInfo leaf, TemplateParser.TemplateInfo templateInfo)
 {
     if (templateInfo.TemplateName == "vector")
     {
         return new ItemVector(TemplateParser.TranslateToCSharp(templateInfo), ExtractVarName(leaf).SanitizedName());
     }
     else
     {
         throw new NotImplementedException("We rae not able to handle template classes other than vector: '" + templateInfo.TemplateName + "'");
     }
 }
Пример #8
0
        /// <summary>
        /// This looks like a C style array - that is "[" and "]" are being used, and in the title. Extract the index in it
        /// and pass it along.
        /// </summary>
        /// <param name="leaf"></param>
        /// <returns></returns>
        private IClassItem ExtractCArrayInfo(SimpleLeafInfo leaf)
        {
            //
            // Grab the name first.
            //

            var m = _arrParser.Match(leaf.Title);
            if (!m.Success)
                return null;

            var vname = m.Groups["vname"].Value;

            //
            // Next job is to parse the remaining type into a simple item that we can use...
            // this allows for "arbitrary" items that are C-style arrays.
            //

            var baseItem = ExtractSimpleItem(new SimpleLeafInfo() { Title = vname, Name = vname, TypeName = leaf.TypeName });

            //
            // Great! And then the new type will be whatever the type is of this base item, but indexed...
            //

            var tname = baseItem.ItemType;
            for (int i = 0; i < m.Groups["iname"].Captures.Count; i++)
            {
                tname += "[]";
            }
            var arr = new ItemCStyleArray(tname, baseItem);

            //
            // Now, loop through and grab all the indicies we can find.
            //

            int index = 0;
            foreach (var indexBound in m.Groups["iname"].Captures.Cast<Capture>())
            {
                index++;
                var iname = indexBound.Value;
                bool isConst = iname.All(char.IsDigit);
                arr.Add(0, iname, isConst);
            }
            return arr;
        }
Пример #9
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;
        }
Пример #10
0
 public SimpleLeafInfo(SimpleLeafInfo old)
 {
     Name = old.Name;
     Title = old.Title;
     TypeName = old.TypeName;
 }