public LuaCondition(int line, Type type, Prefix prefix = Prefix.none, LuaCondition master = null) { this.line = line; this.type = type; this.prefix = prefix; this.master = master; }
public string BuildExpression(LuaCondition masterCondition) { string Expression = ProcessInstructionReturnString(); nextInstruction(); int ChildExpressions = 0; foreach (LuaCondition condition in this.conditions) { if (condition.master == masterCondition) { ChildExpressions++; } } while (ChildExpressions > 0 && this.instructionPtr < this.sizecode) { bool done = false; currentInstruction = this.Instructions[instructionPtr]; foreach (LuaCondition condition in this.conditions) { if (condition.master == masterCondition && condition.line == this.instructionPtr) { Expression += String.Format(" {0} ", condition.prefix); Expression += ProcessInstructionReturnString(); ChildExpressions--; done = true; } } if (!done) { ProcessInstructionReturnString(); } nextInstruction(); } return(Expression); }
public void FindIfStatements() { int lines = -1; LuaCondition master = null; for (int i = 0; i < this.sizecode; i++) { if (this.Instructions[i].OpCode == LuaOpCode.OpCodes.HKS_OPCODE_JMP && this.Instructions[i].visited == false) { // Make sure the skip goes forward if (this.Instructions[i].sBx >= 0) { if (LuaOpCode.isConditionOPCode(this, i - 1)) { // Skip the while loops if (this.Instructions[i + this.Instructions[i].sBx].OpCode == LuaOpCode.OpCodes.HKS_OPCODE_JMP && this.Instructions[i + this.Instructions[i].sBx].sBx < 0) { continue; } // OR statement if (lines == 0) { this.conditions.Add(new LuaCondition(i - 1, LuaCondition.Type.If, LuaCondition.Prefix.or, master)); this.Instructions[i].visited = true; lines--; continue; } // and statement if (lines == this.Instructions[i].sBx) { this.conditions.Add(new LuaCondition(i - 1, LuaCondition.Type.If, LuaCondition.Prefix.and, master)); this.Instructions[i].visited = true; lines--; continue; } master = new LuaCondition(i - 1, LuaCondition.Type.If, LuaCondition.Prefix.none); this.conditions.Add(master); lines = this.Instructions[i].sBx; this.Instructions[i].visited = true; } } } lines--; } List <LuaCondition> newConditions = new List <LuaCondition>(); foreach (LuaCondition condition in this.conditions) { if (condition.master == null) { LuaCondition lastSon = condition; foreach (LuaCondition conditionSon in this.conditions) { if (conditionSon.master == condition) { if (conditionSon.prefix == LuaCondition.Prefix.or) { if (this.Instructions[lastSon.line].A == 1) { this.Instructions[lastSon.line].A = 0; } else { this.Instructions[lastSon.line].A = 1; } } lastSon = conditionSon; } } int skipLines = this.Instructions[lastSon.line + 1].sBx; if (this.Instructions[lastSon.line + 1 + skipLines].OpCode == LuaOpCode.OpCodes.HKS_OPCODE_JMP) { newConditions.Add(new LuaCondition(lastSon.line + 1 + skipLines, LuaCondition.Type.Else)); int skipElseLines = this.Instructions[lastSon.line + 1 + skipLines].sBx; newConditions.Add(new LuaCondition(lastSon.line + 1 + skipLines + skipElseLines, LuaCondition.Type.End)); } else { newConditions.Add(new LuaCondition(lastSon.line + 1 + skipLines, LuaCondition.Type.End)); } } } foreach (LuaCondition condition in newConditions) { this.conditions.Add(condition); } }