aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util
diff options
context:
space:
mode:
authorRaiki Tamura <tamaron1203@gmail.com>2023-08-06 19:17:17 +0900
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 19:00:30 +0100
commit5b47923fe512f088a4f1c31466236843c20b7ff9 (patch)
tree4c3258bbf931ea7093e47d8c7008bcc35d9dbeaa /gcc/rust/util
parent1e288d66cb4f0a25a249c0c6dacc2efbf9e44dc8 (diff)
downloadgcc-5b47923fe512f088a4f1c31466236843c20b7ff9.zip
gcc-5b47923fe512f088a4f1c31466236843c20b7ff9.tar.gz
gcc-5b47923fe512f088a4f1c31466236843c20b7ff9.tar.bz2
gccrs: clean up Codepoint and InputSource
gcc/rust/ChangeLog: * lex/rust-codepoint.h: Moved to... * util/rust-codepoint.h: ...here. * lex/rust-input-source.h: Add missing license * util/rust-unicode.cc: Add missing license * util/rust-punycode.cc (extract_basic_string): Remove constant Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Diffstat (limited to 'gcc/rust/util')
-rw-r--r--gcc/rust/util/rust-codepoint.h48
-rw-r--r--gcc/rust/util/rust-punycode.cc4
-rw-r--r--gcc/rust/util/rust-unicode.cc18
3 files changed, 67 insertions, 3 deletions
diff --git a/gcc/rust/util/rust-codepoint.h b/gcc/rust/util/rust-codepoint.h
new file mode 100644
index 0000000..755c837
--- /dev/null
+++ b/gcc/rust/util/rust-codepoint.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC 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 General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_CODEPOINT_H
+#define RUST_CODEPOINT_H
+
+#include "rust-system.h"
+
+namespace Rust {
+
+// FIXME: move this to rust-unicode.h?
+struct Codepoint
+{
+ uint32_t value;
+
+ // Creates a zero codepoint.
+ Codepoint () : value (0) {}
+
+ // Creates a codepoint from an encoded UTF-8 value.
+ Codepoint (uint32_t value) : value (value) {}
+
+ static Codepoint eof () { return Codepoint (UINT32_MAX); }
+ bool is_eof () const { return value == UINT32_MAX; }
+
+ // Returns a C++ string containing string value of codepoint.
+ std::string as_string ();
+
+ bool operator== (Codepoint other) const { return value == other.value; }
+ bool operator!= (Codepoint other) const { return !operator== (other); }
+};
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/util/rust-punycode.cc b/gcc/rust/util/rust-punycode.cc
index a35d54a..6c796ab 100644
--- a/gcc/rust/util/rust-punycode.cc
+++ b/gcc/rust/util/rust-punycode.cc
@@ -36,15 +36,13 @@ constexpr uint32_t INITIAL_BIAS = 72;
constexpr uint32_t INITIAL_N = 128;
constexpr char DELIMITER = '-';
-constexpr uint32_t MAX_ASCII_CODEPOINT = 0x7F;
-
std::string
extract_basic_string (const std::vector<Codepoint> &src)
{
std::string basic_string;
for (auto c : src)
{
- if (c.value <= MAX_ASCII_CODEPOINT)
+ if (c.value <= 0x7F)
basic_string += c.as_string ();
}
return basic_string;
diff --git a/gcc/rust/util/rust-unicode.cc b/gcc/rust/util/rust-unicode.cc
index b2ddaf0..95653cb 100644
--- a/gcc/rust/util/rust-unicode.cc
+++ b/gcc/rust/util/rust-unicode.cc
@@ -1,3 +1,21 @@
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC 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 General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
#include "rust-system.h"
#include "optional.h"
#include "selftest.h"