@Override public MemberLookupExpr clone() { return new MemberLookupExpr(structure.clone(), member); }
private BinaryExpr compareWithGlFragCoord(boolean value, boolean constContext, Fuzzer fuzzer, int newDepth, String coord) { return new BinaryExpr( new MemberLookupExpr(new VariableIdentifierExpr(OpenGlConstants.GL_FRAG_COORD), coord), makeOpaqueZero(BasicType.FLOAT, constContext, newDepth, fuzzer), value ? BinOp.GE : BinOp.LT); }
private Expr injectionSwitch(String dimension) { assert generationParams.getInjectionSwitchIsAvailable(); return new MemberLookupExpr(new VariableIdentifierExpr(Constants.INJECTION_SWITCH), dimension); }
private Expr insertFieldIntoStruct(String enclosingStructName, StructDefinitionType enclosingStruct, IRandom generator) { Expr result = new VariableIdentifierExpr(enclosingStructName); StructDefinitionType currentStruct = enclosingStruct; while (true) { Map<String, StructDefinitionType> structFields = getStructFields(currentStruct); if (!structFields.keySet().isEmpty() && generator.nextBoolean()) { String fieldName = structFields.keySet().stream().collect(Collectors.toList()) .get(generator.nextInt(structFields.size())); result = new MemberLookupExpr(result, fieldName); currentStruct = structFields.get(fieldName); } else { // Choose random position at which to insert the field. currentStruct.insertField(generator.nextInt(currentStruct.getNumFields() + 1), declToTransform.getVariablesDeclaration().getDeclInfo(0).getName(), declToTransform.getVariablesDeclaration().getBaseType()); result = new MemberLookupExpr(result, declToTransform.getVariablesDeclaration() .getDeclInfo(0).getName()); return result; } } }
@Override public void visitDeclarationStmt(DeclarationStmt declarationStmt) { List<String> existingKeys = new ArrayList<>(); existingKeys.addAll(currentScope.keys()); super.visitDeclarationStmt(declarationStmt); List<String> newKeys = currentScope.keys().stream().filter(key -> !existingKeys.contains(key)) .collect(Collectors.toList()); newKeys.sort(String::compareTo); for (String newKey : newKeys) { if (isCurrentComponentVariable(newKey)) { final ExprStmt insertedStmt = new ExprStmt( new BinaryExpr( new MemberLookupExpr( new VariableIdentifierExpr(mergeSet.getMergedName()), getSwizzle(newKey)), new VariableIdentifierExpr(newKey), BinOp.ASSIGN )); assert parentMap.getParent(declarationStmt) instanceof BlockStmt; ((BlockStmt) parentMap.getParent(declarationStmt)).insertAfter(declarationStmt, insertedStmt); } } } }
@Override public Expr generateExpr(IRandom generator, Expr... args) { assert args.length == getNumArguments(); String[] mapping = chooseVectorComponentNamingScheme(generator); String swizzleIndices = ""; int nextComponent = 0; while (nextComponent < resultType.getNumElements()) { String candidate = mapping[generator.nextInt(argType.getNumElements())]; if (isLValue() && swizzleIndices.contains(candidate)) { continue; } swizzleIndices += candidate; nextComponent++; } return new MemberLookupExpr(args[0], swizzleIndices); }
@Override public void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr) { super.visitVariableIdentifierExpr(variableIdentifierExpr); if (isCurrentComponentVariable(variableIdentifierExpr.getName()) && !inDeclarationOfTargetVariable) { parentMap.getParent(variableIdentifierExpr).replaceChild( variableIdentifierExpr, new MemberLookupExpr(new VariableIdentifierExpr(mergeSet.getMergedName()), getSwizzle(variableIdentifierExpr.getName()))); } }
@Override public Expr visitPostfix_expression(Postfix_expressionContext ctx) { if (ctx.primary_expression() != null) { return visitPrimary_expression(ctx.primary_expression()); } if (ctx.LBRACKET() != null) { return new ArrayIndexExpr(visitPostfix_expression(ctx.postfix_expression()), visitExpression(ctx.integer_expression().expression())); } if (ctx.method_call_generic() != null) { // TODO: check grammar throw new RuntimeException("Not yet supported: " + getOriginalSourceText(ctx)); } if (ctx.IDENTIFIER() != null) { return new MemberLookupExpr(visitPostfix_expression(ctx.postfix_expression()), ctx.IDENTIFIER().getText()); } if (ctx.INC_OP() != null) { return new UnaryExpr(visitPostfix_expression(ctx.postfix_expression()), UnOp.POST_INC); } if (ctx.DEC_OP() != null) { return new UnaryExpr(visitPostfix_expression(ctx.postfix_expression()), UnOp.POST_DEC); } assert ctx.function_call_generic() != null; Expr result = visitFunction_call_generic(ctx.function_call_generic()); assert result != null; return result; }