i++;
m = "..";
}
- else if (c.value < 0x80)
+ else if (c.is_ascii ())
// ASCII
m.push_back (c.value);
else
constexpr uint8_t UTF8_BOM2 = 0xBB;
constexpr uint8_t UTF8_BOM3 = 0xBF;
-constexpr uint32_t MAX_ASCII_CODEPOINT = 0x7F;
-constexpr uint32_t CODEPOINT_INVALID = 0xFFFE;
-
// Input source wrapper thing.
class InputSource
{
// otherwise, get character from direct input character
byte_char = current_char;
- if (byte_char.value > 0x7f)
+ if (!byte_char.is_ascii ())
{
rust_error_at (get_current_location (),
"non-ASCII character in %<byte char%>");
#include "rust-ast.h"
#include "rust-ast-full.h"
#include "rust-diagnostics.h"
+#include "rust-unicode.h"
namespace Rust {
namespace Analysis {
check_proc_macro_non_function (declaration.get_outer_attrs ());
}
+static void
+check_no_mangle_function (const AST::Attribute &attribute,
+ const AST::Function &fun)
+{
+ if (attribute.has_attr_input ())
+ {
+ rust_error_at (attribute.get_locus (), ErrorCode::E0754,
+ "malformed %<no_mangle%> attribute input");
+ rust_inform (attribute.get_locus (),
+ "must be of the form: %<#[no_mangle]%>");
+ }
+ if (!is_ascii_only (fun.get_function_name ().as_string ()))
+ rust_error_at (fun.get_function_name ().get_locus (),
+ "the %<#[no_mangle]%> attribute requires ASCII identifier");
+}
+
void
AttributeChecker::visit (AST::Function &fun)
{
{
check_crate_type (name, attribute);
}
+ else if (result.name == "no_mangle")
+ check_no_mangle_function (attribute, fun);
}
fun.get_definition ()->accept_vis (*this);
}
namespace Rust {
+constexpr uint32_t MAX_ASCII_CODEPOINT = 0x7F;
+constexpr uint32_t CODEPOINT_INVALID = 0xFFFE;
+
// FIXME: move this to rust-unicode.h?
struct Codepoint
{
static Codepoint eof () { return Codepoint (UINT32_MAX); }
bool is_eof () const { return value == UINT32_MAX; }
+ bool is_ascii () const { return value <= MAX_ASCII_CODEPOINT; }
// Returns a C++ string containing string value of codepoint.
std::string as_string ();
std::string basic_string;
for (auto c : src)
{
- if (c.value <= 0x7F)
+ if (c.is_ascii ())
basic_string += c.as_string ();
}
return basic_string;
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
+#include "rust-input-source.h"
#include "rust-system.h"
#include "optional.h"
#include "selftest.h"
return true;
}
+bool
+is_ascii_only (const std::string &str)
+{
+ for (char c : str)
+ if (static_cast<uint32_t> (c) > MAX_ASCII_CODEPOINT)
+ return false;
+ return true;
+}
+
} // namespace Rust
#if CHECKING_P
bool
is_alphabetic (uint32_t codepoint);
+bool
+is_ascii_only (const std::string &str);
+
bool
is_numeric (uint32_t codepoint);