xref: /llvm-project-15.0.7/libc/spec/spec.td (revision b3fc0fa8)
1class Type {}
2
3class NamedType<string name> : Type {
4  string Name = name;
5}
6
7class Field<string name, Type type> {
8  string Name = name;
9  Type FieldType = type;
10}
11
12// Class to describe concrete structs specified by a standard.
13class Struct<string name> : NamedType<name> {
14  list<Field> Fields;
15}
16
17class EnumNameValue<string name, string value = "__default_enum_value__"> {
18  string Name = name;
19  string Value = value;
20}
21
22class Enum<string name, list<EnumNameValue> enumerations> : NamedType<name> {
23  list<EnumNameValue> Enumerations = enumerations;
24}
25
26class PtrType<Type type> : Type {
27  Type PointeeType = type;
28}
29
30class ConstType<Type type> : Type {
31  Type UnqualifiedType = type;
32}
33
34class RestrictedPtrType<Type type> : Type {
35  Type PointeeType = type;
36}
37
38// Builtin types.
39def VarArgType : NamedType<"...">;
40def VoidType : NamedType<"void">;
41def IntType : NamedType<"int">;
42def LongType : NamedType<"long">;
43def UnsignedLongType : NamedType<"unsigned long">;
44def LongLongType : NamedType<"long long">;
45def UnsignedLongLongType : NamedType<"unsigned long long">;
46def FloatType : NamedType<"float">;
47def DoubleType : NamedType<"double">;
48def LongDoubleType : NamedType<"long double">;
49def CharType : NamedType<"char">;
50
51// Common types
52def VoidPtr : PtrType<VoidType>;
53def VoidPtrPtr : PtrType<VoidPtr>;
54def RestrictedVoidPtrPtr : RestrictedPtrType<VoidPtr>;
55def ConstVoidPtr : ConstType<VoidPtr>;
56
57def SizeTType : NamedType<"size_t">;
58def SizeTPtr : PtrType<SizeTType>;
59def RestrictedSizeTPtr : RestrictedPtrType<SizeTType>;
60
61def LongDoublePtr : PtrType<LongDoubleType>;
62
63def IntMaxTType : NamedType<"intmax_t">;
64def UIntMaxTType : NamedType<"uintmax_t">;
65
66// _Noreturn is really not a type, but it is convenient to treat it as a type.
67def NoReturn : NamedType<"_Noreturn void">;
68
69//types moved from stdc.td
70def VoidRestrictedPtr : RestrictedPtrType<VoidType>;
71def ConstVoidRestrictedPtr : ConstType<VoidRestrictedPtr>;
72
73def CharPtr : PtrType<CharType>;
74def ConstCharPtr : ConstType<CharPtr>;
75def CharRestrictedPtr : RestrictedPtrType<CharType>;
76def CharRestrictedPtrPtr : RestrictedPtrType<CharPtr>;
77def ConstCharRestrictedPtr : ConstType<CharRestrictedPtr>;
78
79def OnceFlagType : NamedType<"once_flag">;
80def OnceFlagTypePtr : PtrType<OnceFlagType>;
81// TODO(sivachandra): Remove this non-standard type when a formal
82// way to describe callable types is available.
83def CallOnceFuncType : NamedType<"__call_once_func_t">;
84def MtxTType : NamedType<"mtx_t">;
85def MtxTTypePtr : PtrType<MtxTType>;
86def CndTType : NamedType<"cnd_t">;
87def CndTTypePtr : PtrType<CndTType>;
88def ThrdStartTType : NamedType<"thrd_start_t">;
89def ThrdTType : NamedType<"thrd_t">;
90def ThrdTTypePtr : PtrType<ThrdTType>;
91
92def IntPtr : PtrType<IntType>;
93def RestrictedIntPtr : RestrictedPtrType<IntType>;
94def FloatPtr : PtrType<FloatType>;
95def DoublePtr : PtrType<DoubleType>;
96
97def SigHandlerT : NamedType<"__sighandler_t">;
98
99def TimeTType : NamedType<"time_t">;
100
101def BSearchCompareT : NamedType<"__bsearchcompare_t">;
102def QSortCompareT : NamedType<"__qsortcompare_t">;
103
104def AtexitHandlerT : NamedType<"__atexithandler_t">;
105
106def FILE : NamedType<"FILE">;
107def FILEPtr : PtrType<FILE>;
108def FILERestrictedPtr : RestrictedPtrType<FILE>;
109
110//added because __assert_fail needs it.
111def UnsignedType : NamedType<"unsigned">;
112
113class Macro<string name> {
114  string Name = name;
115}
116
117class EnumeratedNameValue<string name, string value = "__default__"> {
118  string Name = name;
119  string Value = value;
120}
121
122class Annotation {}
123
124class RetValSpec<Type type, list<Annotation> annotations = []> {
125  Type ReturnType = type;
126  list<Annotation> Annotations = annotations;
127}
128
129class ArgSpec<Type type, list<Annotation> annotations = [], string name = ""> {
130  Type ArgType = type;
131  list<Annotation> Annotations = annotations;
132  string Name = name;
133}
134
135class FunctionSpec<string name, RetValSpec return, list<ArgSpec> args> {
136  string Name = name;
137  RetValSpec Return = return;
138  list<ArgSpec> Args = args;
139}
140
141class HeaderSpec<string name,
142                list<Macro> macros = [],
143                list<Type> types = [],
144                list<EnumeratedNameValue> enumerations = [],
145                list<FunctionSpec> functions = []> {
146  string Name = name;
147  list<FunctionSpec> Functions = functions;
148  list<Type> Types = types;
149  list<Macro> Macros = macros;
150  list<EnumeratedNameValue> Enumerations = enumerations;
151}
152
153class StandardSpec<string name> {
154  string Name = name;
155  list<HeaderSpec> Headers;
156}
157