11#ifndef UTILS_H
22#define UTILS_H
33
4- #include < clang/AST/AST.h>
5-
64#include " ir/TypeDef.h"
75#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>
207
218inline std::string uint64ToScalaNat (uint64_t v, std::string accumulator = " " ) {
229 if (v == 0 )
@@ -43,7 +30,7 @@ inline bool typeEquals(const clang::Type *tpe1, const std::string *tpe2) {
4330 return false ;
4431 }
4532 // TODO: What is the proper way ?
46- if (tpe1->getAsTagDecl () && tpe2 ) {
33+ if (tpe1->getAsTagDecl ()) {
4734 return tpe1->getAsTagDecl ()->getNameAsString () == *tpe2;
4835 }
4936 return false ;
@@ -58,8 +45,8 @@ static std::array<std::string, 39> reserved_words = {
5845 " trait" , " try" , " true" , " type" , " val" , " var" ,
5946 " while" , " with" , " yield" }};
6047
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 = " " ) {
6350 auto found = std::find (reserved_words.begin (), reserved_words.end (), name);
6451 if (found != reserved_words.end ()) {
6552 return " `" + name + suffix + " `" ;
@@ -68,26 +55,6 @@ inline std::string handleReservedWords(std::string name,
6855 }
6956}
7057
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-
9158/* *
9259 * @return true if str starts with given prefix
9360 */
0 commit comments