예제 #1
0
            public bool TryFetch(string file, out ANTLR_Result parsed)
            {
                parsed = null;
                InterimResult interim;

                if (file2interim.TryGetValue(file, out interim) && !interim.use_file_cache && interim.parsed != null)
                {
                    parsed = interim.parsed;
                    return(true);
                }
                return(false);
            }
예제 #2
0
            public static void DoWork(object data)
            {
                var sw = new Stopwatch();

                sw.Start();

                var w = (ParseWorker)data;

                string self_bin_file = w.self_file;

                int i = w.start;

                int cache_hit  = 0;
                int cache_miss = 0;

                try
                {
                    for (int cnt = 0; i < (w.start + w.count); ++i, ++cnt)
                    {
                        //too verbose?
                        //if(cnt > 0 && cnt % 1000 == 0)
                        //{
                        //  var elapsed = Math.Round(sw.ElapsedMilliseconds/1000.0f,2);
                        //  Console.WriteLine("BHL Parser " + w.id + " " + cnt + "/" + w.count + ", " + elapsed + " sec");
                        //}

                        var file = w.files[i];
                        using (var sfs = File.OpenRead(file))
                        {
                            var deps = new List <string>();

                            if (w.check_deps)
                            {
                                var imports = w.ParseImports(file, sfs);
                                deps = imports.files;
                            }
                            deps.Add(file);

                            //NOTE: adding self binary as a dep
                            if (self_bin_file.Length > 0)
                            {
                                deps.Add(self_bin_file);
                            }

                            var cache_file = GetCompiledCacheFile(w.cache_dir, file);

                            var interim = new InterimResult();

                            if (!w.use_cache || BuildUtil.NeedToRegen(cache_file, deps))
                            {
                                var parser = Frontend.Stream2Parser(file, sfs);
                                var parsed = new ANTLR_Result(parser.TokenStream, parser.program());

                                interim.parsed = parsed;

                                ++cache_miss;
                                //Console.WriteLine("PARSE " + file + " " + cache_file);
                            }
                            else
                            {
                                interim.use_file_cache = true;

                                ++cache_hit;
                            }

                            w.file2interim[file] = interim;
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e is IError)
                    {
                        w.error = e;
                    }
                    else
                    {
                        //let's log unexpected exceptions immediately
                        Console.Error.WriteLine(e.Message + " " + e.StackTrace);
                        w.error = new BuildError(w.files[i], e);
                    }
                }

                sw.Stop();
                Console.WriteLine("BHL parser {0} done(hit/miss:{2}/{3}, {1} sec)", w.id, Math.Round(sw.ElapsedMilliseconds / 1000.0f, 2), cache_hit, cache_miss);
            }