From 753ddb7ce076a12df07b2f800fe785cf659277df Mon Sep 17 00:00:00 2001
From: Roberto Raggi <qtc-committer@nokia.com>
Date: Mon, 22 Dec 2008 11:40:53 +0100
Subject: [PATCH] Some cleanup in the C++ preprocessor.

Introduced pp-scanner.cpp, renamed `pp' to `Preprocessor' and removed useless #includes.
---
 src/libs/cplusplus/TypeOfExpression.cpp  |   2 +-
 src/libs/cplusplus/cplusplus.pro         |   5 +-
 src/libs/cplusplus/pp-cctype.h           |   6 +-
 src/libs/cplusplus/pp-client.h           |   6 +-
 src/libs/cplusplus/pp-engine.cpp         |  54 ++---
 src/libs/cplusplus/pp-engine.h           |  10 +-
 src/libs/cplusplus/pp-environment.h      |   6 +-
 src/libs/cplusplus/pp-internal.h         |  78 ------
 src/libs/cplusplus/pp-macro-expander.cpp |  17 +-
 src/libs/cplusplus/pp-scanner.cpp        | 296 +++++++++++++++++++++++
 src/libs/cplusplus/pp-scanner.h          | 282 +--------------------
 src/libs/cplusplus/pp.h                  |  12 +-
 src/plugins/cpptools/cppmodelmanager.cpp |   2 +-
 13 files changed, 372 insertions(+), 404 deletions(-)
 delete mode 100644 src/libs/cplusplus/pp-internal.h
 create mode 100644 src/libs/cplusplus/pp-scanner.cpp

diff --git a/src/libs/cplusplus/TypeOfExpression.cpp b/src/libs/cplusplus/TypeOfExpression.cpp
index 46c2042d0f3..8c4ccb05e2f 100644
--- a/src/libs/cplusplus/TypeOfExpression.cpp
+++ b/src/libs/cplusplus/TypeOfExpression.cpp
@@ -136,7 +136,7 @@ QString TypeOfExpression::preprocessedExpression(const QString &expression,
     processEnvironment(documents, thisDocument,
                        &env, &processed);
     const QByteArray code = expression.toUtf8();
-    pp preproc(0, env);
+    Preprocessor preproc(0, env);
     QByteArray preprocessedCode;
     preproc("<expression>", code, &preprocessedCode);
     return QString::fromUtf8(preprocessedCode);
diff --git a/src/libs/cplusplus/cplusplus.pro b/src/libs/cplusplus/cplusplus.pro
index 35ec8a070b3..b8bde402825 100644
--- a/src/libs/cplusplus/cplusplus.pro
+++ b/src/libs/cplusplus/cplusplus.pro
@@ -22,13 +22,13 @@ HEADERS += \
     TypePrettyPrinter.h \
     ResolveExpression.h \
     LookupContext.h \
+    pp.h \
     pp-cctype.h \
     pp-engine.h \
     pp-macro-expander.h \
     pp-scanner.h \
     pp-client.h \
     pp-environment.h \
-    pp-internal.h \
     pp-macro.h
 
 SOURCES += \
@@ -46,6 +46,7 @@ SOURCES += \
     LookupContext.cpp \
     pp-engine.cpp \
     pp-environment.cpp \
-    pp-macro-expander.cpp
+    pp-macro-expander.cpp \
+    pp-scanner.cpp
 
 RESOURCES += cplusplus.qrc
diff --git a/src/libs/cplusplus/pp-cctype.h b/src/libs/cplusplus/pp-cctype.h
index 532f56a7e1d..d55d6c2e4e9 100644
--- a/src/libs/cplusplus/pp-cctype.h
+++ b/src/libs/cplusplus/pp-cctype.h
@@ -50,8 +50,8 @@
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#ifndef PP_CCTYPE_H
-#define PP_CCTYPE_H
+#ifndef CPLUSPLUS_PP_CCTYPE_H
+#define CPLUSPLUS_PP_CCTYPE_H
 
 #include <CPlusPlusForwardDeclarations.h>
 
@@ -73,4 +73,4 @@ inline bool CPLUSPLUS_EXPORT pp_isspace (int __ch)
 
 } // namespace CPlusPlus
 
