예제 #1
0
        //
        // Prints collected messages, common messages have a priority
        //
        public bool Merge(ReportPrinter dest)
        {
            var messages_to_print = merged_messages;

            if (common_messages != null && common_messages.Count > 0)
            {
                messages_to_print = common_messages;
            }

            if (messages_to_print == null)
            {
                return(false);
            }

            bool error_msg = false;

            foreach (AbstractMessage msg in messages_to_print)
            {
                dest.Print(msg, showFullPaths);
                error_msg |= !msg.IsWarning;
            }

            if (reported_missing_definitions != null)
            {
                foreach (var missing in reported_missing_definitions)
                {
                    dest.MissingTypeReported(missing);
                }
            }

            return(error_msg);
        }
예제 #2
0
 public CompilerContext(CompilerSettings settings, ReportPrinter reportPrinter)
 {
     this.settings      = settings;
     this.report        = new Report(this, reportPrinter);
     this.builtin_types = new BuiltinTypes();
     this.TimeReporter  = DisabledTimeReporter;
 }
예제 #3
0
        static void Reset()
        {
            CompilerCallableEntryPoint.PartialReset();

            // Workaround for API limitation where full message printer cannot be passed
            ReportPrinter printer = MessageOutput == Console.Out || MessageOutput == Console.Error ?
                                    new ConsoleReportPrinter(MessageOutput) :
                                    new StreamReportPrinter(MessageOutput);

            ctx = new CompilerContext(new Report(printer));
            RootContext.ToplevelTypes = new ModuleContainer(ctx, true);

            //
            // PartialReset should not reset the core types, this is very redundant.
            //
            if (!TypeManager.InitCoreTypes(ctx))
            {
                throw new Exception("Failed to InitCoreTypes");
            }
            TypeManager.InitOptionalCoreTypes(ctx);

            Location.AddFile(null, "{interactive}");
            Location.Initialize();

            current_debug_name = "interactive" + (count++) + ".dll";
            if (Environment.GetEnvironmentVariable("SAVE") != null)
            {
                CodeGen.Init(current_debug_name, current_debug_name, false, ctx);
            }
            else
            {
                CodeGen.InitDynamic(ctx, current_debug_name);
            }
        }
예제 #4
0
        public ReportPrinter SetPrinter(ReportPrinter printer)
        {
            ReportPrinter old = this.printer;

            this.printer = printer;
            return(old);
        }
예제 #5
0
		public Report (ReportPrinter printer)
		{
			if (printer == null)
				throw new ArgumentNullException ("printer");

			this.printer = printer;
			warning_level = 4;
		}
예제 #6
0
파일: report.cs 프로젝트: litoMalone/mono
		public Report (ReportPrinter printer)
		{
			if (printer == null)
				throw new ArgumentNullException ("printer");

			this.printer = printer;
			warning_level = 4;
		}
예제 #7
0
파일: driver.cs 프로젝트: litoMalone/mono
		public static Driver Create (string[] args, bool require_files, ReportPrinter printer)
		{
			Driver d = new Driver (new CompilerContext (new Report (printer)));

			if (!d.ParseArguments (args, require_files))
				return null;

			return d;
		}
예제 #8
0
파일: driver.cs 프로젝트: nekresh/mono
		public static Driver Create (string[] args, bool require_files, Func<string [], int, int> unknown_option_parser, ReportPrinter printer)
		{
			Driver d = new Driver (new CompilerContext (new Report (printer)));

			if (!d.ParseArguments (args, require_files, unknown_option_parser))
				return null;

			return d;
		}
예제 #9
0
파일: report.cs 프로젝트: Profit0004/mono
		public Report (CompilerContext context, ReportPrinter printer)
		{
			if (context == null)
				throw new ArgumentNullException ("settings");
			if (printer == null)
				throw new ArgumentNullException ("printer");

			this.settings = context.Settings;
			this.printer = printer;
		}
