コード例 #1
0
        public void GenerateClassFromClasses(
            ClassGenerator target,
            int outputChoice,
            int numExtraFiles,
            int numExtraFilesToCreate,
            int extraFileIndexNull,
            int proxyPathChoice,
            string nameSName,
            int NumObjectCollection)
        {
            if (numExtraFiles < 0
                || numExtraFilesToCreate < 0
                || extraFileIndexNull < 0
                || outputChoice < 0
                || proxyPathChoice < 0
                || NumObjectCollection < 0)
                return;

            ///
            /// Kill off the directory we might have left behind from a previous run, and create a new one.
            /// 

            DirectoryInfo testDir = new DirectoryInfo(".\\GenerateClassFromClasses");
            if (testDir.Exists)
            {
                testDir.Delete(true);
            }
            testDir.Create();

            ///
            /// Setup the input stuff so Pex can play
            /// 

            FileInfo outputCSFile;
            if (outputChoice == 1)
            {
                outputCSFile = new FileInfo(testDir.FullName + "\\output.cs");
            }
            else
            {
                outputCSFile = null;
            }

            ROOTClassShell[] objCollect = null;
            if (NumObjectCollection > 0)
            {
                List<ROOTClassShell> objs = new List<ROOTClassShell>();

                for (int i = 0; i < NumObjectCollection; i++)
                {
                    ROOTClassShell rcs = new ROOTClassShell();
                    rcs.Name = "dude_" + i.ToString();

                    for (int j = 0; j < i; j++)
                    {
                        IClassItem item = null;
                        switch (NumObjectCollection % 4)
                        {
                            case 0:
                                item = null;
                                break;

                            case 1:
                                var itm = new ItemSimpleType() { ItemType = "int" };
                                item = itm;
                                break;

                            case 2:
                                var itmv = new ItemVector() { ItemType = "int[]" };
                                item = itmv;
                                break;

                            case 3:
                                var itmr = new ItemROOTClass() { ItemType = "TLorentzVector" };
                                item = itmr;
                                break;
                        }
                        if (item != null)
                            item.Name = "item_" + j.ToString();
                        rcs.Items.Add(item);
                    }
                    objs.Add(rcs);
                }

                if (NumObjectCollection > 0)
                {
                    if (proxyPathChoice == 1)
                    {
                        var proxyFile = new FileInfo(testDir.FullName + "\\GenerateClassFromClasses_" + proxyPathChoice.ToString() + ".h");
                        using (var w = proxyFile.CreateText())
                        {
                            w.WriteLine("hi");
                            w.Close();
                        }
                        objs[0].NtupleProxyPath = proxyFile.FullName;
                    }

                    if (proxyPathChoice == 2)
                    {
                        var proxyFile = new FileInfo(testDir.FullName + "\\GenerateClassFromClasses_" + proxyPathChoice.ToString() + ".h");
                        objs[0].NtupleProxyPath = proxyFile.FullName;
                    }

                    if (proxyPathChoice == 3)
                    {
                        var proxyFile = new FileInfo(testDir.FullName + "\\GenerateClassFromClasses_" + proxyPathChoice.ToString() + ".h");
                        using (var w = proxyFile.CreateText())
                        {
                            w.WriteLine("hi");
                            w.Close();
                        }
                        foreach (var item in objs)
                        {
                            item.NtupleProxyPath = proxyFile.FullName;
                        }
                    }
                }
                objCollect = objs.ToArray();
            }

            ///
            /// Create the final object, and any extra files needed!
            /// 

            NtupleTreeInfo info = new NtupleTreeInfo() { Classes = objCollect };

            info.ClassImplimintationFiles = (from c in Enumerable.Range(0, numExtraFiles)
                                             let f = new FileInfo(testDir.FullName + "\\GenerateClassFromClasses_extra_" + c.ToString() + ".cpp")
                                             select f.FullName
                                                 ).ToArray();

            int maxFilesToCreate = numExtraFilesToCreate > numExtraFiles ? numExtraFiles : numExtraFilesToCreate;
            for (int i = 0; i < maxFilesToCreate; i++)
            {
                using (var w = File.CreateText(info.ClassImplimintationFiles[i]))
                {
                    w.WriteLine();
                    w.Close();
                }
            }

            if (extraFileIndexNull < numExtraFiles)
            {
                info.ClassImplimintationFiles[extraFileIndexNull] = null;
            }

            ///
            /// Ok, do the investigation
            /// 

            target.GenerateClasss(info, outputCSFile, nameSName);

            Assert.IsFalse(info.Classes.Any(c => c.NtupleProxyPath == null), "No null proxy paths allowed");
            Assert.IsFalse(info.Classes.Any(c => !File.Exists(c.NtupleProxyPath)), "proxy files must exist");

            Assert.IsFalse(info.ClassImplimintationFiles.Any(c => c == null), "no null implementation files allowed");
            Assert.IsFalse(info.ClassImplimintationFiles.Any(c => !File.Exists(c)), "all implimntation files must exist");

            /// Check that all the ntuple proxy guys and the temp file guys appear in the file

            foreach (var item in info.Classes.Where(c => c.IsTopLevelClass))
            {
                Assert.IsTrue(FindInFile(outputCSFile, item.NtupleProxyPath), "Could not find the proxy path '" + item.NtupleProxyPath + "'");
            }
            foreach (var item in info.ClassImplimintationFiles)
            {
                Assert.IsTrue(FindInFile(outputCSFile, item), "coul dnot find impl file '" + item + "'");
            }
        }
コード例 #2
0
ファイル: ParseTTree.cs プロジェクト: gordonwatts/LINQtoROOT
        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;
        }