File: mkqtdecl_extract_nc_pointers.rb

package info (click to toggle)
klayout 0.28.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 279,296 kB
  • sloc: cpp: 2,009,432; ruby: 43,292; xml: 25,855; python: 11,686; sh: 1,611; tcl: 212; perl: 170; makefile: 112; ansic: 42
file content (102 lines) | stat: -rw-r--r-- 2,709 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

# 
# Copyright (C) 2006-2023 Matthias Koefferlein
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

# A helper script to detect non-const pointers 
# (those indicate ownership issues).

# run with
# klayout -r mkqtdecl_extract_nc_pointers.rb -z s

events = {}

classes = {}
RBA::Class::each_class do |cls|
  classes[cls.name] = true
end

RBA::Class::each_class do |cls|

  uc = {
    RBA::ArgType.t_void => "",
    RBA::ArgType.t_bool => "b",
    RBA::ArgType.t_char => "c",
    RBA::ArgType.t_schar => "c",
    RBA::ArgType.t_uchar => "uc",
    RBA::ArgType.t_short => "s",
    RBA::ArgType.t_ushort => "us",
    RBA::ArgType.t_int => "i",
    RBA::ArgType.t_uint => "ui",
    RBA::ArgType.t_long => "l",
    RBA::ArgType.t_ulong => "ul",
    RBA::ArgType.t_longlong => "w",
    RBA::ArgType.t_ulonglong => "uw",
    RBA::ArgType.t_double => "d",
    RBA::ArgType.t_float => "f",
    RBA::ArgType.t_var => "v",
    RBA::ArgType.t_string => "s",
    RBA::ArgType.t_qstring => "qs",
    RBA::ArgType.t_string_ccptr => "t",
  }

  if cls.name =~ /_Native$/ || !classes[cls.name + "_Native"]

    m = {}
    cls.each_method do |meth|
      m[meth.name] ||= {}
      has_ptr = false
      has_int = false
      csig = ""
      if meth.is_static?
        csig += "s"
      end
      if meth.is_const?
        csig += "c"
      end
      if csig != ""
        csig += "#"
      end
      meth.each_argument do |a|
        if a.is_ptr? || a.is_cptr? 
          has_ptr = true
          csig += "p"
        end
        if a.type == RBA::ArgType::t_vector
          csig += "a"
          c = uc[a.inner.type].to_s
          csig += c
        elsif a.type == RBA::ArgType::t_object || a.type == RBA::ArgType::t_object_new
          csig += "x"
          csig += a.cls.name
        else
          c = uc[a.type]
          if c == "i" || c == "ui" || c == "l" || c == "ul"
            has_int = true
          end
          csig += c
        end
      end
      if has_ptr && has_int
        puts "#{cls.name}::#{meth.name}_#{csig}"
      end
    end

  end

end