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
2 changes: 2 additions & 0 deletions packages/cxx-frontend/src/TokenKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ export enum TokenKind {
__FLOAT80,
__IMAG__,
__INT128,
__INT128_T,
__INT64,
__REAL__,
__RESTRICT__,
__THREAD,
__UINT128_T,
__UNDERLYING_TYPE,
ALIGNAS,
ALIGNOF,
Expand Down
6 changes: 5 additions & 1 deletion packages/cxx-gen-ast/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export const CXX_KEYWORDS: string[] = [
"volatile",
"wchar_t",
"while",

"__attribute__",
"__builtin_bit_cast",
"__builtin_offsetof",
Expand All @@ -186,11 +187,13 @@ export const CXX_KEYWORDS: string[] = [
"__float128",
"__float80",
"__imag__",
"__int128_t",
"__int128",
"__int64",
"__real__",
"__restrict__",
"__thread",
"__uint128_t",
"__underlying_type",
"_Atomic",
"_Complex",
Expand Down Expand Up @@ -344,12 +347,13 @@ export const C_KEYWORDS: string[] = [
"__float128",
"__float80",
"__imag__",
"__int128_t",
"__int128",
"__int64",
"__real__",
"__thread",
"__uint128_t",
"__underlying_type",
"_Atomic",
"_Complex",
];

Expand Down
77 changes: 51 additions & 26 deletions src/lib/cxx/include/stddef.h
Original file line number Diff line number Diff line change
@@ -1,36 +1,76 @@
#if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \
!defined(__need_wchar_t) && !defined(__need_NULL) && \
!defined(__need_STDDEF_H_misc)
#if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \
!defined(__need_wchar_t) && !defined(__need_NULL) && \
!defined(__need_rsize_t) && !defined(__need_nullptr_t) && \
!defined(__need_max_align_t) && !defined(__need_offsetof) && \
!defined(__need_wint_t)
#define __need_ptrdiff_t
#define __need_size_t
#define __need_wchar_t
#define __need_offsetof
#define __need_max_align_t

#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
#define __need_rsize_t
#endif

#if !defined(__STDDEF_H)
#define __need_NULL
#define __need_STDDEF_H_misc
#endif

#endif /* no needs */

#ifdef __need_ptrdiff_t
#undef __need_ptrdiff_t
typedef long int ptrdiff_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
#endif /* __need_ptrdiff_t */

#ifdef __need_size_t
#undef __need_size_t
typedef long unsigned int size_t;
typedef __SIZE_TYPE__ size_t;
#endif /* __need_size_t */

#ifdef __need_rsize_t
#undef __need_rsize_t
typedef __SIZE_TYPE__ rsize_t;
#endif /* __need_size_t */

#ifdef __need_ptrdiff_t
#undef __need_ptrdiff_t
typedef __PTRDIFF_TYPE__ ptrdiff_t;
#endif /* __need_ptrdiff_t */

#ifdef __need_wchar_t
#undef __need_wchar_t
#ifndef __cplusplus
#if !defined(_WCHAR_T)
#define _WCHAR_T
typedef __WCHAR_TYPE__ wchar_t;
#endif /* _WCHAR_T */
#endif /* __cplusplus */
#endif /* __need_wchar_t */

#ifdef __need_NULL
#undef __need_NULL
#undef NULL
#if !defined(NULL)
#define NULL 0
#endif /* NULL */
#endif /* __need_NULL */

#ifdef __need_STDDEF_H_misc
#undef __need_STDDEF_H_misc
typedef long unsigned int rsize_t;
#ifdef __need_wint_t
#undef __need_wint_t
typedef __WINT_TYPE__ wint_t;
#endif /* __need_wint_t */

#ifdef __need_offsetof
#undef __need_offsetof
#if !defined(offsetof)
#define offsetof(t, d) __builtin_offsetof(t, d)
#endif

#endif /* __need_offsetof */

#ifdef __need_max_align_t
#undef __need_max_align_t

typedef struct {
long long __clang_max_align_nonce1
Expand All @@ -40,19 +80,4 @@ typedef struct {
__attribute__((__aligned__(__alignof__(long double))));
} max_align_t;

#endif /* __need_STDDEF_H_misc */

#ifdef __need_wint_t
#undef __need_wint_t

#ifdef __WINT_TYPE__
typedef __WINT_TYPE__ wint_t;
#else
typedef int wint_t;
#endif

#endif /* __need_wint_t */

#if !defined(offsetof)
#define offsetof(t, d) __builtin_offsetof(t, d)
#endif
#endif /* __need_max_align_t */
8 changes: 8 additions & 0 deletions src/parser/cxx/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ struct Control::Private {
IntType intType;
LongIntType longIntType;
LongLongIntType longLongIntType;
Int128Type int128Type;
UnsignedCharType unsignedCharType;
UnsignedShortIntType unsignedShortIntType;
UnsignedIntType unsignedIntType;
UnsignedLongIntType unsignedLongIntType;
UnsignedLongLongIntType unsignedLongLongIntType;
UnsignedInt128Type unsignedInt128Type;
CharType charType;
Char8Type char8Type;
Char16Type char16Type;
Expand Down Expand Up @@ -302,6 +304,8 @@ auto Control::getLongLongIntType() -> const LongLongIntType* {
return &d->longLongIntType;
}

auto Control::getInt128Type() -> const Int128Type* { return &d->int128Type; }

auto Control::getUnsignedCharType() -> const UnsignedCharType* {
return &d->unsignedCharType;
}
Expand All @@ -322,6 +326,10 @@ auto Control::getUnsignedLongLongIntType() -> const UnsignedLongLongIntType* {
return &d->unsignedLongLongIntType;
}

auto Control::getUnsignedInt128Type() -> const UnsignedInt128Type* {
return &d->unsignedInt128Type;
}

auto Control::getCharType() -> const CharType* { return &d->charType; }

auto Control::getChar8Type() -> const Char8Type* { return &d->char8Type; }
Expand Down
2 changes: 2 additions & 0 deletions src/parser/cxx/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ class Control {
[[nodiscard]] auto getIntType() -> const IntType*;
[[nodiscard]] auto getLongIntType() -> const LongIntType*;
[[nodiscard]] auto getLongLongIntType() -> const LongLongIntType*;
[[nodiscard]] auto getInt128Type() -> const Int128Type*;
[[nodiscard]] auto getUnsignedCharType() -> const UnsignedCharType*;
[[nodiscard]] auto getUnsignedShortIntType() -> const UnsignedShortIntType*;
[[nodiscard]] auto getUnsignedIntType() -> const UnsignedIntType*;
[[nodiscard]] auto getUnsignedLongIntType() -> const UnsignedLongIntType*;
[[nodiscard]] auto getUnsignedLongLongIntType()
-> const UnsignedLongLongIntType*;
[[nodiscard]] auto getUnsignedInt128Type() -> const UnsignedInt128Type*;
[[nodiscard]] auto getCharType() -> const CharType*;
[[nodiscard]] auto getChar8Type() -> const Char8Type*;
[[nodiscard]] auto getChar16Type() -> const Char16Type*;
Expand Down
11 changes: 10 additions & 1 deletion src/parser/cxx/decl_specs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@ void DeclSpecs::Visitor::operator()(IntegralTypeSpecifierAST* ast) {
// ### todo
break;

case TokenKind::T___INT128_T:
case TokenKind::T___INT128:
// ### todo
specs.type_ = control()->getInt128Type();
break;

case TokenKind::T___UINT128_T:
specs.type_ = control()->getUnsignedInt128Type();
break;

default:
Expand Down Expand Up @@ -401,6 +406,10 @@ void DeclSpecs::finish() {
type_ = control()->getIntType();
}

if (type_ == control()->getInt128Type() && isUnsigned) {
type_ = control()->getUnsignedInt128Type();
}

if (!type_) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/parser/cxx/external_name_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct ExternalNameEncoder::TypeVisitor {

void operator()(const LongLongIntType* type) { encoder.out("x"); }

void operator()(const Int128Type* type) { encoder.out("n"); }

void operator()(const UnsignedCharType* type) { encoder.out("h"); }

void operator()(const UnsignedShortIntType* type) { encoder.out("t"); }
Expand All @@ -76,6 +78,8 @@ struct ExternalNameEncoder::TypeVisitor {

void operator()(const UnsignedLongLongIntType* type) { encoder.out("y"); }

void operator()(const UnsignedInt128Type* type) { encoder.out("o"); }

void operator()(const CharType* type) { encoder.out("c"); }

void operator()(const Char8Type* type) { encoder.out("Du"); }
Expand Down
9 changes: 9 additions & 0 deletions src/parser/cxx/memory_layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ struct SizeOf {
return memoryLayout.sizeOfLongLong();
}

auto operator()(const Int128Type*) const -> std::optional<std::size_t> {
return 16;
}

auto operator()(const UnsignedCharType* type) const
-> std::optional<std::size_t> {
return 1;
Expand All @@ -105,6 +109,11 @@ struct SizeOf {
return memoryLayout.sizeOfLongLong();
}

auto operator()(const UnsignedInt128Type*) const
-> std::optional<std::size_t> {
return 16;
}

auto operator()(const CharType* type) const -> std::optional<std::size_t> {
return 1;
}
Expand Down
2 changes: 2 additions & 0 deletions src/parser/cxx/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5046,6 +5046,8 @@ auto Parser::parse_primitive_type_specifier(SpecifierAST*& yyast,
case TokenKind::T_INT:
case TokenKind::T___INT64:
case TokenKind::T___INT128:
case TokenKind::T___INT128_T:
case TokenKind::T___UINT128_T:
makeIntegralTypeSpecifier();
specs.accept(yyast);
return true;
Expand Down
58 changes: 44 additions & 14 deletions src/parser/cxx/private/c_keywords-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -785,25 +785,21 @@ static inline auto classifyC10(const char* s) -> cxx::TokenKind {
}
}
}
} else if (s[2] == 'd') {
if (s[3] == 'e') {
if (s[4] == 'c') {
if (s[5] == 'l') {
if (s[6] == 't') {
if (s[7] == 'y') {
if (s[8] == 'p') {
if (s[9] == 'e') {
return cxx::TokenKind::T___DECLTYPE;
} else if (s[2] == 'i') {
if (s[3] == 'n') {
if (s[4] == 't') {
if (s[5] == '1') {
if (s[6] == '2') {
if (s[7] == '8') {
if (s[8] == '_') {
if (s[9] == 't') {
return cxx::TokenKind::T___INT128_T;
}
}
}
}
}
}
}
} else if (s[2] == 'i') {
if (s[3] == 'n') {
if (s[4] == 'l') {
} else if (s[4] == 'l') {
if (s[5] == 'i') {
if (s[6] == 'n') {
if (s[7] == 'e') {
Expand All @@ -817,6 +813,22 @@ static inline auto classifyC10(const char* s) -> cxx::TokenKind {
}
}
}
} else if (s[2] == 'd') {
if (s[3] == 'e') {
if (s[4] == 'c') {
if (s[5] == 'l') {
if (s[6] == 't') {
if (s[7] == 'y') {
if (s[8] == 'p') {
if (s[9] == 'e') {
return cxx::TokenKind::T___DECLTYPE;
}
}
}
}
}
}
}
} else if (s[2] == 'r') {
if (s[3] == 'e') {
if (s[4] == 's') {
Expand Down Expand Up @@ -912,6 +924,24 @@ static inline auto classifyC11(const char* s) -> cxx::TokenKind {
}
}
}
} else if (s[2] == 'u') {
if (s[3] == 'i') {
if (s[4] == 'n') {
if (s[5] == 't') {
if (s[6] == '1') {
if (s[7] == '2') {
if (s[8] == '8') {
if (s[9] == '_') {
if (s[10] == 't') {
return cxx::TokenKind::T___UINT128_T;
}
}
}
}
}
}
}
}
} else if (s[2] == 'a') {
if (s[3] == 'l') {
if (s[4] == 'i') {
Expand Down
Loading