| 511 | } |
| 512 | |
| 513 | int asCBuilder::CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asCScriptFunction **outFunc) |
| 514 | { |
| 515 | asASSERT(outFunc != 0); |
| 516 | |
| 517 | Reset(); |
| 518 | |
| 519 | // Add the string to the script code |
| 520 | asCScriptCode *script = asNEW(asCScriptCode); |
| 521 | if( script == 0 ) |
| 522 | return asOUT_OF_MEMORY; |
| 523 | |
| 524 | script->SetCode(sectionName, code, true); |
| 525 | script->lineOffset = lineOffset; |
| 526 | script->idx = engine->GetScriptSectionNameIndex(sectionName ? sectionName : ""); |
| 527 | scripts.PushLast(script); |
| 528 | |
| 529 | // Parse the string |
| 530 | asCParser parser(this); |
| 531 | if( parser.ParseScript(scripts[0]) < 0 ) |
| 532 | return asERROR; |
| 533 | |
| 534 | asCScriptNode *node = parser.GetScriptNode(); |
| 535 | |
| 536 | // Make sure there is nothing else than the function in the script code |
| 537 | if( node == 0 || |
| 538 | node->firstChild == 0 || |
| 539 | node->firstChild != node->lastChild || |
| 540 | node->firstChild->nodeType != snFunction ) |
| 541 | { |
| 542 | WriteError(TXT_ONLY_ONE_FUNCTION_ALLOWED, script, 0); |
| 543 | return asERROR; |
| 544 | } |
| 545 | |
| 546 | // Find the function node |
| 547 | node = node->firstChild; |
| 548 | |
| 549 | // Create the function |
| 550 | asSFunctionTraits funcTraits; |
| 551 | asCScriptFunction *func = asNEW(asCScriptFunction)(engine, compileFlags & asCOMP_ADD_TO_MODULE ? module : 0, asFUNC_SCRIPT); |
| 552 | if( func == 0 ) |
| 553 | return asOUT_OF_MEMORY; |
| 554 | |
| 555 | GetParsedFunctionDetails(node, scripts[0], 0, func->name, func->returnType, func->parameterNames, func->parameterTypes, func->inOutFlags, func->defaultArgs, funcTraits, module->m_defaultNamespace); |
| 556 | func->id = engine->GetNextScriptFunctionId(); |
| 557 | func->scriptData->scriptSectionIdx = engine->GetScriptSectionNameIndex(sectionName ? sectionName : ""); |
| 558 | int row, col; |
| 559 | scripts[0]->ConvertPosToRowCol(node->tokenPos, &row, &col); |
| 560 | func->scriptData->declaredAt = (row & 0xFFFFF)|((col & 0xFFF)<<20); |
| 561 | func->nameSpace = module->m_defaultNamespace; |
| 562 | |
| 563 | // Make sure the default args are declared correctly |
| 564 | int r = ValidateDefaultArgs(script, node, func); |
| 565 | if( r < 0 ) |
| 566 | { |
| 567 | func->ReleaseInternal(); |
| 568 | return asERROR; |
| 569 | } |
| 570 |
no test coverage detected