Code Duplication    Length = 75-75 lines in 2 locations

sdk/build-support/cpplint.py 1 location

@@ 3051-3125 (lines=75) @@
3048
              'Zero-parameter constructors should not be marked explicit.')
3049
3050
3051
def CheckSpacingForFunctionCall(filename, clean_lines, linenum, error):
3052
  """Checks for the correctness of various spacing around function calls.
3053
3054
  Args:
3055
    filename: The name of the current file.
3056
    clean_lines: A CleansedLines instance containing the file.
3057
    linenum: The number of the line to check.
3058
    error: The function to call with any errors found.
3059
  """
3060
  line = clean_lines.elided[linenum]
3061
3062
  # Since function calls often occur inside if/for/while/switch
3063
  # expressions - which have their own, more liberal conventions - we
3064
  # first see if we should be looking inside such an expression for a
3065
  # function call, to which we can apply more strict standards.
3066
  fncall = line    # if there's no control flow construct, look at whole line
3067
  for pattern in (r'\bif\s*\((.*)\)\s*{',
3068
                  r'\bfor\s*\((.*)\)\s*{',
3069
                  r'\bwhile\s*\((.*)\)\s*[{;]',
3070
                  r'\bswitch\s*\((.*)\)\s*{'):
3071
    match = Search(pattern, line)
3072
    if match:
3073
      fncall = match.group(1)    # look inside the parens for function calls
3074
      break
3075
3076
  # Except in if/for/while/switch, there should never be space
3077
  # immediately inside parens (eg "f( 3, 4 )").  We make an exception
3078
  # for nested parens ( (a+b) + c ).  Likewise, there should never be
3079
  # a space before a ( when it's a function argument.  I assume it's a
3080
  # function argument when the char before the whitespace is legal in
3081
  # a function name (alnum + _) and we're not starting a macro. Also ignore
3082
  # pointers and references to arrays and functions coz they're too tricky:
3083
  # we use a very simple way to recognize these:
3084
  # " (something)(maybe-something)" or
3085
  # " (something)(maybe-something," or
3086
  # " (something)[something]"
3087
  # Note that we assume the contents of [] to be short enough that
3088
  # they'll never need to wrap.
3089
  if (  # Ignore control structures.
3090
      not Search(r'\b(if|for|while|switch|return|new|delete|catch|sizeof)\b',
3091
                 fncall) and
3092
      # Ignore pointers/references to functions.
3093
      not Search(r' \([^)]+\)\([^)]*(\)|,$)', fncall) and
3094
      # Ignore pointers/references to arrays.
3095
      not Search(r' \([^)]+\)\[[^\]]+\]', fncall)):
3096
    if Search(r'\w\s*\(\s(?!\s*\\$)', fncall):      # a ( used for a fn call
3097
      error(filename, linenum, 'whitespace/parens', 4,
3098
            'Extra space after ( in function call')
3099
    elif Search(r'\(\s+(?!(\s*\\)|\()', fncall):
3100
      error(filename, linenum, 'whitespace/parens', 2,
3101
            'Extra space after (')
3102
    if (Search(r'\w\s+\(', fncall) and
3103
        not Search(r'_{0,2}asm_{0,2}\s+_{0,2}volatile_{0,2}\s+\(', fncall) and
3104
        not Search(r'#\s*define|typedef|using\s+\w+\s*=', fncall) and
3105
        not Search(r'\w\s+\((\w+::)*\*\w+\)\(', fncall) and
3106
        not Search(r'\bcase\s+\(', fncall)):
3107
      # TODO(unknown): Space after an operator function seem to be a common
3108
      # error, silence those for now by restricting them to highest verbosity.
3109
      if Search(r'\boperator_*\b', line):
3110
        error(filename, linenum, 'whitespace/parens', 0,
3111
              'Extra space before ( in function call')
3112
      else:
3113
        error(filename, linenum, 'whitespace/parens', 4,
3114
              'Extra space before ( in function call')
3115
    # If the ) is followed only by a newline or a { + newline, assume it's
3116
    # part of a control statement (if/while/etc), and don't complain
3117
    if Search(r'[^)]\s+\)\s*[^{\s]', fncall):
3118
      # If the closing parenthesis is preceded by only whitespaces,
3119
      # try to give a more descriptive error message.
3120
      if Search(r'^\s+\)', fncall):
3121
        error(filename, linenum, 'whitespace/parens', 2,
3122
              'Closing ) should be moved to the previous line')
3123
      else:
3124
        error(filename, linenum, 'whitespace/parens', 2,
3125
              'Extra space before )')
