parameters: (mpicc, includes)
docstring: Invokes mpicc's C preprocessor on a C file that includes mpi.h.
          Parses the output for declarations, and yields each declaration to
          the caller.
docstring_summary: Invokes mpicc's C preprocessor on a C file that includes mpi.h.
          Parses the output for declarations, and yields each declaration to
          the caller.
docstring_tokens: Invokes mpicc s C preprocessor on a C file that includes mpi . h . Parses the output for declarations and yields each declaration to the caller .
function: def enumerate_mpi_declarations(mpicc, includes):
      """ Invokes mpicc's C preprocessor on a C file that includes mpi.h.
          Parses the output for declarations, and yields each declaration to
          the caller.
      """
      # Create an input file that just includes <mpi.h>
      tmpfile = tempfile.NamedTemporaryFile('w+b', -1, '.c')
      tmpname = "%s" % tmpfile.name
      tmpfile.write('#include <mpi.h>')
      tmpfile.write("\n")
      tmpfile.flush()
  
      # Run the mpicc -E on the temp file and pipe the output
      # back to this process for parsing.
      string_includes = ["-I"+dir for dir in includes]
      mpicc_cmd = "%s -E %s" % (mpicc, " ".join(string_includes))
      try:
          popen = subprocess.Popen("%s %s" % (mpicc_cmd, tmpname), shell=True,
                                   stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      except IOError:
          sys.stderr.write("IOError: couldn't run '" + mpicc_cmd + "' for parsing mpi.h\n")
          sys.exit(1)
  
      # Parse out the declarations from the MPI file
      mpi_h = popen.stdout
      for line in mpi_h:
          line = line.strip()
          begin = begin_decl_re.search(line)
          if begin and not exclude_re.search(line):
              # Grab return type and fn name from initial parse
              return_type, fn_name = begin.groups()
  
              # Accumulate rest of declaration (possibly multi-line)
              while not end_decl_re.search(line):
                  line += " " + mpi_h.next().strip()
  
              # Split args up by commas so we can parse them independently
              fn_and_paren = r'(%s\s*\()' % fn_name
              match = re.search(fn_and_paren, line)
              lparen = match.start(1) + len(match.group(1)) - 1
              rparen = find_matching_paren(line, lparen)
              if rparen < 0:
                  raise ValueError("Malformed declaration in header: '%s'" % line)
  
              arg_string = line[lparen+1:rparen]
              arg_list = map(lambda s: s.strip(), arg_string.split(","))
  
              # Handle functions that take no args specially
              if arg_list == ['void']:
                  arg_list = []
  
              # Parse formal parameter descriptors out of args
              decl = Declaration(return_type, fn_name)
              arg_num = 0
              for arg in arg_list:
                  if arg == '...':   # Special case for Pcontrol.
                      decl.addArgument(Param(None, None, '...', None, arg_num))
                  else:
                      match = formal_re.match(arg)
                      if not match:
                          sys.stderr.write("MATCH FAILED FOR: '%s' in %s\n" % (arg, fn_name))
                          sys.exit(1)
  
                      type, pointers, name, array = match.groups()
                      types.add(type)
                      all_pointers.add(pointers)
                      # If there's no name, make one up.
                      if not name: name = "arg_" + str(arg_num)
  
                      decl.addArgument(Param(type.strip(), pointers, name, array, arg_num))
                  arg_num += 1
  
              yield decl
  
      mpi_h.close()
      return_code = popen.wait()
      if return_code != 0:
          sys.stderr.write("Error: Couldn't run '%s' for parsing mpi.h.\n" % mpicc_cmd)
          sys.stderr.write("       Process exited with code %d.\n" % return_code)
          sys.exit(1)
  
      # Do some cleanup once we're done reading.
      tmpfile.close()
function_tokens: def enumerate_mpi_declarations ( mpicc , includes ) : # Create an input file that just includes <mpi.h> tmpfile = tempfile . NamedTemporaryFile ( 'w+b' , - 1 , '.c' ) tmpname = "%s" % tmpfile . name tmpfile . write ( '#include <mpi.h>' ) tmpfile . write ( "\n" ) tmpfile . flush ( ) # Run the mpicc -E on the temp file and pipe the output # back to this process for parsing. string_includes = [ "-I" + dir for dir in includes ] mpicc_cmd = "%s -E %s" % ( mpicc , " " . join ( string_includes ) ) try : popen = subprocess . Popen ( "%s %s" % ( mpicc_cmd , tmpname ) , shell = True , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) except IOError : sys . stderr . write ( "IOError: couldn't run '" + mpicc_cmd + "' for parsing mpi.h\n" ) sys . exit ( 1 ) # Parse out the declarations from the MPI file mpi_h = popen . stdout for line in mpi_h : line = line . strip ( ) begin = begin_decl_re . search ( line ) if begin and not exclude_re . search ( line ) : # Grab return type and fn name from initial parse return_type , fn_name = begin . groups ( ) # Accumulate rest of declaration (possibly multi-line) while not end_decl_re . search ( line ) : line += " " + mpi_h . next ( ) . strip ( ) # Split args up by commas so we can parse them independently fn_and_paren = r'(%s\s*\()' % fn_name match = re . search ( fn_and_paren , line ) lparen = match . start ( 1 ) + len ( match . group ( 1 ) ) - 1 rparen = find_matching_paren ( line , lparen ) if rparen < 0 : raise ValueError ( "Malformed declaration in header: '%s'" % line ) arg_string = line [ lparen + 1 : rparen ] arg_list = map ( lambda s : s . strip ( ) , arg_string . split ( "," ) ) # Handle functions that take no args specially if arg_list == [ 'void' ] : arg_list = [ ] # Parse formal parameter descriptors out of args decl = Declaration ( return_type , fn_name ) arg_num = 0 for arg in arg_list : if arg == '...' : # Special case for Pcontrol. decl . addArgument ( Param ( None , None , '...' , None , arg_num ) ) else : match = formal_re . match ( arg ) if not match : sys . stderr . write ( "MATCH FAILED FOR: '%s' in %s\n" % ( arg , fn_name ) ) sys . exit ( 1 ) type , pointers , name , array = match . groups ( ) types . add ( type ) all_pointers . add ( pointers ) # If there's no name, make one up. if not name : name = "arg_" + str ( arg_num ) decl . addArgument ( Param ( type . strip ( ) , pointers , name , array , arg_num ) ) arg_num += 1 yield decl mpi_h . close ( ) return_code = popen . wait ( ) if return_code != 0 : sys . stderr . write ( "Error: Couldn't run '%s' for parsing mpi.h.\n" % mpicc_cmd ) sys . stderr . write ( "       Process exited with code %d.\n" % return_code ) sys . exit ( 1 ) # Do some cleanup once we're done reading. tmpfile . close ( )