Skip to content

Commit fd82555

Browse files
committed
Move QualType to its own file, change pointer access API.
1 parent 5b693c4 commit fd82555

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed

compiler/qualtype.h

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* vim: set sts=4 ts=8 sw=4 tw=99 et: */
2+
//
3+
// Copyright (c) AlliedModders LLC, 2024
4+
//
5+
// This software is provided "as-is", without any express or implied warranty.
6+
// In no event will the authors be held liable for any damages arising from
7+
// the use of this software.
8+
//
9+
// Permission is granted to anyone to use this software for any purpose,
10+
// including commercial applications, and to alter it and redistribute it
11+
// freely, subject to the following restrictions:
12+
//
13+
// 1. The origin of this software must not be misrepresented; you must not
14+
// claim that you wrote the original software. If you use this software in
15+
// a product, an acknowledgment in the product documentation would be
16+
// appreciated but is not required.
17+
// 2. Altered source versions must be plainly marked as such, and must not be
18+
// misrepresented as being the original software.
19+
// 3. This notice may not be removed or altered from any source distribution.
20+
#pragma once
21+
22+
#include <amtl/am-bits.h>
23+
#include <amtl/am-hashtable.h>
24+
25+
namespace sp {
26+
namespace cc {
27+
28+
class Type;
29+
30+
// Compact encoding of type + constness.
31+
class QualType {
32+
public:
33+
explicit QualType(Type* type) {
34+
impl_ = type;
35+
}
36+
explicit QualType(Type* type, bool is_const) {
37+
impl_ = ke::SetPointerBits(type, is_const ? 1 : 0);
38+
}
39+
40+
bool is_const() const {
41+
return ke::GetPointerBits<2>(impl_) == 1;
42+
}
43+
44+
Type* operator *() const { return ptr(); }
45+
Type* operator ->() const { return ptr(); }
46+
Type* ptr() const {
47+
return ke::ClearPointerBits<2>(impl_);
48+
}
49+
QualType unqualified() const { return QualType(ptr()); }
50+
51+
uint32_t hash() const { return ke::HashPointer(impl_); }
52+
53+
bool operator ==(const QualType& other) const { return impl_ == other.impl_; }
54+
bool operator !=(const QualType& other) const { return impl_ != other.impl_; }
55+
56+
private:
57+
Type* impl_;
58+
};
59+
60+
} // namespace cc
61+
} // namespace sp

compiler/types.h

+1-30
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "pool-objects.h"
3232
#include "shared/string-atom.h"
3333
#include "stl/stl-vector.h"
34+
#include "qualtype.h"
3435

3536
typedef int32_t cell;
3637
typedef uint32_t ucell;
@@ -85,36 +86,6 @@ class MethodmapDecl;
8586
class PstructDecl;
8687
class Type;
8788

88-
// Compact encoding of type + constness.
89-
class QualType {
90-
public:
91-
explicit QualType(Type* type) {
92-
impl_ = type;
93-
}
94-
explicit QualType(Type* type, bool is_const) {
95-
impl_ = ke::SetPointerBits(type, is_const ? 1 : 0);
96-
}
97-
98-
bool is_const() const {
99-
return ke::GetPointerBits<2>(impl_) == 1;
100-
}
101-
102-
Type* operator *() const { return unqualified(); }
103-
Type* operator ->() const { return unqualified(); }
104-
Type* unqualified() const {
105-
return ke::ClearPointerBits<2>(impl_);
106-
}
107-
108-
uint32_t hash() const { return ke::HashPointer(impl_); }
109-
110-
bool operator ==(const QualType& other) const { return impl_ == other.impl_; }
111-
bool operator !=(const QualType& other) const { return impl_ != other.impl_; }
112-
113-
private:
114-
Type* impl_;
115-
};
116-
117-
11889
struct TypenameInfo {
11990
static constexpr uintptr_t kAtomFlag = 0x1;
12091
static constexpr uintptr_t kLabelFlag = 0x2;

0 commit comments

Comments
 (0)