예제 #1
0
    def offset(self):
        """ If this is a constant access (e.g. A(1))
        return the offset in bytes from the beginning of the
        variable in memory.

        Otherwise, if it's not constant (e.g. A(i))
        returns None
        """
        offset = 0
        # Now we must typecast each argument to a u16 (POINTER) type
        # i is the dimension ith index, b is the bound
        for i, b in zip(self.arglist, self.entry.bounds):
            tmp = i.children[0]
            if is_number(tmp) or is_const(tmp):
                if offset is not None:
                    offset = offset * b.count + tmp.value
            else:
                offset = None
                break

        if offset is not None:
            offset = TYPE.size(gl.SIZE_TYPE) + TYPE.size(gl.BOUND_TYPE) * len(
                self.arglist) + offset * self.type_.size

        return offset
예제 #2
0
 def memsize(self):
     """ Total array cell + indexes size
     """
     return 2 * TYPE.size(gl.PTR_TYPE)
예제 #3
0
 def size(self):
     return self.count * self.type_.size if self.scope != SCOPE.parameter else TYPE.size(
         gl.PTR_TYPE)
예제 #4
0
 def test_size(self):
     for type_ in TYPE.types:
         t = SymbolBASICTYPE(type_)
         self.assertEqual(t.size, TYPE.size(type_))
예제 #5
0
 def test_memsize(self):
     arr = symbols.VARARRAY('test', self.bounds, 1, type_=Type.ubyte)
     self.assertEqual(arr.memsize, 2 * TYPE.size(gl.PTR_TYPE))
예제 #6
0
 def memsize(self):
     """ Total array cell + indexes size
     """
     return (2 + (2 if self.lbound_used or self.ubound_used else 0)
             ) * TYPE.size(gl.PTR_TYPE)
예제 #7
0
 def test_memsize(self):
     arr = symbols.VARARRAY('test', self.bounds, 1, type_=Type.ubyte)
     self.assertEqual(
         arr.memsize,
         arr.size + 1 + TYPE.size(gl.BOUND_TYPE) * len(arr.bounds))
예제 #8
0
 def size(self):
     return TYPE.size(self.type_)
예제 #9
0
 def memsize(self):
     """ Total array cell + indexes size
     """
     return self.size + 1 + TYPE.size(gl.BOUND_TYPE) * len(self.bounds)