Beispiel #1
0
def _parseTypeSuffix(s):
    if s is None:
        return IntType(True, 2)
    sign = s[0].lower() == 's'
    s = s[1:]
    if len(s) > 0:
        width = int(s) // 8
    else:
        width = 2
    return IntType(sign, width)
Beispiel #2
0
 def sizeof_type(self, t):
     if self._transformCast:
         type = t.children[0]
         return _const(Position.fromAny(t), IntType(False, 2),
                       type.getReserveSize())
     else:
         return t
Beispiel #3
0
 def char(self, t):
     l = Position.fromAny(t)
     try:
         value = str(t.children[0])
         return _const(l, IntType(False, 1),
                       ord(unescapeString(value, "'", False)[0]))
     except ValueError as e:
         raise exceptions.LiteralError(l, str(e))
Beispiel #4
0
 def lnot(self, tree):
     a = tree.children[0]
     if isinstance(a, Tree):
         return tree
     elif not a.isConstNumber():
         return tree
     else:
         return _const(Position.fromAny(tree), IntType(False, 1),
                       1 if a.getSource() == 0 else 0)
Beispiel #5
0
 def land(self, tree):
     a, b = tree.children
     if isinstance(a, Tree) or isinstance(b, Tree):
         return tree
     elif a.isConstNumber():
         if bool(a.getSource()):
             return b
         else:
             return _const(Position.fromAny(tree), IntType(False, 1), 0)
     else:
         return tree
Beispiel #6
0
 def sizeof_expr(self, t):
     child = t.children[0]
     if isinstance(child, Tree):
         try:
             type = TypeofTransformer().transform(child)
         except VisitError as e:
             raise e.orig_exc
     else:
         type = child.getType()
     return _const(Position.fromAny(t), IntType(False, 2),
                   type.getReserveSize())
Beispiel #7
0
 def ne(self, tree):
     return binary(tree, operator.ne, IntType(False, 1))
Beispiel #8
0
 def eq(self, tree):
     return binary(tree, operator.eq, IntType(False, 1))
Beispiel #9
0
 def gt(self, tree):
     return binary(tree, operator.gt, IntType(False, 1))