Lines Matching full:self

110     def __init__(self, config, ln):  argument
111 self.config = config
113 self.contents = ""
114 self.function = ""
115 self.sectcheck = ""
116 self.struct_actual = ""
117 self.prototype = ""
119 self.warnings = []
121 self.parameterlist = []
122 self.parameterdescs = {}
123 self.parametertypes = {}
124 self.parameterdesc_start_lines = {}
126 self.section_start_lines = {}
127 self.sectionlist = []
128 self.sections = {}
130 self.anon_struct_union = False
132 self.leading_space = None
135 self.brcount = 0
137 self.in_doc_sect = False
138 self.declaration_start_line = ln + 1
141 def emit_msg(self, log_msg, warning=True): argument
145 self.config.log.info(log_msg)
151 self.warnings.append(log_msg)
154 def dump_section(self, start_new=True): argument
159 name = self.section
160 contents = self.contents
165 self.parameterdescs[name] = contents
166 self.parameterdesc_start_lines[name] = self.new_start_line
168 self.sectcheck += name + " "
169 self.new_start_line = 0
173 self.parameterdescs[name] = contents
174 self.sectcheck += name + " "
175 self.parameterdesc_start_lines[name] = self.new_start_line
176 self.new_start_line = 0
179 if name in self.sections and self.sections[name] != "":
182 self.emit_msg(self.new_start_line,
184 self.sections[name] += contents
186 self.sections[name] = contents
187 self.sectionlist.append(name)
188 self.section_start_lines[name] = self.new_start_line
189 self.new_start_line = 0
191 # self.config.log.debug("Section: %s : %s", name, pformat(vars(self)))
194 self.section = SECTION_DEFAULT
195 self.contents = ""
212 def __init__(self, config, fname): argument
215 self.fname = fname
216 self.config = config
219 self.state = state.NORMAL
220 self.inline_doc_state = state.INLINE_NA
223 self.entry = None
226 self.entries = []
228 def emit_msg(self, ln, msg, warning=True): argument
231 log_msg = f"{self.fname}:{ln} {msg}"
233 if self.entry:
234 self.entry.emit_msg(log_msg, warning)
238 self.config.log.warning(log_msg)
240 self.config.log.info(log_msg)
242 def dump_section(self, start_new=True): argument
247 if self.entry:
248 self.entry.dump_section(start_new)
251 def output_declaration(self, dtype, name, **args): argument
260 # it just stores the declaration content at self.entries, as the
266 args["declaration_start_line"] = self.entry.declaration_start_line
268 args["warnings"] = self.entry.warnings
283 self.entries.append((name, args))
285 self.config.log.debug("Output: %s:%s = %s", dtype, name, pformat(args))
287 def reset_state(self, ln): argument
293 self.entry = KernelEntry(self.config, ln)
296 self.state = state.NORMAL
297 self.inline_doc_state = state.INLINE_NA
299 def push_parameter(self, ln, decl_type, param, dtype, argument
302 Store parameters and their descriptions at self.entry.
305 if self.entry.anon_struct_union and dtype == "" and param == "}":
308 self.entry.anon_struct_union = False
321 if param not in self.entry.parameterdescs or \
322 not self.entry.parameterdescs[param]:
324 self.entry.parameterdescs[param] = "variable arguments"
328 self.entry.parameterdescs[param] = "no arguments"
334 self.entry.parameterdescs[param] = "anonymous\n"
335 self.entry.anon_struct_union = True
346 if param not in self.entry.parameterdescs and not param.startswith("#"):
347 self.entry.parameterdescs[param] = self.undescribed
355 self.emit_msg(ln,
366 self.entry.parameterlist.append(param)
368 self.entry.parametertypes[param] = org_arg
370 def save_struct_actual(self, actual): argument
378 self.entry.struct_actual += actual + " "
380 def create_parameter_list(self, ln, decl_type, args, argument
383 Creates a list of parameters, storing them at self.entry.
408 self.push_parameter(ln, decl_type, arg, "",
420 self.emit_msg(ln, f"Invalid param: {arg}")
424 self.save_struct_actual(param)
425 self.push_parameter(ln, decl_type, param, dtype,
436 self.emit_msg(ln, f"Invalid param: {arg}")
441 self.save_struct_actual(param)
442 self.push_parameter(ln, decl_type, param, dtype,
469 self.emit_msg(ln, f"Invalid param: {param}")
474 self.save_struct_actual(r.group(2))
475 self.push_parameter(ln, decl_type, r.group(2),
482 self.emit_msg(ln, f"Invalid param: {param}")
486 self.save_struct_actual(r.group(1))
487 self.push_parameter(ln, decl_type, r.group(1),
491 self.save_struct_actual(param)
492 self.push_parameter(ln, decl_type, param, dtype,
495 def check_sections(self, ln, decl_name, decl_type, sectcheck, prmscheck): argument
530 self.emit_msg(ln,
533 def check_return_section(self, ln, declaration_name, return_type): argument
539 if not self.config.wreturn:
547 if not self.entry.sections.get("Return", None):
548 self.emit_msg(ln,
551 def dump_struct(self, ln, proto): argument
588 self.emit_msg(ln, f"{proto} error: Cannot parse struct or union!")
591 if self.entry.identifier != declaration_name:
592 self.emit_msg(ln,
593 …f"expecting prototype for {decl_type} {self.entry.identifier}. Prototype was for {decl_type} {decl…
783 self.create_parameter_list(ln, decl_type, members, ';',
785 self.check_sections(ln, declaration_name, decl_type,
786 self.entry.sectcheck, self.entry.struct_actual)
821 self.output_declaration(decl_type, declaration_name,
824 parameterlist=self.entry.parameterlist,
825 parameterdescs=self.entry.parameterdescs,
826 parametertypes=self.entry.parametertypes,
827 parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
828 sectionlist=self.entry.sectionlist,
829 sections=self.entry.sections,
830 section_start_lines=self.entry.section_start_lines,
831 purpose=self.entry.declaration_purpose)
833 def dump_enum(self, ln, proto): argument
835 Stores an enum inside self.entries array.
862 self.emit_msg(ln, f"{proto}: error: Cannot parse enum!")
865 if self.entry.identifier != declaration_name:
866 if self.entry.identifier == "":
867 self.emit_msg(ln,
870 self.emit_msg(ln,
871 …f"expecting prototype for enum {self.entry.identifier}. Prototype was for enum {declaration_name} …
885 self.entry.parameterlist.append(arg)
886 if arg not in self.entry.parameterdescs:
887 self.entry.parameterdescs[arg] = self.undescribed
888 self.emit_msg(ln,
892 for k in self.entry.parameterdescs:
894 self.emit_msg(ln,
897 self.output_declaration('enum', declaration_name,
899 parameterlist=self.entry.parameterlist,
900 parameterdescs=self.entry.parameterdescs,
901 parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
902 sectionlist=self.entry.sectionlist,
903 sections=self.entry.sections,
904 section_start_lines=self.entry.section_start_lines,
905 purpose=self.entry.declaration_purpose)
907 def dump_declaration(self, ln, prototype): argument
909 Stores a data declaration inside self.entries array.
912 if self.entry.decl_type == "enum":
913 self.dump_enum(ln, prototype)
916 if self.entry.decl_type == "typedef":
917 self.dump_typedef(ln, prototype)
920 if self.entry.decl_type in ["union", "struct"]:
921 self.dump_struct(ln, prototype)
924 self.output_declaration(self.entry.decl_type, prototype,
925 entry=self.entry)
927 def dump_function(self, ln, prototype): argument
929 Stores a function of function macro inside self.entries array.
1044 self.create_parameter_list(ln, decl_type, args, ',',
1050 self.emit_msg(ln,
1054 if self.entry.identifier != declaration_name:
1055 self.emit_msg(ln,
1056 …f"expecting prototype for {self.entry.identifier}(). Prototype was for {declaration_name}() instea…
1059 prms = " ".join(self.entry.parameterlist)
1060 self.check_sections(ln, declaration_name, "function",
1061 self.entry.sectcheck, prms)
1063 self.check_return_section(ln, declaration_name, return_type)
1066 self.output_declaration(decl_type, declaration_name,
1070 parameterlist=self.entry.parameterlist,
1071 parameterdescs=self.entry.parameterdescs,
1072 parametertypes=self.entry.parametertypes,
1073 parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
1074 sectionlist=self.entry.sectionlist,
1075 sections=self.entry.sections,
1076 section_start_lines=self.entry.section_start_lines,
1077 purpose=self.entry.declaration_purpose,
1080 self.output_declaration(decl_type, declaration_name,
1084 parameterlist=self.entry.parameterlist,
1085 parameterdescs=self.entry.parameterdescs,
1086 parametertypes=self.entry.parametertypes,
1087 parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
1088 sectionlist=self.entry.sectionlist,
1089 sections=self.entry.sections,
1090 section_start_lines=self.entry.section_start_lines,
1091 purpose=self.entry.declaration_purpose,
1094 def dump_typedef(self, ln, proto): argument
1096 Stores a typedef inside self.entries array.
1118 if self.entry.identifier != declaration_name:
1119 self.emit_msg(ln,
1120 …f"expecting prototype for typedef {self.entry.identifier}. Prototype was for typedef {declaration_…
1124 self.create_parameter_list(ln, decl_type, args, ',', declaration_name)
1126 self.output_declaration(decl_type, declaration_name,
1130 parameterlist=self.entry.parameterlist,
1131 parameterdescs=self.entry.parameterdescs,
1132 parametertypes=self.entry.parametertypes,
1133 parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
1134 sectionlist=self.entry.sectionlist,
1135 sections=self.entry.sections,
1136 section_start_lines=self.entry.section_start_lines,
1137 purpose=self.entry.declaration_purpose)
1150 if self.entry.identifier != declaration_name:
1151 self.emit_msg(ln,
1152 …f"expecting prototype for typedef {self.entry.identifier}. Prototype was for typedef {declaration_…
1155 self.output_declaration('typedef', declaration_name,
1157 sectionlist=self.entry.sectionlist,
1158 sections=self.entry.sections,
1159 section_start_lines=self.entry.section_start_lines,
1160 purpose=self.entry.declaration_purpose)
1163 self.emit_msg(ln, "error: Cannot parse typedef!")
1186 def process_normal(self, ln, line): argument
1195 self.reset_state(ln)
1196 self.entry.in_doc_sect = False
1199 self.state = state.NAME
1201 def process_name(self, ln, line): argument
1207 self.entry.new_start_line = ln
1210 self.entry.section = self.section_intro
1212 self.entry.section = doc_block.group(1)
1214 self.entry.identifier = self.entry.section
1215 self.state = state.DOCBLOCK
1219 self.entry.identifier = doc_decl.group(1)
1220 self.entry.is_kernel_comment = False
1230 self.entry.identifier = r.group(1)
1235 self.entry.decl_type = r.group(1)
1236 self.entry.identifier = r.group(2)
1237 self.entry.is_kernel_comment = True
1247 self.entry.identifier = r.group(1)
1248 self.entry.decl_type = "function"
1251 self.entry.identifier = r.sub("", self.entry.identifier)
1252 self.entry.is_kernel_comment = True
1255 self.entry.identifier = self.entry.identifier.strip(" ")
1257 self.state = state.BODY
1260 self.entry.section = SECTION_DEFAULT
1261 self.entry.new_start_line = ln + 1
1266 self.entry.descr = r.group(1).strip(" ")
1269 self.entry.descr = r.sub(" ", self.entry.descr)
1270 self.entry.declaration_purpose = self.entry.descr
1271 self.state = state.BODY_MAYBE
1273 self.entry.declaration_purpose = ""
1275 if not self.entry.is_kernel_comment:
1276 self.emit_msg(ln,
1278 self.state = state.NORMAL
1280 if not self.entry.declaration_purpose and self.config.wshort_desc:
1281 self.emit_msg(ln,
1284 if not self.entry.identifier and self.entry.decl_type != "enum":
1285 self.emit_msg(ln,
1287 self.state = state.NORMAL
1289 if self.config.verbose:
1290 self.emit_msg(ln,
1291 f"Scanning doc for {self.entry.decl_type} {self.entry.identifier}",
1297 self.emit_msg(ln, f"Cannot find identifier on line:\n{line}")
1299 def process_body(self, ln, line): argument
1304 if self.state == state.BODY_WITH_BLANK_LINE:
1307 self.dump_section()
1308 self.entry.section = SECTION_DEFAULT
1309 self.entry.new_start_line = ln
1310 self.entry.contents = ""
1313 self.entry.in_doc_sect = True
1333 if self.entry.contents.strip("\n"):
1334 self.dump_section()
1336 self.entry.new_start_line = ln
1337 self.entry.section = newsection
1338 self.entry.leading_space = None
1340 self.entry.contents = newcontents.lstrip()
1341 if self.entry.contents:
1342 self.entry.contents += "\n"
1344 self.state = state.BODY
1348 self.dump_section()
1353 self.emit_msg(ln, f"suspicious ending line: {line}")
1355 self.entry.prototype = ""
1356 self.entry.new_start_line = ln + 1
1358 self.state = state.PROTO
1365 if self.entry.section == self.section_context:
1366 self.dump_section()
1368 self.entry.new_start_line = ln
1369 self.state = state.BODY
1371 if self.entry.section != SECTION_DEFAULT:
1372 self.state = state.BODY_WITH_BLANK_LINE
1374 self.state = state.BODY
1376 self.entry.contents += "\n"
1378 elif self.state == state.BODY_MAYBE:
1381 self.entry.declaration_purpose = self.entry.declaration_purpose.rstrip()
1382 self.entry.declaration_purpose += " " + cont
1385 self.entry.declaration_purpose = r.sub(' ',
1386 self.entry.declaration_purpose)
1389 if self.entry.section.startswith('@') or \
1390 self.entry.section == self.section_context:
1391 if self.entry.leading_space is None:
1394 self.entry.leading_space = len(r.group(1))
1396 self.entry.leading_space = 0
1400 for i in range(0, self.entry.leading_space):
1409 if self.entry.leading_space != pos:
1410 self.entry.leading_space = pos
1412 self.entry.contents += cont + "\n"
1416 self.emit_msg(ln, f"bad line: {line}")
1418 def process_inline(self, ln, line): argument
1421 if self.inline_doc_state == state.INLINE_NAME and \
1423 self.entry.section = doc_inline_sect.group(1)
1424 self.entry.new_start_line = ln
1426 self.entry.contents = doc_inline_sect.group(2).lstrip()
1427 if self.entry.contents != "":
1428 self.entry.contents += "\n"
1430 self.inline_doc_state = state.INLINE_TEXT
1435 if self.entry.contents not in ["", "\n"]:
1436 self.dump_section()
1438 self.state = state.PROTO
1439 self.inline_doc_state = state.INLINE_NA
1443 if self.inline_doc_state == state.INLINE_TEXT:
1444 self.entry.contents += doc_content.group(1) + "\n"
1445 if not self.entry.contents.strip(" ").rstrip("\n"):
1446 self.entry.contents = ""
1448 elif self.inline_doc_state == state.INLINE_NAME:
1449 self.emit_msg(ln,
1452 self.inline_doc_state = state.INLINE_ERROR
1454 def syscall_munge(self, ln, proto): # pylint: disable=W0613 argument
1493 def tracepoint_munge(self, ln, proto): argument
1522 self.emit_msg(ln,
1526 self.entry.identifier = f"trace_{self.entry.identifier}"
1530 def process_proto_function(self, ln, line): argument
1538 self.entry.prototype = line
1545 self.entry.prototype += r.group(1) + " "
1550 self.entry.prototype = r.sub('', self.entry.prototype)
1554 self.entry.prototype = r.sub(' ', self.entry.prototype)
1558 self.entry.prototype = r.sub('', self.entry.prototype)
1560 # Handle self.entry.prototypes for function pointers like:
1564 self.entry.prototype = r.sub(r'\1\2', self.entry.prototype)
1566 if 'SYSCALL_DEFINE' in self.entry.prototype:
1567 self.entry.prototype = self.syscall_munge(ln,
1568 self.entry.prototype)
1571 if r.search(self.entry.prototype):
1572 self.entry.prototype = self.tracepoint_munge(ln,
1573 self.entry.prototype)
1575 self.dump_function(ln, self.entry.prototype)
1576 self.reset_state(ln)
1578 def process_proto_type(self, ln, line): argument
1600 if self.entry.prototype:
1601 self.entry.prototype += " "
1602 self.entry.prototype += r.group(1) + r.group(2)
1604 self.entry.brcount += r.group(2).count('{')
1605 self.entry.brcount -= r.group(2).count('}')
1607 self.entry.brcount = max(self.entry.brcount, 0)
1609 if r.group(2) == ';' and self.entry.brcount == 0:
1610 self.dump_declaration(ln, self.entry.prototype)
1611 self.reset_state(ln)
1616 self.entry.prototype += line
1619 def process_proto(self, ln, line): argument
1623 self.entry.section = doc_inline_oneline.group(1)
1624 self.entry.contents = doc_inline_oneline.group(2)
1626 if self.entry.contents != "":
1627 self.entry.contents += "\n"
1628 self.dump_section(start_new=False)
1631 self.state = state.INLINE
1632 self.inline_doc_state = state.INLINE_NAME
1634 elif self.entry.decl_type == 'function':
1635 self.process_proto_function(ln, line)
1638 self.process_proto_type(ln, line)
1640 def process_docblock(self, ln, line): argument
1644 self.dump_section()
1645 self.output_declaration("doc", self.entry.identifier,
1646 sectionlist=self.entry.sectionlist,
1647 sections=self.entry.sections,
1648 section_start_lines=self.entry.section_start_lines)
1649 self.reset_state(ln)
1652 self.entry.contents += doc_content.group(1) + "\n"
1654 def parse_export(self): argument
1662 with open(self.fname, "r", encoding="utf8",
1666 self.process_export(export_table, line)
1673 def parse_kdoc(self): argument
1689 with open(self.fname, "r", encoding="utf8",
1696 if self.state == state.PROTO:
1713 self.config.log.debug("%d %s%s: %s",
1714 ln, state.name[self.state],
1715 state.inline_name[self.inline_doc_state],
1726 self.process_export(export_table, line)
1729 if self.state == state.NORMAL:
1730 self.process_normal(ln, line)
1731 elif self.state == state.NAME:
1732 self.process_name(ln, line)
1733 elif self.state in [state.BODY, state.BODY_MAYBE,
1735 self.process_body(ln, line)
1736 elif self.state == state.INLINE: # scanning for inline parameters
1737 self.process_inline(ln, line)
1738 elif self.state == state.PROTO:
1739 self.process_proto(ln, line)
1740 elif self.state == state.DOCBLOCK:
1741 self.process_docblock(ln, line)
1743 self.config.log.error(f"Error: Cannot open file {self.fname}")
1745 return export_table, self.entries