2
# STUBS handling -- Code generation: Writing declarations.
4
# (c) 2011 Andreas Kupries http://wiki.tcl.tk/andreas%20kupries
6
# A stubs table is represented by a dictionary value.
7
# A gen 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::gen::decl::g {
18
namespace import ::stubs::gen::*
21
namespace eval ::stubs::gen::decl::c {
22
namespace import ::stubs::container::*
25
# # ## ### ##### ######## #############
28
proc ::stubs::gen::decl::gen {table name} {
29
set text "\n/*\n * Exported function declarations:\n */\n\n"
30
append text [g::forall $table $name [list [namespace current]::Make $table] 0]
37
proc ::stubs::gen::decl::Make {table name decl index} {
38
#puts "DECL($name $index) = |$decl|"
40
lassign $decl rtype fname args
42
append text "/* $index */\n"
44
set line "[c::scspec? $table] $rtype"
45
set count [expr {2 - ([string length $line] / 8)}]
46
append line [string range "\t\t\t" 0 $count]
48
set pad [expr {24 - [string length $line]}]
54
if {![llength $args]} {
55
append text $line $fname ";\n"
59
set arg1 [lindex $args 0]
60
switch -exact -- $arg1 {
62
append text $line $fname "(void)"
66
append text [MakeArgs $line $pad [lrange $args 1 end] ", ..."]
70
append text [MakeArgs $line $pad $args]
77
proc ::stubs::gen::decl::MakeArgs {line pad arguments {suffix {}}} {
78
#checker -scope local exclude warnArgWrite
81
foreach arg $arguments {
85
lassign $arg atype aname aind
88
if {[string index $next end] ne "*"} {
91
append next $aname $aind
93
if {([string length $line] + [string length $next] + $pad) > 76} {
94
append text [string trimright $line] \n
101
append line "$suffix)"
103
if {[lindex $arguments end] eq "{const char *} format"} {
104
# TCL_VARARGS case... arguments list already shrunken.
105
set n [llength $arguments]
106
append line " TCL_FORMAT_PRINTF(" $n ", " [expr {$n + 1}] ")"
113
namespace eval ::stubs::gen::decl {
118
package provide stubs::gen::decl 1