MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / IsVarInScope

Method IsVarInScope

src/server/angelscript/angelscript/source/as_context.cpp:4676–4732  ·  view source on GitHub ↗

Interface

Source from the content-addressed store, hash-verified

4674
4675// Interface
4676bool asCContext::IsVarInScope(asUINT varIndex, asUINT stackLevel)
4677{
4678 // Don't return anything if there is no bytecode, e.g. before calling Execute()
4679 if( m_regs.programPointer == 0 ) return false;
4680
4681 if( stackLevel >= GetCallstackSize() ) return false;
4682
4683 asCScriptFunction *func;
4684 asUINT pos;
4685
4686 if( stackLevel == 0 )
4687 {
4688 func = m_currentFunction;
4689 if( func->scriptData == 0 ) return false;
4690 pos = asUINT(m_regs.programPointer - func->scriptData->byteCode.AddressOf());
4691 }
4692 else
4693 {
4694 asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE;
4695 func = (asCScriptFunction*)s[1];
4696 if( func->scriptData == 0 ) return false;
4697 pos = asUINT((asDWORD*)s[2] - func->scriptData->byteCode.AddressOf());
4698 }
4699
4700 // First determine if the program position is after the variable declaration
4701 if( func->scriptData->variables.GetLength() <= varIndex ) return false;
4702 if( func->scriptData->variables[varIndex]->declaredAtProgramPos > pos ) return false;
4703
4704 asUINT declaredAt = func->scriptData->variables[varIndex]->declaredAtProgramPos;
4705
4706 // If the program position is after the variable declaration it is necessary
4707 // determine if the program position is still inside the statement block where
4708 // the variable was delcared.
4709 for( int n = 0; n < (int)func->scriptData->objVariableInfo.GetLength(); n++ )
4710 {
4711 if( func->scriptData->objVariableInfo[n].programPos >= declaredAt )
4712 {
4713 // If the current block ends between the declaredAt and current
4714 // program position, then we know the variable is no longer visible
4715 int level = 0;
4716 for( ; n < (int)func->scriptData->objVariableInfo.GetLength(); n++ )
4717 {
4718 if( func->scriptData->objVariableInfo[n].programPos > pos )
4719 break;
4720
4721 if( func->scriptData->objVariableInfo[n].option == asBLOCK_BEGIN ) level++;
4722 if( func->scriptData->objVariableInfo[n].option == asBLOCK_END && --level < 0 )
4723 return false;
4724 }
4725
4726 break;
4727 }
4728 }
4729
4730 // Variable is visible
4731 return true;
4732}
4733

Callers 2

PrintValueMethod · 0.80
ListLocalVariablesMethod · 0.80

Calls 2

AddressOfMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected