コード例 #1
0
ファイル: ctypesout.py プロジェクト: allefant/scramble
    def struct(self, tokens, block):
        p = self.p

        class TypeDef: pass
        class Field: pass
        t = TypeDef()

        # Example: ["class", "Foo", ":"]
        t.name = tokens[1].value
        t.base = "Structure" if tokens[0].value == "class" else "Union"
        t.fields = []
        for line in block.value:
            if line.value[0].kind == p.STRING: # docstring
                continue

            fields = helper.parse_parameter_list(p, line.value)

            for field in fields:
                f = Field()
                f.name = field.name
                decl = " ".join([x.value for x in field.declaration])
                f.type = self.ctype(decl)
                f.bitfield = field.bitfield
                t.fields.append(f)
        
        self.typedefs.append(t)
コード例 #2
0
ファイル: analyzer.py プロジェクト: allefant/scramble
 def analyze_function(self, name, node, retlist, paramlist):
     node.name = name
     pl = helper.parse_parameter_list(self.parser, paramlist)
     for par in pl:
         param_node = parser.Node(self.parser.LINE, par.declaration)
         self.transform_statement(param_node)
         par.declaration = param_node.value[0]
     node.parameters = pl
     node.ret = retlist
コード例 #3
0
ファイル: ctypesout.py プロジェクト: allefant/scramble
    def function(self, tokens):
        state = "ret"
        p = self.p
        "int def land_get_clip(float *cx1, float *cy1, float *cx2, float *cy2):"
        ret = []
        name = "?"
        params = []
        for i, tok in enumerate(tokens):
            if state == "ret":
                if tok.kind == p.TOKEN and tok.value == "def":
                    state = "name"
                elif tok.kind == p.TOKEN and tok.value == "const":
                    pass
                else:
                    ret += [tok]
            elif state == "name":
                name = tok.value
                state = "params"
                balance = 0
            else:
                if tok.kind == p.SYMBOL and tok.value == "(":
                    pass
                else:
                    params = helper.parse_parameter_list(p, tokens[i:])
                    break

        params2 = []
        for param in params:
            v = " ".join([x.value for x in param.declaration])
            params2.append(self.ctype(v))

        params = params2

        s = name + " = load_function("
        s += '"' + name + '"'
        s += ", "
        if ret: s += self.ctype(" ".join([x.value for x in ret]))
        else: s += "c_int"
        s += ", ["

        first = True
        for param in params:
            if first:
                first = False
            else:
                s += ", "
            s += param
        s += "])"
        return s