public override void Run()
		{
			IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent;
			
			if (content != null && content.PrimaryFileName != null && content is IEditable) {
				
				IParser p = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(((IEditable)content).Text));
				p.Parse();
				if (p.Errors.Count > 0) {
					MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Convert.CorrectSourceCodeErrors}\n" + p.Errors.ErrorOutput);
					return;
				}
				
				VBNetOutputVisitor vbv = new VBNetOutputVisitor();
				
				List<ISpecial> specials = p.Lexer.SpecialTracker.CurrentSpecials;
				PreprocessingDirective.CSharpToVB(specials);
				IAstVisitor v = new CSharpToVBNetConvertVisitor(ParserService.CurrentProjectContent,
				                                                ParserService.GetParseInformation(content.PrimaryFileName));
				v.VisitCompilationUnit(p.CompilationUnit, null);
				using (SpecialNodesInserter.Install(specials, vbv)) {
					vbv.VisitCompilationUnit(p.CompilationUnit, null);
				}
				
				FileService.NewFile("Generated.vb", vbv.Text);
			}
		}
        public string Convert()
        {
            TextReader Reader = this.GetReader();
            IParser    Parser = ParserFactory.CreateParser(this.From, Reader);

            Parser.Parse();
            if (Parser.Errors.Count > 0)
            {
                Log(Level.Error, Parser.Errors.ErrorOutput);
                throw new BuildException("Errors parsing code.", this.Location);
            }
            CompilationUnit Tree = Parser.CompilationUnit;

            IOutputAstVisitor OutputVisitor = null;

            switch (this.To)
            {
            case SupportedLanguage.CSharp:
                OutputVisitor = new CSharpOutputVisitor();
                break;

            case SupportedLanguage.VBNet:
                OutputVisitor = new VBNetOutputVisitor();
                break;
            }
            Tree.AcceptVisitor(OutputVisitor, null);

            return(OutputVisitor.Text);
        }
Esempio n. 3
0
        public override void Run()
        {
            IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent;

            if (content != null && content.PrimaryFileName != null && content is IEditable)
            {
                IParser p = ParserFactory.CreateParser(SupportedLanguage.CSharp, ((IEditable)content).CreateSnapshot().CreateReader());
                p.Parse();
                if (p.Errors.Count > 0)
                {
                    MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Convert.CorrectSourceCodeErrors}\n" + p.Errors.ErrorOutput);
                    return;
                }

                VBNetOutputVisitor vbv = new VBNetOutputVisitor();

                List <ISpecial> specials = p.Lexer.SpecialTracker.CurrentSpecials;
                PreprocessingDirective.CSharpToVB(specials);
                IAstVisitor v = new CSharpToVBNetConvertVisitor(ParserService.CurrentProjectContent,
                                                                ParserService.GetParseInformation(content.PrimaryFileName));
                v.VisitCompilationUnit(p.CompilationUnit, null);
                using (SpecialNodesInserter.Install(specials, vbv)) {
                    vbv.VisitCompilationUnit(p.CompilationUnit, null);
                }

                FileService.NewFile("Generated.vb", vbv.Text);
            }
        }
 private static string GenerateCode(string sourceCode, SupportedLanguage language)
 {
     using (IParser parser = ParserFactory.CreateParser(language, new StringReader(sourceCode)))
     {
         parser.Parse();
         if (parser.Errors.Count == 0)
         {
             IList <ISpecial>  savedSpecialsList = new ISpecial[0];
             IOutputAstVisitor targetVisitor;
             if (language == SupportedLanguage.CSharp)
             {
                 targetVisitor = new VBNetOutputVisitor();
             }
             else
             {
                 targetVisitor = new CSharpOutputVisitor();
             }
             using (SpecialNodesInserter.Install(savedSpecialsList, targetVisitor))
             {
                 parser.CompilationUnit.AcceptVisitor(targetVisitor, null);
             }
             return(targetVisitor.Text);
         }
         StringBuilder errorBuilder = new StringBuilder();
         return(parser.Errors.ErrorOutput);
     }
 }
