Check for non-const references. Separate from CheckLanguage since it scans backwards from current line, instead of scanning forward. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check.
(filename, clean_lines, linenum,
nesting_state, error)
| 4933 | |
| 4934 | |
| 4935 | def CheckForNonConstReference(filename, clean_lines, linenum, |
| 4936 | nesting_state, error): |
| 4937 | """Check for non-const references. |
| 4938 | |
| 4939 | Separate from CheckLanguage since it scans backwards from current |
| 4940 | line, instead of scanning forward. |
| 4941 | |
| 4942 | Args: |
| 4943 | filename: The name of the current file. |
| 4944 | clean_lines: A CleansedLines instance containing the file. |
| 4945 | linenum: The number of the line to check. |
| 4946 | nesting_state: A NestingState instance which maintains information about |
| 4947 | the current stack of nested blocks being parsed. |
| 4948 | error: The function to call with any errors found. |
| 4949 | """ |
| 4950 | # Do nothing if there is no '&' on current line. |
| 4951 | line = clean_lines.elided[linenum] |
| 4952 | if '&' not in line: |
| 4953 | return |
| 4954 | |
| 4955 | # If a function is inherited, current function doesn't have much of |
| 4956 | # a choice, so any non-const references should not be blamed on |
| 4957 | # derived function. |
| 4958 | if IsDerivedFunction(clean_lines, linenum): |
| 4959 | return |
| 4960 | |
| 4961 | # Don't warn on out-of-line method definitions, as we would warn on the |
| 4962 | # in-line declaration, if it isn't marked with 'override'. |
| 4963 | if IsOutOfLineMethodDefinition(clean_lines, linenum): |
| 4964 | return |
| 4965 | |
| 4966 | # Long type names may be broken across multiple lines, usually in one |
| 4967 | # of these forms: |
| 4968 | # LongType |
| 4969 | # ::LongTypeContinued &identifier |
| 4970 | # LongType:: |
| 4971 | # LongTypeContinued &identifier |
| 4972 | # LongType< |
| 4973 | # ...>::LongTypeContinued &identifier |
| 4974 | # |
| 4975 | # If we detected a type split across two lines, join the previous |
| 4976 | # line to current line so that we can match const references |
| 4977 | # accordingly. |
| 4978 | # |
| 4979 | # Note that this only scans back one line, since scanning back |
| 4980 | # arbitrary number of lines would be expensive. If you have a type |
| 4981 | # that spans more than 2 lines, please use a typedef. |
| 4982 | if linenum > 1: |
| 4983 | previous = None |
| 4984 | if Match(r'\s*::(?:[\w<>]|::)+\s*&\s*\S', line): |
| 4985 | # previous_line\n + ::current_line |
| 4986 | previous = Search(r'\b((?:const\s*)?(?:[\w<>]|::)+[\w<>])\s*$', |
| 4987 | clean_lines.elided[linenum - 1]) |
| 4988 | elif Match(r'\s*[a-zA-Z_]([\w<>]|::)+\s*&\s*\S', line): |
| 4989 | # previous_line::\n + current_line |
| 4990 | previous = Search(r'\b((?:const\s*)?(?:[\w<>]|::)+::)\s*$', |
| 4991 | clean_lines.elided[linenum - 1]) |
| 4992 | if previous: |
no test coverage detected