private bool IsGlobalsReference(string expectedType, ParserRuleContext context)
{
string text = context.GetTextSanitized();
GlobalInfo globalInfo = _opcodes.GetGlobalInfo(text);
IExpressionValue value;
// Engine global.
if(globalInfo != null)
{
//ushort[] arr = { 0xFFFF, globalInfo.MaskedOpcode };
value = new LongExpressionValue(0xFFFF, globalInfo.MaskedOpcode);
}
// Map global.
else if(_mapGlobalsLookup.ContainsKey(text))
{
globalInfo = _mapGlobalsLookup[text];
value = new LongExpressionValue(globalInfo.Opcode);
}
// Not a global...
else if (expectedType == TypeHelper.GlobalsReference)
{
throw new CompilerException($"A global reference was expected, but no global with the name \"{text}\" could be found.", context);
}
else
{
return false;
}
string returnType = DetermineReturnType(globalInfo, expectedType, context);
ushort returnTypeOpcode = _opcodes.GetTypeInfo(returnType).Opcode;
ushort opcode = GetGlobalOpCode(returnTypeOpcode, context);
var expression = new ScriptExpression
{
Index = _currentIndex,
Opcode = opcode,
ReturnType = returnTypeOpcode,
Type = ScriptExpressionType.GlobalsReference,
Next = DatumIndex.Null,
StringOffset = _strings.Cache(text),
Value = value,
LineNumber = GetLineNumber(context)
};
OpenDatumAddExpressionIncrement(expression);
return true;
}