1
1
#ifndef UTILS_H
2
2
#define UTILS_H
3
3
4
- #include < clang/AST/AST.h>
5
-
6
4
#include " ir/TypeDef.h"
7
5
#include " ir/types/Type.h"
8
- #include < algorithm>
9
- #include < cctype>
10
- #include < cinttypes>
11
- #include < locale>
12
- #include < string>
13
-
14
- inline std::string basename (const std::string &pathname) {
15
- return {std::find_if (pathname.rbegin (), pathname.rend (),
16
- [](char c) { return c == ' /' ; })
17
- .base (),
18
- pathname.end ()};
19
- }
6
+ #include < clang/AST/AST.h>
20
7
21
8
inline std::string uint64ToScalaNat (uint64_t v, std::string accumulator = " " ) {
22
9
if (v == 0 )
@@ -43,7 +30,7 @@ inline bool typeEquals(const clang::Type *tpe1, const std::string *tpe2) {
43
30
return false ;
44
31
}
45
32
// TODO: What is the proper way ?
46
- if (tpe1->getAsTagDecl () && tpe2 ) {
33
+ if (tpe1->getAsTagDecl ()) {
47
34
return tpe1->getAsTagDecl ()->getNameAsString () == *tpe2;
48
35
}
49
36
return false ;
@@ -58,8 +45,8 @@ static std::array<std::string, 39> reserved_words = {
58
45
" trait" , " try" , " true" , " type" , " val" , " var" ,
59
46
" while" , " with" , " yield" }};
60
47
61
- inline std::string handleReservedWords (std::string name,
62
- std::string suffix = " " ) {
48
+ inline std::string handleReservedWords (const std::string & name,
49
+ const std::string & suffix = " " ) {
63
50
auto found = std::find (reserved_words.begin (), reserved_words.end (), name);
64
51
if (found != reserved_words.end ()) {
65
52
return " `" + name + suffix + " `" ;
@@ -68,26 +55,6 @@ inline std::string handleReservedWords(std::string name,
68
55
}
69
56
}
70
57
71
- // trim from start (in place)
72
- static inline void ltrim (std::string &s) {
73
- s.erase (s.begin (), std::find_if (s.begin (), s.end (),
74
- [](int ch) { return !std::isspace (ch); }));
75
- }
76
-
77
- // trim from end (in place)
78
- static inline void rtrim (std::string &s) {
79
- s.erase (std::find_if (s.rbegin (), s.rend (),
80
- [](int ch) { return !std::isspace (ch); })
81
- .base (),
82
- s.end ());
83
- }
84
-
85
- // trim from both ends (in place)
86
- static inline void trim (std::string &s) {
87
- ltrim (s);
88
- rtrim (s);
89
- }
90
-
91
58
/* *
92
59
* @return true if str starts with given prefix
93
60
*/
0 commit comments