-#endif // PP_CCTYPE_H
+#endif // CPLUSPLUS_PP_CCTYPE_H
diff --git a/src/libs/cplusplus/pp-client.h b/src/libs/cplusplus/pp-client.h
index e866be4aa89..d7dd49b18b7 100644
--- a/src/libs/cplusplus/pp-client.h
+++ b/src/libs/cplusplus/pp-client.h
@@ -31,8 +31,8 @@
 **
 ***************************************************************************/
 
-#ifndef PP_CLIENT_H
-#define PP_CLIENT_H
+#ifndef CPLUSPLUS_PP_CLIENT_H
+#define CPLUSPLUS_PP_CLIENT_H
 
 #include <CPlusPlusForwardDeclarations.h>
 
@@ -79,4 +79,4 @@ public:
 
 } // namespace CPlusPlus
 
-#endif // PP_CLIENT_H
+#endif // CPLUSPLUS_PP_CLIENT_H
diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp
index 0ed09f224de..a6186c6b7c6 100644
--- a/src/libs/cplusplus/pp-engine.cpp
+++ b/src/libs/cplusplus/pp-engine.cpp
@@ -451,7 +451,7 @@ private:
 } // end of anonymous namespace
 
 
-pp::pp (Client *client, Environment &env)
+Preprocessor::Preprocessor(Client *client, Environment &env)
     : client(client),
       env(env),
       expand(env)
@@ -459,7 +459,7 @@ pp::pp (Client *client, Environment &env)
     resetIfLevel ();
 }
 
-void pp::pushState(const State &s)
+void Preprocessor::pushState(const State &s)
 {
     _savedStates.append(state());
     _source = s.source;
@@ -467,7 +467,7 @@ void pp::pushState(const State &s)
     _dot = s.dot;
 }
 
-pp::State pp::state() const
+Preprocessor::State Preprocessor::state() const
 {
     State state;
     state.source = _source;
@@ -476,7 +476,7 @@ pp::State pp::state() const
     return state;
 }
 
-void pp::popState()
+void Preprocessor::popState()
 {
     const State &state = _savedStates.last();
     _source = state.source;
@@ -485,7 +485,7 @@ void pp::popState()
     _savedStates.removeLast();
 }
 
-void pp::operator () (const QByteArray &filename,
+void Preprocessor::operator () (const QByteArray &filename,
                       const QByteArray &source,
                       QByteArray *result)
 {
@@ -497,7 +497,7 @@ void pp::operator () (const QByteArray &filename,
     env.currentFile = previousFile;
 }
 
-pp::State pp::createStateFromSource(const QByteArray &source) const
+Preprocessor::State Preprocessor::createStateFromSource(const QByteArray &source) const
 {
     State state;
     state.source = source;
@@ -512,7 +512,7 @@ pp::State pp::createStateFromSource(const QByteArray &source) const
     return state;
 }
 
-void pp::operator()(const QByteArray &source, QByteArray *result)
+void Preprocessor::operator()(const QByteArray &source, QByteArray *result)
 {
     pushState(createStateFromSource(source));
 
@@ -700,27 +700,27 @@ void pp::operator()(const QByteArray &source, QByteArray *result)
     env.currentLine = previousCurrentLine;
 }
 
-const char *pp::startOfToken(const Token &token) const
+const char *Preprocessor::startOfToken(const Token &token) const
 { return _source.constBegin() + token.begin(); }
 
-const char *pp::endOfToken(const Token &token) const
+const char *Preprocessor::endOfToken(const Token &token) const
 { return _source.constBegin() + token.end(); }
 
-QByteArray pp::tokenSpell(const Token &token) const
+QByteArray Preprocessor::tokenSpell(const Token &token) const
 {
     const QByteArray text = QByteArray::fromRawData(_source.constBegin() + token.offset,
                                                     token.length);
     return text;
 }
 
-QByteArray pp::tokenText(const Token &token) const
+QByteArray Preprocessor::tokenText(const Token &token) const
 {
     const QByteArray text(_source.constBegin() + token.offset,
                           token.length);
     return text;
 }
 
-void pp::processDirective(TokenIterator firstToken, TokenIterator lastToken)
+void Preprocessor::processDirective(TokenIterator firstToken, TokenIterator lastToken)
 {
     RangeLexer tk(firstToken, lastToken);
     ++tk; // skip T_POUND
@@ -771,7 +771,7 @@ void pp::processDirective(TokenIterator firstToken, TokenIterator lastToken)
     }
 }
 
-QVector<Token> pp::tokenize(const QByteArray &text) const
+QVector<Token> Preprocessor::tokenize(const QByteArray &text) const
 {
     QVector<Token> tokens;
     Lexer lex(text.constBegin(), text.constEnd());
@@ -784,7 +784,7 @@ QVector<Token> pp::tokenize(const QByteArray &text) const
     return tokens;
 }
 
-void pp::processInclude(bool skipCurentPath,
+void Preprocessor::processInclude(bool skipCurentPath,
                         TokenIterator firstToken, TokenIterator lastToken,
                         bool acceptMacros)
 {
@@ -836,7 +836,7 @@ void pp::processInclude(bool skipCurentPath,
     }
 }
 
-void pp::processDefine(TokenIterator firstToken, TokenIterator lastToken)
+void Preprocessor::processDefine(TokenIterator firstToken, TokenIterator lastToken)
 {
     RangeLexer tk(firstToken, lastToken);
 
@@ -921,7 +921,7 @@ void pp::processDefine(TokenIterator firstToken, TokenIterator lastToken)
         client->macroAdded(macro);
 }
 
-void pp::processIf(TokenIterator firstToken, TokenIterator lastToken)
+void Preprocessor::processIf(TokenIterator firstToken, TokenIterator lastToken)
 {
     RangeLexer tk(firstToken, lastToken);
 
@@ -948,7 +948,7 @@ void pp::processIf(TokenIterator firstToken, TokenIterator lastToken)
     }
 }
 
-void pp::processElse(TokenIterator firstToken, TokenIterator lastToken)
+void Preprocessor::processElse(TokenIterator firstToken, TokenIterator lastToken)
 {
     RangeLexer tk(firstToken, lastToken);
 
@@ -961,7 +961,7 @@ void pp::processElse(TokenIterator firstToken, TokenIterator lastToken)
     }
 }
 
