Exemple #1
0
        public void TestCsharpParse()
        {
            var testFile = PutTestFileOnDisk("SimpleExample.eg");

            Assert.IsTrue(System.IO.File.Exists(testFile));

            var testResult = CsharpParseTree.InvokeParse(testFile);

            Assert.IsNotNull(testResult);
            Assert.IsNotNull(testResult.CatchBlocks);
            Assert.AreNotEqual(0, testResult.CatchBlocks.Count);

            foreach (var c in testResult.CatchBlocks)
            {
                Console.WriteLine(c);
            }
        }
Exemple #2
0
        public CgTypeCsSrcCode(string assemblyPath, string typeFullName)
        {
            if (string.IsNullOrWhiteSpace(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath));
            }
            AssemblyPath = assemblyPath;
            if (!File.Exists(AssemblyPath))
            {
                throw new FileNotFoundException("Cannot find the compiled assembly.", assemblyPath);
            }

            //this is how we line up a source code file to a reflected runtime type
            var invokeDia2Dump = new InvokeDia2Dump.GetPdbData(assemblyPath);
            var pdbLines       = invokeDia2Dump.SingleTypeNamed(typeFullName);

            if (pdbLines == null)
            {
                throw new ItsDeadJim("Dia2Dump.exe did not return anything for the type " +
                                     $"named '{typeFullName}' from '{invokeDia2Dump.PdbAssemblyFilePath}'");
            }

            //but we don't want the type in our appDomain, so we shell it out as a code-gen type
            _cgType = Etc.GetIsolatedCgOfType(assemblyPath, typeFullName, true);

            _cgType.AssignPdbSymbols(pdbLines.moduleSymbols);

            var sourceCodeFiles = pdbLines.moduleSymbols.Select(ms => ms.file);

            foreach (var src in sourceCodeFiles)
            {
                if (!File.Exists(src))
                {
                    continue;
                }

                //ANTLR CSharp parser seems to have problems with Preprocessor cmd\directives\macros
                var srcLines = File.ReadAllLines(src);
                srcLines = Settings.LangStyle.RemovePreprocessorCmds(srcLines);
                File.WriteAllLines(src, srcLines);

                var antlrParseRslts = CsharpParseTree.InvokeParse(src);
                _cgType.AssignAntlrParseItems(GetAntlrParseItems(antlrParseRslts));
            }
        }
Exemple #3
0
        public CgTypeCsSrcCode(string assemblyPath, string typeFullName, params string[] sourceCodeFiles)
        {
            if (string.IsNullOrWhiteSpace(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath));
            }
            AssemblyPath = assemblyPath;
            if (!File.Exists(AssemblyPath))
            {
                throw new FileNotFoundException("Cannot find the compiled assembly.", assemblyPath);
            }
            _cgType = Etc.GetIsolatedCgOfType(assemblyPath, typeFullName, true);
            if (sourceCodeFiles == null || !sourceCodeFiles.Any())
            {
                return;
            }

            foreach (var src in sourceCodeFiles)
            {
                var antlrParseRslts = CsharpParseTree.InvokeParse(src);
                _cgType.AssignAntlrParseItems(GetAntlrParseItems(antlrParseRslts));
            }
        }
Exemple #4
0
        public CgTypeCsSrcCode(Assembly asm, string typeFullName, params string[] sourceCodeFiles)
        {
            if (asm == null)
            {
                throw new ArgumentNullException(nameof(asm));
            }
            AssemblyPath = asm.Location;
            if (!File.Exists(AssemblyPath))
            {
                throw new FileNotFoundException("Cannot find the compiled assembly.", AssemblyPath);
            }

            //this is how we line up a source code file to a reflected runtime type
            var invokeDia2Dump = new InvokeDia2Dump.GetPdbData(AssemblyPath);
            var pdbLines       = invokeDia2Dump.SingleTypeNamed(typeFullName);

            if (pdbLines == null)
            {
                throw new ItsDeadJim("Dia2Dump.exe did not return anything for the type " +
                                     $"named '{typeFullName}' from '{invokeDia2Dump.PdbAssemblyFilePath}'");
            }

            _cgType = Etc.GetCgOfType(asm, typeFullName, true);

            _cgType.AssignPdbSymbols(pdbLines.moduleSymbols);

            var scf = sourceCodeFiles?.ToList() ?? new List <string>();

            scf.AddRange(pdbLines.moduleSymbols.Select(ms => ms.file));

            foreach (var src in sourceCodeFiles)
            {
                var antlrParseRslts = CsharpParseTree.InvokeParse(src);
                _cgType.AssignAntlrParseItems(GetAntlrParseItems(antlrParseRslts));
            }
        }