def parseSource(source):
  """
  Parses the given source string and adds all found functions
  to the library.
    
  @param header:    Source text
    
  @returns: A library containing the parsed functions
  """
  task    = Task.startTask("parser", "Parsing type declarations", len(source))
  library = Library()

  # Read the type definitions
  typedefs = []
  for match, pos, l in typedefDecl.scanString(source):
    task.updateProgress(pos)
    # Map enumerations to integers
    if match[0] == "enum":
      name = match[-1]
      type = Type("int")
      for i, e in enumerate(match[1]):
        enumeration, value = e
        if value is None:
          value = i
        type.addSymbolicConstant(enumeration, value)
        library.constants[enumeration] = value
    else:
      name, type = match[0]
    library.typeDefs[Type(name)] = type
  task.finish()

  # Read preprocessor constants
  task = Task.startTask("parser", "Parsing preprocessor constants", len(source))
  for match, pos, l in preprocessorCommand.scanString(source):
    task.updateProgress(pos)
    # Only look for #define
    if match.command != "define":
      continue
    
    # Only accept integral constants
    try:
      value = parseInteger(None, None, [match.value])
    except __HOLE__:
      continue
    
    library.constants[match.name] = value
  task.finish()

  def where(pos):
    return "Line %d, column %s" % (lineno(pos, source), col(pos, source))
  
  task = Task.startTask("parser", "Parsing functions", len(source))
  for match, pos, l in function.scanString(source):
    task.updateProgress(pos)
    name, type = match.name[0]
    if not name: continue
    f = Function(name, type)
    f.language = "c"
    for name, type in match.args:
      if not name or not type:
        continue
      f.parameters[name] = Parameter(name, type)

    # Grab the code if any
    if match.body:
      f.body = match.body

    library.functions[f.name] = f
  task.finish()
  return library
dataset/ETHPy150Open skyostil/tracy/src/generator/Parser.py/parseSource