/*** Symbols for cross-project jump-to-definition resolution.*/import pythonprivate import LegacyPointsToprivate newtype TSymbol =TModule(Module m) orTMember(Symbol outer, string part) {exists(Object o | outer.resolvesTo() = o |o.(ModuleObject).hasAttribute(part)oro.(ClassObject).hasAttribute(part))}/*** A "symbol" referencing an object in another module* Symbols are represented by the module name and the dotted name by which the* object would be referred to in that module.* For example for the code:* ```* class C:* def m(self): pass* ```* If the code were in a module `mod`,* then symbol for the method `m` would be "mod/C.m"*/class Symbol extends TSymbol {string toString() {exists(Module m | this = TModule(m) and result = m.getName())orexists(TModule outer, string part |this = TMember(outer, part) andouter = TModule(_) andresult = outer.(Symbol).toString() + "/" + part)orexists(TMember outer, string part |this = TMember(outer, part) andouter = TMember(_, _) andresult = outer.(Symbol).toString() + "." + part)}/** Finds the `AstNode` that this `Symbol` refers to. */AstNode find() {this = TModule(result)orexists(Symbol s, string name | this = TMember(s, name) |exists(ClassObject cls |s.resolvesTo() = cls andcls.attributeRefersTo(name, _, result.getAFlowNode()))orexists(ModuleObject m |s.resolvesTo() = m andm.attributeRefersTo(name, _, result.getAFlowNode())))}/*** Find the class or module `Object` that this `Symbol` refers to, if* this `Symbol` refers to a class or module.*/Object resolvesTo() {this = TModule(result.(ModuleObject).getModule())orexists(Symbol s, string name, Object o |this = TMember(s, name) ando = s.resolvesTo() andresult = attribute_in_scope(o, name))}/*** Gets the `Module` for the module part of this `Symbol`.* For example, this would return the `os` module for the `Symbol` "os/environ".*/Module getModule() {this = TModule(result)orexists(Symbol outer | this = TMember(outer, _) and result = outer.getModule())}/** Gets the `Symbol` that is the named member of this `Symbol`. */Symbol getMember(string name) { result = TMember(this, name) }}/* Helper for `Symbol`.resolvesTo() */private Object attribute_in_scope(Object obj, string name) {exists(ClassObject cls | cls = obj |cls.lookupAttribute(name) = result and result.(ControlFlowNode).getScope() = cls.getPyClass())orexists(ModuleObject mod | mod = obj |mod.attr(name) = result andresult.(ControlFlowNode).getScope() = mod.getModule() andnot result.(ControlFlowNode).isEntryNode())}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。