diff options
-rw-r--r-- | ffi.c | 26 | ||||
-rw-r--r-- | txr.1 | 43 |
2 files changed, 69 insertions, 0 deletions
@@ -3542,6 +3542,32 @@ val ffi_type_compile(val syntax) tft->rput = ffi_bool_rput; #endif return type_copy; + } else if (sym == qref_s) { + val args = cdr(syntax); + val type = nil; + struct txr_ffi_type *tft = 0; + + for (; consp(args); args = cdr(args)) { + val next = car(args); + if (!tft) { + type = ffi_type_compile(next); + tft = ffi_type_struct(type); + if (tft->clone != ffi_struct_clone) + uw_throwf(error_s, lit("~a: ~s in ~s isn't a struct/union type"), + self, next, syntax, nao); + } else { + tft = ffi_find_memb(tft, next); + if (!tft) + uw_throwf(error_s, lit("~a: ~s in ~s is a nonexistent member"), + self, next, syntax, nao); + type = tft->self; + } + } + + if (type == nil || args) + uw_throwf(error_s, lit("~a: invalid ~s syntax"), self, sym, nao); + + return type; } uw_throwf(error_s, lit("~a: unrecognized type operator: ~s"), @@ -62971,6 +62971,49 @@ These additional FFI types for common C language types are provided as .code typedef aliases. +.coNP FFI type @ qref +.synb +.mets (qref < struct-type < member1 >> [ member2 ...]) +.syne +.desc +The FFI type operator +.code qref +provides a way to reference the type of a member of a struct or union. +The +.meta struct-type +argument must be a type expression denoting a struct or union. +The +.meta member1 +argument and any additional arguments must be symbols. + +If +.code S +is a struct or union type, and +.code M +is a member, then +.code "(qref S M)" +is a type expression denoting the type of +.codn M . +Moreover, if +.code M +itself is a struct or union, which has a member named +.code N +then the type of +.code N +can be denoted by the expression +.codn "(qref S M N)" . +Similarly, additional symbols reference through additional struct/union +nestings. + +Note: the referencing dot syntax can be used to write +.code qref +expressions. +For instance, +.code "(qref S M N)" +can be written as +.code S.M.N +instead. + .coNP FFI types @, blkcnt-t @, blksize-t @, clockid-t @, dev-t @, fsblkcnt-t @, fsfilcnt-t @, gid-t @, id-t @, ino-t @, key-t @, loff-t @, mode-t @, nlink-t @, off-t @, pid-t @ ssize-t and @ uid-t The additional names of various common POSIX types may also be available, depending on platform. They are provided as |