Selaa lähdekoodia

Bug fixes.

tags/v1.0^2
Benjamin Attal 10 vuotta sitten
vanhempi
commit
525e049be0
4 muutettua tiedostoa jossa 23 lisäystä ja 17 poistoa
  1. +3
    -3
      bitshift/database/__init__.py
  2. +11
    -8
      bitshift/parser/__init__.py
  3. +4
    -4
      bitshift/parser/python.py
  4. +5
    -2
      bitshift/query/nodes.py

+ 3
- 3
bitshift/database/__init__.py Näytä tiedosto

@@ -32,7 +32,7 @@ class Database(object):
def _migrate(self, cursor, current): def _migrate(self, cursor, current):
"""Migrate the database to the latest schema version.""" """Migrate the database to the latest schema version."""
for version in xrange(current, 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]: for query in MIGRATIONS[version - 1]:
cursor.execute(query) cursor.execute(query)
cursor.execute("UPDATE version SET version = ?", (version + 1,)) 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(): for type_, name, loc_type, row, col, erow, ecol in cursor.fetchall():
sdict = symbols[Symbol.TYPES_INV[type_]] sdict = symbols[Symbol.TYPES_INV[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))
for type_, sdict in symbols.items(): for type_, sdict in symbols.items():
symbols[type_] = [(n, d, u) for n, (d, u) in sdict.iteritems()] symbols[type_] = [(n, d, u) for n, (d, u) in sdict.iteritems()]
@@ -147,7 +147,7 @@ class Database(object):
(DEFAULT, ?, ?, ?, ?, ?, ?)""" (DEFAULT, ?, ?, ?, ?, ?, ?)"""


for (name, decls, uses) in symbols: 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 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 decls] +
[tuple([sym_id, 1] + list(loc)) for loc in uses]) [tuple([sym_id, 1] + list(loc)) for loc in uses])


+ 11
- 8
bitshift/parser/__init__.py Näytä tiedosto

@@ -106,13 +106,7 @@ def parse_via_server(codelet):
server_socket.send("%d\n%s" % (len(codelet.code), codelet.code)) server_socket.send("%d\n%s" % (len(codelet.code), codelet.code))


symbols = json.loads(_recv_data(server_socket)) 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 = { PARSERS = {
"Python": parse_py, "Python": parse_py,
@@ -135,4 +129,13 @@ def parse(codelet):
lang_string = LANGS[lang] lang_string = LANGS[lang]
codelet.language = lang codelet.language = lang
if lang_string in PARSERS: 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

+ 4
- 4
bitshift/parser/python.py Näytä tiedosto

@@ -58,7 +58,7 @@ class _CachedWalker(ast.NodeVisitor):
""" """


line, col = node.lineno, node.col_offset line, col = node.lineno, node.col_offset
pos = (line, col, -1, -1)
pos = (line, col, line, col)


self.cache.append({'nodes': []}) self.cache.append({'nodes': []})
self.generic_visit(node) self.generic_visit(node)
@@ -107,7 +107,7 @@ class _CachedWalker(ast.NodeVisitor):
""" """


line, col = node.lineno, node.col_offset line, col = node.lineno, node.col_offset
pos = (line, col, -1, -1)
pos = (line, col, line, col)


if isinstance(node.func, ast.Name): if isinstance(node.func, ast.Name):
name = node.func.id name = node.func.id
@@ -154,7 +154,7 @@ def parse_py(codelet):


:param codelet: The codelet object to parsed. :param codelet: The codelet object to parsed.


:type code: Codelet
:type code: list
""" """


def strip_encoding(lines): def strip_encoding(lines):
@@ -179,4 +179,4 @@ def parse_py(codelet):
return return
cutter = _CachedWalker() cutter = _CachedWalker()
cutter.visit(tree) cutter.visit(tree)
codelet.symbols = cutter.accum
return cutter.accum

+ 5
- 2
bitshift/query/nodes.py Näytä tiedosto

@@ -194,8 +194,11 @@ class Symbol(_Node):
FUNCTION = 0 FUNCTION = 0
CLASS = 1 CLASS = 1
VARIABLE = 2 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): def __init__(self, type_, name):
""" """


Ladataan…
Peruuta
Tallenna