170 likes | 178 Views
This outline discusses the syntax and semantics of the Cflow language, focusing on composition, logical operations, and the impact of Cflow on the program flow. It covers topics such as type-scoped Cflow, formal proof/semantics, compilation, and translation. It also includes discussions on modifying formal things, the compiling process, and the reduction of guarded advice.
E N D
Outline • Syntax for cflow and cflowbelow • Composition, logical operations • Type-scoped cflow • Impact • Formal proof/semantics • Compilation • Translation • Lifting functions to monadic space • Discussion
Syntax (Basic) • n@advice around {k+cflow(f)} (arg) • And with “+” • n@advice around {k+cflowbelow(f)} • cflowbelow works better with “Not” • {k - cflowbelow(f)}
Syntax (Composition) • And-ing by concatenation • n@advice around {k+cflow(g)+cflow(h)} (arg) • Or-ing joinpoints by “,” • Only on top level • Like DNF (disjunctive normal form) • Can be treated like two different advices • {k+cflow(g), k+cflow(f)}
Syntax (Type-Scoped Cflow) • Not only under the cflow, also the calling type should match • n@advice around {k+cflow(f@ _ :: Int)} • Syntactic sugar: translated to • n_1@advice around {f} (arg :: Int) = proceed arg • n_2@advice around {k+cflow(n_1)}
Modification of Formal Things • Ignoring cflow in pointcut when testing if an advise should apply on a function • Add formal semantics for cflow • Reduction rule
Modification of Compiling Process • Pointcut data structure changed, related functions have to be changed • Already done (w/o type-scoped cflow) • Modifying IL tree • After IL generation • Implemented as a pass of compiler • Evaluator • Reduction of guarded advise
Translation – Big Picture • Put functions in monadic space • Bind it when calling • Left predefined operation unchanged • Reader monad: • newtype Reader e a = Reader { runReader :: (e -> a) } • Feed the context, give the answer • return a = Reader $ \e -> a • Only (\e -> a) in IL
Translation – Basic Blocks • local f c = Reader $ \e -> runReader c (f e) • (\e -> c (f e)) in IL • ask = Reader id • asks sel = ask >>= return . sel • (\e -> sel e) in IL • We can record functions in the stack, i.e. the cflows currently in
Translation – Basic Blocks (cont.) • type Env = • [String] : list of function names • Set String • String -> Bool • bit map (instance of class Bits) • type EnvReader a = Reader Env a
Translation – Functions & Advices • f :: forall a1 a2… an. P => t1 -> t2 • f arg = {expression} • wrapped_f :: forall a1 a2… an. P => EnvReader (t1 -> t2) • wrapped_f = local (cflowEnter “f”) $ Reader $ \e -> \arg -> runReader {expression’} e
Translation – Functions & Advices (cont.) • {expression’}: translated expression • Not change the names of functions • No change on joinpoint • No change on invocation • cflowEnter :: String -> Env -> Env • [String] => name : env • Set => insert name env • Bit map => setBit env offset_of_f
Translation – Expressions • “Return”-ing outer most expression • Functions calls • Get a temporary variable, bind the function on it and replace the call with it • Predefined operations unchanged f (g 1) 2 ~> g >>= \g’-> f >>= \f’-> return $ f’ (g’ 1) 2 if x == 1 then x else x + 1 ~> return $ if x == 1 then x else x + 1 unchanged
Translation – Advices in Chain • cflow-conditioned advice has a non-constant guard • n@advice around {k+cflowbelow(f)} ~> «asks (cflowIn “f”), n» • cflowIn • [String] => name `elem` env • Set => name `member` env • Bit map => testBit offset_of_f env • “And”-ed condition: and-ing asks
Translation – Main Expression • Let the modified main expression be “expr” • runReader (expr) emptyEnv • emptyEnv • [String] => [] • Set => empty • Bit map => all bit unset
Discussion • Translated IL of n@advice{k+cflowbelow(f)} • call(* k(*)) && cflow(execute(* f(*))) • Semantically equivalent tocall(* k(*)) && cflowbelow(call(* f(*))) • cflow vs. cflowbelow • Only different when the advised functions and cflowed functions intersects • cflow(call (* f(*)) = cflowbelow(call(* f(*))) || call(* f(*)) • Can implements cflow by cflowbelow
Discussion (cont.) • Type of Env • [String]: easy for hand-writing • Map: better performance • Bit map: best performance, prevent incremental weaving