@Override public void visitArrayConstructorExpr(ArrayConstructorExpr arrayConstructorExpr) { visit(arrayConstructorExpr.getArrayType()); out.append("[" + arrayConstructorExpr.getArrayType().getArrayInfo().getSize() + "]("); boolean first = true; for (Expr e : arrayConstructorExpr.getArgs()) { if (!first) { out.append(", "); } first = false; visit(e); } out.append(")"); }
private static Integer getSize(Type type) { assert isArrayVectorOrMatrix(type); if (type instanceof ArrayType) { return ((ArrayType) type).getArrayInfo().getSize(); } if (BasicType.allVectorTypes().contains(type)) { return ((BasicType) type).getNumElements(); } return ((BasicType) type).getNumColumns(); }
private void processArrayInfo(Type type) { if (!(type.getWithoutQualifiers() instanceof ArrayType)) { return; } ArrayType arrayType = (ArrayType) type.getWithoutQualifiers(); while (true) { out.append("[" + (arrayType.getArrayInfo().hasSize() ? arrayType.getArrayInfo().getSize() : "") + "]"); if (!(arrayType.getBaseType().getWithoutQualifiers() instanceof ArrayType)) { break; } arrayType = (ArrayType) arrayType.getBaseType().getWithoutQualifiers(); } }
Type dropQualifiersThatCannotBeUsedForLocalVariable(Type type) { if (type instanceof ArrayType) { return new ArrayType( dropQualifiersThatCannotBeUsedForLocalVariable(((ArrayType) type).getBaseType()), ((ArrayType) type).getArrayInfo()); } if (!(type instanceof QualifiedType)) { return type; } List<TypeQualifier> newQualifiers = new ArrayList<>(); for (TypeQualifier q : ((QualifiedType) type).getQualifiers()) { if (Arrays.asList( TypeQualifier.IN_PARAM, TypeQualifier.INOUT_PARAM, TypeQualifier.OUT_PARAM, TypeQualifier.UNIFORM, TypeQualifier.SHADER_INPUT, TypeQualifier.SHADER_OUTPUT).contains(q)) { continue; } // Many of the other qualifiers are probably not allowed; move them up as we discover this newQualifiers.add(q); } return new QualifiedType(((QualifiedType) type).getTargetType(), newQualifiers); }
private Type stripQualifiers(Type type) { // TODO: when implementing this the only compound type I considered was ArrayType. if (type instanceof QualifiedType) { return stripQualifiers(type.getWithoutQualifiers()); } if (type instanceof ArrayType) { return new ArrayType(stripQualifiers(((ArrayType) type).getBaseType()), ((ArrayType) type).getArrayInfo()); } return type; }
@Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { final Type baseType = variablesDeclaration.getBaseType(); visit(baseType); out.append(" "); boolean first = true; for (VariableDeclInfo vdi : variablesDeclaration.getDeclInfos()) { if (!first) { out.append(", "); } first = false; out.append(vdi.getName()); if (vdi.hasArrayInfo()) { out.append("[" + vdi.getArrayInfo().getSize() + "]"); assert !(baseType instanceof ArrayType); } else if (baseType instanceof ArrayType) { out.append("[" + ((ArrayType) baseType).getArrayInfo().getSize() + "]"); } if (vdi.hasInitializer()) { out.append(" = "); visit(vdi.getInitializer()); } } }
ArrayType arrayType = (ArrayType) targetType; List<Expr> args = new ArrayList<>(); for (int i = 0; i < arrayType.getArrayInfo().getSize(); i++) { args.add(makeExpr(arrayType.getBaseType(), isLValue, constContext, depth + 1));