Esempio n. 5
0
        public override void Run()
        {
            IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;

            if (window != null && window.ViewContent is IEditable)
            {
                IParser p = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(((IEditable)window.ViewContent).Text));
                p.Parse();
                if (p.Errors.Count > 0)
                {
                    MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Convert.CorrectSourceCodeErrors}\n" + p.Errors.ErrorOutput);
                    return;
                }

                VBNetOutputVisitor vbv = new VBNetOutputVisitor();

                List <ISpecial> specials = p.Lexer.SpecialTracker.CurrentSpecials;
                PreprocessingDirective.CSharpToVB(specials);
                new CSharpToVBNetConvertVisitor().VisitCompilationUnit(p.CompilationUnit, null);
                using (SpecialNodesInserter.Install(specials, vbv)) {
                    vbv.VisitCompilationUnit(p.CompilationUnit, null);
                }

                FileService.NewFile("Generated.VB", "VBNET", vbv.Text);
            }
        }
Esempio n. 6
0
		public override void Run()
		{
			IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
			
			if (window != null && window.ViewContent is IEditable) {
				
				IParser p = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(((IEditable)window.ViewContent).Text));
				p.Parse();
				if (p.Errors.Count > 0) {
					MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Convert.CorrectSourceCodeErrors}\n" + p.Errors.ErrorOutput);
					return;
				}
				
				VBNetOutputVisitor vbv = new VBNetOutputVisitor();
				
				List<ISpecial> specials = p.Lexer.SpecialTracker.CurrentSpecials;
				PreprocessingDirective.CSharpToVB(specials);
				new CSharpToVBNetConvertVisitor().VisitCompilationUnit(p.CompilationUnit, null);
				using (SpecialNodesInserter.Install(specials, vbv)) {
					vbv.VisitCompilationUnit(p.CompilationUnit, null);
				}
				
				FileService.NewFile("Generated.VB", "VBNET", vbv.Text);
			}
		}
        void CS2VB(string input, string expectedOutput)
        {
            SnippetParser parser = new SnippetParser(SupportedLanguage.CSharp);
            INode         node   = parser.Parse(input);

            // parser.Errors.ErrorOutput contains syntax errors, if any
            Assert.IsNotNull(node);
            Assert.AreEqual("", parser.Errors.ErrorOutput);
            // parser.Specials is the list of comments, preprocessor directives etc.
            PreprocessingDirective.CSharpToVB(parser.Specials);
            // Convert C# constructs to VB.NET:
            node.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
            node.AcceptVisitor(new ToVBNetConvertVisitor(), null);

            VBNetOutputVisitor output = new VBNetOutputVisitor();

            using (SpecialNodesInserter.Install(parser.Specials, output))
            {
                node.AcceptVisitor(output, null);
            }
            // output.Errors.ErrorOutput contains conversion errors/warnings, if any
            // output.Text contains the converted code
            Assert.AreEqual("", output.Errors.ErrorOutput);
            Assert.AreEqual(expectedOutput, output.Text);
        }
		protected string GenerateParams(Type eventType)
		{
			VBNetOutputVisitor v = new VBNetOutputVisitor();
			MethodDeclaration md = ConvertEventInvokeMethodToNRefactory(this.CurrentClassPart, eventType, "name");
			if (md != null) {
				v.AppendCommaSeparatedList(md.Parameters);
			}
			return v.Text;
		}
Esempio n. 9
0
        string AddInteger <T>(string input, int number) where T : Expression
        {
            Expression e = ParseUtil.ParseExpression <T>(input);

            e = Expression.AddInteger(e, number);
            VBNetOutputVisitor v = new VBNetOutputVisitor();

            e.AcceptVisitor(v, null);
            return(v.Text);
        }
Esempio n. 10
0
		void TestProgram(string program)
		{
			IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(program));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
			outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text));
		}
Esempio n. 11
0
		void TestExpression(string expression)
		{
			IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(expression));
			Expression e = parser.ParseExpression();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
			e.AcceptVisitor(outputVisitor, null);
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(StripWhitespace(expression), StripWhitespace(outputVisitor.Text));
		}
