mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-12-21 20:03:33 +01:00
Added subroutines
Version:1.1.3
This commit is contained in:
parent
7f8767ee5e
commit
31547aac08
@ -4,6 +4,7 @@ from irpf90_t import *
|
|||||||
from regexps import *
|
from regexps import *
|
||||||
import error
|
import error
|
||||||
from command_line import command_line
|
from command_line import command_line
|
||||||
|
from util import *
|
||||||
|
|
||||||
# Local regular expressions
|
# Local regular expressions
|
||||||
re_endif = re.compile("end\s+if")
|
re_endif = re.compile("end\s+if")
|
||||||
@ -424,16 +425,7 @@ def irp_simple_statements(text):
|
|||||||
|
|
||||||
def process_subroutine(line):
|
def process_subroutine(line):
|
||||||
assert isinstance(line,Subroutine)
|
assert isinstance(line,Subroutine)
|
||||||
buffer = line.text.split('(')
|
subname = find_subname(line)
|
||||||
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]
|
|
||||||
length = len(subname)
|
length = len(subname)
|
||||||
i = line.i
|
i = line.i
|
||||||
f = line.filename
|
f = line.filename
|
||||||
@ -449,12 +441,8 @@ def irp_simple_statements(text):
|
|||||||
assert isinstance(line,Function)
|
assert isinstance(line,Function)
|
||||||
buffer = line.text.split('(')
|
buffer = line.text.split('(')
|
||||||
if (len(buffer) < 2):
|
if (len(buffer) < 2):
|
||||||
error.fail(line,"Error in Function statement")
|
error.fail(line,"Syntax error")
|
||||||
buffer = " ".join(buffer[:-1])
|
subname = find_subname(line)
|
||||||
buffer = buffer.lower().split()
|
|
||||||
if len(buffer) < 2:
|
|
||||||
error.fail(line,"Error in Function statement")
|
|
||||||
subname = buffer[-1]
|
|
||||||
length = len(subname)
|
length = len(subname)
|
||||||
i = line.i
|
i = line.i
|
||||||
f = line.filename
|
f = line.filename
|
||||||
|
72
src/subroutine.py
Normal file
72
src/subroutine.py
Normal 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
29
src/subroutines.py
Normal 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
|
13
src/util.py
13
src/util.py
@ -26,6 +26,19 @@ def build_dim(dim):
|
|||||||
else:
|
else:
|
||||||
return "(%s)"%( ",".join(dim) )
|
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__':
|
if __name__ == '__main__':
|
||||||
print build_dim([])
|
print build_dim([])
|
||||||
print build_dim(['a'])
|
print build_dim(['a'])
|
||||||
|
@ -10,7 +10,7 @@ class Variable(object):
|
|||||||
def __init__(self,text,name = None):
|
def __init__(self,text,name = None):
|
||||||
assert isinstance(text,list)
|
assert isinstance(text,list)
|
||||||
assert len(text) > 0
|
assert len(text) > 0
|
||||||
assert isinstance(text[0],Line)
|
assert isinstance(text[0],Begin_provider)
|
||||||
self.text = text
|
self.text = text
|
||||||
if name is not None:
|
if name is not None:
|
||||||
self._name = name.lower()
|
self._name = name.lower()
|
||||||
|
@ -1 +1 @@
|
|||||||
version = "1.1.2"
|
version = "1.1.3"
|
||||||
|
Loading…
Reference in New Issue
Block a user