Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmljssourcelocation_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLJSSOURCELOCATION_P_H
5#define QQMLJSSOURCELOCATION_P_H
6
7#include <QtCore/private/qglobal_p.h>
8#include <QtCore/qhashfunctions.h>
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
22
23namespace QQmlJS {
24
26{
27public:
32
33 bool isValid() const { return *this != SourceLocation(); }
34
35 quint32 begin() const { return offset; }
36 quint32 end() const { return offset + length; }
37
38 // Returns a zero length location at the start of the current one.
43 // Returns a zero length location at the end of the current one.
45 {
47 quint32 endLine = startLine;
48 quint32 endColumn = startColumn;
49 while (i < end()) {
50 QChar c = text.at(i);
51 switch (c.unicode()) {
52 case '\n':
53 if (i + 1 < end() && text.at(i + 1) == QLatin1Char('\r'))
54 ++i;
56 case '\r':
57 ++endLine;
58 endColumn = 1;
59 break;
60 default:
61 ++endColumn;
62 }
63 ++i;
64 }
65 return SourceLocation(offset + length, 0, endLine, endColumn);
66 }
67
68// attributes
69 // ### encode
74
75 friend size_t qHash(const SourceLocation &location, size_t seed = 0)
76 {
77 return qHashMulti(seed, location.offset, location.length,
78 location.startLine, location.startColumn);
79 }
80
81 friend bool operator==(const SourceLocation &a, const SourceLocation &b)
82 {
83 return a.offset == b.offset && a.length == b.length
84 && a.startLine == b.startLine && a.startColumn == b.startColumn;
85 }
86
87 friend bool operator!=(const SourceLocation &a, const SourceLocation &b) { return !(a == b); }
88
89 // Returns a source location starting at the beginning of l1, l2 and ending at the end of them.
90 // Ignores invalid source locations.
91 friend SourceLocation combine(const SourceLocation &l1, const SourceLocation &l2) {
92 quint32 e = qMax(l1.end(), l2.end());
94 if (l1.offset <= l2.offset)
95 res = (l1.isValid() ? l1 : l2);
96 else
97 res = (l2.isValid() ? l2 : l1);
98 res.length = e - res.offset;
99 return res;
100 }
101};
102
103} // namespace QQmlJS
104
106
107#endif
\inmodule QtCore
friend size_t qHash(const SourceLocation &location, size_t seed=0)
SourceLocation startZeroLengthLocation() const
friend bool operator!=(const SourceLocation &a, const SourceLocation &b)
friend SourceLocation combine(const SourceLocation &l1, const SourceLocation &l2)
SourceLocation(quint32 offset=0, quint32 length=0, quint32 line=0, quint32 column=0)
SourceLocation endZeroLengthLocation(QStringView text) const
friend bool operator==(const SourceLocation &a, const SourceLocation &b)
\inmodule QtCore
Definition qstringview.h:78
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
QString text
Combined button and popup list for selecting options.
#define Q_FALLTHROUGH()
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLint location
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei length
GLenum GLuint GLintptr offset
GLenum GLenum GLsizei void GLsizei void * column
GLuint res
const GLubyte * c
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
unsigned int quint32
Definition qtypes.h:50
\inmodule QtCore \reentrant
Definition qchar.h:18