private static List <Position> FindPositions(string expr, string name, string fileName, int line, int column, string new_val) { string text = File.ReadAllText(fileName); PascalABCNewLanguageParser parser = new PascalABCNewLanguageParser(); compilation_unit cu = parser.BuildTreeInNormalMode(fileName, text) as compilation_unit; expression e = parser.BuildTreeInExprMode(fileName, expr) as expression; var cv = CollectLightSymInfoVisitor.New; cv.ProcessNode(cu); var rf1 = new ReferenceFinder1(e, cv.Root, cu, new_val); rf1.FindPositions(name, line, column, cu); return(rf1.Positions); }
private ScopeSyntax FindDefInUnit(string unitName) { string dir = Path.GetDirectoryName(global.Pos.file_name); string fname = $"{dir}{Path.DirectorySeparatorChar}{unitName}.pas"; if (!File.Exists(fname)) { return(null); } string fcontent = File.ReadAllText(fname); PascalABCNewLanguageParser parser = new PascalABCNewLanguageParser(); compilation_unit cu = parser.BuildTreeInNormalMode(fname, fcontent) as compilation_unit; var cv = CollectLightSymInfoVisitor.New; cv.ProcessNode(cu); ScopeSyntax d = null; var dn = expr as dot_node; if (dn != null) { GotoIdentByLocation(name, line, column, this.cu); d = FindDef(current, name, cv.Root, unitName); } else if (cv.Root.Symbols.Any(s => s.Id.name == name)) { d = cv.Root; } if (d is TypeScopeSyntax && !(d.Symbols.First(s => s.Id.name == name) .Attr.HasFlag(Attributes.public_attr))) { d = null; } return(d); }
static void Main(string[] args) { PascalABCNewLanguageParser parser = new PascalABCNewLanguageParser(); string root = @"C:\PABCWork.NET\Samples"; //args[0]; var files = GetFiles(root); var visitor = new CountVisitor(); foreach (var x in files) { dynamic res = parser.BuildTree("ProgramFile", x, ParseMode.Normal); var executer = new ExecuteVisitor(visitor); if (res != null) { executer.visit(res); } } List <KeyValuePair <string, int> > myList = visitor.nodeCount.ToList(); myList.Sort((firstPair, nextPair) => { return(nextPair.Value.CompareTo(firstPair.Value)); } ); StreamWriter resFile = new StreamWriter("NodesCount.txt"); foreach (KeyValuePair <string, int> x in myList) { if (x.Value > 0) { resFile.WriteLine(x.Key + " - " + x.Value); } } resFile.Close(); //Console.ReadKey(); }
static void Main(string[] args) { if (args.Length > 0) { var parser = new PascalABCNewLanguageParser(); var package = new List <string>(); if (args.Length > 1) { foreach (var path in args.Skip(1)) { package.AddRange(Directory.GetFiles(path, "*.pas", SearchOption.AllDirectories)); } } else { var landResultsFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\LanD Workspace\last_batch_parsing_report.txt"; if (File.Exists(landResultsFile)) { package.AddRange(Directory.GetFiles( File.ReadAllLines(landResultsFile)[1], "*.pas", SearchOption.AllDirectories)); } else { Console.WriteLine("Не указаны каталоги для парсинга"); return; } } var proceduresCounter = 0; var classesCounter = 0; var propertiesCounter = 0; var procedureOutput = new StreamWriter(Path.Combine(args[0], "routine_baseline.txt"), false); var classOutput = new StreamWriter(Path.Combine(args[0], "class_type_baseline.txt"), false); var propertyOutput = new StreamWriter(Path.Combine(args[0], "property_baseline.txt"), false); var totalTime = new TimeSpan(); foreach (var filename in package) { var text = File.ReadAllText(filename, GetEncoding(filename)); var startTime = DateTime.Now; var tree = parser.BuildTree(filename, text, PascalABCCompiler.Parsers.ParseMode.Normal); totalTime += DateTime.Now - startTime; if (tree != null) { /// Отсекаем автосгенерированные геттеры и сеттеры, /// а также заголовки процедур, используемые как типы var procedures = tree.DescendantNodes() .OfType <procedure_header>() .Where(p => p.name != null && !String.IsNullOrEmpty(p.name.ToString()) && !p.name.ToString().StartsWith("#") && !p.name.ToString().StartsWith("operator") && p.name.ToString() != "implicit" && p.name.ToString() != "explicit") .ToList(); if (procedures.Count > 0) { proceduresCounter += procedures.Count; procedureOutput.WriteLine("***"); procedureOutput.WriteLine(filename); foreach (var node in procedures) { if (node.name?.class_name != null) { procedureOutput.WriteLine($"{node.name.class_name}.{node.name.meth_name}"); } else if (node.name != null) { procedureOutput.WriteLine(node.name); } else { procedureOutput.WriteLine("MISSING_NAME"); } } } var classes = tree.DescendantNodes() .OfType <class_definition>() .Where(node => node.Parent is type_declaration) .ToList(); if (classes.Count > 0) { classOutput.WriteLine("***"); classOutput.WriteLine(filename); foreach (var node in classes) { classOutput.WriteLine(((type_declaration)node.Parent).type_name); } } classesCounter += classes.Count(); var properties = tree.DescendantNodes().OfType <simple_property>().ToList(); if (properties.Count > 0) { propertyOutput.WriteLine("***"); propertyOutput.WriteLine(filename); foreach (var node in properties) { propertyOutput.WriteLine(node.property_name); } } propertiesCounter += properties.Count(); } else { Console.WriteLine(filename); foreach (var error in parser.Errors) { Console.WriteLine(error.Message); } } } procedureOutput.Close(); classOutput.Close(); propertyOutput.Close(); Console.WriteLine($"routines: {proceduresCounter}"); Console.WriteLine($"properties: {propertiesCounter}"); Console.WriteLine($"classes: {classesCounter}"); Console.WriteLine(totalTime.ToString(@"hh\:mm\:ss\:ff")); } }