Esempio n. 12
0
        public override IOutputAstVisitor CreateOutputVisitor()
        {
            VBNetOutputVisitor      v    = new VBNetOutputVisitor();
            VBNetPrettyPrintOptions pOpt = v.Options;

            pOpt.IndentationChar = this.Options.IndentString[0];
            pOpt.IndentSize      = this.Options.IndentString.Length;
            pOpt.TabSize         = this.Options.IndentString.Length;

            return(v);
        }
Esempio n. 13
0
        protected string GenerateParams(Type eventType)
        {
            VBNetOutputVisitor v  = new VBNetOutputVisitor();
            MethodDeclaration  md = ConvertEventInvokeMethodToNRefactory(this.CurrentClassPart, eventType, "name");

            if (md != null)
            {
                v.AppendCommaSeparatedList(md.Parameters);
            }
            return(v.Text);
        }
Esempio n. 14
0
		void TestProgram(string program)
		{
			VBParser parser = ParserFactory.CreateParser(new StringReader(program));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
			outputVisitor.Options.OutputByValModifier = true;
			outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text));
		}
		public void TestProgram(string input, string expectedOutput)
		{
			IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(input));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			parser.CompilationUnit.AcceptVisitor(new CSharpToVBNetConvertVisitor(), null);
			VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
			outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(expectedOutput, outputVisitor.Text);
		}
        public static string PrettyPrint(this INode code)
        {
            if (code == null)
            {
                return(string.Empty);
            }
            VBNetOutputVisitor csOutVisitor = new VBNetOutputVisitor();

            code.AcceptVisitor(csOutVisitor, null);
            return(csOutVisitor.Text);
        }
Esempio n. 17
0
        public void rewriteCode_VBNet(CompilationUnit unit, IList<ISpecial> specials)
        {
            var outputVisitor  = new VBNetOutputVisitor();    		
            using (SpecialNodesInserter.Install(specials, outputVisitor)) {
                unit.AcceptVisitor(outputVisitor, null);
            }
            //codeTextBox.Text = outputVisitor.Text.Replace("\t", "  ");
            VBNetCode = outputVisitor.Text;
    		
//    		PublicDI.log.debug(recreatedCode);
        }
		public override IOutputAstVisitor CreateOutputVisitor()
		{
			VBNetOutputVisitor v = new VBNetOutputVisitor();
			VBNetPrettyPrintOptions pOpt = v.Options;
			
			pOpt.IndentationChar = this.Options.IndentString[0];
			pOpt.IndentSize = this.Options.IndentString.Length;
			pOpt.TabSize = this.Options.IndentString.Length;
			
			return v;
		}
Esempio n. 19
0
        void TestExpression(string expression)
        {
            VBParser   parser = ParserFactory.CreateParser(new StringReader(expression));
            Expression e      = parser.ParseExpression();

            Assert.AreEqual("", parser.Errors.ErrorOutput);
            VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();

            e.AcceptVisitor(outputVisitor, null);
            Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
            Assert.AreEqual(StripWhitespace(expression), StripWhitespace(outputVisitor.Text));
        }
Esempio n. 20
0
        public static string ConvertCS2VBNET(string cscode)
        {
            var snippetParser = new SnippetParser(SupportedLanguage.CSharp);
            var node          = snippetParser.Parse(cscode);

            node.AcceptVisitor(new ToVBNetConvertVisitor(), null);
            var netOutputVisitor = new VBNetOutputVisitor();

            using (SpecialNodesInserter.Install(snippetParser.Specials, netOutputVisitor))
                node.AcceptVisitor(netOutputVisitor, null);
            return(netOutputVisitor.Text);
        }
Esempio n. 21
0
        public void rewriteCode_VBNet(CompilationUnit unit, IList <ISpecial> specials)
        {
            var outputVisitor = new VBNetOutputVisitor();

            using (SpecialNodesInserter.Install(specials, outputVisitor)) {
                unit.AcceptVisitor(outputVisitor, null);
            }
            //codeTextBox.Text = outputVisitor.Text.Replace("\t", "  ");
            VBNetCode = outputVisitor.Text;

//          PublicDI.log.debug(recreatedCode);
        }
