Esempio n. 1
0
        public void Visit(IsVoidNode node)
        {
            node.Operand.Accept(this);

            if (!scope.IsDefinedType("Bool", out node.StaticType))
            {
                errors.Add(SemanticError.NotDeclaredType(new TypeNode(node.Line, node.Column, "Bool")));
            }
        }
Esempio n. 2
0
        public void Visit(IsVoidNode node)
        {
            node.expr.Accept(this);

            if (!scope.IsDefinedType("Bool", out node.staticType))
            {
                errors.Add(ErrorSemantic.NotDeclaredType(new TypeNode(node.line, node.column, "Bool")));
            }
        }
        public override ASTN VisitIsvoid([NotNull] IsvoidContext context)
        {
            IsVoidNode node = new IsVoidNode(context)
            {
                expr = VisitExpr(context.expr()) as ExprNode
            };

            return(node);
        }
        public void GenerateCode(IsVoidNode node, ICIL_CodeGenerator codeGenerator)
        {
            //eval (expr)
            //rholder= true
            //if expr is -1 goto END
            //rholder=false
            //END

            node.Holder = codeGenerator.DefineVariable();
            codeGenerator.AddLocalVariable(new CIL_LocalVariable((Variable)node.Holder));
            codeGenerator.AddInstruction(
                new Allocate((Variable)node.Holder, $"{BuiltIn.Bool}"));

            GenerateCode(node.Expression, codeGenerator);

            var boolean = codeGenerator.DefineVariable();

            codeGenerator.AddLocalVariable(new CIL_LocalVariable(boolean));
            codeGenerator.AddInstruction(new Assign(boolean, true));

            codeGenerator.AddInstruction(
                new SetAttr((Variable)node.Holder, $"{Attribute.Bool_value}", boolean));

            var typeExpr = codeGenerator.DefineVariable();

            codeGenerator.AddLocalVariable(new CIL_LocalVariable(typeExpr));
            codeGenerator.AddInstruction(
                new TypeOf(typeExpr, (Variable)node.Expression.Holder));

            var condition = codeGenerator.DefineVariable();

            codeGenerator.AddLocalVariable(new CIL_LocalVariable(condition));

            codeGenerator.AddInstruction(
                new CilEqualValue(condition, typeExpr, -1));

            var end = codeGenerator.DefineLabel();

            codeGenerator.AddInstruction(
                new ConditionalJump(condition, true, end));

            codeGenerator.AddInstruction(
                new Assign(boolean, false));

            codeGenerator.AddInstruction(
                new SetAttr((Variable)node.Holder, $"{Attribute.Bool_value}", boolean));

            codeGenerator.AddInstruction(
                new Label(end));
        }
Esempio n. 5
0
        public void Visit(IsVoidNode node)
        {
            //if special types non void;
            if (node.Operand.StaticType.Text == "Int" ||
                node.Operand.StaticType.Text == "String" ||
                node.Operand.StaticType.Text == "Bool")
            {
                IC.Add(new AssignmentConstantToVariable(VariableManager.PeekVariableCounter(), 0));
            }
            else
            {
                UnaryOperationVisit(node);
            }

            if (special_object_return_type)
            {
                SetReturnType("Bool");
            }
        }
        public void Visit(IsVoidNode node)
        {
            //if special types non void;
            var s_type = node.expr.staticType.Text;

            if (s_type == "Int" || s_type == "String" || s_type == "Bool")
            {
                Code.Add(new AssignConstToVarCodeLine(VariableManager.PeekVariableCounter(), 0));
            }
            else
            {
                Visit(node as UnaryNode);
            }

            if (object_return_type)
            {
                Code.Add(new AssignStrToVarCodeLine(return_type, "Bool"));
            }
        }
Esempio n. 7
0
 public void CheckSemantic(IsVoidNode node, IScope scope = null)
 {
     CheckSemantic(node.Expression, scope);
     TypeTable.IsDefinedType("Bool", out var booleanType);
     node.ComputedType = booleanType;
 }
Esempio n. 8
0
 public void Visit(IsVoidNode node)
 {
     throw new NotImplementedException();
 }