package { import eu.fittest.Logging.* ; /** * Several functions implementing GCD, just for example. This * class contains some manual logging statements. They use * the fittest-logging library. */ public class GCDLogged { /** * To hold a single instance of logger. */ public static var logger : ByteArrayLogger ; public static function getLogger() : ByteArrayLogger { if (logger==null) { var minloggingLevel : int = 3 ; logger = new ByteArrayLogger(minloggingLevel) ; logger.resume() ; } return logger ; } public static function recGcd (x:int,y:int) : int { getLogger().logLFunEntry(4,"recGcd","GCDLogged",null,x,y) ; var r : int ; if (x == y) { // using some dummy block-ids... getLogger().logLBlock(3,"1.T","recGcd","GCDLogged"); r = x; } else if (x>y) { getLogger().logLBlock(3,"1.ET","recGcd","GCDLogged"); r = recGcd(x-y,y); } else { getLogger().logLBlock(3,"1.EE","recGcd","GCDLogged"); r = recGcd(x,y-x); } getLogger().logLFunExit(4,"recGcd","GCDLogged",null,r) ; return r ; } public static function whileGcd (x:int,y:int) : int { getLogger().logLFunEntry(4,"whileGcd","GCDLogged",null,x,y) ; var iter_count:int = 0 while (x != y) { iter_count++; if (x > y) x = x - y; else y = y - x ; } getLogger().logLBlockLoopExit(3,"2","whileGcd","GCDLogged",iter_count); getLogger().logLFunExit(4,"whileGcd","GCDLogged",null,x) ; return x; } public static function catchGcd (x:int,y:int) : Object { getLogger().logLFunEntry(4,"catchGcd","GCDLogged",null,x,y) ; var r : int ; try { if (x<=0 || y<=0) throw new Error("oops") ; // injected crash else r = whileGcd(x,y) ; } catch (e:Error) { getLogger().logLBlockExceptionHandler(3,"2","catchGcd","GCDLogged",e) ; // trace("catchGcd, handling exception: " + e.getStackTrace()); var r2 : String = "check gcd args!" ; getLogger().logLFunExit(4,"catchGcd","GCDLogged",null,r2) ; return r2 ; } getLogger().logLFunExit(4,"catchGcd","GCDLogged",null,r) ; return r ; } } }