Example #1
0
 @NotNull
 public GLSLQualifiedType getQualifiedType() {
   final GLSLType type = getType();
   final GLSLDeclaration declaration = getParentDeclaration();
   if (declaration == null || declaration.getQualifierList() == null)
     return new GLSLQualifiedType(type);
   return new GLSLQualifiedType(type, declaration.getQualifierList().getQualifiers());
 }
Example #2
0
  @NotNull
  public GLSLType getType() {
    GLSLDeclaration declaration = getParentDeclaration();
    if (declaration == null) return GLSLTypes.UNKNOWN_TYPE;
    GLSLTypeSpecifier declarationType = declaration.getTypeSpecifierNode();
    if (declarationType == null) return GLSLTypes.UNKNOWN_TYPE;

    GLSLType declaredType = declarationType.getType();
    if (!declaredType.isValidType()) return GLSLTypes.UNKNOWN_TYPE;

    GLSLArraySpecifier[] arraySpecifiers = findChildrenByClass(GLSLArraySpecifier.class);
    if (arraySpecifiers.length == 0) {
      return clarifyArrayType(declaredType);
    } else {
      // Must _prepend_ some dimensions to the type
      // In: "vec4[2][4] b[3]" b is "vec4[3][2][4]", not "vec4[2][4][3]"
      if (declaredType instanceof GLSLArrayType) {
        // Already an array, must append the dimensions
        GLSLArrayType declaredArrayType = (GLSLArrayType) declaredType;
        int[] existingDimensions = declaredArrayType.getDimensions();
        int[] combinedDimensions = new int[existingDimensions.length + arraySpecifiers.length];
        System.arraycopy(
            existingDimensions,
            0,
            combinedDimensions,
            arraySpecifiers.length,
            existingDimensions.length);
        for (int i = 0; i < arraySpecifiers.length; i++) {
          combinedDimensions[i] = arraySpecifiers[i].getDimensionSize();
        }
        return clarifyArrayType(
            new GLSLArrayType(declaredArrayType.getBaseType(), combinedDimensions));
      } else {
        int[] dimensions = new int[arraySpecifiers.length];
        for (int i = 0; i < dimensions.length; i++) {
          dimensions[i] = arraySpecifiers[i].getDimensionSize();
        }
        return clarifyArrayType(new GLSLArrayType(declaredType, dimensions));
      }
    }
  }