public WhileAction(ParseInfo parseInfo, Scope scope, While whileContext)
        {
            RawContinue = true;
            Condition   = parseInfo.GetExpression(scope, whileContext.Condition);

            TypeComparison.ExpectNonConstant(parseInfo, whileContext.Condition.Range, Condition.Type());

            Block = parseInfo.SetLoop(this).GetStatement(scope, whileContext.Statement);
            Path  = new PathInfo(Block, whileContext.Range, false);
        }
Exemple #2
0
        public ElseIfAction(ParseInfo parseInfo, Scope scope, ElseIf elseIfContext)
        {
            // Get the else-if's expression.
            Expression = parseInfo.GetExpression(scope, elseIfContext.Expression);

            TypeComparison.ExpectNonConstant(parseInfo, elseIfContext.Expression.Range, Expression.Type());

            // Get the else-if's block.
            Block = parseInfo.GetStatement(scope, elseIfContext.Statement);
        }
Exemple #3
0
        public IfAction(ParseInfo parseInfo, Scope scope, If ifContext)
        {
            // Get the if condition.
            Expression = parseInfo.GetExpression(scope, ifContext.Expression);

            TypeComparison.ExpectNonConstant(parseInfo, ifContext.Expression.Range, Expression.Type());

            // Contains the path info of all blocks in the if/else-if/else list.
            var paths = new List <PathInfo>();

            // Get the if's block.
            Block = parseInfo.GetStatement(scope, ifContext.Statement);

            // Add the if block path info.
            paths.Add(new PathInfo(Block, ifContext.Range, false));

            // Get the else-ifs.
            ElseIfs = new ElseIfAction[ifContext.ElseIfs.Count];
            for (int i = 0; i < ElseIfs.Length; i++)
            {
                ElseIfs[i] = new ElseIfAction(parseInfo, scope, ifContext.ElseIfs[i]);
                paths.Add(new PathInfo(Block, ifContext.Range, false));
            }

            // If there is an else statement, get the else block.
            if (ifContext.Else != null)
            {
                ElseBlock = parseInfo.GetStatement(scope, ifContext.Else.Statement);

                // Add the else path info.
                paths.Add(new PathInfo(ElseBlock, ifContext.Range, true));
            }
            Paths = paths.ToArray();
            if (Block is BlockAction block)
            {
                EndComment = block.EndComment;
            }
        }
        public SetVariableAction(ParseInfo parseInfo, Scope scope, Assignment assignmentContext)
        {
            // Get the variable expression.
            IExpression variableExpression = parseInfo.GetExpression(scope, assignmentContext.VariableExpression);

            // Extract the variable data.
            _variableResolve = new VariableResolve(parseInfo, new VariableResolveOptions()
            {
                ShouldBeSettable = true
            }, variableExpression, assignmentContext.VariableExpression.Range);

            // Get the value.
            _value = parseInfo.SetExpectType(_variableResolve.SetVariable?.Type()).GetExpression(scope, assignmentContext.Value);

            // Get the operation.
            Token              assignmentToken = assignmentContext.AssignmentToken;
            CodeType           variableType = variableExpression.Type(), valueType = _value.Type();
            AssignmentOperator op = AssignmentOperation.OperatorFromTokenType(assignmentToken.TokenType);

            _operation = variableType.Operations.GetOperation(op, valueType);

            // No operators exist for the variable and value pair.
            if (_operation == null)
            {
                // If the variable type is any, use default operation.
                if (assignmentToken.TokenType == TokenType.Equal && variableType.Operations.DefaultAssignment && TypeComparison.IsAny(parseInfo.Types, variableType))
                {
                    _operation = new AssignmentOperation(op, parseInfo.Types.Any());
                }
                // Otherwise, add an error.
                else
                {
                    parseInfo.Script.Diagnostics.Error("Operator '" + assignmentToken.Text + "' cannot be applied to the types '" + variableType.GetNameOrAny() + "' and '" + valueType.GetNameOrAny() + "'.", assignmentToken.Range);
                }
            }
        }