MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / NestingState

Class NestingState

src/tests/coding/cpplint.py:2897–3268  ·  view source on GitHub ↗

Holds states related to parsing braces.

Source from the content-addressed store, hash-verified

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

Callers 1

ProcessFileDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected