From c1b0c0dfa26c7fcfebc52520445176990409d859 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 4 Sep 2009 23:48:49 +0200 Subject: [PATCH] Completed subroutine touches and calls --- src/preprocessed_text.py | 2 -- src/subroutine.py | 12 ++++++++++-- src/util.py | 6 ++++++ src/variable.py | 3 ++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/preprocessed_text.py b/src/preprocessed_text.py index ac7a55a..49a334c 100644 --- a/src/preprocessed_text.py +++ b/src/preprocessed_text.py @@ -440,8 +440,6 @@ def irp_simple_statements(text): def process_function(line): assert isinstance(line,Function) buffer = line.text.split('(') - if (len(buffer) < 2): - error.fail(line,"Syntax error") subname = find_subname(line) length = len(subname) i = line.i diff --git a/src/subroutine.py b/src/subroutine.py index 78a5c5a..35e54c9 100644 --- a/src/subroutine.py +++ b/src/subroutine.py @@ -42,8 +42,15 @@ class Sub(object): ############################################################ def touches(self): if '_touches' not in self.__dict__: - self._touches = filter(lambda x: isinstance(x,Touch),self.text) != [] + from subroutines import subroutines + self._touches = [] + for line in filter(lambda x: isinstance(x,Touch),self.text): + self._touches += line.text.split()[1:] + for sub in self.calls: + self._touches += subroutines[sub].touches + self._touches = make_single(self._touches) return self._touches + touches = property(touches) ############################################################ def regexp(self): @@ -62,6 +69,7 @@ class Sub(object): for line in buffer: sub = line.text.split('(',1)[0].split()[1] self._calls.append(sub) + self._calls = make_single(self._calls) return self._calls calls = property(calls) @@ -69,4 +77,4 @@ class Sub(object): if __name__ == '__main__': from preprocessed_text import preprocessed_text from subroutines import subroutines - print subroutines['invert'].calls + print subroutines['brownian_step'].touches diff --git a/src/util.py b/src/util.py index 0b4aa71..f197d5a 100644 --- a/src/util.py +++ b/src/util.py @@ -38,6 +38,12 @@ def find_subname(line): error.fail(line,"Syntax Error") return buffer[-1] +def make_single(l): + d = {} + for x in l: + d[x] = True + return d.keys() + if __name__ == '__main__': print build_dim([]) diff --git a/src/variable.py b/src/variable.py index 9b0cc73..1ad998d 100644 --- a/src/variable.py +++ b/src/variable.py @@ -165,4 +165,5 @@ class Variable(object): if __name__ == '__main__': from preprocessed_text import preprocessed_text from variables import variables - print variables['elec_fitcusp_lapl'].doc + for v in variables.keys(): + print v