Commit 77aa3064 authored by Roberto Raggi's avatar Roberto Raggi

Removed the MacroResolver

Unfortunately, the MacroResolver does not scale and we get pretty bad performances when parsing big projects.
parent 07f05c8e
...@@ -34,55 +34,6 @@ ...@@ -34,55 +34,6 @@
using namespace CPlusPlus; using namespace CPlusPlus;
FastMacroResolver::FastMacroResolver(TranslationUnit *unit, const Snapshot &snapshot)
: _unit(unit), _snapshot(snapshot)
{
const QString fileName = QString::fromUtf8(unit->fileName(), unit->fileNameLength());
QSet<QString> processed;
updateCache(fileName, &processed);
}
bool FastMacroResolver::isMacro(TranslationUnit *unit, unsigned tokenIndex) const
{
if (unit != _unit){
qWarning() << Q_FUNC_INFO << "unexpected translation unit:" << unit->fileName();
return false;
}
const Token &tk = unit->tokenAt(tokenIndex);
if (tk.isNot(T_IDENTIFIER))
return false;
Identifier *id = tk.identifier;
const QByteArray macroName = QByteArray::fromRawData(id->chars(), id->size());
return _cachedMacros.contains(macroName);
}
void FastMacroResolver::updateCache(const QString &fileName, QSet<QString> *processed)
{
if (processed->contains(fileName))
return;
processed->insert(fileName);
if (Document::Ptr doc = _snapshot.value(fileName)) {
const QList<Macro> definedMacros = doc->definedMacros();
for (int i = definedMacros.size() - 1; i != -1; --i) {
const Macro &macro = definedMacros.at(i);
if (macro.isHidden())
_cachedMacros.remove(macro.name());
else
_cachedMacros.insert(macro.name());
}
foreach (const Document::Include &incl, doc->includes())
updateCache(incl.fileName(), processed);
}
}
FastPreprocessor::FastPreprocessor(const Snapshot &snapshot) FastPreprocessor::FastPreprocessor(const Snapshot &snapshot)
: _snapshot(snapshot), : _snapshot(snapshot),
_preproc(this, &_env) _preproc(this, &_env)
......
...@@ -41,22 +41,6 @@ ...@@ -41,22 +41,6 @@
namespace CPlusPlus { namespace CPlusPlus {
class CPLUSPLUS_EXPORT FastMacroResolver: public MacroResolver
{
public:
FastMacroResolver(TranslationUnit *unit, const Snapshot &snapshot);
virtual bool isMacro(TranslationUnit *unit, unsigned tokenIndex) const;
private:
void updateCache(const QString &fileName, QSet<QString> *processed);
private:
TranslationUnit *_unit;
Snapshot _snapshot;
QSet<QByteArray> _cachedMacros;
};
class CPLUSPLUS_EXPORT FastPreprocessor: public Client class CPLUSPLUS_EXPORT FastPreprocessor: public Client
{ {
Environment _env; Environment _env;
......
...@@ -2090,11 +2090,7 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source) ...@@ -2090,11 +2090,7 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
snapshot = source.snapshot; snapshot = source.snapshot;
doc = source.snapshot.documentFromSource(preprocessedCode, source.fileName); doc = source.snapshot.documentFromSource(preprocessedCode, source.fileName);
FastMacroResolver fastMacroResolver(doc->translationUnit(), snapshot);
doc->control()->setMacroResolver(&fastMacroResolver);
doc->check(); doc->check();
doc->control()->setMacroResolver(0);
} }
Control *control = doc->control(); Control *control = doc->control();
......
...@@ -531,13 +531,7 @@ static void find_helper(QFutureInterface<Utils::FileSearchResult> &future, ...@@ -531,13 +531,7 @@ static void find_helper(QFutureInterface<Utils::FileSearchResult> &future,
if (Identifier *id = control->findIdentifier(symbolId->chars(), symbolId->size())) { if (Identifier *id = control->findIdentifier(symbolId->chars(), symbolId->size())) {
QTime tm; QTime tm;
tm.start(); tm.start();
TranslationUnit *unit = doc->translationUnit();
Control *control = doc->control();
FastMacroResolver fastMacroResolver(unit, snapshot);
control->setMacroResolver(&fastMacroResolver);
doc->parse(); doc->parse();
control->setMacroResolver(0);
//qDebug() << "***" << unit->fileName() << "parsed in:" << tm.elapsed(); //qDebug() << "***" << unit->fileName() << "parsed in:" << tm.elapsed();
...@@ -548,6 +542,8 @@ static void find_helper(QFutureInterface<Utils::FileSearchResult> &future, ...@@ -548,6 +542,8 @@ static void find_helper(QFutureInterface<Utils::FileSearchResult> &future,
tm.start(); tm.start();
Process process(doc, snapshot, &future); Process process(doc, snapshot, &future);
TranslationUnit *unit = doc->translationUnit();
process(symbol, id, unit->ast()); process(symbol, id, unit->ast());
//qDebug() << "***" << unit->fileName() << "processed in:" << tm.elapsed(); //qDebug() << "***" << unit->fileName() << "processed in:" << tm.elapsed();
......
...@@ -83,7 +83,6 @@ class Semantic; ...@@ -83,7 +83,6 @@ class Semantic;
class Control; class Control;
class MemoryPool; class MemoryPool;
class DiagnosticClient; class DiagnosticClient;
class MacroResolver;
class Identifier; class Identifier;
class Literal; class Literal;
......
...@@ -59,11 +59,6 @@ ...@@ -59,11 +59,6 @@
CPLUSPLUS_BEGIN_NAMESPACE CPLUSPLUS_BEGIN_NAMESPACE
MacroResolver::MacroResolver()
{ }
MacroResolver::~MacroResolver()
{ }
template <typename _Iterator> template <typename _Iterator>
static void delete_map_entries(_Iterator first, _Iterator last) static void delete_map_entries(_Iterator first, _Iterator last)
...@@ -93,8 +88,7 @@ public: ...@@ -93,8 +88,7 @@ public:
Data(Control *control) Data(Control *control)
: control(control), : control(control),
translationUnit(0), translationUnit(0),
diagnosticClient(0), diagnosticClient(0)
macroResolver(0)
{ } { }
~Data() ~Data()
...@@ -539,7 +533,6 @@ public: ...@@ -539,7 +533,6 @@ public:
Control *control; Control *control;
TranslationUnit *translationUnit; TranslationUnit *translationUnit;
DiagnosticClient *diagnosticClient; DiagnosticClient *diagnosticClient;
MacroResolver *macroResolver;
LiteralTable<Identifier> identifiers; LiteralTable<Identifier> identifiers;
LiteralTable<StringLiteral> stringLiterals; LiteralTable<StringLiteral> stringLiterals;
LiteralTable<NumericLiteral> numericLiterals; LiteralTable<NumericLiteral> numericLiterals;
...@@ -602,12 +595,6 @@ TranslationUnit *Control::switchTranslationUnit(TranslationUnit *unit) ...@@ -602,12 +595,6 @@ TranslationUnit *Control::switchTranslationUnit(TranslationUnit *unit)
return previousTranslationUnit; return previousTranslationUnit;
} }
MacroResolver *Control::macroResolver() const
{ return d->macroResolver; }
void Control::setMacroResolver(MacroResolver *macroResolver)
{ d->macroResolver = macroResolver; }
DiagnosticClient *Control::diagnosticClient() const DiagnosticClient *Control::diagnosticClient() const
{ return d->diagnosticClient; } { return d->diagnosticClient; }
......
...@@ -55,18 +55,6 @@ ...@@ -55,18 +55,6 @@
CPLUSPLUS_BEGIN_HEADER CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT MacroResolver
{
MacroResolver(const MacroResolver &other);
void operator = (const MacroResolver &other);
public:
MacroResolver();
virtual ~MacroResolver();
virtual bool isMacro(TranslationUnit *unit, unsigned tokenIndex) const = 0;
};
class CPLUSPLUS_EXPORT Control class CPLUSPLUS_EXPORT Control
{ {
public: public:
...@@ -76,9 +64,6 @@ public: ...@@ -76,9 +64,6 @@ public:
TranslationUnit *translationUnit() const; TranslationUnit *translationUnit() const;
TranslationUnit *switchTranslationUnit(TranslationUnit *unit); TranslationUnit *switchTranslationUnit(TranslationUnit *unit);
MacroResolver *macroResolver() const;
void setMacroResolver(MacroResolver *macroResolver);
DiagnosticClient *diagnosticClient() const; DiagnosticClient *diagnosticClient() const;
void setDiagnosticClient(DiagnosticClient *diagnosticClient); void setDiagnosticClient(DiagnosticClient *diagnosticClient);
......
...@@ -244,14 +244,6 @@ void Parser::match(int kind, unsigned *token) ...@@ -244,14 +244,6 @@ void Parser::match(int kind, unsigned *token)
} }
} }
bool Parser::isMacro(unsigned tokenIndex) const
{
if (MacroResolver *r = _control->macroResolver())
return r->isMacro(_translationUnit, tokenIndex);
return false;
}
bool Parser::parseClassOrNamespaceName(NameAST *&node) bool Parser::parseClassOrNamespaceName(NameAST *&node)
{ {
if (LA() == T_IDENTIFIER) { if (LA() == T_IDENTIFIER) {
...@@ -2561,10 +2553,6 @@ bool Parser::parseBuiltinTypeSpecifier(SpecifierAST *&node) ...@@ -2561,10 +2553,6 @@ bool Parser::parseBuiltinTypeSpecifier(SpecifierAST *&node)
bool Parser::parseSimpleDeclaration(DeclarationAST *&node, bool Parser::parseSimpleDeclaration(DeclarationAST *&node,
bool acceptStructDeclarator) bool acceptStructDeclarator)
{ {
if (LA() == T_IDENTIFIER && isMacro(cursor())) {
// printf("***** found macro reference `%s'\n", tok().identifier->chars());
}
unsigned qt_invokable_token = 0; unsigned qt_invokable_token = 0;
if (acceptStructDeclarator && (LA() == T_Q_SIGNAL || LA() == T_Q_SLOT)) if (acceptStructDeclarator && (LA() == T_Q_SIGNAL || LA() == T_Q_SLOT))
qt_invokable_token = consumeToken(); qt_invokable_token = consumeToken();
......
...@@ -286,8 +286,6 @@ private: ...@@ -286,8 +286,6 @@ private:
inline void rewind(unsigned cursor) inline void rewind(unsigned cursor)
{ _tokenIndex = cursor; } { _tokenIndex = cursor; }
bool isMacro(unsigned tokenIndex) const;
private: private:
TranslationUnit *_translationUnit; TranslationUnit *_translationUnit;
Control *_control; Control *_control;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment