| 378 | } |
| 379 | |
| 380 | void PatchGlobalsInFunctions( std::map<Symbol*, ASTNode*>& functions, Symbol* typeSymbol, const InlineString& globalsName, const std::set<Symbol*>& structMembers ) |
| 381 | { |
| 382 | assert( !structMembers.empty() ); |
| 383 | |
| 384 | std::map<Symbol*, ASTNode*> functionsWithGlobals; |
| 385 | std::map<Symbol*, ASTNode*> functionsWithoutGlobals; |
| 386 | |
| 387 | SearchFunctionsForGlobals( structMembers, functions, functionsWithGlobals, functionsWithoutGlobals ); |
| 388 | |
| 389 | ScannerToken token = {}; |
| 390 | token.type = OP_INOUT; |
| 391 | |
| 392 | for( auto& it : functionsWithGlobals ) |
| 393 | { |
| 394 | ASTNode* node = it.second; |
| 395 | assert( node && node->GetNodeType() == NT_FUNCTION_DEFINITION ); |
| 396 | |
| 397 | ASTNode* header = node->GetChild( 0 ); |
| 398 | assert( header->GetNodeType() == NT_FUNCTION_HEADER ); |
| 399 | |
| 400 | ASTNode* body = node->GetChild( 1 ); |
| 401 | assert( body->GetNodeType() == NT_BLOCK ); |
| 402 | |
| 403 | Symbol* symbol = node->GetScope()->AddSymbol( globalsName, DISALOW_OVERRIDES ); |
| 404 | symbol->type.FromSymbol( typeSymbol ); |
| 405 | symbol->addressSpace = AddressSpace::Constant; |
| 406 | symbol->registerSpecifier = typeSymbol->registerSpecifier; |
| 407 | |
| 408 | token.fileLocation = header->GetLocation(); |
| 409 | |
| 410 | Type type; |
| 411 | type.FromSymbol( typeSymbol ); |
| 412 | |
| 413 | ASTNode* globalsParam = new ASTNode( NT_FUNCTION_PARAMETER, header->GetLocation(), header->GetScope(), &token ); |
| 414 | globalsParam->SetType( type ); |
| 415 | globalsParam->SetSymbol( symbol ); |
| 416 | |
| 417 | header->InsertChild( 0, globalsParam ); |
| 418 | |
| 419 | AddFunctionArgument( functionsWithGlobals, header->GetSymbol(), symbol ); |
| 420 | |
| 421 | AddStructDotPrefix( body, structMembers, symbol ); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | bool IsGlobalVarUsed( const std::map<Symbol*, ASTNode*>& functions, const InlineString& name, ASTNode* node ) |
| 426 | { |
no test coverage detected