# src/m_token.h File Reference

Go to the source code of this file.

## Data Structures
struct | sGcElem
struct | libmangle_gc_context_t
struct | sMToken_base
struct | sMToken_value
struct | sMToken_name
struct | sMToken_dim
struct | sMToken_Unary
struct | sMToken_binary
union | uMToken
## Defines
#define | MTOKEN_KIND(PT) ((PT)->base.kind)
#define | MTOKEN_SUBKIND(PT) ((PT)->base.subkind)
#define | MTOKEN_CHAIN(PT) ((PT)->base.chain)
#define | MTOKEN_FLAGS(PT) ((PT)->base.flags)
#define | MTOKEN_FLAGS_UDC 0x1
#define | MTOKEN_FLAGS_NOTE 0x2
#define | MTOKEN_FLAGS_PTRREF 0x4
#define | MTOKEN_FLAGS_ARRAY 0x8
#define | MTOKEN_VALUE(PT) ((PT)->value.value)
#define | MTOKEN_VALUE_SIGNED(PT) ((PT)->value.is_signed)
#define | MTOKEN_VALUE_SIZE(PT) ((PT)->value.size)
#define | MTOKEN_NAME(PT) ((PT)->name.name)
#define | MTOKEN_DIM_VALUE(PT) ((PT)->dim.value)
#define | MTOKEN_DIM_NTTP(PT) ((PT)->dim.non_tt_param)
#define | MTOKEN_DIM_NEGATE(PT) ((PT)->dim.beNegate)
#define | MTOKEN_UNARY(PT) ((PT)->unary.unary)
#define | MTOKEN_BINARY_LEFT(PT) ((PT)->binary.left)
#define | MTOKEN_BINARY_RIGHT(PT) ((PT)->binary.right)
## Enumerations
enum | eMToken { eMToken_none = 0, eMToken_value = 1, eMToken_name = 2, eMToken_dim = 3, eMToken_unary = 4, eMToken_binary = 5, eMToken_MAX }
enum | eMSToken { eMST_unmangled = 0, eMST_nttp = 1, eMST_name = 2, eMST_colon = 3, eMST_rtti = 4, eMST_cv = 5, eMST_vftable = 6, eMST_vbtable = 7, eMST_vcall = 8, eMST_opname = 9, eMST_templargname = 10, eMST_type = 11, eMST_dim, eMST_val, eMST_gcarray, eMST_slashed, eMST_array, eMST_element, eMST_template_argument_list, eMST_ltgt, eMST_frame, eMST_throw, eMST_rframe, eMST_destructor, eMST_oper, eMST_colonarray, eMST_lexical_frame, eMST_scope, eMST_udt_returning, eMST_coloncolon, eMST_assign, eMST_templateparam, eMST_nonetypetemplateparam, eMST_exp, eMST_combine, eMST_ecsu, eMST_based }
## Functions
uMToken * | libmangle_gen_tok (libmangle_gc_context_t *gc, enum eMToken kind, enum eMSToken subkind, size_t addend)
void | libmangle_release_gc (libmangle_gc_context_t *gc)
libmangle_gc_context_t * | libmangle_generate_gc (void)
uMToken * | chain_tok (uMToken *l, uMToken *add)
void | libmangle_dump_tok (FILE *fp, uMToken *p)
void | libmangle_print_decl (FILE *fp, uMToken *p)
char * | libmangle_sprint_decl (uMToken *r)
uMToken * | gen_value (libmangle_gc_context_t *gc, enum eMSToken skind, uint64_t val, int is_signed, int size)
uMToken * | gen_name (libmangle_gc_context_t *gc, enum eMSToken skind, const char *name)
uMToken * | gen_dim (libmangle_gc_context_t *gc, enum eMSToken skind, uint64_t val, const char *non_tt_param, int fSigned, int fNegate)
uMToken * | gen_unary (libmangle_gc_context_t *gc, enum eMSToken skind, uMToken *un)
uMToken * | gen_binary (libmangle_gc_context_t *gc, enum eMSToken skind, uMToken *l, uMToken *r)

## Define Documentation

#define MTOKEN_BINARY_LEFT | ( | PT |  | ) | ((PT)->binary.left)

Sets the left node on binary token, PT pointer to a binary uMToken.

#define MTOKEN_BINARY_RIGHT | ( | PT |  | ) | ((PT)->binary.right)

Sets the right node on binary token, PT pointer to a binary uMToken.

#define MTOKEN_CHAIN | ( | PT |  | ) | ((PT)->base.chain)

Sets the pointer to the next token in the chain.

#define MTOKEN_DIM_NEGATE | ( | PT |  | ) | ((PT)->dim.beNegate)

Retrieve or set negative bit on value token, PT pointer to an generic uMToken

#define MTOKEN_DIM_NTTP | ( | PT |  | ) | ((PT)->dim.non_tt_param)

