summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus
diff options
context:
space:
mode:
authorRoberto Raggi <qtc-committer@nokia.com>2008-12-22 14:10:47 +0100
committerRoberto Raggi <qtc-committer@nokia.com>2008-12-22 14:10:47 +0100
commit0422bcbbd599cafe87735087804a434b78e353ff (patch)
tree51056c498b7909be18eb64058876c23226d3cfb3 /src/libs/cplusplus
parente325aa38d91c9d11b9645004e786924c49e2b325 (diff)
downloadqt-creator-0422bcbbd599cafe87735087804a434b78e353ff.tar.gz
Some more clean up in the preprocessor.
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r--src/libs/cplusplus/CppDocument.h3
-rw-r--r--src/libs/cplusplus/Macro.cpp89
-rw-r--r--src/libs/cplusplus/Macro.h (renamed from src/libs/cplusplus/pp-macro.h)34
-rw-r--r--src/libs/cplusplus/PreprocessorClient.cpp42
-rw-r--r--src/libs/cplusplus/PreprocessorClient.h (renamed from src/libs/cplusplus/pp-client.h)15
-rw-r--r--src/libs/cplusplus/PreprocessorEnvironment.cpp (renamed from src/libs/cplusplus/pp-environment.cpp)15
-rw-r--r--src/libs/cplusplus/PreprocessorEnvironment.h (renamed from src/libs/cplusplus/pp-environment.h)4
-rw-r--r--src/libs/cplusplus/cplusplus.pro12
-rw-r--r--src/libs/cplusplus/pp-engine.h2
-rw-r--r--src/libs/cplusplus/pp-macro-expander.cpp6
-rw-r--r--src/libs/cplusplus/pp.h6
11 files changed, 164 insertions, 64 deletions
diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h
index 98b5ed1a2a..d872dd3a1a 100644
--- a/src/libs/cplusplus/CppDocument.h
+++ b/src/libs/cplusplus/CppDocument.h
@@ -35,8 +35,7 @@
#define CPPDOCUMENT_H
#include <CPlusPlusForwardDeclarations.h>
-
-#include "pp-macro.h"
+#include "Macro.h"
#include <QByteArray>
#include <QList>
diff --git a/src/libs/cplusplus/Macro.cpp b/src/libs/cplusplus/Macro.cpp
new file mode 100644
index 0000000000..d5492b983b
--- /dev/null
+++ b/src/libs/cplusplus/Macro.cpp
@@ -0,0 +1,89 @@
+/***************************************************************************
+**
+** 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 "Macro.h"
+
+using namespace CPlusPlus;
+
+Macro::Macro()
+ : _next(0),
+ _hashcode(0),
+ _line(0),
+ _state(0)
+{ }
+
+QString Macro::toString() const
+{
+ QString text;
+ if (_hidden)
+ text += QLatin1String("#undef ");
+ else
+ text += QLatin1String("#define ");
+ text += QString::fromUtf8(_name.constData(), _name.size());
+ if (_functionLike) {
+ text += QLatin1Char('(');
+ bool first = true;
+ foreach (const QByteArray formal, _formals) {
+ if (! first)
+ text += QLatin1String(", ");
+ else
+ first = false;
+ text += QString::fromUtf8(formal.constData(), formal.size());
+ }
+ if (_variadic)
+ text += QLatin1String("...");
+ text += QLatin1Char(')');
+ }
+ text += QLatin1Char(' ');
+ text += QString::fromUtf8(_definition.constData(), _definition.size());
+ return text;
+}
diff --git a/src/libs/cplusplus/pp-macro.h b/src/libs/cplusplus/Macro.h
index 36fe7995ad..3957f13fab 100644
--- a/src/libs/cplusplus/pp-macro.h
+++ b/src/libs/cplusplus/Macro.h
@@ -64,12 +64,7 @@ namespace CPlusPlus {
class CPLUSPLUS_EXPORT Macro
{
public:
- Macro()
- : _next(0),
- _hashcode(0),
- _line(0),
- _state(0)
- { }
+ Macro();
QByteArray name() const
{ return _name; }
@@ -119,32 +114,7 @@ public:
void setVariadic(bool isVariadic)
{ _variadic = isVariadic; }
- QString toString() const
- {
- QString text;
- if (_hidden)
- text += QLatin1String("#undef ");
- else
- text += QLatin1String("#define ");
- text += QString::fromUtf8(_name.constData(), _name.size());
- if (_functionLike) {
- text += QLatin1Char('(');
- bool first = true;
- foreach (const QByteArray formal, _formals) {
- if (! first)
- text += QLatin1String(", ");
- else
- first = false;
- text += QString::fromUtf8(formal.constData(), formal.size());
- }
- if (_variadic)
- text += QLatin1String("...");
- text += QLatin1Char(')');
- }
- text += QLatin1Char(' ');
- text += QString::fromUtf8(_definition.constData(), _definition.size());
- return text;
- }
+ QString toString() const;
// ### private
Macro *_next;
diff --git a/src/libs/cplusplus/PreprocessorClient.cpp b/src/libs/cplusplus/PreprocessorClient.cpp
new file mode 100644
index 0000000000..2eb5656446
--- /dev/null
+++ b/src/libs/cplusplus/PreprocessorClient.cpp
@@ -0,0 +1,42 @@
+/***************************************************************************
+**
+** 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.
+**
+***************************************************************************/
+
+#include "PreprocessorClient.h"
+
+using namespace CPlusPlus;
+
+Client::Client()
+{ }
+
+Client::~Client()
+{ }
diff --git a/src/libs/cplusplus/pp-client.h b/src/libs/cplusplus/PreprocessorClient.h
index d7dd49b18b..2d37dac3e6 100644
--- a/src/libs/cplusplus/pp-client.h
+++ b/src/libs/cplusplus/PreprocessorClient.h
@@ -35,10 +35,12 @@
#define CPLUSPLUS_PP_CLIENT_H
#include <CPlusPlusForwardDeclarations.h>
+#include <QtGlobal>
-#include <QByteArray>
-#include <QString>
-#include <QFile>
+QT_BEGIN_NAMESPACE
+class QByteArray;
+class QString;
+QT_END_NAMESPACE
namespace CPlusPlus {
@@ -56,11 +58,8 @@ public:
};
public:
- Client()
- { }
-
- virtual ~Client()
- { }
+ Client();
+ virtual ~Client();
virtual void macroAdded(const Macro &macro) = 0;
virtual void sourceNeeded(QString &fileName, IncludeType mode,
diff --git a/src/libs/cplusplus/pp-environment.cpp b/src/libs/cplusplus/PreprocessorEnvironment.cpp
index 7b93c275d3..693fe6160e 100644
--- a/src/libs/cplusplus/pp-environment.cpp
+++ b/src/libs/cplusplus/PreprocessorEnvironment.cpp
@@ -50,16 +50,15 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "pp-environment.h"
-#include "pp.h"
-
+#include "PreprocessorEnvironment.h"
+#include "Macro.h"
#include <cstring>
using namespace CPlusPlus;
Environment::Environment()
: currentLine(0),
- hide_next(false),
+ hideNext(false),
_macros(0),
_allocated_macros(0),
_macro_count(-1),
@@ -94,7 +93,7 @@ Macro *Environment::bind(const Macro &__macro)
Q_ASSERT(! __macro.name().isEmpty());
Macro *m = new Macro (__macro);
- m->_hashcode = hash_code(m->name());
+ m->_hashcode = hashCode(m->name());
if (++_macro_count == _allocated_macros) {
if (! _allocated_macros)
@@ -192,12 +191,12 @@ bool Environment::isBuiltinMacro(const QByteArray &s) const
return false;
}
-Macro *Environment::resolve (const QByteArray &name) const
+Macro *Environment::resolve(const QByteArray &name) const
{
if (! _macros)
return 0;
- Macro *it = _hash[hash_code (name) % _hash_count];
+ Macro *it = _hash[hashCode(name) % _hash_count];
for (; it; it = it->_next) {
if (it->name() != name)
continue;
@@ -208,7 +207,7 @@ Macro *Environment::resolve (const QByteArray &name) const
return it;
}
-unsigned Environment::hash_code (const QByteArray &s)
+unsigned Environment::hashCode(const QByteArray &s)
{
unsigned hash_value = 0;
diff --git a/src/libs/cplusplus/pp-environment.h b/src/libs/cplusplus/PreprocessorEnvironment.h
index 97d0fe02d3..48ee5b2715 100644
--- a/src/libs/cplusplus/pp-environment.h
+++ b/src/libs/cplusplus/PreprocessorEnvironment.h
@@ -90,13 +90,13 @@ public:
{ return _macros + _macro_count + 1; }
private:
- static unsigned hash_code (const QByteArray &s);
+ static unsigned hashCode(const QByteArray &s);
void rehash();
public:
QByteArray currentFile;
unsigned currentLine;
- bool hide_next;
+ bool hideNext;
private:
Macro **_macros;
diff --git a/src/libs/cplusplus/cplusplus.pro b/src/libs/cplusplus/cplusplus.pro
index b8bde40282..f89d4d3f86 100644
--- a/src/libs/cplusplus/cplusplus.pro
+++ b/src/libs/cplusplus/cplusplus.pro
@@ -22,14 +22,14 @@ HEADERS += \
TypePrettyPrinter.h \
ResolveExpression.h \
LookupContext.h \
+ PreprocessorClient.h \
+ PreprocessorEnvironment.h \
+ Macro.h \
pp.h \
pp-cctype.h \
pp-engine.h \
pp-macro-expander.h \
- pp-scanner.h \
- pp-client.h \
- pp-environment.h \
- pp-macro.h
+ pp-scanner.h
SOURCES += \
SimpleLexer.cpp \
@@ -44,8 +44,10 @@ SOURCES += \
TypePrettyPrinter.cpp \
ResolveExpression.cpp \
LookupContext.cpp \
+ PreprocessorClient.cpp \
+ PreprocessorEnvironment.cpp \
+ Macro.cpp \
pp-engine.cpp \
- pp-environment.cpp \
pp-macro-expander.cpp \
pp-scanner.cpp
diff --git a/src/libs/cplusplus/pp-engine.h b/src/libs/cplusplus/pp-engine.h
index 7ff0005c39..d0a573aed9 100644
--- a/src/libs/cplusplus/pp-engine.h
+++ b/src/libs/cplusplus/pp-engine.h
@@ -53,7 +53,7 @@
#ifndef CPLUSPLUS_PP_ENGINE_H
#define CPLUSPLUS_PP_ENGINE_H
-#include "pp-client.h"
+#include "PreprocessorClient.h"
#include <Token.h>
#include <QVector>
diff --git a/src/libs/cplusplus/pp-macro-expander.cpp b/src/libs/cplusplus/pp-macro-expander.cpp
index 5b0f20b66c..40bbc8090b 100644
--- a/src/libs/cplusplus/pp-macro-expander.cpp
+++ b/src/libs/cplusplus/pp-macro-expander.cpp
@@ -213,12 +213,12 @@ const char *MacroExpander::operator () (const char *__first, const char *__last,
}
Macro *macro = env.resolve (fast_name);
- if (! macro || macro->isHidden() || env.hide_next)
+ if (! macro || macro->isHidden() || env.hideNext)
{
if (fast_name.size () == 7 && fast_name [0] == 'd' && fast_name == "defined")
- env.hide_next = true;
+ env.hideNext = true;
else
- env.hide_next = false;
+ env.hideNext = false;
if (fast_name.size () == 8 && fast_name [0] == '_' && fast_name [1] == '_')
{
diff --git a/src/libs/cplusplus/pp.h b/src/libs/cplusplus/pp.h
index 2cf40eed09..96c8186716 100644
--- a/src/libs/cplusplus/pp.h
+++ b/src/libs/cplusplus/pp.h
@@ -53,11 +53,11 @@
#ifndef CPLUSPLUS_PREPROCESSOR_H
#define CPLUSPLUS_PREPROCESSOR_H
-#include "pp-macro.h"
-#include "pp-environment.h"
+#include "Macro.h"
+#include "PreprocessorClient.h"
+#include "PreprocessorEnvironment.h"
#include "pp-scanner.h"
#include "pp-macro-expander.h"
#include "pp-engine.h"
-#include "pp-client.h"
#endif // CPLUSPLUS_PREPROCESSOR_H