2 # QAPI frontend source file info
4 # Copyright (c) 2019 Red Hat Inc.
7 # Markus Armbruster <armbru@redhat.com>
9 # This work is licensed under the terms of the GNU GPL, version 2.
10 # See the COPYING file in the top-level directory.
14 from typing
import List
, Optional
, TypeVar
17 class QAPISchemaPragma
:
18 # Replace with @dataclass in Python 3.7+
19 # pylint: disable=too-few-public-methods
21 def __init__(self
) -> None:
22 # Are documentation comments required?
23 self
.doc_required
= False
24 # Whitelist of commands allowed to return a non-dictionary
25 self
.returns_whitelist
: List
[str] = []
26 # Whitelist of entities allowed to violate case conventions
27 self
.name_case_whitelist
: List
[str] = []
31 T
= TypeVar('T', bound
='QAPISourceInfo')
33 def __init__(self
, fname
: str, line
: int,
34 parent
: Optional
['QAPISourceInfo']):
38 self
.pragma
: QAPISchemaPragma
= (
39 parent
.pragma
if parent
else QAPISchemaPragma()
41 self
.defn_meta
: Optional
[str] = None
42 self
.defn_name
: Optional
[str] = None
44 def set_defn(self
, meta
: str, name
: str) -> None:
48 def next_line(self
: T
) -> T
:
49 info
= copy
.copy(self
)
54 if self
.fname
is None:
57 if self
.line
is not None:
58 ret
+= ':%d' % self
.line
61 def in_defn(self
) -> str:
63 return "%s: In %s '%s':\n" % (self
.fname
,
64 self
.defn_meta
, self
.defn_name
)
67 def include_path(self
) -> str:
71 ret
= 'In file included from %s:\n' % parent
.loc() + ret
72 parent
= parent
.parent
75 def __str__(self
) -> str:
76 return self
.include_path() + self
.in_defn() + self
.loc()