10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-11-10 16:13:42 +01:00

Added subroutines

Version:1.1.3
This commit is contained in:
Anthony Scemama 2009-09-04 18:37:10 +02:00
parent 7f8767ee5e
commit 31547aac08
6 changed files with 120 additions and 18 deletions

View File

@ -4,6 +4,7 @@ from irpf90_t import *
from regexps import *
import error
from command_line import command_line
from util import *
# Local regular expressions
re_endif = re.compile("end\s+if")
@ -424,16 +425,7 @@ def irp_simple_statements(text):
def process_subroutine(line):
assert isinstance(line,Subroutine)
buffer = line.text.split('(')
if len(buffer) > 1:
buffer = " ".join(buffer[:-1])
else:
buffer = buffer[0]
buffer = buffer.lower().split()
if len(buffer) != 2:
print buffer
error.fail(line,"Error in Subroutine statement")
subname = buffer[1]
subname = find_subname(line)
length = len(subname)
i = line.i
f = line.filename
@ -449,12 +441,8 @@ def irp_simple_statements(text):
assert isinstance(line,Function)
buffer = line.text.split('(')
if (len(buffer) < 2):
error.fail(line,"Error in Function statement")
buffer = " ".join(buffer[:-1])
buffer = buffer.lower().split()
if len(buffer) < 2:
error.fail(line,"Error in Function statement")
subname = buffer[-1]
error.fail(line,"Syntax error")
subname = find_subname(line)
length = len(subname)
i = line.i
f = line.filename

72
src/subroutine.py Normal file
View File

@ -0,0 +1,72 @@
#!/usr/bin/python
from irpf90_t import *
from util import *
import error
class Sub(object):
############################################################
def __init__(self,text):
assert isinstance(text,list)
assert len(text) > 0
assert isinstance(text[0],Subroutine) or isinstance(text[0],Function)
self.text = text
############################################################
def name(self):
'''Name is lowercase'''
if '_name' not in self.__dict__:
self._name = find_subname(self.line)
return self._name
name = property(name)
############################################################
def doc(self):
if '_doc' not in self.__dict__:
def f(l): return
buffer = filter(lambda l:isinstance(l,Doc), self.text)
self._doc = map(lambda l: l.text[1:], buffer)
if buffer == []:
error.warn(None,"Subroutine %s is not documented"%(self.name))
return self._doc
doc = property(doc)
############################################################
def line(self):
if '_line' not in self.__dict__:
self._line = self.text[0]
return self._line
line = property(line)
############################################################
def touches(self):
if '_touches' not in self.__dict__:
self._touches = filter(lambda x: isinstance(x,Touch),self.text) != []
return self._touches
############################################################
def regexp(self):
if '_regexp' not in self.__dict__:
import re
self._regexp = re.compile( \
r"^.*[^a-z0-9'\"_]+%s([^a-z0-9_]|$)"%(self.name),re.I)
return self._regexp
regexp = property(regexp)
############################################################
def calls(self):
if '_calls' not in self.__dict__:
buffer = filter(lambda x: isinstance(x,Call),self.text)
self._calls = []
for line in buffer:
sub = line.text.split('(',1)[0].split()[1]
self._calls.append(sub)
return self._calls
calls = property(calls)
######################################################################
if __name__ == '__main__':
from preprocessed_text import preprocessed_text
from subroutines import subroutines
print subroutines['invert'].calls

29
src/subroutines.py Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/python
from subroutine import *
from irpf90_t import *
def create_subroutines():
from preprocessed_text import preprocessed_text
result = {}
for filename, text in preprocessed_text:
buffer = []
inside = False
for line in text:
if isinstance(line,Subroutine):
inside = True
if inside:
buffer.append(line)
if isinstance(line,End):
if inside:
v = Sub(buffer)
result[v.name] = v
buffer = []
inside = False
return result
subroutines = create_subroutines()
if __name__ == '__main__':
for v in subroutines.keys():
print v

View File

@ -26,6 +26,19 @@ def build_dim(dim):
else:
return "(%s)"%( ",".join(dim) )
def find_subname(line):
buffer = line.text.split('(')
if len(buffer) > 1:
buffer = " ".join(buffer[:-1])
else:
buffer = buffer[0]
buffer = buffer.lower().split()
if len(buffer) < 2:
error.fail(line,"Syntax Error")
return buffer[-1]
if __name__ == '__main__':
print build_dim([])
print build_dim(['a'])

View File

@ -10,7 +10,7 @@ class Variable(object):
def __init__(self,text,name = None):
assert isinstance(text,list)
assert len(text) > 0
assert isinstance(text[0],Line)
assert isinstance(text[0],Begin_provider)
self.text = text
if name is not None:
self._name = name.lower()

View File

@ -1 +1 @@
version = "1.1.2"
version = "1.1.3"