summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/CppDocument.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2009-09-25 16:00:14 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2009-09-25 16:08:01 +0200
commit22ed0255b97ff52d808ebd93fabe06e214b56d2d (patch)
tree40dc79d131d6b13a8360ff8e68e7ab6119557d1f /src/libs/cplusplus/CppDocument.cpp
parent90470771fd58722a6a82b3da28bfaa645b250216 (diff)
downloadqt-creator-22ed0255b97ff52d808ebd93fabe06e214b56d2d.tar.gz
Track more macro uses.
In particular macros that are only checked for definition or are expanded during the evaluation of an #if or #elif directive are now also added to the list available through Document::macroUses(). The names of undefined macros that are interesting (because they're used in an #ifdef or a defined(...)) are now available through Document::undefinedMacroUses(). Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/libs/cplusplus/CppDocument.cpp')
-rw-r--r--src/libs/cplusplus/CppDocument.cpp63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp
index 9faabe29b1..675cf6edf9 100644
--- a/src/libs/cplusplus/CppDocument.cpp
+++ b/src/libs/cplusplus/CppDocument.cpp
@@ -44,6 +44,11 @@
#include <QtCore/QBitArray>
#include <QtCore/QtDebug>
+/*!
+ \namespace CPlusPlus
+ The namespace for C++ related tools.
+*/
+
using namespace CPlusPlus;
namespace {
@@ -101,6 +106,7 @@ private:
} // anonymous namespace
+
Document::Document(const QString &fileName)
: _fileName(fileName),
_globalNamespace(0),
@@ -166,9 +172,10 @@ void Document::appendMacro(const Macro &macro)
}
void Document::addMacroUse(const Macro &macro, unsigned offset, unsigned length,
- const QVector<MacroArgumentReference> &actuals)
+ const QVector<MacroArgumentReference> &actuals, bool inCondition)
{
MacroUse use(macro, offset, offset + length);
+ use.setInCondition(inCondition);
foreach (const MacroArgumentReference &actual, actuals) {
const Block arg(actual.position(), actual.position() + actual.length());
@@ -179,6 +186,60 @@ void Document::addMacroUse(const Macro &macro, unsigned offset, unsigned length,
_macroUses.append(use);
}
+void Document::addUndefinedMacroUse(const QByteArray &name, unsigned offset)
+{
+ QByteArray copy(name.data(), name.size());
+ UndefinedMacroUse use(copy, offset);
+ _undefinedMacroUses.append(use);
+}
+
+/*!
+ \class Document::MacroUse
+ \brief Represents the usage of a macro in a \l {Document}.
+ \sa Document::UndefinedMacroUse
+*/
+
+/*!
+ \class Document::UndefinedMacroUse
+ \brief Represents a macro that was looked up, but not found.
+
+ Holds data about the reference to a macro in an \tt{#ifdef} or \tt{#ifndef}
+ or argument to the \tt{defined} operator inside an \tt{#if} or \tt{#elif} that does
+ not exist.
+
+ \sa Document::undefinedMacroUses(), Document::MacroUse, Macro
+*/
+
+/*!
+ \fn QByteArray Document::UndefinedMacroUse::name() const
+
+ Returns the name of the macro that was not found.
+*/
+
+/*!
+ \fn QList<UndefinedMacroUse> Document::undefinedMacroUses() const
+
+ Returns a list of referenced but undefined macros.
+
+ \sa Document::macroUses(), Document::definedMacros(), Macro
+*/
+
+/*!
+ \fn QList<MacroUse> Document::macroUses() const
+
+ Returns a list of macros used.
+
+ \sa Document::undefinedMacroUses(), Document::definedMacros(), Macro
+*/
+
+/*!
+ \fn QList<Macro> Document::definedMacros() const
+
+ Returns the list of macros defined.
+
+ \sa Document::macroUses(), Document::undefinedMacroUses()
+*/
+
TranslationUnit *Document::translationUnit() const
{
return _translationUnit;