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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_TORQUE_UTILS_H_
#define V8_TORQUE_UTILS_H_
#include <string>
#include <unordered_set>
#include <vector>
#include "src/base/functional.h"
namespace v8 {
namespace internal {
namespace torque {
typedef std::vector<std::string> NameVector;
std::string StringLiteralUnquote(const std::string& s);
std::string StringLiteralQuote(const std::string& s);
[[noreturn]] void ReportError(const std::string& error);
std::string CamelifyString(const std::string& underscore_string);
std::string DashifyString(const std::string& underscore_string);
void ReplaceFileContentsIfDifferent(const std::string& file_path,
const std::string& contents);
std::string CurrentPositionAsString();
template <class T>
class Deduplicator {
public:
const T* Add(T x) { return &*(storage_.insert(std::move(x)).first); }
private:
std::unordered_set<T, base::hash<T>> storage_;
};
template <class C, class T>
void PrintCommaSeparatedList(std::ostream& os, const T& list, C transform) {
bool first = true;
for (auto& e : list) {
if (first) {
first = false;
} else {
os << ", ";
}
os << transform(e);
}
}
template <class T,
typename std::enable_if<
std::is_pointer<typename T::value_type>::value, int>::type = 0>
void PrintCommaSeparatedList(std::ostream& os, const T& list) {
bool first = true;
for (auto& e : list) {
if (first) {
first = false;
} else {
os << ", ";
}
os << *e;
}
}
template <class T,
typename std::enable_if<
!std::is_pointer<typename T::value_type>::value, int>::type = 0>
void PrintCommaSeparatedList(std::ostream& os, const T& list) {
bool first = true;
for (auto& e : list) {
if (first) {
first = false;
} else {
os << ", ";
}
os << e;
}
}
} // namespace torque
} // namespace internal
} // namespace v8
#endif // V8_TORQUE_UTILS_H_
|