MCPcopy Create free account
hub / github.com/apache/mesos / _IsType

Function _IsType

support/cpplint.py:3488–3548  ·  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

3486
3487
3488def _IsType(clean_lines, nesting_state, expr):
3489 """Check if expression looks like a type name, returns true if so.
3490
3491 Args:
3492 clean_lines: A CleansedLines instance containing the file.
3493 nesting_state: A NestingState instance which maintains information about
3494 the current stack of nested blocks being parsed.
3495 expr: The expression to check.
3496 Returns:
3497 True, if token looks like a type.
3498 """
3499 # Keep only the last token in the expression
3500 last_word = Match(r'^.*(\b\S+)$', expr)
3501 if last_word:
3502 token = last_word.group(1)
3503 else:
3504 token = expr
3505
3506 # Match native types and stdint types
3507 if _TYPES.match(token):
3508 return True
3509
3510 # Try a bit harder to match templated types. Walk up the nesting
3511 # stack until we find something that resembles a typename
3512 # declaration for what we are looking for.
3513 typename_pattern = (r'\b(?:typename|class|struct)\s+' + re.escape(token) +
3514 r'\b')
3515 block_index = len(nesting_state.stack) - 1
3516 while block_index >= 0:
3517 if isinstance(nesting_state.stack[block_index], _NamespaceInfo):
3518 return False
3519
3520 # Found where the opening brace is. We want to scan from this
3521 # line up to the beginning of the function, minus a few lines.
3522 # template <typename Type1, // stop scanning here
3523 # ...>
3524 # class C
3525 # : public ... { // start scanning here
3526 last_line = nesting_state.stack[block_index].starting_linenum
3527
3528 next_block_start = 0
3529 if block_index > 0:
3530 next_block_start = nesting_state.stack[block_index - 1].starting_linenum
3531 first_line = last_line
3532 while first_line >= next_block_start:
3533 if clean_lines.elided[first_line].find('template') >= 0:
3534 break
3535 first_line -= 1
3536 if first_line < next_block_start:
3537 # Didn't find any "template" keyword before reaching the next block,
3538 # there are probably no template things to check for this block
3539 block_index -= 1
3540 continue
3541
3542 # Look for typename in the specified range
3543 for i in xrange(first_line, last_line + 1, 1):
3544 if Search(typename_pattern, clean_lines.elided[i]):
3545 return True

Callers 1

CheckBracesSpacingFunction · 0.85

Calls 4

MatchFunction · 0.85
SearchFunction · 0.85
matchMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected