Table of Contents Previous Next
Logo
Client-Side Slice-to-Objective-C Mapping : 18.5 Mapping for Identifiers
Copyright © 2003-2010 ZeroC, Inc.

18.5 Mapping for Identifiers

Objective‑C identifiers are derived from Slice identifiers. The exact Objective‑C identifier that is generated depends on the context. For types that are nested in modules (and hence have global visibility in Objective‑C), the generated Objec­tive‑C identifiers are prefixed with their module prefix, as discussed in Section 18.3. Slice identifiers that do not have global visibility (such as operation names and structure members) do not use the module prefix and are preserved without change. For example, consider the following Slice definition:
["objc:prefix:EX"]
module Example {
    struct Point {
        double x;
        double y;
    };
};
This maps to the following Objective‑C definition:
@interface EXPoint : NSObject <NSCopying>
{
    @private
        ICEDouble x;
        ICEDouble y;
}

@property(nonatomic, assign) ICEDouble x;
@property(nonatomic, assign) ICEDouble y;

// More definitions here...
@end
If a Slice identifier is the same as an Objective‑C keyword, the corresponding Objective‑C identifier has an underscore suffix. For example, Slice while maps to Objective‑C while_.
In some cases, the Objective‑C mapping generates more than one identifier for a given Slice construct. For example, an interface Intf generates the identifiers EXIntf and EXIntfPrx. If a Slice identifier happens to be an Objective‑C keyword, the underscore suffix applies only where necessary, so an interface while generates EXWhile and EXWhilePrx.
Note that Slice operation and member names can clash with the name of an inherited method, property, or instance variable. For example:
exception Failed {
    string reason; // Clashes with NSException
};
This is a legal Slice definition. However, the generated exception class derives from NSException, which defines a reason method. To avoid hiding the method in the base class, the generated exception class maps the Slice reason member to the Objective‑C property reason_, just as it would for a keyword.
This escape mechanism applies to all generated classes that directly or indi­rectly derive from NSObject or NSException.

Table of Contents Previous Next
Logo