Пример #1
0
        public override void CheckSemantics(Semantics.Scope scope, List <Semantics.SemanticError> errors)
        {
            //--------------------------------------------------
            // Hacer 'CheckSemantics' A Los Hijos.
            //--------------------------------------------------
            this.LeftVariable.CheckSemantics(scope, errors);
            this.Index.CheckSemantics(scope, errors);

            //--------------------------------------------------
            // ...
            //--------------------------------------------------
            this.ReadOnly = this.LeftVariable.ReadOnly;

            //--------------------------------------------------
            // Poner Por Defecto Que Hay Errores.
            //--------------------------------------------------
            this.ExpressionType = PredefinedTypes.ErrorType;


            //--------------------------------------------------
            // Si Ha Ocurrido Un Error En Alguno De Los Hijos,
            // Parar De Reportar Errores.
            //--------------------------------------------------
            if (this.LeftVariable.ExpressionType == PredefinedTypes.ErrorType ||
                this.Index.ExpressionType == PredefinedTypes.ErrorType)
            {
                return;
            }

            var AT = this.LeftVariable.ExpressionType as ArrayTypeNode;

            //--------------------------------------------------
            // Si La Variable No Es Un Array, Reportar Error.
            //--------------------------------------------------
            if (AT == null)
            {
                errors.Add(SemanticError.InvalidIndexingOperation(this.LeftVariable.ExpressionType, this));
                return;
            }

            //--------------------------------------------------
            // 'Index' Debe Ser De Tipo <int>
            //--------------------------------------------------
            if (this.Index.ExpressionType != PredefinedTypes.IntType)
            {
                errors.Add(SemanticError.InvalidArrayAccess(this.Index));
            }
            else
            {
                this.ExpressionType = AT.ArrayOf;
            }
        }