irpf90/src/create_man.py

364 lines
11 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-06 00:47:20 +02:00
2020-01-27 18:43:22 +01:00
from variable import Variable
from variables import variables
from subroutine import Sub
from subroutines import subroutines
from irpf90_t import *
from util import *
2009-09-06 00:47:20 +02:00
def do_print_short(file,var):
2019-01-17 16:22:26 +01:00
"""Makes a short print, as in irpf90_entities"""
2010-10-02 23:42:55 +02:00
assert type(var) == Variable
2020-01-27 18:22:35 +01:00
print("%s : %s :: %s %s"%( \
2015-01-30 17:29:15 +01:00
var.line.filename[0].ljust(35),
var.type.ljust(30),
var.name.ljust(25),
2020-01-27 18:22:35 +01:00
build_dim(var.dim) ), file=file)
2009-09-06 00:47:20 +02:00
######################################################################
def process_doc(file,line):
2010-10-02 23:42:55 +02:00
assert type(line) == str
2009-09-06 00:47:20 +02:00
line = line.strip()
if line == "":
line = ".br"
2020-01-27 18:22:35 +01:00
print(line, file=file)
2009-09-06 00:47:20 +02:00
######################################################################
def process_deps(file,l):
2010-10-02 23:42:55 +02:00
assert type(l) == list
2009-09-06 00:47:20 +02:00
for v in l:
2020-01-27 18:22:35 +01:00
print("%s\n.br"%(v,), file=file)
2009-09-06 00:47:20 +02:00
######################################################################
def process_types(file,var):
2010-10-02 23:42:55 +02:00
assert type(var) == Variable
2009-09-07 18:02:06 +02:00
vars = [var.name] + var.others
2009-09-06 00:47:20 +02:00
for var in vars:
name = var
var = variables[var]
2010-10-02 23:42:55 +02:00
Type = var.type
2009-09-08 16:00:46 +02:00
dim = build_dim(var.dim)
2020-01-27 18:22:35 +01:00
print("%s\t:: %s\t%s"%(Type,name,dim), file=file)
2009-09-06 00:47:20 +02:00
######################################################################
def do_print(var):
2010-10-02 23:42:55 +02:00
assert type(var) == Variable
2009-09-16 15:59:13 +02:00
filename = var.line.filename[0]
2009-09-06 00:47:20 +02:00
name = var.name
file = open("%s%s.l"%(mandir,var.name), "w")
2020-01-27 18:22:35 +01:00
print('.TH "IRPF90 entities" l %s "IRPF90 entities" %s'%(name,name), file=file)
2009-09-07 18:02:06 +02:00
if var.same_as != var.name:
2009-09-06 00:47:20 +02:00
var = variables[var.same_as]
2020-01-27 18:22:35 +01:00
print(".SH Declaration", file=file)
print(".nf", file=file)
2009-09-06 00:47:20 +02:00
process_types(file,var)
2020-01-27 18:22:35 +01:00
print(".ni", file=file)
2009-09-06 00:47:20 +02:00
if var.doc != []:
2020-01-27 18:22:35 +01:00
print(".SH Description", file=file)
2009-09-06 00:47:20 +02:00
for l in var.doc:
process_doc(file,l)
2020-01-27 18:22:35 +01:00
print(".SH File\n.P", file=file)
print(filename, file=file)
2009-09-06 00:47:20 +02:00
if var.needs != []:
2009-09-16 15:59:13 +02:00
var.needs.sort()
2020-01-27 18:22:35 +01:00
print(".SH Needs", file=file)
2009-09-06 00:47:20 +02:00
process_deps(file,var.needs)
if var.needed_by != []:
2009-09-16 15:59:13 +02:00
var.needed_by.sort()
2020-01-27 18:22:35 +01:00
print(".SH Needed by", file=file)
2009-09-06 00:47:20 +02:00
process_deps(file,var.needed_by)
2020-01-27 18:22:35 +01:00
print(".SH Instability factor", file=file)
2015-01-20 00:01:40 +01:00
fo = len(var.children)
fi = len(var.parents)
2020-01-27 18:22:35 +01:00
print("%5.1f %%"%(100.* (fi / (fi+fo+.000001) )), file=file)
print(".br", file=file)
2009-09-06 00:47:20 +02:00
file.close()
2019-01-17 16:22:26 +01:00
######################################################################
def do_print_rst(var):
"""Print providers in a format suitable for sphinx"""
assert type(var) == Variable
filename = var.line.filename[0]
name = var.name
file = open("%s%s.rst"%(mandir,var.name), "w")
2020-01-27 18:22:35 +01:00
print(".. c:var:: %s\n"%(var.name.lower()), file=file)
print("", file=file)
print(" File : :file:`"+filename+"`", file=file)
print("", file=file)
print(" .. code:: fortran", file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
if var.same_as != var.name:
var = variables[var.same_as]
for v in [var.name] + var.others:
name = v
v = variables[v]
Type = v.type
dim = build_dim(v.dim)
2020-01-27 18:22:35 +01:00
print(" %s\t:: %s\t%s"%(Type,name,dim), file=file)
print("", file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
if var.doc != []:
d = []
for text in var.doc:
text_old = None
while text_old != text:
text_old = text
text = text.replace("$",":math:`",1).replace("$","` ",1)
d.append(text)
loop = True
while loop:
maxlen=0
for l in d:
ll = len(l)
maxlen = max(ll,maxlen)
if ll > 0 and l[0] != ' ':
loop = False
break
loop = loop and maxlen > 0
if loop:
d = [ l[1:] for l in d ]
for line in d:
2020-01-27 18:22:35 +01:00
print(" "+line, file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
if var.needs != []:
var.needs.sort()
2020-01-27 18:22:35 +01:00
print(" Needs:", file=file)
print("", file=file)
print(" .. hlist::", file=file)
print(" :columns: 3", file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
for v in var.needs:
2020-01-27 18:22:35 +01:00
print(" * :c:data:`%s`"%(variables[v].same_as.lower(),), file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
if var.needed_by != []:
var.needed_by.sort()
2020-01-27 18:22:35 +01:00
print(" Needed by:", file=file)
print("", file=file)
print(" .. hlist::", file=file)
print(" :columns: 3", file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
for v in var.needed_by:
2020-01-27 18:22:35 +01:00
print(" * :c:data:`%s`"%(variables[v].same_as.lower(),), file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
file.close()
######################################################################
def process_declaration_subroutine(file, sub):
2020-01-27 18:22:35 +01:00
print(sub.line.text.split('!')[0].strip(), file=file)
# for line in sub.text:
######################################################################
def do_print_subroutines(sub):
assert type(sub) == Sub
filename = sub.line.filename
name = sub.name
file = open("%s%s.l"%(mandir,sub.name), "w")
2020-01-27 18:22:35 +01:00
print('.TH "IRPF90 entities" l %s "IRPF90 entities" %s'%(name,name), file=file)
print(".SH Declaration", file=file)
print(".nf", file=file)
process_declaration_subroutine(file,sub)
2020-01-27 18:22:35 +01:00
print(".ni", file=file)
if sub.doc != []:
2020-01-27 18:22:35 +01:00
print(".SH Description", file=file)
for l in sub.doc:
process_doc(file,l)
2020-01-27 18:22:35 +01:00
print(".SH File\n.P", file=file)
print(filename, file=file)
if sub.needs != []:
sub.needs.sort()
2020-01-27 18:22:35 +01:00
print(".SH Needs", file=file)
process_deps(file,sub.needs)
if sub.called_by != []:
sub.called_by.sort()
2020-01-27 18:22:35 +01:00
print(".SH Called by", file=file)
process_deps(file,sub.called_by)
if sub.calls != []:
sub.calls.sort()
2020-01-27 18:22:35 +01:00
print(".SH Calls", file=file)
process_deps(file,sub.calls)
if sub.touches != []:
sub.touches.sort()
2020-01-27 18:22:35 +01:00
print(".SH Touches", file=file)
process_deps(file,sub.touches)
2020-01-27 18:22:35 +01:00
print(".SH Instability factor", file=file)
2015-01-20 00:01:40 +01:00
fo = len(sub.needs)+len(sub.calls)+len(sub.touches)
fi = len(sub.called_by)
2020-01-27 18:22:35 +01:00
print("%5.1f %%"%(100.* (fi / (fi+fo+.000001) )), file=file)
print(".br", file=file)
file.close()
2019-01-17 16:22:26 +01:00
######################################################################
def do_print_subroutines_rst(sub):
"""Print subroutines in a format suitable for sphinx"""
assert type(sub) == Sub
filename = sub.line.filename
name = sub.name
file = open("%s%s.rst"%(mandir,sub.name), "w")
2024-03-20 16:05:42 +01:00
print(".. c:macro:: %s:\n"%(sub.name.lower()), file=file)
2020-01-27 18:22:35 +01:00
print("", file=file)
print(" File : :file:`"+filename+"`", file=file)
print("", file=file)
print(" .. code:: fortran", file=file)
print("", file=file)
print(" "+sub.line.text.split('!')[0].strip(), file=file)
print("", file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
if sub.doc != []:
d = list(sub.doc)
loop = True
while loop:
maxlen=0
for l in d:
ll = len(l)
maxlen = max(ll,maxlen)
if ll > 0 and l[0] != ' ':
loop = False
break
loop = loop and maxlen > 0
if loop:
d = [ l[1:] for l in d ]
for l in d:
2020-01-27 18:22:35 +01:00
print(" "+l, file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
if sub.needs != []:
sub.needs.sort()
2020-01-27 18:22:35 +01:00
print(" Needs:", file=file)
print("", file=file)
print(" .. hlist::", file=file)
print(" :columns: 3", file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
for v in sub.needs:
2020-01-27 18:22:35 +01:00
print(" * :c:data:`%s`"%(variables[v].same_as.lower(),), file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
if sub.called_by != []:
sub.called_by.sort()
2020-01-27 18:22:35 +01:00
print(" Called by:", file=file)
print("", file=file)
print(" .. hlist::", file=file)
print(" :columns: 3", file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
for v in sub.called_by:
if v in subroutines:
2020-01-27 18:22:35 +01:00
print(" * :c:func:`%s`"%(v.lower(),), file=file)
2019-01-17 16:22:26 +01:00
elif v in variables:
2020-01-27 18:22:35 +01:00
print(" * :c:data:`%s`"%(variables[v.lower()].same_as.lower(),), file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
if sub.calls != []:
sub.calls.sort()
2020-01-27 18:22:35 +01:00
print(" Calls:", file=file)
print("", file=file)
print(" .. hlist::", file=file)
print(" :columns: 3", file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
for v in sub.calls:
2020-01-27 18:22:35 +01:00
print(" * :c:func:`%s`"%(v.lower(),), file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
if sub.touches != []:
sub.touches.sort()
2020-01-27 18:22:35 +01:00
print(" Touches:", file=file)
print("", file=file)
print(" .. hlist::", file=file)
print(" :columns: 3", file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
for v in sub.touches:
2020-01-27 18:22:35 +01:00
print(" * :c:data:`%s`"%(variables[v.lower()].same_as.lower(),), file=file)
print("", file=file)
2019-01-17 16:22:26 +01:00
file.close()
2009-09-06 00:47:20 +02:00
######################################################################
def run():
2020-01-27 18:43:22 +01:00
import parsed_text
import os,sys
2014-11-24 09:59:22 +01:00
pid1 = os.fork()
if pid1 == 0:
2020-01-27 18:22:35 +01:00
for v in list(variables.values()):
2011-04-09 23:45:50 +02:00
do_print(v)
2019-01-17 16:22:26 +01:00
do_print_rst(v)
2020-01-27 18:22:35 +01:00
for s in list(subroutines.values()):
do_print_subroutines(s)
2019-01-17 16:22:26 +01:00
do_print_subroutines_rst(s)
sys.exit(0)
2014-11-24 09:59:22 +01:00
pid2 = os.fork()
if pid2 == 0:
2014-03-11 15:43:02 +01:00
tags = []
2020-01-27 18:22:35 +01:00
l = list(variables.keys())
file = open("irpf90_entities","w")
l.sort()
for v in l:
do_print_short(file,variables[v])
2014-03-11 15:43:02 +01:00
line = variables[v].line
2014-04-25 17:21:04 +02:00
tags.append( '%s\t%s\t%d\n'%(v,line.filename[0],line.i) )
2014-03-11 15:43:02 +01:00
file.close()
2020-01-27 18:22:35 +01:00
l = list(subroutines.keys())
2014-03-11 15:43:02 +01:00
for v in l:
line = subroutines[v].line
2014-04-25 17:21:04 +02:00
tags.append('%s\t%s\t%d\n'%(v,line.filename,line.i))
2014-03-11 15:43:02 +01:00
tags.sort()
file = open("tags","w")
for line in tags:
file.write(line)
file.close()
2020-05-27 23:12:49 +02:00
2020-05-28 17:49:05 +02:00
# # Create emacs tags
# tags = {}
# l = list(variables.keys())
# for v in l:
# line = variables[v].line
# if line.filename[0] not in tags:
# tags[line.filename[0]] = []
# tags[line.filename[0]].append( (v,line) )
# l = list(subroutines.keys())
# for v in l:
# line = subroutines[v].line
# if line.filename not in tags:
# tags[line.filename] = []
# tags[line.filename].append( (v,line) )
#
# file = open("TAGS","w")
# for f in tags:
# tags[f].sort()
# text = ""
# for v, line in tags[f]:
# text += "%s\x7f%s\x01%d,0\n"%(line.text.split('!')[0].rstrip(),v,line.i)
# file.write("\x0c\n%s,%d\n"%(f, len(text)))
# file.write(text)
# file.close()
2020-05-27 23:12:49 +02:00
sys.exit(0)
2009-09-06 00:47:20 +02:00
2014-11-24 09:59:22 +01:00
os.waitpid(pid1,0)
os.waitpid(pid2,0)
2009-09-06 00:47:20 +02:00
######################################################################
if __name__ == '__main__':
run()