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