From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 60E6F3858CD1 for ; Thu, 4 Jan 2024 15:38:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60E6F3858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 60E6F3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704382688; cv=none; b=duKCRaoXv+bClsVxj9yP60OzZlIvvFsgsX5ryVfStE0EBixb6VFd0BCId2J90wgvR44rB4GKOx/Z7MP+GIhtEgsCa2wByZFhCneIho1cULb76MByUi6KXKMfKGdN3Nc9ciQY2m9amQwAAjmbC+t6SGYbf5P6P822feYLHAs31Jw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704382688; c=relaxed/simple; bh=H9xQ8pT/SzUHjsIwnHwSeo7vSKBwOWsmaybjHdyzgls=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=W50FdtfuRFVDQRY3cmuSrmoaD6j36e8VMB54wM+D9XUHGH6e17CihjImF42/D+kVFHDAIfj3B2+KfiD7WNXVINRhLSdCcHtBVgDD1EWuYkDVskcB7CFbALxN3X2NZz6q6s6rIPzLBTs3XGB1/vyWziSFVVasFm/xaFkY6+IutUg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40e3488e33bso5111235e9.3 for ; Thu, 04 Jan 2024 07:38:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1704382685; x=1704987485; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Ixjz6rVs4LDP6TnuKw2icgT4HBJsg0mUnC0LzS97dGI=; b=YhxOJ81P8xMI6ulk0kTJSuriL5uatRc/PJzezou3GfNoZUpeYan3TJRxxnvqQXam56 G+zzo3mpryQxUVEKzV5j03zSlvUKQeuWLW0uIdf5LZDpMDYtEr4lJTO0uTtplfcn1aRY aDeo8FbLq0twg4f+2uBo9U1lPtLQbOL4wVCmV6xCSlSqm69fCnh7KEdN2ZbNd+dqSWbl Y15D2OjHToAeyZ5SoryVWTIbL+emDoqIUC0QBusQBYoS+Y4l86/WgY00hlUd8rt+/3ae Q8q64qYTHY55hYP3MSPlxgDRDhusJVqzoDPTODspSj8hxZjodAdGI6VBzVMdxEX15hk9 e9SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704382685; x=1704987485; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ixjz6rVs4LDP6TnuKw2icgT4HBJsg0mUnC0LzS97dGI=; b=Pgs2iyVpoJxfvigkHag7cNbpsJvpuFtclHl5rmFbihxYGo2utdgmlWGlJXNOUUn4WD zM7wjI199ujaOHrBFKID5dd5rgeJQKsbZxTDJ+t6m24+lrKVXd08zn74UGmtalPOtnF0 KIg11OnoE4FQ3nzfEgJ6QW07uNtTGkLDKlz3SX7HhBD9cd5HVahTnJ0INxaofoc7eyd5 mFT+QBLoARNbO10KRfb8dgBllOHMPxQCSiGrcYWOqbqVvgcKA685suzxtIzC6TQjlz/E uT+MQudW/uShSRcOKD7/1g7oe3FlhAN7ZaKtD+LNAQJYGOKyWQt054Y3mfNG5uOuUPX3 Qqkw== X-Gm-Message-State: AOJu0YxO2NEJs+0tdKHH74BUn41mJCpWkDAC6f56Y5JnFHkcUsMxfX/Q iyRBxt1Ae6zeyR0JpFb6R8rV8J8T0MuD X-Google-Smtp-Source: AGHT+IF/oNF3LtrBAoxjaz+QLhIY4N+rtPviJJPK92OjR8GddrIVojr3ZYL6wWc/LsT6cZhfJW6MdQ== X-Received: by 2002:a05:600c:a2a2:b0:40d:86e3:e699 with SMTP id hu34-20020a05600ca2a200b0040d86e3e699mr320818wmb.219.1704382685007; Thu, 04 Jan 2024 07:38:05 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id p4-20020a056000018400b0033753a61e96sm1499244wrx.108.2024.01.04.07.38.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 07:38:04 -0800 (PST) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Raiki Tamura Subject: [COMMITTED] libcpp: add function to check XID properties Date: Thu, 4 Jan 2024 16:33:53 +0100 Message-ID: <20240104153735.2356348-2-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Raiki Tamura This commit adds a new function intended for checking the XID properties of a possibly unicode character, as well as the accompanying enum describing the possible properties. libcpp/ChangeLog: * charset.cc (cpp_check_xid_property): New. * include/cpplib.h (cpp_check_xid_property): New. (enum cpp_xid_property): New. Signed-off-by: Raiki Tamura --- libcpp/charset.cc | 36 ++++++++++++++++++++++++++++++++++++ libcpp/include/cpplib.h | 7 +++++++ 2 files changed, 43 insertions(+) diff --git a/libcpp/charset.cc b/libcpp/charset.cc index 95ca381eb7b..54d7b9e0932 100644 --- a/libcpp/charset.cc +++ b/libcpp/charset.cc @@ -1332,6 +1332,42 @@ _cpp_uname2c_uax44_lm2 (const char *name, size_t len, char *canon_name) return result; } +/* Returns flags representing the XID properties of the given codepoint. */ +unsigned int +cpp_check_xid_property (cppchar_t c) +{ + // fast path for ASCII + if (c < 0x80) + { + if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')) + return CPP_XID_START | CPP_XID_CONTINUE; + if (('0' <= c && c <= '9') || c == '_') + return CPP_XID_CONTINUE; + } + + if (c > UCS_LIMIT) + return 0; + + int mn, mx, md; + mn = 0; + mx = ARRAY_SIZE (ucnranges) - 1; + while (mx != mn) + { + md = (mn + mx) / 2; + if (c <= ucnranges[md].end) + mx = md; + else + mn = md + 1; + } + + unsigned short flags = ucnranges[mn].flags; + + if (flags & CXX23) + return CPP_XID_START | CPP_XID_CONTINUE; + if (flags & NXX23) + return CPP_XID_CONTINUE; + return 0; +} /* Returns 1 if C is valid in an identifier, 2 if C is valid except at the start of an identifier, and 0 if C is not valid in an diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index f699daaeb64..5746aac9ea4 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -1631,4 +1631,11 @@ bool cpp_valid_utf8_p (const char *data, size_t num_bytes); bool cpp_is_combining_char (cppchar_t c); bool cpp_is_printable_char (cppchar_t c); +enum cpp_xid_property { + CPP_XID_START = 1, + CPP_XID_CONTINUE = 2 +}; + +unsigned int cpp_check_xid_property (cppchar_t c); + #endif /* ! LIBCPP_CPPLIB_H */ -- 2.42.1 P.S.: Note that the requested formatting changes have been adressed - I'm not sure why the patch is formatted this way. Best, Arthur