Retrieve or set the template of a token, PT pointer to a name uMToken

#define MTOKEN_DIM_VALUE | ( | PT |  | ) | ((PT)->dim.value)

Retrieve or set the value of a token, PT pointer to a value uMToken

#define MTOKEN_FLAGS | ( | PT |  | ) | ((PT)->base.flags)

Sets flags in base descriptor.

#define MTOKEN_FLAGS_ARRAY 0x8

Decoded fragment has an array-like expression.

#define MTOKEN_FLAGS_NOTE 0x2

Contains "note" name token.

#define MTOKEN_FLAGS_PTRREF 0x4

Decoded fragment is a referrence.

#define MTOKEN_FLAGS_UDC 0x1

Indicates a following "name" token for named struct/union/class.

#define MTOKEN_KIND | ( | PT |  | ) | ((PT)->base.kind)

Sets the token kind, PT pointer to a base uMToken.

#define MTOKEN_NAME | ( | PT |  | ) | ((PT)->name.name)

Retrieve or set the name string, PT pointer to a name uMToken

#define MTOKEN_SUBKIND | ( | PT |  | ) | ((PT)->base.subkind)

Sets the token subkind, PT pointer to a base uMToken.

#define MTOKEN_UNARY | ( | PT |  | ) | ((PT)->unary.unary)

Sets the leaf element on a unary token, PT pointer to a unary uMToken.

#define MTOKEN_VALUE | ( | PT |  | ) | ((PT)->value.value)

Sets the token value. PT pointer to a value uMToken.

#define MTOKEN_VALUE_SIGNED | ( | PT |  | ) | ((PT)->value.is_signed)

Sets the signed bit on value token. PT pointer to a value uMToken.

#define MTOKEN_VALUE_SIZE | ( | PT |  | ) | ((PT)->value.size)

Sets the byte width of value in value token. PT pointer to a value uMToken.

## Enumeration Type Documentation

enum eMSToken

Token "Subkind" enumeration list. Also used by internal function sprint_decl1() for printing.

See also:
  gen_tok()
  eMToken
  sMToken_base

Enumerator:

  eMST_unmangled | Name is unmagled.
  eMST_nttp | Template name.
  eMST_name | Decoded function name.
  eMST_colon | Class member accessibility.
  eMST_rtti | Runtime Type information name.
  eMST_cv | Function call convention / data qualifiers / pointer.
  eMST_vftable | Virtual Function Table.
  eMST_vbtable | Virtual Base Table.
  eMST_vcall | Virtual Function Call.
  eMST_opname | Overloaded operator.
  eMST_templargname | Explicit template arg name.
  eMST_type | Function return type.
  eMST_dim | Print array-like expression. See also: eMToken_dim
  eMST_val | Print value expression. See also: sMToken_val
  eMST_gcarray |
  eMST_slashed | MSVC extenstion: "__gc" Managed C++ reference. MTOKEN_UNARY appended and prepended with "/".
  eMST_array | MTOKEN_UNARY enclosed by square brackets.
  eMST_element | MTOKEN_UNARY in an argument list.
  eMST_template_argument_list | MTOKEN_UNARY in an argument list.
  eMST_ltgt | MTOKEN_UNARY enclosed by angular brackets.
  eMST_frame | MTOKEN_UNARY enclosed by curly brackets.
  eMST_throw | MTOKEN_UNARY prepended by "throw ".
  eMST_rframe | MTOKEN_UNARY enclosed by parentheses.
  eMST_destructor | MTOKEN_UNARY prepended with "~".
  eMST_oper | indicates that token an operand, prints from MTOKEN_UNARY.
  eMST_colonarray |
  eMST_lexical_frame | Unused, to be removed. MTOKEN_UNARY enclosed by single quotes "'".
  eMST_scope | MTOKEN_UNARY, unenclosed.
  eMST_udt_returning | User defined types (RTTI).
  eMST_coloncolon | "::" between MTOKEN_BINARY_LEFT and MTOKEN_BINARY_RIGHT.
  eMST_assign | "=" between MTOKEN_BINARY_LEFT and MTOKEN_BINARY_RIGHT and appended with "}".
  eMST_templateparam | Explicit template.
  eMST_nonetypetemplateparam | Non-explicit template.
  eMST_exp | dim 'e' (exponent) dim
  eMST_combine | Unary grouping.
  eMST_ecsu | Is an Enum/Class/Struct/Union
  eMST_based | MSVC extension: "__based" Based addressing

enum eMToken

Token "Kind" enumeration list.

See also:
  gen_tok()
  eMSToken
  sMToken_base

Enumerator:

  eMToken_none | Token type: None.
  eMToken_value | Token type: Value.
  eMToken_name | Token type: Name.
  eMToken_dim | Token type: Dim.
  eMToken_unary | Token type: Unary
  eMToken_binary | Token type: Binary
  eMToken_MAX | Unused sentinel.

