-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathqualified_type.cpp
More file actions
executable file
·58 lines (49 loc) · 2.01 KB
/
qualified_type.cpp
File metadata and controls
executable file
·58 lines (49 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "qualified_type.h"
#include "type.h"
std::string QualifiedType::ToString() const{
if (!type) return "(null)";
std::stringstream ss;
if (isConst) ss << "const ";
if (isVolatile) ss << "volatile ";
ss << type->GetName();
ss << std::string(pointerCount, '*');
if (referType == ReferType::Refer) ss << "&";
else if (referType == ReferType::RightRefer) ss << "&&";
return ss.str();
}
bool QualifiedType::CanCast(const QualifiedType& t) const{
if (t.type->IsEnum()){ // const char* -> const string&
if (t.type == type)
return true;
if (type == typeof(int64_t))
return true;
}
if (type->Is(t.type)){
if (pointerCount == 0 && t.pointerCount == 0 && !t.IsReference())
return true;
if (pointerCount == t.pointerCount && (!isConst || t.isConst) && (!isVolatile || t.isVolatile) && (referType == ReferType::None || (referType == ReferType::Refer && t.referType != ReferType::None) || t.referType == ReferType::RightRefer))
return true;
}
return false;//t.type->GetConstructor({ *this }) != nullptr;
}
bool QualifiedType::IsNumber() const{
return type == int8Type || type == int16Type || type == int32Type || type == int64Type
|| type == uint8Type || type == uint16Type || type == uint32Type || type == uint64Type
|| type == floatType || type == doubleType;
}
bool QualifiedType::IsFloatingNumber() const{
return type == floatType || type == doubleType;
}
bool QualifiedType::IsIntegerNumber() const{
return type == int8Type || type == int16Type || type == int32Type || type == int64Type
|| type == uint8Type || type == uint16Type || type == uint32Type || type == uint64Type;
}
bool QualifiedType::IsBool() const{
return type == boolType;
}
bool QualifiedType::IsString() const{
return type == stringType || (type == charType && pointerCount == 1);
}
bool QualifiedType::IsEnum() const{
return type->IsEnum();
}