const target = "__flow_start"

const MUST_USE = 0
const CORRECT = 1
const REQUEST = 2
function err(msg, line) {
    graph("/tmp/error.dot")
    error(msg + ". See /tmp/error.dot")
}

function uno_check(vars, state, line) {
  /* can't do this one since it's not func local
  if(select("", [PARAM_OF("JS_BeginRequest")])) {
    print("JS_BeginRequest checking enabled")
    mark(REQUEST)
  } else if(select("", [PARAM_OF("JS_EndRequest")])) {
      if(match(REQUEST)) {
        print("JS_EndRequest matches")
        unmark(REQUEST)
        mark(CORRECT)
      } else {
        err("JS_EndRequest without JS_BeginRequest");
      }
  }*/
  
  if(select(target, [DECL], [DEF])) {
    print("Control checking enabled");
    mark(MUST_USE)
  }
  if(select(target, [DECL, DEF])) {
    if(match(MUST_USE)) {
      unmark(MUST_USE)
      mark(CORRECT)
    }
//     else
//        err("Flow stops but doesn't start")
  }
  if(_state) {
    setBlockColor("SkyBlue")
  }
}

function path_end() {
  if(marked(MUST_USE) || marked(REQUEST)) {
    err("Control does not flow as expected")
  } else if (marked(CORRECT)){
    graph("/tmp/prettyness.dot");
  }
}

/*
12:59 < crowder> taras: Might be interesting just to grep for things that contain JS_BeginRequest, too, and see if they do EndRequest in all
                 control-flows
1
make CC="gcc -DFLOW_START='{int __flow_start;}' -DFLOW_STOP='{int __flow_start=1;}'"
jsarray.c:1125:
jsexn.c:1178:
jsfun.c:1269:  <-- can't parse
jsinterp.c:1249: <-- same
jsinterp.c:4787:
jsinterp.c:4976:
jsinterp.c:5058:
jsobj.c:562:
jsopcode.c:2318:
jsxml.c:2741:
jsxml.c:5398:
jsxml.c:6453:
*/