3rdparty/bgfx/3rdparty/glslang/glslang/MachineIndependent/Constant.cpp
//
// Constant folding of a bracket (array-style) dereference or struct-like dot
// dereference.  Can handle anything except a multi-character swizzle, though
// all swizzles may go to foldSwizzle().
//
Constant folding of a bracket (array-style) dereference or struct-like dot
dereference.  Can handle anything except a multi-character swizzle, though
all swizzles may go to foldSwizzle().
Constant folding of a bracket ( array - style ) dereference or struct - like dot dereference . Can handle anything except a multi - character swizzle though all swizzles may go to foldSwizzle () .
TIntermTyped* TIntermediate::foldDereference(TIntermTyped* node, int index, const TSourceLoc& loc)
{
    TType dereferencedType(node->getType(), index);
    dereferencedType.getQualifier().storage = EvqConst;
    TIntermTyped* result = 0;
    int size = dereferencedType.computeNumComponents();
    int start;
    if (node->isArray() || ! node->isStruct())
        start = size * index;
    else {
        assert(node->isStruct());
        start = 0;
        for (int i = 0; i < index; ++i)
            start += (*node->getType().getStruct())[i].type->computeNumComponents();
    }
    result = addConstantUnion(TConstUnionArray(node->getAsConstantUnion()->getConstArray(), start, size), node->getType(), loc);
    if (result == 0)
        result = node;
    else
        result->setType(dereferencedType);
    return result;
}
TIntermTyped * TIntermediate :: foldDereference ( TIntermTyped * node , int index , const TSourceLoc & loc ) { TType dereferencedType ( node -> getType ( ) , index ) ; dereferencedType . getQualifier ( ) . storage = EvqConst ; TIntermTyped * result = 0 ; int size = dereferencedType . computeNumComponents ( ) ; int start ; if ( node -> isArray ( ) || ! node -> isStruct ( ) ) start = size * index ; else { assert ( node -> isStruct ( ) ) ; start = 0 ; for ( int i = 0 ; i < index ; ++ i ) start += ( * node -> getType ( ) . getStruct ( ) ) [ i ] . type -> computeNumComponents ( ) ; } result = addConstantUnion ( TConstUnionArray ( node -> getAsConstantUnion ( ) -> getConstArray ( ) , start , size ) , node -> getType ( ) , loc ) ; if ( result == 0 ) result = node ; else result -> setType ( dereferencedType ) ; return result ; }
Constant folding of a bracket (array-style) dereference or struct-like dot
dereference.
Constant folding of a bracket ( array - style ) dereference or struct - like dot dereference .
// arrays, vectors, matrices, all use simple multiplicative math // while structures need to add up heterogeneous members // it is a structure