Пример #1
0
        private Expression GetMapExpression(string mapKey)
        {
            string  program = "namespace Test { public class A { public void Method() { result = " + mapKey + "; } }}";
            IParser parser  = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(program));

            parser.ParseMethodBodies = true;
            parser.Parse();

            CompilationUnit cu = parser.CompilationUnit;

            ParentVisitor parentVisitor = new ParentVisitor();

            parentVisitor.VisitCompilationUnit(cu, null);

            TypeReferenceCorrector typeReferenceCorrector = new TypeReferenceCorrector();

            typeReferenceCorrector.VisitCompilationUnit(cu, null);

            MappingIdentifierMarker mappingIdentifierMarker = new MappingIdentifierMarker();

            mappingIdentifierMarker.MarkIdentifiers(cu);

            NamespaceDeclaration ns  = (NamespaceDeclaration)cu.Children[0];
            TypeDeclaration      ty  = (TypeDeclaration)ns.Children[0];
            MethodDeclaration    md  = (MethodDeclaration)ty.Children[0];
            ExpressionStatement  st  = (ExpressionStatement)md.Body.Children[0];
            AssignmentExpression ase = (AssignmentExpression)st.Expression;

            return(ase);
        }
Пример #2
0
        private void Translate()
        {
            codeBase = new CodeBase(GetLanguage());
            codeBase.Types.LibrariesFolder = Libraries;
            codeBase.Types.HelpersFolder   = HelperDirectory;

            codeBase.Mappings = new Mappings(Mappings);

            parentVisitor = new ParentVisitor();

            typesVisitor          = new TypesVisitor();
            typesVisitor.CodeBase = codeBase;

            projectTypeReferenceCorrector          = new TypeReferenceCorrector(true);
            projectTypeReferenceCorrector.CodeBase = codeBase;

            LoadFiles();

            codeBase.Types.Visitors.Add(parentVisitor);

            BeforeParse();
            progress.SetCount("Parsing", sourceFileCount);
            ParseAndPreVisit();

            BeforeTransformation();

            InheritedTypesExcludeTransformer inheritedTypesExcludeTransformer = new InheritedTypesExcludeTransformer();

            inheritedTypesExcludeTransformer.ParentTypes = baseTypeToExcludeMethod;
            CallVisitor(inheritedTypesExcludeTransformer, null);

            IDictionary visitors = GetVisitors(typeof(AbstractAstVisitor));

            visitors.Add(typeof(InheritorsVisitor).FullName, typeof(InheritorsVisitor));
            IDictionary transformers = GetVisitors(typeof(AbstractAstTransformer));

            transformers.Add(typeof(RenameRepeatedVariableTransformer).Name, typeof(RenameRepeatedVariableTransformer));
            progress.SetCount("Transformation", (visitors.Count + transformers.Count) * sourceFileCount);
            CallVisitors(visitors, "Transformation");
            CallVisitors(transformers, "Transformation");
            AfterTransformation();
            Diagnostics.Set("Phase", "Transformation");
            progress.SetCount("References", sourceFileCount);
            CallVisitor(typeof(ReferenceTransformer), "References");

            progress.SetCount("Mapping", 2 * sourceFileCount);
            CallVisitor(typeof(MemberMapper), "Mapping");
            CallVisitor(typeof(TypeMapper), "Mapping");

            BeforeRefactoring();

            int count = 6;

            if (Mode == "IKVM")
            {
                count++;
            }
            if (Namespace != null)
            {
                count++;
            }
            progress.SetCount("Refactoring", sourceFileCount * count);

            Refactor();

            CallVisitor(typeof(RemoveEmptyBlocksTransformer), null);

            OptimizeUsings();

            GenerateCode();

            SaveFiles();
        }
Пример #3
0
        private Expression GetMapExpression(string mapKey)
        {
            string program = "namespace Test { public class A { public void Method() { result = " + mapKey + "; } }}";
            IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(program));
            parser.ParseMethodBodies = true;
            parser.Parse();

            CompilationUnit cu = parser.CompilationUnit;

            ParentVisitor parentVisitor = new ParentVisitor();
            parentVisitor.VisitCompilationUnit(cu, null);

            TypeReferenceCorrector typeReferenceCorrector = new TypeReferenceCorrector();
            typeReferenceCorrector.VisitCompilationUnit(cu, null);

            MappingIdentifierMarker mappingIdentifierMarker = new MappingIdentifierMarker();
            mappingIdentifierMarker.MarkIdentifiers(cu);

            NamespaceDeclaration ns = (NamespaceDeclaration) cu.Children[0];
            TypeDeclaration ty = (TypeDeclaration) ns.Children[0];
            MethodDeclaration md = (MethodDeclaration) ty.Children[0];
            ExpressionStatement st = (ExpressionStatement) md.Body.Children[0];
            AssignmentExpression ase = (AssignmentExpression) st.Expression;
            return ase;
        }
Пример #4
0
        private void Translate()
        {
            codeBase = new CodeBase(GetLanguage());
            codeBase.Types.LibrariesFolder = Libraries;
            codeBase.Types.HelpersFolder = HelperDirectory;

            codeBase.Mappings = new Mappings(Mappings);

            parentVisitor = new ParentVisitor();

            typesVisitor = new TypesVisitor();
            typesVisitor.CodeBase = codeBase;

            projectTypeReferenceCorrector = new TypeReferenceCorrector(true);
            projectTypeReferenceCorrector.CodeBase = codeBase;

            LoadFiles();

            codeBase.Types.Visitors.Add(parentVisitor);

            BeforeParse();
            progress.SetCount("Parsing", sourceFileCount);
            ParseAndPreVisit();

            BeforeTransformation();

            InheritedTypesExcludeTransformer inheritedTypesExcludeTransformer = new InheritedTypesExcludeTransformer();
            inheritedTypesExcludeTransformer.ParentTypes = baseTypeToExcludeMethod;
            CallVisitor(inheritedTypesExcludeTransformer, null);

            IDictionary visitors = GetVisitors(typeof(AbstractAstVisitor));
            visitors.Add(typeof(InheritorsVisitor).FullName, typeof(InheritorsVisitor));
            IDictionary transformers = GetVisitors(typeof(AbstractAstTransformer));
            transformers.Add(typeof(RenameRepeatedVariableTransformer).Name, typeof(RenameRepeatedVariableTransformer));
            progress.SetCount("Transformation", (visitors.Count + transformers.Count) * sourceFileCount);
            CallVisitors(visitors, "Transformation");
            CallVisitors(transformers, "Transformation");
            AfterTransformation();
            Diagnostics.Set("Phase", "Transformation");
            progress.SetCount("References", sourceFileCount);
            CallVisitor(typeof(ReferenceTransformer), "References");

            progress.SetCount("Mapping", 2 * sourceFileCount);
            CallVisitor(typeof(MemberMapper), "Mapping");
            CallVisitor(typeof(TypeMapper), "Mapping");

            BeforeRefactoring();

            int count = 6;
            if (Mode == "IKVM")
                count++;
            if (Namespace != null)
                count++;
            progress.SetCount("Refactoring", sourceFileCount * count);

            Refactor();

            CallVisitor(typeof(RemoveEmptyBlocksTransformer), null);

            OptimizeUsings();

            GenerateCode();

            SaveFiles();
        }