summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/ast.py
diff options
context:
space:
mode:
authorHolger Freyther <ich@tamarin.(none)>2009-05-18 19:50:14 +0200
committerRichard Purdie <rpurdie@linux.intel.com>2010-02-15 17:07:07 +0000
commit71a19386a36931c2e8cd882bb19c33ace60e4398 (patch)
treeec045a41543026d1cb8bf7cb94b29ceedea11be7 /bitbake/lib/bb/parse/ast.py
parentdf8f7706a6c22863f2c3a51e1a788c5d676fd8b3 (diff)
downloadpoky-71a19386a36931c2e8cd882bb19c33ace60e4398.tar.gz
bitbake: [parser] Firs set of AST nodes with construction and eval
First set of ConfHandling with AST nodes. The include can use a speed up and things might need to be migrated... into this class. Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/parse/ast.py')
-rw-r--r--bitbake/lib/bb/parse/ast.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py
index f21b0aeb45..b6dadd1e2a 100644
--- a/bitbake/lib/bb/parse/ast.py
+++ b/bitbake/lib/bb/parse/ast.py
@@ -30,13 +30,85 @@ class StatementGroup:
30 def __init__(self): 30 def __init__(self):
31 self.statements = [] 31 self.statements = []
32 32
33 def append(self, statement):
34 self.statements.append(statement)
35
33 def eval(self, data): 36 def eval(self, data):
34 """ 37 """
35 Apply each statement on the data... in order 38 Apply each statement on the data... in order
36 """ 39 """
37 map(lambda x: x.eval(data), self.statements) 40 map(lambda x: x.eval(data), self.statements)
38 41
42class IncludeNode:
43 def __init__(self, what_file, fn, lineno):
44 self.what_file = what_file
45 self.from_fn = fn
46 self.from_lineno = lineno
47
48 def eval(self, data):
49 """
50 Include the file and evaluate the statements
51 """
52 s = bb.data.expand(self.what_file, data)
53 bb.msg.debug(3, bb.msg.domain.Parsing, "CONF %s:%d: including %s" % (self.from_fn, self.from_lineno, s))
54
55 # TODO: Cache those includes...
56 statements = StatementGroup()
57 bb.parse.ConfHandler.include(statements, self.from_fn, s, data, False)
58 statements.eval(data)
59
60class ExportNode:
61 def __init__(self, var):
62 self.var = var
63
64 def eval(self, data):
65 bb.data.setVarFlag(self.var, "export", 1, data)
66
67class DataNode:
68 """
69 Various data related updates. For the sake of sanity
70 we have one class doing all this. This means that all
71 this need to be re-evaluated... we might be able to do
72 that faster with multiple classes.
73 """
74 def __init__(self, groupd):
75 self.groupd = groupd
76
77 def eval(self, data):
78 groupd = self.groupd
79 key = groupd["var"]
80 if "exp" in groupd and groupd["exp"] != None:
81 bb.data.setVarFlag(key, "export", 1, data)
82 if "ques" in groupd and groupd["ques"] != None:
83 val = getFunc(groupd, key, data)
84 if val == None:
85 val = groupd["value"]
86 elif "colon" in groupd and groupd["colon"] != None:
87 e = data.createCopy()
88 bb.data.update_data(e)
89 val = bb.data.expand(groupd["value"], e)
90 elif "append" in groupd and groupd["append"] != None:
91 val = "%s %s" % ((getFunc(groupd, key, data) or ""), groupd["value"])
92 elif "prepend" in groupd and groupd["prepend"] != None:
93 val = "%s %s" % (groupd["value"], (getFunc(groupd, key, data) or ""))
94 elif "postdot" in groupd and groupd["postdot"] != None:
95 val = "%s%s" % ((getFunc(groupd, key, data) or ""), groupd["value"])
96 elif "predot" in groupd and groupd["predot"] != None:
97 val = "%s%s" % (groupd["value"], (getFunc(groupd, key, data) or ""))
98 else:
99 val = groupd["value"]
100 if 'flag' in groupd and groupd['flag'] != None:
101 bb.msg.debug(3, bb.msg.domain.Parsing, "setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val))
102 bb.data.setVarFlag(key, groupd['flag'], val, data)
103 else:
104 bb.data.setVar(key, val, data)
105
106
107
39def handleInclude(statements, m, fn, lineno, data, force): 108def handleInclude(statements, m, fn, lineno, data, force):
109 # AST handling
110 statements.append(IncludeNode(m.group(1), fn, lineno))
111
40 s = bb.data.expand(m.group(1), data) 112 s = bb.data.expand(m.group(1), data)
41 bb.msg.debug(3, bb.msg.domain.Parsing, "CONF %s:%d: including %s" % (fn, lineno, s)) 113 bb.msg.debug(3, bb.msg.domain.Parsing, "CONF %s:%d: including %s" % (fn, lineno, s))
42 if force: 114 if force:
@@ -45,9 +117,15 @@ def handleInclude(statements, m, fn, lineno, data, force):
45 bb.parse.ConfHandler.include(statements, fn, s, data, False) 117 bb.parse.ConfHandler.include(statements, fn, s, data, False)
46 118
47def handleExport(statements, m, data): 119def handleExport(statements, m, data):
120 # AST handling
121 statements.append(ExportNode(m.group(1)))
122
48 bb.data.setVarFlag(m.group(1), "export", 1, data) 123 bb.data.setVarFlag(m.group(1), "export", 1, data)
49 124
50def handleData(statements, groupd, data): 125def handleData(statements, groupd, data):
126 # AST handling
127 statements.append(DataNode(groupd))
128
51 key = groupd["var"] 129 key = groupd["var"]
52 if "exp" in groupd and groupd["exp"] != None: 130 if "exp" in groupd and groupd["exp"] != None:
53 bb.data.setVarFlag(key, "export", 1, data) 131 bb.data.setVarFlag(key, "export", 1, data)