-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeUtils.h
72 lines (61 loc) · 2.44 KB
/
TypeUtils.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
This file is part of the clazy static checker.
Copyright (C) 2016 Sergio Martins <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef CLAZY_TYPE_UTILS_H
#define CLAZY_TYPE_UTILS_H
namespace clang {
class CompilerInstance;
class QualType;
class Stmt;
class VarDecl;
class Type;
}
namespace TypeUtils
{
/**
* Returns the sizeof(void*) for the platform we're compiling for, in bits.
*/
int sizeOfPointer(const clang::CompilerInstance &, clang::QualType qt);
struct QualTypeClassification {
bool isConst = false;
bool isReference = false;
bool isBig = false;
bool isNonTriviallyCopyable = false;
bool passBigTypeByConstRef = false;
bool passNonTriviallyCopyableByConstRef = false;
bool passSmallTrivialByValue = false;
int size_of_T = 0;
};
/**
* Classifies a QualType, for example:
*
* This function is useful to know if a type should be passed by value or const-ref.
* The optional parameter body is in order to advise non-const-ref -> value, since the body
* needs to be inspected to see if we that would compile.
*/
bool classifyQualType(const clang::CompilerInstance &ci, const clang::VarDecl *varDecl,
QualTypeClassification &classification,
clang::Stmt *body = nullptr);
/**
* If qt is a reference, return it without a reference.
* If qt is not a reference, return qt.
*
* This is useful because sometimes you have an argument like "const QString &", but qualType.isConstQualified()
* returns false. Must go through qualType->getPointeeType().isConstQualified().
*/
clang::QualType unrefQualType(clang::QualType qt);
}
#endif