private Type getType(Type baseType, ArrayInfo arrayInfo) { if (arrayInfo == null) { return baseType; } return new ArrayType(baseType, arrayInfo); }
@Override public ArrayType clone() { return new ArrayType(baseType.clone(), arrayInfo.clone()); }
private static Initializer makeInitializer(BasicType baseType, ArrayInfo arrayInfo, List<Number> args) { if (arrayInfo != null) { assert arrayInfo.getSize() * baseType.getNumElements() == args.size(); List<Expr> argExprs = new ArrayList<>(); for (int index = 0; index < arrayInfo.getSize(); index++) { argExprs.add(getBasicTypeLiteralExpr(baseType, args.subList(index * baseType.getNumElements(), (index + 1) * baseType.getNumElements()))); } return new ScalarInitializer(new ArrayConstructorExpr( new ArrayType(baseType.getWithoutQualifiers(), arrayInfo.clone()), argExprs)); } return new ScalarInitializer(getBasicTypeLiteralExpr(baseType, args)); }
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 visitFunctionPrototype(FunctionPrototype functionPrototype) { encounteredFunctionPrototypes.add(functionPrototype); for (ParameterDecl p : functionPrototype.getParameters()) { visitParameterDecl(p); if (addEncounteredParametersToScope) { if (p.getName() == null) { continue; } currentScope.add(p.getName(), p.getArrayInfo() == null ? p.getType() : new ArrayType(p.getType(), p.getArrayInfo()), Optional.of(p)); } } }
@Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { visit(variablesDeclaration.getBaseType()); List<VariableDeclInfo> children = new ArrayList<>(); children.addAll(variablesDeclaration.getDeclInfos()); for (VariableDeclInfo declInfo : children) { visitVariableDeclInfo(declInfo); currentScope.add(declInfo.getName(), declInfo.getArrayInfo() == null ? variablesDeclaration.getBaseType() : new ArrayType(variablesDeclaration.getBaseType(), declInfo.getArrayInfo()), Optional.empty(), declInfo, variablesDeclaration); visitVariableDeclInfoAfterAddedToScope(declInfo); } }
private Pair<List<String>, List<Type>> getMembers(Member_listContext memberListContext) { final LinkedList<String> fieldNames = new LinkedList<>(); final LinkedList<Type> fieldTypes = new LinkedList<>(); for (Member_listContext ctx = memberListContext; ctx != null; ctx = ctx.member_list()) { final Type baseType = visitFully_specified_type(ctx.member_declaration().fully_specified_type()); for (Struct_declarator_listContext declarators = ctx.member_declaration() .struct_declarator_list(); declarators != null; declarators = declarators.struct_declarator_list()) { fieldNames.addFirst(declarators.struct_declarator().IDENTIFIER().getText()); if (declarators.struct_declarator().array_specifier() == null) { fieldTypes.addFirst(baseType); } else { fieldTypes.addFirst(new ArrayType(baseType, getArrayInfo(declarators.struct_declarator().array_specifier()))); } } } return new Pair<>(fieldNames, fieldTypes); }
if (header.array_specifier() != null) { return new ArrayConstructorExpr( new ArrayType( getBuiltinType(header.function_identifier().builtin_type_specifier_nonarray()), getArrayInfo(header.array_specifier())), params); header.function_identifier().variable_identifier().getText()); return new ArrayConstructorExpr( new ArrayType(structType, getArrayInfo(header.array_specifier())), params);