35
35
import math # for log
36
36
import os
37
37
import re
38
- import sre_compile
39
38
import string
40
39
import sys
41
40
import sysconfig
@@ -1028,7 +1027,7 @@ def Match(pattern, s):
1028
1027
# performance reasons; factoring it out into a separate function turns out
1029
1028
# to be noticeably expensive.
1030
1029
if pattern not in _regexp_compile_cache :
1031
- _regexp_compile_cache [pattern ] = sre_compile .compile (pattern )
1030
+ _regexp_compile_cache [pattern ] = re .compile (pattern )
1032
1031
return _regexp_compile_cache [pattern ].match (s )
1033
1032
1034
1033
@@ -1046,14 +1045,14 @@ def ReplaceAll(pattern, rep, s):
1046
1045
string with replacements made (or original string if no replacements)
1047
1046
"""
1048
1047
if pattern not in _regexp_compile_cache :
1049
- _regexp_compile_cache [pattern ] = sre_compile .compile (pattern )
1048
+ _regexp_compile_cache [pattern ] = re .compile (pattern )
1050
1049
return _regexp_compile_cache [pattern ].sub (rep , s )
1051
1050
1052
1051
1053
1052
def Search (pattern , s ):
1054
1053
"""Searches the string for the pattern, caching the compiled regexp."""
1055
1054
if pattern not in _regexp_compile_cache :
1056
- _regexp_compile_cache [pattern ] = sre_compile .compile (pattern )
1055
+ _regexp_compile_cache [pattern ] = re .compile (pattern )
1057
1056
return _regexp_compile_cache [pattern ].search (s )
1058
1057
1059
1058
@@ -5356,15 +5355,10 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
5356
5355
'Did you mean "memset(%s, 0, %s)"?'
5357
5356
% (match .group (1 ), match .group (2 )))
5358
5357
5359
- if Search (r'\busing namespace\b' , line ):
5360
- if Search (r'\bliterals\b' , line ):
5361
- error (filename , linenum , 'build/namespaces_literals' , 5 ,
5362
- 'Do not use namespace using-directives. '
5363
- 'Use using-declarations instead.' )
5364
- else :
5365
- error (filename , linenum , 'build/namespaces' , 5 ,
5366
- 'Do not use namespace using-directives. '
5367
- 'Use using-declarations instead.' )
5358
+ if Search (r'\busing namespace\b' , line ) and not Search (r'\b::\w+_literals\b' , line ):
5359
+ error (filename , linenum , 'build/namespaces' , 5 ,
5360
+ 'Do not use namespace using-directives. '
5361
+ 'Use using-declarations instead.' )
5368
5362
5369
5363
# Detect variable-length arrays.
5370
5364
match = Match (r'\s*(.+::)?(\w+) [a-z]\w*\[(.+)];' , line )
@@ -6320,87 +6314,6 @@ def ProcessLine(filename, file_extension, clean_lines, line,
6320
6314
for check_fn in extra_check_functions :
6321
6315
check_fn (filename , clean_lines , line , error )
6322
6316
6323
- def FlagCxx11Features (filename , clean_lines , linenum , error ):
6324
- """Flag those c++11 features that we only allow in certain places.
6325
-
6326
- Args:
6327
- filename: The name of the current file.
6328
- clean_lines: A CleansedLines instance containing the file.
6329
- linenum: The number of the line to check.
6330
- error: The function to call with any errors found.
6331
- """
6332
- line = clean_lines .elided [linenum ]
6333
-
6334
- include = Match (r'\s*#\s*include\s+[<"]([^<"]+)[">]' , line )
6335
-
6336
- # Flag unapproved C++ TR1 headers.
6337
- if include and include .group (1 ).startswith ('tr1/' ):
6338
- error (filename , linenum , 'build/c++tr1' , 5 ,
6339
- ('C++ TR1 headers such as <%s> are unapproved.' ) % include .group (1 ))
6340
-
6341
- # Flag unapproved C++11 headers.
6342
- if include and include .group (1 ) in ('cfenv' ,
6343
- 'condition_variable' ,
6344
- 'fenv.h' ,
6345
- 'future' ,
6346
- 'mutex' ,
6347
- 'thread' ,
6348
- 'chrono' ,
6349
- 'ratio' ,
6350
- 'regex' ,
6351
- 'system_error' ,
6352
- ):
6353
- error (filename , linenum , 'build/c++11' , 5 ,
6354
- ('<%s> is an unapproved C++11 header.' ) % include .group (1 ))
6355
-
6356
- # The only place where we need to worry about C++11 keywords and library
6357
- # features in preprocessor directives is in macro definitions.
6358
- if Match (r'\s*#' , line ) and not Match (r'\s*#\s*define\b' , line ): return
6359
-
6360
- # These are classes and free functions. The classes are always
6361
- # mentioned as std::*, but we only catch the free functions if
6362
- # they're not found by ADL. They're alphabetical by header.
6363
- for top_name in (
6364
- # type_traits
6365
- 'alignment_of' ,
6366
- 'aligned_union' ,
6367
- ):
6368
- if Search (r'\bstd::%s\b' % top_name , line ):
6369
- error (filename , linenum , 'build/c++11' , 5 ,
6370
- ('std::%s is an unapproved C++11 class or function. Send c-style '
6371
- 'an example of where it would make your code more readable, and '
6372
- 'they may let you use it.' ) % top_name )
6373
-
6374
-
6375
- def FlagCxx14Features (filename , clean_lines , linenum , error ):
6376
- """Flag those C++14 features that we restrict.
6377
-
6378
- Args:
6379
- filename: The name of the current file.
6380
- clean_lines: A CleansedLines instance containing the file.
6381
- linenum: The number of the line to check.
6382
- error: The function to call with any errors found.
6383
- """
6384
- line = clean_lines .elided [linenum ]
6385
-
6386
- include = Match (r'\s*#\s*include\s+[<"]([^<"]+)[">]' , line )
6387
-
6388
- # Flag unapproved C++14 headers.
6389
- if include and include .group (1 ) in ('scoped_allocator' , 'shared_mutex' ):
6390
- error (filename , linenum , 'build/c++14' , 5 ,
6391
- ('<%s> is an unapproved C++14 header.' ) % include .group (1 ))
6392
-
6393
- # These are classes and free functions with abseil equivalents.
6394
- for top_name in (
6395
- # memory
6396
- 'make_unique' ,
6397
- ):
6398
- if Search (r'\bstd::%s\b' % top_name , line ):
6399
- error (filename , linenum , 'build/c++14' , 5 ,
6400
- 'std::%s does not exist in C++11. Use absl::%s instead.' %
6401
- (top_name , top_name ))
6402
-
6403
-
6404
6317
def ProcessFileData (filename , file_extension , lines , error ,
6405
6318
extra_check_functions = None ):
6406
6319
"""Performs lint checks and reports any errors to the given error function.
@@ -6437,8 +6350,6 @@ def ProcessFileData(filename, file_extension, lines, error,
6437
6350
ProcessLine (filename , file_extension , clean_lines , line ,
6438
6351
include_state , function_state , nesting_state , error ,
6439
6352
extra_check_functions )
6440
- FlagCxx11Features (filename , clean_lines , line , error )
6441
- FlagCxx14Features (filename , clean_lines , line , error )
6442
6353
nesting_state .CheckCompletedBlocks (filename , error )
6443
6354
6444
6355
CheckForIncludeWhatYouUse (filename , clean_lines , include_state , error )
0 commit comments