Holds states related to parsing braces.
| 2404 | |
| 2405 | |
| 2406 | class NestingState(object): |
| 2407 | """Holds states related to parsing braces.""" |
| 2408 | |
| 2409 | def __init__(self): |
| 2410 | # Stack for tracking all braces. An object is pushed whenever we |
| 2411 | # see a "{", and popped when we see a "}". Only 3 types of |
| 2412 | # objects are possible: |
| 2413 | # - _ClassInfo: a class or struct. |
| 2414 | # - _NamespaceInfo: a namespace. |
| 2415 | # - _BlockInfo: some other type of block. |
| 2416 | self.stack = [] |
| 2417 | |
| 2418 | # Top of the previous stack before each Update(). |
| 2419 | # |
| 2420 | # Because the nesting_stack is updated at the end of each line, we |
| 2421 | # had to do some convoluted checks to find out what is the current |
| 2422 | # scope at the beginning of the line. This check is simplified by |
| 2423 | # saving the previous top of nesting stack. |
| 2424 | # |
| 2425 | # We could save the full stack, but we only need the top. Copying |
| 2426 | # the full nesting stack would slow down cpplint by ~10%. |
| 2427 | self.previous_stack_top = [] |
| 2428 | |
| 2429 | # Stack of _PreprocessorInfo objects. |
| 2430 | self.pp_stack = [] |
| 2431 | |
| 2432 | def SeenOpenBrace(self): |
| 2433 | """Check if we have seen the opening brace for the innermost block. |
| 2434 | |
| 2435 | Returns: |
| 2436 | True if we have seen the opening brace, False if the innermost |
| 2437 | block is still expecting an opening brace. |
| 2438 | """ |
| 2439 | return (not self.stack) or self.stack[-1].seen_open_brace |
| 2440 | |
| 2441 | def InNamespaceBody(self): |
| 2442 | """Check if we are currently one level inside a namespace body. |
| 2443 | |
| 2444 | Returns: |
| 2445 | True if top of the stack is a namespace block, False otherwise. |
| 2446 | """ |
| 2447 | return self.stack and isinstance(self.stack[-1], _NamespaceInfo) |
| 2448 | |
| 2449 | def InExternC(self): |
| 2450 | """Check if we are currently one level inside an 'extern "C"' block. |
| 2451 | |
| 2452 | Returns: |
| 2453 | True if top of the stack is an extern block, False otherwise. |
| 2454 | """ |
| 2455 | return self.stack and isinstance(self.stack[-1], _ExternCInfo) |
| 2456 | |
| 2457 | def InClassDeclaration(self): |
| 2458 | """Check if we are currently one level inside a class or struct declaration. |
| 2459 | |
| 2460 | Returns: |
| 2461 | True if top of the stack is a class/struct, False otherwise. |
| 2462 | """ |
| 2463 | return self.stack and isinstance(self.stack[-1], _ClassInfo) |
no outgoing calls
no test coverage detected
searching dependent graphs…