eĿlipsis
a language independent preprocessor
 
Loading...
Searching...
No Matches
ellipsis-unique.dirs File Reference

Provide a hierarchically organized set of identifers. More...

Macros

#define UNIQ(POS0, POS1)
 Refer to the POS1-last unique identifier recently created.
 
#define UNIQ_DOWN
 Move down one level in the hierarchy of unique identifiers.
 
#define UNIQ_NEW
 Create and return a new unique identifier.
 
#define UNIQ_UP
 Move up one level in the hierarchy of unique identifiers.
 
Interal macros
Remarks
Don't use these directly, they only serve to construct those that are destined for the user.
#define ELLIPSIS_UNIQUE0(NAME, CURRENT, POS0, POS1, ...)
 
#define ELLIPSIS_UNIQUE1(NAME, LEVEL, POS, ...)
 
#define ELLIPSIS_UNIQUE2(NAME, LEVEL, LAST, POS, ...)
 
#define ELLIPSIS_UNIQUE3(NAME, LEVEL, NUMBER)
 
#define ELLIPSIS_UNIQUE_LEVEL
 
#define ELLIPSIS_UNIQUE_NAME()
 
#define ELLIPSIS_UNIQUE_NEW(NAME, LEVEL)
 
#define ELLIPSIS_UNIQUE_UPDOWN(...)
 
#define ELLIPSIS_UNIQUE_UPDOWN1(...)
 

Detailed Description

Provide a hierarchically organized set of identifers.

This provides a set of macros prefixed with UNIQ that expand and manage unique identifiers. (For using other another name than UNIQ, see below.) Central are macros UNIQ_NEW and UNIQ that create respectively refer to an identifier.

double UNIQ_NEW = 5;
double UNIQ_NEW = 6;
printf("%g %g\n", UNIQ(), UNIQ(1));
#define UNIQ_NEW
Create and return a new unique identifier.
Definition ellipsis-unique.dirs:4
#define UNIQ(POS0, POS1)
Refer to the POS1-last unique identifier recently created.
Definition ellipsis-unique.dirs:3

Note that here UNIQ needs parenthesis for the invokation and receives 0, 1, or 2 arguments. The above expands to something similar as the following

double UNIQ_ID_1_9 = 5;
double UNIQ_ID_1_10 = 6;
printf("%g %g\n", UNIQ_ID_1_10, UNIQ_ID_1_9);

Obivously here the concrete names that are chosen depend on the context where this code would be found. You should not try to recover such names manually.

The first argument to UNIQ indicates to which of the unique idenfier it refers: 0, the default, refers to the last identifer created with UNIQ_NEW (here the variable initialized with the value 6), 1 to the one before (here the variable initialized with the value 5).

So the above example should print the values 6 5 in that order.

Two additional macros, UNIQ_UP and UNIQ_DOWN, add a hierarchical aspect, namely nesting levels for identifiers. To see that consider a macro SWAPEM(A, B) with the following expansion:

do {
register auto const UNIQ_NEW = &(A);
register auto const UNIQ_NEW = &(B);
register auto const UNIQ_NEW = *UNIQ(2);
*UNIQ(2) = *UNIQ(1);
*UNIQ(1) = UNIQ();
} while(false)
#define UNIQ_UP
Move up one level in the hierarchy of unique identifiers.
Definition ellipsis-unique.dirs:5
#define UNIQ_DOWN
Move down one level in the hierarchy of unique identifiers.
Definition ellipsis-unique.dirs:6

Here we use UNIQ_UP to move one "level" up in the hierarchy if identifiers. This and the UNIQ_DOWN at the end have no visual effect on the code, only that they steps one level up or down in the identifier hierarchy. To see that in context let's amend our example from above by adding an invokation of SWAPEM.

double UNIQ_NEW = 5;
double UNIQ_NEW = 6;
SWAPEM(UNIQ(), UNIQ(1));
printf("%g %g\n", UNIQ(), UNIQ(1));

The expansion would be looking similar to the following:

double UNIQ_ID_1_9 = 5;
double UNIQ_ID_1_10 = 6;
do { register auto const UNIQ_ID_2_7 = &(UNIQ_ID_1_10); register auto const UNIQ_ID_2_8 = &(UNIQ_ID_1_9); register auto const UNIQ_ID_2_9 = *UNIQ_ID_2_7; *UNIQ_ID_2_7= *UNIQ_ID_2_8; *UNIQ_ID_2_8 = UNIQ_ID_2_9; } while(false);
printf("%g %g\n", UNIQ_ID_1_10, UNIQ_ID_1_9);

So here the expansion of the three lines that we had before has not changed at all; in the printf call we can easily refer to the identifiers as we did before without needing to worry about what effects the invokation of SWAPEM might have caused.

In contrast to that the call to SWAPEM itself sees a new set of names for its variables, here identifiers starting with UNIQ_ID_2_, and so the variables defined there are in no conflict with the identifiers in the surrounding scope.

As a result of this invokation, the contents of the two variables is swapped and the two values would be 5 6, inverted compared to what we had seen above.

UNIQ has an optional second parameter that refers to the level in which the identifier is sought. As for the first paremeter, 0, the default, refers to the current level, 1 refers to one level down and so on.

Typically you would include this feature with a directive such as

#include_directives <ellipsis-unique.dirs>

This provides you with a set of macros as described above that have names starting with UNIQ. If you wand to change that, you may bind the macro UNIQUE_NAME to a prefix of your liking. For example

#include_directives "ellipsis-unique.dirs" __prefix__(bind UNIQUE_NAME LABEL)

creates an alternative set of macros LABEL, LABEL_NEW, LABEL_UP and LABEL_DOWN that can be used in a similar way, but which result in identifiers that use "LABEL" instead of "UNIQ".

See also
ellipsis-loc.h for a simpler feature based on {} scope (C only)

Macro Definition Documentation

◆ ELLIPSIS_UNIQUE0

#define ELLIPSIS_UNIQUE0 (   NAME,
  CURRENT,
  POS0,
  POS1,
  ... 
)

◆ ELLIPSIS_UNIQUE1

#define ELLIPSIS_UNIQUE1 (   NAME,
  LEVEL,
  POS,
  ... 
)

◆ ELLIPSIS_UNIQUE2

#define ELLIPSIS_UNIQUE2 (   NAME,
  LEVEL,
  LAST,
  POS,
  ... 
)

◆ ELLIPSIS_UNIQUE3

#define ELLIPSIS_UNIQUE3 (   NAME,
  LEVEL,
  NUMBER 
)

◆ ELLIPSIS_UNIQUE_LEVEL

#define ELLIPSIS_UNIQUE_LEVEL

◆ ELLIPSIS_UNIQUE_NAME

#define ELLIPSIS_UNIQUE_NAME ( )

◆ ELLIPSIS_UNIQUE_NEW

#define ELLIPSIS_UNIQUE_NEW (   NAME,
  LEVEL 
)

◆ ELLIPSIS_UNIQUE_UPDOWN

#define ELLIPSIS_UNIQUE_UPDOWN (   ...)

◆ ELLIPSIS_UNIQUE_UPDOWN1

#define ELLIPSIS_UNIQUE_UPDOWN1 (   ...)

◆ UNIQ

#define UNIQ (   POS0,
  POS1 
)

Refer to the POS1-last unique identifier recently created.

The second argument may chose identifiers from different levels, 0 is the current level, 1 is one level down and so on.

If omitted both parameters default to 0.

See also
ellipsis-unique.dirs

◆ UNIQ_DOWN

#define UNIQ_DOWN

Move down one level in the hierarchy of unique identifiers.

Otherwise this macro has no visible effect.

See also
ellipsis-unique.dirs

◆ UNIQ_NEW

#define UNIQ_NEW

Create and return a new unique identifier.

See also
ellipsis-unique.dirs

◆ UNIQ_UP

#define UNIQ_UP

Move up one level in the hierarchy of unique identifiers.

Otherwise this macro has no visible effect.

See also
ellipsis-unique.dirs