public override void GetIntCode(BuildICCode codeManager) { codeManager.variableManager.PushCounter(); foreach (var attr in this.Sentences) { codeManager.variableManager.IncreaseCounter(); codeManager.variableManager.Push(attr.Formal.Id.Text, attr.Formal.Type.Text); codeManager.variableManager.PushCounter(); attr.GetIntCode(codeManager); } codeManager.variableManager.IncreaseCounter(); Body.GetIntCode(codeManager); foreach (var attr in Sentences) { codeManager.variableManager.Pop(attr.Formal.Id.Text); } codeManager.variableManager.PopCounter(); if (codeManager.special_object_return_type) { codeManager.SetReturnType(StaticType.Text); } }
public override void GetIntCode(BuildICCode codeManager) { if (LeftOperand is IntegerNode && RightOperand is IntegerNode) { int v = 0; switch (Symbol) { case "+": v = ((IntegerNode)LeftOperand).Value + ((IntegerNode)RightOperand).Value; break; case "-": v = ((IntegerNode)LeftOperand).Value - ((IntegerNode)RightOperand).Value; break; case "*": v = ((IntegerNode)LeftOperand).Value * ((IntegerNode)RightOperand).Value; break; case "/": v = ((IntegerNode)LeftOperand).Value / ((IntegerNode)RightOperand).Value; break; } codeManager.codeLines.Add(new ICAssignConstToVar(codeManager.variableManager.PeekCounter(), v)); } else { codeManager.BinaryOperationCheck(this); } if (codeManager.special_object_return_type) { codeManager.SetReturnType("Int"); } }
public override void GetIntCode(BuildICCode codeManager) { codeManager.UnaryOperationCheck(this); if (codeManager.special_object_return_type) { codeManager.SetReturnType("Int"); } }
public override void GetIntCode(BuildICCode codeManager) { codeManager.codeLines.Add(new ICAssignConstToVar(codeManager.variableManager.PeekCounter(), Value)); if (codeManager.special_object_return_type) { codeManager.SetReturnType("Int"); } }
public override void GetIntCode(BuildICCode codeManager) { if (Operand.StaticType.Text == "Int" || Operand.StaticType.Text == "String" || Operand.StaticType.Text == "Bool") { codeManager.codeLines.Add(new ICAssignConstToVar(codeManager.variableManager.PeekCounter(), 0)); } else { codeManager.UnaryOperationCheck(this); } if (codeManager.special_object_return_type) { codeManager.SetReturnType("Bool"); } }
public override void GetIntCode(BuildICCode codeManager) { var(x, type) = codeManager.variableManager.Peek(Text); if (x != -1) { codeManager.codeLines.Add(new ICAssignVarToVar(codeManager.variableManager.PeekCounter(), x)); } else { codeManager.codeLines.Add(new ICAssignMemToVar(codeManager.variableManager.PeekCounter(), 0, codeManager.virtualTable.getOffset(codeManager.variableManager.ClassName, Text))); } if (codeManager.special_object_return_type) { codeManager.SetReturnType(type); } }
public override void GetIntCode(BuildICCode codeManager) { if (Type.Text == "Int" || Type.Text == "Bool") { codeManager.codeLines.Add(new ICAssignConstToVar(codeManager.variableManager.PeekCounter(), 0)); } else if (Type.Text == "String") { codeManager.codeLines.Add(new ICAssignStrToVar(codeManager.variableManager.PeekCounter(), "")); } else { int s = codeManager.virtualTable.SizeOf(Type.Text); codeManager.codeLines.Add(new ICAllocation(codeManager.variableManager.PeekCounter(), s)); codeManager.codeLines.Add(new ICPushParams(codeManager.variableManager.PeekCounter())); codeManager.codeLines.Add(new ICCallLabel(new ICLabel(Type.Text, "ctor"))); codeManager.codeLines.Add(new ICPopParams(1)); } if (codeManager.special_object_return_type) { codeManager.SetReturnType(Type.Text); } }