10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2025-01-03 01:55:42 +01:00

add support for WHERE statement

This commit is contained in:
Thomas Applencourt 2017-01-23 08:51:58 -06:00
parent 763278756b
commit 3032e754a7
4 changed files with 70 additions and 44 deletions

View File

@ -180,9 +180,15 @@ def create_build_compile(t, l_module, l_ext_modfile=[], ninja=True):
# MOD name are not part of the standart. # MOD name are not part of the standart.
needed_modules = [dress(x, in_root=True) for x in l_ext_modfile] needed_modules = [dress(x, in_root=True) for x in l_ext_modfile]
needed_modules += [
"%s.irp.o" % (x.filename) for x in l_module if x.name in t.needed_modules_usr # Expensive and stupid. We can create a dict to do the loockup only once
] for m in t.needed_modules_usr:
for x in l_module:
if m in x.gen_mod and x.filename != t.filename:
needed_modules.append("%s.irp.o" % x.filename)
from util import uniquify
needed_modules = uniquify(needed_modules)
needed_modules_irp = [ needed_modules_irp = [
"%s.irp.module.o" % (x.filename) for x in l_module if x.name in t.needed_modules_irp "%s.irp.module.o" % (x.filename) for x in l_module if x.name in t.needed_modules_irp
@ -200,12 +206,13 @@ def create_build_compile(t, l_module, l_ext_modfile=[], ninja=True):
list_of_modules = ' '.join(map(dress, needed_modules)) list_of_modules = ' '.join(map(dress, needed_modules))
list_of_modules_irp = ' '.join(map(dress, needed_modules_irp)) list_of_modules_irp = ' '.join(map(dress, needed_modules_irp))
inline_module = True inline_include = True
if not inline_module: if not inline_include:
#Wrong name, this not work! #Wrong name, this not work!
#list_of_includes = ' '.join(map(lambda x: dress(x, in_root=True), t.includes)) #list_of_includes = ' '.join(map(lambda x: dress(x, in_root=True), t.includes))
raise NotImplemented raise NotImplemented
else: else:
#The include have already by included
list_of_includes = ' ' list_of_includes = ' '
l_build = [ l_build = [
@ -283,24 +290,23 @@ def create_makefile(d_flags,d_var,irpf90_flags,ninja=True):
'\n'.join("{0} = {1}".format(k, ' '.join(v)) for k, v in sorted(d_var.iteritems())), '\n'.join("{0} = {1}".format(k, ' '.join(v)) for k, v in sorted(d_var.iteritems())),
''] '']
result += [ result += [ r'# Dark magic below modify with caution!',
r'# Dark magic below modify with caution!', r'# "You are Not Expected to Understand This"',
r'# "You are Not Expected to Understand This"', r"# .",
r"# .", r"# /^\ .",
r"# /^\ .", r'# /\ "V",',
r'# /\ "V",', r"# /__\ I O o",
r"# /__\ I O o", r"# //..\\ I .",
r"# //..\\ I .", r"# \].`[/ I",
r"# \].`[/ I", r"# /l\/j\ (] . O",
r"# /l\/j\ (] . O", r"# /. ~~ ,\/I .",
r"# /. ~~ ,\/I .", r"# \\L__j^\/I o",
r"# \\L__j^\/I o", r"# \/--v} I o .",
r"# \/--v} I o .", r"# | | I _________",
r"# | | I _________", r"# | | I c(` ')o",
r"# | | I c(` ')o", r"# | l I \. ,/",
r"# | l I \. ,/", r"# _/j L l\_! _//^---^\\_",
r"# _/j L l\_! _//^---^\\_", r""]
r""]
result += ["", result += ["",
"ifeq ($(BUILD_SYSTEM),ninja)", "ifeq ($(BUILD_SYSTEM),ninja)",
@ -309,16 +315,16 @@ r""]
"else ifeq ($(BUILD_SYSTEM),make)", "else ifeq ($(BUILD_SYSTEM),make)",
"\tBUILD_FILE=IRPF90_temp/build.make", "\tBUILD_FILE=IRPF90_temp/build.make",
"\tBUILD_SYSTEM += -j", "\tBUILD_SYSTEM += -j",
"else", "else",
"DUMMY:", "DUMMY:",
"\t$(error 'Wrong BUILD_SYSTEM: $(BUILD_SYSTEM)')", "\t$(error 'Wrong BUILD_SYSTEM: $(BUILD_SYSTEM)')",
"endif"] "endif"]
result += ["", result += ["",
"define run_and_touch", "define run_and_touch",
" $(BUILD_SYSTEM) -C $(dir $(1) ) -f $(notdir $(1) ) $(addprefix $(CURDIR)/, $(2)) && touch $(2)", " $(BUILD_SYSTEM) -C $(dir $(1) ) -f $(notdir $(1) ) $(addprefix $(CURDIR)/, $(2)) && touch $(2)",
"endef", "endef",
"", "",
"EXE := $(shell egrep -ri '^\s*program' *.irp.f | cut -d'.' -f1)", "EXE := $(shell egrep -ri '^\s*program' *.irp.f | cut -d'.' -f1)",
"", "",
".PHONY: all", ".PHONY: all",

View File

@ -75,8 +75,8 @@ l_type = [
"Assert", "Touch", "SoftTouch", "Irp_read", "Irp_write", "Irp_If", "Assert", "Touch", "SoftTouch", "Irp_read", "Irp_write", "Irp_If",
"Irp_Else", "Irp_Endif", "Openmp", "Directive", "Use", "Do", "Enddo", "If", "Irp_Else", "Irp_Endif", "Openmp", "Directive", "Use", "Do", "Enddo", "If",
"Elseif", "Else", "Endif", "Select", "Case", "End_select", "Provide", "NoDep", "Return", "Include", "Elseif", "Else", "Endif", "Select", "Case", "End_select", "Provide", "NoDep", "Return", "Include",
"Implicit", "Free", "End", "Provide_all","Contains",'Type','End_module','Interface','End_interface' "Implicit", "Free", "End", "Provide_all","Contains",'Type','End_module','Interface','End_interface',
] 'Where','Elsewhere','Endwhere']
for t in l_type: for t in l_type:
globals()[t] = type(t, (Line, ), {}) globals()[t] = type(t, (Line, ), {})

View File

@ -155,11 +155,15 @@ class Fmodule(object):
result = [] result = []
dec = [] dec = []
use = [] use = []
module = []
for vars, line in text: for vars, line in text:
if isinstance(line, (Subroutine, Function, Program,Interface,Module)): if isinstance(line, (Subroutine, Function, Program,Interface,Module)):
inside += 1 inside += 1
if type(line) == Module:
module.append((vars,line))
if inside: if inside:
result.append((vars, line)) result.append((vars, line))
else: else:
@ -167,6 +171,7 @@ class Fmodule(object):
use.append((vars, line)) use.append((vars, line))
elif type(line) == Declaration: elif type(line) == Declaration:
dec.append((vars, line)) dec.append((vars, line))
if isinstance(line,(End,End_interface,End_module)): if isinstance(line,(End,End_interface,End_module)):
inside += -1 inside += -1
@ -175,13 +180,13 @@ class Fmodule(object):
print 'Something wrong append' print 'Something wrong append'
sys.exit(1) sys.exit(1)
return use, dec, result return use, module, dec, result
result = remove_providers(self.text) result = remove_providers(self.text)
result = modify_functions(result) result = modify_functions(result)
from collections import namedtuple from collections import namedtuple
Residual_text_use_dec = namedtuple('Residual_text_use_dec', ['use', 'dec', 'result']) Residual_text_use_dec = namedtuple('Residual_text_use_dec', ['use', 'module', 'dec', 'result'])
return Residual_text_use_dec(*extract_use_dec_text(result)) return Residual_text_use_dec(*extract_use_dec_text(result))
@ -189,6 +194,11 @@ class Fmodule(object):
def use(self): def use(self):
return set(" %s" % line.text for _, line in self.residual_text_use_dec.use) return set(" %s" % line.text for _, line in self.residual_text_use_dec.use)
@irpy.lazy_property
def gen_mod(self):
'''List of module generated by the user in this module...'''
return set("%s" % line.subname for _, line in self.residual_text_use_dec.module)
@irpy.lazy_property @irpy.lazy_property
def dec(self): def dec(self):
'''The declaration of this module '''The declaration of this module
@ -230,8 +240,7 @@ class Fmodule(object):
@irpy.lazy_property @irpy.lazy_property
def needed_modules(self): def needed_modules(self):
l = set(x.split()[1] for x in self.generated_text + self.head + self.residual_text l = set(x.split(',only').pop(0).split()[1] for x in self.generated_text + self.head + self.residual_text if x.lstrip().startswith("use "))
if x.lstrip().startswith("use "))
if self.name in l: if self.name in l:
l.remove(self.name) l.remove(self.name)

View File

@ -34,6 +34,8 @@ import sys
re_endif = re.compile("end +if") re_endif = re.compile("end +if")
re_elseif = re.compile("else +if") re_elseif = re.compile("else +if")
re_enddo = re.compile("end +do") re_enddo = re.compile("end +do")
re_endwhere = re.compile("end +where")
re_endtype = re.compile("end +type.*") re_endtype = re.compile("end +type.*")
re_endmodule = re.compile("end +module",re.I) re_endmodule = re.compile("end +module",re.I)
re_endselect = re.compile("end +select") re_endselect = re.compile("end +select")
@ -91,7 +93,10 @@ simple_dict = {
"module": Module, "module": Module,
"endmodule": End_module, "endmodule": End_module,
"interface": Interface, "interface": Interface,
"endinterface": End_interface "endinterface": End_interface,
"where": Where,
"elsewhere": Elsewhere,
"endwhere": Endwhere,
} }
def get_canonized_text(text_lower): def get_canonized_text(text_lower):
@ -104,6 +109,7 @@ def get_canonized_text(text_lower):
text_canonized = re_endif.sub("endif", text_canonized) text_canonized = re_endif.sub("endif", text_canonized)
text_canonized = re_endselect.sub("endselect", text_canonized) text_canonized = re_endselect.sub("endselect", text_canonized)
text_canonized = re_endinterface.sub("endinterface", text_canonized) text_canonized = re_endinterface.sub("endinterface", text_canonized)
text_canonized = re_endwhere.sub('endwhere',text_canonized)
for c in """()'"[]""": for c in """()'"[]""":
text_canonized = text_canonized.replace(c, " %s " % c) text_canonized = text_canonized.replace(c, " %s " % c)
@ -422,7 +428,7 @@ def remove_comments(text, form):
inside = False inside = False
elif c == '!' and not inside: elif c == '!' and not inside:
return str_[:i] return str_[:i].strip()
return str_ return str_
@ -842,13 +848,18 @@ def check_begin_end(raw_text):
for t_end, l_begin in d_block.iteritems(): for t_end, l_begin in d_block.iteritems():
n_end = len(d_type[t_end]) n_end = len(d_type[t_end])
n_begin = sum(len(d_type[t_begin]) for t_begin in l_begin) n_begin = sum(len(d_type[t_begin]) for t_begin in l_begin)
if n_end > n_begin: if n_end != n_begin:
if n_end > n_begin:
logger.error("You have more close statement than open statement (%s) (%s)",line.filename,t_end) logger.error("You have more close statement than open statement (%s) (%s)",line.filename,t_end)
sys.exit(1) else:
elif n_end < n_begin:
logger.error('You have more end statement than open statenemt for (%s) (%s)' % (line.filename, t_end)) logger.error('You have more end statement than open statenemt for (%s) (%s)' % (line.filename, t_end))
sys.exit(1)
for i in zip([l for i in l_begin for l in d_type[i]], d_type[t_end]):
logger.debug(i)
sys.exit(1)
###################################################################### ######################################################################
def remove_ifdefs(text): def remove_ifdefs(text):