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

            //Checking children
            Condition.CheckSemantics(scope, report);
            IfBlock.CheckSemantics(scope, report);
            ElseBlock.CheckSemantics(scope, report);

            if (!Condition.IsOK || !IfBlock.IsOK || !ElseBlock.IsOK)
            {
                return;
            }

            TigerType = IfBlock.TigerType;

            //Checking children types
            if (!TigerType.AreCompatible(Condition.TigerType, TigerType.Int))
            {
                report.AddError(SemanticErrors.InvalidConditionType(Condition, Condition.TigerType));
            }
            if (!TigerType.AreCompatible(IfBlock.TigerType, ElseBlock.TigerType))
            {
                report.AddError(SemanticErrors.IncompatibleIfElseReturnType(ElseBlock, IfBlock.TigerType, ElseBlock.TigerType));
            }
        }