Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. @FunctionalInterface
  2. public interface OpaqueZeroOneFactory {
  3. Optional tryMakeOpaque(BasicType type, boolean constContext, final int depth,
  4. Fuzzer fuzzer, boolean isZero);
  5. }
  6.  
  7. public List<OpaqueZeroOneFactory> waysToMakeZero(){
  8. List<OpaqueZeroOneFactory> opaqueZeroList = new ArrayList<>();
  9. opaqueZeroList.add(new SinOne());
  10. opaqueZeroList.add(new LogarithmOne());
  11. return opaqueZeroList ;
  12. }
  13.  
  14. public class SinOne implements OpaqueZeroOneFactory{
  15.  
  16. @Override
  17. public Optional tryMakeOpaque(BasicType type, boolean constContext, int depth, Fuzzer fuzzer,
  18. boolean isZero) {
  19. if (!isZero) {
  20. return Optional.empty();
  21. }
  22. if (!BasicType.allGenTypes().contains(type)) {
  23. return Optional.empty();
  24. }
  25. return Optional.of(new FunctionCallExpr("sin", makeOpaqueZeroOrOne(true, type, constContext
  26. ,depth,fuzzer)));
  27. }
  28. }
  29.  
  30. public class LogarithmOne implements OpaqueZeroOneFactory{
  31. @Override
  32. public Optional tryMakeOpaque(BasicType type, boolean constContext, int depth, Fuzzer fuzzer,
  33. boolean isZero) {
  34. if (!isZero) {
  35. return Optional.empty();
  36. }
  37. if (!BasicType.allGenTypes().contains(type)) {
  38. return Optional.empty();
  39. }
  40. return Optional.of(new FunctionCallExpr("log", makeOpaqueZeroOrOne(false, type, constContext
  41. ,depth,fuzzer)));
  42. }
  43. }
  44.  
  45. private Expr makeOpaqueZeroOrOne(boolean isZero, BasicType type, boolean constContext,
  46. final int depth, Fuzzer fuzzer) {
  47.  
  48. if (isTooDeep(depth)) {
  49. return makeLiteralZeroOrOne(isZero, type);
  50. }
  51. final int newDepth = depth + 1;
  52.  
  53. if(isZero){
  54. List<Optional> availableFunctions = waysToMakeZero()
  55. .stream()
  56. .map(item -> item.tryMakeOpaque(type, constContext, newDepth, fuzzer, isZero))
  57. .filter(Optional::isPresent)
  58. .collect(Collectors.toList());
  59.  
  60. FunctionCallExpr OpaqueZeroFunction = (FunctionCallExpr) availableFunctions
  61. .get(generator.nextInt(availableFunctions.size()))
  62. .orElse(makeLiteralZeroOrOne(isZero, type));
  63. return OpaqueZeroFunction;
  64. }else{
  65. //
  66. // Retrieve a list of opaque one functions
  67. //
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement