! 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? ;
! 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 ;
: 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 -- )
] 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
: def-namespace ( namespace -- )
{
- [ symbol-prefixes>> first >upper constant-prefix set ]
[ consts>> def-consts ]
[ enums>> defer-enums ]
! 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 )
: 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 ]
[ 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 ]
[ "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
TUPLE: const
name
value
- type ;
+ type
+ c-identifier ;
TUPLE: type
name