def add(self, type_, node): ''' Add a node of a given type. ''' try: node_type = matcher_type(node) except MatcherTypeException: node_type = type(node) if type_ & LEAF: self.leaves += 1 if type_ & NONTREE and is_child(node_type, Matcher, fail=False): self.loops += 1 try: if node not in self.__known: self.__known.add(node) if node_type not in self.types: self.types[node_type] = set() self.types[node_type].add(node) if is_child(node_type, Matcher): self.total += 1 else: self.others += 1 else: self.duplicates += 1 except: self.unhashable += 1
def new_clone(node, old_args, kargs): ''' The flattening cloner. ''' new_args = [] type_ = matcher_type(node, fail=False) if type_ in map(canonical_matcher_type, [And, Or]): for arg in old_args: if matcher_type(arg, fail=False) is type_ and \ ((not arg.wrapper and not node.wrapper) or \ (arg.wrapper.functions == node.wrapper.functions and node.wrapper.functions == [add])): new_args.extend(arg.matchers) else: new_args.append(arg) if not new_args: new_args = old_args return clone(node, new_args, kargs)
def new_clone(i, j, node, old_args, kargs): ''' The flattening cloner. ''' new_args = [] type_ = matcher_type(node, fail=False) if type_ in map(canonical_matcher_type, [And, Or]): for arg in old_args: if matcher_type(arg, fail=False) is type_ and \ (not hasattr(arg, 'wrapper') or ((not arg.wrapper and not node.wrapper) or \ (arg.wrapper.functions == node.wrapper.functions and node.wrapper.functions == [add]))): new_args.extend(arg.matchers) else: new_args.append(arg) if not new_args: new_args = old_args return clone(i, j, node, new_args, kargs)
def new_clone(node, old_args, kargs): ''' The flattening cloner. ''' table = matcher_map({And: '*matchers', Or: '*matchers'}) new_args = [] type_ = matcher_type(node, fail=False) if type_ in table: attribute_name = table[type_] for arg in old_args: if matcher_type(arg, fail=False) is type_ \ and not arg.wrapper \ and not node.wrapper: if attribute_name.startswith('*'): new_args.extend(getattr(arg, attribute_name[1:])) else: new_args.append(getattr(arg, attribute_name)) else: new_args.append(arg) if not new_args: new_args = old_args return clone(node, new_args, kargs)