| 395 | } |
| 396 | |
| 397 | void asCCompiler::FinalizeFunction() |
| 398 | { |
| 399 | TimeIt("asCCompiler::FinalizeFunction"); |
| 400 | |
| 401 | asASSERT( outFunc->scriptData ); |
| 402 | asUINT n; |
| 403 | |
| 404 | // Add the type of all temporary variables to the function so this is known to debugger and serializer |
| 405 | for (n = 0; n < tempVariableOffsets.GetLength(); n++) |
| 406 | { |
| 407 | int slot = GetVariableSlot(tempVariableOffsets[n]); |
| 408 | outFunc->AddVariable("", variableAllocations[slot], tempVariableOffsets[n], variableIsOnHeap[slot]); |
| 409 | } |
| 410 | // Add the type of unnamed parameters |
| 411 | int stackPos = outFunc->objectType ? -AS_PTR_SIZE : 0; |
| 412 | // If the return type is a value type returned by value the address of the |
| 413 | // location where the value will be stored is pushed on the stack before |
| 414 | // the arguments |
| 415 | bool isDestructor = (outFunc->name.GetLength() > 0 && outFunc->name[0] == '~') ? true : false; |
| 416 | if (!(isDestructor || m_isConstructor) && outFunc->DoesReturnOnStack()) |
| 417 | stackPos -= AS_PTR_SIZE; |
| 418 | for (n = 0; n < outFunc->parameterNames.GetLength(); n++) |
| 419 | { |
| 420 | // Get the parameter type |
| 421 | asCDataType& type = outFunc->parameterTypes[n]; |
| 422 | |
| 423 | // If the parameter has a name then it was already added to the list in SetupParametersAndReturnVariable |
| 424 | if (outFunc->parameterNames[n] == "") |
| 425 | { |
| 426 | // Object types passed by value are considered to be on heap |
| 427 | bool onHeap = !type.IsReference() && type.IsObject() && !type.IsObjectHandle(); |
| 428 | outFunc->AddVariable("", type, stackPos, onHeap); |
| 429 | } |
| 430 | |
| 431 | // Move to next parameter |
| 432 | stackPos -= type.GetSizeOnStackDWords(); |
| 433 | } |
| 434 | // Add the return type too at the end if it returns on the stack, which is when it uses a hidden parameter |
| 435 | if (outFunc->DoesReturnOnStack()) |
| 436 | { |
| 437 | // Though declared as return by value, locally the return value is seen as a reference |
| 438 | asCDataType returnType = outFunc->returnType; |
| 439 | returnType.MakeReference(true); |
| 440 | outFunc->AddVariable("", returnType, outFunc->objectType ? -AS_PTR_SIZE : 0, false); |
| 441 | } |
| 442 | |
| 443 | // Finalize the bytecode |
| 444 | byteCode.Finalize(tempVariableOffsets); |
| 445 | |
| 446 | // extract the try/catch info before object variable info, as |
| 447 | // some variable info is not needed if there are no try/catch blocks |
| 448 | byteCode.ExtractTryCatchInfo(outFunc); |
| 449 | |
| 450 | byteCode.ExtractObjectVariableInfo(outFunc); |
| 451 | |
| 452 | // Copy byte code to the function |
| 453 | asASSERT( outFunc->scriptData->byteCode.GetLength() == 0 ); |
| 454 | outFunc->scriptData->byteCode.SetLength(byteCode.GetSize()); |
nothing calls this directly
no test coverage detected