diff options
author | Erik Verbruggen <erik.verbruggen@nokia.com> | 2012-03-26 15:18:01 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@nokia.com> | 2012-03-29 14:28:17 +0200 |
commit | 60db5736604583fe99dde3c25412d97f9b77489d (patch) | |
tree | 2f5bf1342086232de0570500fd440a98eb12cb96 /src/libs/cplusplus/PPToken.cpp | |
parent | 159058d9eb7ab233f94cc6a0a5b0e7e8f691a041 (diff) | |
download | qt-creator-60db5736604583fe99dde3c25412d97f9b77489d.tar.gz |
[C++] Rewrite of the preprocessor.
This rewrite fixes a couple of issues with the pre-processor. It now
supports:
- macros in macro bodies
- stringification of parameters [cpp.stringize]
- the concatenation operator [cpp.concat]
- #include MACRO_HERE
- defined() inside macro bodies used in pp-conditions.
Change-Id: Ifdb78041fb6afadf44f939a4bd66ce2832b8601f
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/libs/cplusplus/PPToken.cpp')
-rw-r--r-- | src/libs/cplusplus/PPToken.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libs/cplusplus/PPToken.cpp b/src/libs/cplusplus/PPToken.cpp new file mode 100644 index 0000000000..80577ab6cf --- /dev/null +++ b/src/libs/cplusplus/PPToken.cpp @@ -0,0 +1,45 @@ +#include "PPToken.h" + +#include <cstring> + +using namespace CPlusPlus::Internal; + +ByteArrayRef::ByteArrayRef() + : m_ref(0) + , m_offset(0) + , m_length(0) +{} + +bool ByteArrayRef::startsWith(const char *s) const +{ + int l = std::strlen(s); + if (l > m_length) + return false; + return !qstrncmp(start(), s, l); +} + +int ByteArrayRef::count(char ch) const +{ + if (!m_ref) + return 0; + + int num = 0; + const char *b = start(); + const char *i = b + m_length; + while (i != b) + if (*--i == ch) + ++num; + return num; +} + +PPToken::PPToken() +{} + +void PPToken::squeeze() +{ + if (isValid()) { + m_src = m_src.mid(offset, length()); + m_src.squeeze(); + offset = 0; + } +} |