Esempio n. 1
0
        private Type[] GetKnownTypes()
        {
            if (CompiledAssembly == null)
            {
                throw new Exception("Assembly is not compiled yet");
            }
            var assemblies = _cSharpProject.MetadataReferences.Select(i =>
            {
                if (i is PortableExecutableReference g)
                {
                    return(Sandbox.LoadByFullFilename(g.FilePath).WrappedAssembly);
                }
                throw new NotSupportedException(i.GetType().FullName);
            }).ToList();

            assemblies.Add(CompiledAssembly);
            return(CompileState.GetAllTypes(assemblies));
        }
Esempio n. 2
0
        public TranslationInfo ParseCsSource()
        {
            // must be public
            var knownTypes = GetKnownTypes();

            CheckRequiredTranslator();

            var translationInfo = new TranslationInfo(Sandbox);

            translationInfo.TranslationAssemblies.AddRange(_translationAssemblies);
            translationInfo.Prepare();
            // Console.WriteLine("======================");

            foreach (var tree in ProjectCompilation.SyntaxTrees)
            {
                var now = DateTime.Now;
                Console.WriteLine("parse file {0}", tree.FilePath);
                var root  = (CompilationUnitSyntax)tree.GetRoot();
                var state = new CompileState
                {
                    Context =
                    {
                        RoslynCompilation = ProjectCompilation,
                        RoslynModel       = ProjectCompilation.GetSemanticModel(tree)
                    }
                };
                translationInfo.State = state;

                var langVisitor = new LangVisitor(state)
                {
                    throwNotImplementedException = true
                };
                state.Context.KnownTypes = knownTypes;
                var compilationUnit = langVisitor.Visit(root) as CompilationUnit;
                translationInfo.Compiled.Add(compilationUnit);
                Console.WriteLine("    {0:0.0} sek", DateTime.Now.Subtract(now).TotalSeconds);
            }

            Console.WriteLine("Parsowanie c# skończone, mamy drzewo definicji");
            translationInfo.FillClassTranslations(knownTypes);
            return(translationInfo);
        }