示例#1
0
        public override void CheckSemantics(TigerScope scope, Report report)
        {
            ContainingScope = scope;

            //Checking Children
            TypeNode.CheckSemantics(scope, report);
            LengthExpressionNode.CheckSemantics(scope, report);
            InitialValueExpressionNode.CheckSemantics(scope, report);

            if (!TypeNode.IsOK || !LengthExpressionNode.IsOK || !InitialValueExpressionNode.IsOK)
            {
                return;
            }

            var type = TypeNode.TigerType as ArrayType;

            if (type == null)
            {
                report.AddError(SemanticErrors.NonArrayType(TypeNode, TypeNode.TigerType));
                return;
            }

            TigerType = TypeNode.TigerType;

            //Checking LengthExpression type
            if (!TigerType.AreCompatible(LengthExpressionNode.TigerType, TigerType.Int))
            {
                report.AddError(SemanticErrors.NonIntegerArrayLength(LengthExpressionNode,
                                                                     LengthExpressionNode.TigerType));
            }

            //Checking InitialValueExpression
            if (!type.ContentType.Assignable(InitialValueExpressionNode.TigerType))
            {
                report.AddError(SemanticErrors.ArrayInitialValueInvalidType(InitialValueExpressionNode,
                                                                            InitialValueExpressionNode.TigerType, TypeNode.TigerType));
            }
        }