irpf90/src/subroutine.py

132 lines
4.4 KiB
Python
Raw Normal View History

2020-01-27 18:22:35 +01:00
#!/usr/bin/env python3
2009-09-23 12:51:27 +02:00
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
# the Implicit Reference to Parameters (IRP) method.
# Copyright (C) 2009 Anthony SCEMAMA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Anthony Scemama
# LCPQ - IRSAMC - CNRS
# Universite Paul Sabatier
# 118, route de Narbonne
# 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr
2009-09-23 12:51:27 +02:00
2009-09-04 18:37:10 +02:00
2020-01-27 18:43:22 +01:00
from irpf90_t import *
from util import *
import error
2009-09-04 18:37:10 +02:00
class Sub(object):
############################################################
def __init__(self,text):
2010-10-02 23:42:55 +02:00
assert type(text) == list
2009-09-04 18:37:10 +02:00
assert len(text) > 0
2009-09-05 15:37:23 +02:00
assert type(text[0]) in [Subroutine, Function]
2009-09-04 18:37:10 +02:00
self.text = text
self.called_by = []
2009-09-04 18:37:10 +02:00
############################################################
def name(self):
'''Name is lowercase'''
if '_name' not in self.__dict__:
self._name = find_subname(self.line)
return self._name
name = property(name)
2009-10-21 17:24:24 +02:00
############################################################
def is_function(self):
if '_is_function' not in self.__dict__:
2010-05-19 19:01:05 +02:00
self._is_function = "function" in self.line.lower
2009-10-21 17:24:24 +02:00
return self._is_function
is_function = property(is_function)
2009-09-04 18:37:10 +02:00
############################################################
def doc(self):
if '_doc' not in self.__dict__:
def f(l): return
2020-01-27 18:22:35 +01:00
buffer = [l for l in self.text if type(l) == Doc]
self._doc = [l.text.lstrip()[1:] for l in buffer]
2009-09-04 18:37:10 +02:00
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__:
2020-01-27 18:43:22 +01:00
from subroutines import subroutines
2009-09-04 23:48:49 +02:00
self._touches = []
2020-01-27 18:22:35 +01:00
for line in [x for x in self.text if type(x) in [Touch, SoftTouch]]:
2009-09-04 23:48:49 +02:00
self._touches += line.text.split()[1:]
for sub in self.calls:
2009-09-05 16:05:00 +02:00
if sub in subroutines:
self._touches += subroutines[sub].touches
2009-09-04 23:48:49 +02:00
self._touches = make_single(self._touches)
2009-09-04 18:37:10 +02:00
return self._touches
2009-09-04 23:48:49 +02:00
touches = property(touches)
2009-09-04 18:37:10 +02:00
############################################################
def needs(self):
if '_needs' not in self.__dict__:
2020-01-27 18:43:22 +01:00
import parsed_text
2014-05-13 11:15:24 +02:00
self._needs = make_single(self._needs)
return self._needs
needs = property(needs)
############################################################
def to_provide(self):
if '_to_provide' not in self.__dict__:
2020-01-27 18:43:22 +01:00
import parsed_text
return self._to_provide
to_provide = property(to_provide)
2009-09-04 18:37:10 +02:00
############################################################
def regexp(self):
if '_regexp' not in self.__dict__:
import re
self._regexp = re.compile( \
2009-09-09 16:59:43 +02:00
r"([^a-z0-9'\"_]|^)%s([^a-z0-9_]|$)"%(self.name),re.I)
2009-09-04 18:37:10 +02:00
return self._regexp
regexp = property(regexp)
############################################################
def calls(self):
if '_calls' not in self.__dict__:
2020-01-27 18:22:35 +01:00
buffer = [x for x in self.text if type(x) == Call]
2009-09-04 18:37:10 +02:00
self._calls = []
for line in buffer:
sub = line.text.split('(',1)[0].split()[1].lower()
2009-09-04 18:37:10 +02:00
self._calls.append(sub)
2009-09-04 23:48:49 +02:00
self._calls = make_single(self._calls)
2009-09-04 18:37:10 +02:00
return self._calls
calls = property(calls)
######################################################################
if __name__ == '__main__':
2020-01-27 18:43:22 +01:00
from preprocessed_text import preprocessed_text
from variables import variables
from subroutines import subroutines
2020-01-27 18:22:35 +01:00
print([variables[x].needs for x in subroutines['full_ci'].needs])
print(subroutines['full_ci'].calls)