@Override public ArrayIndexExpr clone() { return new ArrayIndexExpr(array.clone(), index.clone()); }
@Override public void visitArrayIndexExpr(ArrayIndexExpr arrayIndexExpr) { Type type = typer.lookupType(arrayIndexExpr.getArray()); if (type == null) { return; } type = type.getWithoutQualifiers(); assert isArrayVectorOrMatrix(type); if (!staticallyInBounds(arrayIndexExpr.getIndex(), type)) { arrayIndexExpr.setIndex(new TernaryExpr( new BinaryExpr( new BinaryExpr( new ParenExpr(arrayIndexExpr.getIndex().clone()), new IntConstantExpr("0"), BinOp.GE), new BinaryExpr( new ParenExpr(arrayIndexExpr.getIndex().clone()), new IntConstantExpr(getSize(type).toString()), BinOp.LT), BinOp.LAND), arrayIndexExpr.getIndex(), new IntConstantExpr("0")) ); } super.visitArrayIndexExpr(arrayIndexExpr); }
@Override public void visitArrayIndexExpr(ArrayIndexExpr arrayIndexExpr) { super.visitArrayIndexExpr(arrayIndexExpr); Type arrayType = lookupType(arrayIndexExpr.getArray()); if (arrayType == null) { return; } arrayType = arrayType.getWithoutQualifiers(); Type elementType; if (BasicType.allVectorTypes().contains(arrayType)) { elementType = ((BasicType) arrayType).getElementType(); } else if (BasicType.allMatrixTypes().contains(arrayType)) { elementType = ((BasicType) arrayType).getColumnType(); } else { assert arrayType instanceof ArrayType; elementType = ((ArrayType) arrayType).getBaseType(); } types.put(arrayIndexExpr, elementType); }
@Override public void visitFloatConstantExpr(FloatConstantExpr floatConstantExpr) { if (!literalToUniformIndex.containsKey(floatConstantExpr.getValue())) { literalToUniformIndex.put(floatConstantExpr.getValue(), uniformIndex); uniformIndex++; } parentMap.getParent(floatConstantExpr).replaceChild(floatConstantExpr, new ArrayIndexExpr(new VariableIdentifierExpr(Constants.FLOAT_CONST), new IntConstantExpr(Integer.toString( literalToUniformIndex.get(floatConstantExpr.getValue()))))); }
@Override public Expr generateExpr(IRandom generator, Expr... args) { assert args.length == getNumArguments(); int index; if (BasicType.allVectorTypes().contains(argType)) { index = generator.nextInt(argType.getNumElements()); } else { assert BasicType.allMatrixTypes().contains(argType); index = generator.nextInt(BasicType.numColumns(argType)); } return new ArrayIndexExpr(args[0], new IntConstantExpr(String.valueOf(index))); }
false, true, depth)); Expr index = type.isVector() ? new ArrayIndexExpr( new ParenExpr(expr).clone(), new IntConstantExpr(new Integer(i).toString())) : expr.clone();
@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; }