特定のコード行で変数の可能な値の範囲を決定する必要があります。複雑なプロジェクトでは、これは非常に面倒でエラーが発生しやすくなります。そのため、このタスクを自動化する可能性を模索しています。次の簡単なコード スニペットを想像してみてください。
#define checkBoundary(value) if((value)<100 || (value)> 1000) return;
bool checkmaximumForMode0(value)
{
return (value>100);
}
void main(void)
{
int mode = rand()%4;
// x shall be any valid value for an int, just for the sake of completion i use rand here.
int x = rand();
if (x < 0)
return;
switch(mode)
{
case 0:
if(checkmaximumForMode0(x)) return;
case 1:
checkBoundary(x);
default:
if (x<10000)
goto exit;
}
// Now i want to know, which value range of x will i have under what circumstances
int isChecked = x;
// For this easy example:
// Codepath 1(mode = 0): x >= 0 && x <= 100
// Codepath 2(mode = 1): x >= 100 && x <= 1000
// Codepath 3(mode = 2..3): x >= 10000 && x <= maxint
exit:
print( "Exiting");
return
}
このタスクを完全に達成するためのツールまたはその他の方法を知っている人はいますか? さらに、結果の値の範囲を特定の値の範囲のセットに対してチェックし、理想的には結果として非互換性のみを取得したいと考えています。