| ... | ... | @@ -1,322 +1,81 @@ |
| 1 | 1 | 'use strict'; |
| 2 | 2 | |
| 3 | | /** |
| 4 | | * @typedef { |
| 5 | | | "Type" |
| 6 | | | "Void" |
| 7 | | | "Bool" |
| 8 | | | "NoReturn" |
| 9 | | | "Int" |
| 10 | | | "Float" |
| 11 | | | "Pointer" |
| 12 | | | "Array" |
| 13 | | | "Struct" |
| 14 | | | "ComptimeFloat" |
| 15 | | | "ComptimeInt" |
| 16 | | | "Undefined" |
| 17 | | | "Null" |
| 18 | | | "Optional" |
| 19 | | | "ErrorUnion" |
| 20 | | | "ErrorSet" |
| 21 | | | "Enum" |
| 22 | | | "Union" |
| 23 | | | "Fn" |
| 24 | | | "BoundFn" |
| 25 | | | "Opaque" |
| 26 | | | "Frame" |
| 27 | | | "AnyFrame" |
| 28 | | | "Vector" |
| 29 | | | "EnumLiteral" |
| 30 | | | "ComptimeExpr" |
| 31 | | | "Unanalyzed" |
| 32 | | } TypeKind |
| 33 | | */ |
| 34 | | |
| 35 | | /** |
| 36 | | * @typedef {{ |
| 37 | | typeRef: Expr?, |
| 38 | | expr: Expr, |
| 39 | | }} WalkResult |
| 40 | | */ |
| 41 | | |
| 42 | | /** |
| 43 | | * @typedef {{ |
| 44 | | void: {}, |
| 45 | | unreachable: {}, |
| 46 | | anytype: {}, |
| 47 | | type: number, |
| 48 | | comptimeExpr: number, |
| 49 | | call: number, |
| 50 | | int: number, |
| 51 | | float: number, |
| 52 | | bool: boolean, |
| 53 | | undefined: WalkResult, |
| 54 | | null: WalkResult, |
| 55 | | typeOf: WalkResult, |
| 56 | | compileError: string |
| 57 | | string: string, |
| 58 | | struct: Expr[], |
| 59 | | refPath: Expr[], |
| 60 | | declRef: number, |
| 61 | | array: ZigArray, |
| 62 | | enumLiteral: string, |
| 63 | | }} Expr |
| 64 | | */ |
| 65 | | |
| 66 | | /** |
| 67 | | * @typedef {{ |
| 68 | | kind: number, |
| 69 | | name: string, |
| 70 | | src: number, |
| 71 | | privDecls: number[], |
| 72 | | pubDecls: number[], |
| 73 | | fields: WalkResult[] |
| 74 | | }} ContainerType |
| 75 | | */ |
| 76 | | |
| 77 | | /** |
| 78 | | * @typedef {{ |
| 79 | | kind: number, |
| 80 | | name: string, |
| 81 | | src: number, |
| 82 | | ret: WalkResult, |
| 83 | | params: WalkResult[], |
| 84 | | generic: boolean, |
| 85 | | }} Fn |
| 86 | | */ |
| 87 | | |
| 88 | | /** |
| 89 | | * @typedef {{ |
| 90 | | kind: number, |
| 91 | | name: string, |
| 92 | | fields: { name: string, docs: string }[] |
| 93 | | fn: number | undefined, |
| 94 | | }} ErrSetType |
| 95 | | */ |
| 96 | | |
| 97 | | /** |
| 98 | | * @typedef {{ |
| 99 | | kind: number, |
| 100 | | err: WalkResult, |
| 101 | | payload: WalkResult, |
| 102 | | }} ErrUnionType |
| 103 | | */ |
| 104 | | |
| 105 | | // Type, Void, Bool, NoReturn, Int, Float, ComptimeExpr, ComptimeFloat, ComptimeInt, Undefined, Null, ErrorUnion, BoundFn, Opaque, Frame, AnyFrame, Vector, EnumLiteral |
| 106 | | /** |
| 107 | | * @typedef {{ |
| 108 | | kind: number, |
| 109 | | name: string |
| 110 | | }} NumberType |
| 111 | | */ |
| 112 | | |
| 113 | | /** |
| 114 | | * @typedef {{ |
| 115 | | kind: number, |
| 116 | | size: number, |
| 117 | | child: WalkResult |
| 118 | | align: number, |
| 119 | | bitOffsetInHost: number, |
| 120 | | hostIntBytes: number, |
| 121 | | volatile: boolean, |
| 122 | | const: boolean, |
| 123 | | }} PointerType |
| 124 | | */ |
| 125 | | |
| 126 | | /** |
| 127 | | * @typedef {{ |
| 128 | | kind: number, |
| 129 | | len: WalkResult |
| 130 | | child: WalkResult |
| 131 | | }} ArrayType |
| 132 | | */ |
| 133 | | |
| 134 | | /** |
| 135 | | * @typedef {{ |
| 136 | | kind: number, |
| 137 | | name: string, |
| 138 | | child: Expr, |
| 139 | | }} OptionalType |
| 140 | | */ |
| 141 | | |
| 142 | | /** |
| 143 | | * @typedef { |
| 144 | | | OptionalType |
| 145 | | | ArrayType |
| 146 | | | PointerType |
| 147 | | | ContainerType |
| 148 | | | Fn |
| 149 | | | ErrSetType |
| 150 | | | ErrUnionType |
| 151 | | | NumberType |
| 152 | | } Type |
| 153 | | */ |
| 154 | | |
| 155 | | |
| 156 | | /** |
| 157 | | * @typedef {{ |
| 158 | | func: Expr, |
| 159 | | args: Expr[], |
| 160 | | ret: Expr, |
| 161 | | }} Call |
| 162 | | */ |
| 163 | | |
| 164 | | /** |
| 165 | | * @typedef {{ |
| 166 | | file: number, |
| 167 | | line: number, |
| 168 | | col: number, |
| 169 | | name?: string, |
| 170 | | docs?: string, |
| 171 | | fields?: number[], |
| 172 | | comptime: boolean, |
| 173 | | noalias: boolean, |
| 174 | | varArgs: boolean, |
| 175 | | }} AstNode |
| 176 | | */ |
| 177 | | |
| 178 | | /** |
| 179 | | * @typedef {{ |
| 180 | | name: string, |
| 181 | | kind: string, |
| 182 | | src: number, |
| 183 | | value: WalkResult, |
| 184 | | decltest?: number, |
| 185 | | isTest: boolean, |
| 186 | | }} Decl |
| 187 | | */ |
| 188 | | |
| 189 | | /** |
| 190 | | * @typedef {{ |
| 191 | | name: string, |
| 192 | | file: number, |
| 193 | | main: number, |
| 194 | | table: Record<string, number>, |
| 195 | | }} Package |
| 196 | | */ |
| 197 | | |
| 198 | | /** |
| 199 | | * @typedef {{ |
| 200 | | typeRef: WalkResult, |
| 201 | | data: WalkResult[], |
| 202 | | }} ZigArray |
| 203 | | */ |
| 204 | | |
| 205 | | /** |
| 206 | | * @typedef {{ |
| 207 | | code: string, |
| 208 | | typeRef: WalkResult, |
| 209 | | }} ComptimeExpr |
| 210 | | */ |
| 211 | | |
| 212 | | /** |
| 213 | | * @typedef {{ |
| 214 | | typeKinds: TypeKind[]; |
| 215 | | rootPkg: number; |
| 216 | | params: { |
| 217 | | zigId: string; |
| 218 | | zigVersion: string; |
| 219 | | target: string; |
| 220 | | rootName: string; |
| 221 | | builds: { target: string }; |
| 222 | | }; |
| 223 | | packages: Package[]; |
| 224 | | errors: {}; |
| 225 | | astNodes: AstNode[]; |
| 226 | | calls: Call[]; |
| 227 | | files: Record<string, string>; |
| 228 | | types: Type[]; |
| 229 | | decls: Decl[]; |
| 230 | | comptimeExprs: ComptimeExpr[]; |
| 231 | | fns: Fn[]; |
| 232 | | }} DocData |
| 233 | | */ |
| 234 | | |
| 235 | | /** @type {DocData} */ |
| 236 | 3 | var zigAnalysis; |
| 237 | 4 | |
| 238 | 5 | (function() { |
| 239 | | let domStatus = /** @type HTMLElement */(document.getElementById("status")); |
| 240 | | let domSectNav = /** @type HTMLElement */(document.getElementById("sectNav")); |
| 241 | | let domListNav = /** @type HTMLElement */(document.getElementById("listNav")); |
| 242 | | let domSectMainPkg = /** @type HTMLElement */(document.getElementById("sectMainPkg")); |
| 243 | | let domSectPkgs = /** @type HTMLElement */(document.getElementById("sectPkgs")); |
| 244 | | let domListPkgs = /** @type HTMLElement */(document.getElementById("listPkgs")); |
| 245 | | let domSectTypes = /** @type HTMLElement */(document.getElementById("sectTypes")); |
| 246 | | let domListTypes = /** @type HTMLElement */(document.getElementById("listTypes")); |
| 247 | | let domSectTests = /** @type HTMLElement */(document.getElementById("sectTests")); |
| 248 | | let domListTests = /** @type HTMLElement */(document.getElementById("listTests")); |
| 249 | | let domSectNamespaces = /** @type HTMLElement */(document.getElementById("sectNamespaces")); |
| 250 | | let domListNamespaces = /** @type HTMLElement */(document.getElementById("listNamespaces")); |
| 251 | | let domSectErrSets = /** @type HTMLElement */(document.getElementById("sectErrSets")); |
| 252 | | let domListErrSets = /** @type HTMLElement */(document.getElementById("listErrSets")); |
| 253 | | let domSectFns = /** @type HTMLElement */(document.getElementById("sectFns")); |
| 254 | | let domListFns = /** @type HTMLElement */(document.getElementById("listFns")); |
| 255 | | let domSectFields = /** @type HTMLElement */(document.getElementById("sectFields")); |
| 256 | | let domListFields = /** @type HTMLElement */(document.getElementById("listFields")); |
| 257 | | let domSectGlobalVars = /** @type HTMLElement */(document.getElementById("sectGlobalVars")); |
| 258 | | let domListGlobalVars = /** @type HTMLElement */(document.getElementById("listGlobalVars")); |
| 259 | | let domSectValues = /** @type HTMLElement */(document.getElementById("sectValues")); |
| 260 | | let domListValues = /** @type HTMLElement */(document.getElementById("listValues")); |
| 261 | | let domFnProto = /** @type HTMLElement */(document.getElementById("fnProto")); |
| 262 | | let domFnProtoCode = /** @type HTMLElement */(document.getElementById("fnProtoCode")); |
| 263 | | let domSectParams = /** @type HTMLElement */(document.getElementById("sectParams")); |
| 264 | | let domListParams = /** @type HTMLElement */(document.getElementById("listParams")); |
| 265 | | let domTldDocs = /** @type HTMLElement */(document.getElementById("tldDocs")); |
| 266 | | let domSectFnErrors = /** @type HTMLElement */(document.getElementById("sectFnErrors")); |
| 267 | | let domListFnErrors = /** @type HTMLElement */(document.getElementById("listFnErrors")); |
| 268 | | let domTableFnErrors =/** @type HTMLElement */(document.getElementById("tableFnErrors")); |
| 269 | | let domFnErrorsAnyError = /** @type HTMLElement */(document.getElementById("fnErrorsAnyError")); |
| 270 | | let domFnExamples = /** @type HTMLElement */(document.getElementById("fnExamples")); |
| 271 | | // let domListFnExamples = /** @type HTMLElement */(document.getElementById("listFnExamples")); |
| 272 | | let domFnNoExamples = /** @type HTMLElement */(document.getElementById("fnNoExamples")); |
| 273 | | let domDeclNoRef = /** @type HTMLElement */(document.getElementById("declNoRef")); |
| 274 | | let domSearch = /** @type HTMLInputElement */(document.getElementById("search")); |
| 275 | | let domSectSearchResults = /** @type HTMLElement */(document.getElementById("sectSearchResults")); |
| 276 | | |
| 277 | | let domListSearchResults = /** @type HTMLElement */(document.getElementById("listSearchResults")); |
| 278 | | let domSectSearchNoResults = /** @type HTMLElement */(document.getElementById("sectSearchNoResults")); |
| 279 | | let domSectInfo = /** @type HTMLElement */(document.getElementById("sectInfo")); |
| 280 | | // let domTdTarget = /** @type HTMLElement */(document.getElementById("tdTarget")); |
| 281 | | let domPrivDeclsBox = /** @type HTMLInputElement */(document.getElementById("privDeclsBox")); |
| 282 | | let domTdZigVer = /** @type HTMLElement */(document.getElementById("tdZigVer")); |
| 283 | | let domHdrName = /** @type HTMLElement */(document.getElementById("hdrName")); |
| 284 | | let domHelpModal = /** @type HTMLElement */(document.getElementById("helpDialog")); |
| 285 | | |
| 286 | | /** @type number | null */ |
| 6 | let domStatus = (document.getElementById("status")); |
| 7 | let domSectNav = (document.getElementById("sectNav")); |
| 8 | let domListNav = (document.getElementById("listNav")); |
| 9 | let domSectMainPkg = (document.getElementById("sectMainPkg")); |
| 10 | let domSectPkgs = (document.getElementById("sectPkgs")); |
| 11 | let domListPkgs = (document.getElementById("listPkgs")); |
| 12 | let domSectTypes = (document.getElementById("sectTypes")); |
| 13 | let domListTypes = (document.getElementById("listTypes")); |
| 14 | let domSectTests = (document.getElementById("sectTests")); |
| 15 | let domListTests = (document.getElementById("listTests")); |
| 16 | let domSectNamespaces = (document.getElementById("sectNamespaces")); |
| 17 | let domListNamespaces = (document.getElementById("listNamespaces")); |
| 18 | let domSectErrSets = (document.getElementById("sectErrSets")); |
| 19 | let domListErrSets = (document.getElementById("listErrSets")); |
| 20 | let domSectFns = (document.getElementById("sectFns")); |
| 21 | let domListFns = (document.getElementById("listFns")); |
| 22 | let domSectFields = (document.getElementById("sectFields")); |
| 23 | let domListFields = (document.getElementById("listFields")); |
| 24 | let domSectGlobalVars = (document.getElementById("sectGlobalVars")); |
| 25 | let domListGlobalVars = (document.getElementById("listGlobalVars")); |
| 26 | let domSectValues = (document.getElementById("sectValues")); |
| 27 | let domListValues = (document.getElementById("listValues")); |
| 28 | let domFnProto = (document.getElementById("fnProto")); |
| 29 | let domFnProtoCode = (document.getElementById("fnProtoCode")); |
| 30 | let domSectParams = (document.getElementById("sectParams")); |
| 31 | let domListParams = (document.getElementById("listParams")); |
| 32 | let domTldDocs = (document.getElementById("tldDocs")); |
| 33 | let domSectFnErrors = (document.getElementById("sectFnErrors")); |
| 34 | let domListFnErrors = (document.getElementById("listFnErrors")); |
| 35 | let domTableFnErrors =(document.getElementById("tableFnErrors")); |
| 36 | let domFnErrorsAnyError = (document.getElementById("fnErrorsAnyError")); |
| 37 | let domFnExamples = (document.getElementById("fnExamples")); |
| 38 | // let domListFnExamples = (document.getElementById("listFnExamples")); |
| 39 | let domFnNoExamples = (document.getElementById("fnNoExamples")); |
| 40 | let domDeclNoRef = (document.getElementById("declNoRef")); |
| 41 | let domSearch = (document.getElementById("search")); |
| 42 | let domSectSearchResults = (document.getElementById("sectSearchResults")); |
| 43 | |
| 44 | let domListSearchResults = (document.getElementById("listSearchResults")); |
| 45 | let domSectSearchNoResults = (document.getElementById("sectSearchNoResults")); |
| 46 | let domSectInfo = (document.getElementById("sectInfo")); |
| 47 | // let domTdTarget = (document.getElementById("tdTarget")); |
| 48 | let domPrivDeclsBox = (document.getElementById("privDeclsBox")); |
| 49 | let domTdZigVer = (document.getElementById("tdZigVer")); |
| 50 | let domHdrName = (document.getElementById("hdrName")); |
| 51 | let domHelpModal = (document.getElementById("helpDialog")); |
| 52 | |
| 53 | |
| 287 | 54 | let searchTimer = null; |
| 288 | 55 | |
| 289 | | /** @type Object<string, string> */ |
| 56 | |
| 290 | 57 | let escapeHtmlReplacements = { "&": "&amp;", '"': "&quot;", "<": "&lt;", ">": "&gt;" }; |
| 291 | 58 | |
| 292 | | let typeKinds = /** @type {Record<string, number>} */(indexTypeKinds()); |
| 293 | | let typeTypeId = /** @type {number} */ (findTypeTypeId()); |
| 59 | let typeKinds = (indexTypeKinds()); |
| 60 | let typeTypeId = (findTypeTypeId()); |
| 294 | 61 | let pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 }; |
| 295 | 62 | |
| 296 | 63 | // for each package, is an array with packages to get to this one |
| 297 | 64 | let canonPkgPaths = computeCanonicalPackagePaths(); |
| 298 | 65 | |
| 299 | | /** @typedef {{declNames: string[], pkgNames: string[]}} CanonDecl */ |
| 66 | |
| 300 | 67 | |
| 301 | 68 | // for each decl, is an array with {declNames, pkgNames} to get to this one |
| 302 | | /** @type CanonDecl[] | null */ |
| 69 | |
| 303 | 70 | let canonDeclPaths = null; // lazy; use getCanonDeclPath |
| 304 | 71 | |
| 305 | 72 | // for each type, is an array with {declNames, pkgNames} to get to this one |
| 306 | | /** @type number[] | null */ |
| 73 | |
| 307 | 74 | let canonTypeDecls = null; // lazy; use getCanonTypeDecl |
| 308 | 75 | |
| 309 | | /** @typedef {{ |
| 310 | | * showPrivDecls: boolean, |
| 311 | | * pkgNames: string[], |
| 312 | | * pkgObjs: Package[], |
| 313 | | * declNames: string[], |
| 314 | | * declObjs: (Decl | Type)[], |
| 315 | | * callName: any, |
| 316 | | * }} CurNav |
| 317 | | */ |
| 318 | | |
| 319 | | /** @type {CurNav} */ |
| 76 | |
| 77 | |
| 78 | |
| 320 | 79 | let curNav = { |
| 321 | 80 | showPrivDecls: false, |
| 322 | 81 | // each element is a package name, e.g. @import("a") then within there @import("b") |
| ... | ... | @@ -381,34 +140,34 @@ var zigAnalysis; |
| 381 | 140 | } |
| 382 | 141 | } |
| 383 | 142 | |
| 384 | | /** @param {Type | Decl} x */ |
| 143 | |
| 385 | 144 | function isDecl(x) { |
| 386 | 145 | return "value" in x; |
| 387 | 146 | } |
| 388 | 147 | |
| 389 | | /** @param {Type | Decl} x */ |
| 148 | |
| 390 | 149 | function isType(x) { |
| 391 | 150 | return "kind" in x && !("value" in x); |
| 392 | 151 | } |
| 393 | 152 | |
| 394 | | /** @param {Type | Decl} x */ |
| 153 | |
| 395 | 154 | function isContainerType(x) { |
| 396 | | return isType(x) && typeKindIsContainer(/** @type {Type} */(x).kind) ; |
| 155 | return isType(x) && typeKindIsContainer((x).kind) ; |
| 397 | 156 | } |
| 398 | 157 | |
| 399 | | /** @param {Expr} expr */ |
| 158 | |
| 400 | 159 | function typeShorthandName(expr) { |
| 401 | 160 | let resolvedExpr = resolveValue({expr: expr}); |
| 402 | 161 | if (!("type" in resolvedExpr)) { |
| 403 | 162 | return null; |
| 404 | 163 | } |
| 405 | | let type = /** @type {Type} */(zigAnalysis.types[resolvedExpr.type]); |
| 164 | let type = (zigAnalysis.types[resolvedExpr.type]); |
| 406 | 165 | |
| 407 | 166 | outer: for (let i = 0; i < 10000; i += 1) { |
| 408 | 167 | switch (type.kind) { |
| 409 | 168 | case typeKinds.Optional: |
| 410 | 169 | case typeKinds.Pointer: |
| 411 | | let child = /** @type {PointerType | OptionalType} */(type).child; |
| 170 | let child = (type).child; |
| 412 | 171 | let resolvedChild = resolveValue(child); |
| 413 | 172 | if ("type" in resolvedChild) { |
| 414 | 173 | type = zigAnalysis.types[resolvedChild.type]; |
| ... | ... | @@ -440,22 +199,19 @@ var zigAnalysis; |
| 440 | 199 | return escapeHtml(name); |
| 441 | 200 | } |
| 442 | 201 | |
| 443 | | /** @param {number} typeKind */ |
| 202 | |
| 444 | 203 | function typeKindIsContainer(typeKind) { |
| 445 | 204 | return typeKind === typeKinds.Struct || |
| 446 | 205 | typeKind === typeKinds.Union || |
| 447 | 206 | typeKind === typeKinds.Enum; |
| 448 | 207 | } |
| 449 | 208 | |
| 450 | | /** @param {number} typeKind */ |
| 209 | |
| 451 | 210 | function declCanRepresentTypeKind(typeKind) { |
| 452 | 211 | return typeKind === typeKinds.ErrorSet || typeKindIsContainer(typeKind); |
| 453 | 212 | } |
| 454 | 213 | |
| 455 | | // /** |
| 456 | | // * @param {WalkResult[]} path |
| 457 | | // * @return {WalkResult | null} |
| 458 | | // */ |
| 214 | // |
| 459 | 215 | // function findCteInRefPath(path) { |
| 460 | 216 | // for (let i = path.length - 1; i >= 0; i -= 1) { |
| 461 | 217 | // const ref = path[i]; |
| ... | ... | @@ -468,10 +224,7 @@ var zigAnalysis; |
| 468 | 224 | // return null; |
| 469 | 225 | // } |
| 470 | 226 | |
| 471 | | /** |
| 472 | | * @param {WalkResult} value |
| 473 | | * @return {WalkResult} |
| 474 | | */ |
| 227 | |
| 475 | 228 | function resolveValue(value) { |
| 476 | 229 | let i = 0; |
| 477 | 230 | while(i < 1000) { |
| ... | ... | @@ -499,13 +252,10 @@ var zigAnalysis; |
| 499 | 252 | |
| 500 | 253 | } |
| 501 | 254 | console.assert(false); |
| 502 | | return /** @type {WalkResult} */({}); |
| 255 | return ({}); |
| 503 | 256 | } |
| 504 | 257 | |
| 505 | | /** |
| 506 | | * @param {Decl} decl |
| 507 | | * @return {WalkResult} |
| 508 | | */ |
| 258 | |
| 509 | 259 | // function typeOfDecl(decl){ |
| 510 | 260 | // return decl.value.typeRef; |
| 511 | 261 | // |
| ... | ... | @@ -514,18 +264,18 @@ var zigAnalysis; |
| 514 | 264 | // i += 1; |
| 515 | 265 | // console.assert(isDecl(decl)); |
| 516 | 266 | // if ("type" in decl.value) { |
| 517 | | // return /** @type {WalkResult} */({ type: typeTypeId }); |
| 267 | // return ({ type: typeTypeId }); |
| 518 | 268 | // } |
| 519 | 269 | // |
| 520 | 270 | //// if ("string" in decl.value) { |
| 521 | | //// return /** @type {WalkResult} */({ type: { |
| 271 | //// return ({ type: { |
| 522 | 272 | //// kind: typeKinds.Pointer, |
| 523 | 273 | //// size: pointerSizeEnum.One, |
| 524 | 274 | //// child: }); |
| 525 | 275 | //// } |
| 526 | 276 | // |
| 527 | 277 | // if ("refPath" in decl.value) { |
| 528 | | // decl = /** @type {Decl} */({ |
| 278 | // decl = ({ |
| 529 | 279 | // value: decl.value.refPath[decl.value.refPath.length -1] |
| 530 | 280 | // }); |
| 531 | 281 | // continue; |
| ... | ... | @@ -569,17 +319,17 @@ var zigAnalysis; |
| 569 | 319 | // |
| 570 | 320 | // const fn_decl_value = resolveValue(fn_decl.value); |
| 571 | 321 | // console.assert("type" in fn_decl_value); //TODO handle comptimeExpr |
| 572 | | // const fn_type = /** @type {Fn} */(zigAnalysis.types[fn_decl_value.type]); |
| 322 | // const fn_type = (zigAnalysis.types[fn_decl_value.type]); |
| 573 | 323 | // console.assert(fn_type.kind === typeKinds.Fn); |
| 574 | 324 | // return fn_type.ret; |
| 575 | 325 | // } |
| 576 | 326 | // |
| 577 | 327 | // if ("void" in decl.value) { |
| 578 | | // return /** @type {WalkResult} */({ type: typeTypeId }); |
| 328 | // return ({ type: typeTypeId }); |
| 579 | 329 | // } |
| 580 | 330 | // |
| 581 | 331 | // if ("bool" in decl.value) { |
| 582 | | // return /** @type {WalkResult} */({ type: typeKinds.Bool }); |
| 332 | // return ({ type: typeKinds.Bool }); |
| 583 | 333 | // } |
| 584 | 334 | // |
| 585 | 335 | // console.log("TODO: handle in `typeOfDecl` more cases: ", decl); |
| ... | ... | @@ -587,7 +337,7 @@ var zigAnalysis; |
| 587 | 337 | // throw {}; |
| 588 | 338 | // } |
| 589 | 339 | // console.assert(false); |
| 590 | | // return /** @type {WalkResult} */({}); |
| 340 | // return ({}); |
| 591 | 341 | // } |
| 592 | 342 | |
| 593 | 343 | function render() { |
| ... | ... | @@ -639,18 +389,18 @@ var zigAnalysis; |
| 639 | 389 | curNav.pkgObjs.push(pkg); |
| 640 | 390 | } |
| 641 | 391 | |
| 642 | | /** @type {Decl | Type} */ |
| 392 | |
| 643 | 393 | let currentType = zigAnalysis.types[pkg.main]; |
| 644 | 394 | curNav.declObjs = [currentType]; |
| 645 | 395 | for (let i = 0; i < curNav.declNames.length; i += 1) { |
| 646 | 396 | |
| 647 | | /** @type {Decl | Type | null} */ |
| 648 | | let childDecl = findSubDecl(/** @type {ContainerType} */(currentType), curNav.declNames[i]); |
| 397 | |
| 398 | let childDecl = findSubDecl((currentType), curNav.declNames[i]); |
| 649 | 399 | if (childDecl == null) { |
| 650 | 400 | return render404(); |
| 651 | 401 | } |
| 652 | 402 | |
| 653 | | let childDeclValue = resolveValue(/** @type {Decl} */(childDecl).value).expr; |
| 403 | let childDeclValue = resolveValue((childDecl).value).expr; |
| 654 | 404 | if ("type" in childDeclValue) { |
| 655 | 405 | |
| 656 | 406 | const t = zigAnalysis.types[childDeclValue.type]; |
| ... | ... | @@ -659,7 +409,7 @@ var zigAnalysis; |
| 659 | 409 | } |
| 660 | 410 | } |
| 661 | 411 | |
| 662 | | currentType = /** @type {Decl | Type} */(childDecl); |
| 412 | currentType = (childDecl); |
| 663 | 413 | curNav.declObjs.push(currentType); |
| 664 | 414 | } |
| 665 | 415 | |
| ... | ... | @@ -671,32 +421,32 @@ var zigAnalysis; |
| 671 | 421 | let lastIsContainerType = isContainerType(last); |
| 672 | 422 | |
| 673 | 423 | if (lastIsContainerType) { |
| 674 | | return renderContainer(/** @type {ContainerType} */(last)); |
| 424 | return renderContainer((last)); |
| 675 | 425 | } |
| 676 | 426 | |
| 677 | 427 | if (!lastIsDecl && !lastIsType) { |
| 678 | | return renderUnknownDecl(/** @type {Decl} */(last)); |
| 428 | return renderUnknownDecl((last)); |
| 679 | 429 | } |
| 680 | 430 | |
| 681 | 431 | if (lastIsType) { |
| 682 | | return renderType(/** @type {Type} */(last)); |
| 432 | return renderType((last)); |
| 683 | 433 | } |
| 684 | 434 | |
| 685 | 435 | if (lastIsDecl && last.kind === 'var') { |
| 686 | | return renderVar(/** @type {Decl} */(last)); |
| 436 | return renderVar((last)); |
| 687 | 437 | } |
| 688 | 438 | |
| 689 | 439 | if (lastIsDecl && last.kind === 'const') { |
| 690 | | let typeObj = zigAnalysis.types[resolveValue(/** @type {Decl} */(last).value).expr.type]; |
| 440 | let typeObj = zigAnalysis.types[resolveValue((last).value).expr.type]; |
| 691 | 441 | if (typeObj && typeObj.kind === typeKinds.Fn) { |
| 692 | | return renderFn(/** @type {Decl} */(last)); |
| 442 | return renderFn((last)); |
| 693 | 443 | } |
| 694 | 444 | |
| 695 | | return renderValue(/** @type {Decl} */(last)); |
| 445 | return renderValue((last)); |
| 696 | 446 | } |
| 697 | 447 | } |
| 698 | 448 | |
| 699 | | /** @param {Decl} decl */ |
| 449 | |
| 700 | 450 | function renderUnknownDecl(decl) { |
| 701 | 451 | domDeclNoRef.classList.remove("hidden"); |
| 702 | 452 | |
| ... | ... | @@ -709,30 +459,30 @@ var zigAnalysis; |
| 709 | 459 | domTldDocs.classList.remove("hidden"); |
| 710 | 460 | } |
| 711 | 461 | |
| 712 | | /** @param {number} typeIndex */ |
| 462 | |
| 713 | 463 | function typeIsErrSet(typeIndex) { |
| 714 | 464 | let typeObj = zigAnalysis.types[typeIndex]; |
| 715 | 465 | return typeObj.kind === typeKinds.ErrorSet; |
| 716 | 466 | } |
| 717 | 467 | |
| 718 | | /** @param {number} typeIndex */ |
| 468 | |
| 719 | 469 | function typeIsStructWithNoFields(typeIndex) { |
| 720 | 470 | let typeObj = zigAnalysis.types[typeIndex]; |
| 721 | 471 | if (typeObj.kind !== typeKinds.Struct) |
| 722 | 472 | return false; |
| 723 | | return /** @type {ContainerType} */(typeObj).fields.length == 0; |
| 473 | return (typeObj).fields.length == 0; |
| 724 | 474 | } |
| 725 | 475 | |
| 726 | | /** @param {number} typeIndex */ |
| 476 | |
| 727 | 477 | function typeIsGenericFn(typeIndex) { |
| 728 | 478 | let typeObj = zigAnalysis.types[typeIndex]; |
| 729 | 479 | if (typeObj.kind !== typeKinds.Fn) { |
| 730 | 480 | return false; |
| 731 | 481 | } |
| 732 | | return /** @type {Fn} */(typeObj).generic_ret != null; |
| 482 | return (typeObj).generic_ret != null; |
| 733 | 483 | } |
| 734 | 484 | |
| 735 | | /** @param {Decl} fnDecl */ |
| 485 | |
| 736 | 486 | function renderFn(fnDecl) { |
| 737 | 487 | if ("refPath" in fnDecl.value.expr) { |
| 738 | 488 | let last = fnDecl.value.expr.refPath.length - 1; |
| ... | ... | @@ -743,7 +493,7 @@ var zigAnalysis; |
| 743 | 493 | |
| 744 | 494 | let value = resolveValue(fnDecl.value); |
| 745 | 495 | console.assert("type" in value.expr); |
| 746 | | let typeObj = /** @type {Fn} */(zigAnalysis.types[value.expr.type]); |
| 496 | let typeObj = (zigAnalysis.types[value.expr.type]); |
| 747 | 497 | |
| 748 | 498 | domFnProtoCode.innerHTML = exprName(value.expr, { |
| 749 | 499 | wantHtml: true, |
| ... | ... | @@ -762,15 +512,15 @@ var zigAnalysis; |
| 762 | 512 | let retExpr = resolveValue({expr:typeObj.ret}).expr; |
| 763 | 513 | if ("type" in retExpr) { |
| 764 | 514 | let retIndex = retExpr.type; |
| 765 | | let errSetTypeIndex = /** @type {number | null} */(null); |
| 515 | let errSetTypeIndex = (null); |
| 766 | 516 | let retType = zigAnalysis.types[retIndex]; |
| 767 | 517 | if (retType.kind === typeKinds.ErrorSet) { |
| 768 | 518 | errSetTypeIndex = retIndex; |
| 769 | 519 | } else if (retType.kind === typeKinds.ErrorUnion) { |
| 770 | | errSetTypeIndex = /** @type {ErrUnionType} */(retType).err.type; |
| 520 | errSetTypeIndex = (retType).err.type; |
| 771 | 521 | } |
| 772 | 522 | if (errSetTypeIndex != null) { |
| 773 | | let errSetType = /** @type {ErrSetType} */(zigAnalysis.types[errSetTypeIndex]); |
| 523 | let errSetType = (zigAnalysis.types[errSetTypeIndex]); |
| 774 | 524 | renderErrorSet(errSetType); |
| 775 | 525 | } |
| 776 | 526 | } |
| ... | ... | @@ -833,15 +583,12 @@ var zigAnalysis; |
| 833 | 583 | domFnProto.classList.remove("hidden"); |
| 834 | 584 | } |
| 835 | 585 | |
| 836 | | /** |
| 837 | | * @param {Decl} fnDecl |
| 838 | | * @param {Fn} typeObj |
| 839 | | */ |
| 586 | |
| 840 | 587 | function renderFnParamDocs(fnDecl, typeObj) { |
| 841 | 588 | let docCount = 0; |
| 842 | 589 | |
| 843 | 590 | let fnNode = zigAnalysis.astNodes[fnDecl.src]; |
| 844 | | let fields = /** @type {number[]} */(fnNode.fields); |
| 591 | let fields = (fnNode.fields); |
| 845 | 592 | let isVarArgs = fnNode.varArgs; |
| 846 | 593 | |
| 847 | 594 | for (let i = 0; i < fields.length; i += 1) { |
| ... | ... | @@ -869,7 +616,7 @@ var zigAnalysis; |
| 869 | 616 | |
| 870 | 617 | |
| 871 | 618 | let value = typeObj.params[i]; |
| 872 | | let html = '<pre>' + escapeHtml(/** @type {string} */(fieldNode.name)) + ": "; |
| 619 | let html = '<pre>' + escapeHtml((fieldNode.name)) + ": "; |
| 873 | 620 | if (isVarArgs && i === typeObj.params.length - 1) { |
| 874 | 621 | html += '...'; |
| 875 | 622 | } else { |
| ... | ... | @@ -893,7 +640,7 @@ var zigAnalysis; |
| 893 | 640 | resizeDomList(domListNav, len, '<li><a href="#"></a></li>'); |
| 894 | 641 | let list = []; |
| 895 | 642 | let hrefPkgNames = []; |
| 896 | | let hrefDeclNames = /** @type {string[]} */([]); |
| 643 | let hrefDeclNames = ([]); |
| 897 | 644 | for (let i = 0; i < curNav.pkgNames.length; i += 1) { |
| 898 | 645 | hrefPkgNames.push(curNav.pkgNames[i]); |
| 899 | 646 | let name = curNav.pkgNames[i]; |
| ... | ... | @@ -985,11 +732,7 @@ var zigAnalysis; |
| 985 | 732 | } |
| 986 | 733 | } |
| 987 | 734 | |
| 988 | | /** |
| 989 | | * @param {string[]} pkgNames |
| 990 | | * @param {string[]} declNames |
| 991 | | * @param {string} [callName] |
| 992 | | */ |
| 735 | |
| 993 | 736 | |
| 994 | 737 | function navLink(pkgNames, declNames, callName) { |
| 995 | 738 | let base = '#'; |
| ... | ... | @@ -1008,21 +751,21 @@ var zigAnalysis; |
| 1008 | 751 | } |
| 1009 | 752 | } |
| 1010 | 753 | |
| 1011 | | /** @param {number} pkgIndex */ |
| 754 | |
| 1012 | 755 | function navLinkPkg(pkgIndex) { |
| 1013 | 756 | console.log(canonPkgPaths); |
| 1014 | 757 | return navLink(canonPkgPaths[pkgIndex], []); |
| 1015 | 758 | } |
| 1016 | 759 | |
| 1017 | | /** @param {string} childName */ |
| 760 | |
| 1018 | 761 | function navLinkDecl(childName) { |
| 1019 | 762 | return navLink(curNav.pkgNames, curNav.declNames.concat([childName])); |
| 1020 | 763 | } |
| 1021 | 764 | |
| 1022 | | // /** @param {Call} callObj */ |
| 765 | // |
| 1023 | 766 | // function navLinkCall(callObj) { |
| 1024 | 767 | // let declNamesCopy = curNav.declNames.concat([]); |
| 1025 | | // let callName = /** @type {string} */(declNamesCopy.pop()); |
| 768 | // let callName = (declNamesCopy.pop()); |
| 1026 | 769 | |
| 1027 | 770 | // callName += '('; |
| 1028 | 771 | // for (let arg_i = 0; arg_i < callObj.args.length; arg_i += 1) { |
| ... | ... | @@ -1036,10 +779,7 @@ var zigAnalysis; |
| 1036 | 779 | // return navLink(curNav.pkgNames, declNamesCopy); |
| 1037 | 780 | // } |
| 1038 | 781 | |
| 1039 | | /** |
| 1040 | | * @param {any} dlDom |
| 1041 | | * @param {number} desiredLen |
| 1042 | | */ |
| 782 | |
| 1043 | 783 | function resizeDomListDl(dlDom, desiredLen) { |
| 1044 | 784 | // add the missing dom entries |
| 1045 | 785 | for (let i = dlDom.childElementCount / 2; i < desiredLen; i += 1) { |
| ... | ... | @@ -1052,11 +792,7 @@ var zigAnalysis; |
| 1052 | 792 | } |
| 1053 | 793 | } |
| 1054 | 794 | |
| 1055 | | /** |
| 1056 | | * @param {any} listDom |
| 1057 | | * @param {number} desiredLen |
| 1058 | | * @param {string} templateHtml |
| 1059 | | */ |
| 795 | |
| 1060 | 796 | function resizeDomList(listDom, desiredLen, templateHtml) { |
| 1061 | 797 | // add the missing dom entries |
| 1062 | 798 | for (let i = listDom.childElementCount; i < desiredLen; i += 1) { |
| ... | ... | @@ -1067,10 +803,7 @@ var zigAnalysis; |
| 1067 | 803 | listDom.removeChild(listDom.lastChild); |
| 1068 | 804 | } |
| 1069 | 805 | } |
| 1070 | | /** |
| 1071 | | * @param {WalkResult} wr, |
| 1072 | | * @return {Expr} |
| 1073 | | */ |
| 806 | |
| 1074 | 807 | function walkResultTypeRef(wr) { |
| 1075 | 808 | if (wr.typeRef) return wr.typeRef; |
| 1076 | 809 | let resolved = resolveValue(wr); |
| ... | ... | @@ -1079,14 +812,7 @@ var zigAnalysis; |
| 1079 | 812 | } |
| 1080 | 813 | return walkResultTypeRef(resolved); |
| 1081 | 814 | } |
| 1082 | | /** |
| 1083 | | * @typedef {{ |
| 1084 | | wantHtml: boolean, |
| 1085 | | }} RenderWrOptions |
| 1086 | | * @param {Expr} expr, |
| 1087 | | * @param {RenderWrOptions} opts, |
| 1088 | | * @return {string} |
| 1089 | | */ |
| 815 | |
| 1090 | 816 | function exprName(expr, opts) { |
| 1091 | 817 | switch (Object.keys(expr)[0]) { |
| 1092 | 818 | default: throw "oh no"; |
| ... | ... | @@ -1737,7 +1463,7 @@ var zigAnalysis; |
| 1737 | 1463 | } |
| 1738 | 1464 | case typeKinds.Array: |
| 1739 | 1465 | { |
| 1740 | | let arrayObj = /** @type {ArrayType} */ (typeObj); |
| 1466 | let arrayObj = (typeObj); |
| 1741 | 1467 | let name = "["; |
| 1742 | 1468 | let lenName = exprName(arrayObj.len, opts); |
| 1743 | 1469 | let sentinel = arrayObj.sentinel ? ":"+exprName(arrayObj.sentinel, opts) : ""; |
| ... | ... | @@ -1755,10 +1481,10 @@ var zigAnalysis; |
| 1755 | 1481 | return name; |
| 1756 | 1482 | } |
| 1757 | 1483 | case typeKinds.Optional: |
| 1758 | | return "?" + exprName(/**@type {OptionalType} */(typeObj).child, opts); |
| 1484 | return "?" + exprName((typeObj).child, opts); |
| 1759 | 1485 | case typeKinds.Pointer: |
| 1760 | 1486 | { |
| 1761 | | let ptrObj = /** @type {PointerType} */(typeObj); |
| 1487 | let ptrObj = (typeObj); |
| 1762 | 1488 | let sentinel = ptrObj.sentinel ? ":"+exprName(ptrObj.sentinel, opts) : ""; |
| 1763 | 1489 | let is_mutable = !ptrObj.is_mutable ? "const " : ""; |
| 1764 | 1490 | let name = ""; |
| ... | ... | @@ -1844,7 +1570,7 @@ var zigAnalysis; |
| 1844 | 1570 | } |
| 1845 | 1571 | case typeKinds.Float: |
| 1846 | 1572 | { |
| 1847 | | let floatObj = /** @type {NumberType} */ (typeObj); |
| 1573 | let floatObj = (typeObj); |
| 1848 | 1574 | |
| 1849 | 1575 | if (opts.wantHtml) { |
| 1850 | 1576 | return '<span class="tok-type">' + floatObj.name + '</span>'; |
| ... | ... | @@ -1854,7 +1580,7 @@ var zigAnalysis; |
| 1854 | 1580 | } |
| 1855 | 1581 | case typeKinds.Int: |
| 1856 | 1582 | { |
| 1857 | | let intObj = /** @type {NumberType} */(typeObj); |
| 1583 | let intObj = (typeObj); |
| 1858 | 1584 | let name = intObj.name; |
| 1859 | 1585 | if (opts.wantHtml) { |
| 1860 | 1586 | return '<span class="tok-type">' + name + '</span>'; |
| ... | ... | @@ -1906,7 +1632,7 @@ var zigAnalysis; |
| 1906 | 1632 | } |
| 1907 | 1633 | case typeKinds.ErrorSet: |
| 1908 | 1634 | { |
| 1909 | | let errSetObj = /** @type {ErrSetType} */(typeObj); |
| 1635 | let errSetObj = (typeObj); |
| 1910 | 1636 | if (errSetObj.fields == null) { |
| 1911 | 1637 | return '<span class="tok-type">anyerror</span>'; |
| 1912 | 1638 | } else { |
| ... | ... | @@ -1918,14 +1644,14 @@ var zigAnalysis; |
| 1918 | 1644 | |
| 1919 | 1645 | case typeKinds.ErrorUnion: |
| 1920 | 1646 | { |
| 1921 | | let errUnionObj = /** @type {ErrUnionType} */(typeObj); |
| 1647 | let errUnionObj = (typeObj); |
| 1922 | 1648 | let lhs = exprName(errUnionObj.lhs, opts); |
| 1923 | 1649 | let rhs = exprName(errUnionObj.rhs, opts); |
| 1924 | 1650 | return lhs + "!" + rhs; |
| 1925 | 1651 | } |
| 1926 | 1652 | case typeKinds.Fn: |
| 1927 | 1653 | { |
| 1928 | | let fnObj = /** @type {Fn} */(typeObj); |
| 1654 | let fnObj = (typeObj); |
| 1929 | 1655 | let payloadHtml = ""; |
| 1930 | 1656 | if (opts.wantHtml) { |
| 1931 | 1657 | if (fnObj.is_extern) { |
| ... | ... | @@ -2133,16 +1859,13 @@ var zigAnalysis; |
| 2133 | 1859 | } |
| 2134 | 1860 | |
| 2135 | 1861 | |
| 2136 | | /** |
| 2137 | | * @param {Expr} typeRef |
| 2138 | | * @param {string} paramName |
| 2139 | | */ |
| 1862 | |
| 2140 | 1863 | function shouldSkipParamName(typeRef, paramName) { |
| 2141 | 1864 | let resolvedTypeRef = resolveValue({expr: typeRef}); |
| 2142 | 1865 | if ("type" in resolvedTypeRef) { |
| 2143 | 1866 | let typeObj = zigAnalysis.types[resolvedTypeRef.type]; |
| 2144 | 1867 | if (typeObj.kind === typeKinds.Pointer){ |
| 2145 | | let ptrObj = /** @type {PointerType} */(typeObj); |
| 1868 | let ptrObj = (typeObj); |
| 2146 | 1869 | if (getPtrSize(ptrObj) === pointerSizeEnum.One) { |
| 2147 | 1870 | const value = resolveValue(ptrObj.child); |
| 2148 | 1871 | return typeValueName(value, false, true).toLowerCase() === paramName; |
| ... | ... | @@ -2152,12 +1875,12 @@ var zigAnalysis; |
| 2152 | 1875 | return false; |
| 2153 | 1876 | } |
| 2154 | 1877 | |
| 2155 | | /** @param {PointerType} typeObj */ |
| 1878 | |
| 2156 | 1879 | function getPtrSize(typeObj) { |
| 2157 | 1880 | return (typeObj.size == null) ? pointerSizeEnum.One : typeObj.size; |
| 2158 | 1881 | } |
| 2159 | 1882 | |
| 2160 | | /** @param {Type} typeObj */ |
| 1883 | |
| 2161 | 1884 | function renderType(typeObj) { |
| 2162 | 1885 | let name; |
| 2163 | 1886 | if (rootIsStd && typeObj === zigAnalysis.types[zigAnalysis.packages[zigAnalysis.rootPkg].main]) { |
| ... | ... | @@ -2170,11 +1893,11 @@ var zigAnalysis; |
| 2170 | 1893 | domHdrName.classList.remove("hidden"); |
| 2171 | 1894 | } |
| 2172 | 1895 | if (typeObj.kind == typeKinds.ErrorSet) { |
| 2173 | | renderErrorSet(/** @type {ErrSetType} */(typeObj)); |
| 1896 | renderErrorSet((typeObj)); |
| 2174 | 1897 | } |
| 2175 | 1898 | } |
| 2176 | 1899 | |
| 2177 | | /** @param {ErrSetType} errSetType */ |
| 1900 | |
| 2178 | 1901 | function renderErrorSet(errSetType) { |
| 2179 | 1902 | if (errSetType.fields == null) { |
| 2180 | 1903 | domFnErrorsAnyError.classList.remove("hidden"); |
| ... | ... | @@ -2278,7 +2001,7 @@ var zigAnalysis; |
| 2278 | 2001 | |
| 2279 | 2002 | |
| 2280 | 2003 | |
| 2281 | | /** @param {Decl} decl */ |
| 2004 | |
| 2282 | 2005 | function renderValue(decl) { |
| 2283 | 2006 | let resolvedValue = resolveValue(decl.value) |
| 2284 | 2007 | |
| ... | ... | @@ -2295,7 +2018,7 @@ var zigAnalysis; |
| 2295 | 2018 | domFnProto.classList.remove("hidden"); |
| 2296 | 2019 | } |
| 2297 | 2020 | |
| 2298 | | /** @param {Decl} decl */ |
| 2021 | |
| 2299 | 2022 | function renderVar(decl) { |
| 2300 | 2023 | let declTypeRef = typeOfDecl(decl); |
| 2301 | 2024 | domFnProtoCode.innerHTML = '<span class="tok-kw">var</span> ' + |
| ... | ... | @@ -2311,16 +2034,7 @@ var zigAnalysis; |
| 2311 | 2034 | } |
| 2312 | 2035 | |
| 2313 | 2036 | |
| 2314 | | /** |
| 2315 | | * @param {number[]} decls |
| 2316 | | * @param {Decl[]} typesList |
| 2317 | | * @param {Decl[]} namespacesList, |
| 2318 | | * @param {Decl[]} errSetsList, |
| 2319 | | * @param {Decl[]} fnsList, |
| 2320 | | * @param {Decl[]} varsList, |
| 2321 | | * @param {Decl[]} valsList, |
| 2322 | | * @param {Decl[]} testsList |
| 2323 | | */ |
| 2037 | |
| 2324 | 2038 | function categorizeDecls(decls, |
| 2325 | 2039 | typesList, namespacesList, errSetsList, |
| 2326 | 2040 | fnsList, varsList, valsList, testsList) { |
| ... | ... | @@ -2345,7 +2059,7 @@ var zigAnalysis; |
| 2345 | 2059 | const typeExpr = zigAnalysis.types[declValue.expr.type]; |
| 2346 | 2060 | if (typeExpr.kind == typeKinds.Fn) { |
| 2347 | 2061 | const funcRetExpr = resolveValue({ |
| 2348 | | expr: /** @type {Fn} */(typeExpr).ret |
| 2062 | expr: (typeExpr).ret |
| 2349 | 2063 | }); |
| 2350 | 2064 | if ("type" in funcRetExpr.expr && funcRetExpr.expr.type == typeTypeId) { |
| 2351 | 2065 | if (typeIsErrSet(declValue.expr.type)) { |
| ... | ... | @@ -2381,23 +2095,21 @@ var zigAnalysis; |
| 2381 | 2095 | } |
| 2382 | 2096 | } |
| 2383 | 2097 | |
| 2384 | | /** |
| 2385 | | * @param {ContainerType} container |
| 2386 | | */ |
| 2098 | |
| 2387 | 2099 | function renderContainer(container) { |
| 2388 | | /** @type {Decl[]} */ |
| 2100 | |
| 2389 | 2101 | let typesList = []; |
| 2390 | | /** @type {Decl[]} */ |
| 2102 | |
| 2391 | 2103 | let namespacesList = []; |
| 2392 | | /** @type {Decl[]} */ |
| 2104 | |
| 2393 | 2105 | let errSetsList = []; |
| 2394 | | /** @type {Decl[]} */ |
| 2106 | |
| 2395 | 2107 | let fnsList = []; |
| 2396 | | /** @type {Decl[]} */ |
| 2108 | |
| 2397 | 2109 | let varsList = []; |
| 2398 | | /** @type {Decl[]} */ |
| 2110 | |
| 2399 | 2111 | let valsList = []; |
| 2400 | | /** @type {Decl[]} */ |
| 2112 | |
| 2401 | 2113 | let testsList = []; |
| 2402 | 2114 | |
| 2403 | 2115 | categorizeDecls(container.pubDecls, |
| ... | ... | @@ -2497,7 +2209,7 @@ var zigAnalysis; |
| 2497 | 2209 | for (let i = 0; i < containerNode.fields.length; i += 1) { |
| 2498 | 2210 | let fieldNode = zigAnalysis.astNodes[containerNode.fields[i]]; |
| 2499 | 2211 | let divDom = domListFields.children[i]; |
| 2500 | | let fieldName = /** @type {string} */(fieldNode.name); |
| 2212 | let fieldName = (fieldNode.name); |
| 2501 | 2213 | |
| 2502 | 2214 | let html = '<div class="mobile-scroll-container"><pre class="scroll-item">' + escapeHtml(fieldName); |
| 2503 | 2215 | |
| ... | ... | @@ -2611,10 +2323,7 @@ var zigAnalysis; |
| 2611 | 2323 | } |
| 2612 | 2324 | |
| 2613 | 2325 | |
| 2614 | | /** |
| 2615 | | * @param {string | number} a |
| 2616 | | * @param {string | number} b |
| 2617 | | */ |
| 2326 | |
| 2618 | 2327 | function operatorCompare(a, b) { |
| 2619 | 2328 | if (a === b) { |
| 2620 | 2329 | return 0; |
| ... | ... | @@ -2637,7 +2346,7 @@ var zigAnalysis; |
| 2637 | 2346 | } |
| 2638 | 2347 | |
| 2639 | 2348 | function indexTypeKinds() { |
| 2640 | | let map = /** @type {Record<string, number>} */({}); |
| 2349 | let map = ({}); |
| 2641 | 2350 | for (let i = 0; i < zigAnalysis.typeKinds.length; i += 1) { |
| 2642 | 2351 | map[zigAnalysis.typeKinds[i]] = i; |
| 2643 | 2352 | } |
| ... | ... | @@ -2708,10 +2417,7 @@ var zigAnalysis; |
| 2708 | 2417 | } |
| 2709 | 2418 | } |
| 2710 | 2419 | |
| 2711 | | /** |
| 2712 | | * @param {ContainerType} parentType |
| 2713 | | * @param {string} childName |
| 2714 | | */ |
| 2420 | |
| 2715 | 2421 | function findSubDecl(parentType, childName) { |
| 2716 | 2422 | { |
| 2717 | 2423 | // Generic functions |
| ... | ... | @@ -2758,11 +2464,11 @@ var zigAnalysis; |
| 2758 | 2464 | let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg]; |
| 2759 | 2465 | // Breadth-first to keep the path shortest possible. |
| 2760 | 2466 | let stack = [{ |
| 2761 | | path: /** @type {string[]} */([]), |
| 2467 | path: ([]), |
| 2762 | 2468 | pkg: rootPkg, |
| 2763 | 2469 | }]; |
| 2764 | 2470 | while (stack.length !== 0) { |
| 2765 | | let item = /** @type {{path: string[], pkg: Package}} */(stack.shift()); |
| 2471 | let item = (stack.shift()); |
| 2766 | 2472 | for (let key in item.pkg.table) { |
| 2767 | 2473 | let childPkgIndex = item.pkg.table[key]; |
| 2768 | 2474 | if (list[childPkgIndex] != null) continue; |
| ... | ... | @@ -2781,7 +2487,7 @@ var zigAnalysis; |
| 2781 | 2487 | } |
| 2782 | 2488 | |
| 2783 | 2489 | |
| 2784 | | /** @return {CanonDecl[]} */ |
| 2490 | |
| 2785 | 2491 | function computeCanonDeclPaths() { |
| 2786 | 2492 | let list = new Array(zigAnalysis.decls.length); |
| 2787 | 2493 | canonTypeDecls = new Array(zigAnalysis.types.length); |
| ... | ... | @@ -2791,14 +2497,14 @@ var zigAnalysis; |
| 2791 | 2497 | let pkg = zigAnalysis.packages[pkgI]; |
| 2792 | 2498 | let pkgNames = canonPkgPaths[pkgI]; |
| 2793 | 2499 | let stack = [{ |
| 2794 | | declNames: /** @type {string[]} */([]), |
| 2500 | declNames: ([]), |
| 2795 | 2501 | type: zigAnalysis.types[pkg.main], |
| 2796 | 2502 | }]; |
| 2797 | 2503 | while (stack.length !== 0) { |
| 2798 | | let item = /** @type {{declNames: string[], type: Type}} */(stack.shift()); |
| 2504 | let item = (stack.shift()); |
| 2799 | 2505 | |
| 2800 | 2506 | if (isContainerType(item.type)) { |
| 2801 | | let t = /** @type {ContainerType} */(item.type); |
| 2507 | let t = (item.type); |
| 2802 | 2508 | |
| 2803 | 2509 | let len = t.pubDecls ? t.pubDecls.length : 0; |
| 2804 | 2510 | for (let declI = 0; declI < len; declI += 1) { |
| ... | ... | @@ -2833,48 +2539,40 @@ var zigAnalysis; |
| 2833 | 2539 | return list; |
| 2834 | 2540 | } |
| 2835 | 2541 | |
| 2836 | | /** @param {number} index */ |
| 2542 | |
| 2837 | 2543 | function getCanonDeclPath(index) { |
| 2838 | 2544 | if (canonDeclPaths == null) { |
| 2839 | 2545 | canonDeclPaths = computeCanonDeclPaths(); |
| 2840 | 2546 | } |
| 2841 | | //let cd = /** @type {CanonDecl[]}*/(canonDeclPaths); |
| 2547 | //let cd = (canonDeclPaths); |
| 2842 | 2548 | return canonDeclPaths[index]; |
| 2843 | 2549 | } |
| 2844 | 2550 | |
| 2845 | | /** @param {number} index */ |
| 2551 | |
| 2846 | 2552 | function getCanonTypeDecl(index) { |
| 2847 | 2553 | getCanonDeclPath(0); |
| 2848 | | //let ct = /** @type {number[]}*/(canonTypeDecls); |
| 2554 | //let ct = (canonTypeDecls); |
| 2849 | 2555 | return canonTypeDecls[index]; |
| 2850 | 2556 | } |
| 2851 | 2557 | |
| 2852 | | /** @param {string} text */ |
| 2558 | |
| 2853 | 2559 | function escapeHtml(text) { |
| 2854 | 2560 | return text.replace(/[&"<>]/g, function (m) { |
| 2855 | 2561 | return escapeHtmlReplacements[m]; |
| 2856 | 2562 | }); |
| 2857 | 2563 | } |
| 2858 | 2564 | |
| 2859 | | /** @param {string} docs */ |
| 2565 | |
| 2860 | 2566 | function shortDescMarkdown(docs) { |
| 2861 | 2567 | let parts = docs.trim().split("\n"); |
| 2862 | 2568 | let firstLine = parts[0]; |
| 2863 | 2569 | return markdown(firstLine); |
| 2864 | 2570 | } |
| 2865 | 2571 | |
| 2866 | | /** @param {string} input */ |
| 2572 | |
| 2867 | 2573 | function markdown(input) { |
| 2868 | 2574 | const raw_lines = input.split('\n'); // zig allows no '\r', so we don't need to split on CR |
| 2869 | | /** |
| 2870 | | * @type Array<{ |
| 2871 | | * indent: number, |
| 2872 | | * raw_text: string, |
| 2873 | | * text: string, |
| 2874 | | * type: string, |
| 2875 | | * ordered_number: number, |
| 2876 | | * }> |
| 2877 | | */ |
| 2575 | |
| 2878 | 2576 | const lines = []; |
| 2879 | 2577 | |
| 2880 | 2578 | // PHASE 1: |
| ... | ... | @@ -2928,7 +2626,7 @@ var zigAnalysis; |
| 2928 | 2626 | line.text = line.text.substr(1); |
| 2929 | 2627 | } |
| 2930 | 2628 | else if (line.text.match(/^\d+\..*$/)) { // if line starts with {number}{dot} |
| 2931 | | const match = /** @type {RegExpMatchArray} */(line.text.match(/(\d+)\./)); |
| 2629 | const match = (line.text.match(/(\d+)\./)); |
| 2932 | 2630 | line.type = "ul"; |
| 2933 | 2631 | line.text = line.text.substr(match[0].length); |
| 2934 | 2632 | line.ordered_number = Number(match[1].length); |
| ... | ... | @@ -2961,9 +2659,7 @@ var zigAnalysis; |
| 2961 | 2659 | // Render HTML from markdown lines. |
| 2962 | 2660 | // Look at each line and emit fitting HTML code |
| 2963 | 2661 | |
| 2964 | | /** |
| 2965 | | * @param {string } innerText |
| 2966 | | */ |
| 2662 | |
| 2967 | 2663 | function markdownInlines(innerText) { |
| 2968 | 2664 | |
| 2969 | 2665 | // inline types: |
| ... | ... | @@ -2977,8 +2673,8 @@ var zigAnalysis; |
| 2977 | 2673 | //  : <img> |
| 2978 | 2674 | // [[std;format.fmt]] : <a> (inner link) |
| 2979 | 2675 | |
| 2980 | | /** @typedef {{marker: string, tag: string}} Fmt*/ |
| 2981 | | /** @type {Array<Fmt>} */ |
| 2676 | |
| 2677 | |
| 2982 | 2678 | const formats = [ |
| 2983 | 2679 | { |
| 2984 | 2680 | marker: "**", |
| ... | ... | @@ -2998,7 +2694,7 @@ var zigAnalysis; |
| 2998 | 2694 | } |
| 2999 | 2695 | ]; |
| 3000 | 2696 | |
| 3001 | | /** @type {Array<Fmt>} */ |
| 2697 | |
| 3002 | 2698 | const stack = []; |
| 3003 | 2699 | |
| 3004 | 2700 | let innerHTML = ""; |
| ... | ... | @@ -3050,7 +2746,7 @@ var zigAnalysis; |
| 3050 | 2746 | in_code = true; |
| 3051 | 2747 | } else { |
| 3052 | 2748 | let any = false; |
| 3053 | | for (let idx = /** @type {number} */(stack.length > 0 ? -1 : 0); idx < formats.length; idx++) { |
| 2749 | for (let idx = (stack.length > 0 ? -1 : 0); idx < formats.length; idx++) { |
| 3054 | 2750 | const fmt = idx >= 0 ? formats[idx] : stack[stack.length - 1]; |
| 3055 | 2751 | if (innerText.substr(i, fmt.marker.length) == fmt.marker) { |
| 3056 | 2752 | flushRun(); |
| ... | ... | @@ -3074,17 +2770,14 @@ var zigAnalysis; |
| 3074 | 2770 | flushRun(); |
| 3075 | 2771 | |
| 3076 | 2772 | while (stack.length > 0) { |
| 3077 | | const fmt = /** @type {Fmt} */(stack.pop()); |
| 2773 | const fmt = (stack.pop()); |
| 3078 | 2774 | innerHTML += "</" + fmt.tag + ">"; |
| 3079 | 2775 | } |
| 3080 | 2776 | |
| 3081 | 2777 | return innerHTML; |
| 3082 | 2778 | } |
| 3083 | 2779 | |
| 3084 | | /** |
| 3085 | | * @param {string} type |
| 3086 | | * @param {number} line_no |
| 3087 | | */ |
| 2780 | |
| 3088 | 2781 | function previousLineIs(type, line_no) { |
| 3089 | 2782 | if (line_no > 0) { |
| 3090 | 2783 | return (lines[line_no - 1].type == type); |
| ... | ... | @@ -3093,10 +2786,7 @@ var zigAnalysis; |
| 3093 | 2786 | } |
| 3094 | 2787 | } |
| 3095 | 2788 | |
| 3096 | | /** |
| 3097 | | * @param {string} type |
| 3098 | | * @param {number} line_no |
| 3099 | | */ |
| 2789 | |
| 3100 | 2790 | function nextLineIs(type, line_no) { |
| 3101 | 2791 | if (line_no < (lines.length - 1)) { |
| 3102 | 2792 | return (lines[line_no + 1].type == type); |
| ... | ... | @@ -3105,7 +2795,7 @@ var zigAnalysis; |
| 3105 | 2795 | } |
| 3106 | 2796 | } |
| 3107 | 2797 | |
| 3108 | | /** @param {number} line_no */ |
| 2798 | |
| 3109 | 2799 | function getPreviousLineIndent(line_no) { |
| 3110 | 2800 | if (line_no > 0) { |
| 3111 | 2801 | return lines[line_no - 1].indent; |
| ... | ... | @@ -3114,7 +2804,7 @@ var zigAnalysis; |
| 3114 | 2804 | } |
| 3115 | 2805 | } |
| 3116 | 2806 | |
| 3117 | | /** @param {number} line_no */ |
| 2807 | |
| 3118 | 2808 | function getNextLineIndent(line_no) { |
| 3119 | 2809 | if (line_no < (lines.length - 1)) { |
| 3120 | 2810 | return lines[line_no + 1].indent; |
| ... | ... | @@ -3188,13 +2878,13 @@ var zigAnalysis; |
| 3188 | 2878 | } |
| 3189 | 2879 | if (liDom != null) { |
| 3190 | 2880 | let aDom = liDom.children[0]; |
| 3191 | | location.href = /** @type {string} */(aDom.getAttribute("href")); |
| 2881 | location.href = (aDom.getAttribute("href")); |
| 3192 | 2882 | curSearchIndex = -1; |
| 3193 | 2883 | } |
| 3194 | 2884 | domSearch.blur(); |
| 3195 | 2885 | } |
| 3196 | 2886 | |
| 3197 | | /** @param {KeyboardEvent} ev */ |
| 2887 | |
| 3198 | 2888 | function onSearchKeyDown(ev) { |
| 3199 | 2889 | switch (getKeyString(ev)) { |
| 3200 | 2890 | case "Enter": |
| ... | ... | @@ -3239,7 +2929,7 @@ var zigAnalysis; |
| 3239 | 2929 | } |
| 3240 | 2930 | |
| 3241 | 2931 | |
| 3242 | | /** @param {number} dir */ |
| 2932 | |
| 3243 | 2933 | function moveSearchCursor(dir) { |
| 3244 | 2934 | if (curSearchIndex < 0 || curSearchIndex >= domListSearchResults.children.length) { |
| 3245 | 2935 | if (dir > 0) { |
| ... | ... | @@ -3259,7 +2949,7 @@ var zigAnalysis; |
| 3259 | 2949 | renderSearchCursor(); |
| 3260 | 2950 | } |
| 3261 | 2951 | |
| 3262 | | /** @param {KeyboardEvent} ev */ |
| 2952 | |
| 3263 | 2953 | function getKeyString(ev) { |
| 3264 | 2954 | let name; |
| 3265 | 2955 | let ignoreShift = false; |
| ... | ... | @@ -3286,7 +2976,7 @@ var zigAnalysis; |
| 3286 | 2976 | return name; |
| 3287 | 2977 | } |
| 3288 | 2978 | |
| 3289 | | /** @param {KeyboardEvent} ev */ |
| 2979 | |
| 3290 | 2980 | function onWindowKeyDown(ev) { |
| 3291 | 2981 | switch (getKeyString(ev)) { |
| 3292 | 2982 | case "Esc": |
| ... | ... | @@ -3427,7 +3117,7 @@ function renderSearch() { |
| 3427 | 3117 | |
| 3428 | 3118 | function renderSearchCursor() { |
| 3429 | 3119 | for (let i = 0; i < domListSearchResults.children.length; i += 1) { |
| 3430 | | let liDom = /** @type HTMLElement */(domListSearchResults.children[i]); |
| 3120 | let liDom = (domListSearchResults.children[i]); |
| 3431 | 3121 | if (curSearchIndex === i) { |
| 3432 | 3122 | liDom.classList.add("selected"); |
| 3433 | 3123 | } else { |
| ... | ... | @@ -3453,10 +3143,7 @@ function renderSearchCursor() { |
| 3453 | 3143 | // } |
| 3454 | 3144 | |
| 3455 | 3145 | |
| 3456 | | /** |
| 3457 | | * @param {{ name: string }} a |
| 3458 | | * @param {{ name: string }} b |
| 3459 | | */ |
| 3146 | |
| 3460 | 3147 | function byNameProperty(a, b) { |
| 3461 | 3148 | return operatorCompare(a.name, b.name); |
| 3462 | 3149 | } |