Ejemplo n.º 1
0
 public ValueGroupType(EnumData enumData, bool constant) : base(enumData.CodeName)
 {
     Constant = constant;
     EnumData = enumData;
     foreach (EnumMember member in enumData.Members)
     {
         EnumValuePair newPair = new EnumValuePair(member, constant, this);
         ValuePairs.Add(newPair);
         Scope.AddNativeVariable(newPair);
     }
 }
        public ValueGroupType(EnumData enumData, bool constant) : base(enumData.CodeName)
        {
            Scope     = new Scope("enum " + Name);
            Constant  = constant;
            EnumData  = enumData;
            TokenType = TokenType.Enum;

            if (constant)
            {
                TokenModifiers.Add(TokenModifier.Readonly);
            }

            foreach (EnumMember member in enumData.Members)
            {
                EnumValuePair newPair = new EnumValuePair(member, constant, this);
                ValuePairs.Add(newPair);
                Scope.AddNativeVariable(newPair);
            }
        }
        public ValueGroupType(ElementEnum enumData, ITypeSupplier types, bool constant) : base(enumData.Name)
        {
            _staticScope = new Scope("enum " + Name);
            _objectScope = new Scope("enum " + Name);
            _constant    = constant;
            EnumData     = enumData;
            TokenType    = SemanticTokenType.Enum;

            if (constant)
            {
                TokenModifiers.Add(TokenModifier.Readonly);
            }

            foreach (ElementEnumMember member in enumData.Members)
            {
                EnumValuePair newPair = new EnumValuePair(member, constant, this);
                _valuePairs.Add(newPair);
                _staticScope.AddNativeVariable(newPair);
            }

            Operations.DefaultAssignment = !constant;
        }
        private void GetRuleSettings(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Ow_ruleContext ruleContext)
        {
            DeltinScriptParser.ExprContext eventContext  = null;
            DeltinScriptParser.ExprContext teamContext   = null;
            DeltinScriptParser.ExprContext playerContext = null;

            foreach (var exprContext in ruleContext.expr())
            {
                missingBlockRange = DocRange.GetRange(exprContext);

                EnumValuePair enumSetting = (ExpressionTree.ResultingExpression(parseInfo.GetExpression(scope, exprContext)) as CallVariableAction)?.Calling as EnumValuePair;
                EnumData      enumData    = enumSetting?.Member.Enum;

                if (enumData == null || !ValidRuleEnums.Contains(enumData))
                {
                    parseInfo.Script.Diagnostics.Error("Expected enum of type " + string.Join(", ", ValidRuleEnums.Select(vre => vre.CodeName)) + ".", DocRange.GetRange(exprContext));
                }
                else
                {
                    var alreadySet = new Diagnostic("The " + enumData.CodeName + " rule setting was already set.", DocRange.GetRange(exprContext), Diagnostic.Error);

                    // Get the Event option.
                    if (enumData == EnumData.GetEnum <RuleEvent>())
                    {
                        if (_setEventType)
                        {
                            parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet);
                        }
                        EventType     = (RuleEvent)enumSetting.Member.Value;
                        _setEventType = true;
                        eventContext  = exprContext;
                    }
                    // Get the Team option.
                    if (enumData == EnumData.GetEnum <Team>())
                    {
                        if (_setTeam)
                        {
                            parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet);
                        }
                        Team        = (Team)enumSetting.Member.Value;
                        _setTeam    = true;
                        teamContext = exprContext;
                    }
                    // Get the Player option.
                    if (enumData == EnumData.GetEnum <PlayerSelector>())
                    {
                        if (_setPlayer)
                        {
                            parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet);
                        }
                        Player        = (PlayerSelector)enumSetting.Member.Value;
                        _setPlayer    = true;
                        playerContext = exprContext;
                    }
                }
            }

            // Syntax error if changing the Team type when the Event type is set to Global.
            if (_setEventType && EventType == RuleEvent.OngoingGlobal)
            {
                if (Team != Team.All)
                {
                    parseInfo.Script.Diagnostics.Error("Can't change rule Team type with an event type of Ongoing Global.", DocRange.GetRange(teamContext));
                }
                if (Player != PlayerSelector.All)
                {
                    parseInfo.Script.Diagnostics.Error("Can't change rule Player type with an event type of Ongoing Global.", DocRange.GetRange(playerContext));
                }
            }
        }