Jelajahi Sumber

qapi/source: Remove line number from QAPISourceInfo initializer

With the QAPISourceInfo(None, None, None) construct gone, there's no
longer any reason to have to specify that a file starts on the first
line. Remove it from the initializer and default it to 1.

Remove the last vestiges where we check for 'line' being unset, that
can't happen, now.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210519183951.3946870-4-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
John Snow 4 tahun lalu
induk
melakukan
b2b31fdf9b
2 mengubah file dengan 4 tambahan dan 8 penghapusan
  1. 1 1
      scripts/qapi/parser.py
  2. 3 7
      scripts/qapi/source.py

+ 1 - 1
scripts/qapi/parser.py

@@ -47,7 +47,7 @@ def __init__(self, fname, previously_included=None, incl_info=None):
         if self.src == '' or self.src[-1] != '\n':
         if self.src == '' or self.src[-1] != '\n':
             self.src += '\n'
             self.src += '\n'
         self.cursor = 0
         self.cursor = 0
-        self.info = QAPISourceInfo(fname, 1, incl_info)
+        self.info = QAPISourceInfo(fname, incl_info)
         self.line_pos = 0
         self.line_pos = 0
         self.exprs = []
         self.exprs = []
         self.docs = []
         self.docs = []

+ 3 - 7
scripts/qapi/source.py

@@ -31,10 +31,9 @@ def __init__(self) -> None:
 class QAPISourceInfo:
 class QAPISourceInfo:
     T = TypeVar('T', bound='QAPISourceInfo')
     T = TypeVar('T', bound='QAPISourceInfo')
 
 
-    def __init__(self, fname: str, line: int,
-                 parent: Optional['QAPISourceInfo']):
+    def __init__(self, fname: str, parent: Optional['QAPISourceInfo']):
         self.fname = fname
         self.fname = fname
-        self.line = line
+        self.line = 1
         self.parent = parent
         self.parent = parent
         self.pragma: QAPISchemaPragma = (
         self.pragma: QAPISchemaPragma = (
             parent.pragma if parent else QAPISchemaPragma()
             parent.pragma if parent else QAPISchemaPragma()
@@ -52,10 +51,7 @@ def next_line(self: T) -> T:
         return info
         return info
 
 
     def loc(self) -> str:
     def loc(self) -> str:
-        ret = self.fname
-        if self.line is not None:
-            ret += ':%d' % self.line
-        return ret
+        return f"{self.fname}:{self.line}"
 
 
     def in_defn(self) -> str:
     def in_defn(self) -> str:
         if self.defn_name:
         if self.defn_name: