Example #1
0
        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);
        }