TOP

ASN.1/C Compiler Directives

Applies to: ASN.1/C 10.5

Compiler directives, similar to compiler options, control the compiler output. Unlike compiler options, compiler directives can be added to the ASN.1 schema files or can be included in a separate directive file.

See the following topics for more information and examples:

Index

The following table contains compiler directives listed by category. Note that a directive may belong to more than one category. For your convenience, we have included check boxes that, when selected, display a particular group of directives: basic, advanced, or deprecated.

Basic Advanced Deprecated
C File Content ASN1.ConstraintFunction
OSS.NoConstraint
Header File Content/Arrangement OSS.COMMENT
OSS.DefineName
ASN1.PDU
OSS.PDU | OSS.NOPDU
ASN1.Remove
ASN1.WorkingSet
Miscellaneous OSS.ROOT
OSS.SampleCode
OSS.FUNCNAME
OSS.INCLUDES
Performance and Efficiency ASN1.ConstraintFunction
OSS.NoConstraint
ASN1.DeferDecoding
OSS.Truncate
Specification of Output Files OSS.Stylesheet
Standard Output OSS.SUPPRESS
Type Representation ASN1.HugeInteger
OSS.SHORT | OSS.INT | OSS.LONG | OSS.LONGLONG
OSS.LENGTHSIZE SHORT | INT | LONG
OSS.FLOAT | OSS.DOUBLE
ASN1.RealRepresentation
OSS.ARRAY
OSS.BMPSTRING
OSS.NULLTERM
OSS.UNBOUNDED
OSS.ExtractType | OSS.InlineType
OSS.OBJHANDLE (OSS.NOCOPY)
Value Reference OSS.NODEFAULTVALUE
XML-related OSS.Stylesheet

Format

Compiler directives are case-sensitive and have the following format:

  --<[prefix.]directive [absoluteReference] [operand1[,  operand2]...]>--

absoluteReference specifies the ASN.1 input schema items that are affected by the directive.

Directives appear as comments to compilers that do not support them. The following examples illustrate three equivalent ways to specify directives:

  --<OSS.NULLTERM>-- --<OSS.ROOT Module1>--
  --<OSS.NULLTERM>--
  --<OSS.ROOT Module1>--
  --<OSS.NULLTERM>--
  --<OSS.ROOT
  --Module1>--

When you do not specify directives, the compiler uses a default set of assumptions to generate the header and control/code file.

When you specify contradictory directives, the last one takes precedence.

Types

There are three types of compiler directives:

  • Standard directives
  • OSS-specific directives
  • OSS-specific legacy-style directives
Standard OSS Legacy
Syntax
--<ASN1.directive...>--
--<OSS.directive... >--
--<directive...>--
Usage General usage in the industry. Unique to the OSS ASN.1 Tools. Everywhere, except in-line (next to an item). Inline usage is replaced with the ability to reference a particular item. Historically used as in-line directives. OSS directives at a module or global level are a better alternative.
Use the -genDirectives compiler option to save legacy directives into a .gen file to be used outside of the ASN.1 module.
Example
--<ASN1.WorkingSet Mod>--
--<OSS.FLOAT Mod.TypeX>--
A ::= [1] REAL --<DOUBLE>--

If you use implementation-specific directives, note that the OSS ASN.1 compiler ignores them (for example: --<HP., --<TCSI. etc.), and issues warning messages during compilation.

When you have different scopes, local directives take precedence. The scopes can be:

Local
Directives are specified in-line (not recommended).
Example:
A ::= [1] REAL --<DOUBLE>--
Directives reference a specific item (recommended).
Example:
--<OSS.OBJECTID MyModule.MyName 27>--
Module
Directives are specified at the module level, before BEGIN, and they do not reference any specific item.
Example:
ModuleName DEFINITIONS --<OSS.OBJECTID 10>-- ::= BEGIN ...
Global
Directives are specified outside modules, usually in a directives file, and they do not reference any specific item.
Example:
--<OSS.OBJECTID 10>--
ModuleName DEFINITIONS ::= BEGIN ...

Syntax

Directives have the following format:

--<OSS.Directive [absoluteReference] [Operands]>--

Example

--<OSS.Nickname MyModule.MyData Monkey>--

The following table contains examples of using absoluteReference:

ASN.1 module absoluteReference
MyMod DEFINITIONS ::= BEGIN
  Comp1 ::= SET OF SEQUENCE {
    a INTEGER,
    b OCTET STRING OPTIONAL,
    c CHOICE {
      nest1 BOOLEAN,
      nest2 BIT STRING
    }
  }
  Comp2 ::= BOOLEAN 
     (CONSTRAINED BY {--Just a comment--})
     (CONSTRAINED BY {
        SET {con1 NULL, con2 REAL}})
END 
referencing  entire module: MyMod
referencing  SET OF: MyMod.Comp1
referencing  SEQUENCE series: MyMod.Comp1.*
referencing  b: MyMod.Comp1.*.b or MyMod.Comp1.*.2
referencing  nest1: MyMod.Comp1.*.c.nest1 or MyMod.Comp1.*.c.1
referencing  con1: MyMod.Comp1.$2.con1 
Mod DEFINITIONS ::= BEGIN
  C ::= BOOLEAN 
    (CONSTRAINED BY {})
       (CONSTRAINED BY {
          INTEGER, -- "1st" parameter
          IA5String,
          CHOICE {
            f REAL (CONSTRAINED BY
               {SET {e NULL}})
          } -- "3rd" parameter
     })
END
referencing adv1: Mod.C.$2:3.f.$1.adv1

Directives and Parameterized Types

Applying directives to parameterized types

When you apply a directive to a parameterized type definition, note that the directive is applied to each instance of the type.

For example, when the OSS.PDU directive is applied to a parameterized type, all instances of this type are treated as PDUs. Likewise, when the ASN1.WorkingSet directive is applied to a parameterized type, all instances of the type are included in the working set. An exception to this rule is the ASN1.Remove directive which must be explicitly applied to each instance of a parameterized type.

Applying OSS.FUNCNAME or ASN1.ConstraintFunction to a parameterized assignment

When you apply the OSS.FUNCNAME or the ASN1.ConstraintFunction directive to a parameterized assignment, note that the compiler generates names for the user-defined constraint functions which are post-fixed with a number (suffix) for each instance of the parameterized type other than the first instance.

Example

  --<OSS.FUNCNAME Test.Mouse "doggy">--

  Test DEFINITIONS ::= BEGIN
      Mouse {Type} ::= SEQUENCE   {t INTEGER} (CONSTRAINED BY {Type})
      Rat1 ::= [2] Mouse{SEQUENCE {i INTEGER, b BOOLEAN}}
      Rat2 ::= [3] Mouse{SEQUENCE {i INTEGER, b BOOLEAN}}
  END
    

When you use the -userConstraints command-line option, the following code is generated in the header file:

    /* doggy is user-defined constraint function for ASN.1 item Test.Rat1 */
    extern int DLL_ENTRY doggy(struct ossGlobal *, Rat1 *, void **);
    /* doggy_1 is user-defined constraint function for ASN.1 item Test.Rat2 */
    extern int DLL_ENTRY doggy_1(struct ossGlobal *, Rat2 *, void **);
    

Applying directives to instances of parameterized types

When you apply a directive to an instance of a parameterized type, note that it affects only that particular instance.

Example

    --<ASN1.Nickname  Test.S1     "Inst1_Seq">--
    --<OSS.TYPENAME   Test.S1.a   "Inst1_Seq_a">--
    --<OSS.DefineName Test.S1.a   "Inst1_Seq_a_c">--
    --<OSS.DefineName Test.S2.a.c "Inst2_Seq_a_c">--
    
  Test DEFINITIONS ::= BEGIN
    Seq {Type} ::= SEQUENCE   {a Type OPTIONAL}
      S1 ::= [2] Seq{SEQUENCE {b INTEGER}}
      S2 ::= [3] Seq{SEQUENCE {c BOOLEAN OPTIONAL}}
  END
    

The first three directives cause name changes only for the structure S1. The last directive affects the name in the second #define of S2:

typedef struct Inst1_Seq {
    unsigned char   bit_mask;
#       define      Inst1_Seq_a_c_present 0x80
    struct Inst1_Seq_a {
        int             b;
    } a;  /* optional; set in bit_mask Inst1_Seq_a_c_present if present */
} Inst1_Seq;

typedef struct S2 {
    unsigned char   bit_mask;
#       define      a_present 0x80
    struct {
        unsigned char   bit_mask;
#           define      Inst2_Seq_a_c_present 0x80
        ossBoolean      c;  /* optional; set in bit_mask Inst2_Seq_a_c_present
                             * if present */
    } a;  /* optional; set in bit_mask a_present if present */
} S2;
    

Applying directives to types used as substitution types

Directives cannot be applied to types used as substitution types (in instances of parameterized types), to fields of such types, or to types that are parameters in parameterized types.

Example

The following directives have no effect:

  --<ASN1.Nickname Test.T3.bt2.at1 bt2_nickname>--
  --<OSS.TYPENAME Test.T3.bt2 NewName-instance>--
  --<OSS.TYPENAME Test.T2.bt2 NewName-param>--
  
  Test DEFINITIONS ::= BEGIN
     T2 {X} ::= SEQUENCE {at2 BIT STRING, bt2 X OPTIONAL}
     T3 ::= T2 {T1}
     T1 ::= SET {at1 INTEGER, bt1 BOOLEAN}
  END
  

If you change the type for bt2 to a "non-direct" reference to the parameter X (SET OF X), the OSS.TYPENAME directives will succeed:

T2 {X} ::= SEQUENCE {at2 BIT STRING, bt2 SET OF X OPTIONAL}


This documentation applies to the OSS® ASN.1 Tools for C release 10.5 and later.

Copyright © 2017 OSS Nokalva, Inc. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means electronic, mechanical, photocopying, recording or otherwise, without the prior permission of OSS Nokalva, Inc.
Every distributed copy of the OSS® ASN.1 Tools for C is associated with a specific license and related unique license number. That license determines, among other things, what functions of the OSS ASN.1 Tools for C are available to you.