MCPcopy Create free account
hub / github.com/alibaba/GraphScope / UpdatePreprocessor

Method UpdatePreprocessor

analytical_engine/misc/cpplint.py:3019–3073  ·  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

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

Callers 1

UpdateMethod · 0.95

Calls 4

_PreprocessorInfoClass · 0.85
MatchFunction · 0.70
appendMethod · 0.65
popMethod · 0.45

Tested by

no test coverage detected