simplify compilation requestors
This commit is contained in:
56
query.cm
Normal file
56
query.cm
Normal file
@@ -0,0 +1,56 @@
|
||||
// query.cm — Semantic queries over index data.
|
||||
//
|
||||
// All functions take an index object (from index.cm) and return arrays of hits.
|
||||
|
||||
var query = {}
|
||||
|
||||
// Top-level this: references where name=="this" and enclosing==null.
|
||||
query.top_level_this = function(idx) {
|
||||
var hits = []
|
||||
var i = 0
|
||||
var ref = null
|
||||
while (i < length(idx.references)) {
|
||||
ref = idx.references[i]
|
||||
if (ref.name == "this" && ref.enclosing == null) {
|
||||
hits[] = ref
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
return hits
|
||||
}
|
||||
|
||||
// Intrinsic usage: find refs to a built-in name (e.g., print).
|
||||
query.intrinsic = function(idx, name) {
|
||||
var hits = []
|
||||
var i = 0
|
||||
var ref = null
|
||||
if (idx.intrinsic_refs == null) return hits
|
||||
while (i < length(idx.intrinsic_refs)) {
|
||||
ref = idx.intrinsic_refs[i]
|
||||
if (ref.name == name) {
|
||||
hits[] = ref
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
return hits
|
||||
}
|
||||
|
||||
// Variable declarations matching a name and optional kind filter.
|
||||
// kind is one of "var", "def", "fn", "param", or null (any).
|
||||
query.find_decl = function(idx, name, kind) {
|
||||
var hits = []
|
||||
var i = 0
|
||||
var sym = null
|
||||
while (i < length(idx.symbols)) {
|
||||
sym = idx.symbols[i]
|
||||
if (sym.name == name) {
|
||||
if (kind == null || sym.kind == kind) {
|
||||
hits[] = sym
|
||||
}
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
return hits
|
||||
}
|
||||
|
||||
return query
|
||||
Reference in New Issue
Block a user