Exemplo n.º 1
0
		public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings, out IList<ISpecial> specials)
		{
			if (cu == null)
				throw new ArgumentNullException("cu");
			if (input == null)
				throw new ArgumentNullException("input");
			if (settings == null)
				throw new ArgumentNullException("settings");
			IParser parser = ParserFactory.CreateParser(settings.IsVisualBasic ? SupportedLanguage.VBNet : SupportedLanguage.CSharp, input);
			ErrorTrap errorTrap = new ErrorTrap(settings);
			parser.Errors.SemErr = errorTrap.DefaultCodeError;
			parser.Errors.SynErr = errorTrap.DefaultCodeError;
			parser.Errors.Error  = errorTrap.DefaultMsgError;
			parser.Parse();
			specials = parser.Lexer.SpecialTracker.CurrentSpecials;
			if (settings.IsVisualBasic) {
				PreprocessingDirective.VBToCSharp(specials);
			}
			// abort when file has errors
			if (errorTrap.count > 0)
				return null;
			Module m = Converter.Convert(parser.CompilationUnit, settings);
			if (m != null && cu != null) {
				cu.Modules.Add(m);
				if (settings.RemoveRedundantTypeReferences) {
					cu.Accept(new RemoveRedundantTypeReferencesVisitor());
				}
			}
			return m;
		}
Exemplo n.º 2
0
 public ConvertVisitor(ConverterSettings settings)
 {
     this.settings     = settings;
     this.fileName     = settings.FileName;
     this.errors       = settings.Errors;
     this.warnings     = settings.Warnings;
     this.nameComparer = settings.NameComparer;
 }
Exemplo n.º 3
0
		public ConvertVisitor(ConverterSettings settings)
		{
			this.settings = settings;
			this.fileName      = settings.FileName;
			this.errors        = settings.Errors;
			this.warnings      = settings.Warnings;
			this.nameComparer  = settings.NameComparer;
		}
Exemplo n.º 4
0
		public static Expression Convert(NR.Expression expression, ConverterSettings settings)
		{
			if (expression == null)
				throw new ArgumentNullException("expression");
			if (settings == null)
				throw new ArgumentNullException("settings");
			return (Expression)expression.AcceptVisitor(new ConvertVisitor(settings), null);
		}
Exemplo n.º 5
0
 public static Expression Convert(NR.Expression expression, ConverterSettings settings)
 {
     if (expression == null)
     {
         throw new ArgumentNullException("expression");
     }
     if (settings == null)
     {
         throw new ArgumentNullException("settings");
     }
     return((Expression)expression.AcceptVisitor(new ConvertVisitor(settings), null));
 }
Exemplo n.º 6
0
		public static Module Convert(NR.CompilationUnit cu, ConverterSettings settings)
		{
			if (cu == null)
				throw new ArgumentNullException("cu");
			if (settings == null)
				throw new ArgumentNullException("settings");
			if (settings.IsVisualBasic)
				cu.AcceptVisitor(new VBNetConstructsConvertVisitor { AddDefaultValueInitializerToLocalVariableDeclarations = false }, null);
			else
				cu.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
			return (Module)cu.AcceptVisitor(new ConvertVisitor(settings), null);
		}
Exemplo n.º 7
0
        public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings, out IList <ISpecial> specials)
        {
            if (cu == null)
            {
                throw new ArgumentNullException("cu");
            }
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            IParser   parser    = ParserFactory.CreateParser(settings.IsVisualBasic ? SupportedLanguage.VBNet : SupportedLanguage.CSharp, input);
            ErrorTrap errorTrap = new ErrorTrap(settings);

            parser.Errors.SemErr = errorTrap.DefaultCodeError;
            parser.Errors.SynErr = errorTrap.DefaultCodeError;
            parser.Errors.Error  = errorTrap.DefaultMsgError;
            parser.Parse();
            specials = parser.Lexer.SpecialTracker.CurrentSpecials;
            if (settings.IsVisualBasic)
            {
                PreprocessingDirective.VBToCSharp(specials);
            }
            // abort when file has errors
            if (errorTrap.count > 0)
            {
                return(null);
            }
            Module m = Converter.Convert(parser.CompilationUnit, settings);

            if (m != null && cu != null)
            {
                cu.Modules.Add(m);
                if (settings.RemoveRedundantTypeReferences)
                {
                    cu.Accept(new RemoveRedundantTypeReferencesVisitor());
                }
            }
            return(m);
        }
Exemplo n.º 8
0
		public override string GenerateCode(AbstractNode node, string indentation)
		{
			StringBuilder errorBuilder = new StringBuilder();
			ConverterSettings settings = new ConverterSettings("codegeneration.cs");
			string output = null;
			
			Node booNode = (Node)node.AcceptVisitor(new ConvertVisitor(settings), null);
			
			if (settings.Errors.Count > 0) {
				foreach (CompilerError error in settings.Errors) {
					errorBuilder.AppendLine(error.ToString());
				}
			} else {
				if (settings.Warnings.Count > 0) {
					foreach (CompilerWarning warning in settings.Warnings) {
						errorBuilder.AppendLine(warning.ToString());
					}
				}
				booNode.Accept(new RemoveRedundantTypeReferencesVisitor());
				using (StringWriter w = new StringWriter()) {
					BooPrinterVisitor printer = new BooPrinterVisitor(w);
					int indentCount = 0;
					foreach (char c in indentation) {
						if (c == '\t')
							indentCount += 4;
						else
							indentCount += 1;
					}
					indentCount /= 4;
					while (indentCount-- > 0)
						printer.Indent();
					booNode.Accept(printer);
					output = w.ToString();
				}
			}
			if (errorBuilder.Length > 0) {
				MessageService.ShowMessage(errorBuilder.ToString());
			}
			return output;
		}
Exemplo n.º 9
0
 public static Module Convert(NR.CompilationUnit cu, ConverterSettings settings)
 {
     if (cu == null)
     {
         throw new ArgumentNullException("cu");
     }
     if (settings == null)
     {
         throw new ArgumentNullException("settings");
     }
     if (settings.IsVisualBasic)
     {
         cu.AcceptVisitor(new VBNetConstructsConvertVisitor {
             AddDefaultValueInitializerToLocalVariableDeclarations = false
         }, null);
     }
     else
     {
         cu.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
     }
     return((Module)cu.AcceptVisitor(new ConvertVisitor(settings), null));
 }
Exemplo n.º 10
0
 internal ErrorTrap(ConverterSettings settings)
 {
     this.errors   = settings.Errors;
     this.fileName = settings.FileName;
 }
Exemplo n.º 11
0
        public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings)
        {
            IList <ISpecial> specials;

            return(ParseModule(cu, input, settings, out specials));
        }
Exemplo n.º 12
0
 public static ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings)
 {
     ConverterSettings settings = new ConverterSettings(fileName, errors, warnings);
     settings.SimplifyTypeNames = true;
     return settings;
 }
Exemplo n.º 13
0
		ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings)
		{
			ConverterSettings settings = new ConverterSettings(fileName, errors, warnings);
			settings.SimplifyTypeNames = simplifyTypeNames;
			settings.RemoveRedundantTypeReferences = removeRedundantTypeReferences;
			return settings;
		}
Exemplo n.º 14
0
			internal ErrorTrap(ConverterSettings settings)
			{
				this.errors = settings.Errors;
				this.fileName = settings.FileName;
			}
Exemplo n.º 15
0
		public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings)
		{
			IList<ISpecial> specials;
			return ParseModule(cu, input, settings, out specials);
		}