Skip to content

Commit

Permalink
Merge branch 'tj/asn1_macro_prefix' into ccase/r13b04_dev
Browse files Browse the repository at this point in the history
* tj/asn1_macro_prefix:
  Add support for prefixing macro names generated by the compiler

OTP-8453  tj/asn1_macro_prefix
  • Loading branch information
Erlang/OTP committed Feb 17, 2010
2 parents f584be5 + 9d247b1 commit af08a7b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
22 changes: 18 additions & 4 deletions lib/asn1/doc/src/asn1ct.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<erlref>
<header>
<copyright>
<year>1997</year><year>2009</year>
<year>1997</year><year>2010</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
Expand All @@ -13,12 +13,12 @@
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 online 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.

</legalnotice>

<title>asn1ct</title>
Expand Down Expand Up @@ -52,9 +52,11 @@
<v>Options = [Option| OldOption]</v>
<v>Option = ber_bin | per_bin | uper_bin | der | compact_bit_string |
noobj | {n2n,EnumTypeName} |{outdir,Dir} | {i,IncludeDir} | optimize |
driver | asn1config | undec_rest | {inline,OutputName} | inline</v>
driver | asn1config | undec_rest | {inline,OutputName} | inline |
{macro_name_prefix, Prefix} | {record_name_prefix, Prefix}</v>
<v>OldOption = ber | per</v>
<v>Reason = term()</v>
<v>Prefix = string()</v>
</type>
<desc>
<p>Compiles the ASN.1 module <c>Asn1module</c> and generates an
Expand Down Expand Up @@ -270,6 +272,18 @@ Binary = binary()
It is as <c>{inline,OutputName}</c>, but the output file gets the
default name of the source <c>.set.asn</c> file.</p>
</item>
<tag><c>{macro_name_prefix, Prefix}</c></tag>
<item>
<p>All macro names generated by the compiler are prefixed with
<c>Prefix</c>. This is useful when multiple protocols that contains
macros with identical names are included in a single module.</p>
</item>
<tag><c>{record_name_prefix, Prefix}</c></tag>
<item>
<p>All record names generated by the compiler are prefixed with
<c>Prefix</c>. This is useful when multiple protocols that contains
records with identical names are included in a single module.</p>
</item>
</taglist>
<p>Any additional option that is applied will be passed to
the final step when the generated .erl file is compiled.
Expand Down
11 changes: 10 additions & 1 deletion lib/asn1/src/asn1ct_gen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,8 @@ pgen_hrltypes(Erules,Module,[H|T],NumRecords) ->

%% Generates a macro for value Value defined in the ASN.1 module
gen_macro(Value) when is_record(Value,valuedef) ->
emit({"-define('",Value#valuedef.name,"', ",
Prefix = get_macro_name_prefix(),
emit({"-define('",Prefix,Value#valuedef.name,"', ",
{asis,Value#valuedef.value},").",nl}).

%% Generate record functions **************
Expand Down Expand Up @@ -2064,3 +2065,11 @@ get_record_name_prefix() ->
{value,{_,Prefix}} ->
Prefix
end.

get_macro_name_prefix() ->
case lists:keysearch(macro_name_prefix,1,get(encoding_options)) of
false ->
"";
{value,{_,Prefix}} ->
Prefix
end.

0 comments on commit af08a7b

Please sign in to comment.