public void GetContent()
        {
            var parseInfo = _parseInfo
                            .SetReturnType(ReturnType)
                            .SetThisType(ContainingType)
                            .SetCallInfo(CallInfo);

            if (Context.Block != null)
            {
                var returnTracker = new ReturnTracker();
                Block = new BlockAction(parseInfo.SetReturnTracker(returnTracker), _methodScope, Context.Block);

                MultiplePaths = returnTracker.IsMultiplePaths;

                // If there is only one return statement, set SingleReturnValue.
                if (returnTracker.Returns.Count == 1)
                {
                    SingleReturnValue = returnTracker.Returns[0].ReturningValue;
                }
            }
            else if (Context.MacroValue != null)
            {
                MacroValue = SingleReturnValue = parseInfo.SetExpectType(ReturnType).GetExpression(_methodScope, Context.MacroValue);

                SemanticsHelper.ExpectValueType(parseInfo, MacroValue, ReturnType, Context.MacroValue.Range);
            }

            ContentReady.Set();
        }
        public void TrySet(ParseInfo parseInfo, IExpression value, DocRange expressionRange)
        {
            var type = CodeType.GetCodeType(parseInfo.TranslateInfo);

            // Check if the hook was already set.
            if (WasSet)
            {
                parseInfo.Script.Diagnostics.Error("Hooks cannot be set twice.", expressionRange);
            }
            // Check if the given value implements the expected value.
            else if (SemanticsHelper.ExpectValueType(parseInfo, value, type, expressionRange))
            {
                // Set the hook.
                HookValue = value;
                SetHook?.Invoke(value);
            }

            WasSet = true;
        }
        private void GetInitialValue()
        {
            // Get the initial value.
            if (_initialValueContext != null)
            {
                ParseInfo parseInfo = this._parseInfo;

                // Store the initial value's restricted calls.
                RestrictedCallList restrictedCalls = null;
                if (_handleRestrictedCalls)
                {
                    restrictedCalls = new RestrictedCallList();
                    parseInfo       = parseInfo.SetRestrictedCallHandler(restrictedCalls);
                }

                ParseInfo initialValueParseInfo = parseInfo.SetExpectType(CodeType);
                if (parseInfo.CurrentCallInfo == null)
                {
                    CallInfo callInfo = new CallInfo(parseInfo.Script);
                    initialValueParseInfo = initialValueParseInfo.SetCallInfo(callInfo);
                }

                // Parse the initial value.
                InitialValue = initialValueParseInfo.GetExpression(_operationalScope, _initialValueContext);

                // Get the inferred type.
                if (_inferType)
                {
                    CodeType = InitialValue.Type();
                    _variableTypeHandler.SetType(CodeType);
                    AddScriptData();
                }

                // If the initial value's type is constant, make sure the constant type's implements the variable's type.
                if (InitialValue?.Type() != null && InitialValue.Type().IsConstant() && !InitialValue.Type().Implements(CodeType))
                {
                    parseInfo.Script.Diagnostics.Error($"The type '{InitialValue.Type().Name}' cannot be stored.", _initialValueContext.Range);
                }

                // If the variable's type is constant, make sure the value's type matches.
                else
                {
                    SemanticsHelper.ExpectValueType(parseInfo, InitialValue, CodeType, _initialValueContext.Range);
                }

                // Check restricted calls.
                if (_handleRestrictedCalls)
                {
                    foreach (RestrictedCall call in restrictedCalls)
                    {
                        // If the variable type is global, or the variable type is player and the restricted call type is not player...
                        if (VariableType == VariableType.Global ||
                            (VariableType == VariableType.Player && call.CallType != RestrictedCallType.EventPlayer))
                        {
                            // ... then add the error.
                            call.AddDiagnostic(parseInfo.Script.Diagnostics);
                        }
                    }
                }
            }

            ValueReady.Set();
        }