Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @FunctionalInterface
- public interface OpaqueZeroOneFactory {
- Optional tryMakeOpaque(BasicType type, boolean constContext, final int depth,
- Fuzzer fuzzer, boolean isZero);
- }
- public List<OpaqueZeroOneFactory> waysToMakeZero(){
- List<OpaqueZeroOneFactory> opaqueZeroList = new ArrayList<>();
- opaqueZeroList.add(new SinOne());
- opaqueZeroList.add(new LogarithmOne());
- return opaqueZeroList ;
- }
- public class SinOne implements OpaqueZeroOneFactory{
- @Override
- public Optional tryMakeOpaque(BasicType type, boolean constContext, int depth, Fuzzer fuzzer,
- boolean isZero) {
- if (!isZero) {
- return Optional.empty();
- }
- if (!BasicType.allGenTypes().contains(type)) {
- return Optional.empty();
- }
- return Optional.of(new FunctionCallExpr("sin", makeOpaqueZeroOrOne(true, type, constContext
- ,depth,fuzzer)));
- }
- }
- public class LogarithmOne implements OpaqueZeroOneFactory{
- @Override
- public Optional tryMakeOpaque(BasicType type, boolean constContext, int depth, Fuzzer fuzzer,
- boolean isZero) {
- if (!isZero) {
- return Optional.empty();
- }
- if (!BasicType.allGenTypes().contains(type)) {
- return Optional.empty();
- }
- return Optional.of(new FunctionCallExpr("log", makeOpaqueZeroOrOne(false, type, constContext
- ,depth,fuzzer)));
- }
- }
- private Expr makeOpaqueZeroOrOne(boolean isZero, BasicType type, boolean constContext,
- final int depth, Fuzzer fuzzer) {
- if (isTooDeep(depth)) {
- return makeLiteralZeroOrOne(isZero, type);
- }
- final int newDepth = depth + 1;
- if(isZero){
- List<Optional> availableFunctions = waysToMakeZero()
- .stream()
- .map(item -> item.tryMakeOpaque(type, constContext, newDepth, fuzzer, isZero))
- .filter(Optional::isPresent)
- .collect(Collectors.toList());
- FunctionCallExpr OpaqueZeroFunction = (FunctionCallExpr) availableFunctions
- .get(generator.nextInt(availableFunctions.size()))
- .orElse(makeLiteralZeroOrOne(isZero, type));
- return OpaqueZeroFunction;
- }else{
- //
- // Retrieve a list of opaque one functions
- //
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement