]> gitweb.factorcode.org Git - factor.git/commitdiff
gobject-introspection: clean up;
authorAnton Gorenko <ex.rzrjck@gmail.com>
Sun, 6 Mar 2011 08:06:00 +0000 (14:06 +0600)
committerAnton Gorenko <ex.rzrjck@gmail.com>
Sun, 6 Mar 2011 08:06:00 +0000 (14:06 +0600)
basis/gobject-introspection/common/common.factor
basis/gobject-introspection/ffi/ffi.factor
basis/gobject-introspection/loader/loader.factor
basis/gobject-introspection/repository/repository.factor

index 4a88268878bca9a35f67d116c0bff4f0c4cdd358..1c8ad490e09ef98c06420b2561a01e2df465413a 100644 (file)
@@ -1,9 +1,12 @@
 ! Copyright (C) 2010 Anton Gorenko.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces ;
+USING: namespaces sequences ;
 IN: gobject-introspection.common
 
 SYMBOL: current-namespace-name
 
 SYMBOL: implement-structs
 implement-structs [ V{ } ] initialize
+
+: implement-struct? ( c-type -- ? )
+    implement-structs get-global member? ;
index 3b56c78a2acb56d72f4d453cf2789576cc314188..82a1d638ddc77a485476191f3000fa15bdc586a3 100644 (file)
@@ -2,14 +2,11 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.c-types alien.parser arrays ascii
 classes.parser classes.struct combinators combinators.short-circuit
-gobject-introspection.common gobject-introspection.repository
-gobject-introspection.types kernel locals make math.parser namespaces
-parser sequences splitting.monotonic vocabs.parser words
-words.constant ;
+gobject-introspection.repository gobject-introspection.types kernel
+locals make math.parser namespaces parser sequences
+splitting.monotonic vocabs.parser words words.constant ;
 IN: gobject-introspection.ffi
 
-SYMBOL: constant-prefix
-
 : def-c-type ( c-type-name base-c-type -- )
     swap (CREATE-C-TYPE) typedef ;
 
@@ -81,11 +78,8 @@ M: utf8-type parse-const-value drop ;
 : const-value ( const -- value )
     [ value>> ] [ type>> ] bi parse-const-value ;
 
-: const-name ( const -- name )
-    name>> constant-prefix get swap "_" glue ;
-
 : def-const ( const -- )
-    [ const-name create-in dup reset-generic ]
+    [ c-identifier>> create-in dup reset-generic ]
     [ const-value ] bi define-constant ;
 
 : def-consts ( consts -- )
@@ -209,7 +203,7 @@ M: array-type field-type>c-type type>c-type ;
     ] tri <struct-slot-spec> ;
 
 : def-record-type ( record -- )
-    dup c-type>> implement-structs get-global member?
+    dup fields>>
     [
         [ c-type>> create-class-in ]
         [ fields>> [ field>struct-slot ] map ] bi
@@ -321,7 +315,6 @@ M: array-type field-type>c-type type>c-type ;
 
 : def-namespace ( namespace -- )
     {
-        [ symbol-prefixes>> first >upper constant-prefix set ]
         [ consts>> def-consts ]
 
         [ enums>> defer-enums ]
index aedd07231afbfa3223c945521fada2ceecf6bf29..8e17fa5973d2966330f4b4dae2664c71b24194e5 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2010 Anton Gorenko.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators gobject-introspection.repository kernel
-literals math.parser sequences splitting xml.data xml.traversal ;
+USING: accessors ascii combinators gobject-introspection.common
+gobject-introspection.repository kernel literals math.parser
+sequences splitting xml.data xml.traversal ;
 IN: gobject-introspection.loader
 
 : xml>simple-type ( xml -- type )
@@ -128,7 +129,11 @@ CONSTANT: type-tags
 : xml>record ( xml -- record )
     [ record new ] dip {
         [ load-type ]
-        [ "field" tags-named [ xml>field ] map >>fields ]
+        [
+            over c-type>> implement-struct?
+            [ "field" tags-named [ xml>field ] map >>fields ]
+            [ drop ] if
+        ]
         [ "constructor" load-functions >>constructors ]
         [ "method" load-functions >>methods ]
         [ "function" load-functions >>functions ]
@@ -192,6 +197,13 @@ CONSTANT: type-tags
     [ boxed new ] dip
         load-type ;
 
+: fix-conts ( namespace -- )
+    [ symbol-prefixes>> first >upper "_" append ] [ consts>> ] bi
+    [ [ name>> append ] keep c-identifier<< ] with each ;
+
+: postprocess-namespace ( namespace -- )
+    fix-conts ;
+
 : xml>namespace ( xml -- namespace )
     [ namespace new ] dip {
         [ "name" attr >>name ]
@@ -208,7 +220,7 @@ CONSTANT: type-tags
         [ "class" tags-named [ xml>class ] map >>classes ]
         [ "interface" tags-named [ xml>interface ] map >>interfaces ]
         [ "function" load-functions >>functions ]
-    } cleave ;
+    } cleave [ postprocess-namespace ] keep ;
 
 : xml>repository ( xml -- repository )
     [ repository new ] dip
index 87ebcb1308c20bf102b2908695f0116a64a72af5..676e2b296fb9d7dba0383e06d62cb32ca46246e6 100644 (file)
@@ -46,7 +46,8 @@ TUPLE: alias
 TUPLE: const
     name
     value
-    type ;
+    type
+    c-identifier ;
 
 TUPLE: type
     name