Skip to content

Commit a7eb834

Browse files
committed
Add __int128_t and __uint128_t types
Signed-off-by: Roberto Raggi <[email protected]>
1 parent d518640 commit a7eb834

File tree

16 files changed

+173
-30
lines changed

16 files changed

+173
-30
lines changed

packages/cxx-frontend/src/TokenKind.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ export enum TokenKind {
108108
__FLOAT80,
109109
__IMAG__,
110110
__INT128,
111+
__INT128_T,
111112
__INT64,
112113
__REAL__,
113114
__RESTRICT__,
114115
__THREAD,
116+
__UINT128_T,
115117
__UNDERLYING_TYPE,
116118
ALIGNAS,
117119
ALIGNOF,

packages/cxx-gen-ast/src/tokens.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export const CXX_KEYWORDS: string[] = [
176176
"volatile",
177177
"wchar_t",
178178
"while",
179+
179180
"__attribute__",
180181
"__builtin_bit_cast",
181182
"__builtin_offsetof",
@@ -186,11 +187,13 @@ export const CXX_KEYWORDS: string[] = [
186187
"__float128",
187188
"__float80",
188189
"__imag__",
190+
"__int128_t",
189191
"__int128",
190192
"__int64",
191193
"__real__",
192194
"__restrict__",
193195
"__thread",
196+
"__uint128_t",
194197
"__underlying_type",
195198
"_Atomic",
196199
"_Complex",
@@ -344,12 +347,13 @@ export const C_KEYWORDS: string[] = [
344347
"__float128",
345348
"__float80",
346349
"__imag__",
350+
"__int128_t",
347351
"__int128",
348352
"__int64",
349353
"__real__",
350354
"__thread",
355+
"__uint128_t",
351356
"__underlying_type",
352-
"_Atomic",
353357
"_Complex",
354358
];
355359

src/parser/cxx/control.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ struct Control::Private {
9090
IntType intType;
9191
LongIntType longIntType;
9292
LongLongIntType longLongIntType;
93+
Int128Type int128Type;
9394
UnsignedCharType unsignedCharType;
9495
UnsignedShortIntType unsignedShortIntType;
9596
UnsignedIntType unsignedIntType;
9697
UnsignedLongIntType unsignedLongIntType;
9798
UnsignedLongLongIntType unsignedLongLongIntType;
99+
UnsignedInt128Type unsignedInt128Type;
98100
CharType charType;
99101
Char8Type char8Type;
100102
Char16Type char16Type;
@@ -302,6 +304,8 @@ auto Control::getLongLongIntType() -> const LongLongIntType* {
302304
return &d->longLongIntType;
303305
}
304306

307+
auto Control::getInt128Type() -> const Int128Type* { return &d->int128Type; }
308+
305309
auto Control::getUnsignedCharType() -> const UnsignedCharType* {
306310
return &d->unsignedCharType;
307311
}
@@ -322,6 +326,10 @@ auto Control::getUnsignedLongLongIntType() -> const UnsignedLongLongIntType* {
322326
return &d->unsignedLongLongIntType;
323327
}
324328

329+
auto Control::getUnsignedInt128Type() -> const UnsignedInt128Type* {
330+
return &d->unsignedInt128Type;
331+
}
332+
325333
auto Control::getCharType() -> const CharType* { return &d->charType; }
326334

327335
auto Control::getChar8Type() -> const Char8Type* { return &d->char8Type; }

src/parser/cxx/control.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ class Control {
8888
[[nodiscard]] auto getIntType() -> const IntType*;
8989
[[nodiscard]] auto getLongIntType() -> const LongIntType*;
9090
[[nodiscard]] auto getLongLongIntType() -> const LongLongIntType*;
91+
[[nodiscard]] auto getInt128Type() -> const Int128Type*;
9192
[[nodiscard]] auto getUnsignedCharType() -> const UnsignedCharType*;
9293
[[nodiscard]] auto getUnsignedShortIntType() -> const UnsignedShortIntType*;
9394
[[nodiscard]] auto getUnsignedIntType() -> const UnsignedIntType*;
9495
[[nodiscard]] auto getUnsignedLongIntType() -> const UnsignedLongIntType*;
9596
[[nodiscard]] auto getUnsignedLongLongIntType()
9697
-> const UnsignedLongLongIntType*;
98+
[[nodiscard]] auto getUnsignedInt128Type() -> const UnsignedInt128Type*;
9799
[[nodiscard]] auto getCharType() -> const CharType*;
98100
[[nodiscard]] auto getChar8Type() -> const Char8Type*;
99101
[[nodiscard]] auto getChar16Type() -> const Char16Type*;

src/parser/cxx/decl_specs.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,13 @@ void DeclSpecs::Visitor::operator()(IntegralTypeSpecifierAST* ast) {
222222
// ### todo
223223
break;
224224

225+
case TokenKind::T___INT128_T:
225226
case TokenKind::T___INT128:
226-
// ### todo
227+
specs.type_ = control()->getInt128Type();
228+
break;
229+
230+
case TokenKind::T___UINT128_T:
231+
specs.type_ = control()->getUnsignedInt128Type();
227232
break;
228233

229234
default:
@@ -401,6 +406,10 @@ void DeclSpecs::finish() {
401406
type_ = control()->getIntType();
402407
}
403408

409+
if (type_ == control()->getInt128Type() && isUnsigned) {
410+
type_ = control()->getUnsignedInt128Type();
411+
}
412+
404413
if (!type_) {
405414
return;
406415
}

src/parser/cxx/external_name_encoder.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ struct ExternalNameEncoder::TypeVisitor {
6666

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

69+
void operator()(const Int128Type* type) { encoder.out("n"); }
70+
6971
void operator()(const UnsignedCharType* type) { encoder.out("h"); }
7072

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

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

81+
void operator()(const UnsignedInt128Type* type) { encoder.out("o"); }
82+
7983
void operator()(const CharType* type) { encoder.out("c"); }
8084

8185
void operator()(const Char8Type* type) { encoder.out("Du"); }

src/parser/cxx/memory_layout.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ struct SizeOf {
8080
return memoryLayout.sizeOfLongLong();
8181
}
8282

83+
auto operator()(const Int128Type*) const -> std::optional<std::size_t> {
84+
return 16;
85+
}
86+
8387
auto operator()(const UnsignedCharType* type) const
8488
-> std::optional<std::size_t> {
8589
return 1;
@@ -105,6 +109,11 @@ struct SizeOf {
105109
return memoryLayout.sizeOfLongLong();
106110
}
107111

112+
auto operator()(const UnsignedInt128Type*) const
113+
-> std::optional<std::size_t> {
114+
return 16;
115+
}
116+
108117
auto operator()(const CharType* type) const -> std::optional<std::size_t> {
109118
return 1;
110119
}

src/parser/cxx/parser.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5046,6 +5046,8 @@ auto Parser::parse_primitive_type_specifier(SpecifierAST*& yyast,
50465046
case TokenKind::T_INT:
50475047
case TokenKind::T___INT64:
50485048
case TokenKind::T___INT128:
5049+
case TokenKind::T___INT128_T:
5050+
case TokenKind::T___UINT128_T:
50495051
makeIntegralTypeSpecifier();
50505052
specs.accept(yyast);
50515053
return true;

src/parser/cxx/private/c_keywords-priv.h

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -785,25 +785,21 @@ static inline auto classifyC10(const char* s) -> cxx::TokenKind {
785785
}
786786
}
787787
}
788-
} else if (s[2] == 'd') {
789-
if (s[3] == 'e') {
790-
if (s[4] == 'c') {
791-
if (s[5] == 'l') {
792-
if (s[6] == 't') {
793-
if (s[7] == 'y') {
794-
if (s[8] == 'p') {
795-
if (s[9] == 'e') {
796-
return cxx::TokenKind::T___DECLTYPE;
788+
} else if (s[2] == 'i') {
789+
if (s[3] == 'n') {
790+
if (s[4] == 't') {
791+
if (s[5] == '1') {
792+
if (s[6] == '2') {
793+
if (s[7] == '8') {
794+
if (s[8] == '_') {
795+
if (s[9] == 't') {
796+
return cxx::TokenKind::T___INT128_T;
797797
}
798798
}
799799
}
800800
}
801801
}
802-
}
803-
}
804-
} else if (s[2] == 'i') {
805-
if (s[3] == 'n') {
806-
if (s[4] == 'l') {
802+
} else if (s[4] == 'l') {
807803
if (s[5] == 'i') {
808804
if (s[6] == 'n') {
809805
if (s[7] == 'e') {
@@ -817,6 +813,22 @@ static inline auto classifyC10(const char* s) -> cxx::TokenKind {
817813
}
818814
}
819815
}
816+
} else if (s[2] == 'd') {
817+
if (s[3] == 'e') {
818+
if (s[4] == 'c') {
819+
if (s[5] == 'l') {
820+
if (s[6] == 't') {
821+
if (s[7] == 'y') {
822+
if (s[8] == 'p') {
823+
if (s[9] == 'e') {
824+
return cxx::TokenKind::T___DECLTYPE;
825+
}
826+
}
827+
}
828+
}
829+
}
830+
}
831+
}
820832
} else if (s[2] == 'r') {
821833
if (s[3] == 'e') {
822834
if (s[4] == 's') {
@@ -912,6 +924,24 @@ static inline auto classifyC11(const char* s) -> cxx::TokenKind {
912924
}
913925
}
914926
}
927+
} else if (s[2] == 'u') {
928+
if (s[3] == 'i') {
929+
if (s[4] == 'n') {
930+
if (s[5] == 't') {
931+
if (s[6] == '1') {
932+
if (s[7] == '2') {
933+
if (s[8] == '8') {
934+
if (s[9] == '_') {
935+
if (s[10] == 't') {
936+
return cxx::TokenKind::T___UINT128_T;
937+
}
938+
}
939+
}
940+
}
941+
}
942+
}
943+
}
944+
}
915945
} else if (s[2] == 'a') {
916946
if (s[3] == 'l') {
917947
if (s[4] == 'i') {

src/parser/cxx/private/keywords-priv.h

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,25 +1159,21 @@ static inline auto classify10(const char* s) -> cxx::TokenKind {
11591159
}
11601160
}
11611161
}
1162-
} else if (s[2] == 'd') {
1163-
if (s[3] == 'e') {
1164-
if (s[4] == 'c') {
1165-
if (s[5] == 'l') {
1166-
if (s[6] == 't') {
1167-
if (s[7] == 'y') {
1168-
if (s[8] == 'p') {
1169-
if (s[9] == 'e') {
1170-
return cxx::TokenKind::T___DECLTYPE;
1162+
} else if (s[2] == 'i') {
1163+
if (s[3] == 'n') {
1164+
if (s[4] == 't') {
1165+
if (s[5] == '1') {
1166+
if (s[6] == '2') {
1167+
if (s[7] == '8') {
1168+
if (s[8] == '_') {
1169+
if (s[9] == 't') {
1170+
return cxx::TokenKind::T___INT128_T;
11711171
}
11721172
}
11731173
}
11741174
}
11751175
}
1176-
}
1177-
}
1178-
} else if (s[2] == 'i') {
1179-
if (s[3] == 'n') {
1180-
if (s[4] == 'l') {
1176+
} else if (s[4] == 'l') {
11811177
if (s[5] == 'i') {
11821178
if (s[6] == 'n') {
11831179
if (s[7] == 'e') {
@@ -1191,6 +1187,22 @@ static inline auto classify10(const char* s) -> cxx::TokenKind {
11911187
}
11921188
}
11931189
}
1190+
} else if (s[2] == 'd') {
1191+
if (s[3] == 'e') {
1192+
if (s[4] == 'c') {
1193+
if (s[5] == 'l') {
1194+
if (s[6] == 't') {
1195+
if (s[7] == 'y') {
1196+
if (s[8] == 'p') {
1197+
if (s[9] == 'e') {
1198+
return cxx::TokenKind::T___DECLTYPE;
1199+
}
1200+
}
1201+
}
1202+
}
1203+
}
1204+
}
1205+
}
11941206
} else if (s[2] == 'r') {
11951207
if (s[3] == 'e') {
11961208
if (s[4] == 's') {
@@ -1288,6 +1300,24 @@ static inline auto classify11(const char* s) -> cxx::TokenKind {
12881300
}
12891301
}
12901302
}
1303+
} else if (s[2] == 'u') {
1304+
if (s[3] == 'i') {
1305+
if (s[4] == 'n') {
1306+
if (s[5] == 't') {
1307+
if (s[6] == '1') {
1308+
if (s[7] == '2') {
1309+
if (s[8] == '8') {
1310+
if (s[9] == '_') {
1311+
if (s[10] == 't') {
1312+
return cxx::TokenKind::T___UINT128_T;
1313+
}
1314+
}
1315+
}
1316+
}
1317+
}
1318+
}
1319+
}
1320+
}
12911321
} else if (s[2] == 'a') {
12921322
if (s[3] == 'l') {
12931323
if (s[4] == 'i') {

0 commit comments

Comments
 (0)