Esempio n. 22
0
        void TestProgram(string program)
        {
            IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(program));

            parser.Parse();
            Assert.AreEqual("", parser.Errors.ErrorOutput);
            VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();

            outputVisitor.Visit(parser.CompilationUnit, null);
            Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
            Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text));
        }
Esempio n. 23
0
 void GenerateCodeButtonClick(object sender, EventArgs e)
 {
     if (syntaxTree.Unit != null)
     {
         VBNetOutputVisitor visitor = new VBNetOutputVisitor();
         // re-insert the comments we saved from the parser into the output
         using (SpecialNodesInserter.Install(savedSpecials, visitor)) {
             syntaxTree.Unit.AcceptVisitor(visitor, null);
         }
         codeView.Text = visitor.Text.Replace("\t", "  ");
     }
 }
Esempio n. 24
0
        void TestProgram(string program)
        {
            VBParser parser = ParserFactory.CreateParser(new StringReader(program));

            parser.Parse();
            Assert.AreEqual("", parser.Errors.ErrorOutput);
            VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();

            outputVisitor.Options.OutputByValModifier = true;
            outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
            Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
            Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text));
        }
Esempio n. 25
0
        public void TestProgram(string input, string expectedOutput)
        {
            IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(input));

            parser.Parse();
            Assert.AreEqual("", parser.Errors.ErrorOutput);
            parser.CompilationUnit.AcceptVisitor(new CSharpToVBNetConvertVisitor(), null);
            VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();

            outputVisitor.Visit(parser.CompilationUnit, null);
            Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
            Assert.AreEqual(expectedOutput, outputVisitor.Text);
        }
		void TestProgramCS2VB(string programCS, string programVB)
		{
			IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(programCS));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
			using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(),
			                                    outputVisitor)) {
				outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			}
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(programVB.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
			parser.Dispose();
		}
		public void TestProgram(string input, string expectedOutput)
		{
			IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(input));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			parser.CompilationUnit.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
			parser.CompilationUnit.AcceptVisitor(new ToVBNetConvertVisitor(), null);
			VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
			outputVisitor.Options.IndentationChar = ' ';
			outputVisitor.Options.IndentSize = 2;
			outputVisitor.Options.OutputByValModifier = true;
			outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(expectedOutput, outputVisitor.Text);
		}
Esempio n. 28
0
        void TestProgramCS2VB(string programCS, string programVB)
        {
            IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(programCS));

            parser.Parse();
            Assert.AreEqual("", parser.Errors.ErrorOutput);
            VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();

            using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(),
                                                outputVisitor)) {
                outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
            }
            Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
            Assert.AreEqual(programVB.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
            parser.Dispose();
        }
		public override void PrintPreprocessingDirective(PreprocessingDirective directive, bool forceWriteInPreviousBlock)
		{
			if (IsInMemberBody
			    && (string.Equals(directive.Cmd, "#Region", StringComparison.InvariantCultureIgnoreCase)
			        || string.Equals(directive.Cmd, "#End", StringComparison.InvariantCultureIgnoreCase)
			        && directive.Arg.StartsWith("Region", StringComparison.InvariantCultureIgnoreCase)))
			{
				WriteLineInPreviousLine("'" + directive.Cmd + " " + directive.Arg, forceWriteInPreviousBlock);
			} else if (!directive.Expression.IsNull) {
				VBNetOutputVisitor visitor = new VBNetOutputVisitor();
				directive.Expression.AcceptVisitor(visitor, null);
				WriteLineInPreviousLine(directive.Cmd + " " + visitor.Text + " Then", forceWriteInPreviousBlock);
			} else {
				base.PrintPreprocessingDirective(directive, forceWriteInPreviousBlock);
			}
		}
Esempio n. 30
0
		void TestProgramCS2VB(string programCS, string programVB)
		{
			IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(programCS));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
			List<ISpecial> specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
			PreprocessingDirective.CSharpToVB(specials);
			outputVisitor.Options.IndentationChar = ' ';
			outputVisitor.Options.IndentSize = 2;
			using (SpecialNodesInserter.Install(specials, outputVisitor)) {
				outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			}
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(programVB.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
			parser.Dispose();
		}
