diff --git a/bitshift/database/__init__.py b/bitshift/database/__init__.py index b3e6015..5f483f3 100644 --- a/bitshift/database/__init__.py +++ b/bitshift/database/__init__.py @@ -92,10 +92,10 @@ class Database(object): return {} cond = " OR ".join(conds) - symbols = {type_: {} for type_ in Symbol.TYPES_INV} + symbols = {type_: {} for type_ in Symbol.TYPES} cursor.execute(query % cond, tuple(args)) for type_, name, loc_type, row, col, erow, ecol in cursor.fetchall(): - sdict = symbols[Symbol.TYPES_INV[type_]] + sdict = symbols[Symbol.TYPES[type_]] if name not in sdict: sdict[name] = ([], []) sdict[name][loc_type].append((row, col, erow, ecol)) @@ -146,10 +146,11 @@ class Database(object): query2 = """INSERT INTO symbol_locations VALUES (DEFAULT, ?, ?, ?, ?, ?, ?)""" - for (name, decls, uses) in symbols: - cursor.execute(query1, (code_id, Symbol.TYPES_INV.index(sym_type), name)) + type_id = Symbol.TYPES.index(sym_type) + for (name, assigns, uses) in symbols: + cursor.execute(query1, (code_id, type_id, name)) sym_id = cursor.lastrowid - params = ([tuple([sym_id, 0] + list(loc)) for loc in decls] + + params = ([tuple([sym_id, 0] + list(loc)) for loc in assigns] + [tuple([sym_id, 1] + list(loc)) for loc in uses]) cursor.executemany(query2, params) diff --git a/bitshift/parser/__init__.py b/bitshift/parser/__init__.py index 5c02b48..675d8bb 100644 --- a/bitshift/parser/__init__.py +++ b/bitshift/parser/__init__.py @@ -70,7 +70,8 @@ def _recv_data(server_socket): size_data += cur_data size = struct.unpack('>i', size_data[:4])[0] recv_size = size - if recv_size > sys.maxint: recv_size = sys.maxint + if recv_size > sys.maxint: + recv_size = sys.maxint total_data.append(size_data[4:]) else: size_data += cur_data @@ -130,12 +131,10 @@ def parse(codelet): codelet.language = lang if lang_string in PARSERS: 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()] + symbols = { + key: [(name, + [tuple(loc) for loc in syms[name]["assignments"]], + [tuple(loc) for loc in syms[name]["uses"]]) + for name in syms] for key, syms in symbols.iteritems()} - codelet.symbols = symbols - - codelet.symbols = symbols diff --git a/bitshift/query/nodes.py b/bitshift/query/nodes.py index 2596645..cd21fc8 100644 --- a/bitshift/query/nodes.py +++ b/bitshift/query/nodes.py @@ -196,9 +196,8 @@ class Symbol(_Node): VARIABLE = 2 MODULE = 3 INTERFACE = 4 - TYPES = {FUNCTION: "FUNCTION", CLASS: "CLASS", VARIABLE: "VARIABLE", - MODULE: "MODULE", INTERFACE: "INTERFACE"} - TYPES_INV = ["functions", "classes", "vars", "modules", "interfaces"] + TYPES = ["functions", "classes", "vars", "modules", "interfaces"] + TYPE_REPR = ["FUNCTION", "CLASS", "VARIABLE", "MODULE", "INTERFACE"] def __init__(self, type_, name): """ @@ -209,7 +208,7 @@ class Symbol(_Node): self.name = name def __repr__(self): - type_ = self.TYPES.get(self.type, "ALL") + type_ = self.TYPE_REPR[self.type] if self.type >= 0 else "ALL" return "Symbol({0}, {1})".format(type_, self.name) def sortkey(self): @@ -222,7 +221,7 @@ class Symbol(_Node): else: cond, name = "symbol_name = ?", self.name.string if self.type == self.ALL: - types = ", ".join(str(type_) for type_ in self.TYPES) + types = ", ".join(str(typ) for typ in xrange(len(self.TYPES))) cond += " AND symbol_type IN (%s)" % types if self.type != self.ALL: cond += " AND symbol_type = %d" % self.type