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

Method SetupParametersAndReturnVariable

sdk/angelscript/source/as_compiler.cpp:474–574  ·  view source on GitHub ↗

internal

Source from the content-addressed store, hash-verified

472
473// internal
474int asCCompiler::SetupParametersAndReturnVariable(asCArray<asCString> &parameterNames, asCScriptNode *func)
475{
476 int stackPos = 0;
477
478 if( outFunc->objectType )
479 stackPos = -AS_PTR_SIZE; // The first parameter is the pointer to the object
480
481 // Add the first variable scope, which the parameters and
482 // variables declared in the outermost statement block is
483 // part of.
484 AddVariableScope();
485
486 bool isDestructor = false;
487 asCDataType returnType;
488
489 // Examine return type
490 returnType = outFunc->returnType;
491
492 // Check if this is a constructor or destructor
493 if( returnType.GetTokenType() == ttVoid && outFunc->objectType )
494 {
495 if( outFunc->name[0] == '~' )
496 isDestructor = true;
497 else if( outFunc->objectType->name == outFunc->name )
498 m_isConstructor = true;
499 }
500
501 // Is the return type allowed?
502 if( returnType != asCDataType::CreatePrimitive(ttVoid, false) &&
503 !returnType.CanBeInstantiated() &&
504 !returnType.IsReference() &&
505 !returnType.IsObjectHandle() )
506 {
507 // TODO: Hasn't this been validated by the builder already?
508 asCString str;
509 str.Format(TXT_RETURN_CANT_BE_s, returnType.Format(outFunc->nameSpace).AddressOf());
510 Error(str, func);
511 }
512
513 // If the return type is a value type returned by value the address of the
514 // location where the value will be stored is pushed on the stack before
515 // the arguments
516 if( !(isDestructor || m_isConstructor) && outFunc->DoesReturnOnStack() )
517 stackPos -= AS_PTR_SIZE;
518
519 asCVariableScope vs(0);
520
521 // Declare parameters
522 asUINT n;
523 for( n = 0; n < parameterNames.GetLength(); n++ )
524 {
525 // Get the parameter type
526 asCDataType &type = outFunc->parameterTypes[n];
527 asETypeModifiers inoutFlag = n < outFunc->inOutFlags.GetLength() ? outFunc->inOutFlags[n] : asTM_NONE;
528
529 // Is the data type allowed?
530 // TODO: Hasn't this been validated by the builder already?
531 if( (type.IsReference() && inoutFlag != asTM_INOUTREF && !type.CanBeInstantiated()) ||

Callers

nothing calls this directly

Calls 13

GetTokenTypeMethod · 0.80
CanBeInstantiatedMethod · 0.80
IsObjectHandleMethod · 0.80
DoesReturnOnStackMethod · 0.80
IsObjectMethod · 0.80
VarDeclMethod · 0.80
AddVariableMethod · 0.80
GetSizeOnStackDWordsMethod · 0.80
IsReferenceMethod · 0.45
FormatMethod · 0.45
AddressOfMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected