def CombineEqWithoutNewDelta(eq1, eq2): # print("\n\nEq 1: ", eq1, "\n") # print("Eq 2 l: ", eq2.left, "\n\n") # print("Eq 2 r: ", eq2.right, "\n\n") if Type(eq1) == ops.EQ_TST and Type(eq2) == ops.EQ_TST: mul = BinaryNode(ops.MUL) mul.left = BinaryNode.copy(eq1.left) mul.right = BinaryNode.copy(eq2.left) mul2 = BinaryNode(ops.MUL) mul2.left = BinaryNode.copy(eq1.right) mul2.right = BinaryNode.copy(eq2.right) eq1.left = mul eq1.right = mul2 # cie = CombineIntoEq(eq2.left, eq2.right) # ASTVisitor(cie).preorder(eq1) # print("COMBINED: ", eq1, "\n") metadata = {} tech6 = PairInstanceFinderImproved(metadata) ASTVisitor(tech6).preorder(eq1) if tech6.testForApplication(): tech6.makeSubstitution(eq1, SubstitutePairs3) # print("FINAL eq: ", eq1) # sys.exit(0) return eq1
def visit_and(self, node, data): left = BinaryNode("1") right = BinaryNode("1") combined_eq = None marked = False if Type(node.left) == ops.EQ_TST and Type(node.right) == ops.EQ_TST: if getIfEqCountTheSame(node.left) and getIfEqCountTheSame( node.right): print("Next phase: ", node) combined_eq = CombineEqWithoutNewDelta( BinaryNode.copy(node.left), BinaryNode.copy(node.right)) self.attr_index += 1 aei = ApplyEqIndex(self.attr_index) ASTVisitor(aei).preorder(combined_eq) marked = True #else: #print("handle left :=>", node.left, node.left.type) #print("handle right :=>", node.right, node.right.type) if not marked and Type(node.left) == ops.EQ_TST: self.attr_index += 1 pair_eq_index = self.attr_index left = self.visit_equality(node.left, pair_eq_index) if not marked and Type(node.right) == ops.EQ_TST: self.attr_index += 1 pair_eq_index2 = self.attr_index right = self.visit_equality(node.right, pair_eq_index2) if not marked: combined_eq = BinaryNode(ops.EQ_TST, left, right) print("combined_eq first: ", combined_eq) # test whether technique 6 applies, if so, combine? # tech6 = PairInstanceFinder() # ASTVisitor(tech6).preorder(combined_eq) # if tech6.testForApplication(): tech6.makeSubstitution(combined_eq); print("Result: ", combined_eq)# ; exit(-1) # if self.debug: print("Combined eq: ", combined_eq) tech6 = PairInstanceFinderImproved({}) ASTVisitor(tech6).preorder(combined_eq) #print("Instances found: ", tech6.instance) for i in tech6.instance.keys(): key = tech6.instance[i]['key'] data = tech6.instance[i] if self.debug: print("DEBUG: key: ", tech6.instance[i][key], self.settingObj.getSignatureVars(), tech6.instance[i]['pair_index']) if str(data[key]) in self.settingObj.getSignatureVars() and len( data['pair_index']) > 1 and data['instance'] >= 2: # bail on combining pairings since solution will not be correct if self.debug: print("Bailing on applying technique 6.") self.finalAND.append(combined_eq) return if tech6.testForApplication(): tech6.makeSubstitution(combined_eq) print("Result: ", combined_eq) # ; exit(-1) if self.debug: print("Combined eq: ", combined_eq) self.finalAND.append(combined_eq) return
def visit_and(self, node, data): left = BinaryNode("1") right = BinaryNode("1") combined_eq = None marked = False if Type(node.left) == ops.EQ_TST and Type(node.right) == ops.EQ_TST: if getIfEqCountTheSame(node.left) and getIfEqCountTheSame(node.right): print("Next phase: ", node) combined_eq = CombineEqWithoutNewDelta(BinaryNode.copy(node.left), BinaryNode.copy(node.right)) self.attr_index += 1 aei = ApplyEqIndex(self.attr_index) ASTVisitor(aei).preorder(combined_eq) marked = True #else: #print("handle left :=>", node.left, node.left.type) #print("handle right :=>", node.right, node.right.type) if not marked and Type(node.left) == ops.EQ_TST: self.attr_index += 1 pair_eq_index = self.attr_index left = self.visit_equality(node.left, pair_eq_index) if not marked and Type(node.right) == ops.EQ_TST: self.attr_index += 1 pair_eq_index2 = self.attr_index right = self.visit_equality(node.right, pair_eq_index2) if not marked: combined_eq = BinaryNode(ops.EQ_TST, left, right) print("combined_eq first: ", combined_eq) # test whether technique 6 applies, if so, combine? # tech6 = PairInstanceFinder() # ASTVisitor(tech6).preorder(combined_eq) # if tech6.testForApplication(): tech6.makeSubstitution(combined_eq); print("Result: ", combined_eq)# ; exit(-1) # if self.debug: print("Combined eq: ", combined_eq) tech6 = PairInstanceFinderImproved({}) ASTVisitor(tech6).preorder(combined_eq) #print("Instances found: ", tech6.instance) for i in tech6.instance.keys(): key = tech6.instance[i]['key'] data = tech6.instance[i] if self.debug: print("DEBUG: key: ", tech6.instance[i][key], self.settingObj.getSignatureVars(), tech6.instance[i]['pair_index']) if str(data[key]) in self.settingObj.getSignatureVars() and len(data['pair_index']) > 1 and data['instance'] >= 2: # bail on combining pairings since solution will not be correct if self.debug: print("Bailing on applying technique 6.") self.finalAND.append(combined_eq) return if tech6.testForApplication(): tech6.makeSubstitution(combined_eq); print("Result: ", combined_eq)# ; exit(-1) if self.debug: print("Combined eq: ", combined_eq) self.finalAND.append(combined_eq) return