=================== idDeclManagerLocal::CreateNewDecl =================== */
| 1356 | =================== |
| 1357 | */ |
| 1358 | idDecl *idDeclManagerLocal::CreateNewDecl( declType_t type, const char *name, const char *_fileName ) { |
| 1359 | int typeIndex = (int)type; |
| 1360 | int i, hash; |
| 1361 | |
| 1362 | if ( typeIndex < 0 || typeIndex >= declTypes.Num() || declTypes[typeIndex] == NULL ) { |
| 1363 | common->FatalError( "idDeclManager::CreateNewDecl: bad type: %i", typeIndex ); |
| 1364 | } |
| 1365 | |
| 1366 | char canonicalName[MAX_STRING_CHARS]; |
| 1367 | |
| 1368 | MakeNameCanonical( name, canonicalName, sizeof( canonicalName ) ); |
| 1369 | |
| 1370 | idStr fileName = _fileName; |
| 1371 | fileName.BackSlashesToSlashes(); |
| 1372 | |
| 1373 | // see if it already exists |
| 1374 | hash = hashTables[typeIndex].GenerateKey( canonicalName, false ); |
| 1375 | for ( i = hashTables[typeIndex].First( hash ); i >= 0; i = hashTables[typeIndex].Next( i ) ) { |
| 1376 | if ( linearLists[typeIndex][i]->name.Icmp( canonicalName ) == 0 ) { |
| 1377 | linearLists[typeIndex][i]->AllocateSelf(); |
| 1378 | return linearLists[typeIndex][i]->self; |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | idDeclFile *sourceFile; |
| 1383 | |
| 1384 | // find existing source file or create a new one |
| 1385 | for ( i = 0; i < loadedFiles.Num(); i++ ) { |
| 1386 | if ( loadedFiles[i]->fileName.Icmp( fileName ) == 0 ) { |
| 1387 | break; |
| 1388 | } |
| 1389 | } |
| 1390 | if ( i < loadedFiles.Num() ) { |
| 1391 | sourceFile = loadedFiles[i]; |
| 1392 | } else { |
| 1393 | sourceFile = new idDeclFile( fileName, type ); |
| 1394 | loadedFiles.Append( sourceFile ); |
| 1395 | } |
| 1396 | |
| 1397 | idDeclLocal *decl = new idDeclLocal; |
| 1398 | decl->name = canonicalName; |
| 1399 | decl->type = type; |
| 1400 | decl->declState = DS_UNPARSED; |
| 1401 | decl->AllocateSelf(); |
| 1402 | idStr header = declTypes[typeIndex]->typeName; |
| 1403 | idStr defaultText = decl->self->DefaultDefinition(); |
| 1404 | |
| 1405 | |
| 1406 | int size = header.Length() + 1 + idStr::Length( canonicalName ) + 1 + defaultText.Length(); |
| 1407 | char *declText = ( char * ) _alloca( size + 1 ); |
| 1408 | |
| 1409 | memcpy( declText, header, header.Length() ); |
| 1410 | declText[header.Length()] = ' '; |
| 1411 | memcpy( declText + header.Length() + 1, canonicalName, idStr::Length( canonicalName ) ); |
| 1412 | declText[header.Length() + 1 + idStr::Length( canonicalName )] = ' '; |
| 1413 | memcpy( declText + header.Length() + 1 + idStr::Length( canonicalName ) + 1, defaultText, defaultText.Length() + 1 ); |
| 1414 | |
| 1415 | decl->SetTextLocal( declText, size ); |
no test coverage detected