MCPcopy Create free account
hub / github.com/anjo76/angelscript / CompileFunction

Method CompileFunction

sdk/angelscript/source/as_builder.cpp:513–646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

511}
512
513int 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

Callers 2

CompileGlobalVarMethod · 0.45
CompileFunctionsMethod · 0.45

Calls 15

SetCodeMethod · 0.80
PushLastMethod · 0.80
ParseScriptMethod · 0.80
GetScriptNodeMethod · 0.80
ConvertPosToRowColMethod · 0.80
PutMethod · 0.80
DisconnectParentMethod · 0.80
RemoveValueMethod · 0.80
ReleaseInternalMethod · 0.45
AddressOfMethod · 0.45

Tested by

no test coverage detected