예제 #1
0
        public void VisitArrayAssignNode(ArrayAssignStatement node)
        {
            node.IndexExpression.Accept(this);
            node.AssignValueExpression.Accept(this);
            node.IDNode.Accept(this);

            TokenType exprEval = node.AssignValueExpression.EvaluationType;

            Property prop = node.IDNode.Scope.GetProperty(node.IDNode.IDNode.ID);

            if (node.IDNode.Scope.GetProperty(node.IDNode.IDNode.ID).GetTokenType() != TokenType.TYPE_ARRAY)
            {
                analyzer.notifyError(new IllegalAssignmentError(node));
            }
            else
            {
                ArrayProperty arrProp = (ArrayProperty)prop;

                if (prop.DeclarationRow > node.Token.Row)
                {
                    analyzer.notifyError(new UndeclaredVariableError(node.IDNode));
                }

                if (!LegitOperationChecker.isAssignCompatible(arrProp.ArrayElementType, exprEval))
                {
                    analyzer.notifyError(new IllegalTypeError(node));
                }

                if (!LegitOperationChecker.CanBeAssignedTo(arrProp.ArrayElementType, exprEval))
                {
                    analyzer.notifyError(new IllegalAssignmentError(node));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Checks the static semantic constraints of an AssignNode.
        /// </summary>
        /// <returns>An void.</returns>
        /// <param name="node">Node.</param>
        public void VisitAssignNode(AssignNode node)
        {
            node.IDNode.Accept(this);
            node.AssignValueExpression.Accept(this);
            bool errored = false;

            TokenType varEval  = node.IDNode.EvaluationType;
            TokenType exprEval = node.AssignValueExpression.EvaluationType;

            bool     assignable  = node.IDNode.EvaluationType != TokenType.ERROR;
            Property varProperty = node.Scope.GetProperty(node.IDNode.IDNode.ID);

            if (varProperty.DeclarationRow > node.Token.Row)
            {
                analyzer.notifyError(new UndeclaredVariableError(node.IDNode));
                assignable = false;
                errored    = true;
            }

            if (!LegitOperationChecker.isAssignCompatible(varEval, exprEval) && !errored)
            {
                analyzer.notifyError(new IllegalAssignmentError(node));
                assignable = false;
                errored    = true;
            }

            if (!LegitOperationChecker.CanBeAssignedTo(varEval, exprEval) && !errored)
            {
                analyzer.notifyError(new IllegalAssignmentError(node));
                assignable = false;
                errored    = true;
            }

            if (assignable)
            {
                varProperty.Assigned = true;
            }
        }