38 |
38 |
39 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
39 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
40 """ |
40 """ |
41 Class to represent a Python function. |
41 Class to represent a Python function. |
42 """ |
42 """ |
43 def __init__(self, module, name, file, lineno, signature='', separator=','): |
43 def __init__(self, module, name, file, lineno, signature='', |
|
44 separator=','): |
44 """ |
45 """ |
45 Constructor |
46 Constructor |
46 |
47 |
47 @param module name of the module containing this function |
48 @param module name of the module containing this function |
48 @param name name of this function |
49 @param name name of this function |
114 Private method implementing the visit logic delegating to interesting |
115 Private method implementing the visit logic delegating to interesting |
115 methods. |
116 methods. |
116 |
117 |
117 @param root root node to visit |
118 @param root root node to visit |
118 """ |
119 """ |
119 call = lambda n: getattr(self, "visit_{0}".format(n.type), self.visit_noop)(n) |
120 call = lambda n: getattr(self, "visit_{0}".format(n.type), |
|
121 self.visit_noop)(n) |
120 call(root) |
122 call(root) |
121 for node in root: |
123 for node in root: |
122 self.__visit(node) |
124 self.__visit(node) |
123 |
125 |
124 def visit_noop(self, node): |
126 def visit_noop(self, node): |
138 if node.type == "function" and \ |
140 if node.type == "function" and \ |
139 getattr(node, "name", None) and \ |
141 getattr(node, "name", None) and \ |
140 node.functionForm == "declared_form": |
142 node.functionForm == "declared_form": |
141 if self.__stack and self.__stack[-1].endlineno < node.line: |
143 if self.__stack and self.__stack[-1].endlineno < node.line: |
142 del self.__stack[-1] |
144 del self.__stack[-1] |
143 endline = node.line + self.__source.count('\n', node.start, node.end) |
145 endline = node.line + self.__source.count( |
|
146 '\n', node.start, node.end) |
144 if getattr(node, "params", None): |
147 if getattr(node, "params", None): |
145 func_sig = ", ".join([p.value for p in node.params]) |
148 func_sig = ", ".join([p.value for p in node.params]) |
146 else: |
149 else: |
147 func_sig = "" |
150 func_sig = "" |
148 if self.__stack: |
151 if self.__stack: |
173 @param node reference to the node (jasy.js.parse.Node.Node) |
176 @param node reference to the node (jasy.js.parse.Node.Node) |
174 """ |
177 """ |
175 if node.type == "property_init" and node[1].type == "function": |
178 if node.type == "property_init" and node[1].type == "function": |
176 if self.__stack and self.__stack[-1].endlineno < node[0].line: |
179 if self.__stack and self.__stack[-1].endlineno < node[0].line: |
177 del self.__stack[-1] |
180 del self.__stack[-1] |
178 endline = node[0].line + self.__source.count('\n', node.start, node[1].end) |
181 endline = node[0].line + self.__source.count( |
|
182 '\n', node.start, node[1].end) |
179 if getattr(node[1], "params", None): |
183 if getattr(node[1], "params", None): |
180 func_sig = ", ".join([p.value for p in node[1].params]) |
184 func_sig = ", ".join([p.value for p in node[1].params]) |
181 else: |
185 else: |
182 func_sig = "" |
186 func_sig = "" |
183 if self.__stack: |
187 if self.__stack: |
213 if self.__stack and self.__stack[-1].endlineno < node[0].line: |
217 if self.__stack and self.__stack[-1].endlineno < node[0].line: |
214 del self.__stack[-1] |
218 del self.__stack[-1] |
215 if self.__stack: |
219 if self.__stack: |
216 # function variables |
220 # function variables |
217 for var in node: |
221 for var in node: |
218 attr = Attribute(self.__module, var.name, self.__file, var.line) |
222 attr = Attribute( |
|
223 self.__module, var.name, self.__file, var.line) |
219 self.__stack[-1]._addattribute(attr) |
224 self.__stack[-1]._addattribute(attr) |
220 else: |
225 else: |
221 # global variable |
226 # global variable |
222 if "@@Globals@@" not in self.__dict: |
227 if "@@Globals@@" not in self.__dict: |
223 self.__dict["@@Globals@@"] = \ |
228 self.__dict["@@Globals@@"] = ClbrBaseClasses.ClbrBase( |
224 ClbrBaseClasses.ClbrBase(self.__module, "Globals", self.__file, 0) |
229 self.__module, "Globals", self.__file, 0) |
225 for var in node: |
230 for var in node: |
226 self.__dict["@@Globals@@"]._addglobal( |
231 self.__dict["@@Globals@@"]._addglobal(Attribute( |
227 Attribute(self.__module, var.name, self.__file, var.line)) |
232 self.__module, var.name, self.__file, var.line)) |
228 |
233 |
229 def visit_const(self, node): |
234 def visit_const(self, node): |
230 """ |
235 """ |
231 Public method to treat a constant node. |
236 Public method to treat a constant node. |
232 |
237 |
244 self.__file, var.line) |
249 self.__file, var.line) |
245 self.__stack[-1]._addattribute(attr) |
250 self.__stack[-1]._addattribute(attr) |
246 else: |
251 else: |
247 # global variable |
252 # global variable |
248 if "@@Globals@@" not in self.__dict: |
253 if "@@Globals@@" not in self.__dict: |
249 self.__dict["@@Globals@@"] = \ |
254 self.__dict["@@Globals@@"] = ClbrBaseClasses.ClbrBase( |
250 ClbrBaseClasses.ClbrBase(self.__module, "Globals", self.__file, 0) |
255 self.__module, "Globals", self.__file, 0) |
251 for var in node: |
256 for var in node: |
252 self.__dict["@@Globals@@"]._addglobal( |
257 self.__dict["@@Globals@@"]._addglobal( |
253 Attribute(self.__module, "const " + var.name, |
258 Attribute(self.__module, "const " + var.name, |
254 self.__file, var.line)) |
259 self.__file, var.line)) |
255 |
260 |