10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-21 11:53:32 +01:00
irpf90/src/irpf90_t.py

409 lines
11 KiB
Python
Raw Normal View History

2018-04-27 14:33:57 +02:00
#!/usr/bin/env python2
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
import os
from zlib import crc32
2009-09-02 20:45:53 +02:00
irpdir = "IRPF90_temp/"
mandir = "IRPF90_man/"
2011-06-03 10:48:39 +02:00
irp_id = abs(crc32(os.getcwd()))
2009-09-02 20:45:53 +02:00
class Line(object):
def __init__(self,i,text,filename):
self.i = i
self._text = None
2009-09-02 20:45:53 +02:00
self.filename = filename
self._lower = None
self.set_text(text)
def get_text(self):
return self._text
def set_text(self,value):
self._text = value
self._lower = value.lower()
def get_lower(self):
return self._lower
text = property(fget=get_text, fset=set_text)
lower = property(fget=get_lower)
2009-09-02 20:45:53 +02:00
class Empty_line(Line):
2014-04-01 17:47:06 +02:00
str="Empty_line"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Empty_line",self.i,self.text)
class Simple_line(Line):
2014-04-01 17:47:06 +02:00
str="Simple_line"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Simple_line",self.i,self.text)
class Declaration(Line):
2014-04-01 17:47:06 +02:00
str="Declaration"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Declaration",self.i,self.text)
class Continue(Line):
2014-04-01 17:47:06 +02:00
str="Continue"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Continue",self.i,self.text)
class Begin_provider(Line):
2014-04-01 17:47:06 +02:00
str="Begin_provider"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Begin_provider",self.i,self.text)
class Cont_provider(Line):
2014-04-01 17:47:06 +02:00
str="Cont_provider"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Cont_provider",self.i,self.text)
class End_provider(Line):
2014-04-01 17:47:06 +02:00
str="End_provider"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("End_provider",self.i,self.text)
class Begin_doc(Line):
2014-04-01 17:47:06 +02:00
str="Begin_doc"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Begin_doc",self.i,self.text)
class Doc(Line):
2014-04-01 17:47:06 +02:00
str="Doc"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Doc",self.i,self.text)
class End_doc(Line):
2014-04-01 17:47:06 +02:00
str="End_doc"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("End_doc",self.i,self.text)
class Begin_shell(Line):
2014-04-01 17:47:06 +02:00
str="Begin_shell"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Begin_shell",self.i,self.text)
class End_shell(Line):
2014-04-01 17:47:06 +02:00
str="End_shell"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("End_shell",self.i,self.text)
2009-12-09 20:26:09 +01:00
class Begin_template(Line):
2014-04-01 17:47:06 +02:00
str="Begin_template"
2009-12-09 20:26:09 +01:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Begin_template",self.i,self.text)
class End_template(Line):
2014-04-01 17:47:06 +02:00
str="End_template"
2009-12-09 20:26:09 +01:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("End_template",self.i,self.text)
class Subst(Line):
2014-04-01 17:47:06 +02:00
str="Subst"
2009-12-09 20:26:09 +01:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Subst",self.i,self.text)
2009-09-02 20:45:53 +02:00
class Assert(Line):
2014-04-01 17:47:06 +02:00
str="Assert"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Assert",self.i,self.text)
class Touch(Line):
2014-04-01 17:47:06 +02:00
str="Touch"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Touch",self.i,self.text)
2010-03-29 20:43:00 +02:00
class SoftTouch(Touch):
2014-04-01 17:47:06 +02:00
str="SoftTouch"
2010-03-29 20:43:00 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("SoftTouch",self.i,self.text)
2009-09-02 20:45:53 +02:00
class Irp_read(Line):
2014-04-01 17:47:06 +02:00
str="Irp_read"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Irp_read",self.i,self.text)
class Irp_write(Line):
2014-04-01 17:47:06 +02:00
str="Irp_write"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Irp_write",self.i,self.text)
class Irp_If(Line):
2014-04-01 17:47:06 +02:00
str="Irp_If"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Irp_If",self.i,self.text)
class Irp_Else(Line):
2014-04-01 17:47:06 +02:00
str="Irp_Else"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Irp_Else",self.i,self.text)
class Irp_Endif(Line):
2014-04-01 17:47:06 +02:00
str="Irp_Endif"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Irp_Endif",self.i,self.text)
class Openmp(Line):
2014-04-01 17:47:06 +02:00
str="Openmp"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Openmp",self.i,self.text)
class Directive(Line):
2014-04-01 17:47:06 +02:00
str="Directive"
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Directive",self.i,self.text)
2009-09-02 20:45:53 +02:00
class Use(Line):
2014-04-01 17:47:06 +02:00
str="Use"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Use",self.i,self.text)
class Do(Line):
2014-04-01 17:47:06 +02:00
str="Do"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Do",self.i,self.text)
class Enddo (Line):
2014-04-01 17:47:06 +02:00
str="Enddo"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Enddo",self.i,self.text)
class If(Line):
2014-04-01 17:47:06 +02:00
str="If"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("If",self.i,self.text)
class Elseif(Line):
2014-04-01 17:47:06 +02:00
str="Elseif"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Elseif",self.i,self.text)
class Else(Line):
2014-04-01 17:47:06 +02:00
str="Else"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Else",self.i,self.text)
class Endif(Line):
2014-04-01 17:47:06 +02:00
str="Endif"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Endif",self.i,self.text)
class Select(Line):
2014-04-01 17:47:06 +02:00
str="Select"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Select",self.i,self.text)
class Case(Line):
2014-04-01 17:47:06 +02:00
str="Case"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Case",self.i,self.text)
class End_select(Line):
2014-04-01 17:47:06 +02:00
str="End_select"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("End_select",self.i,self.text)
class Program(Line):
2014-04-01 17:47:06 +02:00
str="Program"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Program",self.i,self.text)
class Subroutine(Line):
2014-04-01 17:47:06 +02:00
str="Subroutine"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Subroutine",self.i,self.text)
class Function(Line):
2014-04-01 17:47:06 +02:00
str="Function"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Function",self.i,self.text)
class Call(Line):
2014-04-01 17:47:06 +02:00
str="Call"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Call",self.i,self.text)
class Provide(Line):
2014-04-01 17:47:06 +02:00
str="Provide"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Provide",self.i,self.text)
2011-03-03 15:46:21 +01:00
class NoDep(Line):
2014-04-01 17:47:06 +02:00
str="NoDep"
2011-03-03 15:46:21 +01:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("NoDep",self.i,self.text)
2009-09-02 20:45:53 +02:00
class Return (Line):
2014-04-01 17:47:06 +02:00
str="Return"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Return",self.i,self.text)
class Include(Line):
2014-04-01 17:47:06 +02:00
str="Include"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Include",self.i,self.text)
class Implicit (Line):
2014-04-01 17:47:06 +02:00
str="Implicit"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Implicit",self.i,self.text)
class Free(Line):
2014-04-01 17:47:06 +02:00
str="Free"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Free",self.i,self.text)
class End(Line):
2014-04-01 17:47:06 +02:00
str="End"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("End",self.i,self.text)
class Provide_all (Line):
2014-04-01 17:47:06 +02:00
str="Provide_all"
2009-09-02 20:45:53 +02:00
def __init__(self,i,text,filename):
Line.__init__(self,i,text,filename)
def __repr__(self):
return "%20s:%5d : %s"%("Provide_all",self.i,self.text)
2009-09-04 15:11:42 +02:00
######################################################################
def create_irpf90_files():
result = []
from command_line import command_line
import os
def is_irpf90_file(filename):
2012-02-17 11:32:45 +01:00
return filename.endswith(".irp.f") and not filename.startswith('.')
result = filter ( is_irpf90_file, os.listdir(os.getcwd()) )
2013-11-20 17:43:03 +01:00
for dir in command_line.include_dir:
try:
os.stat(dir)
result += map(lambda x: dir+x, filter ( is_irpf90_file, os.listdir(dir) ) )
except:
continue
2014-01-07 17:01:40 +01:00
if command_line.do_codelet:
result += [command_line.codelet[3]]
2009-09-04 15:11:42 +02:00
return result
irpf90_files = create_irpf90_files()
2009-09-02 20:45:53 +02:00