3126
3127
3128
def IsBlankLine(line):

core/build-support/cpplint.py 1 location

@@ 3051-3125 (lines=75) @@
3048
              'Zero-parameter constructors should not be marked explicit.')
3049
3050
3051
def CheckSpacingForFunctionCall(filename, clean_lines, linenum, error):
3052
  """Checks for the correctness of various spacing around function calls.
3053
3054
  Args:
3055
    filename: The name of the current file.
3056
    clean_lines: A CleansedLines instance containing the file.
3057
    linenum: The number of the line to check.
3058
    error: The function to call with any errors found.
3059
  """
3060
  line = clean_lines.elided[linenum]
3061
3062
  # Since function calls often occur inside if/for/while/switch
3063
  # expressions - which have their own, more liberal conventions - we
3064
  # first see if we should be looking inside such an expression for a
3065
  # function call, to which we can apply more strict standards.
3066
  fncall = line    # if there's no control flow construct, look at whole line
3067
  for pattern in (r'\bif\s*\((.*)\)\s*{',
3068
                  r'\bfor\s*\((.*)\)\s*{',
3069
                  r'\bwhile\s*\((.*)\)\s*[{;]',
3070
                  r'\bswitch\s*\((.*)\)\s*{'):
3071
    match = Search(pattern, line)
3072
    if match:
3073
      fncall = match.group(1)    # look inside the parens for function calls
3074
      break
3075
3076
  # Except in if/for/while/switch, there should never be space
3077
  # immediately inside parens (eg "f( 3, 4 )").  We make an exception
3078
  # for nested parens ( (a+b) + c ).  Likewise, there should never be
3079
  # a space before a ( when it's a function argument.  I assume it's a
3080
  # function argument when the char before the whitespace is legal in
3081
  # a function name (alnum + _) and we're not starting a macro. Also ignore
3082
  # pointers and references to arrays and functions coz they're too tricky:
3083
  # we use a very simple way to recognize these:
3084
  # " (something)(maybe-something)" or
3085
  # " (something)(maybe-something," or
3086
  # " (something)[something]"
3087
  # Note that we assume the contents of [] to be short enough that
3088
  # they'll never need to wrap.
3089
  if (  # Ignore control structures.
3090
      not Search(r'\b(if|for|while|switch|return|new|delete|catch|sizeof)\b',
3091
                 fncall) and
3092
      # Ignore pointers/references to functions.
3093
      not Search(r' \([^)]+\)\([^)]*(\)|,$)', fncall) and
3094
      # Ignore pointers/references to arrays.
3095
      not Search(r' \([^)]+\)\[[^\]]+\]', fncall)):
3096
    if Search(r'\w\s*\(\s(?!\s*\\$)', fncall):      # a ( used for a fn call
3097
      error(filename, linenum, 'whitespace/parens', 4,
3098
            'Extra space after ( in function call')
3099
    elif Search(r'\(\s+(?!(\s*\\)|\()', fncall):
3100
      error(filename, linenum, 'whitespace/parens', 2,
3101
            'Extra space after (')
3102
    if (Search(r'\w\s+\(', fncall) and
3103
        not Search(r'_{0,2}asm_{0,2}\s+_{0,2}volatile_{0,2}\s+\(', fncall) and
3104
        not Search(r'#\s*define|typedef|using\s+\w+\s*=', fncall) and
3105
        not Search(r'\w\s+\((\w+::)*\*\w+\)\(', fncall) and
3106
        not Search(r'\bcase\s+\(', fncall)):
3107
      # TODO(unknown): Space after an operator function seem to be a common
3108
      # error, silence those for now by restricting them to highest verbosity.
3109
      if Search(r'\boperator_*\b', line):
3110
        error(filename, linenum, 'whitespace/parens', 0,
3111
              'Extra space before ( in function call')
3112
      else:
3113
        error(filename, linenum, 'whitespace/parens', 4,
3114
              'Extra space before ( in function call')
3115
    # If the ) is followed only by a newline or a { + newline, assume it's
3116
    # part of a control statement (if/while/etc), and don't complain
3117
    if Search(r'[^)]\s+\)\s*[^{\s]', fncall):
3118
      # If the closing parenthesis is preceded by only whitespaces,
3119
      # try to give a more descriptive error message.
3120
      if Search(r'^\s+\)', fncall):
3121
        error(filename, linenum, 'whitespace/parens', 2,
3122
              'Closing ) should be moved to the previous line')
3123
      else:
3124
        error(filename, linenum, 'whitespace/parens', 2,
3125
              'Extra space before )')
3126
3127
3128
def IsBlankLine(line):