diff --git a/bitshift/database/__init__.py b/bitshift/database/__init__.py index e3cb3f2..b3e6015 100644 --- a/bitshift/database/__init__.py +++ b/bitshift/database/__init__.py @@ -32,7 +32,7 @@ class Database(object): def _migrate(self, cursor, current): """Migrate the database to the latest schema version.""" for version in xrange(current, VERSION): - print "Migrating to %d..." % version + 1 + print "Migrating to %d..." % (version + 1) for query in MIGRATIONS[version - 1]: cursor.execute(query) cursor.execute("UPDATE version SET version = ?", (version + 1,)) @@ -97,7 +97,7 @@ class Database(object): for type_, name, loc_type, row, col, erow, ecol in cursor.fetchall(): sdict = symbols[Symbol.TYPES_INV[type_]] if name not in sdict: - sdict[name] = ((), ()) + sdict[name] = ([], []) sdict[name][loc_type].append((row, col, erow, ecol)) for type_, sdict in symbols.items(): symbols[type_] = [(n, d, u) for n, (d, u) in sdict.iteritems()] @@ -147,7 +147,7 @@ class Database(object): (DEFAULT, ?, ?, ?, ?, ?, ?)""" for (name, decls, uses) in symbols: - cursor.execute(query1, (code_id, Symbol.TYPES_INV[sym_type], name)) + cursor.execute(query1, (code_id, Symbol.TYPES_INV.index(sym_type), name)) sym_id = cursor.lastrowid params = ([tuple([sym_id, 0] + list(loc)) for loc in decls] + [tuple([sym_id, 1] + list(loc)) for loc in uses]) diff --git a/bitshift/parser/__init__.py b/bitshift/parser/__init__.py index 0c96e64..5c02b48 100644 --- a/bitshift/parser/__init__.py +++ b/bitshift/parser/__init__.py @@ -106,13 +106,7 @@ def parse_via_server(codelet): server_socket.send("%d\n%s" % (len(codelet.code), codelet.code)) symbols = json.loads(_recv_data(server_socket)) - symbols = {key: [(name, [tuple(loc) - for loc in syms[name]['assignments']], - [tuple(loc) for loc in syms[name]['uses']]) - for name in syms.keys()] - for key, syms in symbols.iteritems()} - - codelet.symbols = symbols + return symbols PARSERS = { "Python": parse_py, @@ -135,4 +129,13 @@ def parse(codelet): lang_string = LANGS[lang] codelet.language = lang if lang_string in PARSERS: - PARSERS[lang_string](codelet) + symbols = PARSERS[lang_string](codelet) + symbols = {key: [(name, [tuple(loc) + for loc in syms[name]['assignments']], + [tuple(loc) for loc in syms[name]['uses']]) + for name in syms.keys()] + for key, syms in symbols.iteritems()} + + codelet.symbols = symbols + + codelet.symbols = symbols diff --git a/bitshift/parser/python.py b/bitshift/parser/python.py index 3cb141d..67d2631 100644 --- a/bitshift/parser/python.py +++ b/bitshift/parser/python.py @@ -58,7 +58,7 @@ class _CachedWalker(ast.NodeVisitor): """ line, col = node.lineno, node.col_offset - pos = (line, col, -1, -1) + pos = (line, col, line, col) self.cache.append({'nodes': []}) self.generic_visit(node) @@ -107,7 +107,7 @@ class _CachedWalker(ast.NodeVisitor): """ line, col = node.lineno, node.col_offset - pos = (line, col, -1, -1) + pos = (line, col, line, col) if isinstance(node.func, ast.Name): name = node.func.id @@ -154,7 +154,7 @@ def parse_py(codelet): :param codelet: The codelet object to parsed. - :type code: Codelet + :type code: list """ def strip_encoding(lines): @@ -179,4 +179,4 @@ def parse_py(codelet): return cutter = _CachedWalker() cutter.visit(tree) - codelet.symbols = cutter.accum + return cutter.accum diff --git a/bitshift/query/nodes.py b/bitshift/query/nodes.py index d375ffb..2596645 100644 --- a/bitshift/query/nodes.py +++ b/bitshift/query/nodes.py @@ -194,8 +194,11 @@ class Symbol(_Node): FUNCTION = 0 CLASS = 1 VARIABLE = 2 - TYPES = {FUNCTION: "FUNCTION", CLASS: "CLASS", VARIABLE: "VARIABLE"} - TYPES_INV = ["functions", "classes", "vars"] + MODULE = 3 + INTERFACE = 4 + TYPES = {FUNCTION: "FUNCTION", CLASS: "CLASS", VARIABLE: "VARIABLE", + MODULE: "MODULE", INTERFACE: "INTERFACE"} + TYPES_INV = ["functions", "classes", "vars", "modules", "interfaces"] def __init__(self, type_, name): """