Split IntLiteral into IntLiteral, LongLiteral, BigIntLiteral, ShortLiteral
Closed this issue · 1 comments
KvanTTT commented
All of them should implement INumeric
interface. Also, PatternIntLiteral
and PatternIntRangeLiteral
should match them.
The following properties should be added to corresponding types:
int
→IntLiteral
long
→LongLiteral
BigInteger
→BigIntLiteral
short
→ShortLiteral
Also, maybe it makes sense to consider unsigned literals (ByteLiteral
, UShortLiteral
, etc.)?
Since it's not possible to detect a literal type only basing on value (sometimes the left part with type of assignment is required), the following method can be implemented for numeric parsing:
if (!short.TryParse(text, out short shortValue))
{
if (!int.TryParse(text, out int intValue))
{
if (!long.TryParse(text, out long longValue))
{
if (!BigInteger.TryParse(text, out BigInteger bigInteger))
{
// Not a number
}
return new BigIntLiteral(shortValue, textSpan);
}
return new LongLiteral(shortValue, textSpan);
}
return new IntLiteral(shortValue, textSpan);
}
return new ShortLiteral(shortValue, textSpan);
This task is actual because there are many big numbers in sql files and we should handle them. Moreover, sometimes the difference between long
and int
is valuable for weakness or vulnerability detection. For instance, for implicit conversions.