File: c_tools.py

package info (click to toggle)
wxwidgets3.0 3.0.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 120,808 kB
  • ctags: 118,010
  • sloc: cpp: 889,420; makefile: 52,980; ansic: 21,933; sh: 5,603; python: 2,935; xml: 1,534; perl: 281
file content (74 lines) | stat: -rw-r--r-- 2,200 bytes parent folder | download | duplicates (10)
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
"""
C bindings generator
Author: Luke A. Guest
"""

import os

from common import *

class CBuilder:
    def __init__(self, doxyparse, outputdir):
        self.doxyparser = doxyparse
        self.output_dir = outputdir

    def make_bindings(self):
        output_dir = os.path.abspath(os.path.join(self.output_dir, "c"))
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)
    
        for aclass in self.doxyparser.classes:
            # This bit doesn't work, because the aclass.name is not the same as
            # those listed in common
            if aclass.name in excluded_classes:
                #print "Skipping %s" % aclass.name
                continue
                
            self.make_c_header(output_dir, aclass)


    def make_c_header(self, output_dir, aclass):
            filename = os.path.join(output_dir, aclass.name[2:].lower() + ".hh")
            enums_text = make_enums(aclass)
            method_text = self.make_c_methods(aclass)
            class_name = aclass.name[2:].capitalize()
            text = """
// Enums
%s

%s
""" % (enums_text, method_text)

            afile = open(filename, "wb")
            afile.write(text)
            afile.close()


    def make_c_methods(self, aclass):
        retval = ""
        
        wxc_classname = 'wxC' + aclass.name[2:].capitalize()

        for amethod in aclass.constructors:
            retval += """
// %s
%s%s;\n\n
""" % (amethod.brief_description, wxc_classname + '* ' + wxc_classname + '_' + amethod.name, amethod.argsstring)

        for amethod in aclass.methods:
            if amethod.name.startswith('m_'):
                # for some reason, public members are listed as methods
                continue
        
            args = '(' + wxc_classname + '* obj'
            if amethod.argsstring.find('()') != -1:
                args += ')'
            else: 
                args += ', ' + amethod.argsstring[1:].strip()
            
            retval += """
// %s
%s %s%s;\n
""" % (amethod.detailed_description, amethod.return_type, wxc_classname + '_' + amethod.name, args)

        return retval