- Main Page
- Data Structures
- Files

- File List
- Globals

# src/m_token.h

Go to the documentation of this file.

    00001 /*
    00002    Copyright (c) 2009, 2010 mingw-w64 project
    00003
    00004    Contributing authors: Kai Tietz, Jonathan Yong
    00005
    00006    Permission is hereby granted, free of charge, to any person obtaining a
    00007    copy of this software and associated documentation files (the "Software"),
    00008    to deal in the Software without restriction, including without limitation
    00009    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00010    and/or sell copies of the Software, and to permit persons to whom the
    00011    Software is furnished to do so, subject to the following conditions:
    00012
    00013    The above copyright notice and this permission notice shall be included in
    00014    all copies or substantial portions of the Software.
    00015
    00016    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00017    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00018    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00019    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00020    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    00021    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    00022    DEALINGS IN THE SOFTWARE.
    00023 */
    00024 #ifndef _M_TOKEN_HXX
    00025 #define _M_TOKEN_HXX
    00026
    00032 typedef struct sGcElem {
    00033   struct sGcElem *chain;
    00034   size_t length;
    00035   char dta[1];
    00036 } sGcElem;
    00037
    00044 typedef struct libmangle_gc_context_t {
    00045   sGcElem *head;
    00046   sGcElem *tail;
    00047 } libmangle_gc_context_t;
    00048
    00055 typedef enum eMToken {
    00056   eMToken_none = 0,
    00057   eMToken_value = 1,
    00058   eMToken_name = 2,
    00059   eMToken_dim = 3,
    00060   eMToken_unary = 4,
    00061   eMToken_binary = 5,
    00062   eMToken_MAX
    00063 } eMToken;
    00064
    00072 typedef enum eMSToken {
    00073   eMST_unmangled = 0,
    00074   eMST_nttp = 1,
    00075   eMST_name = 2,
    00076   eMST_colon = 3,
    00077   eMST_rtti = 4,
    00078   eMST_cv = 5,
    00079   eMST_vftable = 6,
    00080   eMST_vbtable = 7,
    00081   eMST_vcall = 8,
    00082   eMST_opname = 9,
    00083   eMST_templargname = 10,
    00084   eMST_type = 11,
    00085   eMST_dim,
    00086   eMST_val,
    00087   eMST_gcarray, /* __gc[,,,,] */
    00088   eMST_slashed,
    00089   eMST_array,
    00090   eMST_element,
    00091   eMST_template_argument_list,
    00092   eMST_ltgt,
    00093   eMST_frame,
    00094   eMST_throw,
    00095   eMST_rframe,
    00096   eMST_destructor,
    00097   eMST_oper,
    00098   eMST_colonarray, /* ::[] */
    00099   eMST_lexical_frame,
    00100   eMST_scope,
    00101   eMST_udt_returning,
    00102   eMST_coloncolon,
    00103   eMST_assign,
    00104   eMST_templateparam,
    00105   eMST_nonetypetemplateparam,
    00106   eMST_exp,
    00107   eMST_combine,
    00108   eMST_ecsu,
    00109   eMST_based
    00110 } eMSToken;
    00111
    00116 typedef struct sMToken_base {
    00117   enum eMToken kind;
    00118   enum eMSToken subkind;
    00119   union uMToken *chain;
    00120   int flags;
    00121 } sMToken_base;
    00122
    00124 #define MTOKEN_KIND(PT)         ((PT)->base.kind)
    00125
    00127 #define MTOKEN_SUBKIND(PT)      ((PT)->base.subkind)
    00128
    00130 #define MTOKEN_CHAIN(PT)        ((PT)->base.chain)
    00131
    00133 #define MTOKEN_FLAGS(PT)        ((PT)->base.flags)
    00134
    00135 #define MTOKEN_FLAGS_UDC    0x1
    00136 #define MTOKEN_FLAGS_NOTE   0x2
    00137 #define MTOKEN_FLAGS_PTRREF 0x4
    00138 #define MTOKEN_FLAGS_ARRAY  0x8
    00145 typedef struct sMToken_value {
    00146   sMToken_base base;
    00147   uint64_t value;
    00148   uint64_t size : 5;
    00149   uint64_t is_signed : 1;
    00150 } sMToken_value;
    00151
    00153 #define MTOKEN_VALUE(PT)        ((PT)->value.value)
    00154
    00156 #define MTOKEN_VALUE_SIGNED(PT) ((PT)->value.is_signed)
    00157
    00159 #define MTOKEN_VALUE_SIZE(PT)   ((PT)->value.size)
    00160
    00165 typedef struct sMToken_name {
    00166   sMToken_base base;
    00167   char name[1];
    00168 } sMToken_name;
    00169
    00171 #define MTOKEN_NAME(PT)         ((PT)->name.name)
    00172
    00177 typedef struct sMToken_dim {
    00178   sMToken_base base;
    00179   union uMToken *value;
    00180   union uMToken *non_tt_param;
    00181   int beNegate;
    00182 } sMToken_dim;
    00183
    00185 #define MTOKEN_DIM_VALUE(PT)    ((PT)->dim.value)
    00186
    00188 #define MTOKEN_DIM_NTTP(PT)     ((PT)->dim.non_tt_param)
    00189
    00191 #define MTOKEN_DIM_NEGATE(PT)   ((PT)->dim.beNegate)
    00192
    00197 typedef struct sMToken_Unary
    00198 {
    00199   sMToken_base base;
    00200   union uMToken *unary;
    00201 } sMToken_Unary;
    00202
    00204 #define MTOKEN_UNARY(PT)        ((PT)->unary.unary)
    00205
    00211 typedef struct sMToken_binary {
    00212   sMToken_base base;
    00213   union uMToken *left;
    00214   union uMToken *right;
    00215 } sMToken_binary;
    00216
    00218 #define MTOKEN_BINARY_LEFT(PT)          ((PT)->binary.left)
    00219
    00221 #define MTOKEN_BINARY_RIGHT(PT)         ((PT)->binary.right)
    00222
    00229 typedef union uMToken {
    00230   sMToken_base base;
    00231   sMToken_value value;
    00232   sMToken_name name;
    00233   sMToken_dim dim;
    00234   sMToken_Unary unary;
    00235   sMToken_binary binary;
    00236 } uMToken;
    00237
    00247 uMToken *libmangle_gen_tok (libmangle_gc_context_t *gc, enum eMToken kind, enum eMSToken subkind, size_t addend);
    00248
    00254 void libmangle_release_gc (libmangle_gc_context_t *gc);
    00255
    00261 libmangle_gc_context_t *libmangle_generate_gc (void);
    00262
    00269 uMToken *chain_tok (uMToken *l, uMToken *add);
    00270
    00276 void libmangle_dump_tok (FILE *fp, uMToken *p);
    00277
    00284 void libmangle_print_decl (FILE *fp, uMToken *p);
    00285
    00293 char *libmangle_sprint_decl (uMToken *r);
    00294
    00305 uMToken *gen_value (libmangle_gc_context_t *gc, enum eMSToken skind, uint64_t val, int is_signed, int size);
    00306
    00315 uMToken *gen_name (libmangle_gc_context_t *gc, enum eMSToken skind, const char *name);
    00316
    00328 uMToken *gen_dim (libmangle_gc_context_t *gc, enum eMSToken skind, uint64_t val, const char *non_tt_param, int fSigned, int fNegate);
    00329
    00338 uMToken *gen_unary (libmangle_gc_context_t *gc, enum eMSToken skind, uMToken *un);
    00339
    00349 uMToken *gen_binary (libmangle_gc_context_t *gc, enum eMSToken skind, uMToken *l, uMToken *r);
    00350
    00351 #endif