Ejemplo n.º 1
0
        public void ParseMethodSignature(IMethod method)
        {
            if (method.Parameters != null)
            {
                return; //already set
            }
            var lines     = FortranParseHelper.CleanLinesAndMerge(FortranParseHelper.ExtractMemberLines(method), false, true);
            var firstLine = lines.FirstOrDefault();

            if (firstLine == null)
            {
                throw new ArgumentException("Empty header");
            }
            if (!firstLine.StartsWith(method.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException("Signature does not start with method name");
            }

            var parameterString = firstLine.Substring(method.Name.Length);
            var resultKeyword   = " result";
            var indexOfResult   = parameterString.IndexOf(resultKeyword, StringComparison.InvariantCultureIgnoreCase);

            if (indexOfResult >= 0)
            {
                var resultString = parameterString.Substring(indexOfResult + resultKeyword.Length);
                parameterString           = parameterString.Substring(0, indexOfResult);
                method.ResultVariableName = RemoveUndesiredCharacters(resultString).Trim();
            }

            parameterString = RemoveUndesiredCharacters(parameterString);
            var parameters = parameterString.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            var parameterList = new List <Variable>();

            foreach (var parameter in parameters)
            {
                var parameterName = parameter.Trim();

                if (String.IsNullOrEmpty(parameterName))
                {
                    continue;
                }

                var matchingDeclaration = FindDeclaration(method, parameterName);

                if (matchingDeclaration == null)
                {
                    if (method.ImplicitNone)
                    {
                        throw new ArgumentException(String.Format("Could not find matching declaration in method {0} for parameter {1}, while implicit none is true.", method.Name, parameterName));
                    }
                }
                else
                {
                    parameterList.Add(new Variable {
                        Name = parameterName, Member = method, TypeString = matchingDeclaration.TypeString, IsBuildInType = matchingDeclaration.IsBuildInType
                    });
                }
            }

            method.SetParameters(parameterList);
        }
        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;
            }
        }