Lines Matching refs:self

130     def __init__(self, config, fname, ln):  argument
131 self.config = config
132 self.fname = fname
134 self._contents = []
135 self.prototype = ""
137 self.warnings = []
139 self.parameterlist = []
140 self.parameterdescs = {}
141 self.parametertypes = {}
142 self.parameterdesc_start_lines = {}
144 self.sections_start_lines = {}
145 self.sections = {}
147 self.anon_struct_union = False
149 self.leading_space = None
151 self.fname = fname
154 self.brcount = 0
155 self.declaration_start_line = ln + 1
160 def add_text(self, text): argument
162 self._contents.append(text)
164 def contents(self): argument
166 return '\n'.join(self._contents) + '\n'
169 def emit_msg(self, ln, msg, *, warning=True): argument
175 self.config.log.info(log_msg)
181 self.warnings.append(log_msg)
184 def begin_section(self, line_no, title = SECTION_DEFAULT, dump = False): argument
189 self.dump_section(start_new = True)
190 self.section = title
191 self.new_start_line = line_no
193 def dump_section(self, start_new=True): argument
201 if self.section == SECTION_DEFAULT and not self._contents:
203 name = self.section
204 contents = self.contents()
209 self.parameterdescs[name] = contents
210 self.parameterdesc_start_lines[name] = self.new_start_line
212 self.new_start_line = 0
215 if name in self.sections and self.sections[name] != "":
218 self.emit_msg(self.new_start_line,
221 self.sections[name] += '\n' + contents
223 self.sections[name] = contents
224 self.sections_start_lines[name] = self.new_start_line
225 self.new_start_line = 0
230 self.section = SECTION_DEFAULT
231 self._contents = []
250 def __init__(self, config, fname, xforms, store_src=False): argument
253 self.fname = fname
254 self.config = config
255 self.xforms = xforms
256 self.store_src = store_src
258 tokenizer_set_log(self.config.log, f"{self.fname}: CMatch: ")
261 self.state = state.NORMAL
264 self.entry = None
267 self.entries = []
277 self.emit_msg(0,
281 def emit_msg(self, ln, msg, *, warning=True): argument
284 if self.entry:
285 self.entry.emit_msg(ln, msg, warning=warning)
291 self.config.log.warning(log_msg)
293 self.config.log.info(log_msg)
295 def dump_section(self, start_new=True): argument
300 if self.entry:
301 self.entry.dump_section(start_new)
304 def output_declaration(self, dtype, name, **args): argument
311 item = KdocItem(name, self.fname, dtype,
312 self.entry.declaration_start_line, **args)
313 item.warnings = self.entry.warnings
317 sections = self.entry.sections
321 item.set_sections(sections, self.entry.sections_start_lines)
322 item.set_params(self.entry.parameterlist, self.entry.parameterdescs,
323 self.entry.parametertypes,
324 self.entry.parameterdesc_start_lines)
325 self.entries.append(item)
327 self.config.log.debug("Output: %s:%s = %s", dtype, name, pformat(args))
329 def emit_unused_warnings(self): argument
349 if self.entry and self.entry not in self.entries:
350 for log_msg in self.entry.warnings:
351 self.config.warning(log_msg)
353 def reset_state(self, ln): argument
359 self.emit_unused_warnings()
361 self.entry = KernelEntry(self.config, self.fname, ln)
364 self.state = state.NORMAL
366 def push_parameter(self, ln, decl_type, param, dtype, argument
372 if self.entry.anon_struct_union and dtype == "" and param == "}":
375 self.entry.anon_struct_union = False
395 orig = self.entry.parameterdescs.pop(param, None)
398 not self.entry.parameterdescs.get(param):
399 self.entry.parameterdescs[param] = orig
400 if not self.entry.parameterdescs.get(param):
410 self.emit_msg(ln,
414 self.entry.parameterdescs[param] = "variable arguments"
418 self.entry.parameterdescs[param] = "no arguments"
424 self.entry.parameterdescs[param] = "anonymous\n"
425 self.entry.anon_struct_union = True
430 if param not in self.entry.parameterdescs and not param.startswith("#"):
431 self.entry.parameterdescs[param] = self.undescribed
439 self.emit_msg(ln,
450 self.entry.parameterlist.append(param)
452 self.entry.parametertypes[param] = org_arg
455 def create_parameter_list(self, ln, decl_type, args, argument
485 self.push_parameter(ln, decl_type, arg, "",
498 self.emit_msg(ln, f"Invalid param: {arg}")
501 self.push_parameter(ln, decl_type, param, dtype, arg, declaration_name)
513 self.emit_msg(ln, f"Invalid param: {arg}")
516 self.push_parameter(ln, decl_type, param, dtype, arg, declaration_name)
547 self.push_parameter(ln, decl_type, r.group(2),
555 self.push_parameter(ln, decl_type, bitfield_re.group(1),
559 self.push_parameter(ln, decl_type, param, dtype,
562 def get_suggestions_hint(self, decl_name, possible_names): argument
607 def check_sections(self, ln, decl_name, decl_type): argument
612 for section in self.entry.sections:
613 if section not in self.entry.parameterlist and \
615 hint = self.get_suggestions_hint(section, self.entry.parameterlist)
620 self.emit_msg(ln,
630 for param_name, desc in self.entry.parameterdescs.items():
632 if desc == self.undescribed:
638 if param_name in self.entry.parameterlist:
641 hint = self.get_suggestions_hint(param_name, self.entry.parameterlist)
646 self.emit_msg(ln,
649 def check_return_section(self, ln, declaration_name, return_type): argument
655 if not self.config.wreturn:
663 if not self.entry.sections.get("Return", None):
664 self.emit_msg(ln,
667 def split_struct_proto(self, proto): argument
692 def rewrite_struct_members(self, members): argument
788 def format_struct_decl(self, declaration): argument
825 def dump_struct(self, ln, proto, source): argument
834 struct_parts = self.split_struct_proto(proto)
836 self.emit_msg(ln, f"{proto} error: Cannot parse struct or union!")
840 if self.entry.identifier != declaration_name:
841 self.emit_msg(ln, f"expecting prototype for {decl_type} {self.entry.identifier}. "
847 members = self.xforms.apply("struct", members)
853 members = self.rewrite_struct_members(members)
858 self.create_parameter_list(ln, decl_type, members, ';',
860 self.check_sections(ln, declaration_name, decl_type)
861 self.output_declaration(decl_type, declaration_name,
863 definition=self.format_struct_decl(declaration),
864 purpose=self.entry.declaration_purpose)
866 def dump_enum(self, ln, proto, source): argument
896 self.emit_msg(ln, f"{proto}: error: Cannot parse enum!")
901 if self.entry.identifier != declaration_name:
902 if self.entry.identifier == "":
903 self.emit_msg(ln,
906 self.emit_msg(ln,
924 self.entry.parameterlist.append(arg)
925 if arg not in self.entry.parameterdescs:
926 self.entry.parameterdescs[arg] = self.undescribed
927 self.emit_msg(ln,
933 for k in self.entry.parameterdescs:
935 self.emit_msg(ln,
938 self.output_declaration('enum', declaration_name,
940 purpose=self.entry.declaration_purpose)
942 def dump_var(self, ln, proto, source): argument
976 proto = self.xforms.apply("var", proto)
998 self.emit_msg(ln,f"{proto}: can't parse variable")
1004 self.output_declaration("var", declaration_name,
1008 purpose=self.entry.declaration_purpose)
1010 def dump_declaration(self, ln, prototype, source): argument
1015 if self.entry.decl_type == "enum":
1016 self.dump_enum(ln, prototype, source)
1017 elif self.entry.decl_type == "typedef":
1018 self.dump_typedef(ln, prototype, source)
1019 elif self.entry.decl_type in ["union", "struct"]:
1020 self.dump_struct(ln, prototype, source)
1021 elif self.entry.decl_type == "var":
1022 self.dump_var(ln, prototype, source)
1025 self.emit_message(ln, f'Unknown declaration type: {self.entry.decl_type}')
1027 def dump_function(self, ln, prototype, source): argument
1059 prototype = self.xforms.apply("func", prototype)
1104 self.create_parameter_list(ln, decl_type, args, ',',
1112 self.emit_msg(ln,
1115 if self.entry.identifier != declaration_name:
1116 self.emit_msg(ln, f"expecting prototype for {self.entry.identifier}(). "
1119 self.check_sections(ln, declaration_name, "function")
1120 self.check_return_section(ln, declaration_name, return_type)
1124 self.output_declaration(decl_type, declaration_name,
1128 purpose=self.entry.declaration_purpose,
1132 def dump_typedef(self, ln, proto, source): argument
1157 if self.entry.identifier != declaration_name:
1158 self.emit_msg(ln,
1162 self.create_parameter_list(ln, 'function', args, ',', declaration_name)
1164 self.output_declaration('function', declaration_name,
1168 purpose=self.entry.declaration_purpose)
1177 if self.entry.identifier != declaration_name:
1178 self.emit_msg(ln,
1182 self.output_declaration('typedef', declaration_name,
1184 purpose=self.entry.declaration_purpose)
1187 self.emit_msg(ln, "error: Cannot parse typedef!")
1221 def process_normal(self, ln, line, source): argument
1230 self.reset_state(ln)
1233 self.state = state.NAME
1235 def process_name(self, ln, line, source): argument
1245 self.entry.begin_section(ln, "Introduction")
1247 self.entry.begin_section(ln, doc_block.group(1))
1249 self.entry.identifier = self.entry.section
1250 self.state = state.DOCBLOCK
1255 self.entry.identifier = doc_decl.group(1)
1259 self.entry.decl_type = doc_begin_data.group(1)
1260 self.entry.identifier = doc_begin_data.group(2)
1265 self.entry.identifier = doc_begin_func.group(1)
1266 self.entry.decl_type = "function"
1271 self.emit_msg(ln,
1273 self.state = state.NORMAL
1278 self.state = state.BODY
1279 self.entry.identifier = self.entry.identifier.strip(" ")
1281 self.entry.begin_section(ln + 1)
1289 self.entry.declaration_purpose = trim_whitespace(r.group(1))
1290 self.state = state.DECLARATION
1292 self.entry.declaration_purpose = ""
1294 if not self.entry.declaration_purpose and self.config.wshort_desc:
1295 self.emit_msg(ln,
1298 if not self.entry.identifier and self.entry.decl_type != "enum":
1299 self.emit_msg(ln,
1301 self.state = state.NORMAL
1303 if self.config.verbose:
1304 self.emit_msg(ln,
1311 self.emit_msg(ln, f"Cannot find identifier on line:\n{line}")
1313 def is_new_section(self, ln, line): argument
1318 self.state = state.BODY
1327 self.state = state.SPECIAL_SECTION
1331 self.state = state.SPECIAL_SECTION
1333 self.state = state.SPECIAL_SECTION
1340 self.dump_section()
1341 self.entry.begin_section(ln, newsection)
1342 self.entry.leading_space = None
1344 self.entry.add_text(newcontents.lstrip())
1348 def is_comment_end(self, ln, line): argument
1353 self.dump_section()
1358 self.emit_msg(ln, f"suspicious ending line: {line}")
1360 self.entry.prototype = ""
1361 self.entry.new_start_line = ln + 1
1363 self.state = state.PROTO
1368 def process_decl(self, ln, line, source): argument
1372 if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
1385 self.state = state.BODY
1390 self.entry.declaration_purpose = \
1391 trim_whitespace(self.entry.declaration_purpose + ' ' + cont)
1394 self.emit_msg(ln, f"bad line: {line}")
1397 def process_special(self, ln, line, source): argument
1406 self.entry.begin_section(ln, dump = True)
1407 self.state = state.BODY
1412 if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
1425 if self.entry.leading_space is None:
1428 self.entry.leading_space = len(r.group(1))
1430 self.entry.leading_space = 0
1436 for i in range(0, self.entry.leading_space):
1438 self.entry.leading_space = i
1443 self.entry.add_text(cont[self.entry.leading_space:])
1446 self.emit_msg(ln, f"bad line: {line}")
1448 def process_body(self, ln, line, source): argument
1452 if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
1457 self.entry.add_text(cont)
1460 self.emit_msg(ln, f"bad line: {line}")
1462 def process_inline_name(self, ln, line, source): argument
1466 self.entry.begin_section(ln, doc_inline_sect.group(1))
1467 self.entry.add_text(doc_inline_sect.group(2).lstrip())
1468 self.state = state.INLINE_TEXT
1470 self.dump_section()
1471 self.state = state.PROTO
1473 self.emit_msg(ln, f"Incorrect use of kernel-doc format: {line}")
1474 self.state = state.PROTO
1480 self.process_proto_type(ln, "/**\n" + line, source)
1483 def process_inline_text(self, ln, line, source): argument
1487 self.dump_section()
1488 self.state = state.PROTO
1490 self.entry.add_text(doc_content.group(1))
1493 def syscall_munge(self, ln, proto): # pylint: disable=W0613 argument
1532 def tracepoint_munge(self, ln, proto): argument
1561 self.emit_msg(ln,
1565 self.entry.identifier = f"trace_{self.entry.identifier}"
1569 def process_proto_function(self, ln, line, source): argument
1578 self.entry.prototype = line
1582 self.entry.prototype += r.group(1) + " "
1588 self.entry.prototype = KernRe(r'/\*.*\*/').sub('', self.entry.prototype).strip()
1596 self.entry.prototype = r.sub(r'\1\2', self.entry.prototype)
1600 if 'SYSCALL_DEFINE' in self.entry.prototype:
1601 self.entry.prototype = self.syscall_munge(ln,
1602 self.entry.prototype)
1605 if r.search(self.entry.prototype):
1606 self.entry.prototype = self.tracepoint_munge(ln,
1607 self.entry.prototype)
1611 self.dump_function(ln, self.entry.prototype, source)
1612 self.reset_state(ln)
1614 def process_proto_type(self, ln, line, source): argument
1634 self.entry.prototype += chunk
1640 self.entry.brcount += 1
1642 self.entry.brcount -= 1
1643 elif chunk == ';' and self.entry.brcount <= 0:
1644 self.dump_declaration(ln, self.entry.prototype, source)
1645 self.reset_state(ln)
1651 self.entry.prototype += ' '
1653 def process_proto(self, ln, line, source): argument
1657 self.entry.begin_section(ln, doc_inline_oneline.group(1))
1658 self.entry.add_text(doc_inline_oneline.group(2))
1659 self.dump_section()
1662 self.state = state.INLINE_NAME
1664 elif self.entry.decl_type == 'function':
1665 self.process_proto_function(ln, line, source)
1668 self.process_proto_type(ln, line, source)
1670 def process_docblock(self, ln, line, source): argument
1674 self.dump_section()
1675 self.output_declaration("doc", self.entry.identifier,
1677 self.reset_state(ln)
1680 self.entry.add_text(doc_content.group(1))
1682 def parse_export(self): argument
1690 with open(self.fname, "r", encoding="utf8",
1694 self.process_export(export_table, line)
1714 def parse_kdoc(self): argument
1727 self.state = state.NORMAL
1731 with open(self.fname, "r", encoding="utf8",
1738 if self.state == state.PROTO:
1751 self.config.log.debug("%d %s: %s",
1752 ln, state.name[self.state],
1755 if self.store_src:
1756 if source and self.state == state.NORMAL:
1758 elif self.state != state.NORMAL:
1766 if (self.state != state.NORMAL) or \
1767 not self.process_export(export_table, line):
1768 prev_state = self.state
1770 self.state_actions[self.state](self, ln, line, source)
1771 if prev_state == state.NORMAL and self.state != state.NORMAL:
1774 self.emit_unused_warnings()
1777 self.config.log.error(f"Error: Cannot open file {self.fname}")
1779 return export_table, self.entries