Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
franziskuskiefer committed Jun 18, 2018
1 parent d87ea34 commit 0e71443
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/check.py
Expand Up @@ -249,7 +249,7 @@ def read(node) -> None:
fun_name = node.value.func.id
# Check speclib functions that make types.
if fun_name is "range_t" or fun_name is "array_t" or \
fun_name is "bytes_t" or fun_name is "refine":
fun_name is "bytes_t" or fun_name is "refine_t":
if len(node.targets) > 1:
fail("Custom type assignment must have single assignment target " + str(fun_name))
type_name = node.targets[0]
Expand Down Expand Up @@ -372,6 +372,10 @@ def read(node) -> None:
return
if isinstance(node, UnaryOp):
return
if isinstance(node, Or):
return
if isinstance(node, And):
return
if isinstance(node, Compare):
read(node.left)
for c in node.comparators:
Expand All @@ -381,7 +385,7 @@ def read(node) -> None:
return

if isinstance(node, BoolOp):
# node.op
read(node.op)
for ex in node.values:
read(ex)
return
Expand Down
24 changes: 24 additions & 0 deletions tools/list.py
Expand Up @@ -24,6 +24,23 @@ def print_function(functionNode, indent=" "):
print(return_type, end="")
print("")

def print_constant(node):
target = str(node.targets)
if isinstance(node.targets[0], Name):
target = node.targets[0].id
if isinstance(node.targets[0], Tuple):
elts = node.targets[0].elts
target = ", ".join([e.id for e in elts])
value = str(node.value)
if isinstance(node.value, Name):
value = node.value.id
if isinstance(node.value, Call):
if isinstance(node.value.func, Attribute):
value = node.value.func.value.id
if isinstance(node.value.func, Name):
value = node.value.func.id
print(target + " := " + value)

if len(argv) != 2:
print("Usage: list.py <file>")
exit(1)
Expand All @@ -33,12 +50,19 @@ def print_function(functionNode, indent=" "):

functions = [n for n in node.body if isinstance(n, FunctionDef)]
classes = [n for n in node.body if isinstance(n, ClassDef)]
constants = [n for n in node.body if isinstance(n, Assign)]

print(" === Functions ===")
for function in functions:
print_function(function, "")

print(" === Classes ===")
for class_ in classes:
print(class_.name + ":")
methods = [n for n in class_.body if isinstance(n, FunctionDef)]
for method in methods:
print_function(method)

print(" === Constants & Aliases ===")
for const in constants:
print_constant(const)

0 comments on commit 0e71443

Please sign in to comment.