MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / get_call_from_expr

Function get_call_from_expr

code2flow/php.py:37–78  ·  view source on GitHub ↗

Given an ast that represents a send call, clear and create our generic Call object. Some calls have no chance at resolution (e.g. array[2](param)) so we return nothing instead. :param func_expr ast: :rtype: Call|None

(func_expr)

Source from the content-addressed store, hash-verified

35
36
37def get_call_from_expr(func_expr):
38 """
39 Given an ast that represents a send call, clear and create our
40 generic Call object. Some calls have no chance at resolution (e.g. array[2](param))
41 so we return nothing instead.
42
43 :param func_expr ast:
44 :rtype: Call|None
45 """
46 if func_expr['nodeType'] == 'Expr_FuncCall':
47 token = get_name(func_expr)
48 owner_token = None
49 elif func_expr['nodeType'] == 'Expr_New' and func_expr['class'].get('parts'):
50 token = '__construct'
51 owner_token = get_name(func_expr['class'])
52 elif func_expr['nodeType'] == 'Expr_MethodCall':
53 # token = func_expr['name']['name']
54 token = get_name(func_expr)
55 if 'var' in func_expr['var']:
56 owner_token = OWNER_CONST.UNKNOWN_VAR
57 else:
58 owner_token = get_name(func_expr['var'])
59 elif func_expr['nodeType'] == 'Expr_BinaryOp_Concat' and func_expr['right']['nodeType'] == 'Expr_FuncCall':
60 token = get_name(func_expr['right'])
61 if 'class' in func_expr['left']:
62 owner_token = get_name(func_expr['left']['class'])
63 else:
64 owner_token = get_name(func_expr['left'])
65 elif func_expr['nodeType'] == 'Expr_StaticCall':
66 token = get_name(func_expr)
67 owner_token = get_name(func_expr['class'])
68 else:
69 return None
70
71 if owner_token and token == '__construct':
72 # Taking out owner_token for constructors as a little hack to make it work
73 return Call(token=owner_token,
74 line_number=lineno(func_expr))
75 ret = Call(token=token,
76 owner_token=owner_token,
77 line_number=lineno(func_expr))
78 return ret
79
80
81def walk(tree):

Callers 2

make_callsFunction · 0.85
process_assignFunction · 0.85

Calls 3

get_nameFunction · 0.85
CallClass · 0.85
linenoFunction · 0.70

Tested by

no test coverage detected