<commit_before>'''This module defines all the types needed to maniuplate c++ types used by pythran'''

class weak:pass

def walk_type(obj, cond, op):
    if isinstance(obj,list): return [ walk_type(o, cond, op) for o in obj ]
    elif cond(obj): return op(obj)
    elif isinstance(obj, Type): return type(obj)(*[walk_type(getattr(obj,attr), cond, op) for attr in obj.fields])
    else: return obj

class Type(object):
    """A generic type object, to hold scalars and such"""
    def __init__(self, repr,qualifiers=None):
        self.repr=repr
        self.qualifiers=set(qualifiers) if qualifiers else set()
        self.fields=("repr","qualifiers")

    def generate(self): return self.repr

    def __add__(self, other):
        if self.generate() == other.generate(): return self
        if weak in self.qualifiers and weak not in other.qualifiers: return other
        if weak in other.qualifiers and weak not in self.qualifiers: return self
        return CombinedTypes(self, other)
    def __repr__(self): return self.generate()

class FunctionType(Type):
    def __init__(self, repr,qualifiers=None):
        Type.__init__(self, repr, qualifiers)
    def __add__(self, other):
        if self.generate() == other.generate(): return self
        if isinstance(other, CombinedFunctionTypes) and self in other.types: return other
        return CombinedFunctionTypes([self, other])

class Val(Type):
    """A generic val object, to hold scalars and such"""
    def __init__(self, repr,qualifiers=None):
        Type.__init__(self,repr,qualifiers)
    def __add__(self, other):assert(False)


class CombinedTypes(Type):
    def __init__(self, type0, type1):
        self.type0=type0
        self.type1=type1
        self.qualifiers=type0.qualifiers.union(type1.qualifiers)
        self.fields=("type0", "type1")

    def generate(self):
        return 'decltype(std::declval<{0}>()+std::declval<{1}>())'.format(self.type0.generate(),self.type1.generate())

class ArgumentType(Type):
    """A type to hold function arguments"""
    def __init__(self,num,qualifiers=None):
        self.num=num
        self.qualifiers=set(qualifiers) if qualifiers else set()
        self.fields=("num","qualifiers")

    def generate(self): return "argument_type{0}".format(self.num)

class DeclVal(Type):
    def __init__(self, of):
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("of",)
    def generate(self):
        return 'std::declval<{0}>()'.format(self.of.generate())

class DeclType(Type):
    """Gather the type of a Typed variable"""
    def __init__(self, of):
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("of",)
    def generate(self):
        return 'decltype({0})'.format(self.of.generate())

class ContentType(Type):
    def __init__(self, of):
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("of",)
    def generate(self):
        return 'typename content_of<{0}>::type'.format(self.of.generate())

class ReturnType(Type):
    def __init__(self, call, args):
        self.call=call
        self.args=args
        self.qualifiers=reduce(set.union, [ arg.qualifiers for arg in args ], call.qualifiers)
        self.fields=("call", "args",)
    def generate(self):
        return 'decltype(std::declval<{0}>()({1}))'.format(self.call.generate(), ", ".join("std::declval<{0}>()".format( arg.generate() ) for arg in self.args))

class ElementType(Type):
    def __init__(self, index, of):
        self.index=index
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("index", "of",)
    def generate(self):
        return 'typename std::tuple_element<{0},{1}>::type'.format(self.index, self.of.generate())

class SequenceType(Type):
    def __init__(self, of):
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("of",)
    def generate(self):
        return 'sequence<{0}>'.format(self.of.generate())

class TupleType(Type):
    def __init__(self, ofs):
        self.ofs=ofs
        self.qualifiers=reduce(set.union, [ of.qualifiers for of in ofs ], set())
        self.fields=("ofs",)
    def generate(self):
        return 'std::tuple<{0}>'.format(", ".join(of.generate() for of in self.ofs)) if self.ofs else 'decltype(std::make_tuple())'

class ExpressionType(Type):
    def __init__(self, op, exprs):
        self.op=op
        self.exprs=exprs
        self.qualifiers=reduce(set.union, [ expr.qualifiers for expr in exprs ], set())
        self.fields=("op", "exprs",)
    def generate(self):
        return 'decltype({0})'.format(self.op(*["std::declval<{0}>()".format(expr.generate()) for expr in self.exprs]))
<commit_msg>Fix bug in type aggregation.<commit_after>'''This module defines all the types needed to maniuplate c++ types used by pythran'''

