forked from qt-creator/qt-creator
CppEditor: Generate doxygen comments for functions with macros
...at least for object-like macros. This handles the common case where a macro before the function signature annotates the DLL import/export. Task-number: QTCREATORBUG-15819 Change-Id: I79f22508188019402fb7345222408aaf90106f20 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
@@ -757,8 +757,23 @@ void Snapshot::insert(Document::Ptr doc)
|
||||
}
|
||||
}
|
||||
|
||||
static QList<Macro> macrosDefinedUntilLine(const QList<Macro> ¯os, int line)
|
||||
{
|
||||
QList<Macro> filtered;
|
||||
|
||||
foreach (const Macro ¯o, macros) {
|
||||
if (macro.line() <= unsigned(line))
|
||||
filtered.append(macro);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
Document::Ptr Snapshot::preprocessedDocument(const QByteArray &source,
|
||||
const Utils::FileName &fileName) const
|
||||
const Utils::FileName &fileName,
|
||||
int withDefinedMacrosFromDocumentUntilLine) const
|
||||
{
|
||||
Document::Ptr newDoc = Document::create(fileName.toString());
|
||||
if (Document::Ptr thisDocument = document(fileName)) {
|
||||
@@ -768,10 +783,15 @@ Document::Ptr Snapshot::preprocessedDocument(const QByteArray &source,
|
||||
newDoc->_resolvedIncludes = thisDocument->_resolvedIncludes;
|
||||
newDoc->_unresolvedIncludes = thisDocument->_unresolvedIncludes;
|
||||
newDoc->setLanguageFeatures(thisDocument->languageFeatures());
|
||||
if (withDefinedMacrosFromDocumentUntilLine != -1) {
|
||||
newDoc->_definedMacros = macrosDefinedUntilLine(thisDocument->_definedMacros,
|
||||
withDefinedMacrosFromDocumentUntilLine);
|
||||
}
|
||||
}
|
||||
|
||||
FastPreprocessor pp(*this);
|
||||
const QByteArray preprocessedCode = pp.run(newDoc, source);
|
||||
const bool mergeDefinedMacrosOfDocument = !newDoc->_definedMacros.isEmpty();
|
||||
const QByteArray preprocessedCode = pp.run(newDoc, source, mergeDefinedMacrosOfDocument);
|
||||
newDoc->setUtf8Source(preprocessedCode);
|
||||
return newDoc;
|
||||
}
|
||||
|
||||
@@ -425,10 +425,16 @@ public:
|
||||
Snapshot simplified(Document::Ptr doc) const;
|
||||
|
||||
Document::Ptr preprocessedDocument(const QByteArray &source,
|
||||
const Utils::FileName &fileName) const;
|
||||
const Utils::FileName &fileName,
|
||||
int withDefinedMacrosFromDocumentUntilLine = -1) const;
|
||||
Document::Ptr preprocessedDocument(const QByteArray &source,
|
||||
const QString &fileName) const
|
||||
{ return preprocessedDocument(source, Utils::FileName::fromString(fileName)); }
|
||||
const QString &fileName,
|
||||
int withDefinedMacrosFromDocumentUntilLine = -1) const
|
||||
{
|
||||
return preprocessedDocument(source,
|
||||
Utils::FileName::fromString(fileName),
|
||||
withDefinedMacrosFromDocumentUntilLine);
|
||||
}
|
||||
|
||||
Document::Ptr documentFromSource(const QByteArray &preprocessedDocument,
|
||||
const QString &fileName) const;
|
||||
|
||||
@@ -38,7 +38,9 @@ FastPreprocessor::FastPreprocessor(const Snapshot &snapshot)
|
||||
, _addIncludesToCurrentDoc(false)
|
||||
{ }
|
||||
|
||||
QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QByteArray &source)
|
||||
QByteArray FastPreprocessor::run(Document::Ptr newDoc,
|
||||
const QByteArray &source,
|
||||
bool mergeDefinedMacrosOfDocument)
|
||||
{
|
||||
std::swap(newDoc, _currentDoc);
|
||||
_addIncludesToCurrentDoc = _currentDoc->resolvedIncludes().isEmpty()
|
||||
@@ -57,6 +59,9 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QByteArray &source)
|
||||
|
||||
foreach (const Document::Include &i, doc->resolvedIncludes())
|
||||
mergeEnvironment(i.resolvedFileName());
|
||||
|
||||
if (mergeDefinedMacrosOfDocument)
|
||||
_env.addMacros(_currentDoc->definedMacros());
|
||||
}
|
||||
|
||||
const QByteArray preprocessed = _preproc.run(fileName, source);
|
||||
|
||||
@@ -51,7 +51,9 @@ class CPLUSPLUS_EXPORT FastPreprocessor: public Client
|
||||
public:
|
||||
FastPreprocessor(const Snapshot &snapshot);
|
||||
|
||||
QByteArray run(Document::Ptr newDoc, const QByteArray &source);
|
||||
QByteArray run(Document::Ptr newDoc,
|
||||
const QByteArray &source,
|
||||
bool mergeDefinedMacrosOfDocument = false);
|
||||
|
||||
// CPlusPlus::Client
|
||||
virtual void sourceNeeded(unsigned line, const QString &fileName, IncludeType mode,
|
||||
|
||||
Reference in New Issue
Block a user