public virtual bool CompatibleWith(CodeType type) { if (IsConstant() != type.IsConstant()) { return(false); } if (IsConstant() && type.IsConstant()) { return(true); } return(type.Attributes.StackLength == 1); }
public IWorkshopTree Parse(ActionSet actionSet) { if (_type.IsConstant()) { return(this); } return(Lambda.Workshop.CaptureEncoder.Encode(actionSet, this)); }
protected override void ApplyCodeType(CodeType type) { if (type != null && type.IsConstant()) { _diagnostics.Error($"Constant types cannot be used in subroutine parameters.", _typeRange); } _varInfo.Type = type; }
protected void ApplyCodeType(CodeType type) { if (type != null && type.IsConstant()) { _varInfo.IsWorkshopReference = true; } _varInfo.Type = type; }
protected override void GetCodeType() { var context = _contextHandler.GetCodeType(); CodeType type = CodeType.GetCodeTypeFromContext(_parseInfo, context); if (type != null && type.IsConstant()) { _diagnostics.Error($"Constant types cannot be used in subroutine parameters.", context.Range); } _varInfo.Type = type; }
protected virtual void GetCodeType() { // Get the type. CodeType type = CodeType.GetCodeTypeFromContext(_parseInfo, _contextHandler.GetCodeType()); if (type != null && type.IsConstant()) { _varInfo.IsWorkshopReference = true; } _varInfo.Type = type; }
protected virtual bool DoesImplement(CodeType type) { // Iterate through all extended classes. CodeType checkType = this; while (checkType != null) { if (type.Is(checkType) || (!checkType.IsConstant() && type is AnyType)) { return(true); } checkType = checkType.Extends; } return(false); }
private void CompareParameterTypes(IExpression value, IParameterCallable option, int parameter, DocRange errorRange) { CodeType parameterType = option.Parameters[parameter].Type; if (parameterType != null && ((parameterType.IsConstant() && value.Type() == null) || (value.Type() != null && !value.Type().Implements(parameterType)))) { // The parameter type does not match. string msg = string.Format("Expected a value of type {0}.", option.Parameters[parameter].Type.Name); optionDiagnostics[option].Add(new Diagnostic(msg, errorRange, Diagnostic.Error)); } else if (value.Type() != null && parameterType == null && value.Type().IsConstant()) { string msg = string.Format($"The type '{value.Type().Name}' cannot be used here."); optionDiagnostics[option].Add(new Diagnostic(msg, errorRange, Diagnostic.Error)); } }
private void GetInitialValue() { // Get the initial value. if (_initalValueContext != null) { ParseInfo parseInfo = this.parseInfo; // Store the initial value's restricted calls. RestrictedCallList restrictedCalls = null; if (_handleRestrictedCalls) { restrictedCalls = new RestrictedCallList(); parseInfo = parseInfo.SetRestrictedCallHandler(restrictedCalls); } // Parse the initial value. InitialValue = parseInfo.SetExpectingLambda(CodeType).GetExpression(_operationalScope, _initalValueContext); // 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.", _initalValueContext.Range); } // If the variable's type is constant, make sure the value's type matches. else if (CodeType != null && CodeType.IsConstant() && (InitialValue.Type() == null || !InitialValue.Type().Implements(CodeType))) { parseInfo.Script.Diagnostics.Error($"Expected a value of type '" + CodeType.GetName() + "'", _initalValueContext.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. parseInfo.Script.Diagnostics.Error(call.Message, call.CallRange.range); } } } } }
/// <summary>Confirms that a parameter type matches.</summary> public void CompareParameterTypes(int parameter) { CodeType parameterType = Option.Parameters[parameter].Type; IExpression value = OrderedParameters[parameter]?.Value; if (value == null) { return; } DocRange errorRange = OrderedParameters[parameter].ExpressionRange; if (parameterType != null && ((parameterType.IsConstant() && value.Type() == null) || (value.Type() != null && !value.Type().Implements(parameterType)))) { // The parameter type does not match. string msg = string.Format("Expected a value of type {0}.", Option.Parameters[parameter].Type.GetName()); Error(msg, errorRange); } else if (value.Type() != null && parameterType == null && value.Type().IsConstant()) { string msg = string.Format($"The type '{value.Type().Name}' cannot be used here."); Error(msg, errorRange); } }
// Sets up the method's block. public override void SetupBlock() { Block = new BlockAction(parseInfo.SetCallInfo(CallInfo), methodScope.Child(), Context.Block); // Validate returns. BlockTreeScan validation = new BlockTreeScan(DoesReturnValue, parseInfo, this); validation.ValidateReturns(); MultiplePaths = validation.MultiplePaths; // If there is only one return statement, set SingleReturnValue. if (validation.Returns.Length == 1) { SingleReturnValue = validation.Returns[0].ReturningValue; } // If the return type is a constant type... if (CodeType != null && CodeType.IsConstant()) { // ... iterate through each return statement ... foreach (ReturnAction returnAction in validation.Returns) { // ... If the current return statement returns a value and that value does not implement the return type ... if (returnAction.ReturningValue != null && (returnAction.ReturningValue.Type() == null || !returnAction.ReturningValue.Type().Implements(CodeType))) { // ... then add a syntax error. parseInfo.Script.Diagnostics.Error("Must return a value of type '" + CodeType.GetName() + "'.", returnAction.ErrorRange); } } } WasApplied = true; foreach (var listener in listeners) { listener.Applied(); } }
public bool Settable() { return((CodeType == null || !CodeType.IsConstant()) && (VariableType == VariableType.Global || VariableType == VariableType.Player || VariableType == VariableType.Dynamic)); }
public override bool Is(CodeType type) => !type.IsConstant();
public override bool Implements(CodeType type) => !type.IsConstant() && (type is StructInstance == false || _unknown);