summaryrefslogtreecommitdiff
path: root/src/shared/cplusplus/Literals.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-07-10 17:00:19 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2009-07-10 17:08:15 +0200
commitd685437d74dc11666e3b8e9f5c47acbaeb66ab13 (patch)
tree29b9545e0157467e8eb94547188d669ba94d9e9d /src/shared/cplusplus/Literals.cpp
parent7356280cf712d335be551b7b41087718f1908a6e (diff)
downloadqt-creator-d685437d74dc11666e3b8e9f5c47acbaeb66ab13.tar.gz
Recognize the numeric literals.
Diffstat (limited to 'src/shared/cplusplus/Literals.cpp')
-rw-r--r--src/shared/cplusplus/Literals.cpp96
1 files changed, 94 insertions, 2 deletions
diff --git a/src/shared/cplusplus/Literals.cpp b/src/shared/cplusplus/Literals.cpp
index 0f21e379cf..bf243373ec 100644
--- a/src/shared/cplusplus/Literals.cpp
+++ b/src/shared/cplusplus/Literals.cpp
@@ -105,13 +105,105 @@ StringLiteral::~StringLiteral()
{ }
////////////////////////////////////////////////////////////////////////////////
+enum {
+ NumericLiteralIsChar,
+ NumericLiteralIsWideChar,
+ NumericLiteralIsInt,
+ NumericLiteralIsFloat,
+ NumericLiteralIsDouble,
+ NumericLiteralIsLongDouble,
+ NumericLiteralIsLong,
+ NumericLiteralIsLongLong,
+};
+
NumericLiteral::NumericLiteral(const char *chars, unsigned size)
- : Literal(chars, size)
-{ }
+ : Literal(chars, size), _flags(0)
+{
+ _type = NumericLiteralIsInt;
+
+ if (chars[0] == '\'') {
+ _type = NumericLiteralIsChar;
+ } else if (size > 1 && chars[0] == 'L' && chars[1] == '\'') {
+ _type = NumericLiteralIsWideChar;
+ } else if (size > 1 && chars[0] == '0' && (chars[1] == 'x' || chars[1] == 'X')) {
+ _isHex = true;
+ } else {
+ const char *begin = chars;
+ const char *end = begin + size;
+
+ bool done = false;
+ const char *it = end - 1;
+
+ for (; it != begin - 1 && ! done; --it) {
+ switch (*it) {
+ case 'l': case 'L': // long suffix
+ case 'u': case 'U': // unsigned suffix
+ case 'f': case 'F': // floating suffix
+ break;
+
+ default:
+ done = true;
+ break;
+ } // switch
+ }
+
+ for (const char *dot = it; it != begin - 1; --it) {
+ if (*dot == '.')
+ _type = NumericLiteralIsDouble;
+ }
+
+ for (++it; it != end; ++it) {
+ if (*it == 'l' || *it == 'L') {
+ if (_type == NumericLiteralIsDouble) {
+ _type = NumericLiteralIsLongDouble;
+ } else if (it + 1 != end && (it[1] == 'l' || it[1] == 'L')) {
+ ++it;
+ _type = NumericLiteralIsLongLong;
+ } else {
+ _type = NumericLiteralIsLong;
+ }
+ } else if (*it == 'f' || *it == 'F') {
+ _type = NumericLiteralIsFloat;
+ } else if (*it == 'u' || *it == 'U') {
+ _isUnsigned = true;
+ }
+ }
+ }
+}
NumericLiteral::~NumericLiteral()
{ }
+bool NumericLiteral::isHex() const
+{ return _isHex; }
+
+bool NumericLiteral::isUnsigned() const
+{ return _isUnsigned; }
+
+bool NumericLiteral::isChar() const
+{ return _type == NumericLiteralIsChar; }
+
+bool NumericLiteral::isWideChar() const
+{ return _type == NumericLiteralIsWideChar; }
+
+bool NumericLiteral::isInt() const
+{ return _type == NumericLiteralIsInt; }
+
+bool NumericLiteral::isFloat() const
+{ return _type == NumericLiteralIsFloat; }
+
+bool NumericLiteral::isDouble() const
+{ return _type == NumericLiteralIsDouble; }
+
+bool NumericLiteral::isLongDouble() const
+{ return _type == NumericLiteralIsLongDouble; }
+
+bool NumericLiteral::isLong() const
+{ return _type == NumericLiteralIsLong; }
+
+bool NumericLiteral::isLongLong() const
+{ return _type == NumericLiteralIsLongLong; }
+
////////////////////////////////////////////////////////////////////////////////
Identifier::Identifier(const char *chars, unsigned size)
: Literal(chars, size)