forked from qt-creator/qt-creator
Use Macros.
This commit is contained in:
@@ -138,19 +138,9 @@ void Document::addIncludeFile(const QString &fileName)
|
||||
_includedFiles.append(fileName);
|
||||
}
|
||||
|
||||
QByteArray Document::definedMacros() const
|
||||
void Document::appendMacro(const Macro ¯o)
|
||||
{
|
||||
return _definedMacros;
|
||||
}
|
||||
|
||||
void Document::appendMacro(const QByteArray ¯oName, const QByteArray &text)
|
||||
{
|
||||
int index = macroName.indexOf('(');
|
||||
if (index == -1)
|
||||
_macroNames.insert(macroName);
|
||||
else
|
||||
_macroNames.insert(macroName.left(index));
|
||||
_definedMacros += text;
|
||||
_definedMacros.append(macro);
|
||||
}
|
||||
|
||||
void Document::addMacroUse(unsigned offset, unsigned length)
|
||||
@@ -251,11 +241,6 @@ void Document::stopSkippingBlocks(unsigned stop)
|
||||
_skippedBlocks.back() = Block(start, stop);
|
||||
}
|
||||
|
||||
QSet<QByteArray> Document::macroNames() const
|
||||
{
|
||||
return _macroNames;
|
||||
}
|
||||
|
||||
bool Document::parse(ParseMode mode)
|
||||
{
|
||||
TranslationUnit::ParseMode m = TranslationUnit::ParseTranlationUnit;
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
#include <CPlusPlusForwardDeclarations.h>
|
||||
|
||||
#include "pp-macro.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
@@ -45,6 +47,8 @@
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
class Macro;
|
||||
|
||||
class CPLUSPLUS_EXPORT Document
|
||||
{
|
||||
Document(const Document &other);
|
||||
@@ -63,10 +67,7 @@ public:
|
||||
QStringList includedFiles() const;
|
||||
void addIncludeFile(const QString &fileName);
|
||||
|
||||
QByteArray definedMacros() const;
|
||||
QSet<QByteArray> macroNames() const;
|
||||
|
||||
void appendMacro(const QByteArray ¯oName, const QByteArray &text);
|
||||
void appendMacro(const Macro ¯o);
|
||||
|
||||
void addMacroUse(unsigned offset, unsigned length);
|
||||
|
||||
@@ -81,6 +82,9 @@ public:
|
||||
Scope *globalSymbols() const; // ### deprecate?
|
||||
Namespace *globalNamespace() const;
|
||||
|
||||
QList<Macro> definedMacros() const
|
||||
{ return _definedMacros; }
|
||||
|
||||
Symbol *findSymbolAt(unsigned line, unsigned column) const;
|
||||
|
||||
void setSource(const QByteArray &source);
|
||||
@@ -191,8 +195,7 @@ private:
|
||||
TranslationUnit *_translationUnit;
|
||||
Namespace *_globalNamespace;
|
||||
QList<DiagnosticMessage> _diagnosticMessages;
|
||||
QByteArray _definedMacros;
|
||||
QSet<QByteArray> _macroNames;
|
||||
QList<Macro> _definedMacros;
|
||||
QList<Block> _skippedBlocks;
|
||||
QList<Block> _macroUses;
|
||||
};
|
||||
|
||||
@@ -53,20 +53,22 @@
|
||||
#ifndef PP_CCTYPE_H
|
||||
#define PP_CCTYPE_H
|
||||
|
||||
#include <CPlusPlusForwardDeclarations.h>
|
||||
|
||||
#include <cctype>
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
inline bool pp_isalpha (int __ch)
|
||||
inline bool CPLUSPLUS_EXPORT pp_isalpha (int __ch)
|
||||
{ return std::isalpha ((unsigned char) __ch) != 0; }
|
||||
|
||||
inline bool pp_isalnum (int __ch)
|
||||
inline bool CPLUSPLUS_EXPORT pp_isalnum (int __ch)
|
||||
{ return std::isalnum ((unsigned char) __ch) != 0; }
|
||||
|
||||
inline bool pp_isdigit (int __ch)
|
||||
inline bool CPLUSPLUS_EXPORT pp_isdigit (int __ch)
|
||||
{ return std::isdigit ((unsigned char) __ch) != 0; }
|
||||
|
||||
inline bool pp_isspace (int __ch)
|
||||
inline bool CPLUSPLUS_EXPORT pp_isspace (int __ch)
|
||||
{ return std::isspace ((unsigned char) __ch) != 0; }
|
||||
|
||||
} // namespace CPlusPlus
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#ifndef PP_CLIENT_H
|
||||
#define PP_CLIENT_H
|
||||
|
||||
#include <CPlusPlusForwardDeclarations.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
@@ -42,7 +44,7 @@ namespace CPlusPlus {
|
||||
|
||||
class Macro;
|
||||
|
||||
class Client
|
||||
class CPLUSPLUS_EXPORT Client
|
||||
{
|
||||
Client(const Client &other);
|
||||
void operator=(const Client &other);
|
||||
@@ -60,7 +62,7 @@ public:
|
||||
virtual ~Client()
|
||||
{ }
|
||||
|
||||
virtual void macroAdded(const QByteArray ¯oId, const QByteArray &text) = 0;
|
||||
virtual void macroAdded(const Macro ¯o) = 0;
|
||||
virtual void sourceNeeded(QString &fileName, IncludeType mode) = 0; // ### FIX the signature.
|
||||
|
||||
virtual void startExpandingMacro(unsigned offset,
|
||||
|
||||
@@ -906,16 +906,8 @@ void pp::processDefine(TokenIterator firstToken, TokenIterator lastToken)
|
||||
|
||||
env.bind(macro);
|
||||
|
||||
QByteArray macroText;
|
||||
macroText.reserve(64);
|
||||
macroText += "#define ";
|
||||
|
||||
macroText += macroId;
|
||||
macroText += ' ';
|
||||
macroText += macro.definition;
|
||||
macroText += '\n';
|
||||
|
||||
client->macroAdded(macroId, macroText);
|
||||
if (client)
|
||||
client->macroAdded(macro);
|
||||
}
|
||||
|
||||
void pp::processIf(TokenIterator firstToken, TokenIterator lastToken)
|
||||
@@ -1019,13 +1011,10 @@ void pp::processUndef(TokenIterator firstToken, TokenIterator lastToken)
|
||||
|
||||
if (tk->is(T_IDENTIFIER)) {
|
||||
const QByteArray macroName = tokenText(*tk);
|
||||
env.remove(macroName);
|
||||
const Macro *macro = env.remove(macroName);
|
||||
|
||||
QByteArray macroText;
|
||||
macroText += "#undef ";
|
||||
macroText += macroName;
|
||||
macroText += '\n';
|
||||
client->macroAdded(macroName, macroText);
|
||||
if (client && macro)
|
||||
client->macroAdded(*macro);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace CPlusPlus {
|
||||
#undef PP_DEFINE_BIN_OP
|
||||
};
|
||||
|
||||
class pp
|
||||
class CPLUSPLUS_EXPORT pp
|
||||
{
|
||||
Client *client;
|
||||
Environment &env;
|
||||
|
||||
@@ -115,12 +115,12 @@ Macro *Environment::bind(const Macro &__macro)
|
||||
return m;
|
||||
}
|
||||
|
||||
void Environment::remove (const QByteArray &name)
|
||||
Macro *Environment::remove (const QByteArray &name)
|
||||
{
|
||||
Macro macro;
|
||||
macro.name = name;
|
||||
macro.hidden = true;
|
||||
bind(macro);
|
||||
return bind(macro);
|
||||
}
|
||||
|
||||
bool Environment::isBuiltinMacro(const QByteArray &s) const
|
||||
|
||||
@@ -53,14 +53,16 @@
|
||||
#ifndef PP_ENVIRONMENT_H
|
||||
#define PP_ENVIRONMENT_H
|
||||
|
||||
#include "CPlusPlusForwardDeclarations.h"
|
||||
|
||||
#include <QVector>
|
||||
#include <QByteArray>
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
struct Macro;
|
||||
class Macro;
|
||||
|
||||
class Environment
|
||||
class CPLUSPLUS_EXPORT Environment
|
||||
{
|
||||
public:
|
||||
Environment();
|
||||
@@ -70,7 +72,7 @@ public:
|
||||
Macro *macroAt(unsigned index) const;
|
||||
|
||||
Macro *bind(const Macro ¯o);
|
||||
void remove(const QByteArray &name);
|
||||
Macro *remove(const QByteArray &name);
|
||||
|
||||
Macro *resolve(const QByteArray &name) const;
|
||||
bool isBuiltinMacro(const QByteArray &name) const;
|
||||
|
||||
@@ -53,42 +53,43 @@
|
||||
#ifndef PP_MACRO_H
|
||||
#define PP_MACRO_H
|
||||
|
||||
#include <CPlusPlusForwardDeclarations.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QVector>
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
struct Macro
|
||||
class CPLUSPLUS_EXPORT Macro
|
||||
{
|
||||
public:
|
||||
QByteArray name;
|
||||
QByteArray definition;
|
||||
QVector<QByteArray> formals;
|
||||
QByteArray fileName;
|
||||
int line;
|
||||
Macro *next;
|
||||
unsigned hashcode;
|
||||
|
||||
union
|
||||
{
|
||||
QByteArray name;
|
||||
QByteArray definition;
|
||||
QVector<QByteArray> formals;
|
||||
QByteArray fileName;
|
||||
int line;
|
||||
int lines;
|
||||
Macro *next;
|
||||
unsigned hashcode;
|
||||
unsigned state;
|
||||
|
||||
union
|
||||
struct
|
||||
{
|
||||
unsigned state;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned hidden: 1;
|
||||
unsigned function_like: 1;
|
||||
unsigned variadics: 1;
|
||||
};
|
||||
unsigned hidden: 1;
|
||||
unsigned function_like: 1;
|
||||
unsigned variadics: 1;
|
||||
};
|
||||
};
|
||||
|
||||
inline Macro():
|
||||
inline Macro():
|
||||
line(0),
|
||||
lines(0),
|
||||
next(0),
|
||||
hashcode(0),
|
||||
state(0)
|
||||
{ }
|
||||
};
|
||||
{ }
|
||||
};
|
||||
|
||||
} // namespace CPlusPlus
|
||||
|
||||
|
||||
Reference in New Issue
Block a user