Esempio n. 31
0
		void TestProgram(string program)
		{
			VBParser parser = ParserFactory.CreateParser(new StringReader(program));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
			outputVisitor.Options.IndentationChar = ' ';
			outputVisitor.Options.TabSize = 2;
			outputVisitor.Options.IndentSize = 2;
			using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(),
			                                    outputVisitor)) {
				outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			}
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(program.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
			parser.Dispose();
		}
        public void TestProgram(string input, string expectedOutput)
        {
            IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(input));

            parser.Parse();
            Assert.AreEqual("", parser.Errors.ErrorOutput);
            parser.CompilationUnit.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
            parser.CompilationUnit.AcceptVisitor(new ToVBNetConvertVisitor(), null);
            VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();

            outputVisitor.Options.IndentationChar     = ' ';
            outputVisitor.Options.IndentSize          = 2;
            outputVisitor.Options.OutputByValModifier = true;
            outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
            Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
            Assert.AreEqual(expectedOutput, outputVisitor.Text);
        }
Esempio n. 33
0
 public virtual void PrintPreprocessingDirective(PreprocessingDirective directive, bool forceWriteInPreviousBlock)
 {
     if (!directive.Expression.IsNull)
     {
         VBNetOutputVisitor visitor = new VBNetOutputVisitor();
         directive.Expression.AcceptVisitor(visitor, null);
         WriteLineInPreviousLine(directive.Cmd + " " + visitor.Text, forceWriteInPreviousBlock);
     }
     else if (string.IsNullOrEmpty(directive.Arg))
     {
         WriteLineInPreviousLine(directive.Cmd, forceWriteInPreviousBlock);
     }
     else
     {
         WriteLineInPreviousLine(directive.Cmd + " " + directive.Arg, forceWriteInPreviousBlock);
     }
 }
Esempio n. 34
0
        void TestProgram(string program)
        {
            VBParser parser = ParserFactory.CreateParser(new StringReader(program));

            parser.Parse();
            Assert.AreEqual("", parser.Errors.ErrorOutput);
            VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();

            outputVisitor.Options.IndentationChar = ' ';
            outputVisitor.Options.TabSize         = 2;
            outputVisitor.Options.IndentSize      = 2;
            using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(),
                                                outputVisitor)) {
                outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
            }
            Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
            Assert.AreEqual(program.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
            parser.Dispose();
        }
Esempio n. 35
0
        void TestProgramCS2VB(string programCS, string programVB)
        {
            IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(programCS));

            parser.Parse();
            Assert.AreEqual("", parser.Errors.ErrorOutput);
            VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
            List <ISpecial>    specials      = parser.Lexer.SpecialTracker.RetrieveSpecials();

            PreprocessingDirective.CSharpToVB(specials);
            outputVisitor.Options.IndentationChar = ' ';
            outputVisitor.Options.IndentSize      = 2;
            using (SpecialNodesInserter.Install(specials, outputVisitor)) {
                outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
            }
            Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
            Assert.AreEqual(programVB.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
            parser.Dispose();
        }
		public void TestProgram(string input, string expectedOutput)
		{
			IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(input));
			parser.Parse();
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			var specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
			PreprocessingDirective.CSharpToVB(specials);
			parser.CompilationUnit.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
			parser.CompilationUnit.AcceptVisitor(new ToVBNetConvertVisitor(), null);
			VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
			outputVisitor.Options.IndentationChar = ' ';
			outputVisitor.Options.IndentSize = 2;
			outputVisitor.Options.OutputByValModifier = true;
			using (SpecialNodesInserter.Install(specials, outputVisitor)) {
				outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
			}
			Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
			Assert.AreEqual(expectedOutput.Replace("\r", ""), outputVisitor.Text.Replace("\r", ""));
		}
