Lines Matching refs:self
106 def __init__(self, tu=None, group=None, int_data=None, ptr_data=None, argument
108 clang.cindex.Token.__init__(self)
109 self._id = None
110 self._tu = tu
111 self._group = group
112 self._cursor = cursor
116 self.int_data = int_data
117 self.ptr_data = ptr_data
120 def id(self): argument
122 if self._id is None:
123 return self.spelling
125 return self._id
128 def id(self, new_id): argument
130 self._id = new_id
133 def cursor(self): argument
134 if self._cursor is None:
135 self._cursor = clang.cindex.Token.cursor
136 return self._cursor
139 def cursor(self, new_cursor): argument
140 self._cursor = new_cursor
142 def __repr__(self): argument
143 if self.id == 'defined':
144 return self.id
145 elif self.kind == TokenKind.IDENTIFIER:
146 return "(ident %s)" % self.id
148 return self.id
150 def __str__(self): argument
151 return self.id
163 def SourceRange__contains__(self, other): argument
167 if other.file is None and self.start.file is None:
169 elif (self.start.file.name != other.file.name or
170 other.file.name != self.end.file.name):
174 if self.start.line < other.line < self.end.line:
177 elif self.start.line == other.line == self.end.line:
178 if self.start.column <= other.column <= self.end.column:
180 elif self.start.line == other.line:
182 if self.start.column <= other.column:
184 elif other.line == self.end.line:
186 if other.column <= self.end.column:
214 def __init__(self): argument
216 self._indexer = clang.cindex.Index.create()
217 self._tu = None
218 self._index = 0
219 self.tokens = None
221 def _getTokensWithCursors(self): argument
235 conf.lib.clang_tokenize(self._tu, self._tu.cursor.extent,
249 conf.lib.clang_annotateTokens(self._tu, tokens_memory, count,
255 token_group = TokenGroup(self._tu, tokens_memory, tokens_count)
259 token = Token(self._tu, token_group,
269 def parseString(self, lines): argument
272 self._tu = self._indexer.parse(file_, self.clang_flags,
274 options=self.options)
275 self.tokens = self._getTokensWithCursors()
277 def parseFile(self, file_): argument
279 self._tu = self._indexer.parse(file_, self.clang_flags,
280 options=self.options)
281 self.tokens = self._getTokensWithCursors()
283 def nextToken(self): argument
285 if self._index < len(self.tokens):
286 t = self.tokens[self._index]
287 self._index += 1
296 def __init__(self, line): argument
297 CppTokenizer.__init__(self)
298 self.parseString(line)
304 def __init__(self, file_): argument
305 CppTokenizer.__init__(self)
306 self.parseFile(file_)
314 def __init__(self, tokenizer=None): argument
315 self._tokenizer = tokenizer
316 self._token = None
318 def setTokenizer(self, tokenizer): argument
319 self._tokenizer = tokenizer
321 def expect(self, id): argument
322 self._token = self._tokenizer.nextToken()
323 if self._token is None:
326 tokid = self._token.id
332 def expectToken(self, id, line, col): argument
333 self.expect(id)
334 if self._token.location.line != line:
337 id, self._token.lineno, line))
338 if self._token.location.column != col:
340 self._token.colno, col))
342 def expectTokens(self, tokens): argument
344 self.expectToken(id, line, col)
346 def expectList(self, list_): argument
348 self.expect(item)
416 def __init__(self, tokens): argument
418 self.tokens = tokens
419 self._num_tokens = len(tokens)
420 self._index = 0
424 self.expr = self.parseExpression(0)
426 print "CppExpr: got " + repr(self.expr)
427 if self._index != self._num_tokens:
428 self.throw(BadExpectedToken, "crap at end of input (%d != %d): %s"
429 % (self._index, self._num_tokens, repr(tokens)))
431 def throw(self, exception, msg): argument
432 if self._index < self._num_tokens:
433 tok = self.tokens[self._index]
439 def expectId(self, id): argument
441 token = self.tokens[self._index]
442 if self._index >= self._num_tokens or token.id != id:
443 self.throw(BadExpectedToken,
446 self._index += 1
448 def is_decimal(self): argument
449 token = self.tokens[self._index].id
454 self._index += 1
459 def is_octal(self): argument
460 token = self.tokens[self._index].id
467 self._index += 1
472 def is_hexadecimal(self): argument
473 token = self.tokens[self._index].id
480 self._index += 1
485 def is_integer(self): argument
486 if self.tokens[self._index].kind != TokenKind.LITERAL:
489 c = self.is_hexadecimal()
493 c = self.is_octal()
497 c = self.is_decimal()
503 def is_number(self): argument
504 t = self.tokens[self._index]
505 if t.id == tokMINUS and self._index + 1 < self._num_tokens:
506 self._index += 1
507 c = self.is_integer()
511 if t.id == tokPLUS and self._index + 1 < self._num_tokens:
512 self._index += 1
513 c = self.is_integer()
517 return self.is_integer()
519 def is_defined(self): argument
520 t = self.tokens[self._index]
525 self._index += 1
527 if (self._index < self._num_tokens and
528 self.tokens[self._index].id == tokLPAREN):
530 self._index += 1
532 if self._index >= self._num_tokens:
533 self.throw(BadExpectedToken,
537 t = self.tokens[self._index]
539 self.throw(BadExpectedToken,
542 self._index += 1
544 self.expectId(tokRPAREN)
548 def is_call_or_ident(self): argument
549 if self._index >= self._num_tokens:
552 t = self.tokens[self._index]
558 self._index += 1
559 if (self._index >= self._num_tokens or
560 self.tokens[self._index].id != tokLPAREN):
565 self._index += 1
566 j = self._index
567 while self._index < self._num_tokens:
568 id = self.tokens[self._index].id
572 k = self._index
573 param = self.tokens[j:k]
577 j = self._index + 1
580 self._index += 1
582 if self._index >= self._num_tokens:
585 self._index += 1
594 def parseExpression(self, minPrecedence): argument
595 if self._index >= self._num_tokens:
598 node = self.parsePrimary()
599 while (self.token() and self.isBinary(self.token()) and
600 self.precedence(self.token()) >= minPrecedence):
601 op = self.token()
602 self.nextToken()
603 rhs = self.parseExpression(self.precedence(op) + 1)
608 def parsePrimary(self): argument
609 op = self.token()
610 if self.isUnary(op):
611 self.nextToken()
612 return (op.id, self.parseExpression(self.precedence(op)))
616 self.nextToken()
617 primary = self.parseExpression(0)
618 self.expectId(tokRPAREN)
620 self.nextToken()
621 primary = self.parseExpression(0)
622 self.expectId(":")
624 primary = self.is_number()
628 primary = self.is_defined()
630 primary = self.is_call_or_ident()
632 self.throw(BadExpectedToken,
634 self.tokens[self._index].id))
637 def isBinary(self, token): argument
638 return token.id in self.binaries
640 def isUnary(self, token): argument
641 return token.id in self.unaries
643 def precedence(self, token): argument
644 return self.precedences.get(token.id)
646 def token(self): argument
647 if self._index >= self._num_tokens:
649 return self.tokens[self._index]
651 def nextToken(self): argument
652 self._index += 1
653 if self._index >= self._num_tokens:
655 return self.tokens[self._index]
657 def dump_node(self, e): argument
682 line += " %s)" % self.dump_node(e[1])
684 line += " %s %s)" % (self.dump_node(e[1]), self.dump_node(e[2]))
690 def __repr__(self): argument
691 return self.dump_node(self.expr)
693 def source_node(self, e): argument
710 arg_src = self.source_node(arg)
721 arg1_src = self.source_node(arg)
722 arg2_src = self.source_node(arg2)
731 def __str__(self): argument
732 return self.source_node(self.expr)
741 def toInt(self): argument
742 return self.int_node(self.expr)
744 def optimize_node(self, e, macros=None): argument
774 return self.optimize_node(expanded, macros)
779 v = self.optimize_node(v, macros)
789 l = self.optimize_node(l, macros)
790 r = self.optimize_node(r, macros)
791 li = self.int_node(l)
792 ri = self.int_node(r)
807 l = self.optimize_node(l, macros)
808 r = self.optimize_node(r, macros)
809 li = self.int_node(l)
810 ri = self.int_node(r)
826 def optimize(self, macros=None): argument
829 self.expr = self.optimize_node(self.expr, macros)
982 def __init__(self, tokens, directive=None, lineno=0, identifier=None): argument
1003 self.tokens = tokens
1004 self.directive = directive
1005 self.define_id = identifier
1007 self.lineno = lineno
1009 self.lineno = self.tokens[0].location.line
1011 if self.isIf():
1012 self.expr = CppExpr(self.tokens)
1014 def isDirective(self): argument
1016 return self.directive is not None
1018 def isConditional(self): argument
1020 return self.directive in ["if", "ifdef", "ifndef", "else", "elif",
1023 def isDefine(self): argument
1025 if self.directive != "define":
1027 return self.define_id
1029 def isIf(self): argument
1031 return self.directive in ["if", "ifdef", "ifndef", "elif"]
1033 def isEndif(self): argument
1035 return self.directive == "endif"
1037 def isInclude(self): argument
1044 if self.directive != "include":
1046 return ''.join([str(x) for x in self.tokens])
1101 def writeWithWarning(self, out, warning, left_count, repeat_count, indent): argument
1108 if self.directive is None and not self.tokens:
1111 if self.directive:
1112 out.write(str(self) + '\n')
1119 lines, indent = self.format_blocks(self.tokens, indent)
1129 def __repr__(self): argument
1131 if self.directive:
1132 result = "#%s " % self.directive
1133 if self.isIf():
1134 result += repr(self.expr)
1136 for tok in self.tokens:
1140 for tok in self.tokens:
1145 def __str__(self): argument
1147 if self.directive:
1149 if self.directive == "if":
1151 e = self.expr.expr
1158 result = "#if " + str(self.expr)
1161 elif self.isDefine():
1162 result = "#%s %s" % (self.directive, self.define_id)
1163 if self.tokens:
1165 expr = strip_space(' '.join([tok.id for tok in self.tokens]))
1172 elif self.directive == "error":
1173 result = "#error %s" % ' '.join([tok.id for tok in self.tokens])
1176 result = "#%s" % self.directive
1177 if self.tokens:
1179 result += ''.join([tok.id for tok in self.tokens])
1181 lines, _ = self.format_blocks(self.tokens)
1193 def __init__(self, blocks): argument
1194 self.blocks = blocks
1196 def __len__(self): argument
1197 return len(self.blocks)
1199 def __getitem__(self, n): argument
1200 return self.blocks[n]
1202 def __repr__(self): argument
1203 return repr(self.blocks)
1205 def __str__(self): argument
1206 result = '\n'.join([str(b) for b in self.blocks])
1209 def dump(self): argument
1212 for i, b in enumerate(self.blocks):
1217 def optimizeIf01(self): argument
1219 self.blocks = optimize_if01(self.blocks)
1221 def optimizeMacros(self, macros): argument
1223 for b in self.blocks:
1227 def removeMacroDefines(self, macros): argument
1229 self.blocks = remove_macro_defines(self.blocks, macros)
1231 def optimizeAll(self, macros): argument
1232 self.optimizeMacros(macros)
1233 self.optimizeIf01()
1236 def findIncludes(self): argument
1239 for b in self.blocks:
1245 def write(self, out): argument
1246 out.write(str(self))
1248 def writeWithWarning(self, out, warning, repeat_count): argument
1251 for b in self.blocks:
1255 def removeVarsAndFuncs(self, knownStatics=None): argument
1285 for b in self.blocks:
1390 self.blocks = blocks2
1392 def replaceTokens(self, replacements): argument
1394 for b in self.blocks:
1439 def __init__(self, tokzer=None): argument
1444 self._tokzer = tokzer
1445 self._parsed = False
1448 def parsed(self): argument
1449 return self._parsed
1456 def getBlocks(self, tokzer=None): argument
1494 tokzer = self._tokzer
1509 self._short_extent(cursor.extent)))
1590 self._parsed = True
1594 def parse(self, tokzer): argument
1595 return self.getBlocks(tokzer)
1597 def parseFile(self, path): argument
1598 return self.getBlocks(CppFileTokenizer(path))