/config.cache
*~
*.swp
+php_psi_consts.h
+php_psi_decls.h
+php_psi_macros.h
+php_psi_redirs.h
+php_psi_stdinc.h
+php_psi_structs.h
+php_psi_types.h
+php_psi_va_decls.h
[sys_uio.m4],
[sys_utsname.m4],
[netdb.m4],
+ [netinet_in.m4],
+ [netinet_tcp.m4],
+ [poll.m4],
[syslog.m4],
[time.m4],
[wchar.m4],
PSI_CHECK_SYS_UIO
PSI_CHECK_SYS_UTSNAME
PSI_CHECK_NETDB
+ PSI_CHECK_NETINET_IN
+ PSI_CHECK_NETINET_TCP
+ PSI_CHECK_POLL
PSI_CHECK_SYSLOG
PSI_CHECK_WCHAR
PSI_CHECK_WCTYPE
--- /dev/null
+PSI_CHECK_NETINET_IN() {
+ AC_CHECK_HEADERS(netinet/in.h)
+
+ PSI_TYPE(in_port_t, uint)
+ PSI_TYPE(in_addr_t, uint)
+
+ PSI_STRUCT(struct in_addr, [
+ in_addr_t s_addr]
+ )
+
+ PSI_STRUCT(struct sockaddr_in, [
+ sa_family_t sin_family,
+ in_port_t sin_port,
+ struct in_addr sin_addr]
+ )
+
+ PSI_STRUCT(struct in6_addr, [
+ uint8_t s6_addr@<:@16@:>@]
+ )
+ PSI_STRUCT(struct sockaddr_in6, [
+ sa_family_t sin6_family,
+ in_port_t sin6_port,
+ uint32_t sin6_flowinfo,
+ struct in6_addr sin6_addr,
+ uint32_t sin6_scope_id]
+ )
+
+ PSI_STRUCT(struct ipv6_mreq, [
+ struct in6_addr ipv6mr_multiaddr,
+ unsigned ipv6mr_interface]
+ )
+
+ PSI_CONST(IPPROTO_IP, int)
+ PSI_CONST(IPPROTO_IPV6, int)
+ PSI_CONST(IPPROTO_ICMP, int)
+ PSI_CONST(IPPROTO_RAW, int)
+ PSI_CONST(IPPROTO_TCP, int)
+ PSI_CONST(IPPROTO_UDP, int)
+
+ PSI_CONST(INADDR_ANY, int)
+ PSI_CONST(INADDR_BROADCAST, int)
+ PSI_CONST(INET6_ADDRSTRLEN, int)
+
+ PSI_CONST(IPV6_JOIN_GROUP, int)
+ PSI_CONST(IPV6_LEAVE_GROUP, int)
+ PSI_CONST(IPV6_MULTICAST_HOPS, int)
+ PSI_CONST(IPV6_MULTICAST_IF, int)
+ PSI_CONST(IPV6_MULTICAST_LOOP, int)
+ PSI_CONST(IPV6_UNICAST_HOPS, int)
+ PSI_CONST(IPV6_V6ONLY, int)
+
+ PSI_MACRO(int IN6_IS_ADDR_UNSPECIFIED, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_LOOPBACK, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_MULTICAST, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_LINKLOCAL, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_SITELOCAL, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_V4MAPPED, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_V4COMPAT, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_MC_NODELOCAL, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_MC_LINKLOCAL, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_MC_SITELOCAL, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_MC_ORGLOCAL, [(const struct in6_addr *a)])
+ PSI_MACRO(int IN6_IS_ADDR_MC_GLOBAL, [(const struct in6_addr *a)])
+
+ PSI_EXTVAR(struct in6_addr in6addr_loopback)
+}
--- /dev/null
+PSI_CHECK_NETINET_TCP() {
+ AC_CHECK_HEADERS(netinet/tcp.h)
+
+ PSI_CONST(TCP_NODELAY, int)
+}
--- /dev/null
+PSI_CHECK_POLL() {
+ AC_CHECK_HEADERS(poll.h)
+
+ PSI_STRUCT(struct pollfd, [
+ int fd,
+ short events,
+ short revents]
+ )
+
+ PSI_TYPE(nfds_t, uint)
+
+ PSI_CONST(POLLIN, int)
+ PSI_CONST(POLLRDNORM, int)
+ PSI_CONST(POLLRDBAND, int)
+ PSI_CONST(POLLPRI, int)
+ PSI_CONST(POLLOUT, int)
+ PSI_CONST(POLLWRNORM, int)
+ PSI_CONST(POLLRWBAND, int)
+ PSI_CONST(POLLERR, int)
+ PSI_CONST(POLLHUP, int)
+ PSI_CONST(POLLNVAL, int)
+
+ PSI_DECL(int poll, [(struct pollfd *fds, nfds_t nfds, int timeout)])
+}
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
+#ifdef HAVE_NETINET_TCP_H
+# include <netinet/tcp.h>
+#endif
#ifdef HAVE_ARPA_NAMESER_H
# include <arpa/nameser.h>
#endif
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
+#ifdef HAVE_POLL_H
+# include <poll.h>
+#endif
#ifdef HAVE_RESOLV_H
# include <resolv.h>
#endif
AC_CHECK_ALIGNOF(float)
PSI_TYPE(double)
AC_CHECK_ALIGNOF(double)
+ PSI_TYPE(long double)
+ AC_CHECK_ALIGNOF(long double)
PSI_TYPE(void *)
AC_CHECK_ALIGNOF(void *)
PSI_TYPE(char, int)
+ PSI_TYPE(signed char, int)
PSI_TYPE(unsigned char, uint)
PSI_TYPE(short, int)
+ PSI_TYPE(short int, int)
+ PSI_TYPE(signed short, int)
+ PSI_TYPE(signed short int, int)
PSI_TYPE(unsigned short, uint)
+ PSI_TYPE(unsigned short int, uint)
PSI_TYPE(int, int)
+ PSI_TYPE(signed int, int)
+ PSI_TYPE(signed, int)
PSI_TYPE(unsigned int, uint)
PSI_TYPE(unsigned, uint)
PSI_TYPE(long, int)
+ PSI_TYPE(long int, int)
+ PSI_TYPE(signed long int, int)
PSI_TYPE(unsigned long, uint)
+ PSI_TYPE(unsigned long int, uint)
+ PSI_TYPE(long long, int)
+ PSI_TYPE(long long int, int)
+ PSI_TYPE(signed long long, int)
+ PSI_TYPE(signed long long int, int)
+ PSI_TYPE(unsigned long long, uint)
+ PSI_TYPE(unsigned long long int, uint)
])
return t;
}
+static inline decl_type *init_decl_type_ex(token_t type, int argc, ...) {
+ va_list argv;
+ char *ptr, *arg;
+ unsigned i;
+ size_t len, pos = 0, all = 0;
+ decl_type *t = calloc(1, sizeof(*t));
+
+ va_start(argv, argc);
+ for (i = 0; i < argc; ++i) {
+ arg = va_arg(argv, char *);
+ len = va_arg(argv, size_t);
+
+ if (len) {
+ if (all) {
+ pos = all;
+ ptr = realloc(ptr, 1 + (all += len));
+ } else {
+ ptr = malloc(ptr, 1 + (all = len));
+ }
+ memcpy(ptr + pos, arg, len);
+ }
+ }
+ va_end(argv);
+
+ if (!all) {
+ ptr = calloc(1, 1);
+ } else {
+ ptr[all] = 0;
+ }
+ t->type = type;
+ t->name = ptr;
+ return t;
+}
+
static inline decl_type *real_decl_type(decl_type *type) {
while (type->real) {
type = type->real;
char *cur, *tok, *lim, *eof, *ctx, *mrk, buf[BSIZE];
} PSI_Parser;
+static inline size_t PSI_TokenAllocSize(size_t token_len, size_t fname_len) {
+ return sizeof(PSI_Token) + token_len + fname_len + sizeof(unsigned) + 2;
+}
+
static inline PSI_Token *PSI_TokenAlloc(PSI_Parser *P) {
PSI_Token *T;
size_t token_len, fname_len;
token_len = P->cur - P->tok;
fname_len = strlen(P->psi.file.fn);
- T = calloc(1, sizeof(*T) + token_len + fname_len + sizeof(unsigned) + 2);
+ T = calloc(1, PSI_TokenAllocSize(token_len, fname_len);
T->type = token_typ;
T->size = token_len;
T->text = &T->buf[0];
}
static inline PSI_Token *PSI_TokenCopy(PSI_Token *src) {
- size_t fname_len = strlen(src->file);
- size_t strct_len = sizeof(*src) + src->size + fname_len + sizeof(unsigned) + 2;
+ size_t strct_len = PSI_TokenAllocSize(src->size, strlen(src->file));
PSI_Token *ptr = malloc(strct_len);
memcpy(ptr, src, strct_len);
return ptr;
}
+static inline PSI_Token *PSI_TokenCat(unsigned argc, ...) {
+ va_list argv;
+ unsigned i;
+ PSI_Token *T = NULL;
+
+ va_start(argv, argc);
+ for (i = 0; i < argc; ++i) {
+ PSI_Token *arg = va_arg(argv, PSI_Token *);
+
+ if (T) {
+ size_t fname_len = strlen(T->file);
+
+ T = realloc(T, PSI_TokenAllocSize(T->size + arg->size, fname_len));
+ memmove(&T->buf[T->size + 1], T->file, fname_len + 1);
+ memcpy(T->file - 1, arg->text, arg->size + 1)
+ T->file = &T->buf[T->size + 1];
+ } else {
+ T = PSI_TokenCopy(arg);
+ T->type = PSI_T_NAME;
+ }
+ }
+ va_end(argv);
+
+ return T;
+}
+
static inline const char *PSI_TokenLocation(PSI_Token *t) {
return t ? t->file : "<builtin>:0:0";
}
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include <stdarg.h>
#include "parser.h"
%nonassoc NAME.
%left PLUS MINUS.
%left SLASH ASTERISK.
-%fallback NAME TEMP FREE SET LET RETURN LIB INT UNSIGNED.
+%fallback NAME TEMP FREE SET LET RETURN LIB INT LONG SIGNED UNSIGNED.
file ::= blocks.
type_->token = T;
}
/* unsigned, urgh */
-decl_type(type_) ::= UNSIGNED NAME(T). {
+decl_type(type_) ::= UNSIGNED(U) NAME(N). {
+ PSI_Token *T = PSI_TokenCat(2, U, N);
type_ = init_decl_type(T->type, T->text);
type_->token = T;
- type_->name = realloc(type_->name, T->size + sizeof("unsigned"));
- memmove(type_->name + sizeof("unsigned"), type_->name, T->size);
- memcpy(type_->name, "unsigned", sizeof("unsigned")-1);
- type_->name[sizeof("unsigned")] = ' ';
- type_->name[T->size + sizeof("unsigned")] = 0;
+ free(U);
+ free(N);
+}
+decl_type(type_) ::= SIGNED NAME(T). {
+ type_ = init_decl_type(T->type, T->text);
+ type_->token = T;
+ type_->name = realloc(type_->name, T->size + sizeof("signed"));
+ memmove(type_->name + sizeof("signed"), type_->name, T->size);
+ memcpy(type_->name, "signed", sizeof("signed")-1);
+ type_->name[sizeof("signed")] = ' ';
+ type_->name[T->size + sizeof("signed")] = 0;
}
-/* we have to support plain int here because we have it in our lexer rules */
+/* we have to support plain int, long here because we have it in our lexer rules */
decl_type(type_) ::= INT(T). {
type_ = init_decl_type(PSI_T_NAME, T->text);
type_->token = T;
}
+decl_type(type_) ::= LONG INT(T). {
+ type_ = init_decl_type(PSI_T_NAME, T->text);
+ type_->token = T;
+}
/* structs ! */
decl_type(type_) ::= STRUCT(S) NAME(T). {
type_ = init_decl_type(S->type, T->text);