#!/bin/python
import sys
sys.path += ["/usr/lib64/gobject-introspection/"]

import giscanner
import giscanner.ast
import giscanner.girparser
import re

p = giscanner.girparser.GIRParser()
p.parse (sys.argv[1])


null_re = re.compile("([Rr]eturn|[Rr]eturns|[oO]r|[oO]therwise)[,]?\s*[%\#]?NULL")
nullor_re = re.compile("[%\#]?NULL\s*(or|if|otherwise)")

def function_handler (prefix, func):
  if func.deprecated:
    return

  if func.retval.doc:
    full_name = prefix+"."+func.name
    if func.retval.nullable == False:
      if null_re.search(func.retval.doc) or nullor_re.search(func.retval.doc):
        print (full_name)
        return

#        try:
#          print(str(func.retval.doc))
#        except:
#          print("ERROR PRINTING DOC")

ns = p.get_namespace()
for i in ns:
  element = ns.get(i)
  if element.deprecated:
    continue

  if isinstance(element, giscanner.ast.Callable):
    function_handler(ns.name, element)

  if isinstance(element, giscanner.ast.Class) or isinstance(element, giscanner.ast.Interface):
    allcallables = element.methods + element.virtual_methods + element.static_methods
    for m in allcallables:
      function_handler (ns.name + "." + element.name, m)
