forked from qt-creator/qt-creator
Revert "C++: Fix highlighting for lines with predefined macros"
This takes too much memory. For qtcreator.pro the numbers are as
follows:
Patch applied: ~ 1600MB (RES)
Patch reverted: ~ 510MB (RES)
This reverts commit 4c2daa90ce
.
Task-number: QTCREATORBUG-10973
Change-Id: I843bd7c1ea4a26a1ec55ddc14c2a34a98d040922
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Robert Loehning <robert.loehning@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -137,12 +137,6 @@ public:
|
|||||||
void setVariadic(bool isVariadic)
|
void setVariadic(bool isVariadic)
|
||||||
{ f._variadic = isVariadic; }
|
{ f._variadic = isVariadic; }
|
||||||
|
|
||||||
bool isPredefined() const
|
|
||||||
{ return f._predefined; }
|
|
||||||
|
|
||||||
void setPredefined(bool isPredefined)
|
|
||||||
{ f._predefined = isPredefined; }
|
|
||||||
|
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
QString toStringWithLineBreaks() const;
|
QString toStringWithLineBreaks() const;
|
||||||
|
|
||||||
@@ -157,7 +151,6 @@ private:
|
|||||||
unsigned _hidden: 1;
|
unsigned _hidden: 1;
|
||||||
unsigned _functionLike: 1;
|
unsigned _functionLike: 1;
|
||||||
unsigned _variadic: 1;
|
unsigned _variadic: 1;
|
||||||
unsigned _predefined: 1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QByteArray _name;
|
QByteArray _name;
|
||||||
|
@@ -917,21 +917,23 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
|
|||||||
&& macroNameRef[0] == '_'
|
&& macroNameRef[0] == '_'
|
||||||
&& macroNameRef[1] == '_') {
|
&& macroNameRef[1] == '_') {
|
||||||
PPToken newTk;
|
PPToken newTk;
|
||||||
QByteArray txt;
|
|
||||||
if (macroNameRef == ppLine) {
|
if (macroNameRef == ppLine) {
|
||||||
txt = QByteArray::number(tk->lineno);
|
QByteArray txt = QByteArray::number(tk->lineno);
|
||||||
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
||||||
} else if (macroNameRef == ppFile) {
|
} else if (macroNameRef == ppFile) {
|
||||||
|
QByteArray txt;
|
||||||
txt.append('"');
|
txt.append('"');
|
||||||
txt.append(m_env->currentFileUtf8);
|
txt.append(m_env->currentFileUtf8);
|
||||||
txt.append('"');
|
txt.append('"');
|
||||||
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
||||||
} else if (macroNameRef == ppDate) {
|
} else if (macroNameRef == ppDate) {
|
||||||
|
QByteArray txt;
|
||||||
txt.append('"');
|
txt.append('"');
|
||||||
txt.append(QDate::currentDate().toString().toUtf8());
|
txt.append(QDate::currentDate().toString().toUtf8());
|
||||||
txt.append('"');
|
txt.append('"');
|
||||||
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
||||||
} else if (macroNameRef == ppTime) {
|
} else if (macroNameRef == ppTime) {
|
||||||
|
QByteArray txt;
|
||||||
txt.append('"');
|
txt.append('"');
|
||||||
txt.append(QTime::currentTime().toString().toUtf8());
|
txt.append(QTime::currentTime().toString().toUtf8());
|
||||||
txt.append('"');
|
txt.append('"');
|
||||||
@@ -939,14 +941,10 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newTk.hasSource()) {
|
if (newTk.hasSource()) {
|
||||||
Macro macro;
|
newTk.f.newline = tk->newline();
|
||||||
macro.setName(macroNameRef.toByteArray());
|
newTk.f.whitespace = tk->whitespace();
|
||||||
macro.setFileName(m_env->currentFile);
|
*tk = newTk;
|
||||||
macro.setPredefined(true);
|
return false;
|
||||||
macro.setDefinition(txt, QVector<PPToken>() << newTk);
|
|
||||||
m_env->bind(macro);
|
|
||||||
if (m_client)
|
|
||||||
m_client->macroAdded(macro);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -797,12 +797,10 @@ const Macro *CPPEditorWidget::findCanonicalMacro(const QTextCursor &cursor, Docu
|
|||||||
if (const Macro *macro = doc->findMacroDefinitionAt(line)) {
|
if (const Macro *macro = doc->findMacroDefinitionAt(line)) {
|
||||||
QTextCursor macroCursor = cursor;
|
QTextCursor macroCursor = cursor;
|
||||||
const QByteArray name = identifierUnderCursor(¯oCursor).toLatin1();
|
const QByteArray name = identifierUnderCursor(¯oCursor).toLatin1();
|
||||||
if (macro->name() == name && !macro->isPredefined())
|
if (macro->name() == name)
|
||||||
return macro;
|
return macro;
|
||||||
} else if (const Document::MacroUse *use = doc->findMacroUseAt(cursor.position())) {
|
} else if (const Document::MacroUse *use = doc->findMacroUseAt(cursor.position())) {
|
||||||
const Macro ¯o = use->macro();
|
return &use->macro();
|
||||||
if (!macro.isPredefined())
|
|
||||||
return ¯o;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -592,13 +592,11 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
|
|||||||
m_widget->showPreProcessorWidget();
|
m_widget->showPreProcessorWidget();
|
||||||
} else if (fileName != CppModelManagerInterface::configurationFileName()) {
|
} else if (fileName != CppModelManagerInterface::configurationFileName()) {
|
||||||
const Macro ¯o = use->macro();
|
const Macro ¯o = use->macro();
|
||||||
if (!macro.isPredefined()) {
|
|
||||||
link.targetFileName = macro.fileName();
|
link.targetFileName = macro.fileName();
|
||||||
link.targetLine = macro.line();
|
link.targetLine = macro.line();
|
||||||
link.linkTextStart = use->begin();
|
link.linkTextStart = use->begin();
|
||||||
link.linkTextEnd = use->end();
|
link.linkTextEnd = use->end();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -558,8 +558,6 @@ restart_search:
|
|||||||
usages.clear();
|
usages.clear();
|
||||||
foreach (const Document::MacroUse &use, doc->macroUses()) {
|
foreach (const Document::MacroUse &use, doc->macroUses()) {
|
||||||
const Macro &useMacro = use.macro();
|
const Macro &useMacro = use.macro();
|
||||||
if (useMacro.isPredefined())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (useMacro.fileName() == macro.fileName()) { // Check if this is a match, but possibly against an outdated document.
|
if (useMacro.fileName() == macro.fileName()) { // Check if this is a match, but possibly against an outdated document.
|
||||||
if (source.isEmpty())
|
if (source.isEmpty())
|
||||||
|
@@ -58,9 +58,6 @@ QFuture<TextEditor::HighlightingResult> CppHighlightingSupportInternal::highligh
|
|||||||
|
|
||||||
// Get macro definitions
|
// Get macro definitions
|
||||||
foreach (const CPlusPlus::Macro& macro, doc->definedMacros()) {
|
foreach (const CPlusPlus::Macro& macro, doc->definedMacros()) {
|
||||||
if (macro.isPredefined())
|
|
||||||
continue; // No "real" definition location
|
|
||||||
|
|
||||||
int line, column;
|
int line, column;
|
||||||
editor()->convertPosition(macro.offset(), &line, &column);
|
editor()->convertPosition(macro.offset(), &line, &column);
|
||||||
++column; //Highlighting starts at (column-1) --> compensate here
|
++column; //Highlighting starts at (column-1) --> compensate here
|
||||||
|
@@ -175,8 +175,6 @@ private slots:
|
|||||||
void test_checksymbols_VirtualMethodUse();
|
void test_checksymbols_VirtualMethodUse();
|
||||||
void test_checksymbols_LabelUse();
|
void test_checksymbols_LabelUse();
|
||||||
void test_checksymbols_MacroUse();
|
void test_checksymbols_MacroUse();
|
||||||
void test_checksymbols_Macros__FILE__LINE__DATE__TIME__1();
|
|
||||||
void test_checksymbols_Macros__FILE__LINE__DATE__TIME__2();
|
|
||||||
void test_checksymbols_FunctionUse();
|
void test_checksymbols_FunctionUse();
|
||||||
void test_checksymbols_PseudoKeywordUse();
|
void test_checksymbols_PseudoKeywordUse();
|
||||||
void test_checksymbols_StaticUse();
|
void test_checksymbols_StaticUse();
|
||||||
@@ -328,55 +326,6 @@ void tst_CheckSymbols::test_checksymbols_MacroUse()
|
|||||||
TestData::check(source, expectedUses, macroUses);
|
TestData::check(source, expectedUses, macroUses);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_CheckSymbols::test_checksymbols_Macros__FILE__LINE__DATE__TIME__1()
|
|
||||||
{
|
|
||||||
const QByteArray source =
|
|
||||||
"#define FILE_DATE_TIME __FILE__ \" / \" __DATE__ \" / \" __TIME__\n"
|
|
||||||
"#define LINE_NUMBER 0 + __LINE__\n"
|
|
||||||
"\n"
|
|
||||||
"void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" class Printer;\n"
|
|
||||||
" Printer::printText(FILE_DATE_TIME); Printer::printInteger(LINE_NUMBER); Printer::nl();\n"
|
|
||||||
" return;\n"
|
|
||||||
"}\n";
|
|
||||||
const QList<Use> expectedUses = QList<Use>()
|
|
||||||
<< Use(4, 6, 1, CppHighlightingSupport::FunctionUse)
|
|
||||||
<< Use(6, 11, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(6, 11, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(7, 5, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(7, 41, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(7, 77, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
;
|
|
||||||
|
|
||||||
TestData::check(source, expectedUses);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_CheckSymbols::test_checksymbols_Macros__FILE__LINE__DATE__TIME__2()
|
|
||||||
{
|
|
||||||
const QByteArray source =
|
|
||||||
"void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" class Printer;\n"
|
|
||||||
" Printer::printInteger(__LINE__); Printer::printText(__FILE__); Printer::nl();\n"
|
|
||||||
" Printer::printText(__DATE__); Printer::printText(__TIME__); Printer::nl();\n"
|
|
||||||
" return;\n"
|
|
||||||
"}\n";
|
|
||||||
const QList<Use> expectedUses = QList<Use>()
|
|
||||||
<< Use(1, 6, 1, CppHighlightingSupport::FunctionUse)
|
|
||||||
<< Use(3, 11, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(3, 11, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(4, 5, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(4, 38, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(4, 68, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(5, 5, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(5, 35, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
<< Use(5, 65, 7, CppHighlightingSupport::TypeUse)
|
|
||||||
;
|
|
||||||
|
|
||||||
TestData::check(source, expectedUses);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_CheckSymbols::test_checksymbols_FunctionUse()
|
void tst_CheckSymbols::test_checksymbols_FunctionUse()
|
||||||
{
|
{
|
||||||
const QByteArray source =
|
const QByteArray source =
|
||||||
|
@@ -796,11 +796,7 @@ void tst_Preprocessor::builtin__FILE__()
|
|||||||
));
|
));
|
||||||
const QByteArray result____ =
|
const QByteArray result____ =
|
||||||
"# 1 \"some-file.c\"\n"
|
"# 1 \"some-file.c\"\n"
|
||||||
"const char *f =\n"
|
"const char *f = \"some-file.c\"\n";
|
||||||
"# expansion begin 16,8 ~1\n"
|
|
||||||
"\"some-file.c\"\n"
|
|
||||||
"# expansion end\n"
|
|
||||||
"# 2 \"some-file.c\"\n";
|
|
||||||
|
|
||||||
QCOMPARE(preprocessed, result____);
|
QCOMPARE(preprocessed, result____);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user