## Function Documentation

uMToken* chain_tok | ( | uMToken * | l,
|  | uMToken * | add |
| ) |  |  |

Chains uMTokens together.

Parameters:

  `[in]` | l | uMtoken chain to link up with.
  `[in]` | add | uMtoken to add to chain.

Returns:
  l unchanged

uMToken* gen_binary | ( | libmangle_gc_context_t * | gc,
|  | enum eMSToken | skind,
|  | uMToken * | l,
|  | uMToken * | r |
| ) |  |  |

Generates a binary node token.

Parameters:

  `[in]` | gc | Pointer to garbage collection context.
  `[in]` | skind | Token subKind.
  `[in]` | l | Left node element.
  `[in]` | r | Right node element.

Returns:
  Pointer to binary token.

See also:
  sMToken_binary

uMToken* gen_dim | ( | libmangle_gc_context_t * | gc,
|  | enum eMSToken | skind,
|  | uint64_t | val,
|  | const char * | non_tt_param,
|  | int | fSigned,
|  | int | fNegate |
| ) |  |  |

Constructs a "dim" kind token.

Parameters:

  `[in]` | gc | Pointer to garbage collection context.
  `[in]` | skind | Token subkind.
  `[in]` | val | Token numerical value.
  `[in]` | non_tt_param | pointer to decoded C++ template name.
  `[in]` | fSigned | Signedness of the numerical value.
  `[in]` | fNegate | 1 for "val" is negative digit.

Returns:
  Pointer to dim token.

See also:
  sMToken_dim

uMToken* gen_name | ( | libmangle_gc_context_t * | gc,
|  | enum eMSToken | skind,
|  | const char * | name |
| ) |  |  |

Constructs a "name" kind token.

Parameters:

  `[in]` | gc | Pointer to garbage collection context.
  `[in]` | skind | Token subkind.
  `[in]` | name | Pointer to name string.

Returns:
  Pointer to name token.

See also:
  sMToken_name

uMToken* gen_unary | ( | libmangle_gc_context_t * | gc,
|  | enum eMSToken | skind,
|  | uMToken * | un |
| ) |  |  |

Constructs a "unary" kind token.

Parameters:

  `[in]` | gc | Pointer to garbage collection context.
  `[in]` | skind | Token subkind.
  `[in]` | un | Pointer to leaf element.

Returns:
  Pointer to a unary token.

See also:
  sMToken_unary

uMToken* gen_value | ( | libmangle_gc_context_t * | gc,
|  | enum eMSToken | skind,
|  | uint64_t | val,
|  | int | is_signed,
|  | int | size |
| ) |  |  |

Constructs a "value" kind token.

Parameters:

  `[in]` | gc | Pointer to garbage collection context.
  `[in]` | skind | Token subkind.
  `[in]` | val | Sets the value on token,
  `[in]` | is_signed | Signed bit of val.
  `[in]` | size | Width of val.

Returns:
  Pointer to value token.

See also:
  sMToken_value

void libmangle_dump_tok | ( | FILE * | fp,
|  | uMToken * | p |
| ) |  |  |

Dumps uMToken to a file descriptor for debugging.

Parameters:

  `[in]` | fp | File descriptor to print the token to.
  `[in]` | p | uMToken chain to print.

uMToken* libmangle_gen_tok | ( | libmangle_gc_context_t * | gc,
|  | enum eMToken | kind,
|  | enum eMSToken | subkind,
|  | size_t | addend |
| ) |  |  |

gen_tok constructs uMToken instances Instances are destroyed with libmangle_release_gc().

Parameters:

  `[in]` | gc | Pointer to garbage collection context.
  `[in]` | kind | Kind of token to construct
  `[in]` | subkind | Subkind of token to construct
  `[in]` | addend | Additional byte padding at the end.

See also:
  libmangle_release_gc()

libmangle_gc_context_t* libmangle_generate_gc | ( | void |  | ) |

Constructs a garbage collection context token.

Returns:
  Pointer to context.

See also:
  libmangle_release_gc()

void libmangle_print_decl | ( | FILE * | fp,
|  | uMToken * | p |
| ) |  |  |

Prints C++ name to file descriptor.

Parameters:

  `[in]` | fp | Output file descriptor.
  `[in]` | p | Token containing information about the C++ name.

See also:
  libmangle_decode_ms_name()

void libmangle_release_gc | ( | libmangle_gc_context_t * | gc | ) |

Releases memory tracked by context.

Parameters:

  `[in]` | gc | Garbage collection context to work on.

See also:
  libmangle_generate_gc()

char* libmangle_sprint_decl | ( | uMToken * | r | ) |

Get pointer to decoded C++ name string. Use free() to release returned string.

Parameters:

  `[in]` | r | C++ name token.

Returns:
  pointer to decoded C++ name string.

See also:
  libmangle_decode_ms_name()