Merge branch 'sem_grab'
This commit is contained in:
8
index.cm
8
index.cm
@@ -261,8 +261,12 @@ var index_ast = function(ast, tokens, filename) {
|
|||||||
// Function / arrow function expression — walk body.
|
// Function / arrow function expression — walk body.
|
||||||
if (node.kind == "function" || node.kind == "arrow function") {
|
if (node.kind == "function" || node.kind == "arrow function") {
|
||||||
enc = enclosing
|
enc = enclosing
|
||||||
if (node.name != null && node.function_nr != null) {
|
if (node.function_nr != null) {
|
||||||
enc = filename + ":" + node.name + ":fn"
|
if (node.name != null) {
|
||||||
|
enc = filename + ":" + node.name + ":fn"
|
||||||
|
} else {
|
||||||
|
enc = filename + ":anon_" + text(node.function_nr) + ":fn"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Record params as symbols.
|
// Record params as symbols.
|
||||||
if (node.list != null) {
|
if (node.list != null) {
|
||||||
|
|||||||
19
query.ce
19
query.ce
@@ -1,10 +1,10 @@
|
|||||||
// cell query — Semantic queries across packages.
|
// cell query — Semantic queries across packages.
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
// cell query --this [<package>] Top-level this references
|
// cell query --this [--top|--fn] [<package>] this references
|
||||||
// cell query --intrinsic <name> [<package>] Find built-in intrinsic usage
|
// cell query --intrinsic <name> [<package>] Find built-in intrinsic usage
|
||||||
// cell query --decl <name> [<package>] Variable declarations by name
|
// cell query --decl <name> [<package>] Variable declarations by name
|
||||||
// cell query --help Show usage
|
// cell query --help Show usage
|
||||||
|
|
||||||
var shop = use('internal/shop')
|
var shop = use('internal/shop')
|
||||||
var query_mod = use('query')
|
var query_mod = use('query')
|
||||||
@@ -12,6 +12,7 @@ var fd = use('fd')
|
|||||||
|
|
||||||
var mode = null
|
var mode = null
|
||||||
var name = null
|
var name = null
|
||||||
|
var this_scope = null
|
||||||
var pkg_filter = null
|
var pkg_filter = null
|
||||||
var show_help = false
|
var show_help = false
|
||||||
var i = 0
|
var i = 0
|
||||||
@@ -19,6 +20,10 @@ var i = 0
|
|||||||
for (i = 0; i < length(args); i++) {
|
for (i = 0; i < length(args); i++) {
|
||||||
if (args[i] == '--this') {
|
if (args[i] == '--this') {
|
||||||
mode = "this"
|
mode = "this"
|
||||||
|
} else if (args[i] == '--top') {
|
||||||
|
this_scope = "top"
|
||||||
|
} else if (args[i] == '--fn') {
|
||||||
|
this_scope = "fn"
|
||||||
} else if (args[i] == '--intrinsic') {
|
} else if (args[i] == '--intrinsic') {
|
||||||
mode = "intrinsic"
|
mode = "intrinsic"
|
||||||
if (i + 1 < length(args) && !starts_with(args[i + 1], '-')) {
|
if (i + 1 < length(args) && !starts_with(args[i + 1], '-')) {
|
||||||
@@ -65,7 +70,9 @@ if (show_help) {
|
|||||||
log.console("Semantic queries across packages.")
|
log.console("Semantic queries across packages.")
|
||||||
log.console("")
|
log.console("")
|
||||||
log.console("Options:")
|
log.console("Options:")
|
||||||
log.console(" --this Top-level this references")
|
log.console(" --this All this references")
|
||||||
|
log.console(" --this --top Top-level this only (not inside functions)")
|
||||||
|
log.console(" --this --fn this inside functions only")
|
||||||
log.console(" --intrinsic <name> Find built-in intrinsic usage (e.g., print)")
|
log.console(" --intrinsic <name> Find built-in intrinsic usage (e.g., print)")
|
||||||
log.console(" --decl <name> Variable declarations by name")
|
log.console(" --decl <name> Variable declarations by name")
|
||||||
log.console("")
|
log.console("")
|
||||||
@@ -93,7 +100,7 @@ if (show_help) {
|
|||||||
|
|
||||||
hits = null
|
hits = null
|
||||||
if (mode == "this") {
|
if (mode == "this") {
|
||||||
hits = query_mod.top_level_this(idx)
|
hits = query_mod.find_this(idx, this_scope)
|
||||||
} else if (mode == "intrinsic") {
|
} else if (mode == "intrinsic") {
|
||||||
hits = query_mod.intrinsic(idx, name)
|
hits = query_mod.intrinsic(idx, name)
|
||||||
} else if (mode == "decl") {
|
} else if (mode == "decl") {
|
||||||
|
|||||||
14
query.cm
14
query.cm
@@ -4,15 +4,21 @@
|
|||||||
|
|
||||||
var query = {}
|
var query = {}
|
||||||
|
|
||||||
// Top-level this: references where name=="this" and enclosing==null.
|
// Find this references. scope: "top" (top-level only), "fn" (in functions), null (all).
|
||||||
query.top_level_this = function(idx) {
|
query.find_this = function(idx, scope) {
|
||||||
var hits = []
|
var hits = []
|
||||||
var i = 0
|
var i = 0
|
||||||
var ref = null
|
var ref = null
|
||||||
while (i < length(idx.references)) {
|
while (i < length(idx.references)) {
|
||||||
ref = idx.references[i]
|
ref = idx.references[i]
|
||||||
if (ref.name == "this" && ref.enclosing == null) {
|
if (ref.name == "this") {
|
||||||
hits[] = ref
|
if (scope == null) {
|
||||||
|
hits[] = ref
|
||||||
|
} else if (scope == "top" && ref.enclosing == null) {
|
||||||
|
hits[] = ref
|
||||||
|
} else if (scope == "fn" && ref.enclosing != null) {
|
||||||
|
hits[] = ref
|
||||||
|
}
|
||||||
}
|
}
|
||||||
i = i + 1
|
i = i + 1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user