Supporting MSVC2010 in ktexteditor framework
Nicolás Alvarez
nicolas.alvarez at gmail.com
Wed Nov 5 03:33:58 UTC 2014
Hi all,
According to https://community.kde.org/Frameworks/C++11, KDE
Frameworks support MSVC2010 and later versions. Since ktexteditor is
part of KF5, it is supposed to work on MSVC2010. It currently doesn't;
several unsupported C++11 features were introduced to the library in
the past few months.
We really really need a Windows CI so that this is noticed early :(
The unsupported C++ features include:
- brace initialization: Cursor x = {0,0}; or return {};
- delegating constructors
- range-based for loops
- initializing class members inside the class declaration instead of
doing it in the constructor: class Foo { int x=42; }; (N2756)
- not specifying the return type of lambdas: auto f = []() { return 42; }
I attached the patch that makes ktexteditor build with MSVC2010,
except for a unit test where there's WAY too many brace-init. In my
opinion, the code looks cleaner with these C++11 features, ie. before
the patch.
So, I hereby propose making an exception and bumping the minimum
compiler version *for ktexteditor only* to MSVC2012. Opinions?
--
Nicolás
-------------- next part --------------
diff --git a/autotests/src/script_test_base.cpp b/autotests/src/script_test_base.cpp
index 2799211..58d77d7 100644
--- a/autotests/src/script_test_base.cpp
+++ b/autotests/src/script_test_base.cpp
@@ -161,7 +161,7 @@ void ScriptTestBase::runTest(const ExpectedFailures &failures)
QTextStream(stdout) << out << endl;
}
- for (const Failure &failure : failures) {
+ Q_FOREACH (const Failure &failure, failures) {
QEXPECT_FAIL(failure.first, failure.second, Abort);
}
diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp
index 9a809fa..074c3f5 100644
--- a/src/document/katedocument.cpp
+++ b/src/document/katedocument.cpp
@@ -147,6 +147,7 @@ KTextEditor::DocumentPrivate::DocumentPrivate(bool bSingleViewMode,
editSessionNumber(0),
editIsRunning(false),
m_undoMergeAllEdits(false),
+ m_editingStackPosition(-1),
m_undoManager(new KateUndoManager(this)),
m_editableMarks(markType01),
m_annotationModel(0),
diff --git a/src/document/katedocument.h b/src/document/katedocument.h
index 8e93f7a..8920f17 100644
--- a/src/document/katedocument.h
+++ b/src/document/katedocument.h
@@ -362,7 +362,7 @@ private:
bool editIsRunning;
bool m_undoMergeAllEdits;
QStack<QSharedPointer<KTextEditor::MovingCursor>> m_editingStack;
- int m_editingStackPosition = -1;
+ int m_editingStackPosition;
static const int s_editingStackSizeLimit = 32;
//
diff --git a/src/script/katescript.h b/src/script/katescript.h
index fcc99d1..80c7924 100644
--- a/src/script/katescript.h
+++ b/src/script/katescript.h
@@ -175,7 +175,7 @@ public:
QString backtrace(const QScriptValue &error, const QString &header = QString());
/** Execute a piece of code **/
- QScriptValue evaluate(const QString& program, const FieldMap& env={});
+ QScriptValue evaluate(const QString& program, const FieldMap& env=FieldMap());
/** Displays the backtrace when a script has errored out */
void displayBacktrace(const QScriptValue &error, const QString &header = QString());
diff --git a/src/syntax/katehighlight.cpp b/src/syntax/katehighlight.cpp
index 9d885b7..2e66a2f 100644
--- a/src/syntax/katehighlight.cpp
+++ b/src/syntax/katehighlight.cpp
@@ -1176,8 +1176,8 @@ bool KateHighlighting::isInWord(QChar c, int attrib) const
bool KateHighlighting::canBreakAt(QChar c, int attrib) const
{
- static const QString &sq = QStringLiteral("\"'");
- return (m_additionalData[ hlKeyForAttrib(attrib) ]->wordWrapDeliminator.indexOf(c) != -1) && (sq.indexOf(c) == -1);
+ return (m_additionalData[ hlKeyForAttrib(attrib) ]->wordWrapDeliminator.indexOf(c) != -1) &&
+ (QStringLiteral("\"'").indexOf(c) == -1);
}
QLinkedList<QRegularExpression> KateHighlighting::emptyLines(int attrib) const
diff --git a/src/utils/katetemplatehandler.cpp b/src/utils/katetemplatehandler.cpp
index abb3bd6..08f7483 100644
--- a/src/utils/katetemplatehandler.cpp
+++ b/src/utils/katetemplatehandler.cpp
@@ -122,12 +122,12 @@ KateTemplateHandler::~KateTemplateHandler()
void KateTemplateHandler::sortFields()
{
- std::sort(m_fields.begin(), m_fields.end(), [](const TemplateField& l, const TemplateField& r) {
+ std::sort(m_fields.begin(), m_fields.end(), [](const TemplateField& l, const TemplateField& r) -> bool {
// always sort the final cursor pos last
- if ( l.kind == TemplateField::FinalCursorPosition ) {
+ if ( l.kind == KateTemplateHandler::TemplateField::FinalCursorPosition ) {
return false;
}
- if ( r.kind == TemplateField::FinalCursorPosition ) {
+ if ( r.kind == KateTemplateHandler::TemplateField::FinalCursorPosition ) {
return true;
}
// sort by range
@@ -166,11 +166,11 @@ void KateTemplateHandler::jump(int by, bool initial)
pos = wrap(pos);
// choose field to jump to, including wrap-around
- auto choose_next_field = [this, by, wrap](unsigned int from_field_index) {
+ auto choose_next_field = [this, by, wrap](unsigned int from_field_index) -> unsigned int {
for ( int i = from_field_index + by; ; i += by ) {
auto wrapped_i = wrap(i);
auto kind = m_fields.at(wrapped_i).kind;
- if ( kind == TemplateField::Editable || kind == TemplateField::FinalCursorPosition ) {
+ if ( kind == KateTemplateHandler::TemplateField::Editable || kind == KateTemplateHandler::TemplateField::FinalCursorPosition ) {
// found an editable field by walking into the desired direction
return wrapped_i;
}
@@ -288,7 +288,7 @@ void KateTemplateHandler::parseFields(const QString& templateText)
QRegularExpression defaultField(QStringLiteral("\\w+=([^\\}]*)"));
// compute start cursor of a match
- auto startOfMatch = [this, &templateText](const QRegularExpressionMatch& match) {
+ auto startOfMatch = [this, &templateText](const QRegularExpressionMatch& match) -> Cursor {
const auto offset = match.capturedStart(0);
const auto left = templateText.left(offset);
const auto nl = QLatin1Char('\n');
@@ -299,9 +299,9 @@ void KateTemplateHandler::parseFields(const QString& templateText)
};
// create a moving range spanning the given field
- auto createMovingRangeForMatch = [this, startOfMatch](const QRegularExpressionMatch& match) {
+ auto createMovingRangeForMatch = [this, startOfMatch](const QRegularExpressionMatch& match) -> MovingRange* {
auto matchStart = startOfMatch(match);
- return doc()->newMovingRange({matchStart, matchStart + Cursor(0, match.capturedLength(0))},
+ return doc()->newMovingRange(Range(matchStart, matchStart + Cursor(0, match.capturedLength(0))),
MovingRange::ExpandLeft | MovingRange::ExpandRight);
};
@@ -417,7 +417,7 @@ const KateTemplateHandler::TemplateField KateTemplateHandler::fieldForRange(cons
return field;
}
}
- return {};
+ return TemplateField();
}
void KateTemplateHandler::updateDependentFields(Document *document, const Range &range)
@@ -520,7 +520,7 @@ void KateTemplateHandler::updateDependentFields(Document *document, const Range
void KateTemplateHandler::updateRangeBehaviours()
{
- KTextEditor::Cursor last = {-1, -1};
+ KTextEditor::Cursor last(-1, -1);
for ( int i = 0; i < m_fields.size(); i++ ) {
auto field = m_fields.at(i);
auto end = field.range->end().toCursor();
diff --git a/src/utils/katetemplatehandler.h b/src/utils/katetemplatehandler.h
index c3e49d8..a6a6c07 100644
--- a/src/utils/katetemplatehandler.h
+++ b/src/utils/katetemplatehandler.h
@@ -219,9 +219,11 @@ private:
FunctionCall, // field containing the up-to-date result of a function call [dependent field]
FinalCursorPosition // field marking the final cursor position
};
- Kind kind = Invalid;
+ Kind kind;
// true if this field was edited by the user before
- bool touched = false;
+ bool touched;
+
+ TemplateField(): kind(Invalid), touched(false) {}
bool operator==(const TemplateField& other) {
return range == other.range;
}
diff --git a/src/vimode/marks.cpp b/src/vimode/marks.cpp
index b73eedb..4ee617f 100644
--- a/src/vimode/marks.cpp
+++ b/src/vimode/marks.cpp
@@ -167,7 +167,7 @@ void Marks::syncViMarksAndBookmarks()
const QHash<int, KTextEditor::Mark *> &marks = m_doc->marks();
// Each bookmark should have a vi mark on the same line.
- for (auto mark : marks) {
+ Q_FOREACH (const KTextEditor::Mark* mark, marks) {
if (!(mark->type & KTextEditor::MarkInterface::markType01)) {
continue;
}
@@ -199,7 +199,7 @@ void Marks::syncViMarksAndBookmarks()
}
bool thereIsKateMarkForThisLine = false;
- for (auto mark : marks) {
+ Q_FOREACH (const KTextEditor::Mark* mark, marks) {
if (!(mark->type & KTextEditor::MarkInterface::markType01)) {
continue;
}
diff --git a/src/vimode/range.cpp b/src/vimode/range.cpp
index e2814b3..52938b4 100644
--- a/src/vimode/range.cpp
+++ b/src/vimode/range.cpp
@@ -25,7 +25,8 @@
using namespace KateVi;
Range::Range()
- : Range(-1, -1, -1, -1, InclusiveMotion)
+ : startLine(-1), startColumn(-1), endLine(-1), endColumn(-1)
+ , motionType(InclusiveMotion), valid(true), jump(false)
{
}
@@ -36,17 +37,21 @@ Range::Range(int slin, int scol, int elin, int ecol, MotionType inc)
}
Range::Range(int elin, int ecol, MotionType inc)
- : Range(-1, -1, elin, ecol, inc)
+ : startLine(-1), startColumn(-1), endLine(elin), endColumn(ecol)
+ , motionType(inc), valid(true), jump(false)
{
}
Range::Range(const KTextEditor::Cursor& c, MotionType mt)
- : Range(-1, -1, c.line(), c.column(), mt)
+ : startLine(-1), startColumn(-1), endLine(c.line()), endColumn(c.column())
+ , motionType(mt), valid(true), jump(false)
{
}
Range::Range(const KTextEditor::Cursor& c1, const KTextEditor::Cursor c2, MotionType mt)
- : Range(c1.line(), c1.column(), c2.line(), c2.column(), mt)
+ : startLine(c1.line()), startColumn(c1.column()), endLine(c2.line()), endColumn(c2.column())
+ , motionType(mt), valid(true), jump(false)
+
{
}
More information about the Kde-frameworks-devel
mailing list