[scanner] Support private/public directives
authorJohan Dahlin <johan@gnome.org>
Mon, 20 Sep 2010 20:44:09 +0000 (17:44 -0300)
committerJohan Dahlin <johan@gnome.org>
Mon, 20 Sep 2010 21:54:42 +0000 (18:54 -0300)
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=594125

giscanner/ast.py
giscanner/girparser.py
giscanner/girwriter.py
giscanner/giscannermodule.c
giscanner/scannerlexer.l
giscanner/scannerparser.y
giscanner/sourcescanner.h
giscanner/sourcescanner.py
giscanner/transformer.py
tests/scanner/Regress-1.0-expected.gir
tests/scanner/regress.h

index 08129cb..1b1de5c 100644 (file)
@@ -766,6 +766,7 @@ class Field(Annotated):
         self.writable = writable
         self.bits = bits
         self.anonymous_node = anonymous_node
+        self.private = False
 
     def __cmp__(self, other):
         return cmp(self.name, other.name)
index 8b638bf..06901dc 100644 (file)
@@ -490,6 +490,7 @@ class GIRParser(object):
                       node.attrib.get('writable') == '1',
                       node.attrib.get('bits'),
                       anonymous_node=anonymous_node)
+        field.private = node.attrib.get('private') == '1'
         self._parse_generic_attribs(node, field)
         return field
 
index 80e1719..43dbd26 100644 (file)
@@ -513,6 +513,8 @@ and/or use gtk-doc annotations. ''')
                 attrs.append(('writable', '1'))
             if field.bits:
                 attrs.append(('bits', str(field.bits)))
+            if field.private:
+                attrs.append(('private', '1'))
             with self.tagcontext('field', attrs):
                 self._write_generic(field)
                 self._write_type(field.type)
index b4aae79..de65d6f 100644 (file)
@@ -119,6 +119,13 @@ symbol_get_line (PyGISourceSymbol *self,
 }
 
 static PyObject *
+symbol_get_private (PyGISourceSymbol *self,
+                    void             *context)
+{
+  return PyBool_FromLong (self->symbol->private);
+}
+
+static PyObject *
 symbol_get_ident (PyGISourceSymbol *self,
                  void            *context)
 {
@@ -202,6 +209,7 @@ static const PyGetSetDef _PyGISourceSymbol_getsets[] = {
   { "const_string", (getter)symbol_get_const_string, NULL, NULL},
   { "source_filename", (getter)symbol_get_source_filename, NULL, NULL},
   { "line", (getter)symbol_get_line, NULL, NULL},
+  { "private", (getter)symbol_get_private, NULL, NULL},
   { 0 }
 };
 
index 5a5058b..5b68ca0 100644 (file)
@@ -57,7 +57,7 @@ intsuffix                             ([uU][lL]?[lL]?)|([lL][lL]?[uU]?)
 fracconst                              ([0-9]*\.[0-9]+)|([0-9]+\.)
 exppart                                        [eE][-+]?[0-9]+
 floatsuffix                            [fFlL]
-chartext                               ([^\\\'])|(\\.) 
+chartext                               ([^\\\'])|(\\.)
 stringtext                             ([^\\\"])|(\\.)
 
 %%
@@ -72,6 +72,8 @@ stringtext                            ([^\\\"])|(\\.)
 [\t\f\v\r ]+                           { /* Ignore whitespace. */ }
 
 "/*"                                   { parse_comment(scanner); }
+"/*"[\t ]*<[\t ]*"private"[\t ]*>" */"  { scanner->private = TRUE; }
+"/*"[\t ]*<[\t ]*"public"[\t ]*>" */"   { scanner->private = FALSE; }
 "//".*                                 { }
 
 "#define "[a-zA-Z_][a-zA-Z_0-9]*"("    { yyless (yyleng - 1); return FUNCTION_MACRO; }
index b4df11c..d5f9a65 100644 (file)
@@ -742,10 +742,12 @@ struct_or_union_specifier
 struct_or_union
        : STRUCT
          {
+                scanner->private = FALSE;
                $$ = gi_source_struct_new (NULL);
          }
        | UNION
          {
+                scanner->private = FALSE;
                $$ = gi_source_union_new (NULL);
          }
        ;
@@ -771,7 +773,8 @@ struct_declaration
                else
                    sym->type = CSYMBOL_TYPE_MEMBER;
                gi_source_symbol_merge_type (sym, gi_source_type_copy ($1));
-               $$ = g_list_append ($$, sym);
+                sym->private = scanner->private;
+                $$ = g_list_append ($$, sym);
              }
            ctype_free ($1);
          }
@@ -830,6 +833,7 @@ struct_declarator
 enum_specifier
        : ENUM identifier_or_typedef_name '{' enumerator_list '}'
          {
+                scanner->private = FALSE;
                $$ = gi_source_enum_new ($2);
                $$->child_list = $4;
                $$->is_bitfield = is_bitfield;
@@ -837,6 +841,7 @@ enum_specifier
          }
        | ENUM '{' enumerator_list '}'
          {
+                scanner->private = FALSE;
                $$ = gi_source_enum_new (NULL);
                $$->child_list = $3;
                $$->is_bitfield = is_bitfield;
@@ -844,6 +849,7 @@ enum_specifier
          }
        | ENUM identifier_or_typedef_name '{' enumerator_list ',' '}'
          {
+                scanner->private = FALSE;
                $$ = gi_source_enum_new ($2);
                $$->child_list = $4;
                $$->is_bitfield = is_bitfield;
@@ -851,6 +857,7 @@ enum_specifier
          }
        | ENUM '{' enumerator_list ',' '}'
          {
+                scanner->private = FALSE;
                $$ = gi_source_enum_new (NULL);
                $$->child_list = $3;
                $$->is_bitfield = is_bitfield;
@@ -858,6 +865,7 @@ enum_specifier
          }
        | ENUM identifier_or_typedef_name
          {
+                scanner->private = FALSE;
                $$ = gi_source_enum_new ($2);
          }
        ;
@@ -870,11 +878,17 @@ enumerator_list
          }
          enumerator
          {
-               $$ = g_list_append (NULL, $2);
+              if (!scanner->private)
+                {
+                  $$ = g_list_append (NULL, $2);
+                }
          }
        | enumerator_list ',' enumerator
          {
-               $$ = g_list_append ($1, $3);
+              if (!scanner->private)
+                {
+                  $$ = g_list_append ($1, $3);
+                }
          }
        ;
 
index a7bc176..500d84c 100644 (file)
@@ -107,6 +107,7 @@ struct _GISourceScanner
 {
   char *current_filename;
   gboolean macro_scan;
+  gboolean private; /* set by gtk-doc comment <private>/<public> */
   GSList *symbols;
   GList *filenames;
   GSList *comments; /* _GIComment */
@@ -122,6 +123,7 @@ struct _GISourceSymbol
   char *ident;
   GISourceType *base_type;
   gboolean const_int_set;
+  gboolean private;
   int const_int;
   char *const_string;
   gboolean const_double_set;
index e4c670b..e449f50 100644 (file)
@@ -199,6 +199,10 @@ class SourceSymbol(object):
         return self._symbol.line
 
     @property
+    def private(self):
+        return self._symbol.private
+
+    @property
     def position(self):
         return Position(self._symbol.source_filename,
                         self._symbol.line)
index 70addb2..9f2bc15 100644 (file)
@@ -354,6 +354,8 @@ raise ValueError."""
             if prefixlen > 0:
                 name = child.ident[prefixlen:]
             else:
+                if child.ident is None:
+                    continue
                 # Ok, the enum members don't have a consistent prefix
                 # among them, so let's just remove the global namespace
                 # prefix.
@@ -448,7 +450,12 @@ raise ValueError."""
             # ast.Fields are assumed to be read-write
             # (except for Objects, see also glibtransformer.py)
             node = ast.Field(symbol.ident, ftype,
-                         readable=True, writable=True, bits=symbol.const_int)
+                             readable=True, writable=True,
+                             bits=symbol.const_int)
+            if symbol.private:
+                node.readable = False
+                node.writable = False
+                node.private = True
         return node
 
     def _create_typedef(self, symbol):
index ebbcb0a..15029d2 100644 (file)
@@ -699,6 +699,25 @@ TpAccount::status-changed</doc>
         </callback>
       </field>
     </record>
+    <bitfield name="TestPrivateEnum" c:type="RegressTestPrivateEnum">
+      <member name="before"
+              value="1"
+              c:identifier="REGRESS_TEST_PUBLIC_ENUM_BEFORE"/>
+      <member name="after"
+              value="4"
+              c:identifier="REGRESS_TEST_PUBLIC_ENUM_AFTER"/>
+    </bitfield>
+    <record name="TestPrivateStruct" c:type="RegressTestPrivateStruct">
+      <field name="this_is_public_before" writable="1">
+        <type name="gint" c:type="gint"/>
+      </field>
+      <field name="this_is_private" readable="0" private="1">
+        <type name="gint" c:type="gint"/>
+      </field>
+      <field name="this_is_public_after" writable="1">
+        <type name="gint" c:type="gint"/>
+      </field>
+    </record>
     <record name="TestSimpleBoxedA"
             c:type="RegressTestSimpleBoxedA"
             glib:type-name="RegressTestSimpleBoxedA"
index ac71307..1e68cfa 100644 (file)
@@ -562,4 +562,22 @@ typedef struct _RegressIntset RegressIntset;
  */
 typedef RegressIntset RegressIntSet;
 
+/* private testing */
+
+typedef struct {
+  gint this_is_public_before;
+  /* < private > */
+  gint this_is_private;
+  /* < public > */
+  gint this_is_public_after;
+} RegressTestPrivateStruct;
+
+typedef enum {
+  REGRESS_TEST_PUBLIC_ENUM_BEFORE = 1 << 0,
+  /* <private> */
+  REGRESS_TEST_PRIVATE_ENUM       = 1 << 1,
+  /* <public> */
+  REGRESS_TEST_PUBLIC_ENUM_AFTER  = 1 << 2,
+} RegressTestPrivateEnum;
+
 #endif /* __GITESTTYPES_H__ */