Lines Matching full:self

51         self,  argument
54 self.ifcond = ifcond
56 def _cgen(self) -> str: argument
57 return cgen_ifcond(self.ifcond)
59 def gen_if(self) -> str: argument
60 return gen_if(self._cgen())
62 def gen_endif(self) -> str: argument
63 return gen_endif(self._cgen())
65 def docgen(self) -> str: argument
66 return docgen_ifcond(self.ifcond)
68 def is_present(self) -> bool: argument
69 return bool(self.ifcond)
79 def __init__(self, info: Optional[QAPISourceInfo]): argument
80 self._module: Optional[QAPISchemaModule] = None
86 self.info = info
87 self._checked = False
89 def __repr__(self) -> str: argument
90 return "<%s at 0x%x>" % (type(self).__name__, id(self))
92 def check(self, schema: QAPISchema) -> None: argument
94 self._checked = True
96 def connect_doc(self, doc: Optional[QAPIDoc] = None) -> None: argument
100 self, schema: QAPISchema, info: Optional[QAPISourceInfo] argument
102 assert self._checked
104 self._module = schema.module_by_fname(fname)
105 self._module.add_entity(self)
107 def set_module(self, schema: QAPISchema) -> None: argument
108 self._set_module(schema, self.info)
110 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
112 assert self._checked
119 self, argument
129 self.name = name
130 self.doc = doc
131 self._ifcond = ifcond or QAPISchemaIfCond()
132 self.features = features or []
134 def __repr__(self) -> str: argument
135 return "<%s:%s at 0x%x>" % (type(self).__name__, self.name,
136 id(self))
138 def c_name(self) -> str: argument
139 return c_name(self.name)
141 def check(self, schema: QAPISchema) -> None: argument
142 assert not self._checked
145 for f in self.features:
146 f.check_clash(self.info, seen)
148 def connect_doc(self, doc: Optional[QAPIDoc] = None) -> None: argument
150 doc = doc or self.doc
152 for f in self.features:
156 def ifcond(self) -> QAPISchemaIfCond: argument
157 assert self._checked
158 return self._ifcond
160 def is_implicit(self) -> bool: argument
161 return not self.info
163 def describe(self) -> str: argument
164 return "%s '%s'" % (self.meta, self.name)
168 def visit_begin(self, schema: QAPISchema) -> None: argument
171 def visit_end(self) -> None: argument
174 def visit_module(self, name: str) -> None: argument
177 def visit_needed(self, entity: QAPISchemaEntity) -> bool: argument
182 def visit_include(self, name: str, info: Optional[QAPISourceInfo]) -> None: argument
186 self, name: str, info: Optional[QAPISourceInfo], json_type: str argument
191 self, argument
202 self, argument
211 self, argument
223 self, argument
234 self, argument
244 self, argument
261 self, argument
276 def __init__(self, name: str): argument
277 self.name = name
278 self._entity_list: List[QAPISchemaEntity] = []
307 def add_entity(self, ent: QAPISchemaEntity) -> None: argument
308 self._entity_list.append(ent)
310 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
311 visitor.visit_module(self.name)
312 for entity in self._entity_list:
318 def __init__(self, sub_module: QAPISchemaModule, info: QAPISourceInfo): argument
320 self._sub_module = sub_module
322 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
324 visitor.visit_include(self._sub_module.name, self.info)
331 def c_type(self) -> str: argument
335 def c_param_type(self) -> str: argument
336 return self.c_type()
339 def c_unboxed_type(self) -> str: argument
340 return self.c_type()
343 def json_type(self) -> str: argument
346 def alternate_qtype(self) -> Optional[str]: argument
356 return json2qtype.get(self.json_type())
358 def doc_type(self) -> Optional[str]: argument
359 if self.is_implicit():
361 return self.name
363 def need_has_if_optional(self) -> bool: argument
366 return not self.c_type().endswith(POINTER_SUFFIX)
368 def check(self, schema: QAPISchema) -> None: argument
370 for feat in self.features:
373 self.info,
376 def describe(self) -> str: argument
377 return "%s type '%s'" % (self.meta, self.name)
383 def __init__(self, name: str, json_type: str, c_type: str): argument
387 self._json_type_name = json_type
388 self._c_type_name = c_type
390 def c_name(self) -> str: argument
391 return self.name
393 def c_type(self) -> str: argument
394 return self._c_type_name
396 def c_param_type(self) -> str: argument
397 if self.name == 'str':
398 return 'const ' + self._c_type_name
399 return self._c_type_name
401 def json_type(self) -> str: argument
402 return self._json_type_name
404 def doc_type(self) -> str: argument
405 return self.json_type()
407 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
409 visitor.visit_builtin_type(self.name, self.info, self.json_type())
416 self, argument
428 self.members = members
429 self.prefix = prefix
431 def check(self, schema: QAPISchema) -> None: argument
434 for m in self.members:
435 m.check_clash(self.info, seen)
437 def connect_doc(self, doc: Optional[QAPIDoc] = None) -> None: argument
439 doc = doc or self.doc
440 for m in self.members:
443 def is_implicit(self) -> bool: argument
445 return self.name == 'QType'
447 def c_type(self) -> str: argument
448 return c_name(self.name)
450 def member_names(self) -> List[str]: argument
451 return [m.name for m in self.members]
453 def json_type(self) -> str: argument
456 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
459 self.name, self.info, self.ifcond, self.features,
460 self.members, self.prefix)
467 self, name: str, info: Optional[QAPISourceInfo], element_type: str argument
470 self._element_type_name = element_type
471 self.element_type: QAPISchemaType
473 def need_has_if_optional(self) -> bool: argument
478 def check(self, schema: QAPISchema) -> None: argument
480 self.element_type = schema.resolve_type(
481 self._element_type_name, self.info,
482 self.info.defn_meta if self.info else None)
483 assert not isinstance(self.element_type, QAPISchemaArrayType)
485 def set_module(self, schema: QAPISchema) -> None: argument
486 self._set_module(schema, self.element_type.info)
489 def ifcond(self) -> QAPISchemaIfCond: argument
490 assert self._checked
491 return self.element_type.ifcond
493 def is_implicit(self) -> bool: argument
496 def c_type(self) -> str: argument
497 return c_name(self.name) + POINTER_SUFFIX
499 def json_type(self) -> str: argument
502 def doc_type(self) -> Optional[str]: argument
503 elt_doc_type = self.element_type.doc_type()
508 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
510 visitor.visit_array_type(self.name, self.info, self.ifcond,
511 self.element_type)
513 def describe(self) -> str: argument
514 return "%s type ['%s']" % (self.meta, self._element_type_name)
519 self, argument
532 self.meta = 'union' if branches else 'struct'
537 self._base_name = base
538 self.base = None
539 self.local_members = local_members
540 self.branches = branches
541 self.members: List[QAPISchemaObjectTypeMember]
542 self._check_complete = False
544 def check(self, schema: QAPISchema) -> None: argument
548 if self._check_complete:
551 if self._checked:
553 raise QAPISemError(self.info,
554 "object %s contains itself" % self.name)
557 assert self._checked and not self._check_complete
560 if self._base_name:
561 self.base = schema.resolve_type(self._base_name, self.info,
563 if (not isinstance(self.base, QAPISchemaObjectType)
564 or self.base.branches):
566 self.info,
568 % self.base.describe())
569 self.base.check(schema)
570 self.base.check_clash(self.info, seen)
571 for m in self.local_members:
573 m.check_clash(self.info, seen)
575 # self.check_clash() works in terms of the supertype, but
576 # self.members is declared List[QAPISchemaObjectTypeMember].
580 if self.branches:
581 self.branches.check(schema, seen)
582 self.branches.check_clash(self.info, seen)
584 self.members = members
585 self._check_complete = True # mark completed
589 # on behalf of info, which is not necessarily self.info
591 self, argument
595 assert self._checked
596 for m in self.members:
598 if self.branches:
599 self.branches.check_clash(info, seen)
601 def connect_doc(self, doc: Optional[QAPIDoc] = None) -> None: argument
603 doc = doc or self.doc
604 if self.base and self.base.is_implicit():
605 self.base.connect_doc(doc)
606 for m in self.local_members:
609 def is_implicit(self) -> bool: argument
612 return self.name.startswith('q_')
614 def is_empty(self) -> bool: argument
615 return not self.members and not self.branches
617 def has_conditional_members(self) -> bool: argument
618 return any(m.ifcond.is_present() for m in self.members)
620 def c_name(self) -> str: argument
621 assert self.name != 'q_empty'
624 def c_type(self) -> str: argument
625 assert not self.is_implicit()
626 return c_name(self.name) + POINTER_SUFFIX
628 def c_unboxed_type(self) -> str: argument
629 return c_name(self.name)
631 def json_type(self) -> str: argument
634 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
637 self.name, self.info, self.ifcond, self.features,
638 self.base, self.local_members, self.branches)
640 self.name, self.info, self.ifcond, self.features,
641 self.members, self.branches)
648 self, argument
659 alternatives.tag_member.set_defined_in(self.name)
660 self.alternatives = alternatives
662 def check(self, schema: QAPISchema) -> None: argument
664 self.alternatives.tag_member.check(schema)
665 # Not calling self.alternatives.check_clash(), because there's
667 self.alternatives.check(schema, {})
672 for v in self.alternatives.variants:
673 v.check_clash(self.info, seen)
677 self.info,
679 % (v.describe(self.info), v.type.describe()))
695 self.info,
697 % (v.describe(self.info), types_seen[qt]))
700 def connect_doc(self, doc: Optional[QAPIDoc] = None) -> None: argument
702 doc = doc or self.doc
703 for v in self.alternatives.variants:
706 def c_type(self) -> str: argument
707 return c_name(self.name) + POINTER_SUFFIX
709 def json_type(self) -> str: argument
712 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
715 self.name, self.info, self.ifcond, self.features,
716 self.alternatives)
721 self, argument
725 self.info = info
726 self.tag_member: QAPISchemaObjectTypeMember
727 self.variants = variants
729 def set_defined_in(self, name: str) -> None: argument
730 for v in self.variants:
735 self, schema: QAPISchema, seen: Dict[str, QAPISchemaMember] argument
737 for v in self.variants:
742 def __init__(self, argument
747 self._tag_name = tag_name
750 self, schema: QAPISchema, seen: Dict[str, QAPISchemaMember] argument
753 tag_member = seen.get(c_name(self._tag_name))
760 if not tag_member or self._tag_name != tag_member.name:
762 self.info,
764 % (self._tag_name, base))
765 self.tag_member = tag_member
774 self.info,
776 % (self._tag_name, base))
779 self.info,
781 % (self._tag_name, base))
784 self.info,
786 % (self._tag_name, base))
789 cases = {v.name for v in self.variants}
792 v = QAPISchemaVariant(m.name, self.info,
795 self.variants.append(v)
796 if not self.variants:
797 raise QAPISemError(self.info, "union has no branches")
798 for v in self.variants:
805 self.info,
810 self.info,
812 % (v.describe(self.info), v.type.describe()))
816 self, argument
820 for v in self.variants:
830 def __init__(self, argument
835 self.tag_member = tag_member
838 self, schema: QAPISchema, seen: Dict[str, QAPISchemaMember] argument
841 assert isinstance(self.tag_member.type, QAPISchemaEnumType)
842 assert not self.tag_member.optional
843 assert not self.tag_member.ifcond.is_present()
851 self, argument
856 self.name = name
857 self.info = info
858 self.ifcond = ifcond or QAPISchemaIfCond()
859 self.defined_in: Optional[str] = None
861 def set_defined_in(self, name: str) -> None: argument
862 assert not self.defined_in
863 self.defined_in = name
866 self, argument
870 cname = c_name(self.name)
875 % (self.describe(info), seen[cname].describe(info)))
876 seen[cname] = self
878 def connect_doc(self, doc: Optional[QAPIDoc]) -> None: argument
880 doc.connect_member(self)
882 def describe(self, info: Optional[QAPISourceInfo]) -> str: argument
883 role = self.role
885 defined_in = self.defined_in
907 return "%s '%s' of %s '%s'" % (role, self.name, meta, defined_in)
908 return "%s '%s'" % (role, self.name)
915 self, argument
924 self.features = features or []
926 def connect_doc(self, doc: Optional[QAPIDoc]) -> None: argument
929 for f in self.features:
936 def is_special(self) -> bool: argument
937 return self.name in ('deprecated', 'unstable')
942 self, argument
953 self._type_name = typ
954 self.type: QAPISchemaType # set during check()
955 self.optional = optional
956 self.features = features or []
958 def need_has(self) -> bool: argument
959 return self.optional and self.type.need_has_if_optional()
961 def check(self, schema: QAPISchema) -> None: argument
962 assert self.defined_in
963 self.type = schema.resolve_type(self._type_name, self.info,
964 self.describe)
966 for f in self.features:
967 f.check_clash(self.info, seen)
969 def connect_doc(self, doc: Optional[QAPIDoc]) -> None: argument
972 for f in self.features:
980 self, argument
993 self, argument
1009 self._arg_type_name = arg_type
1010 self.arg_type: Optional[QAPISchemaObjectType] = None
1011 self._ret_type_name = ret_type
1012 self.ret_type: Optional[QAPISchemaType] = None
1013 self.gen = gen
1014 self.success_response = success_response
1015 self.boxed = boxed
1016 self.allow_oob = allow_oob
1017 self.allow_preconfig = allow_preconfig
1018 self.coroutine = coroutine
1020 def check(self, schema: QAPISchema) -> None: argument
1021 assert self.info is not None
1023 if self._arg_type_name:
1025 self._arg_type_name, self.info, "command's 'data'")
1028 self.info,
1031 self.arg_type = arg_type
1032 if self.arg_type.branches and not self.boxed:
1034 self.info,
1036 % self.arg_type.describe())
1037 self.arg_type.check(schema)
1038 if self.arg_type.has_conditional_members() and not self.boxed:
1040 self.info,
1042 if self._ret_type_name:
1043 self.ret_type = schema.resolve_type(
1044 self._ret_type_name, self.info, "command's 'returns'")
1045 if self.name not in self.info.pragma.command_returns_exceptions:
1046 typ = self.ret_type
1051 self.info,
1053 % self.ret_type.describe())
1055 def connect_doc(self, doc: Optional[QAPIDoc] = None) -> None: argument
1057 doc = doc or self.doc
1059 if self.arg_type and self.arg_type.is_implicit():
1060 self.arg_type.connect_doc(doc)
1062 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
1065 self.name, self.info, self.ifcond, self.features,
1066 self.arg_type, self.ret_type, self.gen, self.success_response,
1067 self.boxed, self.allow_oob, self.allow_preconfig,
1068 self.coroutine)
1075 self, argument
1085 self._arg_type_name = arg_type
1086 self.arg_type: Optional[QAPISchemaObjectType] = None
1087 self.boxed = boxed
1089 def check(self, schema: QAPISchema) -> None: argument
1091 if self._arg_type_name:
1093 self._arg_type_name, self.info, "event's 'data'")
1096 self.info,
1099 self.arg_type = typ
1100 if self.arg_type.branches and not self.boxed:
1102 self.info,
1104 % self.arg_type.describe())
1105 self.arg_type.check(schema)
1106 if self.arg_type.has_conditional_members() and not self.boxed:
1108 self.info,
1111 def connect_doc(self, doc: Optional[QAPIDoc] = None) -> None: argument
1113 doc = doc or self.doc
1115 if self.arg_type and self.arg_type.is_implicit():
1116 self.arg_type.connect_doc(doc)
1118 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
1121 self.name, self.info, self.ifcond, self.features,
1122 self.arg_type, self.boxed)
1126 def __init__(self, fname: str): argument
1127 self.fname = fname
1137 self.docs = parser.docs
1138 self._entity_list: List[QAPISchemaEntity] = []
1139 self._entity_dict: Dict[str, QAPISchemaDefinition] = {}
1140 self._module_dict: Dict[str, QAPISchemaModule] = OrderedDict()
1141 self._schema_dir = os.path.dirname(fname)
1142 self._make_module(QAPISchemaModule.BUILTIN_MODULE_NAME)
1143 self._make_module(fname)
1144 self._predefining = True
1145 self._def_predefineds()
1146 self._predefining = False
1147 self._def_exprs(exprs)
1148 self.check()
1150 def _def_entity(self, ent: QAPISchemaEntity) -> None: argument
1151 self._entity_list.append(ent)
1153 def _def_definition(self, defn: QAPISchemaDefinition) -> None: argument
1155 assert defn.info or self._predefining
1156 self._def_entity(defn)
1159 other_defn = self._entity_dict.get(defn.name)
1168 self._entity_dict[defn.name] = defn
1170 def lookup_entity(self, name: str) -> Optional[QAPISchemaEntity]: argument
1171 return self._entity_dict.get(name)
1173 def lookup_type(self, name: str) -> Optional[QAPISchemaType]: argument
1174 typ = self.lookup_entity(name)
1180 self, argument
1185 typ = self.lookup_type(name)
1194 def _module_name(self, fname: str) -> str: argument
1197 return os.path.relpath(fname, self._schema_dir)
1199 def _make_module(self, fname: str) -> QAPISchemaModule: argument
1200 name = self._module_name(fname)
1201 if name not in self._module_dict:
1202 self._module_dict[name] = QAPISchemaModule(name)
1203 return self._module_dict[name]
1205 def module_by_fname(self, fname: str) -> QAPISchemaModule: argument
1206 name = self._module_name(fname)
1207 return self._module_dict[name]
1209 def _def_include(self, expr: QAPIExpression) -> None: argument
1212 self._def_entity(
1213 QAPISchemaInclude(self._make_module(include), expr.info))
1216 self, name: str, json_type: str, c_type: str argument
1218 self._def_definition(QAPISchemaBuiltinType(name, json_type, c_type))
1223 self._make_array_type(name, None)
1225 def _def_predefineds(self) -> None: argument
1241 self._def_builtin_type(*t)
1242 self.the_empty_object_type = QAPISchemaObjectType(
1244 self._def_definition(self.the_empty_object_type)
1248 qtype_values = self._make_enum_members(
1251 self._def_definition(QAPISchemaEnumType(
1255 self, argument
1266 self, argument
1274 self._make_features(features, info))
1277 self, values: List[Dict[str, Any]], info: Optional[QAPISourceInfo] argument
1279 return [self._make_enum_member(v['name'], v.get('if'),
1284 self, element_type: str, info: Optional[QAPISourceInfo] argument
1287 if not self.lookup_type(name):
1288 self._def_definition(QAPISchemaArrayType(
1293 self, argument
1304 typ = self.lookup_entity(name)
1311 self._def_definition(QAPISchemaObjectType(
1315 def _def_enum_type(self, expr: QAPIExpression) -> None: argument
1321 features = self._make_features(expr.get('features'), info)
1322 self._def_definition(QAPISchemaEnumType(
1324 self._make_enum_members(data, info), prefix))
1327 self, argument
1340 typ = self._make_array_type(typ[0], info)
1342 self._make_features(features, info))
1345 self, argument
1349 return [self._make_member(key, value['type'],
1354 def _def_struct_type(self, expr: QAPIExpression) -> None: argument
1360 features = self._make_features(expr.get('features'), info)
1361 self._def_definition(QAPISchemaObjectType(
1363 self._make_members(data, info),
1367 self, argument
1375 typ = self._make_array_type(typ[0], info)
1378 def _def_union_type(self, expr: QAPIExpression) -> None: argument
1386 features = self._make_features(expr.get('features'), info)
1388 base = self._make_implicit_object_type(
1390 'base', self._make_members(base, info))
1392 self._make_variant(key, value['type'],
1397 self._def_definition(
1403 def _def_alternate_type(self, expr: QAPIExpression) -> None: argument
1409 features = self._make_features(expr.get('features'), info)
1411 self._make_variant(key, value['type'],
1416 self._def_definition(
1421 def _def_command(self, expr: QAPIExpression) -> None: argument
1433 features = self._make_features(expr.get('features'), info)
1435 data = self._make_implicit_object_type(
1437 'arg', self._make_members(data, info))
1440 rets = self._make_array_type(rets[0], info)
1441 self._def_definition(
1446 def _def_event(self, expr: QAPIExpression) -> None: argument
1452 features = self._make_features(expr.get('features'), info)
1454 data = self._make_implicit_object_type(
1456 'arg', self._make_members(data, info))
1457 self._def_definition(QAPISchemaEvent(name, info, expr.doc, ifcond,
1460 def _def_exprs(self, exprs: List[QAPIExpression]) -> None: argument
1463 self._def_enum_type(expr)
1465 self._def_struct_type(expr)
1467 self._def_union_type(expr)
1469 self._def_alternate_type(expr)
1471 self._def_command(expr)
1473 self._def_event(expr)
1475 self._def_include(expr)
1479 def check(self) -> None: argument
1480 for ent in self._entity_list:
1481 ent.check(self)
1483 for ent in self._entity_list:
1484 ent.set_module(self)
1485 for doc in self.docs:
1488 def visit(self, visitor: QAPISchemaVisitor) -> None: argument
1489 visitor.visit_begin(self)
1490 for mod in self._module_dict.values():