[gobject-introspection: 1/2] sourcescanner: Allow empty declarations. Fixes #216



commit 5720c77acde1b2348f3c3d08e3a27cf624be1323
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sun Dec 9 10:34:29 2018 +0100

    sourcescanner: Allow empty declarations. Fixes #216
    
    As far as I see these are not valid C and only allowed in C++11.
    But they do occur in the wild (mingw headers) so let's try to handle them.

 giscanner/scannerparser.y           | 4 ++++
 tests/scanner/test_sourcescanner.py | 6 ++++++
 2 files changed, 10 insertions(+)
---
diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y
index 72c17ec3..299910da 100644
--- a/giscanner/scannerparser.y
+++ b/giscanner/scannerparser.y
@@ -791,6 +791,9 @@ declaration
          }
        ;
 
+empty_declaration
+       : ';'
+
 declaration_specifiers
        : storage_class_specifier declaration_specifiers
          {
@@ -1459,6 +1462,7 @@ translation_unit
 external_declaration
        : function_definition
        | declaration
+       | empty_declaration
        | macro
        ;
 
diff --git a/tests/scanner/test_sourcescanner.py b/tests/scanner/test_sourcescanner.py
index 2f383af7..c731049b 100644
--- a/tests/scanner/test_sourcescanner.py
+++ b/tests/scanner/test_sourcescanner.py
@@ -72,6 +72,12 @@ void foo(int bar) {
         self.assertEqual(len(list(scanner.get_comments())), 1)
         self.assertFalse(scanner.get_errors())
 
+    def test_empty_decl(self):
+        # https://gitlab.gnome.org/GNOME/gobject-introspection/issues/216
+        scanner = self._parse_files(";int foo;")
+        self.assertEqual(len(list(scanner.get_symbols())), 1)
+        self.assertFalse(scanner.get_errors())
+
 
 if __name__ == '__main__':
     unittest.main()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]