MCPcopy Create free account
hub / github.com/carbonengine/trinity / PatchGlobalsInFunctions

Function PatchGlobalsInFunctions

shadercompiler/EffectCompilerMetal.cpp:380–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

378}
379
380void 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
425bool IsGlobalVarUsed( const std::map<Symbol*, ASTNode*>& functions, const InlineString& name, ASTNode* node )
426{

Callers 1

CollectGlobalsFunction · 0.85

Calls 13

AddFunctionArgumentFunction · 0.85
AddStructDotPrefixFunction · 0.85
emptyMethod · 0.80
GetNodeTypeMethod · 0.80
AddSymbolMethod · 0.80
GetScopeMethod · 0.80
FromSymbolMethod · 0.80
SetSymbolMethod · 0.80
InsertChildMethod · 0.80
GetSymbolMethod · 0.80
GetChildMethod · 0.45

Tested by

no test coverage detected