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

Class Call

code2flow/model.py:178–259  ·  view source on GitHub ↗

Calls represent function call expressions. They can be an attribute call like object.do_something() Or a "naked" call like do_something()

Source from the content-addressed store, hash-verified

176
177
178class Call():
179 """
180 Calls represent function call expressions.
181 They can be an attribute call like
182 object.do_something()
183 Or a "naked" call like
184 do_something()
185
186 """
187 def __init__(self, token, line_number=None, owner_token=None, definite_constructor=False):
188 self.token = token
189 self.owner_token = owner_token
190 self.line_number = line_number
191 self.definite_constructor = definite_constructor
192
193 def __repr__(self):
194 return f"<Call owner_token={self.owner_token} token={self.token}>"
195
196 def to_string(self):
197 """
198 Returns a representation of this call to be printed by the engine
199 in logging.
200 :rtype: str
201 """
202 if self.owner_token:
203 return f"{self.owner_token}.{self.token}()"
204 return f"{self.token}()"
205
206 def is_attr(self):
207 """
208 Attribute calls are like `a.do_something()` rather than `do_something()`
209 :rtype: bool
210 """
211 return self.owner_token is not None
212
213 def matches_variable(self, variable):
214 """
215 Check whether this variable is what the call is acting on.
216 For example, if we had 'obj' from
217 obj = Obj()
218 as a variable and a call of
219 obj.do_something()
220 Those would match and we would return the "do_something" node from obj.
221
222 :param variable Variable:
223 :rtype: Node
224 """
225
226 if self.is_attr():
227 if self.owner_token == variable.token:
228 for node in getattr(variable.points_to, 'nodes', []):
229 if self.token == node.token:
230 return node
231 for inherit_nodes in getattr(variable.points_to, 'inherits', []):
232 for node in inherit_nodes:
233 if self.token == node.token:
234 return node
235 if variable.points_to in OWNER_CONST:

Callers 5

get_call_from_send_elFunction · 0.85
make_callsFunction · 0.85
get_call_from_exprFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected