parameters: (search_path: Path)
return_statement: return num_errors
docstring: Checks for missing constexpr tags, returns the number of tags found that should be changed
docstring_summary: Checks for missing constexpr tags, returns the number of tags found that should be changed
docstring_tokens: Checks for missing constexpr tags returns the number of tags found that should be changed
function: def constexpr_check(search_path: Path) -> int:
      """Checks for missing constexpr tags, returns the number of tags found that should be changed"""
      num_errors = 0
  
      files_to_search = []
      for p in [search_path]:
          for root, dirs, files in os.walk(p):
              for file in files:
                  f_path = Path(root) / Path(file)
                  f_extension = f_path.suffix
                  if f_extension == ".hh":
                      files_to_search.append(f_path)
                  elif f_extension == ".cc":
                      files_to_search.append(f_path)
  
      files_to_search.sort()
  
      for file in files_to_search:
          with open(file, "r") as f:
              lines = f.readlines()
  
          lines = [x.strip() for x in lines]
  
          bracket_count = 0
  
          for idx, line in enumerate(lines):
  
              # skip blank lines
              if line == "":
                  continue
  
              # skip comment lines
              if line[0:2] == "//":
                  continue
  
              # strip trailing comments
              if "//" in line:
                  tokens = line.split("//")
                  line = tokens[0].strip()
  
              re_match_1 = re.match(const_num_pattern, line)
              re_match_2 = re.match(array_const_pattern, line)
              re_match_3 = re.match(array_us_const_pattern, line)
              if (re_match_1 or re_match_2 or re_match_3) and bracket_count == 0:
                  print("ERROR: 'const' found, convert to 'constexpr'")
                  s = f"{file.name}: {idx + 1} - {line}"
                  print(s)
                  num_errors += 1
  
              # count brackets in line
              bracket_count += line.count("(")
              bracket_count -= line.count(")")
  
      return num_errors
function_tokens: def constexpr_check ( search_path : Path ) -> int : num_errors = 0 files_to_search = [ ] for p in [ search_path ] : for root , dirs , files in os . walk ( p ) : for file in files : f_path = Path ( root ) / Path ( file ) f_extension = f_path . suffix if f_extension == ".hh" : files_to_search . append ( f_path ) elif f_extension == ".cc" : files_to_search . append ( f_path ) files_to_search . sort ( ) for file in files_to_search : with open ( file , "r" ) as f : lines = f . readlines ( ) lines = [ x . strip ( ) for x in lines ] bracket_count = 0 for idx , line in enumerate ( lines ) : # skip blank lines if line == "" : continue # skip comment lines if line [ 0 : 2 ] == "//" : continue # strip trailing comments if "//" in line : tokens = line . split ( "//" ) line = tokens [ 0 ] . strip ( ) re_match_1 = re . match ( const_num_pattern , line ) re_match_2 = re . match ( array_const_pattern , line ) re_match_3 = re . match ( array_us_const_pattern , line ) if ( re_match_1 or re_match_2 or re_match_3 ) and bracket_count == 0 : print ( "ERROR: 'const' found, convert to 'constexpr'" ) s = f"{file.name}: {idx + 1} - {line}" print ( s ) num_errors += 1 # count brackets in line bracket_count += line . count ( "(" ) bracket_count -= line . count ( ")" ) return num_errors