Esempio n. 37
0
 public override void PrintPreprocessingDirective(PreprocessingDirective directive, bool forceWriteInPreviousBlock)
 {
     if (IsInMemberBody &&
         (string.Equals(directive.Cmd, "#Region", StringComparison.InvariantCultureIgnoreCase) ||
          string.Equals(directive.Cmd, "#End", StringComparison.InvariantCultureIgnoreCase) &&
          directive.Arg.StartsWith("Region", StringComparison.InvariantCultureIgnoreCase)))
     {
         WriteLineInPreviousLine("'" + directive.Cmd + " " + directive.Arg, forceWriteInPreviousBlock);
     }
     else if (!directive.Expression.IsNull)
     {
         VBNetOutputVisitor visitor = new VBNetOutputVisitor();
         directive.Expression.AcceptVisitor(visitor, null);
         WriteLineInPreviousLine(directive.Cmd + " " + visitor.Text + " Then", forceWriteInPreviousBlock);
     }
     else
     {
         base.PrintPreprocessingDirective(directive, forceWriteInPreviousBlock);
     }
 }
Esempio n. 38
0
        public void TestProgram(string input, string expectedOutput)
        {
            IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(input));

            parser.Parse();
            Assert.AreEqual("", parser.Errors.ErrorOutput);
            var specials = parser.Lexer.SpecialTracker.RetrieveSpecials();

            PreprocessingDirective.CSharpToVB(specials);
            parser.CompilationUnit.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
            parser.CompilationUnit.AcceptVisitor(new ToVBNetConvertVisitor(), null);
            VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();

            outputVisitor.Options.IndentationChar     = ' ';
            outputVisitor.Options.IndentSize          = 2;
            outputVisitor.Options.OutputByValModifier = true;
            using (SpecialNodesInserter.Install(specials, outputVisitor)) {
                outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
            }
            Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
            Assert.AreEqual(expectedOutput.Replace("\r", ""), outputVisitor.Text.Replace("\r", ""));
        }
		void CS2VB(string input, string expectedOutput)
		{
			SnippetParser parser = new SnippetParser(SupportedLanguage.CSharp);
			INode node = parser.Parse(input);
			// parser.Errors.ErrorOutput contains syntax errors, if any
			Assert.IsNotNull(node);
			Assert.AreEqual("", parser.Errors.ErrorOutput);
			// parser.Specials is the list of comments, preprocessor directives etc.
			PreprocessingDirective.CSharpToVB(parser.Specials);
			// Convert C# constructs to VB.NET:
			node.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
			node.AcceptVisitor(new ToVBNetConvertVisitor(), null);

			VBNetOutputVisitor output = new VBNetOutputVisitor();
			
			using (SpecialNodesInserter.Install(parser.Specials, output)) {
				node.AcceptVisitor(output, null);
			}
			// output.Errors.ErrorOutput contains conversion errors/warnings, if any
			// output.Text contains the converted code
			Assert.AreEqual("", output.Errors.ErrorOutput);
			Assert.AreEqual(expectedOutput, output.Text);
		}
Esempio n. 40
0
		/// <summary>
		/// Dynamizes a list of files.
		/// </summary>
		/// <param name="files">The files to dynamize.</param>
		/// <param name="outDir">The output directory or <B>null</B>.</param>
		static void DynamizeFiles(List<string> files, string outDir)
		{
			Dynamizer dynamizer = new Dynamizer();

			foreach (string file in files)
			{
				Console.WriteLine("Dynamizing types in '{0}'", file);

				IParser parser;
				CompilationUnit unit;

				string ext = Path.GetExtension(file).ToLower();

				using (StreamReader sr = new StreamReader(file))
				{
					switch (ext)
					{
						case ".cs": parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, sr); break;
						case ".vb": parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, sr); break;
						default:
							throw new ArgumentException("Unknown language.");
					}

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

					if (parser.Errors.count > 0)
					{
						throw new ArgumentException("Parse error.");
					}

					unit = parser.CompilationUnit;
				}

				unit = dynamizer.Dynamize(unit);

				string out_path = Path.ChangeExtension(file, ".dynamic" + Path.GetExtension(file));
				if (outDir != null) out_path = Path.Combine(outDir, Path.GetFileName(out_path));

				try
				{
					using (StreamWriter sw = new StreamWriter(out_path))
					{
						IOutputASTVisitor visitor;
						switch (ext)
						{
							case ".cs":
							{
								sw.WriteLine("// ***");
								sw.WriteLine("// Do not edit this file. It has been generated by the ClassDynamizer tool.");
								sw.WriteLine("// ***");
								sw.WriteLine("#pragma warning disable 0108");
								visitor = new CSharpOutputVisitor();
								break;
							}

							case ".vb":
							{
								sw.WriteLine("' ***");
								sw.WriteLine("' Do not edit this file. It has been generated by the ClassDynamizer tool.");
								sw.WriteLine("' ***");
								visitor = new VBNetOutputVisitor();
								break;
							}

							default:
							throw new ArgumentException("Unknown language.");
						}

						unit.AcceptVisitor(visitor, DBNull.Value);

						sw.Write(visitor.Text);
					}
				}
				catch (UnauthorizedAccessException)
				{
					Console.WriteLine("Could not write to '{0}'. Is the file checked out?", out_path);
				}
			}
		}
