============ idProgram::GetDef If type is NULL, it will match any type ============ */
| 1393 | ============ |
| 1394 | */ |
| 1395 | idVarDef *idProgram::GetDef( const idTypeDef *type, const char *name, const idVarDef *scope ) const { |
| 1396 | idVarDef *def; |
| 1397 | idVarDef *bestDef; |
| 1398 | int bestDepth; |
| 1399 | int depth; |
| 1400 | |
| 1401 | bestDepth = 0; |
| 1402 | bestDef = NULL; |
| 1403 | for( def = GetDefList( name ); def != NULL; def = def->Next() ) { |
| 1404 | if ( def->scope->Type() == ev_namespace ) { |
| 1405 | depth = def->DepthOfScope( scope ); |
| 1406 | if ( !depth ) { |
| 1407 | // not in the same namespace |
| 1408 | continue; |
| 1409 | } |
| 1410 | } else if ( def->scope != scope ) { |
| 1411 | // in a different function |
| 1412 | continue; |
| 1413 | } else { |
| 1414 | depth = 1; |
| 1415 | } |
| 1416 | |
| 1417 | if ( !bestDef || ( depth < bestDepth ) ) { |
| 1418 | bestDepth = depth; |
| 1419 | bestDef = def; |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | // see if the name is already in use for another type |
| 1424 | if ( bestDef && type && ( bestDef->TypeDef() != type ) ) { |
| 1425 | throw idCompileError( va( "Type mismatch on redeclaration of %s", name ) ); |
| 1426 | } |
| 1427 | |
| 1428 | return bestDef; |
| 1429 | } |
| 1430 | |
| 1431 | /* |
| 1432 | ============ |
no test coverage detected