ic_erl_template.erl

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

ERL
638
字号
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %%     $Id$%%-module(ic_erl_template).-export([do_gen/3, emit_header/3]).-import(ic_codegen, [emit/2, emit/3, nl/1]).-include("icforms.hrl").-include("ic.hrl").-include_lib("stdlib/include/erl_compile.hrl").-define(TAB, "             ").-define(TAB2, "%             ").-define(TEMPLATE_1_A,	"%%----------------------------------------------------------------------\n"	"%% <LICENSE>\n"	"%% \n"	"%%     $Id$\n"	"%%\n"	"%%----------------------------------------------------------------------\n"	"%% Module       : ~s.erl\n"	"%% \n"	"%% Source       : ~s\n"	"%% \n"	"%% Description  : \n"	"%% \n"	"%% Creation date: ~s\n"	"%%\n"	"%%----------------------------------------------------------------------\n"	"-module(~p).\n\n").-define(TEMPLATE_1_B,	"%%----------------------------------------------------------------------\n"	"%% Internal Exports\n"	"%%----------------------------------------------------------------------\n"	"-export([init/1,\n"	"         terminate/2,\n"	"         code_change/3,\n"	"         handle_info/2]).\n\n"	"%%----------------------------------------------------------------------\n"	"%% Include Files\n"	"%%----------------------------------------------------------------------\n"	"\n\n"	"%%----------------------------------------------------------------------\n"	"%% Macros\n"	"%%----------------------------------------------------------------------\n"	"\n\n"	"%%----------------------------------------------------------------------\n"	"%% Records\n"	"%%----------------------------------------------------------------------\n"	"-record(state, {}).\n\n"	"%%======================================================================\n"	"%% API Functions\n"	"%%======================================================================\n").-define(TEMPLATE_1_C,	"%%======================================================================\n"	"%% Internal Functions\n"	"%%======================================================================\n"	"%%----------------------------------------------------------------------\n"	"%% Function   : init/1\n"	"%% Arguments  : Env = term()\n"	"%% Returns    : {ok, State}          |\n"	"%%              {ok, State, Timeout} |\n"	"%%              ignore               |\n"	"%%              {stop, Reason}\n"	"%% Raises     : -\n"	"%% Description: Initiates the server\n"	"%%----------------------------------------------------------------------\n"	"init(_Env) ->\n"	"\t{ok, #state{}}.\n\n\n"	"%%----------------------------------------------------------------------\n"	"%% Function   : terminate/2\n"	"%% Arguments  : Reason = normal | shutdown | term()\n"	"%%              State = term()\n"	"%% Returns    : ok\n"	"%% Raises     : -\n"	"%% Description: Invoked when the object is terminating.\n"	"%%----------------------------------------------------------------------\n"	"terminate(_Reason, _State) ->\n"	"\tok.\n\n\n"	"%%----------------------------------------------------------------------\n"	"%% Function   : code_change/3\n"	"%% Arguments  : OldVsn = undefined | term()\n"	"%%              State = NewState = term()\n"	"%%              Extra = term()\n"	"%% Returns    : {ok, NewState}\n"	"%% Raises     : -\n"	"%% Description: Invoked when the object should update its internal state\n"	"%%              due to code replacement.\n"	"%%----------------------------------------------------------------------\n"	"code_change(_OldVsn, State, _Extra) ->\n"	"\t{ok, State}.\n\n\n"	"%%----------------------------------------------------------------------\n"	"%% Function   : handle_info/2\n"	"%% Arguments  : Info = normal | shutdown | term()\n"	"%%              State = NewState = term()\n"	"%% Returns    : {noreply, NewState}          |\n"	"%%              {noreply, NewState, Timeout} |\n"	"%%              {stop, Reason, NewState}\n"	"%% Raises     : -\n"	"%% Description: Invoked when, for example, the server traps exits.\n"	"%%----------------------------------------------------------------------\n"	"handle_info(_Info, State) ->\n"	"\t{noreply, State}.\n\n\n").-define(TEMPLATE_2_A,	"%%% #0.    BASIC INFORMATION\n"	"%%% ----------------------------------------------------------------------\n"	"%%% %CCaseFile  : ~s.erl %\n"	"%%% Author      : \n"	"%%% Description : \n"	"%%%\n"	"%%% Modules used: \n"	"%%%\n"	"%%%\n"	"%%% ----------------------------------------------------------------------\n"	"-module(~p).\n"	"-author('unknown').\n"	"-id('').\n"	"-vsn('').\n"	"-date('~s').\n\n"	"%%% ----------------------------------------------------------------------\n"	"%%% Template Id: <ID>\n"	"%%%\n"	"%%% #Copyright (C) 2004\n"	"%%% by <COMPANY>\n"	"%%% <ADDRESS>\n"	"%%% <OTHER INFORMATION>\n"	"%%% \n"	"%%% <LICENSE>\n"	"%%% \n"	"%%% \n"	"%%% ----------------------------------------------------------------------\n"	"%%% #1.    REVISION LOG\n"	"%%% ----------------------------------------------------------------------\n"	"%%% Rev      Date       Name        What\n"	"%%% -----    -------    --------    --------------------------\n"	"%%% \n"	"%%% ----------------------------------------------------------------------\n"	"%%%\n"	"%%% \n"	"%%% #2.    EXPORT LISTS\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #2.1   EXPORTED INTERFACE FUNCTIONS\n"	"%%% ----------------------------------------------------------------------\n").-define(TEMPLATE_2_B,	"%%% ----------------------------------------------------------------------\n"	"%%% #2.2   EXPORTED INTERNAL FUNCTIONS\n"	"%%% ----------------------------------------------------------------------\n"	"-export([init/1,\n"	"         terminate/2,\n"	"         code_change/3,\n"	"         handle_info/2]).\n\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #2.3   INCLUDE FILES\n"	"%%% ----------------------------------------------------------------------\n"	"\n\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #2.4   MACROS\n"	"%%% ----------------------------------------------------------------------\n"	"\n\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #2.5   RECORDS\n"	"%%% ----------------------------------------------------------------------\n"	"-record(state, {}).\n\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #3.    CODE\n"	"%%% #---------------------------------------------------------------------\n"	"%%% #3.1   CODE FOR EXPORTED INTERFACE FUNCTIONS\n"	"%%% #---------------------------------------------------------------------\n").-define(TEMPLATE_2_C,	"%%% ----------------------------------------------------------------------\n"	"%%% #3.3   CODE FOR INTERNAL FUNCTIONS\n"	"%%% ----------------------------------------------------------------------\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #   init/1\n"	"%%% Input      : Env = term()\n"	"%%% Output     : {ok, State}          |\n"	"%%%              {ok, State, Timeout} |\n"	"%%%              ignore               |\n"	"%%%              {stop, Reason}\n"	"%%% Exceptions : -\n"	"%%% Description: Initiates the server\n"	"%%% ----------------------------------------------------------------------\n"	"init(_Env) ->\n"	"\t{ok, #state{}}.\n\n\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #   terminate/2\n"	"%%% Input      : Reason = normal | shutdown | term()\n"	"%%%              State = term()\n"	"%%% Output     : ok\n"	"%%% Exceptions : -\n"	"%%% Description: Invoked when the object is terminating.\n"	"%%% ----------------------------------------------------------------------\n"	"terminate(_Reason, _State) ->\n"	"\tok.\n\n\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #   code_change/3\n"	"%%% Input      : OldVsn = undefined | term()\n"	"%%%              State = NewState = term()\n"	"%%%              Extra = term()\n"	"%%% Output     : {ok, NewState}\n"	"%%% Exceptions : -\n"	"%%% Description: Invoked when the object should update its internal state\n"	"%%%              due to code replacement.\n"	"%%% ----------------------------------------------------------------------\n"	"code_change(_OldVsn, State, _Extra) ->\n"	"\t{ok, State}.\n\n\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #   handle_info/2\n"	"%%% Input      : Info = normal | shutdown | term()\n"	"%%%              State = NewState = term()\n"	"%%% Output     : {noreply, NewState}          |\n"	"%%%              {noreply, NewState, Timeout} |\n"	"%%%              {stop, Reason, NewState}\n"	"%%% Exceptions : -\n"	"%%% Description: Invoked when, for example, the server traps exits.\n"	"%%% ----------------------------------------------------------------------\n"	"handle_info(_Info, State) ->\n"	"\t{noreply, State}.\n\n\n"	"%%% ----------------------------------------------------------------------\n"	"%%% #4     CODE FOR TEMPORARY CORRECTIONS\n"	"%%% ----------------------------------------------------------------------\n\n").%%------------------------------------------------------------%%%% Generate the client side Erlang stubs.%%%% Each module is generated to a separate file.%%%% Export declarations for all interface functions must be%% generated. Each function then needs to generate a function head and%% a body. IDL parameters must be converted into Erlang parameters%% (variables, capitalised) and a type signature list must be%% generated (for later encode/decode).%%%%------------------------------------------------------------do_gen(G, _File, Form) ->     gen_head(G, [], Form),    gen(G, [], Form).gen(G, N, [X|Xs]) when record(X, preproc) ->    NewG = ic:handle_preproc(G, N, X#preproc.cat, X),    gen(NewG, N, Xs);gen(G, N, [X|Xs]) when record(X, module) ->    G2 = ic_file:filename_push(G, N, X, erlang_template_no_gen),    N2 = [ic_forms:get_id2(X) | N],    gen_head(G2, N2, X),    gen(G2, N2, ic_forms:get_body(X)),    G3 = ic_file:filename_pop(G2, erlang_template_no_gen),    gen(G3, N, Xs);gen(G, N, [X|Xs]) when record(X, interface) ->    G2 = ic_file:filename_push(G, N, X, erlang_template),    N2 = [ic_forms:get_id2(X) | N],    gen_head(G2, N2, X),    gen(G2, N2, ic_forms:get_body(X)),    lists:foreach(fun({_Name, Body}) -> gen(G2, N2, Body) end, 		  X#interface.inherit_body),    Fd	= ic_genobj:stubfiled(G2),    case get_template_version(G2) of	?IC_FLAG_TEMPLATE_2 ->	    emit(Fd, ?TEMPLATE_2_C, []);	_ ->	    emit(Fd, ?TEMPLATE_1_C, [])    end,    G3 = ic_file:filename_pop(G2, erlang_template),    gen(G3, N, Xs);gen(G, N, [X|Xs]) when record(X, op) ->    {Name, InArgNames, OutArgNames, Reply} = extract_info(X),    emit_function(G, N, X, ic_genobj:is_stubfile_open(G), 		   ic_forms:is_oneway(X), Name, InArgNames, OutArgNames, Reply),    gen(G, N, Xs);gen(G, N, [X|Xs]) when record(X, attr) ->    emit_attr(G, N, X, ic_genobj:is_stubfile_open(G), fun emit_function/9),    gen(G, N, Xs);gen(G, N, [_X|Xs]) ->    gen(G, N, Xs);gen(_G, _N, []) ->     ok.%% Module Headeremit_header(G, Fd, Name) ->    Date = get_date(),    case get_template_version(G) of	?IC_FLAG_TEMPLATE_2 ->	    emit(Fd, ?TEMPLATE_2_A, [Name, list_to_atom(Name), Date]);	_ ->	    IDLFile = ic_genobj:idlfile(G),	    emit(Fd, ?TEMPLATE_1_A, [Name, IDLFile, Date, list_to_atom(Name)])    end.emit_attr(G, N, X, Open, F) ->    XX = #id_of{type=X},    lists:foreach(fun(Id) ->

⌨️ 快捷键说明

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