@@ -9,6 +9,9 @@ module Cpp14Literal {
99 /** An numeric literal. */
1010 abstract class NumericLiteral extends StandardLibrary:: Literal { }
1111
12+ /** Convenience for implementing class `UnrecognizedNumericLiteral` */
13+ abstract private class RecognizedNumericLiteral extends StandardLibrary:: Literal { }
14+
1215 /** An integer literal. */
1316 abstract class IntegerLiteral extends NumericLiteral {
1417 predicate isSigned ( ) { not isUnsigned ( ) }
@@ -23,7 +26,7 @@ module Cpp14Literal {
2326 * ```
2427 * Octal literals must always start with the digit `0`.
2528 */
26- class OctalLiteral extends IntegerLiteral {
29+ class OctalLiteral extends IntegerLiteral , RecognizedNumericLiteral {
2730 OctalLiteral ( ) { getValueText ( ) .regexpMatch ( "\\s*0[0-7']*[uUlL]*\\s*" ) }
2831
2932 override string getAPrimaryQlClass ( ) { result = "OctalLiteral" }
@@ -35,7 +38,7 @@ module Cpp14Literal {
3538 * unsigned int32_t minus2 = 0xfffffffe;
3639 * ```
3740 */
38- class HexLiteral extends IntegerLiteral {
41+ class HexLiteral extends IntegerLiteral , RecognizedNumericLiteral {
3942 HexLiteral ( ) { getValueText ( ) .regexpMatch ( "\\s*0[xX][0-9a-fA-F']+[uUlL]*\\s*" ) }
4043
4144 override string getAPrimaryQlClass ( ) { result = "HexLiteral" }
@@ -47,7 +50,7 @@ module Cpp14Literal {
4750 * unsigned int32_t binary = 0b101010;
4851 * ```
4952 */
50- class BinaryLiteral extends IntegerLiteral {
53+ class BinaryLiteral extends IntegerLiteral , RecognizedNumericLiteral {
5154 BinaryLiteral ( ) { getValueText ( ) .regexpMatch ( "\\s*0[bB][0-1']*[uUlL]*\\s*" ) }
5255
5356 override string getAPrimaryQlClass ( ) { result = "BinaryLiteral" }
@@ -59,7 +62,7 @@ module Cpp14Literal {
5962 * unsigned int32_t decimal = 10340923;
6063 * ```
6164 */
62- class DecimalLiteral extends IntegerLiteral {
65+ class DecimalLiteral extends IntegerLiteral , RecognizedNumericLiteral {
6366 DecimalLiteral ( ) { getValueText ( ) .regexpMatch ( "\\s*[1-9][0-9']*[uUlL]*\\s*" ) }
6467
6568 override string getAPrimaryQlClass ( ) { result = "DecimalLiteral" }
@@ -71,7 +74,7 @@ module Cpp14Literal {
7174 * double floating = 1.340923e-19;
7275 * ```
7376 */
74- class FloatingLiteral extends NumericLiteral {
77+ class FloatingLiteral extends RecognizedNumericLiteral {
7578 FloatingLiteral ( ) {
7679 getValueText ( ) .regexpMatch ( "\\s*[0-9][0-9']*(\\.[0-9']+)?([eE][\\+\\-]?[0-9']+)?[flFL]?\\s*" ) and
7780 // A decimal literal takes precedent
@@ -83,6 +86,23 @@ module Cpp14Literal {
8386 override string getAPrimaryQlClass ( ) { result = "FloatingLiteral" }
8487 }
8588
89+ /**
90+ * Literal values with conversions and macros cannot always be trivially
91+ * parsed from `Literal.getValueText()`, and have loss of required
92+ * information in `Literal.getValue()`. This class covers cases that appear
93+ * to be `NumericLiteral`s but cannot be determined to be a hex, decimal,
94+ * octal, binary, or float literal, but still are parsed as a Literal with a
95+ * number value.
96+ */
97+ class UnrecognizedNumericLiteral extends NumericLiteral {
98+ UnrecognizedNumericLiteral ( ) {
99+ this .getValue ( ) .regexpMatch ( "[0-9.e]+" ) and
100+ not this instanceof RecognizedNumericLiteral
101+ }
102+ }
103+
104+ predicate test ( RecognizedNumericLiteral r , string valueText ) { valueText = r .getValueText ( ) }
105+
86106 /**
87107 * A character literal. For example:
88108 * ```
0 commit comments