mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-10-14 12:01:38 +02:00
Version:1.1.35
This commit is contained in:
parent
3f01d854f3
commit
50e2bfb3a7
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python -u
|
||||
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
|
||||
# the Implicit Reference to Parameters (IRP) method.
|
||||
# Copyright (C) 2009 Anthony SCEMAMA
|
||||
|
@ -33,14 +33,16 @@ from subroutines import subroutines
|
||||
import regexps
|
||||
import error
|
||||
|
||||
vtuple = map(lambda v: (v, variables[v], variables[v].same_as, variables[v].regexp), variables.keys())
|
||||
vtuple = map(lambda v: (v, variables[v].same_as, variables[v].regexp), variables.keys())
|
||||
stuple = map(lambda s: (s, subroutines[s].regexp), subroutines.keys())
|
||||
stuple = filter(lambda s: subroutines[s[0]].is_function, stuple)
|
||||
|
||||
def find_variables_in_line(line):
|
||||
assert isinstance(line,Line)
|
||||
result = []
|
||||
sub_done = False
|
||||
buffer = line.text.lower()
|
||||
for v,var,same_as,regexp in vtuple:
|
||||
for v,same_as,regexp in vtuple:
|
||||
if v in buffer:
|
||||
if not sub_done:
|
||||
buffer = regexps.re_string.sub('',buffer)
|
||||
@ -49,6 +51,18 @@ def find_variables_in_line(line):
|
||||
result.append(same_as)
|
||||
return result
|
||||
|
||||
def find_funcs_in_line(line):
|
||||
assert isinstance(line,Line)
|
||||
result = []
|
||||
sub_done = False
|
||||
buffer = line.text.lower()
|
||||
for s,regexp in stuple:
|
||||
if s in buffer:
|
||||
if regexp.search(buffer) is not None:
|
||||
result.append(s)
|
||||
return result
|
||||
|
||||
|
||||
def find_subroutine_in_line(line):
|
||||
assert isinstance(line,Call)
|
||||
buffer = line.text.split('(')[0]
|
||||
@ -186,7 +200,10 @@ def get_parsed_text():
|
||||
return main_result
|
||||
|
||||
parsed_text = get_parsed_text()
|
||||
|
||||
|
||||
######################################################################
|
||||
|
||||
def move_to_top(text,t):
|
||||
assert isinstance(text,list)
|
||||
assert t in [ Declaration, Implicit, Use, Cont_provider ]
|
||||
@ -313,6 +330,60 @@ def move_variables():
|
||||
return main_result
|
||||
|
||||
parsed_text = move_variables()
|
||||
######################################################################
|
||||
def build_sub_needs():
|
||||
# Needs
|
||||
for filename, text in parsed_text:
|
||||
sub = None
|
||||
for vars,line in text:
|
||||
if type(line) in [ Subroutine, Function ]:
|
||||
subname = find_subname(line)
|
||||
sub = subroutines[subname]
|
||||
sub.needs = []
|
||||
elif isinstance(line,End):
|
||||
sub.needs = make_single(sub.needs)
|
||||
sub = None
|
||||
if sub is not None:
|
||||
sub.needs += vars
|
||||
|
||||
build_sub_needs()
|
||||
#####################################################################
|
||||
|
||||
def add_subroutine_needs():
|
||||
main_result = []
|
||||
for filename, text in parsed_text:
|
||||
result = []
|
||||
for vars,line in text:
|
||||
if isinstance(line,Call):
|
||||
subname = find_subname(line)
|
||||
vars = subroutines[subname].needs
|
||||
result.append( (vars,line) )
|
||||
main_result.append( (filename, result) )
|
||||
return main_result
|
||||
|
||||
parsed_text = add_subroutine_needs()
|
||||
|
||||
######################################################################
|
||||
def find_vars_from_functions():
|
||||
main_result = []
|
||||
for filename, text in parsed_text:
|
||||
result = []
|
||||
for vars,line in text:
|
||||
if type(line) in [ \
|
||||
Simple_line, Assert,
|
||||
Do , If,
|
||||
Elseif , Select,
|
||||
Call , Provide_all
|
||||
]:
|
||||
funcs = find_funcs_in_line(line)
|
||||
for f in funcs:
|
||||
vars += subroutines[f].needs
|
||||
result.append( (vars,line) )
|
||||
main_result.append( (filename, result) )
|
||||
return main_result
|
||||
|
||||
parsed_text = find_vars_from_functions()
|
||||
parsed_text = move_variables()
|
||||
|
||||
######################################################################
|
||||
def build_needs():
|
||||
@ -368,7 +439,7 @@ parsed_text = result
|
||||
######################################################################
|
||||
if __name__ == '__main__':
|
||||
for i in range(len(parsed_text)):
|
||||
if parsed_text[i][0] == 'libqcio_groups.irp.f':
|
||||
if parsed_text[i][0] == 'jastrow.irp.f':
|
||||
print '!-------- %s -----------'%(parsed_text[i][0])
|
||||
for line in parsed_text[i][1]:
|
||||
print line[1]
|
||||
|
@ -46,6 +46,13 @@ class Sub(object):
|
||||
return self._name
|
||||
name = property(name)
|
||||
|
||||
############################################################
|
||||
def is_function(self):
|
||||
if '_is_function' not in self.__dict__:
|
||||
self._is_function = "function" in self.line.text.lower()
|
||||
return self._is_function
|
||||
is_function = property(is_function)
|
||||
|
||||
############################################################
|
||||
def doc(self):
|
||||
if '_doc' not in self.__dict__:
|
||||
|
@ -35,7 +35,7 @@ def create_subroutines():
|
||||
buffer = []
|
||||
inside = False
|
||||
for line in text:
|
||||
if isinstance(line,Subroutine):
|
||||
if type(line) in [ Subroutine, Function ]:
|
||||
inside = True
|
||||
if inside:
|
||||
buffer.append(line)
|
||||
|
@ -191,7 +191,6 @@ class Variable(object):
|
||||
if '_regexp' not in self.__dict__:
|
||||
import re
|
||||
self._regexp = re.compile( \
|
||||
#r"^.*[^a-z0-9'\"_]+%s([^a-z0-9_]|$)"%(self.name),re.I)
|
||||
r"([^a-z0-9'\"_]|^)%s([^a-z0-9_]|$)"%(self.name),re.I)
|
||||
return self._regexp
|
||||
regexp = property(regexp)
|
||||
|
@ -1 +1 @@
|
||||
version = "1.1.34"
|
||||
version = "1.1.35"
|
||||
|
Loading…
Reference in New Issue
Block a user