Skip to content

[libc] Add ctype.h locale variants #102711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions libc/config/gpu/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,35 @@ set(TARGET_LIBC_ENTRYPOINTS

# ctype.h entrypoints
libc.src.ctype.isalnum
libc.src.ctype.isalnum_l
libc.src.ctype.isalpha
libc.src.ctype.isalpha_l
libc.src.ctype.isascii
libc.src.ctype.isblank
libc.src.ctype.isblank_l
libc.src.ctype.iscntrl
libc.src.ctype.iscntrl_l
libc.src.ctype.isdigit
libc.src.ctype.isdigit_l
libc.src.ctype.isgraph
libc.src.ctype.isgraph_l
libc.src.ctype.islower
libc.src.ctype.islower_l
libc.src.ctype.isprint
libc.src.ctype.isprint_l
libc.src.ctype.ispunct
libc.src.ctype.ispunct_l
libc.src.ctype.isspace
libc.src.ctype.isspace_l
libc.src.ctype.isupper
libc.src.ctype.isupper_l
libc.src.ctype.isxdigit
libc.src.ctype.isxdigit_l
libc.src.ctype.toascii
libc.src.ctype.tolower
libc.src.ctype.tolower_l
libc.src.ctype.toupper
libc.src.ctype.toupper_l

# string.h entrypoints
libc.src.string.bcmp
Expand Down Expand Up @@ -231,6 +245,15 @@ set(TARGET_LIBC_ENTRYPOINTS
# wchar.h entrypoints
libc.src.wchar.wctob

# locale.h entrypoints
libc.src.locale.localeconv
libc.src.locale.duplocale
libc.src.locale.freelocale
libc.src.locale.localeconv
libc.src.locale.newlocale
libc.src.locale.setlocale
libc.src.locale.uselocale

# gpu/rpc.h entrypoints
libc.src.gpu.rpc_host_call
)
Expand Down
1 change: 1 addition & 0 deletions libc/config/gpu/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.wchar
libc.include.uchar
libc.include.features
libc.include.locale

# Header for RPC extensions
libc.include.gpu_rpc
Expand Down
25 changes: 25 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,22 @@ endif()

