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

Function _IsType

steps/cpplint.py:3998–4058  ·  view source on GitHub ↗

Check if expression looks like a type name, returns true if so. Args: clean_lines: A CleansedLines instance containing the file. nesting_state: A NestingState instance which maintains information about the current stack of nested blocks being parsed. expr: The expre

(clean_lines, nesting_state, expr)

Source from the content-addressed store, hash-verified

3996
3997
3998def _IsType(clean_lines, nesting_state, expr):
3999 """Check if expression looks like a type name, returns true if so.
4000
4001 Args:
4002 clean_lines: A CleansedLines instance containing the file.
4003 nesting_state: A NestingState instance which maintains information about
4004 the current stack of nested blocks being parsed.
4005 expr: The expression to check.
4006 Returns:
4007 True, if token looks like a type.
4008 """
4009 # Keep only the last token in the expression
4010 last_word = Match(r'^.*(\b\S+)$', expr)
4011 if last_word:
4012 token = last_word.group(1)
4013 else:
4014 token = expr
4015
4016 # Match native types and stdint types
4017 if _TYPES.match(token):
4018 return True
4019
4020 # Try a bit harder to match templated types. Walk up the nesting
4021 # stack until we find something that resembles a typename
4022 # declaration for what we are looking for.
4023 typename_pattern = (r'\b(?:typename|class|struct)\s+' + re.escape(token) +
4024 r'\b')
4025 block_index = len(nesting_state.stack) - 1
4026 while block_index >= 0:
4027 if isinstance(nesting_state.stack[block_index], _NamespaceInfo):
4028 return False
4029
4030 # Found where the opening brace is. We want to scan from this
4031 # line up to the beginning of the function, minus a few lines.
4032 # template <typename Type1, // stop scanning here
4033 # ...>
4034 # class C
4035 # : public ... { // start scanning here
4036 last_line = nesting_state.stack[block_index].starting_linenum
4037
4038 next_block_start = 0
4039 if block_index > 0:
4040 next_block_start = nesting_state.stack[block_index - 1].starting_linenum
4041 first_line = last_line
4042 while first_line >= next_block_start:
4043 if clean_lines.elided[first_line].find('template') >= 0:
4044 break
4045 first_line -= 1
4046 if first_line < next_block_start:
4047 # Didn't find any "template" keyword before reaching the next block,
4048 # there are probably no template things to check for this block
4049 block_index -= 1
4050 continue
4051
4052 # Look for typename in the specified range
4053 for i in xrange(first_line, last_line + 1, 1):
4054 if Search(typename_pattern, clean_lines.elided[i]):
4055 return True

Callers 1

CheckBracesSpacingFunction · 0.85

Calls 2

MatchFunction · 0.85
SearchFunction · 0.85

Tested by

no test coverage detected