Browse Source

Bug fixes.

tags/v1.0^2
Benjamin Attal 10 years ago
parent
commit
525e049be0
4 changed files with 23 additions and 17 deletions
  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 View File

@@ -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])


+ 11
- 8
bitshift/parser/__init__.py View File

@@ -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

+ 4
- 4
bitshift/parser/python.py View File

@@ -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

+ 5
- 2
bitshift/query/nodes.py View File

@@ -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):
"""


Loading…
Cancel
Save