aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/common/test
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2017-06-27 00:01:27 +0300
committerJack Humbert <jack.humb@gmail.com>2017-07-08 21:59:51 -0400
commit0256cd8ccab841a8a927f6ab0ae02ebf3ca98a96 (patch)
tree3eeae4d0537d4bb1fde26ada6ff98099e3844dcd /tmk_core/common/test
parent7d7996278571334d04e4a05445ffa4bf341806a2 (diff)
downloadfirmware-0256cd8ccab841a8a927f6ab0ae02ebf3ca98a96.tar.gz
firmware-0256cd8ccab841a8a927f6ab0ae02ebf3ca98a96.tar.bz2
firmware-0256cd8ccab841a8a927f6ab0ae02ebf3ca98a96.zip
Build all cpp files in test directories
Diffstat (limited to 'tmk_core/common/test')
0 files changed, 0 insertions, 0 deletions
>107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
#!/usr/bin/python

import sys,os

import libxltypes

(TYPE_BOOL, TYPE_INT, TYPE_UINT, TYPE_STRING) = range(4)

def py_type(ty):
    if ty == libxltypes.bool or isinstance(ty, libxltypes.BitField) and ty.width == 1:
        return TYPE_BOOL
    if isinstance(ty, libxltypes.Number):
        if ty.signed:
            return TYPE_INT
        else:
            return TYPE_UINT
    if ty == libxltypes.string:
        return TYPE_STRING
    return None

def py_wrapstruct(ty):
    l = []
    l.append('typedef struct {')
    l.append('    PyObject_HEAD;')
    l.append('    %s obj;'%ty.typename);
    l.append('}Py_%s;'%ty.rawname)
    l.append('')
    return "\n".join(l) + "\n"

def fsanitize(name):
    "Sanitise a function name given a C type"
    ret = '_'.join(name.split())
    return ret.replace('*', 'ptr')

def py_decls(ty):
    l = []
    l.append('_hidden Py_%s *Py%s_New(void);\n'%(ty.rawname, ty.rawname))
    l.append('_hidden int Py%s_Check(PyObject *self);\n'%ty.rawname)
    for f in ty.fields:
        if py_type(f.type) is not None:
            continue
        l.append('_hidden PyObject *attrib__%s_get(%s *%s);'%(\
                 fsanitize(f.type.typename), f.type.typename, f.name))
        l.append('_hidden int attrib__%s_set(PyObject *v, %s *%s);'%(\
                 fsanitize(f.type.typename), f.type.typename, f.name))
    return '\n'.join(l) + "\n"

def py_attrib_get(ty, f):
    t = py_type(f.type)
    l = []
    l.append('static PyObject *py_%s_%s_get(Py_%s *self, void *priv)'%(ty.rawname, f.name, ty.rawname))
    l.append('{')
    if t == TYPE_BOOL:
        l.append('    PyObject *ret;')
        l.append('    ret = (self->obj.%s) ? Py_True : Py_False;'%f.name)
        l.append('    Py_INCREF(ret);')
        l.append('    return ret;')
    elif t == TYPE_INT:
        l.append('    return genwrap__ll_get(self->obj.%s);'%f.name)