@@ -92,10 +92,10 @@ class Database(object): | |||||
return {} | return {} | ||||
cond = " OR ".join(conds) | 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)) | cursor.execute(query % cond, tuple(args)) | ||||
for type_, name, loc_type, row, col, erow, ecol in cursor.fetchall(): | 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: | if name not in sdict: | ||||
sdict[name] = ([], []) | sdict[name] = ([], []) | ||||
sdict[name][loc_type].append((row, col, erow, ecol)) | sdict[name][loc_type].append((row, col, erow, ecol)) | ||||
@@ -146,10 +146,11 @@ class Database(object): | |||||
query2 = """INSERT INTO symbol_locations VALUES | query2 = """INSERT INTO symbol_locations VALUES | ||||
(DEFAULT, ?, ?, ?, ?, ?, ?)""" | (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 | 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]) | [tuple([sym_id, 1] + list(loc)) for loc in uses]) | ||||
cursor.executemany(query2, params) | cursor.executemany(query2, params) | ||||
@@ -70,7 +70,8 @@ def _recv_data(server_socket): | |||||
size_data += cur_data | size_data += cur_data | ||||
size = struct.unpack('>i', size_data[:4])[0] | size = struct.unpack('>i', size_data[:4])[0] | ||||
recv_size = size | 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:]) | total_data.append(size_data[4:]) | ||||
else: | else: | ||||
size_data += cur_data | size_data += cur_data | ||||
@@ -130,12 +131,10 @@ def parse(codelet): | |||||
codelet.language = lang | codelet.language = lang | ||||
if lang_string in PARSERS: | if lang_string in PARSERS: | ||||
symbols = 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()] | |||||
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()} | for key, syms in symbols.iteritems()} | ||||
codelet.symbols = symbols | codelet.symbols = symbols | ||||
codelet.symbols = symbols |
@@ -196,9 +196,8 @@ class Symbol(_Node): | |||||
VARIABLE = 2 | VARIABLE = 2 | ||||
MODULE = 3 | MODULE = 3 | ||||
INTERFACE = 4 | 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): | def __init__(self, type_, name): | ||||
""" | """ | ||||
@@ -209,7 +208,7 @@ class Symbol(_Node): | |||||
self.name = name | self.name = name | ||||
def __repr__(self): | 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) | return "Symbol({0}, {1})".format(type_, self.name) | ||||
def sortkey(self): | def sortkey(self): | ||||
@@ -222,7 +221,7 @@ class Symbol(_Node): | |||||
else: | else: | ||||
cond, name = "symbol_name = ?", self.name.string | cond, name = "symbol_name = ?", self.name.string | ||||
if self.type == self.ALL: | 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 | cond += " AND symbol_type IN (%s)" % types | ||||
if self.type != self.ALL: | if self.type != self.ALL: | ||||
cond += " AND symbol_type = %d" % self.type | cond += " AND symbol_type = %d" % self.type | ||||