| 4411 | } |
| 4412 | |
| 4413 | void PatchMatrixRows( ParserState& state, ASTNode* node, ASTNode* parent = nullptr, bool rvalue = true, ASTNode* assignment = nullptr ) |
| 4414 | { |
| 4415 | if( node->GetNodeType() == NT_NAME_DECLARATION && node->GetType().IsMatrix() && node->GetChildOrNull( 1 ) && node->GetChild( 1 )->GetNodeType() == NT_INLINE_CONSTRUCTOR ) |
| 4416 | { |
| 4417 | PatchMatrixInitializer( node, 1, node->GetType() ); |
| 4418 | } |
| 4419 | |
| 4420 | if( node->GetNodeType() == NT_FUNCTION_CALL && node->GetSymbol() == nullptr && node->GetType().IsMatrix() ) |
| 4421 | { |
| 4422 | // transpose matrix constructors |
| 4423 | auto copy = node->Copy(); |
| 4424 | auto transpose = ScannerToken::ID( MakeInlineString( "transpose" ), node->GetLocation() ); |
| 4425 | node->SetToken( &transpose ); |
| 4426 | node->GetChildren().clear(); |
| 4427 | node->AddChild( copy ); |
| 4428 | |
| 4429 | std::string diagnosticMessage; |
| 4430 | Symbol* symbol = state.GetSymbolTable().LookupFunction( transpose.stringValue, node, diagnosticMessage ); |
| 4431 | assert( symbol ); |
| 4432 | node->SetSymbol( symbol ); |
| 4433 | |
| 4434 | if( symbol->intrinsicType ) |
| 4435 | { |
| 4436 | node->SetType( ( *symbol->intrinsicType )( node, -1 ) ); |
| 4437 | } |
| 4438 | else |
| 4439 | { |
| 4440 | node->SetType( symbol->type ); |
| 4441 | } |
| 4442 | node = copy; |
| 4443 | } |
| 4444 | // looking for matrix[] expressions |
| 4445 | if( IsIndexOperator( node ) && node->GetChild( 0 )->GetType().IsMatrix() && node->GetChild( 0 )->GetType().arrayDimensions == 0 ) |
| 4446 | { |
| 4447 | if( parent && parent->GetChild( 0 ) == node && IsIndexOperator( parent ) ) |
| 4448 | { |
| 4449 | // m[x][y] -> m[y][x] |
| 4450 | auto x = node->GetChild( 1 ); |
| 4451 | node->ReplaceChild( 1, parent->GetChild( 1 ) ); |
| 4452 | parent->ReplaceChild( 1, x ); |
| 4453 | } |
| 4454 | else |
| 4455 | { |
| 4456 | const auto& matrixType = node->GetChild( 0 )->GetType(); |
| 4457 | if( rvalue ) |
| 4458 | { |
| 4459 | // replace m[x] with matrixRow(m, x) |
| 4460 | ScannerToken callToken = ScannerToken::ID( MakeInlineString( "matrixRow" ), node->GetLocation() ); |
| 4461 | node->SetToken( &callToken ); |
| 4462 | node->SetNodeType( NT_FUNCTION_CALL ); |
| 4463 | } |
| 4464 | else |
| 4465 | { |
| 4466 | // replace m[x] with MatrixRow#LH<#>(m, x) |
| 4467 | char* name = state.AllocateString( 32 ); |
| 4468 | #ifdef _WIN32 |
| 4469 | sprintf_s( name, 32, "MatrixRow%dLH<%d>", matrixType.height, matrixType.width ); |
| 4470 | #else |
no test coverage detected