Esempio n. 41
0
        public string Convert()
        {
            TextReader Reader = this.GetReader();
            IParser Parser = ParserFactory.CreateParser(this.From, Reader);
            Parser.Parse();
            if (Parser.Errors.Count > 0)
            {
                Log(Level.Error, Parser.Errors.ErrorOutput);
                throw new BuildException("Errors parsing code.", this.Location);
            }
            CompilationUnit Tree = Parser.CompilationUnit;

            IOutputAstVisitor OutputVisitor = null;
            switch (this.To)
            {
                case SupportedLanguage.CSharp:
                    OutputVisitor = new CSharpOutputVisitor();
                    break;
                case SupportedLanguage.VBNet:
                    OutputVisitor = new VBNetOutputVisitor();
                    break;
            }
            Tree.AcceptVisitor(OutputVisitor, null);

            return OutputVisitor.Text;
        }
Esempio n. 42
0
        /// <summary>
        /// Dynamizes a list of files.
        /// </summary>
        /// <param name="files">The files to dynamize.</param>
        /// <param name="outDir">The output directory or <B>null</B>.</param>
        static void DynamizeFiles(List <string> files, string outDir)
        {
            Dynamizer dynamizer = new Dynamizer();

            foreach (string file in files)
            {
                Console.WriteLine("Dynamizing types in '{0}'", file);

                IParser         parser;
                CompilationUnit unit;

                string ext = Path.GetExtension(file).ToLower();

                using (StreamReader sr = new StreamReader(file))
                {
                    switch (ext)
                    {
                    case ".cs": parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, sr); break;

                    case ".vb": parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, sr); break;

                    default:
                        throw new ArgumentException("Unknown language.");
                    }

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

                    if (parser.Errors.count > 0)
                    {
                        throw new ArgumentException("Parse error.");
                    }

                    unit = parser.CompilationUnit;
                }

                unit = dynamizer.Dynamize(unit);

                string out_path = Path.ChangeExtension(file, ".dynamic" + Path.GetExtension(file));
                if (outDir != null)
                {
                    out_path = Path.Combine(outDir, Path.GetFileName(out_path));
                }

                try
                {
                    using (StreamWriter sw = new StreamWriter(out_path))
                    {
                        IOutputASTVisitor visitor;
                        switch (ext)
                        {
                        case ".cs":
                        {
                            sw.WriteLine("// ***");
                            sw.WriteLine("// Do not edit this file. It has been generated by the ClassDynamizer tool.");
                            sw.WriteLine("// ***");
                            sw.WriteLine("#pragma warning disable 0108");
                            visitor = new CSharpOutputVisitor();
                            break;
                        }

                        case ".vb":
                        {
                            sw.WriteLine("' ***");
                            sw.WriteLine("' Do not edit this file. It has been generated by the ClassDynamizer tool.");
                            sw.WriteLine("' ***");
                            visitor = new VBNetOutputVisitor();
                            break;
                        }

                        default:
                            throw new ArgumentException("Unknown language.");
                        }

                        unit.AcceptVisitor(visitor, DBNull.Value);

                        sw.Write(visitor.Text);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    Console.WriteLine("Could not write to '{0}'. Is the file checked out?", out_path);
                }
            }
        }