• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/lib/ffi/uc_cparse.h

  1 /*
  2 ** C declaration parser.
  3 ** Copyright (C) 2005-2025 Mike Pall. See Copyright Notice below.
  4 **
  5 ** This header contains derived work from LuaJIT's FFI C parser.
  6 **
  7 ** Modifications:
  8 ** - Adapted for ucode VM integration
  9 ** - Removed JIT-specific dependencies
 10 **
 11 ** See NOTICE and ATTRIBUTION.md for complete attribution details.
 12 */
 13 
 14 #ifndef _UC_CPARSE_H
 15 #define _UC_CPARSE_H
 16 
 17 #include <ucode/types.h>
 18 #include <ucode/vm.h>
 19 
 20 #include "uc_def.h"
 21 #include "uc_ctype.h"
 22 
 23 /* C parser limits. */
 24 #define CPARSE_MAX_BUF          32768   /* Max. token buffer size. */
 25 #define CPARSE_MAX_DECLSTACK    100     /* Max. declaration stack depth. */
 26 #define CPARSE_MAX_DECLDEPTH    20      /* Max. recursive declaration depth. */
 27 #define CPARSE_MAX_PACKSTACK    7       /* Max. pack pragma stack depth. */
 28 
 29 /* Flags for C parser mode. */
 30 #define CPARSE_MODE_MULTI       1       /* Process multiple declarations. */
 31 #define CPARSE_MODE_ABSTRACT    2       /* Accept abstract declarators. */
 32 #define CPARSE_MODE_DIRECT      4       /* Accept direct declarators. */
 33 #define CPARSE_MODE_FIELD       8       /* Accept field width in bits, too. */
 34 #define CPARSE_MODE_NOIMPLICIT  16      /* Reject implicit declarations. */
 35 #define CPARSE_MODE_SKIP        32      /* Skip definitions, ignore errors. */
 36 
 37 typedef int CPChar;     /* C parser character. Unsigned ext. from char. */
 38 typedef int CPToken;    /* C parser token. */
 39 
 40 /* C parser internal value representation. */
 41 typedef struct CPValue {
 42   union {
 43     int32_t i32;        /* Value for CTID_INT32. */
 44     uint32_t u32;       /* Value for CTID_UINT32. */
 45   };
 46   CTypeID id;           /* C Type ID of the value. */
 47 } CPValue;
 48 
 49 /* C parser state. */
 50 typedef struct CPState {
 51   CPChar c;             /* Current character. */
 52   CPToken tok;          /* Current token. */
 53   CPValue val;          /* Token value. */
 54   CType *ct;            /* C type table entry. */
 55   const char *p;        /* Current position in input buffer. */
 56   CTState *cts;         /* C type state. */
 57   const char *srcname;  /* Current source name. */
 58   size_t linenumber;    /* Input line counter. */
 59   int depth;            /* Recursive declaration depth. */
 60   uint32_t tmask;       /* Type mask for next identifier. */
 61   uint32_t mode;        /* C parser mode. */
 62   uint8_t packstack[CPARSE_MAX_PACKSTACK];  /* Stack for pack pragmas. */
 63   uint8_t curpack;      /* Current position in pack pragma stack. */
 64   uc_vm_t *uv_vm;
 65   struct printbuf pb;
 66   uc_value_t *uv_str;
 67   uc_value_t **uv_param;
 68   char *error;
 69   struct cp_func_ids_buf { size_t count; CTypeID *entries; } func_ids_buf;  /* Optional buffer to collect function type IDs */
 70   struct cp_func_ids_buf *func_ids;     /* Pointer to func_ids_buf or external buffer */
 71 } CPState;
 72 
 73 UC_NOAPI bool uc_cparse(CPState *cp);
 74 
 75 UC_NOAPI int uc_cparse_case(uc_value_t *str, const char *match);
 76 
 77 #endif
 78 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt