2
# STUBS handling -- Write stubs table as .decls file
4
# (c) 2011 Andreas Kupries http://wiki.tcl.tk/andreas%20kupries
6
# A stubs table is represented by a dictionary value.
7
# A container is a variable holding a stubs table value.
9
# # ## ### ##### ######## #############
12
package require Tcl 8.4
13
package require stubs::gen
14
package require stubs::container
15
package require lassign84
17
namespace eval ::stubs::writer::g {
18
namespace import ::stubs::gen::*
21
namespace eval ::stubs::writer::c {
22
namespace import ::stubs::container::*
25
# # ## ### ##### ######## #############
28
proc ::stubs::writer::gen {table} {
31
set dscspec [c::scspec? $defaults]
32
set depoch [c::epoch? $defaults]
34
set name [c::library? $table]
35
set scspec [c::scspec? $table]
36
set epoch [c::epoch? $table]
37
set rev [c::revision? $table]
39
lappend lines "\# ${name}.decls -- -*- tcl -*-"
41
lappend lines "\#\tThis file contains the declarations for all public functions"
42
lappend lines "\#\tthat are exported by the \"${name}\" library via its stubs table."
46
lappend lines "library [list $name]"
48
if {($scspec ne $dscspec) ||
49
($epoch ne $depoch )} {
50
if {$scspec ne $dscspec} {
51
lappend lines "scspec [list $scspec]"
53
if {$epoch ne $depoch } {
54
lappend lines "epoch [list $epoch]"
55
lappend lines "revision [list $rev]"
59
foreach if [c::interfaces $table] {
61
lappend lines "interface [list $if]"
63
if {[c::hooks? $table $if]} {
64
lappend lines "hooks [list [c::hooksof $table $if]]"
67
[g::forall $table $if \
68
[list [namespace current]::Make $table] \
72
lappend lines "\# END $name"
74
return [join $lines \n]
80
proc ::stubs::writer::Make {table if decl index} {
81
#puts |---------------------------------------
82
#puts |$if|$index|$decl|
84
lassign $decl rtype fname arguments
85
if {[llength $arguments]} {
86
# what about the third piece of info, array flag?! ...
89
foreach a $arguments {
92
} elseif {$a eq "TCL_VARARGS"} {
95
lassign $a atype aname aflag
96
# aflag either "", or "[]".
97
lappend ax "$atype $aname$aflag"
98
#puts \t|$atype|$aname|$aflag|
101
set ax [join $ax {, }]$suffix
105
set cdecl "\n $rtype $fname ($ax)\n"
106
set platforms [c::slotplatforms $table $if $index]
109
lappend lines "declare $index [list $platforms] \{$cdecl\}"
111
return [join $lines \n]\n
115
namespace eval ::stubs::writer {
120
package provide stubs::writer 1