コード例 #1
0
        public override void EnterStructIncr(LatteParser.StructIncrContext context)
        {
            var objectType = new ExpressionTypeVisitor().GetFieldType(context.expr(), context.ID().GetText(), context.start.Line);

            if (!objectType.Equals(new LatteParser.TIntContext()))
            {
                StateUtils.InterruptWithMessage(
                    context.start.Line,
                    context.ID().Symbol.Column,
                    ErrorMessages.DecrFieldOnlyOnInt(objectType.GetText(), context.ID().GetText()));
            }
        }
コード例 #2
0
        public override void EnterStructAss(LatteParser.StructAssContext context)
        {
            var expressionVisitor = new ExpressionTypeVisitor();
            var objectType        = expressionVisitor.GetFieldType(context.expr()[0], context.ID().GetText(), context.start.Line);
            var exprType          = new ExpressionTypeVisitor().Visit(context.expr()[1]);

            if (!objectType.Equals(exprType) && !IsTypeParent(exprType, objectType))
            {
                StateUtils.InterruptWithMessage(
                    context.start.Line,
                    context.ID().Symbol.Column,
                    ErrorMessages.FieldExprTypesMismatch(objectType.GetText(), context.ID().GetText()));
            }
        }
コード例 #3
0
        public override void EnterDecl(LatteParser.DeclContext context)
        {
            if (context.type().Equals(new LatteParser.TVoidContext()))
            {
                StateUtils.InterruptWithMessage(
                    context.start.Line,
                    context.start.Column,
                    ErrorMessages.VoidDeclaration);
            }

            foreach (var decl in context.item())
            {
                var id = decl.ID().GetText();
                if (_environment.NameToVarDef.ContainsKey(id) &&
                    _environment.NameToVarDef[id].IsDefinedInCurrentBlock)
                {
                    _errorState.AddErrorMessage(new ErrorMessage(
                                                    decl.start.Line,
                                                    decl.start.Column,
                                                    ErrorMessages.VarAlreadyDefined(id)));
                }

                if (_skipNextDecl)
                {
                    _skipNextDecl = false;
                }
                else
                {
                    _environment.NameToVarDef[id] = new VarDef(context.type(), id);
                }

                if (decl.expr() == null)
                {
                    continue;
                }

                var exprType = new ExpressionTypeVisitor().Visit(decl.expr());
                if (!context.type().Equals(exprType) && !IsTypeParent(exprType, context.type()))
                {
                    StateUtils.InterruptWithMessage(
                        decl.start.Line,
                        decl.start.Column,
                        ErrorMessages.VarExprTypesMismatch(decl.ID().GetText()));
                }
            }
        }
コード例 #4
0
        public override void EnterAss(LatteParser.AssContext context)
        {
            var id = context.ID().GetText();

            if (!_environment.NameToVarDef.ContainsKey(id))
            {
                StateUtils.InterruptWithMessage(
                    context.start.Line,
                    context.ID().Symbol.Column,
                    ErrorMessages.VarNotDefined(id));
            }

            var variable = _environment.NameToVarDef[id];
            var exprType = new ExpressionTypeVisitor().Visit(context.expr());

            if (!variable.Type.Equals(exprType) && !IsTypeParent(exprType, variable.Type))
            {
                StateUtils.InterruptWithMessage(
                    context.start.Line,
                    context.ID().Symbol.Column,
                    ErrorMessages.VarExprTypesMismatch(id));
            }
        }