private void CheckWhileStatement(ASTWhileStatementNode whileNode) { //check condition type CheckImplicitCast(whileNode.Condition, typeof(bool)); CheckExpression(whileNode.Condition); //CheckImplicitCast(whileNode.Condition, typeof(bool)); if (whileNode.Body != null) { //check infinity loop or dead code if (ASTExprHelper.IsValuable(whileNode.Condition)) { //infinity loop if (Convert.ToBoolean(ASTExprHelper.GetValue(whileNode.Condition))) { _messages.Add(new MessageRecord( MsgCode.InfinityLoop, whileNode.Body.SourcePath, whileNode.Body.StartLine, whileNode.Body.StartPos )); } else //unreachable code { _messages.Add(new MessageRecord( MsgCode.UnreachableCode, whileNode.Body.SourcePath, whileNode.Body.StartLine, whileNode.Body.StartPos )); } } //body check _inLoop = true; CheckBody(whileNode.Body); _inLoop = false; } else { _messages.Add(new MessageRecord( MsgCode.EmptyBody, whileNode.SourcePath, whileNode.StartLine, whileNode.StartPos )); } }
private void CheckIfStatement(ASTIfStatementNode ifNode) { CheckExpression(ifNode.Condition); CheckImplicitCast(ifNode.Condition, typeof(bool)); //TODO: сначала высчитывать условие а потом смотреть тела if (ASTExprHelper.IsValuable(ifNode.Condition)) { var isTrue = Convert.ToBoolean(ASTExprHelper.GetValue(ifNode.Condition)); //permanetnly true if (isTrue) { if (ifNode.TrueBody != null) { _messages.Add(new MessageRecord( MsgCode.PermanentlyExecution, ifNode.TrueBody.SourcePath, ifNode.TrueBody.StartLine, ifNode.TrueBody.StartPos )); } if (ifNode.ElseBody != null) { _messages.Add(new MessageRecord( MsgCode.UnreachableCode, ifNode.ElseBody.SourcePath, ifNode.ElseBody.StartLine, ifNode.ElseBody.StartPos )); } } else //permanently false { if (ifNode.TrueBody != null) { _messages.Add(new MessageRecord( MsgCode.UnreachableCode, ifNode.TrueBody.SourcePath, ifNode.TrueBody.StartLine, ifNode.TrueBody.StartPos )); } if (ifNode.ElseBody != null) { _messages.Add(new MessageRecord( MsgCode.PermanentlyExecution, ifNode.ElseBody.SourcePath, ifNode.ElseBody.StartLine, ifNode.ElseBody.StartPos )); } } } if (ifNode.TrueBody != null) { CheckBody(ifNode.TrueBody); } if (ifNode.ElseBody != null) { CheckBody(ifNode.ElseBody); } }