-void pp::processElif(TokenIterator firstToken, TokenIterator lastToken)
+void Preprocessor::processElif(TokenIterator firstToken, TokenIterator lastToken)
 {
     RangeLexer tk(firstToken, lastToken);
     ++tk; // skip T_POUND
@@ -980,7 +980,7 @@ void pp::processElif(TokenIterator firstToken, TokenIterator lastToken)
     }
 }
 
-void pp::processEndif(TokenIterator, TokenIterator)
+void Preprocessor::processEndif(TokenIterator, TokenIterator)
 {
     if (iflevel == 0 && !skipping()) {
         // std::cerr << "*** WARNING #endif without #if" << std::endl;
@@ -992,7 +992,7 @@ void pp::processEndif(TokenIterator, TokenIterator)
     }
 }
 
-void pp::processIfdef(bool checkUndefined,
+void Preprocessor::processIfdef(bool checkUndefined,
                       TokenIterator firstToken, TokenIterator lastToken)
 {
     RangeLexer tk(firstToken, lastToken);
@@ -1013,7 +1013,7 @@ void pp::processIfdef(bool checkUndefined,
     }
 }
 
-void pp::processUndef(TokenIterator firstToken, TokenIterator lastToken)
+void Preprocessor::processUndef(TokenIterator firstToken, TokenIterator lastToken)
 {
     RangeLexer tk(firstToken, lastToken);
 
@@ -1029,14 +1029,14 @@ void pp::processUndef(TokenIterator firstToken, TokenIterator lastToken)
     }
 }
 
-void pp::resetIfLevel ()
+void Preprocessor::resetIfLevel ()
 {
     iflevel = 0;
     _skipping[iflevel] = false;
     _true_test[iflevel] = false;
 }
 
