fix subroutine usage scanning

This commit is contained in:
Irmen de Jong 2018-01-15 21:12:17 +01:00
parent 8fc6a5ada9
commit db97be69fe
4 changed files with 11 additions and 22 deletions

View File

@ -267,18 +267,16 @@ class PlyParser:
self._get_subroutine_usages_from_return(module.subroutine_usage, node, block.scope)
elif isinstance(node, Assignment):
self._get_subroutine_usages_from_assignment(module.subroutine_usage, node, block.scope)
print("----------SUBROUTINES IN USE-------------") # XXX
import pprint
pprint.pprint(module.subroutine_usage) # XXX
print("----------/SUBROUTINES IN USE-------------") # XXX
def _get_subroutine_usages_from_subcall(self, usages: Dict[Tuple[str, str], Set[str]],
subcall: SubCall, parent_scope: Scope) -> None:
# node.target (relevant if its a symbolname -- a str), node.arguments (list of CallArgument)
# CallArgument.value = expression.
if isinstance(subcall.target.target, str):
try:
scopename, name = subcall.target.target.split('.')
except ValueError:
scopename = parent_scope.name
name = subcall.target.target
usages[(scopename, name)].add(str(subcall.sourceref))
target = subcall.target.target
if isinstance(target, SymbolName):
usages[(parent_scope.name, target.name)].add(str(subcall.sourceref))
for arg in subcall.arguments:
self._get_subroutine_usages_from_expression(usages, arg.value, parent_scope)
@ -309,14 +307,9 @@ class PlyParser:
def _get_subroutine_usages_from_goto(self, usages: Dict[Tuple[str, str], Set[str]],
goto: Goto, parent_scope: Scope) -> None:
# node.target (relevant if its a symbolname -- a str), node.condition (expression)
if isinstance(goto.target.target, str):
try:
symbol = parent_scope[goto.target.target]
except LookupError:
return
if isinstance(symbol, Subroutine):
usages[(parent_scope.name, symbol.name)].add(str(goto.sourceref))
target = goto.target.target
if isinstance(target, SymbolName):
usages[(parent_scope.name, target.name)].add(str(goto.sourceref))
self._get_subroutine_usages_from_expression(usages, goto.condition, parent_scope)
def _get_subroutine_usages_from_return(self, usages: Dict[Tuple[str, str], Set[str]],

View File

@ -1245,7 +1245,6 @@ def p_calltarget(p):
"""
calltarget : symbolname
| INTEGER
| BITAND symbolname
| dereference
"""
if len(p) == 2:
@ -1402,7 +1401,7 @@ def p_error(p):
if p.value in ("", "\n"):
p.lexer.error_function(sref, "syntax error before end of line")
else:
p.lexer.error_function(sref, "syntax error before '{:.20s}'", str(p.value).rstrip())
p.lexer.error_function(sref, "syntax error before or at '{:.20s}'", str(p.value).rstrip())
else:
lexer.error_function(None, "syntax error at end of input", lexer.source_filename)

View File

@ -24,8 +24,6 @@ bar2:
bar: goto $c000
goto var1 ; jumps to the address in var1
goto mem1 ; jumps to the address in mem1
goto &var1 ; strange, but jumps to the location in memory where var1 sits
goto &mem1 ; strange, but jumps to the location in mempory where mem1 sits (points to)
goto [var1]
goto [$c000.word]
goto [var1]

View File

@ -24,7 +24,6 @@ start:
if_gt goto label
if_cc goto value
;if_cc goto memvalue
if_cc goto &value
;if_cc goto #memvalue
if_cc goto [value]
;if_cc goto [memvalue]