@@ -186,24 +186,21 @@ private predicate trivialIntValue(string s) {
186186 exists ( string pos | trivialPositiveIntValue ( pos ) and s = "-" + pos )
187187}
188188
189- private predicate intTrivial ( Literal lit ) {
190- exists ( string v | trivialIntValue ( v ) and v = lit .getLiteral ( ) )
189+ private predicate intTrivial ( IntegerLiteral lit ) {
190+ // Remove all `_` from literal, if any (e.g. `1_000_000`)
191+ exists ( string v | trivialIntValue ( v ) and v = lit .getLiteral ( ) .replaceAll ( "_" , "" ) )
191192}
192193
193- private predicate longTrivial ( Literal lit ) {
194- exists ( string v | trivialIntValue ( v ) and v + "L" = lit .getLiteral ( ) )
194+ private predicate longTrivial ( LongLiteral lit ) {
195+ exists ( string v |
196+ trivialIntValue ( v ) and
197+ // Remove all `_` from literal, if any (e.g. `1_000_000L`)
198+ v + [ "l" , "L" ] = lit .getLiteral ( ) .replaceAll ( "_" , "" )
199+ )
195200}
196201
197202private predicate powerOfTen ( float f ) {
198- f = 10 or
199- f = 100 or
200- f = 1000 or
201- f = 10000 or
202- f = 100000 or
203- f = 1000000 or
204- f = 10000000 or
205- f = 100000000 or
206- f = 1000000000
203+ f = [ 10 , 100 , 1000 , 10000 , 100000 , 1000000 , 10000000 , 100000000 , 1000000000 ]
207204}
208205
209206private predicate floatTrivial ( Literal lit ) {
@@ -244,7 +241,7 @@ private predicate literalIsConstantInitializer(Literal literal, Field f) {
244241}
245242
246243private predicate nonTrivialValue ( string value , Literal literal , string context ) {
247- value = literal .getLiteral ( ) and
244+ value = literal .getValue ( ) and
248245 not trivial ( literal ) and
249246 not literalIsConstantInitializer ( literal , _) and
250247 not literal .getParent * ( ) instanceof ArrayInit and
@@ -259,7 +256,7 @@ private predicate valueOccurrenceCount(string value, int n, string context) {
259256
260257private predicate occurenceCount ( Literal lit , string value , int n , string context ) {
261258 valueOccurrenceCount ( value , n , context ) and
262- value = lit .getLiteral ( ) and
259+ value = lit .getValue ( ) and
263260 nonTrivialValue ( _, lit , context )
264261}
265262
@@ -296,14 +293,7 @@ private predicate firstOccurrence(Literal lit, string value, string context, int
296293 )
297294}
298295
299- predicate isNumber ( Literal lit ) {
300- lit .getType ( ) .getName ( ) = "char" or
301- lit .getType ( ) .getName ( ) = "short" or
302- lit .getType ( ) .getName ( ) = "int" or
303- lit .getType ( ) .getName ( ) = "long" or
304- lit .getType ( ) .getName ( ) = "float" or
305- lit .getType ( ) .getName ( ) = "double"
306- }
296+ predicate isNumber ( Literal lit ) { lit .getType ( ) instanceof NumericOrCharType }
307297
308298predicate magicConstant ( Literal e , string msg ) {
309299 exists ( string value , int n , string context |
@@ -320,7 +310,7 @@ predicate magicConstant(Literal e, string msg) {
320310
321311private predicate relevantField ( Field f , string value ) {
322312 exists ( Literal lit |
323- not trivial ( lit ) and value = lit .getLiteral ( ) and literalIsConstantInitializer ( lit , f )
313+ not trivial ( lit ) and value = lit .getValue ( ) and literalIsConstantInitializer ( lit , f )
324314 )
325315}
326316
@@ -344,7 +334,7 @@ private predicate candidateConstantForLiteral(
344334 exists ( Literal initLiteral |
345335 literalIsConstantInitializer ( initLiteral , constField ) and
346336 exists ( string value |
347- value = initLiteral .getLiteral ( ) and
337+ value = initLiteral .getValue ( ) and
348338 nonTrivialValue ( value , magicLiteral , context ) and
349339 fieldUsedInContext ( constField , context )
350340 ) and
0 commit comments