Lines Matching full:self

38     def __init__(self, msg):  argument
39 self.msg = msg
41 def __str__(self): argument
42 return self.msg
51 def __and__(self, rhs): argument
52 return KconfigData.AND(self, rhs)
53 def __or__(self, rhs): argument
54 return KconfigData.OR(self, rhs)
55 def __invert__(self): argument
56 return KconfigData.NOT(self)
59 def add_edges_to(self, var): argument
61 def evaluate(self): argument
65 def __init__(self, lhs, rhs): argument
66 self.lhs = lhs
67 self.rhs = rhs
68 def __str__(self): argument
69 return "(%s && %s)" % (self.lhs, self.rhs)
71 def add_edges_to(self, var): argument
72 self.lhs.add_edges_to(var)
73 self.rhs.add_edges_to(var)
74 def evaluate(self): argument
75 return self.lhs.evaluate() and self.rhs.evaluate()
78 def __init__(self, lhs, rhs): argument
79 self.lhs = lhs
80 self.rhs = rhs
81 def __str__(self): argument
82 return "(%s || %s)" % (self.lhs, self.rhs)
84 def add_edges_to(self, var): argument
85 self.lhs.add_edges_to(var)
86 self.rhs.add_edges_to(var)
87 def evaluate(self): argument
88 return self.lhs.evaluate() or self.rhs.evaluate()
91 def __init__(self, lhs): argument
92 self.lhs = lhs
93 def __str__(self): argument
94 return "!%s" % (self.lhs)
96 def add_edges_to(self, var): argument
97 self.lhs.add_edges_to(var)
98 def evaluate(self): argument
99 return not self.lhs.evaluate()
102 def __init__(self, name): argument
103 self.name = name
104 self.value = None
105 self.outgoing = set()
106 self.clauses_for_var = list()
107 def __str__(self): argument
108 return self.name
110 def has_value(self): argument
111 return not (self.value is None)
112 def set_value(self, val, clause): argument
113 self.clauses_for_var.append(clause)
114 if self.has_value() and self.value != val:
115 print("The following clauses were found for " + self.name, file=sys.stderr)
116 for i in self.clauses_for_var:
118 raise KconfigDataError('contradiction between clauses when setting %s' % self)
119 debug_print("=> %s is now %s" % (self.name, val))
120 self.value = val
123 def dfs(self, visited, f): argument
124 if self in visited:
126 visited.add(self)
127 for v in self.outgoing:
129 f(self)
131 def add_edges_to(self, var): argument
132 self.outgoing.add(var)
133 def evaluate(self): argument
134 if not self.has_value():
135 raise KconfigDataError('cycle found including %s' % self)
136 return self.value
139 def __init__(self, dest): argument
140 self.dest = dest
141 def priority(self): argument
143 def process(self): argument
147 def __init__(self, dest, value): argument
148 KconfigData.Clause.__init__(self, dest)
149 self.value = value
150 def __str__(self): argument
151 return "CONFIG_%s=%s" % (self.dest, 'y' if self.value else 'n')
153 def process(self): argument
154 self.dest.set_value(self.value, self)
157 def __init__(self, dest, value, cond=None): argument
158 KconfigData.Clause.__init__(self, dest)
159 self.value = value
160 self.cond = cond
161 if not (self.cond is None):
162 self.cond.add_edges_to(self.dest)
163 def __str__(self): argument
164 value = 'y' if self.value else 'n'
165 if self.cond is None:
166 return "config %s default %s" % (self.dest, value)
168 return "config %s default %s if %s" % (self.dest, value, self.cond)
170 def priority(self): argument
173 def process(self): argument
174 if not self.dest.has_value() and \
175 (self.cond is None or self.cond.evaluate()):
176 self.dest.set_value(self.value, self)
179 def __init__(self, dest, expr): argument
180 KconfigData.Clause.__init__(self, dest)
181 self.expr = expr
182 self.expr.add_edges_to(self.dest)
183 def __str__(self): argument
184 return "config %s depends on %s" % (self.dest, self.expr)
186 def process(self): argument
187 if not self.expr.evaluate():
188 self.dest.set_value(False, self)
191 def __init__(self, dest, cond): argument
192 KconfigData.Clause.__init__(self, dest)
193 self.cond = cond
194 self.cond.add_edges_to(self.dest)
195 def __str__(self): argument
196 return "select %s if %s" % (self.dest, self.cond)
198 def process(self): argument
199 if self.cond.evaluate():
200 self.dest.set_value(True, self)
202 def __init__(self, value_mangler=defconfig): argument
203 self.value_mangler = value_mangler
204 self.previously_included = []
205 self.incl_info = None
206 self.defined_vars = set()
207 self.referenced_vars = dict()
208 self.clauses = list()
212 def check_undefined(self): argument
214 for i in self.referenced_vars:
215 if not (i in self.defined_vars):
220 def compute_config(self): argument
221 if self.check_undefined():
226 for clause in self.clauses:
230 for i in self.referenced_vars:
231 debug_print(i, "->", [str(x) for x in self.referenced_vars[i].outgoing])
241 for name, v in self.referenced_vars.items():
242 self.do_default(v, False)
248 self.clauses.sort(key=lambda x: (-dfo[x.dest], -x.priority()))
251 for clause in self.clauses:
257 for name, v in self.referenced_vars.items():
265 def do_declaration(self, var): argument
266 if (var in self.defined_vars):
269 self.defined_vars.add(var.name)
272 def do_var(self, var): argument
273 if (var in self.referenced_vars):
274 return self.referenced_vars[var]
276 var_obj = self.referenced_vars[var] = KconfigData.Var(var)
279 def do_assignment(self, var, val): argument
280 self.clauses.append(KconfigData.AssignmentClause(var, val))
282 def do_default(self, var, val, cond=None): argument
283 val = self.value_mangler(val)
284 self.clauses.append(KconfigData.DefaultClause(var, val, cond))
286 def do_depends_on(self, var, expr): argument
287 self.clauses.append(KconfigData.DependsOnClause(var, expr))
289 def do_select(self, var, symbol, cond=None): argument
291 self.clauses.append(KconfigData.SelectClause(symbol, cond))
293 def do_imply(self, var, symbol, cond=None): argument
297 self.do_default(symbol, True, cond)
328 def __init__(self, parser, msg, tok=None): argument
329 self.loc = parser.location()
334 self.msg = msg
336 def __str__(self): argument
337 return "%s: %s" % (self.loc, self.msg)
342 def parse(self, fp, mode=None): argument
348 def __init__(self, data): argument
349 self.data = data
351 def parse_file(self, fp): argument
352 self.abs_fname = os.path.abspath(fp.name)
353 self.fname = fp.name
354 self.data.previously_included.append(self.abs_fname)
355 self.src = fp.read()
356 if self.src == '' or self.src[-1] != '\n':
357 self.src += '\n'
358 self.cursor = 0
359 self.line = 1
360 self.line_pos = 0
361 self.get_token()
362 self.parse_config()
364 def do_assignment(self, var, val): argument
367 var = self.data.do_var(var[7:])
368 self.data.do_assignment(var, val)
372 def error_path(self): argument
373 inf = self.data.incl_info
381 def location(self): argument
383 for ch in self.src[self.line_pos:self.pos]:
388 return '%s%s:%d:%d' %(self.error_path(), self.fname, self.line, col)
390 def do_include(self, include): argument
391 incl_abs_fname = os.path.join(os.path.dirname(self.abs_fname),
394 inf = self.data.incl_info
397 raise KconfigParserError(self, "Inclusion loop for %s"
402 if incl_abs_fname in self.data.previously_included:
407 raise KconfigParserError(self,
410 inf = self.data.incl_info
411 self.data.incl_info = { 'file': self.fname, 'line': self.line,
413 KconfigParser(self.data).parse_file(fp)
414 self.data.incl_info = inf
419 def parse_y_or_n(self): argument
420 if self.tok == TOK_Y:
421 self.get_token()
423 if self.tok == TOK_N:
424 self.get_token()
426 raise KconfigParserError(self, 'Expected "y" or "n"')
429 def parse_var(self): argument
430 if self.tok == TOK_ID:
431 val = self.val
432 self.get_token()
433 return self.data.do_var(val)
435 raise KconfigParserError(self, 'Expected identifier')
438 def parse_assignment_var(self): argument
439 if self.tok == TOK_ID:
440 val = self.val
442 raise KconfigParserError(self,
444 self.get_token()
445 return self.data.do_var(val[7:])
447 raise KconfigParserError(self, 'Expected identifier')
450 def parse_assignment(self): argument
451 var = self.parse_assignment_var()
452 if self.tok != TOK_EQUAL:
453 raise KconfigParserError(self, 'Expected "="')
454 self.get_token()
455 self.data.do_assignment(var, self.parse_y_or_n())
460 def parse_primary(self): argument
461 if self.tok == TOK_NOT:
462 self.get_token()
463 val = ~self.parse_primary()
464 elif self.tok == TOK_LPAREN:
465 self.get_token()
466 val = self.parse_expr()
467 if self.tok != TOK_RPAREN:
468 raise KconfigParserError(self, 'Expected ")"')
469 self.get_token()
470 elif self.tok == TOK_ID:
471 val = self.parse_var()
473 raise KconfigParserError(self, 'Expected "!" or "(" or identifier')
477 def parse_disj(self): argument
478 lhs = self.parse_primary()
479 while self.tok == TOK_OR:
480 self.get_token()
481 lhs = lhs | self.parse_primary()
485 def parse_expr(self): argument
486 lhs = self.parse_disj()
487 while self.tok == TOK_AND:
488 self.get_token()
489 lhs = lhs & self.parse_disj()
494 def parse_condition(self): argument
495 if self.tok == TOK_IF:
496 self.get_token()
497 return self.parse_expr()
505 def parse_property(self, var): argument
506 if self.tok == TOK_DEFAULT:
507 self.get_token()
508 val = self.parse_y_or_n()
509 cond = self.parse_condition()
510 self.data.do_default(var, val, cond)
511 elif self.tok == TOK_DEPENDS:
512 self.get_token()
513 if self.tok != TOK_ON:
514 raise KconfigParserError(self, 'Expected "on"')
515 self.get_token()
516 self.data.do_depends_on(var, self.parse_expr())
517 elif self.tok == TOK_SELECT:
518 self.get_token()
519 symbol = self.parse_var()
520 cond = self.parse_condition()
521 self.data.do_select(var, symbol, cond)
522 elif self.tok == TOK_IMPLY:
523 self.get_token()
524 symbol = self.parse_var()
525 cond = self.parse_condition()
526 self.data.do_imply(var, symbol, cond)
527 elif self.tok == TOK_BOOL:
528 self.get_token()
530 raise KconfigParserError(self, 'Error in recursive descent?')
534 def parse_properties(self, var): argument
536 while self.tok == TOK_DEFAULT or self.tok == TOK_DEPENDS or \
537 self.tok == TOK_SELECT or self.tok == TOK_BOOL or \
538 self.tok == TOK_IMPLY:
539 self.parse_property(var)
542 if self.tok != TOK_SOURCE and self.tok != TOK_CONFIG and \
543 self.tok != TOK_ID and self.tok != TOK_EOF:
544 raise KconfigParserError(self, 'expected "source", "config", identifier, '
548 def parse_declaration(self): argument
549 if self.tok == TOK_CONFIG:
550 self.get_token()
551 var = self.parse_var()
552 self.data.do_declaration(var)
553 self.parse_properties(var)
555 raise KconfigParserError(self, 'Error in recursive descent?')
560 def parse_clause(self): argument
561 if self.tok == TOK_SOURCE:
562 val = self.val
563 self.get_token()
564 self.do_include(val)
565 elif self.tok == TOK_CONFIG:
566 self.parse_declaration()
567 elif self.tok == TOK_ID:
568 self.parse_assignment()
570 raise KconfigParserError(self, 'expected "source", "config" or identifier')
573 def parse_config(self): argument
574 while self.tok != TOK_EOF:
575 self.parse_clause()
576 return self.data
580 def get_token(self): argument
582 self.tok = self.src[self.cursor]
583 self.pos = self.cursor
584 self.cursor += 1
586 self.val = None
587 self.tok = self.scan_token()
588 if self.tok is not None:
591 def check_keyword(self, rest): argument
592 if not self.src.startswith(rest, self.cursor):
595 if self.src[self.cursor + length].isalnum() or self.src[self.cursor + length] == '_':
597 self.cursor += length
600 def scan_token(self): argument
601 if self.tok == '#':
602 self.cursor = self.src.find('\n', self.cursor)
604 elif self.tok == '=':
606 elif self.tok == '(':
608 elif self.tok == ')':
610 elif self.tok == '&' and self.src[self.pos+1] == '&':
611 self.cursor += 1
613 elif self.tok == '|' and self.src[self.pos+1] == '|':
614 self.cursor += 1
616 elif self.tok == '!':
618 elif self.tok == 'd' and self.check_keyword("epends"):
620 elif self.tok == 'o' and self.check_keyword("n"):
622 elif self.tok == 's' and self.check_keyword("elect"):
624 elif self.tok == 'i' and self.check_keyword("mply"):
626 elif self.tok == 'c' and self.check_keyword("onfig"):
628 elif self.tok == 'd' and self.check_keyword("efault"):
630 elif self.tok == 'b' and self.check_keyword("ool"):
632 elif self.tok == 'i' and self.check_keyword("f"):
634 elif self.tok == 'y' and self.check_keyword(""):
636 elif self.tok == 'n' and self.check_keyword(""):
638 elif (self.tok == 's' and self.check_keyword("ource")) or \
639 self.tok == 'i' and self.check_keyword("nclude"):
642 while self.src[self.cursor].isspace():
643 self.cursor += 1
644 start = self.cursor
645 self.cursor = self.src.find('\n', self.cursor)
646 self.val = self.src[start:self.cursor]
648 elif self.tok.isalnum():
650 while self.src[self.cursor].isalnum() or self.src[self.cursor] == '_':
651 self.cursor += 1
652 self.val = self.src[self.pos:self.cursor]
654 elif self.tok == '\n':
655 if self.cursor == len(self.src):
657 self.line += 1
658 self.line_pos = self.cursor
659 elif not self.tok.isspace():
660 raise KconfigParserError(self, 'invalid input')