-pp::PP_DIRECTIVE_TYPE pp::classifyDirective (const QByteArray &__directive) const
+Preprocessor::PP_DIRECTIVE_TYPE Preprocessor::classifyDirective (const QByteArray &__directive) const
 {
     switch (__directive.size())
     {
@@ -1085,7 +1085,7 @@ pp::PP_DIRECTIVE_TYPE pp::classifyDirective (const QByteArray &__directive) cons
     return PP_UNKNOWN_DIRECTIVE;
 }
 
-bool pp::testIfLevel()
+bool Preprocessor::testIfLevel()
 {
     const bool result = !_skipping[iflevel++];
     _skipping[iflevel] = _skipping[iflevel - 1];
@@ -1093,10 +1093,10 @@ bool pp::testIfLevel()
     return result;
 }
 
-int pp::skipping() const
+int Preprocessor::skipping() const
 { return _skipping[iflevel]; }
 
-Value pp::evalExpression(TokenIterator firstToken, TokenIterator lastToken,
+Value Preprocessor::evalExpression(TokenIterator firstToken, TokenIterator lastToken,
                          const QByteArray &source) const
 {
     ExpressionEvaluator eval(&env);
@@ -1104,7 +1104,7 @@ Value pp::evalExpression(TokenIterator firstToken, TokenIterator lastToken,
     return result;
 }
 
-bool pp::isQtReservedWord (const QByteArray &macroId) const
+bool Preprocessor::isQtReservedWord (const QByteArray &macroId) const
 {
     const int size = macroId.size();
     if      (size == 9 && macroId.at(0) == 'Q' && macroId == "Q_SIGNALS")
diff --git a/src/libs/cplusplus/pp-engine.h b/src/libs/cplusplus/pp-engine.h
index e7c0af68fb1..7ff0005c393 100644
--- a/src/libs/cplusplus/pp-engine.h
+++ b/src/libs/cplusplus/pp-engine.h
@@ -50,8 +50,8 @@
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#ifndef PP_ENGINE_H
-#define PP_ENGINE_H
+#ifndef CPLUSPLUS_PP_ENGINE_H
+#define CPLUSPLUS_PP_ENGINE_H
 
 #include "pp-client.h"
 
@@ -134,7 +134,7 @@ namespace CPlusPlus {
 #undef PP_DEFINE_BIN_OP
     };
 
-    class CPLUSPLUS_EXPORT pp
+    class CPLUSPLUS_EXPORT Preprocessor
     {
         Client *client;
         Environment &env;
@@ -182,7 +182,7 @@ namespace CPlusPlus {
         State createStateFromSource(const QByteArray &source) const;
 
     public:
-        pp(Client *client, Environment &env);
+        Preprocessor(Client *client, Environment &env);
 
         void operator()(const QByteArray &filename,
                         const QByteArray &source,
@@ -228,4 +228,4 @@ namespace CPlusPlus {
 
 } // namespace CPlusPlus
 
-#endif // PP_ENGINE_H
+#endif // CPLUSPLUS_PP_ENGINE_H
diff --git a/src/libs/cplusplus/pp-environment.h b/src/libs/cplusplus/pp-environment.h
index 4ba6b9353c4..97d0fe02d3c 100644
--- a/src/libs/cplusplus/pp-environment.h
+++ b/src/libs/cplusplus/pp-environment.h
@@ -50,8 +50,8 @@
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#ifndef PP_ENVIRONMENT_H
-#define PP_ENVIRONMENT_H
+#ifndef CPLUSPLUS_PP_ENVIRONMENT_H
+#define CPLUSPLUS_PP_ENVIRONMENT_H
 
 #include "CPlusPlusForwardDeclarations.h"
 
@@ -108,4 +108,4 @@ private:
 
 } // namespace CPlusPlus
 
-#endif // PP_ENVIRONMENT_H
+#endif // CPLUSPLUS_PP_ENVIRONMENT_H
diff --git a/src/libs/cplusplus/pp-internal.h b/src/libs/cplusplus/pp-internal.h
deleted file mode 100644
index f3b8aef835e..00000000000
--- a/src/libs/cplusplus/pp-internal.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/***************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact:  Qt Software Information (qt-info@nokia.com)
-**
-**
-** Non-Open Source Usage
-**
-** Licensees may use this file in accordance with the Qt Beta Version
-** License Agreement, Agreement version 2.2 provided with the Software or,
-** alternatively, in accordance with the terms contained in a written
-** agreement between you and Nokia.
-**
-** GNU General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License versions 2.0 or 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the packaging
-** of this file.  Please review the following information to ensure GNU
-** General Public Licensing requirements will be met:
-**
-** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt GPL Exception
-** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
-**
-***************************************************************************/
-/*
-  Copyright 2005 Roberto Raggi <roberto@kdevelop.org>
-
-  Permission to use, copy, modify, distribute, and sell this software and its
-  documentation for any purpose is hereby granted without fee, provided that
-  the above copyright notice appear in all copies and that both that
-  copyright notice and this permission notice appear in supporting
-  documentation.
-
-  The above copyright notice and this permission notice shall be included in
-  all copies or substantial portions of the Software.
-
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-  KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#ifndef PP_INTERNAL_H
-#define PP_INTERNAL_H
-
-#include <QByteArray>
-
-namespace CPlusPlus {
-namespace _PP_internal {
-
-inline bool comment_p (const char *__first, const char *__last)
-{
-    if (__first == __last)
-        return false;
-
-    if (*__first != '/')
-        return false;
-
-    if (++__first == __last)
-        return false;
-
-    return (*__first == '/' || *__first == '*');
-}
-
-} // _PP_internal
-} // namespace CPlusPlus
-
-#endif // PP_INTERNAL_H
diff --git a/src/libs/cplusplus/pp-macro-expander.cpp b/src/libs/cplusplus/pp-macro-expander.cpp
index 21148d24461..6a7d7e75df8 100644
--- a/src/libs/cplusplus/pp-macro-expander.cpp
+++ b/src/libs/cplusplus/pp-macro-expander.cpp
@@ -32,11 +32,26 @@
 ***************************************************************************/
 
 #include "pp.h"
+#include "pp-cctype.h"
 #include "pp-macro-expander.h"
 #include <QDateTime>
 
 using namespace CPlusPlus;
 
+inline static bool comment_p (const char *__first, const char *__last)
+{
+    if (__first == __last)
+        return false;
+
+    if (*__first != '/')
+        return false;
+
+    if (++__first == __last)
+        return false;
+
+    return (*__first == '/' || *__first == '*');
+}
+
 MacroExpander::MacroExpander (Environment &env, pp_frame *frame)
     : env(env), frame(frame),
       lines(0), generated_lines(0)
@@ -137,7 +152,7 @@ const char *MacroExpander::operator () (const char *__first, const char *__last,
             __result->append(__first, next_pos - __first);
             __first = next_pos;
         }
-        else if (_PP_internal::comment_p (__first, __last))
+        else if (comment_p (__first, __last))
         {
             __first = skip_comment_or_divop (__first, __last);
             int n = skip_comment_or_divop.lines;
diff --git a/src/libs/cplusplus/pp-scanner.cpp b/src/libs/cplusplus/pp-scanner.cpp
new file mode 100644
index 00000000000..8f0f9bf9ae8
--- /dev/null
+++ b/src/libs/cplusplus/pp-scanner.cpp
@@ -0,0 +1,296 @@
+/***************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact:  Qt Software Information (qt-info@nokia.com)
+**
+**
+** Non-Open Source Usage
+**
+** Licensees may use this file in accordance with the Qt Beta Version
+** License Agreement, Agreement version 2.2 provided with the Software or,
+** alternatively, in accordance with the terms contained in a written
+** agreement between you and Nokia.
+**
+** GNU General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the packaging
+** of this file.  Please review the following information to ensure GNU
+** General Public Licensing requirements will be met:
+**
+** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt GPL Exception
+** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
+**
+***************************************************************************/
+/*
+  Copyright 2005 Roberto Raggi <roberto@kdevelop.org>
+
+  Permission to use, copy, modify, distribute, and sell this software and its
+  documentation for any purpose is hereby granted without fee, provided that
+  the above copyright notice appear in all copies and that both that
+  copyright notice and this permission notice appear in supporting
+  documentation.
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "pp-scanner.h"
+#include "pp-cctype.h"
+
+using namespace CPlusPlus;
+
+const char *pp_skip_blanks::operator () (const char *__first, const char *__last)
+{
+    lines = 0;
+
+    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
+        if (*__first == '\\') {
+            const char *__begin = __first;
+            ++__begin;
+
+            if (__begin != __last && *__begin == '\n')
+                ++__first;
+            else
+                break;
+        } else if (*__first == '\n' || !pp_isspace (*__first))
+            break;
+    }
+
+    return __first;
+}
+
+const char *pp_skip_whitespaces::operator () (const char *__first, const char *__last)
+{
+    lines = 0;
+
+    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
+        if (! pp_isspace (*__first))
+            break;
+    }
+
+    return __first;
+}
+
+const char *pp_skip_comment_or_divop::operator () (const char *__first, const char *__last)
+{
+    enum {
+        MAYBE_BEGIN,
+        BEGIN,
+        MAYBE_END,
+        END,
+        IN_COMMENT,
+        IN_CXX_COMMENT
+    } state (MAYBE_BEGIN);
+
+    lines = 0;
+
+    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
+        switch (state) {
+        default:
+            break;
+
+        case MAYBE_BEGIN:
+            if (*__first != '/')
+                return __first;
+
+            state = BEGIN;
+            break;
+
+        case BEGIN:
+            if (*__first == '*')
+                state = IN_COMMENT;
+            else if (*__first == '/')
+                state = IN_CXX_COMMENT;
+            else
+                return __first;
+            break;
+
+        case IN_COMMENT:
+            if (*__first == '*')
+                state = MAYBE_END;
+            break;
+
+        case IN_CXX_COMMENT:
+            if (*__first == '\n')
+                return __first;
+            break;
+
+        case MAYBE_END:
+            if (*__first == '/')
+                state = END;
+            else if (*__first != '*')
+                state = IN_COMMENT;
+            break;
+
+        case END:
+            return __first;
+        }
+    }
+
+    return __first;
+}
+
+const char *pp_skip_identifier::operator () (const char *__first, const char *__last)
+{
+    lines = 0;
+
+    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
+        if (! pp_isalnum (*__first) && *__first != '_')
+            break;
+    }
+
+    return __first;
+}
+
+const char *pp_skip_number::operator () (const char *__first, const char *__last)
+{
+    lines = 0;
+
+    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
+        if (! pp_isalnum (*__first) && *__first != '.')
+            break;
+    }
+
+    return __first;
+}
+
+const char *pp_skip_string_literal::operator () (const char *__first, const char *__last)
+{
+    enum {
+        BEGIN,
+        IN_STRING,
+        QUOTE,
+        END
+    } state (BEGIN);
+
+    lines = 0;
+
+    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
+        switch (state)
+        {
+        default:
+            break;
+
+        case BEGIN:
+            if (*__first != '\"')
+                return __first;
+            state = IN_STRING;
+            break;
+
+        case IN_STRING:
+            if (! (*__first != '\n'))
+                return __last;
+
+            if (*__first == '\"')
+                state = END;
+            else if (*__first == '\\')
+                state = QUOTE;
+            break;
+
+        case QUOTE:
+            state = IN_STRING;
+            break;
+
+        case END:
+            return __first;
+        }
+    }
+
+    return __first;
+}
+
+const char *pp_skip_char_literal::operator () (const char *__first, const char *__last)
+{
+    enum {
+        BEGIN,
+        IN_STRING,
+        QUOTE,
+        END
+    } state (BEGIN);
+
+    lines = 0;
+
+    for (; state != END && __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
+        switch (state)
+        {
+        default:
+            break;
+
+        case BEGIN:
+            if (*__first != '\'')
+                return __first;
+            state = IN_STRING;
+            break;
+
+        case IN_STRING:
+            if (! (*__first != '\n'))
+                return __last;
+
+            if (*__first == '\'')
+                state = END;
+            else if (*__first == '\\')
+                state = QUOTE;
+            break;
+
+        case QUOTE:
+            state = IN_STRING;
+            break;
+        }
+    }
+
+    return __first;
+}
+
+const char *pp_skip_argument::operator () (const char *__first, const char *__last)
+{
+    int depth = 0;
+    lines = 0;
+
+    while (__first != __last) {
+        if (!depth && (*__first == ')' || *__first == ','))
+            break;
+        else if (*__first == '(')
+            ++depth, ++__first;
+        else if (*__first == ')')
+            --depth, ++__first;
+        else if (*__first == '\"') {
+            __first = skip_string_literal (__first, __last);
+            lines += skip_string_literal.lines;
+        } else if (*__first == '\'') {
+            __first = skip_char_literal (__first, __last);
+            lines += skip_char_literal.lines;
+        } else if (*__first == '/') {
+            __first = skip_comment_or_divop (__first, __last);
+            lines += skip_comment_or_divop.lines;
+        } else if (pp_isalpha (*__first) || *__first == '_') {
+            __first = skip_identifier (__first, __last);
+            lines += skip_identifier.lines;
+        } else if (pp_isdigit (*__first)) {
+            __first = skip_number (__first, __last);
+            lines += skip_number.lines;
+        } else if (*__first == '\n') {
+            ++__first;
+            ++lines;
+        } else
+            ++__first;
+    }
+
+    return __first;
+}
+
diff --git a/src/libs/cplusplus/pp-scanner.h b/src/libs/cplusplus/pp-scanner.h
index c2e768912fa..71bd04476ba 100644
--- a/src/libs/cplusplus/pp-scanner.h
+++ b/src/libs/cplusplus/pp-scanner.h
@@ -50,266 +50,57 @@
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#ifndef PP_SCANNER_H
-#define PP_SCANNER_H
+#ifndef CPLUSPLUS_PP_SCANNER_H
+#define CPLUSPLUS_PP_SCANNER_H
 
 namespace CPlusPlus {
 
 struct pp_skip_blanks
 {
   int lines;
-
-
-  const char *operator () (const char *__first, const char *__last)
-  {
-    lines = 0;
-
-    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first)
-      {
-        if (*__first == '\\')
-          {
-            const char *__begin = __first;
-            ++__begin;
-
-            if (__begin != __last && *__begin == '\n')
-                ++__first;
-            else
-              break;
-          }
-        else if (*__first == '\n' || !pp_isspace (*__first))
-          break;
-      }
-
-    return __first;
-  }
+  const char *operator () (const char *first, const char *last);
 };
 
 struct pp_skip_whitespaces
 {
   int lines;
 
-
-  const char *operator () (const char *__first, const char *__last)
-  {
-    lines = 0;
-
-    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first)
-      {
-        if (! pp_isspace (*__first))
-          break;
-      }
-
-    return __first;
-  }
+  const char *operator () (const char *first, const char *last);
 };
 
 struct pp_skip_comment_or_divop
 {
   int lines;
 
-
-  const char *operator () (const char *__first, const char *__last)
-  {
-    enum {
-      MAYBE_BEGIN,
-      BEGIN,
-      MAYBE_END,
-      END,
-      IN_COMMENT,
-      IN_CXX_COMMENT
-    } state (MAYBE_BEGIN);
-
-    lines = 0;
-
-    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first)
-      {
-        switch (state)
-          {
-            default:
-              assert (0);
-              break;
-
-            case MAYBE_BEGIN:
-              if (*__first != '/')
-                return __first;
-
-              state = BEGIN;
-              break;
-
-            case BEGIN:
-              if (*__first == '*')
-                state = IN_COMMENT;
-              else if (*__first == '/')
-                state = IN_CXX_COMMENT;
-              else
-                return __first;
-              break;
-
-            case IN_COMMENT:
-              if (*__first == '*')
-                state = MAYBE_END;
-              break;
-
-            case IN_CXX_COMMENT:
-              if (*__first == '\n')
-                return __first;
-              break;
-
-            case MAYBE_END:
-              if (*__first == '/')
-                state = END;
-              else if (*__first != '*')
-                state = IN_COMMENT;
-              break;
-
-            case END:
-              return __first;
-          }
-      }
-
-    return __first;
-  }
+  const char *operator () (const char *first, const char *last);
 };
 
 struct pp_skip_identifier
 {
   int lines;
 
-
-  const char *operator () (const char *__first, const char *__last)
-  {
-    lines = 0;
-
-    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first)
-      {
-        if (! pp_isalnum (*__first) && *__first != '_')
-          break;
-      }
-
-    return __first;
-  }
+  const char *operator () (const char *first, const char *last);
 };
 
 struct pp_skip_number
 {
   int lines;
 
-
-  const char *operator () (const char *__first, const char *__last)
-  {
-    lines = 0;
-
-    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first)
-      {
-        if (! pp_isalnum (*__first) && *__first != '.')
-          break;
-      }
-
-    return __first;
-  }
+  const char *operator () (const char *first, const char *last);
 };
 
 struct pp_skip_string_literal
 {
   int lines;
 
-
-  const char *operator () (const char *__first, const char *__last)
-  {
-    enum {
-      BEGIN,
-      IN_STRING,
-      QUOTE,
-      END
-    } state (BEGIN);
-
-    lines = 0;
-
-    for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first)
-      {
-        switch (state)
-          {
-            default:
-              assert (0);
-              break;
-
-            case BEGIN:
-              if (*__first != '\"')
-                return __first;
-              state = IN_STRING;
-              break;
-
-            case IN_STRING:
-              if (! (*__first != '\n'))
-                return __last;
-
-              if (*__first == '\"')
-                state = END;
-              else if (*__first == '\\')
-                state = QUOTE;
-              break;
-
-            case QUOTE:
-              state = IN_STRING;
-              break;
-
-            case END:
-              return __first;
-          }
-      }
-
-    return __first;
-  }
+  const char *operator () (const char *first, const char *last);
 };
 
 struct pp_skip_char_literal
 {
   int lines;
 
-
-  const char *operator () (const char *__first, const char *__last)
-  {
-    enum {
-      BEGIN,
-      IN_STRING,
-      QUOTE,
-      END
-    } state (BEGIN);
-
-    lines = 0;
-
-    for (; state != END && __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first)
-      {
-        switch (state)
-          {
-            default:
-              assert (0);
-              break;
-
-            case BEGIN:
-              if (*__first != '\'')
-                return __first;
-              state = IN_STRING;
-              break;
-
-            case IN_STRING:
-              if (! (*__first != '\n'))
-                return __last;
-
-              if (*__first == '\'')
-                state = END;
-              else if (*__first == '\\')
-                state = QUOTE;
-              break;
-
-            case QUOTE:
-              state = IN_STRING;
-              break;
-          }
-      }
-
-    return __first;
-  }
+  const char *operator () (const char *first, const char *last);
 };
 
 struct pp_skip_argument
@@ -321,60 +112,9 @@ struct pp_skip_argument
   pp_skip_comment_or_divop skip_comment_or_divop;
   int lines;
 
-
-  const char *operator () (const char *__first, const char *__last)
-  {
-    int depth = 0;
-    lines = 0;
-
-    while (__first != __last)
-      {
-        if (!depth && (*__first == ')' || *__first == ','))
-          break;
-        else if (*__first == '(')
-          ++depth, ++__first;
-        else if (*__first == ')')
-          --depth, ++__first;
-        else if (*__first == '\"')
-          {
-            __first = skip_string_literal (__first, __last);
-            lines += skip_string_literal.lines;
-          }
-        else if (*__first == '\'')
-          {
-            __first = skip_char_literal (__first, __last);
-            lines += skip_char_literal.lines;
-          }
-        else if (*__first == '/')
-          {
-            __first = skip_comment_or_divop (__first, __last);
-            lines += skip_comment_or_divop.lines;
-          }
-        else if (pp_isalpha (*__first) || *__first == '_')
-          {
-            __first = skip_identifier (__first, __last);
-            lines += skip_identifier.lines;
-          }
-        else if (pp_isdigit (*__first))
-          {
-            __first = skip_number (__first, __last);
-            lines += skip_number.lines;
-          }
-        else if (*__first == '\n')
-          {
-            ++__first;
-            ++lines;
-          }
-        else
-          ++__first;
-      }
-
-    return __first;
-  }
+  const char *operator () (const char *first, const char *last);
 };
 
 } // namespace CPlusPlus
 
-#endif // PP_SCANNER_H
-
-// kate: space-indent on; indent-width 2; replace-tabs on;
+#endif // CPLUSPLUS_PP_SCANNER_H
diff --git a/src/libs/cplusplus/pp.h b/src/libs/cplusplus/pp.h
index 2dee3e87f1d..2cf40eed096 100644
--- a/src/libs/cplusplus/pp.h
+++ b/src/libs/cplusplus/pp.h
@@ -50,15 +50,9 @@
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#ifndef PP_H
-#define PP_H
+#ifndef CPLUSPLUS_PREPROCESSOR_H
+#define CPLUSPLUS_PREPROCESSOR_H
 
-#include <cassert>
-#include <cstring>
-#include <cctype>
-
-#include "pp-cctype.h"
-#include "pp-internal.h"
 #include "pp-macro.h"
 #include "pp-environment.h"
 #include "pp-scanner.h"
@@ -66,4 +60,4 @@
 #include "pp-engine.h"
 #include "pp-client.h"
 
-#endif // PP_H
+#endif // CPLUSPLUS_PREPROCESSOR_H
diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index 6dad51a6434..df611294751 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -144,7 +144,7 @@ private:
     QPointer<CppModelManager> m_modelManager;
     Snapshot m_snapshot;
     Environment env;
-    pp m_proc;
+    Preprocessor m_proc;
     QStringList m_includePaths;
     QStringList m_systemIncludePaths;
     QMap<QString, QByteArray> m_workingCopy;
-- 
GitLab