~ubuntu-branches/ubuntu/hardy/uim/hardy

« back to all changes in this revision

Viewing changes to sigscheme/tools/scm_decl.rb

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2007-04-21 03:46:09 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070421034609-gpcurkutp8vaysqj
Tags: 1:1.4.1-3
* Switch to dh_gtkmodules for the gtk 2.10 transition (Closes:
  #419318)
  - debian/control: Add ${misc:Depends} and remove libgtk2.0-bin on
    uim-gtk2.0.
  - debian/uim-gtk2.0.post{inst,rm}: Removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#===========================================================================
 
2
#  Filename : scm_decl.rb
 
3
#  About    : a function declaration processing library for SigScheme
 
4
#
 
5
#  Copyright (C) 2005-2006 YAMAMOTO Kengo <yamaken AT bp.iij4u.or.jp>
 
6
#  Copyright (c) 2007 SigScheme Project <uim AT freedesktop.org>
 
7
#
 
8
#  All rights reserved.
 
9
#
 
10
#  Redistribution and use in source and binary forms, with or without
 
11
#  modification, are permitted provided that the following conditions
 
12
#  are met:
 
13
#
 
14
#  1. Redistributions of source code must retain the above copyright
 
15
#     notice, this list of conditions and the following disclaimer.
 
16
#  2. Redistributions in binary form must reproduce the above copyright
 
17
#     notice, this list of conditions and the following disclaimer in the
 
18
#     documentation and/or other materials provided with the distribution.
 
19
#  3. Neither the name of authors nor the names of its contributors
 
20
#     may be used to endorse or promote products derived from this software
 
21
#     without specific prior written permission.
 
22
#
 
23
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 
24
#  IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 
25
#  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
26
#  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
 
27
#  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
28
#  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
29
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
30
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
31
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
32
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
33
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
34
#===========================================================================
 
35
 
 
36
# ScmObj
 
37
# scm_p_call_with_values(ScmObj producer, ScmObj consumer,
 
38
#                        ScmEvalState *eval_state)
 
39
# {
 
40
#     ScmObj vals;
 
41
#     DECLARE_FUNCTION("call-with-values", procedure_fixed_tailrec_2);
 
42
#
 
43
#         |
 
44
#         V
 
45
#
 
46
# $1  :prototype       SCM_EXPORT ScmObj scm_p_call_with_values(ScmObj producer, ScmObj consumer, ScmEvalState *eval_state)
 
47
# $2  :scope           SCM_EXPORT
 
48
# $3  :ret             ScmObj
 
49
# $4  :func            scm_p_call_with_values
 
50
# $5  :prefix          p
 
51
# $6  :func_body       call_with_values
 
52
# $7  :args            ScmObj producer, ScmObj consumer, ScmEvalState *eval_state
 
53
# $8  :proc            call-with-values
 
54
# $9  :functype_whole  procedure_fixed_tailrec_2
 
55
# $10 :functype_prefix procedure
 
56
# $11 :functype_spec   fixed_tailrec_2
 
57
SCM_DECL_RE = /\n((SCM_EXPORT\s+)?(ScmObj)\s+(scm_([sp])_(\w+))\(([^{]+)\))[ \t]*\n\s*\{[^{}]+DECLARE_FUNCTION\(\s*\"([^\"]+)\"[\s,]+(([^_]+)_([\w]+))\)/m
 
58
 
 
59
 
 
60
# :register_func   scm_register_procedure_fixed_tailrec_2
 
61
# :functype_code   SCM_PROCEDURE_FIXED_TAILREC_2
 
62
class String
 
63
  def scan_scm_decl
 
64
    res = []
 
65
    scan(SCM_DECL_RE) { |prototype, scope, ret, func, prefix, func_body, args, proc, functype_whole, functype_prefix, functype_spec|
 
66
      decl = {
 
67
        :prototype       => prototype.gsub(/\s+/, " "),
 
68
        :scope           => scope,
 
69
        :ret             => ret,
 
70
        :func            => func,
 
71
        :prefix          => prefix,
 
72
        :func_body       => func_body,
 
73
        :args            => args.gsub(/\s+/, " "),
 
74
        :proc            => proc,
 
75
        :register_func   => "scm_register_" + functype_whole,
 
76
        :functype_code   => "SCM_" + functype_whole.upcase,
 
77
        :functype_whole  => functype_whole,
 
78
        :functype_prefix => functype_prefix,
 
79
        :functype_spec   => functype_spec,
 
80
      }
 
81
      res << yield(decl)
 
82
    }
 
83
    res
 
84
  end
 
85
end
 
86
 
 
87
# Obsolete
 
88
#def scm_func_table_entry(decl)
 
89
#  proc, func, register_func = decl.values_at(:proc, :func, :register_func)
 
90
#  "{ \"#{proc}\", (ScmFuncType)#{func}, (ScmRegisterFunc)#{register_func} }"
 
91
#end
 
92
 
 
93
def scm_func_table_entry(decl)
 
94
  proc, func, functype_code = decl.values_at(:proc, :func, :functype_code)
 
95
  "{ \"#{proc}\", (ScmFuncType)#{func}, #{functype_code} }"
 
96
end
 
97
 
 
98
def scm_func_register_exp(decl)
 
99
  proc, func, register_func = decl.values_at(:proc, :func, :register_func)
 
100
  "#{register_func}(\"#{proc}\", #{func})"
 
101
end
 
102
 
 
103
def scm_generate_func_table_body(str)
 
104
  str.scan_scm_decl { |decl|
 
105
    entry = scm_func_table_entry(decl)
 
106
    "    #{entry},\n"
 
107
  }.join
 
108
end
 
109
 
 
110
def scm_generate_func_register_exps(str)
 
111
  str.scan_scm_decl { |decl|
 
112
    exp = scm_func_register_exp(decl)
 
113
    "    #{exp};\n"
 
114
  }.join
 
115
end
 
116
 
 
117
def scm_generate_func_prototypes(str)
 
118
  str.scan_scm_decl { |decl|
 
119
    "#{decl[:prototype]};\n"
 
120
  }.join
 
121
end
 
122
 
 
123
 
 
124
# usage examples
 
125
 
 
126
#src = ARGF.read
 
127
 
 
128
#print src.scan_scm_decl { |decl|
 
129
#  p decl
 
130
#}
 
131
 
 
132
#print src.scan_scm_decl { |decl|
 
133
#  if (/!$/ =~ decl[:proc])
 
134
#    func = decl[:func]
 
135
#    print "perl -i -pe 's/\\b#{func}\\b/#{func.sub(/d$/, "x")}/g'\n"
 
136
#  end
 
137
#}
 
138
 
 
139
#print scm_generate_func_table_body(src)
 
140
#print scm_generate_func_register_exps(src)
 
141
#print scm_generate_func_prototypes(src)