1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef QQMLSASOURCELOCATION_H |
5 | #define QQMLSASOURCELOCATION_H |
6 | |
7 | #include <QtQmlCompiler/qtqmlcompilerexports.h> |
8 | |
9 | #include <QtCore/qstringview.h> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | namespace QQmlJS { |
14 | class SourceLocation; |
15 | } // namespace QQmlJS |
16 | |
17 | namespace QQmlSA { |
18 | |
19 | class SourceLocationPrivate; |
20 | |
21 | class Q_QMLCOMPILER_EXPORT SourceLocation |
22 | { |
23 | friend class QT_PREPEND_NAMESPACE(QQmlSA::SourceLocationPrivate); |
24 | |
25 | public: |
26 | explicit SourceLocation(quint32 offset = 0, quint32 length = 0, quint32 line = 0, |
27 | quint32 column = 0); |
28 | SourceLocation(const SourceLocation &); |
29 | SourceLocation(SourceLocation &&other) noexcept |
30 | { |
31 | memcpy(dest: m_data, src: other.m_data, n: sizeofSourceLocation); |
32 | memset(s: other.m_data, c: 0, n: sizeofSourceLocation); |
33 | } |
34 | SourceLocation &operator=(const SourceLocation &); |
35 | SourceLocation &operator=(SourceLocation &&other) noexcept |
36 | { |
37 | memcpy(dest: m_data, src: other.m_data, n: sizeofSourceLocation); |
38 | memset(s: other.m_data, c: 0, n: sizeofSourceLocation); |
39 | return *this; |
40 | } |
41 | ~SourceLocation(); |
42 | |
43 | bool isValid() const; |
44 | |
45 | quint32 begin() const; |
46 | quint32 end() const; |
47 | |
48 | quint32 offset() const; |
49 | quint32 length() const; |
50 | quint32 startLine() const; |
51 | quint32 startColumn() const; |
52 | |
53 | SourceLocation startZeroLengthLocation() const; |
54 | SourceLocation endZeroLengthLocation(QStringView text) const; |
55 | |
56 | friend qsizetype qHash(const SourceLocation &location, qsizetype seed = 0) |
57 | { |
58 | return qHashImpl(location, seed); |
59 | } |
60 | |
61 | friend bool operator==(const SourceLocation &lhs, const SourceLocation &rhs) |
62 | { |
63 | return operatorEqualsImpl(lhs, rhs); |
64 | } |
65 | |
66 | friend bool operator!=(const SourceLocation &lhs, const SourceLocation &rhs) |
67 | { |
68 | return !(lhs == rhs); |
69 | } |
70 | |
71 | private: |
72 | static qsizetype qHashImpl(const SourceLocation &location, qsizetype seed); |
73 | static bool operatorEqualsImpl(const SourceLocation &, const SourceLocation &); |
74 | |
75 | static constexpr qsizetype sizeofSourceLocation = 4 * sizeof(quint32); |
76 | alignas(int) char m_data[sizeofSourceLocation] = {}; |
77 | }; |
78 | |
79 | } // namespace QQmlSA |
80 | |
81 | QT_END_NAMESPACE |
82 | |
83 | #endif // QQMLSASOURCELOCATION_H |
84 | |