| ... | @@ -7,7 +7,7 @@ const NAV_MODES = { | ... | @@ -7,7 +7,7 @@ const NAV_MODES = { |
| 7 | GUIDES: "#G;", | 7 | GUIDES: "#G;", |
| 8 | }; | 8 | }; |
| 9 | | 9 | |
| 10 | (function () { | 10 | (function() { |
| 11 | const domBanner = document.getElementById("banner"); | 11 | const domBanner = document.getElementById("banner"); |
| 12 | const domMain = document.getElementById("main"); | 12 | const domMain = document.getElementById("main"); |
| 13 | const domStatus = document.getElementById("status"); | 13 | const domStatus = document.getElementById("status"); |
| ... | @@ -59,7 +59,7 @@ const NAV_MODES = { | ... | @@ -59,7 +59,7 @@ const NAV_MODES = { |
| 59 | const domDocs = document.getElementById("docs"); | 59 | const domDocs = document.getElementById("docs"); |
| 60 | const domGuidesSection = document.getElementById("guides"); | 60 | const domGuidesSection = document.getElementById("guides"); |
| 61 | const domActiveGuide = document.getElementById("activeGuide"); | 61 | const domActiveGuide = document.getElementById("activeGuide"); |
| 62 | | 62 | |
| 63 | const domListSearchResults = document.getElementById("listSearchResults"); | 63 | const domListSearchResults = document.getElementById("listSearchResults"); |
| 64 | const domSectSearchNoResults = document.getElementById("sectSearchNoResults"); | 64 | const domSectSearchNoResults = document.getElementById("sectSearchNoResults"); |
| 65 | const domSectInfo = document.getElementById("sectInfo"); | 65 | const domSectInfo = document.getElementById("sectInfo"); |
| ... | @@ -133,7 +133,7 @@ const NAV_MODES = { | ... | @@ -133,7 +133,7 @@ const NAV_MODES = { |
| 133 | // map of decl index to list of comptime fn calls | 133 | // map of decl index to list of comptime fn calls |
| 134 | // let nodesToCallsMap = indexNodesToCalls(); | 134 | // let nodesToCallsMap = indexNodesToCalls(); |
| 135 | | 135 | |
| 136 | let guidesSearchIndex = {}; | 136 | let guidesSearchIndex = {}; |
| 137 | window.guideSearch = guidesSearchIndex; | 137 | window.guideSearch = guidesSearchIndex; |
| 138 | parseGuides(); | 138 | parseGuides(); |
| 139 | | 139 | |
| ... | @@ -248,7 +248,7 @@ const NAV_MODES = { | ... | @@ -248,7 +248,7 @@ const NAV_MODES = { |
| 248 | } else if (type.kind === typeKinds.Union) { | 248 | } else if (type.kind === typeKinds.Union) { |
| 249 | name = "union"; | 249 | name = "union"; |
| 250 | } else { | 250 | } else { |
| 251 | console.log("TODO: unhalndled case in typeShortName"); | 251 | console.log("TODO: unhandled case in typeShortName"); |
| 252 | return null; | 252 | return null; |
| 253 | } | 253 | } |
| 254 | | 254 | |
| ... | @@ -313,8 +313,8 @@ const NAV_MODES = { | ... | @@ -313,8 +313,8 @@ const NAV_MODES = { |
| 313 | | 313 | |
| 314 | function resolveGenericRet(genericFunc) { | 314 | function resolveGenericRet(genericFunc) { |
| 315 | if (genericFunc.generic_ret == null) return null; | 315 | if (genericFunc.generic_ret == null) return null; |
| 316 | let result = resolveValue({expr: genericFunc.generic_ret}); | 316 | let result = resolveValue({ expr: genericFunc.generic_ret }); |
| 317 | | 317 | |
| 318 | let i = 0; | 318 | let i = 0; |
| 319 | while (true) { | 319 | while (true) { |
| 320 | i += 1; | 320 | i += 1; |
| ... | @@ -437,32 +437,32 @@ const NAV_MODES = { | ... | @@ -437,32 +437,32 @@ const NAV_MODES = { |
| 437 | const section_list = zigAnalysis.guide_sections; | 437 | const section_list = zigAnalysis.guide_sections; |
| 438 | resizeDomList(domGuidesList, section_list.length, '<div><h2><span></span></h2><ul class="modules"></ul></div>'); | 438 | resizeDomList(domGuidesList, section_list.length, '<div><h2><span></span></h2><ul class="modules"></ul></div>'); |
| 439 | for (let j = 0; j < section_list.length; j += 1) { | 439 | for (let j = 0; j < section_list.length; j += 1) { |
| 440 | const section = section_list[j]; | 440 | const section = section_list[j]; |
| 441 | const domSectionName = domGuidesList.children[j].children[0].children[0]; | 441 | const domSectionName = domGuidesList.children[j].children[0].children[0]; |
| 442 | const domGuides = domGuidesList.children[j].children[1]; | 442 | const domGuides = domGuidesList.children[j].children[1]; |
| 443 | domSectionName.textContent = section.name; | 443 | domSectionName.textContent = section.name; |
| 444 | resizeDomList(domGuides, section.guides.length, '<li><a href="#"></a></li>'); | 444 | resizeDomList(domGuides, section.guides.length, '<li><a href="#"></a></li>'); |
| 445 | for (let i = 0; i < section.guides.length; i += 1) { | 445 | for (let i = 0; i < section.guides.length; i += 1) { |
| 446 | const guide = section.guides[i]; | 446 | const guide = section.guides[i]; |
| 447 | let liDom = domGuides.children[i]; | 447 | let liDom = domGuides.children[i]; |
| 448 | let aDom = liDom.children[0]; | 448 | let aDom = liDom.children[0]; |
| 449 | aDom.textContent = guide.title; | 449 | aDom.textContent = guide.title; |
| 450 | aDom.setAttribute("href", NAV_MODES.GUIDES + guide.name); | 450 | aDom.setAttribute("href", NAV_MODES.GUIDES + guide.name); |
| 451 | if (guide.name === curNav.activeGuide) { | 451 | if (guide.name === curNav.activeGuide) { |
| 452 | aDom.classList.add("active"); | 452 | aDom.classList.add("active"); |
| 453 | } else { | 453 | } else { |
| 454 | aDom.classList.remove("active"); | 454 | aDom.classList.remove("active"); |
| 455 | } | | |
| 456 | } | 455 | } |
| | 456 | } |
| 457 | } | 457 | } |
| 458 | | 458 | |
| 459 | if (section_list.length > 0) { | 459 | if (section_list.length > 0) { |
| 460 | domGuidesMenu.classList.remove("hidden"); | 460 | domGuidesMenu.classList.remove("hidden"); |
| 461 | } | 461 | } |
| 462 | | 462 | |
| 463 | | 463 | |
| 464 | if (curNavSearch !== "") { | 464 | if (curNavSearch !== "") { |
| 465 | return renderSearchGuides(); | 465 | return renderSearchGuides(); |
| 466 | } | 466 | } |
| 467 | | 467 | |
| 468 | // main content | 468 | // main content |
| ... | @@ -476,8 +476,8 @@ const NAV_MODES = { | ... | @@ -476,8 +476,8 @@ const NAV_MODES = { |
| 476 | break outer; | 476 | break outer; |
| 477 | } | 477 | } |
| 478 | } | 478 | } |
| 479 | } | 479 | } |
| 480 | | 480 | |
| 481 | if (activeGuide == undefined) { | 481 | if (activeGuide == undefined) { |
| 482 | const root_file_idx = zigAnalysis.modules[zigAnalysis.rootMod].file; | 482 | const root_file_idx = zigAnalysis.modules[zigAnalysis.rootMod].file; |
| 483 | const root_file_name = getFile(root_file_idx).name; | 483 | const root_file_name = getFile(root_file_idx).name; |
| ... | @@ -564,7 +564,7 @@ Happy writing! | ... | @@ -564,7 +564,7 @@ Happy writing! |
| 564 | renderModList(); | 564 | renderModList(); |
| 565 | | 565 | |
| 566 | if (curNavSearch !== "") { | 566 | if (curNavSearch !== "") { |
| 567 | return renderSearchAPI(); | 567 | return renderSearchAPI(); |
| 568 | } | 568 | } |
| 569 | | 569 | |
| 570 | let rootMod = zigAnalysis.modules[zigAnalysis.rootMod]; | 570 | let rootMod = zigAnalysis.modules[zigAnalysis.rootMod]; |
| ... | @@ -660,7 +660,8 @@ Happy writing! | ... | @@ -660,7 +660,8 @@ Happy writing! |
| 660 | if (!decl.decltest) return; | 660 | if (!decl.decltest) return; |
| 661 | const astNode = getAstNode(decl.decltest); | 661 | const astNode = getAstNode(decl.decltest); |
| 662 | domSectDocTests.classList.remove("hidden"); | 662 | domSectDocTests.classList.remove("hidden"); |
| 663 | domDocTestsCode.innerHTML = generate_html_for_src(astNode.code); | 663 | domDocTestsCode.innerHTML = renderTokens( |
| | 664 | DecoratedTokenizer(astNode.code, decl)); |
| 664 | } | 665 | } |
| 665 | | 666 | |
| 666 | function renderUnknownDecl(decl) { | 667 | function renderUnknownDecl(decl) { |
| ... | @@ -707,11 +708,7 @@ Happy writing! | ... | @@ -707,11 +708,7 @@ Happy writing! |
| 707 | console.assert("type" in value.expr); | 708 | console.assert("type" in value.expr); |
| 708 | let typeObj = getType(value.expr.type); | 709 | let typeObj = getType(value.expr.type); |
| 709 | | 710 | |
| 710 | domFnProtoCode.innerHTML = exprName(value.expr, { | 711 | domFnProtoCode.innerHTML = renderTokens(ex(value.expr, { fnDecl: fnDecl })); |
| 711 | wantHtml: true, | | |
| 712 | wantLink: true, | | |
| 713 | fnDecl, | | |
| 714 | }); | | |
| 715 | | 712 | |
| 716 | domFnSourceLink.innerHTML = "[<a target=\"_blank\" href=\"" + sourceFileLink(fnDecl) + "\">src</a>]"; | 713 | domFnSourceLink.innerHTML = "[<a target=\"_blank\" href=\"" + sourceFileLink(fnDecl) + "\">src</a>]"; |
| 717 | | 714 | |
| ... | @@ -840,15 +837,21 @@ Happy writing! | ... | @@ -840,15 +837,21 @@ Happy writing! |
| 840 | | 837 | |
| 841 | let value = typeObj.params[i]; | 838 | let value = typeObj.params[i]; |
| 842 | let preClass = docsNonEmpty ? ' class="fieldHasDocs"' : ""; | 839 | let preClass = docsNonEmpty ? ' class="fieldHasDocs"' : ""; |
| 843 | let html = "<pre" + preClass + ">" + escapeHtml(fieldNode.name) + ": "; | 840 | let html = "<pre" + preClass + ">" + renderTokens((function*() { |
| 844 | if (isVarArgs && i === typeObj.params.length - 1) { | 841 | yield Tok.identifier(fieldNode.name); |
| 845 | html += "..."; | 842 | yield Tok.colon; |
| 846 | } else { | 843 | yield Tok.space; |
| 847 | let name = exprName(value, { wantHtml: false, wantLink: false }); | 844 | if (isVarArgs && i === typeObj.params.length - 1) { |
| 848 | html += '<span class="tok-kw">' + name + "</span>"; | 845 | yield Tok.period; |
| 849 | } | 846 | yield Tok.period; |
| | 847 | yield Tok.period; |
| | 848 | } else { |
| | 849 | yield* ex(value, {}); |
| | 850 | } |
| | 851 | yield Tok.comma; |
| | 852 | }())); |
| 850 | | 853 | |
| 851 | html += ",</pre>"; | 854 | html += "</pre>"; |
| 852 | | 855 | |
| 853 | if (docsNonEmpty) { | 856 | if (docsNonEmpty) { |
| 854 | html += '<div class="fieldDocs">' + markdown(docs) + "</div>"; | 857 | html += '<div class="fieldDocs">' + markdown(docs) + "</div>"; |
| ... | @@ -932,7 +935,7 @@ Happy writing! | ... | @@ -932,7 +935,7 @@ Happy writing! |
| 932 | domSectMainMod.classList.remove("hidden"); | 935 | domSectMainMod.classList.remove("hidden"); |
| 933 | } | 936 | } |
| 934 | | 937 | |
| 935 | list.sort(function (a, b) { | 938 | list.sort(function(a, b) { |
| 936 | return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase()); | 939 | return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase()); |
| 937 | }); | 940 | }); |
| 938 | | 941 | |
| ... | @@ -1054,823 +1057,578 @@ Happy writing! | ... | @@ -1054,823 +1057,578 @@ Happy writing! |
| 1054 | return walkResultTypeRef(resolved); | 1057 | return walkResultTypeRef(resolved); |
| 1055 | } | 1058 | } |
| 1056 | | 1059 | |
| 1057 | function exprName(expr, opts) { | 1060 | function* DecoratedTokenizer(src, context) { |
| 1058 | switch (Object.keys(expr)[0]) { | 1061 | let tok_it = Tokenizer(src); |
| 1059 | default: | 1062 | for (let t of tok_it) { |
| 1060 | throw "this expression is not implemented yet"; | 1063 | if (t.tag == Tag.identifier) { |
| 1061 | case "bool": { | 1064 | const link = detectDeclPath(t.src, context); |
| 1062 | if (expr.bool) { | 1065 | if (link) { |
| 1063 | return "true"; | 1066 | t.link = link; |
| 1064 | } | 1067 | } |
| 1065 | return "false"; | | |
| 1066 | } | | |
| 1067 | case "&": { | | |
| 1068 | return "&" + exprName(zigAnalysis.exprs[expr["&"]], opts); | | |
| 1069 | } | 1068 | } |
| 1070 | case "compileError": { | 1069 | |
| 1071 | let compileError = expr.compileError; | 1070 | yield t; |
| 1072 | return "@compileError(" + exprName(zigAnalysis.exprs[compileError], opts) + ")"; | 1071 | } |
| 1073 | } | 1072 | } |
| 1074 | case "enumLiteral": { | 1073 | |
| 1075 | let literal = expr.enumLiteral; | 1074 | |
| 1076 | return "." + literal; | 1075 | function renderSingleToken(t) { |
| 1077 | } | 1076 | |
| 1078 | case "void": { | 1077 | if (t.tag == Tag.whitespace) { |
| 1079 | return "void"; | 1078 | return t.src; |
| | 1079 | } |
| | 1080 | |
| | 1081 | let src = t.src; |
| | 1082 | // if (t.tag == Tag.identifier) { |
| | 1083 | // src = escapeHtml(src); |
| | 1084 | // } |
| | 1085 | let result = ""; |
| | 1086 | if (t.tag == Tag.identifier && isSimpleType(t.src)) { |
| | 1087 | result = `<span class="zig_type">${src}</span>`; |
| | 1088 | } else if (t.tag == Tag.identifier && isSpecialIndentifier(t.src)) { |
| | 1089 | result = `<span class="zig_special">${src}</span>`; |
| | 1090 | } else if (t.tag == Tag.identifier && t.fnDecl) { |
| | 1091 | result = `<span class="zig_fn">${src}</span>`; |
| | 1092 | } else { |
| | 1093 | result = `<span class="zig_${t.tag}">${src}</span>`; |
| | 1094 | } |
| | 1095 | |
| | 1096 | if (t.link) { |
| | 1097 | result = `<a href="${t.link}">` + result + "</a>"; |
| | 1098 | } |
| | 1099 | |
| | 1100 | return result; |
| | 1101 | } |
| | 1102 | |
| | 1103 | function renderTokens(tok_it) { |
| | 1104 | var html = []; |
| | 1105 | |
| | 1106 | const max_iter = 100000; |
| | 1107 | let i = 0; |
| | 1108 | for (const t of tok_it) { |
| | 1109 | i += 1; |
| | 1110 | if (i > max_iter) |
| | 1111 | throw "too many iterations"; |
| | 1112 | |
| | 1113 | if (t.tag == Tag.eof) |
| | 1114 | break; |
| | 1115 | |
| | 1116 | html.push(renderSingleToken(t)); |
| | 1117 | } |
| | 1118 | |
| | 1119 | return html.join(""); |
| | 1120 | } |
| | 1121 | |
| | 1122 | function* ex(expr, opts) { |
| | 1123 | switch (Object.keys(expr)[0]) { |
| | 1124 | default: |
| | 1125 | throw "this expression is not implemented yet: " + Object.keys(expr)[0]; |
| | 1126 | case "comptimeExpr": { |
| | 1127 | const src = zigAnalysis.comptimeExprs[expr.comptimeExpr].code; |
| | 1128 | yield* DecoratedTokenizer(src); |
| | 1129 | return; |
| 1080 | } | 1130 | } |
| 1081 | case "unreachable": { | 1131 | case "declName": { |
| 1082 | return "unreachable"; | 1132 | yield { src: expr.declName, tag: Tag.identifier }; |
| | 1133 | return; |
| 1083 | } | 1134 | } |
| 1084 | case "slice": { | 1135 | case "declRef": { |
| 1085 | let payloadHtml = ""; | 1136 | const name = getDecl(expr.declRef).name; |
| 1086 | const lhsExpr = zigAnalysis.exprs[expr.slice.lhs]; | 1137 | const canonPath = getCanonDeclPath(expr.declRef); |
| 1087 | const startExpr = zigAnalysis.exprs[expr.slice.start]; | 1138 | if (canonPath) { |
| 1088 | let decl = exprName(lhsExpr, opts); | 1139 | const link = navLink(canonPath.modNames, canonPath.declNames); |
| 1089 | let start = exprName(startExpr, opts); | 1140 | yield { src: name, tag: Tag.identifier, link }; |
| 1090 | let end = ""; | 1141 | } else { |
| 1091 | let sentinel = ""; | 1142 | yield { src: name, tag: Tag.identifier }; |
| 1092 | if (expr.slice["end"]) { | | |
| 1093 | const endExpr = zigAnalysis.exprs[expr.slice.end]; | | |
| 1094 | let end_ = exprName(endExpr, opts); | | |
| 1095 | end += end_; | | |
| 1096 | } | 1143 | } |
| 1097 | if (expr.slice["sentinel"]) { | 1144 | return; |
| 1098 | const sentinelExpr = zigAnalysis.exprs[expr.slice.sentinel]; | 1145 | } |
| 1099 | let sentinel_ = exprName(sentinelExpr, opts); | 1146 | case "refPath": { |
| 1100 | sentinel += " :" + sentinel_; | 1147 | for (let i = 0; i < expr.refPath.length; i += 1) { |
| | 1148 | if (i > 0) yield Tok.period; |
| | 1149 | yield* ex(expr.refPath[i]); |
| 1101 | } | 1150 | } |
| 1102 | payloadHtml += decl + "[" + start + ".." + end + sentinel + "]"; | 1151 | return; |
| 1103 | return payloadHtml; | 1152 | } |
| | 1153 | case "fieldRef": { |
| | 1154 | const field_idx = expr.fieldRef.index; |
| | 1155 | const type = getType(expr.fieldRef.type); |
| | 1156 | const field = getAstNode(type.src).fields[field_idx]; |
| | 1157 | const name = getAstNode(field).name; |
| | 1158 | yield { src: name, tag: Tag.identifier }; |
| | 1159 | return; |
| 1104 | } | 1160 | } |
| 1105 | case "sliceLength": { | 1161 | case "bool": { |
| 1106 | let payloadHtml = ""; | 1162 | if (expr.bool) { |
| 1107 | const lhsExpr = zigAnalysis.exprs[expr.sliceLength.lhs]; | 1163 | yield { src: "true", tag: Tag.identifier }; |
| 1108 | const startExpr = zigAnalysis.exprs[expr.sliceLength.start]; | 1164 | return; |
| 1109 | const lenExpr = zigAnalysis.exprs[expr.sliceLength.len]; | | |
| 1110 | let decl = exprName(lhsExpr, opts); | | |
| 1111 | let start = exprName(startExpr, opts); | | |
| 1112 | let len = exprName(lenExpr, opts); | | |
| 1113 | let sentinel = ""; | | |
| 1114 | if (expr.sliceLength["sentinel"]) { | | |
| 1115 | const sentinelExpr = zigAnalysis.exprs[expr.sliceLength.sentinel]; | | |
| 1116 | let sentinel_ = exprName(sentinelExpr, options); | | |
| 1117 | sentinel += " :" + sentinel_; | | |
| 1118 | } | 1165 | } |
| 1119 | payloadHtml += decl + "[" + start + "..][0.." + len + sentinel + "]"; | 1166 | yield { src: "false", tag: Tag.identifier }; |
| 1120 | return payloadHtml; | 1167 | return; |
| 1121 | } | 1168 | } |
| 1122 | case "sliceIndex": { | 1169 | case "&": { |
| 1123 | const sliceIndex = zigAnalysis.exprs[expr.sliceIndex]; | 1170 | yield { src: "&", tag: Tag.ampersand }; |
| 1124 | return exprName(sliceIndex, opts, opts); | 1171 | yield* ex(zigAnalysis.exprs[expr["&"]], opts); |
| | 1172 | return; |
| 1125 | } | 1173 | } |
| 1126 | case "cmpxchg": { | 1174 | case "call": { |
| 1127 | const typeIndex = zigAnalysis.exprs[expr.cmpxchg.type]; | 1175 | |
| 1128 | const ptrIndex = zigAnalysis.exprs[expr.cmpxchg.ptr]; | 1176 | let call = zigAnalysis.calls[expr.call]; |
| 1129 | const expectedValueIndex = | 1177 | |
| 1130 | zigAnalysis.exprs[expr.cmpxchg.expected_value]; | 1178 | switch (Object.keys(call.func)[0]) { |
| 1131 | const newValueIndex = zigAnalysis.exprs[expr.cmpxchg.new_value]; | 1179 | default: |
| 1132 | const successOrderIndex = zigAnalysis.exprs[expr.cmpxchg.success_order]; | 1180 | throw "TODO"; |
| 1133 | const failureOrderIndex = zigAnalysis.exprs[expr.cmpxchg.failure_order]; | 1181 | case "declRef": |
| 1134 | | 1182 | case "refPath": { |
| 1135 | const type = exprName(typeIndex, opts); | 1183 | yield* ex(call.func, opts); |
| 1136 | const ptr = exprName(ptrIndex, opts); | | |
| 1137 | const expectedValue = exprName(expectedValueIndex, opts); | | |
| 1138 | const newValue = exprName(newValueIndex, opts); | | |
| 1139 | const successOrder = exprName(successOrderIndex, opts); | | |
| 1140 | const failureOrder = exprName(failureOrderIndex, opts); | | |
| 1141 | | | |
| 1142 | let fnName = "@"; | | |
| 1143 | | | |
| 1144 | switch (expr.cmpxchg.name) { | | |
| 1145 | case "cmpxchg_strong": { | | |
| 1146 | fnName += "cmpxchgStrong"; | | |
| 1147 | break; | | |
| 1148 | } | | |
| 1149 | case "cmpxchg_weak": { | | |
| 1150 | fnName += "cmpxchgWeak"; | | |
| 1151 | break; | 1184 | break; |
| 1152 | } | 1185 | } |
| 1153 | default: { | 1186 | } |
| 1154 | console.log("There's only cmpxchg_strong and cmpxchg_weak"); | 1187 | yield Tok.l_paren; |
| | 1188 | |
| | 1189 | for (let i = 0; i < call.args.length; i++) { |
| | 1190 | if (i != 0) { |
| | 1191 | yield Tok.comma; |
| | 1192 | yield Tok.space; |
| 1155 | } | 1193 | } |
| | 1194 | yield* ex(call.args[i], opts); |
| 1156 | } | 1195 | } |
| 1157 | | 1196 | |
| 1158 | return ( | 1197 | yield Tok.r_paren; |
| 1159 | fnName + | 1198 | return; |
| 1160 | "(" + | | |
| 1161 | type + | | |
| 1162 | ", " + | | |
| 1163 | ptr + | | |
| 1164 | ", " + | | |
| 1165 | expectedValue + | | |
| 1166 | ", " + | | |
| 1167 | newValue + | | |
| 1168 | ", " + | | |
| 1169 | "." + | | |
| 1170 | successOrder + | | |
| 1171 | ", " + | | |
| 1172 | "." + | | |
| 1173 | failureOrder + | | |
| 1174 | ")" | | |
| 1175 | ); | | |
| 1176 | } | 1199 | } |
| 1177 | case "cmpxchgIndex": { | 1200 | case "sizeOf": { |
| 1178 | const cmpxchgIndex = zigAnalysis.exprs[expr.cmpxchgIndex]; | 1201 | const sizeOf = zigAnalysis.exprs[expr.sizeOf]; |
| 1179 | return exprName(cmpxchgIndex, opts); | 1202 | yield { src: "@sizeOf", tag: Tag.builtin }; |
| | 1203 | yield { src: "(", tag: Tag.l_paren }; |
| | 1204 | yield* ex(sizeOf, opts); |
| | 1205 | yield { src: ")", tag: Tag.r_paren }; |
| | 1206 | return; |
| 1180 | } | 1207 | } |
| 1181 | case "switchOp": { | 1208 | |
| 1182 | let condExpr = zigAnalysis.exprs[expr.switchOp.cond_index]; | 1209 | case "as": { |
| 1183 | let ast = getAstNode(expr.switchOp.src); | 1210 | const exprArg = zigAnalysis.exprs[expr.as.exprArg]; |
| 1184 | let file_name = expr.switchOp.file_name; | 1211 | yield* ex(exprArg, opts); |
| 1185 | let outer_decl_index = expr.switchOp.outer_decl; | 1212 | return; |
| 1186 | let outer_decl = getType(outer_decl_index); | | |
| 1187 | let line = 0; | | |
| 1188 | // console.log(expr.switchOp) | | |
| 1189 | // console.log(outer_decl) | | |
| 1190 | while (outer_decl_index !== 0 && outer_decl.line_number > 0) { | | |
| 1191 | line += outer_decl.line_number; | | |
| 1192 | outer_decl_index = outer_decl.outer_decl; | | |
| 1193 | outer_decl = getType(outer_decl_index); | | |
| 1194 | // console.log(outer_decl) | | |
| 1195 | } | | |
| 1196 | line += ast.line + 1; | | |
| 1197 | let payloadHtml = ""; | | |
| 1198 | let cond = exprName(condExpr, opts); | | |
| 1199 | | | |
| 1200 | payloadHtml += | | |
| 1201 | "</br>" + | | |
| 1202 | "node_name: " + | | |
| 1203 | ast.name + | | |
| 1204 | "</br>" + | | |
| 1205 | "file: " + | | |
| 1206 | file_name + | | |
| 1207 | "</br>" + | | |
| 1208 | "line: " + | | |
| 1209 | line + | | |
| 1210 | "</br>"; | | |
| 1211 | payloadHtml += | | |
| 1212 | "switch(" + | | |
| 1213 | cond + | | |
| 1214 | ") {" + | | |
| 1215 | '<a href="/src/' + | | |
| 1216 | file_name + | | |
| 1217 | "#L" + | | |
| 1218 | line + | | |
| 1219 | '">' + | | |
| 1220 | "..." + | | |
| 1221 | "</a>}"; | | |
| 1222 | return payloadHtml; | | |
| 1223 | } | 1213 | } |
| 1224 | case "switchIndex": { | 1214 | |
| 1225 | const switchIndex = zigAnalysis.exprs[expr.switchIndex]; | 1215 | case "int": { |
| 1226 | return exprName(switchIndex, opts); | 1216 | yield { src: expr.int, tag: Tag.number_literal }; |
| | 1217 | return; |
| 1227 | } | 1218 | } |
| 1228 | case "fieldRef": { | 1219 | |
| 1229 | const field_idx = expr.fieldRef.index; | 1220 | case "int_big": { |
| 1230 | const type = getType(expr.fieldRef.type); | 1221 | if (expr.int_big.negated) { |
| 1231 | const field = getAstNode(type.src).fields[field_idx]; | 1222 | yield { src: "-", tag: Tag.minus }; |
| 1232 | const name = getAstNode(field).name; | 1223 | } |
| 1233 | return name; | 1224 | yield { src: expr.int_big.value, tag: Tag.number_literal }; |
| | 1225 | return; |
| 1234 | } | 1226 | } |
| 1235 | case "intFromEnum": { | 1227 | |
| 1236 | const intFromEnum = zigAnalysis.exprs[expr.intFromEnum]; | 1228 | case "float": { |
| 1237 | return "@intFromEnum(" + exprName(intFromEnum, opts) + ")"; | 1229 | yield { src: expr.float, tag: Tag.number_literal }; |
| | 1230 | return; |
| 1238 | } | 1231 | } |
| 1239 | case "bitSizeOf": { | 1232 | |
| 1240 | const bitSizeOf = zigAnalysis.exprs[expr.bitSizeOf]; | 1233 | case "float128": { |
| 1241 | return "@bitSizeOf(" + exprName(bitSizeOf, opts) + ")"; | 1234 | yield { src: expr.float128, tag: Tag.number_literal }; |
| | 1235 | return; |
| 1242 | } | 1236 | } |
| 1243 | case "sizeOf": { | 1237 | |
| 1244 | const sizeOf = zigAnalysis.exprs[expr.sizeOf]; | 1238 | case "array": { |
| 1245 | return "@sizeOf(" + exprName(sizeOf, opts) + ")"; | 1239 | yield { src: ".", tag: Tag.period }; |
| | 1240 | yield Tok.l_brace; |
| | 1241 | for (let i = 0; i < expr.array.length; i++) { |
| | 1242 | if (i != 0) { |
| | 1243 | yield { src: ",", tag: Tag.comma }; |
| | 1244 | yield Tok.space; |
| | 1245 | } |
| | 1246 | let elem = zigAnalysis.exprs[expr.array[i]]; |
| | 1247 | yield* ex(elem, opts); |
| | 1248 | } |
| | 1249 | yield Tok.r_brace; |
| | 1250 | return; |
| 1246 | } | 1251 | } |
| 1247 | case "builtinIndex": { | 1252 | |
| 1248 | const builtinIndex = zigAnalysis.exprs[expr.builtinIndex]; | 1253 | case "compileError": { |
| 1249 | return exprName(builtinIndex, opts); | 1254 | yield { src: "@compileError", tag: Tag.builtin }; |
| | 1255 | yield Tok.l_paren; |
| | 1256 | yield* ex(zigAnalysis.exprs[expr.compileError], opts); |
| | 1257 | yield Tok.r_paren; |
| | 1258 | return; |
| 1250 | } | 1259 | } |
| 1251 | case "builtin": { | 1260 | |
| 1252 | const param_expr = zigAnalysis.exprs[expr.builtin.param]; | 1261 | case "string": { |
| 1253 | let param = exprName(param_expr, opts); | 1262 | yield { src: '"' + expr.string + '"', tag: Tag.string_literal }; |
| 1254 | | 1263 | return; |
| 1255 | let payloadHtml = "@"; | 1264 | } |
| 1256 | switch (expr.builtin.name) { | 1265 | |
| 1257 | case "align_of": { | 1266 | case "struct": { |
| 1258 | payloadHtml += "alignOf"; | 1267 | yield Tok.period; |
| 1259 | break; | 1268 | yield Tok.l_brace; |
| 1260 | } | 1269 | yield Tok.space; |
| 1261 | case "int_from_bool": { | 1270 | |
| 1262 | payloadHtml += "intFromBool"; | 1271 | for (let i = 0; i < expr.struct.length; i++) { |
| 1263 | break; | 1272 | const fv = expr.struct[i]; |
| 1264 | } | 1273 | const field_name = fv.name; |
| 1265 | case "embed_file": { | 1274 | const field_value = ex(fv.val.expr, opts); |
| 1266 | payloadHtml += "embedFile"; | 1275 | yield Tok.period; |
| 1267 | break; | 1276 | yield { src: field_name, tag: Tag.identifier }; |
| 1268 | } | 1277 | yield Tok.space; |
| 1269 | case "error_name": { | 1278 | yield Tok.eql; |
| 1270 | payloadHtml += "errorName"; | 1279 | yield Tok.space; |
| 1271 | break; | 1280 | yield* field_value; |
| 1272 | } | 1281 | if (i !== expr.struct.length - 1) { |
| 1273 | case "panic": { | 1282 | yield Tok.comma; |
| 1274 | payloadHtml += "panic"; | 1283 | yield Tok.space; |
| 1275 | break; | 1284 | } else { |
| 1276 | } | 1285 | yield Tok.space; |
| 1277 | case "set_runtime_safety": { | | |
| 1278 | payloadHtml += "setRuntimeSafety"; | | |
| 1279 | break; | | |
| 1280 | } | | |
| 1281 | case "sqrt": { | | |
| 1282 | payloadHtml += "sqrt"; | | |
| 1283 | break; | | |
| 1284 | } | | |
| 1285 | case "sin": { | | |
| 1286 | payloadHtml += "sin"; | | |
| 1287 | break; | | |
| 1288 | } | 1286 | } |
| 1289 | case "cos": { | 1287 | } |
| 1290 | payloadHtml += "cos"; | 1288 | yield Tok.r_brace; |
| | 1289 | return; |
| | 1290 | } |
| | 1291 | |
| | 1292 | case "binOpIndex": { |
| | 1293 | const binOp = zigAnalysis.exprs[expr.binOpIndex]; |
| | 1294 | yield* ex(binOp, opts); |
| | 1295 | return; |
| | 1296 | } |
| | 1297 | |
| | 1298 | case "binOp": { |
| | 1299 | const lhsOp = zigAnalysis.exprs[expr.binOp.lhs]; |
| | 1300 | const rhsOp = zigAnalysis.exprs[expr.binOp.rhs]; |
| | 1301 | |
| | 1302 | if (lhsOp["binOpIndex"] !== undefined) { |
| | 1303 | yield Tok.l_paren; |
| | 1304 | yield* ex(lhsOp, opts); |
| | 1305 | yield Tok.r_paren; |
| | 1306 | } else { |
| | 1307 | yield* ex(lhsOp, opts); |
| | 1308 | } |
| | 1309 | |
| | 1310 | yield Tok.space; |
| | 1311 | |
| | 1312 | switch (expr.binOp.name) { |
| | 1313 | case "add": { |
| | 1314 | yield { src: "+", tag: Tag.plus }; |
| 1291 | break; | 1315 | break; |
| 1292 | } | 1316 | } |
| 1293 | case "tan": { | 1317 | case "addwrap": { |
| 1294 | payloadHtml += "tan"; | 1318 | yield { src: "+%", tag: Tag.plus_percent }; |
| 1295 | break; | 1319 | break; |
| 1296 | } | 1320 | } |
| 1297 | case "exp": { | 1321 | case "add_sat": { |
| 1298 | payloadHtml += "exp"; | 1322 | yield { src: "+|", tag: Tag.plus_pipe }; |
| 1299 | break; | 1323 | break; |
| 1300 | } | 1324 | } |
| 1301 | case "exp2": { | 1325 | case "sub": { |
| 1302 | payloadHtml += "exp2"; | 1326 | yield { src: "-", tag: Tag.minus }; |
| 1303 | break; | 1327 | break; |
| 1304 | } | 1328 | } |
| 1305 | case "log": { | 1329 | case "subwrap": { |
| 1306 | payloadHtml += "log"; | 1330 | yield { src: "-%", tag: Tag.minus_percent }; |
| 1307 | break; | 1331 | break; |
| 1308 | } | 1332 | } |
| 1309 | case "log2": { | 1333 | case "sub_sat": { |
| 1310 | payloadHtml += "log2"; | 1334 | yield { src: "-|", tag: Tag.minus_pipe }; |
| 1311 | break; | 1335 | break; |
| 1312 | } | 1336 | } |
| 1313 | case "log10": { | 1337 | case "mul": { |
| 1314 | payloadHtml += "log10"; | 1338 | yield { src: "*", tag: Tag.asterisk }; |
| 1315 | break; | 1339 | break; |
| 1316 | } | 1340 | } |
| 1317 | case "fabs": { | 1341 | case "mulwrap": { |
| 1318 | payloadHtml += "fabs"; | 1342 | yield { src: "*%", tag: Tag.asterisk_percent }; |
| 1319 | break; | 1343 | break; |
| 1320 | } | 1344 | } |
| 1321 | case "floor": { | 1345 | case "mul_sat": { |
| 1322 | payloadHtml += "floor"; | 1346 | yield { src: "*|", tag: Tag.asterisk_pipe }; |
| 1323 | break; | 1347 | break; |
| 1324 | } | 1348 | } |
| 1325 | case "ceil": { | 1349 | case "div": { |
| 1326 | payloadHtml += "ceil"; | 1350 | yield { src: "/", tag: Tag.slash }; |
| 1327 | break; | 1351 | break; |
| 1328 | } | 1352 | } |
| 1329 | case "trunc": { | 1353 | case "shl": { |
| 1330 | payloadHtml += "trunc"; | 1354 | yield { src: "<<", tag: Tag.angle_bracket_angle_bracket_left }; |
| 1331 | break; | 1355 | break; |
| 1332 | } | 1356 | } |
| 1333 | case "round": { | 1357 | case "shl_sat": { |
| 1334 | payloadHtml += "round"; | 1358 | yield { src: "<<|", tag: Tag.angle_bracket_angle_bracket_left_pipe }; |
| 1335 | break; | 1359 | break; |
| 1336 | } | 1360 | } |
| 1337 | case "tag_name": { | 1361 | case "shr": { |
| 1338 | payloadHtml += "tagName"; | 1362 | yield { src: ">>", tag: Tag.angle_bracket_angle_bracket_right }; |
| 1339 | break; | 1363 | break; |
| 1340 | } | 1364 | } |
| 1341 | case "reify": { | 1365 | case "bit_or": { |
| 1342 | payloadHtml += "Type"; | 1366 | yield { src: "|", tag: Tag.pipe }; |
| 1343 | break; | 1367 | break; |
| 1344 | } | 1368 | } |
| 1345 | case "type_name": { | 1369 | case "bit_and": { |
| 1346 | payloadHtml += "typeName"; | 1370 | yield { src: "&", tag: Tag.ampersand }; |
| 1347 | break; | 1371 | break; |
| 1348 | } | 1372 | } |
| 1349 | case "frame_type": { | 1373 | case "array_cat": { |
| 1350 | payloadHtml += "Frame"; | 1374 | yield { src: "++", tag: Tag.plus_plus }; |
| 1351 | break; | 1375 | break; |
| 1352 | } | 1376 | } |
| 1353 | case "frame_size": { | 1377 | case "array_mul": { |
| 1354 | payloadHtml += "frameSize"; | 1378 | yield { src: "**", tag: Tag.asterisk_asterisk }; |
| 1355 | break; | 1379 | break; |
| 1356 | } | 1380 | } |
| 1357 | case "work_item_id": { | 1381 | case "cmp_eq": { |
| 1358 | payloadHtml += "workItemId"; | 1382 | yield { src: "==", tag: Tag.equal_equal }; |
| 1359 | break; | 1383 | break; |
| 1360 | } | 1384 | } |
| 1361 | case "work_group_size": { | 1385 | case "cmp_neq": { |
| 1362 | payloadHtml += "workGroupSize"; | 1386 | yield { src: "!=", tag: Tag.bang_equal }; |
| 1363 | break; | 1387 | break; |
| 1364 | } | 1388 | } |
| 1365 | case "work_group_id": { | 1389 | case "cmp_gt": { |
| 1366 | payloadHtml += "workGroupId"; | 1390 | yield { src: ">", tag: Tag.angle_bracket_right }; |
| 1367 | break; | 1391 | break; |
| 1368 | } | 1392 | } |
| 1369 | case "int_from_ptr": { | 1393 | case "cmp_gte": { |
| 1370 | payloadHtml += "intFromPtr"; | 1394 | yield { src: ">=", tag: Tag.angle_bracket_right_equal }; |
| 1371 | break; | 1395 | break; |
| 1372 | } | 1396 | } |
| 1373 | case "int_from_error": { | 1397 | case "cmp_lt": { |
| 1374 | payloadHtml += "intFromError"; | 1398 | yield { src: "<", tag: Tag.angle_bracket_left }; |
| 1375 | break; | 1399 | break; |
| 1376 | } | 1400 | } |
| 1377 | case "error_to_int": { | 1401 | case "cmp_lte": { |
| 1378 | payloadHtml += "errorFromInt"; | 1402 | yield { src: "<=", tag: Tag.angle_bracket_left_equal }; |
| 1379 | break; | 1403 | break; |
| 1380 | } | 1404 | } |
| 1381 | case "max": { | 1405 | case "bool_br_and": { |
| 1382 | payloadHtml += "max"; | 1406 | yield { src: "and", tag: Tag.keyword_and }; |
| 1383 | break; | 1407 | break; |
| 1384 | } | 1408 | } |
| 1385 | case "min": { | 1409 | case "bool_br_or": { |
| 1386 | payloadHtml += "min"; | 1410 | yield { src: "or", tag: Tag.keyword_or }; |
| 1387 | break; | 1411 | break; |
| 1388 | } | 1412 | } |
| 1389 | case "bit_not": { | | |
| 1390 | return "~" + param; | | |
| 1391 | } | | |
| 1392 | case "bool_not": { | | |
| 1393 | return "!" + param; | | |
| 1394 | } | | |
| 1395 | case "clz": { | | |
| 1396 | return "@clz(T" + ", " + param + ")"; | | |
| 1397 | } | | |
| 1398 | case "ctz": { | | |
| 1399 | return "@ctz(T" + ", " + param + ")"; | | |
| 1400 | } | | |
| 1401 | case "pop_count": { | | |
| 1402 | return "@popCount(T" + ", " + param + ")"; | | |
| 1403 | } | | |
| 1404 | case "byte_swap": { | | |
| 1405 | return "@byteSwap(T" + ", " + param + ")"; | | |
| 1406 | } | | |
| 1407 | case "bit_reverse": { | | |
| 1408 | return "@bitReverse(T" + ", " + param + ")"; | | |
| 1409 | } | | |
| 1410 | case "truncate": { | | |
| 1411 | return "@truncate(" + param + ")"; | | |
| 1412 | } | | |
| 1413 | default: | 1413 | default: |
| 1414 | console.log("builtin function not handled yet or doesn't exist!"); | 1414 | console.log("operator not handled yet or doesn't exist!"); |
| 1415 | } | 1415 | } |
| 1416 | return payloadHtml + "(" + param + ")"; | 1416 | |
| | 1417 | yield Tok.space; |
| | 1418 | |
| | 1419 | if (rhsOp["binOpIndex"] !== undefined) { |
| | 1420 | yield Tok.l_paren; |
| | 1421 | yield* ex(rhsOp, opts); |
| | 1422 | yield Tok.r_paren; |
| | 1423 | } else { |
| | 1424 | yield* ex(rhsOp, opts); |
| | 1425 | } |
| | 1426 | return; |
| 1417 | } | 1427 | } |
| | 1428 | |
| 1418 | case "builtinBinIndex": { | 1429 | case "builtinBinIndex": { |
| 1419 | const builtinBinIndex = zigAnalysis.exprs[expr.builtinBinIndex]; | 1430 | const builtinBinIndex = zigAnalysis.exprs[expr.builtinBinIndex]; |
| 1420 | return exprName(builtinBinIndex, opts); | 1431 | yield* ex(builtinBinIndex, opts); |
| | 1432 | return; |
| 1421 | } | 1433 | } |
| | 1434 | |
| 1422 | case "builtinBin": { | 1435 | case "builtinBin": { |
| 1423 | const lhsOp = zigAnalysis.exprs[expr.builtinBin.lhs]; | 1436 | const lhsOp = zigAnalysis.exprs[expr.builtinBin.lhs]; |
| 1424 | const rhsOp = zigAnalysis.exprs[expr.builtinBin.rhs]; | 1437 | const rhsOp = zigAnalysis.exprs[expr.builtinBin.rhs]; |
| 1425 | let lhs = exprName(lhsOp, opts); | | |
| 1426 | let rhs = exprName(rhsOp, opts); | | |
| 1427 | | 1438 | |
| 1428 | let payloadHtml = "@"; | 1439 | let builtinName = "@"; |
| 1429 | switch (expr.builtinBin.name) { | 1440 | switch (expr.builtinBin.name) { |
| 1430 | case "int_from_float": { | 1441 | case "int_from_float": { |
| 1431 | payloadHtml += "intFromFloat"; | 1442 | builtinName += "intFromFloat"; |
| 1432 | break; | 1443 | break; |
| 1433 | } | 1444 | } |
| 1434 | case "float_from_int": { | 1445 | case "float_from_int": { |
| 1435 | payloadHtml += "floatFromInt"; | 1446 | builtinName += "floatFromInt"; |
| 1436 | break; | 1447 | break; |
| 1437 | } | 1448 | } |
| 1438 | case "ptr_from_int": { | 1449 | case "ptr_from_int": { |
| 1439 | payloadHtml += "ptrFromInt"; | 1450 | builtinName += "ptrFromInt"; |
| 1440 | break; | 1451 | break; |
| 1441 | } | 1452 | } |
| 1442 | case "enum_from_int": { | 1453 | case "enum_from_int": { |
| 1443 | payloadHtml += "enumFromInt"; | 1454 | builtinName += "enumFromInt"; |
| 1444 | break; | 1455 | break; |
| 1445 | } | 1456 | } |
| 1446 | case "float_cast": { | 1457 | case "float_cast": { |
| 1447 | payloadHtml += "floatCast"; | 1458 | builtinName += "floatCast"; |
| 1448 | break; | 1459 | break; |
| 1449 | } | 1460 | } |
| 1450 | case "int_cast": { | 1461 | case "int_cast": { |
| 1451 | payloadHtml += "intCast"; | 1462 | builtinName += "intCast"; |
| 1452 | break; | 1463 | break; |
| 1453 | } | 1464 | } |
| 1454 | case "ptr_cast": { | 1465 | case "ptr_cast": { |
| 1455 | payloadHtml += "ptrCast"; | 1466 | builtinName += "ptrCast"; |
| 1456 | break; | 1467 | break; |
| 1457 | } | 1468 | } |
| 1458 | case "const_cast": { | 1469 | case "const_cast": { |
| 1459 | payloadHtml += "constCast"; | 1470 | builtinName += "constCast"; |
| 1460 | break; | 1471 | break; |
| 1461 | } | 1472 | } |
| 1462 | case "volatile_cast": { | 1473 | case "volatile_cast": { |
| 1463 | payloadHtml += "volatileCast"; | 1474 | builtinName += "volatileCast"; |
| 1464 | break; | 1475 | break; |
| 1465 | } | 1476 | } |
| 1466 | case "truncate": { | 1477 | case "truncate": { |
| 1467 | payloadHtml += "truncate"; | 1478 | builtinName += "truncate"; |
| 1468 | break; | 1479 | break; |
| 1469 | } | 1480 | } |
| 1470 | case "has_decl": { | 1481 | case "has_decl": { |
| 1471 | payloadHtml += "hasDecl"; | 1482 | builtinName += "hasDecl"; |
| 1472 | break; | 1483 | break; |
| 1473 | } | 1484 | } |
| 1474 | case "has_field": { | 1485 | case "has_field": { |
| 1475 | payloadHtml += "hasField"; | 1486 | builtinName += "hasField"; |
| 1476 | break; | 1487 | break; |
| 1477 | } | 1488 | } |
| 1478 | case "bit_reverse": { | 1489 | case "bit_reverse": { |
| 1479 | payloadHtml += "bitReverse"; | 1490 | builtinName += "bitReverse"; |
| 1480 | break; | 1491 | break; |
| 1481 | } | 1492 | } |
| 1482 | case "div_exact": { | 1493 | case "div_exact": { |
| 1483 | payloadHtml += "divExact"; | 1494 | builtinName += "divExact"; |
| 1484 | break; | 1495 | break; |
| 1485 | } | 1496 | } |
| 1486 | case "div_floor": { | 1497 | case "div_floor": { |
| 1487 | payloadHtml += "divFloor"; | 1498 | builtinName += "divFloor"; |
| 1488 | break; | 1499 | break; |
| 1489 | } | 1500 | } |
| 1490 | case "div_trunc": { | 1501 | case "div_trunc": { |
| 1491 | payloadHtml += "divTrunc"; | 1502 | builtinName += "divTrunc"; |
| 1492 | break; | 1503 | break; |
| 1493 | } | 1504 | } |
| 1494 | case "mod": { | 1505 | case "mod": { |
| 1495 | payloadHtml += "mod"; | 1506 | builtinName += "mod"; |
| 1496 | break; | 1507 | break; |
| 1497 | } | 1508 | } |
| 1498 | case "rem": { | 1509 | case "rem": { |
| 1499 | payloadHtml += "rem"; | 1510 | builtinName += "rem"; |
| 1500 | break; | 1511 | break; |
| 1501 | } | 1512 | } |
| 1502 | case "mod_rem": { | 1513 | case "mod_rem": { |
| 1503 | payloadHtml += "rem"; | 1514 | builtinName += "rem"; |
| 1504 | break; | 1515 | break; |
| 1505 | } | 1516 | } |
| 1506 | case "shl_exact": { | 1517 | case "shl_exact": { |
| 1507 | payloadHtml += "shlExact"; | 1518 | builtinName += "shlExact"; |
| 1508 | break; | 1519 | break; |
| 1509 | } | 1520 | } |
| 1510 | case "shr_exact": { | 1521 | case "shr_exact": { |
| 1511 | payloadHtml += "shrExact"; | 1522 | builtinName += "shrExact"; |
| 1512 | break; | 1523 | break; |
| 1513 | } | 1524 | } |
| 1514 | case "bitcast": { | 1525 | case "bitcast": { |
| 1515 | payloadHtml += "bitCast"; | 1526 | builtinName += "bitCast"; |
| 1516 | break; | 1527 | break; |
| 1517 | } | 1528 | } |
| 1518 | case "align_cast": { | 1529 | case "align_cast": { |
| 1519 | payloadHtml += "alignCast"; | 1530 | builtinName += "alignCast"; |
| 1520 | break; | 1531 | break; |
| 1521 | } | 1532 | } |
| 1522 | case "vector_type": { | 1533 | case "vector_type": { |
| 1523 | payloadHtml += "Vector"; | 1534 | builtinName += "Vector"; |
| 1524 | break; | 1535 | break; |
| 1525 | } | 1536 | } |
| 1526 | case "reduce": { | 1537 | case "reduce": { |
| 1527 | payloadHtml += "reduce"; | 1538 | builtinName += "reduce"; |
| 1528 | break; | 1539 | break; |
| 1529 | } | 1540 | } |
| 1530 | case "splat": { | 1541 | case "splat": { |
| 1531 | payloadHtml += "splat"; | 1542 | builtinName += "splat"; |
| 1532 | break; | 1543 | break; |
| 1533 | } | 1544 | } |
| 1534 | case "offset_of": { | 1545 | case "offset_of": { |
| 1535 | payloadHtml += "offsetOf"; | 1546 | builtinName += "offsetOf"; |
| 1536 | break; | 1547 | break; |
| 1537 | } | 1548 | } |
| 1538 | case "bit_offset_of": { | 1549 | case "bit_offset_of": { |
| 1539 | payloadHtml += "bitOffsetOf"; | 1550 | builtinName += "bitOffsetOf"; |
| 1540 | break; | 1551 | break; |
| 1541 | } | 1552 | } |
| 1542 | default: | 1553 | default: |
| 1543 | console.log("builtin function not handled yet or doesn't exist!"); | 1554 | console.log("builtin function not handled yet or doesn't exist!"); |
| 1544 | } | 1555 | } |
| 1545 | return payloadHtml + "(" + lhs + ", " + rhs + ")"; | | |
| 1546 | } | | |
| 1547 | case "binOpIndex": { | | |
| 1548 | const binOpIndex = zigAnalysis.exprs[expr.binOpIndex]; | | |
| 1549 | return exprName(binOpIndex, opts); | | |
| 1550 | } | | |
| 1551 | case "binOp": { | | |
| 1552 | const lhsOp = zigAnalysis.exprs[expr.binOp.lhs]; | | |
| 1553 | const rhsOp = zigAnalysis.exprs[expr.binOp.rhs]; | | |
| 1554 | let lhs = exprName(lhsOp, opts); | | |
| 1555 | let rhs = exprName(rhsOp, opts); | | |
| 1556 | | | |
| 1557 | let print_lhs = ""; | | |
| 1558 | let print_rhs = ""; | | |
| 1559 | | 1556 | |
| 1560 | if (lhsOp["binOpIndex"]) { | 1557 | yield { src: builtinName, tag: Tag.builtin }; |
| 1561 | print_lhs = "(" + lhs + ")"; | 1558 | yield Tok.l_paren; |
| 1562 | } else { | 1559 | yield* ex(lhsOp, opts); |
| 1563 | print_lhs = lhs; | 1560 | yield Tok.comma; |
| 1564 | } | 1561 | yield Tok.space; |
| 1565 | if (rhsOp["binOpIndex"]) { | 1562 | yield* ex(rhsOp, opts); |
| 1566 | print_rhs = "(" + rhs + ")"; | 1563 | yield Tok.r_paren; |
| 1567 | } else { | 1564 | return; |
| 1568 | print_rhs = rhs; | | |
| 1569 | } | | |
| 1570 | | | |
| 1571 | let operator = ""; | | |
| 1572 | | | |
| 1573 | switch (expr.binOp.name) { | | |
| 1574 | case "add": { | | |
| 1575 | operator += "+"; | | |
| 1576 | break; | | |
| 1577 | } | | |
| 1578 | case "addwrap": { | | |
| 1579 | operator += "+%"; | | |
| 1580 | break; | | |
| 1581 | } | | |
| 1582 | case "add_sat": { | | |
| 1583 | operator += "+|"; | | |
| 1584 | break; | | |
| 1585 | } | | |
| 1586 | case "sub": { | | |
| 1587 | operator += "-"; | | |
| 1588 | break; | | |
| 1589 | } | | |
| 1590 | case "subwrap": { | | |
| 1591 | operator += "-%"; | | |
| 1592 | break; | | |
| 1593 | } | | |
| 1594 | case "sub_sat": { | | |
| 1595 | operator += "-|"; | | |
| 1596 | break; | | |
| 1597 | } | | |
| 1598 | case "mul": { | | |
| 1599 | operator += "*"; | | |
| 1600 | break; | | |
| 1601 | } | | |
| 1602 | case "mulwrap": { | | |
| 1603 | operator += "*%"; | | |
| 1604 | break; | | |
| 1605 | } | | |
| 1606 | case "mul_sat": { | | |
| 1607 | operator += "*|"; | | |
| 1608 | break; | | |
| 1609 | } | | |
| 1610 | case "div": { | | |
| 1611 | operator += "/"; | | |
| 1612 | break; | | |
| 1613 | } | | |
| 1614 | case "shl": { | | |
| 1615 | operator += "<<"; | | |
| 1616 | break; | | |
| 1617 | } | | |
| 1618 | case "shl_sat": { | | |
| 1619 | operator += "<<|"; | | |
| 1620 | break; | | |
| 1621 | } | | |
| 1622 | case "shr": { | | |
| 1623 | operator += ">>"; | | |
| 1624 | break; | | |
| 1625 | } | | |
| 1626 | case "bit_or": { | | |
| 1627 | operator += "|"; | | |
| 1628 | break; | | |
| 1629 | } | | |
| 1630 | case "bit_and": { | | |
| 1631 | operator += "&"; | | |
| 1632 | break; | | |
| 1633 | } | | |
| 1634 | case "array_cat": { | | |
| 1635 | operator += "++"; | | |
| 1636 | break; | | |
| 1637 | } | | |
| 1638 | case "array_mul": { | | |
| 1639 | operator += "**"; | | |
| 1640 | break; | | |
| 1641 | } | | |
| 1642 | case "cmp_eq": { | | |
| 1643 | operator += "=="; | | |
| 1644 | break; | | |
| 1645 | } | | |
| 1646 | case "cmp_neq": { | | |
| 1647 | operator += "!="; | | |
| 1648 | break; | | |
| 1649 | } | | |
| 1650 | case "cmp_gt": { | | |
| 1651 | operator += ">"; | | |
| 1652 | break; | | |
| 1653 | } | | |
| 1654 | case "cmp_gte": { | | |
| 1655 | operator += ">="; | | |
| 1656 | break; | | |
| 1657 | } | | |
| 1658 | case "cmp_lt": { | | |
| 1659 | operator += "<"; | | |
| 1660 | break; | | |
| 1661 | } | | |
| 1662 | case "cmp_lte": { | | |
| 1663 | operator += "<="; | | |
| 1664 | break; | | |
| 1665 | } | | |
| 1666 | case "bool_br_and": { | | |
| 1667 | operator += "and"; | | |
| 1668 | break; | | |
| 1669 | } | | |
| 1670 | case "bool_br_or": { | | |
| 1671 | operator += "or"; | | |
| 1672 | break; | | |
| 1673 | } | | |
| 1674 | default: | | |
| 1675 | console.log("operator not handled yet or doesn't exist!"); | | |
| 1676 | } | | |
| 1677 | | | |
| 1678 | return print_lhs + " " + operator + " " + print_rhs; | | |
| 1679 | } | | |
| 1680 | case "errorSets": { | | |
| 1681 | const errUnionObj = getType(expr.errorSets); | | |
| 1682 | let lhs = exprName(errUnionObj.lhs, opts); | | |
| 1683 | let rhs = exprName(errUnionObj.rhs, opts); | | |
| 1684 | return lhs + " || " + rhs; | | |
| 1685 | } | | |
| 1686 | case "errorUnion": { | | |
| 1687 | const errUnionObj = getType(expr.errorUnion); | | |
| 1688 | let lhs = exprName(errUnionObj.lhs, opts); | | |
| 1689 | let rhs = exprName(errUnionObj.rhs, opts); | | |
| 1690 | return lhs + "!" + rhs; | | |
| 1691 | } | | |
| 1692 | case "struct": { | | |
| 1693 | // const struct_name = | | |
| 1694 | // zigAnalysis.decls[expr.struct[0].val.typeRef.refPath[0].declRef].name; | | |
| 1695 | const struct_name = "."; | | |
| 1696 | let struct_body = ""; | | |
| 1697 | struct_body += struct_name + "{ "; | | |
| 1698 | for (let i = 0; i < expr.struct.length; i++) { | | |
| 1699 | const fv = expr.struct[i]; | | |
| 1700 | const field_name = fv.name; | | |
| 1701 | const field_value = exprName(fv.val.expr, opts); | | |
| 1702 | // TODO: commented out because it seems not needed. if it deals | | |
| 1703 | // with a corner case, please add a comment when re-enabling it. | | |
| 1704 | // let field_value = exprArg[Object.keys(exprArg)[0]]; | | |
| 1705 | // if (field_value instanceof Object) { | | |
| 1706 | // value_field = exprName(value_field) | | |
| 1707 | // zigAnalysis.decls[value_field[0].val.typeRef.refPath[0].declRef] | | |
| 1708 | // .name; | | |
| 1709 | // } | | |
| 1710 | struct_body += "." + field_name + " = " + field_value; | | |
| 1711 | if (i !== expr.struct.length - 1) { | | |
| 1712 | struct_body += ", "; | | |
| 1713 | } else { | | |
| 1714 | struct_body += " "; | | |
| 1715 | } | | |
| 1716 | } | | |
| 1717 | struct_body += "}"; | | |
| 1718 | return struct_body; | | |
| 1719 | } | | |
| 1720 | case "typeOf_peer": { | | |
| 1721 | let payloadHtml = "@TypeOf("; | | |
| 1722 | for (let i = 0; i < expr.typeOf_peer.length; i++) { | | |
| 1723 | let elem = zigAnalysis.exprs[expr.typeOf_peer[i]]; | | |
| 1724 | payloadHtml += exprName(elem, { wantHtml: true, wantLink: true }); | | |
| 1725 | if (i !== expr.typeOf_peer.length - 1) { | | |
| 1726 | payloadHtml += ", "; | | |
| 1727 | } | | |
| 1728 | } | | |
| 1729 | payloadHtml += ")"; | | |
| 1730 | return payloadHtml; | | |
| 1731 | } | | |
| 1732 | case "alignOf": { | | |
| 1733 | const alignRefArg = zigAnalysis.exprs[expr.alignOf]; | | |
| 1734 | let payloadHtml = | | |
| 1735 | "@alignOf(" + | | |
| 1736 | exprName(alignRefArg, { wantHtml: true, wantLink: true }) + | | |
| 1737 | ")"; | | |
| 1738 | return payloadHtml; | | |
| 1739 | } | 1565 | } |
| 1740 | case "typeOf": { | 1566 | |
| 1741 | const typeRefArg = zigAnalysis.exprs[expr.typeOf]; | 1567 | case "enumLiteral": { |
| 1742 | let payloadHtml = | 1568 | let literal = expr.enumLiteral; |
| 1743 | "@TypeOf(" + | 1569 | yield Tok.period; |
| 1744 | exprName(typeRefArg, { wantHtml: true, wantLink: true }) + | 1570 | yield { src: literal, tag: Tag.identifier }; |
| 1745 | ")"; | 1571 | return; |
| 1746 | return payloadHtml; | | |
| 1747 | } | 1572 | } |
| 1748 | case "typeInfo": { | 1573 | |
| 1749 | const typeRefArg = zigAnalysis.exprs[expr.typeInfo]; | 1574 | case "void": { |
| 1750 | let payloadHtml = | 1575 | yield { src: "void", tag: Tag.identifier }; |
| 1751 | "@typeInfo(" + | 1576 | return; |
| 1752 | exprName(typeRefArg, { wantHtml: true, wantLink: true }) + | | |
| 1753 | ")"; | | |
| 1754 | return payloadHtml; | | |
| 1755 | } | 1577 | } |
| | 1578 | |
| 1756 | case "null": { | 1579 | case "null": { |
| 1757 | if (opts.wantHtml) { | 1580 | yield { src: "null", tag: Tag.identifier }; |
| 1758 | return '<span class="tok-null">null</span>'; | 1581 | return; |
| 1759 | } else { | | |
| 1760 | return "null"; | | |
| 1761 | } | | |
| 1762 | } | | |
| 1763 | case "array": { | | |
| 1764 | let payloadHtml = ".{"; | | |
| 1765 | for (let i = 0; i < expr.array.length; i++) { | | |
| 1766 | if (i != 0) payloadHtml += ", "; | | |
| 1767 | let elem = zigAnalysis.exprs[expr.array[i]]; | | |
| 1768 | payloadHtml += exprName(elem, opts); | | |
| 1769 | } | | |
| 1770 | return payloadHtml + "}"; | | |
| 1771 | } | | |
| 1772 | case "comptimeExpr": { | | |
| 1773 | return generate_html_for_src(zigAnalysis.comptimeExprs[expr.comptimeExpr].code); | | |
| 1774 | } | 1582 | } |
| 1775 | case "call": { | | |
| 1776 | let call = zigAnalysis.calls[expr.call]; | | |
| 1777 | let payloadHtml = ""; | | |
| 1778 | | | |
| 1779 | switch (Object.keys(call.func)[0]) { | | |
| 1780 | default: | | |
| 1781 | throw "TODO"; | | |
| 1782 | case "declRef": | | |
| 1783 | case "refPath": { | | |
| 1784 | payloadHtml += exprName(call.func, opts); | | |
| 1785 | break; | | |
| 1786 | } | | |
| 1787 | } | | |
| 1788 | payloadHtml += "("; | | |
| 1789 | | 1583 | |
| 1790 | for (let i = 0; i < call.args.length; i++) { | 1584 | case "undefined": { |
| 1791 | if (i != 0) payloadHtml += ", "; | 1585 | yield { src: "undefined", tag: Tag.identifier }; |
| 1792 | payloadHtml += exprName(call.args[i], opts); | 1586 | return; |
| 1793 | } | | |
| 1794 | | | |
| 1795 | payloadHtml += ")"; | | |
| 1796 | return payloadHtml; | | |
| 1797 | } | | |
| 1798 | case "as": { | | |
| 1799 | // @Check : this should be done in backend because there are legit @as() calls | | |
| 1800 | // const typeRefArg = zigAnalysis.exprs[expr.as.typeRefArg]; | | |
| 1801 | const exprArg = zigAnalysis.exprs[expr.as.exprArg]; | | |
| 1802 | // return "@as(" + exprName(typeRefArg, opts) + | | |
| 1803 | // ", " + exprName(exprArg, opts) + ")"; | | |
| 1804 | return exprName(exprArg, opts); | | |
| 1805 | } | 1587 | } |
| 1806 | case "declRef": { | | |
| 1807 | const name = getDecl(expr.declRef).name; | | |
| 1808 | | 1588 | |
| 1809 | if (opts.wantHtml) { | 1589 | case "anytype": { |
| 1810 | let payloadHtml = ""; | 1590 | yield { src: "anytype", tag: Tag.keyword_anytype }; |
| 1811 | if (opts.wantLink) { | 1591 | return; |
| 1812 | payloadHtml += '<a href="' + findDeclNavLink(name) + '">'; | | |
| 1813 | } | | |
| 1814 | payloadHtml += | | |
| 1815 | '<span class="tok-kw" style="color:lightblue;">' + | | |
| 1816 | name + | | |
| 1817 | "</span>"; | | |
| 1818 | if (opts.wantLink) payloadHtml += "</a>"; | | |
| 1819 | return payloadHtml; | | |
| 1820 | } else { | | |
| 1821 | return name; | | |
| 1822 | } | | |
| 1823 | } | | |
| 1824 | case "refPath": { | | |
| 1825 | let firstComponent = expr.refPath[0]; | | |
| 1826 | let name = exprName(firstComponent, opts); | | |
| 1827 | let url = undefined; | | |
| 1828 | if (opts.wantLink && "declRef" in firstComponent) { | | |
| 1829 | url = findDeclNavLink(getDecl(firstComponent.declRef).name); | | |
| 1830 | } | | |
| 1831 | for (let i = 1; i < expr.refPath.length; i++) { | | |
| 1832 | let component = undefined; | | |
| 1833 | if ("string" in expr.refPath[i]) { | | |
| 1834 | component = expr.refPath[i].string; | | |
| 1835 | } else { | | |
| 1836 | component = exprName(expr.refPath[i], { ...opts, wantLink: false }); | | |
| 1837 | if (opts.wantLink && "declRef" in expr.refPath[i]) { | | |
| 1838 | url += "." + getDecl(expr.refPath[i].declRef).name; | | |
| 1839 | component = '<a href="' + url + '">' + | | |
| 1840 | component + | | |
| 1841 | "</a>"; | | |
| 1842 | } | | |
| 1843 | } | | |
| 1844 | name += "." + component; | | |
| 1845 | } | | |
| 1846 | return name; | | |
| 1847 | } | | |
| 1848 | case "int": { | | |
| 1849 | return "" + expr.int; | | |
| 1850 | } | | |
| 1851 | case "float": { | | |
| 1852 | return "" + expr.float.toFixed(2); | | |
| 1853 | } | | |
| 1854 | case "float128": { | | |
| 1855 | return "" + expr.float128.toFixed(2); | | |
| 1856 | } | 1592 | } |
| 1857 | case "undefined": { | 1593 | |
| 1858 | return "undefined"; | 1594 | case "this": { |
| | 1595 | yield { src: "@This", tag: Tag.builtin }; |
| | 1596 | yield Tok.l_paren; |
| | 1597 | yield Tok.r_paren; |
| | 1598 | return; |
| 1859 | } | 1599 | } |
| 1860 | case "string": { | 1600 | |
| 1861 | return '"' + escapeHtml(expr.string) + '"'; | 1601 | case "typeInfo": { |
| | 1602 | const arg = zigAnalysis.exprs[expr.typeInfo]; |
| | 1603 | yield { src: "@typeInfo", tag: Tag.builtin }; |
| | 1604 | yield Tok.l_paren; |
| | 1605 | yield* ex(arg, opts); |
| | 1606 | yield Tok.r_paren; |
| | 1607 | return; |
| 1862 | } | 1608 | } |
| 1863 | | 1609 | |
| 1864 | case "int_big": { | 1610 | case "switchIndex": { |
| 1865 | return (expr.int_big.negated ? "-" : "") + expr.int_big.value; | 1611 | const switchIndex = zigAnalysis.exprs[expr.switchIndex]; |
| | 1612 | yield* ex(switchIndex, opts); |
| | 1613 | return; |
| 1866 | } | 1614 | } |
| 1867 | | 1615 | |
| 1868 | case "anytype": { | 1616 | case "errorSets": { |
| 1869 | return "anytype"; | 1617 | const errSetsObj = getType(expr.errorSets); |
| | 1618 | yield* ex(errSetsObj.lhs, opts); |
| | 1619 | yield Tok.space; |
| | 1620 | yield { src: "||", tag: Tag.pipe_pipe }; |
| | 1621 | yield Tok.space; |
| | 1622 | yield* ex(errSetsObj.rhs, opts); |
| | 1623 | return; |
| 1870 | } | 1624 | } |
| 1871 | | 1625 | |
| 1872 | case "this": { | 1626 | case "errorUnion": { |
| 1873 | return "@This()"; | 1627 | const errUnionObj = getType(expr.errorUnion); |
| | 1628 | yield* ex(errUnionObj.lhs, opts); |
| | 1629 | yield { src: "!", tag: Tag.bang }; |
| | 1630 | yield* ex(errUnionObj.rhs, opts); |
| | 1631 | return; |
| 1874 | } | 1632 | } |
| 1875 | | 1633 | |
| 1876 | case "type": { | 1634 | case "type": { |
| ... | @@ -1880,416 +1638,389 @@ Happy writing! | ... | @@ -1880,416 +1638,389 @@ Happy writing! |
| 1880 | if (typeof typeObj === "number") typeObj = getType(typeObj); | 1638 | if (typeof typeObj === "number") typeObj = getType(typeObj); |
| 1881 | switch (typeObj.kind) { | 1639 | switch (typeObj.kind) { |
| 1882 | default: | 1640 | default: |
| 1883 | throw "TODO"; | 1641 | throw "TODO: " + typeObj.kind; |
| | 1642 | case typeKinds.Type: { |
| | 1643 | yield { src: typeObj.name, tag: Tag.identifier }; |
| | 1644 | return; |
| | 1645 | } |
| | 1646 | case typeKinds.Void: { |
| | 1647 | yield { src: "void", tag: Tag.identifier }; |
| | 1648 | return; |
| | 1649 | } |
| | 1650 | case typeKinds.NoReturn: { |
| | 1651 | yield { src: "noreturn", tag: Tag.identifier }; |
| | 1652 | return; |
| | 1653 | } |
| | 1654 | case typeKinds.ComptimeExpr: { |
| | 1655 | yield { src: "anyopaque", tag: Tag.identifier }; |
| | 1656 | return; |
| | 1657 | } |
| | 1658 | case typeKinds.Bool: { |
| | 1659 | yield { src: "bool", tag: Tag.identifier }; |
| | 1660 | return; |
| | 1661 | } |
| | 1662 | case typeKinds.ComptimeInt: { |
| | 1663 | yield { src: "comptime_int", tag: Tag.identifier }; |
| | 1664 | return; |
| | 1665 | } |
| | 1666 | case typeKinds.ComptimeFloat: { |
| | 1667 | yield { src: "comptime_float", tag: Tag.identifier }; |
| | 1668 | return; |
| | 1669 | } |
| | 1670 | case typeKinds.Int: { |
| | 1671 | yield { src: typeObj.name, tag: Tag.identifier }; |
| | 1672 | return; |
| | 1673 | } |
| | 1674 | case typeKinds.Float: { |
| | 1675 | yield { src: typeObj.name, tag: Tag.identifier }; |
| | 1676 | return; |
| | 1677 | } |
| | 1678 | case typeKinds.Array: { |
| | 1679 | yield Tok.l_bracket; |
| | 1680 | yield* ex(typeObj.len, opts); |
| | 1681 | if (typeObj.sentinel) { |
| | 1682 | yield Tok.colon; |
| | 1683 | yield* ex(typeObj.sentinel, opts); |
| | 1684 | } |
| | 1685 | yield Tok.r_bracket; |
| | 1686 | yield* ex(typeObj.child, opts); |
| | 1687 | return; |
| | 1688 | } |
| | 1689 | case typeKinds.Optional: { |
| | 1690 | yield { src: "?", tag: Tag.question_mark }; |
| | 1691 | yield* ex(typeObj.child, opts); |
| | 1692 | return; |
| | 1693 | } |
| | 1694 | case typeKinds.Pointer: { |
| | 1695 | let ptrObj = typeObj; |
| | 1696 | switch (ptrObj.size) { |
| | 1697 | default: |
| | 1698 | console.log("TODO: implement unhandled pointer size case"); |
| | 1699 | case pointerSizeEnum.One: |
| | 1700 | yield { src: "*", tag: Tag.asterisk }; |
| | 1701 | break; |
| | 1702 | case pointerSizeEnum.Many: |
| | 1703 | yield Tok.l_bracket; |
| | 1704 | yield { src: "*", tag: Tag.asterisk }; |
| | 1705 | if (ptrObj.sentinel !== null) { |
| | 1706 | yield Tok.colon; |
| | 1707 | yield* ex(ptrObj.sentinel, opts); |
| | 1708 | } |
| | 1709 | yield Tok.r_bracket; |
| | 1710 | break; |
| | 1711 | case pointerSizeEnum.Slice: |
| | 1712 | if (ptrObj.is_ref) { |
| | 1713 | yield { src: "*", tag: Tag.asterisk }; |
| | 1714 | } |
| | 1715 | yield Tok.l_bracket; |
| | 1716 | if (ptrObj.sentinel !== null) { |
| | 1717 | yield Tok.colon; |
| | 1718 | yield* ex(ptrObj.sentinel, opts); |
| | 1719 | } |
| | 1720 | yield Tok.r_bracket; |
| | 1721 | break; |
| | 1722 | case pointerSizeEnum.C: |
| | 1723 | yield Tok.l_bracket; |
| | 1724 | yield { src: "*", tag: Tag.asterisk }; |
| | 1725 | yield { src: "c", tag: Tag.identifier }; |
| | 1726 | if (typeObj.sentinel !== null) { |
| | 1727 | yield Tok.colon; |
| | 1728 | yield* ex(ptrObj.sentinel, opts); |
| | 1729 | } |
| | 1730 | yield Tok.r_bracket; |
| | 1731 | break; |
| | 1732 | } |
| | 1733 | if (!ptrObj.is_mutable) { |
| | 1734 | yield Tok.const; |
| | 1735 | yield Tok.space; |
| | 1736 | } |
| | 1737 | if (ptrObj.is_allowzero) { |
| | 1738 | yield { src: "allowzero", tag: Tag.keyword_allowzero }; |
| | 1739 | yield Tok.space; |
| | 1740 | } |
| | 1741 | if (ptrObj.is_volatile) { |
| | 1742 | yield { src: "volatile", tag: Tag.keyword_volatile }; |
| | 1743 | } |
| | 1744 | if (ptrObj.has_addrspace) { |
| | 1745 | yield { src: "addrspace", tag: Tag.keyword_addrspace }; |
| | 1746 | yield Tok.l_paren; |
| | 1747 | yield Tok.period; |
| | 1748 | yield Tok.r_paren; |
| | 1749 | } |
| | 1750 | if (ptrObj.has_align) { |
| | 1751 | yield { src: "align", tag: Tag.keyword_align }; |
| | 1752 | yield Tok.l_paren; |
| | 1753 | yield* ex(ptrObj.align, opts); |
| | 1754 | if (ptrObj.hostIntBytes !== undefined && ptrObj.hostIntBytes !== null) { |
| | 1755 | yield Tok.colon; |
| | 1756 | yield* ex(ptrObj.bitOffsetInHost, opts); |
| | 1757 | yield Tok.colon; |
| | 1758 | yield* ex(ptrObj.hostIntBytes, opts); |
| | 1759 | } |
| | 1760 | yield Tok.r_paren; |
| | 1761 | yield Tok.space; |
| | 1762 | } |
| | 1763 | yield* ex(ptrObj.child, opts); |
| | 1764 | return; |
| | 1765 | } |
| 1884 | case typeKinds.Struct: { | 1766 | case typeKinds.Struct: { |
| 1885 | let structObj = typeObj; | 1767 | let structObj = typeObj; |
| 1886 | let name = ""; | | |
| 1887 | let layout = ""; | | |
| 1888 | if (structObj.layout !== null) { | 1768 | if (structObj.layout !== null) { |
| 1889 | switch (structObj.layout.enumLiteral) { | 1769 | switch (structObj.layout.enumLiteral) { |
| 1890 | case "Packed": { | 1770 | case "Packed": { |
| 1891 | layout = "packed "; | 1771 | yield { src: "packed", tag: Tag.keyword_packed }; |
| 1892 | break; | 1772 | break; |
| 1893 | } | 1773 | } |
| 1894 | case "Extern": { | 1774 | case "Extern": { |
| 1895 | layout = "extern "; | 1775 | yield { src: "extern", tag: Tag.keyword_extern }; |
| 1896 | break; | 1776 | break; |
| 1897 | } | 1777 | } |
| 1898 | } | 1778 | } |
| | 1779 | yield Tok.space; |
| 1899 | } | 1780 | } |
| 1900 | if (opts.wantHtml) { | 1781 | yield { src: "struct", tag: Tag.keyword_struct }; |
| 1901 | name = "<span class='tok-kw'>" + layout + "struct</span>"; | | |
| 1902 | } else { | | |
| 1903 | name = layout + "struct"; | | |
| 1904 | } | | |
| 1905 | if (structObj.backing_int !== null) { | 1782 | if (structObj.backing_int !== null) { |
| 1906 | name += "(" + exprName(structObj.backing_int, opts) + ")"; | 1783 | yield Tok.l_paren; |
| | 1784 | yield* ex(structObj.backing_int, opts); |
| | 1785 | yield Tok.r_paren; |
| 1907 | } | 1786 | } |
| 1908 | name += " { "; | 1787 | yield Tok.space; |
| 1909 | if (structObj.field_types.length > 1 && opts.wantHtml) { name += "</br>"; } | 1788 | yield Tok.l_brace; |
| 1910 | let indent = ""; | 1789 | |
| 1911 | if (structObj.field_types.length > 1 && opts.wantHtml) { | 1790 | if (structObj.field_types.length > 1) { |
| 1912 | indent = "&nbsp;&nbsp;&nbsp;&nbsp;" | 1791 | yield Tok.enter; |
| | 1792 | } else { |
| | 1793 | yield Tok.space; |
| 1913 | } | 1794 | } |
| 1914 | if (opts.indent && structObj.field_types.length > 1) { | 1795 | |
| 1915 | indent = opts.indent + indent; | 1796 | let indent = 0; |
| | 1797 | if (structObj.field_types.length > 1) { |
| | 1798 | indent = 1; |
| 1916 | } | 1799 | } |
| 1917 | let structNode = getAstNode(structObj.src); | 1800 | if (opts.indent && structObj.field_types.length > 1) { |
| 1918 | let field_end = ","; | 1801 | indent += opts.ident; |
| 1919 | if (structObj.field_types.length > 1 && opts.wantHtml) { | | |
| 1920 | field_end += "</br>"; | | |
| 1921 | } else { | | |
| 1922 | field_end += " "; | | |
| 1923 | } | 1802 | } |
| 1924 | | 1803 | |
| | 1804 | let structNode = getAstNode(structObj.src); |
| 1925 | for (let i = 0; i < structObj.field_types.length; i += 1) { | 1805 | for (let i = 0; i < structObj.field_types.length; i += 1) { |
| 1926 | let fieldNode = getAstNode(structNode.fields[i]); | 1806 | let fieldNode = getAstNode(structNode.fields[i]); |
| 1927 | let fieldName = fieldNode.name; | 1807 | let fieldName = fieldNode.name; |
| 1928 | let html = indent; | 1808 | |
| 1929 | if (!structObj.is_tuple) { | 1809 | for (let j = 0; j < indent; j += 1) { |
| 1930 | html += escapeHtml(fieldName); | 1810 | yield Tok.tab; |
| 1931 | } | 1811 | } |
| 1932 | | 1812 | |
| 1933 | let fieldTypeExpr = structObj.field_types[i]; | 1813 | if (!typeObj.is_tuple) { |
| 1934 | if (!structObj.is_tuple) { | 1814 | yield { src: fieldName, tag: Tag.identifier }; |
| 1935 | html += ": "; | | |
| 1936 | } | 1815 | } |
| 1937 | | 1816 | |
| 1938 | html += exprName(fieldTypeExpr, { ...opts, indent: indent }); | 1817 | let fieldTypeExpr = structObj.field_types[i]; |
| | 1818 | if (!typeObj.is_tuple) { |
| | 1819 | yield Tok.colon; |
| | 1820 | yield Tok.space; |
| | 1821 | } |
| | 1822 | yield* ex(fieldTypeExpr, { ...opts, indent: indent }); |
| 1939 | | 1823 | |
| 1940 | if (structObj.field_defaults[i] !== null) { | 1824 | if (structObj.field_defaults[i] !== null) { |
| 1941 | html += " = " + exprName(structObj.field_defaults[i], opts); | 1825 | yield Tok.space; |
| | 1826 | yield Tok.eql; |
| | 1827 | yield Tok.space; |
| | 1828 | yield* ex(structObj.field_defaults[i], opts); |
| 1942 | } | 1829 | } |
| 1943 | | 1830 | |
| 1944 | html += field_end; | 1831 | if (structObj.field_types.length > 1) { |
| 1945 | | 1832 | yield Tok.comma; |
| 1946 | name += html; | 1833 | yield Tok.enter; |
| 1947 | } | 1834 | } else { |
| 1948 | if (opts.indent && structObj.field_types.length > 1) { | 1835 | yield Tok.space; |
| 1949 | name += opts.indent; | 1836 | } |
| 1950 | } | 1837 | } |
| 1951 | name += "}"; | 1838 | yield Tok.r_brace; |
| 1952 | return name; | 1839 | return; |
| 1953 | } | 1840 | } |
| 1954 | case typeKinds.Enum: { | 1841 | case typeKinds.Enum: { |
| 1955 | let enumObj = typeObj; | 1842 | let enumObj = typeObj; |
| 1956 | let name = ""; | 1843 | yield { src: "enum", tag: Tag.keyword_enum }; |
| 1957 | if (opts.wantHtml) { | | |
| 1958 | name = "<span class='tok-kw'>enum</span>"; | | |
| 1959 | } else { | | |
| 1960 | name = "enum"; | | |
| 1961 | } | | |
| 1962 | if (enumObj.tag) { | 1844 | if (enumObj.tag) { |
| 1963 | name += "(" + exprName(enumObj.tag, opts) + ")"; | 1845 | yield Tok.l_paren; |
| | 1846 | yield* ex(enumObj.tag, opts); |
| | 1847 | yield Tok.r_paren; |
| 1964 | } | 1848 | } |
| 1965 | name += " { "; | 1849 | yield Tok.space; |
| | 1850 | yield Tok.l_brace; |
| | 1851 | |
| 1966 | let enumNode = getAstNode(enumObj.src); | 1852 | let enumNode = getAstNode(enumObj.src); |
| 1967 | let fields_len = enumNode.fields.length; | 1853 | let fields_len = enumNode.fields.length; |
| 1968 | if (enumObj.nonexhaustive) { | 1854 | if (enumObj.nonexhaustive) { |
| 1969 | fields_len += 1; | 1855 | fields_len += 1; |
| 1970 | } | 1856 | } |
| 1971 | if (fields_len > 1 && opts.wantHtml) { name += "</br>"; } | 1857 | |
| 1972 | let indent = ""; | 1858 | if (fields_len > 1) { |
| | 1859 | yield Tok.enter; |
| | 1860 | } else { |
| | 1861 | yield Tok.space; |
| | 1862 | } |
| | 1863 | |
| | 1864 | let indent = 0; |
| 1973 | if (fields_len > 1) { | 1865 | if (fields_len > 1) { |
| 1974 | if (opts.wantHtml) { | 1866 | indent = 1; |
| 1975 | indent = "&nbsp;&nbsp;&nbsp;&nbsp;"; | | |
| 1976 | } else { | | |
| 1977 | indent = " "; | | |
| 1978 | } | | |
| 1979 | } | 1867 | } |
| 1980 | if (opts.indent) { | 1868 | if (opts.indent) { |
| 1981 | indent = opts.indent + indent; | 1869 | indent += opts.indent; |
| 1982 | } | | |
| 1983 | let field_end = ","; | | |
| 1984 | if (fields_len > 1 && opts.wantHtml) { | | |
| 1985 | field_end += "</br>"; | | |
| 1986 | } else { | | |
| 1987 | field_end += " "; | | |
| 1988 | } | 1870 | } |
| | 1871 | |
| 1989 | for (let i = 0; i < enumNode.fields.length; i += 1) { | 1872 | for (let i = 0; i < enumNode.fields.length; i += 1) { |
| 1990 | let fieldNode = getAstNode(enumNode.fields[i]); | 1873 | let fieldNode = getAstNode(enumNode.fields[i]); |
| 1991 | let fieldName = fieldNode.name; | 1874 | let fieldName = fieldNode.name; |
| 1992 | let html = indent + escapeHtml(fieldName); | 1875 | |
| | 1876 | for (let j = 0; j < indent; j += 1) yield Tok.tab; |
| | 1877 | yield { src: fieldName, tag: Tag.identifier }; |
| 1993 | | 1878 | |
| 1994 | if (enumObj.values[i] !== null) { | 1879 | if (enumObj.values[i] !== null) { |
| 1995 | html += " = " + exprName(enumObj.values[i], opts); | 1880 | yield Tok.space; |
| | 1881 | yield Tok.eql; |
| | 1882 | yield Tok.space; |
| | 1883 | yield* ex(enumObj.values[i], opts); |
| 1996 | } | 1884 | } |
| 1997 | | 1885 | |
| 1998 | html += field_end; | 1886 | if (fields_len > 1) { |
| 1999 | | 1887 | yield Tok.comma; |
| 2000 | name += html; | 1888 | yield Tok.enter; |
| | 1889 | } |
| 2001 | } | 1890 | } |
| 2002 | if (enumObj.nonexhaustive) { | 1891 | for (let j = 0; j < indent; j += 1) yield Tok.tab; |
| 2003 | name += indent + "_" + field_end; | 1892 | yield { src: "_", tag: Tag.identifier }; |
| | 1893 | if (fields_len > 1) { |
| | 1894 | yield Tok.comma; |
| | 1895 | yield Tok.enter; |
| 2004 | } | 1896 | } |
| 2005 | if (opts.indent) { | 1897 | if (opts.indent) { |
| 2006 | name += opts.indent; | 1898 | for (let j = 0; j < opts.indent; j += 1) yield Tok.tab; |
| 2007 | } | 1899 | } |
| 2008 | name += "}"; | 1900 | yield Tok.r_brace; |
| 2009 | return name; | 1901 | return; |
| 2010 | } | 1902 | } |
| 2011 | case typeKinds.Union: { | 1903 | case typeKinds.Union: { |
| 2012 | let unionObj = typeObj; | 1904 | let unionObj = typeObj; |
| 2013 | let name = ""; | | |
| 2014 | let layout = ""; | | |
| 2015 | if (unionObj.layout !== null) { | 1905 | if (unionObj.layout !== null) { |
| 2016 | switch (unionObj.layout.enumLiteral) { | 1906 | switch (unionObj.layout.enumLiteral) { |
| 2017 | case "Packed": { | 1907 | case "Packed": { |
| 2018 | layout = "packed "; | 1908 | yield { src: "packed", tag: Tag.keyword_packed }; |
| 2019 | break; | 1909 | break; |
| 2020 | } | 1910 | } |
| 2021 | case "Extern": { | 1911 | case "Extern": { |
| 2022 | layout = "extern "; | 1912 | yield { src: "extern", tag: Tag.keyword_extern }; |
| 2023 | break; | 1913 | break; |
| 2024 | } | 1914 | } |
| 2025 | } | 1915 | } |
| | 1916 | yield Tok.space; |
| 2026 | } | 1917 | } |
| 2027 | if (opts.wantHtml) { | 1918 | yield { src: "union", tag: Tag.keyword_union }; |
| 2028 | name = "<span class='tok-kw'>" + layout + "union</span>"; | | |
| 2029 | } else { | | |
| 2030 | name = layout + "union"; | | |
| 2031 | } | | |
| 2032 | if (unionObj.auto_tag) { | 1919 | if (unionObj.auto_tag) { |
| 2033 | if (opts.wantHtml) { | 1920 | yield Tok.l_paren; |
| 2034 | name += "(<span class='tok-kw'>enum</span>"; | 1921 | yield { src: "enum", tag: Tag.keyword_enum }; |
| 2035 | } else { | | |
| 2036 | name += "(enum"; | | |
| 2037 | } | | |
| 2038 | if (unionObj.tag) { | 1922 | if (unionObj.tag) { |
| 2039 | name += "(" + exprName(unionObj.tag, opts) + "))"; | 1923 | yield Tok.l_paren; |
| | 1924 | yield* ex(unionObj.tag, opts); |
| | 1925 | yield Tok.r_paren; |
| | 1926 | yield Tok.r_paren; |
| 2040 | } else { | 1927 | } else { |
| 2041 | name += ")"; | 1928 | yield Tok.r_paren; |
| 2042 | } | 1929 | } |
| 2043 | } else if (unionObj.tag) { | 1930 | } else if (unionObj.tag) { |
| 2044 | name += "(" + exprName(unionObj.tag, opts) + ")"; | 1931 | yield Tok.l_paren; |
| | 1932 | yield* ex(unionObj.tag, opts); |
| | 1933 | yield Tok.r_paren; |
| 2045 | } | 1934 | } |
| 2046 | name += " { "; | 1935 | yield Tok.space; |
| 2047 | if (unionObj.field_types.length > 1 && opts.wantHtml) { | 1936 | yield Tok.l_brace; |
| 2048 | name += "</br>"; | 1937 | if (unionObj.field_types.length > 1) { |
| | 1938 | yield Tok.enter; |
| | 1939 | } else { |
| | 1940 | yield Tok.space; |
| 2049 | } | 1941 | } |
| 2050 | let indent = ""; | 1942 | let indent = 0; |
| 2051 | if (unionObj.field_types.length > 1 && opts.wantHtml) { | 1943 | if (unionObj.field_types.length > 1) { |
| 2052 | indent = "&nbsp;&nbsp;&nbsp;&nbsp;" | 1944 | indent = 1; |
| 2053 | } | 1945 | } |
| 2054 | if (opts.indent) { | 1946 | if (opts.indent) { |
| 2055 | indent = opts.indent + indent; | 1947 | indent += opts.indent; |
| 2056 | } | 1948 | } |
| 2057 | let unionNode = getAstNode(unionObj.src); | 1949 | let unionNode = getAstNode(unionObj.src); |
| 2058 | let field_end = ","; | | |
| 2059 | if (unionObj.field_types.length > 1 && opts.wantHtml) { | | |
| 2060 | field_end += "</br>"; | | |
| 2061 | } else { | | |
| 2062 | field_end += " "; | | |
| 2063 | } | | |
| 2064 | for (let i = 0; i < unionObj.field_types.length; i += 1) { | 1950 | for (let i = 0; i < unionObj.field_types.length; i += 1) { |
| 2065 | let fieldNode = getAstNode(unionNode.fields[i]); | 1951 | let fieldNode = getAstNode(unionNode.fields[i]); |
| 2066 | let fieldName = fieldNode.name; | 1952 | let fieldName = fieldNode.name; |
| 2067 | let html = indent + escapeHtml(fieldName); | 1953 | for (let j = 0; j < indent; j += 1) yield Tok.tab; |
| | 1954 | yield { src: fieldName, tag: Tag.identifier }; |
| 2068 | | 1955 | |
| 2069 | let fieldTypeExpr = unionObj.field_types[i]; | 1956 | let fieldTypeExpr = unionObj.field_types[i]; |
| 2070 | html += ": "; | 1957 | yield Tok.colon; |
| | 1958 | yield Tok.space; |
| 2071 | | 1959 | |
| 2072 | html += exprName(fieldTypeExpr, { ...opts, indent: indent }); | 1960 | yield* ex(fieldTypeExpr, { ...opts, indent: indent }); |
| 2073 | | 1961 | |
| 2074 | html += field_end; | 1962 | if (unionObj.field_types.length > 1) { |
| 2075 | | 1963 | yield Tok.comma; |
| 2076 | name += html; | 1964 | yield Tok.enter; |
| | 1965 | } else { |
| | 1966 | yield Tok.space; |
| | 1967 | } |
| 2077 | } | 1968 | } |
| 2078 | if (opts.indent) { | 1969 | if (opts.indent) { |
| 2079 | name += opts.indent; | 1970 | for (let j = 0; j < opts.indent; j += 1) yield Tok.tab; |
| 2080 | } | 1971 | } |
| 2081 | name += "}"; | 1972 | yield Tok.r_brace; |
| 2082 | return name; | 1973 | return; |
| 2083 | } | 1974 | } |
| 2084 | case typeKinds.Opaque: { | 1975 | case typeKinds.Opaque: { |
| 2085 | let opaqueObj = typeObj; | 1976 | yield { src: "opaque", tag: Tag.keyword_opaque }; |
| 2086 | return opaqueObj; | 1977 | yield Tok.space; |
| 2087 | } | 1978 | yield Tok.l_brace; |
| 2088 | case typeKinds.ComptimeExpr: { | 1979 | yield Tok.r_brace; |
| 2089 | return "anyopaque"; | 1980 | return; |
| 2090 | } | | |
| 2091 | case typeKinds.Array: { | | |
| 2092 | let arrayObj = typeObj; | | |
| 2093 | let name = "["; | | |
| 2094 | let lenName = exprName(arrayObj.len, opts); | | |
| 2095 | let sentinel = arrayObj.sentinel | | |
| 2096 | ? ":" + exprName(arrayObj.sentinel, opts) | | |
| 2097 | : ""; | | |
| 2098 | // let is_mutable = arrayObj.is_multable ? "const " : ""; | | |
| 2099 | | | |
| 2100 | if (opts.wantHtml) { | | |
| 2101 | name += | | |
| 2102 | '<span class="tok-number">' + lenName + sentinel + "</span>"; | | |
| 2103 | } else { | | |
| 2104 | name += lenName + sentinel; | | |
| 2105 | } | | |
| 2106 | name += "]"; | | |
| 2107 | // name += is_mutable; | | |
| 2108 | name += exprName(arrayObj.child, opts); | | |
| 2109 | return name; | | |
| 2110 | } | | |
| 2111 | case typeKinds.Optional: | | |
| 2112 | return "?" + exprName(typeObj.child, opts); | | |
| 2113 | case typeKinds.Pointer: { | | |
| 2114 | let ptrObj = typeObj; | | |
| 2115 | let sentinel = ptrObj.sentinel | | |
| 2116 | ? ":" + exprName(ptrObj.sentinel, opts) | | |
| 2117 | : ""; | | |
| 2118 | let is_mutable = !ptrObj.is_mutable ? "const " : ""; | | |
| 2119 | let name = ""; | | |
| 2120 | switch (ptrObj.size) { | | |
| 2121 | default: | | |
| 2122 | console.log("TODO: implement unhandled pointer size case"); | | |
| 2123 | case pointerSizeEnum.One: | | |
| 2124 | name += "*"; | | |
| 2125 | name += is_mutable; | | |
| 2126 | break; | | |
| 2127 | case pointerSizeEnum.Many: | | |
| 2128 | name += "[*"; | | |
| 2129 | name += sentinel; | | |
| 2130 | name += "]"; | | |
| 2131 | name += is_mutable; | | |
| 2132 | break; | | |
| 2133 | case pointerSizeEnum.Slice: | | |
| 2134 | if (ptrObj.is_ref) { | | |
| 2135 | name += "*"; | | |
| 2136 | } | | |
| 2137 | name += "["; | | |
| 2138 | name += sentinel; | | |
| 2139 | name += "]"; | | |
| 2140 | name += is_mutable; | | |
| 2141 | break; | | |
| 2142 | case pointerSizeEnum.C: | | |
| 2143 | name += "[*c"; | | |
| 2144 | name += sentinel; | | |
| 2145 | name += "]"; | | |
| 2146 | name += is_mutable; | | |
| 2147 | break; | | |
| 2148 | } | | |
| 2149 | // @check: after the major changes in arrays the consts are came from switch above | | |
| 2150 | // if (!ptrObj.is_mutable) { | | |
| 2151 | // if (opts.wantHtml) { | | |
| 2152 | // name += '<span class="tok-kw">const</span> '; | | |
| 2153 | // } else { | | |
| 2154 | // name += "const "; | | |
| 2155 | // } | | |
| 2156 | // } | | |
| 2157 | if (ptrObj.is_allowzero) { | | |
| 2158 | name += "allowzero "; | | |
| 2159 | } | | |
| 2160 | if (ptrObj.is_volatile) { | | |
| 2161 | name += "volatile "; | | |
| 2162 | } | | |
| 2163 | if (ptrObj.has_addrspace) { | | |
| 2164 | name += "addrspace("; | | |
| 2165 | name += "." + ""; | | |
| 2166 | name += ") "; | | |
| 2167 | } | | |
| 2168 | if (ptrObj.has_align) { | | |
| 2169 | let align = exprName(ptrObj.align, opts); | | |
| 2170 | if (opts.wantHtml) { | | |
| 2171 | name += '<span class="tok-kw">align</span>('; | | |
| 2172 | } else { | | |
| 2173 | name += "align("; | | |
| 2174 | } | | |
| 2175 | if (opts.wantHtml) { | | |
| 2176 | name += '<span class="tok-number">' + align + "</span>"; | | |
| 2177 | } else { | | |
| 2178 | name += align; | | |
| 2179 | } | | |
| 2180 | if (ptrObj.hostIntBytes != null) { | | |
| 2181 | name += ":"; | | |
| 2182 | if (opts.wantHtml) { | | |
| 2183 | name += | | |
| 2184 | '<span class="tok-number">' + | | |
| 2185 | ptrObj.bitOffsetInHost + | | |
| 2186 | "</span>"; | | |
| 2187 | } else { | | |
| 2188 | name += ptrObj.bitOffsetInHost; | | |
| 2189 | } | | |
| 2190 | name += ":"; | | |
| 2191 | if (opts.wantHtml) { | | |
| 2192 | name += | | |
| 2193 | '<span class="tok-number">' + | | |
| 2194 | ptrObj.hostIntBytes + | | |
| 2195 | "</span>"; | | |
| 2196 | } else { | | |
| 2197 | name += ptrObj.hostIntBytes; | | |
| 2198 | } | | |
| 2199 | } | | |
| 2200 | name += ") "; | | |
| 2201 | } | | |
| 2202 | //name += typeValueName(ptrObj.child, wantHtml, wantSubLink, null); | | |
| 2203 | name += exprName(ptrObj.child, opts); | | |
| 2204 | return name; | | |
| 2205 | } | | |
| 2206 | case typeKinds.Float: { | | |
| 2207 | let floatObj = typeObj; | | |
| 2208 | | | |
| 2209 | if (opts.wantHtml) { | | |
| 2210 | return '<span class="tok-type">' + floatObj.name + "</span>"; | | |
| 2211 | } else { | | |
| 2212 | return floatObj.name; | | |
| 2213 | } | | |
| 2214 | } | 1981 | } |
| 2215 | case typeKinds.Int: { | 1982 | case typeKinds.EnumLiteral: { |
| 2216 | let intObj = typeObj; | 1983 | yield { src: "(enum literal)", tag: Tag.identifier }; |
| 2217 | let name = intObj.name; | 1984 | return; |
| 2218 | if (opts.wantHtml) { | | |
| 2219 | return '<span class="tok-type">' + name + "</span>"; | | |
| 2220 | } else { | | |
| 2221 | return name; | | |
| 2222 | } | | |
| 2223 | } | 1985 | } |
| 2224 | case typeKinds.ComptimeInt: | | |
| 2225 | if (opts.wantHtml) { | | |
| 2226 | return '<span class="tok-type">comptime_int</span>'; | | |
| 2227 | } else { | | |
| 2228 | return "comptime_int"; | | |
| 2229 | } | | |
| 2230 | case typeKinds.ComptimeFloat: | | |
| 2231 | if (opts.wantHtml) { | | |
| 2232 | return '<span class="tok-type">comptime_float</span>'; | | |
| 2233 | } else { | | |
| 2234 | return "comptime_float"; | | |
| 2235 | } | | |
| 2236 | case typeKinds.Type: | | |
| 2237 | if (opts.wantHtml) { | | |
| 2238 | return '<span class="tok-type">type</span>'; | | |
| 2239 | } else { | | |
| 2240 | return "type"; | | |
| 2241 | } | | |
| 2242 | case typeKinds.Bool: | | |
| 2243 | if (opts.wantHtml) { | | |
| 2244 | return '<span class="tok-type">bool</span>'; | | |
| 2245 | } else { | | |
| 2246 | return "bool"; | | |
| 2247 | } | | |
| 2248 | case typeKinds.Void: | | |
| 2249 | if (opts.wantHtml) { | | |
| 2250 | return '<span class="tok-type">void</span>'; | | |
| 2251 | } else { | | |
| 2252 | return "void"; | | |
| 2253 | } | | |
| 2254 | case typeKinds.EnumLiteral: | | |
| 2255 | if (opts.wantHtml) { | | |
| 2256 | return '<span class="tok-type">(enum literal)</span>'; | | |
| 2257 | } else { | | |
| 2258 | return "(enum literal)"; | | |
| 2259 | } | | |
| 2260 | case typeKinds.NoReturn: | | |
| 2261 | if (opts.wantHtml) { | | |
| 2262 | return '<span class="tok-type">noreturn</span>'; | | |
| 2263 | } else { | | |
| 2264 | return "noreturn"; | | |
| 2265 | } | | |
| 2266 | case typeKinds.ErrorSet: { | 1986 | case typeKinds.ErrorSet: { |
| 2267 | let errSetObj = typeObj; | 1987 | let errSetObj = typeObj; |
| 2268 | if (errSetObj.fields == null) { | 1988 | if (errSetObj.fields === null) { |
| 2269 | return '<span class="tok-type">anyerror</span>'; | 1989 | yield { src: "anyerror", tag: Tag.identifier }; |
| 2270 | } else if (errSetObj.fields.length == 0) { | 1990 | } else if (errSetObj.fields.length == 0) { |
| 2271 | return "error{}"; | 1991 | yield { src: "error", tag: Tag.keyword_error }; |
| | 1992 | yield Tok.l_brace; |
| | 1993 | yield Tok.r_brace; |
| 2272 | } else if (errSetObj.fields.length == 1) { | 1994 | } else if (errSetObj.fields.length == 1) { |
| 2273 | return "error{" + errSetObj.fields[0].name + "}"; | 1995 | yield { src: "error", tag: Tag.keyword_error }; |
| | 1996 | yield Tok.l_brace; |
| | 1997 | yield { src: errSetObj.fields[0].name, tag: Tag.identifier }; |
| | 1998 | yield Tok.r_brace; |
| 2274 | } else { | 1999 | } else { |
| 2275 | // throw "TODO"; | 2000 | yield { src: "error", tag: Tag.keyword_error }; |
| 2276 | let html = "error{ " + errSetObj.fields[0].name; | 2001 | yield Tok.l_brace; |
| 2277 | for (let i = 1; i < errSetObj.fields.length; i++) html += ", " + errSetObj.fields[i].name; | 2002 | yield { src: errSetObj.fields[0].name, tag: Tag.identifier }; |
| 2278 | html += " }"; | 2003 | for (let i = 1; i < errSetObj.fields.length; i++) { |
| 2279 | return html; | 2004 | yield Tok.comma; |
| | 2005 | yield Tok.space; |
| | 2006 | yield { src: errSetObj.fields[i].name, tag: Tag.identifier }; |
| | 2007 | } |
| | 2008 | yield Tok.r_brace; |
| 2280 | } | 2009 | } |
| | 2010 | return; |
| 2281 | } | 2011 | } |
| 2282 | | | |
| 2283 | case typeKinds.ErrorUnion: { | 2012 | case typeKinds.ErrorUnion: { |
| 2284 | let errUnionObj = typeObj; | 2013 | let errUnionObj = typeObj; |
| 2285 | let lhs = exprName(errUnionObj.lhs, opts); | 2014 | yield* ex(errUnionObj.lhs, opts); |
| 2286 | let rhs = exprName(errUnionObj.rhs, opts); | 2015 | yield { src: "!", tag: Tag.bang }; |
| 2287 | return lhs + "!" + rhs; | 2016 | yield* ex(errUnionObj.rhs, opts); |
| | 2017 | return; |
| 2288 | } | 2018 | } |
| 2289 | case typeKinds.InferredErrorUnion: { | 2019 | case typeKinds.InferredErrorUnion: { |
| 2290 | let errUnionObj = typeObj; | 2020 | let errUnionObj = typeObj; |
| 2291 | let payload = exprName(errUnionObj.payload, opts); | 2021 | yield { src: "!", tag: Tag.bang }; |
| 2292 | return "!" + payload; | 2022 | yield* ex(errUnionObj.payload, opts); |
| | 2023 | return; |
| 2293 | } | 2024 | } |
| 2294 | case typeKinds.Fn: { | 2025 | case typeKinds.Fn: { |
| 2295 | let fnObj = typeObj; | 2026 | let fnObj = typeObj; |
| ... | @@ -2299,45 +2030,32 @@ Happy writing! | ... | @@ -2299,45 +2030,32 @@ Happy writing! |
| 2299 | opts.linkFnNameDecl = null; | 2030 | opts.linkFnNameDecl = null; |
| 2300 | let payloadHtml = ""; | 2031 | let payloadHtml = ""; |
| 2301 | if (opts.addParensIfFnSignature && fnObj.src == 0) { | 2032 | if (opts.addParensIfFnSignature && fnObj.src == 0) { |
| 2302 | payloadHtml += "("; | 2033 | yield Tok.l_paren; |
| 2303 | } | 2034 | } |
| 2304 | if (fnObj.is_extern) { | 2035 | if (fnObj.is_extern) { |
| 2305 | if (opts.wantHtml) { | 2036 | yield { src: "extern", tag: Tag.keyword_extern }; |
| 2306 | payloadHtml += '<span class="tok-kw">extern </span>'; | 2037 | yield Tok.space; |
| 2307 | } else { | | |
| 2308 | payloadHtml += "extern "; | | |
| 2309 | } | | |
| 2310 | } else if (fnObj.has_cc) { | 2038 | } else if (fnObj.has_cc) { |
| 2311 | let cc_expr = zigAnalysis.exprs[fnObj.cc]; | 2039 | let cc_expr = zigAnalysis.exprs[fnObj.cc]; |
| 2312 | if (cc_expr.enumLiteral === "Inline") { | 2040 | if (cc_expr.enumLiteral === "Inline") { |
| 2313 | if(opts.wantHtml) { | 2041 | yield { src: "inline", tag: Tag.keyword_inline }; |
| 2314 | payloadHtml += '<span class="tok-kw">inline </span>' | 2042 | yield Tok.space; |
| 2315 | } else { | | |
| 2316 | payloadHtml += "inline " | | |
| 2317 | } | | |
| 2318 | } | 2043 | } |
| 2319 | } | 2044 | } |
| 2320 | if (fnObj.has_lib_name) { | 2045 | if (fnObj.has_lib_name) { |
| 2321 | payloadHtml += '"' + fnObj.lib_name + '" '; | 2046 | yield { src: '"' + fnObj.lib_name + '"', tag: Tag.string_literal }; |
| | 2047 | yield Tok.space; |
| 2322 | } | 2048 | } |
| 2323 | if (opts.wantHtml) { | 2049 | yield { src: "fn", tag: Tag.keyword_fn }; |
| 2324 | payloadHtml += '<span class="tok-kw">fn </span>'; | 2050 | yield Tok.space; |
| 2325 | if (fnDecl) { | 2051 | if (fnDecl) { |
| 2326 | payloadHtml += '<span class="tok-fn">'; | 2052 | if (linkFnNameDecl) { |
| 2327 | if (linkFnNameDecl) { | 2053 | yield { src: fnDecl.name, tag: Tag.identifier, link: linkFnNameDecl, fnDecl: false }; |
| 2328 | payloadHtml += | 2054 | } else { |
| 2329 | '<a href="' + linkFnNameDecl + '">' + | 2055 | yield { src: fnDecl.name, tag: Tag.identifier, fnDecl: true }; |
| 2330 | escapeHtml(fnDecl.name) + | | |
| 2331 | "</a>"; | | |
| 2332 | } else { | | |
| 2333 | payloadHtml += escapeHtml(fnDecl.name); | | |
| 2334 | } | | |
| 2335 | payloadHtml += "</span>"; | | |
| 2336 | } | 2056 | } |
| 2337 | } else { | | |
| 2338 | payloadHtml += "fn "; | | |
| 2339 | } | 2057 | } |
| 2340 | payloadHtml += "("; | 2058 | yield Tok.l_paren; |
| 2341 | if (fnObj.params) { | 2059 | if (fnObj.params) { |
| 2342 | let fields = null; | 2060 | let fields = null; |
| 2343 | let isVarArgs = false; | 2061 | let isVarArgs = false; |
| ... | @@ -2349,13 +2067,10 @@ Happy writing! | ... | @@ -2349,13 +2067,10 @@ Happy writing! |
| 2349 | | 2067 | |
| 2350 | for (let i = 0; i < fnObj.params.length; i += 1) { | 2068 | for (let i = 0; i < fnObj.params.length; i += 1) { |
| 2351 | if (i != 0) { | 2069 | if (i != 0) { |
| 2352 | payloadHtml += ", "; | 2070 | yield Tok.comma; |
| | 2071 | yield Tok.space; |
| 2353 | } | 2072 | } |
| 2354 | | 2073 | |
| 2355 | if (opts.wantHtml) { | | |
| 2356 | payloadHtml += | | |
| 2357 | "<span class='argBreaker'><br>&nbsp;&nbsp;&nbsp;&nbsp;</span>"; | | |
| 2358 | } | | |
| 2359 | let value = fnObj.params[i]; | 2074 | let value = fnObj.params[i]; |
| 2360 | let paramValue = resolveValue({ expr: value }); | 2075 | let paramValue = resolveValue({ expr: value }); |
| 2361 | | 2076 | |
| ... | @@ -2363,24 +2078,20 @@ Happy writing! | ... | @@ -2363,24 +2078,20 @@ Happy writing! |
| 2363 | let paramNode = getAstNode(fields[i]); | 2078 | let paramNode = getAstNode(fields[i]); |
| 2364 | | 2079 | |
| 2365 | if (paramNode.varArgs) { | 2080 | if (paramNode.varArgs) { |
| 2366 | payloadHtml += "..."; | 2081 | yield Tok.period; |
| | 2082 | yield Tok.period; |
| | 2083 | yield Tok.period; |
| 2367 | continue; | 2084 | continue; |
| 2368 | } | 2085 | } |
| 2369 | | 2086 | |
| 2370 | if (paramNode.noalias) { | 2087 | if (paramNode.noalias) { |
| 2371 | if (opts.wantHtml) { | 2088 | yield { src: "noalias", tag: Tag.keyword_noalias }; |
| 2372 | payloadHtml += '<span class="tok-kw">noalias</span> '; | 2089 | yield Tok.space; |
| 2373 | } else { | | |
| 2374 | payloadHtml += "noalias "; | | |
| 2375 | } | | |
| 2376 | } | 2090 | } |
| 2377 | | 2091 | |
| 2378 | if (paramNode.comptime) { | 2092 | if (paramNode.comptime) { |
| 2379 | if (opts.wantHtml) { | 2093 | yield { src: "comptime", tag: Tag.keyword_comptime }; |
| 2380 | payloadHtml += '<span class="tok-kw">comptime</span> '; | 2094 | yield Tok.space; |
| 2381 | } else { | | |
| 2382 | payloadHtml += "comptime "; | | |
| 2383 | } | | |
| 2384 | } | 2095 | } |
| 2385 | | 2096 | |
| 2386 | let paramName = paramNode.name; | 2097 | let paramName = paramNode.name; |
| ... | @@ -2390,94 +2101,102 @@ Happy writing! | ... | @@ -2390,94 +2101,102 @@ Happy writing! |
| 2390 | if (paramName === "") { | 2101 | if (paramName === "") { |
| 2391 | paramName = "_"; | 2102 | paramName = "_"; |
| 2392 | } | 2103 | } |
| 2393 | payloadHtml += paramName + ": "; | 2104 | yield { src: paramName, tag: Tag.identifier }; |
| | 2105 | yield Tok.colon; |
| | 2106 | yield Tok.space; |
| 2394 | } | 2107 | } |
| 2395 | } | 2108 | } |
| 2396 | } | 2109 | } |
| 2397 | | 2110 | |
| 2398 | if (isVarArgs && i === fnObj.params.length - 1) { | 2111 | if (isVarArgs && i === fnObj.params.length - 1) { |
| 2399 | payloadHtml += "..."; | 2112 | yield Tok.period; |
| | 2113 | yield Tok.period; |
| | 2114 | yield Tok.period; |
| 2400 | } else if ("alignOf" in value) { | 2115 | } else if ("alignOf" in value) { |
| 2401 | payloadHtml += exprName(value, opts); | 2116 | yield* ex(value, opts); |
| 2402 | } else if ("typeOf" in value) { | 2117 | } else if ("typeOf" in value) { |
| 2403 | payloadHtml += exprName(value, opts); | 2118 | yield* ex(value, opts); |
| 2404 | } else if ("typeOf_peer" in value) { | 2119 | } else if ("typeOf_peer" in value) { |
| 2405 | payloadHtml += exprName(value, opts); | 2120 | yield* ex(value, opts); |
| 2406 | } else if ("declRef" in value) { | 2121 | } else if ("declRef" in value) { |
| 2407 | payloadHtml += exprName(value, opts); | 2122 | yield* ex(value, opts); |
| 2408 | } else if ("call" in value) { | 2123 | } else if ("call" in value) { |
| 2409 | payloadHtml += exprName(value, opts); | 2124 | yield* ex(value, opts); |
| 2410 | } else if ("refPath" in value) { | 2125 | } else if ("refPath" in value) { |
| 2411 | payloadHtml += exprName(value, opts); | 2126 | yield* ex(value, opts); |
| 2412 | } else if ("type" in value) { | 2127 | } else if ("type" in value) { |
| 2413 | payloadHtml += exprName(value, opts); | 2128 | yield* ex(value, opts); |
| 2414 | //payloadHtml += '<span class="tok-kw">' + name + "</span>"; | 2129 | //payloadHtml += '<span class="tok-kw">' + name + "</span>"; |
| 2415 | } else if ("binOpIndex" in value) { | 2130 | } else if ("binOpIndex" in value) { |
| 2416 | payloadHtml += exprName(value, opts); | 2131 | yield* ex(value, opts); |
| 2417 | } else if ("comptimeExpr" in value) { | 2132 | } else if ("comptimeExpr" in value) { |
| 2418 | let comptimeExpr = | 2133 | let comptimeExpr = |
| 2419 | zigAnalysis.comptimeExprs[value.comptimeExpr].code; | 2134 | zigAnalysis.comptimeExprs[value.comptimeExpr].code; |
| 2420 | if (opts.wantHtml) { | 2135 | yield* Tokenizer(comptimeExpr); |
| 2421 | payloadHtml += | | |
| 2422 | '<span class="tok-kw">' + comptimeExpr + "</span>"; | | |
| 2423 | } else { | | |
| 2424 | payloadHtml += comptimeExpr; | | |
| 2425 | } | | |
| 2426 | } else if (opts.wantHtml) { | | |
| 2427 | payloadHtml += '<span class="tok-kw">anytype</span>'; | | |
| 2428 | } else { | 2136 | } else { |
| 2429 | payloadHtml += "anytype"; | 2137 | yield { src: "anytype", tag: Tag.keyword_anytype }; |
| 2430 | } | 2138 | } |
| 2431 | } | 2139 | } |
| 2432 | } | 2140 | } |
| 2433 | | 2141 | |
| 2434 | if (opts.wantHtml) { | 2142 | yield Tok.r_paren; |
| 2435 | payloadHtml += "<span class='argBreaker'>,<br></span>"; | 2143 | yield Tok.space; |
| 2436 | } | | |
| 2437 | payloadHtml += ") "; | | |
| 2438 | | 2144 | |
| 2439 | if (fnObj.has_align) { | 2145 | if (fnObj.has_align) { |
| 2440 | let align = zigAnalysis.exprs[fnObj.align]; | 2146 | let align = zigAnalysis.exprs[fnObj.align]; |
| 2441 | payloadHtml += "align(" + exprName(align, opts) + ") "; | 2147 | yield { src: "align", tag: Tag.keyword_align }; |
| | 2148 | yield Tok.l_paren; |
| | 2149 | yield* ex(align, opts); |
| | 2150 | yield Tok.r_paren; |
| | 2151 | yield Tok.space; |
| 2442 | } | 2152 | } |
| 2443 | if (fnObj.has_cc) { | 2153 | if (fnObj.has_cc) { |
| 2444 | let cc = zigAnalysis.exprs[fnObj.cc]; | 2154 | let cc = zigAnalysis.exprs[fnObj.cc]; |
| 2445 | if (cc) { | 2155 | if (cc) { |
| 2446 | if (cc.enumLiteral !== "Inline") { | 2156 | if (cc.enumLiteral !== "Inline") { |
| 2447 | payloadHtml += "callconv(" + exprName(cc, opts) + ") "; | 2157 | yield { src: "collconv", tag: Tag.keyword_callconv }; |
| | 2158 | yield Tok.l_paren; |
| | 2159 | yield* ex(cc, opts); |
| | 2160 | yield Tok.r_paren; |
| | 2161 | yield Tok.space; |
| 2448 | } | 2162 | } |
| 2449 | } | 2163 | } |
| 2450 | } | 2164 | } |
| 2451 | | 2165 | |
| 2452 | if (fnObj.is_inferred_error) { | 2166 | if (fnObj.is_inferred_error) { |
| 2453 | payloadHtml += "!"; | 2167 | yield { src: "!", tag: Tag.bang }; |
| 2454 | } | 2168 | } |
| 2455 | if (fnObj.ret != null) { | 2169 | if (fnObj.ret != null) { |
| 2456 | payloadHtml += exprName(fnObj.ret, { | 2170 | yield* ex(fnObj.ret, { |
| 2457 | ...opts, | 2171 | ...opts, |
| 2458 | addParensIfFnSignature: true, | 2172 | addParensIfFnSignature: true, |
| 2459 | }); | 2173 | }); |
| 2460 | } else if (opts.wantHtml) { | | |
| 2461 | payloadHtml += '<span class="tok-kw">anytype</span>'; | | |
| 2462 | } else { | 2174 | } else { |
| 2463 | payloadHtml += "anytype"; | 2175 | yield { src: "anytype", tag: Tag.keyword_anytype }; |
| 2464 | } | 2176 | } |
| 2465 | | 2177 | |
| 2466 | if (opts.addParensIfFnSignature && fnObj.src == 0) { | 2178 | if (opts.addParensIfFnSignature && fnObj.src == 0) { |
| 2467 | payloadHtml += ")"; | 2179 | yield Tok.r_paren; |
| 2468 | } | 2180 | } |
| 2469 | return payloadHtml; | 2181 | return; |
| 2470 | } | 2182 | } |
| 2471 | // if (wantHtml) { | | |
| 2472 | // return escapeHtml(typeObj.name); | | |
| 2473 | // } else { | | |
| 2474 | // return typeObj.name; | | |
| 2475 | // } | | |
| 2476 | } | 2183 | } |
| 2477 | } | 2184 | } |
| | 2185 | case "typeOf": { |
| | 2186 | const typeRefArg = zigAnalysis.exprs[expr.typeOf]; |
| | 2187 | yield { src: "@TypeOf", tag: Tag.builtin }; |
| | 2188 | yield Tok.l_paren; |
| | 2189 | yield* ex(typeRefArg, opts); |
| | 2190 | yield Tok.r_paren; |
| | 2191 | return; |
| | 2192 | } |
| 2478 | } | 2193 | } |
| | 2194 | |
| | 2195 | |
| 2479 | } | 2196 | } |
| 2480 | | 2197 | |
| | 2198 | |
| | 2199 | |
| 2481 | function shouldSkipParamName(typeRef, paramName) { | 2200 | function shouldSkipParamName(typeRef, paramName) { |
| 2482 | let resolvedTypeRef = resolveValue({ expr: typeRef }); | 2201 | let resolvedTypeRef = resolveValue({ expr: typeRef }); |
| 2483 | if ("type" in resolvedTypeRef) { | 2202 | if ("type" in resolvedTypeRef) { |
| ... | @@ -2504,13 +2223,13 @@ Happy writing! | ... | @@ -2504,13 +2223,13 @@ Happy writing! |
| 2504 | typeObj === | 2223 | typeObj === |
| 2505 | getType(zigAnalysis.modules[zigAnalysis.rootMod].main) | 2224 | getType(zigAnalysis.modules[zigAnalysis.rootMod].main) |
| 2506 | ) { | 2225 | ) { |
| 2507 | name = "std"; | 2226 | name = renderSingleToken(Tok.identifier("std")); |
| 2508 | } else { | 2227 | } else { |
| 2509 | name = exprName({ type: typeObj }, { wantHtml: false, wantLink: false }); | 2228 | name = renderTokens(ex({ type: typeObj })); |
| 2510 | } | 2229 | } |
| 2511 | if (name != null && name != "") { | 2230 | if (name != null && name != "") { |
| 2512 | domHdrName.innerText = | 2231 | domHdrName.innerHTML = "<pre class='inline'>" + name + "</pre> (" |
| 2513 | name + " (" + zigAnalysis.typeKinds[typeObj.kind] + ")"; | 2232 | + zigAnalysis.typeKinds[typeObj.kind] + ")"; |
| 2514 | domHdrName.classList.remove("hidden"); | 2233 | domHdrName.classList.remove("hidden"); |
| 2515 | } | 2234 | } |
| 2516 | if (typeObj.kind == typeKinds.ErrorSet) { | 2235 | if (typeObj.kind == typeKinds.ErrorSet) { |
| ... | @@ -2528,7 +2247,7 @@ Happy writing! | ... | @@ -2528,7 +2247,7 @@ Happy writing! |
| 2528 | //let srcObj = zigAnalysis.astNodes[errObj.src]; | 2247 | //let srcObj = zigAnalysis.astNodes[errObj.src]; |
| 2529 | errorList.push(errObj); | 2248 | errorList.push(errObj); |
| 2530 | } | 2249 | } |
| 2531 | errorList.sort(function (a, b) { | 2250 | errorList.sort(function(a, b) { |
| 2532 | return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase()); | 2251 | return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase()); |
| 2533 | }); | 2252 | }); |
| 2534 | | 2253 | |
| ... | @@ -2624,55 +2343,80 @@ Happy writing! | ... | @@ -2624,55 +2343,80 @@ Happy writing! |
| 2624 | if (resolvedValue.expr.fieldRef) { | 2343 | if (resolvedValue.expr.fieldRef) { |
| 2625 | const declRef = decl.value.expr.refPath[0].declRef; | 2344 | const declRef = decl.value.expr.refPath[0].declRef; |
| 2626 | const type = getDecl(declRef); | 2345 | const type = getDecl(declRef); |
| 2627 | domFnProtoCode.innerHTML = | 2346 | |
| 2628 | '<span class="tok-kw">const</span> ' + | 2347 | domFnProtoCode.innerHTML = renderTokens( |
| 2629 | escapeHtml(decl.name) + | 2348 | (function*() { |
| 2630 | ": " + | 2349 | yield Tok.const; |
| 2631 | type.name + | 2350 | yield Tok.space; |
| 2632 | " = " + | 2351 | yield Tok.identifier(decl.name); |
| 2633 | exprName(decl.value.expr, { wantHtml: true, wantLink: true }) + | 2352 | yield Tok.colon; |
| 2634 | ";"; | 2353 | yield Tok.space; |
| | 2354 | yield Tok.identifier(type.name); |
| | 2355 | yield Tok.space; |
| | 2356 | yield Tok.eql; |
| | 2357 | yield Tok.space; |
| | 2358 | yield* ex(decl.value.expr, {}); |
| | 2359 | yield Tok.semi; |
| | 2360 | })()); |
| 2635 | } else if ( | 2361 | } else if ( |
| 2636 | resolvedValue.expr.string !== undefined || | 2362 | resolvedValue.expr.string !== undefined || |
| 2637 | resolvedValue.expr.call !== undefined || | 2363 | resolvedValue.expr.call !== undefined || |
| 2638 | resolvedValue.expr.comptimeExpr !== undefined | 2364 | resolvedValue.expr.comptimeExpr !== undefined |
| 2639 | ) { | 2365 | ) { |
| 2640 | let typeRef = null; | 2366 | domFnProtoCode.innerHTML = renderTokens( |
| 2641 | if (resolvedValue.typeRef !== undefined) { | 2367 | (function*() { |
| 2642 | typeRef = resolvedValue.typeRef; | 2368 | yield Tok.const; |
| 2643 | } | 2369 | yield Tok.space; |
| 2644 | domFnProtoCode.innerHTML = | 2370 | yield Tok.identifier(decl.name); |
| 2645 | '<span class="tok-kw">const</span> ' + | 2371 | if (decl.value.typeRef) { |
| 2646 | escapeHtml(decl.name) + | 2372 | yield Tok.colon; |
| 2647 | ": " + | 2373 | yield Tok.space; |
| 2648 | exprName(typeRef !== null ? typeRef : resolvedValue.expr, { wantHtml: true, wantLink: true }) + | 2374 | yield* ex(decl.value.typeRef, {}); |
| 2649 | " = " + | 2375 | } |
| 2650 | exprName(decl.value.expr, { wantHtml: true, wantLink: true }) + | 2376 | yield Tok.space; |
| 2651 | ";"; | 2377 | yield Tok.eql; |
| | 2378 | yield Tok.space; |
| | 2379 | yield* ex(decl.value.expr, {}); |
| | 2380 | yield Tok.semi; |
| | 2381 | })()); |
| 2652 | } else if (resolvedValue.expr.compileError) { | 2382 | } else if (resolvedValue.expr.compileError) { |
| 2653 | domFnProtoCode.innerHTML = | 2383 | domFnProtoCode.innerHTML = renderTokens( |
| 2654 | '<span class="tok-kw">const</span> ' + | 2384 | (function*() { |
| 2655 | escapeHtml(decl.name) + | 2385 | yield Tok.const; |
| 2656 | " = " + | 2386 | yield Tok.space; |
| 2657 | exprName(decl.value.expr, { wantHtml: true, wantLink: true }) + | 2387 | yield Tok.identifier(decl.name); |
| 2658 | ";"; | 2388 | yield Tok.space; |
| | 2389 | yield Tok.eql; |
| | 2390 | yield Tok.space; |
| | 2391 | yield* ex(decl.value.expr, {}); |
| | 2392 | yield Tok.semi; |
| | 2393 | })()); |
| 2659 | } else { | 2394 | } else { |
| 2660 | domFnProtoCode.innerHTML = | 2395 | const parent = getType(decl.parent_container); |
| 2661 | '<span class="tok-kw">const</span> ' + | 2396 | domFnProtoCode.innerHTML = renderTokens( |
| 2662 | escapeHtml(decl.name) + | 2397 | (function*() { |
| 2663 | ": " + | 2398 | yield Tok.const; |
| 2664 | exprName(resolvedValue.typeRef, { wantHtml: true, wantLink: true }) + | 2399 | yield Tok.space; |
| 2665 | " = " + | 2400 | yield Tok.identifier(decl.name); |
| 2666 | exprName(decl.value.expr, { wantHtml: true, wantLink: true }) + | 2401 | if (decl.value.typeRef !== null) { |
| 2667 | ";"; | 2402 | yield Tok.colon; |
| | 2403 | yield Tok.space; |
| | 2404 | yield* ex(decl.value.typeRef, {}); |
| | 2405 | } |
| | 2406 | yield Tok.space; |
| | 2407 | yield Tok.eql; |
| | 2408 | yield Tok.space; |
| | 2409 | yield* ex(decl.value.expr, {}); |
| | 2410 | yield Tok.semi; |
| | 2411 | })()); |
| 2668 | } | 2412 | } |
| 2669 | | 2413 | |
| 2670 | let docs = getAstNode(decl.src).docs; | 2414 | let docs = getAstNode(decl.src).docs; |
| 2671 | if (docs != null) { | 2415 | if (docs != null) { |
| 2672 | // TODO: it shouldn't just be decl.parent_container, but rather | 2416 | // TODO: it shouldn't just be decl.parent_container, but rather |
| 2673 | // the type that the decl holds (if the value is a type) | 2417 | // the type that the decl holds (if the value is a type) |
| 2674 | domTldDocs.innerHTML = markdown(docs, getType(decl.parent_container)); | 2418 | domTldDocs.innerHTML = markdown(docs, decl); |
| 2675 | | 2419 | |
| 2676 | domTldDocs.classList.remove("hidden"); | 2420 | domTldDocs.classList.remove("hidden"); |
| 2677 | } | 2421 | } |
| 2678 | | 2422 | |
| ... | @@ -2685,43 +2429,68 @@ Happy writing! | ... | @@ -2685,43 +2429,68 @@ Happy writing! |
| 2685 | if (resolvedVar.expr.fieldRef) { | 2429 | if (resolvedVar.expr.fieldRef) { |
| 2686 | const declRef = decl.value.expr.refPath[0].declRef; | 2430 | const declRef = decl.value.expr.refPath[0].declRef; |
| 2687 | const type = getDecl(declRef); | 2431 | const type = getDecl(declRef); |
| 2688 | domFnProtoCode.innerHTML = | 2432 | domFnProtoCode.innerHTML = renderTokens( |
| 2689 | '<span class="tok-kw">var</span> ' + | 2433 | (function*() { |
| 2690 | escapeHtml(decl.name) + | 2434 | yield Tok.var; |
| 2691 | ": " + | 2435 | yield Tok.space; |
| 2692 | type.name + | 2436 | yield Tok.identifier(decl.name); |
| 2693 | " = " + | 2437 | yield Tok.colon; |
| 2694 | exprName(decl.value.expr, { wantHtml: true, wantLink: true }) + | 2438 | yield Tok.space; |
| 2695 | ";"; | 2439 | yield Tok.identifier(type.name); |
| | 2440 | yield Tok.space; |
| | 2441 | yield Tok.eql; |
| | 2442 | yield Tok.space; |
| | 2443 | yield* ex(decl.value.expr, {}); |
| | 2444 | yield Tok.semi; |
| | 2445 | })()); |
| 2696 | } else if ( | 2446 | } else if ( |
| 2697 | resolvedVar.expr.string !== undefined || | 2447 | resolvedVar.expr.string !== undefined || |
| 2698 | resolvedVar.expr.call !== undefined || | 2448 | resolvedVar.expr.call !== undefined || |
| 2699 | resolvedVar.expr.comptimeExpr !== undefined | 2449 | resolvedVar.expr.comptimeExpr !== undefined |
| 2700 | ) { | 2450 | ) { |
| 2701 | domFnProtoCode.innerHTML = | 2451 | domFnProtoCode.innerHTML = renderTokens( |
| 2702 | '<span class="tok-kw">var</span> ' + | 2452 | (function*() { |
| 2703 | escapeHtml(decl.name) + | 2453 | yield Tok.var; |
| 2704 | ": " + | 2454 | yield Tok.space; |
| 2705 | exprName(resolvedVar.typeRef !== null ? resolvedVar.typeRef : resolvedVar.expr, { wantHtml: true, wantLink: true }) + | 2455 | yield Tok.identifier(decl.name); |
| 2706 | " = " + | 2456 | if (decl.value.typeRef) { |
| 2707 | exprName(decl.value.expr, { wantHtml: true, wantLink: true }) + | 2457 | yield Tok.colon; |
| 2708 | ";"; | 2458 | yield Tok.space; |
| | 2459 | yield* ex(decl.value.typeRef, {}); |
| | 2460 | } |
| | 2461 | yield Tok.space; |
| | 2462 | yield Tok.eql; |
| | 2463 | yield Tok.space; |
| | 2464 | yield* ex(decl.value.expr, {}); |
| | 2465 | yield Tok.semi; |
| | 2466 | })()); |
| 2709 | } else if (resolvedVar.expr.compileError) { | 2467 | } else if (resolvedVar.expr.compileError) { |
| 2710 | domFnProtoCode.innerHTML = | 2468 | domFnProtoCode.innerHTML = renderTokens( |
| 2711 | '<span class="tok-kw">var</span> ' + | 2469 | (function*() { |
| 2712 | escapeHtml(decl.name) + | 2470 | yield Tok.var; |
| 2713 | " = " + | 2471 | yield Tok.space; |
| 2714 | exprName(decl.value.expr, { wantHtml: true, wantLink: true }) + | 2472 | yield Tok.identifier(decl.name); |
| 2715 | ";"; | 2473 | yield Tok.space; |
| | 2474 | yield Tok.eql; |
| | 2475 | yield Tok.space; |
| | 2476 | yield* ex(decl.value.expr, {}); |
| | 2477 | yield Tok.semi; |
| | 2478 | })()); |
| 2716 | } else { | 2479 | } else { |
| 2717 | domFnProtoCode.innerHTML = | 2480 | domFnProtoCode.innerHTML = renderTokens( |
| 2718 | '<span class="tok-kw">var</span> ' + | 2481 | (function*() { |
| 2719 | escapeHtml(decl.name) + | 2482 | yield Tok.var; |
| 2720 | ": " + | 2483 | yield Tok.space; |
| 2721 | exprName(resolvedVar.typeRef, { wantHtml: true, wantLink: true }) + | 2484 | yield Tok.identifier(decl.name); |
| 2722 | " = " + | 2485 | yield Tok.colon; |
| 2723 | exprName(decl.value.expr, { wantHtml: true, wantLink: true }) + | 2486 | yield Tok.space; |
| 2724 | ";"; | 2487 | yield* ex(resolvedVar.typeRef, {}); |
| | 2488 | yield Tok.space; |
| | 2489 | yield Tok.eql; |
| | 2490 | yield Tok.space; |
| | 2491 | yield* ex(decl.value.expr, {}); |
| | 2492 | yield Tok.semi; |
| | 2493 | })()); |
| 2725 | } | 2494 | } |
| 2726 | | 2495 | |
| 2727 | let docs = getAstNode(decl.src).docs; | 2496 | let docs = getAstNode(decl.src).docs; |
| ... | @@ -2955,7 +2724,7 @@ Happy writing! | ... | @@ -2955,7 +2724,7 @@ Happy writing! |
| 2955 | resizeDomList( | 2724 | resizeDomList( |
| 2956 | domListFns, | 2725 | domListFns, |
| 2957 | fnsList.length, | 2726 | fnsList.length, |
| 2958 | "<div><dt><div class=\"fnSignature\"></div><div></div></dt><dd></dd></div>" | 2727 | '<div><dt><pre class="inline fnSignature"></pre><div></div></dt><dd></dd></div>' |
| 2959 | ); | 2728 | ); |
| 2960 | | 2729 | |
| 2961 | for (let i = 0; i < fnsList.length; i += 1) { | 2730 | for (let i = 0; i < fnsList.length; i += 1) { |
| ... | @@ -2968,12 +2737,10 @@ Happy writing! | ... | @@ -2968,12 +2737,10 @@ Happy writing! |
| 2968 | | 2737 | |
| 2969 | let declType = resolveValue(decl.value); | 2738 | let declType = resolveValue(decl.value); |
| 2970 | console.assert("type" in declType.expr); | 2739 | console.assert("type" in declType.expr); |
| 2971 | tdFnSignature.innerHTML = exprName(declType.expr, { | 2740 | tdFnSignature.innerHTML = renderTokens(ex(declType.expr, { |
| 2972 | wantHtml: true, | | |
| 2973 | wantLink: true, | | |
| 2974 | fnDecl: decl, | 2741 | fnDecl: decl, |
| 2975 | linkFnNameDecl: navLinkDecl(decl.name), | 2742 | linkFnNameDecl: navLinkDecl(decl.name), |
| 2976 | }); | 2743 | })); |
| 2977 | tdFnSrc.innerHTML = "<a style=\"float: right;\" target=\"_blank\" href=\"" + | 2744 | tdFnSrc.innerHTML = "<a style=\"float: right;\" target=\"_blank\" href=\"" + |
| 2978 | sourceFileLink(decl) + "\">[src]</a>"; | 2745 | sourceFileLink(decl) + "\">[src]</a>"; |
| 2979 | | 2746 | |
| ... | @@ -3018,14 +2785,22 @@ Happy writing! | ... | @@ -3018,14 +2785,22 @@ Happy writing! |
| 3018 | if (container.kind === typeKinds.Enum) { | 2785 | if (container.kind === typeKinds.Enum) { |
| 3019 | let value = container.values[i]; | 2786 | let value = container.values[i]; |
| 3020 | if (value !== null) { | 2787 | if (value !== null) { |
| 3021 | html += " = " + exprName(value, { wantHtml: true, wantLink: true }); | 2788 | html += renderTokens((function*() { |
| | 2789 | yield Tok.space; |
| | 2790 | yield Tok.eql; |
| | 2791 | yield Tok.space; |
| | 2792 | yield* ex(value, {}); |
| | 2793 | })()); |
| 3022 | } | 2794 | } |
| 3023 | } else { | 2795 | } else { |
| 3024 | let fieldTypeExpr = container.field_types[i]; | 2796 | let fieldTypeExpr = container.field_types[i]; |
| 3025 | if (container.kind !== typeKinds.Struct || !container.is_tuple) { | 2797 | if (container.kind !== typeKinds.Struct || !container.is_tuple) { |
| 3026 | html += ": "; | 2798 | html += renderTokens((function*() { |
| | 2799 | yield Tok.colon; |
| | 2800 | yield Tok.space; |
| | 2801 | })()); |
| 3027 | } | 2802 | } |
| 3028 | html += exprName(fieldTypeExpr, { wantHtml: true, wantLink: true }); | 2803 | html += renderTokens(ex(fieldTypeExpr, {})); |
| 3029 | let tsn = typeShorthandName(fieldTypeExpr); | 2804 | let tsn = typeShorthandName(fieldTypeExpr); |
| 3030 | if (tsn) { | 2805 | if (tsn) { |
| 3031 | html += "<span> (" + tsn + ")</span>"; | 2806 | html += "<span> (" + tsn + ")</span>"; |
| ... | @@ -3033,7 +2808,12 @@ Happy writing! | ... | @@ -3033,7 +2808,12 @@ Happy writing! |
| 3033 | if (container.kind === typeKinds.Struct && !container.is_tuple) { | 2808 | if (container.kind === typeKinds.Struct && !container.is_tuple) { |
| 3034 | let defaultInitExpr = container.field_defaults[i]; | 2809 | let defaultInitExpr = container.field_defaults[i]; |
| 3035 | if (defaultInitExpr !== null) { | 2810 | if (defaultInitExpr !== null) { |
| 3036 | html += " = " + exprName(defaultInitExpr, { wantHtml: true, wantLink: true }); | 2811 | html += renderTokens((function*() { |
| | 2812 | yield Tok.space; |
| | 2813 | yield Tok.eql; |
| | 2814 | yield Tok.space; |
| | 2815 | yield* ex(defaultInitExpr, {}); |
| | 2816 | })()); |
| 3037 | } | 2817 | } |
| 3038 | } | 2818 | } |
| 3039 | } | 2819 | } |
| ... | @@ -3052,7 +2832,7 @@ Happy writing! | ... | @@ -3052,7 +2832,7 @@ Happy writing! |
| 3052 | resizeDomList( | 2832 | resizeDomList( |
| 3053 | domListGlobalVars, | 2833 | domListGlobalVars, |
| 3054 | varsList.length, | 2834 | varsList.length, |
| 3055 | '<tr><td><a href="#"></a></td><td></td><td></td></tr>' | 2835 | '<tr><td><a href="#"></a></td><td><pre class="inline"></pre></td><td></td></tr>' |
| 3056 | ); | 2836 | ); |
| 3057 | for (let i = 0; i < varsList.length; i += 1) { | 2837 | for (let i = 0; i < varsList.length; i += 1) { |
| 3058 | let decl = varsList[i]; | 2838 | let decl = varsList[i]; |
| ... | @@ -3061,15 +2841,13 @@ Happy writing! | ... | @@ -3061,15 +2841,13 @@ Happy writing! |
| 3061 | let tdName = trDom.children[0]; | 2841 | let tdName = trDom.children[0]; |
| 3062 | let tdNameA = tdName.children[0]; | 2842 | let tdNameA = tdName.children[0]; |
| 3063 | let tdType = trDom.children[1]; | 2843 | let tdType = trDom.children[1]; |
| | 2844 | let preType = tdType.children[0]; |
| 3064 | let tdDesc = trDom.children[2]; | 2845 | let tdDesc = trDom.children[2]; |
| 3065 | | 2846 | |
| 3066 | tdNameA.setAttribute("href", navLinkDecl(decl.name)); | 2847 | tdNameA.setAttribute("href", navLinkDecl(decl.name)); |
| 3067 | tdNameA.textContent = decl.name; | 2848 | tdNameA.textContent = decl.name; |
| 3068 | | 2849 | |
| 3069 | tdType.innerHTML = exprName(walkResultTypeRef(decl.value), { | 2850 | preType.innerHTML = renderTokens(ex(walkResultTypeRef(decl.value), {})); |
| 3070 | wantHtml: true, | | |
| 3071 | wantLink: true, | | |
| 3072 | }); | | |
| 3073 | | 2851 | |
| 3074 | let docs = getAstNode(decl.src).docs; | 2852 | let docs = getAstNode(decl.src).docs; |
| 3075 | if (docs != null) { | 2853 | if (docs != null) { |
| ... | @@ -3085,7 +2863,7 @@ Happy writing! | ... | @@ -3085,7 +2863,7 @@ Happy writing! |
| 3085 | resizeDomList( | 2863 | resizeDomList( |
| 3086 | domListValues, | 2864 | domListValues, |
| 3087 | valsList.length, | 2865 | valsList.length, |
| 3088 | '<tr><td><a href="#"></a></td><td></td><td></td></tr>' | 2866 | '<tr><td><a href="#"></a></td><td><pre class="inline"></pre></td><td></td></tr>' |
| 3089 | ); | 2867 | ); |
| 3090 | for (let i = 0; i < valsList.length; i += 1) { | 2868 | for (let i = 0; i < valsList.length; i += 1) { |
| 3091 | let decl = valsList[i]; | 2869 | let decl = valsList[i]; |
| ... | @@ -3094,15 +2872,13 @@ Happy writing! | ... | @@ -3094,15 +2872,13 @@ Happy writing! |
| 3094 | let tdName = trDom.children[0]; | 2872 | let tdName = trDom.children[0]; |
| 3095 | let tdNameA = tdName.children[0]; | 2873 | let tdNameA = tdName.children[0]; |
| 3096 | let tdType = trDom.children[1]; | 2874 | let tdType = trDom.children[1]; |
| | 2875 | let preType = tdType.children[0]; |
| 3097 | let tdDesc = trDom.children[2]; | 2876 | let tdDesc = trDom.children[2]; |
| 3098 | | 2877 | |
| 3099 | tdNameA.setAttribute("href", navLinkDecl(decl.name)); | 2878 | tdNameA.setAttribute("href", navLinkDecl(decl.name)); |
| 3100 | tdNameA.textContent = decl.name; | 2879 | tdNameA.textContent = decl.name; |
| 3101 | | 2880 | |
| 3102 | tdType.innerHTML = exprName(walkResultTypeRef(decl.value), { | 2881 | preType.innerHTML = renderTokens(ex(walkResultTypeRef(decl.value), {})); |
| 3103 | wantHtml: true, | | |
| 3104 | wantLink: true, | | |
| 3105 | }); | | |
| 3106 | | 2882 | |
| 3107 | let docs = getAstNode(decl.src).docs; | 2883 | let docs = getAstNode(decl.src).docs; |
| 3108 | if (docs != null) { | 2884 | if (docs != null) { |
| ... | @@ -3118,24 +2894,21 @@ Happy writing! | ... | @@ -3118,24 +2894,21 @@ Happy writing! |
| 3118 | resizeDomList( | 2894 | resizeDomList( |
| 3119 | domListTests, | 2895 | domListTests, |
| 3120 | testsList.length, | 2896 | testsList.length, |
| 3121 | '<tr><td><a href="#"></a></td><td></td><td></td></tr>' | 2897 | '<tr><td><pre class="inline"></pre></td><td><pre class="inline"></pre></td><td></td></tr>' |
| 3122 | ); | 2898 | ); |
| 3123 | for (let i = 0; i < testsList.length; i += 1) { | 2899 | for (let i = 0; i < testsList.length; i += 1) { |
| 3124 | let decl = testsList[i]; | 2900 | let decl = testsList[i]; |
| 3125 | let trDom = domListTests.children[i]; | 2901 | let trDom = domListTests.children[i]; |
| 3126 | | 2902 | |
| 3127 | let tdName = trDom.children[0]; | 2903 | let tdName = trDom.children[0]; |
| 3128 | let tdNameA = tdName.children[0]; | 2904 | let tdNamePre = tdName.children[0]; |
| 3129 | let tdType = trDom.children[1]; | 2905 | let tdType = trDom.children[1]; |
| | 2906 | let tdTypePre = tdType.children[0]; |
| 3130 | let tdDesc = trDom.children[2]; | 2907 | let tdDesc = trDom.children[2]; |
| 3131 | | 2908 | |
| 3132 | tdNameA.setAttribute("href", navLinkDecl(decl.name)); | 2909 | tdNamePre.innerHTML = renderSingleToken(Tok.identifier(decl.name)); |
| 3133 | tdNameA.textContent = decl.name; | | |
| 3134 | | 2910 | |
| 3135 | tdType.innerHTML = exprName(walkResultTypeRef(decl.value), { | 2911 | tdTypePre.innerHTML = ex(walkResultTypeRef(decl.value), {}); |
| 3136 | wantHtml: true, | | |
| 3137 | wantLink: true, | | |
| 3138 | }); | | |
| 3139 | | 2912 | |
| 3140 | let docs = getAstNode(decl.src).docs; | 2913 | let docs = getAstNode(decl.src).docs; |
| 3141 | if (docs != null) { | 2914 | if (docs != null) { |
| ... | @@ -3260,7 +3033,7 @@ Happy writing! | ... | @@ -3260,7 +3033,7 @@ Happy writing! |
| 3260 | | 3033 | |
| 3261 | return; | 3034 | return; |
| 3262 | case NAV_MODES.GUIDES: | 3035 | case NAV_MODES.GUIDES: |
| 3263 | | 3036 | |
| 3264 | const sections = zigAnalysis.guide_sections; | 3037 | const sections = zigAnalysis.guide_sections; |
| 3265 | if (sections.length != 0 && sections[0].guides.length != 0 && nonSearchPart == "") { | 3038 | if (sections.length != 0 && sections[0].guides.length != 0 && nonSearchPart == "") { |
| 3266 | location.hash = NAV_MODES.GUIDES + sections[0].guides[0].name; | 3039 | location.hash = NAV_MODES.GUIDES + sections[0].guides[0].name; |
| ... | @@ -3428,10 +3201,10 @@ Happy writing! | ... | @@ -3428,10 +3201,10 @@ Happy writing! |
| 3428 | if (list[declIndex] != null) continue; | 3201 | if (list[declIndex] != null) continue; |
| 3429 | | 3202 | |
| 3430 | let decl = getDecl(declIndex); | 3203 | let decl = getDecl(declIndex); |
| 3431 | | 3204 | |
| 3432 | if (decl.is_uns) { | 3205 | if (decl.is_uns) { |
| 3433 | let unsDeclList = [decl]; | 3206 | let unsDeclList = [decl]; |
| 3434 | while(unsDeclList.length != 0) { | 3207 | while (unsDeclList.length != 0) { |
| 3435 | let unsDecl = unsDeclList.pop(); | 3208 | let unsDecl = unsDeclList.pop(); |
| 3436 | let unsDeclVal = resolveValue(unsDecl.value); | 3209 | let unsDeclVal = resolveValue(unsDecl.value); |
| 3437 | if (!("type" in unsDeclVal.expr)) continue; | 3210 | if (!("type" in unsDeclVal.expr)) continue; |
| ... | @@ -3441,7 +3214,7 @@ Happy writing! | ... | @@ -3441,7 +3214,7 @@ Happy writing! |
| 3441 | for (let unsDeclI = 0; unsDeclI < unsPubDeclLen; unsDeclI += 1) { | 3214 | for (let unsDeclI = 0; unsDeclI < unsPubDeclLen; unsDeclI += 1) { |
| 3442 | let childDeclIndex = unsType.pubDecls[unsDeclI]; | 3215 | let childDeclIndex = unsType.pubDecls[unsDeclI]; |
| 3443 | let childDecl = getDecl(childDeclIndex); | 3216 | let childDecl = getDecl(childDeclIndex); |
| 3444 | | 3217 | |
| 3445 | if (childDecl.is_uns) { | 3218 | if (childDecl.is_uns) { |
| 3446 | unsDeclList.push(childDecl); | 3219 | unsDeclList.push(childDecl); |
| 3447 | } else { | 3220 | } else { |
| ... | @@ -3460,54 +3233,54 @@ Happy writing! | ... | @@ -3460,54 +3233,54 @@ Happy writing! |
| 3460 | return list; | 3233 | return list; |
| 3461 | } | 3234 | } |
| 3462 | | 3235 | |
| 3463 | function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | 3236 | function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3464 | let declVal = resolveValue(decl.value); | 3237 | let declVal = resolveValue(decl.value); |
| 3465 | let declNames = item.declNames.concat([decl.name]); | 3238 | let declNames = item.declNames.concat([decl.name]); |
| 3466 | let declIndexes = item.declIndexes.concat([declIndex]); | 3239 | let declIndexes = item.declIndexes.concat([declIndex]); |
| 3467 | | 3240 | |
| 3468 | if (list[declIndex] != null) return; | 3241 | if (list[declIndex] != null) return; |
| 3469 | list[declIndex] = { | 3242 | list[declIndex] = { |
| 3470 | modNames: modNames, | 3243 | modNames: modNames, |
| 3471 | declNames: declNames, | 3244 | declNames: declNames, |
| 3472 | declIndexes: declIndexes, | 3245 | declIndexes: declIndexes, |
| 3473 | }; | 3246 | }; |
| 3474 | | 3247 | |
| 3475 | // add to search index | 3248 | // add to search index |
| 3476 | { | 3249 | { |
| 3477 | declSearchIndex.add(decl.name, {declIndex}); | 3250 | declSearchIndex.add(decl.name, { declIndex }); |
| 3478 | } | | |
| 3479 | | | |
| 3480 | | | |
| 3481 | if ("type" in declVal.expr) { | | |
| 3482 | let value = getType(declVal.expr.type); | | |
| 3483 | if (declCanRepresentTypeKind(value.kind)) { | | |
| 3484 | canonTypeDecls[declVal.type] = declIndex; | | |
| 3485 | } | 3251 | } |
| 3486 | | 3252 | |
| 3487 | if (isContainerType(value)) { | | |
| 3488 | stack.push({ | | |
| 3489 | declNames: declNames, | | |
| 3490 | declIndexes: declIndexes, | | |
| 3491 | type: value, | | |
| 3492 | }); | | |
| 3493 | } | | |
| 3494 | | 3253 | |
| 3495 | // Generic function | 3254 | if ("type" in declVal.expr) { |
| 3496 | if (typeIsGenericFn(declVal.expr.type)) { | 3255 | let value = getType(declVal.expr.type); |
| 3497 | let ret = resolveGenericRet(value); | 3256 | if (declCanRepresentTypeKind(value.kind)) { |
| 3498 | if (ret != null && "type" in ret.expr) { | 3257 | canonTypeDecls[declVal.type] = declIndex; |
| 3499 | let generic_type = getType(ret.expr.type); | 3258 | } |
| 3500 | if (isContainerType(generic_type)) { | 3259 | |
| 3501 | stack.push({ | 3260 | if (isContainerType(value)) { |
| 3502 | declNames: declNames, | 3261 | stack.push({ |
| 3503 | declIndexes: declIndexes, | 3262 | declNames: declNames, |
| 3504 | type: generic_type, | 3263 | declIndexes: declIndexes, |
| 3505 | }); | 3264 | type: value, |
| | 3265 | }); |
| | 3266 | } |
| | 3267 | |
| | 3268 | // Generic function |
| | 3269 | if (typeIsGenericFn(declVal.expr.type)) { |
| | 3270 | let ret = resolveGenericRet(value); |
| | 3271 | if (ret != null && "type" in ret.expr) { |
| | 3272 | let generic_type = getType(ret.expr.type); |
| | 3273 | if (isContainerType(generic_type)) { |
| | 3274 | stack.push({ |
| | 3275 | declNames: declNames, |
| | 3276 | declIndexes: declIndexes, |
| | 3277 | type: generic_type, |
| | 3278 | }); |
| | 3279 | } |
| 3506 | } | 3280 | } |
| 3507 | } | 3281 | } |
| 3508 | } | 3282 | } |
| 3509 | } | 3283 | } |
| 3510 | } | | |
| 3511 | | 3284 | |
| 3512 | function getCanonDeclPath(index) { | 3285 | function getCanonDeclPath(index) { |
| 3513 | if (canonDeclPaths == null) { | 3286 | if (canonDeclPaths == null) { |
| ... | @@ -3524,7 +3297,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3524,7 +3297,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3524 | } | 3297 | } |
| 3525 | | 3298 | |
| 3526 | function escapeHtml(text) { | 3299 | function escapeHtml(text) { |
| 3527 | return text.replace(/[&"<>]/g, function (m) { | 3300 | return text.replace(/[&"<>]/g, function(m) { |
| 3528 | return escapeHtmlReplacements[m]; | 3301 | return escapeHtmlReplacements[m]; |
| 3529 | }); | 3302 | }); |
| 3530 | } | 3303 | } |
| ... | @@ -3553,13 +3326,13 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3553,13 +3326,13 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3553 | } | 3326 | } |
| 3554 | | 3327 | |
| 3555 | function parseGuides() { | 3328 | function parseGuides() { |
| 3556 | for (let j = 0; j < zigAnalysis.guide_sections.length; j+=1){ | 3329 | for (let j = 0; j < zigAnalysis.guide_sections.length; j += 1) { |
| 3557 | const section = zigAnalysis.guide_sections[j]; | 3330 | const section = zigAnalysis.guide_sections[j]; |
| 3558 | for (let i = 0; i < section.guides.length; i+=1){ | 3331 | for (let i = 0; i < section.guides.length; i += 1) { |
| 3559 | let reader = new commonmark.Parser({smart: true}); | 3332 | let reader = new commonmark.Parser({ smart: true }); |
| 3560 | const guide = section.guides[i]; | 3333 | const guide = section.guides[i]; |
| 3561 | const ast = reader.parse(guide.body); | 3334 | const ast = reader.parse(guide.body); |
| 3562 | | 3335 | |
| 3563 | // Find the first text thing to use as a sidebar title | 3336 | // Find the first text thing to use as a sidebar title |
| 3564 | guide.title = "[empty guide]"; | 3337 | guide.title = "[empty guide]"; |
| 3565 | { | 3338 | { |
| ... | @@ -3571,7 +3344,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3571,7 +3344,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3571 | guide.title = node.literal; | 3344 | guide.title = node.literal; |
| 3572 | break; | 3345 | break; |
| 3573 | } | 3346 | } |
| 3574 | } | 3347 | } |
| 3575 | } | 3348 | } |
| 3576 | // Index this guide | 3349 | // Index this guide |
| 3577 | { | 3350 | { |
| ... | @@ -3580,24 +3353,24 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3580,24 +3353,24 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3580 | while ((event = walker.next())) { | 3353 | while ((event = walker.next())) { |
| 3581 | node = event.node; | 3354 | node = event.node; |
| 3582 | if (event.entering == true && node.type === 'text') { | 3355 | if (event.entering == true && node.type === 'text') { |
| 3583 | indexTextForGuide(j, i, node); | 3356 | indexTextForGuide(j, i, node); |
| 3584 | } | 3357 | } |
| 3585 | } | 3358 | } |
| 3586 | } | 3359 | } |
| 3587 | } | 3360 | } |
| 3588 | } | 3361 | } |
| 3589 | } | 3362 | } |
| 3590 | | 3363 | |
| 3591 | function indexTextForGuide(section_idx, guide_idx, node){ | 3364 | function indexTextForGuide(section_idx, guide_idx, node) { |
| 3592 | const terms = node.literal.split(" "); | 3365 | const terms = node.literal.split(" "); |
| 3593 | for (let i = 0; i < terms.length; i += 1){ | 3366 | for (let i = 0; i < terms.length; i += 1) { |
| 3594 | const t = terms[i]; | 3367 | const t = terms[i]; |
| 3595 | if (!guidesSearchIndex[t]) guidesSearchIndex[t] = new Set(); | 3368 | if (!guidesSearchIndex[t]) guidesSearchIndex[t] = new Set(); |
| 3596 | node.guide = {section_idx, guide_idx}; | 3369 | node.guide = { section_idx, guide_idx }; |
| 3597 | guidesSearchIndex[t].add(node); | 3370 | guidesSearchIndex[t].add(node); |
| 3598 | } | 3371 | } |
| 3599 | } | 3372 | } |
| 3600 | | 3373 | |
| 3601 | | 3374 | |
| 3602 | function markdown(input, contextType) { | 3375 | function markdown(input, contextType) { |
| 3603 | const parsed = new commonmark.Parser({ smart: true }).parse(input); | 3376 | const parsed = new commonmark.Parser({ smart: true }).parse(input); |
| ... | @@ -3620,70 +3393,71 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3620,70 +3393,71 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3620 | | 3393 | |
| 3621 | return new commonmark.HtmlRenderer({ safe: true }).render(parsed); | 3394 | return new commonmark.HtmlRenderer({ safe: true }).render(parsed); |
| 3622 | | 3395 | |
| 3623 | function detectDeclPath(text, context) { | 3396 | } |
| 3624 | let result = ""; | | |
| 3625 | let separator = ":"; | | |
| 3626 | const components = text.split("."); | | |
| 3627 | let curDeclOrType = undefined; | | |
| 3628 | | | |
| 3629 | let curContext = context; | | |
| 3630 | let limit = 10000; | | |
| 3631 | while (curContext) { | | |
| 3632 | limit -= 1; | | |
| 3633 | | | |
| 3634 | if (limit == 0) { | | |
| 3635 | throw "too many iterations"; | | |
| 3636 | } | | |
| 3637 | | | |
| 3638 | curDeclOrType = findSubDecl(curContext, components[0]); | | |
| 3639 | | | |
| 3640 | if (!curDeclOrType) { | | |
| 3641 | if (curContext.parent_container == null) break; | | |
| 3642 | curContext = getType(curContext.parent_container); | | |
| 3643 | continue; | | |
| 3644 | } | | |
| 3645 | | 3397 | |
| 3646 | if (curContext == context) { | 3398 | function detectDeclPath(text, context) { |
| 3647 | separator = '.'; | 3399 | let result = ""; |
| 3648 | result = location.hash + separator + components[0]; | 3400 | let separator = ":"; |
| 3649 | } else { | 3401 | const components = text.split("."); |
| 3650 | // We had to go up, which means we need a new path! | 3402 | let curDeclOrType = undefined; |
| 3651 | const canonPath = getCanonDeclPath(curDeclOrType.find_subdecl_idx); | | |
| 3652 | if (!canonPath) return; | | |
| 3653 | | | |
| 3654 | let lastModName = canonPath.modNames[canonPath.modNames.length - 1]; | | |
| 3655 | let fullPath = lastModName + ":" + canonPath.declNames.join("."); | | |
| 3656 | | | |
| 3657 | separator = '.'; | | |
| 3658 | result = "#A;" + fullPath; | | |
| 3659 | } | | |
| 3660 | | 3403 | |
| 3661 | break; | 3404 | let curContext = context; |
| 3662 | } | 3405 | let limit = 10000; |
| | 3406 | while (curContext) { |
| | 3407 | limit -= 1; |
| | 3408 | |
| | 3409 | if (limit == 0) { |
| | 3410 | throw "too many iterations"; |
| | 3411 | } |
| | 3412 | |
| | 3413 | curDeclOrType = findSubDecl(curContext, components[0]); |
| 3663 | | 3414 | |
| 3664 | if (!curDeclOrType) { | 3415 | if (!curDeclOrType) { |
| 3665 | for (let i = 0; i < zigAnalysis.modules.length; i += 1){ | 3416 | if (curContext.parent_container == null) break; |
| 3666 | const p = zigAnalysis.modules[i]; | 3417 | curContext = getType(curContext.parent_container); |
| 3667 | if (p.name == components[0]) { | 3418 | continue; |
| 3668 | curDeclOrType = getType(p.main); | | |
| 3669 | result += "#A;" + components[0]; | | |
| 3670 | break; | | |
| 3671 | } | | |
| 3672 | } | | |
| 3673 | } | 3419 | } |
| 3674 | | 3420 | |
| 3675 | if (!curDeclOrType) return null; | 3421 | if (curContext == context) { |
| 3676 | | 3422 | separator = '.'; |
| 3677 | for (let i = 1; i < components.length; i += 1) { | 3423 | result = location.hash + separator + components[0]; |
| 3678 | curDeclOrType = findSubDecl(curDeclOrType, components[i]); | 3424 | } else { |
| 3679 | if (!curDeclOrType) return null; | 3425 | // We had to go up, which means we need a new path! |
| 3680 | result += separator + components[i]; | 3426 | const canonPath = getCanonDeclPath(curDeclOrType.find_subdecl_idx); |
| | 3427 | if (!canonPath) return; |
| | 3428 | |
| | 3429 | let lastModName = canonPath.modNames[canonPath.modNames.length - 1]; |
| | 3430 | let fullPath = lastModName + ":" + canonPath.declNames.join("."); |
| | 3431 | |
| 3681 | separator = '.'; | 3432 | separator = '.'; |
| | 3433 | result = "#A;" + fullPath; |
| 3682 | } | 3434 | } |
| 3683 | | 3435 | |
| 3684 | return result; | 3436 | break; |
| 3685 | | 3437 | } |
| | 3438 | |
| | 3439 | if (!curDeclOrType) { |
| | 3440 | for (let i = 0; i < zigAnalysis.modules.length; i += 1) { |
| | 3441 | const p = zigAnalysis.modules[i]; |
| | 3442 | if (p.name == components[0]) { |
| | 3443 | curDeclOrType = getType(p.main); |
| | 3444 | result += "#A;" + components[0]; |
| | 3445 | break; |
| | 3446 | } |
| | 3447 | } |
| | 3448 | } |
| | 3449 | |
| | 3450 | if (!curDeclOrType) return null; |
| | 3451 | |
| | 3452 | for (let i = 1; i < components.length; i += 1) { |
| | 3453 | curDeclOrType = findSubDecl(curDeclOrType, components[i]); |
| | 3454 | if (!curDeclOrType) return null; |
| | 3455 | result += separator + components[i]; |
| | 3456 | separator = '.'; |
| 3686 | } | 3457 | } |
| | 3458 | |
| | 3459 | return result; |
| | 3460 | |
| 3687 | } | 3461 | } |
| 3688 | | 3462 | |
| 3689 | function activateSelectedResult() { | 3463 | function activateSelectedResult() { |
| ... | @@ -3723,7 +3497,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3723,7 +3497,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3723 | startSearch(); | 3497 | startSearch(); |
| 3724 | } | 3498 | } |
| 3725 | } | 3499 | } |
| 3726 | | 3500 | |
| 3727 | | 3501 | |
| 3728 | function onSearchKeyDown(ev) { | 3502 | function onSearchKeyDown(ev) { |
| 3729 | switch (getKeyString(ev)) { | 3503 | switch (getKeyString(ev)) { |
| ... | @@ -3824,7 +3598,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3824,7 +3598,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3824 | break; | 3598 | break; |
| 3825 | case "/": | 3599 | case "/": |
| 3826 | if (!getPrefSlashSearch()) break; | 3600 | if (!getPrefSlashSearch()) break; |
| 3827 | // fallthrough | 3601 | // fallthrough |
| 3828 | case "s": | 3602 | case "s": |
| 3829 | if (!isModalVisible(domHelpModal) && !isModalVisible(domPrefsModal)) { | 3603 | if (!isModalVisible(domHelpModal) && !isModalVisible(domPrefsModal)) { |
| 3830 | if (ev.target == domSearch) break; | 3604 | if (ev.target == domSearch) break; |
| ... | @@ -3846,9 +3620,9 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3846,9 +3620,9 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3846 | | 3620 | |
| 3847 | // toggle the help modal | 3621 | // toggle the help modal |
| 3848 | if (isModalVisible(domHelpModal)) { | 3622 | if (isModalVisible(domHelpModal)) { |
| 3849 | hideModal(domHelpModal); | 3623 | hideModal(domHelpModal); |
| 3850 | } else { | 3624 | } else { |
| 3851 | showModal(domHelpModal); | 3625 | showModal(domHelpModal); |
| 3852 | } | 3626 | } |
| 3853 | ev.preventDefault(); | 3627 | ev.preventDefault(); |
| 3854 | ev.stopPropagation(); | 3628 | ev.stopPropagation(); |
| ... | @@ -3927,21 +3701,21 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3927,21 +3701,21 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3927 | function renderSearchGuides() { | 3701 | function renderSearchGuides() { |
| 3928 | const searchTrimmed = false; | 3702 | const searchTrimmed = false; |
| 3929 | let ignoreCase = curNavSearch.toLowerCase() === curNavSearch; | 3703 | let ignoreCase = curNavSearch.toLowerCase() === curNavSearch; |
| 3930 | | 3704 | |
| 3931 | let terms = getSearchTerms(); | 3705 | let terms = getSearchTerms(); |
| 3932 | let matchedItems = new Set(); | 3706 | let matchedItems = new Set(); |
| 3933 | | 3707 | |
| 3934 | for (let i = 0; i < terms.length; i += 1) { | 3708 | for (let i = 0; i < terms.length; i += 1) { |
| 3935 | const nodes = guidesSearchIndex[terms[i]]; | 3709 | const nodes = guidesSearchIndex[terms[i]]; |
| 3936 | if (nodes) { | 3710 | if (nodes) { |
| 3937 | for (const n of nodes) { | 3711 | for (const n of nodes) { |
| 3938 | matchedItems.add(n); | 3712 | matchedItems.add(n); |
| 3939 | } | 3713 | } |
| 3940 | } | 3714 | } |
| 3941 | } | 3715 | } |
| 3942 | | 3716 | |
| 3943 | | 3717 | |
| 3944 | | 3718 | |
| 3945 | if (matchedItems.size !== 0) { | 3719 | if (matchedItems.size !== 0) { |
| 3946 | // Build up the list of search results | 3720 | // Build up the list of search results |
| 3947 | let matchedItemsHTML = ""; | 3721 | let matchedItemsHTML = ""; |
| ... | @@ -3966,14 +3740,14 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -3966,14 +3740,14 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 3966 | } | 3740 | } |
| 3967 | } | 3741 | } |
| 3968 | | 3742 | |
| 3969 | function renderSearchAPI(){ | 3743 | function renderSearchAPI() { |
| 3970 | if (canonDeclPaths == null) { | 3744 | if (canonDeclPaths == null) { |
| 3971 | canonDeclPaths = computeCanonDeclPaths(); | 3745 | canonDeclPaths = computeCanonDeclPaths(); |
| 3972 | } | 3746 | } |
| 3973 | let declSet = new Set(); | 3747 | let declSet = new Set(); |
| 3974 | let otherDeclSet = new Set(); // for low quality results | 3748 | let otherDeclSet = new Set(); // for low quality results |
| 3975 | let declScores = {}; | 3749 | let declScores = {}; |
| 3976 | | 3750 | |
| 3977 | let ignoreCase = curNavSearch.toLowerCase() === curNavSearch; | 3751 | let ignoreCase = curNavSearch.toLowerCase() === curNavSearch; |
| 3978 | let term_list = getSearchTerms(); | 3752 | let term_list = getSearchTerms(); |
| 3979 | for (let i = 0; i < term_list.length; i += 1) { | 3753 | for (let i = 0; i < term_list.length; i += 1) { |
| ... | @@ -4004,7 +3778,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -4004,7 +3778,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 4004 | if (declSet.has(p)) { | 3778 | if (declSet.has(p)) { |
| 4005 | found = true; | 3779 | found = true; |
| 4006 | break; | 3780 | break; |
| 4007 | } | 3781 | } |
| 4008 | } | 3782 | } |
| 4009 | if (!found) { | 3783 | if (!found) { |
| 4010 | otherDeclSet.add(d); | 3784 | otherDeclSet.add(d); |
| ... | @@ -4012,9 +3786,9 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -4012,9 +3786,9 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 4012 | termSet.add(d); | 3786 | termSet.add(d); |
| 4013 | } | 3787 | } |
| 4014 | } | 3788 | } |
| 4015 | | 3789 | |
| 4016 | if (declScores[d] == undefined) declScores[d] = 0; | 3790 | if (declScores[d] == undefined) declScores[d] = 0; |
| 4017 | | 3791 | |
| 4018 | // scores (lower is better) | 3792 | // scores (lower is better) |
| 4019 | let decl_name = decl.name; | 3793 | let decl_name = decl.name; |
| 4020 | if (ignoreCase) decl_name = decl_name.toLowerCase(); | 3794 | if (ignoreCase) decl_name = decl_name.toLowerCase(); |
| ... | @@ -4022,21 +3796,21 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -4022,21 +3796,21 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 4022 | // shallow path are preferable | 3796 | // shallow path are preferable |
| 4023 | const path_depth = canonPath.declNames.length * 50; | 3797 | const path_depth = canonPath.declNames.length * 50; |
| 4024 | // matching the start of a decl name is good | 3798 | // matching the start of a decl name is good |
| 4025 | const match_from_start = decl_name.startsWith(term) ? -term.length * (2 -ignoreCase) : (decl_name.length - term.length) + 1; | 3799 | const match_from_start = decl_name.startsWith(term) ? -term.length * (2 - ignoreCase) : (decl_name.length - term.length) + 1; |
| 4026 | // being a perfect match is good | 3800 | // being a perfect match is good |
| 4027 | const is_full_match = (decl_name === term) ? -decl_name.length * (1 - ignoreCase) : Math.abs(decl_name.length - term.length); | 3801 | const is_full_match = (decl_name === term) ? -decl_name.length * (1 - ignoreCase) : Math.abs(decl_name.length - term.length); |
| 4028 | // matching the end of a decl name is good | 3802 | // matching the end of a decl name is good |
| 4029 | const matches_the_end = decl_name.endsWith(term) ? -term.length * (1 - ignoreCase) : (decl_name.length - term.length) + 1; | 3803 | const matches_the_end = decl_name.endsWith(term) ? -term.length * (1 - ignoreCase) : (decl_name.length - term.length) + 1; |
| 4030 | // explicitly penalizing scream case decls | 3804 | // explicitly penalizing scream case decls |
| 4031 | const decl_is_scream_case = decl.name.toUpperCase() != decl.name ? 0 : decl.name.length; | 3805 | const decl_is_scream_case = decl.name.toUpperCase() != decl.name ? 0 : decl.name.length; |
| 4032 | | 3806 | |
| 4033 | const score = path_depth | 3807 | const score = path_depth |
| 4034 | + match_from_start | 3808 | + match_from_start |
| 4035 | + is_full_match | 3809 | + is_full_match |
| 4036 | + matches_the_end | 3810 | + matches_the_end |
| 4037 | + decl_is_scream_case; | 3811 | + decl_is_scream_case; |
| 4038 | | 3812 | |
| 4039 | declScores[d] += score; | 3813 | declScores[d] += score; |
| 4040 | } | 3814 | } |
| 4041 | } | 3815 | } |
| 4042 | if (i != 0) { | 3816 | if (i != 0) { |
| ... | @@ -4047,19 +3821,19 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -4047,19 +3821,19 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 4047 | if (termSet.has(p) || otherDeclSet.has(p)) { | 3821 | if (termSet.has(p) || otherDeclSet.has(p)) { |
| 4048 | found = true; | 3822 | found = true; |
| 4049 | break; | 3823 | break; |
| 4050 | } | 3824 | } |
| 4051 | } | 3825 | } |
| 4052 | if (found) { | 3826 | if (found) { |
| 4053 | declScores[d] = declScores[d] / term_list.length; | 3827 | declScores[d] = declScores[d] / term_list.length; |
| 4054 | } | 3828 | } |
| 4055 | | 3829 | |
| 4056 | termOtherSet.add(d); | 3830 | termOtherSet.add(d); |
| 4057 | } | 3831 | } |
| 4058 | declSet = termSet; | 3832 | declSet = termSet; |
| 4059 | for (let d of termOtherSet) { | 3833 | for (let d of termOtherSet) { |
| 4060 | otherDeclSet.add(d); | 3834 | otherDeclSet.add(d); |
| 4061 | } | 3835 | } |
| 4062 | | 3836 | |
| 4063 | } | 3837 | } |
| 4064 | } | 3838 | } |
| 4065 | | 3839 | |
| ... | @@ -4068,21 +3842,21 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -4068,21 +3842,21 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 4068 | low_quality: [], | 3842 | low_quality: [], |
| 4069 | }; | 3843 | }; |
| 4070 | for (let idx of declSet) { | 3844 | for (let idx of declSet) { |
| 4071 | matchedItems.high_quality.push({points: declScores[idx], declIndex: idx}) | 3845 | matchedItems.high_quality.push({ points: declScores[idx], declIndex: idx }) |
| 4072 | } | 3846 | } |
| 4073 | for (let idx of otherDeclSet) { | 3847 | for (let idx of otherDeclSet) { |
| 4074 | matchedItems.low_quality.push({points: declScores[idx], declIndex: idx}) | 3848 | matchedItems.low_quality.push({ points: declScores[idx], declIndex: idx }) |
| 4075 | } | 3849 | } |
| 4076 | | 3850 | |
| 4077 | matchedItems.high_quality.sort(function (a, b) { | 3851 | matchedItems.high_quality.sort(function(a, b) { |
| 4078 | let cmp = operatorCompare(a.points, b.points); | 3852 | let cmp = operatorCompare(a.points, b.points); |
| 4079 | return cmp; | 3853 | return cmp; |
| 4080 | }); | 3854 | }); |
| 4081 | matchedItems.low_quality.sort(function (a, b) { | 3855 | matchedItems.low_quality.sort(function(a, b) { |
| 4082 | let cmp = operatorCompare(a.points, b.points); | 3856 | let cmp = operatorCompare(a.points, b.points); |
| 4083 | return cmp; | 3857 | return cmp; |
| 4084 | }); | 3858 | }); |
| 4085 | | 3859 | |
| 4086 | // Build up the list of search results | 3860 | // Build up the list of search results |
| 4087 | let matchedItemsHTML = ""; | 3861 | let matchedItemsHTML = ""; |
| 4088 | | 3862 | |
| ... | @@ -4099,7 +3873,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -4099,7 +3873,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 4099 | | 3873 | |
| 4100 | let lastModName = canonPath.modNames[canonPath.modNames.length - 1]; | 3874 | let lastModName = canonPath.modNames[canonPath.modNames.length - 1]; |
| 4101 | let text = lastModName + "." + canonPath.declNames.join("."); | 3875 | let text = lastModName + "." + canonPath.declNames.join("."); |
| 4102 | | 3876 | |
| 4103 | | 3877 | |
| 4104 | const href = navLink(canonPath.modNames, canonPath.declNames); | 3878 | const href = navLink(canonPath.modNames, canonPath.declNames); |
| 4105 | | 3879 | |
| ... | @@ -4113,7 +3887,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -4113,7 +3887,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 4113 | | 3887 | |
| 4114 | domSectSearchResults.classList.remove("hidden"); | 3888 | domSectSearchResults.classList.remove("hidden"); |
| 4115 | } | 3889 | } |
| 4116 | | 3890 | |
| 4117 | function renderSearchAPIOld() { | 3891 | function renderSearchAPIOld() { |
| 4118 | let matchedItems = []; | 3892 | let matchedItems = []; |
| 4119 | let ignoreCase = curNavSearch.toLowerCase() === curNavSearch; | 3893 | let ignoreCase = curNavSearch.toLowerCase() === curNavSearch; |
| ... | @@ -4179,7 +3953,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { | ... | @@ -4179,7 +3953,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { |
| 4179 | } | 3953 | } |
| 4180 | | 3954 | |
| 4181 | if (matchedItems.length !== 0) { | 3955 | if (matchedItems.length !== 0) { |
| 4182 | matchedItems.sort(function (a, b) { | 3956 | matchedItems.sort(function(a, b) { |
| 4183 | let cmp = operatorCompare(b.points, a.points); | 3957 | let cmp = operatorCompare(b.points, a.points); |
| 4184 | if (cmp != 0) return cmp; | 3958 | if (cmp != 0) return cmp; |
| 4185 | return operatorCompare(a.decl.name, b.decl.name); | 3959 | return operatorCompare(a.decl.name, b.decl.name); |
| ... | @@ -4485,12 +4259,12 @@ function toggleExpand(event) { | ... | @@ -4485,12 +4259,12 @@ function toggleExpand(event) { |
| 4485 | function RadixTree() { | 4259 | function RadixTree() { |
| 4486 | this.root = null; | 4260 | this.root = null; |
| 4487 | | 4261 | |
| 4488 | RadixTree.prototype.search = function (query) { | 4262 | RadixTree.prototype.search = function(query) { |
| 4489 | return this.root.search(query); | 4263 | return this.root.search(query); |
| 4490 | | 4264 | |
| 4491 | } | 4265 | } |
| 4492 | | 4266 | |
| 4493 | RadixTree.prototype.add = function (declName, value) { | 4267 | RadixTree.prototype.add = function(declName, value) { |
| 4494 | if (this.root == null) { | 4268 | if (this.root == null) { |
| 4495 | this.root = new Node(declName.toLowerCase(), null, [value]); | 4269 | this.root = new Node(declName.toLowerCase(), null, [value]); |
| 4496 | } else { | 4270 | } else { |
| ... | @@ -4499,7 +4273,7 @@ function RadixTree() { | ... | @@ -4499,7 +4273,7 @@ function RadixTree() { |
| 4499 | | 4273 | |
| 4500 | const not_scream_case = declName.toUpperCase() != declName; | 4274 | const not_scream_case = declName.toUpperCase() != declName; |
| 4501 | let found_separator = false; | 4275 | let found_separator = false; |
| 4502 | for (let i = 1; i < declName.length; i +=1) { | 4276 | for (let i = 1; i < declName.length; i += 1) { |
| 4503 | if (declName[i] == '_' || declName[i] == '.') { | 4277 | if (declName[i] == '_' || declName[i] == '.') { |
| 4504 | found_separator = true; | 4278 | found_separator = true; |
| 4505 | continue; | 4279 | continue; |
| ... | @@ -4507,42 +4281,42 @@ function RadixTree() { | ... | @@ -4507,42 +4281,42 @@ function RadixTree() { |
| 4507 | | 4281 | |
| 4508 | | 4282 | |
| 4509 | if (found_separator || (declName[i].toLowerCase() !== declName[i])) { | 4283 | if (found_separator || (declName[i].toLowerCase() !== declName[i])) { |
| 4510 | if (declName.length > i+1 | 4284 | if (declName.length > i + 1 |
| 4511 | && declName[i+1].toLowerCase() != declName[i+1]) continue; | 4285 | && declName[i + 1].toLowerCase() != declName[i + 1]) continue; |
| 4512 | let suffix = declName.slice(i); | 4286 | let suffix = declName.slice(i); |
| 4513 | this.root.add(suffix.toLowerCase(), value); | 4287 | this.root.add(suffix.toLowerCase(), value); |
| 4514 | found_separator = false; | 4288 | found_separator = false; |
| 4515 | } | 4289 | } |
| 4516 | } | 4290 | } |
| 4517 | } | 4291 | } |
| 4518 | | 4292 | |
| 4519 | function Node(labels, next, values) { | 4293 | function Node(labels, next, values) { |
| 4520 | this.labels = labels; | 4294 | this.labels = labels; |
| 4521 | this.next = next; | 4295 | this.next = next; |
| 4522 | this.values = values; | 4296 | this.values = values; |
| 4523 | } | 4297 | } |
| 4524 | | 4298 | |
| 4525 | Node.prototype.isCompressed = function () { | 4299 | Node.prototype.isCompressed = function() { |
| 4526 | return !Array.isArray(this.next); | 4300 | return !Array.isArray(this.next); |
| 4527 | } | 4301 | } |
| 4528 | | 4302 | |
| 4529 | Node.prototype.search = function (word) { | 4303 | Node.prototype.search = function(word) { |
| 4530 | let full_matches = []; | 4304 | let full_matches = []; |
| 4531 | let partial_matches = []; | 4305 | let partial_matches = []; |
| 4532 | let subtree_root = null; | 4306 | let subtree_root = null; |
| 4533 | | 4307 | |
| 4534 | let cn = this; | 4308 | let cn = this; |
| 4535 | char_loop: for (let i = 0; i < word.length;) { | 4309 | char_loop: for (let i = 0; i < word.length;) { |
| 4536 | if (cn.isCompressed()) { | 4310 | if (cn.isCompressed()) { |
| 4537 | for (let j = 0; j < cn.labels.length; j += 1) { | 4311 | for (let j = 0; j < cn.labels.length; j += 1) { |
| 4538 | let current_idx = i+j; | 4312 | let current_idx = i + j; |
| 4539 | | 4313 | |
| 4540 | if (current_idx == word.length) { | 4314 | if (current_idx == word.length) { |
| 4541 | partial_matches = cn.values; | 4315 | partial_matches = cn.values; |
| 4542 | subtree_root = cn.next; | 4316 | subtree_root = cn.next; |
| 4543 | break char_loop; | 4317 | break char_loop; |
| 4544 | } | 4318 | } |
| 4545 | | 4319 | |
| 4546 | if (word[current_idx] != cn.labels[j]) return null; | 4320 | if (word[current_idx] != cn.labels[j]) return null; |
| 4547 | } | 4321 | } |
| 4548 | | 4322 | |
| ... | @@ -4553,33 +4327,33 @@ function RadixTree() { | ... | @@ -4553,33 +4327,33 @@ function RadixTree() { |
| 4553 | subtree_root = cn.next; | 4327 | subtree_root = cn.next; |
| 4554 | break char_loop; | 4328 | break char_loop; |
| 4555 | } | 4329 | } |
| 4556 | | 4330 | |
| 4557 | | 4331 | |
| 4558 | i = new_idx; | 4332 | i = new_idx; |
| 4559 | cn = cn.next; | 4333 | cn = cn.next; |
| 4560 | continue; | 4334 | continue; |
| 4561 | } else { | 4335 | } else { |
| 4562 | for (let j = 0; j < cn.labels.length; j += 1) { | 4336 | for (let j = 0; j < cn.labels.length; j += 1) { |
| 4563 | if (word[i] == cn.labels[j]) { | 4337 | if (word[i] == cn.labels[j]) { |
| 4564 | if (i == word.length - 1) { | 4338 | if (i == word.length - 1) { |
| 4565 | full_matches = cn.values[j]; | 4339 | full_matches = cn.values[j]; |
| 4566 | subtree_root = cn.next[j]; | 4340 | subtree_root = cn.next[j]; |
| 4567 | break char_loop; | 4341 | break char_loop; |
| 4568 | } | 4342 | } |
| 4569 | | 4343 | |
| 4570 | let next = cn.next[j]; | 4344 | let next = cn.next[j]; |
| 4571 | if (next == null) return null; | 4345 | if (next == null) return null; |
| 4572 | cn = next; | 4346 | cn = next; |
| 4573 | i += 1; | 4347 | i += 1; |
| 4574 | continue char_loop; | 4348 | continue char_loop; |
| 4575 | } | 4349 | } |
| 4576 | } | 4350 | } |
| 4577 | | 4351 | |
| 4578 | // didn't find a match | 4352 | // didn't find a match |
| 4579 | return null; | 4353 | return null; |
| 4580 | } | 4354 | } |
| 4581 | } | 4355 | } |
| 4582 | | 4356 | |
| 4583 | // Match was found, let's collect all other | 4357 | // Match was found, let's collect all other |
| 4584 | // partial matches from the subtree | 4358 | // partial matches from the subtree |
| 4585 | let stack = [subtree_root]; | 4359 | let stack = [subtree_root]; |
| ... | @@ -4594,22 +4368,22 @@ function RadixTree() { | ... | @@ -4594,22 +4368,22 @@ function RadixTree() { |
| 4594 | for (let v of node.values) { | 4368 | for (let v of node.values) { |
| 4595 | partial_matches = partial_matches.concat(v); | 4369 | partial_matches = partial_matches.concat(v); |
| 4596 | } | 4370 | } |
| 4597 | | 4371 | |
| 4598 | for (let n of node.next) { | 4372 | for (let n of node.next) { |
| 4599 | if (n != null) stack.push(n); | 4373 | if (n != null) stack.push(n); |
| 4600 | } | 4374 | } |
| 4601 | } | 4375 | } |
| 4602 | } | 4376 | } |
| 4603 | | 4377 | |
| 4604 | return {full: full_matches, partial: partial_matches}; | 4378 | return { full: full_matches, partial: partial_matches }; |
| 4605 | } | 4379 | } |
| 4606 | | 4380 | |
| 4607 | Node.prototype.add = function (word, value) { | 4381 | Node.prototype.add = function(word, value) { |
| 4608 | let cn = this; | 4382 | let cn = this; |
| 4609 | char_loop: for (let i = 0; i < word.length;) { | 4383 | char_loop: for (let i = 0; i < word.length;) { |
| 4610 | if (cn.isCompressed()) { | 4384 | if (cn.isCompressed()) { |
| 4611 | for(let j = 0; j < cn.labels.length; j += 1) { | 4385 | for (let j = 0; j < cn.labels.length; j += 1) { |
| 4612 | let current_idx = i+j; | 4386 | let current_idx = i + j; |
| 4613 | | 4387 | |
| 4614 | if (current_idx == word.length) { | 4388 | if (current_idx == word.length) { |
| 4615 | if (j < cn.labels.length - 1) { | 4389 | if (j < cn.labels.length - 1) { |
| ... | @@ -4621,13 +4395,13 @@ function RadixTree() { | ... | @@ -4621,13 +4395,13 @@ function RadixTree() { |
| 4621 | cn.values.push(value); | 4395 | cn.values.push(value); |
| 4622 | return; | 4396 | return; |
| 4623 | } | 4397 | } |
| 4624 | | 4398 | |
| 4625 | if (word[current_idx] == cn.labels[j]) continue; | 4399 | if (word[current_idx] == cn.labels[j]) continue; |
| 4626 | | 4400 | |
| 4627 | // if we're here, a mismatch was found | 4401 | // if we're here, a mismatch was found |
| 4628 | if (j != cn.labels.length - 1) { | 4402 | if (j != cn.labels.length - 1) { |
| 4629 | // create a suffix node | 4403 | // create a suffix node |
| 4630 | const label_suffix = cn.labels.slice(j+1); | 4404 | const label_suffix = cn.labels.slice(j + 1); |
| 4631 | let node = new Node(label_suffix, cn.next, [...cn.values]); | 4405 | let node = new Node(label_suffix, cn.next, [...cn.values]); |
| 4632 | cn.next = node; | 4406 | cn.next = node; |
| 4633 | cn.values = []; | 4407 | cn.values = []; |
| ... | @@ -4641,11 +4415,11 @@ function RadixTree() { | ... | @@ -4641,11 +4415,11 @@ function RadixTree() { |
| 4641 | // meaning that the current node should hold its value | 4415 | // meaning that the current node should hold its value |
| 4642 | word_values.push(value); | 4416 | word_values.push(value); |
| 4643 | } else { | 4417 | } else { |
| 4644 | node = new Node(word.slice(current_idx+1), null, [value]); | 4418 | node = new Node(word.slice(current_idx + 1), null, [value]); |
| 4645 | } | 4419 | } |
| 4646 | | 4420 | |
| 4647 | cn.labels = cn.labels[j] + word[current_idx]; | 4421 | cn.labels = cn.labels[j] + word[current_idx]; |
| 4648 | cn.next = [cn.next, node]; | 4422 | cn.next = [cn.next, node]; |
| 4649 | cn.values = [cn.values, word_values]; | 4423 | cn.values = [cn.values, word_values]; |
| 4650 | | 4424 | |
| 4651 | if (j != 0) { | 4425 | if (j != 0) { |
| ... | @@ -4657,7 +4431,7 @@ function RadixTree() { | ... | @@ -4657,7 +4431,7 @@ function RadixTree() { |
| 4657 | } | 4431 | } |
| 4658 | | 4432 | |
| 4659 | return; | 4433 | return; |
| 4660 | } | 4434 | } |
| 4661 | // label matched fully with word, are there any more chars? | 4435 | // label matched fully with word, are there any more chars? |
| 4662 | const new_idx = i + cn.labels.length; | 4436 | const new_idx = i + cn.labels.length; |
| 4663 | if (new_idx == word.length) { | 4437 | if (new_idx == word.length) { |
| ... | @@ -4673,7 +4447,7 @@ function RadixTree() { | ... | @@ -4673,7 +4447,7 @@ function RadixTree() { |
| 4673 | i = new_idx; | 4447 | i = new_idx; |
| 4674 | continue; | 4448 | continue; |
| 4675 | } | 4449 | } |
| 4676 | } | 4450 | } |
| 4677 | } else { // node is not compressed | 4451 | } else { // node is not compressed |
| 4678 | let letter = word[i]; | 4452 | let letter = word[i]; |
| 4679 | for (let j = 0; j < cn.labels.length; j += 1) { | 4453 | for (let j = 0; j < cn.labels.length; j += 1) { |
| ... | @@ -4683,7 +4457,7 @@ function RadixTree() { | ... | @@ -4683,7 +4457,7 @@ function RadixTree() { |
| 4683 | return; | 4457 | return; |
| 4684 | } | 4458 | } |
| 4685 | if (cn.next[j] == null) { | 4459 | if (cn.next[j] == null) { |
| 4686 | let node = new Node(word.slice(i+1), null, [value]); | 4460 | let node = new Node(word.slice(i + 1), null, [value]); |
| 4687 | cn.next[j] = node; | 4461 | cn.next[j] = node; |
| 4688 | return; | 4462 | return; |
| 4689 | } else { | 4463 | } else { |
| ... | @@ -4700,7 +4474,7 @@ function RadixTree() { | ... | @@ -4700,7 +4474,7 @@ function RadixTree() { |
| 4700 | cn.next.push(null); | 4474 | cn.next.push(null); |
| 4701 | cn.values.push([value]); | 4475 | cn.values.push([value]); |
| 4702 | } else { | 4476 | } else { |
| 4703 | let node = new Node(word.slice(i+1), null, [value]); | 4477 | let node = new Node(word.slice(i + 1), null, [value]); |
| 4704 | cn.next.push(node); | 4478 | cn.next.push(node); |
| 4705 | cn.values.push([]); | 4479 | cn.values.push([]); |
| 4706 | } | 4480 | } |