MCPcopy Index your code
hub / github.com/nodejs/node / NestingState

Class NestingState

tools/cpplint.py:3275–3717  ·  view source on GitHub ↗

Holds states related to parsing braces.

Source from the content-addressed store, hash-verified

3273
3274
3275class NestingState:
3276 """Holds states related to parsing braces."""
3277
3278 def __init__(self):
3279 # Stack for tracking all braces. An object is pushed whenever we
3280 # see a "{", and popped when we see a "}". Only 3 types of
3281 # objects are possible:
3282 # - _ClassInfo: a class or struct.
3283 # - _NamespaceInfo: a namespace.
3284 # - _BlockInfo: some other type of block.
3285 self.stack: list[_BlockInfo] = []
3286
3287 # Top of the previous stack before each Update().
3288 #
3289 # Because the nesting_stack is updated at the end of each line, we
3290 # had to do some convoluted checks to find out what is the current
3291 # scope at the beginning of the line. This check is simplified by
3292 # saving the previous top of nesting stack.
3293 #
3294 # We could save the full stack, but we only need the top. Copying
3295 # the full nesting stack would slow down cpplint by ~10%.
3296 self.previous_stack_top: _BlockInfo | None = None
3297
3298 # The number of open parentheses in the previous stack top before the last update.
3299 # Used to prevent false indentation detection when e.g. a function parameter is indented.
3300 # We can't use previous_stack_top, a shallow copy whose open_parentheses value is updated.
3301 self.previous_open_parentheses = 0
3302
3303 # The last stack item we popped.
3304 self.popped_top: _BlockInfo | None = None
3305
3306 # Stack of _PreprocessorInfo objects.
3307 self.pp_stack = []
3308
3309 def SeenOpenBrace(self):
3310 """Check if we have seen the opening brace for the innermost block.
3311
3312 Returns:
3313 True if we have seen the opening brace, False if the innermost
3314 block is still expecting an opening brace.
3315 """
3316 return (not self.stack) or self.stack[-1].seen_open_brace
3317
3318 def InNamespaceBody(self):
3319 """Check if we are currently one level inside a namespace body.
3320
3321 Returns:
3322 True if top of the stack is a namespace block, False otherwise.
3323 """
3324 return self.stack and isinstance(self.stack[-1], _NamespaceInfo)
3325
3326 def InExternC(self):
3327 """Check if we are currently one level inside an 'extern "C"' block.
3328
3329 Returns:
3330 True if top of the stack is an extern block, False otherwise.
3331 """
3332 return self.stack and isinstance(self.stack[-1], _ExternCInfo)

Callers 1

ProcessFileDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…