Ejemplo n.º 1
0
        public IEnumerable <LocationInFile> FindInFileContents(MemberOrSearchTerm memberUsageToFind, string fileContents)
        {
            var results = new List <LocationInFile>();

            //remove comments:
            var cleanedLines = FortranParseHelper.CleanLines(fileContents.Split('\n'), false, false).ToList();

            int lineNr = 0;

            foreach (var line in cleanedLines)
            {
                lineNr++;
                SearchInLine(line, memberUsageToFind.Name, lineNr, results);
            }

            return(results);
        }
        public void ParseDeclarationsAndUses(IMember member)
        {
            if (member.LocalVariables.Any() || member.Uses.Any())
            {
                return; //already parsed (on file modification they are cleared)
            }
            member.ClearLocalVariables();
            member.ClearUses();

            var memberLines  = FortranParseHelper.ExtractMemberLines(member);
            var cleanedLines = FortranParseHelper.CleanLines(memberLines, false, false).ToArray();

            var mergedLines = FortranParseHelper.CleanLinesAndMerge(memberLines, true, true);

            var lineHint = 1;

            foreach (var line in mergedLines)
            {
                if (TryReadAndEat("#", line)) //preprocessor directives
                {
                    continue;
                }
                if (TryReadAndEat("private", line)) //preprocessor directives
                {
                    continue;
                }
                if (TryReadAndEat("public", line)) //preprocessor directives
                {
                    continue;
                }
                if (TryReadAndEat("write", line)) //allowed?!?!?!
                {
                    continue;
                }
                if (TryReadAndEat("implicit ", line))
                {
                    if (line.IndexOf("none", StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        member.ImplicitNone = true;
                    }
                    continue;
                }
                if (TryReadUses(member, line))
                {
                    continue;
                }
                if (TryReadVariableDeclaration(member, line, cleanedLines, ref lineHint))
                {
                    continue;
                }
                if (TryReadAndEat("parameter", line))
                {
                    continue;
                }
                if (TryReadAndEat("data", line))
                {
                    continue;
                }
                if (TryReadAndEat("common", line))
                {
                    continue;
                }
                if (TryReadAndEat("save", line))
                {
                    continue;
                }
                if (TryReadAndEat("intent", line))
                {
                    continue;
                }
                if (TryReadAndEat("include", line))
                {
                    continue;
                }
                //if we get here, it's the end of variable declarations because the line is non-empty and
                //non-commment, yet doesn't start with an expected string (variable, implicit, etc)
                break;
            }
        }