예제 #10
0
        public Report(CompilerContext context, ReportPrinter printer)
        {
            if (context == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (printer == null)
            {
                throw new ArgumentNullException("printer");
            }

            this.settings = context.Settings;
            this.printer  = printer;
        }
예제 #11
0
파일: driver.cs 프로젝트: holmak/NRefactory
        public static CompilerCompilationUnit ParseFile(string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
        {
            lock (parseLock) {
                try {
                    //                                     Driver d = Driver.Create (args, false, null, reportPrinter);
                    //                                     if (d == null)
                    //                                             return null;

                    var r = new Report (reportPrinter);
                    CommandLineParser cmd = new CommandLineParser (r, Console.Out);
                    var setting = cmd.ParseArguments (args);
                    if (setting == null || r.Errors > 0)
                        return null;
                    setting.Version = LanguageVersion.V_5;

                    CompilerContext ctx = new CompilerContext (setting, r);

                    var files = new List<CompilationSourceFile> ();
                    var unit = new CompilationSourceFile (inputFile, inputFile, 0);
                    var module = new ModuleContainer (ctx);
                    unit.NamespaceContainer = new NamespaceContainer (null, module, null, unit);
                    files.Add (unit);
                    Location.Initialize (files);

                    // TODO: encoding from driver
                    SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.UTF8);

                    RootContext.ToplevelTypes = module;

                    CSharpParser parser = new CSharpParser (reader, unit);
                    parser.Lexer.TabSize = 1;
                    parser.Lexer.sbag = new SpecialsBag ();
                    parser.LocationsBag = new LocationsBag ();
                    parser.UsingsBag = new UsingsBag ();
                    parser.parse ();

                    return new CompilerCompilationUnit () {
                        ModuleCompiled = RootContext.ToplevelTypes,
                        LocationsBag = parser.LocationsBag,
                        UsingsBag = parser.UsingsBag,
                        SpecialsBag = parser.Lexer.sbag,
                        LastYYValue = parser.LastYYVal
                    };
                } finally {
                    Reset ();
                }
            }
        }
예제 #12
0
		//
		// Prints collected messages, common messages have a priority
		//
		public bool Merge (ReportPrinter dest)
		{
			var messages_to_print = merged_messages;
			if (common_messages != null && common_messages.Count > 0) {
				messages_to_print = common_messages;
			}

			if (messages_to_print == null)
				return false;

			bool error_msg = false;
			foreach (AbstractMessage msg in messages_to_print) {
				dest.Print (msg);
				error_msg |= !msg.IsWarning;
			}

			return error_msg;
		}
예제 #13
0
        public MCSCompiler(string assemblyFileName, ReportPrinter reporter)
        {
            // Загружаем сборку компилятора
            _dmcsAssembly = Assembly.LoadFile(assemblyFileName);

            // Пробуем получить тип драйвера компиляции
            _driverType = ReflectionUtils.ExtractTypeByName(_dmcsAssembly, "Mono.CSharp.Driver");

            // Если не удалось
            if (_driverType == null)
            {
                SuccessfulCreated = false;

                throw new ClassDriverNotFoundException(String.Format("В сборке \"{0}\" не найден тип драйвера компиляции", assemblyFileName));
            }

            SuccessfulCreated = true;

            _reporter = reporter;
        }
예제 #14
0
        //
        // Prints collected messages, common messages have a priority
        //
        public bool Merge(ReportPrinter dest)
        {
            ArrayList messages_to_print = merged_messages;

            if (common_messages != null && common_messages.Count > 0)
            {
                messages_to_print = common_messages;
            }

            if (messages_to_print == null)
            {
                return(false);
            }

            foreach (AbstractMessage msg in messages_to_print)
            {
                dest.Print(msg);
            }

            return(true);
        }
예제 #15
0
        public static CompilerCompilationUnit ParseFile(string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
        {
            lock (parseLock) {
                try {
                    Driver d = Driver.Create (args, false, null, reportPrinter);
                    if (d == null)
                        return null;

                    Location.AddFile (null, inputFile);
                    Location.Initialize ();

                    // TODO: encoding from driver
                    SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.Default);

                    CompilerContext ctx = new CompilerContext (new Report (reportPrinter));

                    RootContext.ToplevelTypes = new ModuleContainer (ctx);
                    CompilationUnit unit = null;
                    try {
                        unit = (CompilationUnit) Location.SourceFiles [0];
                    } catch (Exception) {
                        string path = Path.GetFullPath (inputFile);
                        unit = new CompilationUnit (inputFile, path, 0);
                    }
                    CSharpParser parser = new CSharpParser (reader, unit, RootContext.ToplevelTypes);
                    parser.Lexer.TabSize = 1;
                    parser.Lexer.sbag = new SpecialsBag ();
                    parser.LocationsBag = new LocationsBag ();
                    parser.UsingsBag = new UsingsBag ();
                    parser.parse ();

                    return new CompilerCompilationUnit () { ModuleCompiled = RootContext.ToplevelTypes, LocationsBag = parser.LocationsBag, UsingsBag = parser.UsingsBag, SpecialsBag = parser.Lexer.sbag };
                } finally {
                    Reset ();
                }
            }
        }
예제 #16
0
 internal static ReportPrinter SetPrinter(ReportPrinter report_printer)
 {
     return(ctx.Report.SetPrinter(report_printer));
 }
예제 #17
0
        //
        // Parses the string @input and returns a CSharpParser if succeeful.
        //
        // if @silent is set to true then no errors are
        // reported to the user.  This is used to do various calls to the
        // parser and check if the expression is parsable.
        //
        // @partial_input: if @silent is true, then it returns whether the
        // parsed expression was partial, and more data is needed
        //
        static CSharpParser ParseString(ParseMode mode, string input, out bool partial_input)
        {
            partial_input = false;
            Reset();
            queued_fields.Clear();
            Tokenizer.LocatedToken.Initialize();

            Stream s = new MemoryStream(Encoding.Default.GetBytes(input));
            SeekableStreamReader seekable = new SeekableStreamReader(s, Encoding.Default);

            InputKind kind = ToplevelOrStatement(seekable);

            if (kind == InputKind.Error)
            {
                if (mode == ParseMode.ReportErrors)
                {
                    ctx.Report.Error(-25, "Detection Parsing Error");
                }
                partial_input = false;
                return(null);
            }

            if (kind == InputKind.EOF)
            {
                if (mode == ParseMode.ReportErrors)
                {
                    Console.Error.WriteLine("Internal error: EOF condition should have been detected in a previous call with silent=true");
                }
                partial_input = true;
                return(null);
            }
            seekable.Position = 0;

            CSharpParser parser = new CSharpParser(seekable, Location.SourceFiles [0], RootContext.ToplevelTypes);

            if (kind == InputKind.StatementOrExpression)
            {
                parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
                RootContext.StatementMode = true;
            }
            else
            {
                //
                // Do not activate EvalCompilationUnitParserCharacter until
                // I have figured out all the limitations to invoke methods
                // in the generated classes.  See repl.txt
                //
                parser.Lexer.putback_char = Tokenizer.EvalUsingDeclarationsParserCharacter;
                //parser.Lexer.putback_char = Tokenizer.EvalCompilationUnitParserCharacter;
                RootContext.StatementMode = false;
            }

            if (mode == ParseMode.GetCompletions)
            {
                parser.Lexer.CompleteOnEOF = true;
            }

            ReportPrinter old_printer = null;

            if ((mode == ParseMode.Silent || mode == ParseMode.GetCompletions) && CSharpParser.yacc_verbose_flag == 0)
            {
                old_printer = SetPrinter(new StreamReportPrinter(TextWriter.Null));
            }

            try
            {
                parser.parse();
            }
            finally
            {
                if (ctx.Report.Errors != 0)
                {
                    if (mode != ParseMode.ReportErrors && parser.UnexpectedEOF)
                    {
                        partial_input = true;
                    }

                    parser.undo.ExecuteUndo();
                    parser = null;
                }

                if (old_printer != null)
                {
                    SetPrinter(old_printer);
                }
            }
            return(parser);
        }
예제 #18
0
		public CompilerContext (CompilerSettings settings, ReportPrinter reportPrinter)
		{
			this.settings = settings;
			this.report = new Report (this, reportPrinter);
			this.builtin_types = new BuiltinTypes ();
			this.TimeReporter = DisabledTimeReporter;
		}
예제 #19
0
파일: driver.cs 프로젝트: rblenis/cudafy
        public static CompilerCompilationUnit ParseFile(string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
        {
            lock (parseLock) {
                try {
                    //                                     Driver d = Driver.Create (args, false, null, reportPrinter);
                    //                                     if (d == null)
                    //                                             return null;

                    var r = new Report(reportPrinter);
                    CommandLineParser cmd = new CommandLineParser(r, Console.Out);
                    var setting           = cmd.ParseArguments(args);
                    if (setting == null || r.Errors > 0)
                    {
                        return(null);
                    }

                    CompilerContext ctx = new CompilerContext(setting, r);

                    var files  = new List <CompilationSourceFile> ();
                    var unit   = new CompilationSourceFile(inputFile, inputFile, 0);
                    var module = new ModuleContainer(ctx);
                    unit.NamespaceContainer = new NamespaceContainer(null, module, null, unit);
                    files.Add(unit);
                    Location.Initialize(files);

                    // TODO: encoding from driver
                    SeekableStreamReader reader = new SeekableStreamReader(input, Encoding.Default);

                    RootContext.ToplevelTypes = module;

                    CSharpParser parser = new CSharpParser(reader, unit);
                    parser.Lexer.TabSize = 1;
                    parser.Lexer.sbag    = new SpecialsBag();
                    parser.LocationsBag  = new LocationsBag();
                    parser.UsingsBag     = new UsingsBag();
                    parser.parse();

                    return(new CompilerCompilationUnit()
                    {
                        ModuleCompiled = RootContext.ToplevelTypes, LocationsBag = parser.LocationsBag, UsingsBag = parser.UsingsBag, SpecialsBag = parser.Lexer.sbag
                    });
                } finally {
                    Reset();
                }
            }
        }
예제 #20
0
		//
		// Prints collected messages, common messages have a priority
		//
		public bool Merge (ReportPrinter dest)
		{
			ArrayList messages_to_print = merged_messages;
			if (common_messages != null && common_messages.Count > 0) {
				messages_to_print = common_messages;
			}

			if (messages_to_print == null)
				return false;

			foreach (AbstractMessage msg in messages_to_print)
				dest.Print (msg);

			return true;
		}
예제 #21
0
		public ReportPrinter SetPrinter (ReportPrinter printer)
		{
			ReportPrinter old = this.printer;
			this.printer = printer;
			return old;
		}
예제 #22
0
파일: eval.cs 프로젝트: silk/monodevelop
		internal static ReportPrinter SetPrinter (ReportPrinter report_printer)
		{
			return ctx.Report.SetPrinter (report_printer);
		}				
예제 #23
0
파일: report.cs 프로젝트: litoMalone/mono
		//
		// Prints collected messages, common messages have a priority
		//
		public bool Merge (ReportPrinter dest)
		{
			var messages_to_print = merged_messages;
			if (common_messages != null && common_messages.Count > 0) {
				messages_to_print = common_messages;
			}

			if (messages_to_print == null)
				return false;

			bool error_msg = false;
			foreach (AbstractMessage msg in messages_to_print) {
				dest.Print (msg);
				error_msg |= !msg.IsWarning;
			}

			return error_msg;
		}
예제 #24
0
        //
        // Parses the string @input and returns a CSharpParser if succeeful.
        //
        // if @silent is set to true then no errors are
        // reported to the user.  This is used to do various calls to the
        // parser and check if the expression is parsable.
        //
        // @partial_input: if @silent is true, then it returns whether the
        // parsed expression was partial, and more data is needed
        //
        CSharpParser ParseString(ParseMode mode, string input, out bool partial_input)
        {
            partial_input = false;
            Reset();
            Tokenizer.LocatedToken.Initialize();

            Stream s = new MemoryStream(Encoding.UTF8.GetBytes(input));
            SeekableStreamReader seekable = new SeekableStreamReader(s, Encoding.UTF8);

            InputKind kind = ToplevelOrStatement(seekable);

            if (kind == InputKind.Error)
            {
                if (mode == ParseMode.ReportErrors)
                {
                    ctx.Report.Error(-25, "Detection Parsing Error");
                }
                partial_input = false;
                return(null);
            }

            if (kind == InputKind.EOF)
            {
                if (mode == ParseMode.ReportErrors)
                {
                    Console.Error.WriteLine("Internal error: EOF condition should have been detected in a previous call with silent=true");
                }
                partial_input = true;
                return(null);
            }
            seekable.Position = 0;

            if (ns == null)
            {
                ns = new NamespaceEntry(module, null, Location.SourceFiles[0], null);
            }

            ns.DeclarationFound = false;
            CSharpParser parser = new CSharpParser(seekable, Location.SourceFiles [0], module, ns);

            if (kind == InputKind.StatementOrExpression)
            {
                parser.Lexer.putback_char  = Tokenizer.EvalStatementParserCharacter;
                ctx.Settings.StatementMode = true;
            }
            else
            {
                parser.Lexer.putback_char  = Tokenizer.EvalCompilationUnitParserCharacter;
                ctx.Settings.StatementMode = false;
            }

            if (mode == ParseMode.GetCompletions)
            {
                parser.Lexer.CompleteOnEOF = true;
            }

            ReportPrinter old_printer = null;

            if ((mode == ParseMode.Silent || mode == ParseMode.GetCompletions) && CSharpParser.yacc_verbose_flag == 0)
            {
                old_printer = ctx.Report.SetPrinter(new StreamReportPrinter(TextWriter.Null));
            }

            try {
                parser.parse();
            } finally {
                if (ctx.Report.Errors != 0)
                {
                    if (mode != ParseMode.ReportErrors && parser.UnexpectedEOF)
                    {
                        partial_input = true;
                    }

                    if (parser.undo != null)
                    {
                        parser.undo.ExecuteUndo();
                    }

                    parser = null;
                }

                if (old_printer != null)
                {
                    ctx.Report.SetPrinter(old_printer);
                }
            }
            return(parser);
        }
예제 #25
0
파일: report.cs 프로젝트: Profit0004/mono
		//
		// Prints collected messages, common messages have a priority
		//
		public bool Merge (ReportPrinter dest)
		{
			var messages_to_print = merged_messages;
			if (common_messages != null && common_messages.Count > 0) {
				messages_to_print = common_messages;
			}

			if (messages_to_print == null)
				return false;

			bool error_msg = false;
			foreach (AbstractMessage msg in messages_to_print) {
				dest.Print (msg, showFullPaths);
				error_msg |= !msg.IsWarning;
			}

			if (reported_missing_definitions != null) {
				foreach (var missing in reported_missing_definitions)
					dest.MissingTypeReported (missing);
			}

			return error_msg;
		}
예제 #26
0
        //
        // Parses the string @input and returns a CSharpParser if succeeful.
        //
        // if @silent is set to true then no errors are
        // reported to the user.  This is used to do various calls to the
        // parser and check if the expression is parsable.
        //
        // @partial_input: if @silent is true, then it returns whether the
        // parsed expression was partial, and more data is needed
        //
        CSharpParser ParseString(ParseMode mode, string input, out bool partial_input)
        {
            partial_input = false;
            Reset();

            var enc = ctx.Settings.Encoding;
            var s   = new MemoryStream(enc.GetBytes(input));
            SeekableStreamReader seekable = new SeekableStreamReader(s, enc);

            InputKind kind = ToplevelOrStatement(seekable);

            if (kind == InputKind.Error)
            {
                if (mode == ParseMode.ReportErrors)
                {
                    ctx.Report.Error(-25, "Detection Parsing Error");
                }
                partial_input = false;
                return(null);
            }

            if (kind == InputKind.EOF)
            {
                if (mode == ParseMode.ReportErrors)
                {
                    Console.Error.WriteLine("Internal error: EOF condition should have been detected in a previous call with silent=true");
                }
                partial_input = true;
                return(null);
            }
            seekable.Position = 0;

            source_file.DeclarationFound = false;
            CSharpParser parser = new CSharpParser(seekable, source_file, new ParserSession());

            if (kind == InputKind.StatementOrExpression)
            {
                parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
                parser.Lexer.parsing_block++;
                ctx.Settings.StatementMode = true;
            }
            else
            {
                parser.Lexer.putback_char  = Tokenizer.EvalCompilationUnitParserCharacter;
                ctx.Settings.StatementMode = false;
            }

            if (mode == ParseMode.GetCompletions)
            {
                parser.Lexer.CompleteOnEOF = true;
            }

            ReportPrinter old_printer = null;

            if ((mode == ParseMode.Silent || mode == ParseMode.GetCompletions))
            {
                old_printer = ctx.Report.SetPrinter(new StreamReportPrinter(TextWriter.Null));
            }

            try {
                parser.parse();
            } finally {
                if (ctx.Report.Errors != 0)
                {
                    if (mode != ParseMode.ReportErrors && parser.UnexpectedEOF)
                    {
                        partial_input = true;
                    }

                    if (parser.undo != null)
                    {
                        parser.undo.ExecuteUndo();
                    }

                    parser = null;
                }

                if (old_printer != null)
                {
                    ctx.Report.SetPrinter(old_printer);
                }
            }
            return(parser);
        }