Code Duplication    Length = 75-75 lines in 2 locations

sdk/build-support/cpplint.py 1 location

@@ 1811-1885 (lines=75) @@
1808
  return (line, clean_lines.NumLines(), -1)
1809
1810
1811
def FindStartOfExpressionInLine(line, endpos, stack):
1812
  """Find position at the matching start of current expression.
1813
1814
  This is almost the reverse of FindEndOfExpressionInLine, but note
1815
  that the input position and returned position differs by 1.
1816
1817
  Args:
1818
    line: a CleansedLines line.
1819
    endpos: start searching at this position.
1820
    stack: nesting stack at endpos.
1821
1822
  Returns:
1823
    On finding matching start: (index at matching start, None)
1824
    On finding an unclosed expression: (-1, None)
1825
    Otherwise: (-1, new stack at beginning of this line)
1826
  """
1827
  i = endpos
1828
  while i >= 0:
1829
    char = line[i]
1830
    if char in ')]}':
1831
      # Found end of expression, push to expression stack
1832
      stack.append(char)
1833
    elif char == '>':
1834
      # Found potential end of template argument list.
1835
      #
1836
      # Ignore it if it's a "->" or ">=" or "operator>"
1837
      if (i > 0 and
1838
          (line[i - 1] == '-' or
1839
           Match(r'\s>=\s', line[i - 1:]) or
1840
           Search(r'\boperator\s*$', line[0:i]))):
1841
        i -= 1
1842
      else:
1843
        stack.append('>')
1844
    elif char == '<':
1845
      # Found potential start of template argument list
1846
      if i > 0 and line[i - 1] == '<':
1847
        # Left shift operator
1848
        i -= 1
1849
      else:
1850
        # If there is a matching '>', we can pop the expression stack.
1851
        # Otherwise, ignore this '<' since it must be an operator.
1852
        if stack and stack[-1] == '>':
1853
          stack.pop()
1854
          if not stack:
1855
            return (i, None)
1856
    elif char in '([{':
1857
      # Found start of expression.
1858
      #
1859
      # If there are any unmatched '>' on the stack, they must be
1860
      # operators.  Remove those.
1861
      while stack and stack[-1] == '>':
1862
        stack.pop()
1863
      if not stack:
1864
        return (-1, None)
1865
      if ((char == '(' and stack[-1] == ')') or
1866
          (char == '[' and stack[-1] == ']') or
1867
          (char == '{' and stack[-1] == '}')):
1868
        stack.pop()
1869
        if not stack:
1870
          return (i, None)
1871
      else:
1872
        # Mismatched parentheses
1873
        return (-1, None)
1874
    elif char == ';':
1875
      # Found something that look like end of statements.  If we are currently
1876
      # expecting a '<', the matching '>' must have been an operator, since
1877
      # template argument list should not contain statements.
1878
      while stack and stack[-1] == '>':
1879
        stack.pop()
1880
      if not stack:
1881
        return (-1, None)
1882
1883
    i -= 1
1884
1885
  return (-1, stack)
1886
1887
1888
def ReverseCloseExpression(clean_lines, linenum, pos):

core/build-support/cpplint.py 1 location

@@ 1811-1885 (lines=75) @@
1808
  return (line, clean_lines.NumLines(), -1)
1809
1810
1811
def FindStartOfExpressionInLine(line, endpos, stack):
1812
  """Find position at the matching start of current expression.
1813
1814
  This is almost the reverse of FindEndOfExpressionInLine, but note
1815
  that the input position and returned position differs by 1.
1816
1817
  Args:
1818
    line: a CleansedLines line.
1819
    endpos: start searching at this position.
1820
    stack: nesting stack at endpos.
1821
1822
  Returns:
1823
    On finding matching start: (index at matching start, None)
1824
    On finding an unclosed expression: (-1, None)
1825
    Otherwise: (-1, new stack at beginning of this line)
1826
  """
1827
  i = endpos
1828
  while i >= 0:
1829
    char = line[i]
1830
    if char in ')]}':
1831
      # Found end of expression, push to expression stack
1832
      stack.append(char)
1833
    elif char == '>':
1834
      # Found potential end of template argument list.
1835
      #
1836
      # Ignore it if it's a "->" or ">=" or "operator>"
1837
      if (i > 0 and
1838
          (line[i - 1] == '-' or
1839
           Match(r'\s>=\s', line[i - 1:]) or
1840
           Search(r'\boperator\s*$', line[0:i]))):
1841
        i -= 1
1842
      else:
1843
        stack.append('>')
1844
    elif char == '<':
1845
      # Found potential start of template argument list
1846
      if i > 0 and line[i - 1] == '<':
1847
        # Left shift operator
1848
        i -= 1
1849
      else:
1850
        # If there is a matching '>', we can pop the expression stack.
1851
        # Otherwise, ignore this '<' since it must be an operator.
1852
        if stack and stack[-1] == '>':
1853
          stack.pop()
1854
          if not stack:
1855
            return (i, None)
1856
    elif char in '([{':
1857
      # Found start of expression.
1858
      #
1859
      # If there are any unmatched '>' on the stack, they must be
1860
      # operators.  Remove those.
1861
      while stack and stack[-1] == '>':
1862
        stack.pop()
1863
      if not stack:
1864
        return (-1, None)
1865
      if ((char == '(' and stack[-1] == ')') or
1866
          (char == '[' and stack[-1] == ']') or
1867
          (char == '{' and stack[-1] == '}')):
1868
        stack.pop()
1869
        if not stack:
1870
          return (i, None)
1871
      else:
1872
        # Mismatched parentheses
1873
        return (-1, None)
1874
    elif char == ';':
1875
      # Found something that look like end of statements.  If we are currently
1876
      # expecting a '<', the matching '>' must have been an operator, since
1877
      # template argument list should not contain statements.
1878
      while stack and stack[-1] == '>':
1879
        stack.pop()
1880
      if not stack:
1881
        return (-1, None)
1882
1883
    i -= 1
1884
1885
  return (-1, stack)
1886
1887
1888
def ReverseCloseExpression(clean_lines, linenum, pos):