summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/parse_c/bitbakec.pyx
blob: 362cc2021eea744ac7599226f2790e3969892136 (plain)
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
103
104
105
106
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
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-

cdef extern from "stdio.h":
    ctypedef int FILE
    FILE *fopen(char*, char*)
    int fclose(FILE *fp)


cdef extern from "lexerc.h":
    ctypedef struct lex_t:
        void* parser
        void* scanner
        FILE* file
        void* data

    int lineError
    int errorParse

    cdef extern void parse(FILE*, object)

def parsefile(object file, object data):
    print "parsefile: 1", file, data

    # Open the file
    cdef FILE* f

    f = fopen(file, "r")
    print "parsefile: 2 opening file"
    if (f == NULL):
        raise IOError("No such file %s." % file)

    print "parsefile: 3 parse"
    parse(f, data)

    # Close the file
    print "parsefile: 4 closing"
    fclose(f)

 
cdef public void e_assign(lex_t* container, char* key, char* what):
    print "e_assign", key, what
    d = <object>container.data
    d.setVar(key, what)    

cdef public void e_export(lex_t* c, char* what):
    print "e_export", what
    #exp:
    # bb.data.setVarFlag(key, "export", 1, data)
    d = <object>container.data
    d.setVarFlag(key, "export", 1)

cdef public void e_immediate(lex_t* c, char* key, char* what):
    print "e_immediate", key, what
    #colon:
    # val = bb.data.expand(groupd["value"], data)
    d = <object>c.data
    d.setVar(key, d.expand(what))

cdef public void e_cond(lex_t* c, char* key, char* what):
    print "e_cond", key, what
    #ques:
    # val = bb.data.getVar(key, data)
    # if val == None:    
    #    val = groupd["value"]
    d = <object>c.data
    d.setVar(key, (d.getVar(key) or what))

cdef public void e_prepend(lex_t* c, char* key, char* what):
    print "e_prepend", key, what
    #prepend:
    # val = "%s %s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
    d = <object>c.data
    d.setVar(key, what + " " + (d.getVar(key) or ""))

cdef public void e_append(lex_t* c, char* key, char* what):
    print "e_append", key, what
    #append:
    # val = "%s %s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
    d = <object>c.data
    d.setVar(key, (d.getVar(key) or "") + " " + what)

cdef public void e_precat(lex_t* c, char* key, char* what):
    print "e_precat", key, what
    #predot:
    # val = "%s%s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
    d = <object>c.data
    d.setVar(key, what + (d.getVar(key) or ""))

cdef public void e_postcat(lex_t* c, char* key, char* what):
    print "e_postcat", key, what
    #postdot:
    # val = "%s%s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
    d = <object>c.data
    d.setVar(key, (d.getVar(key) or "") + what)

cdef public void e_addtask(lex_t* c, char* name, char* before, char* after):
    print "e_addtask", name, before, after
    # func = m.group("func")
    # before = m.group("before")
    # after = m.group("after")
    # if func is None:
    #     return
    # var = "do_" + func
    #
    # data.setVarFlag(var, "task", 1, d)
    #
    # if after is not None:
    # #  set up deps for function
    #     data.setVarFlag(var, "deps", after.split(), d)
    # if before is not None:
    # #   set up things that depend on this func
    #     data.setVarFlag(var, "postdeps", before.split(), d)
    # return
    
    do = "do_%s" % name
    d = <object>c.data
    d.setVarFlag(do, "task", 1)

    if strlen(before) > 0:
        d.setVarFlag(do, "deps", ("%s" % after).split())
    if strlen(after) > 0:
        d.setVarFlag(do, "deps", ("%s" % before).split())


cdef public void e_addhandler(lex_t* c, char* h):
    print "e_addhandler", h
    # data.setVarFlag(h, "handler", 1, d)
    d = <object>c.data
    d.setVarFlag(h, "handler", 1)

cdef public void e_export_func(lex_t* c, char* function):
    print "e_export_func", function
    pass

cdef public void e_inherit(lex_t* c, char* file):
    print "e_inherit", file
    pass

cdef public void e_include(lex_t* c, char* file):
    print "e_include", file
    d = <object>c.data
    d.expand(file)
    
    try:
        parsefile(file, d)
    except IOError:
        print "Could not include required file %s" % file


cdef public void e_require(lex_t* c, char* file):
    print "e_require", file
    d = <object>c.data
    d.expand(file)
    
    try:
        parsefile(file, d)
    except IOError:
        raise CParseError("Could not include required file %s" % file)

cdef public void e_proc(lex_t* c, char* key, char* what):
    print "e_proc", key, what
    pass

cdef public void e_proc_python(lex_t* c, char* key, char* what):
    print "e_proc_python", key, what
    pass

cdef public void e_proc_fakeroot(lex_t* c, char* key, char* what):
    print "e_fakeroot", key, what
    pass

cdef public void e_def(lex_t* c, char* a, char* b, char* d):
    print "e_def", key, what
    pass

cdef public void e_parse_error(lex_t* c):
    print "e_parse_error", "line:", lineError, "parse:", errorParse
    raise CParseError("There was an parse error, sorry unable to give more information at the current time.")