MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / NestingState

Class NestingState

steps/cpplint.py:2911–3282  ·  view source on GitHub ↗

Holds states related to parsing braces.

Source from the content-addressed store, hash-verified

2909
2910
2911class NestingState(object):
2912 """Holds states related to parsing braces."""
2913
2914 def __init__(self):
2915 # Stack for tracking all braces. An object is pushed whenever we
2916 # see a "{", and popped when we see a "}". Only 3 types of
2917 # objects are possible:
2918 # - _ClassInfo: a class or struct.
2919 # - _NamespaceInfo: a namespace.
2920 # - _BlockInfo: some other type of block.
2921 self.stack = []
2922
2923 # Top of the previous stack before each Update().
2924 #
2925 # Because the nesting_stack is updated at the end of each line, we
2926 # had to do some convoluted checks to find out what is the current
2927 # scope at the beginning of the line. This check is simplified by
2928 # saving the previous top of nesting stack.
2929 #
2930 # We could save the full stack, but we only need the top. Copying
2931 # the full nesting stack would slow down cpplint by ~10%.
2932 self.previous_stack_top = []
2933
2934 # Stack of _PreprocessorInfo objects.
2935 self.pp_stack = []
2936
2937 def SeenOpenBrace(self):
2938 """Check if we have seen the opening brace for the innermost block.
2939
2940 Returns:
2941 True if we have seen the opening brace, False if the innermost
2942 block is still expecting an opening brace.
2943 """
2944 return (not self.stack) or self.stack[-1].seen_open_brace
2945
2946 def InNamespaceBody(self):
2947 """Check if we are currently one level inside a namespace body.
2948
2949 Returns:
2950 True if top of the stack is a namespace block, False otherwise.
2951 """
2952 return self.stack and isinstance(self.stack[-1], _NamespaceInfo)
2953
2954 def InExternC(self):
2955 """Check if we are currently one level inside an 'extern "C"' block.
2956
2957 Returns:
2958 True if top of the stack is an extern block, False otherwise.
2959 """
2960 return self.stack and isinstance(self.stack[-1], _ExternCInfo)
2961
2962 def InClassDeclaration(self):
2963 """Check if we are currently one level inside a class or struct declaration.
2964
2965 Returns:
2966 True if top of the stack is a class/struct, False otherwise.
2967 """
2968 return self.stack and isinstance(self.stack[-1], _ClassInfo)

Callers 1

ProcessFileDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected