private Optional<Integer> maybeGetArrayCount(VariableDeclInfo vdi) { if (vdi.hasArrayInfo()) { return Optional.of(vdi.getArrayInfo().getSize()); } return Optional.empty(); }
private boolean incompatibleComponentVariableIsDeclaredInBlock() { final BasicType expectedType = getComponentType(); for (VariablesDeclaration variablesDeclaration : block.getStmts() .stream() .filter(item -> item instanceof DeclarationStmt) .map(item -> (DeclarationStmt) item) .map(item -> item.getVariablesDeclaration()) .collect(Collectors.toList())) { final Type actualType = variablesDeclaration.getBaseType().getWithoutQualifiers(); for (VariableDeclInfo vdi : variablesDeclaration.getDeclInfos() .stream() .filter(item -> item.getName().equals(getComponentName())) .collect(Collectors.toList())) { if (actualType != expectedType || vdi.hasArrayInfo()) { return true; } } } return false; }
public StructificationOpportunity(DeclarationStmt declToTransform, BlockStmt block, TranslationUnit tu, ShadingLanguageVersion shadingLanguageVersion) { assert declToTransform.getVariablesDeclaration().getNumDecls() == 1 : "Only solo declarations can be structified"; assert !declToTransform.getVariablesDeclaration().getDeclInfo(0).hasArrayInfo() : "Structification of arrays not supported"; this.declToTransform = declToTransform; this.block = block; this.tu = tu; this.shadingLanguageVersion = shadingLanguageVersion; }
@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()); } } }
@Override public void visitVariableDeclInfo(VariableDeclInfo variableDeclInfo) { if (variableDeclInfo.hasArrayInfo()) { visitChildFromParent(this::visitArrayInfo, variableDeclInfo.getArrayInfo(), variableDeclInfo); } if (variableDeclInfo.hasInitializer()) { visitChildFromParent(variableDeclInfo.getInitializer(), variableDeclInfo); } }
if (vdi.hasArrayInfo()) { arrayLength = vdi.getArrayInfo().getSize(); } else {
if (declInfo.hasArrayInfo()) { return Optional.empty();
@Override public void visitDeclarationStmt(DeclarationStmt declarationStmt) { super.visitDeclarationStmt(declarationStmt); // Currently we only structify solo declarations if (declarationStmt.getVariablesDeclaration().getNumDecls() != 1) { return; } // We don't currently structify arrays if (declarationStmt.getVariablesDeclaration().getDeclInfo(0).hasArrayInfo()) { return; } final Type baseType = declarationStmt.getVariablesDeclaration().getBaseType(); if (hasQualifiers(baseType)) { return; } // TODO: For simplicity, at present we do not structify non-basic types. The issue is that // if a struct S is to be structified, we need to declare the structs that enclose S *after* // S is declared, which is a bit fiddly (currently they all go at the top of the translation // unit). if (!(baseType.getWithoutQualifiers() instanceof BasicType)) { return; } opportunities.add(new StructificationOpportunity(declarationStmt, currentBlock(), tu, shadingLanguageVersion)); }
assert !variablesDeclaration.getDeclInfo(0).hasArrayInfo(); final String uniformName = variablesDeclaration.getDeclInfo(0).getName(); assert uniformsInfo.containsKey(uniformName);