authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-06-09 17:41:59+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:12-07:00
log45e3b1a23df6f0f0174b277194b5301662d7c256
treeb601038a247ccc688d0166dad51078dda9baffc9
parent02bd5fe93a08fa778ce0adb0a82b26becbfdc7e7

autodoc: remove type annotations from main.js


1 files changed, 175 insertions(+), 488 deletions(-)

lib/docs/main.js+175-488
......@@ -1,322 +1,81 @@
11'use strict';
22
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} */
2363var zigAnalysis;
2374
2385(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
28754 let searchTimer = null;
28855
289 /** @type Object<string, string> */
56
29057 let escapeHtmlReplacements = { "&": "&amp;", '"': "&quot;", "<": "&lt;", ">": "&gt;" };
29158
292 let typeKinds = /** @type {Record<string, number>} */(indexTypeKinds());
293 let typeTypeId = /** @type {number} */ (findTypeTypeId());
59 let typeKinds = (indexTypeKinds());
60 let typeTypeId = (findTypeTypeId());
29461 let pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 };
29562
29663 // for each package, is an array with packages to get to this one
29764 let canonPkgPaths = computeCanonicalPackagePaths();
29865
299 /** @typedef {{declNames: string[], pkgNames: string[]}} CanonDecl */
66
30067
30168 // for each decl, is an array with {declNames, pkgNames} to get to this one
302 /** @type CanonDecl[] | null */
69
30370 let canonDeclPaths = null; // lazy; use getCanonDeclPath
30471
30572 // for each type, is an array with {declNames, pkgNames} to get to this one
306 /** @type number[] | null */
73
30774 let canonTypeDecls = null; // lazy; use getCanonTypeDecl
30875
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
32079 let curNav = {
32180 showPrivDecls: false,
32281 // each element is a package name, e.g. @import("a") then within there @import("b")
......@@ -381,34 +140,34 @@ var zigAnalysis;
381140 }
382141 }
383142
384 /** @param {Type | Decl} x */
143
385144 function isDecl(x) {
386145 return "value" in x;
387146 }
388147
389 /** @param {Type | Decl} x */
148
390149 function isType(x) {
391150 return "kind" in x && !("value" in x);
392151 }
393152
394 /** @param {Type | Decl} x */
153
395154 function isContainerType(x) {
396 return isType(x) && typeKindIsContainer(/** @type {Type} */(x).kind) ;
155 return isType(x) && typeKindIsContainer((x).kind) ;
397156 }
398157
399 /** @param {Expr} expr */
158
400159 function typeShorthandName(expr) {
401160 let resolvedExpr = resolveValue({expr: expr});
402161 if (!("type" in resolvedExpr)) {
403162 return null;
404163 }
405 let type = /** @type {Type} */(zigAnalysis.types[resolvedExpr.type]);
164 let type = (zigAnalysis.types[resolvedExpr.type]);
406165
407166 outer: for (let i = 0; i < 10000; i += 1) {
408167 switch (type.kind) {
409168 case typeKinds.Optional:
410169 case typeKinds.Pointer:
411 let child = /** @type {PointerType | OptionalType} */(type).child;
170 let child = (type).child;
412171 let resolvedChild = resolveValue(child);
413172 if ("type" in resolvedChild) {
414173 type = zigAnalysis.types[resolvedChild.type];
......@@ -440,22 +199,19 @@ var zigAnalysis;
440199 return escapeHtml(name);
441200 }
442201
443 /** @param {number} typeKind */
202
444203 function typeKindIsContainer(typeKind) {
445204 return typeKind === typeKinds.Struct ||
446205 typeKind === typeKinds.Union ||
447206 typeKind === typeKinds.Enum;
448207 }
449208
450 /** @param {number} typeKind */
209
451210 function declCanRepresentTypeKind(typeKind) {
452211 return typeKind === typeKinds.ErrorSet || typeKindIsContainer(typeKind);
453212 }
454213
455 // /**
456 // * @param {WalkResult[]} path
457 // * @return {WalkResult | null}
458 // */
214 //
459215 // function findCteInRefPath(path) {
460216 // for (let i = path.length - 1; i >= 0; i -= 1) {
461217 // const ref = path[i];
......@@ -468,10 +224,7 @@ var zigAnalysis;
468224 // return null;
469225 // }
470226
471 /**
472 * @param {WalkResult} value
473 * @return {WalkResult}
474 */
227
475228 function resolveValue(value) {
476229 let i = 0;
477230 while(i < 1000) {
......@@ -499,13 +252,10 @@ var zigAnalysis;
499252
500253 }
501254 console.assert(false);
502 return /** @type {WalkResult} */({});
255 return ({});
503256 }
504257
505 /**
506 * @param {Decl} decl
507 * @return {WalkResult}
508 */
258
509259// function typeOfDecl(decl){
510260// return decl.value.typeRef;
511261//
......@@ -514,18 +264,18 @@ var zigAnalysis;
514264// i += 1;
515265// console.assert(isDecl(decl));
516266// if ("type" in decl.value) {
517// return /** @type {WalkResult} */({ type: typeTypeId });
267// return ({ type: typeTypeId });
518268// }
519269//
520270//// if ("string" in decl.value) {
521//// return /** @type {WalkResult} */({ type: {
271//// return ({ type: {
522272//// kind: typeKinds.Pointer,
523273//// size: pointerSizeEnum.One,
524274//// child: });
525275//// }
526276//
527277// if ("refPath" in decl.value) {
528// decl = /** @type {Decl} */({
278// decl = ({
529279// value: decl.value.refPath[decl.value.refPath.length -1]
530280// });
531281// continue;
......@@ -569,17 +319,17 @@ var zigAnalysis;
569319//
570320// const fn_decl_value = resolveValue(fn_decl.value);
571321// 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]);
573323// console.assert(fn_type.kind === typeKinds.Fn);
574324// return fn_type.ret;
575325// }
576326//
577327// if ("void" in decl.value) {
578// return /** @type {WalkResult} */({ type: typeTypeId });
328// return ({ type: typeTypeId });
579329// }
580330//
581331// if ("bool" in decl.value) {
582// return /** @type {WalkResult} */({ type: typeKinds.Bool });
332// return ({ type: typeKinds.Bool });
583333// }
584334//
585335// console.log("TODO: handle in `typeOfDecl` more cases: ", decl);
......@@ -587,7 +337,7 @@ var zigAnalysis;
587337// throw {};
588338// }
589339// console.assert(false);
590// return /** @type {WalkResult} */({});
340// return ({});
591341// }
592342
593343 function render() {
......@@ -639,18 +389,18 @@ var zigAnalysis;
639389 curNav.pkgObjs.push(pkg);
640390 }
641391
642 /** @type {Decl | Type} */
392
643393 let currentType = zigAnalysis.types[pkg.main];
644394 curNav.declObjs = [currentType];
645395 for (let i = 0; i < curNav.declNames.length; i += 1) {
646396
647 /** @type {Decl | Type | null} */
648 let childDecl = findSubDecl(/** @type {ContainerType} */(currentType), curNav.declNames[i]);
397
398 let childDecl = findSubDecl((currentType), curNav.declNames[i]);
649399 if (childDecl == null) {
650400 return render404();
651401 }
652402
653 let childDeclValue = resolveValue(/** @type {Decl} */(childDecl).value).expr;
403 let childDeclValue = resolveValue((childDecl).value).expr;
654404 if ("type" in childDeclValue) {
655405
656406 const t = zigAnalysis.types[childDeclValue.type];
......@@ -659,7 +409,7 @@ var zigAnalysis;
659409 }
660410 }
661411
662 currentType = /** @type {Decl | Type} */(childDecl);
412 currentType = (childDecl);
663413 curNav.declObjs.push(currentType);
664414 }
665415
......@@ -671,32 +421,32 @@ var zigAnalysis;
671421 let lastIsContainerType = isContainerType(last);
672422
673423 if (lastIsContainerType) {
674 return renderContainer(/** @type {ContainerType} */(last));
424 return renderContainer((last));
675425 }
676426
677427 if (!lastIsDecl && !lastIsType) {
678 return renderUnknownDecl(/** @type {Decl} */(last));
428 return renderUnknownDecl((last));
679429 }
680430
681431 if (lastIsType) {
682 return renderType(/** @type {Type} */(last));
432 return renderType((last));
683433 }
684434
685435 if (lastIsDecl && last.kind === 'var') {
686 return renderVar(/** @type {Decl} */(last));
436 return renderVar((last));
687437 }
688438
689439 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];
691441 if (typeObj && typeObj.kind === typeKinds.Fn) {
692 return renderFn(/** @type {Decl} */(last));
442 return renderFn((last));
693443 }
694444
695 return renderValue(/** @type {Decl} */(last));
445 return renderValue((last));
696446 }
697447 }
698448
699 /** @param {Decl} decl */
449
700450 function renderUnknownDecl(decl) {
701451 domDeclNoRef.classList.remove("hidden");
702452
......@@ -709,30 +459,30 @@ var zigAnalysis;
709459 domTldDocs.classList.remove("hidden");
710460 }
711461
712 /** @param {number} typeIndex */
462
713463 function typeIsErrSet(typeIndex) {
714464 let typeObj = zigAnalysis.types[typeIndex];
715465 return typeObj.kind === typeKinds.ErrorSet;
716466 }
717467
718 /** @param {number} typeIndex */
468
719469 function typeIsStructWithNoFields(typeIndex) {
720470 let typeObj = zigAnalysis.types[typeIndex];
721471 if (typeObj.kind !== typeKinds.Struct)
722472 return false;
723 return /** @type {ContainerType} */(typeObj).fields.length == 0;
473 return (typeObj).fields.length == 0;
724474 }
725475
726 /** @param {number} typeIndex */
476
727477 function typeIsGenericFn(typeIndex) {
728478 let typeObj = zigAnalysis.types[typeIndex];
729479 if (typeObj.kind !== typeKinds.Fn) {
730480 return false;
731481 }
732 return /** @type {Fn} */(typeObj).generic_ret != null;
482 return (typeObj).generic_ret != null;
733483 }
734484
735 /** @param {Decl} fnDecl */
485
736486 function renderFn(fnDecl) {
737487 if ("refPath" in fnDecl.value.expr) {
738488 let last = fnDecl.value.expr.refPath.length - 1;
......@@ -743,7 +493,7 @@ var zigAnalysis;
743493
744494 let value = resolveValue(fnDecl.value);
745495 console.assert("type" in value.expr);
746 let typeObj = /** @type {Fn} */(zigAnalysis.types[value.expr.type]);
496 let typeObj = (zigAnalysis.types[value.expr.type]);
747497
748498 domFnProtoCode.innerHTML = exprName(value.expr, {
749499 wantHtml: true,
......@@ -762,15 +512,15 @@ var zigAnalysis;
762512 let retExpr = resolveValue({expr:typeObj.ret}).expr;
763513 if ("type" in retExpr) {
764514 let retIndex = retExpr.type;
765 let errSetTypeIndex = /** @type {number | null} */(null);
515 let errSetTypeIndex = (null);
766516 let retType = zigAnalysis.types[retIndex];
767517 if (retType.kind === typeKinds.ErrorSet) {
768518 errSetTypeIndex = retIndex;
769519 } else if (retType.kind === typeKinds.ErrorUnion) {
770 errSetTypeIndex = /** @type {ErrUnionType} */(retType).err.type;
520 errSetTypeIndex = (retType).err.type;
771521 }
772522 if (errSetTypeIndex != null) {
773 let errSetType = /** @type {ErrSetType} */(zigAnalysis.types[errSetTypeIndex]);
523 let errSetType = (zigAnalysis.types[errSetTypeIndex]);
774524 renderErrorSet(errSetType);
775525 }
776526 }
......@@ -833,15 +583,12 @@ var zigAnalysis;
833583 domFnProto.classList.remove("hidden");
834584 }
835585
836 /**
837 * @param {Decl} fnDecl
838 * @param {Fn} typeObj
839 */
586
840587 function renderFnParamDocs(fnDecl, typeObj) {
841588 let docCount = 0;
842589
843590 let fnNode = zigAnalysis.astNodes[fnDecl.src];
844 let fields = /** @type {number[]} */(fnNode.fields);
591 let fields = (fnNode.fields);
845592 let isVarArgs = fnNode.varArgs;
846593
847594 for (let i = 0; i < fields.length; i += 1) {
......@@ -869,7 +616,7 @@ var zigAnalysis;
869616
870617
871618 let value = typeObj.params[i];
872 let html = '<pre>' + escapeHtml(/** @type {string} */(fieldNode.name)) + ": ";
619 let html = '<pre>' + escapeHtml((fieldNode.name)) + ": ";
873620 if (isVarArgs && i === typeObj.params.length - 1) {
874621 html += '...';
875622 } else {
......@@ -893,7 +640,7 @@ var zigAnalysis;
893640 resizeDomList(domListNav, len, '<li><a href="#"></a></li>');
894641 let list = [];
895642 let hrefPkgNames = [];
896 let hrefDeclNames = /** @type {string[]} */([]);
643 let hrefDeclNames = ([]);
897644 for (let i = 0; i < curNav.pkgNames.length; i += 1) {
898645 hrefPkgNames.push(curNav.pkgNames[i]);
899646 let name = curNav.pkgNames[i];
......@@ -985,11 +732,7 @@ var zigAnalysis;
985732 }
986733 }
987734
988 /**
989 * @param {string[]} pkgNames
990 * @param {string[]} declNames
991 * @param {string} [callName]
992 */
735
993736
994737 function navLink(pkgNames, declNames, callName) {
995738 let base = '#';
......@@ -1008,21 +751,21 @@ var zigAnalysis;
1008751 }
1009752 }
1010753
1011 /** @param {number} pkgIndex */
754
1012755 function navLinkPkg(pkgIndex) {
1013756 console.log(canonPkgPaths);
1014757 return navLink(canonPkgPaths[pkgIndex], []);
1015758 }
1016759
1017 /** @param {string} childName */
760
1018761 function navLinkDecl(childName) {
1019762 return navLink(curNav.pkgNames, curNav.declNames.concat([childName]));
1020763 }
1021764
1022 // /** @param {Call} callObj */
765 //
1023766 // function navLinkCall(callObj) {
1024767 // let declNamesCopy = curNav.declNames.concat([]);
1025 // let callName = /** @type {string} */(declNamesCopy.pop());
768 // let callName = (declNamesCopy.pop());
1026769
1027770 // callName += '(';
1028771 // for (let arg_i = 0; arg_i < callObj.args.length; arg_i += 1) {
......@@ -1036,10 +779,7 @@ var zigAnalysis;
1036779 // return navLink(curNav.pkgNames, declNamesCopy);
1037780 // }
1038781
1039 /**
1040 * @param {any} dlDom
1041 * @param {number} desiredLen
1042 */
782
1043783 function resizeDomListDl(dlDom, desiredLen) {
1044784 // add the missing dom entries
1045785 for (let i = dlDom.childElementCount / 2; i < desiredLen; i += 1) {
......@@ -1052,11 +792,7 @@ var zigAnalysis;
1052792 }
1053793 }
1054794
1055 /**
1056 * @param {any} listDom
1057 * @param {number} desiredLen
1058 * @param {string} templateHtml
1059 */
795
1060796 function resizeDomList(listDom, desiredLen, templateHtml) {
1061797 // add the missing dom entries
1062798 for (let i = listDom.childElementCount; i < desiredLen; i += 1) {
......@@ -1067,10 +803,7 @@ var zigAnalysis;
1067803 listDom.removeChild(listDom.lastChild);
1068804 }
1069805 }
1070 /**
1071 * @param {WalkResult} wr,
1072 * @return {Expr}
1073 */
806
1074807 function walkResultTypeRef(wr) {
1075808 if (wr.typeRef) return wr.typeRef;
1076809 let resolved = resolveValue(wr);
......@@ -1079,14 +812,7 @@ var zigAnalysis;
1079812 }
1080813 return walkResultTypeRef(resolved);
1081814 }
1082 /**
1083 * @typedef {{
1084 wantHtml: boolean,
1085 }} RenderWrOptions
1086 * @param {Expr} expr,
1087 * @param {RenderWrOptions} opts,
1088 * @return {string}
1089 */
815
1090816 function exprName(expr, opts) {
1091817 switch (Object.keys(expr)[0]) {
1092818 default: throw "oh no";
......@@ -1737,7 +1463,7 @@ var zigAnalysis;
17371463 }
17381464 case typeKinds.Array:
17391465 {
1740 let arrayObj = /** @type {ArrayType} */ (typeObj);
1466 let arrayObj = (typeObj);
17411467 let name = "[";
17421468 let lenName = exprName(arrayObj.len, opts);
17431469 let sentinel = arrayObj.sentinel ? ":"+exprName(arrayObj.sentinel, opts) : "";
......@@ -1755,10 +1481,10 @@ var zigAnalysis;
17551481 return name;
17561482 }
17571483 case typeKinds.Optional:
1758 return "?" + exprName(/**@type {OptionalType} */(typeObj).child, opts);
1484 return "?" + exprName((typeObj).child, opts);
17591485 case typeKinds.Pointer:
17601486 {
1761 let ptrObj = /** @type {PointerType} */(typeObj);
1487 let ptrObj = (typeObj);
17621488 let sentinel = ptrObj.sentinel ? ":"+exprName(ptrObj.sentinel, opts) : "";
17631489 let is_mutable = !ptrObj.is_mutable ? "const " : "";
17641490 let name = "";
......@@ -1844,7 +1570,7 @@ var zigAnalysis;
18441570 }
18451571 case typeKinds.Float:
18461572 {
1847 let floatObj = /** @type {NumberType} */ (typeObj);
1573 let floatObj = (typeObj);
18481574
18491575 if (opts.wantHtml) {
18501576 return '<span class="tok-type">' + floatObj.name + '</span>';
......@@ -1854,7 +1580,7 @@ var zigAnalysis;
18541580 }
18551581 case typeKinds.Int:
18561582 {
1857 let intObj = /** @type {NumberType} */(typeObj);
1583 let intObj = (typeObj);
18581584 let name = intObj.name;
18591585 if (opts.wantHtml) {
18601586 return '<span class="tok-type">' + name + '</span>';
......@@ -1906,7 +1632,7 @@ var zigAnalysis;
19061632 }
19071633 case typeKinds.ErrorSet:
19081634 {
1909 let errSetObj = /** @type {ErrSetType} */(typeObj);
1635 let errSetObj = (typeObj);
19101636 if (errSetObj.fields == null) {
19111637 return '<span class="tok-type">anyerror</span>';
19121638 } else {
......@@ -1918,14 +1644,14 @@ var zigAnalysis;
19181644
19191645 case typeKinds.ErrorUnion:
19201646 {
1921 let errUnionObj = /** @type {ErrUnionType} */(typeObj);
1647 let errUnionObj = (typeObj);
19221648 let lhs = exprName(errUnionObj.lhs, opts);
19231649 let rhs = exprName(errUnionObj.rhs, opts);
19241650 return lhs + "!" + rhs;
19251651 }
19261652 case typeKinds.Fn:
19271653 {
1928 let fnObj = /** @type {Fn} */(typeObj);
1654 let fnObj = (typeObj);
19291655 let payloadHtml = "";
19301656 if (opts.wantHtml) {
19311657 if (fnObj.is_extern) {
......@@ -2133,16 +1859,13 @@ var zigAnalysis;
21331859 }
21341860
21351861
2136 /**
2137 * @param {Expr} typeRef
2138 * @param {string} paramName
2139 */
1862
21401863 function shouldSkipParamName(typeRef, paramName) {
21411864 let resolvedTypeRef = resolveValue({expr: typeRef});
21421865 if ("type" in resolvedTypeRef) {
21431866 let typeObj = zigAnalysis.types[resolvedTypeRef.type];
21441867 if (typeObj.kind === typeKinds.Pointer){
2145 let ptrObj = /** @type {PointerType} */(typeObj);
1868 let ptrObj = (typeObj);
21461869 if (getPtrSize(ptrObj) === pointerSizeEnum.One) {
21471870 const value = resolveValue(ptrObj.child);
21481871 return typeValueName(value, false, true).toLowerCase() === paramName;
......@@ -2152,12 +1875,12 @@ var zigAnalysis;
21521875 return false;
21531876 }
21541877
2155 /** @param {PointerType} typeObj */
1878
21561879 function getPtrSize(typeObj) {
21571880 return (typeObj.size == null) ? pointerSizeEnum.One : typeObj.size;
21581881 }
21591882
2160 /** @param {Type} typeObj */
1883
21611884 function renderType(typeObj) {
21621885 let name;
21631886 if (rootIsStd && typeObj === zigAnalysis.types[zigAnalysis.packages[zigAnalysis.rootPkg].main]) {
......@@ -2170,11 +1893,11 @@ var zigAnalysis;
21701893 domHdrName.classList.remove("hidden");
21711894 }
21721895 if (typeObj.kind == typeKinds.ErrorSet) {
2173 renderErrorSet(/** @type {ErrSetType} */(typeObj));
1896 renderErrorSet((typeObj));
21741897 }
21751898 }
21761899
2177 /** @param {ErrSetType} errSetType */
1900
21781901 function renderErrorSet(errSetType) {
21791902 if (errSetType.fields == null) {
21801903 domFnErrorsAnyError.classList.remove("hidden");
......@@ -2278,7 +2001,7 @@ var zigAnalysis;
22782001
22792002
22802003
2281 /** @param {Decl} decl */
2004
22822005 function renderValue(decl) {
22832006 let resolvedValue = resolveValue(decl.value)
22842007
......@@ -2295,7 +2018,7 @@ var zigAnalysis;
22952018 domFnProto.classList.remove("hidden");
22962019 }
22972020
2298 /** @param {Decl} decl */
2021
22992022 function renderVar(decl) {
23002023 let declTypeRef = typeOfDecl(decl);
23012024 domFnProtoCode.innerHTML = '<span class="tok-kw">var</span> ' +
......@@ -2311,16 +2034,7 @@ var zigAnalysis;
23112034 }
23122035
23132036
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
23242038 function categorizeDecls(decls,
23252039 typesList, namespacesList, errSetsList,
23262040 fnsList, varsList, valsList, testsList) {
......@@ -2345,7 +2059,7 @@ var zigAnalysis;
23452059 const typeExpr = zigAnalysis.types[declValue.expr.type];
23462060 if (typeExpr.kind == typeKinds.Fn) {
23472061 const funcRetExpr = resolveValue({
2348 expr: /** @type {Fn} */(typeExpr).ret
2062 expr: (typeExpr).ret
23492063 });
23502064 if ("type" in funcRetExpr.expr && funcRetExpr.expr.type == typeTypeId) {
23512065 if (typeIsErrSet(declValue.expr.type)) {
......@@ -2381,23 +2095,21 @@ var zigAnalysis;
23812095 }
23822096 }
23832097
2384 /**
2385 * @param {ContainerType} container
2386 */
2098
23872099 function renderContainer(container) {
2388 /** @type {Decl[]} */
2100
23892101 let typesList = [];
2390 /** @type {Decl[]} */
2102
23912103 let namespacesList = [];
2392 /** @type {Decl[]} */
2104
23932105 let errSetsList = [];
2394 /** @type {Decl[]} */
2106
23952107 let fnsList = [];
2396 /** @type {Decl[]} */
2108
23972109 let varsList = [];
2398 /** @type {Decl[]} */
2110
23992111 let valsList = [];
2400 /** @type {Decl[]} */
2112
24012113 let testsList = [];
24022114
24032115 categorizeDecls(container.pubDecls,
......@@ -2497,7 +2209,7 @@ var zigAnalysis;
24972209 for (let i = 0; i < containerNode.fields.length; i += 1) {
24982210 let fieldNode = zigAnalysis.astNodes[containerNode.fields[i]];
24992211 let divDom = domListFields.children[i];
2500 let fieldName = /** @type {string} */(fieldNode.name);
2212 let fieldName = (fieldNode.name);
25012213
25022214 let html = '<div class="mobile-scroll-container"><pre class="scroll-item">' + escapeHtml(fieldName);
25032215
......@@ -2611,10 +2323,7 @@ var zigAnalysis;
26112323 }
26122324
26132325
2614 /**
2615 * @param {string | number} a
2616 * @param {string | number} b
2617 */
2326
26182327 function operatorCompare(a, b) {
26192328 if (a === b) {
26202329 return 0;
......@@ -2637,7 +2346,7 @@ var zigAnalysis;
26372346 }
26382347
26392348 function indexTypeKinds() {
2640 let map = /** @type {Record<string, number>} */({});
2349 let map = ({});
26412350 for (let i = 0; i < zigAnalysis.typeKinds.length; i += 1) {
26422351 map[zigAnalysis.typeKinds[i]] = i;
26432352 }
......@@ -2708,10 +2417,7 @@ var zigAnalysis;
27082417 }
27092418 }
27102419
2711 /**
2712 * @param {ContainerType} parentType
2713 * @param {string} childName
2714 */
2420
27152421 function findSubDecl(parentType, childName) {
27162422 {
27172423 // Generic functions
......@@ -2758,11 +2464,11 @@ var zigAnalysis;
27582464 let rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
27592465 // Breadth-first to keep the path shortest possible.
27602466 let stack = [{
2761 path: /** @type {string[]} */([]),
2467 path: ([]),
27622468 pkg: rootPkg,
27632469 }];
27642470 while (stack.length !== 0) {
2765 let item = /** @type {{path: string[], pkg: Package}} */(stack.shift());
2471 let item = (stack.shift());
27662472 for (let key in item.pkg.table) {
27672473 let childPkgIndex = item.pkg.table[key];
27682474 if (list[childPkgIndex] != null) continue;
......@@ -2781,7 +2487,7 @@ var zigAnalysis;
27812487 }
27822488
27832489
2784 /** @return {CanonDecl[]} */
2490
27852491 function computeCanonDeclPaths() {
27862492 let list = new Array(zigAnalysis.decls.length);
27872493 canonTypeDecls = new Array(zigAnalysis.types.length);
......@@ -2791,14 +2497,14 @@ var zigAnalysis;
27912497 let pkg = zigAnalysis.packages[pkgI];
27922498 let pkgNames = canonPkgPaths[pkgI];
27932499 let stack = [{
2794 declNames: /** @type {string[]} */([]),
2500 declNames: ([]),
27952501 type: zigAnalysis.types[pkg.main],
27962502 }];
27972503 while (stack.length !== 0) {
2798 let item = /** @type {{declNames: string[], type: Type}} */(stack.shift());
2504 let item = (stack.shift());
27992505
28002506 if (isContainerType(item.type)) {
2801 let t = /** @type {ContainerType} */(item.type);
2507 let t = (item.type);
28022508
28032509 let len = t.pubDecls ? t.pubDecls.length : 0;
28042510 for (let declI = 0; declI < len; declI += 1) {
......@@ -2833,48 +2539,40 @@ var zigAnalysis;
28332539 return list;
28342540 }
28352541
2836 /** @param {number} index */
2542
28372543 function getCanonDeclPath(index) {
28382544 if (canonDeclPaths == null) {
28392545 canonDeclPaths = computeCanonDeclPaths();
28402546 }
2841 //let cd = /** @type {CanonDecl[]}*/(canonDeclPaths);
2547 //let cd = (canonDeclPaths);
28422548 return canonDeclPaths[index];
28432549 }
28442550
2845 /** @param {number} index */
2551
28462552 function getCanonTypeDecl(index) {
28472553 getCanonDeclPath(0);
2848 //let ct = /** @type {number[]}*/(canonTypeDecls);
2554 //let ct = (canonTypeDecls);
28492555 return canonTypeDecls[index];
28502556 }
28512557
2852 /** @param {string} text */
2558
28532559 function escapeHtml(text) {
28542560 return text.replace(/[&"<>]/g, function (m) {
28552561 return escapeHtmlReplacements[m];
28562562 });
28572563 }
28582564
2859 /** @param {string} docs */
2565
28602566 function shortDescMarkdown(docs) {
28612567 let parts = docs.trim().split("\n");
28622568 let firstLine = parts[0];
28632569 return markdown(firstLine);
28642570 }
28652571
2866 /** @param {string} input */
2572
28672573 function markdown(input) {
28682574 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
28782576 const lines = [];
28792577
28802578 // PHASE 1:
......@@ -2928,7 +2626,7 @@ var zigAnalysis;
29282626 line.text = line.text.substr(1);
29292627 }
29302628 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+)\./));
29322630 line.type = "ul";
29332631 line.text = line.text.substr(match[0].length);
29342632 line.ordered_number = Number(match[1].length);
......@@ -2961,9 +2659,7 @@ var zigAnalysis;
29612659 // Render HTML from markdown lines.
29622660 // Look at each line and emit fitting HTML code
29632661
2964 /**
2965 * @param {string } innerText
2966 */
2662
29672663 function markdownInlines(innerText) {
29682664
29692665 // inline types:
......@@ -2977,8 +2673,8 @@ var zigAnalysis;
29772673 // ![{TEXT}]({URL}) : <img>
29782674 // [[std;format.fmt]] : <a> (inner link)
29792675
2980 /** @typedef {{marker: string, tag: string}} Fmt*/
2981 /** @type {Array<Fmt>} */
2676
2677
29822678 const formats = [
29832679 {
29842680 marker: "**",
......@@ -2998,7 +2694,7 @@ var zigAnalysis;
29982694 }
29992695 ];
30002696
3001 /** @type {Array<Fmt>} */
2697
30022698 const stack = [];
30032699
30042700 let innerHTML = "";
......@@ -3050,7 +2746,7 @@ var zigAnalysis;
30502746 in_code = true;
30512747 } else {
30522748 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++) {
30542750 const fmt = idx >= 0 ? formats[idx] : stack[stack.length - 1];
30552751 if (innerText.substr(i, fmt.marker.length) == fmt.marker) {
30562752 flushRun();
......@@ -3074,17 +2770,14 @@ var zigAnalysis;
30742770 flushRun();
30752771
30762772 while (stack.length > 0) {
3077 const fmt = /** @type {Fmt} */(stack.pop());
2773 const fmt = (stack.pop());
30782774 innerHTML += "</" + fmt.tag + ">";
30792775 }
30802776
30812777 return innerHTML;
30822778 }
30832779
3084 /**
3085 * @param {string} type
3086 * @param {number} line_no
3087 */
2780
30882781 function previousLineIs(type, line_no) {
30892782 if (line_no > 0) {
30902783 return (lines[line_no - 1].type == type);
......@@ -3093,10 +2786,7 @@ var zigAnalysis;
30932786 }
30942787 }
30952788
3096 /**
3097 * @param {string} type
3098 * @param {number} line_no
3099 */
2789
31002790 function nextLineIs(type, line_no) {
31012791 if (line_no < (lines.length - 1)) {
31022792 return (lines[line_no + 1].type == type);
......@@ -3105,7 +2795,7 @@ var zigAnalysis;
31052795 }
31062796 }
31072797
3108 /** @param {number} line_no */
2798
31092799 function getPreviousLineIndent(line_no) {
31102800 if (line_no > 0) {
31112801 return lines[line_no - 1].indent;
......@@ -3114,7 +2804,7 @@ var zigAnalysis;
31142804 }
31152805 }
31162806
3117 /** @param {number} line_no */
2807
31182808 function getNextLineIndent(line_no) {
31192809 if (line_no < (lines.length - 1)) {
31202810 return lines[line_no + 1].indent;
......@@ -3188,13 +2878,13 @@ var zigAnalysis;
31882878 }
31892879 if (liDom != null) {
31902880 let aDom = liDom.children[0];
3191 location.href = /** @type {string} */(aDom.getAttribute("href"));
2881 location.href = (aDom.getAttribute("href"));
31922882 curSearchIndex = -1;
31932883 }
31942884 domSearch.blur();
31952885 }
31962886
3197 /** @param {KeyboardEvent} ev */
2887
31982888 function onSearchKeyDown(ev) {
31992889 switch (getKeyString(ev)) {
32002890 case "Enter":
......@@ -3239,7 +2929,7 @@ var zigAnalysis;
32392929 }
32402930
32412931
3242 /** @param {number} dir */
2932
32432933 function moveSearchCursor(dir) {
32442934 if (curSearchIndex < 0 || curSearchIndex >= domListSearchResults.children.length) {
32452935 if (dir > 0) {
......@@ -3259,7 +2949,7 @@ var zigAnalysis;
32592949 renderSearchCursor();
32602950 }
32612951
3262 /** @param {KeyboardEvent} ev */
2952
32632953 function getKeyString(ev) {
32642954 let name;
32652955 let ignoreShift = false;
......@@ -3286,7 +2976,7 @@ var zigAnalysis;
32862976 return name;
32872977 }
32882978
3289 /** @param {KeyboardEvent} ev */
2979
32902980 function onWindowKeyDown(ev) {
32912981 switch (getKeyString(ev)) {
32922982 case "Esc":
......@@ -3427,7 +3117,7 @@ function renderSearch() {
34273117
34283118function renderSearchCursor() {
34293119 for (let i = 0; i < domListSearchResults.children.length; i += 1) {
3430 let liDom = /** @type HTMLElement */(domListSearchResults.children[i]);
3120 let liDom = (domListSearchResults.children[i]);
34313121 if (curSearchIndex === i) {
34323122 liDom.classList.add("selected");
34333123 } else {
......@@ -3453,10 +3143,7 @@ function renderSearchCursor() {
34533143// }
34543144
34553145
3456/**
3457* @param {{ name: string }} a
3458* @param {{ name: string }} b
3459*/
3146
34603147function byNameProperty(a, b) {
34613148 return operatorCompare(a.name, b.name);
34623149}