| 4364 | } |
| 4365 | |
| 4366 | void PatchMatrixInitializer( ASTNode* parent, unsigned index, const Type& type ) |
| 4367 | { |
| 4368 | // wrap matrix initializer in a "constructor", i.e. { a, b,..} -> float4x4( { a, b, ..} ) |
| 4369 | auto initializer = parent->GetChild( index ); |
| 4370 | if( type.arrayDimensions > 0 ) |
| 4371 | { |
| 4372 | auto elementType = type; |
| 4373 | --elementType.arrayDimensions; |
| 4374 | |
| 4375 | for( unsigned i = 0; i < initializer->GetChildrenCount(); ++i ) |
| 4376 | { |
| 4377 | PatchMatrixInitializer( initializer, i, elementType ); |
| 4378 | } |
| 4379 | } |
| 4380 | else |
| 4381 | { |
| 4382 | std::vector<ASTNode*> children; |
| 4383 | ExpandInitializerList( initializer, children ); |
| 4384 | |
| 4385 | if( int( children.size() ) == type.width * type.height ) |
| 4386 | { |
| 4387 | initializer->GetChildren().clear(); |
| 4388 | |
| 4389 | for( int row = 0; row < type.height; ++row ) |
| 4390 | { |
| 4391 | auto rowNode = new ASTNode( NT_INLINE_CONSTRUCTOR, initializer->GetLocation(), initializer->GetScope(), nullptr ); |
| 4392 | rowNode->SetType( TypeFromTokenType( OP_FLOAT, type.width ) ); |
| 4393 | for( int col = 0; col < type.width; ++col ) |
| 4394 | { |
| 4395 | rowNode->AddChild( children[row * type.width + col] ); |
| 4396 | } |
| 4397 | initializer->AddChild( rowNode ); |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | ScannerToken token; |
| 4402 | token.type = type.builtInType; |
| 4403 | token.fileLocation = initializer->GetLocation(); |
| 4404 | token.intValue = type.width | ( type.height << 8 ); |
| 4405 | auto constructor = new ASTNode( NT_FUNCTION_CALL, initializer->GetLocation(), initializer->GetScope(), &token ); |
| 4406 | constructor->AddChild( initializer ); |
| 4407 | initializer->SetType( type ); |
| 4408 | constructor->SetType( type ); |
| 4409 | parent->ReplaceChild( index, constructor ); |
| 4410 | } |
| 4411 | } |
| 4412 | |
| 4413 | void PatchMatrixRows( ParserState& state, ASTNode* node, ASTNode* parent = nullptr, bool rvalue = true, ASTNode* assignment = nullptr ) |
| 4414 | { |
no test coverage detected