mirror of
https://github.com/ziglang/zig.git
synced 2025-12-15 18:53:07 +00:00
generated docs contain generic instantiations and comptime calls
This commit is contained in:
parent
ffc0c26b27
commit
a55db08a7b
@ -2439,3 +2439,8 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
|
|||||||
);
|
);
|
||||||
std.debug.warn("{} sp = 0x{x}\n", prefix, sp);
|
std.debug.warn("{} sp = 0x{x}\n", prefix, sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reference everything so it gets tested.
|
||||||
|
test "" {
|
||||||
|
_ = leb;
|
||||||
|
}
|
||||||
|
|||||||
@ -210,6 +210,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<h1 id="hdrName" class="hidden"></h1>
|
<h1 id="hdrName" class="hidden"></h1>
|
||||||
<div id="fnDocs" class="hidden"></div>
|
<div id="fnDocs" class="hidden"></div>
|
||||||
|
<div id="fnExamples" class="hidden"></div>
|
||||||
|
<div id="fnNoExamples" class="hidden">
|
||||||
|
<p>This function is not tested or referenced.</p>
|
||||||
|
</div>
|
||||||
<div id="sectSearchResults" class="hidden">
|
<div id="sectSearchResults" class="hidden">
|
||||||
<h2>Search Results</h2>
|
<h2>Search Results</h2>
|
||||||
<ul id="listSearchResults"></ul>
|
<ul id="listSearchResults"></ul>
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
var domFnProto = document.getElementById("fnProto");
|
var domFnProto = document.getElementById("fnProto");
|
||||||
var domFnProtoCode = document.getElementById("fnProtoCode");
|
var domFnProtoCode = document.getElementById("fnProtoCode");
|
||||||
var domFnDocs = document.getElementById("fnDocs");
|
var domFnDocs = document.getElementById("fnDocs");
|
||||||
|
var domFnExamples = document.getElementById("fnExamples");
|
||||||
|
var domFnNoExamples = document.getElementById("fnNoExamples");
|
||||||
var domSearch = document.getElementById("search");
|
var domSearch = document.getElementById("search");
|
||||||
var domSectSearchResults = document.getElementById("sectSearchResults");
|
var domSectSearchResults = document.getElementById("sectSearchResults");
|
||||||
var domListSearchResults = document.getElementById("listSearchResults");
|
var domListSearchResults = document.getElementById("listSearchResults");
|
||||||
@ -50,6 +52,12 @@
|
|||||||
|
|
||||||
var rootIsStd = detectRootIsStd();
|
var rootIsStd = detectRootIsStd();
|
||||||
var typeTypeId = findTypeTypeId();
|
var typeTypeId = findTypeTypeId();
|
||||||
|
|
||||||
|
// map of decl index to list of non-generic fn indexes
|
||||||
|
var nodesToFnsMap = indexNodesToFns();
|
||||||
|
// map of decl index to list of comptime fn calls
|
||||||
|
var nodesToCallsMap = indexNodesToCalls();
|
||||||
|
|
||||||
domSearch.addEventListener('keydown', onSearchKeyDown, false);
|
domSearch.addEventListener('keydown', onSearchKeyDown, false);
|
||||||
window.addEventListener('hashchange', onHashChange, false);
|
window.addEventListener('hashchange', onHashChange, false);
|
||||||
window.addEventListener('keydown', onWindowKeyDown, false);
|
window.addEventListener('keydown', onWindowKeyDown, false);
|
||||||
@ -81,6 +89,8 @@
|
|||||||
domSectInfo.classList.add("hidden");
|
domSectInfo.classList.add("hidden");
|
||||||
domHdrName.classList.add("hidden");
|
domHdrName.classList.add("hidden");
|
||||||
domSectNav.classList.add("hidden");
|
domSectNav.classList.add("hidden");
|
||||||
|
domFnExamples.classList.add("hidden");
|
||||||
|
domFnNoExamples.classList.add("hidden");
|
||||||
|
|
||||||
renderTitle();
|
renderTitle();
|
||||||
renderInfo();
|
renderInfo();
|
||||||
@ -138,16 +148,51 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function typeIsGenericFn(typeIndex) {
|
||||||
|
var typeObj = zigAnalysis.types[typeIndex];
|
||||||
|
if (typeObj.kind !== typeKindFnId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return typeObj.generic;
|
||||||
|
}
|
||||||
|
|
||||||
function renderFn(fnDecl) {
|
function renderFn(fnDecl) {
|
||||||
var typeObj = zigAnalysis.types[fnDecl.type];
|
var typeObj = zigAnalysis.types[fnDecl.type];
|
||||||
domFnProtoCode.textContent = "fn " + fnDecl.name + typeObj.name.substring(2);
|
domFnProtoCode.textContent = "fn " + fnDecl.name + typeObj.name.substring(2);
|
||||||
|
|
||||||
|
var docsSource = null;
|
||||||
var srcNode = zigAnalysis.astNodes[fnDecl.src];
|
var srcNode = zigAnalysis.astNodes[fnDecl.src];
|
||||||
if (srcNode.docs != null) {
|
if (srcNode.docs != null) {
|
||||||
domFnDocs.innerHTML = markdown(srcNode.docs);
|
docsSource = srcNode.docs;
|
||||||
domFnDocs.classList.remove("hidden");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var protoSrcIndex;
|
||||||
|
if (typeIsGenericFn(fnDecl.type)) {
|
||||||
|
protoSrcIndex = fnDecl.value;
|
||||||
|
|
||||||
|
var instantiations = nodesToFnsMap[protoSrcIndex];
|
||||||
|
var calls = nodesToCallsMap[protoSrcIndex];
|
||||||
|
if (instantiations == null && calls == null) {
|
||||||
|
domFnNoExamples.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
// TODO show examples
|
||||||
|
domFnExamples.classList.remove("hidden");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
protoSrcIndex = zigAnalysis.fns[fnDecl.value].src;
|
||||||
|
|
||||||
|
domFnExamples.classList.add("hidden");
|
||||||
|
domFnNoExamples.classList.add("hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
var protoSrcNode = zigAnalysis.astNodes[protoSrcIndex];
|
||||||
|
if (docsSource == null && protoSrcNode.docs != null) {
|
||||||
|
docsSource = protoSrcNode.docs;
|
||||||
|
}
|
||||||
|
if (docsSource != null) {
|
||||||
|
domFnDocs.innerHTML = markdown(docsSource);
|
||||||
|
domFnDocs.classList.remove("hidden");
|
||||||
|
}
|
||||||
domFnProto.classList.remove("hidden");
|
domFnProto.classList.remove("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,6 +313,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function allCompTimeFnCallsHaveTypeResult(typeIndex, value) {
|
||||||
|
var srcIndex = typeIsGenericFn(typeIndex) ? value : zigAnalysis.fns[value].src;
|
||||||
|
var calls = nodesToCallsMap[srcIndex];
|
||||||
|
if (calls == null) return false;
|
||||||
|
for (var i = 0; i < calls.length; i += 1) {
|
||||||
|
var call = zigAnalysis.calls[calls[i]];
|
||||||
|
if (call.result.type !== typeTypeId) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function renderContainer(container) {
|
function renderContainer(container) {
|
||||||
var typesList = [];
|
var typesList = [];
|
||||||
var fnsList = [];
|
var fnsList = [];
|
||||||
@ -279,11 +335,15 @@
|
|||||||
} else {
|
} else {
|
||||||
var typeKind = zigAnalysis.types[decl.type].kind;
|
var typeKind = zigAnalysis.types[decl.type].kind;
|
||||||
if (typeKind === typeKindFnId) {
|
if (typeKind === typeKindFnId) {
|
||||||
|
if (allCompTimeFnCallsHaveTypeResult(decl.type, decl.value)) {
|
||||||
|
typesList.push(decl);
|
||||||
|
} else {
|
||||||
fnsList.push(decl);
|
fnsList.push(decl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
typesList.sort(function(a, b) {
|
typesList.sort(function(a, b) {
|
||||||
return operatorCompare(a.name, b.name);
|
return operatorCompare(a.name, b.name);
|
||||||
});
|
});
|
||||||
@ -688,4 +748,32 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function indexNodesToFns() {
|
||||||
|
var map = {};
|
||||||
|
for (var i = 0; i < zigAnalysis.fns.length; i += 1) {
|
||||||
|
var fn = zigAnalysis.fns[i];
|
||||||
|
if (typeIsGenericFn(fn.type)) continue;
|
||||||
|
if (map[fn.src] == null) {
|
||||||
|
map[fn.src] = [i];
|
||||||
|
} else {
|
||||||
|
map[fn.src].push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
function indexNodesToCalls() {
|
||||||
|
var map = {};
|
||||||
|
for (var i = 0; i < zigAnalysis.calls.length; i += 1) {
|
||||||
|
var call = zigAnalysis.calls[i];
|
||||||
|
var fn = zigAnalysis.fns[call.fn];
|
||||||
|
if (map[fn.src] == null) {
|
||||||
|
map[fn.src] = [i];
|
||||||
|
} else {
|
||||||
|
map[fn.src].push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
120
lib/std/std.zig
120
lib/std/std.zig
@ -62,61 +62,69 @@ pub const unicode = @import("unicode.zig");
|
|||||||
pub const valgrind = @import("valgrind.zig");
|
pub const valgrind = @import("valgrind.zig");
|
||||||
pub const zig = @import("zig.zig");
|
pub const zig = @import("zig.zig");
|
||||||
|
|
||||||
test "std" {
|
// Reference everything so it gets tested.
|
||||||
// run tests from these
|
test "" {
|
||||||
_ = @import("array_list.zig");
|
_ = AlignedArrayList;
|
||||||
_ = @import("atomic.zig");
|
_ = ArrayList;
|
||||||
_ = @import("bloom_filter.zig");
|
_ = AutoHashMap;
|
||||||
_ = @import("buf_map.zig");
|
_ = BloomFilter;
|
||||||
_ = @import("buf_set.zig");
|
_ = BufMap;
|
||||||
_ = @import("buffer.zig");
|
_ = BufSet;
|
||||||
_ = @import("hash_map.zig");
|
_ = Buffer;
|
||||||
_ = @import("linked_list.zig");
|
_ = BufferOutStream;
|
||||||
_ = @import("mutex.zig");
|
_ = DynLib;
|
||||||
_ = @import("statically_initialized_mutex.zig");
|
_ = HashMap;
|
||||||
_ = @import("segmented_list.zig");
|
_ = Mutex;
|
||||||
_ = @import("spinlock.zig");
|
_ = PackedIntArrayEndian;
|
||||||
_ = @import("child_process.zig");
|
_ = PackedIntArray;
|
||||||
|
_ = PackedIntSliceEndian;
|
||||||
|
_ = PackedIntSlice;
|
||||||
|
_ = PriorityQueue;
|
||||||
|
_ = SinglyLinkedList;
|
||||||
|
_ = StaticallyInitializedMutex;
|
||||||
|
_ = SegmentedList;
|
||||||
|
_ = SpinLock;
|
||||||
|
_ = StringHashMap;
|
||||||
|
_ = ChildProcess;
|
||||||
|
_ = TailQueue;
|
||||||
|
_ = Thread;
|
||||||
|
|
||||||
_ = @import("ascii.zig");
|
_ = atomic;
|
||||||
_ = @import("base64.zig");
|
_ = base64;
|
||||||
_ = @import("build.zig");
|
_ = build;
|
||||||
_ = @import("c.zig");
|
_ = c;
|
||||||
_ = @import("coff.zig");
|
_ = coff;
|
||||||
_ = @import("crypto.zig");
|
_ = crypto;
|
||||||
_ = @import("cstr.zig");
|
_ = cstr;
|
||||||
_ = @import("debug.zig");
|
_ = debug;
|
||||||
_ = @import("dwarf.zig");
|
_ = dwarf;
|
||||||
_ = @import("dynamic_library.zig");
|
_ = elf;
|
||||||
_ = @import("elf.zig");
|
_ = event;
|
||||||
_ = @import("event.zig");
|
_ = fmt;
|
||||||
_ = @import("fmt.zig");
|
_ = fs;
|
||||||
_ = @import("fs.zig");
|
_ = hash;
|
||||||
_ = @import("hash.zig");
|
_ = hash_map;
|
||||||
_ = @import("heap.zig");
|
_ = heap;
|
||||||
_ = @import("http.zig");
|
_ = http;
|
||||||
_ = @import("io.zig");
|
_ = io;
|
||||||
_ = @import("json.zig");
|
_ = json;
|
||||||
_ = @import("lazy_init.zig");
|
_ = lazyInit;
|
||||||
_ = @import("macho.zig");
|
_ = macho;
|
||||||
_ = @import("math.zig");
|
_ = math;
|
||||||
_ = @import("mem.zig");
|
_ = mem;
|
||||||
_ = @import("meta.zig");
|
_ = meta;
|
||||||
_ = @import("net.zig");
|
_ = net;
|
||||||
_ = @import("os.zig");
|
_ = os;
|
||||||
_ = @import("pdb.zig");
|
_ = packed_int_array;
|
||||||
_ = @import("process.zig");
|
_ = pdb;
|
||||||
_ = @import("packed_int_array.zig");
|
_ = process;
|
||||||
_ = @import("priority_queue.zig");
|
_ = rand;
|
||||||
_ = @import("rand.zig");
|
_ = rb;
|
||||||
_ = @import("rb.zig");
|
_ = sort;
|
||||||
_ = @import("sort.zig");
|
_ = ascii;
|
||||||
_ = @import("testing.zig");
|
_ = testing;
|
||||||
_ = @import("thread.zig");
|
_ = time;
|
||||||
_ = @import("time.zig");
|
_ = unicode;
|
||||||
_ = @import("unicode.zig");
|
_ = valgrind;
|
||||||
_ = @import("valgrind.zig");
|
_ = zig;
|
||||||
_ = @import("zig.zig");
|
|
||||||
|
|
||||||
_ = @import("debug/leb128.zig");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1325,6 +1325,9 @@ bool tld_ptr_eql(const Tld *a, const Tld *b);
|
|||||||
uint32_t node_ptr_hash(const AstNode *ptr);
|
uint32_t node_ptr_hash(const AstNode *ptr);
|
||||||
bool node_ptr_eql(const AstNode *a, const AstNode *b);
|
bool node_ptr_eql(const AstNode *a, const AstNode *b);
|
||||||
|
|
||||||
|
uint32_t fn_ptr_hash(const ZigFn *ptr);
|
||||||
|
bool fn_ptr_eql(const ZigFn *a, const ZigFn *b);
|
||||||
|
|
||||||
struct ZigTypeUnion {
|
struct ZigTypeUnion {
|
||||||
AstNode *decl_node;
|
AstNode *decl_node;
|
||||||
TypeUnionField *fields;
|
TypeUnionField *fields;
|
||||||
|
|||||||
@ -7328,6 +7328,14 @@ bool node_ptr_eql(const AstNode *a, const AstNode *b) {
|
|||||||
return a == b;
|
return a == b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t fn_ptr_hash(const ZigFn *ptr) {
|
||||||
|
return hash_ptr((void*)ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fn_ptr_eql(const ZigFn *a, const ZigFn *b) {
|
||||||
|
return a == b;
|
||||||
|
}
|
||||||
|
|
||||||
ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
|
ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
|
||||||
Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));
|
Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));
|
||||||
resolve_top_level_decl(codegen, tld, nullptr, false);
|
resolve_top_level_decl(codegen, tld, nullptr, false);
|
||||||
|
|||||||
@ -352,6 +352,9 @@ struct AnalDumpCtx {
|
|||||||
ZigList<Tld *> decl_list;
|
ZigList<Tld *> decl_list;
|
||||||
HashMap<const Tld *, uint32_t, tld_ptr_hash, tld_ptr_eql> decl_map;
|
HashMap<const Tld *, uint32_t, tld_ptr_hash, tld_ptr_eql> decl_map;
|
||||||
|
|
||||||
|
ZigList<ZigFn *> fn_list;
|
||||||
|
HashMap<const ZigFn *, uint32_t, fn_ptr_hash, fn_ptr_eql> fn_map;
|
||||||
|
|
||||||
ZigList<AstNode *> node_list;
|
ZigList<AstNode *> node_list;
|
||||||
HashMap<const AstNode *, uint32_t, node_ptr_hash, node_ptr_eql> node_map;
|
HashMap<const AstNode *, uint32_t, node_ptr_hash, node_ptr_eql> node_map;
|
||||||
};
|
};
|
||||||
@ -430,6 +433,17 @@ static uint32_t anal_dump_get_node_id(AnalDumpCtx *ctx, AstNode *node) {
|
|||||||
return node_id;
|
return node_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t anal_dump_get_fn_id(AnalDumpCtx *ctx, ZigFn *fn) {
|
||||||
|
uint32_t fn_id = ctx->fn_list.length;
|
||||||
|
auto existing_entry = ctx->fn_map.put_unique(fn, fn_id);
|
||||||
|
if (existing_entry == nullptr) {
|
||||||
|
ctx->fn_list.append(fn);
|
||||||
|
} else {
|
||||||
|
fn_id = existing_entry->value;
|
||||||
|
}
|
||||||
|
return fn_id;
|
||||||
|
}
|
||||||
|
|
||||||
static uint32_t anal_dump_get_decl_id(AnalDumpCtx *ctx, Tld *tld) {
|
static uint32_t anal_dump_get_decl_id(AnalDumpCtx *ctx, Tld *tld) {
|
||||||
uint32_t decl_id = ctx->decl_list.length;
|
uint32_t decl_id = ctx->decl_list.length;
|
||||||
auto existing_entry = ctx->decl_map.put_unique(tld, decl_id);
|
auto existing_entry = ctx->decl_map.put_unique(tld, decl_id);
|
||||||
@ -494,6 +508,11 @@ static void anal_dump_node_ref(AnalDumpCtx *ctx, AstNode *node) {
|
|||||||
jw_int(&ctx->jw, node_id);
|
jw_int(&ctx->jw, node_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void anal_dump_fn_ref(AnalDumpCtx *ctx, ZigFn *fn) {
|
||||||
|
uint32_t fn_id = anal_dump_get_fn_id(ctx, fn);
|
||||||
|
jw_int(&ctx->jw, fn_id);
|
||||||
|
}
|
||||||
|
|
||||||
static void anal_dump_decl_ref(AnalDumpCtx *ctx, Tld *tld) {
|
static void anal_dump_decl_ref(AnalDumpCtx *ctx, Tld *tld) {
|
||||||
uint32_t decl_id = anal_dump_get_decl_id(ctx, tld);
|
uint32_t decl_id = anal_dump_get_decl_id(ctx, tld);
|
||||||
jw_int(&ctx->jw, decl_id);
|
jw_int(&ctx->jw, decl_id);
|
||||||
@ -600,8 +619,10 @@ static void anal_dump_decl(AnalDumpCtx *ctx, Tld *tld) {
|
|||||||
|
|
||||||
jw_object_field(jw, "type");
|
jw_object_field(jw, "type");
|
||||||
anal_dump_type_ref(ctx, fn->type_entry);
|
anal_dump_type_ref(ctx, fn->type_entry);
|
||||||
}
|
|
||||||
|
|
||||||
|
jw_object_field(jw, "value");
|
||||||
|
anal_dump_fn_ref(ctx, fn);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -642,6 +663,19 @@ static void anal_dump_value(AnalDumpCtx *ctx, AstNode *source_node, ZigType *ty,
|
|||||||
anal_dump_type_ref(ctx, val_ty);
|
anal_dump_type_ref(ctx, val_ty);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case ZigTypeIdFn: {
|
||||||
|
if (value->data.x_ptr.special == ConstPtrSpecialFunction) {
|
||||||
|
ZigFn *val_fn = value->data.x_ptr.data.fn.fn_entry;
|
||||||
|
if (val_fn->type_entry->data.fn.is_generic) {
|
||||||
|
anal_dump_node_ref(ctx, val_fn->proto_node);
|
||||||
|
} else {
|
||||||
|
anal_dump_fn_ref(ctx, val_fn);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
jw_null(&ctx->jw);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
jw_null(&ctx->jw);
|
jw_null(&ctx->jw);
|
||||||
return;
|
return;
|
||||||
@ -721,6 +755,11 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
|
|||||||
jw_int(jw, ty->data.floating.bit_count);
|
jw_int(jw, ty->data.floating.bit_count);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ZigTypeIdFn: {
|
||||||
|
jw_object_field(jw, "generic");
|
||||||
|
jw_bool(jw, ty->data.fn.is_generic);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// TODO
|
// TODO
|
||||||
break;
|
break;
|
||||||
@ -763,7 +802,7 @@ void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) {
|
|||||||
doc_comments_buf = nullptr;
|
doc_comments_buf = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (doc_comments_buf->list.length != 0) {
|
if (doc_comments_buf != nullptr && doc_comments_buf->list.length != 0) {
|
||||||
jw_object_field(jw, "docs");
|
jw_object_field(jw, "docs");
|
||||||
jw_string(jw, buf_ptr(doc_comments_buf));
|
jw_string(jw, buf_ptr(doc_comments_buf));
|
||||||
}
|
}
|
||||||
@ -771,6 +810,19 @@ void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) {
|
|||||||
jw_end_object(jw);
|
jw_end_object(jw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void anal_dump_fn(AnalDumpCtx *ctx, ZigFn *fn) {
|
||||||
|
JsonWriter *jw = &ctx->jw;
|
||||||
|
|
||||||
|
jw_begin_object(jw);
|
||||||
|
|
||||||
|
jw_object_field(jw, "src");
|
||||||
|
anal_dump_node_ref(ctx, fn->proto_node);
|
||||||
|
|
||||||
|
jw_object_field(jw, "type");
|
||||||
|
anal_dump_type_ref(ctx, fn->type_entry);
|
||||||
|
|
||||||
|
jw_end_object(jw);
|
||||||
|
}
|
||||||
|
|
||||||
void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const char *nl) {
|
void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const char *nl) {
|
||||||
Error err;
|
Error err;
|
||||||
@ -783,6 +835,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
|
|||||||
ctx.file_map.init(16);
|
ctx.file_map.init(16);
|
||||||
ctx.decl_map.init(16);
|
ctx.decl_map.init(16);
|
||||||
ctx.node_map.init(16);
|
ctx.node_map.init(16);
|
||||||
|
ctx.fn_map.init(16);
|
||||||
|
|
||||||
jw_begin_object(jw);
|
jw_begin_object(jw);
|
||||||
|
|
||||||
@ -822,6 +875,71 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
|
|||||||
jw_object_field(jw, "rootPkg");
|
jw_object_field(jw, "rootPkg");
|
||||||
anal_dump_pkg_ref(&ctx, g->root_package);
|
anal_dump_pkg_ref(&ctx, g->root_package);
|
||||||
|
|
||||||
|
// Poke the functions
|
||||||
|
for (size_t i = 0; i < g->fn_defs.length; i += 1) {
|
||||||
|
ZigFn *fn = g->fn_defs.at(i);
|
||||||
|
(void)anal_dump_get_fn_id(&ctx, fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
jw_object_field(jw, "calls");
|
||||||
|
jw_begin_array(jw);
|
||||||
|
{
|
||||||
|
auto it = g->memoized_fn_eval_table.entry_iterator();
|
||||||
|
for (;;) {
|
||||||
|
auto *entry = it.next();
|
||||||
|
if (!entry)
|
||||||
|
break;
|
||||||
|
|
||||||
|
jw_array_elem(jw);
|
||||||
|
jw_begin_object(jw);
|
||||||
|
|
||||||
|
jw_object_field(jw, "args");
|
||||||
|
jw_begin_object(jw);
|
||||||
|
|
||||||
|
Scope *scope = entry->key;
|
||||||
|
while (scope != nullptr) {
|
||||||
|
if (scope->id == ScopeIdVarDecl) {
|
||||||
|
ZigVar *var = reinterpret_cast<ScopeVarDecl *>(scope)->var;
|
||||||
|
jw_object_field(jw, var->name);
|
||||||
|
jw_begin_object(jw);
|
||||||
|
jw_object_field(jw, "type");
|
||||||
|
anal_dump_type_ref(&ctx, var->var_type);
|
||||||
|
jw_object_field(jw, "value");
|
||||||
|
anal_dump_value(&ctx, scope->source_node, var->var_type, var->const_value);
|
||||||
|
jw_end_object(jw);
|
||||||
|
} else if (scope->id == ScopeIdFnDef) {
|
||||||
|
jw_end_object(jw);
|
||||||
|
|
||||||
|
jw_object_field(jw, "fn");
|
||||||
|
ZigFn *fn = reinterpret_cast<ScopeFnDef *>(scope)->fn_entry;
|
||||||
|
anal_dump_fn_ref(&ctx, fn);
|
||||||
|
|
||||||
|
ConstExprValue *result = entry->value;
|
||||||
|
jw_object_field(jw, "result");
|
||||||
|
jw_begin_object(jw);
|
||||||
|
jw_object_field(jw, "type");
|
||||||
|
anal_dump_type_ref(&ctx, result->type);
|
||||||
|
jw_object_field(jw, "value");
|
||||||
|
anal_dump_value(&ctx, scope->source_node, result->type, result);
|
||||||
|
jw_end_object(jw);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
scope = scope->parent;
|
||||||
|
}
|
||||||
|
jw_end_object(jw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jw_end_array(jw);
|
||||||
|
|
||||||
|
jw_object_field(jw, "fns");
|
||||||
|
jw_begin_array(jw);
|
||||||
|
for (uint32_t i = 0; i < ctx.fn_list.length; i += 1) {
|
||||||
|
ZigFn *fn = ctx.fn_list.at(i);
|
||||||
|
jw_array_elem(jw);
|
||||||
|
anal_dump_fn(&ctx, fn);
|
||||||
|
}
|
||||||
|
jw_end_array(jw);
|
||||||
|
|
||||||
jw_object_field(jw, "packages");
|
jw_object_field(jw, "packages");
|
||||||
jw_begin_array(jw);
|
jw_begin_array(jw);
|
||||||
for (uint32_t i = 0; i < ctx.pkg_list.length; i += 1) {
|
for (uint32_t i = 0; i < ctx.pkg_list.length; i += 1) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user