if(LLVM_LIBC_FULL_BUILD)
list(APPEND TARGET_LIBC_ENTRYPOINTS
# ctype.h entrypoints
libc.src.ctype.isalnum_l
libc.src.ctype.isalpha_l
libc.src.ctype.isblank_l
libc.src.ctype.iscntrl_l
libc.src.ctype.isdigit_l
libc.src.ctype.isgraph_l
libc.src.ctype.islower_l
libc.src.ctype.isprint_l
libc.src.ctype.ispunct_l
libc.src.ctype.isspace_l
libc.src.ctype.isupper_l
libc.src.ctype.isxdigit_l
libc.src.ctype.tolower_l
libc.src.ctype.toupper_l

# assert.h entrypoints
libc.src.assert.__assert_fail

Expand Down Expand Up @@ -982,6 +998,15 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.time.nanosleep
libc.src.time.time

# locale.h entrypoints
libc.src.locale.localeconv
libc.src.locale.duplocale
libc.src.locale.freelocale
libc.src.locale.localeconv
libc.src.locale.newlocale
libc.src.locale.setlocale
libc.src.locale.uselocale

# unistd.h entrypoints
libc.src.unistd.__llvm_libc_syscall
libc.src.unistd._exit
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.unistd
libc.include.wchar
libc.include.uchar
libc.include.locale

libc.include.arpa_inet

Expand Down
9 changes: 9 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,12 @@ add_proxy_header_library(
libc.include.llvm-libc-types.cookie_io_functions_t
libc.include.stdio
)

add_proxy_header_library(
locale_t
HDRS
locale_t.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.locale_t
libc.include.locale
)
22 changes: 22 additions & 0 deletions libc/hdr/types/locale_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from locale_t.h ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_LOCALE_T_H
#define LLVM_LIBC_HDR_LOCALE_T_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/locale_t.h"

#else // overlay mode

#error "type not available in overlay mode"

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_LOCALE_T_H
13 changes: 13 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ add_header_macro(
ctype.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.locale_t
)

add_header_macro(
Expand Down Expand Up @@ -717,6 +718,18 @@ add_header_macro(
.llvm-libc-types.wchar_t
)

add_header_macro(
locale
../libc/newhdrgen/yaml/locale.yaml
locale.h.def
locale.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-macros.locale_macros
.llvm-libc-types.locale_t
.llvm-libc-types.struct_lconv
)

if(LIBC_TARGET_OS_IS_GPU)
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/gpu)

Expand Down
6 changes: 6 additions & 0 deletions libc/include/llvm-libc-macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,9 @@ add_macro_header(
HDR
elf-macros.h
)

add_macro_header(
locale_macros
HDR
locale-macros.h
)
32 changes: 32 additions & 0 deletions libc/include/llvm-libc-macros/locale-macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===-- Definition of macros from locale.h --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_MACROS_LOCALE_MACROS_H
#define LLVM_LIBC_MACROS_LOCALE_MACROS_H

#include "../llvm-libc-types/locale_t.h"

#define LC_CTYPE 0
#define LC_NUMERIC 1
#define LC_TIME 2
#define LC_COLLATE 3
#define LC_MONETARY 4
#define LC_MESSAGES 5
#define LC_ALL 6

#define LC_GLOBAL_LOCALE ((locale_t)(-1))

#define LC_CTYPE_MASK (1 << LC_CTYPE)
#define LC_NUMERIC_MASK (1 << LC_NUMERIC)
#define LC_TIME_MASK (1 << LC_TIME)
#define LC_COLLATE_MASK (1 << LC_COLLATE)
#define LC_MONETARY_MASK (1 << LC_MONETARY)
#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
#define LC_ALL_MASK 0x7fffffff

#endif // LLVM_LIBC_MACROS_LOCALE_MACROS_H
2 changes: 2 additions & 0 deletions libc/include/llvm-libc-types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,5 @@ DEPENDS
.fsblkcnt_t
.fsfilcnt_t
)
add_header(locale_t HDR locale_t.h)
add_header(struct_lconv HDR struct_lconv.h)
22 changes: 22 additions & 0 deletions libc/include/llvm-libc-types/locale_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of type locale_t ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_TYPES_LOCALE_T_H
#define LLVM_LIBC_TYPES_LOCALE_T_H

#define NUM_LOCALE_CATEGORIES 6

struct __locale_data;

struct __locale_t {
struct __locale_data *data[NUM_LOCALE_CATEGORIES];
};

typedef struct __locale_t *locale_t;

#endif // LLVM_LIBC_TYPES_LOCALE_T_H
39 changes: 39 additions & 0 deletions libc/include/llvm-libc-types/struct_lconv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===-- Definition of type lconv ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_TYPES_LCONV_H
#define LLVM_LIBC_TYPES_LCONV_H

struct lconv {
char *decimal_point;
char *thousands_sep;
char *grouping;
char *mon_decimal_point;
char *mon_thousands_sep;
char *mon_grouping;
char *positive_sign;
char *negative_sign;
char *currency_symbol;
char frac_digits;
char p_cs_precedes;
char n_cs_precedes;
char p_sep_by_space;
char n_sep_by_space;
char p_sign_posn;
char n_sign_posn;
char *int_curr_symbol;
char int_frac_digits;
char int_p_cs_precedes;
char int_n_cs_precedes;
char int_p_sep_by_space;
char int_n_sep_by_space;
char int_p_sign_posn;
char int_n_sign_posn;
};

#endif // LLVM_LIBC_TYPES_LCONV_H
20 changes: 20 additions & 0 deletions libc/include/locale.h.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- C standard library header locale.h --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_LOCALE_H
#define LLVM_LIBC_LOCALE_H

#include "__llvm-libc-common.h"

#include "llvm-libc-macros/locale-macros.h"
#include "llvm-libc-types/locale_t.h"
#include "llvm-libc-types/struct_lconv.h"

%%public_api()

#endif // LLVM_LIBC_LOCALE_H
Loading
Loading