def is_integer(*p): try: return all(i.is_basic and Type.is_integral(i.type_) for i in p) except Exception: pass return False
def common_type(a, b): """ Returns a type which is common for both a and b types. Returns None if no common types allowed. """ if a is None or b is None: return None if not isinstance(a, symbols.TYPE): a = a.type_ if not isinstance(b, symbols.TYPE): b = b.type_ if a == b: # Both types are the same? return a # Returns it if a == Type.unknown and b == Type.unknown: return symbols.BASICTYPE(global_.DEFAULT_TYPE) if a == Type.unknown: return b if b == Type.unknown: return a # TODO: This will removed / expanded in the future assert a.is_basic assert b.is_basic types = (a, b) if Type.float_ in types: return Type.float_ if Type.fixed in types: return Type.fixed if Type.string in types: # TODO: Check this ?? return Type.unknown result = a if a.size > b.size else b if not Type.is_unsigned(a) or not Type.is_unsigned(b): result = Type.to_signed(result) return result
def is_numeric(*p): """ Returns false unless all elements in p are of numerical type """ try: return all(i.type_.is_basic and Type.is_numeric(i.type_) for i in p) except Exception: pass return False
def is_signed(*p): """ Returns false unless all types in p are signed """ try: return all(i.type_.is_basic and Type.is_signed(i.type_) for i in p) except Exception: pass return False