diff options
author | Neil <nyamatongwe@gmail.com> | 2025-04-03 14:52:19 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-04-03 14:52:19 +1100 |
commit | b4300bf40c1134231af48cab4f38c5394976d9a1 (patch) | |
tree | 9ee9c88ab3b5f19a1933ecc5dfd02d5d2c5e9d0b /src | |
parent | edb7369a2c6a19393dc413a9595a234969fc2731 (diff) | |
download | scintilla-mirror-b4300bf40c1134231af48cab4f38c5394976d9a1.tar.gz |
Turn on type conversion warnings for GCC and fix them.
Diffstat (limited to 'src')
-rw-r--r-- | src/DBCS.h | 6 | ||||
-rw-r--r-- | src/Document.cxx | 2 | ||||
-rw-r--r-- | src/EditView.cxx | 24 | ||||
-rw-r--r-- | src/Editor.cxx | 16 | ||||
-rw-r--r-- | src/LineMarker.cxx | 2 | ||||
-rw-r--r-- | src/MarginView.cxx | 2 | ||||
-rw-r--r-- | src/PositionCache.cxx | 2 | ||||
-rw-r--r-- | src/Selection.cxx | 4 | ||||
-rw-r--r-- | src/Selection.h | 1 |
9 files changed, 32 insertions, 27 deletions
diff --git a/src/DBCS.h b/src/DBCS.h index 12bbaf986..ba6230649 100644 --- a/src/DBCS.h +++ b/src/DBCS.h @@ -31,11 +31,9 @@ bool IsDBCSValidSingleByte(int codePage, int ch) noexcept; // Calculate a number from a DBCS byte pair that can be used to index into an array or map. // Should only be called with genuine DBCS character pairs which means that ch1 has top bit set. constexpr uint16_t DBCSIndex(char ch1, char ch2) noexcept { - constexpr unsigned int highStart = 0x80U; - constexpr unsigned int byteMultiply = 0x100U; - const unsigned char uch1 = ch1; + const unsigned char uch1 = ch1 & 0x7F; const unsigned char uch2 = ch2; - return ((uch1 - highStart) * byteMultiply) + uch2; + return (uch1 << 8) | uch2; } struct DBCSPair { diff --git a/src/Document.cxx b/src/Document.cxx index ddcf43276..8f6806824 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -120,7 +120,7 @@ void ActionDuration::AddSample(size_t numberActions, double durationOfActions) n // Most recent value contributes 25% to smoothed value. constexpr double alpha = 0.25; - const double durationOne = durationOfActions / numberActions; + const double durationOne = durationOfActions / static_cast<double>(numberActions); duration = std::clamp(alpha * durationOne + (1.0 - alpha) * duration, minDuration, maxDuration); } diff --git a/src/EditView.cxx b/src/EditView.cxx index 8215f7b68..e8c8562ec 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -670,8 +670,8 @@ Point EditView::LocationFromPosition(Surface *surface, const EditModel &model, S pt.y = static_cast<XYPOSITION>(subLine*vs.lineHeight); } } - pt.y += (lineVisible - topLine) * vs.lineHeight; - pt.x += pos.VirtualSpace() * vs.styles[ll->EndLineStyle()].spaceWidth; + pt.y += static_cast<XYPOSITION>((lineVisible - topLine) * vs.lineHeight); + pt.x += pos.VirtualSpaceWidth(vs.styles[ll->EndLineStyle()].spaceWidth); } return pt; } @@ -958,7 +958,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle XYPOSITION virtualSpace = 0; if (lastSubLine) { const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - virtualSpace = model.sel.VirtualSpaceFor(model.pdoc->LineEnd(line)) * spaceWidth; + virtualSpace = static_cast<XYPOSITION>(model.sel.VirtualSpaceFor(model.pdoc->LineEnd(line))) * spaceWidth; } const XYPOSITION xEol = ll->positions[lineEnd] - subLineStart; @@ -977,9 +977,9 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle if (!portion.Empty()) { const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; rcSegment.left = xStart + ll->positions[portion.start.Position() - posLineStart] - - subLineStart+portion.start.VirtualSpace() * spaceWidth; + subLineStart + portion.start.VirtualSpaceWidth(spaceWidth); rcSegment.right = xStart + ll->positions[portion.end.Position() - posLineStart] - - subLineStart+portion.end.VirtualSpace() * spaceWidth; + subLineStart + portion.end.VirtualSpaceWidth(spaceWidth); rcSegment.left = (rcSegment.left > rcLine.left) ? rcSegment.left : rcLine.left; rcSegment.right = (rcSegment.right < rcLine.right) ? rcSegment.right : rcLine.right; surface->FillRectangleAligned(rcSegment, Fill( @@ -1149,8 +1149,8 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con } const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - const XYPOSITION virtualSpace = model.sel.VirtualSpaceFor( - model.pdoc->LineEnd(line)) * spaceWidth; + const XYPOSITION virtualSpace = static_cast<XYPOSITION>(model.sel.VirtualSpaceFor( + model.pdoc->LineEnd(line))) * spaceWidth; rcSegment.left = xStart + ll->positions[ll->numCharsInLine] - subLineStart + virtualSpace + vsDraw.aveCharWidth; rcSegment.right = rcSegment.left + static_cast<XYPOSITION>(widthFoldDisplayText); @@ -1267,8 +1267,8 @@ void EditView::DrawEOLAnnotationText(Surface *surface, const EditModel &model, c leftBoxSpace + rightBoxSpace); const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - const XYPOSITION virtualSpace = model.sel.VirtualSpaceFor( - model.pdoc->LineEnd(line)) * spaceWidth; + const XYPOSITION virtualSpace = static_cast<XYPOSITION>(model.sel.VirtualSpaceFor( + model.pdoc->LineEnd(line))) * spaceWidth; rcSegment.left = xStart + ll->positions[ll->numCharsInLine] - subLineStart + virtualSpace + vsDraw.aveCharWidth; @@ -1518,7 +1518,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt } const int offset = static_cast<int>(posCaret.Position() - posLineStart); const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - const XYPOSITION virtualOffset = posCaret.VirtualSpace() * spaceWidth; + const XYPOSITION virtualOffset = posCaret.VirtualSpaceWidth(spaceWidth); if (ll->InLine(offset, subLine) && offset <= ll->numCharsBeforeEOL) { XYPOSITION xposCaret = ll->positions[offset] + virtualOffset - ll->positions[ll->LineStart(subLine)]; if (model.BidirectionalEnabled() && (posCaret.VirtualSpace() == 0)) { @@ -1785,7 +1785,9 @@ void DrawTranslucentSelection(Surface *surface, const EditModel &model, const Vi const ColourRGBA selectionBack = SelectionBackground( model, vsDraw, model.sel.RangeType(r)); const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth; - const Interval intervalVirtual{ portion.start.VirtualSpace() * spaceWidth, portion.end.VirtualSpace() * spaceWidth }; + const Interval intervalVirtual{ + portion.start.VirtualSpaceWidth(spaceWidth), + portion.end.VirtualSpaceWidth(spaceWidth) }; if (model.BidirectionalEnabled()) { const SelectionSegment portionInSubLine = portionInLine.Subtract(lineRange.start); diff --git a/src/Editor.cxx b/src/Editor.cxx index 1557ce75e..ead69617d 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -267,7 +267,7 @@ PointDocument Editor::DocumentPointFromView(Point ptView) const { ptDocument.y += ptOrigin.y; } else { ptDocument.x += xOffset; - ptDocument.y += topLine * vs.lineHeight; + ptDocument.y += static_cast<double>(topLine * vs.lineHeight); } return ptDocument; } @@ -1113,9 +1113,9 @@ void Editor::MoveCaretInsideView(bool ensureVisible) { false, false, UserVirtualSpace()), Selection::SelTypes::none, ensureVisible); } else if ((pt.y + vs.lineHeight - 1) > rcClient.bottom) { - const ptrdiff_t yOfLastLineFullyDisplayed = static_cast<ptrdiff_t>(rcClient.top) + (LinesOnScreen() - 1) * vs.lineHeight; + const ptrdiff_t yOfLastLineFullyDisplayed = static_cast<ptrdiff_t>(rcClient.top) + ((LinesOnScreen() - 1) * vs.lineHeight); MovePositionTo(SPositionFromLocation( - Point::FromInts(lastXChosen - xOffset, static_cast<int>(rcClient.top + yOfLastLineFullyDisplayed)), + Point::FromInts(lastXChosen - xOffset, static_cast<int>(rcClient.top + static_cast<XYPOSITION>(yOfLastLineFullyDisplayed))), false, false, UserVirtualSpace()), Selection::SelTypes::none, ensureVisible); } @@ -1607,7 +1607,7 @@ bool Editor::WrapBlock(Surface *surface, Sci::Line lineToWrap, Sci::Line lineToW // Multiply duration by number of threads to produce (near) equivalence to duration if single threaded const double durationShortLines = epWrapping.Duration(true); - const double durationShortLinesThreads = durationShortLines * threads; + const double durationShortLinesThreads = durationShortLines * static_cast<double>(threads); // Wrap all the long lines in the main thread. // LayoutLine may then multi-thread over segments in each line. @@ -3366,7 +3366,7 @@ SelectionPosition Editor::PositionUpOrDown(SelectionPosition spStart, int direct // There is an equivalent case when moving down which skips // over a line. Point ptNew = LocationFromPosition(posNew.Position()); - while ((posNew.Position() > spStart.Position()) && (ptNew.y > newY)) { + while ((posNew.Position() > spStart.Position()) && (ptNew.y > static_cast<XYPOSITION>(newY))) { posNew.Add(-1); posNew.SetVirtualSpace(0); ptNew = LocationFromPosition(posNew.Position()); @@ -4175,7 +4175,7 @@ void Editor::Indent(bool forwards, bool lineIndent) { sel.Range(r) = SelectionRange(caretPosition + lengthInserted); } else { int numSpaces = (pdoc->tabInChars) - - (pdoc->GetColumn(caretPosition) % (pdoc->tabInChars)); + static_cast<int>((pdoc->GetColumn(caretPosition) % (pdoc->tabInChars))); if (numSpaces < 1) numSpaces = pdoc->tabInChars; const std::string spaceText(numSpaces, ' '); @@ -7487,7 +7487,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { break; case Message::MarkerSetStrokeWidth: if (wParam <= MarkerMax) - vs.markers[wParam].strokeWidth = lParam / 100.0f; + vs.markers[wParam].strokeWidth = static_cast<XYPOSITION>(lParam) / 100.0f; InvalidateStyleData(); RedrawSelMargin(); break; @@ -8181,7 +8181,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::IndicSetStrokeWidth: if (wParam <= IndicatorMax && lParam >= 0 && lParam <= 1000) { - vs.indicators[wParam].strokeWidth = lParam / 100.0f; + vs.indicators[wParam].strokeWidth = static_cast<XYPOSITION>(lParam) / 100.0; InvalidateStyleRedraw(); } break; diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx index 0afa64f2b..faa32d9aa 100644 --- a/src/LineMarker.cxx +++ b/src/LineMarker.cxx @@ -196,7 +196,7 @@ void LineMarker::DrawFoldingMark(Surface *surface, const PRectangle &rcWhole, Fo // To centre +/-, odd strokeWidth -> odd symbol width, even -> even const XYPOSITION widthSymbol = ((std::lround(minDimension * pixelDivisions) % 2) == (std::lround(widthStroke * pixelDivisions) % 2)) ? - minDimension : minDimension - 1.0f / pixelDivisions; + minDimension : minDimension - (1.0 / static_cast<XYPOSITION>(pixelDivisions)); const Point centre = PixelAlign(rcWhole.Centre(), pixelDivisions); diff --git a/src/MarginView.cxx b/src/MarginView.cxx index 348b5dd05..09b01959e 100644 --- a/src/MarginView.cxx +++ b/src/MarginView.cxx @@ -278,7 +278,7 @@ void MarginView::PaintOneMargin(Surface *surface, PRectangle rc, PRectangle rcOn const Point ptOrigin = model.GetVisibleOriginInMain(); const Sci::Line lineStartPaint = static_cast<Sci::Line>(rcOneMargin.top + ptOrigin.y) / vs.lineHeight; Sci::Line visibleLine = model.TopLineOfMain() + lineStartPaint; - XYPOSITION yposScreen = lineStartPaint * vs.lineHeight - ptOrigin.y; + XYPOSITION yposScreen = static_cast<XYPOSITION>(lineStartPaint * vs.lineHeight) - ptOrigin.y; // Work out whether the top line is whitespace located after a // lessening of fold level which implies a 'fold tail' but which should not // be displayed until the last of a sequence of whitespace. diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index df5e5acf9..89276d2a0 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -1133,7 +1133,7 @@ void PositionCache::MeasureWidths(Surface *surface, const ViewStyle &vstyle, uns if (AllGraphicASCII(sv)) { const XYPOSITION monospaceCharacterWidth = style.monospaceCharacterWidth; for (size_t i = 0; i < sv.length(); i++) { - positions[i] = monospaceCharacterWidth * (i+1); + positions[i] = monospaceCharacterWidth * static_cast<XYPOSITION>(i+1); } return; } diff --git a/src/Selection.cxx b/src/Selection.cxx index 0de60a958..795570ee2 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -96,6 +96,10 @@ bool SelectionPosition::operator >=(const SelectionPosition &other) const noexce return *this > other; } +double SelectionPosition::VirtualSpaceWidth(double spaceWidth) const noexcept { + return static_cast<double>(virtualSpace) * spaceWidth; +} + std::string SelectionPosition::ToString() const { std::string result = std::to_string(position); if (virtualSpace) { diff --git a/src/Selection.h b/src/Selection.h index 8ffcbb0bb..6779ee7ce 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -50,6 +50,7 @@ public: Sci::Position VirtualSpace() const noexcept { return virtualSpace; } + [[nodiscard]] double VirtualSpaceWidth(double spaceWidth) const noexcept; void SetVirtualSpace(Sci::Position virtualSpace_) noexcept { PLATFORM_ASSERT(virtualSpace_ < 800000000); if (virtualSpace_ >= 0) |