Beispiel #1
0
    def __rewrite_tristate(self, tree):
        def tristate_not(symbol):
            if symbol in self.rsf.options() and self.rsf.options()[symbol].tristate():
                if self.eval_to_module:
                    return [BoolParser.NEQUAL, symbol, "y"]
                else:
                    return [BoolParser.EQUAL,  symbol, "n"]
            return [BoolParser.NOT, symbol]
        def tristate(symbol):
            if symbol in self.rsf.options() and self.rsf.options()[symbol].tristate():
                if self.eval_to_module:
                    return [BoolParser.NEQUAL, symbol, "n"]
                else:
                    return [BoolParser.EQUAL,  symbol, "y"]
            return symbol

        if tree[0] in [BoolParser.AND, BoolParser.OR]:
            for i in range(1, len(tree)):
                if type(tree[i]) == list:
                    if tree[i][0] == BoolParser.NOT:
                        tree[i] = tristate_not(tree[i][1])
                    else:
                        tree[i] = tree_change(self.__rewrite_tristate, tree[i])
                else:
                    tree[i] = tristate(tree[i])
            return tree
Beispiel #2
0
    def __rewrite_tristate(self, tree):
        def tristate_not(symbol):
            if symbol in self.rsf.options() and self.rsf.options(
            )[symbol].tristate():
                if self.eval_to_module:
                    return [BoolParser.NEQUAL, symbol, "y"]
                else:
                    return [BoolParser.EQUAL, symbol, "n"]
            return [BoolParser.NOT, symbol]

        def tristate(symbol):
            if symbol in self.rsf.options() and self.rsf.options(
            )[symbol].tristate():
                if self.eval_to_module:
                    return [BoolParser.NEQUAL, symbol, "n"]
                else:
                    return [BoolParser.EQUAL, symbol, "y"]
            return symbol

        if tree[0] in [BoolParser.AND, BoolParser.OR]:
            for i in range(1, len(tree)):
                if type(tree[i]) == list:
                    if tree[i][0] == BoolParser.NOT:
                        tree[i] = tristate_not(tree[i][1])
                    else:
                        tree[i] = tree_change(self.__rewrite_tristate, tree[i])
                else:
                    tree[i] = tristate(tree[i])
            return tree
Beispiel #3
0
 def __rewrite_not(self, tree):
     if tree[0] == BoolParser.NOT and type(tree[1]) == list:
         tree = tree[1]
         if tree[0] == BoolParser.AND:
             tree = [BoolParser.OR] + map(lambda x: [BoolParser.NOT, x], tree[1:])
             return tree_change(self.__rewrite_not, tree)
         elif tree[0] == BoolParser.OR:
             tree = [BoolParser.AND] + map(lambda x: [BoolParser.NOT, x], tree[1:])
             return tree_change(self.__rewrite_not, tree)
         elif tree[0] == BoolParser.NOT:
             return tree_change(self.__rewrite_not, tree[1])
         elif tree[0] == BoolParser.EQUAL:
             tree[0] = BoolParser.NEQUAL
             return tree
         elif tree[0] == BoolParser.NEQUAL:
             tree[0] = BoolParser.EQUAL
             return tree
Beispiel #4
0
    def rewrite_choice(self):
        """Removes all CHOICE_ items"""
        def __recr(tree):
            tree = filter(lambda x: not(type(x) == str and x.startswith("CHOICE_")), tree)
            if len(tree) == 1:
                return []
            return tree

        self.expr = tree_change(__recr, self.expr)
        return self.expr
Beispiel #5
0
 def __rewrite_not(self, tree):
     if tree[0] == BoolParser.NOT and type(tree[1]) == list:
         tree = tree[1]
         if tree[0] == BoolParser.AND:
             tree = [BoolParser.OR] + map(lambda x: [BoolParser.NOT, x],
                                          tree[1:])
             return tree_change(self.__rewrite_not, tree)
         elif tree[0] == BoolParser.OR:
             tree = [BoolParser.AND] + map(lambda x: [BoolParser.NOT, x],
                                           tree[1:])
             return tree_change(self.__rewrite_not, tree)
         elif tree[0] == BoolParser.NOT:
             return tree_change(self.__rewrite_not, tree[1])
         elif tree[0] == BoolParser.EQUAL:
             tree[0] = BoolParser.NEQUAL
             return tree
         elif tree[0] == BoolParser.NEQUAL:
             tree[0] = BoolParser.EQUAL
             return tree
