ic_pragma.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 1,956 行 · 第 1/4 页

ERL
1,956
字号
		    %% Inherited scopes		    CleanList = remove_inherited(S,InhList),		    getBrokerDataLoop(G,S,X,RS,CleanList,CSF)	    end;		ListOfOpScopes ->	   %io:format(" 13"),            case get_inherited(S,Scope,ListOfOpScopes) of		[[OpScope]] ->		    case member([OpScope],InhList) of 			true ->			    getBrokerData(G,X,RS,OpScope,CSF);			false ->			    CleanList = remove_inherited(S,InhList),			    getBrokerDataLoop(G,S,X,RS,CleanList,CSF)		    end;		_ ->		    CleanList = remove_inherited(S,InhList), 		    getBrokerDataLoop(G,S,X,RS,CleanList,CSF)	    end    end;%% Just add InhList after removing all inheritedgetBrokerDataInh(G,S,X,RS,_Scope,CSF,InhList) ->   %io:format(" 9"),    CleanList = remove_inherited(S,InhList),    getBrokerDataLoop(G,S,X,RS,CleanList,CSF).%% Loops over a list of scopesgetBrokerDataLoop(G,S,X,RS,List,CSF) ->    getBrokerDataLoop(G,S,X,RS,List,[],CSF).getBrokerDataLoop(G,_,_X,_RS,[],BrokerDataList,_CSF) ->    case no_doubles(BrokerDataList) of	[BrokerData] -> %% No pragma codeopt / Multiple branches with pragma codeopt	    BrokerData;	List ->	    DefaultBD = defaultBrokerData(G),	    case member(DefaultBD,List) of		true ->		    %% Remove default, choose codeoption 		    NewList = delete(DefaultBD,List),		    case NewList of			[BData] -> %% A branch only, with pragma codeopt			    BData;			_Other -> %% Multiple branches with pragma codeopt			    %%io:format("Multiple branches ~p~n",[Other]),			    NewList		    end;		false -> %% Multiple branches with pragma codeopt		    flatten(List)	    end    end;getBrokerDataLoop(G,S,X,RS,[[Scope]|Scopes],_Found,CSF) when integer(Scope) ->   getBrokerData(G,S,X,RS,[[Scope]|Scopes],CSF); getBrokerDataLoop(G,S,X,RS,[[Scope]|Scopes],Found,CSF) ->    %% Start from the beginning, check for overridings    case member(overridedFrom(S,RS,Scope),CSF) of %% Avoid infinite loops	true ->	    getBrokerDataLoop(G,S,X,RS,Scopes,Found,CSF);	false ->	    BrokerData = getBrokerData(G,X,RS,Scope,CSF),	    getBrokerDataLoop(G,S,X,RS,Scopes,[BrokerData|Found],[Scope|CSF])    end.%%%--------------------------------------%%% Finds out the overrider of a scope%%%--------------------------------------overridedFrom(S,RS,Scope) ->    overridedFrom(S,RS,Scope,Scope).	    overridedFrom(S,RS,Last,Scope) ->    case ets:match(S,{inherits,'$0',Scope}) of	[] -> 	    %% No inheritence, no pragma codeopt,	    %% choose the last scope.	    Last;	[[RS]] ->	    %% Garbage, unused interface with pragma            %% code option ! Danger !	    Last;		[[InhScope]] ->	    case ets:match(S,{codeopt,InhScope,'$1','_','_','_'}) of		[] -> 		    %% InhScope has no code options, keep Last.		    overridedFrom(S,RS,Scope,InhScope);		_ ->		    %% InhScope has code option, Last = InhScope.		    overridedFrom(S,RS,InhScope,InhScope)	    end;	List -> 	    %% Several inherit from Scope, choose the one feeseble,	    %% the one DIRECTLY inherited by Scope and not through	    %% other interface.  	    case remove_inheriters(S,RS,List) of		[] ->		    Scope;		Removed ->		    Removed	    end    end.%%%------------------------------------------------------%%% Removes all the scopes that inherit from others %%%------------------------------------------------------remove_inheriters(S,RS,InheriterList) ->    DominantList =	dominantList(S,InheriterList),    ReducedInhList = 	[X || X <- InheriterList, 	      member(X,DominantList)],    case ReducedInhList of        [] ->	    [];	[_OneOnly] ->	    ReducedInhList;	_Other ->	    EtsList = ets:tab2list(S),	    CleanList = 		[X || X <- EtsList, element(1,X) == inherits],%	    CodeOptList = %		[X || X <- EtsList, element(1,X) == codeopt],	    NoInheriters =remove_inheriters2(S,ReducedInhList,CleanList),	    [ [X] || [X] <- NoInheriters,		     inherits(RS,X,CleanList)]    end.remove_inheriters2(_,[A],_) ->    [A];remove_inheriters2(_S,[A,B],EtsList) ->    case remove_inh(A,B,[A,B],EtsList) of	[[X]] ->	    X;	List ->	    List    end;remove_inheriters2(S,[A,B|Rest],EtsList) ->    case remove_inh(A,B,[A,B|Rest],EtsList) of	[A,B|Rest] ->	    [A,B|Rest];	NewList ->	    remove_inheriters2(S,NewList,EtsList)    end.remove_inh([X],[Y],List,EtsList) ->    case inherits(X,Y,EtsList) of	true ->	    delete([X],List);	false ->	    case inherits(Y,X,EtsList) of		true ->		    delete([Y],List);		false ->		    List	    end    end.%%%----------------------------------------------%%% Should remove all scope links that inherit %%% from others in the list %%%----------------------------------------------remove_inherited(S,InheriterList) ->    EtsList = ets:tab2list(S),    CleanList = 	[X || X <- EtsList, element(1,X) == inherits],    remove_inherited(S,InheriterList,CleanList).remove_inherited(_S,[A,B],EtsList) ->    case remove_inhed(A,B,[A,B],EtsList) of	[[X]] ->	    [[X]];	List ->	    List    end;remove_inherited(S,[A,B|Rest],EtsList) ->    case remove_inhed(A,B,[A,B|Rest],EtsList) of	[A,B|Rest] ->	    [A,B|Rest];	NewList ->	    remove_inherited(S,NewList,EtsList)    end.remove_inhed([X],[Y],List,EtsList) ->    case inherits(X,Y,EtsList) of	true ->	    delete([Y],List);	false ->	    case inherits(Y,X,EtsList) of		true ->		    delete([X],List);		false ->		    List	    end    end.%%%----------------------------------------------%%% Should return all scope links that is %%  are inherited from scope in the list %%%----------------------------------------------get_inherited(S,Scope,OpScopeList) ->    EtsList = ets:tab2list(S),    [[element(3,X)] || X <- EtsList, 		       element(1,X) == inherits,		       element(2,X) == Scope,		       member([element(3,X)],OpScopeList)].%%%---------------------------------------------------%%% Returns a the list of scopes that have codeoption%%% from a list of scopes%%%---------------------------------------------------dominantList(S,IL) ->    dominantList(S,IL,[]).dominantList(_S,[],Found) ->    Found;dominantList(S,[[X]|Xs],Found) ->    case ets:match(S,{codeopt,X,'$1','_','_','_'}) of	[] ->	    dominantList(S,Xs,Found);	_ ->	    dominantList(S,Xs,[[X]|Found])     end.%%%---------------------------------------------------%%% Returns true if X direct or indirect inherits Y%%%---------------------------------------------------inherits(X,Y,EtsList) ->    case member({inherits,X,Y},EtsList) of	true ->	    %% Direct inherited	    true;	false ->	    %% Indirectly inherited	    AllInh = [ B || {inherits,A,B} <- EtsList, A == X ], 	    inherits(X,Y,AllInh,EtsList)    end.inherits(_X,_Y,[],_EtsList) ->    false;inherits(X,Y,[Z|Zs],EtsList) ->    case inherits2(X,Y,Z,EtsList) of	true ->	    true;	false ->	    inherits(X,Y,Zs,EtsList)    end.inherits2(_X,Y,Z,EtsList) ->    case  member({inherits,Z,Y},EtsList) of	true ->	    true;	false ->	    inherits(Z,Y,EtsList)    end.%%%% is_inherited_by/3%%%% Returns :%%%%     true if the first parameter is%%          inherited by the second one%%%%     false otherwise   %%is_inherited_by(Interface1,Interface2,PragmaTab) ->    FullList = ets:tab2list(PragmaTab),    InheritsList = 	[X || X <- FullList, element(1,X) == inherits],    inherits(Interface2,Interface1,InheritsList).%% Filters all pragma prefix from list not in same file %% the objectfilter_pragma_prefix_list(PragmaTab, Name, Scope, List) ->    IdlFile = scoped_names_idl_file(PragmaTab, Name, Scope),    filter_pragma_prefix_list2(PragmaTab,IdlFile,List,[]).filter_pragma_prefix_list2(_,_,[],Found) ->    Found;filter_pragma_prefix_list2(PT, IdlFile, [PP|PPs], Found) ->    case PP of 	{prefix,_,_,_,IdlFile,_} -> %% Same file as the Object, keep	    filter_pragma_prefix_list2(PT, IdlFile, PPs, [PP|Found]);		_Other -> %% NOT in same file as the Object, throw away	    filter_pragma_prefix_list2(PT, IdlFile, PPs, Found)    end.scoped_names_idl_file(PragmaTab, Name, Scope) ->    case ets:match(PragmaTab,{'_','$0','_','$2',Scope,Name,'_','_','_'}) of	[[IdlFile, _Type]] -> %% Usual case 	    IdlFile;	[[_File,module]|_Files] -> %% Multiple modules, get LOCAL file	    case ets:match(PragmaTab,{file_data_local,'$0','_',module,Scope,Name,'_','_','_'}) of		[[LocalIdlFile]] -> 		    LocalIdlFile;		_ -> %% Should  NEVER occur		    error	    end;	_ ->	    error %% Should  NEVER occur    end.%%-------------------------------------------------%%%% Register specific pragma code options%%%% If there is an operation with that%% scope, denote this as {codeopt_specific,Scope}%%%%-------------------------------------------------denote_specific_code_opts(G) ->    case ic_options:get_opt(G, be) of	noc ->	    S = ic_genobj:pragmatab(G),	    COList = ets:match(S,{codeopt,'$0','_','_','_','_'}),	    OPList = ets:match(S,{op,'$0','$1','_','_'}),	    denote_specific_code_opts(S,COList,OPList);	_ ->	    ok    end.denote_specific_code_opts(_,_,[]) ->    ok;denote_specific_code_opts(S,COList,[[OpN,OpS]|OPSs]) ->    case lists:member([[OpN|OpS]],COList) of	true ->	    insert(S, {codeopt_specific,[OpN|OpS]});	false ->	    ok    end,    denote_specific_code_opts(S,COList,OPSs).%%---------------------------------------------%%%% Returns true/false if it denotes an operation%%%%---------------------------------------------isOperation(_S,[]) ->    false;isOperation(_S,[_]) ->    false;isOperation(S,[H|T]) ->    case ets:match(S,{op,H,T,'$2','$3'}) of	[] ->	    false;	_ ->	    true    end.hasSpecificCodeoptionOnTopFile(S,File,Scope) ->    case ets:match(S,{codeopt,Scope,'_','$2',File,[File]}) of	[] ->	    false;	_ ->	    true    end.hasNonSpecificCodeoptionOnTopFile(S,File) ->    case ets:match(S,{codeopt,'_','_','$2',File,[File]}) of	[] ->	    false;	_ ->	    true    end.%%---------------------------------------------%%%% Returns {ok,IfrId}/error when searching a random local type%%%%---------------------------------------------fetchRandomLocalType(G) ->        S = ic_genobj:pragmatab(G),    case ets:match(S,{file_data_local,'_','_','$2','$3','$4','_','_','_'}) of			[] ->	    false;		List ->	    fetchRandomLocalType(S,List)    end.fetchRandomLocalType(_,[]) ->    false;fetchRandomLocalType(S,[[module|_]|Tail]) ->    fetchRandomLocalType(S,Tail);fetchRandomLocalType(S,[[_,Scope,Name]|Tail]) ->    case ets:match(S,{alias,[Name|Scope],'$1'}) of	[] ->	    fetchRandomLocalType(S,Tail);	[[IfrId]] ->	    {ok,IfrId}    end.%%---------------------------------------------%%%% Returns A list of local operation mapping %% for a given scope%%%%---------------------------------------------fetchLocalOperationNames(G,I) ->    S = ic_genobj:pragmatab(G),    case ets:match(S,{file_data_local,'_','_',op,I,'$4','_','_','_'}) of	[] ->	    [];	List ->	    fetchLocalOperationNames2(List,[])    end.fetchLocalOperationNames2([],Found) ->    lists:reverse(Found);fetchLocalOperationNames2([[Name]|Names],Found) ->    fetchLocalOperationNames2(Names,[Name|Found]).%%------------------------------------------------%%%%  Returns a true if this scoped id is a local%%  one, false otherwise%%%%------------------------------------------------is_local(G,ScopedId) ->    S = ic_genobj:pragmatab(G),    Name = ic_util:to_undersc(ScopedId),    case ets:match(S,{file_data_local,'_','_','_',tl(ScopedId),'_',Name,'_','_'}) of	[[]] ->	    true;	_ ->	    false    end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?