Lines Matching defs:for

54 import math  # for log
90 Style checker for C/C++ source files.
98 This will miss some errors, and is not a substitute for a code review.
113 compatible output (vs7) may also be used. Further support exists for
150 is provided for each category like 'build/class'.
154 guard CPP variable. By default, this is determined by searching for a
177 The root directory used for deriving header guard CPP variable.
179 which by default is determined by searching for a directory that contains
185 cwd=top/src), the header guard CPP variables for
194 This is the allowed line length for the project. The default value is
201 Search for files to lint recursively. Each directory given in the list
254 upwards looking for more .cfg files in parent directories. This option
265 "linelength" allows to specify the allowed line length for the project.
362 # keywords to use with --outputs which generate stdout for machine processing
369 # These error categories are no longer enforced by cpplint, but for backwards-
382 # The default list of categories suppressed for C (not C++) files.
387 # The default list of categories suppressed for Linux Kernel files.
392 # We used to check for high-bit characters, but after much discussion we
516 # 17.6.1.2 C++ headers for C library facilities
703 # glibc for linux
742 # uppercase character, such as Python.h or nsStringAPI.h, for example).
747 # Pattern for matching FileInfo.BaseName() against test file name
762 # Replacement macros for CHECK/DCHECK/EXPECT_TRUE/EXPECT_FALSE
763 _CHECK_REPLACEMENT = dict([(macro_var, {}) for macro_var in _CHECK_MACROS])
765 for op, replacement in [('==', 'EQ'), ('!=', 'NE'),
773 for op, inv_replacement in [('==', 'NE'), ('!=', 'EQ'),
802 # but those have always been troublesome for cpplint.
807 # These constants define types of headers for use with
834 # Commands for sed to fix the problem
839 'Remove space before ( in for (': r's/for (/for(/',
856 # The root directory used for deriving header guard CPP variable.
912 # category should be suppressed for every line.
918 _hpp_headers = {ext.strip() for ext in val.split(',')}
938 return {h for h in _valid_extensions if 'h' in h}
941 # The allowed extensions for file names
950 extensions = [ext.strip() for ext in val.split(',')]
954 'for example: extensions=hpp,cpp\n'
1001 for line in lines:
1003 for category in _DEFAULT_C_SUPPRESSED_CATEGORIES:
1006 for category in _DEFAULT_KERNEL_SUPPRESSED_CATEGORIES:
1036 # The regexp compilation caching is inlined in both Match and Search for
1063 """Searches the string for the pattern, caching the compiled regexp."""
1075 """Tracks line numbers for includes, and the order in which includes appear.
1081 Call CheckNextIncludeOrder() once for each header in the file, passing
1127 for section_list in self.include_list:
1128 for f in section_list:
1134 """Reset section checking for preprocessor directive.
1155 """Returns a path canonicalized for alphabetical comparison.
1270 # "gsed" - like sed, but names the command gsed, e.g. for macOS homebrew users
1279 """Sets the output format for errors."""
1318 for filt in filters.split(','):
1322 for filt in self.filters:
1352 for category, count in sorted(iteritems(self.errors_by_category)):
1360 # Hide infos from stdout to keep stdout pure for machine consumption
1398 for failure in self._junit_failures:
1404 # Create a testcase for each file
1405 for failed_file in failed_file_order:
1411 texts = [template.format(f[1], f[2], f[3], f[4]) for f in failures]
1494 _NORMAL_TRIGGER = 250 # for --v=0, 500 for --v=1, etc.
1556 """Provides utility functions for filenames.
1600 # up the directory tree for the top of the SVN checkout
1673 for one_filter in _Filters():
1681 assert False # should have been checked for in SetFilter.
1705 confidence: A number from 1-5 representing a confidence score for
1792 for line in raw_lines:
1794 # Inside a raw string, look for the end
1797 # Found the end of the string, match leading space for this
1807 # Look for beginning of a raw string, and replace them with
1811 # Look for beginning of a raw string.
1812 # See 2.14.15 [lex.string] for syntax.
1842 # emit a warning for unterminated string.
1847 """Find the beginning marker for a multiline comment."""
1867 """Clears a range of lines for multi-line comments."""
1870 for i in range(begin, end):
1924 for linenum in range(len(self.lines_without_raw_strings)):
1980 # There is no special handling for floating point here, because
2015 for i in xrange(startpos, len(line)):
2244 for line in xrange(1, min(len(lines), 11)):
2346 # adapt slashes for windows
2381 # Don't check for header guards if there are error suppression
2384 # Because this is silencing a warning for a nonexistent line, we
2388 for i in raw_lines:
2393 for i in raw_lines:
2404 for linenum, line in enumerate(raw_lines):
2426 # for backward compatibility.
2437 # Check for "//" comments on endif line.
2443 # Issue low severity warning for deprecated double trailing underscore
2450 # only wants "/**/" comments, look for those instead.
2452 for i in xrange(1, len(raw_lines) - 1):
2462 # Low severity warning for double trailing underscore
2480 for ext in GetHeaderExtensions():
2488 for section_list in include_state.include_list:
2489 for f in section_list:
2506 """Logs an error for each line containing bad characters.
2512 it shouldn't). Note that it's possible for this to throw off line
2515 2. NUL bytes. These are problematic for some tools.
2522 for linenum, line in enumerate(lines):
2551 /* ... */ comments are legit inside macros, for one line.
2553 other. Likewise, it's ok for strings to extend across multiple
2617 """Checks for calls to thread-unsafe functions.
2632 for single_thread_func, multithread_safe_func, pattern in _THREADING_LIST:
2634 # function we are looking for
2639 '...) for improved thread safety.')
2643 """Checks that VLOG() is only used for defining a logging level.
2667 """Checks for invalid increment *count++.
2715 This is mostly for checking the text after the class identifier
2730 This is mostly used for checking end of namespace comments.
2743 This is convenient for verifying that an object is an instance of
2747 True for this class, False for derived classes.
2774 # Remember initial indentation level for this class. Using raw_lines here
2775 # instead of elided to account for leading comments.
2782 # But it's still good enough for CheckSectionSpacing.
2785 for i in range(linenum, clean_lines.NumLines()):
2793 # Look for a bare ':'
2801 for i in xrange(linenum - 1, self.starting_linenum, -1):
2841 # warning for missing namespace comments if there aren't enough
2855 # Look for matching comment at end of namespace.
2857 # Note that we accept C style "/* */" comments for terminating
2907 # Stack for tracking all braces. An object is pushed whenever we
2930 """Check if we have seen the opening brace for the innermost block.
3032 We make the following assumptions (good enough for most files):
3146 # Look for a class declaration in whatever is left of the line
3147 # after parsing namespaces. The regexp accounts for decorated classes
3163 # To avoid template argument cases, we scan forward and look for
3173 # If we have not yet seen the opening brace for the innermost block,
3228 # the stack for these.
3233 # Also pop these stack for these.
3249 for i in range(len(self.stack), 0, -1):
3265 # cpplint_unittest.py for an example of this.
3266 for obj in self.stack:
3292 Additionally, check for constructor/destructor style violations and reference
3293 members, as it is very convenient to do so while checking for
3306 # Remove comments from the line, but leave in strings for now.
3317 # Remove escaped backslashes before looking for undefined escapes.
3352 # attempt triggered 5 warnings for mostly benign code in the regtest, hence
3354 # Here's the original regexp, for the reference:
3372 # Look for single-argument constructors that aren't marked explicit.
3401 variadic_args = [arg for arg in constructor_args if '&&...' in arg]
3402 defaulted_args = [arg for arg in constructor_args if '=' in arg]
3443 """Checks for the correctness of various spacing around function calls.
3453 # Since function calls often occur inside if/for/while/switch
3455 # first see if we should be looking inside such an expression for a
3458 for pattern in (r'\bif\s*\((.*)\)\s*{',
3464 fncall = match.group(1) # look inside the parens for function calls
3467 # Except in if/for/while/switch, there should never be space
3469 # for nested parens ( (a+b) + c ). Likewise, there should never be
3481 not Search(r'\b(if|elif|for|while|switch|return|new|delete|catch|sizeof)\b',
3487 if Search(r'\w\s*\(\s(?!\s*\\$)', fncall): # a ( used for a fn call
3499 # error, silence those for now by restricting them to highest verbosity.
3550 """Reports for long function bodies.
3588 for start_linenum in xrange(linenum, clean_lines.NumLines()):
3606 # No body for the function (or evidence of a non-function) was found.
3620 """Checks for common mistakes in comments.
3633 # Allow one space for new scopes, two spaces otherwise:
3642 # Checks for common mistakes in TODO comments.
3659 # Comparisons made explicit for correctness -- pylint: disable=g-explicit-bool-comparison
3674 """Checks for the correctness of various spacing issues in the code.
3676 Things we check for: spaces around operators, spaces after
3677 if/for/while/switch, no spaces around parens in function calls, two
3697 # Before nixing comments, check if the line is blank for no good
3703 # for this block:
3710 # Also skip blank line checks for 'extern "C"' blocks, which are formatted
3727 # the same line as the function name). We also check for the case where
3732 # We are looking for the opening column of initializer list, which
3741 # Search for the function arguments or an initializer list. We use a
3744 # or colon (for initializer lists) we assume that it is the last line of
3787 # You shouldn't have spaces before your brackets, except for C++11 attributes
3794 # In range-based for, we wanted spaces before and after the colon, but
3796 if (Search(r'for *\(.*[^:]:[^: ]', line) or
3797 Search(r'for *\(.*[^: ]:[^:]', line)):
3799 'Missing space around colon in range-based for loop')
3803 """Checks for horizontal spacing around operators.
3813 # Don't try to do spacing checks for operator methods. Do this by
3815 # preserving column position for all other characters.
3827 # Otherwise not. Note we only check for non-spaces on *both* sides;
3832 and not Search(r'\b(if|while|for) ', line)
3841 # though, so we punt on this one for now. TODO.
3846 # check non-include lines for spacing around < and >.
3859 # Look for < that is not surrounded by spaces. This is only
3871 # Look for > that is not surrounded by spaces. Similar to the
3893 # We allow no-spaces around >> for almost anything. This is because
3894 # C++11 allows ">>" to close nested templates, which accounts for
3898 # likely due to ">>" being used for right shifts, e.g.:
3914 'Extra space for operator %s' % match.group(1))
3918 """Checks for horizontal spacing around parentheses.
3928 # No spaces after an if, while, switch, or for
3929 match = Search(r' (if\(|for\(|while\(|switch\()', line)
3934 # For if/for/while/switch, the left and right parens should be
3938 # Exception: "for ( ; foo; bar)" and "for (foo; bar; )" are allowed.
3939 match = Search(r'\b(if|for|while|switch)\s*'
3956 """Checks for horizontal spacing near commas and semicolons.
3971 # for empty macro arguments.
3983 # except for few corner cases
4015 # declaration for what we are looking for.
4041 # there are probably no template things to check for this block
4045 # Look for typename in the specified range
4046 for i in xrange(first_line, last_line + 1, 1):
4055 """Checks for horizontal spacing near commas.
4068 # an initializer list, for instance), you should have spaces before your
4071 # this is an easy test. Except that braces used for initialization don't
4076 # Try a bit harder to check for brace initialization. This
4088 # We check for the character following the closing brace, and
4092 # To account for nested initializer list, we allow any number of
4095 # cause false negatives for things that are not initializer lists.
4110 for offset in xrange(endlinenum + 1,
4113 # We also suppress warnings for `uint64_t{expression}` etc., as the style
4114 # guide recommends brace initialization for integral types to avoid
4127 # There's a special case for "for" since the style guide allows space before
4161 """Checks for additional blank line issues related to sections.
4177 # Also skip checks if we are on the first line. This accounts for
4194 # private, but needed to be public for implementation reasons.
4202 # account for multi-line base-specifier lists, e.g.:
4206 for i in range(class_info.starting_linenum, linenum):
4239 """Looks for misplaced braces (e.g. at the end of line).
4254 # used for brace initializers inside function calls. We don't detect this
4302 # required for single-line statements'. We additionally allow multi-line,
4306 # lower than the if. We also check for ambiguous if/else nesting without
4317 # Check for an opening brace, either directly after the if or on the next
4329 # We allow a mix of whitespace and closing braces (e.g. for one-liner
4330 # methods) and a single \ after the semicolon (for macros)
4358 """Looks for redundant trailing semicolon.
4375 # for (;;) {};
4397 # Note that naively checking for the preceding "{" will also match
4410 # to namespaces. For now we do not warn for this case.
4422 # But we still issue warnings for macros that we know are safe to
4432 # the downside for getting the allowed checks wrong means some extra
4433 # semicolons, while the downside for getting disallowed checks wrong
4472 # duplicate warnings for the blank line case:
4485 # Current {} pair is eligible for semicolon check, and we have found
4488 # Note: because we are scanning forward for opening braces, and
4489 # outputting warnings for the matching closing brace, if there are
4493 # We need to check the line forward for NOLINT
4505 """Look for empty loop/conditional body with only a single semicolon.
4514 # Search for loop keywords at the beginning of the line. Because only
4521 matched = Match(r'\s*(for|while|if)\s*\(', line)
4528 # No warning for all other cases, including whitespace or newline, since we
4529 # have a separate check for semicolons preceded by whitespace.
4538 # Check for if statements that have completely empty bodies (no comments)
4541 # Find the position of the opening { for the if statement.
4617 for macro in _CHECK_MACROS:
4663 for i in xrange(linenum + 1, end_line):
4668 # This avoids false positives for inputs like "CHECK((a < 4) == b)",
4688 # contains more than one term, for example:
4726 # to avoid suggesting replacements for unprintable things like
4767 # it provides a way to workaround this warning for people who use
4770 # TODO(unknown): remove this once cpplint has better support for
4775 for match in _ALT_TOKEN_REPLACEMENT_PATTERN.finditer(line):
4788 The width of the line in column positions, accounting for Unicode
4793 for uc in unicodedata.normalize('NFC', line):
4818 do what we can. In particular we check for 2-space indents, line lengths,
4844 # NOTE: here are the conditions rob pike used for his tests. Mine aren't
4852 # if(match(prev, " +for \\(")) complain = 0;
4853 # if(prevodd && match(prevprev, " +for \\(")) complain = 0;
4860 # There are certain situations we allow one space, notably for
4862 # We also don't check for lines that look like continuation lines
4864 # because the rules for how to indent those are non-trivial.
4911 # for loops are allowed two ;'s (and may run over two lines).
4912 cleansed_line.find('for') == -1 and
4913 (GetPreviousNonBlankLine(clean_lines, linenum)[0].find('for') == -1 or
4967 for suffix in itertools.chain(
4969 for test_suffix, ext in itertools.product(_test_suffixes, GetNonHeaderExtensions())),
4971 for suffix, ext in itertools.product(['inl', 'imp', 'internal'], GetHeaderExtensions()))):
5006 # those already checked for above.
5009 # Mark include as C header if in list or in a known folder for standard-ish C headers.
5075 # We also make an exception for Lua headers, which follow google
5098 for extension in GetNonHeaderExtensions():
5109 for ext in GetHeaderExtensions():
5121 # 1) for foo.cc, foo.h (preferred location)
5124 # 4) for foo.cc, foo.h (deprecated location)
5152 occurrences of the punctuations, so for the text like
5202 # Patterns for matching call-by-reference parameters.
5260 # to silence warnings for conditional includes.
5274 # (handled in CheckForNonStandardConstructs for now)
5280 # we regularly allow is "unsigned short port" for port.
5284 'Use "unsigned short" for ports, not "short"')
5301 # Check for suspicious usage of "if" like
5305 'Did you mean "else if"? If not, start a new line for "if".')
5307 # Check for potential format string bugs like printf(foo).
5324 # Check for potential memset bugs like memset(buf, sizeof(buf), 0).
5351 for tok in tokens:
5367 # A catch all for tricky sizeof cases, including 'sizeof expression',
5378 "('k' followed by CamelCase) compile-time constant for the size.")
5380 # Check for use of unnamed namespaces in header files. Registration
5389 ' for more information.')
5393 """Check for unsafe global or static objects.
5407 # Check for people declaring static/global STL strings at the top level.
5412 # TODO(unknown): File bugs for clang-tidy to find these.
5454 """Check for printf related issues.
5492 # Scan back a few lines for start of current function
5493 for i in xrange(linenum, max(-1, linenum - 10), -1):
5496 # Look for "override" after the matching closing parenthesis
5513 # Scan back a few lines for start of current function
5514 for i in xrange(linenum, max(-1, linenum - 10), -1):
5530 for i in xrange(linenum, 1, -1):
5564 """Check for non-const references.
5622 # Check for templated parameter that is split across multiple lines
5631 for i in xrange(startline, linenum + 1):
5634 # Check for non-const references in function parameters. A single '&' may
5636 # inside expression: binary & for bitwise AND
5637 # inside expression: unary & for taking the address of something
5641 # TODO(unknown): Doesn't account for 'catch(Exception& e)' [rare].
5649 # current line for something that starts with ':'.
5655 for i in xrange(linenum - 1, max(0, linenum - 10), -1):
5686 for i in xrange(2):
5692 for parameter in re.findall(_RE_PATTERN_REF_PARAM, decls):
5738 # Avoid arrays by looking for brackets that come after the closing
5773 # Check pointer casts for other than string constants
5777 # In addition, we look for people taking the address of a cast. This
5781 # Some non-identifier character is required before the '&' for the
5821 """Checks for a C-style cast by looking for the pattern.
5827 cast_type: The string for the C++ cast to recommend. This is either
5849 for i in xrange(linenum - 1, max(0, linenum - 5), -1):
5858 # A single unnamed argument for a function tends to look like old style cast.
5859 # If we see those, don't issue warnings for deprecated casts.
5946 for _header, _templates in _HEADERS_MAYBE_TEMPLATES:
5947 for _template in _templates:
5967 for _header, _templates in _HEADERS_CONTAINING_TEMPLATES:
5968 for _template in _templates:
5984 If the filename_cc contains a longer path than the filename_h, for example,
5996 filename_cc: is the path for the source (e.g. .cc) file
5997 filename_h: is the path for the header path
6039 io: The io factory to use to read the file. Provided for testability.
6048 for line in headerfile:
6063 """Reports for missing stl includes.
6066 necessary for the stl containers and functions that you use. We only give one
6076 io: The IO factory to use to read the header file. Provided for unittest
6082 for linenum in xrange(clean_lines.NumLines()):
6096 for pattern, template, header in _re_pattern_headers_maybe_templates:
6104 for pattern, template, header in _re_pattern_templates:
6116 include_dict = dict([item for sublist in include_state.include_list
6117 for item in sublist])
6119 # Did we find the header for this file (if any) and successfully load it?
6130 # e.g. If the file name is 'foo_flymake.cc', we should search for 'foo.h'
6137 for header in header_keys:
6143 # If we can't find the header file for a .cc, assume it's because we don't
6149 for extension in GetNonHeaderExtensions():
6154 for required_header_unstripped in sorted(required, key=required.__getitem__):
6159 'Add #include ' + required_header_unstripped + ' for ' + template)
6195 # Look for "virtual" on current line.
6212 # Look for the next opening parenthesis. This is the start of the
6220 for start_line in xrange(linenum, min(linenum + 3, clean_lines.NumLines())):
6233 # Look for "override" or "final" after the parameter list
6235 for i in xrange(end_line, min(end_line + 3, clean_lines.NumLines())):
6259 # Look for closing parenthesis nearby. We need one to confirm where
6316 only works for classes and namespaces inside of a namespace.
6385 for check_fn in extra_check_functions:
6428 for top_name in (
6491 for line in xrange(clean_lines.NumLines()):
6535 for line in file_handle:
6550 # For example, if we are checking for lint errors in /foo/bar/baz.cc
6588 "Skipping config file '%s': Can't open for reading\n" % cfg_file)
6593 for cfg_filter in reversed(cfg_filters):
6624 # Support the UNIX convention of using "-" for stdin. Note that
6641 # The -1 accounts for the extra trailing blank line we get from split()
6642 for linenum in range(len(lines) - 1):
6651 "Skipping input '%s': Can't open for reading\n" % filename)
6681 for linenum in crlf_lines:
6719 sys.stderr.write(''.join(' %s\n' % cat for cat in _ERROR_CATEGORIES))
6759 for (opt, val) in opts:
6838 for filename in filenames:
6843 for root, _, files in os.walk(filename):
6844 for loopfile in files:
6851 for filename in expanded:
6860 exclude_paths = [os.path.abspath(f) for f in _excludes]
6862 return [f for f in fnames
6863 if not any(e for e in exclude_paths
6893 for filename in filenames: