Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
d685437d
Commit
d685437d
authored
Jul 10, 2009
by
Roberto Raggi
Browse files
Recognize the numeric literals.
parent
7356280c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/shared/cplusplus/Literals.cpp
View file @
d685437d
...
...
@@ -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
)
...
...
src/shared/cplusplus/Literals.h
View file @
d685437d
...
...
@@ -101,6 +101,29 @@ class CPLUSPLUS_EXPORT NumericLiteral: public Literal
public:
NumericLiteral
(
const
char
*
chars
,
unsigned
size
);
virtual
~
NumericLiteral
();
bool
isChar
()
const
;
bool
isWideChar
()
const
;
bool
isInt
()
const
;
bool
isFloat
()
const
;
bool
isDouble
()
const
;
bool
isLongDouble
()
const
;
bool
isLong
()
const
;
bool
isLongLong
()
const
;
bool
isUnsigned
()
const
;
bool
isHex
()
const
;
private:
union
{
unsigned
_flags
;
struct
{
unsigned
_type
:
8
;
unsigned
_isHex
:
1
;
unsigned
_isUnsigned
:
1
;
};
};
};
class
CPLUSPLUS_EXPORT
Identifier
:
public
Literal
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment