Esempio n. 1
0
        public void TestConstCStyleArray()
        {
            // Simple set of types for an index array
            var vArray = new ItemCStyleArray("int[]", new ItemSimpleType("arr", "int"));

            vArray.Add(0, "10", true);
            var vIndex = new ItemSimpleType("n", "int");

            ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename")
            {
            };

            mainClass.Add(vIndex);
            mainClass.Add(vArray);
            var ntup = new NtupleTreeInfo()
            {
                Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0]
            };

            var userinfo = new TTreeUserInfo()
            {
                Groups = new ArrayGroup[] { new ArrayGroup()
                                            {
                                                Name      = "ungrouped",
                                                Variables = new VariableInfo[] {
                                                    new VariableInfo()
                                                    {
                                                        NETName = "n", TTreeName = "n"
                                                    },
                                                    new VariableInfo()
                                                    {
                                                        NETName = "arr", TTreeName = "arr"
                                                    }
                                                }
                                            } }
            };

            var cg         = new ClassGenerator();
            var outputFile = new FileInfo("TestConstCStyleArray.cs");

            cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>()
            {
                { "TestSimpleRename", userinfo }
            });

            CopyToOutput(outputFile);

            /// Look through this to see if we can make sure there are no renames!
            Assert.IsTrue(FindInFile(outputFile, "int[] arr"), "Array Decl missing");
            Assert.IsTrue(FindInFile(outputFile, "int n"), "Index decl missing");
            Assert.IsTrue(FindInFile(outputFile, "[ArraySizeIndex(\"10\", IsConstantExpression = true, Index = 0)]"), "Missing array size index attribute");
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void TestCStyleArrayBadIndexName()
        {
            // Simple set of types for an index array
            var vArray = new ItemCStyleArray("int[]", new ItemSimpleType("arr", "int"));

            vArray.Add(0, "i", false);
            var vIndex = new ItemSimpleType("n", "int");

            ROOTClassShell mainClass = new ROOTClassShell("TestSimpleRename")
            {
            };

            mainClass.Add(vIndex);
            mainClass.Add(vArray);
            var ntup = new NtupleTreeInfo()
            {
                Classes = new ROOTClassShell[] { mainClass }, ClassImplimintationFiles = new string[0]
            };

            var userinfo = new TTreeUserInfo()
            {
                Groups = new ArrayGroup[] { new ArrayGroup()
                                            {
                                                Name      = "ungrouped",
                                                Variables = new VariableInfo[] {
                                                    new VariableInfo()
                                                    {
                                                        NETName = "n", TTreeName = "n"
                                                    },
                                                    new VariableInfo()
                                                    {
                                                        NETName = "arr", TTreeName = "arr"
                                                    }
                                                }
                                            } }
            };

            var cg         = new ClassGenerator();
            var outputFile = new FileInfo("TestCStyleArray.cs");

            cg.GenerateClasss(ntup, outputFile, "junk", new Dictionary <string, TTreeUserInfo>()
            {
                { "TestSimpleRename", userinfo }
            });
        }