PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/work/find_feature.py

http://github.com/tybor/Liberty
Python | 60 lines | 53 code | 6 blank | 1 comment | 3 complexity | f42ae2a98ffcae7fd92a6335f7a7b5b5 MD5 | raw file
 1#!/usr/bin/env python
 2
 3import re
 4import sys
 5
 6eiffel_feature = re.compile(r'^\s*(?P<feature_name>\w+)(?P<signature> \(((; )?((, )?(\w+))+: (\w+(\[\w+\])?))*\))?(: (?P<result_type>\w+))? is$')
 7eiffel_signature = re.compile(r'(?P<locals>((, )?(\w+))+): (NATIVE_ARRAY\[(?P<array_type>\w+)\]|(?P<type>\w+))')
 8eiffel_locals = re.compile(r'(?P<local>\w+)')
 9
10code = sys.argv[1]
11symbol = sys.argv[2]
12classname = sys.argv[3][:-2].upper()
13
14i = 5
15while i > 0:
16    line = sys.stdin.readline()
17    match = eiffel_feature.match(line)
18    if match:
19        feature = match.groupdict()
20
21        feature_name = "liberty_plugin__%s__%s" % (classname, feature["feature_name"])
22
23        r = feature["result_type"]
24        if r:
25            result_type = "EIF_%s" % r
26            do_return = " return"
27        else:
28            result_type = "void"
29            do_return = ""
30
31        c_signature = ""
32        c_locals = ""
33
34        s = feature["signature"]
35        if s:
36            i = 0
37            for match in eiffel_signature.finditer(s):
38                signature = match.groupdict()
39                if signature["type"]:
40                    local_type = "EIF_%s" % signature["type"]
41                else:
42                    local_type = "EIF_%s*" % signature["array_type"]
43                for match in eiffel_locals.finditer(signature["locals"]):
44                    local = match.groupdict()["local"]
45                    if i:
46                        c_signature = c_signature + ", "
47                        c_locals = c_locals + ", "
48                    i = i + 1
49                    c_signature = c_signature + "%s a%d" % (local_type, i)
50                    c_locals = c_locals + "a%d" % i
51            c_locals = "(" + c_locals + ")"
52
53        if code == "code":
54            print "%s __attribute__((visibility(\"default\"))) %s(%s) {%s %s%s; }" % (result_type, feature_name, c_signature, do_return, symbol, c_locals)
55        elif code == "header":
56            print "extern %s %s(%s);" % (result_type, feature_name, c_signature)
57
58        i = 0
59    else:
60        i = i - 1