| 274 | } |
| 275 | |
| 276 | bool SearchFunctionsForGlobals( ASTNode* node, const std::set<Symbol*>& structMembers, const std::map<Symbol*, ASTNode*>& functions, std::map<Symbol*, ASTNode*>& functionsWithGlobals, std::map<Symbol*, ASTNode*>& functionsWithoutGlobals ) |
| 277 | { |
| 278 | for( size_t i = 0, n = node->GetChildrenCount(); i < n; ++i ) |
| 279 | { |
| 280 | ASTNode* childNode = node->GetChild( i ); |
| 281 | if( !childNode ) |
| 282 | { |
| 283 | continue; |
| 284 | } |
| 285 | |
| 286 | if( childNode->GetNodeType() == NT_VAR_IDENTIFIER ) |
| 287 | { |
| 288 | Symbol* symbol = childNode->GetSymbol(); |
| 289 | |
| 290 | auto it = structMembers.find( symbol ); |
| 291 | if( it != structMembers.end() ) |
| 292 | { |
| 293 | return true; |
| 294 | } |
| 295 | } |
| 296 | else if( childNode->GetNodeType() == NT_FUNCTION_CALL ) |
| 297 | { |
| 298 | Symbol* symbol = childNode->GetSymbol(); |
| 299 | if( symbol ) |
| 300 | { |
| 301 | if( functionsWithGlobals.find( symbol ) != functionsWithGlobals.end() ) |
| 302 | { |
| 303 | // The function was aready marked as using globals. |
| 304 | return true; |
| 305 | } |
| 306 | else if( functionsWithoutGlobals.find( symbol ) == functionsWithoutGlobals.end() ) |
| 307 | { |
| 308 | // If the function wasn't found in both lists it means either it was not checked yet |
| 309 | // or it's a standard library function. |
| 310 | auto it = functions.find( symbol ); |
| 311 | if( it != functions.end() ) |
| 312 | { |
| 313 | ASTNode* definition = it->second; |
| 314 | assert( definition && definition->GetNodeType() == NT_FUNCTION_DEFINITION ); |
| 315 | |
| 316 | [[maybe_unused]] ASTNode* header = definition->GetChild( 0 ); |
| 317 | assert( header->GetNodeType() == NT_FUNCTION_HEADER ); |
| 318 | assert( header->GetSymbol() == symbol ); |
| 319 | |
| 320 | ASTNode* body = definition->GetChild( 1 ); |
| 321 | assert( body->GetNodeType() == NT_BLOCK ); |
| 322 | |
| 323 | bool found = SearchFunctionsForGlobals( body, structMembers, functions, functionsWithGlobals, functionsWithoutGlobals ); |
| 324 | if( found ) |
| 325 | { |
| 326 | functionsWithGlobals.insert( { it->first, it->second } ); |
| 327 | return true; |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | functionsWithoutGlobals.insert( { it->first, it->second } ); |
| 332 | } |
| 333 | } |
no test coverage detected