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 | #include "qqmlsasourcelocation.h" |
5 | #include "qqmlsasourcelocation_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | using namespace Qt::StringLiterals; |
10 | |
11 | namespace QQmlSA { |
12 | |
13 | static_assert(SourceLocationPrivate::sizeOfSourceLocation() == sizeof(SourceLocation)); |
14 | |
15 | /*! |
16 | \class QQmlSA::SourceLocation |
17 | \inmodule QtQmlCompiler |
18 | |
19 | \brief Represents a location or region in the source code. |
20 | */ |
21 | QQmlSA::SourceLocation::SourceLocation(quint32 offset, quint32 length, quint32 line, quint32 column) |
22 | { |
23 | new (m_data) QQmlJS::SourceLocation{ offset, length, line, column }; |
24 | } |
25 | |
26 | // explicitly defaulted out-of-line for PIMPL |
27 | QQmlSA::SourceLocation::SourceLocation(const SourceLocation &other) = default; |
28 | QQmlSA::SourceLocation & QQmlSA::SourceLocation::operator=(const QQmlSA::SourceLocation &other) = default; |
29 | SourceLocation::~SourceLocation() = default; |
30 | |
31 | bool QQmlSA::SourceLocation::isValid() const |
32 | { |
33 | return QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: *this).isValid(); |
34 | } |
35 | |
36 | /*! |
37 | Returns the offset of the beginning of this source location. |
38 | */ |
39 | quint32 QQmlSA::SourceLocation::begin() const |
40 | { |
41 | return QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: *this).begin(); |
42 | } |
43 | |
44 | /*! |
45 | Returns the offset of the end of this source location. |
46 | */ |
47 | quint32 QQmlSA::SourceLocation::end() const |
48 | { |
49 | return QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: *this).end(); |
50 | } |
51 | |
52 | /*! |
53 | Returns the offset of the beginning of this source location. |
54 | */ |
55 | quint32 QQmlSA::SourceLocation::offset() const |
56 | { |
57 | return QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: *this).offset; |
58 | } |
59 | |
60 | /*! |
61 | Returns the length of this source location. |
62 | */ |
63 | quint32 QQmlSA::SourceLocation::length() const |
64 | { |
65 | return QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: *this).length; |
66 | } |
67 | |
68 | /*! |
69 | Returns the line number containing the beginning of this source location. |
70 | */ |
71 | quint32 QQmlSA::SourceLocation::startLine() const |
72 | { |
73 | return QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: *this).startLine; |
74 | } |
75 | |
76 | /*! |
77 | Returns the column number containing the beginning of this source location. |
78 | */ |
79 | quint32 QQmlSA::SourceLocation::startColumn() const |
80 | { |
81 | return QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: *this).startColumn; |
82 | } |
83 | |
84 | /*! |
85 | Returns a source location of lenth zero pointing to the beginning of this |
86 | source location. |
87 | */ |
88 | QQmlSA::SourceLocation QQmlSA::SourceLocation::startZeroLengthLocation() const |
89 | { |
90 | QQmlSA::SourceLocation saLocation; |
91 | auto &wrappedLocation = reinterpret_cast<QQmlJS::SourceLocation &>(saLocation.m_data); |
92 | wrappedLocation = |
93 | QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: *this).startZeroLengthLocation(); |
94 | |
95 | return saLocation; |
96 | } |
97 | |
98 | /*! |
99 | Returns a source location of lenth zero pointing to the end of this source |
100 | location pointing to \a text. |
101 | */ |
102 | QQmlSA::SourceLocation QQmlSA::SourceLocation::endZeroLengthLocation(QStringView text) const |
103 | { |
104 | QQmlSA::SourceLocation saLocation; |
105 | auto &wrappedLocation = reinterpret_cast<QQmlJS::SourceLocation &>(saLocation.m_data); |
106 | wrappedLocation = wrappedLocation.endZeroLengthLocation(text); |
107 | |
108 | return saLocation; |
109 | } |
110 | |
111 | qsizetype QQmlSA::SourceLocation::qHashImpl(const SourceLocation &location, qsizetype seed) |
112 | { |
113 | return qHash(location: QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: location), seed); |
114 | } |
115 | |
116 | bool QQmlSA::SourceLocation::operatorEqualsImpl(const SourceLocation &lhs, |
117 | const SourceLocation &rhs) |
118 | { |
119 | return QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: lhs) |
120 | == QQmlSA::SourceLocationPrivate::sourceLocation(sourceLocation: rhs); |
121 | } |
122 | |
123 | } // namespace QQmlSA |
124 | |
125 | QT_END_NAMESPACE |
126 |