24 DCHECK((
'"' == s.front() &&
'"' == s.back()) ||
25 (
'\'' == s.front() &&
'\'' == s.back()));
27 for (
size_t i = 1;
i < s.
length() - 1; ++
i) {
88 if (isdigit(c))
return c -
'0';
89 if (isupper(c))
return c -
'A' + 10;
99 std::ostringstream decoded;
101 for (
auto iter = path.begin(),
end = path.end(); iter !=
end; ++iter) {
102 std::string::value_type c = (*iter);
111 if (std::distance(iter,
end) <= 2)
return std::nullopt;
113 unsigned char first = (*++iter);
114 unsigned char second = (*++iter);
115 if (!isxdigit(first) || !isxdigit(
second))
return std::nullopt;
122 return decoded.str();
127 std::optional<SourcePosition>
position;
128 if (CurrentSourcePosition::HasScope()) {
129 position = CurrentSourcePosition::Get();
132 if (CurrentScope::HasScope()) {
138 Scope* scope = CurrentScope::Get();
141 if (!requester.
IsNone()) {
143 {
"Note: in specialization " + requester.
name +
" requested here",
145 scope = requester.
scope;
154 TorqueMessages::Get().push_back(
message_);
156 TorqueMessages::Get().push_back(message);
166bool ContainsUnderscore(
const std::string& s) {
167 if (s.empty())
return false;
168 return s.find(
"_") != std::string::npos;
171bool ContainsUpperCase(
const std::string& s) {
172 if (s.empty())
return false;
173 return std::any_of(s.begin(), s.end(), [](
char c) { return isupper(c); });
179bool IsKeywordLikeName(
const std::string& s) {
180 static const char*
const keyword_like_constants[]{
181 "True",
"False",
"TheHole",
"PromiseHole",
"Null",
"Undefined"};
183 return std::find(std::begin(keyword_like_constants),
184 std::end(keyword_like_constants),
185 s) != std::end(keyword_like_constants);
190bool IsMachineType(
const std::string& s) {
191 static const char*
const machine_types[]{
215 return std::find(std::begin(machine_types), std::end(machine_types), s) !=
216 std::end(machine_types);
222 if (s.empty())
return false;
224 if (s[0] ==
'_')
start = 1;
225 return islower(s[
start]) && !ContainsUnderscore(s.substr(
start));
229 if (s.empty())
return false;
231 if (s[0] ==
'_')
start = 1;
232 return isupper(s[
start]);
236 if (s.empty())
return false;
237 return !ContainsUpperCase(s);
241 if (s.empty())
return false;
242 if (IsKeywordLikeName(s))
return true;
248 if (s.empty())
return false;
249 if (IsMachineType(s))
return true;
256 size_t js_position = camellified_string.find(
"JS");
259 bool previousWasLowerOrDigit =
false;
260 for (
size_t index = 0; index < camellified_string.size(); ++
index) {
261 char current = camellified_string[
index];
262 if ((previousWasLowerOrDigit && isupper(current)) ||
263 (js_position != std::string::npos &&
264 index == js_position + strlen(
"JS"))) {
267 if (current ==
'.' || current ==
'-') {
269 previousWasLowerOrDigit =
false;
272 result += toupper(current);
273 previousWasLowerOrDigit = islower(current) || isdigit(current);
280 bool word_beginning =
true;
281 for (
auto current : underscore_string) {
282 if (current ==
'_' || current ==
'-') {
283 word_beginning =
true;
286 if (word_beginning) {
287 current = toupper(current);
290 word_beginning =
false;
297 bool previousWasLower =
false;
298 for (
auto current : camel_string) {
299 if (previousWasLower && isupper(current)) {
302 result += tolower(current);
303 previousWasLower = (islower(current));
309 std::string
result = underscore_string;
315 std::replace(path.begin(), path.end(),
'-',
'_');
316 std::replace(path.begin(), path.end(),
'/',
'_');
317 std::replace(path.begin(), path.end(),
'\\',
'_');
318 std::replace(path.begin(), path.end(),
'.',
'_');
319 transform(path.begin(), path.end(), path.begin(), ::toupper);
324 return str.length() >= 2 && str[0] ==
'_' && str[1] !=
'_';
329 std::ifstream old_contents_stream(file_path.c_str());
330 std::string old_contents;
331 bool file_exists =
false;
332 if (old_contents_stream.good()) {
334 std::istreambuf_iterator<char> eos;
336 std::string(std::istreambuf_iterator<char>(old_contents_stream), eos);
337 old_contents_stream.close();
339 if (!file_exists || old_contents !=
contents) {
340 std::ofstream new_contents_stream;
341 new_contents_stream.open(file_path.c_str());
343 new_contents_stream.close();
348 :
os_(os), d_(
std::move(d)) {
349 os_ <<
"#ifdef " <<
d_ <<
"\n";
354 std::initializer_list<std::string> namespaces)
355 :
os_(os), d_(
std::move(namespaces)) {
356 for (
const std::string& s :
d_) {
357 os_ <<
"namespace " << s <<
" {\n";
361 for (
auto i =
d_.rbegin();
i !=
d_.rend(); ++
i) {
362 os_ <<
"} // namespace " << *
i <<
"\n";
370 os_ <<
"#ifndef " <<
d_ <<
"\n";
371 os_ <<
"#define " <<
d_ <<
"\n\n";
376 os_ <<
"\n// Has to be the last include (doesn't have include guards):\n"
377 "#include \"src/objects/object-macros.h\"\n";
380 os_ <<
"\n#include \"src/objects/object-macros-undef.h\"\n";
391 if (a.SingleValue().has_value())
return os << *a.SingleValue();
392 return os <<
"[" << a.value_ <<
" mod 2^" << a.modulus_log_2_ <<
"]";
Scope * ParentScope() const
IfDefScope(std::ostream &os, std::string d)
IncludeGuardScope(std::ostream &os, std::string file_name)
IncludeObjectMacrosScope(std::ostream &os)
~IncludeObjectMacrosScope()
std::vector< TorqueMessage > extra_messages_
NamespaceScope(std::ostream &os, std::initializer_list< std::string > namespaces)
std::vector< std::string > d_
static const size_t kMaxModulusLog2
size_t AlignmentLog2() const
const SpecializationRequester & GetSpecializationRequester() const
#define EXPORT_CONTEXTUAL_VARIABLE(VarName)
ZoneVector< RpoNumber > & result
constexpr unsigned CountTrailingZeros(T value)
static const char *const INT31_TYPE_STRING
static const char kFileUriPrefix[]
static const char *const NEVER_TYPE_STRING
static const char *const FLOAT32_TYPE_STRING
static const char *const BOOL_TYPE_STRING
bool IsUpperCamelCase(const std::string &s)
std::string CapifyStringWithUnderscores(const std::string &camellified_string)
static const char *const INT16_TYPE_STRING
static const char *const UINT64_TYPE_STRING
std::ostream & operator<<(std::ostream &os, Identifier *id)
static const char *const FLOAT16_RAW_BITS_TYPE_STRING
std::string StringLiteralQuote(const std::string &s)
static const char *const INT8_TYPE_STRING
void ReplaceFileContentsIfDifferent(const std::string &file_path, const std::string &contents)
static const char *const INT32_TYPE_STRING
static const char *const UINT8_TYPE_STRING
static const char *const FLOAT64_OR_UNDEFINED_OR_HOLE_TYPE_STRING
static const char *const VOID_TYPE_STRING
static const char *const UINTPTR_TYPE_STRING
static const char *const BINT_TYPE_STRING
static const char *const UINT16_TYPE_STRING
static const char *const UINT32_TYPE_STRING
std::string SnakeifyString(const std::string &camel_string)
static const char *const CHAR8_TYPE_STRING
static const char *const INTPTR_TYPE_STRING
static const char *const INT64_TYPE_STRING
static int HexCharToInt(unsigned char c)
bool IsValidTypeName(const std::string &s)
std::string DashifyString(const std::string &underscore_string)
bool StartsWithSingleUnderscore(const std::string &str)
static const int kFileUriPrefixLength
bool IsSnakeCase(const std::string &s)
std::string CamelifyString(const std::string &underscore_string)
std::optional< std::string > FileUriDecode(const std::string &uri)
bool IsLowerCamelCase(const std::string &s)
bool IsValidNamespaceConstName(const std::string &s)
std::string UnderlinifyPath(std::string path)
static const char *const FLOAT64_TYPE_STRING
static const char *const CHAR16_TYPE_STRING
std::string StringLiteralUnquote(const std::string &s)
static const char *const UINT31_TYPE_STRING
base::Vector< const char > contents
#define DCHECK(condition)