forked from qt-creator/qt-creator
Merge branch '0.9.1-beta' of git@scm.dev.nokia.troll.no:creator/mainline into 0.9.1-beta
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
#include "cmakeproject.h"
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmakeprojectnodes.h"
|
||||
#include "cmakestep.h"
|
||||
#include "makestep.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
@@ -188,7 +190,7 @@ QString CMakeProject::buildDirectory(const QString &buildConfiguration) const
|
||||
{
|
||||
Q_UNUSED(buildConfiguration)
|
||||
//TODO
|
||||
return "";
|
||||
return QFileInfo(m_fileName).absolutePath();
|
||||
}
|
||||
|
||||
ProjectExplorer::BuildStepConfigWidget *CMakeProject::createConfigWidget()
|
||||
@@ -225,13 +227,29 @@ QStringList CMakeProject::files(FilesMode fileMode) const
|
||||
void CMakeProject::saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer)
|
||||
{
|
||||
// TODO
|
||||
Q_UNUSED(writer)
|
||||
Q_UNUSED(writer);
|
||||
}
|
||||
|
||||
void CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader)
|
||||
{
|
||||
// TODO
|
||||
Q_UNUSED(reader)
|
||||
Q_UNUSED(reader);
|
||||
if (buildConfigurations().isEmpty()) {
|
||||
// No build configuration, adding those
|
||||
|
||||
// TODO do we want to create one build configuration per target?
|
||||
// or how do we want to handle that?
|
||||
|
||||
CMakeStep *cmakeStep = new CMakeStep(this);
|
||||
MakeStep *makeStep = new MakeStep(this);
|
||||
|
||||
insertBuildStep(0, cmakeStep);
|
||||
insertBuildStep(1, makeStep);
|
||||
|
||||
addBuildConfiguration("all");
|
||||
setActiveBuildConfiguration("all");
|
||||
}
|
||||
// Restoring is fine
|
||||
}
|
||||
|
||||
|
||||
@@ -376,12 +394,36 @@ void CMakeCbpParser::parseBuild()
|
||||
|
||||
void CMakeCbpParser::parseTarget()
|
||||
{
|
||||
m_targetOutput.clear();
|
||||
m_targetType = false;
|
||||
while(!atEnd()) {
|
||||
readNext();
|
||||
if (isEndElement()) {
|
||||
if (m_targetType && !m_targetOutput.isEmpty()) {
|
||||
qDebug()<<"found target "<<m_targetOutput;
|
||||
m_targets.insert(m_targetOutput);
|
||||
}
|
||||
return;
|
||||
} else if (name() == "Compiler") {
|
||||
parseCompiler();
|
||||
} else if (name() == "Option") {
|
||||
parseTargetOption();
|
||||
} else if (isStartElement()) {
|
||||
parseUnknownElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeCbpParser::parseTargetOption()
|
||||
{
|
||||
if (attributes().hasAttribute("output"))
|
||||
m_targetOutput = attributes().value("output").toString();
|
||||
else if (attributes().hasAttribute("type") && attributes().value("type") == "1")
|
||||
m_targetType = true;
|
||||
while(!atEnd()) {
|
||||
readNext();
|
||||
if (isEndElement()) {
|
||||
return;
|
||||
} else if (name() == "Compiler") {
|
||||
parseCompiler();
|
||||
} else if (isStartElement()) {
|
||||
parseUnknownElement();
|
||||
}
|
||||
|
||||
@@ -123,13 +123,18 @@ private:
|
||||
void parseProject();
|
||||
void parseBuild();
|
||||
void parseTarget();
|
||||
void parseTargetOption();
|
||||
void parseCompiler();
|
||||
void parseAdd();
|
||||
void parseUnit();
|
||||
void parseUnknownElement();
|
||||
|
||||
QSet<QString> m_targets;
|
||||
QList<ProjectExplorer::FileNode *> m_fileList;
|
||||
QStringList m_includeFiles;
|
||||
|
||||
QString m_targetOutput;
|
||||
bool m_targetType;
|
||||
};
|
||||
|
||||
class CMakeFile : public Core::IFile
|
||||
|
||||
@@ -54,7 +54,7 @@ bool CMakeStep::init(const QString &buildConfiguration)
|
||||
setEnabled(buildConfiguration, true);
|
||||
setWorkingDirectory(buildConfiguration, m_pro->buildDirectory(buildConfiguration));
|
||||
setCommand(buildConfiguration, "cmake"); // TODO give full path here?
|
||||
setArguments(buildConfiguration, QStringList()); // TODO
|
||||
setArguments(buildConfiguration, QStringList() << "-GUnix Makefiles"); // TODO
|
||||
setEnvironment(buildConfiguration, m_pro->environment(buildConfiguration));
|
||||
return AbstractProcessStep::init(buildConfiguration);
|
||||
}
|
||||
|
||||
@@ -699,7 +699,9 @@ void CppCodeCompletion::addMacros(const LookupContext &context)
|
||||
continue;
|
||||
processed.insert(fn);
|
||||
if (Document::Ptr doc = context.document(fn)) {
|
||||
macroNames += doc->macroNames();
|
||||
foreach (const Macro macro, doc->definedMacros()) {
|
||||
macroNames.insert(macro.name);
|
||||
}
|
||||
todo += doc->includedFiles();
|
||||
}
|
||||
}
|
||||
@@ -1025,6 +1027,10 @@ bool CppCodeCompletion::partiallyComplete(const QList<TextEditor::CompletionItem
|
||||
void CppCodeCompletion::cleanup()
|
||||
{
|
||||
m_completions.clear();
|
||||
|
||||
// Set empty map in order to avoid referencing old versions of the documents
|
||||
// until the next completion
|
||||
typeOfExpression.setDocuments(QMap<QString, Document::Ptr>());
|
||||
}
|
||||
|
||||
int CppCodeCompletion::findStartOfName(const TextEditor::ITextEditor *editor)
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
**
|
||||
***************************************************************************/
|
||||
|
||||
#include "pp.h"
|
||||
#include <cplusplus/pp.h>
|
||||
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cpphoverhandler.h"
|
||||
@@ -107,7 +107,7 @@ static const char pp_configuration[] =
|
||||
namespace CppTools {
|
||||
namespace Internal {
|
||||
|
||||
class CppPreprocessor: public rpp::Client
|
||||
class CppPreprocessor: public CPlusPlus::Client
|
||||
{
|
||||
public:
|
||||
CppPreprocessor(QPointer<CppModelManager> modelManager);
|
||||
@@ -129,12 +129,11 @@ protected:
|
||||
void mergeEnvironment(CPlusPlus::Document::Ptr doc);
|
||||
void mergeEnvironment(CPlusPlus::Document::Ptr doc, QSet<QString> *processed);
|
||||
|
||||
virtual void macroAdded(const QByteArray ¯oName,
|
||||
const QByteArray ¯oText);
|
||||
virtual void macroAdded(const Macro ¯o);
|
||||
virtual void startExpandingMacro(unsigned offset,
|
||||
const rpp::Macro ¯o,
|
||||
const Macro ¯o,
|
||||
const QByteArray &originalText);
|
||||
virtual void stopExpandingMacro(unsigned offset, const rpp::Macro ¯o);
|
||||
virtual void stopExpandingMacro(unsigned offset, const Macro ¯o);
|
||||
virtual void startSkippingBlocks(unsigned offset);
|
||||
virtual void stopSkippingBlocks(unsigned offset);
|
||||
virtual void sourceNeeded(QString &fileName, IncludeType type);
|
||||
@@ -142,8 +141,8 @@ protected:
|
||||
private:
|
||||
QPointer<CppModelManager> m_modelManager;
|
||||
CppModelManager::DocumentTable m_documents;
|
||||
rpp::Environment env;
|
||||
rpp::pp m_proc;
|
||||
Environment env;
|
||||
pp m_proc;
|
||||
QStringList m_includePaths;
|
||||
QStringList m_systemIncludePaths;
|
||||
QMap<QString, QByteArray> m_workingCopy;
|
||||
@@ -295,16 +294,16 @@ QByteArray CppPreprocessor::tryIncludeFile(QString &fileName, IncludeType type)
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
void CppPreprocessor::macroAdded(const QByteArray ¯oName, const QByteArray ¯oText)
|
||||
void CppPreprocessor::macroAdded(const Macro ¯o)
|
||||
{
|
||||
if (! m_currentDoc)
|
||||
return;
|
||||
|
||||
m_currentDoc->appendMacro(macroName, macroText);
|
||||
m_currentDoc->appendMacro(macro);
|
||||
}
|
||||
|
||||
void CppPreprocessor::startExpandingMacro(unsigned offset,
|
||||
const rpp::Macro &,
|
||||
const Macro &,
|
||||
const QByteArray &originalText)
|
||||
{
|
||||
if (! m_currentDoc)
|
||||
@@ -314,7 +313,7 @@ void CppPreprocessor::startExpandingMacro(unsigned offset,
|
||||
m_currentDoc->addMacroUse(offset, originalText.length());
|
||||
}
|
||||
|
||||
void CppPreprocessor::stopExpandingMacro(unsigned, const rpp::Macro &)
|
||||
void CppPreprocessor::stopExpandingMacro(unsigned, const Macro &)
|
||||
{
|
||||
if (! m_currentDoc)
|
||||
return;
|
||||
@@ -340,14 +339,13 @@ void CppPreprocessor::mergeEnvironment(Document::Ptr doc, QSet<QString> *process
|
||||
|
||||
processed->insert(fn);
|
||||
|
||||
foreach (QString includedFile, doc->includedFiles())
|
||||
foreach (QString includedFile, doc->includedFiles()) {
|
||||
mergeEnvironment(m_documents.value(includedFile), processed);
|
||||
}
|
||||
|
||||
const QByteArray macros = doc->definedMacros();
|
||||
QByteArray localFileName = doc->fileName().toUtf8();
|
||||
|
||||
QByteArray dummy;
|
||||
m_proc(localFileName, macros, &dummy);
|
||||
foreach (const Macro macro, doc->definedMacros()) {
|
||||
env.bind(macro);
|
||||
}
|
||||
}
|
||||
|
||||
void CppPreprocessor::startSkippingBlocks(unsigned offset)
|
||||
|
||||
@@ -10,7 +10,7 @@ unix:QMAKE_CXXFLAGS_DEBUG += -O3
|
||||
INCLUDEPATH += .
|
||||
DEFINES += CPPTOOLS_LIBRARY
|
||||
CONFIG += help
|
||||
include(rpp/rpp.pri)|error("Can't find RPP")
|
||||
|
||||
HEADERS += cpptools_global.h \
|
||||
cppquickopenfilter.h \
|
||||
cppclassesfilter.h \
|
||||
|
||||
@@ -1,74 +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.2, 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_CCTYPE_H
|
||||
#define PP_CCTYPE_H
|
||||
|
||||
#include <cctype>
|
||||
|
||||
namespace rpp {
|
||||
|
||||
inline bool pp_isalpha (int __ch)
|
||||
{ return std::isalpha ((unsigned char) __ch) != 0; }
|
||||
|
||||
inline bool pp_isalnum (int __ch)
|
||||
{ return std::isalnum ((unsigned char) __ch) != 0; }
|
||||
|
||||
inline bool pp_isdigit (int __ch)
|
||||
{ return std::isdigit ((unsigned char) __ch) != 0; }
|
||||
|
||||
inline bool pp_isspace (int __ch)
|
||||
{ return std::isspace ((unsigned char) __ch) != 0; }
|
||||
|
||||
} // namespace rpp
|
||||
|
||||
#endif // PP_CCTYPE_H
|
||||
@@ -1,79 +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.2, included in the file GPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef PP_CLIENT_H
|
||||
#define PP_CLIENT_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
|
||||
namespace rpp {
|
||||
|
||||
class Macro;
|
||||
|
||||
class Client
|
||||
{
|
||||
Client(const Client &other);
|
||||
void operator=(const Client &other);
|
||||
|
||||
public:
|
||||
enum IncludeType {
|
||||
IncludeLocal,
|
||||
IncludeGlobal
|
||||
};
|
||||
|
||||
public:
|
||||
Client()
|
||||
{ }
|
||||
|
||||
virtual ~Client()
|
||||
{ }
|
||||
|
||||
virtual void macroAdded(const QByteArray ¯oId, const QByteArray &text) = 0;
|
||||
virtual void sourceNeeded(QString &fileName, IncludeType mode) = 0; // ### FIX the signature.
|
||||
|
||||
virtual void startExpandingMacro(unsigned offset,
|
||||
const Macro ¯o,
|
||||
const QByteArray &originalTextt) = 0;
|
||||
|
||||
virtual void stopExpandingMacro(unsigned offset,
|
||||
const Macro ¯o) = 0;
|
||||
|
||||
virtual void startSkippingBlocks(unsigned offset) = 0;
|
||||
virtual void stopSkippingBlocks(unsigned offset) = 0;
|
||||
};
|
||||
|
||||
} // namespace rpp
|
||||
|
||||
#endif // PP_CLIENT_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,231 +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.2, 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_ENGINE_H
|
||||
#define PP_ENGINE_H
|
||||
|
||||
#include "pp-client.h"
|
||||
|
||||
#include <Token.h>
|
||||
#include <QVector>
|
||||
|
||||
namespace CPlusPlus {
|
||||
class Token;
|
||||
}
|
||||
|
||||
namespace rpp {
|
||||
|
||||
struct Value
|
||||
{
|
||||
enum Kind {
|
||||
Kind_Long,
|
||||
Kind_ULong,
|
||||
};
|
||||
|
||||
Kind kind;
|
||||
|
||||
union {
|
||||
long l;
|
||||
unsigned long ul;
|
||||
};
|
||||
|
||||
|
||||
Value()
|
||||
: kind(Kind_Long), l(0)
|
||||
{ }
|
||||
|
||||
inline bool is_ulong () const
|
||||
{ return kind == Kind_ULong; }
|
||||
|
||||
inline void set_ulong (unsigned long v)
|
||||
{
|
||||
ul = v;
|
||||
kind = Kind_ULong;
|
||||
}
|
||||
|
||||
inline void set_long (long v)
|
||||
{
|
||||
l = v;
|
||||
kind = Kind_Long;
|
||||
}
|
||||
|
||||
inline bool is_zero () const
|
||||
{ return l == 0; }
|
||||
|
||||
#define PP_DEFINE_BIN_OP(name, op) \
|
||||
inline Value operator op(const Value &other) const \
|
||||
{ \
|
||||
Value v = *this; \
|
||||
if (v.is_ulong () || other.is_ulong ()) \
|
||||
v.set_ulong (v.ul op other.ul); \
|
||||
else \
|
||||
v.set_long (v.l op other.l); \
|
||||
return v; \
|
||||
}
|
||||
|
||||
PP_DEFINE_BIN_OP(op_add, +)
|
||||
PP_DEFINE_BIN_OP(op_sub, -)
|
||||
PP_DEFINE_BIN_OP(op_mult, *)
|
||||
PP_DEFINE_BIN_OP(op_div, /)
|
||||
PP_DEFINE_BIN_OP(op_mod, %)
|
||||
PP_DEFINE_BIN_OP(op_lhs, <<)
|
||||
PP_DEFINE_BIN_OP(op_rhs, >>)
|
||||
PP_DEFINE_BIN_OP(op_lt, <)
|
||||
PP_DEFINE_BIN_OP(op_gt, >)
|
||||
PP_DEFINE_BIN_OP(op_le, <=)
|
||||
PP_DEFINE_BIN_OP(op_ge, >=)
|
||||
PP_DEFINE_BIN_OP(op_eq, ==)
|
||||
PP_DEFINE_BIN_OP(op_ne, !=)
|
||||
PP_DEFINE_BIN_OP(op_bit_and, &)
|
||||
PP_DEFINE_BIN_OP(op_bit_or, |)
|
||||
PP_DEFINE_BIN_OP(op_bit_xor, ^)
|
||||
PP_DEFINE_BIN_OP(op_and, &&)
|
||||
PP_DEFINE_BIN_OP(op_or, ||)
|
||||
|
||||
#undef PP_DEFINE_BIN_OP
|
||||
};
|
||||
|
||||
class pp
|
||||
{
|
||||
Client *client;
|
||||
Environment &env;
|
||||
MacroExpander expand;
|
||||
|
||||
enum { MAX_LEVEL = 512 };
|
||||
|
||||
bool _skipping[MAX_LEVEL]; // ### move in state
|
||||
bool _true_test[MAX_LEVEL]; // ### move in state
|
||||
int iflevel; // ### move in state
|
||||
|
||||
enum PP_DIRECTIVE_TYPE
|
||||
{
|
||||
PP_UNKNOWN_DIRECTIVE,
|
||||
PP_DEFINE,
|
||||
PP_INCLUDE,
|
||||
PP_INCLUDE_NEXT,
|
||||
PP_ELIF,
|
||||
PP_ELSE,
|
||||
PP_ENDIF,
|
||||
PP_IF,
|
||||
PP_IFDEF,
|
||||
PP_IFNDEF,
|
||||
PP_UNDEF
|
||||
};
|
||||
|
||||
typedef const CPlusPlus::Token *TokenIterator;
|
||||
|
||||
struct State {
|
||||
QByteArray source;
|
||||
QVector<CPlusPlus::Token> tokens;
|
||||
TokenIterator dot;
|
||||
};
|
||||
|
||||
QList<State> _savedStates;
|
||||
|
||||
State state() const;
|
||||
void pushState(const State &state);
|
||||
void popState();
|
||||
|
||||
QByteArray _source;
|
||||
QVector<CPlusPlus::Token> _tokens;
|
||||
TokenIterator _dot;
|
||||
|
||||
State createStateFromSource(const QByteArray &source) const;
|
||||
|
||||
public:
|
||||
pp(Client *client, Environment &env);
|
||||
|
||||
void operator()(const QByteArray &filename,
|
||||
const QByteArray &source,
|
||||
QByteArray *result);
|
||||
|
||||
void operator()(const QByteArray &source,
|
||||
QByteArray *result);
|
||||
|
||||
private:
|
||||
void resetIfLevel();
|
||||
bool testIfLevel();
|
||||
int skipping() const;
|
||||
|
||||
PP_DIRECTIVE_TYPE classifyDirective(const QByteArray &directive) const;
|
||||
|
||||
Value evalExpression(TokenIterator firstToken,
|
||||
TokenIterator lastToken,
|
||||
const QByteArray &source) const;
|
||||
|
||||
QVector<CPlusPlus::Token> tokenize(const QByteArray &text) const;
|
||||
|
||||
const char *startOfToken(const CPlusPlus::Token &token) const;
|
||||
const char *endOfToken(const CPlusPlus::Token &token) const;
|
||||
|
||||
QByteArray tokenSpell(const CPlusPlus::Token &token) const;
|
||||
QByteArray tokenText(const CPlusPlus::Token &token) const; // does a deep copy
|
||||
|
||||
void processDirective(TokenIterator dot, TokenIterator lastToken);
|
||||
void processInclude(bool skipCurrentPath,
|
||||
TokenIterator dot, TokenIterator lastToken,
|
||||
bool acceptMacros = true);
|
||||
void processDefine(TokenIterator dot, TokenIterator lastToken);
|
||||
void processIf(TokenIterator dot, TokenIterator lastToken);
|
||||
void processElse(TokenIterator dot, TokenIterator lastToken);
|
||||
void processElif(TokenIterator dot, TokenIterator lastToken);
|
||||
void processEndif(TokenIterator dot, TokenIterator lastToken);
|
||||
void processIfdef(bool checkUndefined,
|
||||
TokenIterator dot, TokenIterator lastToken);
|
||||
void processUndef(TokenIterator dot, TokenIterator lastToken);
|
||||
|
||||
bool isQtReservedWord(const QByteArray &name) const;
|
||||
};
|
||||
|
||||
} // namespace rpp
|
||||
|
||||
#endif // PP_ENGINE_H
|
||||
@@ -1,231 +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.2, 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-environment.h"
|
||||
#include "pp.h"
|
||||
#include <cstring>
|
||||
|
||||
using namespace rpp;
|
||||
|
||||
Environment::Environment ()
|
||||
: currentLine(0),
|
||||
hide_next(false),
|
||||
_macros(0),
|
||||
_allocated_macros(0),
|
||||
_macro_count(-1),
|
||||
_hash(0),
|
||||
_hash_count(401)
|
||||
{
|
||||
}
|
||||
|
||||
Environment::~Environment ()
|
||||
{
|
||||
if (_macros) {
|
||||
qDeleteAll(firstMacro(), lastMacro());
|
||||
free(_macros);
|
||||
}
|
||||
|
||||
if (_hash)
|
||||
free(_hash);
|
||||
}
|
||||
|
||||
unsigned Environment::macroCount () const
|
||||
{ return _macro_count + 1; }
|
||||
|
||||
Macro *Environment::macroAt (unsigned index) const
|
||||
{ return _macros[index]; }
|
||||
|
||||
Macro *Environment::bind(const Macro &__macro)
|
||||
{
|
||||
Q_ASSERT(! __macro.name.isEmpty());
|
||||
|
||||
Macro *m = new Macro (__macro);
|
||||
m->hashcode = hash_code(m->name);
|
||||
m->fileName = current_file;
|
||||
m->line = currentLine;
|
||||
|
||||
if (++_macro_count == _allocated_macros) {
|
||||
if (! _allocated_macros)
|
||||
_allocated_macros = 401;
|
||||
else
|
||||
_allocated_macros <<= 1;
|
||||
|
||||
_macros = (Macro **) realloc(_macros, sizeof(Macro *) * _allocated_macros);
|
||||
}
|
||||
|
||||
_macros[_macro_count] = m;
|
||||
|
||||
if (! _hash || _macro_count > (_hash_count >> 1)) {
|
||||
rehash();
|
||||
} else {
|
||||
const unsigned h = m->hashcode % _hash_count;
|
||||
m->next = _hash[h];
|
||||
_hash[h] = m;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
void Environment::remove (const QByteArray &name)
|
||||
{
|
||||
Macro macro;
|
||||
macro.name = name;
|
||||
macro.hidden = true;
|
||||
bind(macro);
|
||||
}
|
||||
|
||||
bool Environment::isBuiltinMacro(const QByteArray &s) const
|
||||
{
|
||||
if (s.length() != 8)
|
||||
return false;
|
||||
|
||||
if (s[0] == '_') {
|
||||
if (s[1] == '_') {
|
||||
if (s[2] == 'D') {
|
||||
if (s[3] == 'A') {
|
||||
if (s[4] == 'T') {
|
||||
if (s[5] == 'E') {
|
||||
if (s[6] == '_') {
|
||||
if (s[7] == '_') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (s[2] == 'F') {
|
||||
if (s[3] == 'I') {
|
||||
if (s[4] == 'L') {
|
||||
if (s[5] == 'E') {
|
||||
if (s[6] == '_') {
|
||||
if (s[7] == '_') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (s[2] == 'L') {
|
||||
if (s[3] == 'I') {
|
||||
if (s[4] == 'N') {
|
||||
if (s[5] == 'E') {
|
||||
if (s[6] == '_') {
|
||||
if (s[7] == '_') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (s[2] == 'T') {
|
||||
if (s[3] == 'I') {
|
||||
if (s[4] == 'M') {
|
||||
if (s[5] == 'E') {
|
||||
if (s[6] == '_') {
|
||||
if (s[7] == '_') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Macro *Environment::resolve (const QByteArray &name) const
|
||||
{
|
||||
if (! _macros)
|
||||
return 0;
|
||||
|
||||
Macro *it = _hash[hash_code (name) % _hash_count];
|
||||
for (; it; it = it->next) {
|
||||
if (it->name != name)
|
||||
continue;
|
||||
else if (it->hidden)
|
||||
return 0;
|
||||
else break;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
unsigned Environment::hash_code (const QByteArray &s)
|
||||
{
|
||||
unsigned hash_value = 0;
|
||||
|
||||
for (int i = 0; i < s.size (); ++i)
|
||||
hash_value = (hash_value << 5) - hash_value + s.at (i);
|
||||
|
||||
return hash_value;
|
||||
}
|
||||
|
||||
void Environment::rehash()
|
||||
{
|
||||
if (_hash) {
|
||||
free(_hash);
|
||||
_hash_count <<= 1;
|
||||
}
|
||||
|
||||
_hash = (Macro **) calloc(_hash_count, sizeof(Macro *));
|
||||
|
||||
for (Macro **it = firstMacro(); it != lastMacro(); ++it) {
|
||||
Macro *m= *it;
|
||||
const unsigned h = m->hashcode % _hash_count;
|
||||
m->next = _hash[h];
|
||||
_hash[h] = m;
|
||||
}
|
||||
}
|
||||
@@ -1,109 +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.2, 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_ENVIRONMENT_H
|
||||
#define PP_ENVIRONMENT_H
|
||||
|
||||
#include <QVector>
|
||||
#include <QByteArray>
|
||||
|
||||
namespace rpp {
|
||||
|
||||
struct Macro;
|
||||
|
||||
class Environment
|
||||
{
|
||||
public:
|
||||
Environment();
|
||||
~Environment();
|
||||
|
||||
unsigned macroCount() const;
|
||||
Macro *macroAt(unsigned index) const;
|
||||
|
||||
Macro *bind(const Macro ¯o);
|
||||
void remove(const QByteArray &name);
|
||||
|
||||
Macro *resolve(const QByteArray &name) const;
|
||||
bool isBuiltinMacro(const QByteArray &name) const;
|
||||
|
||||
const Macro *const *firstMacro() const
|
||||
{ return _macros; }
|
||||
|
||||
Macro **firstMacro()
|
||||
{ return _macros; }
|
||||
|
||||
const Macro *const *lastMacro() const
|
||||
{ return _macros + _macro_count + 1; }
|
||||
|
||||
Macro **lastMacro()
|
||||
{ return _macros + _macro_count + 1; }
|
||||
|
||||
private:
|
||||
static unsigned hash_code (const QByteArray &s);
|
||||
void rehash();
|
||||
|
||||
public:
|
||||
QByteArray current_file;
|
||||
unsigned currentLine;
|
||||
bool hide_next;
|
||||
|
||||
private:
|
||||
Macro **_macros;
|
||||
int _allocated_macros;
|
||||
int _macro_count;
|
||||
Macro **_hash;
|
||||
int _hash_count;
|
||||
};
|
||||
|
||||
} // namespace rpp
|
||||
|
||||
#endif // PP_ENVIRONMENT_H
|
||||
@@ -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.2, 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 rpp {
|
||||
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 rpp
|
||||
|
||||
#endif // PP_INTERNAL_H
|
||||
@@ -1,361 +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.2, included in the file GPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
***************************************************************************/
|
||||
|
||||
#include "pp.h"
|
||||
#include "pp-macro-expander.h"
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace rpp;
|
||||
|
||||
MacroExpander::MacroExpander (Environment &env, pp_frame *frame)
|
||||
: env(env), frame(frame),
|
||||
lines(0), generated_lines(0)
|
||||
{ }
|
||||
|
||||
const QByteArray *MacroExpander::resolve_formal(const QByteArray &__name)
|
||||
{
|
||||
if (! (frame && frame->expanding_macro))
|
||||
return 0;
|
||||
|
||||
const QVector<QByteArray> &formals = frame->expanding_macro->formals;
|
||||
for (int index = 0; index < formals.size(); ++index) {
|
||||
const QByteArray formal = formals.at(index);
|
||||
|
||||
if (formal == __name && index < frame->actuals.size())
|
||||
return &frame->actuals.at(index);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *MacroExpander::operator () (const char *__first, const char *__last,
|
||||
QByteArray *__result)
|
||||
{
|
||||
generated_lines = 0;
|
||||
__first = skip_blanks (__first, __last);
|
||||
lines = skip_blanks.lines;
|
||||
|
||||
while (__first != __last)
|
||||
{
|
||||
if (*__first == '\n')
|
||||
{
|
||||
__result->append("\n# ");
|
||||
__result->append(QByteArray::number(env.currentLine));
|
||||
__result->append(' ');
|
||||
__result->append('"');
|
||||
__result->append(env.current_file);
|
||||
__result->append('"');
|
||||
__result->append('\n');
|
||||
++lines;
|
||||
|
||||
__first = skip_blanks (++__first, __last);
|
||||
lines += skip_blanks.lines;
|
||||
|
||||
if (__first != __last && *__first == '#')
|
||||
break;
|
||||
}
|
||||
else if (*__first == '#')
|
||||
{
|
||||
__first = skip_blanks (++__first, __last);
|
||||
lines += skip_blanks.lines;
|
||||
|
||||
const char *end_id = skip_identifier (__first, __last);
|
||||
const QByteArray fast_name(__first, end_id - __first);
|
||||
__first = end_id;
|
||||
|
||||
if (const QByteArray *actual = resolve_formal (fast_name))
|
||||
{
|
||||
__result->append('\"');
|
||||
|
||||
const char *actual_begin = actual->constData ();
|
||||
const char *actual_end = actual_begin + actual->size ();
|
||||
|
||||
for (const char *it = skip_whitespaces (actual_begin, actual_end);
|
||||
it != actual_end; ++it)
|
||||
{
|
||||
if (*it == '"' || *it == '\\')
|
||||
{
|
||||
__result->append('\\');
|
||||
__result->append(*it);
|
||||
}
|
||||
else if (*it == '\n')
|
||||
{
|
||||
__result->append('"');
|
||||
__result->append('\n');
|
||||
__result->append('"');
|
||||
}
|
||||
else
|
||||
__result->append(*it);
|
||||
}
|
||||
|
||||
__result->append('\"');
|
||||
}
|
||||
else
|
||||
__result->append('#'); // ### warning message?
|
||||
}
|
||||
else if (*__first == '\"')
|
||||
{
|
||||
const char *next_pos = skip_string_literal (__first, __last);
|
||||
lines += skip_string_literal.lines;
|
||||
__result->append(__first, next_pos - __first);
|
||||
__first = next_pos;
|
||||
}
|
||||
else if (*__first == '\'')
|
||||
{
|
||||
const char *next_pos = skip_char_literal (__first, __last);
|
||||
lines += skip_char_literal.lines;
|
||||
__result->append(__first, next_pos - __first);
|
||||
__first = next_pos;
|
||||
}
|
||||
else if (_PP_internal::comment_p (__first, __last))
|
||||
{
|
||||
__first = skip_comment_or_divop (__first, __last);
|
||||
int n = skip_comment_or_divop.lines;
|
||||
lines += n;
|
||||
|
||||
while (n-- > 0)
|
||||
__result->append('\n');
|
||||
}
|
||||
else if (pp_isspace (*__first))
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
{
|
||||
if (*__first == '\n' || !pp_isspace (*__first))
|
||||
break;
|
||||
}
|
||||
|
||||
__result->append(' ');
|
||||
}
|
||||
else if (pp_isdigit (*__first))
|
||||
{
|
||||
const char *next_pos = skip_number (__first, __last);
|
||||
lines += skip_number.lines;
|
||||
__result->append(__first, next_pos - __first);
|
||||
__first = next_pos;
|
||||
}
|
||||
else if (pp_isalpha (*__first) || *__first == '_')
|
||||
{
|
||||
const char *name_begin = __first;
|
||||
const char *name_end = skip_identifier (__first, __last);
|
||||
__first = name_end; // advance
|
||||
|
||||
// search for the paste token
|
||||
const char *next = skip_blanks (__first, __last);
|
||||
bool paste = false;
|
||||
if (next != __last && *next == '#')
|
||||
{
|
||||
paste = true;
|
||||
++next;
|
||||
if (next != __last && *next == '#')
|
||||
__first = skip_blanks(++next, __last);
|
||||
}
|
||||
|
||||
const QByteArray fast_name(name_begin, name_end - name_begin);
|
||||
|
||||
if (const QByteArray *actual = resolve_formal (fast_name))
|
||||
{
|
||||
const char *begin = actual->constData ();
|
||||
const char *end = begin + actual->size ();
|
||||
if (paste) {
|
||||
for (--end; end != begin - 1; --end) {
|
||||
if (! pp_isspace(*end))
|
||||
break;
|
||||
}
|
||||
++end;
|
||||
}
|
||||
__result->append(begin, end - begin);
|
||||
continue;
|
||||
}
|
||||
|
||||
Macro *macro = env.resolve (fast_name);
|
||||
if (! macro || macro->hidden || env.hide_next)
|
||||
{
|
||||
if (fast_name.size () == 7 && fast_name [0] == 'd' && fast_name == "defined")
|
||||
env.hide_next = true;
|
||||
else
|
||||
env.hide_next = false;
|
||||
|
||||
if (fast_name.size () == 8 && fast_name [0] == '_' && fast_name [1] == '_')
|
||||
{
|
||||
if (fast_name == "__LINE__")
|
||||
{
|
||||
char buf [16];
|
||||
const size_t count = qsnprintf (buf, 16, "%d", env.currentLine + lines);
|
||||
__result->append(buf, count);
|
||||
continue;
|
||||
}
|
||||
|
||||
else if (fast_name == "__FILE__")
|
||||
{
|
||||
__result->append('"');
|
||||
__result->append(env.current_file);
|
||||
__result->append('"');
|
||||
continue;
|
||||
}
|
||||
|
||||
else if (fast_name == "__DATE__")
|
||||
{
|
||||
__result->append('"');
|
||||
__result->append(QDate::currentDate().toString().toUtf8());
|
||||
__result->append('"');
|
||||
continue;
|
||||
}
|
||||
|
||||
else if (fast_name == "__TIME__")
|
||||
{
|
||||
__result->append('"');
|
||||
__result->append(QTime::currentTime().toString().toUtf8());
|
||||
__result->append('"');
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
__result->append(name_begin, name_end - name_begin);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! macro->function_like)
|
||||
{
|
||||
Macro *m = 0;
|
||||
|
||||
if (! macro->definition.isEmpty())
|
||||
{
|
||||
macro->hidden = true;
|
||||
|
||||
QByteArray __tmp;
|
||||
__tmp.reserve (256);
|
||||
|
||||
MacroExpander expand_macro (env);
|
||||
expand_macro (macro->definition.constBegin (), macro->definition.constEnd (), &__tmp);
|
||||
generated_lines += expand_macro.lines;
|
||||
|
||||
if (! __tmp.isEmpty ())
|
||||
{
|
||||
const char *__tmp_begin = __tmp.constBegin();
|
||||
const char *__tmp_end = __tmp.constEnd();
|
||||
const char *__begin_id = skip_whitespaces (__tmp_begin, __tmp_end);
|
||||
const char *__end_id = skip_identifier (__begin_id, __tmp_end);
|
||||
|
||||
if (__end_id == __tmp_end)
|
||||
{
|
||||
const QByteArray __id (__begin_id, __end_id - __begin_id);
|
||||
m = env.resolve (__id);
|
||||
}
|
||||
|
||||
if (! m)
|
||||
*__result += __tmp;
|
||||
}
|
||||
|
||||
macro->hidden = false;
|
||||
}
|
||||
|
||||
if (! m)
|
||||
continue;
|
||||
|
||||
macro = m;
|
||||
}
|
||||
|
||||
// function like macro
|
||||
const char *arg_it = skip_whitespaces (__first, __last);
|
||||
|
||||
if (arg_it == __last || *arg_it != '(')
|
||||
{
|
||||
__result->append(name_begin, name_end - name_begin);
|
||||
lines += skip_whitespaces.lines;
|
||||
__first = arg_it;
|
||||
continue;
|
||||
}
|
||||
|
||||
QVector<QByteArray> actuals;
|
||||
actuals.reserve (5);
|
||||
++arg_it; // skip '('
|
||||
|
||||
MacroExpander expand_actual (env, frame);
|
||||
|
||||
const char *arg_end = skip_argument_variadics (actuals, macro, arg_it, __last);
|
||||
if (arg_it != arg_end)
|
||||
{
|
||||
const QByteArray actual (arg_it, arg_end - arg_it);
|
||||
QByteArray expanded;
|
||||
expand_actual (actual.constBegin (), actual.constEnd (), &expanded);
|
||||
actuals.push_back (expanded);
|
||||
arg_it = arg_end;
|
||||
}
|
||||
|
||||
while (arg_it != __last && *arg_end == ',')
|
||||
{
|
||||
++arg_it; // skip ','
|
||||
|
||||
arg_end = skip_argument_variadics (actuals, macro, arg_it, __last);
|
||||
const QByteArray actual (arg_it, arg_end - arg_it);
|
||||
QByteArray expanded;
|
||||
expand_actual (actual.constBegin (), actual.constEnd (), &expanded);
|
||||
actuals.push_back (expanded);
|
||||
arg_it = arg_end;
|
||||
}
|
||||
|
||||
if (! (arg_it != __last && *arg_it == ')'))
|
||||
return __last;
|
||||
|
||||
++arg_it; // skip ')'
|
||||
__first = arg_it;
|
||||
|
||||
pp_frame frame (macro, actuals);
|
||||
MacroExpander expand_macro (env, &frame);
|
||||
macro->hidden = true;
|
||||
expand_macro (macro->definition.constBegin (), macro->definition.constEnd (), __result);
|
||||
macro->hidden = false;
|
||||
generated_lines += expand_macro.lines;
|
||||
}
|
||||
else
|
||||
__result->append(*__first++);
|
||||
}
|
||||
|
||||
return __first;
|
||||
}
|
||||
|
||||
const char *MacroExpander::skip_argument_variadics (QVector<QByteArray> const &__actuals,
|
||||
Macro *__macro,
|
||||
const char *__first, const char *__last)
|
||||
{
|
||||
const char *arg_end = skip_argument (__first, __last);
|
||||
|
||||
while (__macro->variadics && __first != arg_end && arg_end != __last && *arg_end == ','
|
||||
&& (__actuals.size () + 1) == __macro->formals.size ())
|
||||
{
|
||||
arg_end = skip_argument (++arg_end, __last);
|
||||
}
|
||||
|
||||
return arg_end;
|
||||
}
|
||||
@@ -1,103 +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.2, 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_MACRO_EXPANDER_H
|
||||
#define PP_MACRO_EXPANDER_H
|
||||
|
||||
namespace rpp {
|
||||
|
||||
struct pp_frame
|
||||
{
|
||||
Macro *expanding_macro;
|
||||
const QVector<QByteArray> actuals;
|
||||
|
||||
pp_frame (Macro *expanding_macro, const QVector<QByteArray> &actuals)
|
||||
: expanding_macro (expanding_macro),
|
||||
actuals (actuals)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MacroExpander
|
||||
{
|
||||
Environment &env;
|
||||
pp_frame *frame;
|
||||
|
||||
pp_skip_number skip_number;
|
||||
pp_skip_identifier skip_identifier;
|
||||
pp_skip_string_literal skip_string_literal;
|
||||
pp_skip_char_literal skip_char_literal;
|
||||
pp_skip_argument skip_argument;
|
||||
pp_skip_comment_or_divop skip_comment_or_divop;
|
||||
pp_skip_blanks skip_blanks;
|
||||
pp_skip_whitespaces skip_whitespaces;
|
||||
|
||||
const QByteArray *resolve_formal (const QByteArray &name);
|
||||
|
||||
public:
|
||||
MacroExpander (Environment &env, pp_frame *frame = 0);
|
||||
|
||||
const char *operator () (const char *first, const char *last,
|
||||
QByteArray *result);
|
||||
|
||||
const char *skip_argument_variadics (const QVector<QByteArray> &actuals,
|
||||
Macro *macro,
|
||||
const char *first, const char *last);
|
||||
|
||||
public: // attributes
|
||||
int lines;
|
||||
int generated_lines;
|
||||
};
|
||||
|
||||
} // namespace rpp
|
||||
|
||||
#endif // PP_MACRO_EXPANDER_H
|
||||
|
||||
@@ -1,95 +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.2, 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_MACRO_H
|
||||
#define PP_MACRO_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QVector>
|
||||
|
||||
namespace rpp {
|
||||
|
||||
struct Macro
|
||||
{
|
||||
QByteArray name;
|
||||
QByteArray definition;
|
||||
QVector<QByteArray> formals;
|
||||
QByteArray fileName;
|
||||
int line;
|
||||
int lines;
|
||||
Macro *next;
|
||||
unsigned hashcode;
|
||||
|
||||
union
|
||||
{
|
||||
unsigned state;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned hidden: 1;
|
||||
unsigned function_like: 1;
|
||||
unsigned variadics: 1;
|
||||
};
|
||||
};
|
||||
|
||||
inline Macro():
|
||||
line(0),
|
||||
lines(0),
|
||||
next(0),
|
||||
hashcode(0),
|
||||
state(0)
|
||||
{ }
|
||||
};
|
||||
|
||||
} // namespace rpp
|
||||
|
||||
#endif // PP_MACRO_H
|
||||
@@ -1,380 +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.2, 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_SCANNER_H
|
||||
#define PP_SCANNER_H
|
||||
|
||||
namespace rpp {
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
struct pp_skip_argument
|
||||
{
|
||||
pp_skip_identifier skip_number;
|
||||
pp_skip_identifier skip_identifier;
|
||||
pp_skip_string_literal skip_string_literal;
|
||||
pp_skip_char_literal skip_char_literal;
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace rpp
|
||||
|
||||
#endif // PP_SCANNER_H
|
||||
|
||||
// kate: space-indent on; indent-width 2; replace-tabs on;
|
||||
@@ -1,69 +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.2, 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_H
|
||||
#define PP_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"
|
||||
#include "pp-macro-expander.h"
|
||||
#include "pp-engine.h"
|
||||
#include "pp-client.h"
|
||||
|
||||
#endif // PP_H
|
||||
@@ -1,18 +0,0 @@
|
||||
DEPENDPATH += $$PWD
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += $$PWD/pp-cctype.h \
|
||||
$$PWD/pp-engine.h \
|
||||
$$PWD/pp-environment.h \
|
||||
$$PWD/pp-internal.h \
|
||||
$$PWD/pp-macro-expander.h \
|
||||
$$PWD/pp-macro.h \
|
||||
$$PWD/pp-scanner.h \
|
||||
$$PWD/pp.h \
|
||||
$$PWD/pp-client.h
|
||||
|
||||
SOURCES += $$PWD/pp-engine.cpp \
|
||||
$$PWD/pp-environment.cpp \
|
||||
$$PWD/pp-macro-expander.cpp
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const
|
||||
void SearchSymbols::appendItem(const QString &name,
|
||||
const QString &info,
|
||||
ModelItemInfo::ItemType type,
|
||||
const CPlusPlus::Symbol *symbol)
|
||||
const Symbol *symbol)
|
||||
{
|
||||
const QIcon icon = icons.iconForSymbol(symbol);
|
||||
items.append(ModelItemInfo(name, info, type,
|
||||
|
||||
@@ -605,7 +605,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList & /*arguments*/, QStrin
|
||||
}
|
||||
}
|
||||
|
||||
connect(m_sessionManagerAction, SIGNAL(triggered()), this, SLOT(sessionManager()));
|
||||
connect(m_sessionManagerAction, SIGNAL(triggered()), this, SLOT(showSessionManager()));
|
||||
connect(m_newAction, SIGNAL(triggered()), this, SLOT(newProject()));
|
||||
#if 0
|
||||
connect(m_loadAction, SIGNAL(triggered()), this, SLOT(loadAction()));
|
||||
@@ -765,10 +765,10 @@ void ProjectExplorerPlugin::newProject()
|
||||
updateActions();
|
||||
}
|
||||
|
||||
void ProjectExplorerPlugin::sessionManager()
|
||||
void ProjectExplorerPlugin::showSessionManager()
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << "ProjectExplorerPlugin::newSession";
|
||||
qDebug() << "ProjectExplorerPlugin::showSessionManager";
|
||||
|
||||
if (m_session->isDefaultVirgin()) {
|
||||
// do not save new virgin default sessions
|
||||
|
||||
@@ -143,7 +143,7 @@ private slots:
|
||||
void unloadProject();
|
||||
void clearSession();
|
||||
void newProject();
|
||||
void sessionManager();
|
||||
void showSessionManager();
|
||||
void populateBuildConfigurationMenu();
|
||||
void buildConfigurationMenuTriggered(QAction *);
|
||||
void populateRunConfigurationMenu();
|
||||
|
||||
@@ -709,7 +709,7 @@ void SessionManager::editDependencies()
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
QList<Project *> SessionManager::projects() const
|
||||
const QList<Project *> &SessionManager::projects() const
|
||||
{
|
||||
return m_file->m_projects;
|
||||
}
|
||||
@@ -839,26 +839,26 @@ Project *SessionManager::projectForFile(const QString &fileName) const
|
||||
if (debug)
|
||||
qDebug() << "SessionManager::projectForFile(" << fileName << ")";
|
||||
|
||||
Project *project = 0;
|
||||
const QList<Project *> &projectList = projects();
|
||||
|
||||
QList<Project *> projectList = projects();
|
||||
// Check current project first
|
||||
Project *currentProject = ProjectExplorerPlugin::instance()->currentProject();
|
||||
if (currentProject && projectContainsFile(currentProject, fileName))
|
||||
return currentProject;
|
||||
|
||||
// Always check current project first
|
||||
if (Project *currentProject = ProjectExplorerPlugin::instance()->currentProject()) {
|
||||
projectList.removeOne(currentProject);
|
||||
projectList.insert(0, currentProject);
|
||||
}
|
||||
foreach (Project *p, projectList)
|
||||
if (p != currentProject && projectContainsFile(p, fileName))
|
||||
return p;
|
||||
|
||||
foreach (Project *p, projectList) {
|
||||
if (!m_projectFileCache.contains(p)) {
|
||||
m_projectFileCache.insert(p, p->files(Project::AllFiles));
|
||||
}
|
||||
if (m_projectFileCache.value(p).contains(fileName)) {
|
||||
project = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return project;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool SessionManager::projectContainsFile(Project *p, const QString &fileName) const
|
||||
{
|
||||
if (!m_projectFileCache.contains(p))
|
||||
m_projectFileCache.insert(p, p->files(Project::AllFiles));
|
||||
|
||||
return m_projectFileCache.value(p).contains(fileName);
|
||||
}
|
||||
|
||||
void SessionManager::setEditorCodec(Core::IEditor *editor, const QString &fileName)
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
Core::IFile *file() const;
|
||||
Project *startupProject() const;
|
||||
|
||||
QList<Project *> projects() const;
|
||||
const QList<Project *> &projects() const;
|
||||
|
||||
bool isDefaultVirgin() const;
|
||||
bool isDefaultSession(const QString &session) const;
|
||||
@@ -182,6 +182,7 @@ private:
|
||||
bool loadImpl(const QString &fileName);
|
||||
bool createImpl(const QString &fileName);
|
||||
QString sessionNameToFileName(const QString &session);
|
||||
bool projectContainsFile(Project *p, const QString &fileName) const;
|
||||
|
||||
bool recursiveDependencyCheck(const QString &newDep, const QString &checkDep) const;
|
||||
QStringList dependencies(const QString &proName) const;
|
||||
|
||||
@@ -474,6 +474,9 @@ void Qt4Project::updateCodeModel()
|
||||
}
|
||||
}
|
||||
|
||||
// Add mkspec directory
|
||||
allIncludePaths.append(qtVersion(activeBuildConfiguration())->mkspecPath());
|
||||
|
||||
QStringList files;
|
||||
files += m_projectFiles->files[HeaderType];
|
||||
files += m_projectFiles->generatedFiles[HeaderType];
|
||||
|
||||
@@ -728,6 +728,12 @@ QString QtVersion::mkspec() const
|
||||
return m_mkspec;
|
||||
}
|
||||
|
||||
QString QtVersion::mkspecPath() const
|
||||
{
|
||||
updateMkSpec();
|
||||
return m_mkspecFullPath;
|
||||
}
|
||||
|
||||
QHash<QString,QString> QtVersion::versionInfo() const
|
||||
{
|
||||
updateVersionInfo();
|
||||
@@ -1023,25 +1029,25 @@ void QtVersion::updateMkSpec() const
|
||||
//qDebug()<<"Finding mkspec for"<<path();
|
||||
|
||||
QString mkspec;
|
||||
QFile f(path() + "/.qmake.cache");
|
||||
if (f.exists() && f.open(QIODevice::ReadOnly)) {
|
||||
while(!f.atEnd()) {
|
||||
QByteArray line = f.readLine();
|
||||
if(line.startsWith("QMAKESPEC")) {
|
||||
const QList<QByteArray> &temp = line.split('=');
|
||||
if(temp.size() == 2) {
|
||||
mkspec = temp.at(1).trimmed();
|
||||
if (mkspec.startsWith("$$QT_BUILD_TREE/mkspecs/"))
|
||||
mkspec = mkspec.mid(QString("$$QT_BUILD_TREE/mkspecs/").length());
|
||||
else if (mkspec.startsWith("$$QT_BUILD_TREE\\mkspecs\\"))
|
||||
mkspec = mkspec.mid(QString("$$QT_BUILD_TREE\\mkspecs\\").length());
|
||||
mkspec = QDir::fromNativeSeparators(mkspec);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
} else {
|
||||
// QFile f(path() + "/.qmake.cache");
|
||||
// if (f.exists() && f.open(QIODevice::ReadOnly)) {
|
||||
// while(!f.atEnd()) {
|
||||
// QByteArray line = f.readLine();
|
||||
// if(line.startsWith("QMAKESPEC")) {
|
||||
// const QList<QByteArray> &temp = line.split('=');
|
||||
// if(temp.size() == 2) {
|
||||
// mkspec = temp.at(1).trimmed();
|
||||
// if (mkspec.startsWith("$$QT_BUILD_TREE/mkspecs/"))
|
||||
// mkspec = mkspec.mid(QString("$$QT_BUILD_TREE/mkspecs/").length());
|
||||
// else if (mkspec.startsWith("$$QT_BUILD_TREE\\mkspecs\\"))
|
||||
// mkspec = mkspec.mid(QString("$$QT_BUILD_TREE\\mkspecs\\").length());
|
||||
// mkspec = QDir::fromNativeSeparators(mkspec);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// f.close();
|
||||
// } else {
|
||||
// no .qmake.cache so look at the default mkspec
|
||||
QString mkspecPath = versionInfo().value("QMAKE_MKSPECS");
|
||||
if (mkspecPath.isEmpty())
|
||||
@@ -1096,8 +1102,9 @@ void QtVersion::updateMkSpec() const
|
||||
mkspec = f2.symLinkTarget();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// }
|
||||
|
||||
m_mkspecFullPath = mkspec;
|
||||
int index = mkspec.lastIndexOf('/');
|
||||
if(index == -1)
|
||||
index = mkspec.lastIndexOf('\\');
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
QString path() const;
|
||||
QString sourcePath() const;
|
||||
QString mkspec() const;
|
||||
QString mkspecPath() const;
|
||||
QString makeCommand() const;
|
||||
QString qmakeCommand() const;
|
||||
// Returns the PREFIX, BINPREFIX, DOCPREFIX and similar information
|
||||
@@ -107,6 +108,7 @@ private:
|
||||
QString m_path;
|
||||
QString m_sourcePath;
|
||||
mutable QString m_mkspec; // updated lazily
|
||||
mutable QString m_mkspecFullPath;
|
||||
QString m_mingwDirectory;
|
||||
QString m_prependPath;
|
||||
QString m_msvcVersion;
|
||||
|
||||
Reference in New Issue
Block a user