Exemplo n.º 1
0
        public override void VisitChildren(IVisitor visitor)
        {
            Condition.Visit(visitor);

            IfBody.Visit(visitor);
            ElseBody.Visit(visitor);
        }
Exemplo n.º 2
0
 public void Execute(Scope s)
 {
     if ((bool)Condition.GetValue(s))
     {
         IfBody.Execute(s);
     }
     else
     if (ElseBody != null)
     {
         ElseBody.Execute(s);
     }
 }
        public override void SecondSemanticCheck(List <SemanticError> errors, Scope scope)
        {
            Condition.SecondSemanticCheck(errors, scope);
            IfBody.SecondSemanticCheck(errors, scope);
            ElseBody.SecondSemanticCheck(errors, scope);

            if (Condition.StaticType.Text != "Bool") // AKI AKI AKI
            {
                errors.Add(new SemanticError(Condition.Line, Condition.Column, TypeError.InconsistentType));
            }
            StaticType = SemanticCheck.SemanticCheckAlgoritms.LowerCommonAncestor(IfBody.StaticType, ElseBody.StaticType);
        }
Exemplo n.º 4
0
        public override bool Equals(object other)
        {
            var otherNode = other as IfStmtNode;

            if (null == otherNode)
            {
                return(false);
            }

            return(IfExprNode.Equals(otherNode.IfExprNode) &&
                   otherNode != null && IfBody.SequenceEqual(otherNode.IfBody) &&
                   ElseIfList != null && ElseIfList.SequenceEqual(otherNode.ElseIfList) &&
                   ElseBody != null && ElseBody.SequenceEqual(otherNode.ElseBody));
        }
Exemplo n.º 5
0
        public override string ToString()
        {
            var builder = new StringBuilder();

            builder.Append($"if ({Predicate})\n{{");
            builder.Append(AstUtil.Indent(IfBody.ToString()));

            if (ElseBody != null)
            {
                builder.Append("\n}\nelse\n{");
                builder.Append(AstUtil.Indent(ElseBody.ToString()));
            }

            builder.Append("\n}");

            return(builder.ToString());
        }
        public override void GetIntCode(BuildICCode codeManager)
        {
            var tag = codeManager.codeLines.Count.ToString();

            Condition.GetIntCode(codeManager);

            codeManager.codeLines.Add(new ICCondJump(codeManager.variableManager.PeekCounter(), new ICLabel("_else", tag)));

            IfBody.GetIntCode(codeManager);

            codeManager.codeLines.Add(new ICJump(new ICLabel("_endif", tag)));

            codeManager.codeLines.Add(new ICLabel("_else", tag));

            ElseBody.GetIntCode(codeManager);

            codeManager.codeLines.Add(new ICLabel("_endif", tag));
        }
Exemplo n.º 7
0
        public override Address GenerateCode(List <Instruction> instructions)
        {
            Condition.GenerateCode(instructions);

            Label trueLabel = new Label();

            instructions.Add(new LabelInstruction(trueLabel));
            IfBody.GenerateCode(instructions);

            JumpInstruction doneJump = new JumpInstruction(null);

            NextInstructionsToBackpatch.Add(doneJump);
            instructions.Add(doneJump);

            Label falseLabel = new Label();

            instructions.Add(new LabelInstruction(falseLabel));
            ElseBody.GenerateCode(instructions);
            ElseBody.NextInstructionsToBackpatch.AddRange(NextInstructionsToBackpatch);

            Condition.Backpatch(trueLabel, falseLabel);

            return(base.GenerateCode(instructions));
        }
Exemplo n.º 8
0
 public override string ToString()
 {
     return($@"if ({Condition.ToString()}) {IfBody.ToString()} else {ElseBody.ToString()}");
 }