| author | |
| committer | |
| log | 92d9cef07116da8639ac33b7fd83ba1b35f0750c |
| tree | b76b7924fb16a2313721b7a294b04f75db621bcb |
| parent | 56e07622c692f70eb10836b86c5fda02c53e2394 |
| parent | 17ffe166c286de5ff0ef4d67f60267abba5f6e12 |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
beginnings of implementing translate-c in userland26 files changed, 2349 insertions(+), 1053 deletions(-)
CMakeLists.txt+1| ... | ... | @@ -508,6 +508,7 @@ set(ZIG_STD_FILES |
| 508 | 508 | "heap.zig" |
| 509 | 509 | "io.zig" |
| 510 | 510 | "io/seekable_stream.zig" |
| 511 | "io/c_out_stream.zig" | |
| 511 | 512 | "json.zig" |
| 512 | 513 | "lazy_init.zig" |
| 513 | 514 | "linked_list.zig" |
src-self-hosted/clang.zig created+969| ... | ... | @@ -0,0 +1,969 @@ |
| 1 | pub const struct_ZigClangAPValue = @OpaqueType(); | |
| 2 | pub const struct_ZigClangAPSInt = @OpaqueType(); | |
| 3 | pub const struct_ZigClangASTContext = @OpaqueType(); | |
| 4 | pub const struct_ZigClangASTUnit = @OpaqueType(); | |
| 5 | pub const struct_ZigClangArraySubscriptExpr = @OpaqueType(); | |
| 6 | pub const struct_ZigClangArrayType = @OpaqueType(); | |
| 7 | pub const struct_ZigClangAttributedType = @OpaqueType(); | |
| 8 | pub const struct_ZigClangBinaryOperator = @OpaqueType(); | |
| 9 | pub const struct_ZigClangBreakStmt = @OpaqueType(); | |
| 10 | pub const struct_ZigClangBuiltinType = @OpaqueType(); | |
| 11 | pub const struct_ZigClangCStyleCastExpr = @OpaqueType(); | |
| 12 | pub const struct_ZigClangCallExpr = @OpaqueType(); | |
| 13 | pub const struct_ZigClangCaseStmt = @OpaqueType(); | |
| 14 | pub const struct_ZigClangCompoundAssignOperator = @OpaqueType(); | |
| 15 | pub const struct_ZigClangCompoundStmt = @OpaqueType(); | |
| 16 | pub const struct_ZigClangConditionalOperator = @OpaqueType(); | |
| 17 | pub const struct_ZigClangConstantArrayType = @OpaqueType(); | |
| 18 | pub const struct_ZigClangContinueStmt = @OpaqueType(); | |
| 19 | pub const struct_ZigClangDecayedType = @OpaqueType(); | |
| 20 | pub const struct_ZigClangDecl = @OpaqueType(); | |
| 21 | pub const struct_ZigClangDeclRefExpr = @OpaqueType(); | |
| 22 | pub const struct_ZigClangDeclStmt = @OpaqueType(); | |
| 23 | pub const struct_ZigClangDefaultStmt = @OpaqueType(); | |
| 24 | pub const struct_ZigClangDiagnosticOptions = @OpaqueType(); | |
| 25 | pub const struct_ZigClangDiagnosticsEngine = @OpaqueType(); | |
| 26 | pub const struct_ZigClangDoStmt = @OpaqueType(); | |
| 27 | pub const struct_ZigClangElaboratedType = @OpaqueType(); | |
| 28 | pub const struct_ZigClangEnumConstantDecl = @OpaqueType(); | |
| 29 | pub const struct_ZigClangEnumDecl = @OpaqueType(); | |
| 30 | pub const struct_ZigClangEnumType = @OpaqueType(); | |
| 31 | pub const struct_ZigClangExpr = @OpaqueType(); | |
| 32 | pub const struct_ZigClangFieldDecl = @OpaqueType(); | |
| 33 | pub const struct_ZigClangFileID = @OpaqueType(); | |
| 34 | pub const struct_ZigClangForStmt = @OpaqueType(); | |
| 35 | pub const struct_ZigClangFullSourceLoc = @OpaqueType(); | |
| 36 | pub const struct_ZigClangFunctionDecl = @OpaqueType(); | |
| 37 | pub const struct_ZigClangFunctionProtoType = @OpaqueType(); | |
| 38 | pub const struct_ZigClangIfStmt = @OpaqueType(); | |
| 39 | pub const struct_ZigClangImplicitCastExpr = @OpaqueType(); | |
| 40 | pub const struct_ZigClangIncompleteArrayType = @OpaqueType(); | |
| 41 | pub const struct_ZigClangIntegerLiteral = @OpaqueType(); | |
| 42 | pub const struct_ZigClangMacroDefinitionRecord = @OpaqueType(); | |
| 43 | pub const struct_ZigClangMemberExpr = @OpaqueType(); | |
| 44 | pub const struct_ZigClangNamedDecl = @OpaqueType(); | |
| 45 | pub const struct_ZigClangNone = @OpaqueType(); | |
| 46 | pub const struct_ZigClangPCHContainerOperations = @OpaqueType(); | |
| 47 | pub const struct_ZigClangParenExpr = @OpaqueType(); | |
| 48 | pub const struct_ZigClangParenType = @OpaqueType(); | |
| 49 | pub const struct_ZigClangParmVarDecl = @OpaqueType(); | |
| 50 | pub const struct_ZigClangPointerType = @OpaqueType(); | |
| 51 | pub const struct_ZigClangPreprocessedEntity = @OpaqueType(); | |
| 52 | pub const struct_ZigClangRecordDecl = @OpaqueType(); | |
| 53 | pub const struct_ZigClangRecordType = @OpaqueType(); | |
| 54 | pub const struct_ZigClangReturnStmt = @OpaqueType(); | |
| 55 | pub const struct_ZigClangSkipFunctionBodiesScope = @OpaqueType(); | |
| 56 | pub const struct_ZigClangSourceManager = @OpaqueType(); | |
| 57 | pub const struct_ZigClangSourceRange = @OpaqueType(); | |
| 58 | pub const struct_ZigClangStmt = @OpaqueType(); | |
| 59 | pub const struct_ZigClangStorageClass = @OpaqueType(); | |
| 60 | pub const struct_ZigClangStringLiteral = @OpaqueType(); | |
| 61 | pub const struct_ZigClangStringRef = @OpaqueType(); | |
| 62 | pub const struct_ZigClangSwitchStmt = @OpaqueType(); | |
| 63 | pub const struct_ZigClangTagDecl = @OpaqueType(); | |
| 64 | pub const struct_ZigClangType = @OpaqueType(); | |
| 65 | pub const struct_ZigClangTypedefNameDecl = @OpaqueType(); | |
| 66 | pub const struct_ZigClangTypedefType = @OpaqueType(); | |
| 67 | pub const struct_ZigClangUnaryExprOrTypeTraitExpr = @OpaqueType(); | |
| 68 | pub const struct_ZigClangUnaryOperator = @OpaqueType(); | |
| 69 | pub const struct_ZigClangValueDecl = @OpaqueType(); | |
| 70 | pub const struct_ZigClangVarDecl = @OpaqueType(); | |
| 71 | pub const struct_ZigClangWhileStmt = @OpaqueType(); | |
| 72 | pub const ZigClangBO_PtrMemD = enum_ZigClangBO._PtrMemD; | |
| 73 | pub const ZigClangBO_PtrMemI = enum_ZigClangBO._PtrMemI; | |
| 74 | pub const ZigClangBO_Mul = enum_ZigClangBO._Mul; | |
| 75 | pub const ZigClangBO_Div = enum_ZigClangBO._Div; | |
| 76 | pub const ZigClangBO_Rem = enum_ZigClangBO._Rem; | |
| 77 | pub const ZigClangBO_Add = enum_ZigClangBO._Add; | |
| 78 | pub const ZigClangBO_Sub = enum_ZigClangBO._Sub; | |
| 79 | pub const ZigClangBO_Shl = enum_ZigClangBO._Shl; | |
| 80 | pub const ZigClangBO_Shr = enum_ZigClangBO._Shr; | |
| 81 | pub const ZigClangBO_Cmp = enum_ZigClangBO._Cmp; | |
| 82 | pub const ZigClangBO_LT = enum_ZigClangBO._LT; | |
| 83 | pub const ZigClangBO_GT = enum_ZigClangBO._GT; | |
| 84 | pub const ZigClangBO_LE = enum_ZigClangBO._LE; | |
| 85 | pub const ZigClangBO_GE = enum_ZigClangBO._GE; | |
| 86 | pub const ZigClangBO_EQ = enum_ZigClangBO._EQ; | |
| 87 | pub const ZigClangBO_NE = enum_ZigClangBO._NE; | |
| 88 | pub const ZigClangBO_And = enum_ZigClangBO._And; | |
| 89 | pub const ZigClangBO_Xor = enum_ZigClangBO._Xor; | |
| 90 | pub const ZigClangBO_Or = enum_ZigClangBO._Or; | |
| 91 | pub const ZigClangBO_LAnd = enum_ZigClangBO._LAnd; | |
| 92 | pub const ZigClangBO_LOr = enum_ZigClangBO._LOr; | |
| 93 | pub const ZigClangBO_Assign = enum_ZigClangBO._Assign; | |
| 94 | pub const ZigClangBO_MulAssign = enum_ZigClangBO._MulAssign; | |
| 95 | pub const ZigClangBO_DivAssign = enum_ZigClangBO._DivAssign; | |
| 96 | pub const ZigClangBO_RemAssign = enum_ZigClangBO._RemAssign; | |
| 97 | pub const ZigClangBO_AddAssign = enum_ZigClangBO._AddAssign; | |
| 98 | pub const ZigClangBO_SubAssign = enum_ZigClangBO._SubAssign; | |
| 99 | pub const ZigClangBO_ShlAssign = enum_ZigClangBO._ShlAssign; | |
| 100 | pub const ZigClangBO_ShrAssign = enum_ZigClangBO._ShrAssign; | |
| 101 | pub const ZigClangBO_AndAssign = enum_ZigClangBO._AndAssign; | |
| 102 | pub const ZigClangBO_XorAssign = enum_ZigClangBO._XorAssign; | |
| 103 | pub const ZigClangBO_OrAssign = enum_ZigClangBO._OrAssign; | |
| 104 | pub const ZigClangBO_Comma = enum_ZigClangBO._Comma; | |
| 105 | pub const enum_ZigClangBO = extern enum { | |
| 106 | _PtrMemD, | |
| 107 | _PtrMemI, | |
| 108 | _Mul, | |
| 109 | _Div, | |
| 110 | _Rem, | |
| 111 | _Add, | |
| 112 | _Sub, | |
| 113 | _Shl, | |
| 114 | _Shr, | |
| 115 | _Cmp, | |
| 116 | _LT, | |
| 117 | _GT, | |
| 118 | _LE, | |
| 119 | _GE, | |
| 120 | _EQ, | |
| 121 | _NE, | |
| 122 | _And, | |
| 123 | _Xor, | |
| 124 | _Or, | |
| 125 | _LAnd, | |
| 126 | _LOr, | |
| 127 | _Assign, | |
| 128 | _MulAssign, | |
| 129 | _DivAssign, | |
| 130 | _RemAssign, | |
| 131 | _AddAssign, | |
| 132 | _SubAssign, | |
| 133 | _ShlAssign, | |
| 134 | _ShrAssign, | |
| 135 | _AndAssign, | |
| 136 | _XorAssign, | |
| 137 | _OrAssign, | |
| 138 | _Comma, | |
| 139 | }; | |
| 140 | pub const ZigClangUO_PostInc = enum_ZigClangUO._PostInc; | |
| 141 | pub const ZigClangUO_PostDec = enum_ZigClangUO._PostDec; | |
| 142 | pub const ZigClangUO_PreInc = enum_ZigClangUO._PreInc; | |
| 143 | pub const ZigClangUO_PreDec = enum_ZigClangUO._PreDec; | |
| 144 | pub const ZigClangUO_AddrOf = enum_ZigClangUO._AddrOf; | |
| 145 | pub const ZigClangUO_Deref = enum_ZigClangUO._Deref; | |
| 146 | pub const ZigClangUO_Plus = enum_ZigClangUO._Plus; | |
| 147 | pub const ZigClangUO_Minus = enum_ZigClangUO._Minus; | |
| 148 | pub const ZigClangUO_Not = enum_ZigClangUO._Not; | |
| 149 | pub const ZigClangUO_LNot = enum_ZigClangUO._LNot; | |
| 150 | pub const ZigClangUO_Real = enum_ZigClangUO._Real; | |
| 151 | pub const ZigClangUO_Imag = enum_ZigClangUO._Imag; | |
| 152 | pub const ZigClangUO_Extension = enum_ZigClangUO._Extension; | |
| 153 | pub const ZigClangUO_Coawait = enum_ZigClangUO._Coawait; | |
| 154 | pub const enum_ZigClangUO = extern enum { | |
| 155 | _PostInc, | |
| 156 | _PostDec, | |
| 157 | _PreInc, | |
| 158 | _PreDec, | |
| 159 | _AddrOf, | |
| 160 | _Deref, | |
| 161 | _Plus, | |
| 162 | _Minus, | |
| 163 | _Not, | |
| 164 | _LNot, | |
| 165 | _Real, | |
| 166 | _Imag, | |
| 167 | _Extension, | |
| 168 | _Coawait, | |
| 169 | }; | |
| 170 | pub const ZigClangType_Builtin = enum_ZigClangTypeClass.ZigClangType_Builtin; | |
| 171 | pub const ZigClangType_Complex = enum_ZigClangTypeClass.ZigClangType_Complex; | |
| 172 | pub const ZigClangType_Pointer = enum_ZigClangTypeClass.ZigClangType_Pointer; | |
| 173 | pub const ZigClangType_BlockPointer = enum_ZigClangTypeClass.ZigClangType_BlockPointer; | |
| 174 | pub const ZigClangType_LValueReference = enum_ZigClangTypeClass.ZigClangType_LValueReference; | |
| 175 | pub const ZigClangType_RValueReference = enum_ZigClangTypeClass.ZigClangType_RValueReference; | |
| 176 | pub const ZigClangType_MemberPointer = enum_ZigClangTypeClass.ZigClangType_MemberPointer; | |
| 177 | pub const ZigClangType_ConstantArray = enum_ZigClangTypeClass.ZigClangType_ConstantArray; | |
| 178 | pub const ZigClangType_IncompleteArray = enum_ZigClangTypeClass.ZigClangType_IncompleteArray; | |
| 179 | pub const ZigClangType_VariableArray = enum_ZigClangTypeClass.ZigClangType_VariableArray; | |
| 180 | pub const ZigClangType_DependentSizedArray = enum_ZigClangTypeClass.ZigClangType_DependentSizedArray; | |
| 181 | pub const ZigClangType_DependentSizedExtVector = enum_ZigClangTypeClass.ZigClangType_DependentSizedExtVector; | |
| 182 | pub const ZigClangType_DependentAddressSpace = enum_ZigClangTypeClass.ZigClangType_DependentAddressSpace; | |
| 183 | pub const ZigClangType_Vector = enum_ZigClangTypeClass.ZigClangType_Vector; | |
| 184 | pub const ZigClangType_DependentVector = enum_ZigClangTypeClass.ZigClangType_DependentVector; | |
| 185 | pub const ZigClangType_ExtVector = enum_ZigClangTypeClass.ZigClangType_ExtVector; | |
| 186 | pub const ZigClangType_FunctionProto = enum_ZigClangTypeClass.ZigClangType_FunctionProto; | |
| 187 | pub const ZigClangType_FunctionNoProto = enum_ZigClangTypeClass.ZigClangType_FunctionNoProto; | |
| 188 | pub const ZigClangType_UnresolvedUsing = enum_ZigClangTypeClass.ZigClangType_UnresolvedUsing; | |
| 189 | pub const ZigClangType_Paren = enum_ZigClangTypeClass.ZigClangType_Paren; | |
| 190 | pub const ZigClangType_Typedef = enum_ZigClangTypeClass.ZigClangType_Typedef; | |
| 191 | pub const ZigClangType_Adjusted = enum_ZigClangTypeClass.ZigClangType_Adjusted; | |
| 192 | pub const ZigClangType_Decayed = enum_ZigClangTypeClass.ZigClangType_Decayed; | |
| 193 | pub const ZigClangType_TypeOfExpr = enum_ZigClangTypeClass.ZigClangType_TypeOfExpr; | |
| 194 | pub const ZigClangType_TypeOf = enum_ZigClangTypeClass.ZigClangType_TypeOf; | |
| 195 | pub const ZigClangType_Decltype = enum_ZigClangTypeClass.ZigClangType_Decltype; | |
| 196 | pub const ZigClangType_UnaryTransform = enum_ZigClangTypeClass.ZigClangType_UnaryTransform; | |
| 197 | pub const ZigClangType_Record = enum_ZigClangTypeClass.ZigClangType_Record; | |
| 198 | pub const ZigClangType_Enum = enum_ZigClangTypeClass.ZigClangType_Enum; | |
| 199 | pub const ZigClangType_Elaborated = enum_ZigClangTypeClass.ZigClangType_Elaborated; | |
| 200 | pub const ZigClangType_Attributed = enum_ZigClangTypeClass.ZigClangType_Attributed; | |
| 201 | pub const ZigClangType_TemplateTypeParm = enum_ZigClangTypeClass.ZigClangType_TemplateTypeParm; | |
| 202 | pub const ZigClangType_SubstTemplateTypeParm = enum_ZigClangTypeClass.ZigClangType_SubstTemplateTypeParm; | |
| 203 | pub const ZigClangType_SubstTemplateTypeParmPack = enum_ZigClangTypeClass.ZigClangType_SubstTemplateTypeParmPack; | |
| 204 | pub const ZigClangType_TemplateSpecialization = enum_ZigClangTypeClass.ZigClangType_TemplateSpecialization; | |
| 205 | pub const ZigClangType_Auto = enum_ZigClangTypeClass.ZigClangType_Auto; | |
| 206 | pub const ZigClangType_DeducedTemplateSpecialization = enum_ZigClangTypeClass.ZigClangType_DeducedTemplateSpecialization; | |
| 207 | pub const ZigClangType_InjectedClassName = enum_ZigClangTypeClass.ZigClangType_InjectedClassName; | |
| 208 | pub const ZigClangType_DependentName = enum_ZigClangTypeClass.ZigClangType_DependentName; | |
| 209 | pub const ZigClangType_DependentTemplateSpecialization = enum_ZigClangTypeClass.ZigClangType_DependentTemplateSpecialization; | |
| 210 | pub const ZigClangType_PackExpansion = enum_ZigClangTypeClass.ZigClangType_PackExpansion; | |
| 211 | pub const ZigClangType_ObjCTypeParam = enum_ZigClangTypeClass.ZigClangType_ObjCTypeParam; | |
| 212 | pub const ZigClangType_ObjCObject = enum_ZigClangTypeClass.ZigClangType_ObjCObject; | |
| 213 | pub const ZigClangType_ObjCInterface = enum_ZigClangTypeClass.ZigClangType_ObjCInterface; | |
| 214 | pub const ZigClangType_ObjCObjectPointer = enum_ZigClangTypeClass.ZigClangType_ObjCObjectPointer; | |
| 215 | pub const ZigClangType_Pipe = enum_ZigClangTypeClass.ZigClangType_Pipe; | |
| 216 | pub const ZigClangType_Atomic = enum_ZigClangTypeClass.ZigClangType_Atomic; | |
| 217 | pub const enum_ZigClangTypeClass = extern enum { | |
| 218 | ZigClangType_Builtin, | |
| 219 | ZigClangType_Complex, | |
| 220 | ZigClangType_Pointer, | |
| 221 | ZigClangType_BlockPointer, | |
| 222 | ZigClangType_LValueReference, | |
| 223 | ZigClangType_RValueReference, | |
| 224 | ZigClangType_MemberPointer, | |
| 225 | ZigClangType_ConstantArray, | |
| 226 | ZigClangType_IncompleteArray, | |
| 227 | ZigClangType_VariableArray, | |
| 228 | ZigClangType_DependentSizedArray, | |
| 229 | ZigClangType_DependentSizedExtVector, | |
| 230 | ZigClangType_DependentAddressSpace, | |
| 231 | ZigClangType_Vector, | |
| 232 | ZigClangType_DependentVector, | |
| 233 | ZigClangType_ExtVector, | |
| 234 | ZigClangType_FunctionProto, | |
| 235 | ZigClangType_FunctionNoProto, | |
| 236 | ZigClangType_UnresolvedUsing, | |
| 237 | ZigClangType_Paren, | |
| 238 | ZigClangType_Typedef, | |
| 239 | ZigClangType_Adjusted, | |
| 240 | ZigClangType_Decayed, | |
| 241 | ZigClangType_TypeOfExpr, | |
| 242 | ZigClangType_TypeOf, | |
| 243 | ZigClangType_Decltype, | |
| 244 | ZigClangType_UnaryTransform, | |
| 245 | ZigClangType_Record, | |
| 246 | ZigClangType_Enum, | |
| 247 | ZigClangType_Elaborated, | |
| 248 | ZigClangType_Attributed, | |
| 249 | ZigClangType_TemplateTypeParm, | |
| 250 | ZigClangType_SubstTemplateTypeParm, | |
| 251 | ZigClangType_SubstTemplateTypeParmPack, | |
| 252 | ZigClangType_TemplateSpecialization, | |
| 253 | ZigClangType_Auto, | |
| 254 | ZigClangType_DeducedTemplateSpecialization, | |
| 255 | ZigClangType_InjectedClassName, | |
| 256 | ZigClangType_DependentName, | |
| 257 | ZigClangType_DependentTemplateSpecialization, | |
| 258 | ZigClangType_PackExpansion, | |
| 259 | ZigClangType_ObjCTypeParam, | |
| 260 | ZigClangType_ObjCObject, | |
| 261 | ZigClangType_ObjCInterface, | |
| 262 | ZigClangType_ObjCObjectPointer, | |
| 263 | ZigClangType_Pipe, | |
| 264 | ZigClangType_Atomic, | |
| 265 | }; | |
| 266 | pub const ZigClangStmt_NoStmtClass = enum_ZigClangStmtClass.ZigClangStmt_NoStmtClass; | |
| 267 | pub const ZigClangStmt_GCCAsmStmtClass = enum_ZigClangStmtClass.ZigClangStmt_GCCAsmStmtClass; | |
| 268 | pub const ZigClangStmt_MSAsmStmtClass = enum_ZigClangStmtClass.ZigClangStmt_MSAsmStmtClass; | |
| 269 | pub const ZigClangStmt_AttributedStmtClass = enum_ZigClangStmtClass.ZigClangStmt_AttributedStmtClass; | |
| 270 | pub const ZigClangStmt_BreakStmtClass = enum_ZigClangStmtClass.ZigClangStmt_BreakStmtClass; | |
| 271 | pub const ZigClangStmt_CXXCatchStmtClass = enum_ZigClangStmtClass.ZigClangStmt_CXXCatchStmtClass; | |
| 272 | pub const ZigClangStmt_CXXForRangeStmtClass = enum_ZigClangStmtClass.ZigClangStmt_CXXForRangeStmtClass; | |
| 273 | pub const ZigClangStmt_CXXTryStmtClass = enum_ZigClangStmtClass.ZigClangStmt_CXXTryStmtClass; | |
| 274 | pub const ZigClangStmt_CapturedStmtClass = enum_ZigClangStmtClass.ZigClangStmt_CapturedStmtClass; | |
| 275 | pub const ZigClangStmt_CompoundStmtClass = enum_ZigClangStmtClass.ZigClangStmt_CompoundStmtClass; | |
| 276 | pub const ZigClangStmt_ContinueStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ContinueStmtClass; | |
| 277 | pub const ZigClangStmt_CoreturnStmtClass = enum_ZigClangStmtClass.ZigClangStmt_CoreturnStmtClass; | |
| 278 | pub const ZigClangStmt_CoroutineBodyStmtClass = enum_ZigClangStmtClass.ZigClangStmt_CoroutineBodyStmtClass; | |
| 279 | pub const ZigClangStmt_DeclStmtClass = enum_ZigClangStmtClass.ZigClangStmt_DeclStmtClass; | |
| 280 | pub const ZigClangStmt_DoStmtClass = enum_ZigClangStmtClass.ZigClangStmt_DoStmtClass; | |
| 281 | pub const ZigClangStmt_BinaryConditionalOperatorClass = enum_ZigClangStmtClass.ZigClangStmt_BinaryConditionalOperatorClass; | |
| 282 | pub const ZigClangStmt_ConditionalOperatorClass = enum_ZigClangStmtClass.ZigClangStmt_ConditionalOperatorClass; | |
| 283 | pub const ZigClangStmt_AddrLabelExprClass = enum_ZigClangStmtClass.ZigClangStmt_AddrLabelExprClass; | |
| 284 | pub const ZigClangStmt_ArrayInitIndexExprClass = enum_ZigClangStmtClass.ZigClangStmt_ArrayInitIndexExprClass; | |
| 285 | pub const ZigClangStmt_ArrayInitLoopExprClass = enum_ZigClangStmtClass.ZigClangStmt_ArrayInitLoopExprClass; | |
| 286 | pub const ZigClangStmt_ArraySubscriptExprClass = enum_ZigClangStmtClass.ZigClangStmt_ArraySubscriptExprClass; | |
| 287 | pub const ZigClangStmt_ArrayTypeTraitExprClass = enum_ZigClangStmtClass.ZigClangStmt_ArrayTypeTraitExprClass; | |
| 288 | pub const ZigClangStmt_AsTypeExprClass = enum_ZigClangStmtClass.ZigClangStmt_AsTypeExprClass; | |
| 289 | pub const ZigClangStmt_AtomicExprClass = enum_ZigClangStmtClass.ZigClangStmt_AtomicExprClass; | |
| 290 | pub const ZigClangStmt_BinaryOperatorClass = enum_ZigClangStmtClass.ZigClangStmt_BinaryOperatorClass; | |
| 291 | pub const ZigClangStmt_CompoundAssignOperatorClass = enum_ZigClangStmtClass.ZigClangStmt_CompoundAssignOperatorClass; | |
| 292 | pub const ZigClangStmt_BlockExprClass = enum_ZigClangStmtClass.ZigClangStmt_BlockExprClass; | |
| 293 | pub const ZigClangStmt_CXXBindTemporaryExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXBindTemporaryExprClass; | |
| 294 | pub const ZigClangStmt_CXXBoolLiteralExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXBoolLiteralExprClass; | |
| 295 | pub const ZigClangStmt_CXXConstructExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXConstructExprClass; | |
| 296 | pub const ZigClangStmt_CXXTemporaryObjectExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXTemporaryObjectExprClass; | |
| 297 | pub const ZigClangStmt_CXXDefaultArgExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXDefaultArgExprClass; | |
| 298 | pub const ZigClangStmt_CXXDefaultInitExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXDefaultInitExprClass; | |
| 299 | pub const ZigClangStmt_CXXDeleteExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXDeleteExprClass; | |
| 300 | pub const ZigClangStmt_CXXDependentScopeMemberExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXDependentScopeMemberExprClass; | |
| 301 | pub const ZigClangStmt_CXXFoldExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXFoldExprClass; | |
| 302 | pub const ZigClangStmt_CXXInheritedCtorInitExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXInheritedCtorInitExprClass; | |
| 303 | pub const ZigClangStmt_CXXNewExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXNewExprClass; | |
| 304 | pub const ZigClangStmt_CXXNoexceptExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXNoexceptExprClass; | |
| 305 | pub const ZigClangStmt_CXXNullPtrLiteralExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXNullPtrLiteralExprClass; | |
| 306 | pub const ZigClangStmt_CXXPseudoDestructorExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXPseudoDestructorExprClass; | |
| 307 | pub const ZigClangStmt_CXXScalarValueInitExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXScalarValueInitExprClass; | |
| 308 | pub const ZigClangStmt_CXXStdInitializerListExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXStdInitializerListExprClass; | |
| 309 | pub const ZigClangStmt_CXXThisExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXThisExprClass; | |
| 310 | pub const ZigClangStmt_CXXThrowExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXThrowExprClass; | |
| 311 | pub const ZigClangStmt_CXXTypeidExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXTypeidExprClass; | |
| 312 | pub const ZigClangStmt_CXXUnresolvedConstructExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXUnresolvedConstructExprClass; | |
| 313 | pub const ZigClangStmt_CXXUuidofExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXUuidofExprClass; | |
| 314 | pub const ZigClangStmt_CallExprClass = enum_ZigClangStmtClass.ZigClangStmt_CallExprClass; | |
| 315 | pub const ZigClangStmt_CUDAKernelCallExprClass = enum_ZigClangStmtClass.ZigClangStmt_CUDAKernelCallExprClass; | |
| 316 | pub const ZigClangStmt_CXXMemberCallExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXMemberCallExprClass; | |
| 317 | pub const ZigClangStmt_CXXOperatorCallExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXOperatorCallExprClass; | |
| 318 | pub const ZigClangStmt_UserDefinedLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_UserDefinedLiteralClass; | |
| 319 | pub const ZigClangStmt_CStyleCastExprClass = enum_ZigClangStmtClass.ZigClangStmt_CStyleCastExprClass; | |
| 320 | pub const ZigClangStmt_CXXFunctionalCastExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXFunctionalCastExprClass; | |
| 321 | pub const ZigClangStmt_CXXConstCastExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXConstCastExprClass; | |
| 322 | pub const ZigClangStmt_CXXDynamicCastExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXDynamicCastExprClass; | |
| 323 | pub const ZigClangStmt_CXXReinterpretCastExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXReinterpretCastExprClass; | |
| 324 | pub const ZigClangStmt_CXXStaticCastExprClass = enum_ZigClangStmtClass.ZigClangStmt_CXXStaticCastExprClass; | |
| 325 | pub const ZigClangStmt_ObjCBridgedCastExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCBridgedCastExprClass; | |
| 326 | pub const ZigClangStmt_ImplicitCastExprClass = enum_ZigClangStmtClass.ZigClangStmt_ImplicitCastExprClass; | |
| 327 | pub const ZigClangStmt_CharacterLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_CharacterLiteralClass; | |
| 328 | pub const ZigClangStmt_ChooseExprClass = enum_ZigClangStmtClass.ZigClangStmt_ChooseExprClass; | |
| 329 | pub const ZigClangStmt_CompoundLiteralExprClass = enum_ZigClangStmtClass.ZigClangStmt_CompoundLiteralExprClass; | |
| 330 | pub const ZigClangStmt_ConvertVectorExprClass = enum_ZigClangStmtClass.ZigClangStmt_ConvertVectorExprClass; | |
| 331 | pub const ZigClangStmt_CoawaitExprClass = enum_ZigClangStmtClass.ZigClangStmt_CoawaitExprClass; | |
| 332 | pub const ZigClangStmt_CoyieldExprClass = enum_ZigClangStmtClass.ZigClangStmt_CoyieldExprClass; | |
| 333 | pub const ZigClangStmt_DeclRefExprClass = enum_ZigClangStmtClass.ZigClangStmt_DeclRefExprClass; | |
| 334 | pub const ZigClangStmt_DependentCoawaitExprClass = enum_ZigClangStmtClass.ZigClangStmt_DependentCoawaitExprClass; | |
| 335 | pub const ZigClangStmt_DependentScopeDeclRefExprClass = enum_ZigClangStmtClass.ZigClangStmt_DependentScopeDeclRefExprClass; | |
| 336 | pub const ZigClangStmt_DesignatedInitExprClass = enum_ZigClangStmtClass.ZigClangStmt_DesignatedInitExprClass; | |
| 337 | pub const ZigClangStmt_DesignatedInitUpdateExprClass = enum_ZigClangStmtClass.ZigClangStmt_DesignatedInitUpdateExprClass; | |
| 338 | pub const ZigClangStmt_ExpressionTraitExprClass = enum_ZigClangStmtClass.ZigClangStmt_ExpressionTraitExprClass; | |
| 339 | pub const ZigClangStmt_ExtVectorElementExprClass = enum_ZigClangStmtClass.ZigClangStmt_ExtVectorElementExprClass; | |
| 340 | pub const ZigClangStmt_FixedPointLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_FixedPointLiteralClass; | |
| 341 | pub const ZigClangStmt_FloatingLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_FloatingLiteralClass; | |
| 342 | pub const ZigClangStmt_ConstantExprClass = enum_ZigClangStmtClass.ZigClangStmt_ConstantExprClass; | |
| 343 | pub const ZigClangStmt_ExprWithCleanupsClass = enum_ZigClangStmtClass.ZigClangStmt_ExprWithCleanupsClass; | |
| 344 | pub const ZigClangStmt_FunctionParmPackExprClass = enum_ZigClangStmtClass.ZigClangStmt_FunctionParmPackExprClass; | |
| 345 | pub const ZigClangStmt_GNUNullExprClass = enum_ZigClangStmtClass.ZigClangStmt_GNUNullExprClass; | |
| 346 | pub const ZigClangStmt_GenericSelectionExprClass = enum_ZigClangStmtClass.ZigClangStmt_GenericSelectionExprClass; | |
| 347 | pub const ZigClangStmt_ImaginaryLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_ImaginaryLiteralClass; | |
| 348 | pub const ZigClangStmt_ImplicitValueInitExprClass = enum_ZigClangStmtClass.ZigClangStmt_ImplicitValueInitExprClass; | |
| 349 | pub const ZigClangStmt_InitListExprClass = enum_ZigClangStmtClass.ZigClangStmt_InitListExprClass; | |
| 350 | pub const ZigClangStmt_IntegerLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_IntegerLiteralClass; | |
| 351 | pub const ZigClangStmt_LambdaExprClass = enum_ZigClangStmtClass.ZigClangStmt_LambdaExprClass; | |
| 352 | pub const ZigClangStmt_MSPropertyRefExprClass = enum_ZigClangStmtClass.ZigClangStmt_MSPropertyRefExprClass; | |
| 353 | pub const ZigClangStmt_MSPropertySubscriptExprClass = enum_ZigClangStmtClass.ZigClangStmt_MSPropertySubscriptExprClass; | |
| 354 | pub const ZigClangStmt_MaterializeTemporaryExprClass = enum_ZigClangStmtClass.ZigClangStmt_MaterializeTemporaryExprClass; | |
| 355 | pub const ZigClangStmt_MemberExprClass = enum_ZigClangStmtClass.ZigClangStmt_MemberExprClass; | |
| 356 | pub const ZigClangStmt_NoInitExprClass = enum_ZigClangStmtClass.ZigClangStmt_NoInitExprClass; | |
| 357 | pub const ZigClangStmt_OMPArraySectionExprClass = enum_ZigClangStmtClass.ZigClangStmt_OMPArraySectionExprClass; | |
| 358 | pub const ZigClangStmt_ObjCArrayLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCArrayLiteralClass; | |
| 359 | pub const ZigClangStmt_ObjCAvailabilityCheckExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCAvailabilityCheckExprClass; | |
| 360 | pub const ZigClangStmt_ObjCBoolLiteralExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCBoolLiteralExprClass; | |
| 361 | pub const ZigClangStmt_ObjCBoxedExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCBoxedExprClass; | |
| 362 | pub const ZigClangStmt_ObjCDictionaryLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCDictionaryLiteralClass; | |
| 363 | pub const ZigClangStmt_ObjCEncodeExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCEncodeExprClass; | |
| 364 | pub const ZigClangStmt_ObjCIndirectCopyRestoreExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCIndirectCopyRestoreExprClass; | |
| 365 | pub const ZigClangStmt_ObjCIsaExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCIsaExprClass; | |
| 366 | pub const ZigClangStmt_ObjCIvarRefExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCIvarRefExprClass; | |
| 367 | pub const ZigClangStmt_ObjCMessageExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCMessageExprClass; | |
| 368 | pub const ZigClangStmt_ObjCPropertyRefExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCPropertyRefExprClass; | |
| 369 | pub const ZigClangStmt_ObjCProtocolExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCProtocolExprClass; | |
| 370 | pub const ZigClangStmt_ObjCSelectorExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCSelectorExprClass; | |
| 371 | pub const ZigClangStmt_ObjCStringLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCStringLiteralClass; | |
| 372 | pub const ZigClangStmt_ObjCSubscriptRefExprClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCSubscriptRefExprClass; | |
| 373 | pub const ZigClangStmt_OffsetOfExprClass = enum_ZigClangStmtClass.ZigClangStmt_OffsetOfExprClass; | |
| 374 | pub const ZigClangStmt_OpaqueValueExprClass = enum_ZigClangStmtClass.ZigClangStmt_OpaqueValueExprClass; | |
| 375 | pub const ZigClangStmt_UnresolvedLookupExprClass = enum_ZigClangStmtClass.ZigClangStmt_UnresolvedLookupExprClass; | |
| 376 | pub const ZigClangStmt_UnresolvedMemberExprClass = enum_ZigClangStmtClass.ZigClangStmt_UnresolvedMemberExprClass; | |
| 377 | pub const ZigClangStmt_PackExpansionExprClass = enum_ZigClangStmtClass.ZigClangStmt_PackExpansionExprClass; | |
| 378 | pub const ZigClangStmt_ParenExprClass = enum_ZigClangStmtClass.ZigClangStmt_ParenExprClass; | |
| 379 | pub const ZigClangStmt_ParenListExprClass = enum_ZigClangStmtClass.ZigClangStmt_ParenListExprClass; | |
| 380 | pub const ZigClangStmt_PredefinedExprClass = enum_ZigClangStmtClass.ZigClangStmt_PredefinedExprClass; | |
| 381 | pub const ZigClangStmt_PseudoObjectExprClass = enum_ZigClangStmtClass.ZigClangStmt_PseudoObjectExprClass; | |
| 382 | pub const ZigClangStmt_ShuffleVectorExprClass = enum_ZigClangStmtClass.ZigClangStmt_ShuffleVectorExprClass; | |
| 383 | pub const ZigClangStmt_SizeOfPackExprClass = enum_ZigClangStmtClass.ZigClangStmt_SizeOfPackExprClass; | |
| 384 | pub const ZigClangStmt_StmtExprClass = enum_ZigClangStmtClass.ZigClangStmt_StmtExprClass; | |
| 385 | pub const ZigClangStmt_StringLiteralClass = enum_ZigClangStmtClass.ZigClangStmt_StringLiteralClass; | |
| 386 | pub const ZigClangStmt_SubstNonTypeTemplateParmExprClass = enum_ZigClangStmtClass.ZigClangStmt_SubstNonTypeTemplateParmExprClass; | |
| 387 | pub const ZigClangStmt_SubstNonTypeTemplateParmPackExprClass = enum_ZigClangStmtClass.ZigClangStmt_SubstNonTypeTemplateParmPackExprClass; | |
| 388 | pub const ZigClangStmt_TypeTraitExprClass = enum_ZigClangStmtClass.ZigClangStmt_TypeTraitExprClass; | |
| 389 | pub const ZigClangStmt_TypoExprClass = enum_ZigClangStmtClass.ZigClangStmt_TypoExprClass; | |
| 390 | pub const ZigClangStmt_UnaryExprOrTypeTraitExprClass = enum_ZigClangStmtClass.ZigClangStmt_UnaryExprOrTypeTraitExprClass; | |
| 391 | pub const ZigClangStmt_UnaryOperatorClass = enum_ZigClangStmtClass.ZigClangStmt_UnaryOperatorClass; | |
| 392 | pub const ZigClangStmt_VAArgExprClass = enum_ZigClangStmtClass.ZigClangStmt_VAArgExprClass; | |
| 393 | pub const ZigClangStmt_ForStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ForStmtClass; | |
| 394 | pub const ZigClangStmt_GotoStmtClass = enum_ZigClangStmtClass.ZigClangStmt_GotoStmtClass; | |
| 395 | pub const ZigClangStmt_IfStmtClass = enum_ZigClangStmtClass.ZigClangStmt_IfStmtClass; | |
| 396 | pub const ZigClangStmt_IndirectGotoStmtClass = enum_ZigClangStmtClass.ZigClangStmt_IndirectGotoStmtClass; | |
| 397 | pub const ZigClangStmt_LabelStmtClass = enum_ZigClangStmtClass.ZigClangStmt_LabelStmtClass; | |
| 398 | pub const ZigClangStmt_MSDependentExistsStmtClass = enum_ZigClangStmtClass.ZigClangStmt_MSDependentExistsStmtClass; | |
| 399 | pub const ZigClangStmt_NullStmtClass = enum_ZigClangStmtClass.ZigClangStmt_NullStmtClass; | |
| 400 | pub const ZigClangStmt_OMPAtomicDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPAtomicDirectiveClass; | |
| 401 | pub const ZigClangStmt_OMPBarrierDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPBarrierDirectiveClass; | |
| 402 | pub const ZigClangStmt_OMPCancelDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPCancelDirectiveClass; | |
| 403 | pub const ZigClangStmt_OMPCancellationPointDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPCancellationPointDirectiveClass; | |
| 404 | pub const ZigClangStmt_OMPCriticalDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPCriticalDirectiveClass; | |
| 405 | pub const ZigClangStmt_OMPFlushDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPFlushDirectiveClass; | |
| 406 | pub const ZigClangStmt_OMPDistributeDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPDistributeDirectiveClass; | |
| 407 | pub const ZigClangStmt_OMPDistributeParallelForDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPDistributeParallelForDirectiveClass; | |
| 408 | pub const ZigClangStmt_OMPDistributeParallelForSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPDistributeParallelForSimdDirectiveClass; | |
| 409 | pub const ZigClangStmt_OMPDistributeSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPDistributeSimdDirectiveClass; | |
| 410 | pub const ZigClangStmt_OMPForDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPForDirectiveClass; | |
| 411 | pub const ZigClangStmt_OMPForSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPForSimdDirectiveClass; | |
| 412 | pub const ZigClangStmt_OMPParallelForDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPParallelForDirectiveClass; | |
| 413 | pub const ZigClangStmt_OMPParallelForSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPParallelForSimdDirectiveClass; | |
| 414 | pub const ZigClangStmt_OMPSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPSimdDirectiveClass; | |
| 415 | pub const ZigClangStmt_OMPTargetParallelForSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetParallelForSimdDirectiveClass; | |
| 416 | pub const ZigClangStmt_OMPTargetSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetSimdDirectiveClass; | |
| 417 | pub const ZigClangStmt_OMPTargetTeamsDistributeDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetTeamsDistributeDirectiveClass; | |
| 418 | pub const ZigClangStmt_OMPTargetTeamsDistributeParallelForDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetTeamsDistributeParallelForDirectiveClass; | |
| 419 | pub const ZigClangStmt_OMPTargetTeamsDistributeParallelForSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetTeamsDistributeParallelForSimdDirectiveClass; | |
| 420 | pub const ZigClangStmt_OMPTargetTeamsDistributeSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetTeamsDistributeSimdDirectiveClass; | |
| 421 | pub const ZigClangStmt_OMPTaskLoopDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTaskLoopDirectiveClass; | |
| 422 | pub const ZigClangStmt_OMPTaskLoopSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTaskLoopSimdDirectiveClass; | |
| 423 | pub const ZigClangStmt_OMPTeamsDistributeDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTeamsDistributeDirectiveClass; | |
| 424 | pub const ZigClangStmt_OMPTeamsDistributeParallelForDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTeamsDistributeParallelForDirectiveClass; | |
| 425 | pub const ZigClangStmt_OMPTeamsDistributeParallelForSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTeamsDistributeParallelForSimdDirectiveClass; | |
| 426 | pub const ZigClangStmt_OMPTeamsDistributeSimdDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTeamsDistributeSimdDirectiveClass; | |
| 427 | pub const ZigClangStmt_OMPMasterDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPMasterDirectiveClass; | |
| 428 | pub const ZigClangStmt_OMPOrderedDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPOrderedDirectiveClass; | |
| 429 | pub const ZigClangStmt_OMPParallelDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPParallelDirectiveClass; | |
| 430 | pub const ZigClangStmt_OMPParallelSectionsDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPParallelSectionsDirectiveClass; | |
| 431 | pub const ZigClangStmt_OMPSectionDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPSectionDirectiveClass; | |
| 432 | pub const ZigClangStmt_OMPSectionsDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPSectionsDirectiveClass; | |
| 433 | pub const ZigClangStmt_OMPSingleDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPSingleDirectiveClass; | |
| 434 | pub const ZigClangStmt_OMPTargetDataDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetDataDirectiveClass; | |
| 435 | pub const ZigClangStmt_OMPTargetDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetDirectiveClass; | |
| 436 | pub const ZigClangStmt_OMPTargetEnterDataDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetEnterDataDirectiveClass; | |
| 437 | pub const ZigClangStmt_OMPTargetExitDataDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetExitDataDirectiveClass; | |
| 438 | pub const ZigClangStmt_OMPTargetParallelDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetParallelDirectiveClass; | |
| 439 | pub const ZigClangStmt_OMPTargetParallelForDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetParallelForDirectiveClass; | |
| 440 | pub const ZigClangStmt_OMPTargetTeamsDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetTeamsDirectiveClass; | |
| 441 | pub const ZigClangStmt_OMPTargetUpdateDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTargetUpdateDirectiveClass; | |
| 442 | pub const ZigClangStmt_OMPTaskDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTaskDirectiveClass; | |
| 443 | pub const ZigClangStmt_OMPTaskgroupDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTaskgroupDirectiveClass; | |
| 444 | pub const ZigClangStmt_OMPTaskwaitDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTaskwaitDirectiveClass; | |
| 445 | pub const ZigClangStmt_OMPTaskyieldDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTaskyieldDirectiveClass; | |
| 446 | pub const ZigClangStmt_OMPTeamsDirectiveClass = enum_ZigClangStmtClass.ZigClangStmt_OMPTeamsDirectiveClass; | |
| 447 | pub const ZigClangStmt_ObjCAtCatchStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCAtCatchStmtClass; | |
| 448 | pub const ZigClangStmt_ObjCAtFinallyStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCAtFinallyStmtClass; | |
| 449 | pub const ZigClangStmt_ObjCAtSynchronizedStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCAtSynchronizedStmtClass; | |
| 450 | pub const ZigClangStmt_ObjCAtThrowStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCAtThrowStmtClass; | |
| 451 | pub const ZigClangStmt_ObjCAtTryStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCAtTryStmtClass; | |
| 452 | pub const ZigClangStmt_ObjCAutoreleasePoolStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCAutoreleasePoolStmtClass; | |
| 453 | pub const ZigClangStmt_ObjCForCollectionStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ObjCForCollectionStmtClass; | |
| 454 | pub const ZigClangStmt_ReturnStmtClass = enum_ZigClangStmtClass.ZigClangStmt_ReturnStmtClass; | |
| 455 | pub const ZigClangStmt_SEHExceptStmtClass = enum_ZigClangStmtClass.ZigClangStmt_SEHExceptStmtClass; | |
| 456 | pub const ZigClangStmt_SEHFinallyStmtClass = enum_ZigClangStmtClass.ZigClangStmt_SEHFinallyStmtClass; | |
| 457 | pub const ZigClangStmt_SEHLeaveStmtClass = enum_ZigClangStmtClass.ZigClangStmt_SEHLeaveStmtClass; | |
| 458 | pub const ZigClangStmt_SEHTryStmtClass = enum_ZigClangStmtClass.ZigClangStmt_SEHTryStmtClass; | |
| 459 | pub const ZigClangStmt_CaseStmtClass = enum_ZigClangStmtClass.ZigClangStmt_CaseStmtClass; | |
| 460 | pub const ZigClangStmt_DefaultStmtClass = enum_ZigClangStmtClass.ZigClangStmt_DefaultStmtClass; | |
| 461 | pub const ZigClangStmt_SwitchStmtClass = enum_ZigClangStmtClass.ZigClangStmt_SwitchStmtClass; | |
| 462 | pub const ZigClangStmt_WhileStmtClass = enum_ZigClangStmtClass.ZigClangStmt_WhileStmtClass; | |
| 463 | pub const enum_ZigClangStmtClass = extern enum { | |
| 464 | ZigClangStmt_NoStmtClass = 0, | |
| 465 | ZigClangStmt_GCCAsmStmtClass = 1, | |
| 466 | ZigClangStmt_MSAsmStmtClass = 2, | |
| 467 | ZigClangStmt_AttributedStmtClass = 3, | |
| 468 | ZigClangStmt_BreakStmtClass = 4, | |
| 469 | ZigClangStmt_CXXCatchStmtClass = 5, | |
| 470 | ZigClangStmt_CXXForRangeStmtClass = 6, | |
| 471 | ZigClangStmt_CXXTryStmtClass = 7, | |
| 472 | ZigClangStmt_CapturedStmtClass = 8, | |
| 473 | ZigClangStmt_CompoundStmtClass = 9, | |
| 474 | ZigClangStmt_ContinueStmtClass = 10, | |
| 475 | ZigClangStmt_CoreturnStmtClass = 11, | |
| 476 | ZigClangStmt_CoroutineBodyStmtClass = 12, | |
| 477 | ZigClangStmt_DeclStmtClass = 13, | |
| 478 | ZigClangStmt_DoStmtClass = 14, | |
| 479 | ZigClangStmt_BinaryConditionalOperatorClass = 15, | |
| 480 | ZigClangStmt_ConditionalOperatorClass = 16, | |
| 481 | ZigClangStmt_AddrLabelExprClass = 17, | |
| 482 | ZigClangStmt_ArrayInitIndexExprClass = 18, | |
| 483 | ZigClangStmt_ArrayInitLoopExprClass = 19, | |
| 484 | ZigClangStmt_ArraySubscriptExprClass = 20, | |
| 485 | ZigClangStmt_ArrayTypeTraitExprClass = 21, | |
| 486 | ZigClangStmt_AsTypeExprClass = 22, | |
| 487 | ZigClangStmt_AtomicExprClass = 23, | |
| 488 | ZigClangStmt_BinaryOperatorClass = 24, | |
| 489 | ZigClangStmt_CompoundAssignOperatorClass = 25, | |
| 490 | ZigClangStmt_BlockExprClass = 26, | |
| 491 | ZigClangStmt_CXXBindTemporaryExprClass = 27, | |
| 492 | ZigClangStmt_CXXBoolLiteralExprClass = 28, | |
| 493 | ZigClangStmt_CXXConstructExprClass = 29, | |
| 494 | ZigClangStmt_CXXTemporaryObjectExprClass = 30, | |
| 495 | ZigClangStmt_CXXDefaultArgExprClass = 31, | |
| 496 | ZigClangStmt_CXXDefaultInitExprClass = 32, | |
| 497 | ZigClangStmt_CXXDeleteExprClass = 33, | |
| 498 | ZigClangStmt_CXXDependentScopeMemberExprClass = 34, | |
| 499 | ZigClangStmt_CXXFoldExprClass = 35, | |
| 500 | ZigClangStmt_CXXInheritedCtorInitExprClass = 36, | |
| 501 | ZigClangStmt_CXXNewExprClass = 37, | |
| 502 | ZigClangStmt_CXXNoexceptExprClass = 38, | |
| 503 | ZigClangStmt_CXXNullPtrLiteralExprClass = 39, | |
| 504 | ZigClangStmt_CXXPseudoDestructorExprClass = 40, | |
| 505 | ZigClangStmt_CXXScalarValueInitExprClass = 41, | |
| 506 | ZigClangStmt_CXXStdInitializerListExprClass = 42, | |
| 507 | ZigClangStmt_CXXThisExprClass = 43, | |
| 508 | ZigClangStmt_CXXThrowExprClass = 44, | |
| 509 | ZigClangStmt_CXXTypeidExprClass = 45, | |
| 510 | ZigClangStmt_CXXUnresolvedConstructExprClass = 46, | |
| 511 | ZigClangStmt_CXXUuidofExprClass = 47, | |
| 512 | ZigClangStmt_CallExprClass = 48, | |
| 513 | ZigClangStmt_CUDAKernelCallExprClass = 49, | |
| 514 | ZigClangStmt_CXXMemberCallExprClass = 50, | |
| 515 | ZigClangStmt_CXXOperatorCallExprClass = 51, | |
| 516 | ZigClangStmt_UserDefinedLiteralClass = 52, | |
| 517 | ZigClangStmt_CStyleCastExprClass = 53, | |
| 518 | ZigClangStmt_CXXFunctionalCastExprClass = 54, | |
| 519 | ZigClangStmt_CXXConstCastExprClass = 55, | |
| 520 | ZigClangStmt_CXXDynamicCastExprClass = 56, | |
| 521 | ZigClangStmt_CXXReinterpretCastExprClass = 57, | |
| 522 | ZigClangStmt_CXXStaticCastExprClass = 58, | |
| 523 | ZigClangStmt_ObjCBridgedCastExprClass = 59, | |
| 524 | ZigClangStmt_ImplicitCastExprClass = 60, | |
| 525 | ZigClangStmt_CharacterLiteralClass = 61, | |
| 526 | ZigClangStmt_ChooseExprClass = 62, | |
| 527 | ZigClangStmt_CompoundLiteralExprClass = 63, | |
| 528 | ZigClangStmt_ConvertVectorExprClass = 64, | |
| 529 | ZigClangStmt_CoawaitExprClass = 65, | |
| 530 | ZigClangStmt_CoyieldExprClass = 66, | |
| 531 | ZigClangStmt_DeclRefExprClass = 67, | |
| 532 | ZigClangStmt_DependentCoawaitExprClass = 68, | |
| 533 | ZigClangStmt_DependentScopeDeclRefExprClass = 69, | |
| 534 | ZigClangStmt_DesignatedInitExprClass = 70, | |
| 535 | ZigClangStmt_DesignatedInitUpdateExprClass = 71, | |
| 536 | ZigClangStmt_ExpressionTraitExprClass = 72, | |
| 537 | ZigClangStmt_ExtVectorElementExprClass = 73, | |
| 538 | ZigClangStmt_FixedPointLiteralClass = 74, | |
| 539 | ZigClangStmt_FloatingLiteralClass = 75, | |
| 540 | ZigClangStmt_ConstantExprClass = 76, | |
| 541 | ZigClangStmt_ExprWithCleanupsClass = 77, | |
| 542 | ZigClangStmt_FunctionParmPackExprClass = 78, | |
| 543 | ZigClangStmt_GNUNullExprClass = 79, | |
| 544 | ZigClangStmt_GenericSelectionExprClass = 80, | |
| 545 | ZigClangStmt_ImaginaryLiteralClass = 81, | |
| 546 | ZigClangStmt_ImplicitValueInitExprClass = 82, | |
| 547 | ZigClangStmt_InitListExprClass = 83, | |
| 548 | ZigClangStmt_IntegerLiteralClass = 84, | |
| 549 | ZigClangStmt_LambdaExprClass = 85, | |
| 550 | ZigClangStmt_MSPropertyRefExprClass = 86, | |
| 551 | ZigClangStmt_MSPropertySubscriptExprClass = 87, | |
| 552 | ZigClangStmt_MaterializeTemporaryExprClass = 88, | |
| 553 | ZigClangStmt_MemberExprClass = 89, | |
| 554 | ZigClangStmt_NoInitExprClass = 90, | |
| 555 | ZigClangStmt_OMPArraySectionExprClass = 91, | |
| 556 | ZigClangStmt_ObjCArrayLiteralClass = 92, | |
| 557 | ZigClangStmt_ObjCAvailabilityCheckExprClass = 93, | |
| 558 | ZigClangStmt_ObjCBoolLiteralExprClass = 94, | |
| 559 | ZigClangStmt_ObjCBoxedExprClass = 95, | |
| 560 | ZigClangStmt_ObjCDictionaryLiteralClass = 96, | |
| 561 | ZigClangStmt_ObjCEncodeExprClass = 97, | |
| 562 | ZigClangStmt_ObjCIndirectCopyRestoreExprClass = 98, | |
| 563 | ZigClangStmt_ObjCIsaExprClass = 99, | |
| 564 | ZigClangStmt_ObjCIvarRefExprClass = 100, | |
| 565 | ZigClangStmt_ObjCMessageExprClass = 101, | |
| 566 | ZigClangStmt_ObjCPropertyRefExprClass = 102, | |
| 567 | ZigClangStmt_ObjCProtocolExprClass = 103, | |
| 568 | ZigClangStmt_ObjCSelectorExprClass = 104, | |
| 569 | ZigClangStmt_ObjCStringLiteralClass = 105, | |
| 570 | ZigClangStmt_ObjCSubscriptRefExprClass = 106, | |
| 571 | ZigClangStmt_OffsetOfExprClass = 107, | |
| 572 | ZigClangStmt_OpaqueValueExprClass = 108, | |
| 573 | ZigClangStmt_UnresolvedLookupExprClass = 109, | |
| 574 | ZigClangStmt_UnresolvedMemberExprClass = 110, | |
| 575 | ZigClangStmt_PackExpansionExprClass = 111, | |
| 576 | ZigClangStmt_ParenExprClass = 112, | |
| 577 | ZigClangStmt_ParenListExprClass = 113, | |
| 578 | ZigClangStmt_PredefinedExprClass = 114, | |
| 579 | ZigClangStmt_PseudoObjectExprClass = 115, | |
| 580 | ZigClangStmt_ShuffleVectorExprClass = 116, | |
| 581 | ZigClangStmt_SizeOfPackExprClass = 117, | |
| 582 | ZigClangStmt_StmtExprClass = 118, | |
| 583 | ZigClangStmt_StringLiteralClass = 119, | |
| 584 | ZigClangStmt_SubstNonTypeTemplateParmExprClass = 120, | |
| 585 | ZigClangStmt_SubstNonTypeTemplateParmPackExprClass = 121, | |
| 586 | ZigClangStmt_TypeTraitExprClass = 122, | |
| 587 | ZigClangStmt_TypoExprClass = 123, | |
| 588 | ZigClangStmt_UnaryExprOrTypeTraitExprClass = 124, | |
| 589 | ZigClangStmt_UnaryOperatorClass = 125, | |
| 590 | ZigClangStmt_VAArgExprClass = 126, | |
| 591 | ZigClangStmt_ForStmtClass = 127, | |
| 592 | ZigClangStmt_GotoStmtClass = 128, | |
| 593 | ZigClangStmt_IfStmtClass = 129, | |
| 594 | ZigClangStmt_IndirectGotoStmtClass = 130, | |
| 595 | ZigClangStmt_LabelStmtClass = 131, | |
| 596 | ZigClangStmt_MSDependentExistsStmtClass = 132, | |
| 597 | ZigClangStmt_NullStmtClass = 133, | |
| 598 | ZigClangStmt_OMPAtomicDirectiveClass = 134, | |
| 599 | ZigClangStmt_OMPBarrierDirectiveClass = 135, | |
| 600 | ZigClangStmt_OMPCancelDirectiveClass = 136, | |
| 601 | ZigClangStmt_OMPCancellationPointDirectiveClass = 137, | |
| 602 | ZigClangStmt_OMPCriticalDirectiveClass = 138, | |
| 603 | ZigClangStmt_OMPFlushDirectiveClass = 139, | |
| 604 | ZigClangStmt_OMPDistributeDirectiveClass = 140, | |
| 605 | ZigClangStmt_OMPDistributeParallelForDirectiveClass = 141, | |
| 606 | ZigClangStmt_OMPDistributeParallelForSimdDirectiveClass = 142, | |
| 607 | ZigClangStmt_OMPDistributeSimdDirectiveClass = 143, | |
| 608 | ZigClangStmt_OMPForDirectiveClass = 144, | |
| 609 | ZigClangStmt_OMPForSimdDirectiveClass = 145, | |
| 610 | ZigClangStmt_OMPParallelForDirectiveClass = 146, | |
| 611 | ZigClangStmt_OMPParallelForSimdDirectiveClass = 147, | |
| 612 | ZigClangStmt_OMPSimdDirectiveClass = 148, | |
| 613 | ZigClangStmt_OMPTargetParallelForSimdDirectiveClass = 149, | |
| 614 | ZigClangStmt_OMPTargetSimdDirectiveClass = 150, | |
| 615 | ZigClangStmt_OMPTargetTeamsDistributeDirectiveClass = 151, | |
| 616 | ZigClangStmt_OMPTargetTeamsDistributeParallelForDirectiveClass = 152, | |
| 617 | ZigClangStmt_OMPTargetTeamsDistributeParallelForSimdDirectiveClass = 153, | |
| 618 | ZigClangStmt_OMPTargetTeamsDistributeSimdDirectiveClass = 154, | |
| 619 | ZigClangStmt_OMPTaskLoopDirectiveClass = 155, | |
| 620 | ZigClangStmt_OMPTaskLoopSimdDirectiveClass = 156, | |
| 621 | ZigClangStmt_OMPTeamsDistributeDirectiveClass = 157, | |
| 622 | ZigClangStmt_OMPTeamsDistributeParallelForDirectiveClass = 158, | |
| 623 | ZigClangStmt_OMPTeamsDistributeParallelForSimdDirectiveClass = 159, | |
| 624 | ZigClangStmt_OMPTeamsDistributeSimdDirectiveClass = 160, | |
| 625 | ZigClangStmt_OMPMasterDirectiveClass = 161, | |
| 626 | ZigClangStmt_OMPOrderedDirectiveClass = 162, | |
| 627 | ZigClangStmt_OMPParallelDirectiveClass = 163, | |
| 628 | ZigClangStmt_OMPParallelSectionsDirectiveClass = 164, | |
| 629 | ZigClangStmt_OMPSectionDirectiveClass = 165, | |
| 630 | ZigClangStmt_OMPSectionsDirectiveClass = 166, | |
| 631 | ZigClangStmt_OMPSingleDirectiveClass = 167, | |
| 632 | ZigClangStmt_OMPTargetDataDirectiveClass = 168, | |
| 633 | ZigClangStmt_OMPTargetDirectiveClass = 169, | |
| 634 | ZigClangStmt_OMPTargetEnterDataDirectiveClass = 170, | |
| 635 | ZigClangStmt_OMPTargetExitDataDirectiveClass = 171, | |
| 636 | ZigClangStmt_OMPTargetParallelDirectiveClass = 172, | |
| 637 | ZigClangStmt_OMPTargetParallelForDirectiveClass = 173, | |
| 638 | ZigClangStmt_OMPTargetTeamsDirectiveClass = 174, | |
| 639 | ZigClangStmt_OMPTargetUpdateDirectiveClass = 175, | |
| 640 | ZigClangStmt_OMPTaskDirectiveClass = 176, | |
| 641 | ZigClangStmt_OMPTaskgroupDirectiveClass = 177, | |
| 642 | ZigClangStmt_OMPTaskwaitDirectiveClass = 178, | |
| 643 | ZigClangStmt_OMPTaskyieldDirectiveClass = 179, | |
| 644 | ZigClangStmt_OMPTeamsDirectiveClass = 180, | |
| 645 | ZigClangStmt_ObjCAtCatchStmtClass = 181, | |
| 646 | ZigClangStmt_ObjCAtFinallyStmtClass = 182, | |
| 647 | ZigClangStmt_ObjCAtSynchronizedStmtClass = 183, | |
| 648 | ZigClangStmt_ObjCAtThrowStmtClass = 184, | |
| 649 | ZigClangStmt_ObjCAtTryStmtClass = 185, | |
| 650 | ZigClangStmt_ObjCAutoreleasePoolStmtClass = 186, | |
| 651 | ZigClangStmt_ObjCForCollectionStmtClass = 187, | |
| 652 | ZigClangStmt_ReturnStmtClass = 188, | |
| 653 | ZigClangStmt_SEHExceptStmtClass = 189, | |
| 654 | ZigClangStmt_SEHFinallyStmtClass = 190, | |
| 655 | ZigClangStmt_SEHLeaveStmtClass = 191, | |
| 656 | ZigClangStmt_SEHTryStmtClass = 192, | |
| 657 | ZigClangStmt_CaseStmtClass = 193, | |
| 658 | ZigClangStmt_DefaultStmtClass = 194, | |
| 659 | ZigClangStmt_SwitchStmtClass = 195, | |
| 660 | ZigClangStmt_WhileStmtClass = 196, | |
| 661 | }; | |
| 662 | pub const ZigClangCK_Dependent = enum_ZigClangCK._Dependent; | |
| 663 | pub const ZigClangCK_BitCast = enum_ZigClangCK._BitCast; | |
| 664 | pub const ZigClangCK_LValueBitCast = enum_ZigClangCK._LValueBitCast; | |
| 665 | pub const ZigClangCK_LValueToRValue = enum_ZigClangCK._LValueToRValue; | |
| 666 | pub const ZigClangCK_NoOp = enum_ZigClangCK._NoOp; | |
| 667 | pub const ZigClangCK_BaseToDerived = enum_ZigClangCK._BaseToDerived; | |
| 668 | pub const ZigClangCK_DerivedToBase = enum_ZigClangCK._DerivedToBase; | |
| 669 | pub const ZigClangCK_UncheckedDerivedToBase = enum_ZigClangCK._UncheckedDerivedToBase; | |
| 670 | pub const ZigClangCK_Dynamic = enum_ZigClangCK._Dynamic; | |
| 671 | pub const ZigClangCK_ToUnion = enum_ZigClangCK._ToUnion; | |
| 672 | pub const ZigClangCK_ArrayToPointerDecay = enum_ZigClangCK._ArrayToPointerDecay; | |
| 673 | pub const ZigClangCK_FunctionToPointerDecay = enum_ZigClangCK._FunctionToPointerDecay; | |
| 674 | pub const ZigClangCK_NullToPointer = enum_ZigClangCK._NullToPointer; | |
| 675 | pub const ZigClangCK_NullToMemberPointer = enum_ZigClangCK._NullToMemberPointer; | |
| 676 | pub const ZigClangCK_BaseToDerivedMemberPointer = enum_ZigClangCK._BaseToDerivedMemberPointer; | |
| 677 | pub const ZigClangCK_DerivedToBaseMemberPointer = enum_ZigClangCK._DerivedToBaseMemberPointer; | |
| 678 | pub const ZigClangCK_MemberPointerToBoolean = enum_ZigClangCK._MemberPointerToBoolean; | |
| 679 | pub const ZigClangCK_ReinterpretMemberPointer = enum_ZigClangCK._ReinterpretMemberPointer; | |
| 680 | pub const ZigClangCK_UserDefinedConversion = enum_ZigClangCK._UserDefinedConversion; | |
| 681 | pub const ZigClangCK_ConstructorConversion = enum_ZigClangCK._ConstructorConversion; | |
| 682 | pub const ZigClangCK_IntegralToPointer = enum_ZigClangCK._IntegralToPointer; | |
| 683 | pub const ZigClangCK_PointerToIntegral = enum_ZigClangCK._PointerToIntegral; | |
| 684 | pub const ZigClangCK_PointerToBoolean = enum_ZigClangCK._PointerToBoolean; | |
| 685 | pub const ZigClangCK_ToVoid = enum_ZigClangCK._ToVoid; | |
| 686 | pub const ZigClangCK_VectorSplat = enum_ZigClangCK._VectorSplat; | |
| 687 | pub const ZigClangCK_IntegralCast = enum_ZigClangCK._IntegralCast; | |
| 688 | pub const ZigClangCK_IntegralToBoolean = enum_ZigClangCK._IntegralToBoolean; | |
| 689 | pub const ZigClangCK_IntegralToFloating = enum_ZigClangCK._IntegralToFloating; | |
| 690 | pub const ZigClangCK_FixedPointCast = enum_ZigClangCK._FixedPointCast; | |
| 691 | pub const ZigClangCK_FixedPointToBoolean = enum_ZigClangCK._FixedPointToBoolean; | |
| 692 | pub const ZigClangCK_FloatingToIntegral = enum_ZigClangCK._FloatingToIntegral; | |
| 693 | pub const ZigClangCK_FloatingToBoolean = enum_ZigClangCK._FloatingToBoolean; | |
| 694 | pub const ZigClangCK_BooleanToSignedIntegral = enum_ZigClangCK._BooleanToSignedIntegral; | |
| 695 | pub const ZigClangCK_FloatingCast = enum_ZigClangCK._FloatingCast; | |
| 696 | pub const ZigClangCK_CPointerToObjCPointerCast = enum_ZigClangCK._CPointerToObjCPointerCast; | |
| 697 | pub const ZigClangCK_BlockPointerToObjCPointerCast = enum_ZigClangCK._BlockPointerToObjCPointerCast; | |
| 698 | pub const ZigClangCK_AnyPointerToBlockPointerCast = enum_ZigClangCK._AnyPointerToBlockPointerCast; | |
| 699 | pub const ZigClangCK_ObjCObjectLValueCast = enum_ZigClangCK._ObjCObjectLValueCast; | |
| 700 | pub const ZigClangCK_FloatingRealToComplex = enum_ZigClangCK._FloatingRealToComplex; | |
| 701 | pub const ZigClangCK_FloatingComplexToReal = enum_ZigClangCK._FloatingComplexToReal; | |
| 702 | pub const ZigClangCK_FloatingComplexToBoolean = enum_ZigClangCK._FloatingComplexToBoolean; | |
| 703 | pub const ZigClangCK_FloatingComplexCast = enum_ZigClangCK._FloatingComplexCast; | |
| 704 | pub const ZigClangCK_FloatingComplexToIntegralComplex = enum_ZigClangCK._FloatingComplexToIntegralComplex; | |
| 705 | pub const ZigClangCK_IntegralRealToComplex = enum_ZigClangCK._IntegralRealToComplex; | |
| 706 | pub const ZigClangCK_IntegralComplexToReal = enum_ZigClangCK._IntegralComplexToReal; | |
| 707 | pub const ZigClangCK_IntegralComplexToBoolean = enum_ZigClangCK._IntegralComplexToBoolean; | |
| 708 | pub const ZigClangCK_IntegralComplexCast = enum_ZigClangCK._IntegralComplexCast; | |
| 709 | pub const ZigClangCK_IntegralComplexToFloatingComplex = enum_ZigClangCK._IntegralComplexToFloatingComplex; | |
| 710 | pub const ZigClangCK_ARCProduceObject = enum_ZigClangCK._ARCProduceObject; | |
| 711 | pub const ZigClangCK_ARCConsumeObject = enum_ZigClangCK._ARCConsumeObject; | |
| 712 | pub const ZigClangCK_ARCReclaimReturnedObject = enum_ZigClangCK._ARCReclaimReturnedObject; | |
| 713 | pub const ZigClangCK_ARCExtendBlockObject = enum_ZigClangCK._ARCExtendBlockObject; | |
| 714 | pub const ZigClangCK_AtomicToNonAtomic = enum_ZigClangCK._AtomicToNonAtomic; | |
| 715 | pub const ZigClangCK_NonAtomicToAtomic = enum_ZigClangCK._NonAtomicToAtomic; | |
| 716 | pub const ZigClangCK_CopyAndAutoreleaseBlockObject = enum_ZigClangCK._CopyAndAutoreleaseBlockObject; | |
| 717 | pub const ZigClangCK_BuiltinFnToFnPtr = enum_ZigClangCK._BuiltinFnToFnPtr; | |
| 718 | pub const ZigClangCK_ZeroToOCLOpaqueType = enum_ZigClangCK._ZeroToOCLOpaqueType; | |
| 719 | pub const ZigClangCK_AddressSpaceConversion = enum_ZigClangCK._AddressSpaceConversion; | |
| 720 | pub const ZigClangCK_IntToOCLSampler = enum_ZigClangCK._IntToOCLSampler; | |
| 721 | pub const enum_ZigClangCK = extern enum { | |
| 722 | _Dependent, | |
| 723 | _BitCast, | |
| 724 | _LValueBitCast, | |
| 725 | _LValueToRValue, | |
| 726 | _NoOp, | |
| 727 | _BaseToDerived, | |
| 728 | _DerivedToBase, | |
| 729 | _UncheckedDerivedToBase, | |
| 730 | _Dynamic, | |
| 731 | _ToUnion, | |
| 732 | _ArrayToPointerDecay, | |
| 733 | _FunctionToPointerDecay, | |
| 734 | _NullToPointer, | |
| 735 | _NullToMemberPointer, | |
| 736 | _BaseToDerivedMemberPointer, | |
| 737 | _DerivedToBaseMemberPointer, | |
| 738 | _MemberPointerToBoolean, | |
| 739 | _ReinterpretMemberPointer, | |
| 740 | _UserDefinedConversion, | |
| 741 | _ConstructorConversion, | |
| 742 | _IntegralToPointer, | |
| 743 | _PointerToIntegral, | |
| 744 | _PointerToBoolean, | |
| 745 | _ToVoid, | |
| 746 | _VectorSplat, | |
| 747 | _IntegralCast, | |
| 748 | _IntegralToBoolean, | |
| 749 | _IntegralToFloating, | |
| 750 | _FixedPointCast, | |
| 751 | _FixedPointToBoolean, | |
| 752 | _FloatingToIntegral, | |
| 753 | _FloatingToBoolean, | |
| 754 | _BooleanToSignedIntegral, | |
| 755 | _FloatingCast, | |
| 756 | _CPointerToObjCPointerCast, | |
| 757 | _BlockPointerToObjCPointerCast, | |
| 758 | _AnyPointerToBlockPointerCast, | |
| 759 | _ObjCObjectLValueCast, | |
| 760 | _FloatingRealToComplex, | |
| 761 | _FloatingComplexToReal, | |
| 762 | _FloatingComplexToBoolean, | |
| 763 | _FloatingComplexCast, | |
| 764 | _FloatingComplexToIntegralComplex, | |
| 765 | _IntegralRealToComplex, | |
| 766 | _IntegralComplexToReal, | |
| 767 | _IntegralComplexToBoolean, | |
| 768 | _IntegralComplexCast, | |
| 769 | _IntegralComplexToFloatingComplex, | |
| 770 | _ARCProduceObject, | |
| 771 | _ARCConsumeObject, | |
| 772 | _ARCReclaimReturnedObject, | |
| 773 | _ARCExtendBlockObject, | |
| 774 | _AtomicToNonAtomic, | |
| 775 | _NonAtomicToAtomic, | |
| 776 | _CopyAndAutoreleaseBlockObject, | |
| 777 | _BuiltinFnToFnPtr, | |
| 778 | _ZeroToOCLOpaqueType, | |
| 779 | _AddressSpaceConversion, | |
| 780 | _IntToOCLSampler, | |
| 781 | }; | |
| 782 | pub const ZigClangAPValueUninitialized = enum_ZigClangAPValueKind.ZigClangAPValueUninitialized; | |
| 783 | pub const ZigClangAPValueInt = enum_ZigClangAPValueKind.ZigClangAPValueInt; | |
| 784 | pub const ZigClangAPValueFloat = enum_ZigClangAPValueKind.ZigClangAPValueFloat; | |
| 785 | pub const ZigClangAPValueComplexInt = enum_ZigClangAPValueKind.ZigClangAPValueComplexInt; | |
| 786 | pub const ZigClangAPValueComplexFloat = enum_ZigClangAPValueKind.ZigClangAPValueComplexFloat; | |
| 787 | pub const ZigClangAPValueLValue = enum_ZigClangAPValueKind.ZigClangAPValueLValue; | |
| 788 | pub const ZigClangAPValueVector = enum_ZigClangAPValueKind.ZigClangAPValueVector; | |
| 789 | pub const ZigClangAPValueArray = enum_ZigClangAPValueKind.ZigClangAPValueArray; | |
| 790 | pub const ZigClangAPValueStruct = enum_ZigClangAPValueKind.ZigClangAPValueStruct; | |
| 791 | pub const ZigClangAPValueUnion = enum_ZigClangAPValueKind.ZigClangAPValueUnion; | |
| 792 | pub const ZigClangAPValueMemberPointer = enum_ZigClangAPValueKind.ZigClangAPValueMemberPointer; | |
| 793 | pub const ZigClangAPValueAddrLabelDiff = enum_ZigClangAPValueKind.ZigClangAPValueAddrLabelDiff; | |
| 794 | pub const enum_ZigClangAPValueKind = extern enum { | |
| 795 | ZigClangAPValueUninitialized, | |
| 796 | ZigClangAPValueInt, | |
| 797 | ZigClangAPValueFloat, | |
| 798 | ZigClangAPValueComplexInt, | |
| 799 | ZigClangAPValueComplexFloat, | |
| 800 | ZigClangAPValueLValue, | |
| 801 | ZigClangAPValueVector, | |
| 802 | ZigClangAPValueArray, | |
| 803 | ZigClangAPValueStruct, | |
| 804 | ZigClangAPValueUnion, | |
| 805 | ZigClangAPValueMemberPointer, | |
| 806 | ZigClangAPValueAddrLabelDiff, | |
| 807 | }; | |
| 808 | pub extern fn ZigClangSourceManager_getSpellingLoc(arg0: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation; | |
| 809 | pub extern fn ZigClangSourceManager_getFilename(arg0: ?*const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) [*c]const u8; | |
| 810 | pub extern fn ZigClangSourceManager_getSpellingLineNumber(arg0: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; | |
| 811 | pub extern fn ZigClangSourceManager_getSpellingColumnNumber(arg0: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; | |
| 812 | pub extern fn ZigClangSourceManager_getCharacterData(arg0: ?*const struct_ZigClangSourceManager, SL: struct_ZigClangSourceLocation) [*c]const u8; | |
| 813 | pub extern fn ZigClangASTContext_getPointerType(arg0: ?*const struct_ZigClangASTContext, T: struct_ZigClangQualType) struct_ZigClangQualType; | |
| 814 | pub extern fn ZigClangASTUnit_getASTContext(arg0: ?*struct_ZigClangASTUnit) ?*struct_ZigClangASTContext; | |
| 815 | pub extern fn ZigClangASTUnit_getSourceManager(arg0: ?*struct_ZigClangASTUnit) ?*struct_ZigClangSourceManager; | |
| 816 | pub extern fn ZigClangASTUnit_visitLocalTopLevelDecls(arg0: ?*struct_ZigClangASTUnit, context: ?*c_void, Fn: ?extern fn (?*c_void, ?*const struct_ZigClangDecl) bool) bool; | |
| 817 | pub extern fn ZigClangRecordType_getDecl(record_ty: ?*const struct_ZigClangRecordType) ?*const struct_ZigClangRecordDecl; | |
| 818 | pub extern fn ZigClangEnumType_getDecl(record_ty: ?*const struct_ZigClangEnumType) ?*const struct_ZigClangEnumDecl; | |
| 819 | pub extern fn ZigClangRecordDecl_getCanonicalDecl(record_decl: ?*const struct_ZigClangRecordDecl) ?*const struct_ZigClangTagDecl; | |
| 820 | pub extern fn ZigClangEnumDecl_getCanonicalDecl(arg0: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangTagDecl; | |
| 821 | pub extern fn ZigClangTypedefNameDecl_getCanonicalDecl(arg0: ?*const struct_ZigClangTypedefNameDecl) ?*const struct_ZigClangTypedefNameDecl; | |
| 822 | pub extern fn ZigClangRecordDecl_getDefinition(arg0: ?*const struct_ZigClangRecordDecl) ?*const struct_ZigClangRecordDecl; | |
| 823 | pub extern fn ZigClangEnumDecl_getDefinition(arg0: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangEnumDecl; | |
| 824 | pub extern fn ZigClangRecordDecl_getLocation(arg0: ?*const struct_ZigClangRecordDecl) struct_ZigClangSourceLocation; | |
| 825 | pub extern fn ZigClangEnumDecl_getLocation(arg0: ?*const struct_ZigClangEnumDecl) struct_ZigClangSourceLocation; | |
| 826 | pub extern fn ZigClangTypedefNameDecl_getLocation(arg0: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangSourceLocation; | |
| 827 | pub extern fn ZigClangRecordDecl_isUnion(record_decl: ?*const struct_ZigClangRecordDecl) bool; | |
| 828 | pub extern fn ZigClangRecordDecl_isStruct(record_decl: ?*const struct_ZigClangRecordDecl) bool; | |
| 829 | pub extern fn ZigClangRecordDecl_isAnonymousStructOrUnion(record_decl: ?*const struct_ZigClangRecordDecl) bool; | |
| 830 | pub extern fn ZigClangEnumDecl_getIntegerType(arg0: ?*const struct_ZigClangEnumDecl) struct_ZigClangQualType; | |
| 831 | pub extern fn ZigClangDecl_getName_bytes_begin(decl: ?*const struct_ZigClangDecl) [*c]const u8; | |
| 832 | pub extern fn ZigClangSourceLocation_eq(a: struct_ZigClangSourceLocation, b: struct_ZigClangSourceLocation) bool; | |
| 833 | pub extern fn ZigClangTypedefType_getDecl(arg0: ?*const struct_ZigClangTypedefType) ?*const struct_ZigClangTypedefNameDecl; | |
| 834 | pub extern fn ZigClangTypedefNameDecl_getUnderlyingType(arg0: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangQualType; | |
| 835 | pub extern fn ZigClangQualType_getCanonicalType(arg0: struct_ZigClangQualType) struct_ZigClangQualType; | |
| 836 | pub extern fn ZigClangQualType_getTypePtr(arg0: struct_ZigClangQualType) ?*const struct_ZigClangType; | |
| 837 | pub extern fn ZigClangQualType_addConst(arg0: [*c]struct_ZigClangQualType) void; | |
| 838 | pub extern fn ZigClangQualType_eq(arg0: struct_ZigClangQualType, arg1: struct_ZigClangQualType) bool; | |
| 839 | pub extern fn ZigClangQualType_isConstQualified(arg0: struct_ZigClangQualType) bool; | |
| 840 | pub extern fn ZigClangQualType_isVolatileQualified(arg0: struct_ZigClangQualType) bool; | |
| 841 | pub extern fn ZigClangQualType_isRestrictQualified(arg0: struct_ZigClangQualType) bool; | |
| 842 | pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) enum_ZigClangTypeClass; | |
| 843 | pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool; | |
| 844 | pub extern fn ZigClangType_getTypeClassName(self: ?*const struct_ZigClangType) [*c]const u8; | |
| 845 | pub extern fn ZigClangStmt_getBeginLoc(self: ?*const struct_ZigClangStmt) struct_ZigClangSourceLocation; | |
| 846 | pub extern fn ZigClangStmt_getStmtClass(self: ?*const struct_ZigClangStmt) enum_ZigClangStmtClass; | |
| 847 | pub extern fn ZigClangStmt_classof_Expr(self: ?*const struct_ZigClangStmt) bool; | |
| 848 | pub extern fn ZigClangExpr_getStmtClass(self: ?*const struct_ZigClangExpr) enum_ZigClangStmtClass; | |
| 849 | pub extern fn ZigClangExpr_getType(self: ?*const struct_ZigClangExpr) struct_ZigClangQualType; | |
| 850 | pub extern fn ZigClangExpr_getBeginLoc(self: ?*const struct_ZigClangExpr) struct_ZigClangSourceLocation; | |
| 851 | pub extern fn ZigClangAPValue_getKind(self: ?*const struct_ZigClangAPValue) enum_ZigClangAPValueKind; | |
| 852 | pub extern fn ZigClangAPValue_getInt(self: ?*const struct_ZigClangAPValue) ?*const struct_ZigClangAPSInt; | |
| 853 | pub extern fn ZigClangAPValue_getArrayInitializedElts(self: ?*const struct_ZigClangAPValue) c_uint; | |
| 854 | pub extern fn ZigClangAPValue_getArrayInitializedElt(self: ?*const struct_ZigClangAPValue, i: c_uint) ?*const struct_ZigClangAPValue; | |
| 855 | pub extern fn ZigClangAPValue_getArrayFiller(self: ?*const struct_ZigClangAPValue) ?*const struct_ZigClangAPValue; | |
| 856 | pub extern fn ZigClangAPValue_getArraySize(self: ?*const struct_ZigClangAPValue) c_uint; | |
| 857 | pub extern fn ZigClangAPValue_getLValueBase(self: ?*const struct_ZigClangAPValue) struct_ZigClangAPValueLValueBase; | |
| 858 | pub extern fn ZigClangAPSInt_isSigned(self: ?*const struct_ZigClangAPSInt) bool; | |
| 859 | pub extern fn ZigClangAPSInt_isNegative(self: ?*const struct_ZigClangAPSInt) bool; | |
| 860 | pub extern fn ZigClangAPSInt_negate(self: ?*const struct_ZigClangAPSInt) ?*const struct_ZigClangAPSInt; | |
| 861 | pub extern fn ZigClangAPSInt_free(self: ?*const struct_ZigClangAPSInt) void; | |
| 862 | pub extern fn ZigClangAPSInt_getRawData(self: ?*const struct_ZigClangAPSInt) [*c]const u64; | |
| 863 | pub extern fn ZigClangAPSInt_getNumWords(self: ?*const struct_ZigClangAPSInt) c_uint; | |
| 864 | pub extern fn ZigClangAPValueLValueBase_dyn_cast_Expr(self: struct_ZigClangAPValueLValueBase) ?*const struct_ZigClangExpr; | |
| 865 | pub extern fn ZigClangASTUnit_delete(arg0: ?*struct_ZigClangASTUnit) void; | |
| 866 | pub const ZigClangSourceLocation = struct_ZigClangSourceLocation; | |
| 867 | pub const ZigClangQualType = struct_ZigClangQualType; | |
| 868 | pub const ZigClangAPValueLValueBase = struct_ZigClangAPValueLValueBase; | |
| 869 | pub const ZigClangAPValue = struct_ZigClangAPValue; | |
| 870 | pub const ZigClangAPSInt = struct_ZigClangAPSInt; | |
| 871 | pub const ZigClangASTContext = struct_ZigClangASTContext; | |
| 872 | pub const ZigClangASTUnit = struct_ZigClangASTUnit; | |
| 873 | pub const ZigClangArraySubscriptExpr = struct_ZigClangArraySubscriptExpr; | |
| 874 | pub const ZigClangArrayType = struct_ZigClangArrayType; | |
| 875 | pub const ZigClangAttributedType = struct_ZigClangAttributedType; | |
| 876 | pub const ZigClangBinaryOperator = struct_ZigClangBinaryOperator; | |
| 877 | pub const ZigClangBreakStmt = struct_ZigClangBreakStmt; | |
| 878 | pub const ZigClangBuiltinType = struct_ZigClangBuiltinType; | |
| 879 | pub const ZigClangCStyleCastExpr = struct_ZigClangCStyleCastExpr; | |
| 880 | pub const ZigClangCallExpr = struct_ZigClangCallExpr; | |
| 881 | pub const ZigClangCaseStmt = struct_ZigClangCaseStmt; | |
| 882 | pub const ZigClangCompoundAssignOperator = struct_ZigClangCompoundAssignOperator; | |
| 883 | pub const ZigClangCompoundStmt = struct_ZigClangCompoundStmt; | |
| 884 | pub const ZigClangConditionalOperator = struct_ZigClangConditionalOperator; | |
| 885 | pub const ZigClangConstantArrayType = struct_ZigClangConstantArrayType; | |
| 886 | pub const ZigClangContinueStmt = struct_ZigClangContinueStmt; | |
| 887 | pub const ZigClangDecayedType = struct_ZigClangDecayedType; | |
| 888 | pub const ZigClangDecl = struct_ZigClangDecl; | |
| 889 | pub const ZigClangDeclRefExpr = struct_ZigClangDeclRefExpr; | |
| 890 | pub const ZigClangDeclStmt = struct_ZigClangDeclStmt; | |
| 891 | pub const ZigClangDefaultStmt = struct_ZigClangDefaultStmt; | |
| 892 | pub const ZigClangDiagnosticOptions = struct_ZigClangDiagnosticOptions; | |
| 893 | pub const ZigClangDiagnosticsEngine = struct_ZigClangDiagnosticsEngine; | |
| 894 | pub const ZigClangDoStmt = struct_ZigClangDoStmt; | |
| 895 | pub const ZigClangElaboratedType = struct_ZigClangElaboratedType; | |
| 896 | pub const ZigClangEnumConstantDecl = struct_ZigClangEnumConstantDecl; | |
| 897 | pub const ZigClangEnumDecl = struct_ZigClangEnumDecl; | |
| 898 | pub const ZigClangEnumType = struct_ZigClangEnumType; | |
| 899 | pub const ZigClangExpr = struct_ZigClangExpr; | |
| 900 | pub const ZigClangFieldDecl = struct_ZigClangFieldDecl; | |
| 901 | pub const ZigClangFileID = struct_ZigClangFileID; | |
| 902 | pub const ZigClangForStmt = struct_ZigClangForStmt; | |
| 903 | pub const ZigClangFullSourceLoc = struct_ZigClangFullSourceLoc; | |
| 904 | pub const ZigClangFunctionDecl = struct_ZigClangFunctionDecl; | |
| 905 | pub const ZigClangFunctionProtoType = struct_ZigClangFunctionProtoType; | |
| 906 | pub const ZigClangIfStmt = struct_ZigClangIfStmt; | |
| 907 | pub const ZigClangImplicitCastExpr = struct_ZigClangImplicitCastExpr; | |
| 908 | pub const ZigClangIncompleteArrayType = struct_ZigClangIncompleteArrayType; | |
| 909 | pub const ZigClangIntegerLiteral = struct_ZigClangIntegerLiteral; | |
| 910 | pub const ZigClangMacroDefinitionRecord = struct_ZigClangMacroDefinitionRecord; | |
| 911 | pub const ZigClangMemberExpr = struct_ZigClangMemberExpr; | |
| 912 | pub const ZigClangNamedDecl = struct_ZigClangNamedDecl; | |
| 913 | pub const ZigClangNone = struct_ZigClangNone; | |
| 914 | pub const ZigClangPCHContainerOperations = struct_ZigClangPCHContainerOperations; | |
| 915 | pub const ZigClangParenExpr = struct_ZigClangParenExpr; | |
| 916 | pub const ZigClangParenType = struct_ZigClangParenType; | |
| 917 | pub const ZigClangParmVarDecl = struct_ZigClangParmVarDecl; | |
| 918 | pub const ZigClangPointerType = struct_ZigClangPointerType; | |
| 919 | pub const ZigClangPreprocessedEntity = struct_ZigClangPreprocessedEntity; | |
| 920 | pub const ZigClangRecordDecl = struct_ZigClangRecordDecl; | |
| 921 | pub const ZigClangRecordType = struct_ZigClangRecordType; | |
| 922 | pub const ZigClangReturnStmt = struct_ZigClangReturnStmt; | |
| 923 | pub const ZigClangSkipFunctionBodiesScope = struct_ZigClangSkipFunctionBodiesScope; | |
| 924 | pub const ZigClangSourceManager = struct_ZigClangSourceManager; | |
| 925 | pub const ZigClangSourceRange = struct_ZigClangSourceRange; | |
| 926 | pub const ZigClangStmt = struct_ZigClangStmt; | |
| 927 | pub const ZigClangStorageClass = struct_ZigClangStorageClass; | |
| 928 | pub const ZigClangStringLiteral = struct_ZigClangStringLiteral; | |
| 929 | pub const ZigClangStringRef = struct_ZigClangStringRef; | |
| 930 | pub const ZigClangSwitchStmt = struct_ZigClangSwitchStmt; | |
| 931 | pub const ZigClangTagDecl = struct_ZigClangTagDecl; | |
| 932 | pub const ZigClangType = struct_ZigClangType; | |
| 933 | pub const ZigClangTypedefNameDecl = struct_ZigClangTypedefNameDecl; | |
| 934 | pub const ZigClangTypedefType = struct_ZigClangTypedefType; | |
| 935 | pub const ZigClangUnaryExprOrTypeTraitExpr = struct_ZigClangUnaryExprOrTypeTraitExpr; | |
| 936 | pub const ZigClangUnaryOperator = struct_ZigClangUnaryOperator; | |
| 937 | pub const ZigClangValueDecl = struct_ZigClangValueDecl; | |
| 938 | pub const ZigClangVarDecl = struct_ZigClangVarDecl; | |
| 939 | pub const ZigClangWhileStmt = struct_ZigClangWhileStmt; | |
| 940 | pub const ZigClangBO = enum_ZigClangBO; | |
| 941 | pub const ZigClangUO = enum_ZigClangUO; | |
| 942 | pub const ZigClangTypeClass = enum_ZigClangTypeClass; | |
| 943 | pub const ZigClangStmtClass = enum_ZigClangStmtClass; | |
| 944 | pub const ZigClangCK = enum_ZigClangCK; | |
| 945 | pub const ZigClangAPValueKind = enum_ZigClangAPValueKind; | |
| 946 | ||
| 947 | pub const Stage2ErrorMsg = extern struct { | |
| 948 | filename_ptr: ?[*]const u8, | |
| 949 | filename_len: usize, | |
| 950 | msg_ptr: [*]const u8, | |
| 951 | msg_len: usize, | |
| 952 | // valid until the ASTUnit is freed | |
| 953 | source: ?[*]const u8, | |
| 954 | // 0 based | |
| 955 | line: c_uint, | |
| 956 | // 0 based | |
| 957 | column: c_uint, | |
| 958 | // byte offset into source | |
| 959 | offset: c_uint, | |
| 960 | }; | |
| 961 | pub extern fn ZigClangErrorMsg_delete(ptr: [*c]Stage2ErrorMsg, len: usize) void; | |
| 962 | ||
| 963 | pub extern fn ZigClangLoadFromCommandLine( | |
| 964 | args_begin: [*]?[*]const u8, | |
| 965 | args_end: [*]?[*]const u8, | |
| 966 | errors_ptr: *[*]Stage2ErrorMsg, | |
| 967 | errors_len: *usize, | |
| 968 | resources_path: [*c]const u8, | |
| 969 | ) ?*ZigClangASTUnit; |
src-self-hosted/main.zig+17-1| ... | ... | @@ -858,7 +858,23 @@ fn cmdHelp(allocator: *Allocator, args: []const []const u8) !void { |
| 858 | 858 | try stdout.write(usage); |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | const info_zen = @import("stage1.zig").info_zen; | |
| 861 | pub const info_zen = | |
| 862 | \\ | |
| 863 | \\ * Communicate intent precisely. | |
| 864 | \\ * Edge cases matter. | |
| 865 | \\ * Favor reading code over writing code. | |
| 866 | \\ * Only one obvious way to do things. | |
| 867 | \\ * Runtime crashes are better than bugs. | |
| 868 | \\ * Compile errors are better than runtime crashes. | |
| 869 | \\ * Incremental improvements. | |
| 870 | \\ * Avoid local maximums. | |
| 871 | \\ * Reduce the amount one must remember. | |
| 872 | \\ * Minimize energy spent on coding style. | |
| 873 | \\ * Together we serve end users. | |
| 874 | \\ | |
| 875 | \\ | |
| 876 | ; | |
| 877 | ||
| 862 | 878 | fn cmdZen(allocator: *Allocator, args: []const []const u8) !void { |
| 863 | 879 | try stdout.write(info_zen); |
| 864 | 880 | } |
src-self-hosted/stage1.zig+110-19| ... | ... | @@ -1,31 +1,122 @@ |
| 1 | 1 | // This is Zig code that is used by both stage1 and stage2. |
| 2 | 2 | // The prototypes in src/userland.h must match these definitions. |
| 3 | comptime { | |
| 4 | _ = @import("translate_c.zig"); | |
| 5 | } | |
| 6 | 3 | |
| 7 | pub const info_zen = | |
| 8 | \\ | |
| 9 | \\ * Communicate intent precisely. | |
| 10 | \\ * Edge cases matter. | |
| 11 | \\ * Favor reading code over writing code. | |
| 12 | \\ * Only one obvious way to do things. | |
| 13 | \\ * Runtime crashes are better than bugs. | |
| 14 | \\ * Compile errors are better than runtime crashes. | |
| 15 | \\ * Incremental improvements. | |
| 16 | \\ * Avoid local maximums. | |
| 17 | \\ * Reduce the amount one must remember. | |
| 18 | \\ * Minimize energy spent on coding style. | |
| 19 | \\ * Together we serve end users. | |
| 20 | \\ | |
| 21 | \\ | |
| 22 | ; | |
| 4 | const std = @import("std"); | |
| 23 | 5 | |
| 6 | // ABI warning | |
| 24 | 7 | export fn stage2_zen(ptr: *[*]const u8, len: *usize) void { |
| 8 | const info_zen = @import("main.zig").info_zen; | |
| 25 | 9 | ptr.* = &info_zen; |
| 26 | 10 | len.* = info_zen.len; |
| 27 | 11 | } |
| 28 | 12 | |
| 13 | // ABI warning | |
| 29 | 14 | export fn stage2_panic(ptr: [*]const u8, len: usize) void { |
| 30 | 15 | @panic(ptr[0..len]); |
| 31 | 16 | } |
| 17 | ||
| 18 | // ABI warning | |
| 19 | const TranslateMode = extern enum { | |
| 20 | import, | |
| 21 | translate, | |
| 22 | }; | |
| 23 | ||
| 24 | // ABI warning | |
| 25 | const Error = extern enum { | |
| 26 | None, | |
| 27 | OutOfMemory, | |
| 28 | InvalidFormat, | |
| 29 | SemanticAnalyzeFail, | |
| 30 | AccessDenied, | |
| 31 | Interrupted, | |
| 32 | SystemResources, | |
| 33 | FileNotFound, | |
| 34 | FileSystem, | |
| 35 | FileTooBig, | |
| 36 | DivByZero, | |
| 37 | Overflow, | |
| 38 | PathAlreadyExists, | |
| 39 | Unexpected, | |
| 40 | ExactDivRemainder, | |
| 41 | NegativeDenominator, | |
| 42 | ShiftedOutOneBits, | |
| 43 | CCompileErrors, | |
| 44 | EndOfFile, | |
| 45 | IsDir, | |
| 46 | NotDir, | |
| 47 | UnsupportedOperatingSystem, | |
| 48 | SharingViolation, | |
| 49 | PipeBusy, | |
| 50 | PrimitiveTypeNotFound, | |
| 51 | CacheUnavailable, | |
| 52 | PathTooLong, | |
| 53 | CCompilerCannotFindFile, | |
| 54 | ReadingDepFile, | |
| 55 | InvalidDepFile, | |
| 56 | MissingArchitecture, | |
| 57 | MissingOperatingSystem, | |
| 58 | UnknownArchitecture, | |
| 59 | UnknownOperatingSystem, | |
| 60 | UnknownABI, | |
| 61 | InvalidFilename, | |
| 62 | DiskQuota, | |
| 63 | DiskSpace, | |
| 64 | UnexpectedWriteFailure, | |
| 65 | UnexpectedSeekFailure, | |
| 66 | UnexpectedFileTruncationFailure, | |
| 67 | Unimplemented, | |
| 68 | OperationAborted, | |
| 69 | BrokenPipe, | |
| 70 | NoSpaceLeft, | |
| 71 | }; | |
| 72 | ||
| 73 | const FILE = std.c.FILE; | |
| 74 | const ast = std.zig.ast; | |
| 75 | const translate_c = @import("translate_c.zig"); | |
| 76 | ||
| 77 | /// Args should have a null terminating last arg. | |
| 78 | export fn stage2_translate_c( | |
| 79 | out_ast: **ast.Tree, | |
| 80 | out_errors_ptr: *[*]translate_c.ClangErrMsg, | |
| 81 | out_errors_len: *usize, | |
| 82 | args_begin: [*]?[*]const u8, | |
| 83 | args_end: [*]?[*]const u8, | |
| 84 | mode: TranslateMode, | |
| 85 | resources_path: [*]const u8, | |
| 86 | ) Error { | |
| 87 | var errors: []translate_c.ClangErrMsg = undefined; | |
| 88 | out_ast.* = translate_c.translate(args_begin, args_end, switch (mode) { | |
| 89 | .import => translate_c.Mode.import, | |
| 90 | .translate => translate_c.Mode.translate, | |
| 91 | }, &errors, resources_path) catch |err| switch (err) { | |
| 92 | error.Unimplemented => return Error.Unimplemented, | |
| 93 | error.SemanticAnalyzeFail => { | |
| 94 | out_errors_ptr.* = errors.ptr; | |
| 95 | out_errors_len.* = errors.len; | |
| 96 | return Error.CCompileErrors; | |
| 97 | }, | |
| 98 | error.OutOfMemory => return Error.OutOfMemory, | |
| 99 | }; | |
| 100 | return Error.None; | |
| 101 | } | |
| 102 | ||
| 103 | export fn stage2_free_clang_errors(errors_ptr: [*]translate_c.ClangErrMsg, errors_len: usize) void { | |
| 104 | translate_c.freeErrors(errors_ptr[0..errors_len]); | |
| 105 | } | |
| 106 | ||
| 107 | export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error { | |
| 108 | const c_out_stream = &std.io.COutStream.init(output_file).stream; | |
| 109 | _ = std.zig.render(std.heap.c_allocator, c_out_stream, tree) catch |e| switch (e) { | |
| 110 | error.SystemResources => return Error.SystemResources, | |
| 111 | error.OperationAborted => return Error.OperationAborted, | |
| 112 | error.BrokenPipe => return Error.BrokenPipe, | |
| 113 | error.DiskQuota => return Error.DiskQuota, | |
| 114 | error.FileTooBig => return Error.FileTooBig, | |
| 115 | error.NoSpaceLeft => return Error.NoSpaceLeft, | |
| 116 | error.AccessDenied => return Error.AccessDenied, | |
| 117 | error.OutOfMemory => return Error.OutOfMemory, | |
| 118 | error.Unexpected => return Error.Unexpected, | |
| 119 | error.InputOutput => return Error.FileSystem, | |
| 120 | }; | |
| 121 | return Error.None; | |
| 122 | } |
src-self-hosted/translate_c.zig+32-2| ... | ... | @@ -2,7 +2,37 @@ |
| 2 | 2 | // and stage2. Currently it's not used by anything, as it's not feature complete. |
| 3 | 3 | |
| 4 | 4 | const std = @import("std"); |
| 5 | const ast = std.zig.ast; | |
| 6 | use @import("clang.zig"); | |
| 5 | 7 | |
| 6 | export fn stage2_translate_c() void { | |
| 7 | std.debug.panic("unimplemented"); | |
| 8 | pub const Mode = enum { | |
| 9 | import, | |
| 10 | translate, | |
| 11 | }; | |
| 12 | ||
| 13 | pub const ClangErrMsg = Stage2ErrorMsg; | |
| 14 | ||
| 15 | pub fn translate( | |
| 16 | args_begin: [*]?[*]const u8, | |
| 17 | args_end: [*]?[*]const u8, | |
| 18 | mode: Mode, | |
| 19 | errors: *[]ClangErrMsg, | |
| 20 | resources_path: [*]const u8, | |
| 21 | ) !*ast.Tree { | |
| 22 | const ast_unit = ZigClangLoadFromCommandLine( | |
| 23 | args_begin, | |
| 24 | args_end, | |
| 25 | &errors.ptr, | |
| 26 | &errors.len, | |
| 27 | resources_path, | |
| 28 | ) orelse { | |
| 29 | if (errors.len == 0) return error.OutOfMemory; | |
| 30 | return error.SemanticAnalyzeFail; | |
| 31 | }; | |
| 32 | ||
| 33 | return error.Unimplemented; | |
| 34 | } | |
| 35 | ||
| 36 | pub fn freeErrors(errors: []ClangErrMsg) void { | |
| 37 | ZigClangErrorMsg_delete(errors.ptr, errors.len); | |
| 8 | 38 | } |
src/analyze.cpp+1-1| ... | ... | @@ -3725,7 +3725,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { |
| 3725 | 3725 | } |
| 3726 | 3726 | if (g->verbose_ir) { |
| 3727 | 3727 | fprintf(stderr, "\n"); |
| 3728 | ast_render(g, stderr, fn_table_entry->body_node, 4); | |
| 3728 | ast_render(stderr, fn_table_entry->body_node, 4); | |
| 3729 | 3729 | fprintf(stderr, "\n{ // (IR)\n"); |
| 3730 | 3730 | ir_print(g, stderr, &fn_table_entry->ir_executable, 4); |
| 3731 | 3731 | fprintf(stderr, "}\n"); |
src/analyze.hpp+2| ... | ... | @@ -247,4 +247,6 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose |
| 247 | 247 | LLVMTypeRef get_llvm_type(CodeGen *g, ZigType *type); |
| 248 | 248 | ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type); |
| 249 | 249 | |
| 250 | void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, bool translate_c); | |
| 251 | ||
| 250 | 252 | #endif |
src/ast_render.cpp+1-3| ... | ... | @@ -296,7 +296,6 @@ void ast_print(FILE *f, AstNode *node, int indent) { |
| 296 | 296 | |
| 297 | 297 | |
| 298 | 298 | struct AstRender { |
| 299 | CodeGen *codegen; | |
| 300 | 299 | int indent; |
| 301 | 300 | int indent_size; |
| 302 | 301 | FILE *f; |
| ... | ... | @@ -1170,9 +1169,8 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 1170 | 1169 | } |
| 1171 | 1170 | |
| 1172 | 1171 | |
| 1173 | void ast_render(CodeGen *codegen, FILE *f, AstNode *node, int indent_size) { | |
| 1172 | void ast_render(FILE *f, AstNode *node, int indent_size) { | |
| 1174 | 1173 | AstRender ar = {0}; |
| 1175 | ar.codegen = codegen; | |
| 1176 | 1174 | ar.f = f; |
| 1177 | 1175 | ar.indent_size = indent_size; |
| 1178 | 1176 | ar.indent = 0; |
src/ast_render.hpp+1-1| ... | ... | @@ -15,6 +15,6 @@ |
| 15 | 15 | |
| 16 | 16 | void ast_print(FILE *f, AstNode *node, int indent); |
| 17 | 17 | |
| 18 | void ast_render(CodeGen *codegen, FILE *f, AstNode *node, int indent_size); | |
| 18 | void ast_render(FILE *f, AstNode *node, int indent_size); | |
| 19 | 19 | |
| 20 | 20 | #endif |
src/codegen.cpp+164-107| ... | ... | @@ -8153,7 +8153,126 @@ static void detect_libc(CodeGen *g) { |
| 8153 | 8153 | } |
| 8154 | 8154 | } |
| 8155 | 8155 | |
| 8156 | AstNode *codegen_translate_c(CodeGen *g, Buf *full_path, bool use_userland_implementation) { | |
| 8156 | // does not add the "cc" arg | |
| 8157 | void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, bool translate_c) { | |
| 8158 | if (translate_c) { | |
| 8159 | args.append("-x"); | |
| 8160 | args.append("c"); | |
| 8161 | } | |
| 8162 | ||
| 8163 | if (out_dep_path != nullptr) { | |
| 8164 | args.append("-MD"); | |
| 8165 | args.append("-MV"); | |
| 8166 | args.append("-MF"); | |
| 8167 | args.append(out_dep_path); | |
| 8168 | } | |
| 8169 | ||
| 8170 | args.append("-nostdinc"); | |
| 8171 | args.append("-fno-spell-checking"); | |
| 8172 | ||
| 8173 | if (translate_c) { | |
| 8174 | // this gives us access to preprocessing entities, presumably at | |
| 8175 | // the cost of performance | |
| 8176 | args.append("-Xclang"); | |
| 8177 | args.append("-detailed-preprocessing-record"); | |
| 8178 | } else { | |
| 8179 | switch (g->err_color) { | |
| 8180 | case ErrColorAuto: | |
| 8181 | break; | |
| 8182 | case ErrColorOff: | |
| 8183 | args.append("-fno-color-diagnostics"); | |
| 8184 | args.append("-fno-caret-diagnostics"); | |
| 8185 | break; | |
| 8186 | case ErrColorOn: | |
| 8187 | args.append("-fcolor-diagnostics"); | |
| 8188 | args.append("-fcaret-diagnostics"); | |
| 8189 | break; | |
| 8190 | } | |
| 8191 | } | |
| 8192 | ||
| 8193 | args.append("-isystem"); | |
| 8194 | args.append(buf_ptr(g->zig_c_headers_dir)); | |
| 8195 | ||
| 8196 | for (size_t i = 0; i < g->libc_include_dir_len; i += 1) { | |
| 8197 | Buf *include_dir = g->libc_include_dir_list[i]; | |
| 8198 | args.append("-isystem"); | |
| 8199 | args.append(buf_ptr(include_dir)); | |
| 8200 | } | |
| 8201 | ||
| 8202 | if (g->zig_target->is_native) { | |
| 8203 | args.append("-march=native"); | |
| 8204 | } else { | |
| 8205 | args.append("-target"); | |
| 8206 | args.append(buf_ptr(&g->triple_str)); | |
| 8207 | } | |
| 8208 | if (g->zig_target->os == OsFreestanding) { | |
| 8209 | args.append("-ffreestanding"); | |
| 8210 | } | |
| 8211 | ||
| 8212 | if (!g->strip_debug_symbols) { | |
| 8213 | args.append("-g"); | |
| 8214 | } | |
| 8215 | ||
| 8216 | switch (g->build_mode) { | |
| 8217 | case BuildModeDebug: | |
| 8218 | // windows c runtime requires -D_DEBUG if using debug libraries | |
| 8219 | args.append("-D_DEBUG"); | |
| 8220 | ||
| 8221 | if (g->libc_link_lib != nullptr) { | |
| 8222 | args.append("-fstack-protector-strong"); | |
| 8223 | args.append("--param"); | |
| 8224 | args.append("ssp-buffer-size=4"); | |
| 8225 | } else { | |
| 8226 | args.append("-fno-stack-protector"); | |
| 8227 | } | |
| 8228 | args.append("-fno-omit-frame-pointer"); | |
| 8229 | break; | |
| 8230 | case BuildModeSafeRelease: | |
| 8231 | // See the comment in the BuildModeFastRelease case for why we pass -O2 rather | |
| 8232 | // than -O3 here. | |
| 8233 | args.append("-O2"); | |
| 8234 | if (g->libc_link_lib != nullptr) { | |
| 8235 | args.append("-D_FORTIFY_SOURCE=2"); | |
| 8236 | args.append("-fstack-protector-strong"); | |
| 8237 | args.append("--param"); | |
| 8238 | args.append("ssp-buffer-size=4"); | |
| 8239 | } else { | |
| 8240 | args.append("-fno-stack-protector"); | |
| 8241 | } | |
| 8242 | args.append("-fomit-frame-pointer"); | |
| 8243 | break; | |
| 8244 | case BuildModeFastRelease: | |
| 8245 | args.append("-DNDEBUG"); | |
| 8246 | // Here we pass -O2 rather than -O3 because, although we do the equivalent of | |
| 8247 | // -O3 in Zig code, the justification for the difference here is that Zig | |
| 8248 | // has better detection and prevention of undefined behavior, so -O3 is safer for | |
| 8249 | // Zig code than it is for C code. Also, C programmers are used to their code | |
| 8250 | // running in -O2 and thus the -O3 path has been tested less. | |
| 8251 | args.append("-O2"); | |
| 8252 | args.append("-fno-stack-protector"); | |
| 8253 | args.append("-fomit-frame-pointer"); | |
| 8254 | break; | |
| 8255 | case BuildModeSmallRelease: | |
| 8256 | args.append("-DNDEBUG"); | |
| 8257 | args.append("-Os"); | |
| 8258 | args.append("-fno-stack-protector"); | |
| 8259 | args.append("-fomit-frame-pointer"); | |
| 8260 | break; | |
| 8261 | } | |
| 8262 | ||
| 8263 | if (target_supports_fpic(g->zig_target) && g->have_pic) { | |
| 8264 | args.append("-fPIC"); | |
| 8265 | } | |
| 8266 | ||
| 8267 | for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) { | |
| 8268 | args.append(g->clang_argv[arg_i]); | |
| 8269 | } | |
| 8270 | ||
| 8271 | ||
| 8272 | } | |
| 8273 | ||
| 8274 | void codegen_translate_c(CodeGen *g, Buf *full_path, FILE *out_file, bool use_userland_implementation) { | |
| 8275 | Error err; | |
| 8157 | 8276 | Buf *src_basename = buf_alloc(); |
| 8158 | 8277 | Buf *src_dirname = buf_alloc(); |
| 8159 | 8278 | os_path_split(full_path, src_dirname, src_basename); |
| ... | ... | @@ -8165,19 +8284,47 @@ AstNode *codegen_translate_c(CodeGen *g, Buf *full_path, bool use_userland_imple |
| 8165 | 8284 | |
| 8166 | 8285 | init(g); |
| 8167 | 8286 | |
| 8168 | if (use_userland_implementation) { | |
| 8169 | // TODO improve this | |
| 8170 | stage2_translate_c(); | |
| 8171 | zig_panic("TODO"); | |
| 8287 | Stage2TranslateMode trans_mode = buf_ends_with_str(full_path, ".h") ? | |
| 8288 | Stage2TranslateModeImport : Stage2TranslateModeTranslate; | |
| 8289 | ||
| 8290 | ||
| 8291 | ZigList<const char *> clang_argv = {0}; | |
| 8292 | add_cc_args(g, clang_argv, nullptr, true); | |
| 8293 | ||
| 8294 | clang_argv.append(buf_ptr(full_path)); | |
| 8295 | ||
| 8296 | if (g->verbose_cc) { | |
| 8297 | fprintf(stderr, "clang"); | |
| 8298 | for (size_t i = 0; i < clang_argv.length; i += 1) { | |
| 8299 | fprintf(stderr, " %s", clang_argv.at(i)); | |
| 8300 | } | |
| 8301 | fprintf(stderr, "\n"); | |
| 8172 | 8302 | } |
| 8173 | 8303 | |
| 8174 | ZigList<ErrorMsg *> errors = {0}; | |
| 8304 | clang_argv.append(nullptr); // to make the [start...end] argument work | |
| 8305 | ||
| 8306 | const char *resources_path = buf_ptr(g->zig_c_headers_dir); | |
| 8307 | Stage2ErrorMsg *errors_ptr; | |
| 8308 | size_t errors_len; | |
| 8309 | Stage2Ast *ast; | |
| 8175 | 8310 | AstNode *root_node; |
| 8176 | Error err = parse_h_file(&root_node, &errors, buf_ptr(full_path), g, nullptr); | |
| 8177 | 8311 | |
| 8178 | if (err == ErrorCCompileErrors && errors.length > 0) { | |
| 8179 | for (size_t i = 0; i < errors.length; i += 1) { | |
| 8180 | ErrorMsg *err_msg = errors.at(i); | |
| 8312 | if (use_userland_implementation) { | |
| 8313 | err = stage2_translate_c(&ast, &errors_ptr, &errors_len, | |
| 8314 | &clang_argv.at(0), &clang_argv.last(), trans_mode, resources_path); | |
| 8315 | } else { | |
| 8316 | err = parse_h_file(g, &root_node, &errors_ptr, &errors_len, &clang_argv.at(0), &clang_argv.last(), | |
| 8317 | trans_mode, resources_path); | |
| 8318 | } | |
| 8319 | ||
| 8320 | if (err == ErrorCCompileErrors && errors_len > 0) { | |
| 8321 | for (size_t i = 0; i < errors_len; i += 1) { | |
| 8322 | Stage2ErrorMsg *clang_err = &errors_ptr[i]; | |
| 8323 | ErrorMsg *err_msg = err_msg_create_with_offset( | |
| 8324 | clang_err->filename_ptr ? | |
| 8325 | buf_create_from_mem(clang_err->filename_ptr, clang_err->filename_len) : buf_alloc(), | |
| 8326 | clang_err->line, clang_err->column, clang_err->offset, clang_err->source, | |
| 8327 | buf_create_from_mem(clang_err->msg_ptr, clang_err->msg_len)); | |
| 8181 | 8328 | print_err_msg(err_msg, g->err_color); |
| 8182 | 8329 | } |
| 8183 | 8330 | exit(1); |
| ... | ... | @@ -8188,7 +8335,12 @@ AstNode *codegen_translate_c(CodeGen *g, Buf *full_path, bool use_userland_imple |
| 8188 | 8335 | exit(1); |
| 8189 | 8336 | } |
| 8190 | 8337 | |
| 8191 | return root_node; | |
| 8338 | ||
| 8339 | if (use_userland_implementation) { | |
| 8340 | stage2_render_ast(ast, out_file); | |
| 8341 | } else { | |
| 8342 | ast_render(out_file, root_node, 4); | |
| 8343 | } | |
| 8192 | 8344 | } |
| 8193 | 8345 | |
| 8194 | 8346 | static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *basename) { |
| ... | ... | @@ -8507,93 +8659,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 8507 | 8659 | args.append("cc"); |
| 8508 | 8660 | |
| 8509 | 8661 | Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path)); |
| 8510 | args.append("-MD"); | |
| 8511 | args.append("-MV"); | |
| 8512 | args.append("-MF"); | |
| 8513 | args.append(buf_ptr(out_dep_path)); | |
| 8514 | ||
| 8515 | args.append("-nostdinc"); | |
| 8516 | args.append("-fno-spell-checking"); | |
| 8517 | ||
| 8518 | switch (g->err_color) { | |
| 8519 | case ErrColorAuto: | |
| 8520 | break; | |
| 8521 | case ErrColorOff: | |
| 8522 | args.append("-fno-color-diagnostics"); | |
| 8523 | args.append("-fno-caret-diagnostics"); | |
| 8524 | break; | |
| 8525 | case ErrColorOn: | |
| 8526 | args.append("-fcolor-diagnostics"); | |
| 8527 | args.append("-fcaret-diagnostics"); | |
| 8528 | break; | |
| 8529 | } | |
| 8530 | ||
| 8531 | args.append("-isystem"); | |
| 8532 | args.append(buf_ptr(g->zig_c_headers_dir)); | |
| 8533 | ||
| 8534 | for (size_t i = 0; i < g->libc_include_dir_len; i += 1) { | |
| 8535 | Buf *include_dir = g->libc_include_dir_list[i]; | |
| 8536 | args.append("-isystem"); | |
| 8537 | args.append(buf_ptr(include_dir)); | |
| 8538 | } | |
| 8539 | ||
| 8540 | if (g->zig_target->is_native) { | |
| 8541 | args.append("-march=native"); | |
| 8542 | } else { | |
| 8543 | args.append("-target"); | |
| 8544 | args.append(buf_ptr(&g->triple_str)); | |
| 8545 | } | |
| 8546 | if (g->zig_target->os == OsFreestanding) { | |
| 8547 | args.append("-ffreestanding"); | |
| 8548 | } | |
| 8549 | ||
| 8550 | if (!g->strip_debug_symbols) { | |
| 8551 | args.append("-g"); | |
| 8552 | } | |
| 8553 | ||
| 8554 | switch (g->build_mode) { | |
| 8555 | case BuildModeDebug: | |
| 8556 | if (g->libc_link_lib != nullptr) { | |
| 8557 | args.append("-fstack-protector-strong"); | |
| 8558 | args.append("--param"); | |
| 8559 | args.append("ssp-buffer-size=4"); | |
| 8560 | } else { | |
| 8561 | args.append("-fno-stack-protector"); | |
| 8562 | } | |
| 8563 | args.append("-fno-omit-frame-pointer"); | |
| 8564 | break; | |
| 8565 | case BuildModeSafeRelease: | |
| 8566 | // See the comment in the BuildModeFastRelease case for why we pass -O2 rather | |
| 8567 | // than -O3 here. | |
| 8568 | args.append("-O2"); | |
| 8569 | if (g->libc_link_lib != nullptr) { | |
| 8570 | args.append("-D_FORTIFY_SOURCE=2"); | |
| 8571 | args.append("-fstack-protector-strong"); | |
| 8572 | args.append("--param"); | |
| 8573 | args.append("ssp-buffer-size=4"); | |
| 8574 | } else { | |
| 8575 | args.append("-fno-stack-protector"); | |
| 8576 | } | |
| 8577 | args.append("-fomit-frame-pointer"); | |
| 8578 | break; | |
| 8579 | case BuildModeFastRelease: | |
| 8580 | args.append("-DNDEBUG"); | |
| 8581 | // Here we pass -O2 rather than -O3 because, although we do the equivalent of | |
| 8582 | // -O3 in Zig code, the justification for the difference here is that Zig | |
| 8583 | // has better detection and prevention of undefined behavior, so -O3 is safer for | |
| 8584 | // Zig code than it is for C code. Also, C programmers are used to their code | |
| 8585 | // running in -O2 and thus the -O3 path has been tested less. | |
| 8586 | args.append("-O2"); | |
| 8587 | args.append("-fno-stack-protector"); | |
| 8588 | args.append("-fomit-frame-pointer"); | |
| 8589 | break; | |
| 8590 | case BuildModeSmallRelease: | |
| 8591 | args.append("-DNDEBUG"); | |
| 8592 | args.append("-Os"); | |
| 8593 | args.append("-fno-stack-protector"); | |
| 8594 | args.append("-fomit-frame-pointer"); | |
| 8595 | break; | |
| 8596 | } | |
| 8662 | add_cc_args(g, args, buf_ptr(out_dep_path), false); | |
| 8597 | 8663 | |
| 8598 | 8664 | args.append("-o"); |
| 8599 | 8665 | args.append(buf_ptr(out_obj_path)); |
| ... | ... | @@ -8601,19 +8667,10 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 8601 | 8667 | args.append("-c"); |
| 8602 | 8668 | args.append(buf_ptr(c_source_file)); |
| 8603 | 8669 | |
| 8604 | if (target_supports_fpic(g->zig_target) && g->have_pic) { | |
| 8605 | args.append("-fPIC"); | |
| 8606 | } | |
| 8607 | ||
| 8608 | for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) { | |
| 8609 | args.append(g->clang_argv[arg_i]); | |
| 8610 | } | |
| 8611 | ||
| 8612 | 8670 | for (size_t arg_i = 0; arg_i < c_file->args.length; arg_i += 1) { |
| 8613 | 8671 | args.append(c_file->args.at(arg_i)); |
| 8614 | 8672 | } |
| 8615 | 8673 | |
| 8616 | ||
| 8617 | 8674 | if (g->verbose_cc) { |
| 8618 | 8675 | print_zig_cc_cmd("zig", &args); |
| 8619 | 8676 | } |
src/codegen.hpp+2-1| ... | ... | @@ -12,6 +12,7 @@ |
| 12 | 12 | #include "errmsg.hpp" |
| 13 | 13 | #include "target.hpp" |
| 14 | 14 | #include "libc_installation.hpp" |
| 15 | #include "userland.h" | |
| 15 | 16 | |
| 16 | 17 | #include <stdio.h> |
| 17 | 18 | |
| ... | ... | @@ -50,7 +51,7 @@ ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const c |
| 50 | 51 | void codegen_add_assembly(CodeGen *g, Buf *path); |
| 51 | 52 | void codegen_add_object(CodeGen *g, Buf *object_path); |
| 52 | 53 | |
| 53 | AstNode *codegen_translate_c(CodeGen *g, Buf *path, bool use_userland_implementation); | |
| 54 | void codegen_translate_c(CodeGen *g, Buf *full_path, FILE *out_file, bool use_userland_implementation); | |
| 54 | 55 | |
| 55 | 56 | Buf *codegen_generate_builtin_source(CodeGen *g); |
| 56 | 57 |
src/error.cpp+4| ... | ... | @@ -50,6 +50,10 @@ const char *err_str(Error err) { |
| 50 | 50 | case ErrorUnexpectedWriteFailure: return "unexpected write failure"; |
| 51 | 51 | case ErrorUnexpectedSeekFailure: return "unexpected seek failure"; |
| 52 | 52 | case ErrorUnexpectedFileTruncationFailure: return "unexpected file truncation failure"; |
| 53 | case ErrorUnimplemented: return "unimplemented"; | |
| 54 | case ErrorOperationAborted: return "operation aborted"; | |
| 55 | case ErrorBrokenPipe: return "broken pipe"; | |
| 56 | case ErrorNoSpaceLeft: return "no space left"; | |
| 53 | 57 | } |
| 54 | 58 | return "(invalid error)"; |
| 55 | 59 | } |
src/error.hpp+1-43| ... | ... | @@ -8,49 +8,7 @@ |
| 8 | 8 | #ifndef ERROR_HPP |
| 9 | 9 | #define ERROR_HPP |
| 10 | 10 | |
| 11 | enum Error { | |
| 12 | ErrorNone, | |
| 13 | ErrorNoMem, | |
| 14 | ErrorInvalidFormat, | |
| 15 | ErrorSemanticAnalyzeFail, | |
| 16 | ErrorAccess, | |
| 17 | ErrorInterrupted, | |
| 18 | ErrorSystemResources, | |
| 19 | ErrorFileNotFound, | |
| 20 | ErrorFileSystem, | |
| 21 | ErrorFileTooBig, | |
| 22 | ErrorDivByZero, | |
| 23 | ErrorOverflow, | |
| 24 | ErrorPathAlreadyExists, | |
| 25 | ErrorUnexpected, | |
| 26 | ErrorExactDivRemainder, | |
| 27 | ErrorNegativeDenominator, | |
| 28 | ErrorShiftedOutOneBits, | |
| 29 | ErrorCCompileErrors, | |
| 30 | ErrorEndOfFile, | |
| 31 | ErrorIsDir, | |
| 32 | ErrorNotDir, | |
| 33 | ErrorUnsupportedOperatingSystem, | |
| 34 | ErrorSharingViolation, | |
| 35 | ErrorPipeBusy, | |
| 36 | ErrorPrimitiveTypeNotFound, | |
| 37 | ErrorCacheUnavailable, | |
| 38 | ErrorPathTooLong, | |
| 39 | ErrorCCompilerCannotFindFile, | |
| 40 | ErrorReadingDepFile, | |
| 41 | ErrorInvalidDepFile, | |
| 42 | ErrorMissingArchitecture, | |
| 43 | ErrorMissingOperatingSystem, | |
| 44 | ErrorUnknownArchitecture, | |
| 45 | ErrorUnknownOperatingSystem, | |
| 46 | ErrorUnknownABI, | |
| 47 | ErrorInvalidFilename, | |
| 48 | ErrorDiskQuota, | |
| 49 | ErrorDiskSpace, | |
| 50 | ErrorUnexpectedWriteFailure, | |
| 51 | ErrorUnexpectedSeekFailure, | |
| 52 | ErrorUnexpectedFileTruncationFailure, | |
| 53 | }; | |
| 11 | #include "userland.h" | |
| 54 | 12 | |
| 55 | 13 | const char *err_str(Error err); |
| 56 | 14 |
src/ir.cpp+34-8| ... | ... | @@ -10350,7 +10350,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod |
| 10350 | 10350 | |
| 10351 | 10351 | if (codegen->verbose_ir) { |
| 10352 | 10352 | fprintf(stderr, "\nSource: "); |
| 10353 | ast_render(codegen, stderr, node, 4); | |
| 10353 | ast_render(stderr, node, 4); | |
| 10354 | 10354 | fprintf(stderr, "\n{ // (IR)\n"); |
| 10355 | 10355 | ir_print(codegen, stderr, ir_executable, 2); |
| 10356 | 10356 | fprintf(stderr, "}\n"); |
| ... | ... | @@ -19092,24 +19092,50 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 19092 | 19092 | fprintf(stderr, "@cImport source: %s\n", buf_ptr(&tmp_c_file_path)); |
| 19093 | 19093 | } |
| 19094 | 19094 | |
| 19095 | ZigList<ErrorMsg *> errors = {0}; | |
| 19096 | ||
| 19097 | 19095 | Buf *tmp_dep_file = buf_sprintf("%s.d", buf_ptr(&tmp_c_file_path)); |
| 19096 | ||
| 19097 | ZigList<const char *> clang_argv = {0}; | |
| 19098 | ||
| 19099 | add_cc_args(ira->codegen, clang_argv, buf_ptr(tmp_dep_file), true); | |
| 19100 | ||
| 19101 | clang_argv.append(buf_ptr(&tmp_c_file_path)); | |
| 19102 | ||
| 19103 | if (ira->codegen->verbose_cc) { | |
| 19104 | fprintf(stderr, "clang"); | |
| 19105 | for (size_t i = 0; i < clang_argv.length; i += 1) { | |
| 19106 | fprintf(stderr, " %s", clang_argv.at(i)); | |
| 19107 | } | |
| 19108 | fprintf(stderr, "\n"); | |
| 19109 | } | |
| 19110 | ||
| 19111 | clang_argv.append(nullptr); // to make the [start...end] argument work | |
| 19112 | ||
| 19098 | 19113 | AstNode *root_node; |
| 19099 | if ((err = parse_h_file(&root_node, &errors, buf_ptr(&tmp_c_file_path), ira->codegen, tmp_dep_file))) { | |
| 19114 | Stage2ErrorMsg *errors_ptr; | |
| 19115 | size_t errors_len; | |
| 19116 | ||
| 19117 | const char *resources_path = buf_ptr(ira->codegen->zig_c_headers_dir); | |
| 19118 | ||
| 19119 | if ((err = parse_h_file(ira->codegen, &root_node, &errors_ptr, &errors_len, | |
| 19120 | &clang_argv.at(0), &clang_argv.last(), Stage2TranslateModeImport, resources_path))) | |
| 19121 | { | |
| 19100 | 19122 | if (err != ErrorCCompileErrors) { |
| 19101 | 19123 | ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err))); |
| 19102 | 19124 | return ira->codegen->invalid_instruction; |
| 19103 | 19125 | } |
| 19104 | assert(errors.length > 0); | |
| 19105 | 19126 | |
| 19106 | 19127 | ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed")); |
| 19107 | 19128 | if (ira->codegen->libc_link_lib == nullptr) { |
| 19108 | 19129 | add_error_note(ira->codegen, parent_err_msg, node, |
| 19109 | 19130 | buf_sprintf("libc headers not available; compilation does not link against libc")); |
| 19110 | 19131 | } |
| 19111 | for (size_t i = 0; i < errors.length; i += 1) { | |
| 19112 | ErrorMsg *err_msg = errors.at(i); | |
| 19132 | for (size_t i = 0; i < errors_len; i += 1) { | |
| 19133 | Stage2ErrorMsg *clang_err = &errors_ptr[i]; | |
| 19134 | ErrorMsg *err_msg = err_msg_create_with_offset( | |
| 19135 | clang_err->filename_ptr ? | |
| 19136 | buf_create_from_mem(clang_err->filename_ptr, clang_err->filename_len) : buf_alloc(), | |
| 19137 | clang_err->line, clang_err->column, clang_err->offset, clang_err->source, | |
| 19138 | buf_create_from_mem(clang_err->msg_ptr, clang_err->msg_len)); | |
| 19113 | 19139 | err_msg_add_note(parent_err_msg, err_msg); |
| 19114 | 19140 | } |
| 19115 | 19141 | |
| ... | ... | @@ -19139,7 +19165,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 19139 | 19165 | buf_sprintf("C import failed: unable to open output file: %s", strerror(errno))); |
| 19140 | 19166 | return ira->codegen->invalid_instruction; |
| 19141 | 19167 | } |
| 19142 | ast_render(ira->codegen, out_file, root_node, 4); | |
| 19168 | ast_render(out_file, root_node, 4); | |
| 19143 | 19169 | if (fclose(out_file) != 0) { |
| 19144 | 19170 | ir_add_error_node(ira, node, |
| 19145 | 19171 | buf_sprintf("C import failed: unable to write to output file: %s", strerror(errno))); |
src/main.cpp+1-2| ... | ... | @@ -1188,8 +1188,7 @@ int main(int argc, char **argv) { |
| 1188 | 1188 | zig_unreachable(); |
| 1189 | 1189 | } |
| 1190 | 1190 | } else if (cmd == CmdTranslateC || cmd == CmdTranslateCUserland) { |
| 1191 | AstNode *root_node = codegen_translate_c(g, in_file_buf, cmd == CmdTranslateCUserland); | |
| 1192 | ast_render(g, stdout, root_node, 4); | |
| 1191 | codegen_translate_c(g, in_file_buf, stdout, cmd == CmdTranslateCUserland); | |
| 1193 | 1192 | if (timing_info) |
| 1194 | 1193 | codegen_print_timing_report(g, stderr); |
| 1195 | 1194 | return EXIT_SUCCESS; |
src/translate_c.cpp+12-164| ... | ... | @@ -76,10 +76,9 @@ struct TransScopeWhile { |
| 76 | 76 | }; |
| 77 | 77 | |
| 78 | 78 | struct Context { |
| 79 | ZigList<ErrorMsg *> *errors; | |
| 79 | AstNode *root; | |
| 80 | 80 | VisibMod visib_mod; |
| 81 | 81 | bool want_export; |
| 82 | AstNode *root; | |
| 83 | 82 | HashMap<const void *, AstNode *, ptr_hash, ptr_eq> decl_table; |
| 84 | 83 | HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> macro_table; |
| 85 | 84 | HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> global_table; |
| ... | ... | @@ -5018,14 +5017,15 @@ static void process_preprocessor_entities(Context *c, ZigClangASTUnit *zunit) { |
| 5018 | 5017 | } |
| 5019 | 5018 | } |
| 5020 | 5019 | |
| 5021 | Error parse_h_file(AstNode **out_root_node, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 5022 | CodeGen *codegen, Buf *tmp_dep_file) | |
| 5020 | Error parse_h_file(CodeGen *codegen, AstNode **out_root_node, | |
| 5021 | Stage2ErrorMsg **errors_ptr, size_t *errors_len, | |
| 5022 | const char **args_begin, const char **args_end, | |
| 5023 | Stage2TranslateMode mode, const char *resources_path) | |
| 5023 | 5024 | { |
| 5024 | 5025 | Context context = {0}; |
| 5025 | 5026 | Context *c = &context; |
| 5026 | 5027 | c->warnings_on = codegen->verbose_cimport; |
| 5027 | c->errors = errors; | |
| 5028 | if (buf_ends_with_str(buf_create_from_str(target_file), ".h")) { | |
| 5028 | if (mode == Stage2TranslateModeImport) { | |
| 5029 | 5029 | c->visib_mod = VisibModPub; |
| 5030 | 5030 | c->want_export = false; |
| 5031 | 5031 | } else { |
| ... | ... | @@ -5039,164 +5039,10 @@ Error parse_h_file(AstNode **out_root_node, ZigList<ErrorMsg *> *errors, const c |
| 5039 | 5039 | c->codegen = codegen; |
| 5040 | 5040 | c->global_scope = trans_scope_root_create(c); |
| 5041 | 5041 | |
| 5042 | ZigList<const char *> clang_argv = {0}; | |
| 5043 | ||
| 5044 | clang_argv.append("-x"); | |
| 5045 | clang_argv.append("c"); | |
| 5046 | ||
| 5047 | if (tmp_dep_file != nullptr) { | |
| 5048 | clang_argv.append("-MD"); | |
| 5049 | clang_argv.append("-MV"); | |
| 5050 | clang_argv.append("-MF"); | |
| 5051 | clang_argv.append(buf_ptr(tmp_dep_file)); | |
| 5052 | } | |
| 5053 | ||
| 5054 | if (c->codegen->zig_target->is_native) { | |
| 5055 | char *ZIG_PARSEC_CFLAGS = getenv("ZIG_NATIVE_PARSEC_CFLAGS"); | |
| 5056 | if (ZIG_PARSEC_CFLAGS) { | |
| 5057 | Buf tmp_buf = BUF_INIT; | |
| 5058 | char *start = ZIG_PARSEC_CFLAGS; | |
| 5059 | char *space = strstr(start, " "); | |
| 5060 | while (space) { | |
| 5061 | if (space - start > 0) { | |
| 5062 | buf_init_from_mem(&tmp_buf, start, space - start); | |
| 5063 | clang_argv.append(buf_ptr(buf_create_from_buf(&tmp_buf))); | |
| 5064 | } | |
| 5065 | start = space + 1; | |
| 5066 | space = strstr(start, " "); | |
| 5067 | } | |
| 5068 | buf_init_from_str(&tmp_buf, start); | |
| 5069 | clang_argv.append(buf_ptr(buf_create_from_buf(&tmp_buf))); | |
| 5070 | } | |
| 5071 | } | |
| 5072 | ||
| 5073 | clang_argv.append("-nobuiltininc"); | |
| 5074 | clang_argv.append("-nostdinc"); | |
| 5075 | clang_argv.append("-nostdinc++"); | |
| 5076 | if (codegen->libc_link_lib == nullptr) { | |
| 5077 | clang_argv.append("-nolibc"); | |
| 5078 | } | |
| 5079 | ||
| 5080 | clang_argv.append("-isystem"); | |
| 5081 | clang_argv.append(buf_ptr(codegen->zig_c_headers_dir)); | |
| 5082 | ||
| 5083 | for (size_t i = 0; i < codegen->libc_include_dir_len; i += 1) { | |
| 5084 | Buf *include_dir = codegen->libc_include_dir_list[i]; | |
| 5085 | clang_argv.append("-isystem"); | |
| 5086 | clang_argv.append(buf_ptr(include_dir)); | |
| 5087 | } | |
| 5088 | ||
| 5089 | // windows c runtime requires -D_DEBUG if using debug libraries | |
| 5090 | if (codegen->build_mode == BuildModeDebug) { | |
| 5091 | clang_argv.append("-D_DEBUG"); | |
| 5092 | } | |
| 5093 | ||
| 5094 | for (size_t i = 0; i < codegen->clang_argv_len; i += 1) { | |
| 5095 | clang_argv.append(codegen->clang_argv[i]); | |
| 5096 | } | |
| 5097 | ||
| 5098 | // we don't need spell checking and it slows things down | |
| 5099 | clang_argv.append("-fno-spell-checking"); | |
| 5100 | ||
| 5101 | // this gives us access to preprocessing entities, presumably at | |
| 5102 | // the cost of performance | |
| 5103 | clang_argv.append("-Xclang"); | |
| 5104 | clang_argv.append("-detailed-preprocessing-record"); | |
| 5105 | ||
| 5106 | if (c->codegen->zig_target->is_native) { | |
| 5107 | clang_argv.append("-march=native"); | |
| 5108 | } else { | |
| 5109 | clang_argv.append("-target"); | |
| 5110 | clang_argv.append(buf_ptr(&c->codegen->triple_str)); | |
| 5111 | } | |
| 5112 | if (c->codegen->zig_target->os == OsFreestanding) { | |
| 5113 | clang_argv.append("-ffreestanding"); | |
| 5114 | } | |
| 5115 | ||
| 5116 | clang_argv.append(target_file); | |
| 5117 | ||
| 5118 | if (codegen->verbose_cc) { | |
| 5119 | fprintf(stderr, "clang"); | |
| 5120 | for (size_t i = 0; i < clang_argv.length; i += 1) { | |
| 5121 | fprintf(stderr, " %s", clang_argv.at(i)); | |
| 5122 | } | |
| 5123 | fprintf(stderr, "\n"); | |
| 5124 | } | |
| 5125 | ||
| 5126 | // to make the [start...end] argument work | |
| 5127 | clang_argv.append(nullptr); | |
| 5128 | ||
| 5129 | clang::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diags(clang::CompilerInstance::createDiagnostics(new clang::DiagnosticOptions)); | |
| 5130 | ||
| 5131 | std::shared_ptr<clang::PCHContainerOperations> pch_container_ops = std::make_shared<clang::PCHContainerOperations>(); | |
| 5132 | ||
| 5133 | bool only_local_decls = true; | |
| 5134 | bool capture_diagnostics = true; | |
| 5135 | bool user_files_are_volatile = true; | |
| 5136 | bool allow_pch_with_compiler_errors = false; | |
| 5137 | bool single_file_parse = false; | |
| 5138 | bool for_serialization = false; | |
| 5139 | const char *resources_path = buf_ptr(codegen->zig_c_headers_dir); | |
| 5140 | std::unique_ptr<clang::ASTUnit> err_unit; | |
| 5141 | ZigClangASTUnit *ast_unit = reinterpret_cast<ZigClangASTUnit *>(clang::ASTUnit::LoadFromCommandLine( | |
| 5142 | &clang_argv.at(0), &clang_argv.last(), | |
| 5143 | pch_container_ops, diags, resources_path, | |
| 5144 | only_local_decls, capture_diagnostics, clang::None, true, 0, clang::TU_Complete, | |
| 5145 | false, false, allow_pch_with_compiler_errors, clang::SkipFunctionBodiesScope::None, | |
| 5146 | single_file_parse, user_files_are_volatile, for_serialization, clang::None, &err_unit, | |
| 5147 | nullptr)); | |
| 5148 | ||
| 5149 | // Early failures in LoadFromCommandLine may return with ErrUnit unset. | |
| 5150 | if (!ast_unit && !err_unit) { | |
| 5151 | return ErrorFileSystem; | |
| 5152 | } | |
| 5153 | ||
| 5154 | if (diags->getClient()->getNumErrors() > 0) { | |
| 5155 | if (ast_unit) { | |
| 5156 | err_unit = std::unique_ptr<clang::ASTUnit>(reinterpret_cast<clang::ASTUnit *>(ast_unit)); | |
| 5157 | } | |
| 5158 | ||
| 5159 | for (clang::ASTUnit::stored_diag_iterator it = err_unit->stored_diag_begin(), | |
| 5160 | it_end = err_unit->stored_diag_end(); | |
| 5161 | it != it_end; ++it) | |
| 5162 | { | |
| 5163 | switch (it->getLevel()) { | |
| 5164 | case clang::DiagnosticsEngine::Ignored: | |
| 5165 | case clang::DiagnosticsEngine::Note: | |
| 5166 | case clang::DiagnosticsEngine::Remark: | |
| 5167 | case clang::DiagnosticsEngine::Warning: | |
| 5168 | continue; | |
| 5169 | case clang::DiagnosticsEngine::Error: | |
| 5170 | case clang::DiagnosticsEngine::Fatal: | |
| 5171 | break; | |
| 5172 | } | |
| 5173 | llvm::StringRef msg_str_ref = it->getMessage(); | |
| 5174 | Buf *msg = string_ref_to_buf(msg_str_ref); | |
| 5175 | clang::FullSourceLoc fsl = it->getLocation(); | |
| 5176 | if (fsl.hasManager()) { | |
| 5177 | clang::FileID file_id = fsl.getFileID(); | |
| 5178 | clang::StringRef filename = fsl.getManager().getFilename(fsl); | |
| 5179 | unsigned line = fsl.getSpellingLineNumber() - 1; | |
| 5180 | unsigned column = fsl.getSpellingColumnNumber() - 1; | |
| 5181 | unsigned offset = fsl.getManager().getFileOffset(fsl); | |
| 5182 | const char *source = (const char *)fsl.getManager().getBufferData(file_id).bytes_begin(); | |
| 5183 | Buf *path; | |
| 5184 | if (filename.empty()) { | |
| 5185 | path = buf_alloc(); | |
| 5186 | } else { | |
| 5187 | path = string_ref_to_buf(filename); | |
| 5188 | } | |
| 5189 | ||
| 5190 | ErrorMsg *err_msg = err_msg_create_with_offset(path, line, column, offset, source, msg); | |
| 5191 | ||
| 5192 | c->errors->append(err_msg); | |
| 5193 | } else { | |
| 5194 | // NOTE the only known way this gets triggered right now is if you have a lot of errors | |
| 5195 | // clang emits "too many errors emitted, stopping now" | |
| 5196 | fprintf(stderr, "unexpected error from clang: %s\n", buf_ptr(msg)); | |
| 5197 | } | |
| 5198 | } | |
| 5199 | ||
| 5042 | ZigClangASTUnit *ast_unit = ZigClangLoadFromCommandLine(args_begin, args_end, errors_ptr, errors_len, | |
| 5043 | resources_path); | |
| 5044 | if (ast_unit == nullptr) { | |
| 5045 | if (*errors_len == 0) return ErrorNoMem; | |
| 5200 | 5046 | return ErrorCCompileErrors; |
| 5201 | 5047 | } |
| 5202 | 5048 | |
| ... | ... | @@ -5214,5 +5060,7 @@ Error parse_h_file(AstNode **out_root_node, ZigList<ErrorMsg *> *errors, const c |
| 5214 | 5060 | |
| 5215 | 5061 | *out_root_node = c->root; |
| 5216 | 5062 | |
| 5063 | ZigClangASTUnit_delete(ast_unit); | |
| 5064 | ||
| 5217 | 5065 | return ErrorNone; |
| 5218 | 5066 | } |
src/translate_c.hpp+4-2| ... | ... | @@ -11,7 +11,9 @@ |
| 11 | 11 | |
| 12 | 12 | #include "all_types.hpp" |
| 13 | 13 | |
| 14 | Error parse_h_file(AstNode **out_root_node, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 15 | CodeGen *codegen, Buf *tmp_dep_file); | |
| 14 | Error parse_h_file(CodeGen *codegen, AstNode **out_root_node, | |
| 15 | Stage2ErrorMsg **errors_ptr, size_t *errors_len, | |
| 16 | const char **args_begin, const char **args_end, | |
| 17 | Stage2TranslateMode mode, const char *resources_path); | |
| 16 | 18 | |
| 17 | 19 | #endif |
src/userland.cpp+16-1| ... | ... | @@ -2,15 +2,25 @@ |
| 2 | 2 | // src-self-hosted/stage1.zig |
| 3 | 3 | |
| 4 | 4 | #include "userland.h" |
| 5 | #include "ast_render.hpp" | |
| 5 | 6 | #include <stdio.h> |
| 6 | 7 | #include <stdlib.h> |
| 7 | 8 | #include <string.h> |
| 8 | 9 | |
| 9 | void stage2_translate_c(void) { | |
| 10 | Error stage2_translate_c(struct Stage2Ast **out_ast, | |
| 11 | struct Stage2ErrorMsg **out_errors_ptr, size_t *out_errors_len, | |
| 12 | const char **args_begin, const char **args_end, enum Stage2TranslateMode mode, | |
| 13 | const char *resources_path) | |
| 14 | { | |
| 10 | 15 | const char *msg = "stage0 called stage2_translate_c"; |
| 11 | 16 | stage2_panic(msg, strlen(msg)); |
| 12 | 17 | } |
| 13 | 18 | |
| 19 | void stage2_free_clang_errors(struct Stage2ErrorMsg *ptr, size_t len) { | |
| 20 | const char *msg = "stage0 called stage2_free_clang_errors"; | |
| 21 | stage2_panic(msg, strlen(msg)); | |
| 22 | } | |
| 23 | ||
| 14 | 24 | void stage2_zen(const char **ptr, size_t *len) { |
| 15 | 25 | const char *msg = "stage0 called stage2_zen"; |
| 16 | 26 | stage2_panic(msg, strlen(msg)); |
| ... | ... | @@ -22,3 +32,8 @@ void stage2_panic(const char *ptr, size_t len) { |
| 22 | 32 | fflush(stderr); |
| 23 | 33 | abort(); |
| 24 | 34 | } |
| 35 | ||
| 36 | void stage2_render_ast(struct Stage2Ast *ast, FILE *output_file) { | |
| 37 | const char *msg = "stage0 called stage2_render_ast"; | |
| 38 | stage2_panic(msg, strlen(msg)); | |
| 39 | } |
src/userland.h+97-5| ... | ... | @@ -9,17 +9,109 @@ |
| 9 | 9 | #define ZIG_USERLAND_H |
| 10 | 10 | |
| 11 | 11 | #include <stddef.h> |
| 12 | #include <stdio.h> | |
| 12 | 13 | |
| 13 | 14 | #ifdef __cplusplus |
| 14 | #define ZIG_USERLAND_EXTERN_C extern "C" | |
| 15 | #define ZIG_EXTERN_C extern "C" | |
| 15 | 16 | #else |
| 16 | #define ZIG_USERLAND_EXTERN_C | |
| 17 | #define ZIG_EXTERN_C | |
| 17 | 18 | #endif |
| 18 | 19 | |
| 19 | ZIG_USERLAND_EXTERN_C void stage2_translate_c(void); | |
| 20 | #if defined(_MSC_VER) | |
| 21 | #define ZIG_ATTRIBUTE_NORETURN __declspec(noreturn) | |
| 22 | #else | |
| 23 | #define ZIG_ATTRIBUTE_NORETURN __attribute__((noreturn)) | |
| 24 | #endif | |
| 25 | ||
| 26 | // ABI warning: the types and declarations in this file must match both those in | |
| 27 | // userland.cpp and src-self-hosted/stage1.zig. | |
| 28 | ||
| 29 | // ABI warning | |
| 30 | enum Error { | |
| 31 | ErrorNone, | |
| 32 | ErrorNoMem, | |
| 33 | ErrorInvalidFormat, | |
| 34 | ErrorSemanticAnalyzeFail, | |
| 35 | ErrorAccess, | |
| 36 | ErrorInterrupted, | |
| 37 | ErrorSystemResources, | |
| 38 | ErrorFileNotFound, | |
| 39 | ErrorFileSystem, | |
| 40 | ErrorFileTooBig, | |
| 41 | ErrorDivByZero, | |
| 42 | ErrorOverflow, | |
| 43 | ErrorPathAlreadyExists, | |
| 44 | ErrorUnexpected, | |
| 45 | ErrorExactDivRemainder, | |
| 46 | ErrorNegativeDenominator, | |
| 47 | ErrorShiftedOutOneBits, | |
| 48 | ErrorCCompileErrors, | |
| 49 | ErrorEndOfFile, | |
| 50 | ErrorIsDir, | |
| 51 | ErrorNotDir, | |
| 52 | ErrorUnsupportedOperatingSystem, | |
| 53 | ErrorSharingViolation, | |
| 54 | ErrorPipeBusy, | |
| 55 | ErrorPrimitiveTypeNotFound, | |
| 56 | ErrorCacheUnavailable, | |
| 57 | ErrorPathTooLong, | |
| 58 | ErrorCCompilerCannotFindFile, | |
| 59 | ErrorReadingDepFile, | |
| 60 | ErrorInvalidDepFile, | |
| 61 | ErrorMissingArchitecture, | |
| 62 | ErrorMissingOperatingSystem, | |
| 63 | ErrorUnknownArchitecture, | |
| 64 | ErrorUnknownOperatingSystem, | |
| 65 | ErrorUnknownABI, | |
| 66 | ErrorInvalidFilename, | |
| 67 | ErrorDiskQuota, | |
| 68 | ErrorDiskSpace, | |
| 69 | ErrorUnexpectedWriteFailure, | |
| 70 | ErrorUnexpectedSeekFailure, | |
| 71 | ErrorUnexpectedFileTruncationFailure, | |
| 72 | ErrorUnimplemented, | |
| 73 | ErrorOperationAborted, | |
| 74 | ErrorBrokenPipe, | |
| 75 | ErrorNoSpaceLeft, | |
| 76 | }; | |
| 77 | ||
| 78 | // ABI warning | |
| 79 | enum Stage2TranslateMode { | |
| 80 | Stage2TranslateModeImport, | |
| 81 | Stage2TranslateModeTranslate, | |
| 82 | }; | |
| 83 | ||
| 84 | // ABI warning | |
| 85 | struct Stage2ErrorMsg { | |
| 86 | const char *filename_ptr; // can be null | |
| 87 | size_t filename_len; | |
| 88 | const char *msg_ptr; | |
| 89 | size_t msg_len; | |
| 90 | const char *source; // valid until the ASTUnit is freed. can be null | |
| 91 | unsigned line; // 0 based | |
| 92 | unsigned column; // 0 based | |
| 93 | unsigned offset; // byte offset into source | |
| 94 | }; | |
| 95 | ||
| 96 | // ABI warning | |
| 97 | struct Stage2Ast; | |
| 98 | ||
| 99 | // ABI warning | |
| 100 | ZIG_EXTERN_C enum Error stage2_translate_c(struct Stage2Ast **out_ast, | |
| 101 | struct Stage2ErrorMsg **out_errors_ptr, size_t *out_errors_len, | |
| 102 | const char **args_begin, const char **args_end, enum Stage2TranslateMode mode, | |
| 103 | const char *resources_path); | |
| 104 | ||
| 105 | // ABI warning | |
| 106 | ZIG_EXTERN_C void stage2_free_clang_errors(struct Stage2ErrorMsg *ptr, size_t len); | |
| 107 | ||
| 108 | // ABI warning | |
| 109 | ZIG_EXTERN_C void stage2_render_ast(struct Stage2Ast *ast, FILE *output_file); | |
| 20 | 110 | |
| 21 | ZIG_USERLAND_EXTERN_C void stage2_zen(const char **ptr, size_t *len); | |
| 111 | // ABI warning | |
| 112 | ZIG_EXTERN_C void stage2_zen(const char **ptr, size_t *len); | |
| 22 | 113 | |
| 23 | ZIG_USERLAND_EXTERN_C void stage2_panic(const char *ptr, size_t len); | |
| 114 | // ABI warning | |
| 115 | ZIG_EXTERN_C ZIG_ATTRIBUTE_NORETURN void stage2_panic(const char *ptr, size_t len); | |
| 24 | 116 | |
| 25 | 117 | #endif |
src/zig_clang.cpp+112| ... | ... | @@ -1147,3 +1147,115 @@ ZigClangAPValueLValueBase ZigClangAPValue_getLValueBase(const ZigClangAPValue *s |
| 1147 | 1147 | clang::APValue::LValueBase lval_base = casted->getLValueBase(); |
| 1148 | 1148 | return bitcast(lval_base); |
| 1149 | 1149 | } |
| 1150 | ||
| 1151 | ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char **args_end, | |
| 1152 | struct Stage2ErrorMsg **errors_ptr, size_t *errors_len, const char *resources_path) | |
| 1153 | { | |
| 1154 | clang::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diags(clang::CompilerInstance::createDiagnostics(new clang::DiagnosticOptions)); | |
| 1155 | ||
| 1156 | std::shared_ptr<clang::PCHContainerOperations> pch_container_ops = std::make_shared<clang::PCHContainerOperations>(); | |
| 1157 | ||
| 1158 | bool only_local_decls = true; | |
| 1159 | bool capture_diagnostics = true; | |
| 1160 | bool user_files_are_volatile = true; | |
| 1161 | bool allow_pch_with_compiler_errors = false; | |
| 1162 | bool single_file_parse = false; | |
| 1163 | bool for_serialization = false; | |
| 1164 | std::unique_ptr<clang::ASTUnit> *err_unit = new std::unique_ptr<clang::ASTUnit>(); | |
| 1165 | clang::ASTUnit *ast_unit = clang::ASTUnit::LoadFromCommandLine( | |
| 1166 | args_begin, args_end, | |
| 1167 | pch_container_ops, diags, resources_path, | |
| 1168 | only_local_decls, capture_diagnostics, clang::None, true, 0, clang::TU_Complete, | |
| 1169 | false, false, allow_pch_with_compiler_errors, clang::SkipFunctionBodiesScope::None, | |
| 1170 | single_file_parse, user_files_are_volatile, for_serialization, clang::None, err_unit, | |
| 1171 | nullptr); | |
| 1172 | ||
| 1173 | // Early failures in LoadFromCommandLine may return with ErrUnit unset. | |
| 1174 | if (!ast_unit && !err_unit) { | |
| 1175 | return nullptr; | |
| 1176 | } | |
| 1177 | ||
| 1178 | if (diags->getClient()->getNumErrors() > 0) { | |
| 1179 | if (ast_unit) { | |
| 1180 | *err_unit = std::unique_ptr<clang::ASTUnit>(ast_unit); | |
| 1181 | } | |
| 1182 | ||
| 1183 | size_t cap = 4; | |
| 1184 | *errors_len = 0; | |
| 1185 | *errors_ptr = reinterpret_cast<Stage2ErrorMsg*>(malloc(cap * sizeof(Stage2ErrorMsg))); | |
| 1186 | if (*errors_ptr == nullptr) { | |
| 1187 | return nullptr; | |
| 1188 | } | |
| 1189 | ||
| 1190 | for (clang::ASTUnit::stored_diag_iterator it = (*err_unit)->stored_diag_begin(), | |
| 1191 | it_end = (*err_unit)->stored_diag_end(); | |
| 1192 | it != it_end; ++it) | |
| 1193 | { | |
| 1194 | switch (it->getLevel()) { | |
| 1195 | case clang::DiagnosticsEngine::Ignored: | |
| 1196 | case clang::DiagnosticsEngine::Note: | |
| 1197 | case clang::DiagnosticsEngine::Remark: | |
| 1198 | case clang::DiagnosticsEngine::Warning: | |
| 1199 | continue; | |
| 1200 | case clang::DiagnosticsEngine::Error: | |
| 1201 | case clang::DiagnosticsEngine::Fatal: | |
| 1202 | break; | |
| 1203 | } | |
| 1204 | llvm::StringRef msg_str_ref = it->getMessage(); | |
| 1205 | if (*errors_len >= cap) { | |
| 1206 | cap *= 2; | |
| 1207 | Stage2ErrorMsg *new_errors = reinterpret_cast<Stage2ErrorMsg *>( | |
| 1208 | realloc(*errors_ptr, cap * sizeof(Stage2ErrorMsg))); | |
| 1209 | if (new_errors == nullptr) { | |
| 1210 | free(*errors_ptr); | |
| 1211 | *errors_ptr = nullptr; | |
| 1212 | *errors_len = 0; | |
| 1213 | return nullptr; | |
| 1214 | } | |
| 1215 | *errors_ptr = new_errors; | |
| 1216 | } | |
| 1217 | Stage2ErrorMsg *msg = *errors_ptr + *errors_len; | |
| 1218 | *errors_len += 1; | |
| 1219 | msg->msg_ptr = (const char *)msg_str_ref.bytes_begin(); | |
| 1220 | msg->msg_len = msg_str_ref.size(); | |
| 1221 | ||
| 1222 | clang::FullSourceLoc fsl = it->getLocation(); | |
| 1223 | if (fsl.hasManager()) { | |
| 1224 | clang::FileID file_id = fsl.getFileID(); | |
| 1225 | clang::StringRef filename = fsl.getManager().getFilename(fsl); | |
| 1226 | if (filename.empty()) { | |
| 1227 | msg->filename_ptr = nullptr; | |
| 1228 | } else { | |
| 1229 | msg->filename_ptr = (const char *)filename.bytes_begin(); | |
| 1230 | msg->filename_len = filename.size(); | |
| 1231 | } | |
| 1232 | msg->source = (const char *)fsl.getManager().getBufferData(file_id).bytes_begin(); | |
| 1233 | msg->line = fsl.getSpellingLineNumber() - 1; | |
| 1234 | msg->column = fsl.getSpellingColumnNumber() - 1; | |
| 1235 | msg->offset = fsl.getManager().getFileOffset(fsl); | |
| 1236 | } else { | |
| 1237 | // The only known way this gets triggered right now is if you have a lot of errors | |
| 1238 | // clang emits "too many errors emitted, stopping now" | |
| 1239 | msg->filename_ptr = nullptr; | |
| 1240 | msg->source = nullptr; | |
| 1241 | } | |
| 1242 | } | |
| 1243 | ||
| 1244 | if (*errors_len == 0) { | |
| 1245 | free(*errors_ptr); | |
| 1246 | *errors_ptr = nullptr; | |
| 1247 | } | |
| 1248 | ||
| 1249 | return nullptr; | |
| 1250 | } | |
| 1251 | ||
| 1252 | return reinterpret_cast<ZigClangASTUnit *>(ast_unit); | |
| 1253 | } | |
| 1254 | ||
| 1255 | void ZigClangErrorMsg_delete(Stage2ErrorMsg *ptr, size_t len) { | |
| 1256 | free(ptr); | |
| 1257 | } | |
| 1258 | ||
| 1259 | void ZigClangASTUnit_delete(struct ZigClangASTUnit *self) { | |
| 1260 | delete reinterpret_cast<clang::ASTUnit *>(self); | |
| 1261 | } |
src/zig_clang.h+92-89| ... | ... | @@ -8,17 +8,13 @@ |
| 8 | 8 | #ifndef ZIG_ZIG_CLANG_H |
| 9 | 9 | #define ZIG_ZIG_CLANG_H |
| 10 | 10 | |
| 11 | #include "userland.h" | |
| 11 | 12 | #include <inttypes.h> |
| 12 | ||
| 13 | #ifdef __cplusplus | |
| 14 | #define ZIG_EXTERN_C extern "C" | |
| 15 | #else | |
| 16 | #define ZIG_EXTERN_C | |
| 17 | #endif | |
| 13 | #include <stdbool.h> | |
| 18 | 14 | |
| 19 | 15 | // ATTENTION: If you modify this file, be sure to update the corresponding |
| 20 | // extern function declarations in the self-hosted compiler. | |
| 21 | // Note: not yet, we don't have the corresponding clang.zig yet. | |
| 16 | // extern function declarations in the self-hosted compiler file | |
| 17 | // src-self-hosted/clang.zig. | |
| 22 | 18 | |
| 23 | 19 | struct ZigClangSourceLocation { |
| 24 | 20 | unsigned ID; |
| ... | ... | @@ -486,86 +482,93 @@ enum ZigClangAPValueKind { |
| 486 | 482 | ZigClangAPValueAddrLabelDiff, |
| 487 | 483 | }; |
| 488 | 484 | |
| 489 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangSourceManager_getSpellingLoc(const ZigClangSourceManager *, | |
| 490 | ZigClangSourceLocation Loc); | |
| 491 | ZIG_EXTERN_C const char *ZigClangSourceManager_getFilename(const ZigClangSourceManager *, | |
| 492 | ZigClangSourceLocation SpellingLoc); | |
| 493 | ZIG_EXTERN_C unsigned ZigClangSourceManager_getSpellingLineNumber(const ZigClangSourceManager *, | |
| 494 | ZigClangSourceLocation Loc); | |
| 495 | ZIG_EXTERN_C unsigned ZigClangSourceManager_getSpellingColumnNumber(const ZigClangSourceManager *, | |
| 496 | ZigClangSourceLocation Loc); | |
| 497 | ZIG_EXTERN_C const char* ZigClangSourceManager_getCharacterData(const ZigClangSourceManager *, | |
| 498 | ZigClangSourceLocation SL); | |
| 499 | ||
| 500 | ZIG_EXTERN_C ZigClangQualType ZigClangASTContext_getPointerType(const ZigClangASTContext*, ZigClangQualType T); | |
| 501 | ||
| 502 | ZIG_EXTERN_C ZigClangASTContext *ZigClangASTUnit_getASTContext(ZigClangASTUnit *); | |
| 503 | ZIG_EXTERN_C ZigClangSourceManager *ZigClangASTUnit_getSourceManager(ZigClangASTUnit *); | |
| 504 | ZIG_EXTERN_C bool ZigClangASTUnit_visitLocalTopLevelDecls(ZigClangASTUnit *, void *context, | |
| 505 | bool (*Fn)(void *context, const ZigClangDecl *decl)); | |
| 506 | ||
| 507 | ZIG_EXTERN_C const ZigClangRecordDecl *ZigClangRecordType_getDecl(const ZigClangRecordType *record_ty); | |
| 508 | ZIG_EXTERN_C const ZigClangEnumDecl *ZigClangEnumType_getDecl(const ZigClangEnumType *record_ty); | |
| 509 | ||
| 510 | ZIG_EXTERN_C const ZigClangTagDecl *ZigClangRecordDecl_getCanonicalDecl(const ZigClangRecordDecl *record_decl); | |
| 511 | ZIG_EXTERN_C const ZigClangTagDecl *ZigClangEnumDecl_getCanonicalDecl(const ZigClangEnumDecl *); | |
| 512 | ZIG_EXTERN_C const ZigClangTypedefNameDecl *ZigClangTypedefNameDecl_getCanonicalDecl(const ZigClangTypedefNameDecl *); | |
| 513 | ||
| 514 | ZIG_EXTERN_C const ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const ZigClangRecordDecl *); | |
| 515 | ZIG_EXTERN_C const ZigClangEnumDecl *ZigClangEnumDecl_getDefinition(const ZigClangEnumDecl *); | |
| 516 | ||
| 517 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangRecordDecl_getLocation(const ZigClangRecordDecl *); | |
| 518 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangEnumDecl_getLocation(const ZigClangEnumDecl *); | |
| 519 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangTypedefNameDecl_getLocation(const ZigClangTypedefNameDecl *); | |
| 520 | ||
| 521 | ZIG_EXTERN_C bool ZigClangRecordDecl_isUnion(const ZigClangRecordDecl *record_decl); | |
| 522 | ZIG_EXTERN_C bool ZigClangRecordDecl_isStruct(const ZigClangRecordDecl *record_decl); | |
| 523 | ZIG_EXTERN_C bool ZigClangRecordDecl_isAnonymousStructOrUnion(const ZigClangRecordDecl *record_decl); | |
| 524 | ||
| 525 | ZIG_EXTERN_C ZigClangQualType ZigClangEnumDecl_getIntegerType(const ZigClangEnumDecl *); | |
| 526 | ||
| 527 | ZIG_EXTERN_C const char *ZigClangDecl_getName_bytes_begin(const ZigClangDecl *decl); | |
| 528 | ||
| 529 | ZIG_EXTERN_C bool ZigClangSourceLocation_eq(ZigClangSourceLocation a, ZigClangSourceLocation b); | |
| 530 | ||
| 531 | ZIG_EXTERN_C const ZigClangTypedefNameDecl *ZigClangTypedefType_getDecl(const ZigClangTypedefType *); | |
| 532 | ZIG_EXTERN_C ZigClangQualType ZigClangTypedefNameDecl_getUnderlyingType(const ZigClangTypedefNameDecl *); | |
| 533 | ||
| 534 | ZIG_EXTERN_C ZigClangQualType ZigClangQualType_getCanonicalType(ZigClangQualType); | |
| 535 | ZIG_EXTERN_C const ZigClangType *ZigClangQualType_getTypePtr(ZigClangQualType); | |
| 536 | ZIG_EXTERN_C void ZigClangQualType_addConst(ZigClangQualType *); | |
| 537 | ZIG_EXTERN_C bool ZigClangQualType_eq(ZigClangQualType, ZigClangQualType); | |
| 538 | ZIG_EXTERN_C bool ZigClangQualType_isConstQualified(ZigClangQualType); | |
| 539 | ZIG_EXTERN_C bool ZigClangQualType_isVolatileQualified(ZigClangQualType); | |
| 540 | ZIG_EXTERN_C bool ZigClangQualType_isRestrictQualified(ZigClangQualType); | |
| 541 | ||
| 542 | ZIG_EXTERN_C ZigClangTypeClass ZigClangType_getTypeClass(const ZigClangType *self); | |
| 543 | ZIG_EXTERN_C bool ZigClangType_isVoidType(const ZigClangType *self); | |
| 544 | ZIG_EXTERN_C const char *ZigClangType_getTypeClassName(const ZigClangType *self); | |
| 545 | ||
| 546 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangStmt_getBeginLoc(const ZigClangStmt *self); | |
| 547 | ZIG_EXTERN_C ZigClangStmtClass ZigClangStmt_getStmtClass(const ZigClangStmt *self); | |
| 548 | ZIG_EXTERN_C bool ZigClangStmt_classof_Expr(const ZigClangStmt *self); | |
| 549 | ||
| 550 | ZIG_EXTERN_C ZigClangStmtClass ZigClangExpr_getStmtClass(const ZigClangExpr *self); | |
| 551 | ZIG_EXTERN_C ZigClangQualType ZigClangExpr_getType(const ZigClangExpr *self); | |
| 552 | ZIG_EXTERN_C ZigClangSourceLocation ZigClangExpr_getBeginLoc(const ZigClangExpr *self); | |
| 553 | ||
| 554 | ZIG_EXTERN_C ZigClangAPValueKind ZigClangAPValue_getKind(const ZigClangAPValue *self); | |
| 555 | ZIG_EXTERN_C const ZigClangAPSInt *ZigClangAPValue_getInt(const ZigClangAPValue *self); | |
| 556 | ZIG_EXTERN_C unsigned ZigClangAPValue_getArrayInitializedElts(const ZigClangAPValue *self); | |
| 557 | ZIG_EXTERN_C const ZigClangAPValue *ZigClangAPValue_getArrayInitializedElt(const ZigClangAPValue *self, unsigned i); | |
| 558 | ZIG_EXTERN_C const ZigClangAPValue *ZigClangAPValue_getArrayFiller(const ZigClangAPValue *self); | |
| 559 | ZIG_EXTERN_C unsigned ZigClangAPValue_getArraySize(const ZigClangAPValue *self); | |
| 560 | ZIG_EXTERN_C ZigClangAPValueLValueBase ZigClangAPValue_getLValueBase(const ZigClangAPValue *self); | |
| 561 | ||
| 562 | ZIG_EXTERN_C bool ZigClangAPSInt_isSigned(const ZigClangAPSInt *self); | |
| 563 | ZIG_EXTERN_C bool ZigClangAPSInt_isNegative(const ZigClangAPSInt *self); | |
| 564 | ZIG_EXTERN_C const ZigClangAPSInt *ZigClangAPSInt_negate(const ZigClangAPSInt *self); | |
| 565 | ZIG_EXTERN_C void ZigClangAPSInt_free(const ZigClangAPSInt *self); | |
| 566 | ZIG_EXTERN_C const uint64_t *ZigClangAPSInt_getRawData(const ZigClangAPSInt *self); | |
| 567 | ZIG_EXTERN_C unsigned ZigClangAPSInt_getNumWords(const ZigClangAPSInt *self); | |
| 568 | ||
| 569 | ZIG_EXTERN_C const ZigClangExpr *ZigClangAPValueLValueBase_dyn_cast_Expr(ZigClangAPValueLValueBase self); | |
| 485 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangSourceManager_getSpellingLoc(const struct ZigClangSourceManager *, | |
| 486 | struct ZigClangSourceLocation Loc); | |
| 487 | ZIG_EXTERN_C const char *ZigClangSourceManager_getFilename(const struct ZigClangSourceManager *, | |
| 488 | struct ZigClangSourceLocation SpellingLoc); | |
| 489 | ZIG_EXTERN_C unsigned ZigClangSourceManager_getSpellingLineNumber(const struct ZigClangSourceManager *, | |
| 490 | struct ZigClangSourceLocation Loc); | |
| 491 | ZIG_EXTERN_C unsigned ZigClangSourceManager_getSpellingColumnNumber(const struct ZigClangSourceManager *, | |
| 492 | struct ZigClangSourceLocation Loc); | |
| 493 | ZIG_EXTERN_C const char* ZigClangSourceManager_getCharacterData(const struct ZigClangSourceManager *, | |
| 494 | struct ZigClangSourceLocation SL); | |
| 495 | ||
| 496 | ZIG_EXTERN_C struct ZigClangQualType ZigClangASTContext_getPointerType(const struct ZigClangASTContext*, struct ZigClangQualType T); | |
| 497 | ||
| 498 | ||
| 499 | // Can return null. | |
| 500 | ZIG_EXTERN_C struct ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char **args_end, | |
| 501 | struct Stage2ErrorMsg **errors_ptr, size_t *errors_len, const char *resources_path); | |
| 502 | ZIG_EXTERN_C void ZigClangASTUnit_delete(struct ZigClangASTUnit *); | |
| 503 | ZIG_EXTERN_C void ZigClangErrorMsg_delete(struct Stage2ErrorMsg *ptr, size_t len); | |
| 504 | ||
| 505 | ZIG_EXTERN_C struct ZigClangASTContext *ZigClangASTUnit_getASTContext(struct ZigClangASTUnit *); | |
| 506 | ZIG_EXTERN_C struct ZigClangSourceManager *ZigClangASTUnit_getSourceManager(struct ZigClangASTUnit *); | |
| 507 | ZIG_EXTERN_C bool ZigClangASTUnit_visitLocalTopLevelDecls(struct ZigClangASTUnit *, void *context, | |
| 508 | bool (*Fn)(void *context, const struct ZigClangDecl *decl)); | |
| 509 | ||
| 510 | ZIG_EXTERN_C const struct ZigClangRecordDecl *ZigClangRecordType_getDecl(const struct ZigClangRecordType *record_ty); | |
| 511 | ZIG_EXTERN_C const struct ZigClangEnumDecl *ZigClangEnumType_getDecl(const struct ZigClangEnumType *record_ty); | |
| 512 | ||
| 513 | ZIG_EXTERN_C const struct ZigClangTagDecl *ZigClangRecordDecl_getCanonicalDecl(const struct ZigClangRecordDecl *record_decl); | |
| 514 | ZIG_EXTERN_C const struct ZigClangTagDecl *ZigClangEnumDecl_getCanonicalDecl(const struct ZigClangEnumDecl *); | |
| 515 | ZIG_EXTERN_C const struct ZigClangTypedefNameDecl *ZigClangTypedefNameDecl_getCanonicalDecl(const struct ZigClangTypedefNameDecl *); | |
| 516 | ||
| 517 | ZIG_EXTERN_C const struct ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const struct ZigClangRecordDecl *); | |
| 518 | ZIG_EXTERN_C const struct ZigClangEnumDecl *ZigClangEnumDecl_getDefinition(const struct ZigClangEnumDecl *); | |
| 519 | ||
| 520 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangRecordDecl_getLocation(const struct ZigClangRecordDecl *); | |
| 521 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangEnumDecl_getLocation(const struct ZigClangEnumDecl *); | |
| 522 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangTypedefNameDecl_getLocation(const struct ZigClangTypedefNameDecl *); | |
| 523 | ||
| 524 | ZIG_EXTERN_C bool ZigClangRecordDecl_isUnion(const struct ZigClangRecordDecl *record_decl); | |
| 525 | ZIG_EXTERN_C bool ZigClangRecordDecl_isStruct(const struct ZigClangRecordDecl *record_decl); | |
| 526 | ZIG_EXTERN_C bool ZigClangRecordDecl_isAnonymousStructOrUnion(const struct ZigClangRecordDecl *record_decl); | |
| 527 | ||
| 528 | ZIG_EXTERN_C struct ZigClangQualType ZigClangEnumDecl_getIntegerType(const struct ZigClangEnumDecl *); | |
| 529 | ||
| 530 | ZIG_EXTERN_C const char *ZigClangDecl_getName_bytes_begin(const struct ZigClangDecl *decl); | |
| 531 | ||
| 532 | ZIG_EXTERN_C bool ZigClangSourceLocation_eq(struct ZigClangSourceLocation a, struct ZigClangSourceLocation b); | |
| 533 | ||
| 534 | ZIG_EXTERN_C const struct ZigClangTypedefNameDecl *ZigClangTypedefType_getDecl(const struct ZigClangTypedefType *); | |
| 535 | ZIG_EXTERN_C struct ZigClangQualType ZigClangTypedefNameDecl_getUnderlyingType(const struct ZigClangTypedefNameDecl *); | |
| 536 | ||
| 537 | ZIG_EXTERN_C struct ZigClangQualType ZigClangQualType_getCanonicalType(struct ZigClangQualType); | |
| 538 | ZIG_EXTERN_C const struct ZigClangType *ZigClangQualType_getTypePtr(struct ZigClangQualType); | |
| 539 | ZIG_EXTERN_C void ZigClangQualType_addConst(struct ZigClangQualType *); | |
| 540 | ZIG_EXTERN_C bool ZigClangQualType_eq(struct ZigClangQualType, struct ZigClangQualType); | |
| 541 | ZIG_EXTERN_C bool ZigClangQualType_isConstQualified(struct ZigClangQualType); | |
| 542 | ZIG_EXTERN_C bool ZigClangQualType_isVolatileQualified(struct ZigClangQualType); | |
| 543 | ZIG_EXTERN_C bool ZigClangQualType_isRestrictQualified(struct ZigClangQualType); | |
| 544 | ||
| 545 | ZIG_EXTERN_C enum ZigClangTypeClass ZigClangType_getTypeClass(const struct ZigClangType *self); | |
| 546 | ZIG_EXTERN_C bool ZigClangType_isVoidType(const struct ZigClangType *self); | |
| 547 | ZIG_EXTERN_C const char *ZigClangType_getTypeClassName(const struct ZigClangType *self); | |
| 548 | ||
| 549 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangStmt_getBeginLoc(const struct ZigClangStmt *self); | |
| 550 | ZIG_EXTERN_C enum ZigClangStmtClass ZigClangStmt_getStmtClass(const struct ZigClangStmt *self); | |
| 551 | ZIG_EXTERN_C bool ZigClangStmt_classof_Expr(const struct ZigClangStmt *self); | |
| 552 | ||
| 553 | ZIG_EXTERN_C enum ZigClangStmtClass ZigClangExpr_getStmtClass(const struct ZigClangExpr *self); | |
| 554 | ZIG_EXTERN_C struct ZigClangQualType ZigClangExpr_getType(const struct ZigClangExpr *self); | |
| 555 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangExpr_getBeginLoc(const struct ZigClangExpr *self); | |
| 556 | ||
| 557 | ZIG_EXTERN_C enum ZigClangAPValueKind ZigClangAPValue_getKind(const struct ZigClangAPValue *self); | |
| 558 | ZIG_EXTERN_C const struct ZigClangAPSInt *ZigClangAPValue_getInt(const struct ZigClangAPValue *self); | |
| 559 | ZIG_EXTERN_C unsigned ZigClangAPValue_getArrayInitializedElts(const struct ZigClangAPValue *self); | |
| 560 | ZIG_EXTERN_C const struct ZigClangAPValue *ZigClangAPValue_getArrayInitializedElt(const struct ZigClangAPValue *self, unsigned i); | |
| 561 | ZIG_EXTERN_C const struct ZigClangAPValue *ZigClangAPValue_getArrayFiller(const struct ZigClangAPValue *self); | |
| 562 | ZIG_EXTERN_C unsigned ZigClangAPValue_getArraySize(const struct ZigClangAPValue *self); | |
| 563 | ZIG_EXTERN_C struct ZigClangAPValueLValueBase ZigClangAPValue_getLValueBase(const struct ZigClangAPValue *self); | |
| 564 | ||
| 565 | ZIG_EXTERN_C bool ZigClangAPSInt_isSigned(const struct ZigClangAPSInt *self); | |
| 566 | ZIG_EXTERN_C bool ZigClangAPSInt_isNegative(const struct ZigClangAPSInt *self); | |
| 567 | ZIG_EXTERN_C const struct ZigClangAPSInt *ZigClangAPSInt_negate(const struct ZigClangAPSInt *self); | |
| 568 | ZIG_EXTERN_C void ZigClangAPSInt_free(const struct ZigClangAPSInt *self); | |
| 569 | ZIG_EXTERN_C const uint64_t *ZigClangAPSInt_getRawData(const struct ZigClangAPSInt *self); | |
| 570 | ZIG_EXTERN_C unsigned ZigClangAPSInt_getNumWords(const struct ZigClangAPSInt *self); | |
| 571 | ||
| 572 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangAPValueLValueBase_dyn_cast_Expr(struct ZigClangAPValueLValueBase self); | |
| 570 | 573 | |
| 571 | 574 | #endif |
std/c.zig+6| ... | ... | @@ -12,6 +12,12 @@ pub use switch (builtin.os) { |
| 12 | 12 | |
| 13 | 13 | // TODO https://github.com/ziglang/zig/issues/265 on this whole file |
| 14 | 14 | |
| 15 | pub const FILE = @OpaqueType(); | |
| 16 | pub extern "c" fn fopen(filename: [*]const u8, modes: [*]const u8) ?*FILE; | |
| 17 | pub extern "c" fn fclose(stream: *FILE) c_int; | |
| 18 | pub extern "c" fn fwrite(ptr: [*]const u8, size_of_type: usize, item_count: usize, stream: *FILE) usize; | |
| 19 | pub extern "c" fn fread(ptr: [*]u8, size_of_type: usize, item_count: usize, stream: *FILE) usize; | |
| 20 | ||
| 15 | 21 | pub extern "c" fn abort() noreturn; |
| 16 | 22 | pub extern "c" fn exit(code: c_int) noreturn; |
| 17 | 23 | pub extern "c" fn isatty(fd: c_int) c_int; |
std/io.zig+20-13| ... | ... | @@ -36,6 +36,7 @@ pub fn getStdIn() GetStdIoErrs!File { |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | pub const SeekableStream = @import("io/seekable_stream.zig").SeekableStream; |
| 39 | pub const COutStream = @import("io/c_out_stream.zig").COutStream; | |
| 39 | 40 | |
| 40 | 41 | pub fn InStream(comptime ReadError: type) type { |
| 41 | 42 | return struct { |
| ... | ... | @@ -1089,8 +1090,11 @@ test "io.readLineSliceFrom" { |
| 1089 | 1090 | } |
| 1090 | 1091 | |
| 1091 | 1092 | pub const Packing = enum { |
| 1092 | Byte, /// Pack data to byte alignment | |
| 1093 | Bit, /// Pack data to bit alignment | |
| 1093 | /// Pack data to byte alignment | |
| 1094 | Byte, | |
| 1095 | ||
| 1096 | /// Pack data to bit alignment | |
| 1097 | Bit, | |
| 1094 | 1098 | }; |
| 1095 | 1099 | |
| 1096 | 1100 | /// Creates a deserializer that deserializes types from any stream. |
| ... | ... | @@ -1111,10 +1115,12 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 1111 | 1115 | pub const Stream = InStream(Error); |
| 1112 | 1116 | |
| 1113 | 1117 | pub fn init(in_stream: *Stream) Self { |
| 1114 | return Self{ .in_stream = switch (packing) { | |
| 1115 | .Bit => BitInStream(endian, Stream.Error).init(in_stream), | |
| 1116 | .Byte => in_stream, | |
| 1117 | } }; | |
| 1118 | return Self{ | |
| 1119 | .in_stream = switch (packing) { | |
| 1120 | .Bit => BitInStream(endian, Stream.Error).init(in_stream), | |
| 1121 | .Byte => in_stream, | |
| 1122 | }, | |
| 1123 | }; | |
| 1118 | 1124 | } |
| 1119 | 1125 | |
| 1120 | 1126 | pub fn alignToByte(self: *Self) void { |
| ... | ... | @@ -1281,7 +1287,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 1281 | 1287 | ptr.* = null; |
| 1282 | 1288 | return; |
| 1283 | 1289 | } |
| 1284 | ||
| 1290 | ||
| 1285 | 1291 | ptr.* = OC(undefined); //make it non-null so the following .? is guaranteed safe |
| 1286 | 1292 | const val_ptr = &ptr.*.?; |
| 1287 | 1293 | try self.deserializeInto(val_ptr); |
| ... | ... | @@ -1320,10 +1326,12 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1320 | 1326 | pub const Stream = OutStream(Error); |
| 1321 | 1327 | |
| 1322 | 1328 | pub fn init(out_stream: *Stream) Self { |
| 1323 | return Self{ .out_stream = switch (packing) { | |
| 1324 | .Bit => BitOutStream(endian, Stream.Error).init(out_stream), | |
| 1325 | .Byte => out_stream, | |
| 1326 | } }; | |
| 1329 | return Self{ | |
| 1330 | .out_stream = switch (packing) { | |
| 1331 | .Bit => BitOutStream(endian, Stream.Error).init(out_stream), | |
| 1332 | .Byte => out_stream, | |
| 1333 | }, | |
| 1334 | }; | |
| 1327 | 1335 | } |
| 1328 | 1336 | |
| 1329 | 1337 | /// Flushes any unwritten bits to the stream |
| ... | ... | @@ -1447,7 +1455,6 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1447 | 1455 | |
| 1448 | 1456 | test "import io tests" { |
| 1449 | 1457 | comptime { |
| 1450 | _ = @import("io_test.zig"); | |
| 1458 | _ = @import("io/test.zig"); | |
| 1451 | 1459 | } |
| 1452 | 1460 | } |
| 1453 |
std/io/c_out_stream.zig created+48| ... | ... | @@ -0,0 +1,48 @@ |
| 1 | const std = @import("../std.zig"); | |
| 2 | const OutStream = std.io.OutStream; | |
| 3 | const builtin = @import("builtin"); | |
| 4 | const posix = std.os.posix; | |
| 5 | ||
| 6 | /// TODO make std.os.FILE use *FILE when linking libc and this just becomes | |
| 7 | /// std.io.FileOutStream because std.os.File.write would do this when linking | |
| 8 | /// libc. | |
| 9 | pub const COutStream = struct { | |
| 10 | pub const Error = std.os.File.WriteError; | |
| 11 | pub const Stream = OutStream(Error); | |
| 12 | ||
| 13 | stream: Stream, | |
| 14 | c_file: *std.c.FILE, | |
| 15 | ||
| 16 | pub fn init(c_file: *std.c.FILE) COutStream { | |
| 17 | return COutStream{ | |
| 18 | .c_file = c_file, | |
| 19 | .stream = Stream{ .writeFn = writeFn }, | |
| 20 | }; | |
| 21 | } | |
| 22 | ||
| 23 | fn writeFn(out_stream: *Stream, bytes: []const u8) Error!void { | |
| 24 | const self = @fieldParentPtr(COutStream, "stream", out_stream); | |
| 25 | const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, self.c_file); | |
| 26 | if (amt_written == bytes.len) return; | |
| 27 | // TODO errno on windows. should we have a posix layer for windows? | |
| 28 | if (builtin.os == .windows) { | |
| 29 | return error.InputOutput; | |
| 30 | } | |
| 31 | const errno = std.c._errno().*; | |
| 32 | switch (errno) { | |
| 33 | 0 => unreachable, | |
| 34 | posix.EINVAL => unreachable, | |
| 35 | posix.EFAULT => unreachable, | |
| 36 | posix.EAGAIN => unreachable, // this is a blocking API | |
| 37 | posix.EBADF => unreachable, // always a race condition | |
| 38 | posix.EDESTADDRREQ => unreachable, // connect was never called | |
| 39 | posix.EDQUOT => return error.DiskQuota, | |
| 40 | posix.EFBIG => return error.FileTooBig, | |
| 41 | posix.EIO => return error.InputOutput, | |
| 42 | posix.ENOSPC => return error.NoSpaceLeft, | |
| 43 | posix.EPERM => return error.AccessDenied, | |
| 44 | posix.EPIPE => return error.BrokenPipe, | |
| 45 | else => return std.os.unexpectedErrorPosix(@intCast(usize, errno)), | |
| 46 | } | |
| 47 | } | |
| 48 | }; |
std/io/test.zig created+602| ... | ... | @@ -0,0 +1,602 @@ |
| 1 | const std = @import("../std.zig"); | |
| 2 | const io = std.io; | |
| 3 | const meta = std.meta; | |
| 4 | const trait = std.trait; | |
| 5 | const DefaultPrng = std.rand.DefaultPrng; | |
| 6 | const expect = std.testing.expect; | |
| 7 | const expectError = std.testing.expectError; | |
| 8 | const mem = std.mem; | |
| 9 | const os = std.os; | |
| 10 | const builtin = @import("builtin"); | |
| 11 | ||
| 12 | test "write a file, read it, then delete it" { | |
| 13 | var raw_bytes: [200 * 1024]u8 = undefined; | |
| 14 | var allocator = &std.heap.FixedBufferAllocator.init(raw_bytes[0..]).allocator; | |
| 15 | ||
| 16 | var data: [1024]u8 = undefined; | |
| 17 | var prng = DefaultPrng.init(1234); | |
| 18 | prng.random.bytes(data[0..]); | |
| 19 | const tmp_file_name = "temp_test_file.txt"; | |
| 20 | { | |
| 21 | var file = try os.File.openWrite(tmp_file_name); | |
| 22 | defer file.close(); | |
| 23 | ||
| 24 | var file_out_stream = file.outStream(); | |
| 25 | var buf_stream = io.BufferedOutStream(os.File.WriteError).init(&file_out_stream.stream); | |
| 26 | const st = &buf_stream.stream; | |
| 27 | try st.print("begin"); | |
| 28 | try st.write(data[0..]); | |
| 29 | try st.print("end"); | |
| 30 | try buf_stream.flush(); | |
| 31 | } | |
| 32 | ||
| 33 | { | |
| 34 | // make sure openWriteNoClobber doesn't harm the file | |
| 35 | if (os.File.openWriteNoClobber(tmp_file_name, os.File.default_mode)) |file| { | |
| 36 | unreachable; | |
| 37 | } else |err| { | |
| 38 | std.debug.assert(err == os.File.OpenError.PathAlreadyExists); | |
| 39 | } | |
| 40 | } | |
| 41 | ||
| 42 | { | |
| 43 | var file = try os.File.openRead(tmp_file_name); | |
| 44 | defer file.close(); | |
| 45 | ||
| 46 | const file_size = try file.getEndPos(); | |
| 47 | const expected_file_size = "begin".len + data.len + "end".len; | |
| 48 | expect(file_size == expected_file_size); | |
| 49 | ||
| 50 | var file_in_stream = file.inStream(); | |
| 51 | var buf_stream = io.BufferedInStream(os.File.ReadError).init(&file_in_stream.stream); | |
| 52 | const st = &buf_stream.stream; | |
| 53 | const contents = try st.readAllAlloc(allocator, 2 * 1024); | |
| 54 | defer allocator.free(contents); | |
| 55 | ||
| 56 | expect(mem.eql(u8, contents[0.."begin".len], "begin")); | |
| 57 | expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data)); | |
| 58 | expect(mem.eql(u8, contents[contents.len - "end".len ..], "end")); | |
| 59 | } | |
| 60 | try os.deleteFile(tmp_file_name); | |
| 61 | } | |
| 62 | ||
| 63 | test "BufferOutStream" { | |
| 64 | var bytes: [100]u8 = undefined; | |
| 65 | var allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator; | |
| 66 | ||
| 67 | var buffer = try std.Buffer.initSize(allocator, 0); | |
| 68 | var buf_stream = &std.io.BufferOutStream.init(&buffer).stream; | |
| 69 | ||
| 70 | const x: i32 = 42; | |
| 71 | const y: i32 = 1234; | |
| 72 | try buf_stream.print("x: {}\ny: {}\n", x, y); | |
| 73 | ||
| 74 | expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n")); | |
| 75 | } | |
| 76 | ||
| 77 | test "SliceInStream" { | |
| 78 | const bytes = []const u8{ 1, 2, 3, 4, 5, 6, 7 }; | |
| 79 | var ss = io.SliceInStream.init(bytes); | |
| 80 | ||
| 81 | var dest: [4]u8 = undefined; | |
| 82 | ||
| 83 | var read = try ss.stream.read(dest[0..4]); | |
| 84 | expect(read == 4); | |
| 85 | expect(mem.eql(u8, dest[0..4], bytes[0..4])); | |
| 86 | ||
| 87 | read = try ss.stream.read(dest[0..4]); | |
| 88 | expect(read == 3); | |
| 89 | expect(mem.eql(u8, dest[0..3], bytes[4..7])); | |
| 90 | ||
| 91 | read = try ss.stream.read(dest[0..4]); | |
| 92 | expect(read == 0); | |
| 93 | } | |
| 94 | ||
| 95 | test "PeekStream" { | |
| 96 | const bytes = []const u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; | |
| 97 | var ss = io.SliceInStream.init(bytes); | |
| 98 | var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream); | |
| 99 | ||
| 100 | var dest: [4]u8 = undefined; | |
| 101 | ||
| 102 | ps.putBackByte(9); | |
| 103 | ps.putBackByte(10); | |
| 104 | ||
| 105 | var read = try ps.stream.read(dest[0..4]); | |
| 106 | expect(read == 4); | |
| 107 | expect(dest[0] == 10); | |
| 108 | expect(dest[1] == 9); | |
| 109 | expect(mem.eql(u8, dest[2..4], bytes[0..2])); | |
| 110 | ||
| 111 | read = try ps.stream.read(dest[0..4]); | |
| 112 | expect(read == 4); | |
| 113 | expect(mem.eql(u8, dest[0..4], bytes[2..6])); | |
| 114 | ||
| 115 | read = try ps.stream.read(dest[0..4]); | |
| 116 | expect(read == 2); | |
| 117 | expect(mem.eql(u8, dest[0..2], bytes[6..8])); | |
| 118 | ||
| 119 | ps.putBackByte(11); | |
| 120 | ps.putBackByte(12); | |
| 121 | ||
| 122 | read = try ps.stream.read(dest[0..4]); | |
| 123 | expect(read == 2); | |
| 124 | expect(dest[0] == 12); | |
| 125 | expect(dest[1] == 11); | |
| 126 | } | |
| 127 | ||
| 128 | test "SliceOutStream" { | |
| 129 | var buffer: [10]u8 = undefined; | |
| 130 | var ss = io.SliceOutStream.init(buffer[0..]); | |
| 131 | ||
| 132 | try ss.stream.write("Hello"); | |
| 133 | expect(mem.eql(u8, ss.getWritten(), "Hello")); | |
| 134 | ||
| 135 | try ss.stream.write("world"); | |
| 136 | expect(mem.eql(u8, ss.getWritten(), "Helloworld")); | |
| 137 | ||
| 138 | expectError(error.OutOfSpace, ss.stream.write("!")); | |
| 139 | expect(mem.eql(u8, ss.getWritten(), "Helloworld")); | |
| 140 | ||
| 141 | ss.reset(); | |
| 142 | expect(ss.getWritten().len == 0); | |
| 143 | ||
| 144 | expectError(error.OutOfSpace, ss.stream.write("Hello world!")); | |
| 145 | expect(mem.eql(u8, ss.getWritten(), "Hello worl")); | |
| 146 | } | |
| 147 | ||
| 148 | test "BitInStream" { | |
| 149 | const mem_be = []u8{ 0b11001101, 0b00001011 }; | |
| 150 | const mem_le = []u8{ 0b00011101, 0b10010101 }; | |
| 151 | ||
| 152 | var mem_in_be = io.SliceInStream.init(mem_be[0..]); | |
| 153 | const InError = io.SliceInStream.Error; | |
| 154 | var bit_stream_be = io.BitInStream(builtin.Endian.Big, InError).init(&mem_in_be.stream); | |
| 155 | ||
| 156 | var out_bits: usize = undefined; | |
| 157 | ||
| 158 | expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits)); | |
| 159 | expect(out_bits == 1); | |
| 160 | expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits)); | |
| 161 | expect(out_bits == 2); | |
| 162 | expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits)); | |
| 163 | expect(out_bits == 3); | |
| 164 | expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits)); | |
| 165 | expect(out_bits == 4); | |
| 166 | expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits)); | |
| 167 | expect(out_bits == 5); | |
| 168 | expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 169 | expect(out_bits == 1); | |
| 170 | ||
| 171 | mem_in_be.pos = 0; | |
| 172 | bit_stream_be.bit_count = 0; | |
| 173 | expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits)); | |
| 174 | expect(out_bits == 15); | |
| 175 | ||
| 176 | mem_in_be.pos = 0; | |
| 177 | bit_stream_be.bit_count = 0; | |
| 178 | expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits)); | |
| 179 | expect(out_bits == 16); | |
| 180 | ||
| 181 | _ = try bit_stream_be.readBits(u0, 0, &out_bits); | |
| 182 | ||
| 183 | expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 184 | expect(out_bits == 0); | |
| 185 | expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1)); | |
| 186 | ||
| 187 | var mem_in_le = io.SliceInStream.init(mem_le[0..]); | |
| 188 | var bit_stream_le = io.BitInStream(builtin.Endian.Little, InError).init(&mem_in_le.stream); | |
| 189 | ||
| 190 | expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits)); | |
| 191 | expect(out_bits == 1); | |
| 192 | expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits)); | |
| 193 | expect(out_bits == 2); | |
| 194 | expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits)); | |
| 195 | expect(out_bits == 3); | |
| 196 | expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits)); | |
| 197 | expect(out_bits == 4); | |
| 198 | expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits)); | |
| 199 | expect(out_bits == 5); | |
| 200 | expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 201 | expect(out_bits == 1); | |
| 202 | ||
| 203 | mem_in_le.pos = 0; | |
| 204 | bit_stream_le.bit_count = 0; | |
| 205 | expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits)); | |
| 206 | expect(out_bits == 15); | |
| 207 | ||
| 208 | mem_in_le.pos = 0; | |
| 209 | bit_stream_le.bit_count = 0; | |
| 210 | expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits)); | |
| 211 | expect(out_bits == 16); | |
| 212 | ||
| 213 | _ = try bit_stream_le.readBits(u0, 0, &out_bits); | |
| 214 | ||
| 215 | expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 216 | expect(out_bits == 0); | |
| 217 | expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1)); | |
| 218 | } | |
| 219 | ||
| 220 | test "BitOutStream" { | |
| 221 | var mem_be = []u8{0} ** 2; | |
| 222 | var mem_le = []u8{0} ** 2; | |
| 223 | ||
| 224 | var mem_out_be = io.SliceOutStream.init(mem_be[0..]); | |
| 225 | const OutError = io.SliceOutStream.Error; | |
| 226 | var bit_stream_be = io.BitOutStream(builtin.Endian.Big, OutError).init(&mem_out_be.stream); | |
| 227 | ||
| 228 | try bit_stream_be.writeBits(u2(1), 1); | |
| 229 | try bit_stream_be.writeBits(u5(2), 2); | |
| 230 | try bit_stream_be.writeBits(u128(3), 3); | |
| 231 | try bit_stream_be.writeBits(u8(4), 4); | |
| 232 | try bit_stream_be.writeBits(u9(5), 5); | |
| 233 | try bit_stream_be.writeBits(u1(1), 1); | |
| 234 | ||
| 235 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011); | |
| 236 | ||
| 237 | mem_out_be.pos = 0; | |
| 238 | ||
| 239 | try bit_stream_be.writeBits(u15(0b110011010000101), 15); | |
| 240 | try bit_stream_be.flushBits(); | |
| 241 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010); | |
| 242 | ||
| 243 | mem_out_be.pos = 0; | |
| 244 | try bit_stream_be.writeBits(u32(0b110011010000101), 16); | |
| 245 | expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101); | |
| 246 | ||
| 247 | try bit_stream_be.writeBits(u0(0), 0); | |
| 248 | ||
| 249 | var mem_out_le = io.SliceOutStream.init(mem_le[0..]); | |
| 250 | var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream); | |
| 251 | ||
| 252 | try bit_stream_le.writeBits(u2(1), 1); | |
| 253 | try bit_stream_le.writeBits(u5(2), 2); | |
| 254 | try bit_stream_le.writeBits(u128(3), 3); | |
| 255 | try bit_stream_le.writeBits(u8(4), 4); | |
| 256 | try bit_stream_le.writeBits(u9(5), 5); | |
| 257 | try bit_stream_le.writeBits(u1(1), 1); | |
| 258 | ||
| 259 | expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101); | |
| 260 | ||
| 261 | mem_out_le.pos = 0; | |
| 262 | try bit_stream_le.writeBits(u15(0b110011010000101), 15); | |
| 263 | try bit_stream_le.flushBits(); | |
| 264 | expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110); | |
| 265 | ||
| 266 | mem_out_le.pos = 0; | |
| 267 | try bit_stream_le.writeBits(u32(0b1100110100001011), 16); | |
| 268 | expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101); | |
| 269 | ||
| 270 | try bit_stream_le.writeBits(u0(0), 0); | |
| 271 | } | |
| 272 | ||
| 273 | test "BitStreams with File Stream" { | |
| 274 | const tmp_file_name = "temp_test_file.txt"; | |
| 275 | { | |
| 276 | var file = try os.File.openWrite(tmp_file_name); | |
| 277 | defer file.close(); | |
| 278 | ||
| 279 | var file_out = file.outStream(); | |
| 280 | var file_out_stream = &file_out.stream; | |
| 281 | const OutError = os.File.WriteError; | |
| 282 | var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream); | |
| 283 | ||
| 284 | try bit_stream.writeBits(u2(1), 1); | |
| 285 | try bit_stream.writeBits(u5(2), 2); | |
| 286 | try bit_stream.writeBits(u128(3), 3); | |
| 287 | try bit_stream.writeBits(u8(4), 4); | |
| 288 | try bit_stream.writeBits(u9(5), 5); | |
| 289 | try bit_stream.writeBits(u1(1), 1); | |
| 290 | try bit_stream.flushBits(); | |
| 291 | } | |
| 292 | { | |
| 293 | var file = try os.File.openRead(tmp_file_name); | |
| 294 | defer file.close(); | |
| 295 | ||
| 296 | var file_in = file.inStream(); | |
| 297 | var file_in_stream = &file_in.stream; | |
| 298 | const InError = os.File.ReadError; | |
| 299 | var bit_stream = io.BitInStream(builtin.endian, InError).init(file_in_stream); | |
| 300 | ||
| 301 | var out_bits: usize = undefined; | |
| 302 | ||
| 303 | expect(1 == try bit_stream.readBits(u2, 1, &out_bits)); | |
| 304 | expect(out_bits == 1); | |
| 305 | expect(2 == try bit_stream.readBits(u5, 2, &out_bits)); | |
| 306 | expect(out_bits == 2); | |
| 307 | expect(3 == try bit_stream.readBits(u128, 3, &out_bits)); | |
| 308 | expect(out_bits == 3); | |
| 309 | expect(4 == try bit_stream.readBits(u8, 4, &out_bits)); | |
| 310 | expect(out_bits == 4); | |
| 311 | expect(5 == try bit_stream.readBits(u9, 5, &out_bits)); | |
| 312 | expect(out_bits == 5); | |
| 313 | expect(1 == try bit_stream.readBits(u1, 1, &out_bits)); | |
| 314 | expect(out_bits == 1); | |
| 315 | ||
| 316 | expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1)); | |
| 317 | } | |
| 318 | try os.deleteFile(tmp_file_name); | |
| 319 | } | |
| 320 | ||
| 321 | fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void { | |
| 322 | //@NOTE: if this test is taking too long, reduce the maximum tested bitsize | |
| 323 | const max_test_bitsize = 128; | |
| 324 | ||
| 325 | const total_bytes = comptime blk: { | |
| 326 | var bytes = 0; | |
| 327 | comptime var i = 0; | |
| 328 | while (i <= max_test_bitsize) : (i += 1) bytes += (i / 8) + @boolToInt(i % 8 > 0); | |
| 329 | break :blk bytes * 2; | |
| 330 | }; | |
| 331 | ||
| 332 | var data_mem: [total_bytes]u8 = undefined; | |
| 333 | var out = io.SliceOutStream.init(data_mem[0..]); | |
| 334 | const OutError = io.SliceOutStream.Error; | |
| 335 | var out_stream = &out.stream; | |
| 336 | var serializer = io.Serializer(endian, packing, OutError).init(out_stream); | |
| 337 | ||
| 338 | var in = io.SliceInStream.init(data_mem[0..]); | |
| 339 | const InError = io.SliceInStream.Error; | |
| 340 | var in_stream = &in.stream; | |
| 341 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); | |
| 342 | ||
| 343 | comptime var i = 0; | |
| 344 | inline while (i <= max_test_bitsize) : (i += 1) { | |
| 345 | const U = @IntType(false, i); | |
| 346 | const S = @IntType(true, i); | |
| 347 | try serializer.serializeInt(U(i)); | |
| 348 | if (i != 0) try serializer.serializeInt(S(-1)) else try serializer.serialize(S(0)); | |
| 349 | } | |
| 350 | try serializer.flush(); | |
| 351 | ||
| 352 | i = 0; | |
| 353 | inline while (i <= max_test_bitsize) : (i += 1) { | |
| 354 | const U = @IntType(false, i); | |
| 355 | const S = @IntType(true, i); | |
| 356 | const x = try deserializer.deserializeInt(U); | |
| 357 | const y = try deserializer.deserializeInt(S); | |
| 358 | expect(x == U(i)); | |
| 359 | if (i != 0) expect(y == S(-1)) else expect(y == 0); | |
| 360 | } | |
| 361 | ||
| 362 | const u8_bit_count = comptime meta.bitCount(u8); | |
| 363 | //0 + 1 + 2 + ... n = (n * (n + 1)) / 2 | |
| 364 | //and we have each for unsigned and signed, so * 2 | |
| 365 | const total_bits = (max_test_bitsize * (max_test_bitsize + 1)); | |
| 366 | const extra_packed_byte = @boolToInt(total_bits % u8_bit_count > 0); | |
| 367 | const total_packed_bytes = (total_bits / u8_bit_count) + extra_packed_byte; | |
| 368 | ||
| 369 | expect(in.pos == if (packing == .Bit) total_packed_bytes else total_bytes); | |
| 370 | ||
| 371 | //Verify that empty error set works with serializer. | |
| 372 | //deserializer is covered by SliceInStream | |
| 373 | const NullError = io.NullOutStream.Error; | |
| 374 | var null_out = io.NullOutStream.init(); | |
| 375 | var null_out_stream = &null_out.stream; | |
| 376 | var null_serializer = io.Serializer(endian, packing, NullError).init(null_out_stream); | |
| 377 | try null_serializer.serialize(data_mem[0..]); | |
| 378 | try null_serializer.flush(); | |
| 379 | } | |
| 380 | ||
| 381 | test "Serializer/Deserializer Int" { | |
| 382 | try testIntSerializerDeserializer(.Big, .Byte); | |
| 383 | try testIntSerializerDeserializer(.Little, .Byte); | |
| 384 | // TODO these tests are disabled due to tripping an LLVM assertion | |
| 385 | // https://github.com/ziglang/zig/issues/2019 | |
| 386 | //try testIntSerializerDeserializer(builtin.Endian.Big, true); | |
| 387 | //try testIntSerializerDeserializer(builtin.Endian.Little, true); | |
| 388 | } | |
| 389 | ||
| 390 | fn testIntSerializerDeserializerInfNaN( | |
| 391 | comptime endian: builtin.Endian, | |
| 392 | comptime packing: io.Packing, | |
| 393 | ) !void { | |
| 394 | const mem_size = (16 * 2 + 32 * 2 + 64 * 2 + 128 * 2) / comptime meta.bitCount(u8); | |
| 395 | var data_mem: [mem_size]u8 = undefined; | |
| 396 | ||
| 397 | var out = io.SliceOutStream.init(data_mem[0..]); | |
| 398 | const OutError = io.SliceOutStream.Error; | |
| 399 | var out_stream = &out.stream; | |
| 400 | var serializer = io.Serializer(endian, packing, OutError).init(out_stream); | |
| 401 | ||
| 402 | var in = io.SliceInStream.init(data_mem[0..]); | |
| 403 | const InError = io.SliceInStream.Error; | |
| 404 | var in_stream = &in.stream; | |
| 405 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); | |
| 406 | ||
| 407 | //@TODO: isInf/isNan not currently implemented for f128. | |
| 408 | try serializer.serialize(std.math.nan(f16)); | |
| 409 | try serializer.serialize(std.math.inf(f16)); | |
| 410 | try serializer.serialize(std.math.nan(f32)); | |
| 411 | try serializer.serialize(std.math.inf(f32)); | |
| 412 | try serializer.serialize(std.math.nan(f64)); | |
| 413 | try serializer.serialize(std.math.inf(f64)); | |
| 414 | //try serializer.serialize(std.math.nan(f128)); | |
| 415 | //try serializer.serialize(std.math.inf(f128)); | |
| 416 | const nan_check_f16 = try deserializer.deserialize(f16); | |
| 417 | const inf_check_f16 = try deserializer.deserialize(f16); | |
| 418 | const nan_check_f32 = try deserializer.deserialize(f32); | |
| 419 | const inf_check_f32 = try deserializer.deserialize(f32); | |
| 420 | const nan_check_f64 = try deserializer.deserialize(f64); | |
| 421 | const inf_check_f64 = try deserializer.deserialize(f64); | |
| 422 | //const nan_check_f128 = try deserializer.deserialize(f128); | |
| 423 | //const inf_check_f128 = try deserializer.deserialize(f128); | |
| 424 | expect(std.math.isNan(nan_check_f16)); | |
| 425 | expect(std.math.isInf(inf_check_f16)); | |
| 426 | expect(std.math.isNan(nan_check_f32)); | |
| 427 | expect(std.math.isInf(inf_check_f32)); | |
| 428 | expect(std.math.isNan(nan_check_f64)); | |
| 429 | expect(std.math.isInf(inf_check_f64)); | |
| 430 | //expect(std.math.isNan(nan_check_f128)); | |
| 431 | //expect(std.math.isInf(inf_check_f128)); | |
| 432 | } | |
| 433 | ||
| 434 | test "Serializer/Deserializer Int: Inf/NaN" { | |
| 435 | try testIntSerializerDeserializerInfNaN(.Big, .Byte); | |
| 436 | try testIntSerializerDeserializerInfNaN(.Little, .Byte); | |
| 437 | try testIntSerializerDeserializerInfNaN(.Big, .Bit); | |
| 438 | try testIntSerializerDeserializerInfNaN(.Little, .Bit); | |
| 439 | } | |
| 440 | ||
| 441 | fn testAlternateSerializer(self: var, serializer: var) !void { | |
| 442 | try serializer.serialize(self.f_f16); | |
| 443 | } | |
| 444 | ||
| 445 | fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void { | |
| 446 | const ColorType = enum(u4) { | |
| 447 | RGB8 = 1, | |
| 448 | RA16 = 2, | |
| 449 | R32 = 3, | |
| 450 | }; | |
| 451 | ||
| 452 | const TagAlign = union(enum(u32)) { | |
| 453 | A: u8, | |
| 454 | B: u8, | |
| 455 | C: u8, | |
| 456 | }; | |
| 457 | ||
| 458 | const Color = union(ColorType) { | |
| 459 | RGB8: struct { | |
| 460 | r: u8, | |
| 461 | g: u8, | |
| 462 | b: u8, | |
| 463 | a: u8, | |
| 464 | }, | |
| 465 | RA16: struct { | |
| 466 | r: u16, | |
| 467 | a: u16, | |
| 468 | }, | |
| 469 | R32: u32, | |
| 470 | }; | |
| 471 | ||
| 472 | const PackedStruct = packed struct { | |
| 473 | f_i3: i3, | |
| 474 | f_u2: u2, | |
| 475 | }; | |
| 476 | ||
| 477 | //to test custom serialization | |
| 478 | const Custom = struct { | |
| 479 | f_f16: f16, | |
| 480 | f_unused_u32: u32, | |
| 481 | ||
| 482 | pub fn deserialize(self: *@This(), deserializer: var) !void { | |
| 483 | try deserializer.deserializeInto(&self.f_f16); | |
| 484 | self.f_unused_u32 = 47; | |
| 485 | } | |
| 486 | ||
| 487 | pub const serialize = testAlternateSerializer; | |
| 488 | }; | |
| 489 | ||
| 490 | const MyStruct = struct { | |
| 491 | f_i3: i3, | |
| 492 | f_u8: u8, | |
| 493 | f_tag_align: TagAlign, | |
| 494 | f_u24: u24, | |
| 495 | f_i19: i19, | |
| 496 | f_void: void, | |
| 497 | f_f32: f32, | |
| 498 | f_f128: f128, | |
| 499 | f_packed_0: PackedStruct, | |
| 500 | f_i7arr: [10]i7, | |
| 501 | f_of64n: ?f64, | |
| 502 | f_of64v: ?f64, | |
| 503 | f_color_type: ColorType, | |
| 504 | f_packed_1: PackedStruct, | |
| 505 | f_custom: Custom, | |
| 506 | f_color: Color, | |
| 507 | }; | |
| 508 | ||
| 509 | const my_inst = MyStruct{ | |
| 510 | .f_i3 = -1, | |
| 511 | .f_u8 = 8, | |
| 512 | .f_tag_align = TagAlign{ .B = 148 }, | |
| 513 | .f_u24 = 24, | |
| 514 | .f_i19 = 19, | |
| 515 | .f_void = {}, | |
| 516 | .f_f32 = 32.32, | |
| 517 | .f_f128 = 128.128, | |
| 518 | .f_packed_0 = PackedStruct{ .f_i3 = -1, .f_u2 = 2 }, | |
| 519 | .f_i7arr = [10]i7{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | |
| 520 | .f_of64n = null, | |
| 521 | .f_of64v = 64.64, | |
| 522 | .f_color_type = ColorType.R32, | |
| 523 | .f_packed_1 = PackedStruct{ .f_i3 = 1, .f_u2 = 1 }, | |
| 524 | .f_custom = Custom{ .f_f16 = 38.63, .f_unused_u32 = 47 }, | |
| 525 | .f_color = Color{ .R32 = 123822 }, | |
| 526 | }; | |
| 527 | ||
| 528 | var data_mem: [@sizeOf(MyStruct)]u8 = undefined; | |
| 529 | var out = io.SliceOutStream.init(data_mem[0..]); | |
| 530 | const OutError = io.SliceOutStream.Error; | |
| 531 | var out_stream = &out.stream; | |
| 532 | var serializer = io.Serializer(endian, packing, OutError).init(out_stream); | |
| 533 | ||
| 534 | var in = io.SliceInStream.init(data_mem[0..]); | |
| 535 | const InError = io.SliceInStream.Error; | |
| 536 | var in_stream = &in.stream; | |
| 537 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); | |
| 538 | ||
| 539 | try serializer.serialize(my_inst); | |
| 540 | ||
| 541 | const my_copy = try deserializer.deserialize(MyStruct); | |
| 542 | expect(meta.eql(my_copy, my_inst)); | |
| 543 | } | |
| 544 | ||
| 545 | test "Serializer/Deserializer generic" { | |
| 546 | try testSerializerDeserializer(builtin.Endian.Big, .Byte); | |
| 547 | try testSerializerDeserializer(builtin.Endian.Little, .Byte); | |
| 548 | try testSerializerDeserializer(builtin.Endian.Big, .Bit); | |
| 549 | try testSerializerDeserializer(builtin.Endian.Little, .Bit); | |
| 550 | } | |
| 551 | ||
| 552 | fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !void { | |
| 553 | const E = enum(u14) { | |
| 554 | One = 1, | |
| 555 | Two = 2, | |
| 556 | }; | |
| 557 | ||
| 558 | const A = struct { | |
| 559 | e: E, | |
| 560 | }; | |
| 561 | ||
| 562 | const C = union(E) { | |
| 563 | One: u14, | |
| 564 | Two: f16, | |
| 565 | }; | |
| 566 | ||
| 567 | var data_mem: [4]u8 = undefined; | |
| 568 | var out = io.SliceOutStream.init(data_mem[0..]); | |
| 569 | const OutError = io.SliceOutStream.Error; | |
| 570 | var out_stream = &out.stream; | |
| 571 | var serializer = io.Serializer(endian, packing, OutError).init(out_stream); | |
| 572 | ||
| 573 | var in = io.SliceInStream.init(data_mem[0..]); | |
| 574 | const InError = io.SliceInStream.Error; | |
| 575 | var in_stream = &in.stream; | |
| 576 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); | |
| 577 | ||
| 578 | try serializer.serialize(u14(3)); | |
| 579 | expectError(error.InvalidEnumTag, deserializer.deserialize(A)); | |
| 580 | out.pos = 0; | |
| 581 | try serializer.serialize(u14(3)); | |
| 582 | try serializer.serialize(u14(88)); | |
| 583 | expectError(error.InvalidEnumTag, deserializer.deserialize(C)); | |
| 584 | } | |
| 585 | ||
| 586 | test "Deserializer bad data" { | |
| 587 | try testBadData(.Big, .Byte); | |
| 588 | try testBadData(.Little, .Byte); | |
| 589 | try testBadData(.Big, .Bit); | |
| 590 | try testBadData(.Little, .Bit); | |
| 591 | } | |
| 592 | ||
| 593 | test "c out stream" { | |
| 594 | if (!builtin.link_libc) return error.SkipZigTest; | |
| 595 | ||
| 596 | const filename = c"tmp_io_test_file.txt"; | |
| 597 | const out_file = std.c.fopen(filename, c"w") orelse return error.UnableToOpenTestFile; | |
| 598 | defer std.os.deleteFileC(filename) catch {}; | |
| 599 | ||
| 600 | const out_stream = &io.COutStream.init(out_file).stream; | |
| 601 | try out_stream.print("hi: {}\n", i32(123)); | |
| 602 | } |
std/io_test.zig deleted-591| ... | ... | @@ -1,591 +0,0 @@ |
| 1 | const std = @import("std.zig"); | |
| 2 | const io = std.io; | |
| 3 | const meta = std.meta; | |
| 4 | const trait = std.trait; | |
| 5 | const DefaultPrng = std.rand.DefaultPrng; | |
| 6 | const expect = std.testing.expect; | |
| 7 | const expectError = std.testing.expectError; | |
| 8 | const mem = std.mem; | |
| 9 | const os = std.os; | |
| 10 | const builtin = @import("builtin"); | |
| 11 | ||
| 12 | test "write a file, read it, then delete it" { | |
| 13 | var raw_bytes: [200 * 1024]u8 = undefined; | |
| 14 | var allocator = &std.heap.FixedBufferAllocator.init(raw_bytes[0..]).allocator; | |
| 15 | ||
| 16 | var data: [1024]u8 = undefined; | |
| 17 | var prng = DefaultPrng.init(1234); | |
| 18 | prng.random.bytes(data[0..]); | |
| 19 | const tmp_file_name = "temp_test_file.txt"; | |
| 20 | { | |
| 21 | var file = try os.File.openWrite(tmp_file_name); | |
| 22 | defer file.close(); | |
| 23 | ||
| 24 | var file_out_stream = file.outStream(); | |
| 25 | var buf_stream = io.BufferedOutStream(os.File.WriteError).init(&file_out_stream.stream); | |
| 26 | const st = &buf_stream.stream; | |
| 27 | try st.print("begin"); | |
| 28 | try st.write(data[0..]); | |
| 29 | try st.print("end"); | |
| 30 | try buf_stream.flush(); | |
| 31 | } | |
| 32 | ||
| 33 | { | |
| 34 | // make sure openWriteNoClobber doesn't harm the file | |
| 35 | if (os.File.openWriteNoClobber(tmp_file_name, os.File.default_mode)) |file| { | |
| 36 | unreachable; | |
| 37 | } else |err| { | |
| 38 | std.debug.assert(err == os.File.OpenError.PathAlreadyExists); | |
| 39 | } | |
| 40 | } | |
| 41 | ||
| 42 | { | |
| 43 | var file = try os.File.openRead(tmp_file_name); | |
| 44 | defer file.close(); | |
| 45 | ||
| 46 | const file_size = try file.getEndPos(); | |
| 47 | const expected_file_size = "begin".len + data.len + "end".len; | |
| 48 | expect(file_size == expected_file_size); | |
| 49 | ||
| 50 | var file_in_stream = file.inStream(); | |
| 51 | var buf_stream = io.BufferedInStream(os.File.ReadError).init(&file_in_stream.stream); | |
| 52 | const st = &buf_stream.stream; | |
| 53 | const contents = try st.readAllAlloc(allocator, 2 * 1024); | |
| 54 | defer allocator.free(contents); | |
| 55 | ||
| 56 | expect(mem.eql(u8, contents[0.."begin".len], "begin")); | |
| 57 | expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data)); | |
| 58 | expect(mem.eql(u8, contents[contents.len - "end".len ..], "end")); | |
| 59 | } | |
| 60 | try os.deleteFile(tmp_file_name); | |
| 61 | } | |
| 62 | ||
| 63 | test "BufferOutStream" { | |
| 64 | var bytes: [100]u8 = undefined; | |
| 65 | var allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator; | |
| 66 | ||
| 67 | var buffer = try std.Buffer.initSize(allocator, 0); | |
| 68 | var buf_stream = &std.io.BufferOutStream.init(&buffer).stream; | |
| 69 | ||
| 70 | const x: i32 = 42; | |
| 71 | const y: i32 = 1234; | |
| 72 | try buf_stream.print("x: {}\ny: {}\n", x, y); | |
| 73 | ||
| 74 | expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n")); | |
| 75 | } | |
| 76 | ||
| 77 | test "SliceInStream" { | |
| 78 | const bytes = []const u8{ 1, 2, 3, 4, 5, 6, 7 }; | |
| 79 | var ss = io.SliceInStream.init(bytes); | |
| 80 | ||
| 81 | var dest: [4]u8 = undefined; | |
| 82 | ||
| 83 | var read = try ss.stream.read(dest[0..4]); | |
| 84 | expect(read == 4); | |
| 85 | expect(mem.eql(u8, dest[0..4], bytes[0..4])); | |
| 86 | ||
| 87 | read = try ss.stream.read(dest[0..4]); | |
| 88 | expect(read == 3); | |
| 89 | expect(mem.eql(u8, dest[0..3], bytes[4..7])); | |
| 90 | ||
| 91 | read = try ss.stream.read(dest[0..4]); | |
| 92 | expect(read == 0); | |
| 93 | } | |
| 94 | ||
| 95 | test "PeekStream" { | |
| 96 | const bytes = []const u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; | |
| 97 | var ss = io.SliceInStream.init(bytes); | |
| 98 | var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream); | |
| 99 | ||
| 100 | var dest: [4]u8 = undefined; | |
| 101 | ||
| 102 | ps.putBackByte(9); | |
| 103 | ps.putBackByte(10); | |
| 104 | ||
| 105 | var read = try ps.stream.read(dest[0..4]); | |
| 106 | expect(read == 4); | |
| 107 | expect(dest[0] == 10); | |
| 108 | expect(dest[1] == 9); | |
| 109 | expect(mem.eql(u8, dest[2..4], bytes[0..2])); | |
| 110 | ||
| 111 | read = try ps.stream.read(dest[0..4]); | |
| 112 | expect(read == 4); | |
| 113 | expect(mem.eql(u8, dest[0..4], bytes[2..6])); | |
| 114 | ||
| 115 | read = try ps.stream.read(dest[0..4]); | |
| 116 | expect(read == 2); | |
| 117 | expect(mem.eql(u8, dest[0..2], bytes[6..8])); | |
| 118 | ||
| 119 | ps.putBackByte(11); | |
| 120 | ps.putBackByte(12); | |
| 121 | ||
| 122 | read = try ps.stream.read(dest[0..4]); | |
| 123 | expect(read == 2); | |
| 124 | expect(dest[0] == 12); | |
| 125 | expect(dest[1] == 11); | |
| 126 | } | |
| 127 | ||
| 128 | test "SliceOutStream" { | |
| 129 | var buffer: [10]u8 = undefined; | |
| 130 | var ss = io.SliceOutStream.init(buffer[0..]); | |
| 131 | ||
| 132 | try ss.stream.write("Hello"); | |
| 133 | expect(mem.eql(u8, ss.getWritten(), "Hello")); | |
| 134 | ||
| 135 | try ss.stream.write("world"); | |
| 136 | expect(mem.eql(u8, ss.getWritten(), "Helloworld")); | |
| 137 | ||
| 138 | expectError(error.OutOfSpace, ss.stream.write("!")); | |
| 139 | expect(mem.eql(u8, ss.getWritten(), "Helloworld")); | |
| 140 | ||
| 141 | ss.reset(); | |
| 142 | expect(ss.getWritten().len == 0); | |
| 143 | ||
| 144 | expectError(error.OutOfSpace, ss.stream.write("Hello world!")); | |
| 145 | expect(mem.eql(u8, ss.getWritten(), "Hello worl")); | |
| 146 | } | |
| 147 | ||
| 148 | test "BitInStream" { | |
| 149 | const mem_be = []u8{ 0b11001101, 0b00001011 }; | |
| 150 | const mem_le = []u8{ 0b00011101, 0b10010101 }; | |
| 151 | ||
| 152 | var mem_in_be = io.SliceInStream.init(mem_be[0..]); | |
| 153 | const InError = io.SliceInStream.Error; | |
| 154 | var bit_stream_be = io.BitInStream(builtin.Endian.Big, InError).init(&mem_in_be.stream); | |
| 155 | ||
| 156 | var out_bits: usize = undefined; | |
| 157 | ||
| 158 | expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits)); | |
| 159 | expect(out_bits == 1); | |
| 160 | expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits)); | |
| 161 | expect(out_bits == 2); | |
| 162 | expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits)); | |
| 163 | expect(out_bits == 3); | |
| 164 | expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits)); | |
| 165 | expect(out_bits == 4); | |
| 166 | expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits)); | |
| 167 | expect(out_bits == 5); | |
| 168 | expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 169 | expect(out_bits == 1); | |
| 170 | ||
| 171 | mem_in_be.pos = 0; | |
| 172 | bit_stream_be.bit_count = 0; | |
| 173 | expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits)); | |
| 174 | expect(out_bits == 15); | |
| 175 | ||
| 176 | mem_in_be.pos = 0; | |
| 177 | bit_stream_be.bit_count = 0; | |
| 178 | expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits)); | |
| 179 | expect(out_bits == 16); | |
| 180 | ||
| 181 | _ = try bit_stream_be.readBits(u0, 0, &out_bits); | |
| 182 | ||
| 183 | expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 184 | expect(out_bits == 0); | |
| 185 | expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1)); | |
| 186 | ||
| 187 | var mem_in_le = io.SliceInStream.init(mem_le[0..]); | |
| 188 | var bit_stream_le = io.BitInStream(builtin.Endian.Little, InError).init(&mem_in_le.stream); | |
| 189 | ||
| 190 | expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits)); | |
| 191 | expect(out_bits == 1); | |
| 192 | expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits)); | |
| 193 | expect(out_bits == 2); | |
| 194 | expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits)); | |
| 195 | expect(out_bits == 3); | |
| 196 | expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits)); | |
| 197 | expect(out_bits == 4); | |
| 198 | expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits)); | |
| 199 | expect(out_bits == 5); | |
| 200 | expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 201 | expect(out_bits == 1); | |
| 202 | ||
| 203 | mem_in_le.pos = 0; | |
| 204 | bit_stream_le.bit_count = 0; | |
| 205 | expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits)); | |
| 206 | expect(out_bits == 15); | |
| 207 | ||
| 208 | mem_in_le.pos = 0; | |
| 209 | bit_stream_le.bit_count = 0; | |
| 210 | expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits)); | |
| 211 | expect(out_bits == 16); | |
| 212 | ||
| 213 | _ = try bit_stream_le.readBits(u0, 0, &out_bits); | |
| 214 | ||
| 215 | expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 216 | expect(out_bits == 0); | |
| 217 | expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1)); | |
| 218 | } | |
| 219 | ||
| 220 | test "BitOutStream" { | |
| 221 | var mem_be = []u8{0} ** 2; | |
| 222 | var mem_le = []u8{0} ** 2; | |
| 223 | ||
| 224 | var mem_out_be = io.SliceOutStream.init(mem_be[0..]); | |
| 225 | const OutError = io.SliceOutStream.Error; | |
| 226 | var bit_stream_be = io.BitOutStream(builtin.Endian.Big, OutError).init(&mem_out_be.stream); | |
| 227 | ||
| 228 | try bit_stream_be.writeBits(u2(1), 1); | |
| 229 | try bit_stream_be.writeBits(u5(2), 2); | |
| 230 | try bit_stream_be.writeBits(u128(3), 3); | |
| 231 | try bit_stream_be.writeBits(u8(4), 4); | |
| 232 | try bit_stream_be.writeBits(u9(5), 5); | |
| 233 | try bit_stream_be.writeBits(u1(1), 1); | |
| 234 | ||
| 235 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011); | |
| 236 | ||
| 237 | mem_out_be.pos = 0; | |
| 238 | ||
| 239 | try bit_stream_be.writeBits(u15(0b110011010000101), 15); | |
| 240 | try bit_stream_be.flushBits(); | |
| 241 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010); | |
| 242 | ||
| 243 | mem_out_be.pos = 0; | |
| 244 | try bit_stream_be.writeBits(u32(0b110011010000101), 16); | |
| 245 | expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101); | |
| 246 | ||
| 247 | try bit_stream_be.writeBits(u0(0), 0); | |
| 248 | ||
| 249 | var mem_out_le = io.SliceOutStream.init(mem_le[0..]); | |
| 250 | var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream); | |
| 251 | ||
| 252 | try bit_stream_le.writeBits(u2(1), 1); | |
| 253 | try bit_stream_le.writeBits(u5(2), 2); | |
| 254 | try bit_stream_le.writeBits(u128(3), 3); | |
| 255 | try bit_stream_le.writeBits(u8(4), 4); | |
| 256 | try bit_stream_le.writeBits(u9(5), 5); | |
| 257 | try bit_stream_le.writeBits(u1(1), 1); | |
| 258 | ||
| 259 | expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101); | |
| 260 | ||
| 261 | mem_out_le.pos = 0; | |
| 262 | try bit_stream_le.writeBits(u15(0b110011010000101), 15); | |
| 263 | try bit_stream_le.flushBits(); | |
| 264 | expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110); | |
| 265 | ||
| 266 | mem_out_le.pos = 0; | |
| 267 | try bit_stream_le.writeBits(u32(0b1100110100001011), 16); | |
| 268 | expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101); | |
| 269 | ||
| 270 | try bit_stream_le.writeBits(u0(0), 0); | |
| 271 | } | |
| 272 | ||
| 273 | test "BitStreams with File Stream" { | |
| 274 | const tmp_file_name = "temp_test_file.txt"; | |
| 275 | { | |
| 276 | var file = try os.File.openWrite(tmp_file_name); | |
| 277 | defer file.close(); | |
| 278 | ||
| 279 | var file_out = file.outStream(); | |
| 280 | var file_out_stream = &file_out.stream; | |
| 281 | const OutError = os.File.WriteError; | |
| 282 | var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream); | |
| 283 | ||
| 284 | try bit_stream.writeBits(u2(1), 1); | |
| 285 | try bit_stream.writeBits(u5(2), 2); | |
| 286 | try bit_stream.writeBits(u128(3), 3); | |
| 287 | try bit_stream.writeBits(u8(4), 4); | |
| 288 | try bit_stream.writeBits(u9(5), 5); | |
| 289 | try bit_stream.writeBits(u1(1), 1); | |
| 290 | try bit_stream.flushBits(); | |
| 291 | } | |
| 292 | { | |
| 293 | var file = try os.File.openRead(tmp_file_name); | |
| 294 | defer file.close(); | |
| 295 | ||
| 296 | var file_in = file.inStream(); | |
| 297 | var file_in_stream = &file_in.stream; | |
| 298 | const InError = os.File.ReadError; | |
| 299 | var bit_stream = io.BitInStream(builtin.endian, InError).init(file_in_stream); | |
| 300 | ||
| 301 | var out_bits: usize = undefined; | |
| 302 | ||
| 303 | expect(1 == try bit_stream.readBits(u2, 1, &out_bits)); | |
| 304 | expect(out_bits == 1); | |
| 305 | expect(2 == try bit_stream.readBits(u5, 2, &out_bits)); | |
| 306 | expect(out_bits == 2); | |
| 307 | expect(3 == try bit_stream.readBits(u128, 3, &out_bits)); | |
| 308 | expect(out_bits == 3); | |
| 309 | expect(4 == try bit_stream.readBits(u8, 4, &out_bits)); | |
| 310 | expect(out_bits == 4); | |
| 311 | expect(5 == try bit_stream.readBits(u9, 5, &out_bits)); | |
| 312 | expect(out_bits == 5); | |
| 313 | expect(1 == try bit_stream.readBits(u1, 1, &out_bits)); | |
| 314 | expect(out_bits == 1); | |
| 315 | ||
| 316 | expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1)); | |
| 317 | } | |
| 318 | try os.deleteFile(tmp_file_name); | |
| 319 | } | |
| 320 | ||
| 321 | fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void { | |
| 322 | //@NOTE: if this test is taking too long, reduce the maximum tested bitsize | |
| 323 | const max_test_bitsize = 128; | |
| 324 | ||
| 325 | const total_bytes = comptime blk: { | |
| 326 | var bytes = 0; | |
| 327 | comptime var i = 0; | |
| 328 | while (i <= max_test_bitsize) : (i += 1) bytes += (i / 8) + @boolToInt(i % 8 > 0); | |
| 329 | break :blk bytes * 2; | |
| 330 | }; | |
| 331 | ||
| 332 | var data_mem: [total_bytes]u8 = undefined; | |
| 333 | var out = io.SliceOutStream.init(data_mem[0..]); | |
| 334 | const OutError = io.SliceOutStream.Error; | |
| 335 | var out_stream = &out.stream; | |
| 336 | var serializer = io.Serializer(endian, packing, OutError).init(out_stream); | |
| 337 | ||
| 338 | var in = io.SliceInStream.init(data_mem[0..]); | |
| 339 | const InError = io.SliceInStream.Error; | |
| 340 | var in_stream = &in.stream; | |
| 341 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); | |
| 342 | ||
| 343 | comptime var i = 0; | |
| 344 | inline while (i <= max_test_bitsize) : (i += 1) { | |
| 345 | const U = @IntType(false, i); | |
| 346 | const S = @IntType(true, i); | |
| 347 | try serializer.serializeInt(U(i)); | |
| 348 | if (i != 0) try serializer.serializeInt(S(-1)) else try serializer.serialize(S(0)); | |
| 349 | } | |
| 350 | try serializer.flush(); | |
| 351 | ||
| 352 | i = 0; | |
| 353 | inline while (i <= max_test_bitsize) : (i += 1) { | |
| 354 | const U = @IntType(false, i); | |
| 355 | const S = @IntType(true, i); | |
| 356 | const x = try deserializer.deserializeInt(U); | |
| 357 | const y = try deserializer.deserializeInt(S); | |
| 358 | expect(x == U(i)); | |
| 359 | if (i != 0) expect(y == S(-1)) else expect(y == 0); | |
| 360 | } | |
| 361 | ||
| 362 | const u8_bit_count = comptime meta.bitCount(u8); | |
| 363 | //0 + 1 + 2 + ... n = (n * (n + 1)) / 2 | |
| 364 | //and we have each for unsigned and signed, so * 2 | |
| 365 | const total_bits = (max_test_bitsize * (max_test_bitsize + 1)); | |
| 366 | const extra_packed_byte = @boolToInt(total_bits % u8_bit_count > 0); | |
| 367 | const total_packed_bytes = (total_bits / u8_bit_count) + extra_packed_byte; | |
| 368 | ||
| 369 | expect(in.pos == if (packing == .Bit) total_packed_bytes else total_bytes); | |
| 370 | ||
| 371 | //Verify that empty error set works with serializer. | |
| 372 | //deserializer is covered by SliceInStream | |
| 373 | const NullError = io.NullOutStream.Error; | |
| 374 | var null_out = io.NullOutStream.init(); | |
| 375 | var null_out_stream = &null_out.stream; | |
| 376 | var null_serializer = io.Serializer(endian, packing, NullError).init(null_out_stream); | |
| 377 | try null_serializer.serialize(data_mem[0..]); | |
| 378 | try null_serializer.flush(); | |
| 379 | } | |
| 380 | ||
| 381 | test "Serializer/Deserializer Int" { | |
| 382 | try testIntSerializerDeserializer(.Big, .Byte); | |
| 383 | try testIntSerializerDeserializer(.Little, .Byte); | |
| 384 | // TODO these tests are disabled due to tripping an LLVM assertion | |
| 385 | // https://github.com/ziglang/zig/issues/2019 | |
| 386 | //try testIntSerializerDeserializer(builtin.Endian.Big, true); | |
| 387 | //try testIntSerializerDeserializer(builtin.Endian.Little, true); | |
| 388 | } | |
| 389 | ||
| 390 | fn testIntSerializerDeserializerInfNaN( | |
| 391 | comptime endian: builtin.Endian, | |
| 392 | comptime packing: io.Packing, | |
| 393 | ) !void { | |
| 394 | const mem_size = (16 * 2 + 32 * 2 + 64 * 2 + 128 * 2) / comptime meta.bitCount(u8); | |
| 395 | var data_mem: [mem_size]u8 = undefined; | |
| 396 | ||
| 397 | var out = io.SliceOutStream.init(data_mem[0..]); | |
| 398 | const OutError = io.SliceOutStream.Error; | |
| 399 | var out_stream = &out.stream; | |
| 400 | var serializer = io.Serializer(endian, packing, OutError).init(out_stream); | |
| 401 | ||
| 402 | var in = io.SliceInStream.init(data_mem[0..]); | |
| 403 | const InError = io.SliceInStream.Error; | |
| 404 | var in_stream = &in.stream; | |
| 405 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); | |
| 406 | ||
| 407 | //@TODO: isInf/isNan not currently implemented for f128. | |
| 408 | try serializer.serialize(std.math.nan(f16)); | |
| 409 | try serializer.serialize(std.math.inf(f16)); | |
| 410 | try serializer.serialize(std.math.nan(f32)); | |
| 411 | try serializer.serialize(std.math.inf(f32)); | |
| 412 | try serializer.serialize(std.math.nan(f64)); | |
| 413 | try serializer.serialize(std.math.inf(f64)); | |
| 414 | //try serializer.serialize(std.math.nan(f128)); | |
| 415 | //try serializer.serialize(std.math.inf(f128)); | |
| 416 | const nan_check_f16 = try deserializer.deserialize(f16); | |
| 417 | const inf_check_f16 = try deserializer.deserialize(f16); | |
| 418 | const nan_check_f32 = try deserializer.deserialize(f32); | |
| 419 | const inf_check_f32 = try deserializer.deserialize(f32); | |
| 420 | const nan_check_f64 = try deserializer.deserialize(f64); | |
| 421 | const inf_check_f64 = try deserializer.deserialize(f64); | |
| 422 | //const nan_check_f128 = try deserializer.deserialize(f128); | |
| 423 | //const inf_check_f128 = try deserializer.deserialize(f128); | |
| 424 | expect(std.math.isNan(nan_check_f16)); | |
| 425 | expect(std.math.isInf(inf_check_f16)); | |
| 426 | expect(std.math.isNan(nan_check_f32)); | |
| 427 | expect(std.math.isInf(inf_check_f32)); | |
| 428 | expect(std.math.isNan(nan_check_f64)); | |
| 429 | expect(std.math.isInf(inf_check_f64)); | |
| 430 | //expect(std.math.isNan(nan_check_f128)); | |
| 431 | //expect(std.math.isInf(inf_check_f128)); | |
| 432 | } | |
| 433 | ||
| 434 | test "Serializer/Deserializer Int: Inf/NaN" { | |
| 435 | try testIntSerializerDeserializerInfNaN(.Big, .Byte); | |
| 436 | try testIntSerializerDeserializerInfNaN(.Little, .Byte); | |
| 437 | try testIntSerializerDeserializerInfNaN(.Big, .Bit); | |
| 438 | try testIntSerializerDeserializerInfNaN(.Little, .Bit); | |
| 439 | } | |
| 440 | ||
| 441 | fn testAlternateSerializer(self: var, serializer: var) !void { | |
| 442 | try serializer.serialize(self.f_f16); | |
| 443 | } | |
| 444 | ||
| 445 | fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void { | |
| 446 | const ColorType = enum(u4) { | |
| 447 | RGB8 = 1, | |
| 448 | RA16 = 2, | |
| 449 | R32 = 3, | |
| 450 | }; | |
| 451 | ||
| 452 | const TagAlign = union(enum(u32)) { | |
| 453 | A: u8, | |
| 454 | B: u8, | |
| 455 | C: u8, | |
| 456 | }; | |
| 457 | ||
| 458 | const Color = union(ColorType) { | |
| 459 | RGB8: struct { | |
| 460 | r: u8, | |
| 461 | g: u8, | |
| 462 | b: u8, | |
| 463 | a: u8, | |
| 464 | }, | |
| 465 | RA16: struct { | |
| 466 | r: u16, | |
| 467 | a: u16, | |
| 468 | }, | |
| 469 | R32: u32, | |
| 470 | }; | |
| 471 | ||
| 472 | const PackedStruct = packed struct { | |
| 473 | f_i3: i3, | |
| 474 | f_u2: u2, | |
| 475 | }; | |
| 476 | ||
| 477 | //to test custom serialization | |
| 478 | const Custom = struct { | |
| 479 | f_f16: f16, | |
| 480 | f_unused_u32: u32, | |
| 481 | ||
| 482 | pub fn deserialize(self: *@This(), deserializer: var) !void { | |
| 483 | try deserializer.deserializeInto(&self.f_f16); | |
| 484 | self.f_unused_u32 = 47; | |
| 485 | } | |
| 486 | ||
| 487 | pub const serialize = testAlternateSerializer; | |
| 488 | }; | |
| 489 | ||
| 490 | const MyStruct = struct { | |
| 491 | f_i3: i3, | |
| 492 | f_u8: u8, | |
| 493 | f_tag_align: TagAlign, | |
| 494 | f_u24: u24, | |
| 495 | f_i19: i19, | |
| 496 | f_void: void, | |
| 497 | f_f32: f32, | |
| 498 | f_f128: f128, | |
| 499 | f_packed_0: PackedStruct, | |
| 500 | f_i7arr: [10]i7, | |
| 501 | f_of64n: ?f64, | |
| 502 | f_of64v: ?f64, | |
| 503 | f_color_type: ColorType, | |
| 504 | f_packed_1: PackedStruct, | |
| 505 | f_custom: Custom, | |
| 506 | f_color: Color, | |
| 507 | }; | |
| 508 | ||
| 509 | const my_inst = MyStruct{ | |
| 510 | .f_i3 = -1, | |
| 511 | .f_u8 = 8, | |
| 512 | .f_tag_align = TagAlign{ .B = 148 }, | |
| 513 | .f_u24 = 24, | |
| 514 | .f_i19 = 19, | |
| 515 | .f_void = {}, | |
| 516 | .f_f32 = 32.32, | |
| 517 | .f_f128 = 128.128, | |
| 518 | .f_packed_0 = PackedStruct{ .f_i3 = -1, .f_u2 = 2 }, | |
| 519 | .f_i7arr = [10]i7{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, | |
| 520 | .f_of64n = null, | |
| 521 | .f_of64v = 64.64, | |
| 522 | .f_color_type = ColorType.R32, | |
| 523 | .f_packed_1 = PackedStruct{ .f_i3 = 1, .f_u2 = 1 }, | |
| 524 | .f_custom = Custom{ .f_f16 = 38.63, .f_unused_u32 = 47 }, | |
| 525 | .f_color = Color{ .R32 = 123822 }, | |
| 526 | }; | |
| 527 | ||
| 528 | var data_mem: [@sizeOf(MyStruct)]u8 = undefined; | |
| 529 | var out = io.SliceOutStream.init(data_mem[0..]); | |
| 530 | const OutError = io.SliceOutStream.Error; | |
| 531 | var out_stream = &out.stream; | |
| 532 | var serializer = io.Serializer(endian, packing, OutError).init(out_stream); | |
| 533 | ||
| 534 | var in = io.SliceInStream.init(data_mem[0..]); | |
| 535 | const InError = io.SliceInStream.Error; | |
| 536 | var in_stream = &in.stream; | |
| 537 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); | |
| 538 | ||
| 539 | try serializer.serialize(my_inst); | |
| 540 | ||
| 541 | const my_copy = try deserializer.deserialize(MyStruct); | |
| 542 | expect(meta.eql(my_copy, my_inst)); | |
| 543 | } | |
| 544 | ||
| 545 | test "Serializer/Deserializer generic" { | |
| 546 | try testSerializerDeserializer(builtin.Endian.Big, .Byte); | |
| 547 | try testSerializerDeserializer(builtin.Endian.Little, .Byte); | |
| 548 | try testSerializerDeserializer(builtin.Endian.Big, .Bit); | |
| 549 | try testSerializerDeserializer(builtin.Endian.Little, .Bit); | |
| 550 | } | |
| 551 | ||
| 552 | fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !void { | |
| 553 | const E = enum(u14) { | |
| 554 | One = 1, | |
| 555 | Two = 2, | |
| 556 | }; | |
| 557 | ||
| 558 | const A = struct { | |
| 559 | e: E, | |
| 560 | }; | |
| 561 | ||
| 562 | const C = union(E) { | |
| 563 | One: u14, | |
| 564 | Two: f16, | |
| 565 | }; | |
| 566 | ||
| 567 | var data_mem: [4]u8 = undefined; | |
| 568 | var out = io.SliceOutStream.init(data_mem[0..]); | |
| 569 | const OutError = io.SliceOutStream.Error; | |
| 570 | var out_stream = &out.stream; | |
| 571 | var serializer = io.Serializer(endian, packing, OutError).init(out_stream); | |
| 572 | ||
| 573 | var in = io.SliceInStream.init(data_mem[0..]); | |
| 574 | const InError = io.SliceInStream.Error; | |
| 575 | var in_stream = &in.stream; | |
| 576 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); | |
| 577 | ||
| 578 | try serializer.serialize(u14(3)); | |
| 579 | expectError(error.InvalidEnumTag, deserializer.deserialize(A)); | |
| 580 | out.pos = 0; | |
| 581 | try serializer.serialize(u14(3)); | |
| 582 | try serializer.serialize(u14(88)); | |
| 583 | expectError(error.InvalidEnumTag, deserializer.deserialize(C)); | |
| 584 | } | |
| 585 | ||
| 586 | test "Deserializer bad data" { | |
| 587 | try testBadData(.Big, .Byte); | |
| 588 | try testBadData(.Little, .Byte); | |
| 589 | try testBadData(.Big, .Bit); | |
| 590 | try testBadData(.Little, .Bit); | |
| 591 | } |