class weak:pass

def walk_type(obj, cond, op):
    if isinstance(obj,list): return [ walk_type(o, cond, op) for o in obj ]
    elif cond(obj): return op(obj)
    elif isinstance(obj, Type): return type(obj)(*[walk_type(getattr(obj,attr), cond, op) for attr in obj.fields])
    else: return obj

class Type(object):
    """A generic type object, to hold scalars and such"""
    def __init__(self, repr,qualifiers=None):
        self.repr=repr
        self.qualifiers=set(qualifiers) if qualifiers else set()
        self.fields=("repr","qualifiers")

    def generate(self): return self.repr

    def __add__(self, other):
        if self.generate() == other.generate(): return self
        if weak in self.qualifiers and weak not in other.qualifiers: return other
        if weak in other.qualifiers and weak not in self.qualifiers: return self
        return CombinedTypes([self, other])
    def __repr__(self): return self.generate()

class Val(Type):
    """A generic val object, to hold scalars and such"""
    def __init__(self, repr,qualifiers=None):
        Type.__init__(self,repr,qualifiers)
    def __add__(self, other):assert(False)


class CombinedTypes(Type):
    def __init__(self, types):
        self.types=types
        self.qualifiers=reduce(set.union, [ t.qualifiers for t in types ], set())
        self.fields=("types",)

    def __add__(self, other):
        if self.generate() == other.generate(): return self
        if other in self.types: return self
        if weak in other.qualifiers and weak not in self.qualifiers: return self
        return CombinedTypes(self.types+[other])

    def generate(self):
        return 'decltype({0})'.format(" + ".join('std::declval<{0}>()'.format(t.generate()) for t in self.types ))

class ArgumentType(Type):
    """A type to hold function arguments"""
    def __init__(self,num,qualifiers=None):
        self.num=num
        self.qualifiers=set(qualifiers) if qualifiers else set()
        self.fields=("num","qualifiers")

    def generate(self): return "argument_type{0}".format(self.num)

class DeclVal(Type):
    def __init__(self, of):
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("of",)
    def generate(self):
        return 'std::declval<{0}>()'.format(self.of.generate())

class DeclType(Type):
    """Gather the type of a Typed variable"""
    def __init__(self, of):
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("of",)
    def generate(self):
        return 'decltype({0})'.format(self.of.generate())

class ContentType(Type):
    def __init__(self, of):
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("of",)
    def generate(self):
        return 'typename content_of<{0}>::type'.format(self.of.generate())

class ReturnType(Type):
    def __init__(self, call, args):
        self.call=call
        self.args=args
        self.qualifiers=reduce(set.union, [ arg.qualifiers for arg in args ], call.qualifiers)
        self.fields=("call", "args",)
    def generate(self):
        return 'decltype(std::declval<{0}>()({1}))'.format(self.call.generate(), ", ".join("std::declval<{0}>()".format( arg.generate() ) for arg in self.args))

class ElementType(Type):
    def __init__(self, index, of):
        self.index=index
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("index", "of",)
    def generate(self):
        return 'typename std::tuple_element<{0},{1}>::type'.format(self.index, self.of.generate())

class SequenceType(Type):
    def __init__(self, of):
        self.of=of
        self.qualifiers=of.qualifiers
        self.fields=("of",)
    def generate(self):
        return 'sequence<{0}>'.format(self.of.generate())

class TupleType(Type):
    def __init__(self, ofs):
        self.ofs=ofs
        self.qualifiers=reduce(set.union, [ of.qualifiers for of in ofs ], set())
        self.fields=("ofs",)
    def generate(self):
        return 'std::tuple<{0}>'.format(", ".join(of.generate() for of in self.ofs)) if self.ofs else 'decltype(std::make_tuple())'

class ExpressionType(Type):
    def __init__(self, op, exprs):
        self.op=op
        self.exprs=exprs
        self.qualifiers=reduce(set.union, [ expr.qualifiers for expr in exprs ], set())
        self.fields=("op", "exprs",)
    def generate(self):
        return 'decltype({0})'.format(self.op(*["std::declval<{0}>()".format(expr.generate()) for expr in self.exprs]))

{'fraction_non_alphanumeric': 0.15071305099394988, 'fraction_numerical': 0.004537597234226448, 'mean_word_length': 3.3317735142723444, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1958243', 'n_tokens_mistral': 2912, 'n_tokens_neox': 2884, 'n_words': 699}