From 479304d0a7c25319ef6b225dba65a60f62074506 Mon Sep 17 00:00:00 2001 From: Anton Gorenko Date: Sun, 6 Mar 2011 14:06:00 +0600 Subject: [PATCH] gobject-introspection: clean up; --- .../common/common.factor | 5 ++++- basis/gobject-introspection/ffi/ffi.factor | 17 +++++----------- .../loader/loader.factor | 20 +++++++++++++++---- .../repository/repository.factor | 3 ++- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/basis/gobject-introspection/common/common.factor b/basis/gobject-introspection/common/common.factor index 4a88268878..1c8ad490e0 100644 --- a/basis/gobject-introspection/common/common.factor +++ b/basis/gobject-introspection/common/common.factor @@ -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? ; diff --git a/basis/gobject-introspection/ffi/ffi.factor b/basis/gobject-introspection/ffi/ffi.factor index 3b56c78a2a..82a1d638dd 100644 --- a/basis/gobject-introspection/ffi/ffi.factor +++ b/basis/gobject-introspection/ffi/ffi.factor @@ -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 ; : 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 ] diff --git a/basis/gobject-introspection/loader/loader.factor b/basis/gobject-introspection/loader/loader.factor index aedd07231a..8e17fa5973 100644 --- a/basis/gobject-introspection/loader/loader.factor +++ b/basis/gobject-introspection/loader/loader.factor @@ -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 diff --git a/basis/gobject-introspection/repository/repository.factor b/basis/gobject-introspection/repository/repository.factor index 87ebcb1308..676e2b296f 100644 --- a/basis/gobject-introspection/repository/repository.factor +++ b/basis/gobject-introspection/repository/repository.factor @@ -46,7 +46,8 @@ TUPLE: alias TUPLE: const name value - type ; + type + c-identifier ; TUPLE: type name