diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2006-10-20 06:43:31 +0000 |
---|---|---|
committer | Pearu Peterson <pearu.peterson@gmail.com> | 2006-10-20 06:43:31 +0000 |
commit | b489d3b282fd7e2ebebbf316d31b2c66a5e62389 (patch) | |
tree | 1e00703a784d7dd5a172f5b80a8fb103f547aa13 /numpy/f2py/lib/parser/base_classes.py | |
parent | d4b47b7573c6d3d21cac7e97a0aee306d15b8d1b (diff) | |
download | numpy-b489d3b282fd7e2ebebbf316d31b2c66a5e62389.tar.gz |
F2PY G3: started impl array support and expression parser.
Diffstat (limited to 'numpy/f2py/lib/parser/base_classes.py')
-rw-r--r-- | numpy/f2py/lib/parser/base_classes.py | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/numpy/f2py/lib/parser/base_classes.py b/numpy/f2py/lib/parser/base_classes.py index ebce02108..b7d00dfe5 100644 --- a/numpy/f2py/lib/parser/base_classes.py +++ b/numpy/f2py/lib/parser/base_classes.py @@ -120,6 +120,11 @@ class Variable: self.bind = [] self.check = [] self.init = None + + # after calling analyze the following additional attributes are set: + # .is_array: + # rank + # shape return def __repr__(self): @@ -339,7 +344,7 @@ class Variable: s += ', ' + ', '.join(a) + ' :: ' s += self.name if self.bounds: - s += '(%s)' % (', '.join(self.bounds)) + s += '(%s)' % (', '.join([':'.join(spec) for spec in self.bounds])) if self.length: if is_int_literal_constant(self.length): s += '*%s' % (self.length) @@ -349,8 +354,59 @@ class Variable: s += ' = ' + self.init return s + def get_array_spec(self): + assert self.is_array(),'array_spec is available only for arrays' + if self.bounds: + if self.dimension: + self.parent.warning('both bounds=%r and dimension=%r are defined, ignoring dimension.' % (self.bounds, self.dimension)) + array_spec = self.bounds + else: + array_spec = self.dimension + return array_spec + + def is_deferred_shape_array(self): + if not self.is_array(): return False + return self.is_allocatable() or self.is_pointer(): + + def is_assumed_size_array(self): + if not self.is_array(): return False + return self.get_array_spec()[-1][-1]=='*' + + def is_assumed_shape_array(self): + if not self.is_array(): return False + if self.is_deferred_shape_array(): return False + for spec in self.get_array_spec(): + if not spec[-1]: return True + return False + + def is_explicit_shape_array(self): + if not self.is_array(): return False + if self.is_deferred_shape_array(): return False + for spec in self.get_array_spec(): + if not spec[-1] or spec[-1] == '*': return False + return True + + def is_allocatable_array(self): + return self.is_array() and self.is_allocatable() + + def is_array_pointer(self): + return self.is_array() and self.is_pointer() + def analyze(self): typedecl = self.get_typedecl() + if self.is_array(): + array_spec = self.get_array_spec() + self.rank = len(array_spec) + if self.is_deferred_shape_array(): # a(:,:) + pass + elif self.is_explict_shape_array(self): + shape = [] + for spec in array_spec: + if len(spec)==1: + shape.append(spec[0]) + else: + shape.append(spec[1]-spec[0]) + self.shape = shape return class ProgramBlock: |