anchor.diff:  %%@spec build_callgraph(DirList::[dir()]) -> #callgraph{}
   %%@doc Build a function call graph out of the Erlang files contained in the given directories.
   
  --spec(build_callgraph(DirList::[dir()]) -> #callgraph{}).
  -build_callgraph(DirList) ->
  -    Files = refac_util:expand_files(DirList, ".erl"),
  -    CallGraph = build_callgraph(Files, []),
  -    %% io:format("CallGraph:\n~p\n", [CallGraph]),
  -    refac_callgraph:construct(CallGraph).
  +-spec(build_scc_callgraph(DirList::[dir()]) -> #callgraph{}).
  +build_scc_callgraph(DirList) ->
  +    CallerCalleesWithDef = build_callercallee_callgraph(DirList),
  +    CallerCallees =  lists:map(fun ({{Caller, _CallerDef}, Callee}) -> {Caller, Callee} end, CallerCalleesWithDef),
  +    {Sccs, E} = refac_callgraph:construct(CallerCalleesWithDef),
  +    #callgraph{callercallee = CallerCallees, scc_order = Sccs, external_calls = E}.
  +    
      
   
  --spec(build_callgraph/2::([filename()], [{{{atom(), atom(), integer()}, syntaxTree()}, {atom(), atom(), integer()}}]) ->
  - 	     [{{{atom(), atom(), integer()}, syntaxTree()}, [{atom(), atom(), integer()}]}]).
  -build_callgraph([FileName | Left], Acc) ->
  -    {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(FileName, true, []),
  -    case lists:keysearch(errors,1, Info) of 
  -	{value, {errors, _Errors}} -> erlang:error("Syntax error in " ++ FileName);
  -	_ ->  G1 = build_callgraph(AnnAST, Info, FileName),
  -	      Acc1 = Acc ++ G1,
  -	      build_callgraph(Left, Acc1)
  -    end; 
  -build_callgraph([], Acc) -> Acc.
  -
  --spec(build_callgraph/3::(syntaxTree(),moduleInfo(),filename()) -> 
  -	     [{{{atom(), atom(), integer()}, syntaxTree()}, [{atom(), atom(), integer()}]}]).
  -build_callgraph(Node, Info, _FileName) ->
  -    {value, {module, ModName}} = lists:keysearch(module, 1, Info),
  -    Inscope_Funs = [{erlang, Fun, Arity} || {Fun, Arity} <- auto_imported_bifs()] ++
  -		     refac_util:inscope_funs(Info),  %% NOTE: orders matters here.
  +-spec(build_callercallee_callgraph/1::([dir()]) -> [{{{atom(), atom(), integer()}, syntaxTree()}, [{atom(), atom(), integer()}]}]).
  +build_callercallee_callgraph(SearchPaths) ->
  +    Files = refac_util:expand_files(SearchPaths, ".erl"),
  +    lists:append(lists:map(fun(FileName) ->
  +		      {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(FileName, true, SearchPaths),
  +		      case lists:keysearch(errors,1, Info) of 
  +			  {value, {errors, _Errors}} -> erlang:error("Syntax error in " ++ FileName);
  +			  _ ->  do_build_callgraph(FileName, {AnnAST, Info})
  +		      end
  +	      end, Files)).
  +    
  +   
  +-spec(do_build_callgraph/2::(filename(), {syntaxTree(),moduleInfo()}) -> 
  +    [{{{atom(), atom(), integer()}, syntaxTree()}, [{atom(), atom(), integer()}]}]).
  +do_build_callgraph(FileName, {AnnAST, Info}) ->
  +     case lists:keysearch(module, 1, Info) of 
  +	    {value, {module, ModName}}  -> ModName;
  +	    _ -> ModName = list_to_atom(filename:basename(FileName, ".erl")),
  +		 ModName
  +	end,
  +    Inscope_Funs = refac_util:auto_imported_bifs() ++ refac_util:inscope_funs(Info), 
       HandleSpecialFuns = fun (Arguments, S) ->
   				case Arguments of
  -				  [F, A] ->
  -				      case {refac_syntax:type(F), refac_syntax:type(A)} of
  -					{atom, list} ->
  -					    FunName = refac_syntax:atom_value(F),
  -					    Arity = refac_syntax:list_length(A),
  -					    ordsets:add_element({ModName, FunName, Arity}, S);
  -					_ -> S
  -				      end;
  -				  [M, F, A] ->
  -				      case {refac_syntax:type(M), refac_syntax:type(F), refac_syntax:type(A)} of
  -					{atom, atom, list} ->
  -					    ModName = refac_syntax:atom_value(M),
  -					    FunName = refac_syntax:atom_value(F),
  -					    Arity = refac_syntax:list_length(A),
  -					    ordsets:add_element({ModName, FunName, Arity}, S);
  -					_ -> S
  -				      end;
  -				  [M, F, A, _O] ->
  -				      case {refac_syntax:type(M), refac_syntax:type(F), refac_syntax:type(A)} of
  -					{atom, atom, list} ->
  -					    ModName = refac_syntax:atom_value(M),
  -					    FunName = refac_syntax:atom_value(F),
  -					    Arity = refac_syntax:list_length(A),
  -					    ordsets:add_element({ModName, FunName, Arity}, S);
  -					_ -> S
  -				      end
  +				    [F, A] ->
  +					case {refac_syntax:type(F), refac_syntax:type(A)} of
  +					    {atom, list} ->
  +						FunName = refac_syntax:atom_value(F),
  +						Arity = refac_syntax:list_length(A),
  +						ordsets:add_element({ModName, FunName, Arity}, S);
  +					    _ -> S
  +					end;
  +				    [M, F, A] ->
  +					case {refac_syntax:type(M), refac_syntax:type(F), refac_syntax:type(A)} of
  +					    {atom, atom, list} ->
  +						ModName1 = refac_syntax:atom_value(M),
  +						FunName = refac_syntax:atom_value(F),
  +						Arity = refac_syntax:list_length(A),
  +						ordsets:add_element({ModName1, FunName, Arity}, S);
  +					    _ -> S
  +					end;
  +				    [M, F, A, _O] ->
  +					case {refac_syntax:type(M), refac_syntax:type(F), refac_syntax:type(A)} of
  +					    {atom, atom, list} ->
  +						ModName1 = refac_syntax:atom_value(M),
  +						FunName = refac_syntax:atom_value(F),
  +						Arity = refac_syntax:list_length(A),
  +						ordsets:add_element({ModName1, FunName, Arity}, S);
  +					    _ -> S
  +					end
   				end
   			end,
       F2 = fun (T, S) ->
   		 case refac_syntax:type(T) of
   		   application ->
  -		       Operator = refac_syntax:application_operator(T),
  -		       Arguments = refac_syntax:application_arguments(T),
  -		       Arity = length(Arguments),
  +			 Operator = refac_syntax:application_operator(T),
  +			 Arguments = refac_syntax:application_arguments(T),
  +			 Arity = length(Arguments),
   		       case refac_syntax:type(Operator) of
  -			 atom ->
  -			     Op = refac_syntax:atom_value(Operator),
  -			     R = lists:filter(fun ({_M, F, A}) -> (F == Op) and (A == Arity) end, Inscope_Funs),
  +			   atom ->
  +			       Op = refac_syntax:atom_value(Operator),
  +			       R = lists:filter(fun ({_M, F, A}) -> (F == Op) and (A == Arity) end, Inscope_Funs),
   			     if R == [] ->
  -				    ordsets:add_element({unknown, Op, Arity},
  -							S);  %% Should we give an error message here?
  +				     %% Qn: Should we give an error/warning msg here?
  +				     ordsets:add_element({unknown, Op, Arity},S); 
   				true ->
  -				    {M, Op, Arity} = hd(R),
  -				    S1 = ordsets:add_element({M, Op, Arity}, S),
  -				    case {Op, Arity} of
  -				      {apply, 2} -> HandleSpecialFuns(Arguments, S1);
  -				      {apply, 3} -> HandleSpecialFuns(Arguments, S1);
  -				      {spawn, 3} -> HandleSpecialFuns(Arguments, S1);
  -				      {spawn, 4} -> HandleSpecialFuns(Arguments, S1);
  -				      {spawn_link, 3} -> HandleSpecialFuns(Arguments, S1);
  -				      {spawn_link, 4} -> HandleSpecialFuns(Arguments, S1);
  +				     {M, Op, Arity} = hd(R),
  +				     S1 = ordsets:add_element({M, Op, Arity}, S),
  +				     case {Op, Arity} of
  +					 {apply, 2} -> HandleSpecialFuns(Arguments, S1);
  +					 {apply, 3} -> HandleSpecialFuns(Arguments, S1);
   				      _ -> S1
  -				    end
  +				     end
   			     end;
  -			 module_qualifier ->
  -			     Mod = refac_syntax:module_qualifier_argument(Operator),
  -			     Body = refac_syntax:module_qualifier_body(Operator),
  -			     case {refac_syntax:type(Mod), refac_syntax:type(Body)} of
  -			       {atom, atom} ->
  -				   Mod1 = refac_syntax:atom_value(Mod),
  -				   Op = refac_syntax:atom_value(Body),
  -				   S1 = ordsets:add_element({Mod1, Op, Arity}, S),
  -				   case {Mod1, Op, Arity} of
  -				     {erlang, apply, 2} -> HandleSpecialFuns(Arguments, S1);
  -				     {erlang, apply, 3} -> HandleSpecialFuns(Arguments, S1);
  -				     {erlang, spawn, 3} -> HandleSpecialFuns(Arguments, S1);
  -				     {erlang, spawn, 4} -> HandleSpecialFuns(Arguments, S1);
  -				     {erlang, spawn_link, 3} -> HandleSpecialFuns(Arguments, S1);
  -				     {erlang, spawn_link, 4} -> HandleSpecialFuns(Arguments, S1);
  -				     _ -> S1
  -				   end;
  -			       _ -> S
  -			     end;
  -			 _ -> S
  +			   module_qualifier ->
  +			       Mod = refac_syntax:module_qualifier_argument(Operator),
  +			       Body = refac_syntax:module_qualifier_body(Operator),
  +			       case {refac_syntax:type(Mod), refac_syntax:type(Body)} of
  +				   {atom, atom} ->
  +				       Mod1 = refac_syntax:atom_value(Mod),
  +				       Op = refac_syntax:atom_value(Body),
  +				       S1 = ordsets:add_element({Mod1, Op, Arity}, S),
  +				       case {Mod1, Op, Arity} of
  +					   {erlang, apply, 2} -> HandleSpecialFuns(Arguments, S1);
  +					   {erlang, apply, 3} -> HandleSpecialFuns(Arguments, S1);
  +					   _ -> S1
  +				       end;
  +				   _ -> S
  +			       end;
  +			   _ -> S
   		       end;
  -		   arity_qualifier ->
  -		       Fun = refac_syntax:arity_qualifier_body(T),
  -		       A = refac_syntax:arity_qualifier_argument(T),
  -		       case {refac_syntax:type(Fun), refac_syntax:type(A)} of
  -			 {atom, integer} ->
  -			     FunName = refac_syntax:atom_value(Fun),
  -			     Arity = refac_syntax:integer_value(A),
  -			     ordsets:add_element({ModName, FunName, Arity}, S);
  -			 _ -> S
  -		       end;
  -		   _ -> S
  +		     arity_qualifier ->
  +			 Fun = refac_syntax:arity_qualifier_body(T),
  +			 A = refac_syntax:arity_qualifier_argument(T),
  +			 case {refac_syntax:type(Fun), refac_syntax:type(A)} of
  +			     {atom, integer} ->
  +				 FunName = refac_syntax:atom_value(Fun),
  +				 Arity = refac_syntax:integer_value(A),
  +				 ordsets:add_element({ModName, FunName, Arity}, S);
  +			     _ -> S
  +			 end;
  +		     _ -> S
   		 end
   	 end,
       F1 = fun (T, S) ->
   		 case refac_syntax:type(T) of
  -		   function ->
  -		       FunName = refac_syntax:data(refac_syntax:function_name(T)),
  -		       Arity = refac_syntax:function_arity(T),
  -		       Caller = {{ModName, FunName, Arity}, T},
  -		       CalledFuns = lists:usort(refac_syntax_lib:fold(F2, [], T)),
  -		       ordsets:add_element({Caller, CalledFuns}, S);
  -		   _ -> S
  +		     function ->
  +			 FunName = refac_syntax:data(refac_syntax:function_name(T)),
  +			 Arity = refac_syntax:function_arity(T),
  +			 Caller = {{ModName, FunName, Arity}, T},
  +			 CalledFuns = lists:usort(refac_syntax_lib:fold(F2, [], T)),
  +			 ordsets:add_element({Caller, CalledFuns}, S);
  +			%% lists:foldr(fun(E,S_) -> ordsets:add_element({Caller, E}, S_) end, S,  CalledFuns);
  +		     _ -> S
   		 end
   	 end,
  -    lists:usort(refac_syntax_lib:fold(F1, [], Node)).
  +    lists:usort(refac_syntax_lib:fold(F1, [], AnnAST)).
  +
   
   %% =====================================================================
   %% @spec bifs_side_effect_table()->[{{atom(), atom(), integer()}, boolean()}]
  
positive.code:      lists:concat(lists:reverse(Acc));
  concat_toks([T|Ts], Acc) ->
       case T of 
  	{atom, _, V} -> S = case is_upper(hd(atom_to_list(V))) of 
  				true -> "'"++atom_to_list(V)++"'";
  				_ -> V
  			    end,
  			concat_toks(Ts, [S|Acc]);
  	{string, _, V} -> concat_toks(Ts,['"', process_str(V), '"'|Acc]);
  
negative.code:     end.
  
  
  