| 590 | } |
| 591 | |
| 592 | void CollectGlobals( |
| 593 | ParserState& state, |
| 594 | std::map<Symbol*, ASTNode*>& functions, |
| 595 | std::vector<ASTNode*>& globals ) |
| 596 | { |
| 597 | ZoneScoped; |
| 598 | |
| 599 | ASTNode* root = state.GetTree(); |
| 600 | if( !root ) |
| 601 | { |
| 602 | return; |
| 603 | } |
| 604 | |
| 605 | ASTNode* globalsStruct = nullptr; |
| 606 | ASTNode* uiStruct = nullptr; |
| 607 | |
| 608 | std::set<Symbol*> globalsStructMembers; |
| 609 | std::set<Symbol*> uiStructMembers; |
| 610 | std::vector<ASTNode*> cbuffers; |
| 611 | |
| 612 | // Move all globals to the new buffer. |
| 613 | for( size_t i = 0; i < root->GetChildrenCount(); ++i ) |
| 614 | { |
| 615 | ASTNode* node = root->GetChild( i ); |
| 616 | if( node && node->GetNodeType() == NT_CBUFFER ) |
| 617 | { |
| 618 | auto cbufferStruct = new ASTNode( NT_STRUCT, node->GetLocation(), node->GetScope(), nullptr ); |
| 619 | |
| 620 | Symbol* globalsSymbol = node->GetSymbol(); |
| 621 | globalsSymbol->isTypeName = true; |
| 622 | globalsSymbol->definition = cbufferStruct; |
| 623 | if( globalsSymbol->registerSpecifier.empty() ) |
| 624 | { |
| 625 | globalsSymbol->registerSpecifier[MakeInlineString( "" )] = RegisterSpecifier::Register( MetalRegister::CBuffer, 0 ); |
| 626 | } |
| 627 | else |
| 628 | { |
| 629 | globalsSymbol->registerSpecifier.begin()->second.registerType = MetalRegister::CBuffer; |
| 630 | } |
| 631 | |
| 632 | cbufferStruct->SetSymbol( globalsSymbol ); |
| 633 | |
| 634 | for( size_t j = 0; j < node->GetChildrenCount(); ++j ) |
| 635 | { |
| 636 | node->GetChild( j )->SetNodeType( NT_STRUCT_MEMBER ); |
| 637 | cbufferStruct->AddChild( node->GetChild( j ) ); |
| 638 | } |
| 639 | |
| 640 | state.GetTree()->ReplaceChild( i, cbufferStruct ); |
| 641 | cbuffers.push_back( cbufferStruct ); |
| 642 | continue; |
| 643 | } |
| 644 | if( node && node->GetNodeType() == NT_VAR_DECLARATION_LIST ) |
| 645 | { |
| 646 | ASTNode* childNode = node->GetChildOrNull( 0 ); |
| 647 | if( childNode && childNode->GetNodeType() == NT_NAME_DECLARATION ) |
| 648 | { |
| 649 | Symbol* symbol = childNode->GetSymbol(); |
no test coverage detected