| ... | ... | @@ -32,18 +32,6 @@ |
| 32 | 32 | } TypeKind |
| 33 | 33 | */ |
| 34 | 34 | |
| 35 | | /** |
| 36 | | * @typedef { |
| 37 | | | WalkResult |
| 38 | | | { unspecified: {} } |
| 39 | | | { anytype: {} } |
| 40 | | | { type: number } |
| 41 | | | { comptimeExpr: number } |
| 42 | | | { call: number } |
| 43 | | | { hasCte: boolean; declPath: number[] } |
| 44 | | } TypeRef |
| 45 | | */ |
| 46 | | |
| 47 | 35 | /** |
| 48 | 36 | * @typedef { |
| 49 | 37 | | { void: {} } |
| ... | ... | @@ -52,16 +40,16 @@ |
| 52 | 40 | | { type: number } |
| 53 | 41 | | { comptimeExpr: number } |
| 54 | 42 | | { call: number } |
| 55 | | | { int: { typeRef: TypeRef; value: number } } |
| 56 | | | { float: { typeRef: TypeRef; value: number } } |
| 43 | | { int: { typeRef: WalkResult; value: number } } |
| 44 | | { float: { typeRef: WalkResult; value: number } } |
| 57 | 45 | | { bool: boolean } |
| 58 | | | { undefined: TypeRef } |
| 59 | | | { null: TypeRef } |
| 46 | | { undefined: WalkResult } |
| 47 | | { null: WalkResult } |
| 60 | 48 | | { typeOf: WalkResult } |
| 61 | 49 | | { compileError: string } |
| 62 | 50 | | { string: string } |
| 63 | 51 | | { struct: Struct } |
| 64 | | | { hasCte: boolean; declPath: number[] } |
| 52 | | { refPath: WalkResult[] } |
| 65 | 53 | | { array: ZigArray } |
| 66 | 54 | | { enumLiteral: string } |
| 67 | 55 | } WalkResult |
| ... | ... | @@ -75,8 +63,8 @@ |
| 75 | 63 | | { len: WalkResult; child: TypeRef } // Array |
| 76 | 64 | | { name: string; fields: { name: string; docs: string }[] } // ErrorSet |
| 77 | 65 | | { size: "One" | "Many" | "Slice" | "C"; child: TypeRef } // Pointer |
| 78 | | | { name: string; src?: number; privDecls: number[]; pubDecls: number[]; fields?: TypeRef[] } // Struct, Enum, Union |
| 79 | | | { name: string; src?: number; ret: TypeRef; params?: TypeRef[] } // Fn |
| 66 | | { name: string; src: number; privDecls: number[]; pubDecls: number[]; fields: WalkResult[] } // Struct, Enum, Union |
| 67 | | { name: string; src: number; ret: WalkResult; params: WalkResult[] } // Fn |
| 80 | 68 | ) |
| 81 | 69 | } Type |
| 82 | 70 | */ |
| ... | ... | @@ -85,14 +73,14 @@ |
| 85 | 73 | * @typedef {{ |
| 86 | 74 | name: string, |
| 87 | 75 | src: number | null, |
| 88 | | ret: TypeRef, |
| 89 | | params: TypeRef[] | null, |
| 76 | ret: WalkResult, |
| 77 | params: WalkResult[] | null, |
| 90 | 78 | }} Fn |
| 91 | 79 | */ |
| 92 | 80 | |
| 93 | 81 | /** |
| 94 | 82 | * @typedef {{ |
| 95 | | func: TypeRef, |
| 83 | func: WalkResult, |
| 96 | 84 | args: WalkResult[], |
| 97 | 85 | ret: WalkResult, |
| 98 | 86 | }} Call |
| ... | ... | @@ -135,21 +123,21 @@ |
| 135 | 123 | src?: number, |
| 136 | 124 | privDecls: number[], |
| 137 | 125 | pubDecls: number[], |
| 138 | | fields?: TypeRef[], |
| 126 | fields?: WalkResult[], |
| 139 | 127 | }} Struct |
| 140 | 128 | */ |
| 141 | 129 | |
| 142 | 130 | /** |
| 143 | 131 | * @typedef {{ |
| 144 | 132 | len: WalkResult, |
| 145 | | child: TypeRef, |
| 133 | child: WalkResult, |
| 146 | 134 | }} ZigArray |
| 147 | 135 | */ |
| 148 | 136 | |
| 149 | 137 | /** |
| 150 | 138 | * @typedef {{ |
| 151 | 139 | code: string, |
| 152 | | typeRef: TypeRef, |
| 140 | typeRef: WalkResult, |
| 153 | 141 | }} ComptimeExpr |
| 154 | 142 | */ |
| 155 | 143 | |
| ... | ... | @@ -219,6 +207,7 @@ var zigAnalysis; |
| 219 | 207 | var domSectSearchNoResults = document.getElementById("sectSearchNoResults"); |
| 220 | 208 | var domSectInfo = document.getElementById("sectInfo"); |
| 221 | 209 | var domTdTarget = document.getElementById("tdTarget"); |
| 210 | var domPrivDeclsBox = document.getElementById("privDeclsBox"); |
| 222 | 211 | var domTdZigVer = document.getElementById("tdZigVer"); |
| 223 | 212 | var domHdrName = document.getElementById("hdrName"); |
| 224 | 213 | var domHelpModal = document.getElementById("helpDialog"); |
| ... | ... | @@ -238,6 +227,7 @@ var zigAnalysis; |
| 238 | 227 | var canonTypeDecls = null; // lazy; use getCanonTypeDecl |
| 239 | 228 | |
| 240 | 229 | var curNav = { |
| 230 | showPrivDecls: false, |
| 241 | 231 | // each element is a package name, e.g. @import("a") then within there @import("b") |
| 242 | 232 | // starting implicitly from root package |
| 243 | 233 | pkgNames: [], |
| ... | ... | @@ -264,6 +254,18 @@ var zigAnalysis; |
| 264 | 254 | // var nodesToCallsMap = indexNodesToCalls(); |
| 265 | 255 | |
| 266 | 256 | domSearch.addEventListener('keydown', onSearchKeyDown, false); |
| 257 | domPrivDeclsBox.addEventListener('change', function() { |
| 258 | if (this.checked != curNav.showPrivDecls) { |
| 259 | if (this.checked && location.hash.length > 1 && location.hash[1] != '*'){ |
| 260 | location.hash = "#*" + location.hash.substring(1); |
| 261 | return; |
| 262 | } |
| 263 | if (!this.checked && location.hash.length > 1 && location.hash[1] == '*') { |
| 264 | location.hash = "#" + location.hash.substring(2); |
| 265 | return; |
| 266 | } |
| 267 | } |
| 268 | }, false); |
| 267 | 269 | window.addEventListener('hashchange', onHashChange, false); |
| 268 | 270 | window.addEventListener('keydown', onWindowKeyDown, false); |
| 269 | 271 | onHashChange(); |
| ... | ... | @@ -323,19 +325,13 @@ var zigAnalysis; |
| 323 | 325 | return typeKind === typeKinds.ErrorSet || typeKindIsContainer(typeKind); |
| 324 | 326 | } |
| 325 | 327 | |
| 326 | | function findCteInDeclPath(path) { |
| 328 | function findCteInRefPath(path) { |
| 327 | 329 | for (var i = path.length - 1; i >= 0; i -= 1) { |
| 328 | | const decl = zigAnalysis.decls[path[i]]; |
| 329 | | if ("comptimeExpr" in decl.value) { |
| 330 | | return decl; |
| 331 | | } |
| 332 | | |
| 333 | | if ("declPath" in decl.value) { |
| 334 | | const res = findCteInDeclPath(decl.value.declPath); |
| 335 | | if (res !== null) { |
| 336 | | return res; |
| 337 | | } |
| 338 | | } |
| 330 | const ref = path[i]; |
| 331 | if ("string" in ref) continue; |
| 332 | if ("comptimeExpr" in ref) return ref; |
| 333 | if ("refPath" in ref) return findCteinRefPath(ref.refPath); |
| 334 | return null; |
| 339 | 335 | } |
| 340 | 336 | |
| 341 | 337 | return null; |
| ... | ... | @@ -346,14 +342,15 @@ var zigAnalysis; |
| 346 | 342 | while(i < 1000) { |
| 347 | 343 | i += 1; |
| 348 | 344 | |
| 349 | | if ("declPath" in value) { |
| 350 | | if (value.hasCte) { |
| 351 | | return findCteInDeclPath(value.declPath).value; |
| 352 | | } |
| 353 | | value = zigAnalysis.decls[value.declPath[0]].value; |
| 345 | if ("refPath" in value) { |
| 346 | value = value.refPath[value.refPath.length -1]; |
| 354 | 347 | continue; |
| 355 | 348 | } |
| 356 | 349 | |
| 350 | if ("declRef" in value) { |
| 351 | value = zigAnalysis.decls[value.declRef].value; |
| 352 | } |
| 353 | |
| 357 | 354 | return value; |
| 358 | 355 | |
| 359 | 356 | } |
| ... | ... | @@ -369,13 +366,15 @@ var zigAnalysis; |
| 369 | 366 | return { type: typeTypeId }; |
| 370 | 367 | } |
| 371 | 368 | |
| 372 | | if ("declPath" in decl.value) { |
| 373 | | if (decl.value.hasCte) { |
| 374 | | decl = findCteInDeclPath(decl.value.declPath); |
| 375 | | } else { |
| 376 | | decl = zigAnalysis.decls[decl.value.declPath[0]]; |
| 377 | | } |
| 369 | if ("refPath" in decl.value) { |
| 370 | decl = { |
| 371 | value: decl.value.refPath[decl.value.refPath.length -1] |
| 372 | }; |
| 373 | continue; |
| 374 | } |
| 378 | 375 | |
| 376 | if ("declRef" in decl.value) { |
| 377 | decl = zigAnalysis.decls[decl.value.declRef]; |
| 379 | 378 | continue; |
| 380 | 379 | } |
| 381 | 380 | |
| ... | ... | @@ -402,8 +401,14 @@ var zigAnalysis; |
| 402 | 401 | |
| 403 | 402 | if ("call" in decl.value) { |
| 404 | 403 | const fn_call = zigAnalysis.calls[decl.value.call]; |
| 405 | | console.assert("declPath" in fn_call.func); |
| 406 | | const fn_decl = zigAnalysis.decls[fn_call.func.declPath[0]]; |
| 404 | var fn_decl = undefined; |
| 405 | if ("declRef" in fn_call.func) { |
| 406 | fn_decl = zigAnalysis.decls[fn_call.func.declRef]; |
| 407 | } else if ("refPath" in fn_call.func) { |
| 408 | console.assert("declRef" in fn_call.func.refPath[fn_call.func.refPath.length -1]); |
| 409 | fn_decl = zigAnalysis.decls[fn_call.func.refPath[fn_call.func.refPath.length -1].declRef.value]; |
| 410 | } else throw {}; |
| 411 | |
| 407 | 412 | const fn_decl_value = resolveValue(fn_decl.value); |
| 408 | 413 | console.assert("type" in fn_decl_value); //TODO handle comptimeExpr |
| 409 | 414 | const fn_type = zigAnalysis.types[fn_decl_value.type]; |
| ... | ... | @@ -456,6 +461,8 @@ var zigAnalysis; |
| 456 | 461 | renderInfo(); |
| 457 | 462 | renderPkgList(); |
| 458 | 463 | |
| 464 | domPrivDeclsBox.checked = curNav.showPrivDecls; |
| 465 | |
| 459 | 466 | if (curNavSearch !== "") { |
| 460 | 467 | return renderSearch(); |
| 461 | 468 | } |
| ... | ... | @@ -547,7 +554,7 @@ var zigAnalysis; |
| 547 | 554 | var typeObj = zigAnalysis.types[typeIndex]; |
| 548 | 555 | if (typeObj.kind !== typeKinds.Struct) |
| 549 | 556 | return false; |
| 550 | | return !typeObj.fields; |
| 557 | return typeObj.fields.length == 0; |
| 551 | 558 | } |
| 552 | 559 | |
| 553 | 560 | function typeIsGenericFn(typeIndex) { |
| ... | ... | @@ -850,22 +857,14 @@ var zigAnalysis; |
| 850 | 857 | if ("comptimeExpr" in typeValue) { |
| 851 | 858 | return "[ComptimeExpr]"; |
| 852 | 859 | } |
| 853 | | if ("declPath" in typeValue) { |
| 860 | if ("refPath" in typeValue) { |
| 854 | 861 | var result = ""; |
| 855 | | for (var j = typeValue.declPath.length - 1; j >= 0; j--) { |
| 856 | | var decl = zigAnalysis.decls[typeValue.declPath[j]]; |
| 857 | | |
| 858 | | // TODO: handle nested decl paths properly! |
| 859 | | if (typeValue.hasCte) { |
| 860 | | if (wantHtml) |
| 861 | | result += "<a href=\"\">[ComptimeExpr]</a>"; |
| 862 | | else |
| 863 | | result += "[ComptimeExpr]"; |
| 864 | | break; |
| 865 | | } |
| 866 | | var name = escapeHtml(decl.name); |
| 862 | for (var j = 0; j < typeValue.refPath.length; j++) { |
| 863 | |
| 864 | var name = "[RefPath]"; |
| 867 | 865 | if (wantHtml) { |
| 868 | | result += '<a href="'+navLinkDecl(decl.name)+'">'; |
| 866 | //result += '<a href="'+navLinkDecl(decl.name)+'">'; |
| 867 | result += '<a href="">'; |
| 869 | 868 | result += '<span class="tok-kw" style="color:lightblue;">' + |
| 870 | 869 | name + '</span>'; |
| 871 | 870 | result += '</a>'; |
| ... | ... | @@ -1182,24 +1181,11 @@ var zigAnalysis; |
| 1182 | 1181 | |
| 1183 | 1182 | if (isVarArgs && i === typeObj.params.length - 1) { |
| 1184 | 1183 | payloadHtml += '...'; |
| 1185 | | } else if ("declPath" in value) { |
| 1186 | | if (value.hasCte) { |
| 1187 | | var cte = findCteInDeclPath(value.declPath); |
| 1188 | | payloadHtml += "[ComptimeExpr]"; |
| 1189 | | } else { |
| 1190 | | var decl = zigAnalysis.decls[value.declPath[0]]; |
| 1191 | | var val = resolveValue(decl.value); |
| 1192 | | if ("comptimeExpr" in val) { |
| 1193 | | payloadHtml += "[ComptimeExpr]"; |
| 1194 | | } else { |
| 1195 | | console.assert("type" in val); |
| 1196 | | var valType = zigAnalysis.types[val.type]; |
| 1197 | | var valTypeName = typeShorthandName(valType); |
| 1198 | | payloadHtml += '<a href="'+navLinkDecl(decl.name)+'">'; |
| 1199 | | payloadHtml += '<span class="tok-kw" style="color:lightblue;">' + escapeHtml(decl.name) + '</span>'; |
| 1200 | | payloadHtml += '</a>'; |
| 1201 | | } |
| 1202 | | } |
| 1184 | } else if ("refPath" in value) { |
| 1185 | payloadHtml += '<a href="">'; |
| 1186 | payloadHtml += '<span class="tok-kw" style="color:lightblue;">[Ref Path]</span>'; |
| 1187 | payloadHtml += '</a>'; |
| 1188 | |
| 1203 | 1189 | } else if ("type" in value) { |
| 1204 | 1190 | var name = typeValueName(value, false); |
| 1205 | 1191 | payloadHtml += '<span class="tok-kw">' + escapeHtml(name) + '</span>'; |
| ... | ... | @@ -1422,17 +1408,13 @@ var zigAnalysis; |
| 1422 | 1408 | domFnProto.classList.remove("hidden"); |
| 1423 | 1409 | } |
| 1424 | 1410 | |
| 1425 | | function renderContainer(container) { |
| 1426 | | var typesList = []; |
| 1427 | | var namespacesList = []; |
| 1428 | | var errSetsList = []; |
| 1429 | | var fnsList = []; |
| 1430 | | var varsList = []; |
| 1431 | | var valsList = []; |
| 1432 | 1411 | |
| 1433 | | var declLen = container.pubDecls ? container.pubDecls.length : 0; |
| 1434 | | for (var i = 0; i < declLen; i += 1) { |
| 1435 | | var decl = zigAnalysis.decls[container.pubDecls[i]]; |
| 1412 | function categorizeDecls(decls, |
| 1413 | typesList, namespacesList, errSetsList, |
| 1414 | fnsList, varsList, valsList) { |
| 1415 | |
| 1416 | for (var i = 0; i < decls.length; i += 1) { |
| 1417 | var decl = zigAnalysis.decls[decls[i]]; |
| 1436 | 1418 | var declValue = resolveValue(decl.value); |
| 1437 | 1419 | |
| 1438 | 1420 | if (decl.kind === 'var') { |
| ... | ... | @@ -1441,7 +1423,19 @@ var zigAnalysis; |
| 1441 | 1423 | } |
| 1442 | 1424 | |
| 1443 | 1425 | if (decl.kind === 'const') { |
| 1444 | | if (!("type" in declValue)){ |
| 1426 | if ("call" in declValue) { |
| 1427 | let c = zigAnalysis.calls[declValue.call]; |
| 1428 | console.assert("comptimeExpr" in c.ret); |
| 1429 | let fDecl = resolveValue(c.func); |
| 1430 | console.assert("type" in fDecl); |
| 1431 | let fType = zigAnalysis.types[fDecl.type]; |
| 1432 | console.assert("type" in fType.ret); |
| 1433 | if (fType.ret.type === typeTypeId) { |
| 1434 | typesList.push(decl); |
| 1435 | } else { |
| 1436 | valsList.push(decl); |
| 1437 | } |
| 1438 | } else if (!("type" in declValue)){ |
| 1445 | 1439 | valsList.push(decl); |
| 1446 | 1440 | } else { |
| 1447 | 1441 | var value = zigAnalysis.types[declValue.type]; |
| ... | ... | @@ -1465,42 +1459,23 @@ var zigAnalysis; |
| 1465 | 1459 | } |
| 1466 | 1460 | } |
| 1467 | 1461 | } |
| 1462 | } |
| 1468 | 1463 | |
| 1469 | | declLen = container.privDecls ? container.privDecls.length : 0; |
| 1470 | | for (var i = 0; i < declLen; i += 1) { |
| 1471 | | var decl = zigAnalysis.decls[container.privDecls[i]]; |
| 1472 | | var declValue = resolveValue(decl.value); |
| 1473 | | |
| 1474 | | if (decl.kind === 'var') { |
| 1475 | | varsList.push(decl); |
| 1476 | | continue; |
| 1477 | | } |
| 1464 | function renderContainer(container) { |
| 1465 | var typesList = []; |
| 1466 | var namespacesList = []; |
| 1467 | var errSetsList = []; |
| 1468 | var fnsList = []; |
| 1469 | var varsList = []; |
| 1470 | var valsList = []; |
| 1478 | 1471 | |
| 1479 | | if (decl.kind === 'const') { |
| 1480 | | if (!("type" in declValue)){ |
| 1481 | | valsList.push(decl); |
| 1482 | | } else { |
| 1483 | | var value = zigAnalysis.types[declValue.type]; |
| 1484 | | var kind = value.kind; |
| 1485 | | if (kind === typeKinds.Fn) { |
| 1486 | | // TODO: handle CTE return types when we know their type. |
| 1487 | | const resVal = resolveValue(value.ret); |
| 1488 | | if ("type" in resVal && resVal.type == typeTypeId) { |
| 1489 | | typesList.push(decl); |
| 1490 | | } else { |
| 1491 | | fnsList.push(decl); |
| 1492 | | } |
| 1472 | categorizeDecls(container.pubDecls, |
| 1473 | typesList, namespacesList, errSetsList, |
| 1474 | fnsList, varsList, valsList); |
| 1475 | if (curNav.showPrivDecls) categorizeDecls(container.privDecls, |
| 1476 | typesList, namespacesList, errSetsList, |
| 1477 | fnsList, varsList, valsList); |
| 1493 | 1478 | |
| 1494 | | } else if (typeIsErrSet(declValue.type)) { |
| 1495 | | errSetsList.push(decl); |
| 1496 | | } else if (typeIsStructWithNoFields(declValue.type)) { |
| 1497 | | namespacesList.push(decl); |
| 1498 | | } else { |
| 1499 | | typesList.push(decl); |
| 1500 | | } |
| 1501 | | } |
| 1502 | | } |
| 1503 | | } |
| 1504 | 1479 | |
| 1505 | 1480 | typesList.sort(byNameProperty); |
| 1506 | 1481 | namespacesList.sort(byNameProperty); |
| ... | ... | @@ -1712,6 +1687,7 @@ var zigAnalysis; |
| 1712 | 1687 | |
| 1713 | 1688 | function updateCurNav() { |
| 1714 | 1689 | curNav = { |
| 1690 | showPrivDecls: false, |
| 1715 | 1691 | pkgNames: [], |
| 1716 | 1692 | pkgObjs: [], |
| 1717 | 1693 | declNames: [], |
| ... | ... | @@ -1721,6 +1697,11 @@ var zigAnalysis; |
| 1721 | 1697 | |
| 1722 | 1698 | if (location.hash[0] === '#' && location.hash.length > 1) { |
| 1723 | 1699 | var query = location.hash.substring(1); |
| 1700 | if (query[0] === '*') { |
| 1701 | curNav.showPrivDecls = true; |
| 1702 | query = query.substring(1); |
| 1703 | } |
| 1704 | |
| 1724 | 1705 | var qpos = query.indexOf("?"); |
| 1725 | 1706 | var nonSearchPart; |
| 1726 | 1707 | if (qpos === -1) { |