Beispiel #6
0
    def rewrite_choice(self):
        """Removes all CHOICE_ items"""
        def __recr(tree):
            tree = filter(
                lambda x: not (type(x) == str and x.startswith("CHOICE_")),
                tree)
            if len(tree) == 1:
                return []
            return tree

        self.expr = tree_change(__recr, self.expr)
        return self.expr
Beispiel #7
0
 def to_symbol(tree):
     if type(tree) in [list, tuple]:
         return tree_change(self.__rewrite_symbol, tree)
     if tree == "m":
         if self.eval_to_module:
             # m is true, if the expression can evaluate to module
             return tools.new_free_item()
         else:
             #otherwise it is false, because expr = y is needed
             a = tools.new_free_item()
             return [BoolParser.AND, a, [BoolParser.NOT, a]]
     return self.rsf.symbol(tree)
    def __rewrite_tristate(self, tree):
        #pylint: disable=R0912

        # Dependencies reduce the upper limit of a symbol (tristate means 3 values: y=2, m=1, n=0).
        # When the dependency of a symbol evaluates to m (=1), the symbol cannot
        # evaluate to y (=2) anymore. Example:
        #
        # config A | tristate | depends on B
        # config B | tristate
        #
        # B=y  -> A=m || A=n || A=y
        # B=m  -> A=m || A=n
        # B=n  -> /
        #
        # config A | tristate | depends on !B
        # config B | tristate
        #
        # B=y  -> /
        # B=m  -> A=m || A=n
        # B=n  -> A=m || A=n || A=y

        def tristate_not(symbol):
            if symbol in self.rsf.options() and self.rsf.options(
            )[symbol].tristate():
                if self.eval_to_module:
                    # when B is a tristate and is allowed to be 'm', !B means (B!=y || B=m).
                    return [
                        BoolParser.OR, [BoolParser.NEQUAL, symbol, "y"],
                        [BoolParser.EQUAL, symbol, "m"]
                    ]
                else:
                    return [BoolParser.EQUAL, symbol, "n"]
            return [BoolParser.NOT, symbol]

        def tristate(symbol):
            if symbol in self.rsf.options() and self.rsf.options(
            )[symbol].tristate():
                if self.eval_to_module:
                    return [BoolParser.NEQUAL, symbol, "n"]
                else:
                    return [BoolParser.EQUAL, symbol, "y"]
            return symbol

        if tree[0] in [BoolParser.AND, BoolParser.OR]:
            for i in range(1, len(tree)):
                if type(tree[i]) == list:
                    if tree[i][0] == BoolParser.NOT:
                        tree[i] = tristate_not(tree[i][1])
                    else:
                        tree[i] = tree_change(self.__rewrite_tristate, tree[i])
                else:
                    tree[i] = tristate(tree[i])
            return tree
Beispiel #9
0
 def to_symbol(tree):
     if type(tree) in [list, tuple]:
         return tree_change(self.__rewrite_symbol, tree)
     if tree == "m":
         if self.eval_to_module:
             # m is true, if the expression can evaluate to module
             return tools.new_free_item()
         else:
             #otherwise it is false, because expr = y is needed
             a = tools.new_free_item()
             return [BoolParser.AND, a,
                     [BoolParser.NOT, a]]
     return self.rsf.symbol(tree)
    def rewrite_choice(self):
        """Removes all CHOICE_ items"""
        def __recr(tree):
            tree = [
                x for x in tree
                if not (type(x) == str and x.startswith("CHOICE_"))
            ]
            if len(tree) == 1:
                return []
            return tree

        self.expr = tree_change(__recr, self.expr)
        return self.expr
Beispiel #11
0
 def rewrite_symbol(self):
     self.expr = tree_change(self.__rewrite_symbol, self.expr)
     return self.expr
Beispiel #12
0
 def rewrite_tristate(self):
     self.expr = tree_change(self.__rewrite_tristate, self.expr)
     return self.expr
Beispiel #13
0
 def rewrite_not(self):
     self.expr = tree_change(self.__rewrite_not, self.expr)
     return self.expr
Beispiel #14
0
 def rewrite_tristate(self):
     self.expr = tree_change(self.__rewrite_tristate, self.expr)
     return self.expr
Beispiel #15
0
 def rewrite_not(self):
     self.expr = tree_change(self.__rewrite_not, self.expr)
     return self.expr
Beispiel #16
0
 def rewrite_symbol(self):
     self.expr = tree_change(self.__rewrite_symbol, self.expr)
     return self.expr