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

Method UpdatePreprocessor

src/tests/coding/cpplint.py:3016–3070  ·  view source on GitHub ↗

Update preprocessor stack. We need to handle preprocessors due to classes like this: #ifdef SWIG struct ResultDetailsPageElementExtensionPoint { #else struct ResultDetailsPageElementExtensionPoint : public Extension { #endif We make the following assumptions (

(self, line)

Source from the content-addressed store, hash-verified

3014 return False
3015
3016 def UpdatePreprocessor(self, line):
3017 """Update preprocessor stack.
3018
3019 We need to handle preprocessors due to classes like this:
3020 #ifdef SWIG
3021 struct ResultDetailsPageElementExtensionPoint {
3022 #else
3023 struct ResultDetailsPageElementExtensionPoint : public Extension {
3024 #endif
3025
3026 We make the following assumptions (good enough for most files):
3027 - Preprocessor condition evaluates to true from #if up to first
3028 #else/#elif/#endif.
3029
3030 - Preprocessor condition evaluates to false from #else/#elif up
3031 to #endif. We still perform lint checks on these lines, but
3032 these do not affect nesting stack.
3033
3034 Args:
3035 line: current line to check.
3036 """
3037 if Match(r'^\s*#\s*(if|ifdef|ifndef)\b', line):
3038 # Beginning of #if block, save the nesting stack here. The saved
3039 # stack will allow us to restore the parsing state in the #else case.
3040 self.pp_stack.append(_PreprocessorInfo(copy.deepcopy(self.stack)))
3041 elif Match(r'^\s*#\s*(else|elif)\b', line):
3042 # Beginning of #else block
3043 if self.pp_stack:
3044 if not self.pp_stack[-1].seen_else:
3045 # This is the first #else or #elif block. Remember the
3046 # whole nesting stack up to this point. This is what we
3047 # keep after the #endif.
3048 self.pp_stack[-1].seen_else = True
3049 self.pp_stack[-1].stack_before_else = copy.deepcopy(self.stack)
3050
3051 # Restore the stack to how it was before the #if
3052 self.stack = copy.deepcopy(self.pp_stack[-1].stack_before_if)
3053 else:
3054 # TODO(unknown): unexpected #else, issue warning?
3055 pass
3056 elif Match(r'^\s*#\s*endif\b', line):
3057 # End of #if or #else blocks.
3058 if self.pp_stack:
3059 # If we saw an #else, we will need to restore the nesting
3060 # stack to its former state before the #else, otherwise we
3061 # will just continue from where we left off.
3062 if self.pp_stack[-1].seen_else:
3063 # Here we can just use a shallow copy since we are the last
3064 # reference to it.
3065 self.stack = self.pp_stack[-1].stack_before_else
3066 # Drop the corresponding #if
3067 self.pp_stack.pop()
3068 else:
3069 # TODO(unknown): unexpected #endif, issue warning?
3070 pass
3071
3072 # TODO(unknown): Update() is too long, but we will refactor later.
3073 def Update(self, filename, clean_lines, linenum, error):

Callers 1

UpdateMethod · 0.95

Calls 3

_PreprocessorInfoClass · 0.85
MatchFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected