Skip to content
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
3 changes: 3 additions & 0 deletions libc/config/baremetal/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.wchar.wcslen
libc.src.wchar.wctob

# wctype.h entrypoints
libc.src.wctype.iswalpha

# internal entrypoints
libc.startup.baremetal.init
libc.startup.baremetal.fini
Expand Down
1 change: 1 addition & 0 deletions libc/config/baremetal/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.time
libc.include.uchar
libc.include.wchar
libc.include.wctype
)
3 changes: 3 additions & 0 deletions libc/config/baremetal/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.wchar.wcslen
libc.src.wchar.wctob

# wctype.h entrypoints
libc.src.wctype.iswalpha

# internal entrypoints
libc.startup.baremetal.init
libc.startup.baremetal.fini
Expand Down
1 change: 1 addition & 0 deletions libc/config/baremetal/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.time
libc.include.uchar
libc.include.wchar
libc.include.wctype
)
3 changes: 3 additions & 0 deletions libc/config/darwin/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib.calloc
libc.src.stdlib.realloc
libc.src.stdlib.free

# wctype.h entrypoints
libc.src.wctype.iswalpha
)

if(LLVM_LIBC_FULL_BUILD)
Expand Down
1 change: 1 addition & 0 deletions libc/config/darwin/aarch64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.stdlib
libc.include.string
libc.include.strings
libc.include.wctype
)
3 changes: 3 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.wchar.wcslen
libc.src.wchar.wctob

# wctype.h entrypoints
libc.src.wctype.iswalpha

# sys/uio.h entrypoints
libc.src.sys.uio.writev
libc.src.sys.uio.readv
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.uchar
libc.include.unistd
libc.include.wchar
libc.include.wctype
)
3 changes: 3 additions & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ set(TARGET_LIBC_ENTRYPOINTS
# sys/time.h entrypoints
libc.src.sys.time.setitimer
libc.src.sys.time.getitimer

# wctype.h entrypoints
libc.src.wctype.iswalpha
)

if(LLVM_LIBC_FULL_BUILD)
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.strings
libc.include.uchar
libc.include.wchar
libc.include.wctype

# Disabled due to epoll_wait syscalls not being available on this platform.
# libc.include.sys_epoll
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.wchar.wcslen
libc.src.wchar.wctob

# wctype.h entrypoints
libc.src.wctype.iswalpha

# sys/uio.h entrypoints
libc.src.sys.uio.writev
libc.src.sys.uio.readv
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.uchar
libc.include.unistd
libc.include.wchar
libc.include.wctype
)
2 changes: 2 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.wchar.wcstoul
libc.src.wchar.wcstoull

# wctype.h entrypoints
libc.src.wctype.iswalpha

# sys/uio.h entrypoints
libc.src.sys.uio.writev
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 @@ -57,4 +57,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.uchar
libc.include.unistd
libc.include.wchar
libc.include.wctype
)
3 changes: 3 additions & 0 deletions libc/config/windows/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ set(TARGET_LIBC_ENTRYPOINTS

# unistd.h entrypoints
libc.src.unistd.getentropy

# wctype.h entrypoints
libc.src.wctype.iswalpha
)

set(TARGET_LIBM_ENTRYPOINTS
Expand Down
1 change: 1 addition & 0 deletions libc/config/windows/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.fenv
libc.include.math
libc.include.unistd
libc.include.wctype
)
9 changes: 9 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,15 @@ add_header_macro(
.llvm-libc-types.wchar_t
)

add_header_macro(
wctype
../libc/include/wctype.yaml
wctype.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.wint_t
)

add_header_macro(
locale
../libc/include/locale.yaml
Expand Down
10 changes: 10 additions & 0 deletions libc/include/wctype.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
header: wctype.h
types:
- type_name: wint_t
functions:
- name: iswalpha
standards:
- stdc
return_type: int
arguments:
- type: wint_t
1 change: 1 addition & 0 deletions libc/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_subdirectory(strings)
add_subdirectory(time)
add_subdirectory(unistd)
add_subdirectory(wchar)
add_subdirectory(wctype)

if(${LIBC_TARGET_OS} STREQUAL "linux")
add_subdirectory(dirent)
Expand Down
9 changes: 9 additions & 0 deletions libc/src/wctype/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_entrypoint_object(
iswalpha
SRCS
iswalpha.cpp
HDRS
iswalpha.h
DEPENDS
libc.src.__support.wctype_utils
)
19 changes: 19 additions & 0 deletions libc/src/wctype/iswalpha.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of iswalpha ----------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "src/wctype/iswalpha.h"
#include "src/__support/common.h"
#include "src/__support/wctype_utils.h"

#include "hdr/types/wint_t.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(bool, iswalpha, (wint_t c)) { return internal::iswalpha(c); }

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/wctype/iswalpha.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for iswalpha ----------------------*- C++ -*-===//
//
// 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_SRC_WCTYPE_ISWALPHA_H
#define LLVM_LIBC_SRC_WCTYPE_ISWALPHA_H

#include "hdr/types/wint_t.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE_DECL {

bool iswalpha(wint_t c);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_WCTYPE_ISWALPHA_H
1 change: 1 addition & 0 deletions libc/test/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ add_subdirectory(stdlib)
add_subdirectory(string)
add_subdirectory(strings)
add_subdirectory(wchar)
add_subdirectory(wctype)
add_subdirectory(time)
add_subdirectory(unistd)

Expand Down
11 changes: 11 additions & 0 deletions libc/test/src/wctype/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_custom_target(libc_wctype_unittests)

add_libc_test(
iswalpha_test
SUITE
libc_wctype_unittests
SRCS
iswalpha_test.cpp
DEPENDS
libc.src.wctype.iswalpha
)
54 changes: 54 additions & 0 deletions libc/test/src/wctype/iswalpha_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//===-- Unittests for iswalpha --------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "src/__support/CPP/span.h"
#include "src/wctype/iswalpha.h"

#include "test/UnitTest/LibcTest.h"
#include "test/UnitTest/Test.h"

namespace {

// TODO: Merge the wctype tests using this framework.
constexpr char WALPHA_ARRAY[] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
};

bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) {
for (size_t i = 0; i < arr.size(); ++i)
if (static_cast<int>(arr[i]) == ch)
return true;
return false;
}

} // namespace

TEST(LlvmLibciswalpha, SimpleTest) {
EXPECT_TRUE(LIBC_NAMESPACE::iswalpha('a'));
EXPECT_TRUE(LIBC_NAMESPACE::iswalpha('B'));

EXPECT_FALSE(LIBC_NAMESPACE::iswalpha('3'));
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(' '));
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha('?'));
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha('\0'));
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(-1));
}

TEST(LlvmLibciswalpha, DefaultLocale) {
// Loops through all characters, verifying that letters return
// true and everything else returns false.
for (int ch = -255; ch < 255; ++ch) {
if (in_span(ch, WALPHA_ARRAY))
EXPECT_TRUE(LIBC_NAMESPACE::iswalpha(ch));
else
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(ch));
}
}
Loading