mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-12-21 11:53:32 +01:00
Optimization: lower() -> text_lower
Version:1.1.48
This commit is contained in:
parent
d3f76c4580
commit
83c9ce5635
@ -73,7 +73,7 @@ class CommandLine(object):
|
|||||||
self._touched = []
|
self._touched = []
|
||||||
for o,a in self.opts:
|
for o,a in self.opts:
|
||||||
if o in [ "-t", options['t'][0] ]:
|
if o in [ "-t", options['t'][0] ]:
|
||||||
self._touched.append(a)
|
self._touched.append(a.lower())
|
||||||
return self._touched
|
return self._touched
|
||||||
touched = property(fget=touched)
|
touched = property(fget=touched)
|
||||||
|
|
||||||
@ -142,6 +142,7 @@ do_$LONG = property(fget=do_$LONG)
|
|||||||
self.do_version or \
|
self.do_version or \
|
||||||
self.do_help or \
|
self.do_help or \
|
||||||
self.do_preprocess or \
|
self.do_preprocess or \
|
||||||
|
self.do_touch or \
|
||||||
self.do_init )
|
self.do_init )
|
||||||
return self._do_run
|
return self._do_run
|
||||||
do_run = property(fget=do_run)
|
do_run = property(fget=do_run)
|
||||||
|
@ -48,10 +48,23 @@ def main():
|
|||||||
print line.text
|
print line.text
|
||||||
|
|
||||||
|
|
||||||
|
if command_line.do_touch:
|
||||||
|
from variables import variables
|
||||||
|
for var in command_line.touched:
|
||||||
|
if var not in variables:
|
||||||
|
print "%s is not an IRP entity"%(var,)
|
||||||
|
else:
|
||||||
|
print "%s touches the following entities:"%(var,)
|
||||||
|
parents = variables[var].parents
|
||||||
|
parents.sort()
|
||||||
|
for x in parents:
|
||||||
|
print "- %s"%(x,)
|
||||||
|
|
||||||
if not command_line.do_run:
|
if not command_line.do_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
|
||||||
import irp_stack
|
import irp_stack
|
||||||
irp_stack.create()
|
irp_stack.create()
|
||||||
|
|
||||||
@ -70,17 +83,5 @@ def main():
|
|||||||
import create_man
|
import create_man
|
||||||
create_man.run()
|
create_man.run()
|
||||||
|
|
||||||
if command_line.do_touch:
|
|
||||||
from variables import variables
|
|
||||||
for var in command_line.touched:
|
|
||||||
if var not in variables:
|
|
||||||
print "%s is not an IRP entity"%(var,)
|
|
||||||
else:
|
|
||||||
print "%s touches the following entities:"%(var,)
|
|
||||||
parents = variables[var].parents
|
|
||||||
parents.sort()
|
|
||||||
for x in parents:
|
|
||||||
print "- %s"%(x,)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -34,6 +34,14 @@ class Line(object):
|
|||||||
self.i = i
|
self.i = i
|
||||||
self.text = text
|
self.text = text
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
self._lower = None
|
||||||
|
|
||||||
|
def get_lower(self):
|
||||||
|
if self._lower is None:
|
||||||
|
self._lower = self.text.lower()
|
||||||
|
return self._lower
|
||||||
|
|
||||||
|
text_lower = property(fget=get_lower)
|
||||||
|
|
||||||
class Empty_line(Line):
|
class Empty_line(Line):
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
|
@ -36,16 +36,17 @@ import error
|
|||||||
vtuple = map(lambda v: (v, variables[v].same_as, variables[v].regexp), variables.keys())
|
vtuple = map(lambda v: (v, variables[v].same_as, variables[v].regexp), variables.keys())
|
||||||
stuple = map(lambda s: (s, subroutines[s].regexp), subroutines.keys())
|
stuple = map(lambda s: (s, subroutines[s].regexp), subroutines.keys())
|
||||||
stuple = filter(lambda s: subroutines[s[0]].is_function, stuple)
|
stuple = filter(lambda s: subroutines[s[0]].is_function, stuple)
|
||||||
|
re_string_sub = regexps.re_string.sub
|
||||||
|
|
||||||
def find_variables_in_line(line):
|
def find_variables_in_line(line):
|
||||||
assert isinstance(line,Line)
|
assert isinstance(line,Line)
|
||||||
result = []
|
result = []
|
||||||
sub_done = False
|
sub_done = False
|
||||||
buffer = line.text.lower()
|
buffer = line.text_lower
|
||||||
for v,same_as,regexp in vtuple:
|
for v,same_as,regexp in vtuple:
|
||||||
if v in buffer:
|
if v in buffer:
|
||||||
if not sub_done:
|
if not sub_done:
|
||||||
buffer = regexps.re_string.sub('',buffer)
|
buffer = re_string_sub('',buffer)
|
||||||
sub_done = True
|
sub_done = True
|
||||||
if regexp.search(buffer) is not None:
|
if regexp.search(buffer) is not None:
|
||||||
result.append(same_as)
|
result.append(same_as)
|
||||||
@ -55,7 +56,7 @@ def find_funcs_in_line(line):
|
|||||||
assert isinstance(line,Line)
|
assert isinstance(line,Line)
|
||||||
result = []
|
result = []
|
||||||
sub_done = False
|
sub_done = False
|
||||||
buffer = line.text.lower()
|
buffer = line.text_lower
|
||||||
for s,regexp in stuple:
|
for s,regexp in stuple:
|
||||||
if s in buffer:
|
if s in buffer:
|
||||||
if regexp.search(buffer) is not None:
|
if regexp.search(buffer) is not None:
|
||||||
@ -115,7 +116,7 @@ def get_parsed_text():
|
|||||||
varlist = []
|
varlist = []
|
||||||
result.append( ([],line) )
|
result.append( ([],line) )
|
||||||
elif isinstance(line,Provide):
|
elif isinstance(line,Provide):
|
||||||
l = line.text.lower().split()[1:]
|
l = line.text_lower.split()[1:]
|
||||||
l = filter(lambda x: x not in varlist, l)
|
l = filter(lambda x: x not in varlist, l)
|
||||||
for v in l:
|
for v in l:
|
||||||
if v not in variables.keys():
|
if v not in variables.keys():
|
||||||
@ -133,10 +134,10 @@ def get_parsed_text():
|
|||||||
if subroutines[sub].touches != []:
|
if subroutines[sub].touches != []:
|
||||||
result.append( ([],Provide_all(line.i,"",line.filename)) )
|
result.append( ([],Provide_all(line.i,"",line.filename)) )
|
||||||
elif isinstance(line,Free):
|
elif isinstance(line,Free):
|
||||||
vars = line.text.split()
|
vars = line.text_lower.split()
|
||||||
if len(vars) < 2:
|
if len(vars) < 2:
|
||||||
error.fail(line,"Syntax error")
|
error.fail(line,"Syntax error")
|
||||||
vars = map(lower,vars[1:])
|
vars = vars[1:]
|
||||||
for v in vars:
|
for v in vars:
|
||||||
variables[v].is_freed = True
|
variables[v].is_freed = True
|
||||||
result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||||
@ -153,10 +154,10 @@ def get_parsed_text():
|
|||||||
variables[line.filename]._is_written = True
|
variables[line.filename]._is_written = True
|
||||||
result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||||
elif isinstance(line,Touch):
|
elif isinstance(line,Touch):
|
||||||
vars = line.text.split()
|
vars = line.text_lower.split()
|
||||||
if len(vars) < 2:
|
if len(vars) < 2:
|
||||||
error.fail(line,"Syntax error")
|
error.fail(line,"Syntax error")
|
||||||
vars = map(lower,vars[1:])
|
vars = vars[1:]
|
||||||
for v in vars:
|
for v in vars:
|
||||||
if v not in variables:
|
if v not in variables:
|
||||||
error.fail(line,"Variable %s unknown"%(v,))
|
error.fail(line,"Variable %s unknown"%(v,))
|
||||||
@ -187,9 +188,9 @@ def get_parsed_text():
|
|||||||
elif type(line) in [ Begin_provider, Cont_provider ]:
|
elif type(line) in [ Begin_provider, Cont_provider ]:
|
||||||
if isinstance(line,Begin_provider):
|
if isinstance(line,Begin_provider):
|
||||||
varlist = []
|
varlist = []
|
||||||
buffer = map(strip,line.text.replace(']','').split(','))
|
buffer = map(strip,line.text_lower.replace(']','').split(','))
|
||||||
assert len(buffer) > 1
|
assert len(buffer) > 1
|
||||||
v = buffer[1].lower()
|
v = buffer[1]
|
||||||
varlist.append(v)
|
varlist.append(v)
|
||||||
variable_list = find_variables_in_line(line)
|
variable_list = find_variables_in_line(line)
|
||||||
try:
|
try:
|
||||||
@ -373,8 +374,8 @@ def build_needs():
|
|||||||
var = None
|
var = None
|
||||||
for vars,line in text:
|
for vars,line in text:
|
||||||
if isinstance(line,Begin_provider):
|
if isinstance(line,Begin_provider):
|
||||||
buffer = map(strip,line.text.replace(']',',').split(','))
|
buffer = map(strip,line.text_lower.replace(']',',').split(','))
|
||||||
var = variables[buffer[1].lower()]
|
var = variables[buffer[1]]
|
||||||
var.needs = []
|
var.needs = []
|
||||||
var.to_provide = vars
|
var.to_provide = vars
|
||||||
elif isinstance(line,End_provider):
|
elif isinstance(line,End_provider):
|
||||||
|
@ -67,11 +67,11 @@ def build_dim_colons(v):
|
|||||||
|
|
||||||
import error
|
import error
|
||||||
def find_subname(line):
|
def find_subname(line):
|
||||||
buffer = line.text
|
buffer = line.text_lower
|
||||||
if not buffer.endswith(')'):
|
if not buffer.endswith(')'):
|
||||||
buffer += "()"
|
buffer += "()"
|
||||||
buffer = buffer.split('(')
|
buffer = buffer.split('(')
|
||||||
buffer = buffer[0].lower().split()
|
buffer = buffer[0].split()
|
||||||
if len(buffer) < 2:
|
if len(buffer) < 2:
|
||||||
error.fail(line,"Syntax Error")
|
error.fail(line,"Syntax Error")
|
||||||
return buffer[-1]
|
return buffer[-1]
|
||||||
|
@ -39,7 +39,7 @@ class Variable(object):
|
|||||||
assert isinstance(text[0],Begin_provider)
|
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
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
def is_touched(self):
|
def is_touched(self):
|
||||||
@ -543,7 +543,7 @@ class Variable(object):
|
|||||||
##########################################################
|
##########################################################
|
||||||
def parents(self):
|
def parents(self):
|
||||||
if '_parents' not in self.__dict__:
|
if '_parents' not in self.__dict__:
|
||||||
if not self._is_main:
|
if not self.is_main:
|
||||||
self._parents = []
|
self._parents = []
|
||||||
else:
|
else:
|
||||||
from variables import variables
|
from variables import variables
|
||||||
|
Loading…
Reference in New Issue
Block a user