Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter empty preprocessor flags; don't treat arithmetic gotos as function references #214

Merged
merged 2 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ford/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ def __init__(self,filename,docmark='!',predocmark='',docmark_alt='',
raise Exception('Error: predocmark and predocmark_alt are the same.')

if preprocessor:
macros = ['-D' + mac.strip() for mac in macros]
incdirs = ['-I' + d.strip() for d in inc_dirs]
# Populate the macro definition and include directory path from
# the input lists. To define a macro we prepend '-D' and for an
# include path we prepend '-I'. It's important that we do not
# prepend to an empty string as 'cpp ... -D file.F90' doesn't do
# what is desired; use filter to remove these.
macros = ['-D' + mac.strip() for mac in filter(None,macros)]
incdirs = ['-I' + d.strip() for d in filter(None,inc_dirs)]
preprocessor = preprocessor + macros + incdirs + [filename]
fpp = subprocess.Popen(preprocessor, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down
15 changes: 11 additions & 4 deletions ford/sourceform.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ class FortranContainer(FortranBase):
COMMON_SPLIT_RE = re.compile("\s*(/\s*\w+\s*/)\s*",re.IGNORECASE)
FINAL_RE = re.compile("^final\s*::\s*(\w.*)",re.IGNORECASE)
USE_RE = re.compile("^use(?:\s*(?:,\s*(?:non_)?intrinsic\s*)?::\s*|\s+)(\w+)\s*($|,.*)",re.IGNORECASE)
ARITH_GOTO_RE = re.compile("go\s*to\s*\([0-9,\s]+\)",re.IGNORECASE)
CALL_RE = re.compile("(?:^|(?<=[^a-zA-Z0-9_%]))\w+(?=\s*\(\s*(?:.*?)\s*\))",re.IGNORECASE)
SUBCALL_RE = re.compile("^(?:if\s*\(.*\)\s*)?call\s+(\w+)\s*(?:\(\s*(.*?)\s*\))?$",re.IGNORECASE)

Expand Down Expand Up @@ -754,10 +755,16 @@ def __init__(self,source,first_line,parent=None,inherited_permission=None,
raise Exception("Found USE statemnt in {}".format(type(self).__name__[7:].upper()))
elif self.CALL_RE.search(line):
if hasattr(self,'calls'):
callvals = self.CALL_RE.findall(line)
for val in callvals:
if val.lower() not in self.calls and val.lower() not in INTRINSICS:
self.calls.append(val.lower())
# Arithmetic GOTOs looks little like function references:
# "goto (1, 2, 3) i". But even in free-form source we're
# allowed to use a space: "go to (1, 2, 3) i". Our CALL_RE
# expression doesn't catch that so we first rule such a
# GOTO out.
if not self.ARITH_GOTO_RE.search(line):
callvals = self.CALL_RE.findall(line)
for val in callvals:
if val.lower() not in self.calls and val.lower() not in INTRINSICS:
self.calls.append(val.lower())
else:
pass
# Not raising an error here as too much possibility that something
Expand Down