forked from qt-creator/qt-creator
Some more clean up in the preprocessor.
This commit is contained in:
@@ -35,8 +35,7 @@
|
||||
#define CPPDOCUMENT_H
|
||||
|
||||
#include <CPlusPlusForwardDeclarations.h>
|
||||
|
||||
#include "pp-macro.h"
|
||||
#include "Macro.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
|
||||
89
src/libs/cplusplus/Macro.cpp
Normal file
89
src/libs/cplusplus/Macro.cpp
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
42
src/libs/cplusplus/PreprocessorClient.cpp
Normal file
42
src/libs/cplusplus/PreprocessorClient.cpp
Normal file
@@ -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()
|
||||
{ }
|
||||
@@ -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 ¯o) = 0;
|
||||
virtual void sourceNeeded(QString &fileName, IncludeType mode,
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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] == '_')
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user