Index: base/services/eventlog/rpc.c
===================================================================
--- base/services/eventlog/rpc.c	(revision 41348)
+++ base/services/eventlog/rpc.c	(working copy)
@@ -660,7 +660,7 @@
 }
 
 
-void __RPC_FAR *__RPC_USER midl_user_allocate(size_t len)
+void __RPC_FAR *__RPC_USER midl_user_allocate(SIZE_T len)
 {
     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
 }
Index: base/services/umpnpmgr/umpnpmgr.c
===================================================================
--- base/services/umpnpmgr/umpnpmgr.c	(revision 41348)
+++ base/services/umpnpmgr/umpnpmgr.c	(working copy)
@@ -135,7 +135,7 @@
 }
 
 
-void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
+void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
 {
     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
 }
Index: base/services/wlansvc/rpcserver.c
===================================================================
--- base/services/wlansvc/rpcserver.c	(revision 41348)
+++ base/services/wlansvc/rpcserver.c	(working copy)
@@ -525,7 +525,7 @@
     return ERROR_CALL_NOT_IMPLEMENTED;
 }
 
-void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
+void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
 {
     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
 }
Index: base/system/services/rpcserver.c
===================================================================
--- base/system/services/rpcserver.c	(revision 41348)
+++ base/system/services/rpcserver.c	(working copy)
@@ -5084,7 +5084,7 @@
 }
 
 
-void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
+void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
 {
     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
 }
Index: dll/win32/advapi32/service/rpc.c
===================================================================
--- dll/win32/advapi32/service/rpc.c	(revision 41348)
+++ dll/win32/advapi32/service/rpc.c	(working copy)
@@ -12,7 +12,7 @@
 
 
 void __RPC_FAR * __RPC_USER
-midl_user_allocate(size_t len)
+midl_user_allocate(SIZE_T len)
 {
     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
 }
Index: dll/win32/lsasrv/lsasrv.c
===================================================================
--- dll/win32/lsasrv/lsasrv.c	(revision 41348)
+++ dll/win32/lsasrv/lsasrv.c	(working copy)
@@ -51,7 +51,7 @@
 }
 
 
-void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
+void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
 {
     return RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, len);
 }
Index: dll/win32/ole32/moniker.c
===================================================================
--- dll/win32/ole32/moniker.c	(revision 41348)
+++ dll/win32/ole32/moniker.c	(working copy)
@@ -1660,7 +1660,7 @@
     return S_OK;
 }
 
-void * __RPC_USER MIDL_user_allocate(size_t size)
+void * __RPC_USER MIDL_user_allocate(SIZE_T size)
 {
     return HeapAlloc(GetProcessHeap(), 0, size);
 }
Index: dll/win32/ole32/stg_stream.c
===================================================================
--- dll/win32/ole32/stg_stream.c	(revision 41348)
+++ dll/win32/ole32/stg_stream.c	(working copy)
@@ -575,6 +575,10 @@
     return STG_E_ACCESSDENIED;
   }
 
+  /* In simple mode keep the stream size above the small block limit */
+  if (This->parentStorage->ancestorStorage->base.openFlags & STGM_SIMPLE)
+    libNewSize.u.LowPart = max(libNewSize.u.LowPart, LIMIT_TO_USE_SMALL_BLOCK);
+
   if (This->streamSize.u.LowPart == libNewSize.u.LowPart)
     return S_OK;
 
@@ -841,12 +845,18 @@
 
   if (readSuccessful)
   {
+    StorageImpl *root = This->parentStorage->ancestorStorage;
+
     StorageUtl_CopyPropertyToSTATSTG(pstatstg,
 				     &curProperty,
 				     grfStatFlag);
 
     pstatstg->grfMode = This->grfMode;
 
+    /* In simple create mode cbSize is the current pos */
+    if((root->base.openFlags & STGM_SIMPLE) && root->create)
+      pstatstg->cbSize = This->currentPosition;
+
     return S_OK;
   }
 
Index: dll/win32/ole32/storage32.c
===================================================================
--- dll/win32/ole32/storage32.c	(revision 41348)
+++ dll/win32/ole32/storage32.c	(working copy)
@@ -979,6 +979,10 @@
       (grfMode & STGM_TRANSACTED))
     return STG_E_INVALIDFUNCTION;
 
+  /* Can't create a stream on read-only storage */
+  if ( STGM_ACCESS_MODE( This->openFlags ) == STGM_READ )
+    return STG_E_ACCESSDENIED;
+
   /*
    * Check that we're compatible with the parent's storage mode
    * if not in transacted mode
@@ -988,6 +992,9 @@
       return STG_E_ACCESSDENIED;
   }
 
+  if(This->ancestorStorage->base.openFlags & STGM_SIMPLE)
+    if(grfMode & STGM_CREATE) return STG_E_INVALIDFLAG;
+
   /*
    * Initialize the out parameter
    */
@@ -1226,8 +1233,13 @@
     /*
      * An element with this name already exists
      */
-    if (STGM_CREATE_MODE(grfMode) == STGM_CREATE)
-      IStorage_DestroyElement(iface, pwcsName);
+    if (STGM_CREATE_MODE(grfMode) == STGM_CREATE &&
+        STGM_ACCESS_MODE(This->base.openFlags) != STGM_READ)
+    {
+      hr = IStorage_DestroyElement(iface, pwcsName);
+      if (FAILED(hr))
+        return hr;
+    }
     else
     {
       WARN("file already exists\n");
@@ -1792,6 +1804,9 @@
   if (pwcsName==NULL)
     return STG_E_INVALIDPOINTER;
 
+  if ( STGM_ACCESS_MODE( This->base.openFlags ) == STGM_READ )
+    return STG_E_ACCESSDENIED;
+
   /*
    * Create a property enumeration to search the property with the given name
    */
@@ -2383,7 +2398,7 @@
   ILockBytes*  pLkbyt,
   DWORD        openFlags,
   BOOL         fileBased,
-  BOOL         fileCreate)
+  BOOL         create)
 {
   HRESULT     hr = S_OK;
   StgProperty currentProperty;
@@ -2395,19 +2410,13 @@
 
   memset(This, 0, sizeof(StorageImpl));
 
-  /*
-   * Initialize stream list
-   */
-
   list_init(&This->base.strmHead);
 
-  /*
-   * Initialize the virtual function table.
-   */
   This->base.lpVtbl = &Storage32Impl_Vtbl;
   This->base.pssVtbl = &IPropertySetStorage_Vtbl;
   This->base.v_destructor = StorageImpl_Destroy;
   This->base.openFlags = (openFlags & ~STGM_CREATE);
+  This->create = create;
 
   /*
    * This is the top-level storage so initialize the ancestor pointer
@@ -2415,14 +2424,8 @@
    */
   This->base.ancestorStorage = This;
 
-  /*
-   * Initialize the physical support of the storage.
-   */
   This->hFile = hFile;
 
-  /*
-   * Store copy of file path.
-   */
   if(pwcsName) {
       This->pwcsName = HeapAlloc(GetProcessHeap(), 0,
                                 (lstrlenW(pwcsName)+1)*sizeof(WCHAR));
@@ -2445,7 +2448,7 @@
   if (This->bigBlockFile == 0)
     return E_FAIL;
 
-  if (fileCreate)
+  if (create)
   {
     ULARGE_INTEGER size;
     BYTE bigBlockBuffer[BIG_BLOCK_SIZE];
@@ -2526,7 +2529,7 @@
   /*
    * Write the root property (memory only)
    */
-  if (fileCreate)
+  if (create)
   {
     StgProperty rootProp;
     /*
Index: dll/win32/ole32/storage32.h
===================================================================
--- dll/win32/ole32/storage32.h	(revision 41348)
+++ dll/win32/ole32/storage32.h	(working copy)
@@ -255,6 +255,8 @@
    */
   HANDLE           hFile;      /* Physical support for the Docfile */
   LPOLESTR         pwcsName;   /* Full path of the document file */
+  BOOL             create;     /* Was the storage created or opened.
+                                  The behaviour of STGM_SIMPLE depends on this */
 
   /* FIXME: should this be in Storage32BaseImpl ? */
   WCHAR            filename[PROPERTY_NAME_BUFFER_LEN];
Index: dll/win32/ole32/usrmarshal.c
===================================================================
--- dll/win32/ole32/usrmarshal.c	(revision 41348)
+++ dll/win32/ole32/usrmarshal.c	(working copy)
@@ -307,7 +307,7 @@
     RemotableHandle *remhandle = (RemotableHandle *)pBuffer;
     if (remhandle->fContext != WDT_INPROC_CALL)
         RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
-    *handle = (HANDLE)remhandle->u.hInproc;
+    *handle = (HANDLE)(LONG_PTR)remhandle->u.hInproc;
     return pBuffer + sizeof(RemotableHandle);
 }
 
Index: dll/win32/rpcrt4/cproxy.c
===================================================================
--- dll/win32/rpcrt4/cproxy.c	(revision 41348)
+++ dll/win32/rpcrt4/cproxy.c	(working copy)
@@ -2,6 +2,7 @@
  * COM proxy implementation
  *
  * Copyright 2001 Ove Kåven, TransGaming Technologies
+ * Copyright 2009 Alexandre Julliard
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,9 @@
  * TODO: Handle non-i386 architectures
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <stdarg.h>
 
 #define COBJMACROS
@@ -37,21 +41,19 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 
-struct StublessThunk;
-
 /* I don't know what MS's std proxy structure looks like,
    so this probably doesn't match, but that shouldn't matter */
 typedef struct {
   const IRpcProxyBufferVtbl *lpVtbl;
   LPVOID *PVtbl;
   LONG RefCount;
-  const MIDL_STUBLESS_PROXY_INFO *stubless;
   const IID* piid;
   LPUNKNOWN pUnkOuter;
+  IUnknown *base_object;  /* must be at offset 0x10 from PVtbl */
+  IRpcProxyBuffer *base_proxy;
   PCInterfaceName name;
   LPPSFACTORYBUFFER pPSFactory;
   LPRPCCHANNELBUFFER pChannel;
-  struct StublessThunk *thunks;
 } StdProxyImpl;
 
 static const IRpcProxyBufferVtbl StdProxy_Vtbl;
@@ -62,66 +64,109 @@
 
 #include "pshpack1.h"
 
-struct StublessThunk {
+struct thunk {
   BYTE push;
   DWORD index;
-  BYTE call;
+  BYTE jmp;
   LONG handler;
-  BYTE ret;
-  WORD bytes;
-  BYTE pad[3];
 };
 
 #include "poppack.h"
 
-/* adjust the stack size since we don't use Windows's method */
-#define STACK_ADJUST sizeof(DWORD)
+extern void call_stubless_func(void);
+__ASM_GLOBAL_FUNC(call_stubless_func,
+                  "pushl %esp\n\t"  /* pointer to index */
+                  "call " __ASM_NAME("ObjectStubless") "\n\t"
+                  "popl %edx\n\t"  /* args size */
+                  "movl (%esp),%ecx\n\t"  /* return address */
+                  "addl %edx,%esp\n\t"
+                  "jmp *%ecx" );
 
-#define FILL_STUBLESS(x,idx,stk) \
- x->push = 0x68; /* pushl [immediate] */ \
- x->index = (idx); \
- x->call = 0xe8; /* call [near] */ \
- x->handler = (char*)ObjectStubless - (char*)&x->ret; \
- x->ret = 0xc2; /* ret [immediate] */ \
- x->bytes = stk; \
- x->pad[0] = 0x8d; /* leal (%esi),%esi */ \
- x->pad[1] = 0x76; \
- x->pad[2] = 0x00;
+HRESULT WINAPI ObjectStubless(DWORD *args)
+{
+    DWORD index = args[0];
+    void **iface = (void **)args[2];
+    const void **vtbl = (const void **)*iface;
+    const MIDL_STUBLESS_PROXY_INFO *stubless = *(const MIDL_STUBLESS_PROXY_INFO **)(vtbl - 2);
+    const PFORMAT_STRING fs = stubless->ProcFormatString + stubless->FormatStringOffset[index];
 
-static HRESULT WINAPI ObjectStubless(DWORD index)
+    /* store bytes to remove from stack */
+    args[0] = *(const WORD*)(fs + 8);
+    TRACE("(%p)->(%d)([%d bytes]) ret=%08x\n", iface, index, args[0], args[1]);
+
+    return NdrClientCall2(stubless->pStubDesc, fs, args + 2);
+}
+
+#define BLOCK_SIZE 1024
+#define MAX_BLOCKS 64  /* 64k methods should be enough for anybody */
+
+static const struct thunk *method_blocks[MAX_BLOCKS];
+
+static const struct thunk *allocate_block( unsigned int num )
 {
-  char *args = (char*)(&index + 2);
-  LPVOID iface = *(LPVOID*)args;
+    unsigned int i;
+    struct thunk *prev, *block;
 
-  ICOM_THIS_MULTI(StdProxyImpl,PVtbl,iface);
+    block = VirtualAlloc( NULL, BLOCK_SIZE * sizeof(*block),
+                          MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
+    if (!block) return NULL;
 
-  PFORMAT_STRING fs = This->stubless->ProcFormatString + This->stubless->FormatStringOffset[index];
-  unsigned bytes = *(const WORD*)(fs+8) - STACK_ADJUST;
-  TRACE("(%p)->(%d)([%d bytes]) ret=%08x\n", iface, index, bytes, *(DWORD*)(args+bytes));
+    for (i = 0; i < BLOCK_SIZE; i++)
+    {
+        block[i].push    = 0x68; /* pushl */
+        block[i].index   = BLOCK_SIZE * num + i + 3;
+        block[i].jmp     = 0xe9; /* jmp */
+        block[i].handler = (char *)call_stubless_func - (char *)(&block[i].handler + 1);
+    }
+    VirtualProtect( block, BLOCK_SIZE * sizeof(*block), PAGE_EXECUTE_READ, NULL );
+    prev = InterlockedCompareExchangePointer( (void **)&method_blocks[num], block, NULL );
+    if (prev) /* someone beat us to it */
+    {
+        VirtualFree( block, 0, MEM_RELEASE );
+        block = prev;
+    }
+    return block;
+}
 
-  return NdrClientCall2(This->stubless->pStubDesc, fs, args);
+static BOOL fill_stubless_table( IUnknownVtbl *vtbl, DWORD num )
+{
+    const void **entry = (const void **)(vtbl + 1);
+    DWORD i, j;
+
+    if (num - 3 > BLOCK_SIZE * MAX_BLOCKS)
+    {
+        FIXME( "%u methods not supported\n", num );
+        return FALSE;
+    }
+    for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
+    {
+        const struct thunk *block = method_blocks[i];
+        if (!block && !(block = allocate_block( i ))) return FALSE;
+        for (j = 0; j < BLOCK_SIZE && j < num - 3 - i * BLOCK_SIZE; j++, entry++)
+            if (*entry == (LPVOID)-1) *entry = &block[j];
+    }
+    return TRUE;
 }
 
 #else  /* __i386__ */
 
-/* can't do that on this arch */
-struct StublessThunk { int dummy; };
-#define FILL_STUBLESS(x,idx,stk) \
- ERR("stubless proxies are not supported on this architecture\n");
-#define STACK_ADJUST 0
+static BOOL fill_stubless_table( IUnknownVtbl *vtbl, DWORD num )
+{
+    ERR("stubless proxies are not supported on this architecture\n");
+    return FALSE;
+}
 
 #endif  /* __i386__ */
 
-HRESULT WINAPI StdProxy_Construct(REFIID riid,
-                                 LPUNKNOWN pUnkOuter,
-                                 const ProxyFileInfo *ProxyInfo,
-                                 int Index,
-                                 LPPSFACTORYBUFFER pPSFactory,
-                                 LPRPCPROXYBUFFER *ppProxy,
-                                 LPVOID *ppvObj)
+HRESULT StdProxy_Construct(REFIID riid,
+                           LPUNKNOWN pUnkOuter,
+                           const ProxyFileInfo *ProxyInfo,
+                           int Index,
+                           LPPSFACTORYBUFFER pPSFactory,
+                           LPRPCPROXYBUFFER *ppProxy,
+                           LPVOID *ppvObj)
 {
   StdProxyImpl *This;
-  const MIDL_STUBLESS_PROXY_INFO *stubless = NULL;
   PCInterfaceName name = ProxyInfo->pNamesArray[Index];
   CInterfaceProxyVtbl *vtbl = ProxyInfo->pProxyVtblList[Index];
 
@@ -129,14 +174,12 @@
 
   /* TableVersion = 2 means it is the stubless version of CInterfaceProxyVtbl */
   if (ProxyInfo->TableVersion > 1) {
-    stubless = *(const void **)vtbl;
+    ULONG count = ProxyInfo->pStubVtblList[Index]->header.DispatchTableCount;
     vtbl = (CInterfaceProxyVtbl *)((const void **)vtbl + 1);
-    TRACE("stubless=%p\n", stubless);
+    TRACE("stubless vtbl %p: count=%d\n", vtbl->Vtbl, count );
+    fill_stubless_table( (IUnknownVtbl *)vtbl->Vtbl, count );
   }
 
-  TRACE("iid=%s\n", debugstr_guid(vtbl->header.piid));
-  TRACE("vtbl=%p\n", vtbl->Vtbl);
-
   if (!IsEqualGUID(vtbl->header.piid, riid)) {
     ERR("IID mismatch during proxy creation\n");
     return RPC_E_UNEXPECTED;
@@ -145,51 +188,37 @@
   This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(StdProxyImpl));
   if (!This) return E_OUTOFMEMORY;
 
-  if (stubless) {
-    CInterfaceStubVtbl *svtbl = ProxyInfo->pStubVtblList[Index];
-    unsigned long i, count = svtbl->header.DispatchTableCount;
-    /* Maybe the original vtbl is just modified directly to point at
-     * ObjectStublessClientXXX thunks in real Windows, but I don't like it
-     */
-    TRACE("stubless thunks: count=%ld\n", count);
-    This->thunks = HeapAlloc(GetProcessHeap(),0,sizeof(struct StublessThunk)*count);
-    This->PVtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPVOID)*count);
-    for (i=0; i<count; i++) {
-      struct StublessThunk *thunk = &This->thunks[i];
-      if (vtbl->Vtbl[i] == (LPVOID)-1) {
-        PFORMAT_STRING fs = stubless->ProcFormatString + stubless->FormatStringOffset[i];
-        unsigned bytes = *(const WORD*)(fs+8) - STACK_ADJUST;
-        TRACE("method %ld: stacksize=%d\n", i, bytes);
-        FILL_STUBLESS(thunk, i, bytes)
-        This->PVtbl[i] = thunk;
-      }
-      else {
-        memset(thunk, 0, sizeof(struct StublessThunk));
-        This->PVtbl[i] = vtbl->Vtbl[i];
-      }
-    }
-  }
-  else 
-    This->PVtbl = vtbl->Vtbl;
-
+  if (!pUnkOuter) pUnkOuter = (IUnknown *)This;
   This->lpVtbl = &StdProxy_Vtbl;
+  This->PVtbl = vtbl->Vtbl;
   /* one reference for the proxy */
   This->RefCount = 1;
-  This->stubless = stubless;
   This->piid = vtbl->header.piid;
+  This->base_object = NULL;
+  This->base_proxy = NULL;
   This->pUnkOuter = pUnkOuter;
   This->name = name;
   This->pPSFactory = pPSFactory;
   This->pChannel = NULL;
+
+  if(ProxyInfo->pDelegatedIIDs && ProxyInfo->pDelegatedIIDs[Index])
+  {
+      HRESULT r = create_proxy( ProxyInfo->pDelegatedIIDs[Index], NULL,
+                                &This->base_proxy, (void **)&This->base_object );
+      if (FAILED(r))
+      {
+          HeapFree( GetProcessHeap(), 0, This );
+          return r;
+      }
+  }
+
   *ppProxy = (LPRPCPROXYBUFFER)&This->lpVtbl;
   *ppvObj = &This->PVtbl;
-  /* if there is no outer unknown then the caller will control the lifetime
-   * of the proxy object through the proxy buffer, so no need to increment the
-   * ref count of the proxy object */
-  if (pUnkOuter)
-    IUnknown_AddRef((IUnknown *)*ppvObj);
+  IUnknown_AddRef((IUnknown *)*ppvObj);
   IPSFactoryBuffer_AddRef(pPSFactory);
 
+  TRACE( "iid=%s this %p proxy %p obj %p vtbl %p base proxy %p base obj %p\n",
+         debugstr_guid(riid), This, *ppProxy, *ppvObj, This->PVtbl, This->base_proxy, This->base_object );
   return S_OK;
 }
 
@@ -200,11 +229,10 @@
   if (This->pChannel)
     IRpcProxyBuffer_Disconnect(iface);
 
+  if (This->base_object) IUnknown_Release( This->base_object );
+  if (This->base_proxy) IRpcProxyBuffer_Release( This->base_proxy );
+
   IPSFactoryBuffer_Release(This->pPSFactory);
-  if (This->thunks) {
-    HeapFree(GetProcessHeap(),0,This->PVtbl);
-    HeapFree(GetProcessHeap(),0,This->thunks);
-  }
   HeapFree(GetProcessHeap(),0,This);
 }
 
@@ -259,6 +287,7 @@
 
   This->pChannel = pChannel;
   IRpcChannelBuffer_AddRef(pChannel);
+  if (This->base_proxy) IRpcProxyBuffer_Connect( This->base_proxy, pChannel );
   return S_OK;
 }
 
@@ -267,6 +296,8 @@
   ICOM_THIS_MULTI(StdProxyImpl,lpVtbl,iface);
   TRACE("(%p)->Disconnect()\n",This);
 
+  if (This->base_proxy) IRpcProxyBuffer_Disconnect( This->base_proxy );
+
   IRpcChannelBuffer_Release(This->pChannel);
   This->pChannel = NULL;
 }
Index: dll/win32/rpcrt4/cpsf.c
===================================================================
--- dll/win32/rpcrt4/cpsf.c	(revision 41348)
+++ dll/win32/rpcrt4/cpsf.c	(working copy)
@@ -145,6 +145,40 @@
   CStdPSFactory_CreateStub
 };
 
+
+static void init_psfactory( CStdPSFactoryBuffer *psfac, const ProxyFileInfo **file_list )
+{
+    DWORD i, j, k;
+
+    psfac->lpVtbl = &CStdPSFactory_Vtbl;
+    psfac->RefCount = 0;
+    psfac->pProxyFileList = file_list;
+    for (i = 0; file_list[i]; i++)
+    {
+        const PCInterfaceProxyVtblList *proxies = file_list[i]->pProxyVtblList;
+        const PCInterfaceStubVtblList *stubs = file_list[i]->pStubVtblList;
+
+        for (j = 0; j < file_list[i]->TableSize; j++)
+        {
+            /* FIXME: i think that different vtables should be copied for
+             * async interfaces */
+            void * const *pSrcRpcStubVtbl = (void * const *)&CStdStubBuffer_Vtbl;
+            void **pRpcStubVtbl = (void **)&stubs[j]->Vtbl;
+
+            if (file_list[i]->pDelegatedIIDs && file_list[i]->pDelegatedIIDs[j])
+            {
+                fill_delegated_proxy_table( (IUnknownVtbl *)proxies[j]->Vtbl,
+                                            stubs[j]->header.DispatchTableCount );
+                pSrcRpcStubVtbl = (void * const *)&CStdStubBuffer_Delegating_Vtbl;
+            }
+
+            for (k = 0; k < sizeof(IRpcStubBufferVtbl)/sizeof(void *); k++)
+                if (!pRpcStubVtbl[k]) pRpcStubVtbl[k] = pSrcRpcStubVtbl[k];
+        }
+    }
+}
+
+
 /***********************************************************************
  *           NdrDllGetClassObject [RPCRT4.@]
  */
@@ -158,35 +192,8 @@
     pPSFactoryBuffer);
 
   *ppv = NULL;
-  if (!pPSFactoryBuffer->lpVtbl) {
-    const ProxyFileInfo **pProxyFileList2;
-    DWORD max_delegating_vtbl_size = 0;
-    pPSFactoryBuffer->lpVtbl = &CStdPSFactory_Vtbl;
-    pPSFactoryBuffer->RefCount = 0;
-    pPSFactoryBuffer->pProxyFileList = pProxyFileList;
-    for (pProxyFileList2 = pProxyFileList; *pProxyFileList2; pProxyFileList2++) {
-      int i;
-      for (i = 0; i < (*pProxyFileList2)->TableSize; i++) {
-        /* FIXME: i think that different vtables should be copied for
-         * async interfaces */
-        void * const *pSrcRpcStubVtbl = (void * const *)&CStdStubBuffer_Vtbl;
-        void **pRpcStubVtbl = (void **)&(*pProxyFileList2)->pStubVtblList[i]->Vtbl;
-        unsigned int j;
+  if (!pPSFactoryBuffer->lpVtbl) init_psfactory( pPSFactoryBuffer, pProxyFileList );
 
-        if ((*pProxyFileList2)->pDelegatedIIDs && (*pProxyFileList2)->pDelegatedIIDs[i]) {
-          pSrcRpcStubVtbl = (void * const *)&CStdStubBuffer_Delegating_Vtbl;
-          if ((*pProxyFileList2)->pStubVtblList[i]->header.DispatchTableCount > max_delegating_vtbl_size)
-            max_delegating_vtbl_size = (*pProxyFileList2)->pStubVtblList[i]->header.DispatchTableCount;
-        }
-
-        for (j = 0; j < sizeof(IRpcStubBufferVtbl)/sizeof(void *); j++)
-          if (!pRpcStubVtbl[j])
-            pRpcStubVtbl[j] = pSrcRpcStubVtbl[j];
-      }
-    }
-    if(max_delegating_vtbl_size > 0)
-      create_delegating_vtbl(max_delegating_vtbl_size);
-  }
   if (pclsid && IsEqualGUID(rclsid, pclsid))
     return IPSFactoryBuffer_QueryInterface((LPPSFACTORYBUFFER)pPSFactoryBuffer, iid, ppv);
   else {
@@ -207,7 +214,7 @@
  */
 HRESULT WINAPI NdrDllCanUnloadNow(CStdPSFactoryBuffer *pPSFactoryBuffer)
 {
-  return !(pPSFactoryBuffer->RefCount);
+  return pPSFactoryBuffer->RefCount != 0 ? S_FALSE : S_OK;
 }
 
 
@@ -266,7 +273,7 @@
   if (len && len < sizeof(module)) {
       TRACE("registering CLSID %s => %s\n", debugstr_w(clsid), debugstr_w(module));
       if (RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key) == ERROR_SUCCESS) {
-          RegSetValueExW(subkey, NULL, 0, REG_SZ, (const BYTE *)psfactoryW, sizeof(psfactoryW));
+          RegSetValueExW(key, NULL, 0, REG_SZ, (const BYTE *)psfactoryW, sizeof(psfactoryW));
           if (RegCreateKeyW(key, inprocserverW, &subkey) == ERROR_SUCCESS) {
               RegSetValueExW(subkey, NULL, 0, REG_SZ, (LPBYTE)module, (strlenW(module)+1)*sizeof(WCHAR));
               RegSetValueExW(subkey, threadingmodelW, 0, REG_SZ, (const BYTE *)bothW, sizeof(bothW));
Index: dll/win32/rpcrt4/cpsf.h
===================================================================
--- dll/win32/rpcrt4/cpsf.h	(revision 41348)
+++ dll/win32/rpcrt4/cpsf.h	(working copy)
@@ -21,36 +21,25 @@
 #ifndef __WINE_CPSF_H
 #define __WINE_CPSF_H
 
-HRESULT WINAPI StdProxy_Construct(REFIID riid,
-				  LPUNKNOWN pUnkOuter,
-				  const ProxyFileInfo *ProxyInfo,
-				  int Index,
-				  LPPSFACTORYBUFFER pPSFactory,
-				  LPRPCPROXYBUFFER *ppProxy,
-				  LPVOID *ppvObj);
+HRESULT StdProxy_Construct(REFIID riid, LPUNKNOWN pUnkOuter, const ProxyFileInfo *ProxyInfo,
+                           int Index, LPPSFACTORYBUFFER pPSFactory, LPRPCPROXYBUFFER *ppProxy,
+                           LPVOID *ppvObj);
 
-HRESULT WINAPI CStdStubBuffer_Construct(REFIID riid,
-					LPUNKNOWN pUnkServer,
-					PCInterfaceName name,
-					CInterfaceStubVtbl *vtbl,
-					LPPSFACTORYBUFFER pPSFactory,
-					LPRPCSTUBBUFFER *ppStub);
+HRESULT CStdStubBuffer_Construct(REFIID riid, LPUNKNOWN pUnkServer, PCInterfaceName name,
+                                 CInterfaceStubVtbl *vtbl, LPPSFACTORYBUFFER pPSFactory,
+                                 LPRPCSTUBBUFFER *ppStub);
 
-HRESULT WINAPI CStdStubBuffer_Delegating_Construct(REFIID riid,
-                                                   LPUNKNOWN pUnkServer,
-                                                   PCInterfaceName name,
-                                                   CInterfaceStubVtbl *vtbl,
-                                                   REFIID delegating_iid,
-                                                   LPPSFACTORYBUFFER pPSFactory,
-                                                   LPRPCSTUBBUFFER *ppStub);
+HRESULT CStdStubBuffer_Delegating_Construct(REFIID riid, LPUNKNOWN pUnkServer, PCInterfaceName name,
+                                            CInterfaceStubVtbl *vtbl, REFIID delegating_iid,
+                                            LPPSFACTORYBUFFER pPSFactory, LPRPCSTUBBUFFER *ppStub);
 
 const MIDL_SERVER_INFO *CStdStubBuffer_GetServerInfo(IRpcStubBuffer *iface);
 
 const IRpcStubBufferVtbl CStdStubBuffer_Vtbl;
 const IRpcStubBufferVtbl CStdStubBuffer_Delegating_Vtbl;
 
-void create_delegating_vtbl(DWORD num_methods);
-
+BOOL fill_delegated_proxy_table(IUnknownVtbl *vtbl, DWORD num);
+HRESULT create_proxy(REFIID iid, IUnknown *pUnkOuter, IRpcProxyBuffer **pproxy, void **ppv);
 HRESULT create_stub(REFIID iid, IUnknown *pUnk, IRpcStubBuffer **ppstub);
 
 #endif  /* __WINE_CPSF_H */
Index: dll/win32/rpcrt4/cstub.c
===================================================================
--- dll/win32/rpcrt4/cstub.c	(revision 41348)
+++ dll/win32/rpcrt4/cstub.c	(working copy)
@@ -2,6 +2,7 @@
  * COM stub (CStdStubBuffer) implementation
  *
  * Copyright 2001 Ove Kåven, TransGaming Technologies
+ * Copyright 2009 Alexandre Julliard
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -61,12 +62,12 @@
     return (cstdstubbuffer_delegating_t*)((char *)iface - FIELD_OFFSET(cstdstubbuffer_delegating_t, stub_buffer));
 }
 
-HRESULT WINAPI CStdStubBuffer_Construct(REFIID riid,
-                                       LPUNKNOWN pUnkServer,
-                                       PCInterfaceName name,
-                                       CInterfaceStubVtbl *vtbl,
-                                       LPPSFACTORYBUFFER pPSFactory,
-                                       LPRPCSTUBBUFFER *ppStub)
+HRESULT CStdStubBuffer_Construct(REFIID riid,
+                                 LPUNKNOWN pUnkServer,
+                                 PCInterfaceName name,
+                                 CInterfaceStubVtbl *vtbl,
+                                 LPPSFACTORYBUFFER pPSFactory,
+                                 LPRPCSTUBBUFFER *ppStub)
 {
   CStdStubBuffer *This;
   IUnknown *pvServer;
@@ -113,20 +114,16 @@
 {
     DWORD ref;
     DWORD size;
-    void **methods;
     IUnknownVtbl vtbl;
     /* remaining entries in vtbl */
 } ref_counted_vtbl;
 
-static struct
-{
-    ref_counted_vtbl *table;
-} current_vtbl;
+static ref_counted_vtbl *current_vtbl;
 
 
 static HRESULT WINAPI delegating_QueryInterface(IUnknown *pUnk, REFIID iid, void **ppv)
 {
-    *ppv = (void *)pUnk;
+    *ppv = pUnk;
     return S_OK;
 }
 
@@ -161,87 +158,137 @@
 } vtbl_method_t;
 #include "poppack.h"
 
-static void fill_table(IUnknownVtbl *vtbl, void **methods, DWORD num)
+#define BLOCK_SIZE 1024
+#define MAX_BLOCKS 64  /* 64k methods should be enough for anybody */
+
+static const vtbl_method_t *method_blocks[MAX_BLOCKS];
+
+static const vtbl_method_t *allocate_block( unsigned int num )
 {
-    vtbl_method_t *method;
-    void **entry;
-    DWORD i;
+    unsigned int i;
+    vtbl_method_t *prev, *block;
 
+    block = VirtualAlloc( NULL, BLOCK_SIZE * sizeof(*block),
+                          MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
+    if (!block) return NULL;
+
+    for (i = 0; i < BLOCK_SIZE; i++)
+    {
+        block[i].mov1 = 0x0424448b;
+        block[i].mov2 = 0x408b;
+        block[i].sixteen = 0x10;
+        block[i].mov3 = 0x04244489;
+        block[i].mov4 = 0x008b;
+        block[i].mov5 = 0x808b;
+        block[i].offset = (BLOCK_SIZE * num + i + 3) << 2;
+        block[i].jmp = 0xe0ff;
+        block[i].pad[0] = 0x8d;
+        block[i].pad[1] = 0x76;
+        block[i].pad[2] = 0x00;
+    }
+    VirtualProtect( block, BLOCK_SIZE * sizeof(*block), PAGE_EXECUTE_READ, NULL );
+    prev = InterlockedCompareExchangePointer( (void **)&method_blocks[num], block, NULL );
+    if (prev) /* someone beat us to it */
+    {
+        VirtualFree( block, 0, MEM_RELEASE );
+        block = prev;
+    }
+    return block;
+}
+
+static BOOL fill_delegated_stub_table(IUnknownVtbl *vtbl, DWORD num)
+{
+    const void **entry = (const void **)(vtbl + 1);
+    DWORD i, j;
+
+    if (num - 3 > BLOCK_SIZE * MAX_BLOCKS)
+    {
+        FIXME( "%u methods not supported\n", num );
+        return FALSE;
+    }
     vtbl->QueryInterface = delegating_QueryInterface;
     vtbl->AddRef = delegating_AddRef;
     vtbl->Release = delegating_Release;
+    for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
+    {
+        const vtbl_method_t *block = method_blocks[i];
+        if (!block && !(block = allocate_block( i ))) return FALSE;
+        for (j = 0; j < BLOCK_SIZE && j < num - 3 - i * BLOCK_SIZE; j++) *entry++ = &block[j];
+    }
+    return TRUE;
+}
 
-    method = (vtbl_method_t*)methods;
-    entry = (void**)(vtbl + 1);
+BOOL fill_delegated_proxy_table(IUnknownVtbl *vtbl, DWORD num)
+{
+    const void **entry = (const void **)(vtbl + 1);
+    DWORD i, j;
 
-    for(i = 3; i < num; i++)
+    if (num - 3 > BLOCK_SIZE * MAX_BLOCKS)
     {
-        *entry = method;
-        method->mov1 = 0x0424448b;
-        method->mov2 = 0x408b;
-        method->sixteen = 0x10;
-        method->mov3 = 0x04244489;
-        method->mov4 = 0x008b;
-        method->mov5 = 0x808b;
-        method->offset = i << 2;
-        method->jmp = 0xe0ff;
-        method->pad[0] = 0x8d;
-        method->pad[1] = 0x76;
-        method->pad[2] = 0x00;
-
-        method++;
-        entry++;
+        FIXME( "%u methods not supported\n", num );
+        return FALSE;
     }
+    vtbl->QueryInterface = IUnknown_QueryInterface_Proxy;
+    vtbl->AddRef = IUnknown_AddRef_Proxy;
+    vtbl->Release = IUnknown_Release_Proxy;
+    for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
+    {
+        const vtbl_method_t *block = method_blocks[i];
+        if (!block && !(block = allocate_block( i ))) return FALSE;
+        for (j = 0; j < BLOCK_SIZE && j < num - 3 - i * BLOCK_SIZE; j++, entry++)
+            if (!*entry) *entry = &block[j];
+    }
+    return TRUE;
 }
 
 #else  /* __i386__ */
 
-typedef struct {int dummy;} vtbl_method_t;
-static void fill_table(IUnknownVtbl *vtbl, void **methods, DWORD num)
+static BOOL fill_delegated_stub_table(IUnknownVtbl *vtbl, DWORD num)
 {
     ERR("delegated stubs are not supported on this architecture\n");
+    return FALSE;
 }
 
+BOOL fill_delegated_proxy_table(IUnknownVtbl *vtbl, DWORD num)
+{
+    ERR("delegated proxies are not supported on this architecture\n");
+    return FALSE;
+}
+
 #endif  /* __i386__ */
 
-void create_delegating_vtbl(DWORD num_methods)
+static IUnknownVtbl *get_delegating_vtbl(DWORD num_methods)
 {
-    TRACE("%d\n", num_methods);
-    if(num_methods <= 3)
-    {
-        ERR("should have more than %d methods\n", num_methods);
-        return;
-    }
+    IUnknownVtbl *ret;
 
+    if (num_methods < 256) num_methods = 256;  /* avoid frequent reallocations */
+
     EnterCriticalSection(&delegating_vtbl_section);
-    if(!current_vtbl.table || num_methods > current_vtbl.table->size)
+
+    if(!current_vtbl || num_methods > current_vtbl->size)
     {
-        DWORD size;
-        DWORD old_protect;
-        if(current_vtbl.table && current_vtbl.table->ref == 0)
+        ref_counted_vtbl *table = HeapAlloc(GetProcessHeap(), 0,
+                                            FIELD_OFFSET(ref_counted_vtbl, vtbl) + num_methods * sizeof(void*));
+        if (!table)
         {
+            LeaveCriticalSection(&delegating_vtbl_section);
+            return NULL;
+        }
+
+        table->ref = 0;
+        table->size = num_methods;
+        fill_delegated_stub_table(&table->vtbl, num_methods);
+
+        if (current_vtbl && current_vtbl->ref == 0)
+        {
             TRACE("freeing old table\n");
-            VirtualFree(current_vtbl.table->methods, 0, MEM_RELEASE);
-            HeapFree(GetProcessHeap(), 0, current_vtbl.table);
+            HeapFree(GetProcessHeap(), 0, current_vtbl);
         }
-        size = (num_methods - 3) * sizeof(vtbl_method_t);
-        current_vtbl.table = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(ref_counted_vtbl, vtbl) + num_methods * sizeof(void*));
-        current_vtbl.table->ref = 0;
-        current_vtbl.table->size = num_methods;
-        current_vtbl.table->methods = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
-        fill_table(&current_vtbl.table->vtbl, current_vtbl.table->methods, num_methods);
-        VirtualProtect(current_vtbl.table->methods, size, PAGE_EXECUTE_READ, &old_protect);
+        current_vtbl = table;
     }
-    LeaveCriticalSection(&delegating_vtbl_section);
-}
 
-static IUnknownVtbl *get_delegating_vtbl(void)
-{
-    IUnknownVtbl *ret;
-
-    EnterCriticalSection(&delegating_vtbl_section);
-    current_vtbl.table->ref++;
-    ret = &current_vtbl.table->vtbl;
+    current_vtbl->ref++;
+    ret = &current_vtbl->vtbl;
     LeaveCriticalSection(&delegating_vtbl_section);
     return ret;
 }
@@ -253,22 +300,21 @@
     EnterCriticalSection(&delegating_vtbl_section);
     table->ref--;
     TRACE("ref now %d\n", table->ref);
-    if(table->ref == 0 && table != current_vtbl.table)
+    if(table->ref == 0 && table != current_vtbl)
     {
         TRACE("... and we're not current so free'ing\n");
-        VirtualFree(current_vtbl.table->methods, 0, MEM_RELEASE);
         HeapFree(GetProcessHeap(), 0, table);
     }
     LeaveCriticalSection(&delegating_vtbl_section);
 }
 
-HRESULT WINAPI CStdStubBuffer_Delegating_Construct(REFIID riid,
-                                                   LPUNKNOWN pUnkServer,
-                                                   PCInterfaceName name,
-                                                   CInterfaceStubVtbl *vtbl,
-                                                   REFIID delegating_iid,
-                                                   LPPSFACTORYBUFFER pPSFactory,
-                                                   LPRPCSTUBBUFFER *ppStub)
+HRESULT CStdStubBuffer_Delegating_Construct(REFIID riid,
+                                            LPUNKNOWN pUnkServer,
+                                            PCInterfaceName name,
+                                            CInterfaceStubVtbl *vtbl,
+                                            REFIID delegating_iid,
+                                            LPPSFACTORYBUFFER pPSFactory,
+                                            LPRPCSTUBBUFFER *ppStub)
 {
     cstdstubbuffer_delegating_t *This;
     IUnknown *pvServer;
@@ -294,7 +340,7 @@
         return E_OUTOFMEMORY;
     }
 
-    This->base_obj = get_delegating_vtbl();
+    This->base_obj = get_delegating_vtbl( vtbl->header.DispatchTableCount );
     r = create_stub(delegating_iid, (IUnknown*)&This->base_obj, &This->base_stub);
     if(FAILED(r))
     {
Index: dll/win32/rpcrt4/ndr_contexthandle.c
===================================================================
--- dll/win32/rpcrt4/ndr_contexthandle.c	(revision 41348)
+++ dll/win32/rpcrt4/ndr_contexthandle.c	(working copy)
@@ -59,7 +59,7 @@
 
 static struct context_handle_entry *get_context_entry(NDR_CCONTEXT CContext)
 {
-    struct context_handle_entry *che = (struct context_handle_entry*) CContext;
+    struct context_handle_entry *che = CContext;
 
     if (che->magic != NDR_CONTEXT_HANDLE_MAGIC)
         return NULL;
@@ -111,7 +111,7 @@
     }
     else
     {
-        ndr_context_handle *wire_data = (ndr_context_handle *)pBuff;
+        ndr_context_handle *wire_data = pBuff;
         wire_data->attributes = 0;
         wire_data->uuid = GUID_NULL;
     }
Index: dll/win32/rpcrt4/ndr_es.c
===================================================================
--- dll/win32/rpcrt4/ndr_es.c	(revision 41348)
+++ dll/win32/rpcrt4/ndr_es.c	(working copy)
@@ -105,7 +105,7 @@
     handle_t Handle, void *UserState, MIDL_ES_ALLOC AllocFn,
     MIDL_ES_WRITE WriteFn, MIDL_ES_READ ReadFn, MIDL_ES_CODE Operation)
 {
-    MIDL_ES_MESSAGE *pEsMsg = (MIDL_ES_MESSAGE *)Handle;
+    MIDL_ES_MESSAGE *pEsMsg = Handle;
 
     TRACE("(%p, %p, %p, %p, %p, %d)\n", Handle, UserState, AllocFn,
         WriteFn, ReadFn, Operation);
@@ -324,7 +324,7 @@
 {
     /* pointer to start of stack where arguments start */
     RPC_MESSAGE rpcMsg;
-    MIDL_ES_MESSAGE *pEsMsg = (MIDL_ES_MESSAGE *)Handle;
+    MIDL_ES_MESSAGE *pEsMsg = Handle;
     /* size of stack */
     unsigned short stack_size;
     /* header for procedure string */
Index: dll/win32/rpcrt4/ndr_marshall.c
===================================================================
--- dll/win32/rpcrt4/ndr_marshall.c	(revision 41348)
+++ dll/win32/rpcrt4/ndr_marshall.c	(working copy)
@@ -102,9 +102,9 @@
     } while(0)
 
 #define STD_OVERFLOW_CHECK(_Msg) do { \
-    TRACE("buffer=%d/%d\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
+    TRACE("buffer=%d/%d\n", (ULONG)(_Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer), _Msg->BufferLength); \
     if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
-        ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
+        ERR("buffer overflow %d bytes\n", (ULONG)(_Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength))); \
   } while (0)
 
 #define NDR_POINTER_ID_BASE 0x20000
@@ -998,9 +998,8 @@
 /***********************************************************************
  *           PointerMemorySize [internal]
  */
-static unsigned long PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
-                                       unsigned char *Buffer,
-                                       PFORMAT_STRING pFormat)
+static ULONG PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
+                               unsigned char *Buffer, PFORMAT_STRING pFormat)
 {
   unsigned type = pFormat[0], attr = pFormat[1];
   PFORMAT_STRING desc;
@@ -1043,6 +1042,8 @@
   }
 
   if (attr & RPC_FC_P_DEREF) {
+    ALIGN_LENGTH(pStubMsg->MemorySize, sizeof(void*));
+    pStubMsg->MemorySize += sizeof(void*);
     TRACE("deref\n");
   }
 
@@ -1339,8 +1340,8 @@
 /***********************************************************************
  *           EmbeddedPointerMemorySize [internal]
  */
-static unsigned long EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
-                                               PFORMAT_STRING pFormat)
+static ULONG EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
+                                       PFORMAT_STRING pFormat)
 {
   unsigned char *Mark = pStubMsg->BufferMark;
   unsigned rep, count, stride;
@@ -1500,18 +1501,28 @@
 
   TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
 
-  /* Increment the buffer here instead of in PointerUnmarshall,
-   * as that is used by embedded pointers which already handle the incrementing
-   * the buffer, and shouldn't read any additional pointer data from the
-   * buffer */
-  if (*pFormat != RPC_FC_RP)
+  if (*pFormat == RPC_FC_RP)
   {
+    Buffer = pStubMsg->Buffer;
+    /* Do the NULL ref pointer check here because embedded pointers can be
+     * NULL if the type the pointer is embedded in was allocated rather than
+     * being passed in by the client */
+    if (pStubMsg->IsClient && !*ppMemory)
+    {
+      ERR("NULL ref pointer is not allowed\n");
+      RpcRaiseException(RPC_X_NULL_REF_POINTER);
+    }
+  }
+  else
+  {
+    /* Increment the buffer here instead of in PointerUnmarshall,
+     * as that is used by embedded pointers which already handle the incrementing
+     * the buffer, and shouldn't read any additional pointer data from the
+     * buffer */
     ALIGN_POINTER(pStubMsg->Buffer, 4);
     Buffer = pStubMsg->Buffer;
     safe_buffer_increment(pStubMsg, 4);
   }
-  else
-    Buffer = pStubMsg->Buffer;
 
   PointerUnmarshall(pStubMsg, Buffer, ppMemory, *ppMemory, pFormat, fMustAlloc);
 
@@ -1545,10 +1556,14 @@
 ULONG WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
                                   PFORMAT_STRING pFormat)
 {
-  /* unsigned size = *(LPWORD)(pFormat+2); */
-  FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
-  PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
-  return 0;
+    unsigned char *Buffer = pStubMsg->Buffer;
+    if (*pFormat != RPC_FC_RP)
+    {
+        ALIGN_POINTER(pStubMsg->Buffer, 4);
+        safe_buffer_increment(pStubMsg, 4);
+    }
+    ALIGN_LENGTH(pStubMsg->MemorySize, 4);
+    return PointerMemorySize(pStubMsg, Buffer, pFormat);
 }
 
 /***********************************************************************
@@ -2559,8 +2574,8 @@
 } NDR_RANGE;
 #include "poppack.h"
 
-static unsigned long EmbeddedComplexSize(MIDL_STUB_MESSAGE *pStubMsg,
-                                         PFORMAT_STRING pFormat)
+static ULONG EmbeddedComplexSize(MIDL_STUB_MESSAGE *pStubMsg,
+                                 PFORMAT_STRING pFormat)
 {
   switch (*pFormat) {
   case RPC_FC_STRUCT:
@@ -2621,8 +2636,8 @@
 }
 
 
-static unsigned long EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
-                                               PFORMAT_STRING pFormat)
+static ULONG EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
+                                       PFORMAT_STRING pFormat)
 {
   NDR_MEMORYSIZE m = NdrMemorySizer[*pFormat & NDR_TABLE_MASK];
 
@@ -2643,7 +2658,7 @@
 {
   PFORMAT_STRING desc;
   NDR_MARSHALL m;
-  unsigned long size;
+  ULONG size;
 
   while (*pFormat != RPC_FC_END) {
     switch (*pFormat) {
@@ -2732,7 +2747,7 @@
       pFormat += 2;
       desc = pFormat + *(const SHORT*)pFormat;
       size = EmbeddedComplexSize(pStubMsg, desc);
-      TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
+      TRACE("embedded complex (size=%d) <= %p\n", size, pMemory);
       m = NdrMarshaller[*desc & NDR_TABLE_MASK];
       if (m)
       {
@@ -2768,7 +2783,7 @@
 {
   PFORMAT_STRING desc;
   NDR_UNMARSHALL m;
-  unsigned long size;
+  ULONG size;
 
   while (*pFormat != RPC_FC_END) {
     switch (*pFormat) {
@@ -2858,7 +2873,7 @@
       pFormat += 2;
       desc = pFormat + *(const SHORT*)pFormat;
       size = EmbeddedComplexSize(pStubMsg, desc);
-      TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
+      TRACE("embedded complex (size=%d) => %p\n", size, pMemory);
       if (fMustAlloc)
         /* we can't pass fMustAlloc=TRUE into the marshaller for this type
          * since the type is part of the memory block that is encompassed by
@@ -2900,7 +2915,7 @@
 {
   PFORMAT_STRING desc;
   NDR_BUFFERSIZE m;
-  unsigned long size;
+  ULONG size;
 
   while (*pFormat != RPC_FC_END) {
     switch (*pFormat) {
@@ -3005,7 +3020,7 @@
 {
   PFORMAT_STRING desc;
   NDR_FREE m;
-  unsigned long size;
+  ULONG size;
 
   while (*pFormat != RPC_FC_END) {
     switch (*pFormat) {
@@ -3080,12 +3095,12 @@
   return pMemory;
 }
 
-static unsigned long ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
-                                             PFORMAT_STRING pFormat,
-                                             PFORMAT_STRING pPointer)
+static ULONG ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
+                                     PFORMAT_STRING pFormat,
+                                     PFORMAT_STRING pPointer)
 {
   PFORMAT_STRING desc;
-  unsigned long size = 0;
+  ULONG size = 0;
 
   while (*pFormat != RPC_FC_END) {
     switch (*pFormat) {
@@ -3179,11 +3194,10 @@
   return size;
 }
 
-unsigned long ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg,
-                                PFORMAT_STRING pFormat)
+ULONG ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat)
 {
   PFORMAT_STRING desc;
-  unsigned long size = 0;
+  ULONG size = 0;
 
   while (*pFormat != RPC_FC_END) {
     switch (*pFormat) {
@@ -3264,18 +3278,18 @@
   {
     int saved_ignore_embedded = pStubMsg->IgnoreEmbeddedPointers;
     /* save buffer length */
-    unsigned long saved_buffer_length = pStubMsg->BufferLength;
+    ULONG saved_buffer_length = pStubMsg->BufferLength;
 
     /* get the buffer pointer after complex array data, but before
      * pointer data */
-    pStubMsg->BufferLength = pStubMsg->Buffer - pStubMsg->BufferStart;
+    pStubMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
     pStubMsg->IgnoreEmbeddedPointers = 1;
     NdrComplexStructBufferSize(pStubMsg, pMemory, pFormat);
     pStubMsg->IgnoreEmbeddedPointers = saved_ignore_embedded;
 
     /* save it for use by embedded pointer code later */
-    pStubMsg->PointerBufferMark = pStubMsg->BufferStart + pStubMsg->BufferLength;
-    TRACE("difference = 0x%x\n", pStubMsg->PointerBufferMark - pStubMsg->Buffer);
+    pStubMsg->PointerBufferMark = (unsigned char *)pStubMsg->RpcMsg->Buffer + pStubMsg->BufferLength;
+    TRACE("difference = 0x%x\n", (ULONG)(pStubMsg->PointerBufferMark - pStubMsg->Buffer));
     pointer_buffer_mark_set = 1;
 
     /* restore the original buffer length */
@@ -3294,7 +3308,7 @@
 
   if (conf_array)
   {
-    unsigned long struct_size = ComplexStructSize(pStubMsg, pFormat);
+    ULONG struct_size = ComplexStructSize(pStubMsg, pFormat);
     array_compute_and_write_conformance(conf_array[0], pStubMsg,
                                         pMemory + struct_size, conf_array);
     /* these could be changed in ComplexMarshall so save them for later */
@@ -3361,7 +3375,7 @@
 
     /* save it for use by embedded pointer code later */
     pStubMsg->PointerBufferMark = pStubMsg->Buffer;
-    TRACE("difference = 0x%lx\n", (unsigned long)(pStubMsg->PointerBufferMark - saved_buffer));
+    TRACE("difference = 0x%x\n", (ULONG)(pStubMsg->PointerBufferMark - saved_buffer));
     pointer_buffer_mark_set = 1;
 
     /* restore the original buffer */
@@ -3438,7 +3452,7 @@
   if(!pStubMsg->IgnoreEmbeddedPointers && !pStubMsg->PointerLength)
   {
     int saved_ignore_embedded = pStubMsg->IgnoreEmbeddedPointers;
-    unsigned long saved_buffer_length = pStubMsg->BufferLength;
+    ULONG saved_buffer_length = pStubMsg->BufferLength;
 
     /* get the buffer length after complex struct data, but before
      * pointer data */
@@ -3449,7 +3463,7 @@
     /* save it for use by embedded pointer code later */
     pStubMsg->PointerLength = pStubMsg->BufferLength;
     pointer_length_set = 1;
-    TRACE("difference = 0x%lx\n", pStubMsg->PointerLength - saved_buffer_length);
+    TRACE("difference = 0x%x\n", pStubMsg->PointerLength - saved_buffer_length);
 
     /* restore the original buffer length */
     pStubMsg->BufferLength = saved_buffer_length;
@@ -3465,7 +3479,7 @@
 
   if (conf_array)
   {
-    unsigned long struct_size = ComplexStructSize(pStubMsg, pFormat);
+    ULONG struct_size = ComplexStructSize(pStubMsg, pFormat);
     array_compute_and_size_conformance(conf_array[0], pStubMsg, pMemory + struct_size,
                                        conf_array);
 
@@ -3823,21 +3837,21 @@
     /* save buffer fields that may be changed by buffer sizer functions
      * and that may be needed later on */
     int saved_ignore_embedded = pStubMsg->IgnoreEmbeddedPointers;
-    unsigned long saved_buffer_length = pStubMsg->BufferLength;
-    unsigned long saved_max_count = pStubMsg->MaxCount;
-    unsigned long saved_offset = pStubMsg->Offset;
-    unsigned long saved_actual_count = pStubMsg->ActualCount;
+    ULONG saved_buffer_length = pStubMsg->BufferLength;
+    ULONG_PTR saved_max_count = pStubMsg->MaxCount;
+    ULONG saved_offset = pStubMsg->Offset;
+    ULONG saved_actual_count = pStubMsg->ActualCount;
 
     /* get the buffer pointer after complex array data, but before
      * pointer data */
-    pStubMsg->BufferLength = pStubMsg->Buffer - pStubMsg->BufferStart;
+    pStubMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
     pStubMsg->IgnoreEmbeddedPointers = 1;
     NdrComplexArrayBufferSize(pStubMsg, pMemory, pFormat);
     pStubMsg->IgnoreEmbeddedPointers = saved_ignore_embedded;
 
     /* save it for use by embedded pointer code later */
-    pStubMsg->PointerBufferMark = pStubMsg->BufferStart + pStubMsg->BufferLength;
-    TRACE("difference = 0x%x\n", pStubMsg->Buffer - pStubMsg->BufferStart);
+    pStubMsg->PointerBufferMark = (unsigned char *)pStubMsg->RpcMsg->Buffer + pStubMsg->BufferLength;
+    TRACE("difference = 0x%x\n", (ULONG)(pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer));
     pointer_buffer_mark_set = 1;
 
     /* restore fields */
@@ -3915,7 +3929,7 @@
   size = pStubMsg->MemorySize;
   pStubMsg->IgnoreEmbeddedPointers = saved_ignore_embedded;
 
-  TRACE("difference = 0x%lx\n", (unsigned long)(pStubMsg->Buffer - saved_buffer));
+  TRACE("difference = 0x%x\n", (ULONG)(pStubMsg->Buffer - saved_buffer));
   if (!pStubMsg->PointerBufferMark)
   {
     /* save it for use by embedded pointer code later */
@@ -3979,10 +3993,10 @@
     /* save buffer fields that may be changed by buffer sizer functions
      * and that may be needed later on */
     int saved_ignore_embedded = pStubMsg->IgnoreEmbeddedPointers;
-    unsigned long saved_buffer_length = pStubMsg->BufferLength;
-    unsigned long saved_max_count = pStubMsg->MaxCount;
-    unsigned long saved_offset = pStubMsg->Offset;
-    unsigned long saved_actual_count = pStubMsg->ActualCount;
+    ULONG saved_buffer_length = pStubMsg->BufferLength;
+    ULONG_PTR saved_max_count = pStubMsg->MaxCount;
+    ULONG saved_offset = pStubMsg->Offset;
+    ULONG saved_actual_count = pStubMsg->ActualCount;
 
     /* get the buffer pointer after complex array data, but before
      * pointer data */
@@ -4237,7 +4251,7 @@
   unsigned index = *(const WORD*)&pFormat[2];
   DWORD bufsize = *(const WORD*)&pFormat[6];
   USER_MARSHAL_CB umcb;
-  unsigned long saved_buffer_length = 0;
+  ULONG saved_buffer_length = 0;
 
   TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
   TRACE("index=%d\n", index);
@@ -4891,7 +4905,7 @@
 {
     unsigned char type;
     unsigned char alignment;
-    unsigned long total_size;
+    ULONG total_size;
 } NDR_LGFARRAY_FORMAT;
 #include "poppack.h"
 
@@ -4903,7 +4917,7 @@
                                 PFORMAT_STRING pFormat)
 {
     const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
-    unsigned long total_size;
+    ULONG total_size;
 
     TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
 
@@ -4946,7 +4960,7 @@
                                 unsigned char fMustAlloc)
 {
     const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
-    unsigned long total_size;
+    ULONG total_size;
     unsigned char *saved_buffer;
 
     TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
@@ -5001,7 +5015,7 @@
                                 PFORMAT_STRING pFormat)
 {
     const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
-    unsigned long total_size;
+    ULONG total_size;
 
     TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
 
@@ -5413,7 +5427,7 @@
 }
 
 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
-                                                             unsigned long discriminant,
+                                                             ULONG discriminant,
                                                              PFORMAT_STRING pFormat)
 {
     unsigned short num_arms, arm, type;
@@ -5436,13 +5450,13 @@
     {
         if(type == 0xffff)
         {
-            ERR("no arm for 0x%lx and no default case\n", discriminant);
+            ERR("no arm for 0x%x and no default case\n", discriminant);
             RpcRaiseException(RPC_S_INVALID_TAG);
             return NULL;
         }
         if(type == 0)
         {
-            TRACE("falling back to empty default case for 0x%lx\n", discriminant);
+            TRACE("falling back to empty default case for 0x%x\n", discriminant);
             return NULL;
         }
     }
@@ -5547,7 +5561,6 @@
             case RPC_FC_UP:
             case RPC_FC_OP:
             case RPC_FC_FP:
-                **(void***)ppMemory = NULL;
                 ALIGN_POINTER(pStubMsg->Buffer, 4);
                 saved_buffer = pStubMsg->Buffer;
                 if (pStubMsg->PointerBufferMark)
@@ -5782,10 +5795,18 @@
     if (fMustAlloc)
         *ppMemory = NdrAllocate(pStubMsg, size);
 
+    /* we can't pass fMustAlloc=TRUE into the marshaller for the arm
+     * since the arm is part of the memory block that is encompassed by
+     * the whole union. Memory is forced to allocate when pointers
+     * are set to NULL, so we emulate that part of fMustAlloc=TRUE by
+     * clearing the memory we pass in to the unmarshaller */
+    if (fMustAlloc)
+        memset(*ppMemory, 0, size);
+
     NdrBaseTypeUnmarshall(pStubMsg, ppMemory, &switch_type, FALSE);
     pMemoryArm = *ppMemory + increment;
 
-    return union_arm_unmarshall(pStubMsg, &pMemoryArm, switch_value, pFormat, fMustAlloc);
+    return union_arm_unmarshall(pStubMsg, &pMemoryArm, switch_value, pFormat, FALSE);
 }
 
 /***********************************************************************
@@ -5889,10 +5910,10 @@
     return union_arm_marshall(pStubMsg, pMemory, pStubMsg->MaxCount, pFormat + *(const SHORT*)pFormat);
 }
 
-static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
+static LONG unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
                                     PFORMAT_STRING *ppFormat)
 {
-    long discriminant = 0;
+    LONG discriminant = 0;
 
     switch(**ppFormat)
     {
@@ -5945,7 +5966,7 @@
                                 PFORMAT_STRING pFormat,
                                 unsigned char fMustAlloc)
 {
-    long discriminant;
+    LONG discriminant;
     unsigned short size;
 
     TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
@@ -5953,7 +5974,7 @@
 
     /* Unmarshall discriminant */
     discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
-    TRACE("unmarshalled discriminant %lx\n", discriminant);
+    TRACE("unmarshalled discriminant %x\n", discriminant);
 
     pFormat += *(const SHORT*)pFormat;
 
@@ -5964,7 +5985,15 @@
     if (fMustAlloc)
         *ppMemory = NdrAllocate(pStubMsg, size);
 
-    return union_arm_unmarshall(pStubMsg, ppMemory, discriminant, pFormat, fMustAlloc);
+    /* we can't pass fMustAlloc=TRUE into the marshaller for the arm
+     * since the arm is part of the memory block that is encompassed by
+     * the whole union. Memory is forced to allocate when pointers
+     * are set to NULL, so we emulate that part of fMustAlloc=TRUE by
+     * clearing the memory we pass in to the unmarshaller */
+    if (fMustAlloc)
+        memset(*ppMemory, 0, size);
+
+    return union_arm_unmarshall(pStubMsg, ppMemory, discriminant, pFormat, FALSE);
 }
 
 /***********************************************************************
@@ -6179,68 +6208,68 @@
     TRACE("base_type = 0x%02x, low_value = %d, high_value = %d\n",
         base_type, pRange->low_value, pRange->high_value);
 
-#define RANGE_UNMARSHALL(type, format_spec) \
+#define RANGE_UNMARSHALL(mem_type, wire_type, format_spec) \
     do \
     { \
-        ALIGN_POINTER(pStubMsg->Buffer, sizeof(type)); \
+        ALIGN_POINTER(pStubMsg->Buffer, sizeof(wire_type)); \
         if (!fMustAlloc && !*ppMemory) \
             fMustAlloc = TRUE; \
         if (fMustAlloc) \
-            *ppMemory = NdrAllocate(pStubMsg, sizeof(type)); \
-        if (pStubMsg->Buffer + sizeof(type) > pStubMsg->BufferEnd) \
+            *ppMemory = NdrAllocate(pStubMsg, sizeof(mem_type)); \
+        if (pStubMsg->Buffer + sizeof(wire_type) > pStubMsg->BufferEnd) \
         { \
             ERR("buffer overflow - Buffer = %p, BufferEnd = %p\n", \
                 pStubMsg->Buffer, (unsigned char *)pStubMsg->RpcMsg->Buffer + pStubMsg->BufferLength); \
             RpcRaiseException(RPC_X_BAD_STUB_DATA); \
         } \
-        if ((*(type *)pStubMsg->Buffer < (type)pRange->low_value) || \
-            (*(type *)pStubMsg->Buffer > (type)pRange->high_value)) \
+        if ((*(wire_type *)pStubMsg->Buffer < (mem_type)pRange->low_value) || \
+            (*(wire_type *)pStubMsg->Buffer > (mem_type)pRange->high_value)) \
         { \
             ERR("value exceeded bounds: " format_spec ", low: " format_spec ", high: " format_spec "\n", \
-                *(type *)pStubMsg->Buffer, (type)pRange->low_value, \
-                (type)pRange->high_value); \
+                *(wire_type *)pStubMsg->Buffer, (mem_type)pRange->low_value, \
+                (mem_type)pRange->high_value); \
             RpcRaiseException(RPC_S_INVALID_BOUND); \
             return NULL; \
         } \
         TRACE("*ppMemory: %p\n", *ppMemory); \
-        **(type **)ppMemory = *(type *)pStubMsg->Buffer; \
-        pStubMsg->Buffer += sizeof(type); \
+        **(mem_type **)ppMemory = *(wire_type *)pStubMsg->Buffer; \
+        pStubMsg->Buffer += sizeof(wire_type); \
     } while (0)
 
     switch(base_type)
     {
     case RPC_FC_CHAR:
     case RPC_FC_SMALL:
-        RANGE_UNMARSHALL(UCHAR, "%d");
+        RANGE_UNMARSHALL(UCHAR, UCHAR, "%d");
         TRACE("value: 0x%02x\n", **ppMemory);
         break;
     case RPC_FC_BYTE:
     case RPC_FC_USMALL:
-        RANGE_UNMARSHALL(CHAR, "%u");
+        RANGE_UNMARSHALL(CHAR, CHAR, "%u");
         TRACE("value: 0x%02x\n", **ppMemory);
         break;
     case RPC_FC_WCHAR: /* FIXME: valid? */
     case RPC_FC_USHORT:
-        RANGE_UNMARSHALL(USHORT, "%u");
+        RANGE_UNMARSHALL(USHORT, USHORT, "%u");
         TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
         break;
     case RPC_FC_SHORT:
-        RANGE_UNMARSHALL(SHORT, "%d");
+        RANGE_UNMARSHALL(SHORT, SHORT, "%d");
         TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
         break;
     case RPC_FC_LONG:
-        RANGE_UNMARSHALL(LONG, "%d");
+    case RPC_FC_ENUM32:
+        RANGE_UNMARSHALL(LONG, LONG, "%d");
         TRACE("value: 0x%08x\n", **(ULONG **)ppMemory);
         break;
     case RPC_FC_ULONG:
-        RANGE_UNMARSHALL(ULONG, "%u");
+        RANGE_UNMARSHALL(ULONG, ULONG, "%u");
         TRACE("value: 0x%08x\n", **(ULONG **)ppMemory);
         break;
     case RPC_FC_ENUM16:
-    case RPC_FC_ENUM32:
-        FIXME("Unhandled enum type\n");
+        RANGE_UNMARSHALL(UINT, USHORT, "%u");
+        TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
         break;
-    case RPC_FC_ERROR_STATUS_T: /* FIXME: valid? */
     case RPC_FC_FLOAT:
     case RPC_FC_DOUBLE:
     case RPC_FC_HYPER:
@@ -6538,36 +6567,51 @@
     case RPC_FC_WCHAR:
     case RPC_FC_SHORT:
     case RPC_FC_USHORT:
+        ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
         safe_buffer_increment(pStubMsg, sizeof(USHORT));
+        ALIGN_LENGTH(pStubMsg->MemorySize, sizeof(USHORT));
         pStubMsg->MemorySize += sizeof(USHORT);
         return sizeof(USHORT);
     case RPC_FC_LONG:
     case RPC_FC_ULONG:
     case RPC_FC_ENUM32:
+        ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
         safe_buffer_increment(pStubMsg, sizeof(ULONG));
+        ALIGN_LENGTH(pStubMsg->MemorySize, sizeof(ULONG));
         pStubMsg->MemorySize += sizeof(ULONG);
         return sizeof(ULONG);
     case RPC_FC_FLOAT:
+        ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
         safe_buffer_increment(pStubMsg, sizeof(float));
+        ALIGN_LENGTH(pStubMsg->MemorySize, sizeof(float));
         pStubMsg->MemorySize += sizeof(float);
         return sizeof(float);
     case RPC_FC_DOUBLE:
+        ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
         safe_buffer_increment(pStubMsg, sizeof(double));
+        ALIGN_LENGTH(pStubMsg->MemorySize, sizeof(double));
         pStubMsg->MemorySize += sizeof(double);
         return sizeof(double);
     case RPC_FC_HYPER:
+        ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
         safe_buffer_increment(pStubMsg, sizeof(ULONGLONG));
+        ALIGN_LENGTH(pStubMsg->MemorySize, sizeof(ULONGLONG));
         pStubMsg->MemorySize += sizeof(ULONGLONG);
         return sizeof(ULONGLONG);
     case RPC_FC_ERROR_STATUS_T:
+        ALIGN_POINTER(pStubMsg->Buffer, sizeof(error_status_t));
         safe_buffer_increment(pStubMsg, sizeof(error_status_t));
+        ALIGN_LENGTH(pStubMsg->MemorySize, sizeof(error_status_t));
         pStubMsg->MemorySize += sizeof(error_status_t);
         return sizeof(error_status_t);
     case RPC_FC_ENUM16:
+        ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
         safe_buffer_increment(pStubMsg, sizeof(USHORT));
+        ALIGN_LENGTH(pStubMsg->MemorySize, sizeof(UINT));
         pStubMsg->MemorySize += sizeof(UINT);
         return sizeof(UINT);
     case RPC_FC_IGNORE:
+        ALIGN_LENGTH(pStubMsg->MemorySize, sizeof(void *));
         pStubMsg->MemorySize += sizeof(void *);
         return sizeof(void *);
     default:
@@ -6627,7 +6671,7 @@
     if (pFormat[1] & 0x80)
         NdrClientContextMarshall(pStubMsg, *(NDR_CCONTEXT **)pMemory, FALSE);
     else
-        NdrClientContextMarshall(pStubMsg, (NDR_CCONTEXT *)pMemory, FALSE);
+        NdrClientContextMarshall(pStubMsg, pMemory, FALSE);
 
     return NULL;
 }
Index: dll/win32/rpcrt4/ndr_misc.h
===================================================================
--- dll/win32/rpcrt4/ndr_misc.h	(revision 41348)
+++ dll/win32/rpcrt4/ndr_misc.h	(working copy)
@@ -62,6 +62,6 @@
 extern const NDR_MEMORYSIZE NdrMemorySizer[];
 extern const NDR_FREE       NdrFreer[];
 
-unsigned long ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat);
+ULONG ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat);
 
 #endif  /* __WINE_NDR_MISC_H */
Index: dll/win32/rpcrt4/ndr_ole.c
===================================================================
--- dll/win32/rpcrt4/ndr_ole.c	(revision 41348)
+++ dll/win32/rpcrt4/ndr_ole.c	(working copy)
@@ -354,7 +354,7 @@
 /***********************************************************************
  *           NdrOleAllocate [RPCRT4.@]
  */
-void * WINAPI NdrOleAllocate(size_t Size)
+void * WINAPI NdrOleAllocate(SIZE_T Size)
 {
   if (!LoadCOM()) return NULL;
   return COM_MemAlloc(Size);
@@ -370,6 +370,30 @@
 }
 
 /***********************************************************************
+ * Helper function to create a proxy.
+ * Probably similar to NdrpCreateProxy.
+ */
+HRESULT create_proxy(REFIID iid, IUnknown *pUnkOuter, IRpcProxyBuffer **pproxy, void **ppv)
+{
+    CLSID clsid;
+    IPSFactoryBuffer *psfac;
+    HRESULT r;
+
+    if(!LoadCOM()) return E_FAIL;
+
+    r = COM_GetPSClsid( iid, &clsid );
+    if(FAILED(r)) return r;
+
+    r = COM_GetClassObject( &clsid, CLSCTX_INPROC_SERVER, NULL, &IID_IPSFactoryBuffer, (void**)&psfac );
+    if(FAILED(r)) return r;
+
+    r = IPSFactoryBuffer_CreateProxy(psfac, pUnkOuter, iid, pproxy, ppv);
+
+    IPSFactoryBuffer_Release(psfac);
+    return r;
+}
+
+/***********************************************************************
  * Helper function to create a stub.
  * This probably looks very much like NdrpCreateStub.
  */
Index: dll/win32/rpcrt4/ndr_stubless.c
===================================================================
--- dll/win32/rpcrt4/ndr_stubless.c	(revision 41348)
+++ dll/win32/rpcrt4/ndr_stubless.c	(working copy)
@@ -173,7 +173,7 @@
                 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
                     pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
                 else
-                    pArg = (void *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
+                    pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
                 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
                 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
                 *phBinding = pGenPair->pfnBind(pObject);
@@ -256,7 +256,7 @@
                 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
                     pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
                 else
-                    pArg = (void *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
+                    pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
                 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
                 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
                 pGenPair->pfnUnbind(pObject, hBinding);
@@ -1522,3 +1522,339 @@
     DWORD dwPhase;
     NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);
 }
+
+struct async_call_data
+{
+    MIDL_STUB_MESSAGE *pStubMsg;
+    const NDR_PROC_HEADER *pProcHeader;
+    PFORMAT_STRING pHandleFormat;
+    PFORMAT_STRING pParamFormat;
+    RPC_BINDING_HANDLE hBinding;
+    /* size of stack */
+    unsigned short stack_size;
+    /* number of parameters. optional for client to give it to us */
+    unsigned char number_of_params;
+    /* correlation cache */
+    unsigned long NdrCorrCache[256];
+};
+
+LONG_PTR WINAPIV NdrAsyncClientCall(PMIDL_STUB_DESC pStubDesc,
+  PFORMAT_STRING pFormat, ...)
+{
+    /* pointer to start of stack where arguments start */
+    PRPC_MESSAGE pRpcMsg;
+    PMIDL_STUB_MESSAGE pStubMsg;
+    RPC_ASYNC_STATE *pAsync;
+    struct async_call_data *async_call_data;
+    /* procedure number */
+    unsigned short procedure_number;
+    /* cache of Oif_flags from v2 procedure header */
+    INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
+    /* cache of extension flags from NDR_PROC_HEADER_EXTS */
+    INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
+    /* the type of pass we are currently doing */
+    int phase;
+    /* header for procedure string */
+    const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
+    /* -Oif or -Oicf generated format */
+    BOOL bV2Format = FALSE;
+
+    TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
+
+    /* Later NDR language versions probably won't be backwards compatible */
+    if (pStubDesc->Version > 0x50002)
+    {
+        FIXME("Incompatible stub description version: 0x%x\n", pStubDesc->Version);
+        RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
+    }
+
+    async_call_data = I_RpcAllocate(sizeof(*async_call_data) + sizeof(MIDL_STUB_MESSAGE) + sizeof(RPC_MESSAGE));
+    if (!async_call_data) RpcRaiseException(ERROR_OUTOFMEMORY);
+    async_call_data->number_of_params = ~0;
+    async_call_data->pProcHeader = pProcHeader;
+
+    async_call_data->pStubMsg = pStubMsg = (PMIDL_STUB_MESSAGE)(async_call_data + 1);
+    pRpcMsg = (PRPC_MESSAGE)(pStubMsg + 1);
+
+    if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
+    {
+        const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
+        async_call_data->stack_size = pProcHeader->stack_size;
+        procedure_number = pProcHeader->proc_num;
+        pFormat += sizeof(NDR_PROC_HEADER_RPC);
+    }
+    else
+    {
+        async_call_data->stack_size = pProcHeader->stack_size;
+        procedure_number = pProcHeader->proc_num;
+        pFormat += sizeof(NDR_PROC_HEADER);
+    }
+    TRACE("stack size: 0x%x\n", async_call_data->stack_size);
+    TRACE("proc num: %d\n", procedure_number);
+
+    /* create the full pointer translation tables, if requested */
+    if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
+        pStubMsg->FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
+
+    if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
+    {
+        ERR("objects not supported\n");
+        I_RpcFree(async_call_data);
+        RpcRaiseException(RPC_X_BAD_STUB_DATA);
+    }
+
+    NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDesc, procedure_number);
+
+    TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
+    TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
+
+    /* needed for conformance of top-level objects */
+#ifdef __i386__
+    pStubMsg->StackTop = I_RpcAllocate(async_call_data->stack_size);
+    /* FIXME: this may read one more DWORD than is necessary, but it shouldn't hurt */
+    memcpy(pStubMsg->StackTop, *(unsigned char **)(&pFormat+1), async_call_data->stack_size);
+#else
+# warning Stack not retrieved for your CPU architecture
+#endif
+
+    pAsync = *(RPC_ASYNC_STATE **)pStubMsg->StackTop;
+    pAsync->StubInfo = async_call_data;
+    async_call_data->pHandleFormat = pFormat;
+
+    pFormat = client_get_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, &async_call_data->hBinding);
+    if (!pFormat) return 0;
+
+    bV2Format = (pStubDesc->Version >= 0x20000);
+
+    if (bV2Format)
+    {
+        const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
+            (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
+
+        Oif_flags = pOIFHeader->Oi2Flags;
+        async_call_data->number_of_params = pOIFHeader->number_of_params;
+
+        pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
+    }
+
+    TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags);
+
+    if (Oif_flags.HasExtensions)
+    {
+        const NDR_PROC_HEADER_EXTS *pExtensions =
+            (const NDR_PROC_HEADER_EXTS *)pFormat;
+        ext_flags = pExtensions->Flags2;
+        pFormat += pExtensions->Size;
+    }
+
+    async_call_data->pParamFormat = pFormat;
+
+    pStubMsg->BufferLength = 0;
+
+    /* store the RPC flags away */
+    if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
+        pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
+
+    /* use alternate memory allocation routines */
+    if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
+        NdrRpcSmSetClientToOsf(pStubMsg);
+
+    if (Oif_flags.HasPipes)
+    {
+        FIXME("pipes not supported yet\n");
+        RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
+        /* init pipes package */
+        /* NdrPipesInitialize(...) */
+    }
+    if (ext_flags.HasNewCorrDesc)
+    {
+        /* initialize extra correlation package */
+        NdrCorrelationInitialize(pStubMsg, async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache), 0);
+    }
+
+    /* order of phases:
+     * 1. PROXY_CALCSIZE - calculate the buffer size
+     * 2. PROXY_GETBUFFER - allocate the buffer
+     * 3. PROXY_MARHSAL - marshal [in] params into the buffer
+     * 4. PROXY_SENDRECEIVE - send buffer
+     * Then in NdrpCompleteAsyncClientCall:
+     * 1. PROXY_SENDRECEIVE - receive buffer
+     * 2. PROXY_UNMARHSAL - unmarshal [out] params from buffer
+     */
+    for (phase = PROXY_CALCSIZE; phase <= PROXY_SENDRECEIVE; phase++)
+    {
+        RPC_STATUS status;
+        TRACE("phase = %d\n", phase);
+        switch (phase)
+        {
+        case PROXY_GETBUFFER:
+            /* allocate the buffer */
+            if (Oif_flags.HasPipes)
+                /* NdrGetPipeBuffer(...) */
+                FIXME("pipes not supported yet\n");
+            else
+            {
+                if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
+#if 0
+                    NdrNsGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
+#else
+                    FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
+#endif
+                else
+                    NdrGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
+            }
+            pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
+            status = I_RpcAsyncSetHandle(pRpcMsg, pAsync);
+            if (status != RPC_S_OK)
+                RpcRaiseException(status);
+            break;
+        case PROXY_SENDRECEIVE:
+            pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
+            /* send the [in] params only */
+            if (Oif_flags.HasPipes)
+                /* NdrPipesSend(...) */
+                FIXME("pipes not supported yet\n");
+            else
+            {
+                if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
+#if 0
+                    NdrNsSend(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
+#else
+                    FIXME("using auto handle - call NdrNsSend when it gets implemented\n");
+#endif
+                else
+                {
+                    pStubMsg->RpcMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
+                    status = I_RpcSend(pStubMsg->RpcMsg);
+                    if (status != RPC_S_OK)
+                        RpcRaiseException(status);
+                }
+            }
+
+            break;
+        case PROXY_CALCSIZE:
+        case PROXY_MARSHAL:
+            if (bV2Format)
+                client_do_args(pStubMsg, pFormat, phase, pStubMsg->StackTop,
+                    async_call_data->number_of_params, NULL);
+            else
+                client_do_args_old_format(pStubMsg, pFormat, phase,
+                    pStubMsg->StackTop, async_call_data->stack_size, NULL,
+                    (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT), FALSE);
+            break;
+        default:
+            ERR("shouldn't reach here. phase %d\n", phase);
+            break;
+        }
+    }
+
+    TRACE("returning 0\n");
+    return 0;
+}
+
+RPC_STATUS NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE *pAsync, void *Reply)
+{
+    /* pointer to start of stack where arguments start */
+    PMIDL_STUB_MESSAGE pStubMsg;
+    struct async_call_data *async_call_data;
+    /* the type of pass we are currently doing */
+    int phase;
+    /* header for procedure string */
+    const NDR_PROC_HEADER * pProcHeader;
+    /* -Oif or -Oicf generated format */
+    BOOL bV2Format;
+    RPC_STATUS status = RPC_S_OK;
+
+    if (!pAsync->StubInfo)
+        return RPC_S_INVALID_ASYNC_HANDLE;
+
+    async_call_data = pAsync->StubInfo;
+    pStubMsg = async_call_data->pStubMsg;
+    pProcHeader = async_call_data->pProcHeader;
+
+    bV2Format = (pStubMsg->StubDesc->Version >= 0x20000);
+
+    /* order of phases:
+     * 1. PROXY_CALCSIZE - calculate the buffer size
+     * 2. PROXY_GETBUFFER - allocate the buffer
+     * 3. PROXY_MARHSAL - marshal [in] params into the buffer
+     * 4. PROXY_SENDRECEIVE - send buffer
+     * Then in NdrpCompleteAsyncClientCall:
+     * 1. PROXY_SENDRECEIVE - receive buffer
+     * 2. PROXY_UNMARHSAL - unmarshal [out] params from buffer
+     */
+    for (phase = PROXY_SENDRECEIVE; phase <= PROXY_UNMARSHAL; phase++)
+    {
+        switch (phase)
+        {
+        case PROXY_SENDRECEIVE:
+            pStubMsg->RpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
+            /* receive the [out] params */
+            if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
+#if 0
+                NdrNsReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
+#else
+                FIXME("using auto handle - call NdrNsReceive when it gets implemented\n");
+#endif
+            else
+            {
+                status = I_RpcReceive(pStubMsg->RpcMsg);
+                if (status != RPC_S_OK)
+                    goto cleanup;
+                pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
+                pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
+                pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
+                pStubMsg->Buffer = pStubMsg->BufferStart;
+            }
+
+            /* convert strings, floating point values and endianess into our
+             * preferred format */
+#if 0
+            if ((pStubMsg->RpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
+                NdrConvert(pStubMsg, pFormat);
+#endif
+
+            break;
+        case PROXY_UNMARSHAL:
+            if (bV2Format)
+                client_do_args(pStubMsg, async_call_data->pParamFormat, phase, pStubMsg->StackTop,
+                    async_call_data->number_of_params, Reply);
+            else
+                client_do_args_old_format(pStubMsg, async_call_data->pParamFormat, phase,
+                    pStubMsg->StackTop, async_call_data->stack_size, Reply, FALSE, FALSE);
+            break;
+        default:
+            ERR("shouldn't reach here. phase %d\n", phase);
+            break;
+        }
+    }
+
+cleanup:
+    if (pStubMsg->fHasNewCorrDesc)
+    {
+        /* free extra correlation package */
+        NdrCorrelationFree(pStubMsg);
+    }
+
+    /* free the full pointer translation tables */
+    if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
+        NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
+
+    /* free marshalling buffer */
+    NdrFreeBuffer(pStubMsg);
+    client_free_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, async_call_data->hBinding);
+
+    I_RpcFree(pStubMsg->StackTop);
+    I_RpcFree(async_call_data);
+
+    TRACE("-- 0x%x\n", status);
+    return status;
+}
+
+RPCRTAPI LONG RPC_ENTRY NdrAsyncStubCall(struct IRpcStubBuffer* pThis,
+    struct IRpcChannelBuffer* pChannel, PRPC_MESSAGE pRpcMsg,
+    DWORD * pdwStubPhase)
+{
+    FIXME("unimplemented, expect crash!\n");
+    return 0;
+}
Index: dll/win32/rpcrt4/ndr_stubless.h
===================================================================
--- dll/win32/rpcrt4/ndr_stubless.h	(revision 41348)
+++ dll/win32/rpcrt4/ndr_stubless.h	(working copy)
@@ -240,3 +240,4 @@
     PFORMAT_STRING pFormat, int phase, unsigned char *args,
     unsigned short stack_size, unsigned char *pRetVal, BOOL object_proc,
     BOOL ignore_retval);
+RPC_STATUS NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE *pAsync, void *Reply);
Index: dll/win32/rpcrt4/rpc_assoc.c
===================================================================
--- dll/win32/rpcrt4/rpc_assoc.c	(revision 41348)
+++ dll/win32/rpcrt4/rpc_assoc.c	(working copy)
@@ -394,6 +394,7 @@
     if (status != RPC_S_OK)
         return status;
 
+    NewConnection->assoc = assoc;
     status = RPCRT4_OpenClientConnection(NewConnection);
     if (status != RPC_S_OK)
     {
@@ -416,6 +417,7 @@
 void RpcAssoc_ReleaseIdleConnection(RpcAssoc *assoc, RpcConnection *Connection)
 {
     assert(!Connection->server);
+    Connection->async_state = NULL;
     EnterCriticalSection(&assoc->cs);
     if (!assoc->assoc_group_id) assoc->assoc_group_id = Connection->assoc_group_id;
     list_add_head(&assoc->free_connection_pool, &Connection->conn_pool_entry);
Index: dll/win32/rpcrt4/rpc_assoc.h
===================================================================
--- dll/win32/rpcrt4/rpc_assoc.h	(revision 41348)
+++ dll/win32/rpcrt4/rpc_assoc.h	(working copy)
@@ -34,6 +34,7 @@
 
     /* id of this association group */
     ULONG assoc_group_id;
+    UUID http_uuid;
 
     CRITICAL_SECTION cs;
 
Index: dll/win32/rpcrt4/rpc_async.c
===================================================================
--- dll/win32/rpcrt4/rpc_async.c	(revision 41348)
+++ dll/win32/rpcrt4/rpc_async.c	(working copy)
@@ -29,11 +29,17 @@
 
 #include "rpc_binding.h"
 #include "rpc_message.h"
+#include "ndr_stubless.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
 
 #define RPC_ASYNC_SIGNATURE 0x43595341
 
+static inline BOOL valid_async_handle(PRPC_ASYNC_STATE pAsync)
+{
+    return pAsync->Signature == RPC_ASYNC_SIGNATURE;
+}
+
 /***********************************************************************
  *           RpcAsyncInitializeHandle [RPCRT4.@]
  *
@@ -104,8 +110,14 @@
  */
 RPC_STATUS WINAPI RpcAsyncCompleteCall(PRPC_ASYNC_STATE pAsync, void *Reply)
 {
-    FIXME("(%p, %p): stub\n", pAsync, Reply);
-    return RPC_S_INVALID_ASYNC_HANDLE;
+    TRACE("(%p, %p)\n", pAsync, Reply);
+
+    if (!valid_async_handle(pAsync))
+        return RPC_S_INVALID_ASYNC_HANDLE;
+
+    /* FIXME: check completed */
+
+    return NdrpCompleteAsyncClientCall(pAsync, Reply);
 }
 
 /***********************************************************************
Index: dll/win32/rpcrt4/rpc_binding.c
===================================================================
--- dll/win32/rpcrt4/rpc_binding.c	(revision 41348)
+++ dll/win32/rpcrt4/rpc_binding.c	(working copy)
@@ -661,11 +661,11 @@
   return RPC_S_OK;
 
 fail:
-  if (ObjUuid) RpcStringFreeA((unsigned char**)ObjUuid);
-  if (Protseq) RpcStringFreeA((unsigned char**)Protseq);
-  if (NetworkAddr) RpcStringFreeA((unsigned char**)NetworkAddr);
-  if (Endpoint) RpcStringFreeA((unsigned char**)Endpoint);
-  if (Options) RpcStringFreeA((unsigned char**)Options);
+  if (ObjUuid) RpcStringFreeA(ObjUuid);
+  if (Protseq) RpcStringFreeA(Protseq);
+  if (NetworkAddr) RpcStringFreeA(NetworkAddr);
+  if (Endpoint) RpcStringFreeA(Endpoint);
+  if (Options) RpcStringFreeA(Options);
   return RPC_S_INVALID_STRING_BINDING;
 }
 
@@ -812,7 +812,7 @@
  */
 RPC_STATUS WINAPI RpcBindingInqObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
 {
-  RpcBinding* bind = (RpcBinding*)Binding;
+  RpcBinding* bind = Binding;
 
   TRACE("(%p,%p) = %s\n", Binding, ObjectUuid, debugstr_guid(&bind->ObjectUuid));
   *ObjectUuid = bind->ObjectUuid;
@@ -824,7 +824,7 @@
  */
 RPC_STATUS WINAPI RpcBindingSetObject( RPC_BINDING_HANDLE Binding, UUID* ObjectUuid )
 {
-  RpcBinding* bind = (RpcBinding*)Binding;
+  RpcBinding* bind = Binding;
 
   TRACE("(%p,%s)\n", Binding, debugstr_guid(ObjectUuid));
   if (bind->server) return RPC_S_WRONG_KIND_OF_BINDING;
@@ -856,11 +856,11 @@
   if (ret == RPC_S_OK)
     ret = RPCRT4_CompleteBindingA(bind, (char*)NetworkAddr, (char*)Endpoint, (char*)Options);
 
-  RpcStringFreeA((unsigned char**)&Options);
-  RpcStringFreeA((unsigned char**)&Endpoint);
-  RpcStringFreeA((unsigned char**)&NetworkAddr);
-  RpcStringFreeA((unsigned char**)&Protseq);
-  RpcStringFreeA((unsigned char**)&ObjectUuid);
+  RpcStringFreeA(&Options);
+  RpcStringFreeA(&Endpoint);
+  RpcStringFreeA(&NetworkAddr);
+  RpcStringFreeA(&Protseq);
+  RpcStringFreeA(&ObjectUuid);
 
   if (ret == RPC_S_OK) 
     *Binding = (RPC_BINDING_HANDLE)bind;
@@ -915,7 +915,7 @@
 RPC_STATUS WINAPI RpcBindingToStringBindingA( RPC_BINDING_HANDLE Binding, RPC_CSTR *StringBinding )
 {
   RPC_STATUS ret;
-  RpcBinding* bind = (RpcBinding*)Binding;
+  RpcBinding* bind = Binding;
   RPC_CSTR ObjectUuid;
 
   TRACE("(%p,%p)\n", Binding, StringBinding);
@@ -946,7 +946,7 @@
   TRACE("(%p,%p)\n", Binding, StringBinding);
   ret = RpcBindingToStringBindingA(Binding, &str);
   *StringBinding = RPCRT4_strdupAtoW((char*)str);
-  RpcStringFreeA((unsigned char**)&str);
+  RpcStringFreeA(&str);
   return ret;
 }
 
@@ -969,7 +969,7 @@
  */
 RPC_STATUS WINAPI I_RpcBindingSetAsync( RPC_BINDING_HANDLE Binding, RPC_BLOCKING_FN BlockingFn)
 {
-  RpcBinding* bind = (RpcBinding*)Binding;
+  RpcBinding* bind = Binding;
 
   TRACE( "(%p,%p): stub\n", Binding, BlockingFn );
 
@@ -986,7 +986,7 @@
   RPC_BINDING_HANDLE* DestinationBinding)
 {
   RpcBinding *DestBinding;
-  RpcBinding *SrcBinding = (RpcBinding*)SourceBinding;
+  RpcBinding *SrcBinding = SourceBinding;
   RPC_STATUS status;
 
   TRACE("(%p, %p)\n", SourceBinding, DestinationBinding);
@@ -1501,7 +1501,7 @@
                           RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr,
                           RPC_SECURITY_QOS *SecurityQos )
 {
-  RpcBinding* bind = (RpcBinding*)Binding;
+  RpcBinding* bind = Binding;
   SECURITY_STATUS r;
   CredHandle cred;
   TimeStamp exp;
@@ -1631,7 +1631,7 @@
                           ULONG AuthnSvc, RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr,
                           RPC_SECURITY_QOS *SecurityQos )
 {
-  RpcBinding* bind = (RpcBinding*)Binding;
+  RpcBinding* bind = Binding;
   SECURITY_STATUS r;
   CredHandle cred;
   TimeStamp exp;
@@ -1640,7 +1640,7 @@
   PSecPkgInfoW packages;
   ULONG cbMaxToken;
 
-  TRACE("%p %s %u %u %p %u %p\n", Binding, debugstr_w((const WCHAR*)ServerPrincName),
+  TRACE("%p %s %u %u %p %u %p\n", Binding, debugstr_w(ServerPrincName),
         AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, SecurityQos);
 
   if (SecurityQos)
@@ -1772,7 +1772,7 @@
 RpcBindingSetAuthInfoW( RPC_BINDING_HANDLE Binding, RPC_WSTR ServerPrincName, ULONG AuthnLevel,
                         ULONG AuthnSvc, RPC_AUTH_IDENTITY_HANDLE AuthIdentity, ULONG AuthzSvr )
 {
-    TRACE("%p %s %u %u %p %u\n", Binding, debugstr_w((const WCHAR*)ServerPrincName),
+    TRACE("%p %s %u %u %p %u\n", Binding, debugstr_w(ServerPrincName),
           AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr);
     return RpcBindingSetAuthInfoExW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvr, NULL);
 }
Index: dll/win32/rpcrt4/rpc_binding.h
===================================================================
--- dll/win32/rpcrt4/rpc_binding.h	(revision 41348)
+++ dll/win32/rpcrt4/rpc_binding.h	(working copy)
@@ -24,6 +24,7 @@
 #include "rpcndr.h"
 #include "security.h"
 #include "wine/list.h"
+#include "rpc_defs.h"
 
 
 typedef struct _RpcAuthInfo
@@ -74,6 +75,7 @@
   struct list conn_pool_entry;
   ULONG assoc_group_id; /* association group returned during binding */
   RPC_ASYNC_STATE *async_state;
+  struct _RpcAssoc *assoc; /* association this connection is part of */
 
   /* server-only */
   /* The active interface bound to server. */
@@ -96,6 +98,7 @@
   int (*wait_for_incoming_data)(RpcConnection *conn);
   size_t (*get_top_of_tower)(unsigned char *tower_data, const char *networkaddr, const char *endpoint);
   RPC_STATUS (*parse_top_of_tower)(const unsigned char *tower_data, size_t tower_size, char **networkaddr, char **endpoint);
+  RPC_STATUS (*receive_fragment)(RpcConnection *conn, RpcPktHdr **Header, void **Payload);
 };
 
 /* don't know what MS's structure looks like */
Index: dll/win32/rpcrt4/rpc_defs.h
===================================================================
--- dll/win32/rpcrt4/rpc_defs.h	(revision 41348)
+++ dll/win32/rpcrt4/rpc_defs.h	(working copy)
@@ -120,6 +120,14 @@
   } protocols[1];
 } RpcPktBindNAckHdr;
 
+/* undocumented packet sent during RPC over HTTP */
+typedef struct
+{
+  RpcPktCommonHdr common;
+  unsigned short flags;
+  unsigned short num_data_items;
+} RpcPktHttpHdr;
+
 /* Union representing all possible packet headers */
 typedef union
 {
@@ -130,6 +138,7 @@
   RpcPktBindHdr bind;
   RpcPktBindAckHdr bind_ack;
   RpcPktBindNAckHdr bind_nack;
+  RpcPktHttpHdr http;
 } RpcPktHdr;
 
 typedef struct
@@ -174,6 +183,7 @@
 #define PKT_SHUTDOWN           17
 #define PKT_CO_CANCEL          18
 #define PKT_ORPHANED           19
+#define PKT_HTTP               20
 
 #define RESULT_ACCEPT               0
 #define RESULT_USER_REJECTION       1
Index: dll/win32/rpcrt4/rpc_epmap.c
===================================================================
--- dll/win32/rpcrt4/rpc_epmap.c	(revision 41348)
+++ dll/win32/rpcrt4/rpc_epmap.c	(working copy)
@@ -116,7 +116,7 @@
 
 static inline BOOL is_epm_destination_local(RPC_BINDING_HANDLE handle)
 {
-    RpcBinding *bind = (RpcBinding *)handle;
+    RpcBinding *bind = handle;
     const char *protseq = bind->Protseq;
     const char *network_addr = bind->NetworkAddr;
 
@@ -127,7 +127,7 @@
 
 static RPC_STATUS get_epm_handle_client(RPC_BINDING_HANDLE handle, RPC_BINDING_HANDLE *epm_handle)
 {
-    RpcBinding *bind = (RpcBinding *)handle;
+    RpcBinding *bind = handle;
     const char * pszEndpoint = NULL;
     RPC_STATUS status;
     RpcBinding* epm_bind;
@@ -149,7 +149,7 @@
     status = RpcBindingCopy(handle, epm_handle);
     if (status != RPC_S_OK) return status;
 
-    epm_bind = (RpcBinding*)*epm_handle;
+    epm_bind = *epm_handle;
     if (epm_bind->AuthInfo)
     {
         /* don't bother with authenticating against the EPM by default
@@ -187,7 +187,7 @@
 RPC_STATUS WINAPI RpcEpRegisterA( RPC_IF_HANDLE IfSpec, RPC_BINDING_VECTOR *BindingVector,
                                   UUID_VECTOR *UuidVector, RPC_CSTR Annotation )
 {
-  PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
+  PRPC_SERVER_INTERFACE If = IfSpec;
   unsigned long i;
   RPC_STATUS status = RPC_S_OK;
   error_status_t status2;
@@ -197,7 +197,7 @@
   TRACE("(%p,%p,%p,%s)\n", IfSpec, BindingVector, UuidVector, debugstr_a((char*)Annotation));
   TRACE(" ifid=%s\n", debugstr_guid(&If->InterfaceId.SyntaxGUID));
   for (i=0; i<BindingVector->Count; i++) {
-    RpcBinding* bind = (RpcBinding*)(BindingVector->BindingH[i]);
+    RpcBinding* bind = BindingVector->BindingH[i];
     TRACE(" protseq[%ld]=%s\n", i, debugstr_a(bind->Protseq));
     TRACE(" endpoint[%ld]=%s\n", i, debugstr_a(bind->Endpoint));
   }
@@ -222,7 +222,7 @@
   for (i = 0; i < BindingVector->Count; i++)
   {
       unsigned j;
-      RpcBinding* bind = (RpcBinding*)(BindingVector->BindingH[i]);
+      RpcBinding* bind = BindingVector->BindingH[i];
       for (j = 0; j < (UuidVector ? UuidVector->Count : 1); j++)
       {
           int len = strlen((char *)Annotation);
@@ -281,12 +281,27 @@
 }
 
 /***********************************************************************
+ *             RpcEpRegisterW (RPCRT4.@)
+ */
+RPC_STATUS WINAPI RpcEpRegisterW( RPC_IF_HANDLE IfSpec, RPC_BINDING_VECTOR *BindingVector,
+                                  UUID_VECTOR *UuidVector, RPC_WSTR Annotation )
+{
+  LPSTR annA = RPCRT4_strdupWtoA(Annotation);
+  RPC_STATUS status;
+
+  status = RpcEpRegisterA(IfSpec, BindingVector, UuidVector, (RPC_CSTR)annA);
+
+  HeapFree(GetProcessHeap(), 0, annA);
+  return status;
+}
+
+/***********************************************************************
  *             RpcEpUnregister (RPCRT4.@)
  */
 RPC_STATUS WINAPI RpcEpUnregister( RPC_IF_HANDLE IfSpec, RPC_BINDING_VECTOR *BindingVector,
                                    UUID_VECTOR *UuidVector )
 {
-  PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
+  PRPC_SERVER_INTERFACE If = IfSpec;
   unsigned long i;
   RPC_STATUS status = RPC_S_OK;
   error_status_t status2;
@@ -296,7 +311,7 @@
   TRACE("(%p,%p,%p)\n", IfSpec, BindingVector, UuidVector);
   TRACE(" ifid=%s\n", debugstr_guid(&If->InterfaceId.SyntaxGUID));
   for (i=0; i<BindingVector->Count; i++) {
-    RpcBinding* bind = (RpcBinding*)(BindingVector->BindingH[i]);
+    RpcBinding* bind = BindingVector->BindingH[i];
     TRACE(" protseq[%ld]=%s\n", i, debugstr_a(bind->Protseq));
     TRACE(" endpoint[%ld]=%s\n", i, debugstr_a(bind->Endpoint));
   }
@@ -319,7 +334,7 @@
   for (i = 0; i < BindingVector->Count; i++)
   {
       unsigned j;
-      RpcBinding* bind = (RpcBinding*)(BindingVector->BindingH[i]);
+      RpcBinding* bind = BindingVector->BindingH[i];
       for (j = 0; j < (UuidVector ? UuidVector->Count : 1); j++)
       {
           status = TowerConstruct(&If->InterfaceId, &If->TransferSyntax,
@@ -372,8 +387,8 @@
  */
 RPC_STATUS WINAPI RpcEpResolveBinding( RPC_BINDING_HANDLE Binding, RPC_IF_HANDLE IfSpec )
 {
-  PRPC_CLIENT_INTERFACE If = (PRPC_CLIENT_INTERFACE)IfSpec;
-  RpcBinding* bind = (RpcBinding*)Binding;
+  PRPC_CLIENT_INTERFACE If = IfSpec;
+  RpcBinding* bind = Binding;
   RPC_STATUS status;
   error_status_t status2;
   handle_t handle;
@@ -596,7 +611,7 @@
     return RPC_S_OK;
 }
 
-void __RPC_FAR * __RPC_USER MIDL_user_allocate(size_t len)
+void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
 {
     return HeapAlloc(GetProcessHeap(), 0, len);
 }
Index: dll/win32/rpcrt4/rpc_message.c
===================================================================
--- dll/win32/rpcrt4/rpc_message.c	(revision 41348)
+++ dll/win32/rpcrt4/rpc_message.c	(working copy)
@@ -59,13 +59,13 @@
 
 static RPC_STATUS I_RpcReAllocateBuffer(PRPC_MESSAGE pMsg);
 
-static DWORD RPCRT4_GetHeaderSize(const RpcPktHdr *Header)
+DWORD RPCRT4_GetHeaderSize(const RpcPktHdr *Header)
 {
   static const DWORD header_sizes[] = {
     sizeof(Header->request), 0, sizeof(Header->response),
     sizeof(Header->fault), 0, 0, 0, 0, 0, 0, 0, sizeof(Header->bind),
     sizeof(Header->bind_ack), sizeof(Header->bind_nack),
-    0, 0, 0, 0, 0
+    0, 0, 0, 0, 0, 0, sizeof(Header->http)
   };
   ULONG ret = 0;
   
@@ -76,7 +76,7 @@
     if (Header->common.flags & RPC_FLG_OBJECT_UUID)
       ret += sizeof(UUID);
   } else {
-    TRACE("invalid packet type\n");
+    WARN("invalid packet type %u\n", Header->common.ptype);
   }
 
   return ret;
@@ -283,6 +283,118 @@
   return header;
 }
 
+RpcPktHdr *RPCRT4_BuildHttpHeader(unsigned long DataRepresentation,
+                                  unsigned short flags,
+                                  unsigned short num_data_items,
+                                  unsigned int payload_size)
+{
+  RpcPktHdr *header;
+
+  header = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(header->http) + payload_size);
+  if (header == NULL) {
+      ERR("failed to allocate memory\n");
+    return NULL;
+  }
+
+  RPCRT4_BuildCommonHeader(header, PKT_HTTP, DataRepresentation);
+  /* since the packet isn't current sent using RPCRT4_Send, set the flags
+   * manually here */
+  header->common.flags = RPC_FLG_FIRST|RPC_FLG_LAST;
+  header->common.call_id = 0;
+  header->common.frag_len = sizeof(header->http) + payload_size;
+  header->http.flags = flags;
+  header->http.num_data_items = num_data_items;
+
+  return header;
+}
+
+#define WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, type, value) \
+    do { \
+        *(unsigned int *)(payload) = (type); \
+        (payload) += 4; \
+        *(unsigned int *)(payload) = (value); \
+        (payload) += 4; \
+    } while (0)
+
+#define WRITE_HTTP_PAYLOAD_FIELD_UUID(payload, type, uuid) \
+    do { \
+        *(unsigned int *)(payload) = (type); \
+        (payload) += 4; \
+        *(UUID *)(payload) = (uuid); \
+        (payload) += sizeof(UUID); \
+    } while (0)
+
+#define WRITE_HTTP_PAYLOAD_FIELD_FLOW_CONTROL(payload, bytes_transmitted, flow_control_increment, uuid) \
+    do { \
+        *(unsigned int *)(payload) = 0x00000001; \
+        (payload) += 4; \
+        *(unsigned int *)(payload) = (bytes_transmitted); \
+        (payload) += 4; \
+        *(unsigned int *)(payload) = (flow_control_increment); \
+        (payload) += 4; \
+        *(UUID *)(payload) = (uuid); \
+        (payload) += sizeof(UUID); \
+    } while (0)
+
+RpcPktHdr *RPCRT4_BuildHttpConnectHeader(unsigned short flags, int out_pipe,
+                                         const UUID *connection_uuid,
+                                         const UUID *pipe_uuid,
+                                         const UUID *association_uuid)
+{
+  RpcPktHdr *header;
+  unsigned int size;
+  char *payload;
+
+  size = 8 + 4 + sizeof(UUID) + 4 + sizeof(UUID) + 8;
+  if (!out_pipe)
+    size += 8 + 4 + sizeof(UUID);
+
+  header = RPCRT4_BuildHttpHeader(NDR_LOCAL_DATA_REPRESENTATION, flags,
+                                  out_pipe ? 4 : 6, size);
+  if (!header) return NULL;
+  payload = (char *)(&header->http+1);
+
+  /* FIXME: what does this part of the payload do? */
+  WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x00000006, 0x00000001);
+
+  WRITE_HTTP_PAYLOAD_FIELD_UUID(payload, 0x00000003, *connection_uuid);
+  WRITE_HTTP_PAYLOAD_FIELD_UUID(payload, 0x00000003, *pipe_uuid);
+
+  if (out_pipe)
+    /* FIXME: what does this part of the payload do? */
+    WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x00000000, 0x00010000);
+  else
+  {
+    /* FIXME: what does this part of the payload do? */
+    WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x00000004, 0x40000000);
+    /* FIXME: what does this part of the payload do? */
+    WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x00000005, 0x000493e0);
+
+    WRITE_HTTP_PAYLOAD_FIELD_UUID(payload, 0x0000000c, *association_uuid);
+  }
+
+  return header;
+}
+
+RpcPktHdr *RPCRT4_BuildHttpFlowControlHeader(BOOL server, ULONG bytes_transmitted,
+                                             ULONG flow_control_increment,
+                                             const UUID *pipe_uuid)
+{
+  RpcPktHdr *header;
+  char *payload;
+
+  header = RPCRT4_BuildHttpHeader(NDR_LOCAL_DATA_REPRESENTATION, 0x2, 2,
+                                  5 * sizeof(ULONG) + sizeof(UUID));
+  if (!header) return NULL;
+  payload = (char *)(&header->http+1);
+
+  WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x0000000d, (server ? 0x0 : 0x3));
+
+  WRITE_HTTP_PAYLOAD_FIELD_FLOW_CONTROL(payload, bytes_transmitted,
+                                        flow_control_increment, *pipe_uuid);
+  return header;
+}
+
 VOID RPCRT4_FreeHeader(RpcPktHdr *Header)
 {
   HeapFree(GetProcessHeap(), 0, Header);
@@ -362,6 +474,206 @@
     }
 }
 
+/* assumes the common header fields have already been validated */
+BOOL RPCRT4_IsValidHttpPacket(RpcPktHdr *hdr, unsigned char *data,
+                              unsigned short data_len)
+{
+  unsigned short i;
+  BYTE *p = data;
+
+  for (i = 0; i < hdr->http.num_data_items; i++)
+  {
+    ULONG type;
+
+    if (data_len < sizeof(ULONG))
+      return FALSE;
+
+    type = *(ULONG *)p;
+    p += sizeof(ULONG);
+    data_len -= sizeof(ULONG);
+
+    switch (type)
+    {
+      case 0x3:
+      case 0xc:
+        if (data_len < sizeof(GUID))
+          return FALSE;
+        p += sizeof(GUID);
+        data_len -= sizeof(GUID);
+        break;
+      case 0x0:
+      case 0x2:
+      case 0x4:
+      case 0x5:
+      case 0x6:
+      case 0xd:
+        if (data_len < sizeof(ULONG))
+          return FALSE;
+        p += sizeof(ULONG);
+        data_len -= sizeof(ULONG);
+        break;
+      case 0x1:
+        if (data_len < 24)
+          return FALSE;
+        p += 24;
+        data_len -= 24;
+        break;
+      default:
+        FIXME("unimplemented type 0x%x\n", type);
+        break;
+    }
+  }
+  return TRUE;
+}
+
+/* assumes the HTTP packet has been validated */
+static unsigned char *RPCRT4_NextHttpHeaderField(unsigned char *data)
+{
+  ULONG type;
+
+  type = *(ULONG *)data;
+  data += sizeof(ULONG);
+
+  switch (type)
+  {
+    case 0x3:
+    case 0xc:
+      return data + sizeof(GUID);
+    case 0x0:
+    case 0x2:
+    case 0x4:
+    case 0x5:
+    case 0x6:
+    case 0xd:
+      return data + sizeof(ULONG);
+    case 0x1:
+      return data + 24;
+    default:
+      FIXME("unimplemented type 0x%x\n", type);
+      return data;
+  }
+}
+
+#define READ_HTTP_PAYLOAD_FIELD_TYPE(data) *(ULONG *)(data)
+#define GET_HTTP_PAYLOAD_FIELD_DATA(data) ((data) + sizeof(ULONG))
+
+/* assumes the HTTP packet has been validated */
+RPC_STATUS RPCRT4_ParseHttpPrepareHeader1(RpcPktHdr *header,
+                                          unsigned char *data, ULONG *field1)
+{
+  ULONG type;
+  if (header->http.flags != 0x0)
+  {
+    ERR("invalid flags 0x%x\n", header->http.flags);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  if (header->http.num_data_items != 1)
+  {
+    ERR("invalid number of data items %d\n", header->http.num_data_items);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
+  if (type != 0x00000002)
+  {
+    ERR("invalid type 0x%08x\n", type);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  *field1 = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
+  return RPC_S_OK;
+}
+
+/* assumes the HTTP packet has been validated */
+RPC_STATUS RPCRT4_ParseHttpPrepareHeader2(RpcPktHdr *header,
+                                          unsigned char *data, ULONG *field1,
+                                          ULONG *bytes_until_next_packet,
+                                          ULONG *field3)
+{
+  ULONG type;
+  if (header->http.flags != 0x0)
+  {
+    ERR("invalid flags 0x%x\n", header->http.flags);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  if (header->http.num_data_items != 3)
+  {
+    ERR("invalid number of data items %d\n", header->http.num_data_items);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+
+  type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
+  if (type != 0x00000006)
+  {
+    ERR("invalid type for field 1: 0x%08x\n", type);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  *field1 = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
+  data = RPCRT4_NextHttpHeaderField(data);
+
+  type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
+  if (type != 0x00000000)
+  {
+    ERR("invalid type for field 2: 0x%08x\n", type);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  *bytes_until_next_packet = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
+  data = RPCRT4_NextHttpHeaderField(data);
+
+  type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
+  if (type != 0x00000002)
+  {
+    ERR("invalid type for field 3: 0x%08x\n", type);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  *field3 = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
+
+  return RPC_S_OK;
+}
+
+RPC_STATUS RPCRT4_ParseHttpFlowControlHeader(RpcPktHdr *header,
+                                             unsigned char *data, BOOL server,
+                                             ULONG *bytes_transmitted,
+                                             ULONG *flow_control_increment,
+                                             UUID *pipe_uuid)
+{
+  ULONG type;
+  if (header->http.flags != 0x2)
+  {
+    ERR("invalid flags 0x%x\n", header->http.flags);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  if (header->http.num_data_items != 2)
+  {
+    ERR("invalid number of data items %d\n", header->http.num_data_items);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+
+  type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
+  if (type != 0x0000000d)
+  {
+    ERR("invalid type for field 1: 0x%08x\n", type);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  if (*(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data) != (server ? 0x3 : 0x0))
+  {
+    ERR("invalid type for 0xd field data: 0x%08x\n", *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data));
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  data = RPCRT4_NextHttpHeaderField(data);
+
+  type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
+  if (type != 0x00000001)
+  {
+    ERR("invalid type for field 2: 0x%08x\n", type);
+    return RPC_S_PROTOCOL_ERROR;
+  }
+  *bytes_transmitted = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
+  *flow_control_increment = *(ULONG *)(GET_HTTP_PAYLOAD_FIELD_DATA(data) + 4);
+  *pipe_uuid = *(UUID *)(GET_HTTP_PAYLOAD_FIELD_DATA(data) + 8);
+
+  return RPC_S_OK;
+}
+
+
 static RPC_STATUS RPCRT4_SecurePacket(RpcConnection *Connection,
     enum secure_packet_direction dir,
     RpcPktHdr *hdr, unsigned int hdr_size,
@@ -687,7 +999,7 @@
 }
 
 /* validates version and frag_len fields */
-static RPC_STATUS RPCRT4_ValidateCommonHeader(const RpcPktCommonHdr *hdr)
+RPC_STATUS RPCRT4_ValidateCommonHeader(const RpcPktCommonHdr *hdr)
 {
   DWORD hdr_length;
 
@@ -716,11 +1028,11 @@
 }
 
 /***********************************************************************
- *           RPCRT4_receive_fragment (internal)
+ *           RPCRT4_default_receive_fragment (internal)
  * 
  * Receive a fragment from a connection.
  */
-static RPC_STATUS RPCRT4_receive_fragment(RpcConnection *Connection, RpcPktHdr **Header, void **Payload)
+static RPC_STATUS RPCRT4_default_receive_fragment(RpcConnection *Connection, RpcPktHdr **Header, void **Payload)
 {
   RPC_STATUS status;
   DWORD hdr_length;
@@ -794,6 +1106,14 @@
   return status;
 }
 
+static RPC_STATUS RPCRT4_receive_fragment(RpcConnection *Connection, RpcPktHdr **Header, void **Payload)
+{
+    if (Connection->ops->receive_fragment)
+        return Connection->ops->receive_fragment(Connection, Header, Payload);
+    else
+        return RPCRT4_default_receive_fragment(Connection, Header, Payload);
+}
+
 /***********************************************************************
  *           RPCRT4_ReceiveWithAuth (internal)
  *
@@ -998,7 +1318,7 @@
  */
 RPC_STATUS WINAPI I_RpcNegotiateTransferSyntax(PRPC_MESSAGE pMsg)
 {
-  RpcBinding* bind = (RpcBinding*)pMsg->Handle;
+  RpcBinding* bind = pMsg->Handle;
   RpcConnection* conn;
   RPC_STATUS status = RPC_S_OK;
 
@@ -1063,7 +1383,7 @@
 RPC_STATUS WINAPI I_RpcGetBuffer(PRPC_MESSAGE pMsg)
 {
   RPC_STATUS status;
-  RpcBinding* bind = (RpcBinding*)pMsg->Handle;
+  RpcBinding* bind = pMsg->Handle;
 
   TRACE("(%p): BufferLength=%d\n", pMsg, pMsg->BufferLength);
 
@@ -1120,7 +1440,7 @@
  */
 RPC_STATUS WINAPI I_RpcFreeBuffer(PRPC_MESSAGE pMsg)
 {
-  RpcBinding* bind = (RpcBinding*)pMsg->Handle;
+  RpcBinding* bind = pMsg->Handle;
 
   TRACE("(%p) Buffer=%p\n", pMsg, pMsg->Buffer);
 
@@ -1214,7 +1534,7 @@
  */
 RPC_STATUS WINAPI I_RpcSend(PRPC_MESSAGE pMsg)
 {
-  RpcBinding* bind = (RpcBinding*)pMsg->Handle;
+  RpcBinding* bind = pMsg->Handle;
   RpcConnection* conn;
   RPC_STATUS status;
   RpcPktHdr *hdr;
@@ -1268,7 +1588,7 @@
  */
 RPC_STATUS WINAPI I_RpcReceive(PRPC_MESSAGE pMsg)
 {
-  RpcBinding* bind = (RpcBinding*)pMsg->Handle;
+  RpcBinding* bind = pMsg->Handle;
   RPC_STATUS status;
   RpcPktHdr *hdr = NULL;
   RpcConnection *conn;
@@ -1360,7 +1680,7 @@
  */
 RPC_STATUS WINAPI I_RpcAsyncSetHandle(PRPC_MESSAGE pMsg, PRPC_ASYNC_STATE pAsync)
 {
-    RpcBinding* bind = (RpcBinding*)pMsg->Handle;
+    RpcBinding* bind = pMsg->Handle;
     RpcConnection *conn;
 
     TRACE("(%p, %p)\n", pMsg, pAsync);
Index: dll/win32/rpcrt4/rpc_message.h
===================================================================
--- dll/win32/rpcrt4/rpc_message.h	(revision 41348)
+++ dll/win32/rpcrt4/rpc_message.h	(working copy)
@@ -30,10 +30,20 @@
 RpcPktHdr *RPCRT4_BuildBindHeader(unsigned long DataRepresentation, unsigned short MaxTransmissionSize, unsigned short MaxReceiveSize, unsigned long AssocGroupId, const RPC_SYNTAX_IDENTIFIER *AbstractId, const RPC_SYNTAX_IDENTIFIER *TransferId);
 RpcPktHdr *RPCRT4_BuildBindNackHeader(unsigned long DataRepresentation, unsigned char RpcVersion, unsigned char RpcVersionMinor);
 RpcPktHdr *RPCRT4_BuildBindAckHeader(unsigned long DataRepresentation, unsigned short MaxTransmissionSize, unsigned short MaxReceiveSize, unsigned long AssocGroupId, LPCSTR ServerAddress, unsigned long Result, unsigned long Reason, const RPC_SYNTAX_IDENTIFIER *TransferId);
+RpcPktHdr *RPCRT4_BuildHttpHeader(unsigned long DataRepresentation, unsigned short flags, unsigned short num_data_items, unsigned int payload_size);
+RpcPktHdr *RPCRT4_BuildHttpConnectHeader(unsigned short flags, int out_pipe, const UUID *connection_uuid, const UUID *pipe_uuid, const UUID *association_uuid);
+RpcPktHdr *RPCRT4_BuildHttpFlowControlHeader(BOOL server, ULONG bytes_transmitted, ULONG flow_control_increment, const UUID *pipe_uuid);
 VOID RPCRT4_FreeHeader(RpcPktHdr *Header);
 RPC_STATUS RPCRT4_Send(RpcConnection *Connection, RpcPktHdr *Header, void *Buffer, unsigned int BufferLength);
 RPC_STATUS RPCRT4_Receive(RpcConnection *Connection, RpcPktHdr **Header, PRPC_MESSAGE pMsg);
 RPC_STATUS RPCRT4_ReceiveWithAuth(RpcConnection *Connection, RpcPktHdr **Header, PRPC_MESSAGE pMsg, unsigned char **auth_data_out, unsigned long *auth_length_out);
+DWORD RPCRT4_GetHeaderSize(const RpcPktHdr *Header);
+RPC_STATUS RPCRT4_ValidateCommonHeader(const RpcPktCommonHdr *hdr);
+
+BOOL RPCRT4_IsValidHttpPacket(RpcPktHdr *hdr, unsigned char *data, unsigned short data_len);
+RPC_STATUS RPCRT4_ParseHttpPrepareHeader1(RpcPktHdr *header, unsigned char *data, ULONG *field1);
+RPC_STATUS RPCRT4_ParseHttpPrepareHeader2(RpcPktHdr *header, unsigned char *data, ULONG *field1, ULONG *bytes_until_next_packet, ULONG *field3);
+RPC_STATUS RPCRT4_ParseHttpFlowControlHeader(RpcPktHdr *header, unsigned char *data, BOOL server, ULONG *bytes_transmitted, ULONG *flow_control_increment, UUID *pipe_uuid);
 NCA_STATUS RPC2NCA_STATUS(RPC_STATUS status);
 RPC_STATUS RPCRT4_AuthorizeConnection(RpcConnection* conn, BYTE *challenge, ULONG count);
 
Index: dll/win32/rpcrt4/rpc_server.c
===================================================================
--- dll/win32/rpcrt4/rpc_server.c	(revision 41348)
+++ dll/win32/rpcrt4/rpc_server.c	(working copy)
@@ -367,7 +367,7 @@
 
 static DWORD CALLBACK RPCRT4_io_thread(LPVOID the_arg)
 {
-  RpcConnection* conn = (RpcConnection*)the_arg;
+  RpcConnection* conn = the_arg;
   RpcPktHdr *hdr;
   RPC_MESSAGE *msg;
   RPC_STATUS status;
@@ -449,27 +449,23 @@
 
     /* start waiting */
     res = cps->ops->wait_for_new_connection(cps, count, objs);
-    if (res == -1)
+
+    if (res == -1 || (res == 0 && !std_listen))
+    {
+      /* cleanup */
+      cps->ops->free_wait_array(cps, objs);
+      EnterCriticalSection(&cps->cs);
+      for (conn = cps->conn; conn; conn = conn->Next)
+        RPCRT4_CloseConnection(conn);
+      LeaveCriticalSection(&cps->cs);
+
+      if (res == 0 && !std_listen)
+        SetEvent(cps->server_ready_event);
       break;
+    }
     else if (res == 0)
-    {
-      if (!std_listen)
-      {
-        SetEvent(cps->server_ready_event);
-        break;
-      }
       set_ready_event = TRUE;
-    }
   }
-  cps->ops->free_wait_array(cps, objs);
-  EnterCriticalSection(&cps->cs);
-  /* close connections */
-  conn = cps->conn;
-  while (conn) {
-    RPCRT4_CloseConnection(conn);
-    conn = conn->Next;
-  }
-  LeaveCriticalSection(&cps->cs);
   return 0;
 }
 
@@ -570,11 +566,32 @@
   LeaveCriticalSection(&listen_cs);
 }
 
-static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps, LPSTR endpoint)
+static BOOL RPCRT4_protseq_is_endpoint_registered(RpcServerProtseq *protseq, const char *endpoint)
 {
+  RpcConnection *conn;
+  EnterCriticalSection(&protseq->cs);
+  for (conn = protseq->conn; conn; conn = conn->Next)
+  {
+    if (!endpoint || !strcmp(endpoint, conn->Endpoint))
+      break;
+  }
+  LeaveCriticalSection(&protseq->cs);
+  return (conn != NULL);
+}
+
+static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps, const char *endpoint)
+{
   RPC_STATUS status;
 
-  status = ps->ops->open_endpoint(ps, endpoint);
+  EnterCriticalSection(&ps->cs);
+
+  if (RPCRT4_protseq_is_endpoint_registered(ps, endpoint))
+    status = RPC_S_OK;
+  else
+    status = ps->ops->open_endpoint(ps, endpoint);
+
+  LeaveCriticalSection(&ps->cs);
+
   if (status != RPC_S_OK)
     return status;
 
@@ -608,11 +625,8 @@
   count = 0;
   LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
     EnterCriticalSection(&ps->cs);
-    conn = ps->conn;
-    while (conn) {
+    for (conn = ps->conn; conn; conn = conn->Next)
       count++;
-      conn = conn->Next;
-    }
     LeaveCriticalSection(&ps->cs);
   }
   if (count) {
@@ -624,12 +638,10 @@
     count = 0;
     LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
       EnterCriticalSection(&ps->cs);
-      conn = ps->conn;
-      while (conn) {
+      for (conn = ps->conn; conn; conn = conn->Next) {
        RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count],
                           conn);
        count++;
-       conn = conn->Next;
       }
       LeaveCriticalSection(&ps->cs);
     }
@@ -681,7 +693,7 @@
  *
  * Must be called with server_cs held.
  */
-static RPC_STATUS alloc_serverprotoseq(UINT MaxCalls, char *Protseq, RpcServerProtseq **ps)
+static RPC_STATUS alloc_serverprotoseq(UINT MaxCalls, const char *Protseq, RpcServerProtseq **ps)
 {
   const struct protseq_ops *ops = rpcrt4_get_protseq_ops(Protseq);
 
@@ -695,7 +707,7 @@
   if (!*ps)
     return RPC_S_OUT_OF_RESOURCES;
   (*ps)->MaxCalls = MaxCalls;
-  (*ps)->Protseq = Protseq;
+  (*ps)->Protseq = RPCRT4_strdupA(Protseq);
   (*ps)->ops = ops;
   (*ps)->MaxCalls = 0;
   (*ps)->conn = NULL;
@@ -711,8 +723,19 @@
   return RPC_S_OK;
 }
 
+/* must be called with server_cs held */
+static void destroy_serverprotoseq(RpcServerProtseq *ps)
+{
+    RPCRT4_strfree(ps->Protseq);
+    DeleteCriticalSection(&ps->cs);
+    CloseHandle(ps->mgr_mutex);
+    CloseHandle(ps->server_ready_event);
+    list_remove(&ps->entry);
+    HeapFree(GetProcessHeap(), 0, ps);
+}
+
 /* Finds a given protseq or creates a new one if one doesn't already exist */
-static RPC_STATUS RPCRT4_get_or_create_serverprotseq(UINT MaxCalls, char *Protseq, RpcServerProtseq **ps)
+static RPC_STATUS RPCRT4_get_or_create_serverprotseq(UINT MaxCalls, const char *Protseq, RpcServerProtseq **ps)
 {
     RPC_STATUS status;
     RpcServerProtseq *cps;
@@ -741,19 +764,18 @@
 RPC_STATUS WINAPI RpcServerUseProtseqEpExA( RPC_CSTR Protseq, UINT MaxCalls, RPC_CSTR Endpoint, LPVOID SecurityDescriptor,
                                             PRPC_POLICY lpPolicy )
 {
-  char *szps = (char*)Protseq, *szep = (char*)Endpoint;
   RpcServerProtseq* ps;
   RPC_STATUS status;
 
-  TRACE("(%s,%u,%s,%p,{%u,%u,%u})\n", debugstr_a(szps), MaxCalls,
-       debugstr_a(szep), SecurityDescriptor,
+  TRACE("(%s,%u,%s,%p,{%u,%u,%u})\n", debugstr_a((const char *)Protseq),
+       MaxCalls, debugstr_a((const char *)Endpoint), SecurityDescriptor,
        lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
 
-  status = RPCRT4_get_or_create_serverprotseq(MaxCalls, RPCRT4_strdupA(szps), &ps);
+  status = RPCRT4_get_or_create_serverprotseq(MaxCalls, (const char *)Protseq, &ps);
   if (status != RPC_S_OK)
     return status;
 
-  return RPCRT4_use_protseq(ps, szep);
+  return RPCRT4_use_protseq(ps, (const char *)Endpoint);
 }
 
 /***********************************************************************
@@ -764,13 +786,16 @@
 {
   RpcServerProtseq* ps;
   RPC_STATUS status;
+  LPSTR ProtseqA;
   LPSTR EndpointA;
 
   TRACE("(%s,%u,%s,%p,{%u,%u,%u})\n", debugstr_w( Protseq ), MaxCalls,
        debugstr_w( Endpoint ), SecurityDescriptor,
        lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
 
-  status = RPCRT4_get_or_create_serverprotseq(MaxCalls, RPCRT4_strdupWtoA(Protseq), &ps);
+  ProtseqA = RPCRT4_strdupWtoA(Protseq);
+  status = RPCRT4_get_or_create_serverprotseq(MaxCalls, ProtseqA, &ps);
+  RPCRT4_strfree(ProtseqA);
   if (status != RPC_S_OK)
     return status;
 
@@ -785,8 +810,16 @@
  */
 RPC_STATUS WINAPI RpcServerUseProtseqA(RPC_CSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
 {
+  RPC_STATUS status;
+  RpcServerProtseq* ps;
+
   TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq), MaxCalls, SecurityDescriptor);
-  return RpcServerUseProtseqEpA(Protseq, MaxCalls, NULL, SecurityDescriptor);
+
+  status = RPCRT4_get_or_create_serverprotseq(MaxCalls, (const char *)Protseq, &ps);
+  if (status != RPC_S_OK)
+    return status;
+
+  return RPCRT4_use_protseq(ps, NULL);
 }
 
 /***********************************************************************
@@ -794,10 +827,38 @@
  */
 RPC_STATUS WINAPI RpcServerUseProtseqW(RPC_WSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
 {
+  RPC_STATUS status;
+  RpcServerProtseq* ps;
+  LPSTR ProtseqA;
+
   TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq), MaxCalls, SecurityDescriptor);
-  return RpcServerUseProtseqEpW(Protseq, MaxCalls, NULL, SecurityDescriptor);
+
+  ProtseqA = RPCRT4_strdupWtoA(Protseq);
+  status = RPCRT4_get_or_create_serverprotseq(MaxCalls, ProtseqA, &ps);
+  RPCRT4_strfree(ProtseqA);
+  if (status != RPC_S_OK)
+    return status;
+
+  return RPCRT4_use_protseq(ps, NULL);
 }
 
+void RPCRT4_destroy_all_protseqs(void)
+{
+    RpcServerProtseq *cps, *cursor2;
+
+    if (listen_count != 0)
+        std_listen = FALSE;
+
+    EnterCriticalSection(&server_cs);
+    LIST_FOR_EACH_ENTRY_SAFE(cps, cursor2, &protseqs, RpcServerProtseq, entry)
+    {
+        if (listen_count != 0)
+            RPCRT4_sync_with_server_thread(cps);
+        destroy_serverprotoseq(cps);
+    }
+    LeaveCriticalSection(&server_cs);
+}
+
 /***********************************************************************
  *             RpcServerRegisterIf (RPCRT4.@)
  */
@@ -823,7 +884,7 @@
 RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
                       UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
 {
-  PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
+  PRPC_SERVER_INTERFACE If = IfSpec;
   RpcServerInterface* sif;
   unsigned int i;
 
@@ -876,7 +937,7 @@
  */
 RPC_STATUS WINAPI RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, UINT WaitForCallsToComplete )
 {
-  PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
+  PRPC_SERVER_INTERFACE If = IfSpec;
   HANDLE event = NULL;
   BOOL found = FALSE;
   BOOL completed = TRUE;
Index: dll/win32/rpcrt4/rpc_server.h
===================================================================
--- dll/win32/rpcrt4/rpc_server.h	(revision 41348)
+++ dll/win32/rpcrt4/rpc_server.h	(working copy)
@@ -56,7 +56,7 @@
      * new connection was established */
     int (*wait_for_new_connection)(RpcServerProtseq *protseq, unsigned int count, void *wait_array);
     /* opens the endpoint and optionally begins listening */
-    RPC_STATUS (*open_endpoint)(RpcServerProtseq *protseq, LPSTR endpoint);
+    RPC_STATUS (*open_endpoint)(RpcServerProtseq *protseq, const char *endpoint);
 };
 
 typedef struct _RpcServerInterface
@@ -79,4 +79,6 @@
 void RPCRT4_new_client(RpcConnection* conn);
 const struct protseq_ops *rpcrt4_get_protseq_ops(const char *protseq);
 
+void RPCRT4_destroy_all_protseqs(void);
+
 #endif  /* __WINE_RPC_SERVER_H */
Index: dll/win32/rpcrt4/rpc_transport.c
===================================================================
--- dll/win32/rpcrt4/rpc_transport.c	(revision 41348)
+++ dll/win32/rpcrt4/rpc_transport.c	(working copy)
@@ -40,6 +40,8 @@
 # ifndef EAGAIN
 #  define EAGAIN WSAEWOULDBLOCK
 # endif
+# undef errno
+# define errno WSAGetLastError()
 #else
 # include <errno.h>
 # ifdef HAVE_UNISTD_H
@@ -64,16 +66,21 @@
 # ifdef HAVE_SYS_POLL_H
 #  include <sys/poll.h>
 # endif
+# ifdef HAVE_SYS_FILIO_H
+#  include <sys/filio.h>
+# endif
+# ifdef HAVE_SYS_IOCTL_H
+#  include <sys/ioctl.h>
+# endif
 # define closesocket close
+# define ioctlsocket ioctl
 #endif /* defined(__MINGW32__) || defined (_MSC_VER) */
 
-#include <winsock2.h>
-#include <ws2tcpip.h>
-
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
 #include "winerror.h"
+#include "wininet.h"
 #include "winternl.h"
 #include "wine/unicode.h"
 
@@ -83,16 +90,17 @@
 #include "wine/debug.h"
 
 #include "rpc_binding.h"
+#include "rpc_assoc.h"
 #include "rpc_message.h"
 #include "rpc_server.h"
 #include "epm_towers.h"
 
-#include "unix_func.h"
-
 #ifndef SOL_TCP
 # define SOL_TCP IPPROTO_TCP
 #endif
 
+#define DEFAULT_NCACN_HTTP_TIMEOUT (60 * 1000)
+
 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
 
 static RPC_STATUS RPCRT4_SpawnConnection(RpcConnection** Connection, RpcConnection* OldConnection);
@@ -258,13 +266,24 @@
   return r;
 }
 
-static RPC_STATUS rpcrt4_protseq_ncalrpc_open_endpoint(RpcServerProtseq* protseq, LPSTR endpoint)
+static RPC_STATUS rpcrt4_protseq_ncalrpc_open_endpoint(RpcServerProtseq* protseq, const char *endpoint)
 {
   static const char prefix[] = "\\\\.\\pipe\\lrpc\\";
   RPC_STATUS r;
   LPSTR pname;
   RpcConnection *Connection;
+  char generated_endpoint[22];
 
+  if (!endpoint)
+  {
+    static LONG lrpc_nameless_id;
+    DWORD process_id = GetCurrentProcessId();
+    ULONG id = InterlockedIncrement(&lrpc_nameless_id);
+    snprintf(generated_endpoint, sizeof(generated_endpoint),
+             "LRPC%08x.%08x", process_id, id);
+    endpoint = generated_endpoint;
+  }
+
   r = RPCRT4_CreateConnection(&Connection, TRUE, protseq->Protseq, NULL,
                               endpoint, NULL, NULL, NULL);
   if (r != RPC_S_OK)
@@ -305,13 +324,24 @@
   return r;
 }
 
-static RPC_STATUS rpcrt4_protseq_ncacn_np_open_endpoint(RpcServerProtseq *protseq, LPSTR endpoint)
+static RPC_STATUS rpcrt4_protseq_ncacn_np_open_endpoint(RpcServerProtseq *protseq, const char *endpoint)
 {
   static const char prefix[] = "\\\\.";
   RPC_STATUS r;
   LPSTR pname;
   RpcConnection *Connection;
+  char generated_endpoint[21];
 
+  if (!endpoint)
+  {
+    static LONG np_nameless_id;
+    DWORD process_id = GetCurrentProcessId();
+    ULONG id = InterlockedExchangeAdd(&np_nameless_id, 1 );
+    snprintf(generated_endpoint, sizeof(generated_endpoint),
+             "\\\\pipe\\\\%08x.%03x", process_id, id);
+    endpoint = generated_endpoint;
+  }
+
   r = RPCRT4_CreateConnection(&Connection, TRUE, protseq->Protseq, NULL,
                               endpoint, NULL, NULL, NULL);
   if (r != RPC_S_OK)
@@ -756,15 +786,294 @@
 
 /**** ncacn_ip_tcp support ****/
 
-#ifdef HAVE_SOCKETPAIR
+static size_t rpcrt4_ip_tcp_get_top_of_tower(unsigned char *tower_data,
+                                             const char *networkaddr,
+                                             unsigned char tcp_protid,
+                                             const char *endpoint)
+{
+    twr_tcp_floor_t *tcp_floor;
+    twr_ipv4_floor_t *ipv4_floor;
+    struct addrinfo *ai;
+    struct addrinfo hints;
+    int ret;
+    size_t size = sizeof(*tcp_floor) + sizeof(*ipv4_floor);
 
+    TRACE("(%p, %s, %s)\n", tower_data, networkaddr, endpoint);
+
+    if (!tower_data)
+        return size;
+
+    tcp_floor = (twr_tcp_floor_t *)tower_data;
+    tower_data += sizeof(*tcp_floor);
+
+    ipv4_floor = (twr_ipv4_floor_t *)tower_data;
+
+    tcp_floor->count_lhs = sizeof(tcp_floor->protid);
+    tcp_floor->protid = tcp_protid;
+    tcp_floor->count_rhs = sizeof(tcp_floor->port);
+
+    ipv4_floor->count_lhs = sizeof(ipv4_floor->protid);
+    ipv4_floor->protid = EPM_PROTOCOL_IP;
+    ipv4_floor->count_rhs = sizeof(ipv4_floor->ipv4addr);
+
+    hints.ai_flags          = AI_NUMERICHOST;
+    /* FIXME: only support IPv4 at the moment. how is IPv6 represented by the EPM? */
+    hints.ai_family         = PF_INET;
+    hints.ai_socktype       = SOCK_STREAM;
+    hints.ai_protocol       = IPPROTO_TCP;
+    hints.ai_addrlen        = 0;
+    hints.ai_addr           = NULL;
+    hints.ai_canonname      = NULL;
+    hints.ai_next           = NULL;
+
+    ret = getaddrinfo(networkaddr, endpoint, &hints, &ai);
+    if (ret)
+    {
+        ret = getaddrinfo("0.0.0.0", endpoint, &hints, &ai);
+        if (ret)
+        {
+            ERR("getaddrinfo failed: %s\n", gai_strerror(ret));
+            return 0;
+        }
+    }
+
+    if (ai->ai_family == PF_INET)
+    {
+        const struct sockaddr_in *sin = (const struct sockaddr_in *)ai->ai_addr;
+        tcp_floor->port = sin->sin_port;
+        ipv4_floor->ipv4addr = sin->sin_addr.s_addr;
+    }
+    else
+    {
+        ERR("unexpected protocol family %d\n", ai->ai_family);
+        return 0;
+    }
+
+    freeaddrinfo(ai);
+
+    return size;
+}
+
+static RPC_STATUS rpcrt4_ip_tcp_parse_top_of_tower(const unsigned char *tower_data,
+                                                   size_t tower_size,
+                                                   char **networkaddr,
+                                                   unsigned char tcp_protid,
+                                                   char **endpoint)
+{
+    const twr_tcp_floor_t *tcp_floor = (const twr_tcp_floor_t *)tower_data;
+    const twr_ipv4_floor_t *ipv4_floor;
+    struct in_addr in_addr;
+
+    TRACE("(%p, %d, %p, %p)\n", tower_data, (int)tower_size, networkaddr, endpoint);
+
+    if (tower_size < sizeof(*tcp_floor))
+        return EPT_S_NOT_REGISTERED;
+
+    tower_data += sizeof(*tcp_floor);
+    tower_size -= sizeof(*tcp_floor);
+
+    if (tower_size < sizeof(*ipv4_floor))
+        return EPT_S_NOT_REGISTERED;
+
+    ipv4_floor = (const twr_ipv4_floor_t *)tower_data;
+
+    if ((tcp_floor->count_lhs != sizeof(tcp_floor->protid)) ||
+        (tcp_floor->protid != tcp_protid) ||
+        (tcp_floor->count_rhs != sizeof(tcp_floor->port)) ||
+        (ipv4_floor->count_lhs != sizeof(ipv4_floor->protid)) ||
+        (ipv4_floor->protid != EPM_PROTOCOL_IP) ||
+        (ipv4_floor->count_rhs != sizeof(ipv4_floor->ipv4addr)))
+        return EPT_S_NOT_REGISTERED;
+
+    if (endpoint)
+    {
+        *endpoint = I_RpcAllocate(6 /* sizeof("65535") + 1 */);
+        if (!*endpoint)
+            return RPC_S_OUT_OF_RESOURCES;
+        sprintf(*endpoint, "%u", ntohs(tcp_floor->port));
+    }
+
+    if (networkaddr)
+    {
+        *networkaddr = I_RpcAllocate(INET_ADDRSTRLEN);
+        if (!*networkaddr)
+        {
+            if (endpoint)
+            {
+                I_RpcFree(*endpoint);
+                *endpoint = NULL;
+            }
+            return RPC_S_OUT_OF_RESOURCES;
+        }
+        in_addr.s_addr = ipv4_floor->ipv4addr;
+        if (!inet_ntop(AF_INET, &in_addr, *networkaddr, INET_ADDRSTRLEN))
+        {
+            ERR("inet_ntop: %s\n", strerror(errno));
+            I_RpcFree(*networkaddr);
+            *networkaddr = NULL;
+            if (endpoint)
+            {
+                I_RpcFree(*endpoint);
+                *endpoint = NULL;
+            }
+            return EPT_S_NOT_REGISTERED;
+        }
+    }
+
+    return RPC_S_OK;
+}
+
 typedef struct _RpcConnection_tcp
 {
   RpcConnection common;
   int sock;
+#ifdef HAVE_SOCKETPAIR
   int cancel_fds[2];
+#else
+  HANDLE sock_event;
+  HANDLE cancel_event;
+#endif
 } RpcConnection_tcp;
 
+#ifdef HAVE_SOCKETPAIR
+
+static BOOL rpcrt4_sock_wait_init(RpcConnection_tcp *tcpc)
+{
+  if (socketpair(PF_UNIX, SOCK_STREAM, 0, tcpc->cancel_fds) < 0)
+  {
+    ERR("socketpair() failed: %s\n", strerror(errno));
+    return FALSE;
+  }
+  return TRUE;
+}
+
+static BOOL rpcrt4_sock_wait_for_recv(RpcConnection_tcp *tcpc)
+{
+  struct pollfd pfds[2];
+  pfds[0].fd = tcpc->sock;
+  pfds[0].events = POLLIN;
+  pfds[1].fd = tcpc->cancel_fds[0];
+  pfds[1].events = POLLIN;
+  if (poll(pfds, 2, -1 /* infinite */) == -1 && errno != EINTR)
+  {
+    ERR("poll() failed: %s\n", strerror(errno));
+    return FALSE;
+  }
+  if (pfds[1].revents & POLLIN) /* canceled */
+  {
+    char dummy;
+    read(pfds[1].fd, &dummy, sizeof(dummy));
+    return FALSE;
+  }
+  return TRUE;
+}
+
+static BOOL rpcrt4_sock_wait_for_send(RpcConnection_tcp *tcpc)
+{
+  struct pollfd pfd;
+  pfd.fd = tcpc->sock;
+  pfd.events = POLLOUT;
+  if (poll(&pfd, 1, -1 /* infinite */) == -1 && errno != EINTR)
+  {
+    ERR("poll() failed: %s\n", strerror(errno));
+    return FALSE;
+  }
+  return TRUE;
+}
+
+static void rpcrt4_sock_wait_cancel(RpcConnection_tcp *tcpc)
+{
+  char dummy = 1;
+
+  write(tcpc->cancel_fds[1], &dummy, 1);
+}
+
+static void rpcrt4_sock_wait_destroy(RpcConnection_tcp *tcpc)
+{
+  close(tcpc->cancel_fds[0]);
+  close(tcpc->cancel_fds[1]);
+}
+
+#else /* HAVE_SOCKETPAIR */
+
+static BOOL rpcrt4_sock_wait_init(RpcConnection_tcp *tcpc)
+{
+  static BOOL wsa_inited;
+  if (!wsa_inited)
+  {
+    WSADATA wsadata;
+    WSAStartup(MAKEWORD(2, 2), &wsadata);
+    /* Note: WSAStartup can be called more than once so we don't bother with
+     * making accesses to wsa_inited thread-safe */
+    wsa_inited = TRUE;
+  }
+  tcpc->sock_event = CreateEventW(NULL, FALSE, FALSE, NULL);
+  tcpc->cancel_event = CreateEventW(NULL, FALSE, FALSE, NULL);
+  if (!tcpc->sock_event || !tcpc->cancel_event)
+  {
+    ERR("event creation failed\n");
+    if (tcpc->sock_event) CloseHandle(tcpc->sock_event);
+    return FALSE;
+  }
+  return TRUE;
+}
+
+static BOOL rpcrt4_sock_wait_for_recv(RpcConnection_tcp *tcpc)
+{
+  HANDLE wait_handles[2];
+  DWORD res;
+  if (WSAEventSelect(tcpc->sock, tcpc->sock_event, FD_READ | FD_CLOSE) == SOCKET_ERROR)
+  {
+    ERR("WSAEventSelect() failed with error %d\n", WSAGetLastError());
+    return FALSE;
+  }
+  wait_handles[0] = tcpc->sock_event;
+  wait_handles[1] = tcpc->cancel_event;
+  res = WaitForMultipleObjects(2, wait_handles, FALSE, INFINITE);
+  switch (res)
+  {
+  case WAIT_OBJECT_0:
+    return TRUE;
+  case WAIT_OBJECT_0 + 1:
+    return FALSE;
+  default:
+    ERR("WaitForMultipleObjects() failed with error %d\n", GetLastError());
+    return FALSE;
+  }
+}
+
+static BOOL rpcrt4_sock_wait_for_send(RpcConnection_tcp *tcpc)
+{
+  DWORD res;
+  if (WSAEventSelect(tcpc->sock, tcpc->sock_event, FD_WRITE | FD_CLOSE) == SOCKET_ERROR)
+  {
+    ERR("WSAEventSelect() failed with error %d\n", WSAGetLastError());
+    return FALSE;
+  }
+  res = WaitForSingleObject(tcpc->sock_event, INFINITE);
+  switch (res)
+  {
+  case WAIT_OBJECT_0:
+    return TRUE;
+  default:
+    ERR("WaitForMultipleObjects() failed with error %d\n", GetLastError());
+    return FALSE;
+  }
+}
+
+static void rpcrt4_sock_wait_cancel(RpcConnection_tcp *tcpc)
+{
+  SetEvent(tcpc->cancel_event);
+}
+
+static void rpcrt4_sock_wait_destroy(RpcConnection_tcp *tcpc)
+{
+  CloseHandle(tcpc->sock_event);
+  CloseHandle(tcpc->cancel_event);
+}
+
+#endif
+
 static RpcConnection *rpcrt4_conn_tcp_alloc(void)
 {
   RpcConnection_tcp *tcpc;
@@ -772,9 +1081,8 @@
   if (tcpc == NULL)
     return NULL;
   tcpc->sock = -1;
-  if (socketpair(PF_UNIX, SOCK_STREAM, 0, tcpc->cancel_fds) < 0)
+  if (!rpcrt4_sock_wait_init(tcpc))
   {
-    ERR("socketpair() failed: %s\n", strerror(errno));
     HeapFree(GetProcessHeap(), 0, tcpc);
     return NULL;
   }
@@ -815,7 +1123,14 @@
   for (ai_cur = ai; ai_cur; ai_cur = ai_cur->ai_next)
   {
     int val;
+    u_long nonblocking;
 
+    if (ai_cur->ai_family != AF_INET && ai_cur->ai_family != AF_INET6)
+    {
+      TRACE("skipping non-IP/IPv6 address family\n");
+      continue;
+    }
+
     if (TRACE_ON(rpc))
     {
       char host[256];
@@ -842,7 +1157,7 @@
 
     /* RPC depends on having minimal latency so disable the Nagle algorithm */
     val = 1;
-    setsockopt(sock, SOL_TCP, TCP_NODELAY, &val, sizeof(val));
+    setsockopt(sock, SOL_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
     fcntl(sock, F_SETFL, O_NONBLOCK); /* make socket nonblocking */
 
     tcpc->sock = sock;
@@ -857,7 +1172,7 @@
   return RPC_S_SERVER_UNAVAILABLE;
 }
 
-static RPC_STATUS rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(RpcServerProtseq *protseq, LPSTR endpoint)
+static RPC_STATUS rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(RpcServerProtseq *protseq, const char *endpoint)
 {
     RPC_STATUS status = RPC_S_CANT_CREATE_ENDPOINT;
     int sock;
@@ -878,7 +1193,7 @@
     hints.ai_canonname      = NULL;
     hints.ai_next           = NULL;
 
-    ret = getaddrinfo(NULL, endpoint, &hints, &ai);
+    ret = getaddrinfo(NULL, endpoint ? endpoint : "0", &hints, &ai);
     if (ret)
     {
         ERR("getaddrinfo for port %s failed: %s\n", endpoint,
@@ -892,11 +1207,20 @@
     {
         RpcConnection_tcp *tcpc;
         RPC_STATUS create_status;
+        struct sockaddr_storage sa;
+        socklen_t sa_len;
+        char service[NI_MAXSERV];
+        u_long nonblocking;
 
+        if (ai_cur->ai_family != AF_INET && ai_cur->ai_family != AF_INET6)
+        {
+            TRACE("skipping non-IP/IPv6 address family\n");
+            continue;
+        }
+
         if (TRACE_ON(rpc))
         {
             char host[256];
-            char service[256];
             getnameinfo(ai_cur->ai_addr, ai_cur->ai_addrlen,
                         host, sizeof(host), service, sizeof(service),
                         NI_NUMERICHOST | NI_NUMERICSERV);
@@ -922,9 +1246,28 @@
               status = RPC_S_CANT_CREATE_ENDPOINT;
             continue;
         }
+
+        sa_len = sizeof(sa);
+        if (getsockname(sock, (struct sockaddr *)&sa, &sa_len))
+        {
+            WARN("getsockname() failed: %s\n", strerror(errno));
+            status = RPC_S_CANT_CREATE_ENDPOINT;
+            continue;
+        }
+
+        ret = getnameinfo((struct sockaddr *)&sa, sa_len,
+                          NULL, 0, service, sizeof(service),
+                          NI_NUMERICSERV);
+        if (ret)
+        {
+            WARN("getnameinfo failed: %s\n", gai_strerror(ret));
+            status = RPC_S_CANT_CREATE_ENDPOINT;
+            continue;
+        }
+
         create_status = RPCRT4_CreateConnection((RpcConnection **)&tcpc, TRUE,
                                                 protseq->Protseq, NULL,
-                                                endpoint, NULL, NULL, NULL);
+                                                service, NULL, NULL, NULL);
         if (create_status != RPC_S_OK)
         {
             closesocket(sock);
@@ -956,6 +1299,10 @@
 
         tcpc->common.Next = first_connection;
         first_connection = &tcpc->common;
+
+        /* since IPv4 and IPv6 share the same port space, we only need one
+         * successful bind to listen for both */
+        break;
     }
 
     freeaddrinfo(ai);
@@ -1024,22 +1371,8 @@
     }
     else
     {
-      struct pollfd pfds[2];
-      pfds[0].fd = tcpc->sock;
-      pfds[0].events = POLLIN;
-      pfds[1].fd = tcpc->cancel_fds[0];
-      pfds[1].events = POLLIN;
-      if (poll(pfds, 2, -1 /* infinite */) == -1 && errno != EINTR)
-      {
-        ERR("poll() failed: %s\n", strerror(errno));
+      if (!rpcrt4_sock_wait_for_recv(tcpc))
         return -1;
-      }
-      if (pfds[1].revents & POLLIN) /* canceled */
-      {
-        char dummy;
-        read(pfds[1].fd, &dummy, sizeof(dummy));
-        return -1;
-      }
     }
   } while (bytes_read != count);
   TRACE("%d %p %u -> %d\n", tcpc->sock, buffer, count, bytes_read);
@@ -1060,14 +1393,8 @@
       return -1;
     else
     {
-      struct pollfd pfd;
-      pfd.fd = tcpc->sock;
-      pfd.events = POLLOUT;
-      if (poll(&pfd, 1, -1 /* infinite */) == -1 && errno != EINTR)
-      {
-        ERR("poll() failed: %s\n", strerror(errno));
+      if (!rpcrt4_sock_wait_for_send(tcpc))
         return -1;
-      }
     }
   } while (bytes_written != count);
   TRACE("%d %p %u -> %d\n", tcpc->sock, buffer, count, bytes_written);
@@ -1083,44 +1410,25 @@
   if (tcpc->sock != -1)
     closesocket(tcpc->sock);
   tcpc->sock = -1;
-  close(tcpc->cancel_fds[0]);
-  close(tcpc->cancel_fds[1]);
+  rpcrt4_sock_wait_destroy(tcpc);
   return 0;
 }
 
 static void rpcrt4_conn_tcp_cancel_call(RpcConnection *Connection)
 {
     RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
-    char dummy = 1;
-
     TRACE("%p\n", Connection);
-
-    write(tcpc->cancel_fds[1], &dummy, 1);
+    rpcrt4_sock_wait_cancel(tcpc);
 }
 
 static int rpcrt4_conn_tcp_wait_for_incoming_data(RpcConnection *Connection)
 {
     RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
-    struct pollfd pfds[2];
 
     TRACE("%p\n", Connection);
 
-    pfds[0].fd = tcpc->sock;
-    pfds[0].events = POLLIN;
-    pfds[1].fd = tcpc->cancel_fds[0];
-    pfds[1].events = POLLIN;
-    if (poll(pfds, 2, -1 /* infinite */) == -1 && errno != EINTR)
-    {
-      ERR("poll() failed: %s\n", strerror(errno));
-      return -1;
-    }
-    if (pfds[1].revents & POLLIN) /* canceled */
-    {
-      char dummy;
-      read(pfds[1].fd, &dummy, sizeof(dummy));
-      return -1;
-    }
-
+    if (!rpcrt4_sock_wait_for_recv(tcpc))
+        return -1;
     return 0;
 }
 
@@ -1128,137 +1436,12 @@
                                                    const char *networkaddr,
                                                    const char *endpoint)
 {
-    twr_tcp_floor_t *tcp_floor;
-    twr_ipv4_floor_t *ipv4_floor;
-    struct addrinfo *ai;
-    struct addrinfo hints;
-    int ret;
-    size_t size = sizeof(*tcp_floor) + sizeof(*ipv4_floor);
-
-    TRACE("(%p, %s, %s)\n", tower_data, networkaddr, endpoint);
-
-    if (!tower_data)
-        return size;
-
-    tcp_floor = (twr_tcp_floor_t *)tower_data;
-    tower_data += sizeof(*tcp_floor);
-
-    ipv4_floor = (twr_ipv4_floor_t *)tower_data;
-
-    tcp_floor->count_lhs = sizeof(tcp_floor->protid);
-    tcp_floor->protid = EPM_PROTOCOL_TCP;
-    tcp_floor->count_rhs = sizeof(tcp_floor->port);
-
-    ipv4_floor->count_lhs = sizeof(ipv4_floor->protid);
-    ipv4_floor->protid = EPM_PROTOCOL_IP;
-    ipv4_floor->count_rhs = sizeof(ipv4_floor->ipv4addr);
-
-    hints.ai_flags          = AI_NUMERICHOST;
-    /* FIXME: only support IPv4 at the moment. how is IPv6 represented by the EPM? */
-    hints.ai_family         = PF_INET;
-    hints.ai_socktype       = SOCK_STREAM;
-    hints.ai_protocol       = IPPROTO_TCP;
-    hints.ai_addrlen        = 0;
-    hints.ai_addr           = NULL;
-    hints.ai_canonname      = NULL;
-    hints.ai_next           = NULL;
-
-    ret = getaddrinfo(networkaddr, endpoint, &hints, &ai);
-    if (ret)
-    {
-        ret = getaddrinfo("0.0.0.0", endpoint, &hints, &ai);
-        if (ret)
-        {
-            ERR("getaddrinfo failed: %s\n", gai_strerror(ret));
-            return 0;
-        }
-    }
-
-    if (ai->ai_family == PF_INET)
-    {
-        const struct sockaddr_in *sin = (const struct sockaddr_in *)ai->ai_addr;
-        tcp_floor->port = sin->sin_port;
-        ipv4_floor->ipv4addr = sin->sin_addr.s_addr;
-    }
-    else
-    {
-        ERR("unexpected protocol family %d\n", ai->ai_family);
-        return 0;
-    }
-
-    freeaddrinfo(ai);
-
-    return size;
+    return rpcrt4_ip_tcp_get_top_of_tower(tower_data, networkaddr,
+                                          EPM_PROTOCOL_TCP, endpoint);
 }
 
-static RPC_STATUS rpcrt4_ncacn_ip_tcp_parse_top_of_tower(const unsigned char *tower_data,
-                                                         size_t tower_size,
-                                                         char **networkaddr,
-                                                         char **endpoint)
-{
-    const twr_tcp_floor_t *tcp_floor = (const twr_tcp_floor_t *)tower_data;
-    const twr_ipv4_floor_t *ipv4_floor;
-    struct in_addr in_addr;
+#ifdef HAVE_SOCKETPAIR
 
-    TRACE("(%p, %d, %p, %p)\n", tower_data, (int)tower_size, networkaddr, endpoint);
-
-    if (tower_size < sizeof(*tcp_floor))
-        return EPT_S_NOT_REGISTERED;
-
-    tower_data += sizeof(*tcp_floor);
-    tower_size -= sizeof(*tcp_floor);
-
-    if (tower_size < sizeof(*ipv4_floor))
-        return EPT_S_NOT_REGISTERED;
-
-    ipv4_floor = (const twr_ipv4_floor_t *)tower_data;
-
-    if ((tcp_floor->count_lhs != sizeof(tcp_floor->protid)) ||
-        (tcp_floor->protid != EPM_PROTOCOL_TCP) ||
-        (tcp_floor->count_rhs != sizeof(tcp_floor->port)) ||
-        (ipv4_floor->count_lhs != sizeof(ipv4_floor->protid)) ||
-        (ipv4_floor->protid != EPM_PROTOCOL_IP) ||
-        (ipv4_floor->count_rhs != sizeof(ipv4_floor->ipv4addr)))
-        return EPT_S_NOT_REGISTERED;
-
-    if (endpoint)
-    {
-        *endpoint = I_RpcAllocate(6 /* sizeof("65535") + 1 */);
-        if (!*endpoint)
-            return RPC_S_OUT_OF_RESOURCES;
-        sprintf(*endpoint, "%u", ntohs(tcp_floor->port));
-    }
-
-    if (networkaddr)
-    {
-        *networkaddr = I_RpcAllocate(INET_ADDRSTRLEN);
-        if (!*networkaddr)
-        {
-            if (endpoint)
-            {
-                I_RpcFree(*endpoint);
-                *endpoint = NULL;
-            }
-            return RPC_S_OUT_OF_RESOURCES;
-        }
-        in_addr.s_addr = ipv4_floor->ipv4addr;
-        if (!inet_ntop(AF_INET, &in_addr, *networkaddr, INET_ADDRSTRLEN))
-        {
-            ERR("inet_ntop: %s\n", strerror(errno));
-            I_RpcFree(*networkaddr);
-            *networkaddr = NULL;
-            if (endpoint)
-            {
-                I_RpcFree(*endpoint);
-                *endpoint = NULL;
-            }
-            return EPT_S_NOT_REGISTERED;
-        }
-    }
-
-    return RPC_S_OK;
-}
-
 typedef struct _RpcServerProtseq_sock
 {
     RpcServerProtseq common;
@@ -1398,8 +1581,1100 @@
     return 1;
 }
 
+#else /* HAVE_SOCKETPAIR */
+
+typedef struct _RpcServerProtseq_sock
+{
+    RpcServerProtseq common;
+    HANDLE mgr_event;
+} RpcServerProtseq_sock;
+
+static RpcServerProtseq *rpcrt4_protseq_sock_alloc(void)
+{
+    RpcServerProtseq_sock *ps = HeapAlloc(GetProcessHeap(), 0, sizeof(*ps));
+    if (ps)
+    {
+        static BOOL wsa_inited;
+        if (!wsa_inited)
+        {
+            WSADATA wsadata;
+            WSAStartup(MAKEWORD(2, 2), &wsadata);
+            /* Note: WSAStartup can be called more than once so we don't bother with
+             * making accesses to wsa_inited thread-safe */
+            wsa_inited = TRUE;
+        }
+        ps->mgr_event = CreateEventW(NULL, FALSE, FALSE, NULL);
+    }
+    return &ps->common;
+}
+
+static void rpcrt4_protseq_sock_signal_state_changed(RpcServerProtseq *protseq)
+{
+    RpcServerProtseq_sock *sockps = CONTAINING_RECORD(protseq, RpcServerProtseq_sock, common);
+    SetEvent(sockps->mgr_event);
+}
+
+static void *rpcrt4_protseq_sock_get_wait_array(RpcServerProtseq *protseq, void *prev_array, unsigned int *count)
+{
+    HANDLE *objs = prev_array;
+    RpcConnection_tcp *conn;
+    RpcServerProtseq_sock *sockps = CONTAINING_RECORD(protseq, RpcServerProtseq_sock, common);
+
+    EnterCriticalSection(&protseq->cs);
+
+    /* open and count connections */
+    *count = 1;
+    conn = CONTAINING_RECORD(protseq->conn, RpcConnection_tcp, common);
+    while (conn)
+    {
+        if (conn->sock != -1)
+            (*count)++;
+        conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_tcp, common);
+    }
+
+    /* make array of connections */
+    if (objs)
+        objs = HeapReAlloc(GetProcessHeap(), 0, objs, *count*sizeof(HANDLE));
+    else
+        objs = HeapAlloc(GetProcessHeap(), 0, *count*sizeof(HANDLE));
+    if (!objs)
+    {
+        ERR("couldn't allocate objs\n");
+        LeaveCriticalSection(&protseq->cs);
+        return NULL;
+    }
+
+    objs[0] = sockps->mgr_event;
+    *count = 1;
+    conn = CONTAINING_RECORD(protseq->conn, RpcConnection_tcp, common);
+    while (conn)
+    {
+        if (conn->sock != -1)
+        {
+            int res = WSAEventSelect(conn->sock, conn->sock_event, FD_ACCEPT);
+            if (res == SOCKET_ERROR)
+                ERR("WSAEventSelect() failed with error %d\n", WSAGetLastError());
+            else
+            {
+                objs[*count] = conn->sock_event;
+                (*count)++;
+            }
+        }
+        conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_tcp, common);
+    }
+    LeaveCriticalSection(&protseq->cs);
+    return objs;
+}
+
+static void rpcrt4_protseq_sock_free_wait_array(RpcServerProtseq *protseq, void *array)
+{
+    HeapFree(GetProcessHeap(), 0, array);
+}
+
+static int rpcrt4_protseq_sock_wait_for_new_connection(RpcServerProtseq *protseq, unsigned int count, void *wait_array)
+{
+    HANDLE b_handle;
+    HANDLE *objs = wait_array;
+    DWORD res;
+    RpcConnection *cconn;
+    RpcConnection_tcp *conn;
+
+    if (!objs)
+        return -1;
+
+    do
+    {
+        /* an alertable wait isn't strictly necessary, but due to our
+         * overlapped I/O implementation in Wine we need to free some memory
+         * by the file user APC being called, even if no completion routine was
+         * specified at the time of starting the async operation */
+        res = WaitForMultipleObjectsEx(count, objs, FALSE, INFINITE, TRUE);
+    } while (res == WAIT_IO_COMPLETION);
+
+    if (res == WAIT_OBJECT_0)
+        return 0;
+    else if (res == WAIT_FAILED)
+    {
+        ERR("wait failed with error %d\n", GetLastError());
+        return -1;
+    }
+    else
+    {
+        b_handle = objs[res - WAIT_OBJECT_0];
+        /* find which connection got a RPC */
+        EnterCriticalSection(&protseq->cs);
+        conn = CONTAINING_RECORD(protseq->conn, RpcConnection_tcp, common);
+        while (conn)
+        {
+            if (b_handle == conn->sock_event) break;
+            conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_tcp, common);
+        }
+        cconn = NULL;
+        if (conn)
+            RPCRT4_SpawnConnection(&cconn, &conn->common);
+        else
+            ERR("failed to locate connection for handle %p\n", b_handle);
+        LeaveCriticalSection(&protseq->cs);
+        if (cconn)
+        {
+            RPCRT4_new_client(cconn);
+            return 1;
+        }
+        else return -1;
+    }
+}
+
 #endif  /* HAVE_SOCKETPAIR */
 
+static RPC_STATUS rpcrt4_ncacn_ip_tcp_parse_top_of_tower(const unsigned char *tower_data,
+                                                         size_t tower_size,
+                                                         char **networkaddr,
+                                                         char **endpoint)
+{
+    return rpcrt4_ip_tcp_parse_top_of_tower(tower_data, tower_size,
+                                            networkaddr, EPM_PROTOCOL_TCP,
+                                            endpoint);
+}
+
+/**** ncacn_http support ****/
+
+/* 60 seconds is the period native uses */
+#define HTTP_IDLE_TIME 60000
+
+/* reference counted to avoid a race between a cancelled call's connection
+ * being destroyed and the asynchronous InternetReadFileEx call being
+ * completed */
+typedef struct _RpcHttpAsyncData
+{
+    LONG refs;
+    HANDLE completion_event;
+    INTERNET_BUFFERSA inet_buffers;
+    void *destination_buffer; /* the address that inet_buffers.lpvBuffer will be
+                               * copied into when the call completes */
+    CRITICAL_SECTION cs;
+} RpcHttpAsyncData;
+
+static ULONG RpcHttpAsyncData_AddRef(RpcHttpAsyncData *data)
+{
+    return InterlockedIncrement(&data->refs);
+}
+
+static ULONG RpcHttpAsyncData_Release(RpcHttpAsyncData *data)
+{
+    ULONG refs = InterlockedDecrement(&data->refs);
+    if (!refs)
+    {
+        TRACE("destroying async data %p\n", data);
+        CloseHandle(data->completion_event);
+        HeapFree(GetProcessHeap(), 0, data->inet_buffers.lpvBuffer);
+        DeleteCriticalSection(&data->cs);
+        HeapFree(GetProcessHeap(), 0, data);
+    }
+    return refs;
+}
+
+typedef struct _RpcConnection_http
+{
+    RpcConnection common;
+    HINTERNET app_info;
+    HINTERNET session;
+    HINTERNET in_request;
+    HINTERNET out_request;
+    HANDLE timer_cancelled;
+    HANDLE cancel_event;
+    DWORD last_sent_time;
+    ULONG bytes_received;
+    ULONG flow_control_mark; /* send a control packet to the server when this many bytes received */
+    ULONG flow_control_increment; /* number of bytes to increment flow_control_mark by */
+    UUID connection_uuid;
+    UUID in_pipe_uuid;
+    UUID out_pipe_uuid;
+    RpcHttpAsyncData *async_data;
+} RpcConnection_http;
+
+static RpcConnection *rpcrt4_ncacn_http_alloc(void)
+{
+    RpcConnection_http *httpc;
+    httpc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*httpc));
+    if (!httpc) return NULL;
+    httpc->async_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcHttpAsyncData));
+    if (!httpc->async_data)
+    {
+        HeapFree(GetProcessHeap(), 0, httpc);
+        return NULL;
+    }
+    TRACE("async data = %p\n", httpc->async_data);
+    httpc->cancel_event = CreateEventW(NULL, FALSE, FALSE, NULL);
+    httpc->async_data->refs = 1;
+    httpc->async_data->inet_buffers.dwStructSize = sizeof(INTERNET_BUFFERSA);
+    httpc->async_data->inet_buffers.lpvBuffer = NULL;
+    httpc->async_data->destination_buffer = NULL;
+    InitializeCriticalSection(&httpc->async_data->cs);
+    return &httpc->common;
+}
+
+typedef struct _HttpTimerThreadData
+{
+    PVOID timer_param;
+    DWORD *last_sent_time;
+    HANDLE timer_cancelled;
+} HttpTimerThreadData;
+
+static VOID rpcrt4_http_keep_connection_active_timer_proc(PVOID param, BOOLEAN dummy)
+{
+    HINTERNET in_request = param;
+    RpcPktHdr *idle_pkt;
+
+    idle_pkt = RPCRT4_BuildHttpHeader(NDR_LOCAL_DATA_REPRESENTATION, 0x0001,
+                                      0, 0);
+    if (idle_pkt)
+    {
+        DWORD bytes_written;
+        InternetWriteFile(in_request, idle_pkt, idle_pkt->common.frag_len, &bytes_written);
+        RPCRT4_FreeHeader(idle_pkt);
+    }
+}
+
+static inline DWORD rpcrt4_http_timer_calc_timeout(DWORD *last_sent_time)
+{
+    DWORD cur_time = GetTickCount();
+    DWORD cached_last_sent_time = *last_sent_time;
+    return HTTP_IDLE_TIME - (cur_time - cached_last_sent_time > HTTP_IDLE_TIME ? 0 : cur_time - cached_last_sent_time);
+}
+
+static DWORD CALLBACK rpcrt4_http_timer_thread(PVOID param)
+{
+    HttpTimerThreadData *data_in = param;
+    HttpTimerThreadData data;
+    DWORD timeout;
+
+    data = *data_in;
+    HeapFree(GetProcessHeap(), 0, data_in);
+
+    for (timeout = HTTP_IDLE_TIME;
+         WaitForSingleObject(data.timer_cancelled, timeout) == WAIT_TIMEOUT;
+         timeout = rpcrt4_http_timer_calc_timeout(data.last_sent_time))
+    {
+        /* are we too soon after last send? */
+        if (GetTickCount() - HTTP_IDLE_TIME < *data.last_sent_time)
+            continue;
+        rpcrt4_http_keep_connection_active_timer_proc(data.timer_param, TRUE);
+    }
+
+    CloseHandle(data.timer_cancelled);
+    return 0;
+}
+
+static VOID WINAPI rpcrt4_http_internet_callback(
+     HINTERNET hInternet,
+     DWORD_PTR dwContext,
+     DWORD dwInternetStatus,
+     LPVOID lpvStatusInformation,
+     DWORD dwStatusInformationLength)
+{
+    RpcHttpAsyncData *async_data = (RpcHttpAsyncData *)dwContext;
+
+    switch (dwInternetStatus)
+    {
+    case INTERNET_STATUS_REQUEST_COMPLETE:
+        TRACE("INTERNET_STATUS_REQUEST_COMPLETED\n");
+        if (async_data)
+        {
+            if (async_data->inet_buffers.lpvBuffer)
+            {
+                EnterCriticalSection(&async_data->cs);
+                if (async_data->destination_buffer)
+                {
+                    memcpy(async_data->destination_buffer,
+                           async_data->inet_buffers.lpvBuffer,
+                           async_data->inet_buffers.dwBufferLength);
+                    async_data->destination_buffer = NULL;
+                }
+                LeaveCriticalSection(&async_data->cs);
+            }
+            HeapFree(GetProcessHeap(), 0, async_data->inet_buffers.lpvBuffer);
+            async_data->inet_buffers.lpvBuffer = NULL;
+            SetEvent(async_data->completion_event);
+            RpcHttpAsyncData_Release(async_data);
+        }
+        break;
+    }
+}
+
+static RPC_STATUS rpcrt4_http_check_response(HINTERNET hor)
+{
+    BOOL ret;
+    DWORD status_code;
+    DWORD size;
+    DWORD index;
+    WCHAR buf[32];
+    WCHAR *status_text = buf;
+    TRACE("\n");
+
+    index = 0;
+    size = sizeof(status_code);
+    ret = HttpQueryInfoW(hor, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status_code, &size, &index);
+    if (!ret)
+        return GetLastError();
+    if (status_code < 400)
+        return RPC_S_OK;
+    index = 0;
+    size = sizeof(buf);
+    ret = HttpQueryInfoW(hor, HTTP_QUERY_STATUS_TEXT, status_text, &size, &index);
+    if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+    {
+        status_text = HeapAlloc(GetProcessHeap(), 0, size);
+        ret = HttpQueryInfoW(hor, HTTP_QUERY_STATUS_TEXT, status_text, &size, &index);
+    }
+
+    ERR("server returned: %d %s\n", status_code, ret ? debugstr_w(status_text) : "<status text unavailable>");
+    if(status_text != buf) HeapFree(GetProcessHeap(), 0, status_text);
+
+    if (status_code == HTTP_STATUS_DENIED)
+        return ERROR_ACCESS_DENIED;
+    return RPC_S_SERVER_UNAVAILABLE;
+}
+
+static RPC_STATUS rpcrt4_http_internet_connect(RpcConnection_http *httpc)
+{
+    static const WCHAR wszUserAgent[] = {'M','S','R','P','C',0};
+    LPWSTR proxy = NULL;
+    LPWSTR user = NULL;
+    LPWSTR password = NULL;
+    LPWSTR servername = NULL;
+    const WCHAR *option;
+    INTERNET_PORT port = INTERNET_INVALID_PORT_NUMBER; /* use default port */
+
+    if (httpc->common.QOS &&
+        (httpc->common.QOS->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP))
+    {
+        const RPC_HTTP_TRANSPORT_CREDENTIALS_W *http_cred = httpc->common.QOS->qos->u.HttpCredentials;
+        if (http_cred->TransportCredentials)
+        {
+            WCHAR *p;
+            const SEC_WINNT_AUTH_IDENTITY_W *cred = http_cred->TransportCredentials;
+            ULONG len = cred->DomainLength + 1 + cred->UserLength;
+            user = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
+            if (!user)
+                return RPC_S_OUT_OF_RESOURCES;
+            p = user;
+            if (cred->DomainLength)
+            {
+                memcpy(p, cred->Domain, cred->DomainLength * sizeof(WCHAR));
+                p += cred->DomainLength;
+                *p = '\\';
+                p++;
+            }
+            memcpy(p, cred->User, cred->UserLength * sizeof(WCHAR));
+            p[cred->UserLength] = 0;
+
+            password = RPCRT4_strndupW(cred->Password, cred->PasswordLength);
+        }
+    }
+
+    for (option = httpc->common.NetworkOptions; option;
+         option = (strchrW(option, ',') ? strchrW(option, ',')+1 : NULL))
+    {
+        static const WCHAR wszRpcProxy[] = {'R','p','c','P','r','o','x','y','=',0};
+        static const WCHAR wszHttpProxy[] = {'H','t','t','p','P','r','o','x','y','=',0};
+
+        if (!strncmpiW(option, wszRpcProxy, sizeof(wszRpcProxy)/sizeof(wszRpcProxy[0])-1))
+        {
+            const WCHAR *value_start = option + sizeof(wszRpcProxy)/sizeof(wszRpcProxy[0])-1;
+            const WCHAR *value_end;
+            const WCHAR *p;
+
+            value_end = strchrW(option, ',');
+            if (!value_end)
+                value_end = value_start + strlenW(value_start);
+            for (p = value_start; p < value_end; p++)
+                if (*p == ':')
+                {
+                    port = atoiW(p+1);
+                    value_end = p;
+                    break;
+                }
+            TRACE("RpcProxy value is %s\n", debugstr_wn(value_start, value_end-value_start));
+            servername = RPCRT4_strndupW(value_start, value_end-value_start);
+        }
+        else if (!strncmpiW(option, wszHttpProxy, sizeof(wszHttpProxy)/sizeof(wszHttpProxy[0])-1))
+        {
+            const WCHAR *value_start = option + sizeof(wszHttpProxy)/sizeof(wszHttpProxy[0])-1;
+            const WCHAR *value_end;
+
+            value_end = strchrW(option, ',');
+            if (!value_end)
+                value_end = value_start + strlenW(value_start);
+            TRACE("HttpProxy value is %s\n", debugstr_wn(value_start, value_end-value_start));
+            proxy = RPCRT4_strndupW(value_start, value_end-value_start);
+        }
+        else
+            FIXME("unhandled option %s\n", debugstr_w(option));
+    }
+
+    httpc->app_info = InternetOpenW(wszUserAgent, proxy ? INTERNET_OPEN_TYPE_PROXY : INTERNET_OPEN_TYPE_PRECONFIG,
+                                    NULL, NULL, INTERNET_FLAG_ASYNC);
+    if (!httpc->app_info)
+    {
+        HeapFree(GetProcessHeap(), 0, password);
+        HeapFree(GetProcessHeap(), 0, user);
+        ERR("InternetOpenW failed with error %d\n", GetLastError());
+        return RPC_S_SERVER_UNAVAILABLE;
+    }
+    InternetSetStatusCallbackW(httpc->app_info, rpcrt4_http_internet_callback);
+
+    /* if no RpcProxy option specified, set the HTTP server address to the
+     * RPC server address */
+    if (!servername)
+    {
+        servername = HeapAlloc(GetProcessHeap(), 0, (strlen(httpc->common.NetworkAddr) + 1)*sizeof(WCHAR));
+        if (!servername)
+        {
+            HeapFree(GetProcessHeap(), 0, password);
+            HeapFree(GetProcessHeap(), 0, user);
+            return RPC_S_OUT_OF_RESOURCES;
+        }
+        MultiByteToWideChar(CP_ACP, 0, httpc->common.NetworkAddr, -1, servername, strlen(httpc->common.NetworkAddr) + 1);
+    }
+
+    httpc->session = InternetConnectW(httpc->app_info, servername, port, user, password,
+                                      INTERNET_SERVICE_HTTP, 0, 0);
+
+    HeapFree(GetProcessHeap(), 0, password);
+    HeapFree(GetProcessHeap(), 0, user);
+    HeapFree(GetProcessHeap(), 0, servername);
+
+    if (!httpc->session)
+    {
+        ERR("InternetConnectW failed with error %d\n", GetLastError());
+        return RPC_S_SERVER_UNAVAILABLE;
+    }
+
+    return RPC_S_OK;
+}
+
+/* prepare the in pipe for use by RPC packets */
+static RPC_STATUS rpcrt4_http_prepare_in_pipe(HINTERNET in_request, RpcHttpAsyncData *async_data,
+                                              const UUID *connection_uuid,
+                                              const UUID *in_pipe_uuid,
+                                              const UUID *association_uuid)
+{
+    BYTE packet[44];
+    BOOL ret;
+    RPC_STATUS status;
+    RpcPktHdr *hdr;
+    INTERNET_BUFFERSW buffers_in;
+    DWORD bytes_read, bytes_written;
+
+    /* prepare in pipe */
+    ResetEvent(async_data->completion_event);
+    RpcHttpAsyncData_AddRef(async_data);
+    ret = HttpSendRequestW(in_request, NULL, 0, NULL, 0);
+    if (!ret)
+    {
+        if (GetLastError() == ERROR_IO_PENDING)
+            WaitForSingleObject(async_data->completion_event, INFINITE);
+        else
+        {
+            RpcHttpAsyncData_Release(async_data);
+            ERR("HttpSendRequestW failed with error %d\n", GetLastError());
+            return RPC_S_SERVER_UNAVAILABLE;
+        }
+    }
+    status = rpcrt4_http_check_response(in_request);
+    if (status != RPC_S_OK) return status;
+
+    InternetReadFile(in_request, packet, 20, &bytes_read);
+    /* FIXME: do something with retrieved data */
+
+    memset(&buffers_in, 0, sizeof(buffers_in));
+    buffers_in.dwStructSize = sizeof(buffers_in);
+    /* FIXME: get this from the registry */
+    buffers_in.dwBufferTotal = 1024 * 1024 * 1024; /* 1Gb */
+    ResetEvent(async_data->completion_event);
+    RpcHttpAsyncData_AddRef(async_data);
+    ret = HttpSendRequestExW(in_request, &buffers_in, NULL, 0, 0);
+    if (!ret)
+    {
+        if (GetLastError() == ERROR_IO_PENDING)
+            WaitForSingleObject(async_data->completion_event, INFINITE);
+        else
+        {
+            RpcHttpAsyncData_Release(async_data);
+            ERR("HttpSendRequestExW failed with error %d\n", GetLastError());
+            return RPC_S_SERVER_UNAVAILABLE;
+        }
+    }
+
+    TRACE("sending HTTP connect header to server\n");
+    hdr = RPCRT4_BuildHttpConnectHeader(0, FALSE, connection_uuid, in_pipe_uuid, association_uuid);
+    if (!hdr) return RPC_S_OUT_OF_RESOURCES;
+    ret = InternetWriteFile(in_request, hdr, hdr->common.frag_len, &bytes_written);
+    RPCRT4_FreeHeader(hdr);
+    if (!ret)
+    {
+        ERR("InternetWriteFile failed with error %d\n", GetLastError());
+        return RPC_S_SERVER_UNAVAILABLE;
+    }
+
+    return RPC_S_OK;
+}
+
+static RPC_STATUS rpcrt4_http_read_http_packet(HINTERNET request, RpcPktHdr *hdr, BYTE **data)
+{
+    BOOL ret;
+    DWORD bytes_read;
+    unsigned short data_len;
+
+    ret = InternetReadFile(request, hdr, sizeof(hdr->common), &bytes_read);
+    if (!ret)
+        return RPC_S_SERVER_UNAVAILABLE;
+    if (hdr->common.ptype != PKT_HTTP || hdr->common.frag_len < sizeof(hdr->http))
+    {
+        ERR("wrong packet type received %d or wrong frag_len %d\n",
+            hdr->common.ptype, hdr->common.frag_len);
+        return RPC_S_PROTOCOL_ERROR;
+    }
+
+    ret = InternetReadFile(request, &hdr->common + 1, sizeof(hdr->http) - sizeof(hdr->common), &bytes_read);
+    if (!ret)
+        return RPC_S_SERVER_UNAVAILABLE;
+
+    data_len = hdr->common.frag_len - sizeof(hdr->http);
+    if (data_len)
+    {
+        *data = HeapAlloc(GetProcessHeap(), 0, data_len);
+        if (!*data)
+            return RPC_S_OUT_OF_RESOURCES;
+        ret = InternetReadFile(request, *data, data_len, &bytes_read);
+        if (!ret)
+        {
+            HeapFree(GetProcessHeap(), 0, *data);
+            return RPC_S_SERVER_UNAVAILABLE;
+        }
+    }
+    else
+        *data = NULL;
+
+    if (!RPCRT4_IsValidHttpPacket(hdr, *data, data_len))
+    {
+        ERR("invalid http packet\n");
+        return RPC_S_PROTOCOL_ERROR;
+    }
+
+    return RPC_S_OK;
+}
+
+/* prepare the out pipe for use by RPC packets */
+static RPC_STATUS rpcrt4_http_prepare_out_pipe(HINTERNET out_request,
+                                               RpcHttpAsyncData *async_data,
+                                               const UUID *connection_uuid,
+                                               const UUID *out_pipe_uuid,
+                                               ULONG *flow_control_increment)
+{
+    BYTE packet[20];
+    BOOL ret;
+    RPC_STATUS status;
+    RpcPktHdr *hdr;
+    DWORD bytes_read;
+    BYTE *data_from_server;
+    RpcPktHdr pkt_from_server;
+    ULONG field1, field3;
+
+    ResetEvent(async_data->completion_event);
+    RpcHttpAsyncData_AddRef(async_data);
+    ret = HttpSendRequestW(out_request, NULL, 0, NULL, 0);
+    if (!ret)
+    {
+        if (GetLastError() == ERROR_IO_PENDING)
+            WaitForSingleObject(async_data->completion_event, INFINITE);
+        else
+        {
+            RpcHttpAsyncData_Release(async_data);
+            ERR("HttpSendRequestW failed with error %d\n", GetLastError());
+            return RPC_S_SERVER_UNAVAILABLE;
+        }
+    }
+    status = rpcrt4_http_check_response(out_request);
+    if (status != RPC_S_OK) return status;
+
+    InternetReadFile(out_request, packet, 20, &bytes_read);
+    /* FIXME: do something with retrieved data */
+
+    hdr = RPCRT4_BuildHttpConnectHeader(0, TRUE, connection_uuid, out_pipe_uuid, NULL);
+    if (!hdr) return RPC_S_OUT_OF_RESOURCES;
+    ResetEvent(async_data->completion_event);
+    RpcHttpAsyncData_AddRef(async_data);
+    ret = HttpSendRequestW(out_request, NULL, 0, hdr, hdr->common.frag_len);
+    if (!ret)
+    {
+        if (GetLastError() == ERROR_IO_PENDING)
+            WaitForSingleObject(async_data->completion_event, INFINITE);
+        else
+        {
+            RpcHttpAsyncData_Release(async_data);
+            ERR("HttpSendRequestW failed with error %d\n", GetLastError());
+            RPCRT4_FreeHeader(hdr);
+            return RPC_S_SERVER_UNAVAILABLE;
+        }
+    }
+    RPCRT4_FreeHeader(hdr);
+    status = rpcrt4_http_check_response(out_request);
+    if (status != RPC_S_OK) return status;
+
+    status = rpcrt4_http_read_http_packet(out_request, &pkt_from_server,
+                                          &data_from_server);
+    if (status != RPC_S_OK) return status;
+    status = RPCRT4_ParseHttpPrepareHeader1(&pkt_from_server, data_from_server,
+                                            &field1);
+    HeapFree(GetProcessHeap(), 0, data_from_server);
+    if (status != RPC_S_OK) return status;
+    TRACE("received (%d) from first prepare header\n", field1);
+
+    status = rpcrt4_http_read_http_packet(out_request, &pkt_from_server,
+                                          &data_from_server);
+    if (status != RPC_S_OK) return status;
+    status = RPCRT4_ParseHttpPrepareHeader2(&pkt_from_server, data_from_server,
+                                            &field1, flow_control_increment,
+                                            &field3);
+    HeapFree(GetProcessHeap(), 0, data_from_server);
+    if (status != RPC_S_OK) return status;
+    TRACE("received (0x%08x 0x%08x %d) from second prepare header\n", field1, *flow_control_increment, field3);
+
+    return RPC_S_OK;
+}
+
+static RPC_STATUS rpcrt4_ncacn_http_open(RpcConnection* Connection)
+{
+    RpcConnection_http *httpc = (RpcConnection_http *)Connection;
+    static const WCHAR wszVerbIn[] = {'R','P','C','_','I','N','_','D','A','T','A',0};
+    static const WCHAR wszVerbOut[] = {'R','P','C','_','O','U','T','_','D','A','T','A',0};
+    static const WCHAR wszRpcProxyPrefix[] = {'/','r','p','c','/','r','p','c','p','r','o','x','y','.','d','l','l','?',0};
+    static const WCHAR wszColon[] = {':',0};
+    static const WCHAR wszAcceptType[] = {'a','p','p','l','i','c','a','t','i','o','n','/','r','p','c',0};
+    LPCWSTR wszAcceptTypes[] = { wszAcceptType, NULL };
+    WCHAR *url;
+    RPC_STATUS status;
+    BOOL secure;
+    HttpTimerThreadData *timer_data;
+    HANDLE thread;
+
+    TRACE("(%s, %s)\n", Connection->NetworkAddr, Connection->Endpoint);
+
+    if (Connection->server)
+    {
+        ERR("ncacn_http servers not supported yet\n");
+        return RPC_S_SERVER_UNAVAILABLE;
+    }
+
+    if (httpc->in_request)
+        return RPC_S_OK;
+
+    httpc->async_data->completion_event = CreateEventW(NULL, FALSE, FALSE, NULL);
+
+    status = UuidCreate(&httpc->connection_uuid);
+    status = UuidCreate(&httpc->in_pipe_uuid);
+    status = UuidCreate(&httpc->out_pipe_uuid);
+
+    status = rpcrt4_http_internet_connect(httpc);
+    if (status != RPC_S_OK)
+        return status;
+
+    url = HeapAlloc(GetProcessHeap(), 0, sizeof(wszRpcProxyPrefix) + (strlen(Connection->NetworkAddr) + 1 + strlen(Connection->Endpoint))*sizeof(WCHAR));
+    if (!url)
+        return RPC_S_OUT_OF_MEMORY;
+    memcpy(url, wszRpcProxyPrefix, sizeof(wszRpcProxyPrefix));
+    MultiByteToWideChar(CP_ACP, 0, Connection->NetworkAddr, -1, url+sizeof(wszRpcProxyPrefix)/sizeof(wszRpcProxyPrefix[0])-1, strlen(Connection->NetworkAddr)+1);
+    strcatW(url, wszColon);
+    MultiByteToWideChar(CP_ACP, 0, Connection->Endpoint, -1, url+strlenW(url), strlen(Connection->Endpoint)+1);
+
+    secure = httpc->common.QOS &&
+             (httpc->common.QOS->qos->AdditionalSecurityInfoType == RPC_C_AUTHN_INFO_TYPE_HTTP) &&
+             (httpc->common.QOS->qos->u.HttpCredentials->Flags & RPC_C_HTTP_FLAG_USE_SSL);
+
+    httpc->in_request = HttpOpenRequestW(httpc->session, wszVerbIn, url, NULL, NULL,
+                                         wszAcceptTypes,
+                                         (secure ? INTERNET_FLAG_SECURE : 0)|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_PRAGMA_NOCACHE,
+                                         (DWORD_PTR)httpc->async_data);
+    if (!httpc->in_request)
+    {
+        ERR("HttpOpenRequestW failed with error %d\n", GetLastError());
+        return RPC_S_SERVER_UNAVAILABLE;
+    }
+    httpc->out_request = HttpOpenRequestW(httpc->session, wszVerbOut, url, NULL, NULL,
+                                          wszAcceptTypes,
+                                          (secure ? INTERNET_FLAG_SECURE : 0)|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_PRAGMA_NOCACHE,
+                                          (DWORD_PTR)httpc->async_data);
+    if (!httpc->out_request)
+    {
+        ERR("HttpOpenRequestW failed with error %d\n", GetLastError());
+        return RPC_S_SERVER_UNAVAILABLE;
+    }
+
+    status = rpcrt4_http_prepare_in_pipe(httpc->in_request,
+                                         httpc->async_data,
+                                         &httpc->connection_uuid,
+                                         &httpc->in_pipe_uuid,
+                                         &Connection->assoc->http_uuid);
+    if (status != RPC_S_OK)
+        return status;
+
+    status = rpcrt4_http_prepare_out_pipe(httpc->out_request,
+                                          httpc->async_data,
+                                          &httpc->connection_uuid,
+                                          &httpc->out_pipe_uuid,
+                                          &httpc->flow_control_increment);
+    if (status != RPC_S_OK)
+        return status;
+
+    httpc->flow_control_mark = httpc->flow_control_increment / 2;
+    httpc->last_sent_time = GetTickCount();
+    httpc->timer_cancelled = CreateEventW(NULL, FALSE, FALSE, NULL);
+
+    timer_data = HeapAlloc(GetProcessHeap(), 0, sizeof(*timer_data));
+    if (!timer_data)
+        return ERROR_OUTOFMEMORY;
+    timer_data->timer_param = httpc->in_request;
+    timer_data->last_sent_time = &httpc->last_sent_time;
+    timer_data->timer_cancelled = httpc->timer_cancelled;
+    /* FIXME: should use CreateTimerQueueTimer when implemented */
+    thread = CreateThread(NULL, 0, rpcrt4_http_timer_thread, timer_data, 0, NULL);
+    if (!thread)
+    {
+        HeapFree(GetProcessHeap(), 0, timer_data);
+        return GetLastError();
+    }
+    CloseHandle(thread);
+
+    return RPC_S_OK;
+}
+
+static RPC_STATUS rpcrt4_ncacn_http_handoff(RpcConnection *old_conn, RpcConnection *new_conn)
+{
+    assert(0);
+    return RPC_S_SERVER_UNAVAILABLE;
+}
+
+static int rpcrt4_ncacn_http_read(RpcConnection *Connection,
+                                void *buffer, unsigned int count)
+{
+  RpcConnection_http *httpc = (RpcConnection_http *) Connection;
+  char *buf = buffer;
+  BOOL ret = TRUE;
+  unsigned int bytes_left = count;
+
+  ResetEvent(httpc->async_data->completion_event);
+  while (bytes_left)
+  {
+    RpcHttpAsyncData_AddRef(httpc->async_data);
+    httpc->async_data->inet_buffers.dwBufferLength = bytes_left;
+    httpc->async_data->inet_buffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, bytes_left);
+    httpc->async_data->destination_buffer = buf;
+    ret = InternetReadFileExA(httpc->out_request, &httpc->async_data->inet_buffers, IRF_ASYNC, 0);
+    if (ret)
+    {
+        /* INTERNET_STATUS_REQUEST_COMPLETED won't be sent, so release our
+         * async ref now */
+        RpcHttpAsyncData_Release(httpc->async_data);
+        memcpy(buf, httpc->async_data->inet_buffers.lpvBuffer,
+               httpc->async_data->inet_buffers.dwBufferLength);
+        HeapFree(GetProcessHeap(), 0, httpc->async_data->inet_buffers.lpvBuffer);
+        httpc->async_data->inet_buffers.lpvBuffer = NULL;
+        httpc->async_data->destination_buffer = NULL;
+    }
+    else
+    {
+        if (GetLastError() == ERROR_IO_PENDING)
+        {
+            HANDLE handles[2] = { httpc->async_data->completion_event, httpc->cancel_event };
+            DWORD result = WaitForMultipleObjects(2, handles, FALSE, DEFAULT_NCACN_HTTP_TIMEOUT);
+            if (result == WAIT_OBJECT_0)
+                ret = TRUE;
+            else
+            {
+                TRACE("call cancelled\n");
+                EnterCriticalSection(&httpc->async_data->cs);
+                httpc->async_data->destination_buffer = NULL;
+                LeaveCriticalSection(&httpc->async_data->cs);
+                break;
+            }
+        }
+        else
+        {
+            HeapFree(GetProcessHeap(), 0, httpc->async_data->inet_buffers.lpvBuffer);
+            httpc->async_data->inet_buffers.lpvBuffer = NULL;
+            httpc->async_data->destination_buffer = NULL;
+            RpcHttpAsyncData_Release(httpc->async_data);
+            break;
+        }
+    }
+    if (!httpc->async_data->inet_buffers.dwBufferLength)
+        break;
+    bytes_left -= httpc->async_data->inet_buffers.dwBufferLength;
+    buf += httpc->async_data->inet_buffers.dwBufferLength;
+  }
+  TRACE("%p %p %u -> %s\n", httpc->out_request, buffer, count, ret ? "TRUE" : "FALSE");
+  return ret ? count : -1;
+}
+
+static RPC_STATUS rpcrt4_ncacn_http_receive_fragment(RpcConnection *Connection, RpcPktHdr **Header, void **Payload)
+{
+  RpcConnection_http *httpc = (RpcConnection_http *) Connection;
+  RPC_STATUS status;
+  DWORD hdr_length;
+  LONG dwRead;
+  RpcPktCommonHdr common_hdr;
+
+  *Header = NULL;
+
+  TRACE("(%p, %p, %p)\n", Connection, Header, Payload);
+
+again:
+  /* read packet common header */
+  dwRead = rpcrt4_ncacn_http_read(Connection, &common_hdr, sizeof(common_hdr));
+  if (dwRead != sizeof(common_hdr)) {
+    WARN("Short read of header, %d bytes\n", dwRead);
+    status = RPC_S_PROTOCOL_ERROR;
+    goto fail;
+  }
+  if (!memcmp(&common_hdr, "HTTP/1.1", sizeof("HTTP/1.1")) ||
+      !memcmp(&common_hdr, "HTTP/1.0", sizeof("HTTP/1.0")))
+  {
+    FIXME("server returned %s\n", debugstr_a((const char *)&common_hdr));
+    status = RPC_S_PROTOCOL_ERROR;
+    goto fail;
+  }
+
+  status = RPCRT4_ValidateCommonHeader(&common_hdr);
+  if (status != RPC_S_OK) goto fail;
+
+  hdr_length = RPCRT4_GetHeaderSize((RpcPktHdr*)&common_hdr);
+  if (hdr_length == 0) {
+    WARN("header length == 0\n");
+    status = RPC_S_PROTOCOL_ERROR;
+    goto fail;
+  }
+
+  *Header = HeapAlloc(GetProcessHeap(), 0, hdr_length);
+  if (!*Header)
+  {
+    status = RPC_S_OUT_OF_RESOURCES;
+    goto fail;
+  }
+  memcpy(*Header, &common_hdr, sizeof(common_hdr));
+
+  /* read the rest of packet header */
+  dwRead = rpcrt4_ncacn_http_read(Connection, &(*Header)->common + 1, hdr_length - sizeof(common_hdr));
+  if (dwRead != hdr_length - sizeof(common_hdr)) {
+    WARN("bad header length, %d bytes, hdr_length %d\n", dwRead, hdr_length);
+    status = RPC_S_PROTOCOL_ERROR;
+    goto fail;
+  }
+
+  if (common_hdr.frag_len - hdr_length)
+  {
+    *Payload = HeapAlloc(GetProcessHeap(), 0, common_hdr.frag_len - hdr_length);
+    if (!*Payload)
+    {
+      status = RPC_S_OUT_OF_RESOURCES;
+      goto fail;
+    }
+
+    dwRead = rpcrt4_ncacn_http_read(Connection, *Payload, common_hdr.frag_len - hdr_length);
+    if (dwRead != common_hdr.frag_len - hdr_length)
+    {
+      WARN("bad data length, %d/%d\n", dwRead, common_hdr.frag_len - hdr_length);
+      status = RPC_S_PROTOCOL_ERROR;
+      goto fail;
+    }
+  }
+  else
+    *Payload = NULL;
+
+  if ((*Header)->common.ptype == PKT_HTTP)
+  {
+    if (!RPCRT4_IsValidHttpPacket(*Header, *Payload, common_hdr.frag_len - hdr_length))
+    {
+      ERR("invalid http packet of length %d bytes\n", (*Header)->common.frag_len);
+      status = RPC_S_PROTOCOL_ERROR;
+      goto fail;
+    }
+    if ((*Header)->http.flags == 0x0001)
+    {
+      TRACE("http idle packet, waiting for real packet\n");
+      if ((*Header)->http.num_data_items != 0)
+      {
+        ERR("HTTP idle packet should have no data items instead of %d\n", (*Header)->http.num_data_items);
+        status = RPC_S_PROTOCOL_ERROR;
+        goto fail;
+      }
+    }
+    else if ((*Header)->http.flags == 0x0002)
+    {
+      ULONG bytes_transmitted;
+      ULONG flow_control_increment;
+      UUID pipe_uuid;
+      status = RPCRT4_ParseHttpFlowControlHeader(*Header, *Payload,
+                                                 Connection->server,
+                                                 &bytes_transmitted,
+                                                 &flow_control_increment,
+                                                 &pipe_uuid);
+      if (status != RPC_S_OK)
+        goto fail;
+      TRACE("received http flow control header (0x%x, 0x%x, %s)\n",
+            bytes_transmitted, flow_control_increment, debugstr_guid(&pipe_uuid));
+      /* FIXME: do something with parsed data */
+    }
+    else
+    {
+      FIXME("unrecognised http packet with flags 0x%04x\n", (*Header)->http.flags);
+      status = RPC_S_PROTOCOL_ERROR;
+      goto fail;
+    }
+    RPCRT4_FreeHeader(*Header);
+    *Header = NULL;
+    HeapFree(GetProcessHeap(), 0, *Payload);
+    *Payload = NULL;
+    goto again;
+  }
+
+  /* success */
+  status = RPC_S_OK;
+
+  httpc->bytes_received += common_hdr.frag_len;
+
+  TRACE("httpc->bytes_received = 0x%x\n", httpc->bytes_received);
+
+  if (httpc->bytes_received > httpc->flow_control_mark)
+  {
+    RpcPktHdr *hdr = RPCRT4_BuildHttpFlowControlHeader(httpc->common.server,
+                                                       httpc->bytes_received,
+                                                       httpc->flow_control_increment,
+                                                       &httpc->out_pipe_uuid);
+    if (hdr)
+    {
+      DWORD bytes_written;
+      BOOL ret2;
+      TRACE("sending flow control packet at 0x%x\n", httpc->bytes_received);
+      ret2 = InternetWriteFile(httpc->in_request, hdr, hdr->common.frag_len, &bytes_written);
+      RPCRT4_FreeHeader(hdr);
+      if (ret2)
+        httpc->flow_control_mark = httpc->bytes_received + httpc->flow_control_increment / 2;
+    }
+  }
+
+fail:
+  if (status != RPC_S_OK) {
+    RPCRT4_FreeHeader(*Header);
+    *Header = NULL;
+    HeapFree(GetProcessHeap(), 0, *Payload);
+    *Payload = NULL;
+  }
+  return status;
+}
+
+static int rpcrt4_ncacn_http_write(RpcConnection *Connection,
+                                 const void *buffer, unsigned int count)
+{
+  RpcConnection_http *httpc = (RpcConnection_http *) Connection;
+  DWORD bytes_written;
+  BOOL ret;
+
+  httpc->last_sent_time = ~0U; /* disable idle packet sending */
+  ret = InternetWriteFile(httpc->in_request, buffer, count, &bytes_written);
+  httpc->last_sent_time = GetTickCount();
+  TRACE("%p %p %u -> %s\n", httpc->in_request, buffer, count, ret ? "TRUE" : "FALSE");
+  return ret ? bytes_written : -1;
+}
+
+static int rpcrt4_ncacn_http_close(RpcConnection *Connection)
+{
+  RpcConnection_http *httpc = (RpcConnection_http *) Connection;
+
+  TRACE("\n");
+
+  SetEvent(httpc->timer_cancelled);
+  if (httpc->in_request)
+    InternetCloseHandle(httpc->in_request);
+  httpc->in_request = NULL;
+  if (httpc->out_request)
+    InternetCloseHandle(httpc->out_request);
+  httpc->out_request = NULL;
+  if (httpc->app_info)
+    InternetCloseHandle(httpc->app_info);
+  httpc->app_info = NULL;
+  if (httpc->session)
+    InternetCloseHandle(httpc->session);
+  httpc->session = NULL;
+  RpcHttpAsyncData_Release(httpc->async_data);
+  if (httpc->cancel_event)
+    CloseHandle(httpc->cancel_event);
+
+  return 0;
+}
+
+static void rpcrt4_ncacn_http_cancel_call(RpcConnection *Connection)
+{
+  RpcConnection_http *httpc = (RpcConnection_http *) Connection;
+
+  SetEvent(httpc->cancel_event);
+}
+
+static int rpcrt4_ncacn_http_wait_for_incoming_data(RpcConnection *Connection)
+{
+  BOOL ret;
+  RpcConnection_http *httpc = (RpcConnection_http *) Connection;
+
+  RpcHttpAsyncData_AddRef(httpc->async_data);
+  ret = InternetQueryDataAvailable(httpc->out_request,
+    &httpc->async_data->inet_buffers.dwBufferLength, IRF_ASYNC, 0);
+  if (ret)
+  {
+      /* INTERNET_STATUS_REQUEST_COMPLETED won't be sent, so release our
+       * async ref now */
+      RpcHttpAsyncData_Release(httpc->async_data);
+  }
+  else
+  {
+    if (GetLastError() == ERROR_IO_PENDING)
+    {
+      HANDLE handles[2] = { httpc->async_data->completion_event, httpc->cancel_event };
+      DWORD result = WaitForMultipleObjects(2, handles, FALSE, DEFAULT_NCACN_HTTP_TIMEOUT);
+      if (result != WAIT_OBJECT_0)
+      {
+        TRACE("call cancelled\n");
+        return -1;
+      }
+    }
+    else
+    {
+      RpcHttpAsyncData_Release(httpc->async_data);
+      return -1;
+    }
+  }
+
+  /* success */
+  return 0;
+}
+
+static size_t rpcrt4_ncacn_http_get_top_of_tower(unsigned char *tower_data,
+                                                 const char *networkaddr,
+                                                 const char *endpoint)
+{
+    return rpcrt4_ip_tcp_get_top_of_tower(tower_data, networkaddr,
+                                          EPM_PROTOCOL_HTTP, endpoint);
+}
+
+static RPC_STATUS rpcrt4_ncacn_http_parse_top_of_tower(const unsigned char *tower_data,
+                                                       size_t tower_size,
+                                                       char **networkaddr,
+                                                       char **endpoint)
+{
+    return rpcrt4_ip_tcp_parse_top_of_tower(tower_data, tower_size,
+                                            networkaddr, EPM_PROTOCOL_HTTP,
+                                            endpoint);
+}
+
 static const struct connection_ops conn_protseq_list[] = {
   { "ncacn_np",
     { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_SMB },
@@ -1413,6 +2688,7 @@
     rpcrt4_conn_np_wait_for_incoming_data,
     rpcrt4_ncacn_np_get_top_of_tower,
     rpcrt4_ncacn_np_parse_top_of_tower,
+    NULL,
   },
   { "ncalrpc",
     { EPM_PROTOCOL_NCALRPC, EPM_PROTOCOL_PIPE },
@@ -1426,8 +2702,8 @@
     rpcrt4_conn_np_wait_for_incoming_data,
     rpcrt4_ncalrpc_get_top_of_tower,
     rpcrt4_ncalrpc_parse_top_of_tower,
+    NULL,
   },
-#ifdef HAVE_SOCKETPAIR
   { "ncacn_ip_tcp",
     { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_TCP },
     rpcrt4_conn_tcp_alloc,
@@ -1440,8 +2716,22 @@
     rpcrt4_conn_tcp_wait_for_incoming_data,
     rpcrt4_ncacn_ip_tcp_get_top_of_tower,
     rpcrt4_ncacn_ip_tcp_parse_top_of_tower,
-  }
-#endif
+    NULL,
+  },
+  { "ncacn_http",
+    { EPM_PROTOCOL_NCACN, EPM_PROTOCOL_HTTP },
+    rpcrt4_ncacn_http_alloc,
+    rpcrt4_ncacn_http_open,
+    rpcrt4_ncacn_http_handoff,
+    rpcrt4_ncacn_http_read,
+    rpcrt4_ncacn_http_write,
+    rpcrt4_ncacn_http_close,
+    rpcrt4_ncacn_http_cancel_call,
+    rpcrt4_ncacn_http_wait_for_incoming_data,
+    rpcrt4_ncacn_http_get_top_of_tower,
+    rpcrt4_ncacn_http_parse_top_of_tower,
+    rpcrt4_ncacn_http_receive_fragment,
+  },
 };
 
 
@@ -1465,7 +2755,6 @@
         rpcrt4_protseq_np_wait_for_new_connection,
         rpcrt4_protseq_ncalrpc_open_endpoint,
     },
-#ifdef HAVE_SOCKETPAIR
     {
         "ncacn_ip_tcp",
         rpcrt4_protseq_sock_alloc,
@@ -1475,7 +2764,6 @@
         rpcrt4_protseq_sock_wait_for_new_connection,
         rpcrt4_protseq_ncacn_ip_tcp_open_endpoint,
     },
-#endif
 };
 
 #define ARRAYSIZE(a) (sizeof((a)) / sizeof((a)[0]))
Index: dll/win32/rpcrt4/rpcrt4.spec
===================================================================
--- dll/win32/rpcrt4/rpcrt4.spec	(revision 41348)
+++ dll/win32/rpcrt4/rpcrt4.spec	(working copy)
@@ -116,8 +116,9 @@
 @ stdcall NDRSContextUnmarshallEx(ptr ptr ptr)
 @ stub NDRcopy
 @ stdcall NdrAllocate(ptr long)
-@ stub NdrAsyncClientCall
+@ varargs NdrAsyncClientCall(ptr ptr)
 @ stub NdrAsyncServerCall
+@ stdcall NdrAsyncStubCall(ptr ptr ptr ptr)
 @ stdcall NdrByteCountPointerBufferSize(ptr ptr ptr)
 @ stdcall NdrByteCountPointerFree(ptr ptr ptr)
 @ stdcall NdrByteCountPointerMarshall(ptr ptr ptr)
@@ -370,7 +371,7 @@
 @ stdcall RpcEpRegisterA(ptr ptr ptr str)
 @ stub RpcEpRegisterNoReplaceA
 @ stub RpcEpRegisterNoReplaceW
-@ stub RpcEpRegisterW
+@ stdcall RpcEpRegisterW(ptr ptr ptr wstr)
 @ stdcall RpcEpResolveBinding(ptr ptr)
 @ stdcall RpcEpUnregister(ptr ptr ptr)
 @ stub RpcErrorAddRecord # wxp
Index: dll/win32/rpcrt4/rpcrt4_main.c
===================================================================
--- dll/win32/rpcrt4/rpcrt4_main.c	(revision 41348)
+++ dll/win32/rpcrt4/rpcrt4_main.c	(working copy)
@@ -135,6 +135,7 @@
         break;
 
     case DLL_PROCESS_DETACH:
+        RPCRT4_destroy_all_protseqs();
         break;
     }
 
@@ -1015,4 +1016,4 @@
     }
     else
         return rpc_cancel_thread(target_tid);
-}
+}
\ No newline at end of file
Index: dll/win32/wlanapi/main.c
===================================================================
--- dll/win32/wlanapi/main.c	(revision 41348)
+++ dll/win32/wlanapi/main.c	(working copy)
@@ -198,7 +198,7 @@
 }
 
 void __RPC_FAR * __RPC_USER
-midl_user_allocate(size_t len)
+midl_user_allocate(SIZE_T len)
 {
     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
 }
Index: include/psdk/rpcndr.h
===================================================================
--- include/psdk/rpcndr.h	(revision 41348)
+++ include/psdk/rpcndr.h	(working copy)
@@ -335,7 +335,7 @@
 typedef struct _MIDL_STUB_DESC
 {
   void *RpcInterfaceInformation;
-  void * (__WINE_ALLOC_SIZE(1) __RPC_API *pfnAllocate)(size_t);
+  void * (__WINE_ALLOC_SIZE(1) __RPC_API *pfnAllocate)(SIZE_T);
   void (__RPC_API *pfnFree)(void *);
   union {
     handle_t *pAutoHandle;
@@ -678,7 +678,7 @@
                             ULONG *pFaultStatus, RPC_STATUS Status_ );
 
 RPCRTAPI void* RPC_ENTRY
-  NdrOleAllocate( size_t Size ) __WINE_ALLOC_SIZE(1);
+  NdrOleAllocate( SIZE_T Size ) __WINE_ALLOC_SIZE(1);
 RPCRTAPI void RPC_ENTRY
   NdrOleFree( void* NodeToFree );
 
Index: ReactOS-i386.rbuild
===================================================================
--- ReactOS-i386.rbuild	(revision 41348)
+++ ReactOS-i386.rbuild	(working copy)
@@ -42,6 +42,9 @@
 	<compilerflag>-Wno-strict-aliasing</compilerflag>
 	<compilerflag>-Wpointer-arith</compilerflag>
 	<compilerflag>-Wno-multichar</compilerflag>
+
+	<compilerflag compiler="midl">--win32</compilerflag>
+
 	<!-- compilerflag>-H</compilerflag>    enable this for header traces -->
 	<linkerflag>-disable-stdcall-fixup</linkerflag>
 
Index: tools/widl/client.c
===================================================================
--- tools/widl/client.c	(revision 41348)
+++ tools/widl/client.c	(working copy)
@@ -41,6 +41,7 @@
 static FILE* client;
 static int indent = 0;
 
+static void print_client( const char *format, ... ) __attribute__((format (printf, 1, 2)));
 static void print_client( const char *format, ... )
 {
     va_list va;
@@ -166,7 +167,7 @@
         /* declare return value '_RetVal' */
         if (!is_void(type_function_get_rettype(func->type)))
         {
-            print_client("");
+            print_client("%s", "");
             write_type_decl_left(client, type_function_get_rettype(func->type));
             fprintf(client, " _RetVal;\n");
         }
@@ -387,7 +388,7 @@
 
 static void write_clientinterfacedecl(type_t *iface)
 {
-    unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
+    unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION);
     const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
     const str_list_t *endpoints = get_attrp(iface->attrs, ATTR_ENDPOINT);
 
@@ -397,7 +398,7 @@
     print_client("{\n");
     indent++;
     print_client("sizeof(RPC_CLIENT_INTERFACE),\n");
-    print_client("{{0x%08lx,0x%04x,0x%04x,{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}},{%d,%d}},\n",
+    print_client("{{0x%08x,0x%04x,0x%04x,{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}},{%d,%d}},\n",
                  uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1],
                  uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6],
                  uuid->Data4[7], MAJORVERSION(ver), MINORVERSION(ver));
@@ -468,7 +469,7 @@
     const statement_t *stmt;
     if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
     {
-        if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
+        if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
         {
             int has_func = 0;
             const statement_t *stmt2;
Index: tools/widl/expr.c
===================================================================
--- tools/widl/expr.c	(revision 41348)
+++ tools/widl/expr.c	(working copy)
@@ -33,7 +33,11 @@
 #include "expr.h"
 #include "header.h"
 #include "typetree.h"
+#include "typegen.h"
 
+static int is_integer_type(const type_t *type);
+static int is_float_type(const type_t *type);
+
 expr_t *make_expr(enum expr_type type)
 {
     expr_t *e = xmalloc(sizeof(expr_t));
@@ -105,38 +109,17 @@
     e->ref = expr;
     e->u.tref = tref;
     e->is_const = FALSE;
-    /* check for cast of constant expression */
     if (type == EXPR_SIZEOF)
     {
-        switch (tref->type)
+        /* only do this for types that should be the same on all platforms */
+        if (is_integer_type(tref) || is_float_type(tref))
         {
-        case RPC_FC_BYTE:
-        case RPC_FC_CHAR:
-        case RPC_FC_SMALL:
-        case RPC_FC_USMALL:
+            unsigned int align = 0;
             e->is_const = TRUE;
-            e->cval = 1;
-            break;
-        case RPC_FC_WCHAR:
-        case RPC_FC_USHORT:
-        case RPC_FC_SHORT:
-            e->is_const = TRUE;
-            e->cval = 2;
-            break;
-        case RPC_FC_LONG:
-        case RPC_FC_ULONG:
-        case RPC_FC_FLOAT:
-        case RPC_FC_ERROR_STATUS_T:
-            e->is_const = TRUE;
-            e->cval = 4;
-            break;
-        case RPC_FC_HYPER:
-        case RPC_FC_DOUBLE:
-            e->is_const = TRUE;
-            e->cval = 8;
-            break;
+            e->cval = type_memsize(tref, &align);
         }
     }
+    /* check for cast of constant expression */
     if (type == EXPR_CAST && expr->is_const)
     {
         e->is_const = TRUE;
@@ -302,34 +285,44 @@
 
 static int is_integer_type(const type_t *type)
 {
-    switch (type->type)
+    switch (type_get_type(type))
     {
-    case RPC_FC_BYTE:
-    case RPC_FC_CHAR:
-    case RPC_FC_SMALL:
-    case RPC_FC_USMALL:
-    case RPC_FC_WCHAR:
-    case RPC_FC_SHORT:
-    case RPC_FC_USHORT:
-    case RPC_FC_LONG:
-    case RPC_FC_ULONG:
-    case RPC_FC_INT3264:
-    case RPC_FC_UINT3264:
-    case RPC_FC_HYPER:
-    case RPC_FC_ENUM16:
-    case RPC_FC_ENUM32:
+    case TYPE_ENUM:
         return TRUE;
+    case TYPE_BASIC:
+        switch (type_basic_get_type(type))
+        {
+        case TYPE_BASIC_INT8:
+        case TYPE_BASIC_INT16:
+        case TYPE_BASIC_INT32:
+        case TYPE_BASIC_INT64:
+        case TYPE_BASIC_INT:
+        case TYPE_BASIC_CHAR:
+        case TYPE_BASIC_HYPER:
+        case TYPE_BASIC_BYTE:
+        case TYPE_BASIC_WCHAR:
+        case TYPE_BASIC_ERROR_STATUS_T:
+            return TRUE;
+        default:
+            return FALSE;
+        }
     default:
         return FALSE;
     }
 }
 
+static int is_float_type(const type_t *type)
+{
+    return (type_get_type(type) == TYPE_BASIC &&
+        (type_basic_get_type(type) == TYPE_BASIC_FLOAT ||
+         type_basic_get_type(type) == TYPE_BASIC_DOUBLE));
+}
+
 static void check_scalar_type(const struct expr_loc *expr_loc,
                               const type_t *cont_type, const type_t *type)
 {
     if (!cont_type || (!is_integer_type(type) && !is_ptr(type) &&
-                       type->type != RPC_FC_FLOAT &&
-                       type->type != RPC_FC_DOUBLE))
+                       !is_float_type(type)))
         error_loc_info(&expr_loc->v->loc_info, "scalar type required in expression%s%s\n",
                        expr_loc->attr ? " for attribute " : "",
                        expr_loc->attr ? expr_loc->attr : "");
@@ -338,9 +331,7 @@
 static void check_arithmetic_type(const struct expr_loc *expr_loc,
                                   const type_t *cont_type, const type_t *type)
 {
-    if (!cont_type || (!is_integer_type(type) &&
-                       type->type != RPC_FC_FLOAT &&
-                       type->type != RPC_FC_DOUBLE))
+    if (!cont_type || (!is_integer_type(type) && !is_float_type(type)))
         error_loc_info(&expr_loc->v->loc_info, "arithmetic type required in expression%s%s\n",
                        expr_loc->attr ? " for attribute " : "",
                        expr_loc->attr ? expr_loc->attr : "");
@@ -365,12 +356,33 @@
 
     if (cont_type)
     {
-        if (cont_type->type == RPC_FC_FUNCTION)
+        switch (type_get_type(cont_type))
+        {
+        case TYPE_FUNCTION:
             fields = type_function_get_args(cont_type);
-        else if (is_struct(cont_type->type))
+            break;
+        case TYPE_STRUCT:
             fields = type_struct_get_fields(cont_type);
-        else if (is_union(cont_type->type))
+            break;
+        case TYPE_UNION:
+        case TYPE_ENCAPSULATED_UNION:
             fields = type_union_get_cases(cont_type);
+            break;
+        case TYPE_VOID:
+        case TYPE_BASIC:
+        case TYPE_ENUM:
+        case TYPE_MODULE:
+        case TYPE_COCLASS:
+        case TYPE_INTERFACE:
+        case TYPE_POINTER:
+        case TYPE_ARRAY:
+            /* nothing to do */
+            break;
+        case TYPE_ALIAS:
+            /* shouldn't get here because of using type_get_type above */
+            assert(0);
+            break;
+        }
     }
 
     if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
@@ -390,6 +402,19 @@
     return type;
 }
 
+static int is_valid_member_operand(const type_t *type)
+{
+    switch (type_get_type(type))
+    {
+    case TYPE_STRUCT:
+    case TYPE_UNION:
+    case TYPE_ENUM:
+        return TRUE;
+    default:
+        return FALSE;
+    }
+}
+
 static struct expression_type resolve_expression(const struct expr_loc *expr_loc,
                                                  const type_t *cont_type,
                                                  const expr_t *e)
@@ -407,22 +432,22 @@
     case EXPR_TRUEFALSE:
         result.is_variable = FALSE;
         result.is_temporary = FALSE;
-        result.type = find_type("int", 0);
+        result.type = type_new_int(TYPE_BASIC_INT, 0);
         break;
     case EXPR_STRLIT:
         result.is_variable = FALSE;
         result.is_temporary = TRUE;
-        result.type = make_type(RPC_FC_RP, find_type("char", 0));
+        result.type = type_new_pointer(RPC_FC_UP, type_new_int(TYPE_BASIC_CHAR, 0), NULL);
         break;
     case EXPR_WSTRLIT:
         result.is_variable = FALSE;
         result.is_temporary = TRUE;
-        result.type = make_type(RPC_FC_RP, find_type("wchar_t", 0));
+        result.type = type_new_pointer(RPC_FC_UP, type_new_int(TYPE_BASIC_WCHAR, 0), NULL);
         break;
     case EXPR_DOUBLE:
         result.is_variable = FALSE;
-        result.is_temporary = FALSE;
-        result.type = find_type("double", 0);
+        result.is_temporary = TRUE;
+        result.type = type_new_basic(TYPE_BASIC_DOUBLE);
         break;
     case EXPR_IDENTIFIER:
     {
@@ -443,7 +468,7 @@
         check_scalar_type(expr_loc, cont_type, result.type);
         result.is_variable = FALSE;
         result.is_temporary = FALSE;
-        result.type = find_type("int", 0);
+        result.type = type_new_int(TYPE_BASIC_INT, 0);
         break;
     case EXPR_NOT:
         result = resolve_expression(expr_loc, cont_type, e->ref);
@@ -464,14 +489,14 @@
                            expr_loc->attr ? expr_loc->attr : "");
             result.is_variable = FALSE;
         result.is_temporary = TRUE;
-        result.type = make_type(RPC_FC_RP, result.type);
+        result.type = type_new_pointer(RPC_FC_UP, result.type, NULL);
         break;
     case EXPR_PPTR:
         result = resolve_expression(expr_loc, cont_type, e->ref);
         if (result.type && is_ptr(result.type))
             result.type = type_pointer_get_ref(result.type);
         else if(result.type && is_array(result.type)
-                            && !result.type->declarray)
+                            && type_array_is_decl_as_ptr(result.type))
             result.type = type_array_get_element(result.type);
         else
             error_loc_info(&expr_loc->v->loc_info, "dereference operator applied to non-pointer type in expression%s%s\n",
@@ -485,7 +510,7 @@
     case EXPR_SIZEOF:
         result.is_variable = FALSE;
         result.is_temporary = FALSE;
-        result.type = find_type("int", 0);
+        result.type = type_new_int(TYPE_BASIC_INT, 0);
         break;
     case EXPR_SHL:
     case EXPR_SHR:
@@ -523,12 +548,12 @@
         check_scalar_type(expr_loc, cont_type, result_right.type);
         result.is_variable = FALSE;
         result.is_temporary = FALSE;
-        result.type = find_type("int", 0);
+        result.type = type_new_int(TYPE_BASIC_INT, 0);
         break;
     }
     case EXPR_MEMBER:
         result = resolve_expression(expr_loc, cont_type, e->ref);
-        if (result.type && (is_struct(result.type->type) || is_union(result.type->type) || result.type->type == RPC_FC_ENUM16 || result.type->type == RPC_FC_ENUM32))
+        if (result.type && is_valid_member_operand(result.type))
             result = resolve_expression(expr_loc, result.type, e->u.ext);
         else
             error_loc_info(&expr_loc->v->loc_info, "'.' or '->' operator applied to a type that isn't a structure, union or enumeration in expression%s%s\n",
Index: tools/widl/hash.c
===================================================================
--- tools/widl/hash.c	(revision 41348)
+++ tools/widl/hash.c	(working copy)
@@ -23,6 +23,7 @@
 
 #include <host/nls.h>
 
+#include "widltypes.h"
 #include "hash.h"
 
 static const unsigned char Lookup_16[128 * 3] = {
@@ -500,7 +501,7 @@
  *  skind and lcid, while the low word is based on a repeated string
  *  hash of skind/str.
  */
-unsigned long lhash_val_of_name_sys( syskind_t skind, LCID lcid, LPCSTR lpStr)
+unsigned int lhash_val_of_name_sys( syskind_t skind, LCID lcid, LPCSTR lpStr)
 {
   ULONG nOffset, nMask = skind == SYS_MAC ? 1 : 0;
   ULONG nHiWord, nLoWord = 0x0deadbee;
Index: tools/widl/hash.h
===================================================================
--- tools/widl/hash.h	(revision 41348)
+++ tools/widl/hash.h	(working copy)
@@ -22,12 +22,6 @@
 #ifndef __WIDL_HASH_H
 #define __WIDL_HASH_H
 
-typedef enum tag_syskind_t {
-    SYS_WIN16 = 0,
-    SYS_WIN32,
-    SYS_MAC
-} syskind_t;
+extern unsigned int lhash_val_of_name_sys( syskind_t skind, LCID lcid, LPCSTR lpStr);
 
-extern unsigned long lhash_val_of_name_sys( syskind_t skind, LCID lcid, LPCSTR lpStr);
-
 #endif
Index: tools/widl/header.c
===================================================================
--- tools/widl/header.c	(revision 41348)
+++ tools/widl/header.c	(working copy)
@@ -149,7 +149,7 @@
   if (!v) return;
   if (v->type) {
     indent(h, 0);
-    write_type_def_or_decl(h, v->type, TRUE, "%s", v->name);
+    write_type_def_or_decl(h, v->type, TRUE, v->name);
     fprintf(h, ";\n");
   }
 }
@@ -183,7 +183,7 @@
 int needs_space_after(type_t *t)
 {
   return (type_is_alias(t) ||
-          (!is_ptr(t) && (!is_conformant_array(t) || t->declarray || (is_array(t) && t->name))));
+          (!is_ptr(t) && (!is_array(t) || !type_array_is_decl_as_ptr(t) || t->name)));
 }
 
 void write_type_left(FILE *h, type_t *t, int declonly)
@@ -191,21 +191,13 @@
   if (!h) return;
 
   if (is_attr(t->attrs, ATTR_CONST) &&
-      (type_is_alias(t) || t->declarray || !is_ptr(t)))
+      (type_is_alias(t) || !is_ptr(t)))
     fprintf(h, "const ");
 
   if (type_is_alias(t)) fprintf(h, "%s", t->name);
-  else if (t->declarray) write_type_left(h, type_array_get_element(t), declonly);
   else {
-    if (t->sign > 0) fprintf(h, "signed ");
-    else if (t->sign < 0) fprintf(h, "unsigned ");
-
-    if (is_array(t) && !t->name) {
-      write_type_left(h, type_array_get_element(t), declonly);
-      fprintf(h, "%s*", needs_space_after(type_array_get_element(t)) ? " " : "");
-    } else switch (t->type) {
-      case RPC_FC_ENUM16:
-      case RPC_FC_ENUM32:
+    switch (type_get_type_detect_alias(t)) {
+      case TYPE_ENUM:
         if (!declonly && t->defined && !t->written) {
           if (t->name) fprintf(h, "enum %s {\n", t->name);
           else fprintf(h, "enum {\n");
@@ -217,19 +209,14 @@
         }
         else fprintf(h, "enum %s", t->name ? t->name : "");
         break;
-      case RPC_FC_STRUCT:
-      case RPC_FC_CVSTRUCT:
-      case RPC_FC_CPSTRUCT:
-      case RPC_FC_CSTRUCT:
-      case RPC_FC_PSTRUCT:
-      case RPC_FC_BOGUS_STRUCT:
-      case RPC_FC_ENCAPSULATED_UNION:
+      case TYPE_STRUCT:
+      case TYPE_ENCAPSULATED_UNION:
         if (!declonly && t->defined && !t->written) {
           if (t->name) fprintf(h, "struct %s {\n", t->name);
           else fprintf(h, "struct {\n");
           t->written = TRUE;
           indentation++;
-          if (t->type == RPC_FC_ENCAPSULATED_UNION)
+          if (type_get_type(t) != TYPE_STRUCT)
             write_fields(h, type_encapsulated_union_get_fields(t));
           else
             write_fields(h, type_struct_get_fields(t));
@@ -238,7 +225,7 @@
         }
         else fprintf(h, "struct %s", t->name ? t->name : "");
         break;
-      case RPC_FC_NON_ENCAPSULATED_UNION:
+      case TYPE_UNION:
         if (!declonly && t->defined && !t->written) {
           if (t->name) fprintf(h, "union %s {\n", t->name);
           else fprintf(h, "union {\n");
@@ -250,16 +237,68 @@
         }
         else fprintf(h, "union %s", t->name ? t->name : "");
         break;
-      case RPC_FC_RP:
-      case RPC_FC_UP:
-      case RPC_FC_FP:
-      case RPC_FC_OP:
+      case TYPE_POINTER:
         write_type_left(h, type_pointer_get_ref(t), declonly);
         fprintf(h, "%s*", needs_space_after(type_pointer_get_ref(t)) ? " " : "");
         if (is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const ");
         break;
-      default:
+      case TYPE_ARRAY:
+        if (t->name && type_array_is_decl_as_ptr(t))
+          fprintf(h, "%s", t->name);
+        else
+        {
+          write_type_left(h, type_array_get_element(t), declonly);
+          if (type_array_is_decl_as_ptr(t))
+            fprintf(h, "%s*", needs_space_after(type_array_get_element(t)) ? " " : "");
+        }
+        break;
+      case TYPE_BASIC:
+        if (type_basic_get_type(t) != TYPE_BASIC_INT32 &&
+            type_basic_get_type(t) != TYPE_BASIC_HYPER)
+        {
+          if (type_basic_get_sign(t) < 0) fprintf(h, "signed ");
+          else if (type_basic_get_sign(t) > 0) fprintf(h, "unsigned ");
+        }
+        switch (type_basic_get_type(t))
+        {
+        case TYPE_BASIC_INT8: fprintf(h, "small"); break;
+        case TYPE_BASIC_INT16: fprintf(h, "short"); break;
+        case TYPE_BASIC_INT: fprintf(h, "int"); break;
+        case TYPE_BASIC_INT64: fprintf(h, "__int64"); break;
+        case TYPE_BASIC_BYTE: fprintf(h, "byte"); break;
+        case TYPE_BASIC_CHAR: fprintf(h, "char"); break;
+        case TYPE_BASIC_WCHAR: fprintf(h, "wchar_t"); break;
+        case TYPE_BASIC_FLOAT: fprintf(h, "float"); break;
+        case TYPE_BASIC_DOUBLE: fprintf(h, "double"); break;
+        case TYPE_BASIC_ERROR_STATUS_T: fprintf(h, "error_status_t"); break;
+        case TYPE_BASIC_HANDLE: fprintf(h, "handle_t"); break;
+        case TYPE_BASIC_INT32:
+          if (type_basic_get_sign(t) > 0)
+            fprintf(h, "ULONG");
+          else
+            fprintf(h, "LONG");
+          break;
+        case TYPE_BASIC_HYPER:
+          if (type_basic_get_sign(t) > 0)
+            fprintf(h, "MIDL_uhyper");
+          else
+            fprintf(h, "hyper");
+          break;
+        }
+        break;
+      case TYPE_INTERFACE:
+      case TYPE_MODULE:
+      case TYPE_COCLASS:
         fprintf(h, "%s", t->name);
+        break;
+      case TYPE_VOID:
+        fprintf(h, "void");
+        break;
+      case TYPE_ALIAS:
+      case TYPE_FUNCTION:
+        /* handled elsewhere */
+        assert(0);
+        break;
     }
   }
 }
@@ -268,18 +307,19 @@
 {
   if (!h) return;
 
-  if (t->declarray) {
+  if (type_get_type(t) == TYPE_ARRAY && !type_array_is_decl_as_ptr(t)) {
     if (is_conformant_array(t)) {
       fprintf(h, "[%s]", is_field ? "1" : "");
       t = type_array_get_element(t);
     }
-    for ( ; t->declarray; t = type_array_get_element(t))
-      fprintf(h, "[%lu]", type_array_get_dim(t));
+    for ( ;
+         type_get_type(t) == TYPE_ARRAY && !type_array_is_decl_as_ptr(t);
+         t = type_array_get_element(t))
+      fprintf(h, "[%u]", type_array_get_dim(t));
   }
 }
 
-void write_type_v(FILE *h, type_t *t, int is_field, int declonly,
-                  const char *fmt, va_list args)
+static void write_type_v(FILE *h, type_t *t, int is_field, int declonly, const char *name)
 {
   type_t *pt;
   int ptr_level = 0;
@@ -289,7 +329,7 @@
   for (pt = t; is_ptr(pt); pt = type_pointer_get_ref(pt), ptr_level++)
     ;
 
-  if (pt->type == RPC_FC_FUNCTION) {
+  if (type_get_type_detect_alias(pt) == TYPE_FUNCTION) {
     int i;
     const char *callconv = get_attrp(pt->attrs, ATTR_CALLCONV);
     if (!callconv) callconv = "";
@@ -302,12 +342,10 @@
       fputc('*', h);
   } else
     write_type_left(h, t, declonly);
-  if (fmt) {
-    if (needs_space_after(t))
-      fputc(' ', h);
-    vfprintf(h, fmt, args);
-  }
-  if (pt->type == RPC_FC_FUNCTION) {
+
+  if (name) fprintf(h, "%s%s", needs_space_after(t) ? " " : "", name );
+
+  if (type_get_type_detect_alias(pt) == TYPE_FUNCTION) {
     if (ptr_level) fputc(')', h);
     fputc('(', h);
     write_args(h, type_function_get_args(pt), NULL, 0, FALSE);
@@ -316,20 +354,14 @@
     write_type_right(h, t, is_field);
 }
 
-void write_type_def_or_decl(FILE *f, type_t *t, int field, const char *fmt, ...)
+void write_type_def_or_decl(FILE *f, type_t *t, int field, const char *name)
 {
-  va_list args;
-  va_start(args, fmt);
-  write_type_v(f, t, field, FALSE, fmt, args);
-  va_end(args);
+  write_type_v(f, t, field, FALSE, name);
 }
 
-void write_type_decl(FILE *f, type_t *t, const char *fmt, ...)
+void write_type_decl(FILE *f, type_t *t, const char *name)
 {
-  va_list args;
-  va_start(args, fmt);
-  write_type_v(f, t, FALSE, TRUE, fmt, args);
-  va_end(args);
+  write_type_v(f, t, FALSE, TRUE, name);
 }
 
 void write_type_decl_left(FILE *f, type_t *t)
@@ -389,7 +421,9 @@
         /* don't carry on parsing fields within this type */
         break;
       }
-      if (type->type != RPC_FC_BIND_PRIMITIVE && is_attr(type->attrs, ATTR_HANDLE)) {
+      if ((type_get_type(type) != TYPE_BASIC ||
+           type_basic_get_type(type) != TYPE_BASIC_HANDLE) &&
+          is_attr(type->attrs, ATTR_HANDLE)) {
         if (!generic_handle_registered(name))
         {
           generic_handle_t *gh = xmalloc(sizeof(*gh));
@@ -412,13 +446,22 @@
       }
       else if (type_is_complete(type))
       {
-        var_list_t *vars = NULL;
-        if (type->type == RPC_FC_ENUM16 || type->type == RPC_FC_ENUM32)
+        var_list_t *vars;
+        switch (type_get_type_detect_alias(type))
+        {
+        case TYPE_ENUM:
           vars = type_enum_get_values(type);
-        else if (is_struct(type->type))
+          break;
+        case TYPE_STRUCT:
           vars = type_struct_get_fields(type);
-        else if (is_union(type->type))
+          break;
+        case TYPE_UNION:
           vars = type_union_get_cases(type);
+          break;
+        default:
+          vars = NULL;
+          break;
+        }
         check_for_additional_prototype_types(vars);
       }
 
@@ -471,7 +514,7 @@
 static void write_typedef(FILE *header, type_t *type)
 {
   fprintf(header, "typedef ");
-  write_type_def_or_decl(header, type_alias_get_aliasee(type), FALSE, "%s", type->name);
+  write_type_def_or_decl(header, type_alias_get_aliasee(type), FALSE, type->name);
   fprintf(header, ";\n");
 }
 
@@ -515,7 +558,7 @@
         fprintf(header, "extern ");
         break;
     }
-    write_type_def_or_decl(header, v->type, FALSE, "%s", v->name);
+    write_type_def_or_decl(header, v->type, FALSE, v->name);
     fprintf(header, ";\n\n");
   }
 }
@@ -537,26 +580,24 @@
         return NULL;
 
     LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
-        if (var->type->type == RPC_FC_BIND_PRIMITIVE)
+    {
+        const type_t *type = var->type;
+        if (type_get_type(type) == TYPE_BASIC && type_basic_get_type(type) == TYPE_BASIC_HANDLE)
             return var;
+    }
 
     return NULL;
 }
 
 const type_t* get_explicit_generic_handle_type(const var_t* var)
 {
-    const type_t *t = var->type;
-
-    if (t->type == RPC_FC_BIND_PRIMITIVE)
-        return NULL;
-
-    if (!is_ptr(t) && is_attr(t->attrs, ATTR_HANDLE))
-        return t;
-    else
-        for (; is_ptr(t); t = t->ref)
-            if (t->type != RPC_FC_BIND_PRIMITIVE && is_attr(t->attrs, ATTR_HANDLE))
-                return t;
-
+    const type_t *t;
+    for (t = var->type;
+         is_ptr(t) || type_is_alias(t);
+         t = type_is_alias(t) ? type_alias_get_aliasee(t) : type_pointer_get_ref(t))
+        if ((type_get_type_detect_alias(t) != TYPE_BASIC || type_basic_get_type(t) != TYPE_BASIC_HANDLE) &&
+            is_attr(t->attrs, ATTR_HANDLE))
+            return t;
     return NULL;
 }
 
@@ -685,7 +726,7 @@
         }
         else fprintf(h, ",");
     }
-    write_type_decl(h, arg->type, "%s", arg->name);
+    write_type_decl(h, arg->type, arg->name);
     count++;
   }
   if (do_indent) indentation--;
@@ -808,7 +849,7 @@
           fprintf(fp, "    %s\n", comment);
           if (rt->name && strcmp(rt->name, "HRESULT") == 0)
             fprintf(fp, "    return E_NOTIMPL;\n");
-          else if (rt->type) {
+          else if (type_get_type(rt) != TYPE_VOID) {
             fprintf(fp, "    ");
             write_type_decl(fp, rt, "rv");
             fprintf(fp, ";\n");
@@ -841,7 +882,7 @@
   const statement_t *stmt;
   if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
   {
-    if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
+    if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
       write_locals(local_stubs, stmt->u.type, TRUE);
     else if (stmt->type == STMT_LIBRARY)
       write_local_stubs_stmts(local_stubs, stmt->u.lib->stmts);
@@ -998,7 +1039,7 @@
   if (!allocate_written)
   {
     allocate_written = 1;
-    fprintf(header, "void * __RPC_USER MIDL_user_allocate(size_t);\n");
+    fprintf(header, "void * __RPC_USER MIDL_user_allocate(SIZE_T);\n");
     fprintf(header, "void __RPC_USER MIDL_user_free(void *);\n\n");
   }
 
@@ -1064,7 +1105,7 @@
     switch (stmt->type)
     {
       case STMT_TYPE:
-        if (stmt->u.type->type == RPC_FC_IP)
+        if (type_get_type(stmt->u.type) == TYPE_INTERFACE)
           write_imports(header, type_iface_get_stmts(stmt->u.type));
         break;
       case STMT_TYPEREF:
@@ -1095,12 +1136,12 @@
     switch (stmt->type)
     {
       case STMT_TYPE:
-        if (stmt->u.type->type == RPC_FC_IP)
+        if (type_get_type(stmt->u.type) == TYPE_INTERFACE)
         {
           if (is_object(stmt->u.type->attrs) || is_attr(stmt->u.type->attrs, ATTR_DISPINTERFACE))
             write_forward(header, stmt->u.type);
         }
-        else if (stmt->u.type->type == RPC_FC_COCLASS)
+        else if (type_get_type(stmt->u.type) == TYPE_COCLASS)
           write_coclass_forward(header, stmt->u.type);
         break;
       case STMT_TYPEREF:
@@ -1129,7 +1170,7 @@
     switch (stmt->type)
     {
       case STMT_TYPE:
-        if (stmt->u.type->type == RPC_FC_IP)
+        if (type_get_type(stmt->u.type) == TYPE_INTERFACE)
         {
           type_t *iface = stmt->u.type;
           if (is_attr(stmt->u.type->attrs, ATTR_DISPINTERFACE) || is_object(stmt->u.type->attrs))
@@ -1145,7 +1186,7 @@
             write_rpc_interface_end(header, iface);
           }
         }
-        else if (stmt->u.type->type == RPC_FC_COCLASS)
+        else if (type_get_type(stmt->u.type) == TYPE_COCLASS)
           write_coclass(header, stmt->u.type);
         else
         {
@@ -1156,7 +1197,7 @@
       case STMT_TYPEREF:
         /* FIXME: shouldn't write out forward declarations for undefined
         * interfaces but a number of our IDL files depend on this */
-        if (stmt->u.type->type == RPC_FC_IP && !stmt->u.type->written)
+        if (type_get_type(stmt->u.type) == TYPE_INTERFACE && !stmt->u.type->written)
           write_forward(header, stmt->u.type);
         break;
       case STMT_IMPORTLIB:
@@ -1181,7 +1222,7 @@
         fprintf(header, "%s\n", stmt->u.str);
         break;
       case STMT_DECLARATION:
-        if (iface && stmt->u.var->type->type == RPC_FC_FUNCTION)
+        if (iface && type_get_type(stmt->u.var->type) == TYPE_FUNCTION)
         {
           if (!ignore_funcs)
           {
Index: tools/widl/header.h
===================================================================
--- tools/widl/header.h	(revision 41348)
+++ tools/widl/header.h	(working copy)
@@ -34,8 +34,8 @@
 extern const char* get_name(const var_t *v);
 extern void write_type_left(FILE *h, type_t *t, int declonly);
 extern void write_type_right(FILE *h, type_t *t, int is_field);
-extern void write_type_def_or_decl(FILE *h, type_t *t, int is_field, const char *fmt, ...);
-extern void write_type_decl(FILE *f, type_t *t, const char *fmt, ...);
+extern void write_type_def_or_decl(FILE *h, type_t *t, int is_field, const char *name);
+extern void write_type_decl(FILE *f, type_t *t, const char *name);
 extern void write_type_decl_left(FILE *f, type_t *t);
 extern int needs_space_after(type_t *t);
 extern int is_object(const attr_list_t *list);
@@ -75,7 +75,9 @@
 static inline int is_context_handle(const type_t *type)
 {
     const type_t *t;
-    for (t = type; is_ptr(t); t = type_pointer_get_ref(t))
+    for (t = type;
+         is_ptr(t) || type_is_alias(t);
+         t = type_is_alias(t) ? type_alias_get_aliasee(t) : type_pointer_get_ref(t))
         if (is_attr(t->attrs, ATTR_CONTEXTHANDLE))
             return 1;
     return 0;
Index: tools/widl/parser.l
===================================================================
--- tools/widl/parser.l	(revision 41348)
+++ tools/widl/parser.l	(working copy)
@@ -341,7 +341,6 @@
         {"requestedit",                 tREQUESTEDIT},
         {"restricted",                  tRESTRICTED},
         {"retval",                      tRETVAL},
-        {"single",                      tSINGLE},
         {"size_is",                     tSIZEIS},
         {"source",                      tSOURCE},
         {"strict_context_handle",       tSTRICTCONTEXTHANDLE},
Index: tools/widl/parser.tab.c
===================================================================
--- tools/widl/parser.tab.c	(revision 41348)
+++ tools/widl/parser.tab.c	(working copy)
@@ -1,30 +1,39 @@
-/* A Bison parser, made by GNU Bison 2.1.  */
 
-/* Skeleton parser for Yacc-like parsing with Bison,
-   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+/* A Bison parser, made by GNU Bison 2.4.1.  */
 
-   This program is free software; you can redistribute it and/or modify
+/* Skeleton implementation for Bison's Yacc-like parsers in C
+   
+      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
+   
+   This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+   
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-
+   
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* As a special exception, when this file is copied by Bison into a
-   Bison output file, you may use that output file without restriction.
-   This special exception was added by the Free Software Foundation
-   in version 1.24 of Bison.  */
+/* As a special exception, you may create a larger work that contains
+   part or all of the Bison parser skeleton and distribute that work
+   under terms of your choice, so long as that work isn't itself a
+   parser generator using the skeleton or a modified version thereof
+   as a parser skeleton.  Alternatively, if you modify or redistribute
+   the parser skeleton itself, you may (at your option) remove this
+   special exception, which will cause the skeleton and the resulting
+   Bison output files to be licensed under the GNU General Public
+   License without this special exception.
+   
+   This special exception was added by the Free Software Foundation in
+   version 2.2 of Bison.  */
 
-/* Written by Richard Stallman by simplifying the original so called
-   ``semantic'' parser.  */
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+   simplifying the original so-called "semantic" parser.  */
 
 /* All symbols defined below should begin with yy or YY, to avoid
    infringing on user name space.  This should be done even for local
@@ -37,7 +46,7 @@
 #define YYBISON 1
 
 /* Bison version.  */
-#define YYBISON_VERSION "2.1"
+#define YYBISON_VERSION "2.4.1"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
@@ -45,331 +54,28 @@
 /* Pure parsers.  */
 #define YYPURE 0
 
+/* Push parsers.  */
+#define YYPUSH 0
+
+/* Pull parsers.  */
+#define YYPULL 1
+
 /* Using locations.  */
 #define YYLSP_NEEDED 0
 
 /* Substitute the variable and function names.  */
-#define yyparse parser_parse
-#define yylex   parser_lex
-#define yyerror parser_error
-#define yylval  parser_lval
-#define yychar  parser_char
-#define yydebug parser_debug
-#define yynerrs parser_nerrs
+#define yyparse         parser_parse
+#define yylex           parser_lex
+#define yyerror         parser_error
+#define yylval          parser_lval
+#define yychar          parser_char
+#define yydebug         parser_debug
+#define yynerrs         parser_nerrs
 
 
-/* Tokens.  */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
-   /* Put the tokens into the symbol table, so that GDB and other debuggers
-      know about them.  */
-   enum yytokentype {
-     aIDENTIFIER = 258,
-     aKNOWNTYPE = 259,
-     aNUM = 260,
-     aHEXNUM = 261,
-     aDOUBLE = 262,
-     aSTRING = 263,
-     aWSTRING = 264,
-     aUUID = 265,
-     aEOF = 266,
-     SHL = 267,
-     SHR = 268,
-     MEMBERPTR = 269,
-     EQUALITY = 270,
-     INEQUALITY = 271,
-     GREATEREQUAL = 272,
-     LESSEQUAL = 273,
-     LOGICALOR = 274,
-     LOGICALAND = 275,
-     tAGGREGATABLE = 276,
-     tALLOCATE = 277,
-     tAPPOBJECT = 278,
-     tASYNC = 279,
-     tASYNCUUID = 280,
-     tAUTOHANDLE = 281,
-     tBINDABLE = 282,
-     tBOOLEAN = 283,
-     tBROADCAST = 284,
-     tBYTE = 285,
-     tBYTECOUNT = 286,
-     tCALLAS = 287,
-     tCALLBACK = 288,
-     tCASE = 289,
-     tCDECL = 290,
-     tCHAR = 291,
-     tCOCLASS = 292,
-     tCODE = 293,
-     tCOMMSTATUS = 294,
-     tCONST = 295,
-     tCONTEXTHANDLE = 296,
-     tCONTEXTHANDLENOSERIALIZE = 297,
-     tCONTEXTHANDLESERIALIZE = 298,
-     tCONTROL = 299,
-     tCPPQUOTE = 300,
-     tDEFAULT = 301,
-     tDEFAULTCOLLELEM = 302,
-     tDEFAULTVALUE = 303,
-     tDEFAULTVTABLE = 304,
-     tDISPLAYBIND = 305,
-     tDISPINTERFACE = 306,
-     tDLLNAME = 307,
-     tDOUBLE = 308,
-     tDUAL = 309,
-     tENDPOINT = 310,
-     tENTRY = 311,
-     tENUM = 312,
-     tERRORSTATUST = 313,
-     tEXPLICITHANDLE = 314,
-     tEXTERN = 315,
-     tFALSE = 316,
-     tFASTCALL = 317,
-     tFLOAT = 318,
-     tHANDLE = 319,
-     tHANDLET = 320,
-     tHELPCONTEXT = 321,
-     tHELPFILE = 322,
-     tHELPSTRING = 323,
-     tHELPSTRINGCONTEXT = 324,
-     tHELPSTRINGDLL = 325,
-     tHIDDEN = 326,
-     tHYPER = 327,
-     tID = 328,
-     tIDEMPOTENT = 329,
-     tIIDIS = 330,
-     tIMMEDIATEBIND = 331,
-     tIMPLICITHANDLE = 332,
-     tIMPORT = 333,
-     tIMPORTLIB = 334,
-     tIN = 335,
-     tIN_LINE = 336,
-     tINLINE = 337,
-     tINPUTSYNC = 338,
-     tINT = 339,
-     tINT64 = 340,
-     tINTERFACE = 341,
-     tLCID = 342,
-     tLENGTHIS = 343,
-     tLIBRARY = 344,
-     tLOCAL = 345,
-     tLONG = 346,
-     tMETHODS = 347,
-     tMODULE = 348,
-     tNONBROWSABLE = 349,
-     tNONCREATABLE = 350,
-     tNONEXTENSIBLE = 351,
-     tNULL = 352,
-     tOBJECT = 353,
-     tODL = 354,
-     tOLEAUTOMATION = 355,
-     tOPTIONAL = 356,
-     tOUT = 357,
-     tPASCAL = 358,
-     tPOINTERDEFAULT = 359,
-     tPROPERTIES = 360,
-     tPROPGET = 361,
-     tPROPPUT = 362,
-     tPROPPUTREF = 363,
-     tPTR = 364,
-     tPUBLIC = 365,
-     tRANGE = 366,
-     tREADONLY = 367,
-     tREF = 368,
-     tREGISTER = 369,
-     tREQUESTEDIT = 370,
-     tRESTRICTED = 371,
-     tRETVAL = 372,
-     tSAFEARRAY = 373,
-     tSHORT = 374,
-     tSIGNED = 375,
-     tSINGLE = 376,
-     tSIZEIS = 377,
-     tSIZEOF = 378,
-     tSMALL = 379,
-     tSOURCE = 380,
-     tSTATIC = 381,
-     tSTDCALL = 382,
-     tSTRICTCONTEXTHANDLE = 383,
-     tSTRING = 384,
-     tSTRUCT = 385,
-     tSWITCH = 386,
-     tSWITCHIS = 387,
-     tSWITCHTYPE = 388,
-     tTRANSMITAS = 389,
-     tTRUE = 390,
-     tTYPEDEF = 391,
-     tUNION = 392,
-     tUNIQUE = 393,
-     tUNSIGNED = 394,
-     tUUID = 395,
-     tV1ENUM = 396,
-     tVARARG = 397,
-     tVERSION = 398,
-     tVOID = 399,
-     tWCHAR = 400,
-     tWIREMARSHAL = 401,
-     ADDRESSOF = 402,
-     NEG = 403,
-     POS = 404,
-     PPTR = 405,
-     CAST = 406
-   };
-#endif
-/* Tokens.  */
-#define aIDENTIFIER 258
-#define aKNOWNTYPE 259
-#define aNUM 260
-#define aHEXNUM 261
-#define aDOUBLE 262
-#define aSTRING 263
-#define aWSTRING 264
-#define aUUID 265
-#define aEOF 266
-#define SHL 267
-#define SHR 268
-#define MEMBERPTR 269
-#define EQUALITY 270
-#define INEQUALITY 271
-#define GREATEREQUAL 272
-#define LESSEQUAL 273
-#define LOGICALOR 274
-#define LOGICALAND 275
-#define tAGGREGATABLE 276
-#define tALLOCATE 277
-#define tAPPOBJECT 278
-#define tASYNC 279
-#define tASYNCUUID 280
-#define tAUTOHANDLE 281
-#define tBINDABLE 282
-#define tBOOLEAN 283
-#define tBROADCAST 284
-#define tBYTE 285
-#define tBYTECOUNT 286
-#define tCALLAS 287
-#define tCALLBACK 288
-#define tCASE 289
-#define tCDECL 290
-#define tCHAR 291
-#define tCOCLASS 292
-#define tCODE 293
-#define tCOMMSTATUS 294
-#define tCONST 295
-#define tCONTEXTHANDLE 296
-#define tCONTEXTHANDLENOSERIALIZE 297
-#define tCONTEXTHANDLESERIALIZE 298
-#define tCONTROL 299
-#define tCPPQUOTE 300
-#define tDEFAULT 301
-#define tDEFAULTCOLLELEM 302
-#define tDEFAULTVALUE 303
-#define tDEFAULTVTABLE 304
-#define tDISPLAYBIND 305
-#define tDISPINTERFACE 306
-#define tDLLNAME 307
-#define tDOUBLE 308
-#define tDUAL 309
-#define tENDPOINT 310
-#define tENTRY 311
-#define tENUM 312
-#define tERRORSTATUST 313
-#define tEXPLICITHANDLE 314
-#define tEXTERN 315
-#define tFALSE 316
-#define tFASTCALL 317
-#define tFLOAT 318
-#define tHANDLE 319
-#define tHANDLET 320
-#define tHELPCONTEXT 321
-#define tHELPFILE 322
-#define tHELPSTRING 323
-#define tHELPSTRINGCONTEXT 324
-#define tHELPSTRINGDLL 325
-#define tHIDDEN 326
-#define tHYPER 327
-#define tID 328
-#define tIDEMPOTENT 329
-#define tIIDIS 330
-#define tIMMEDIATEBIND 331
-#define tIMPLICITHANDLE 332
-#define tIMPORT 333
-#define tIMPORTLIB 334
-#define tIN 335
-#define tIN_LINE 336
-#define tINLINE 337
-#define tINPUTSYNC 338
-#define tINT 339
-#define tINT64 340
-#define tINTERFACE 341
-#define tLCID 342
-#define tLENGTHIS 343
-#define tLIBRARY 344
-#define tLOCAL 345
-#define tLONG 346
-#define tMETHODS 347
-#define tMODULE 348
-#define tNONBROWSABLE 349
-#define tNONCREATABLE 350
-#define tNONEXTENSIBLE 351
-#define tNULL 352
-#define tOBJECT 353
-#define tODL 354
-#define tOLEAUTOMATION 355
-#define tOPTIONAL 356
-#define tOUT 357
-#define tPASCAL 358
-#define tPOINTERDEFAULT 359
-#define tPROPERTIES 360
-#define tPROPGET 361
-#define tPROPPUT 362
-#define tPROPPUTREF 363
-#define tPTR 364
-#define tPUBLIC 365
-#define tRANGE 366
-#define tREADONLY 367
-#define tREF 368
-#define tREGISTER 369
-#define tREQUESTEDIT 370
-#define tRESTRICTED 371
-#define tRETVAL 372
-#define tSAFEARRAY 373
-#define tSHORT 374
-#define tSIGNED 375
-#define tSINGLE 376
-#define tSIZEIS 377
-#define tSIZEOF 378
-#define tSMALL 379
-#define tSOURCE 380
-#define tSTATIC 381
-#define tSTDCALL 382
-#define tSTRICTCONTEXTHANDLE 383
-#define tSTRING 384
-#define tSTRUCT 385
-#define tSWITCH 386
-#define tSWITCHIS 387
-#define tSWITCHTYPE 388
-#define tTRANSMITAS 389
-#define tTRUE 390
-#define tTYPEDEF 391
-#define tUNION 392
-#define tUNIQUE 393
-#define tUNSIGNED 394
-#define tUUID 395
-#define tV1ENUM 396
-#define tVARARG 397
-#define tVERSION 398
-#define tVOID 399
-#define tWCHAR 400
-#define tWIREMARSHAL 401
-#define ADDRESSOF 402
-#define NEG 403
-#define POS 404
-#define PPTR 405
-#define CAST 406
+/* Copy the first part of user declarations.  */
 
-
-
-
-/* Copy the first part of user declarations.  */
+/* Line 189 of yacc.c  */
 #line 1 "parser.y"
 
 /*
@@ -401,9 +107,6 @@
 #include <assert.h>
 #include <ctype.h>
 #include <string.h>
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
 
 #include "widl.h"
 #include "utils.h"
@@ -441,7 +144,7 @@
 
 #define YYERROR_VERBOSE
 
-unsigned char pointer_default = RPC_FC_UP;
+static unsigned char pointer_default = RPC_FC_UP;
 static int is_object_interface = FALSE;
 
 typedef struct list typelist_t;
@@ -465,7 +168,6 @@
 
 typelist_t incomplete_types = LIST_INIT(incomplete_types);
 
-static void add_incomplete(type_t *t);
 static void fix_incomplete(void);
 static void fix_incomplete_types(type_t *complete_type);
 
@@ -482,30 +184,18 @@
 static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls);
 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
 static ifref_t *make_ifref(type_t *iface);
-static var_list_t *append_var(var_list_t *list, var_t *var);
 static var_list_t *append_var_list(var_list_t *list, var_list_t *vars);
-static var_t *make_var(char *name);
 static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *p);
 static declarator_t *make_declarator(var_t *var);
 static func_list_t *append_func(func_list_t *list, func_t *func);
 static func_t *make_func(var_t *def);
-static type_t *make_class(char *name);
 static type_t *make_safearray(type_t *type);
-static type_t *make_builtin(char *name);
-static type_t *make_int(int sign);
 static typelib_t *make_library(const char *name, const attr_list_t *attrs);
 static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type);
 
-static type_t *type_new_enum(char *name, var_list_t *enums);
-static type_t *type_new_struct(char *name, int defined, var_list_t *fields);
-static type_t *type_new_nonencapsulated_union(char *name, var_list_t *fields);
-static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases);
-
-static type_t *reg_type(type_t *type, const char *name, int t);
 static type_t *reg_typedefs(decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs);
 static type_t *find_type_or_error(const char *name, int t);
 static type_t *find_type_or_error2(char *name, int t);
-static type_t *get_type(unsigned char type, char *name, int t);
 
 static var_t *reg_const(var_t *var);
 
@@ -541,11 +231,10 @@
 static statement_t *make_statement_typedef(var_list_t *names);
 static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt);
 
-#define tsENUM   1
-#define tsSTRUCT 2
-#define tsUNION  3
 
 
+/* Line 189 of yacc.c  */
+#line 238 "parser.tab.c"
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
@@ -565,9 +254,173 @@
 # define YYTOKEN_TABLE 0
 #endif
 
-#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
-#line 176 "parser.y"
-typedef union YYSTYPE {
+
+/* Tokens.  */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+   /* Put the tokens into the symbol table, so that GDB and other debuggers
+      know about them.  */
+   enum yytokentype {
+     aIDENTIFIER = 258,
+     aKNOWNTYPE = 259,
+     aNUM = 260,
+     aHEXNUM = 261,
+     aDOUBLE = 262,
+     aSTRING = 263,
+     aWSTRING = 264,
+     aUUID = 265,
+     aEOF = 266,
+     SHL = 267,
+     SHR = 268,
+     MEMBERPTR = 269,
+     EQUALITY = 270,
+     INEQUALITY = 271,
+     GREATEREQUAL = 272,
+     LESSEQUAL = 273,
+     LOGICALOR = 274,
+     LOGICALAND = 275,
+     tAGGREGATABLE = 276,
+     tALLOCATE = 277,
+     tAPPOBJECT = 278,
+     tASYNC = 279,
+     tASYNCUUID = 280,
+     tAUTOHANDLE = 281,
+     tBINDABLE = 282,
+     tBOOLEAN = 283,
+     tBROADCAST = 284,
+     tBYTE = 285,
+     tBYTECOUNT = 286,
+     tCALLAS = 287,
+     tCALLBACK = 288,
+     tCASE = 289,
+     tCDECL = 290,
+     tCHAR = 291,
+     tCOCLASS = 292,
+     tCODE = 293,
+     tCOMMSTATUS = 294,
+     tCONST = 295,
+     tCONTEXTHANDLE = 296,
+     tCONTEXTHANDLENOSERIALIZE = 297,
+     tCONTEXTHANDLESERIALIZE = 298,
+     tCONTROL = 299,
+     tCPPQUOTE = 300,
+     tDEFAULT = 301,
+     tDEFAULTCOLLELEM = 302,
+     tDEFAULTVALUE = 303,
+     tDEFAULTVTABLE = 304,
+     tDISPLAYBIND = 305,
+     tDISPINTERFACE = 306,
+     tDLLNAME = 307,
+     tDOUBLE = 308,
+     tDUAL = 309,
+     tENDPOINT = 310,
+     tENTRY = 311,
+     tENUM = 312,
+     tERRORSTATUST = 313,
+     tEXPLICITHANDLE = 314,
+     tEXTERN = 315,
+     tFALSE = 316,
+     tFASTCALL = 317,
+     tFLOAT = 318,
+     tHANDLE = 319,
+     tHANDLET = 320,
+     tHELPCONTEXT = 321,
+     tHELPFILE = 322,
+     tHELPSTRING = 323,
+     tHELPSTRINGCONTEXT = 324,
+     tHELPSTRINGDLL = 325,
+     tHIDDEN = 326,
+     tHYPER = 327,
+     tID = 328,
+     tIDEMPOTENT = 329,
+     tIIDIS = 330,
+     tIMMEDIATEBIND = 331,
+     tIMPLICITHANDLE = 332,
+     tIMPORT = 333,
+     tIMPORTLIB = 334,
+     tIN = 335,
+     tIN_LINE = 336,
+     tINLINE = 337,
+     tINPUTSYNC = 338,
+     tINT = 339,
+     tINT64 = 340,
+     tINTERFACE = 341,
+     tLCID = 342,
+     tLENGTHIS = 343,
+     tLIBRARY = 344,
+     tLOCAL = 345,
+     tLONG = 346,
+     tMETHODS = 347,
+     tMODULE = 348,
+     tNONBROWSABLE = 349,
+     tNONCREATABLE = 350,
+     tNONEXTENSIBLE = 351,
+     tNULL = 352,
+     tOBJECT = 353,
+     tODL = 354,
+     tOLEAUTOMATION = 355,
+     tOPTIONAL = 356,
+     tOUT = 357,
+     tPASCAL = 358,
+     tPOINTERDEFAULT = 359,
+     tPROPERTIES = 360,
+     tPROPGET = 361,
+     tPROPPUT = 362,
+     tPROPPUTREF = 363,
+     tPTR = 364,
+     tPUBLIC = 365,
+     tRANGE = 366,
+     tREADONLY = 367,
+     tREF = 368,
+     tREGISTER = 369,
+     tREQUESTEDIT = 370,
+     tRESTRICTED = 371,
+     tRETVAL = 372,
+     tSAFEARRAY = 373,
+     tSHORT = 374,
+     tSIGNED = 375,
+     tSIZEIS = 376,
+     tSIZEOF = 377,
+     tSMALL = 378,
+     tSOURCE = 379,
+     tSTATIC = 380,
+     tSTDCALL = 381,
+     tSTRICTCONTEXTHANDLE = 382,
+     tSTRING = 383,
+     tSTRUCT = 384,
+     tSWITCH = 385,
+     tSWITCHIS = 386,
+     tSWITCHTYPE = 387,
+     tTRANSMITAS = 388,
+     tTRUE = 389,
+     tTYPEDEF = 390,
+     tUNION = 391,
+     tUNIQUE = 392,
+     tUNSIGNED = 393,
+     tUUID = 394,
+     tV1ENUM = 395,
+     tVARARG = 396,
+     tVERSION = 397,
+     tVOID = 398,
+     tWCHAR = 399,
+     tWIREMARSHAL = 400,
+     ADDRESSOF = 401,
+     NEG = 402,
+     POS = 403,
+     PPTR = 404,
+     CAST = 405
+   };
+#endif
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+{
+
+/* Line 214 of yacc.c  */
+#line 156 "parser.y"
+
 	attr_t *attr;
 	attr_list_t *attr_list;
 	str_list_t *str_list;
@@ -594,36 +447,71 @@
 	struct _import_t *import;
 	struct _decl_spec_t *declspec;
 	enum storage_class stgclass;
+
+
+
+/* Line 214 of yacc.c  */
+#line 455 "parser.tab.c"
 } YYSTYPE;
-/* Line 196 of yacc.c.  */
-#line 600 "parser.tab.c"
+# define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
 #endif
 
 
-
 /* Copy the second part of user declarations.  */
 
 
-/* Line 219 of yacc.c.  */
-#line 612 "parser.tab.c"
+/* Line 264 of yacc.c  */
+#line 467 "parser.tab.c"
 
-#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
-# define YYSIZE_T __SIZE_TYPE__
+#ifdef short
+# undef short
 #endif
-#if ! defined (YYSIZE_T) && defined (size_t)
-# define YYSIZE_T size_t
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
 #endif
-#if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
-# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
-# define YYSIZE_T size_t
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#elif (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+typedef signed char yytype_int8;
+#else
+typedef short int yytype_int8;
 #endif
-#if ! defined (YYSIZE_T)
-# define YYSIZE_T unsigned int
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
 #endif
 
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+#  define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+#  define YYSIZE_T size_t
+# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYSIZE_T size_t
+# else
+#  define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
 #ifndef YY_
 # if YYENABLE_NLS
 #  if ENABLE_NLS
@@ -636,74 +524,111 @@
 # endif
 #endif
 
-#if ! defined (yyoverflow) || YYERROR_VERBOSE
+/* Suppress unused-variable warnings by "using" E.  */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(e) ((void) (e))
+#else
+# define YYUSE(e) /* empty */
+#endif
 
+/* Identity function, used to suppress warnings about constant conditions.  */
+#ifndef lint
+# define YYID(n) (n)
+#else
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static int
+YYID (int yyi)
+#else
+static int
+YYID (yyi)
+    int yyi;
+#endif
+{
+  return yyi;
+}
+#endif
+
+#if ! defined yyoverflow || YYERROR_VERBOSE
+
 /* The parser invokes alloca or malloc; define the necessary symbols.  */
 
 # ifdef YYSTACK_USE_ALLOCA
 #  if YYSTACK_USE_ALLOCA
 #   ifdef __GNUC__
 #    define YYSTACK_ALLOC __builtin_alloca
+#   elif defined __BUILTIN_VA_ARG_INCR
+#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+#   elif defined _AIX
+#    define YYSTACK_ALLOC __alloca
+#   elif defined _MSC_VER
+#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+#    define alloca _alloca
 #   else
 #    define YYSTACK_ALLOC alloca
-#    if defined (__STDC__) || defined (__cplusplus)
+#    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-#     define YYINCLUDED_STDLIB_H
+#     ifndef _STDLIB_H
+#      define _STDLIB_H 1
+#     endif
 #    endif
 #   endif
 #  endif
 # endif
 
 # ifdef YYSTACK_ALLOC
-   /* Pacify GCC's `empty if-body' warning. */
-#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+   /* Pacify GCC's `empty if-body' warning.  */
+#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
 #  ifndef YYSTACK_ALLOC_MAXIMUM
     /* The OS might guarantee only one guard page at the bottom of the stack,
        and a page size can be as small as 4096 bytes.  So we cannot safely
        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
        to allow for a few compiler-allocated temporary stack slots.  */
-#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */
+#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
 #  endif
 # else
 #  define YYSTACK_ALLOC YYMALLOC
 #  define YYSTACK_FREE YYFREE
 #  ifndef YYSTACK_ALLOC_MAXIMUM
-#   define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1)
+#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
 #  endif
-#  ifdef __cplusplus
-extern "C" {
+#  if (defined __cplusplus && ! defined _STDLIB_H \
+       && ! ((defined YYMALLOC || defined malloc) \
+	     && (defined YYFREE || defined free)))
+#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+#   ifndef _STDLIB_H
+#    define _STDLIB_H 1
+#   endif
 #  endif
 #  ifndef YYMALLOC
 #   define YYMALLOC malloc
-#   if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \
-	&& (defined (__STDC__) || defined (__cplusplus)))
+#   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
 #   endif
 #  endif
 #  ifndef YYFREE
 #   define YYFREE free
-#   if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \
-	&& (defined (__STDC__) || defined (__cplusplus)))
+#   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
 void free (void *); /* INFRINGES ON USER NAME SPACE */
 #   endif
 #  endif
-#  ifdef __cplusplus
-}
-#  endif
 # endif
-#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
 
 
-#if (! defined (yyoverflow) \
-     && (! defined (__cplusplus) \
-	 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
+#if (! defined yyoverflow \
+     && (! defined __cplusplus \
+	 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
 
 /* A type that is properly aligned for any stack member.  */
 union yyalloc
 {
-  short int yyss;
-  YYSTYPE yyvs;
-  };
+  yytype_int16 yyss_alloc;
+  YYSTYPE yyvs_alloc;
+};
 
 /* The size of the maximum gap between one aligned stack and the next.  */
 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
@@ -711,13 +636,13 @@
 /* The size of an array large to enough to hold all stacks, each with
    N elements.  */
 # define YYSTACK_BYTES(N) \
-     ((N) * (sizeof (short int) + sizeof (YYSTYPE))			\
+     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
       + YYSTACK_GAP_MAXIMUM)
 
 /* Copy COUNT objects from FROM to TO.  The source and destination do
    not overlap.  */
 # ifndef YYCOPY
-#  if defined (__GNUC__) && 1 < __GNUC__
+#  if defined __GNUC__ && 1 < __GNUC__
 #   define YYCOPY(To, From, Count) \
       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
 #  else
@@ -728,7 +653,7 @@
 	  for (yyi = 0; yyi < (Count); yyi++)	\
 	    (To)[yyi] = (From)[yyi];		\
 	}					\
-      while (0)
+      while (YYID (0))
 #  endif
 # endif
 
@@ -737,62 +662,56 @@
    elements in the stack, and YYPTR gives the new location of the
    stack.  Advance YYPTR to a properly aligned location for the next
    stack.  */
-# define YYSTACK_RELOCATE(Stack)					\
+# define YYSTACK_RELOCATE(Stack_alloc, Stack)				\
     do									\
       {									\
 	YYSIZE_T yynewbytes;						\
-	YYCOPY (&yyptr->Stack, Stack, yysize);				\
-	Stack = &yyptr->Stack;						\
+	YYCOPY (&yyptr->Stack_alloc, Stack, yysize);			\
+	Stack = &yyptr->Stack_alloc;					\
 	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
 	yyptr += yynewbytes / sizeof (*yyptr);				\
       }									\
-    while (0)
+    while (YYID (0))
 
 #endif
 
-#if defined (__STDC__) || defined (__cplusplus)
-   typedef signed char yysigned_char;
-#else
-   typedef short int yysigned_char;
-#endif
-
-/* YYFINAL -- State number of the termination state. */
+/* YYFINAL -- State number of the termination state.  */
 #define YYFINAL  3
 /* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   2034
+#define YYLAST   1996
 
-/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS  176
-/* YYNNTS -- Number of nonterminals. */
+/* YYNTOKENS -- Number of terminals.  */
+#define YYNTOKENS  175
+/* YYNNTS -- Number of nonterminals.  */
 #define YYNNTS  88
-/* YYNRULES -- Number of rules. */
-#define YYNRULES  312
-/* YYNRULES -- Number of states. */
-#define YYNSTATES  548
+/* YYNRULES -- Number of rules.  */
+#define YYNRULES  311
+/* YYNRULES -- Number of states.  */
+#define YYNSTATES  547
 
 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
 #define YYUNDEFTOK  2
-#define YYMAXUTOK   406
+#define YYMAXUTOK   405
 
 #define YYTRANSLATE(YYX)						\
   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
 
 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
-static const unsigned char yytranslate[] =
+static const yytype_uint8 yytranslate[] =
 {
        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,   160,     2,     2,     2,   159,   152,     2,
-     171,   172,   157,   156,   147,   155,   167,   158,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,   149,   170,
-     153,   175,   154,   148,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,   159,     2,     2,     2,   158,   151,     2,
+     170,   171,   156,   155,   146,   154,   166,   157,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,   148,   169,
+     152,   174,   153,   147,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,   168,     2,   169,   151,     2,     2,     2,     2,     2,
+       2,   167,     2,   168,   150,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,   173,   150,   174,   161,     2,     2,     2,
+       2,     2,     2,   172,   149,   173,   160,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
@@ -820,13 +739,13 @@
      115,   116,   117,   118,   119,   120,   121,   122,   123,   124,
      125,   126,   127,   128,   129,   130,   131,   132,   133,   134,
      135,   136,   137,   138,   139,   140,   141,   142,   143,   144,
-     145,   146,   162,   163,   164,   165,   166
+     145,   161,   162,   163,   164,   165
 };
 
 #if YYDEBUG
 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
    YYRHS.  */
-static const unsigned short int yyprhs[] =
+static const yytype_uint16 yyprhs[] =
 {
        0,     0,     3,     5,     6,     9,    12,    16,    19,    22,
       25,    28,    29,    32,    35,    39,    42,    45,    48,    51,
@@ -851,158 +770,158 @@
      609,   613,   616,   619,   620,   623,   626,   628,   632,   636,
      640,   643,   644,   646,   647,   649,   651,   653,   655,   657,
      659,   661,   664,   667,   669,   671,   673,   675,   677,   679,
-     681,   682,   684,   686,   689,   691,   694,   697,   699,   701,
-     704,   707,   710,   716,   717,   720,   723,   726,   729,   732,
-     735,   739,   742,   746,   752,   758,   759,   762,   765,   768,
-     771,   778,   787,   790,   793,   796,   799,   802,   805,   811,
-     813,   815,   817,   819,   821,   822,   825,   828,   832,   833,
-     835,   838,   841,   844,   848,   851,   853,   855,   859,   862,
-     867,   869,   873,   875,   879,   881,   883,   885,   891,   893,
-     895,   897,   899,   902,   904,   907,   909,   912,   917,   922,
-     928,   939,   941
+     680,   682,   684,   687,   689,   692,   695,   697,   699,   702,
+     705,   708,   714,   715,   718,   721,   724,   727,   730,   733,
+     737,   740,   744,   750,   756,   757,   760,   763,   766,   769,
+     776,   785,   788,   791,   794,   797,   800,   803,   809,   811,
+     813,   815,   817,   819,   820,   823,   826,   830,   831,   833,
+     836,   839,   842,   846,   849,   851,   853,   857,   860,   865,
+     867,   871,   873,   877,   879,   881,   883,   889,   891,   893,
+     895,   897,   900,   902,   905,   907,   910,   915,   920,   926,
+     937,   939
 };
 
-/* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const short int yyrhs[] =
+/* YYRHS -- A `-1'-separated list of the rules' RHS.  */
+static const yytype_int16 yyrhs[] =
 {
-     177,     0,    -1,   178,    -1,    -1,   178,   243,    -1,   178,
-     242,    -1,   178,   229,   170,    -1,   178,   231,    -1,   178,
-     246,    -1,   178,   190,    -1,   178,   182,    -1,    -1,   179,
-     243,    -1,   179,   242,    -1,   179,   229,   170,    -1,   179,
-     231,    -1,   179,   246,    -1,   179,   182,    -1,   179,   187,
-      -1,   179,   190,    -1,    -1,   180,   182,    -1,    -1,   170,
-      -1,   184,    -1,   183,   170,    -1,   222,   170,    -1,   186,
-      -1,   261,   170,    -1,   208,    -1,   259,    -1,   262,    -1,
-     197,   208,    -1,   197,   259,    -1,   197,   262,    -1,    45,
-     171,     8,   172,    -1,    78,     8,   170,    -1,   185,   179,
-      11,    -1,    79,   171,     8,   172,   181,    -1,    89,     3,
-      -1,   197,   188,   173,    -1,   189,   179,   174,   181,    -1,
-      -1,   193,    -1,   144,    -1,   194,    -1,   193,   147,   194,
-      -1,   192,    -1,   197,   251,   254,    -1,   251,   254,    -1,
-     168,   210,   169,    -1,   168,   157,   169,    -1,    -1,   197,
-      -1,   168,   198,   169,    -1,   200,    -1,   198,   147,   200,
-      -1,   198,   169,   168,   200,    -1,     8,    -1,   199,   147,
+     176,     0,    -1,   177,    -1,    -1,   177,   242,    -1,   177,
+     241,    -1,   177,   228,   169,    -1,   177,   230,    -1,   177,
+     245,    -1,   177,   189,    -1,   177,   181,    -1,    -1,   178,
+     242,    -1,   178,   241,    -1,   178,   228,   169,    -1,   178,
+     230,    -1,   178,   245,    -1,   178,   181,    -1,   178,   186,
+      -1,   178,   189,    -1,    -1,   179,   181,    -1,    -1,   169,
+      -1,   183,    -1,   182,   169,    -1,   221,   169,    -1,   185,
+      -1,   260,   169,    -1,   207,    -1,   258,    -1,   261,    -1,
+     196,   207,    -1,   196,   258,    -1,   196,   261,    -1,    45,
+     170,     8,   171,    -1,    78,     8,   169,    -1,   184,   178,
+      11,    -1,    79,   170,     8,   171,   180,    -1,    89,     3,
+      -1,   196,   187,   172,    -1,   188,   178,   173,   180,    -1,
+      -1,   192,    -1,   143,    -1,   193,    -1,   192,   146,   193,
+      -1,   191,    -1,   196,   250,   253,    -1,   250,   253,    -1,
+     167,   209,   168,    -1,   167,   156,   168,    -1,    -1,   196,
+      -1,   167,   197,   168,    -1,   199,    -1,   197,   146,   199,
+      -1,   197,   168,   167,   199,    -1,     8,    -1,   198,   146,
        8,    -1,    -1,    21,    -1,    23,    -1,    24,    -1,    26,
-      -1,    27,    -1,    29,    -1,    32,   171,   225,   172,    -1,
-      34,   171,   212,   172,    -1,    41,    -1,    42,    -1,    43,
-      -1,    44,    -1,    46,    -1,    47,    -1,    48,   171,   214,
-     172,    -1,    49,    -1,    50,    -1,    52,   171,     8,   172,
-      -1,    54,    -1,    55,   171,   199,   172,    -1,    56,   171,
-     214,   172,    -1,    59,    -1,    64,    -1,    66,   171,   213,
-     172,    -1,    67,   171,     8,   172,    -1,    68,   171,     8,
-     172,    -1,    69,   171,   213,   172,    -1,    70,   171,     8,
-     172,    -1,    71,    -1,    73,   171,   213,   172,    -1,    74,
-      -1,    75,   171,   211,   172,    -1,    76,    -1,    77,   171,
-      65,     3,   172,    -1,    80,    -1,    83,    -1,    88,   171,
-     209,   172,    -1,    87,   171,   213,   172,    -1,    90,    -1,
+      -1,    27,    -1,    29,    -1,    32,   170,   224,   171,    -1,
+      34,   170,   211,   171,    -1,    41,    -1,    42,    -1,    43,
+      -1,    44,    -1,    46,    -1,    47,    -1,    48,   170,   213,
+     171,    -1,    49,    -1,    50,    -1,    52,   170,     8,   171,
+      -1,    54,    -1,    55,   170,   198,   171,    -1,    56,   170,
+     213,   171,    -1,    59,    -1,    64,    -1,    66,   170,   212,
+     171,    -1,    67,   170,     8,   171,    -1,    68,   170,     8,
+     171,    -1,    69,   170,   212,   171,    -1,    70,   170,     8,
+     171,    -1,    71,    -1,    73,   170,   212,   171,    -1,    74,
+      -1,    75,   170,   210,   171,    -1,    76,    -1,    77,   170,
+      65,     3,   171,    -1,    80,    -1,    83,    -1,    88,   170,
+     208,   171,    -1,    87,   170,   212,   171,    -1,    90,    -1,
       94,    -1,    95,    -1,    96,    -1,    98,    -1,    99,    -1,
-     100,    -1,   101,    -1,   102,    -1,   104,   171,   258,   172,
+     100,    -1,   101,    -1,   102,    -1,   104,   170,   257,   171,
       -1,   106,    -1,   107,    -1,   108,    -1,   110,    -1,   111,
-     171,   213,   147,   213,   172,    -1,   112,    -1,   115,    -1,
-     116,    -1,   117,    -1,   122,   171,   209,   172,    -1,   125,
-      -1,   128,    -1,   129,    -1,   132,   171,   211,   172,    -1,
-     133,   171,   260,   172,    -1,   134,   171,   260,   172,    -1,
-     140,   171,   201,   172,    -1,   141,    -1,   142,    -1,   143,
-     171,   263,   172,    -1,   146,   171,   260,   172,    -1,   258,
+     170,   212,   146,   212,   171,    -1,   112,    -1,   115,    -1,
+     116,    -1,   117,    -1,   121,   170,   208,   171,    -1,   124,
+      -1,   127,    -1,   128,    -1,   131,   170,   210,   171,    -1,
+     132,   170,   259,   171,    -1,   133,   170,   259,   171,    -1,
+     139,   170,   200,   171,    -1,   140,    -1,   141,    -1,   142,
+     170,   262,   171,    -1,   145,   170,   259,   171,    -1,   257,
       -1,    10,    -1,     8,    -1,    35,    -1,    62,    -1,   103,
-      -1,   127,    -1,    -1,   203,   204,    -1,    34,   213,   149,
-     219,    -1,    46,   149,   219,    -1,    -1,   206,   147,    -1,
-     206,    -1,   207,    -1,   206,   147,   207,    -1,   225,   175,
-     213,    -1,   225,    -1,    57,   224,   173,   205,   174,    -1,
-     210,    -1,   209,   147,   210,    -1,    -1,   211,    -1,     5,
-      -1,     6,    -1,     7,    -1,    61,    -1,    97,    -1,   135,
-      -1,     8,    -1,     9,    -1,     3,    -1,   211,   148,   211,
-     149,   211,    -1,   211,    19,   211,    -1,   211,    20,   211,
-      -1,   211,   150,   211,    -1,   211,   151,   211,    -1,   211,
-     152,   211,    -1,   211,    15,   211,    -1,   211,    16,   211,
-      -1,   211,   154,   211,    -1,   211,   153,   211,    -1,   211,
-      17,   211,    -1,   211,    18,   211,    -1,   211,    12,   211,
-      -1,   211,    13,   211,    -1,   211,   156,   211,    -1,   211,
-     155,   211,    -1,   211,   159,   211,    -1,   211,   157,   211,
-      -1,   211,   158,   211,    -1,   160,   211,    -1,   161,   211,
-      -1,   156,   211,    -1,   155,   211,    -1,   152,   211,    -1,
-     157,   211,    -1,   211,    14,     3,    -1,   211,   167,     3,
-      -1,   171,   260,   172,   211,    -1,   123,   171,   260,   172,
-      -1,   211,   168,   211,   169,    -1,   171,   211,   172,    -1,
-     213,    -1,   212,   147,   213,    -1,   211,    -1,   211,    -1,
-      -1,   215,   216,    -1,   196,   251,   256,   170,    -1,   196,
-     262,   170,    -1,   220,   170,    -1,   197,   170,    -1,    -1,
-     218,   217,    -1,   220,   170,    -1,   170,    -1,   196,   251,
-     254,    -1,   196,   251,   254,    -1,   197,   251,   257,    -1,
-     251,   257,    -1,    -1,   225,    -1,    -1,     3,    -1,     4,
-      -1,     3,    -1,     4,    -1,    30,    -1,   145,    -1,   228,
-      -1,   120,   228,    -1,   139,   228,    -1,   139,    -1,    63,
-      -1,   121,    -1,    53,    -1,    28,    -1,    58,    -1,    65,
-      -1,    -1,    84,    -1,    84,    -1,   119,   227,    -1,   124,
-      -1,    91,   227,    -1,    72,   227,    -1,    85,    -1,    36,
-      -1,    37,     3,    -1,    37,     4,    -1,   197,   229,    -1,
-     230,   173,   232,   174,   181,    -1,    -1,   232,   233,    -1,
-     196,   243,    -1,    51,     3,    -1,    51,     4,    -1,   197,
-     234,    -1,   105,   149,    -1,   236,   220,   170,    -1,    92,
-     149,    -1,   237,   221,   170,    -1,   235,   173,   236,   237,
-     174,    -1,   235,   173,   240,   170,   174,    -1,    -1,   149,
-       4,    -1,    86,     3,    -1,    86,     4,    -1,   197,   240,
-      -1,   241,   239,   173,   180,   174,   181,    -1,   241,   149,
-       3,   173,   186,   180,   174,   181,    -1,   238,   181,    -1,
-     240,   170,    -1,   234,   170,    -1,    93,     3,    -1,    93,
-       4,    -1,   197,   244,    -1,   245,   173,   180,   174,   181,
-      -1,    60,    -1,   126,    -1,   114,    -1,    82,    -1,    40,
-      -1,    -1,   250,   249,    -1,   260,   252,    -1,   253,   260,
-     252,    -1,    -1,   253,    -1,   249,   252,    -1,   248,   252,
-      -1,   247,   252,    -1,   157,   250,   254,    -1,   202,   254,
-      -1,   255,    -1,   225,    -1,   171,   254,   172,    -1,   255,
-     195,    -1,   255,   171,   191,   172,    -1,   254,    -1,   256,
-     147,   254,    -1,   254,    -1,   254,   175,   214,    -1,   113,
-      -1,   138,    -1,   109,    -1,   130,   224,   173,   215,   174,
-      -1,   144,    -1,     4,    -1,   226,    -1,   208,    -1,    57,
-       3,    -1,   259,    -1,   130,     3,    -1,   262,    -1,   137,
-       3,    -1,   118,   171,   260,   172,    -1,   136,   196,   251,
-     256,    -1,   137,   224,   173,   218,   174,    -1,   137,   224,
-     131,   171,   220,   172,   223,   173,   203,   174,    -1,     5,
-      -1,     5,   167,     5,    -1
+      -1,   126,    -1,    -1,   202,   203,    -1,    34,   212,   148,
+     218,    -1,    46,   148,   218,    -1,    -1,   205,   146,    -1,
+     205,    -1,   206,    -1,   205,   146,   206,    -1,   224,   174,
+     212,    -1,   224,    -1,    57,   223,   172,   204,   173,    -1,
+     209,    -1,   208,   146,   209,    -1,    -1,   210,    -1,     5,
+      -1,     6,    -1,     7,    -1,    61,    -1,    97,    -1,   134,
+      -1,     8,    -1,     9,    -1,     3,    -1,   210,   147,   210,
+     148,   210,    -1,   210,    19,   210,    -1,   210,    20,   210,
+      -1,   210,   149,   210,    -1,   210,   150,   210,    -1,   210,
+     151,   210,    -1,   210,    15,   210,    -1,   210,    16,   210,
+      -1,   210,   153,   210,    -1,   210,   152,   210,    -1,   210,
+      17,   210,    -1,   210,    18,   210,    -1,   210,    12,   210,
+      -1,   210,    13,   210,    -1,   210,   155,   210,    -1,   210,
+     154,   210,    -1,   210,   158,   210,    -1,   210,   156,   210,
+      -1,   210,   157,   210,    -1,   159,   210,    -1,   160,   210,
+      -1,   155,   210,    -1,   154,   210,    -1,   151,   210,    -1,
+     156,   210,    -1,   210,    14,     3,    -1,   210,   166,     3,
+      -1,   170,   259,   171,   210,    -1,   122,   170,   259,   171,
+      -1,   210,   167,   210,   168,    -1,   170,   210,   171,    -1,
+     212,    -1,   211,   146,   212,    -1,   210,    -1,   210,    -1,
+      -1,   214,   215,    -1,   195,   250,   255,   169,    -1,   195,
+     261,   169,    -1,   219,   169,    -1,   196,   169,    -1,    -1,
+     217,   216,    -1,   219,   169,    -1,   169,    -1,   195,   250,
+     253,    -1,   195,   250,   253,    -1,   196,   250,   256,    -1,
+     250,   256,    -1,    -1,   224,    -1,    -1,     3,    -1,     4,
+      -1,     3,    -1,     4,    -1,    30,    -1,   144,    -1,   227,
+      -1,   120,   227,    -1,   138,   227,    -1,   138,    -1,    63,
+      -1,    53,    -1,    28,    -1,    58,    -1,    65,    -1,    -1,
+      84,    -1,    84,    -1,   119,   226,    -1,   123,    -1,    91,
+     226,    -1,    72,   226,    -1,    85,    -1,    36,    -1,    37,
+       3,    -1,    37,     4,    -1,   196,   228,    -1,   229,   172,
+     231,   173,   180,    -1,    -1,   231,   232,    -1,   195,   242,
+      -1,    51,     3,    -1,    51,     4,    -1,   196,   233,    -1,
+     105,   148,    -1,   235,   219,   169,    -1,    92,   148,    -1,
+     236,   220,   169,    -1,   234,   172,   235,   236,   173,    -1,
+     234,   172,   239,   169,   173,    -1,    -1,   148,     4,    -1,
+      86,     3,    -1,    86,     4,    -1,   196,   239,    -1,   240,
+     238,   172,   179,   173,   180,    -1,   240,   148,     3,   172,
+     185,   179,   173,   180,    -1,   237,   180,    -1,   239,   169,
+      -1,   233,   169,    -1,    93,     3,    -1,    93,     4,    -1,
+     196,   243,    -1,   244,   172,   179,   173,   180,    -1,    60,
+      -1,   125,    -1,   114,    -1,    82,    -1,    40,    -1,    -1,
+     249,   248,    -1,   259,   251,    -1,   252,   259,   251,    -1,
+      -1,   252,    -1,   248,   251,    -1,   247,   251,    -1,   246,
+     251,    -1,   156,   249,   253,    -1,   201,   253,    -1,   254,
+      -1,   224,    -1,   170,   253,   171,    -1,   254,   194,    -1,
+     254,   170,   190,   171,    -1,   253,    -1,   255,   146,   253,
+      -1,   253,    -1,   253,   174,   213,    -1,   113,    -1,   137,
+      -1,   109,    -1,   129,   223,   172,   214,   173,    -1,   143,
+      -1,     4,    -1,   225,    -1,   207,    -1,    57,     3,    -1,
+     258,    -1,   129,     3,    -1,   261,    -1,   136,     3,    -1,
+     118,   170,   259,   171,    -1,   135,   195,   250,   255,    -1,
+     136,   223,   172,   217,   173,    -1,   136,   223,   130,   170,
+     219,   171,   222,   172,   202,   173,    -1,     5,    -1,     5,
+     166,     5,    -1
 };
 
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
-static const unsigned short int yyrline[] =
+static const yytype_uint16 yyrline[] =
 {
-       0,   347,   347,   360,   361,   362,   363,   366,   369,   370,
-     371,   374,   375,   376,   377,   378,   381,   382,   383,   384,
-     387,   388,   391,   392,   396,   397,   398,   399,   400,   404,
-     405,   406,   407,   408,   409,   412,   414,   422,   428,   432,
-     434,   438,   445,   446,   449,   452,   453,   454,   458,   465,
-     473,   474,   477,   478,   482,   485,   486,   487,   490,   491,
-     494,   495,   496,   497,   498,   499,   500,   501,   502,   503,
-     504,   505,   506,   507,   508,   509,   510,   511,   512,   513,
-     514,   515,   516,   517,   518,   519,   520,   521,   522,   523,
-     524,   525,   526,   527,   528,   529,   530,   531,   532,   533,
-     534,   535,   536,   537,   538,   539,   540,   541,   542,   543,
-     544,   545,   546,   547,   551,   552,   553,   554,   555,   556,
-     557,   558,   559,   560,   561,   562,   563,   564,   565,   566,
-     567,   571,   572,   577,   578,   579,   580,   583,   584,   587,
-     591,   597,   598,   599,   602,   606,   615,   619,   624,   627,
-     628,   641,   642,   645,   646,   647,   648,   649,   650,   651,
-     652,   653,   654,   655,   656,   657,   658,   659,   660,   661,
-     662,   663,   664,   665,   666,   667,   668,   669,   670,   671,
-     672,   673,   674,   675,   676,   677,   678,   679,   680,   681,
-     682,   683,   684,   687,   688,   691,   697,   703,   704,   707,
-     712,   719,   720,   723,   724,   728,   729,   732,   740,   749,
-     755,   761,   762,   765,   766,   767,   770,   772,   775,   776,
-     777,   778,   779,   795,   796,   797,   798,   799,   800,   801,
-     804,   805,   808,   809,   810,   811,   812,   813,   814,   817,
-     818,   826,   832,   836,   837,   841,   844,   845,   848,   858,
-     859,   862,   863,   866,   872,   878,   879,   882,   883,   886,
-     897,   904,   910,   914,   915,   918,   919,   922,   927,   934,
-     935,   936,   940,   944,   947,   948,   951,   952,   956,   957,
-     961,   962,   963,   967,   969,   970,   974,   975,   976,   977,
-     984,   985,   989,   990,   994,   995,   996,   999,  1002,  1003,
-    1004,  1005,  1006,  1007,  1008,  1009,  1010,  1011,  1014,  1020,
-    1022,  1028,  1029
+       0,   326,   326,   339,   340,   341,   342,   345,   348,   349,
+     350,   353,   354,   355,   356,   357,   360,   361,   362,   363,
+     366,   367,   370,   371,   375,   376,   377,   378,   379,   383,
+     384,   385,   386,   387,   388,   391,   393,   401,   407,   411,
+     413,   417,   424,   425,   428,   431,   432,   433,   437,   444,
+     452,   453,   456,   457,   461,   464,   465,   466,   469,   470,
+     473,   474,   475,   476,   477,   478,   479,   480,   481,   482,
+     483,   484,   485,   486,   487,   488,   489,   490,   491,   492,
+     493,   494,   495,   496,   497,   498,   499,   500,   501,   502,
+     503,   504,   505,   506,   507,   508,   509,   510,   511,   512,
+     513,   514,   515,   516,   517,   518,   519,   520,   521,   522,
+     523,   524,   525,   526,   530,   531,   532,   533,   534,   535,
+     536,   537,   538,   539,   540,   541,   542,   543,   544,   545,
+     546,   550,   551,   556,   557,   558,   559,   562,   563,   566,
+     570,   576,   577,   578,   581,   585,   594,   598,   603,   606,
+     607,   620,   621,   624,   625,   626,   627,   628,   629,   630,
+     631,   632,   633,   634,   635,   636,   637,   638,   639,   640,
+     641,   642,   643,   644,   645,   646,   647,   648,   649,   650,
+     651,   652,   653,   654,   655,   656,   657,   658,   659,   660,
+     661,   662,   663,   666,   667,   670,   676,   682,   683,   686,
+     691,   698,   699,   702,   703,   707,   708,   711,   719,   728,
+     734,   740,   741,   744,   745,   746,   749,   751,   754,   755,
+     756,   757,   758,   759,   760,   761,   762,   763,   764,   767,
+     768,   771,   772,   773,   774,   775,   776,   777,   780,   781,
+     789,   795,   799,   800,   804,   807,   808,   811,   821,   822,
+     825,   826,   829,   835,   841,   842,   845,   846,   849,   860,
+     867,   873,   877,   878,   881,   882,   885,   890,   897,   898,
+     899,   903,   907,   910,   911,   914,   915,   919,   920,   924,
+     925,   926,   930,   932,   933,   937,   938,   939,   940,   947,
+     948,   952,   953,   957,   958,   959,   962,   965,   966,   967,
+     968,   969,   970,   971,   972,   973,   974,   977,   983,   985,
+     991,   992
 };
 #endif
 
 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
-   First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
 static const char *const yytname[] =
 {
   "$end", "error", "$undefined", "aIDENTIFIER", "aKNOWNTYPE", "aNUM",
@@ -1027,29 +946,29 @@
   "tOPTIONAL", "tOUT", "tPASCAL", "tPOINTERDEFAULT", "tPROPERTIES",
   "tPROPGET", "tPROPPUT", "tPROPPUTREF", "tPTR", "tPUBLIC", "tRANGE",
   "tREADONLY", "tREF", "tREGISTER", "tREQUESTEDIT", "tRESTRICTED",
-  "tRETVAL", "tSAFEARRAY", "tSHORT", "tSIGNED", "tSINGLE", "tSIZEIS",
-  "tSIZEOF", "tSMALL", "tSOURCE", "tSTATIC", "tSTDCALL",
-  "tSTRICTCONTEXTHANDLE", "tSTRING", "tSTRUCT", "tSWITCH", "tSWITCHIS",
-  "tSWITCHTYPE", "tTRANSMITAS", "tTRUE", "tTYPEDEF", "tUNION", "tUNIQUE",
-  "tUNSIGNED", "tUUID", "tV1ENUM", "tVARARG", "tVERSION", "tVOID",
-  "tWCHAR", "tWIREMARSHAL", "','", "'?'", "':'", "'|'", "'^'", "'&'",
-  "'<'", "'>'", "'-'", "'+'", "'*'", "'/'", "'%'", "'!'", "'~'",
-  "ADDRESSOF", "NEG", "POS", "PPTR", "CAST", "'.'", "'['", "']'", "';'",
-  "'('", "')'", "'{'", "'}'", "'='", "$accept", "input", "gbl_statements",
-  "imp_statements", "int_statements", "semicolon_opt", "statement",
-  "typedecl", "cppquote", "import_start", "import", "importlib",
-  "libraryhdr", "library_start", "librarydef", "m_args", "no_args", "args",
-  "arg", "array", "m_attributes", "attributes", "attrib_list", "str_list",
-  "attribute", "uuid_string", "callconv", "cases", "case", "enums",
-  "enum_list", "enum", "enumdef", "m_exprs", "m_expr", "expr",
-  "expr_list_int_const", "expr_int_const", "expr_const", "fields", "field",
-  "ne_union_field", "ne_union_fields", "union_field", "s_field", "funcdef",
-  "declaration", "m_ident", "t_ident", "ident", "base_type", "m_int",
-  "int_std", "coclass", "coclasshdr", "coclassdef", "coclass_ints",
-  "coclass_int", "dispinterface", "dispinterfacehdr", "dispint_props",
-  "dispint_meths", "dispinterfacedef", "inherit", "interface",
-  "interfacehdr", "interfacedef", "interfacedec", "module", "modulehdr",
-  "moduledef", "storage_cls_spec", "function_specifier", "type_qualifier",
+  "tRETVAL", "tSAFEARRAY", "tSHORT", "tSIGNED", "tSIZEIS", "tSIZEOF",
+  "tSMALL", "tSOURCE", "tSTATIC", "tSTDCALL", "tSTRICTCONTEXTHANDLE",
+  "tSTRING", "tSTRUCT", "tSWITCH", "tSWITCHIS", "tSWITCHTYPE",
+  "tTRANSMITAS", "tTRUE", "tTYPEDEF", "tUNION", "tUNIQUE", "tUNSIGNED",
+  "tUUID", "tV1ENUM", "tVARARG", "tVERSION", "tVOID", "tWCHAR",
+  "tWIREMARSHAL", "','", "'?'", "':'", "'|'", "'^'", "'&'", "'<'", "'>'",
+  "'-'", "'+'", "'*'", "'/'", "'%'", "'!'", "'~'", "ADDRESSOF", "NEG",
+  "POS", "PPTR", "CAST", "'.'", "'['", "']'", "';'", "'('", "')'", "'{'",
+  "'}'", "'='", "$accept", "input", "gbl_statements", "imp_statements",
+  "int_statements", "semicolon_opt", "statement", "typedecl", "cppquote",
+  "import_start", "import", "importlib", "libraryhdr", "library_start",
+  "librarydef", "m_args", "no_args", "args", "arg", "array",
+  "m_attributes", "attributes", "attrib_list", "str_list", "attribute",
+  "uuid_string", "callconv", "cases", "case", "enums", "enum_list", "enum",
+  "enumdef", "m_exprs", "m_expr", "expr", "expr_list_int_const",
+  "expr_int_const", "expr_const", "fields", "field", "ne_union_field",
+  "ne_union_fields", "union_field", "s_field", "funcdef", "declaration",
+  "m_ident", "t_ident", "ident", "base_type", "m_int", "int_std",
+  "coclass", "coclasshdr", "coclassdef", "coclass_ints", "coclass_int",
+  "dispinterface", "dispinterfacehdr", "dispint_props", "dispint_meths",
+  "dispinterfacedef", "inherit", "interface", "interfacehdr",
+  "interfacedef", "interfacedec", "module", "modulehdr", "moduledef",
+  "storage_cls_spec", "function_specifier", "type_qualifier",
   "m_type_qual_list", "decl_spec", "m_decl_spec_no_type",
   "decl_spec_no_type", "declarator", "direct_declarator",
   "declarator_list", "init_declarator", "pointer_type", "structdef",
@@ -1060,7 +979,7 @@
 # ifdef YYPRINT
 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
    token YYLEX-NUM.  */
-static const unsigned short int yytoknum[] =
+static const yytype_uint16 yytoknum[] =
 {
        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
@@ -1076,52 +995,52 @@
      365,   366,   367,   368,   369,   370,   371,   372,   373,   374,
      375,   376,   377,   378,   379,   380,   381,   382,   383,   384,
      385,   386,   387,   388,   389,   390,   391,   392,   393,   394,
-     395,   396,   397,   398,   399,   400,   401,    44,    63,    58,
-     124,    94,    38,    60,    62,    45,    43,    42,    47,    37,
-      33,   126,   402,   403,   404,   405,   406,    46,    91,    93,
-      59,    40,    41,   123,   125,    61
+     395,   396,   397,   398,   399,   400,    44,    63,    58,   124,
+      94,    38,    60,    62,    45,    43,    42,    47,    37,    33,
+     126,   401,   402,   403,   404,   405,    46,    91,    93,    59,
+      40,    41,   123,   125,    61
 };
 # endif
 
 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
-static const unsigned short int yyr1[] =
+static const yytype_uint16 yyr1[] =
 {
-       0,   176,   177,   178,   178,   178,   178,   178,   178,   178,
-     178,   179,   179,   179,   179,   179,   179,   179,   179,   179,
-     180,   180,   181,   181,   182,   182,   182,   182,   182,   183,
-     183,   183,   183,   183,   183,   184,   185,   186,   187,   188,
-     189,   190,   191,   191,   192,   193,   193,   193,   194,   194,
-     195,   195,   196,   196,   197,   198,   198,   198,   199,   199,
-     200,   200,   200,   200,   200,   200,   200,   200,   200,   200,
-     200,   200,   200,   200,   200,   200,   200,   200,   200,   200,
-     200,   200,   200,   200,   200,   200,   200,   200,   200,   200,
-     200,   200,   200,   200,   200,   200,   200,   200,   200,   200,
-     200,   200,   200,   200,   200,   200,   200,   200,   200,   200,
-     200,   200,   200,   200,   200,   200,   200,   200,   200,   200,
-     200,   200,   200,   200,   200,   200,   200,   200,   200,   200,
-     200,   201,   201,   202,   202,   202,   202,   203,   203,   204,
-     204,   205,   205,   205,   206,   206,   207,   207,   208,   209,
-     209,   210,   210,   211,   211,   211,   211,   211,   211,   211,
-     211,   211,   211,   211,   211,   211,   211,   211,   211,   211,
-     211,   211,   211,   211,   211,   211,   211,   211,   211,   211,
-     211,   211,   211,   211,   211,   211,   211,   211,   211,   211,
-     211,   211,   211,   212,   212,   213,   214,   215,   215,   216,
-     216,   217,   217,   218,   218,   219,   219,   220,   221,   222,
-     222,   223,   223,   224,   224,   224,   225,   225,   226,   226,
-     226,   226,   226,   226,   226,   226,   226,   226,   226,   226,
-     227,   227,   228,   228,   228,   228,   228,   228,   228,   229,
-     229,   230,   231,   232,   232,   233,   234,   234,   235,   236,
-     236,   237,   237,   238,   238,   239,   239,   240,   240,   241,
-     242,   242,   242,   243,   243,   244,   244,   245,   246,   247,
-     247,   247,   248,   249,   250,   250,   251,   251,   252,   252,
-     253,   253,   253,   254,   254,   254,   255,   255,   255,   255,
-     256,   256,   257,   257,   258,   258,   258,   259,   260,   260,
-     260,   260,   260,   260,   260,   260,   260,   260,   261,   262,
-     262,   263,   263
+       0,   175,   176,   177,   177,   177,   177,   177,   177,   177,
+     177,   178,   178,   178,   178,   178,   178,   178,   178,   178,
+     179,   179,   180,   180,   181,   181,   181,   181,   181,   182,
+     182,   182,   182,   182,   182,   183,   184,   185,   186,   187,
+     188,   189,   190,   190,   191,   192,   192,   192,   193,   193,
+     194,   194,   195,   195,   196,   197,   197,   197,   198,   198,
+     199,   199,   199,   199,   199,   199,   199,   199,   199,   199,
+     199,   199,   199,   199,   199,   199,   199,   199,   199,   199,
+     199,   199,   199,   199,   199,   199,   199,   199,   199,   199,
+     199,   199,   199,   199,   199,   199,   199,   199,   199,   199,
+     199,   199,   199,   199,   199,   199,   199,   199,   199,   199,
+     199,   199,   199,   199,   199,   199,   199,   199,   199,   199,
+     199,   199,   199,   199,   199,   199,   199,   199,   199,   199,
+     199,   200,   200,   201,   201,   201,   201,   202,   202,   203,
+     203,   204,   204,   204,   205,   205,   206,   206,   207,   208,
+     208,   209,   209,   210,   210,   210,   210,   210,   210,   210,
+     210,   210,   210,   210,   210,   210,   210,   210,   210,   210,
+     210,   210,   210,   210,   210,   210,   210,   210,   210,   210,
+     210,   210,   210,   210,   210,   210,   210,   210,   210,   210,
+     210,   210,   210,   211,   211,   212,   213,   214,   214,   215,
+     215,   216,   216,   217,   217,   218,   218,   219,   220,   221,
+     221,   222,   222,   223,   223,   223,   224,   224,   225,   225,
+     225,   225,   225,   225,   225,   225,   225,   225,   225,   226,
+     226,   227,   227,   227,   227,   227,   227,   227,   228,   228,
+     229,   230,   231,   231,   232,   233,   233,   234,   235,   235,
+     236,   236,   237,   237,   238,   238,   239,   239,   240,   241,
+     241,   241,   242,   242,   243,   243,   244,   245,   246,   246,
+     246,   247,   248,   249,   249,   250,   250,   251,   251,   252,
+     252,   252,   253,   253,   253,   254,   254,   254,   254,   255,
+     255,   256,   256,   257,   257,   257,   258,   259,   259,   259,
+     259,   259,   259,   259,   259,   259,   259,   260,   261,   261,
+     262,   262
 };
 
 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
-static const unsigned char yyr2[] =
+static const yytype_uint8 yyr2[] =
 {
        0,     2,     1,     0,     2,     2,     3,     2,     2,     2,
        2,     0,     2,     2,     3,     2,     2,     2,     2,     2,
@@ -1145,168 +1064,168 @@
        4,     4,     3,     1,     3,     1,     1,     0,     2,     4,
        3,     2,     2,     0,     2,     2,     1,     3,     3,     3,
        2,     0,     1,     0,     1,     1,     1,     1,     1,     1,
-       1,     2,     2,     1,     1,     1,     1,     1,     1,     1,
-       0,     1,     1,     2,     1,     2,     2,     1,     1,     2,
-       2,     2,     5,     0,     2,     2,     2,     2,     2,     2,
-       3,     2,     3,     5,     5,     0,     2,     2,     2,     2,
-       6,     8,     2,     2,     2,     2,     2,     2,     5,     1,
-       1,     1,     1,     1,     0,     2,     2,     3,     0,     1,
-       2,     2,     2,     3,     2,     1,     1,     3,     2,     4,
-       1,     3,     1,     3,     1,     1,     1,     5,     1,     1,
-       1,     1,     2,     1,     2,     1,     2,     4,     4,     5,
-      10,     1,     3
+       1,     2,     2,     1,     1,     1,     1,     1,     1,     0,
+       1,     1,     2,     1,     2,     2,     1,     1,     2,     2,
+       2,     5,     0,     2,     2,     2,     2,     2,     2,     3,
+       2,     3,     5,     5,     0,     2,     2,     2,     2,     6,
+       8,     2,     2,     2,     2,     2,     2,     5,     1,     1,
+       1,     1,     1,     0,     2,     2,     3,     0,     1,     2,
+       2,     2,     3,     2,     1,     1,     3,     2,     4,     1,
+       3,     1,     3,     1,     1,     1,     5,     1,     1,     1,
+       1,     2,     1,     2,     1,     2,     4,     4,     5,    10,
+       1,     3
 };
 
 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
    means the default is an error.  */
-static const unsigned short int yydefact[] =
+static const yytype_uint16 yydefact[] =
 {
-       3,     0,     2,     1,   299,   227,   218,   238,     0,   273,
-       0,     0,   226,   213,   228,   269,   224,   229,   230,     0,
-     272,   232,   237,     0,   230,   271,     0,   230,     0,   225,
-     234,   270,   213,    52,   213,   223,   298,   219,    60,    10,
-       0,    24,    11,    27,    11,     9,     0,   301,     0,   300,
-     220,     0,     0,     7,     0,     0,    22,     0,   255,     5,
-       4,     0,     8,   278,   278,   278,     0,     0,   303,   278,
-       0,   305,   239,   240,     0,   246,   247,   302,   215,     0,
-     231,   236,     0,   257,   258,   235,     0,   233,   221,   304,
-       0,     0,    53,   306,     0,   222,    61,    62,    63,    64,
-      65,    66,     0,     0,    69,    70,    71,    72,    73,    74,
-       0,    76,    77,     0,    79,     0,     0,    82,    83,     0,
-       0,     0,     0,     0,    89,     0,    91,     0,    93,     0,
-      95,    96,     0,     0,    99,   100,   101,   102,   103,   104,
-     105,   106,   107,     0,   109,   110,   111,   296,   112,     0,
-     114,   294,   115,   116,   117,     0,   119,   120,   121,     0,
-       0,     0,   295,     0,   126,   127,     0,     0,     0,    55,
-     130,    25,     0,     0,     0,     0,     0,   301,   241,   248,
-     259,   267,     0,   303,   305,    26,     6,   243,   264,     0,
-      23,   262,   263,     0,     0,    20,   282,   279,   281,   280,
-     216,   217,   133,   134,   135,   136,   274,     0,     0,   286,
-     292,   285,   210,   301,   303,   278,   305,   276,    28,     0,
-     141,    36,     0,   197,     0,     0,   203,     0,     0,     0,
+       3,     0,     2,     1,   298,   226,   218,   237,     0,   272,
+       0,     0,   225,   213,   227,   268,   224,   228,   229,     0,
+     271,   231,   236,     0,   229,   270,     0,   229,     0,   233,
+     269,   213,    52,   213,   223,   297,   219,    60,    10,     0,
+      24,    11,    27,    11,     9,     0,   300,     0,   299,   220,
+       0,     0,     7,     0,     0,    22,     0,   254,     5,     4,
+       0,     8,   277,   277,   277,     0,     0,   302,   277,     0,
+     304,   238,   239,     0,   245,   246,   301,   215,     0,   230,
+     235,     0,   256,   257,   234,     0,   232,   221,   303,     0,
+       0,    53,   305,     0,   222,    61,    62,    63,    64,    65,
+      66,     0,     0,    69,    70,    71,    72,    73,    74,     0,
+      76,    77,     0,    79,     0,     0,    82,    83,     0,     0,
+       0,     0,     0,    89,     0,    91,     0,    93,     0,    95,
+      96,     0,     0,    99,   100,   101,   102,   103,   104,   105,
+     106,   107,     0,   109,   110,   111,   295,   112,     0,   114,
+     293,   115,   116,   117,     0,   119,   120,   121,     0,     0,
+       0,   294,     0,   126,   127,     0,     0,     0,    55,   130,
+      25,     0,     0,     0,     0,     0,   300,   240,   247,   258,
+     266,     0,   302,   304,    26,     6,   242,   263,     0,    23,
+     261,   262,     0,     0,    20,   281,   278,   280,   279,   216,
+     217,   133,   134,   135,   136,   273,     0,     0,   285,   291,
+     284,   210,   300,   302,   277,   304,   275,    28,     0,   141,
+      36,     0,   197,     0,     0,   203,     0,     0,     0,     0,
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,   151,     0,     0,   151,     0,     0,     0,     0,
-       0,     0,    60,    54,    37,     0,    17,    18,    19,     0,
-      15,    13,    12,    16,    22,    39,   265,   266,    40,   209,
-      52,     0,    52,     0,     0,   256,    20,     0,     0,     0,
-     284,     0,   151,    42,   288,   277,    35,     0,   143,   144,
-     147,   307,    52,   290,   308,    52,    52,     0,   161,   153,
-     154,   155,   159,   160,   156,   157,     0,   158,     0,     0,
-       0,     0,     0,     0,     0,   195,     0,   193,   196,     0,
-       0,    58,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,   149,   152,     0,     0,     0,     0,
-       0,     0,   132,   131,     0,   311,     0,     0,    56,    60,
-       0,    14,    41,    22,     0,   244,   249,     0,     0,     0,
-      52,     0,     0,     0,    22,    21,     0,   275,   283,   287,
-     293,     0,     0,   298,     0,    47,    43,    45,     0,     0,
-     148,   142,     0,   297,     0,   198,     0,     0,   309,    53,
-     204,     0,    67,     0,   185,   184,   183,   186,   181,   182,
+       0,   151,     0,     0,   151,     0,     0,     0,     0,     0,
+       0,    60,    54,    37,     0,    17,    18,    19,     0,    15,
+      13,    12,    16,    22,    39,   264,   265,    40,   209,    52,
+       0,    52,     0,     0,   255,    20,     0,     0,     0,   283,
+       0,   151,    42,   287,   276,    35,     0,   143,   144,   147,
+     306,    52,   289,   307,    52,    52,     0,   161,   153,   154,
+     155,   159,   160,   156,   157,     0,   158,     0,     0,     0,
+       0,     0,     0,     0,   195,     0,   193,   196,     0,     0,
+      58,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,   149,   152,     0,     0,     0,     0,     0,
+       0,   132,   131,     0,   310,     0,     0,    56,    60,     0,
+      14,    41,    22,     0,   243,   248,     0,     0,     0,    52,
+       0,     0,     0,    22,    21,     0,   274,   282,   286,   292,
+       0,     0,   297,     0,    47,    43,    45,     0,     0,   148,
+     142,     0,   296,     0,   198,     0,     0,   308,    53,   204,
+       0,    67,     0,   185,   184,   183,   186,   181,   182,     0,
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,    68,    75,    78,     0,    80,
-      81,    84,    85,    86,    87,    88,    90,    92,     0,    98,
-     151,    97,   108,     0,   118,   122,   123,   124,   125,     0,
-     128,   129,    57,     0,   242,   245,   251,     0,   250,   253,
-       0,     0,   254,    20,    22,   268,    51,    50,   289,     0,
-       0,    49,   145,   146,     0,   305,   291,   211,   202,   201,
-       0,   192,     0,   174,   175,   187,   168,   169,   172,   173,
-     163,   164,     0,   165,   166,   167,   171,   170,   177,   176,
-     179,   180,   178,   188,     0,   194,    59,    94,   150,     0,
-     312,    22,   207,     0,   252,     0,   260,    46,    48,     0,
-     200,     0,   212,   190,   189,     0,   191,   113,    38,   208,
-      22,   199,   137,   162,   261,     0,     0,     0,   310,   138,
-       0,    52,    52,   206,   140,     0,   139,   205
+       0,     0,     0,     0,    68,    75,    78,     0,    80,    81,
+      84,    85,    86,    87,    88,    90,    92,     0,    98,   151,
+      97,   108,     0,   118,   122,   123,   124,   125,     0,   128,
+     129,    57,     0,   241,   244,   250,     0,   249,   252,     0,
+       0,   253,    20,    22,   267,    51,    50,   288,     0,     0,
+      49,   145,   146,     0,   304,   290,   211,   202,   201,     0,
+     192,     0,   174,   175,   187,   168,   169,   172,   173,   163,
+     164,     0,   165,   166,   167,   171,   170,   177,   176,   179,
+     180,   178,   188,     0,   194,    59,    94,   150,     0,   311,
+      22,   207,     0,   251,     0,   259,    46,    48,     0,   200,
+       0,   212,   190,   189,     0,   191,   113,    38,   208,    22,
+     199,   137,   162,   260,     0,     0,     0,   309,   138,     0,
+      52,    52,   206,   140,     0,   139,   205
 };
 
-/* YYDEFGOTO[NTERM-NUM]. */
-static const short int yydefgoto[] =
+/* YYDEFGOTO[NTERM-NUM].  */
+static const yytype_int16 yydefgoto[] =
 {
-      -1,     1,     2,   172,   277,   191,   365,    40,    41,    42,
-      43,   257,   176,    44,   258,   374,   375,   376,   377,   284,
-     358,    92,   168,   322,   169,   344,   208,   535,   539,   287,
-     288,   289,   213,   333,   334,   315,   316,   317,   319,   292,
-     385,   390,   296,   544,   545,   461,    48,   521,    79,   209,
-      49,    81,    50,   259,    52,   260,   270,   355,    54,    55,
-     272,   360,    56,   194,    57,    58,   261,   262,   181,    61,
-     263,    63,    64,    65,   278,    66,   196,    67,   210,   211,
-     294,   212,   170,   214,    69,    70,   216,   346
+      -1,     1,     2,   171,   276,   190,   364,    39,    40,    41,
+      42,   256,   175,    43,   257,   373,   374,   375,   376,   283,
+     357,    91,   167,   321,   168,   343,   207,   534,   538,   286,
+     287,   288,   212,   332,   333,   314,   315,   316,   318,   291,
+     384,   389,   295,   543,   544,   460,    47,   520,    78,   208,
+      48,    80,    49,   258,    51,   259,   269,   354,    53,    54,
+     271,   359,    55,   193,    56,    57,   260,   261,   180,    60,
+     262,    62,    63,    64,   277,    65,   195,    66,   209,   210,
+     293,   211,   169,   213,    68,    69,   215,   345
 };
 
 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
-#define YYPACT_NINF -265
-static const short int yypact[] =
+#define YYPACT_NINF -269
+static const yytype_int16 yypact[] =
 {
-    -265,    38,  1016,  -265,  -265,  -265,  -265,  -265,   133,  -265,
-    -118,   135,  -265,   138,  -265,  -265,  -265,  -265,   -26,    63,
-    -265,  -265,  -265,   140,   -26,  -265,   -44,   -26,    -3,  -265,
-    -265,  -265,   142,   -57,   144,    -3,  -265,  -265,  1888,  -265,
-      -8,  -265,  -265,  -265,  -265,  -265,  1650,    21,    23,  -265,
-    -265,    26,   -23,  -265,    28,   -14,    30,    31,    55,  -265,
-    -265,    32,  -265,    -4,    -4,    -4,   114,  1763,    33,    -4,
-      42,    43,  -265,  -265,   212,  -265,  -265,    49,  -265,    51,
-    -265,  -265,    57,  -265,  -265,  -265,  1763,  -265,  -265,    49,
-      58,  1693,  -265,   -94,   -89,  -265,  -265,  -265,  -265,  -265,
-    -265,  -265,    66,    67,  -265,  -265,  -265,  -265,  -265,  -265,
-      68,  -265,  -265,    72,  -265,    75,    86,  -265,  -265,    87,
-      89,    90,    92,    93,  -265,    94,  -265,    96,  -265,    99,
-    -265,  -265,   103,   109,  -265,  -265,  -265,  -265,  -265,  -265,
-    -265,  -265,  -265,   111,  -265,  -265,  -265,  -265,  -265,   113,
-    -265,  -265,  -265,  -265,  -265,   115,  -265,  -265,  -265,   116,
-     117,   118,  -265,   119,  -265,  -265,   120,   121,   -72,  -265,
-    -265,  -265,   921,   405,   225,   149,    76,   123,  -265,  -265,
-    -265,  -265,   114,   132,   134,  -265,  -265,  -265,  -265,    19,
-    -265,  -265,  -265,   151,   130,  -265,  -265,  -265,  -265,  -265,
-    -265,  -265,  -265,  -265,  -265,  -265,  -265,   114,   114,  -265,
-      73,   -85,  -265,  -265,  -265,    -4,  -265,  -265,  -265,   141,
-     154,  -265,   146,  -265,   114,   136,  -265,   154,    95,    95,
-     297,   298,    95,    95,   308,   311,    95,   314,    95,    95,
-     258,    95,    95,   -62,    95,    95,    95,  1763,  1763,   122,
-     319,  1763,  1888,   158,  -265,   156,  -265,  -265,  -265,   159,
-    -265,  -265,  -265,  -265,    30,  -265,  -265,  -265,  -265,  -265,
-     -48,   179,   -60,   161,   160,  -265,  -265,   500,    37,   162,
-    -265,    95,   446,  1091,  -265,  -265,  -265,   170,   188,  -265,
-     171,  -265,   -45,  -265,   189,   -57,   -43,   173,  -265,  -265,
-    -265,  -265,  -265,  -265,  -265,  -265,   176,  -265,    95,    95,
-      95,    95,    95,    95,   785,  1386,   -82,  -265,  1386,   177,
-     180,  -265,   -80,   182,   184,   185,   187,   190,   192,   195,
-    1225,   345,   198,   -79,  -265,  1386,   199,   208,   -77,  1268,
-     201,   202,  -265,  -265,   203,   193,   204,   205,  -265,  1888,
-     370,  -265,  -265,    30,   -12,  -265,  -265,   230,  1693,   210,
-     -40,   207,   304,   595,    30,  -265,  1693,  -265,  -265,  -265,
-    -265,    54,   214,   -53,   213,  -265,   239,  -265,  1693,   114,
-    -265,   154,    95,  -265,  1693,  -265,   114,   215,  -265,   218,
-    -265,   221,  -265,  1763,     1,     1,     1,     1,     1,     1,
-    1291,   240,    95,    95,   408,    95,    95,    95,    95,    95,
-      95,    95,    95,    95,    95,    95,    95,    95,    95,    95,
-      95,    95,   410,    95,    95,  -265,  -265,  -265,   406,  -265,
-    -265,  -265,  -265,  -265,  -265,  -265,  -265,  -265,   243,  -265,
-      95,  -265,  -265,    95,  -265,  -265,  -265,  -265,  -265,   411,
-    -265,  -265,  -265,   245,  -265,  -265,  -265,   114,  -265,  -265,
-    1693,   248,  -265,  -265,    30,  -265,  -265,  -265,  -265,  1134,
-     114,  -265,  -265,  -265,   114,   250,  -265,   154,  -265,  -265,
-     249,  -265,    95,   183,   183,  -265,   534,   534,   153,   153,
-    1493,  1416,  1336,  1439,  1462,  1509,   153,   153,    77,    77,
-       1,     1,     1,  -265,  1314,  -265,  -265,  -265,  -265,   251,
-    -265,    30,  -265,   114,  -265,   690,  -265,  -265,  -265,   -81,
-    -265,   252,  -265,  -265,     1,    95,  -265,  -265,  -265,  -265,
-      30,  -265,  -265,  1386,  -265,   -11,    95,   273,  -265,  -265,
-     275,   -83,   -83,  -265,  -265,   256,  -265,  -265
+    -269,    42,  1015,  -269,  -269,  -269,  -269,  -269,    82,  -269,
+    -118,   125,  -269,   127,  -269,  -269,  -269,  -269,   -14,    88,
+    -269,  -269,  -269,   129,   -14,  -269,   -70,   -14,   253,  -269,
+    -269,   131,   -64,   134,   253,  -269,  -269,  1851,  -269,   -22,
+    -269,  -269,  -269,  -269,  -269,  1607,   -21,   -20,  -269,  -269,
+     -19,   -58,  -269,   -17,   -18,   -10,    -8,     5,  -269,  -269,
+      -4,  -269,    -5,    -5,    -5,   255,  1727,    -7,    -5,    28,
+      30,  -269,  -269,   147,  -269,  -269,    20,  -269,    26,  -269,
+    -269,    43,  -269,  -269,  -269,  1727,  -269,  -269,    20,    31,
+    1684,  -269,   -96,   -94,  -269,  -269,  -269,  -269,  -269,  -269,
+    -269,    41,    46,  -269,  -269,  -269,  -269,  -269,  -269,    50,
+    -269,  -269,    53,  -269,    56,    59,  -269,  -269,    63,    64,
+      65,    67,    73,  -269,    76,  -269,    77,  -269,    84,  -269,
+    -269,    95,    96,  -269,  -269,  -269,  -269,  -269,  -269,  -269,
+    -269,  -269,    99,  -269,  -269,  -269,  -269,  -269,   100,  -269,
+    -269,  -269,  -269,  -269,   103,  -269,  -269,  -269,   111,   113,
+     114,  -269,   115,  -269,  -269,   116,   117,   -93,  -269,  -269,
+    -269,   921,   404,   161,   136,    58,   119,  -269,  -269,  -269,
+    -269,   255,   122,   123,  -269,  -269,  -269,  -269,    -6,  -269,
+    -269,  -269,   139,    91,  -269,  -269,  -269,  -269,  -269,  -269,
+    -269,  -269,  -269,  -269,  -269,  -269,   255,   255,  -269,   128,
+    -129,  -269,  -269,  -269,    -5,  -269,  -269,  -269,   -15,   141,
+    -269,   130,  -269,   255,   133,  -269,   141,    85,    85,   296,
+     297,    85,    85,   298,   304,    85,   307,    85,    85,   251,
+      85,    85,   -55,    85,    85,    85,  1727,  1727,   102,   317,
+    1727,  1851,   156,  -269,   154,  -269,  -269,  -269,   157,  -269,
+    -269,  -269,  -269,   -10,  -269,  -269,  -269,  -269,  -269,   -66,
+     179,   -69,   159,   158,  -269,  -269,   498,   101,   160,  -269,
+      85,   867,  1109,  -269,  -269,  -269,   163,   183,  -269,   166,
+    -269,   -56,  -269,   188,   -64,   -54,   170,  -269,  -269,  -269,
+    -269,  -269,  -269,  -269,  -269,   172,  -269,    85,    85,    85,
+      85,    85,    85,   780,  1402,  -106,  -269,  1402,   174,   175,
+    -269,  -102,   176,   177,   178,   180,   181,   182,   184,  1189,
+     340,   185,   -90,  -269,  1402,   190,   204,   -82,  1242,   192,
+     195,  -269,  -269,   198,   193,   199,   202,  -269,  1851,   366,
+    -269,  -269,   -10,   -12,  -269,  -269,   227,  1684,   208,   -51,
+     205,   301,   592,   -10,  -269,  1684,  -269,  -269,  -269,  -269,
+      54,   212,   -74,   211,  -269,   238,  -269,  1684,   255,  -269,
+     141,    85,  -269,  1684,  -269,   255,   214,  -269,   217,  -269,
+     218,  -269,  1727,    34,    34,    34,    34,    34,    34,  1292,
+     219,    85,    85,   407,    85,    85,    85,    85,    85,    85,
+      85,    85,    85,    85,    85,    85,    85,    85,    85,    85,
+      85,   409,    85,    85,  -269,  -269,  -269,   405,  -269,  -269,
+    -269,  -269,  -269,  -269,  -269,  -269,  -269,   243,  -269,    85,
+    -269,  -269,    85,  -269,  -269,  -269,  -269,  -269,   411,  -269,
+    -269,  -269,   246,  -269,  -269,  -269,   255,  -269,  -269,  1684,
+     249,  -269,  -269,   -10,  -269,  -269,  -269,  -269,  1159,   255,
+    -269,  -269,  -269,   255,   250,  -269,   141,  -269,  -269,   252,
+    -269,    85,    94,    94,  -269,  1114,  1114,   153,   153,  1368,
+    1439,  1349,  1420,  1462,  1496,   153,   153,    29,    29,    34,
+      34,    34,  -269,  1315,  -269,  -269,  -269,  -269,   256,  -269,
+     -10,  -269,   255,  -269,   686,  -269,  -269,  -269,   -67,  -269,
+     248,  -269,  -269,    34,    85,  -269,  -269,  -269,  -269,   -10,
+    -269,  -269,  1402,  -269,   -16,    85,   273,  -269,  -269,   274,
+     -43,   -43,  -269,  -269,   259,  -269,  -269
 };
 
 /* YYPGOTO[NTERM-NUM].  */
-static const short int yypgoto[] =
+static const yytype_int16 yypgoto[] =
 {
-    -265,  -265,  -265,   385,  -264,  -257,    11,  -265,  -265,  -265,
-      69,  -265,  -265,  -265,   428,  -265,  -265,  -265,   -37,  -265,
-     -30,    -2,  -265,  -265,  -235,  -265,  -265,  -265,  -265,  -265,
-    -265,    53,     2,   191,  -255,   -13,  -265,  -222,  -208,  -265,
-    -265,  -265,  -265,  -105,  -241,  -265,  -265,  -265,   101,  -199,
-    -265,    85,    78,    18,  -265,   436,  -265,  -265,   393,  -265,
-    -265,  -265,  -265,  -265,   -28,  -265,   438,    -1,  -265,  -265,
-     441,  -265,  -265,   166,  -265,   -41,   -35,   -20,  -198,  -265,
-     -27,   264,   216,     6,   -61,  -265,     0,  -265
+    -269,  -269,  -269,   386,  -268,  -257,     8,  -269,  -269,  -269,
+      69,  -269,  -269,  -269,   429,  -269,  -269,  -269,   -35,  -269,
+     -27,    -2,  -269,  -269,  -230,  -269,  -269,  -269,  -269,  -269,
+    -269,    55,     2,   194,  -264,   -13,  -269,  -221,  -207,  -269,
+    -269,  -269,  -269,  -105,  -245,  -269,  -269,  -269,    92,  -199,
+    -269,    60,    93,    23,  -269,   435,  -269,  -269,   394,  -269,
+    -269,  -269,  -269,  -269,   -30,  -269,   440,     1,  -269,  -269,
+     441,  -269,  -269,   168,  -269,   -44,     3,   -31,  -194,  -269,
+     -26,   265,   206,     6,   -57,  -269,     0,  -269
 };
 
 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
@@ -1314,481 +1233,473 @@
    number is the opposite.  If zero, do what YYDEFACT says.
    If YYTABLE_NINF, syntax error.  */
 #define YYTABLE_NINF -215
-static const short int yytable[] =
+static const yytype_int16 yytable[] =
 {
-      46,    60,    71,    91,    47,   182,   215,   352,    68,   279,
-     280,   324,   363,    39,   327,   404,   329,   348,   180,   332,
-      51,   290,   337,   536,   323,   222,   293,   372,   297,   198,
-     199,   359,   357,     7,   217,   537,     9,  -214,     3,    11,
-     200,   201,   225,   197,   197,   197,   184,   147,   177,   197,
-     224,   151,   183,    74,   387,   391,    15,   298,    80,   299,
-     300,   301,   302,   303,   178,   424,   386,   428,   440,    18,
-     440,    82,   202,   370,    23,   252,   162,     9,    20,  -214,
-     368,    21,    22,   282,   226,    38,   283,   543,    24,   531,
-     425,   404,   429,   441,   -44,   444,   454,   253,   298,   203,
-     299,   300,   301,   302,   303,    23,    88,   465,    38,    85,
-      25,    38,    87,    95,   452,   304,    27,   200,   201,   -44,
-      38,    30,    31,    38,   271,    38,   353,    86,    38,   383,
-     342,   388,   343,    90,   459,    94,    72,    73,    75,    76,
-     204,    77,    78,    83,    84,    89,    78,    93,    78,   202,
-     187,   305,   266,   267,   274,   275,   304,   200,   201,   189,
-     473,   273,   171,   538,   205,   402,   403,   404,   422,   423,
-      46,    46,    71,    71,    47,    47,   203,   306,    68,    68,
-     285,   471,   290,   256,   256,   508,   340,   341,   476,   307,
-     347,   -29,   305,   185,   206,   197,   186,   404,   188,   515,
-     190,   192,   505,   -30,   193,   195,   308,   516,   207,   309,
-     310,   311,   218,   -31,   312,   313,   318,   204,   306,   318,
-     219,   509,  -214,   466,   220,   314,   330,   221,   265,   335,
-     307,   223,   335,   339,   419,   420,   421,   227,   228,   229,
-     354,   205,   379,   230,   422,   423,   231,   308,   281,   268,
-     309,   310,   311,   401,   528,   312,   313,   232,   233,   512,
-     234,   235,   384,   236,   237,   238,   314,   239,   318,   335,
-     240,   206,   518,   534,   241,   366,   293,    71,   522,    47,
-     242,   378,   243,    68,   244,   207,   245,   246,   247,   248,
-     249,   250,   251,   -32,   389,   394,   395,   396,   397,   398,
-     399,   400,   -33,   276,   -34,   320,   321,   295,   417,   418,
-     419,   420,   421,   286,   540,   529,   325,   457,   291,   326,
-     422,   423,   328,   331,   345,   182,   349,   350,   356,   351,
-     460,   361,   480,   362,   369,   381,   386,   470,   417,   418,
-     419,   420,   421,   474,   380,   392,   382,   393,   438,   426,
-     422,   423,   427,   455,   430,   443,   431,   432,   397,   433,
-     449,   366,   434,    71,   435,    47,   184,   436,   177,    68,
-     439,   442,   183,   446,   447,   448,   450,   451,   453,   456,
-     458,   462,    19,   467,   475,   468,   469,   477,   478,   483,
-     484,   479,   486,   487,   488,   489,   490,   491,   492,   493,
-     494,   495,   496,   497,   498,   499,   500,   501,   502,     4,
-     504,   485,   482,   503,   506,   507,   510,   511,   514,   513,
-     520,   523,   541,   527,   542,   532,   547,   335,   379,   173,
-      45,   463,   517,     5,   472,     6,   338,   546,    53,   179,
-      59,     7,     8,    62,   367,     9,   269,   519,     0,   298,
-      10,   299,   300,   301,   302,   303,    11,     0,    12,   336,
-       0,     0,    13,    14,     0,    15,     0,   378,    16,   524,
-      17,     0,     0,     0,     0,     0,     0,    18,     0,     0,
-       0,     0,     0,    19,   255,     0,     0,    20,     0,    21,
-      22,    23,     0,     0,     0,     0,    24,     0,     0,     0,
-       0,     0,     0,     0,     4,     0,     0,   304,     0,     0,
-       0,     0,   533,   366,     0,    71,     0,    47,     0,    25,
-       0,    68,     0,    26,    27,    28,    29,     0,     5,    30,
-       6,    31,     0,     0,     0,    32,     7,     0,     0,     0,
-       9,    33,    34,   305,    35,    10,   402,   403,   404,    36,
-      37,   407,   408,    12,     0,     0,     0,    13,    14,     0,
-      15,     0,     0,    16,     0,    17,     0,     0,     0,   306,
-       0,     0,    18,    38,     0,     0,     0,     0,    19,   264,
-       0,   307,    20,     0,    21,    22,     0,     0,     0,     0,
-       0,    24,     0,     0,     0,     0,     0,     0,   308,     4,
-       0,   309,   310,   371,     0,     0,   312,   313,     0,     0,
-       0,     0,     0,     0,    25,     0,     0,   314,    26,    27,
-      28,    29,     0,     5,    30,     6,    31,     0,     0,     0,
-      32,     7,     0,     0,     0,     9,    33,    34,     0,    35,
-      10,     0,     0,     0,    36,    37,     0,     0,    12,     0,
-       0,     0,    13,    14,     0,    15,     0,     0,    16,     0,
-      17,     0,     0,     0,     0,     0,     0,    18,    38,     0,
-       0,     0,     0,    19,   364,     0,     0,    20,     0,    21,
-      22,     0,     0,     0,     0,     0,    24,   415,   416,   417,
-     418,   419,   420,   421,     4,     0,     0,     0,     0,     0,
-       0,   422,   423,     0,     0,     0,     0,     0,     0,    25,
-       0,     0,     0,    26,    27,    28,    29,     0,     5,    30,
-       6,    31,     0,     0,     0,    32,     7,     0,     0,     0,
-       9,    33,    34,     0,    35,    10,     0,     0,     0,    36,
-      37,     0,     0,    12,     0,     0,     0,    13,    14,     0,
-      15,     0,     0,    16,     0,    17,     0,     0,     0,     0,
-       0,     0,    18,    38,     0,     0,     0,     0,    19,   464,
-       0,     0,    20,     0,    21,    22,     0,     0,     0,     0,
-       0,    24,     0,     0,     0,     0,     0,     0,   298,     4,
-     299,   300,   301,   302,   303,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,    25,     0,     0,     0,    26,    27,
-      28,    29,     0,     5,    30,     6,    31,     0,     0,     0,
-      32,     7,     0,     0,     0,     0,    33,    34,     0,    35,
-       0,     0,     0,     0,    36,    37,     0,     0,    12,     0,
-       0,     0,    13,    14,     0,     0,   304,     0,    16,     0,
-      17,     0,     0,     0,     0,     0,     0,    18,    38,     0,
-       0,     0,     0,     0,   530,     0,     0,     0,     0,    21,
-      22,     0,     0,     0,     0,     0,    24,     0,     0,     0,
-       0,     0,   305,     0,     0,     0,     0,     0,     0,     0,
+      45,   181,    70,    59,    46,    90,   351,   362,    67,   214,
+      38,   323,   278,   279,   326,   179,   328,   371,   535,   331,
+     289,   347,   336,   356,   322,    50,   358,   296,   221,   292,
+     536,   196,   196,   196,  -214,     9,   224,   196,   281,    11,
+     423,   282,     3,   403,   427,   183,   223,   176,   403,   386,
+     390,   182,    73,   251,   146,    15,   439,   297,   150,   298,
+     299,   300,   301,   302,   439,   424,   197,   198,   177,   428,
+      79,   216,   -44,   369,    23,   252,  -214,    20,   225,   385,
+      23,   440,   161,   367,    84,    71,    72,    86,   297,   443,
+     298,   299,   300,   301,   302,   453,    81,   -44,    37,   270,
+      85,    37,   530,    37,   199,   200,   464,   352,   403,    25,
+     341,    37,   342,    37,   186,   303,    37,   382,   451,   387,
+      30,    87,   458,    89,    37,    93,   542,    94,    74,    75,
+      76,    77,    82,    83,    88,    77,   201,    92,    77,   265,
+     266,     9,   273,   274,   199,   200,   303,   170,   -29,   184,
+     185,   304,   187,   192,   188,   218,   285,   537,   272,   189,
+     472,   191,   -30,   202,   264,   401,   402,   403,   194,    45,
+      45,    70,    70,    46,    46,   507,   305,    67,    67,   255,
+     255,   289,   304,   196,   470,   418,   419,   420,   306,   339,
+     340,   475,  -214,   346,   514,   421,   422,   217,   219,   -31,
+     421,   422,   504,   222,   203,   307,   515,   305,   308,   309,
+     310,   226,   220,   311,   312,   317,   227,   284,   317,   306,
+     228,   508,   465,   229,   313,   329,   230,   204,   334,   231,
+     267,   334,   338,   232,   233,   234,   307,   235,   378,   308,
+     309,   310,   353,   236,   311,   312,   237,   238,   416,   417,
+     418,   419,   420,   527,   239,   313,   400,   205,   199,   200,
+     421,   422,   511,   275,   383,   240,   241,   317,   334,   242,
+     243,   206,   533,   244,   365,   517,    70,   521,    46,   292,
+     377,   245,    67,   246,   247,   248,   249,   250,   -32,     7,
+     201,   -33,   -34,   388,   393,   394,   395,   396,   397,   398,
+     399,   290,   280,   294,   319,   320,   324,   416,   417,   418,
+     419,   420,   325,   456,   539,   327,   330,   202,   528,   421,
+     422,   181,   344,   348,   349,    18,   350,   355,   360,   380,
+     361,   368,   459,   469,   385,   479,   379,    21,    22,   473,
+     381,   391,   392,   437,    24,   425,   426,   429,   430,   431,
+     442,   432,   433,   434,   454,   435,   438,   396,   203,   448,
+     365,   441,    70,   445,    46,   183,   446,   176,    67,   447,
+     449,   182,    27,   450,   452,   455,    29,   457,   461,    19,
+     466,   204,   467,   474,   468,   476,   477,   478,   482,   483,
+     481,   485,   486,   487,   488,   489,   490,   491,   492,   493,
+     494,   495,   496,   497,   498,   499,   500,   501,     4,   503,
+     484,   205,   502,   505,   506,   512,   509,   510,   513,   519,
+     531,   540,   541,   522,   378,   206,   334,   526,   546,   172,
+     462,    44,     5,   516,     6,   471,   545,    52,   337,   178,
+       7,     8,    58,    61,     9,   366,   268,   518,   335,    10,
+       0,     0,     0,     0,     0,    11,     0,    12,     0,     0,
+       0,    13,    14,     0,    15,     0,   377,    16,   523,    17,
+       0,     0,     0,     0,     0,     0,    18,     0,     0,     0,
+       0,     0,    19,   254,     0,     0,    20,     0,    21,    22,
+      23,     0,     0,     0,     0,    24,     0,     0,     0,     0,
+       0,     0,     4,     0,     0,     0,     0,     0,     0,     0,
+       0,   532,   365,     0,    70,     0,    46,     0,    25,     0,
+      67,     0,    26,    27,    28,     0,     5,    29,     6,    30,
+       0,     0,     0,    31,     7,     0,     0,     0,     9,    32,
+      33,     0,    34,    10,     0,     0,     0,    35,    36,     0,
+       0,    12,     0,     0,     0,    13,    14,     0,    15,     0,
+       0,    16,     0,    17,     0,     0,     0,     0,     0,     0,
+      18,    37,     0,     0,     0,     0,    19,   263,     0,     0,
+      20,     0,    21,    22,     0,     0,     0,     0,     0,    24,
+       0,     0,     0,     0,     0,     0,     4,     0,     0,     0,
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,    26,    27,    28,    29,     0,   306,    30,
-       0,     0,     0,     0,     0,    32,     0,     0,     0,     0,
-     307,     0,    34,     0,    35,     4,     0,     0,     0,    36,
-      37,     0,   254,     0,     0,     0,     0,   308,     0,     0,
-     309,   310,   311,     0,     0,   312,   313,     0,     0,     5,
-       0,     6,     0,     0,     0,     0,   314,     7,     8,     0,
-       0,     9,     0,     0,     0,     0,    10,     0,     0,     0,
-       0,     0,    11,     0,    12,     0,     0,     0,    13,    14,
-       0,    15,     0,     0,    16,     0,    17,     0,     0,     0,
-       0,     0,     0,    18,     0,     0,     0,     0,     0,    19,
-     255,     0,     0,    20,     0,    21,    22,    23,     0,     0,
-       0,     0,    24,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,    25,     0,     0,     0,    26,    27,    28,     0,
+       5,    29,     6,    30,     0,     0,     0,    31,     7,     0,
+       0,     0,     9,    32,    33,     0,    34,    10,     0,     0,
+       0,    35,    36,     0,     0,    12,     0,     0,     0,    13,
+      14,     0,    15,     0,     0,    16,     0,    17,     0,     0,
+       0,     0,     0,     0,    18,    37,     0,     0,     0,     0,
+      19,   363,     0,     0,    20,     0,    21,    22,     0,     0,
+       0,     0,     0,    24,     0,     0,     0,     0,     0,     0,
        4,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,    25,     0,     0,     0,    26,
-      27,    28,    29,     0,     5,    30,     6,    31,     0,     0,
-       0,    32,     7,     8,     0,     0,     9,    33,    34,     0,
-      35,    10,     0,     0,     0,    36,    37,    11,     0,    12,
+       0,     0,     0,     0,     0,     0,    25,     0,     0,     0,
+      26,    27,    28,     0,     5,    29,     6,    30,     0,     0,
+       0,    31,     7,     0,     0,     0,     9,    32,    33,     0,
+      34,    10,     0,     0,     0,    35,    36,     0,     0,    12,
        0,     0,     0,    13,    14,     0,    15,     0,     0,    16,
-       0,    17,     0,     0,     0,     0,     0,     0,    18,    38,
-       0,     0,     0,     0,    19,     4,     0,     0,    20,     0,
-      21,    22,    23,     0,     0,     0,     0,    24,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     5,
-       0,     6,     0,     0,     0,     0,     0,     7,     0,     0,
-      25,     9,     0,     0,    26,    27,    28,    29,     4,     0,
-      30,     0,    31,     0,    12,     0,    32,     0,    13,    14,
-       0,    15,    33,    34,    16,    35,    17,     0,     0,     0,
-      36,    37,     5,    18,     6,     0,     0,     0,     0,     0,
-       7,     0,     0,    20,     9,    21,    22,     0,     0,     0,
-       0,     0,    24,     0,    38,     0,     0,    12,     0,     0,
-       0,    13,    14,     0,    15,     0,     0,    16,     0,    17,
-       0,     0,     0,     0,     0,    25,    18,     0,     0,    26,
-      27,    28,    29,     0,     0,    30,    20,    31,    21,    22,
-       0,    32,     0,     0,     0,    24,     0,     0,    34,     0,
-      35,     0,     0,     0,     0,   373,    37,   402,   403,   404,
-     405,   406,   407,   408,   409,   410,     0,     0,    25,     0,
-       0,     0,    26,    27,    28,    29,     0,     0,    30,    38,
-      31,     0,     0,     0,    32,     0,     0,     0,     0,     0,
-       0,    34,     0,    35,     0,     0,     0,     0,    36,    37,
-     402,   403,   404,   405,   406,   407,   408,   409,   410,     0,
+       0,    17,     0,     0,     0,     0,     0,     0,    18,    37,
+       0,     0,     0,     0,    19,   463,     0,     0,    20,     0,
+      21,    22,     0,     0,     0,     0,     0,    24,     0,     0,
+       0,     0,     0,   297,     4,   298,   299,   300,   301,   302,
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,    38,   402,   403,   404,   405,   406,   407,   408,
-     409,   410,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,   402,   403,   404,   405,
-     406,   407,   408,   409,   410,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,   402,   403,
-     404,   405,   406,   407,   408,   409,   410,     0,     0,     0,
+      25,     0,     0,     0,    26,    27,    28,     0,     5,    29,
+       6,    30,     0,     0,     0,    31,     7,     0,     0,     0,
+       0,    32,    33,     0,    34,     0,     0,     0,     0,    35,
+      36,     0,     0,    12,     0,     0,     0,    13,    14,     0,
+       0,   303,     0,    16,     0,    17,     0,     0,     0,     0,
+       0,     0,    18,    37,     0,     0,     0,     0,     0,   529,
+       0,     0,     0,     0,    21,    22,     0,     0,     0,     0,
+     297,    24,   298,   299,   300,   301,   302,   304,     0,     0,
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,   411,     0,   412,   413,   414,   415,   416,
-     417,   418,   419,   420,   421,     0,     0,     0,     0,     0,
-       0,     0,   422,   423,     0,     0,     0,   437,   402,   403,
-     404,   405,   406,   407,   408,   409,   410,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,   411,     0,   412,   413,
-     414,   415,   416,   417,   418,   419,   420,   421,   402,   403,
-     404,   405,   406,   407,   408,   422,   423,     0,     0,   411,
-     445,   412,   413,   414,   415,   416,   417,   418,   419,   420,
-     421,   402,   403,   404,   405,   406,   407,   408,   422,   423,
-       0,     0,   411,   481,   412,   413,   414,   415,   416,   417,
-     418,   419,   420,   421,   402,   403,   404,   405,   406,   407,
-     408,   422,   423,   526,   411,   525,   412,   413,   414,   415,
-     416,   417,   418,   419,   420,   421,     0,     0,     0,     0,
-       0,     0,     0,   422,   423,   402,   403,   404,   405,   406,
-     407,   408,     0,   410,     0,     0,     0,     0,     0,     0,
-       0,   402,   403,   404,   405,   406,   407,   408,     0,     0,
-       0,     0,     0,     0,   411,     0,   412,   413,   414,   415,
-     416,   417,   418,   419,   420,   421,     0,     0,     0,     0,
-       0,     0,     0,   422,   423,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,   412,   413,   414,   415,
-     416,   417,   418,   419,   420,   421,     0,     0,     0,     0,
-       0,     0,     0,   422,   423,     0,     0,     0,     0,     0,
-     413,   414,   415,   416,   417,   418,   419,   420,   421,     0,
-       0,     0,     0,     0,     0,     0,   422,   423,     0,     0,
-       0,     0,     0,     0,   414,   415,   416,   417,   418,   419,
-     420,   421,     0,     0,     0,     0,     0,     0,     0,   422,
-     423,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,   412,   413,   414,   415,   416,   417,   418,
-     419,   420,   421,     0,     4,     0,     0,     0,     0,     0,
-     422,   423,   415,   416,   417,   418,   419,   420,   421,     0,
-       0,     0,     0,     0,     0,     0,   422,   423,     5,     0,
-       6,     0,     0,     0,     0,     0,     7,     8,     0,     0,
-       9,     0,     0,     0,     0,     0,     0,     4,     0,     0,
-       0,    11,     0,    12,     0,     0,     0,    13,    14,     0,
-      15,     0,     0,    16,     0,    17,     0,     0,     0,     0,
-       0,     5,    18,     6,     0,     0,     0,     0,     0,     7,
-       0,     0,    20,     9,    21,    22,    23,     0,     0,   174,
-       0,    24,     0,   175,     0,     0,    12,     0,     0,     0,
-      13,    14,     0,    15,     0,     0,    16,     0,    17,     0,
-       0,     0,     0,     0,    25,    18,     0,     4,    26,    27,
-      28,    29,     0,     0,    30,    20,    31,    21,    22,     0,
-      32,     0,     0,     0,    24,     0,     0,    34,     0,    35,
-       0,     5,     0,     6,    36,    37,     0,     0,     0,     7,
-       0,     0,     0,     0,     0,     0,     0,    25,     0,     0,
-       0,    26,    27,    28,    29,     0,    12,    30,     0,    31,
-      13,    14,     0,    32,     0,     0,    16,     0,    17,     0,
-      34,     0,    35,     0,     0,    18,     0,    36,    37,     0,
-       0,     0,     0,     0,     0,     0,     0,    21,    22,     0,
-       0,     0,     0,     0,    24,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,    26,    27,
+      28,     0,   305,    29,     0,     0,     0,     0,     0,    31,
+       0,     0,     0,     0,   306,     0,    33,     0,    34,     0,
+       0,     0,     0,    35,    36,     4,     0,     0,   303,     0,
+       0,   307,   253,     0,   308,   309,   310,     0,     0,   311,
+     312,     0,     0,     0,     0,     0,     0,     0,     0,     5,
+     313,     6,     0,     0,     0,     0,     0,     7,     8,     0,
+       0,     9,     0,     0,   304,     0,    10,     0,     0,     0,
+       0,     0,    11,     0,    12,     0,     0,     0,    13,    14,
+       0,    15,     0,     0,    16,     0,    17,     0,     0,   305,
+       0,     0,     0,    18,     0,     0,     0,     0,     0,    19,
+     254,   306,     0,    20,     0,    21,    22,    23,     0,     0,
+       0,     0,    24,     0,     0,     0,     0,     0,   307,     4,
+       0,   308,   309,   370,     0,     0,   311,   312,     0,     0,
+       0,     0,     0,     0,     0,    25,     0,   313,     0,    26,
+      27,    28,     0,     5,    29,     6,    30,     0,     0,     0,
+      31,     7,     8,     0,     0,     9,    32,    33,     0,    34,
+      10,     0,     0,     0,    35,    36,    11,     0,    12,     0,
+       0,     0,    13,    14,     0,    15,     0,     0,    16,     0,
+      17,     0,     0,     0,     0,     0,     0,    18,    37,     0,
+       0,     0,     0,    19,     0,     0,     0,    20,     0,    21,
+      22,    23,     0,     0,     0,     0,    24,     0,     0,     0,
+       0,     0,     0,     4,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,   401,   402,   403,    25,
+       0,   406,   407,    26,    27,    28,     0,     5,    29,     6,
+      30,     0,     0,     0,    31,     7,     0,     0,     0,     9,
+      32,    33,     0,    34,     0,     0,     0,     0,    35,    36,
+       0,     0,    12,     4,     0,     0,    13,    14,     0,    15,
+       0,     0,    16,     0,    17,     0,     0,     0,     0,     0,
+       0,    18,    37,     0,     0,     0,     0,     5,     0,     6,
+       0,    20,     0,    21,    22,     7,     0,     0,     0,     9,
+      24,   401,   402,   403,   404,   405,   406,   407,   408,   409,
+       0,     0,    12,     0,     0,     0,    13,    14,     0,    15,
+       0,     0,    16,    25,    17,     0,     0,    26,    27,    28,
+       0,    18,    29,     0,    30,     0,     0,     0,    31,     0,
+       0,    20,     0,    21,    22,    33,     0,    34,     0,     0,
+      24,     0,   372,    36,   401,   402,   403,   404,   405,   406,
+     407,   408,   409,     0,     0,     0,   414,   415,   416,   417,
+     418,   419,   420,    25,     0,     0,    37,    26,    27,    28,
+     421,   422,    29,     0,    30,     0,     0,     0,    31,     0,
+       0,     0,     0,     0,     0,    33,     0,    34,     0,     0,
+       0,     0,    35,    36,   401,   402,   403,   404,   405,   406,
+     407,   408,   409,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,    37,   401,   402,   403,
+     404,   405,   406,   407,   408,   409,   410,     0,   411,   412,
+     413,   414,   415,   416,   417,   418,   419,   420,     0,     0,
+       0,     0,     0,     0,     0,   421,   422,     0,     0,     0,
+     436,   401,   402,   403,   404,   405,   406,   407,   408,   409,
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     401,   402,   403,   404,   405,   406,   407,     0,   409,   410,
+       0,   411,   412,   413,   414,   415,   416,   417,   418,   419,
+     420,     0,     0,     0,     0,     0,     0,     0,   421,   422,
+       0,     0,     0,   444,   401,   402,   403,   404,   405,   406,
+     407,   408,   409,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,   401,   402,   403,   404,   405,   406,   407,   410,
+       0,   411,   412,   413,   414,   415,   416,   417,   418,   419,
+     420,   401,   402,   403,   404,   405,   406,   407,   421,   422,
+       0,     0,   410,   480,   411,   412,   413,   414,   415,   416,
+     417,   418,   419,   420,   401,   402,   403,   404,   405,   406,
+     407,   421,   422,   525,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,   410,   524,   411,   412,
+     413,   414,   415,   416,   417,   418,   419,   420,   401,   402,
+     403,   404,   405,   406,   407,   421,   422,   411,   412,   413,
+     414,   415,   416,   417,   418,   419,   420,     0,     0,     0,
+       0,     0,     0,     0,   421,   422,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,   410,
+       0,   411,   412,   413,   414,   415,   416,   417,   418,   419,
+     420,     0,     0,     0,     0,     0,     0,     0,   421,   422,
+     412,   413,   414,   415,   416,   417,   418,   419,   420,     0,
+       0,     0,     0,     0,     0,     0,   421,   422,   411,   412,
+     413,   414,   415,   416,   417,   418,   419,   420,     0,     0,
+       0,     0,     0,     0,     0,   421,   422,     0,     0,     0,
+       0,     4,     0,   413,   414,   415,   416,   417,   418,   419,
+     420,     0,     0,     0,     0,     0,     0,     0,   421,   422,
+       0,     0,     0,     0,     0,     5,     0,     6,     0,     0,
+       0,     0,     0,     7,     8,     0,     0,     9,   414,   415,
+     416,   417,   418,   419,   420,     0,     0,     0,    11,     0,
+      12,     0,   421,   422,    13,    14,     0,    15,     0,     0,
+      16,     0,    17,     0,     0,     0,     0,     0,     0,    18,
+       0,     0,     0,     0,     0,     0,     0,     0,     4,    20,
+       0,    21,    22,    23,     0,     0,   173,     0,    24,     0,
+     174,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     5,     0,     6,     0,     0,     0,     0,     0,
+       7,    25,     0,     0,     9,    26,    27,    28,     0,     0,
+      29,     4,    30,     0,     0,     0,    31,    12,     0,     0,
+       0,    13,    14,    33,    15,    34,     0,    16,     0,    17,
+      35,    36,     0,     0,     0,     5,    18,     6,     0,     0,
+       0,     0,     0,     7,     0,     0,    20,     0,    21,    22,
+       0,     0,     0,     0,     0,    24,     0,     0,     0,     0,
+      12,     0,     0,     0,    13,    14,     0,     0,     0,     0,
+      16,     0,    17,     0,     0,     0,     0,     0,    25,    18,
+       0,     0,    26,    27,    28,     0,     0,    29,     0,    30,
+       0,    21,    22,    31,     0,     0,     0,     0,    24,     0,
+      33,     0,    34,     0,     0,     0,     0,    35,    36,     0,
        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,    26,    27,    28,    29,     0,     0,    30,     0,     0,
-       0,     0,     0,    32,     0,     0,     0,     0,     0,     0,
-      34,     0,    35,     0,     0,     0,     0,    36,    37,    96,
-       0,    97,    98,     0,    99,   100,     0,   101,     0,     0,
-     102,     0,   103,     0,     0,     0,     0,     0,     0,   104,
-     105,   106,   107,     0,   108,   109,   110,   111,   112,     0,
-     113,     0,   114,   115,   116,     0,     0,   117,     0,     0,
-       0,     0,   118,     0,   119,   120,   121,   122,   123,   124,
-       0,   125,   126,   127,   128,   129,     0,     0,   130,     0,
-       0,   131,     0,     0,     0,   132,   133,     0,   134,     0,
-       0,     0,   135,   136,   137,     0,   138,   139,   140,   141,
-     142,     0,   143,     0,   144,   145,   146,   147,   148,   149,
-     150,   151,     0,   152,   153,   154,     0,     0,     0,     0,
-     155,     0,     0,   156,     0,     0,   157,   158,     0,     0,
-     159,   160,   161,     0,     0,     0,   162,     0,   163,   164,
-     165,   166,     0,     0,   167
+       0,     0,     0,     0,     0,    26,    27,    28,     0,     0,
+      29,     0,     0,     0,     0,     0,    31,     0,     0,     0,
+       0,     0,     0,    33,     0,    34,     0,     0,     0,     0,
+      35,    36,    95,     0,    96,    97,     0,    98,    99,     0,
+     100,     0,     0,   101,     0,   102,     0,     0,     0,     0,
+       0,     0,   103,   104,   105,   106,     0,   107,   108,   109,
+     110,   111,     0,   112,     0,   113,   114,   115,     0,     0,
+     116,     0,     0,     0,     0,   117,     0,   118,   119,   120,
+     121,   122,   123,     0,   124,   125,   126,   127,   128,     0,
+       0,   129,     0,     0,   130,     0,     0,     0,   131,   132,
+       0,   133,     0,     0,     0,   134,   135,   136,     0,   137,
+     138,   139,   140,   141,     0,   142,     0,   143,   144,   145,
+     146,   147,   148,   149,   150,     0,   151,   152,   153,     0,
+       0,     0,   154,     0,     0,   155,     0,     0,   156,   157,
+       0,     0,   158,   159,   160,     0,     0,     0,   161,     0,
+     162,   163,   164,   165,     0,     0,   166
 };
 
-static const short int yycheck[] =
+static const yytype_int16 yycheck[] =
 {
-       2,     2,     2,    33,     2,    46,    67,   264,     2,   207,
-     208,   233,   276,     2,   236,    14,   238,   252,    46,   241,
-       2,   220,   244,    34,   232,    86,   224,   282,   227,    64,
-      65,   272,    92,    36,    69,    46,    40,   131,     0,    51,
-       3,     4,   131,    63,    64,    65,    46,   109,    46,    69,
-      91,   113,    46,   171,   295,   296,    60,     3,    84,     5,
-       6,     7,     8,     9,    46,   147,   147,   147,   147,    72,
-     147,     8,    35,   281,    86,   147,   138,    40,    82,   173,
-     278,    84,    85,   168,   173,   168,   171,   170,    91,   170,
-     172,    14,   172,   172,   147,   172,   353,   169,     3,    62,
-       5,     6,     7,     8,     9,    86,    28,   364,   168,    24,
-     114,   168,    27,    35,   349,    61,   119,     3,     4,   172,
-     168,   124,   126,   168,   105,   168,   174,   171,   168,   174,
-       8,   174,    10,    32,   174,    34,     3,     4,     3,     4,
-     103,     3,     4,     3,     4,     3,     4,     3,     4,    35,
-     173,    97,     3,     4,     3,     4,    61,     3,     4,   173,
-     382,   189,   170,   174,   127,    12,    13,    14,   167,   168,
-     172,   173,   172,   173,   172,   173,    62,   123,   172,   173,
-     215,   379,   381,   172,   173,   440,   247,   248,   386,   135,
-     251,   170,    97,   170,   157,   215,   170,    14,   170,   463,
-     170,   170,   424,   170,   149,   173,   152,   464,   171,   155,
-     156,   157,   170,   170,   160,   161,   229,   103,   123,   232,
-       8,   443,   173,   169,   173,   171,   239,   170,     3,   242,
-     135,   173,   245,   246,   157,   158,   159,   171,   171,   171,
-     270,   127,   283,   171,   167,   168,   171,   152,   175,   173,
-     155,   156,   157,   314,   511,   160,   161,   171,   171,   457,
-     171,   171,   292,   171,   171,   171,   171,   171,   281,   282,
-     171,   157,   470,   530,   171,   277,   474,   277,   477,   277,
-     171,   283,   171,   277,   171,   171,   171,   171,   171,   171,
-     171,   171,   171,   170,   296,   308,   309,   310,   311,   312,
-     313,   314,   170,   173,   170,     8,     8,   171,   155,   156,
-     157,   158,   159,   172,   536,   513,     8,   358,   172,     8,
-     167,   168,     8,    65,     5,   366,   168,   171,   149,   170,
-     360,   170,   393,   173,   172,   147,   147,   378,   155,   156,
-     157,   158,   159,   384,   174,   172,   175,   171,     3,   172,
-     167,   168,   172,   354,   172,   147,   172,   172,   371,   172,
-     167,   363,   172,   363,   172,   363,   366,   172,   366,   363,
-     172,   172,   366,   172,   172,   172,   172,   172,     8,   149,
-     170,   174,    78,   169,   384,   172,   147,   172,   170,   402,
-     403,   170,   405,   406,   407,   408,   409,   410,   411,   412,
-     413,   414,   415,   416,   417,   418,   419,   420,   421,     4,
-     423,     3,   172,     3,     8,   172,     5,   172,   170,   460,
-     170,   172,   149,   172,   149,   173,   170,   440,   469,    44,
-       2,   362,   469,    28,   381,    30,   245,   542,     2,    46,
-       2,    36,    37,     2,   278,    40,   182,   474,    -1,     3,
-      45,     5,     6,     7,     8,     9,    51,    -1,    53,   243,
-      -1,    -1,    57,    58,    -1,    60,    -1,   469,    63,   482,
-      65,    -1,    -1,    -1,    -1,    -1,    -1,    72,    -1,    -1,
-      -1,    -1,    -1,    78,    79,    -1,    -1,    82,    -1,    84,
-      85,    86,    -1,    -1,    -1,    -1,    91,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,     4,    -1,    -1,    61,    -1,    -1,
-      -1,    -1,   525,   515,    -1,   515,    -1,   515,    -1,   114,
-      -1,   515,    -1,   118,   119,   120,   121,    -1,    28,   124,
-      30,   126,    -1,    -1,    -1,   130,    36,    -1,    -1,    -1,
-      40,   136,   137,    97,   139,    45,    12,    13,    14,   144,
-     145,    17,    18,    53,    -1,    -1,    -1,    57,    58,    -1,
-      60,    -1,    -1,    63,    -1,    65,    -1,    -1,    -1,   123,
-      -1,    -1,    72,   168,    -1,    -1,    -1,    -1,    78,   174,
-      -1,   135,    82,    -1,    84,    85,    -1,    -1,    -1,    -1,
-      -1,    91,    -1,    -1,    -1,    -1,    -1,    -1,   152,     4,
-      -1,   155,   156,   157,    -1,    -1,   160,   161,    -1,    -1,
-      -1,    -1,    -1,    -1,   114,    -1,    -1,   171,   118,   119,
-     120,   121,    -1,    28,   124,    30,   126,    -1,    -1,    -1,
-     130,    36,    -1,    -1,    -1,    40,   136,   137,    -1,   139,
-      45,    -1,    -1,    -1,   144,   145,    -1,    -1,    53,    -1,
-      -1,    -1,    57,    58,    -1,    60,    -1,    -1,    63,    -1,
-      65,    -1,    -1,    -1,    -1,    -1,    -1,    72,   168,    -1,
-      -1,    -1,    -1,    78,   174,    -1,    -1,    82,    -1,    84,
-      85,    -1,    -1,    -1,    -1,    -1,    91,   153,   154,   155,
-     156,   157,   158,   159,     4,    -1,    -1,    -1,    -1,    -1,
-      -1,   167,   168,    -1,    -1,    -1,    -1,    -1,    -1,   114,
-      -1,    -1,    -1,   118,   119,   120,   121,    -1,    28,   124,
-      30,   126,    -1,    -1,    -1,   130,    36,    -1,    -1,    -1,
-      40,   136,   137,    -1,   139,    45,    -1,    -1,    -1,   144,
-     145,    -1,    -1,    53,    -1,    -1,    -1,    57,    58,    -1,
-      60,    -1,    -1,    63,    -1,    65,    -1,    -1,    -1,    -1,
-      -1,    -1,    72,   168,    -1,    -1,    -1,    -1,    78,   174,
-      -1,    -1,    82,    -1,    84,    85,    -1,    -1,    -1,    -1,
-      -1,    91,    -1,    -1,    -1,    -1,    -1,    -1,     3,     4,
-       5,     6,     7,     8,     9,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,   114,    -1,    -1,    -1,   118,   119,
-     120,   121,    -1,    28,   124,    30,   126,    -1,    -1,    -1,
-     130,    36,    -1,    -1,    -1,    -1,   136,   137,    -1,   139,
-      -1,    -1,    -1,    -1,   144,   145,    -1,    -1,    53,    -1,
-      -1,    -1,    57,    58,    -1,    -1,    61,    -1,    63,    -1,
-      65,    -1,    -1,    -1,    -1,    -1,    -1,    72,   168,    -1,
-      -1,    -1,    -1,    -1,   174,    -1,    -1,    -1,    -1,    84,
-      85,    -1,    -1,    -1,    -1,    -1,    91,    -1,    -1,    -1,
-      -1,    -1,    97,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+       2,    45,     2,     2,     2,    32,   263,   275,     2,    66,
+       2,   232,   206,   207,   235,    45,   237,   281,    34,   240,
+     219,   251,   243,    92,   231,     2,   271,   226,    85,   223,
+      46,    62,    63,    64,   130,    40,   130,    68,   167,    51,
+     146,   170,     0,    14,   146,    45,    90,    45,    14,   294,
+     295,    45,   170,   146,   109,    60,   146,     3,   113,     5,
+       6,     7,     8,     9,   146,   171,    63,    64,    45,   171,
+      84,    68,   146,   280,    86,   168,   172,    82,   172,   146,
+      86,   171,   137,   277,    24,     3,     4,    27,     3,   171,
+       5,     6,     7,     8,     9,   352,     8,   171,   167,   105,
+     170,   167,   169,   167,     3,     4,   363,   173,    14,   114,
+       8,   167,    10,   167,   172,    61,   167,   173,   348,   173,
+     125,    28,   173,    31,   167,    33,   169,    34,     3,     4,
+       3,     4,     3,     4,     3,     4,    35,     3,     4,     3,
+       4,    40,     3,     4,     3,     4,    61,   169,   169,   169,
+     169,    97,   169,   148,   172,     8,   171,   173,   188,   169,
+     381,   169,   169,    62,     3,    12,    13,    14,   172,   171,
+     172,   171,   172,   171,   172,   439,   122,   171,   172,   171,
+     172,   380,    97,   214,   378,   156,   157,   158,   134,   246,
+     247,   385,   172,   250,   462,   166,   167,   169,   172,   169,
+     166,   167,   423,   172,   103,   151,   463,   122,   154,   155,
+     156,   170,   169,   159,   160,   228,   170,   214,   231,   134,
+     170,   442,   168,   170,   170,   238,   170,   126,   241,   170,
+     172,   244,   245,   170,   170,   170,   151,   170,   282,   154,
+     155,   156,   269,   170,   159,   160,   170,   170,   154,   155,
+     156,   157,   158,   510,   170,   170,   313,   156,     3,     4,
+     166,   167,   456,   172,   291,   170,   170,   280,   281,   170,
+     170,   170,   529,   170,   276,   469,   276,   476,   276,   473,
+     282,   170,   276,   170,   170,   170,   170,   170,   169,    36,
+      35,   169,   169,   295,   307,   308,   309,   310,   311,   312,
+     313,   171,   174,   170,     8,     8,     8,   154,   155,   156,
+     157,   158,     8,   357,   535,     8,    65,    62,   512,   166,
+     167,   365,     5,   167,   170,    72,   169,   148,   169,   146,
+     172,   171,   359,   377,   146,   392,   173,    84,    85,   383,
+     174,   171,   170,     3,    91,   171,   171,   171,   171,   171,
+     146,   171,   171,   171,   353,   171,   171,   370,   103,   166,
+     362,   171,   362,   171,   362,   365,   171,   365,   362,   171,
+     171,   365,   119,   171,     8,   148,   123,   169,   173,    78,
+     168,   126,   171,   383,   146,   171,   169,   169,   401,   402,
+     171,   404,   405,   406,   407,   408,   409,   410,   411,   412,
+     413,   414,   415,   416,   417,   418,   419,   420,     4,   422,
+       3,   156,     3,     8,   171,   459,     5,   171,   169,   169,
+     172,   148,   148,   171,   468,   170,   439,   171,   169,    43,
+     361,     2,    28,   468,    30,   380,   541,     2,   244,    45,
+      36,    37,     2,     2,    40,   277,   181,   473,   242,    45,
+      -1,    -1,    -1,    -1,    -1,    51,    -1,    53,    -1,    -1,
+      -1,    57,    58,    -1,    60,    -1,   468,    63,   481,    65,
+      -1,    -1,    -1,    -1,    -1,    -1,    72,    -1,    -1,    -1,
+      -1,    -1,    78,    79,    -1,    -1,    82,    -1,    84,    85,
+      86,    -1,    -1,    -1,    -1,    91,    -1,    -1,    -1,    -1,
+      -1,    -1,     4,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,   524,   514,    -1,   514,    -1,   514,    -1,   114,    -1,
+     514,    -1,   118,   119,   120,    -1,    28,   123,    30,   125,
+      -1,    -1,    -1,   129,    36,    -1,    -1,    -1,    40,   135,
+     136,    -1,   138,    45,    -1,    -1,    -1,   143,   144,    -1,
+      -1,    53,    -1,    -1,    -1,    57,    58,    -1,    60,    -1,
+      -1,    63,    -1,    65,    -1,    -1,    -1,    -1,    -1,    -1,
+      72,   167,    -1,    -1,    -1,    -1,    78,   173,    -1,    -1,
+      82,    -1,    84,    85,    -1,    -1,    -1,    -1,    -1,    91,
+      -1,    -1,    -1,    -1,    -1,    -1,     4,    -1,    -1,    -1,
       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,   118,   119,   120,   121,    -1,   123,   124,
-      -1,    -1,    -1,    -1,    -1,   130,    -1,    -1,    -1,    -1,
-     135,    -1,   137,    -1,   139,     4,    -1,    -1,    -1,   144,
-     145,    -1,    11,    -1,    -1,    -1,    -1,   152,    -1,    -1,
-     155,   156,   157,    -1,    -1,   160,   161,    -1,    -1,    28,
-      -1,    30,    -1,    -1,    -1,    -1,   171,    36,    37,    -1,
-      -1,    40,    -1,    -1,    -1,    -1,    45,    -1,    -1,    -1,
-      -1,    -1,    51,    -1,    53,    -1,    -1,    -1,    57,    58,
-      -1,    60,    -1,    -1,    63,    -1,    65,    -1,    -1,    -1,
-      -1,    -1,    -1,    72,    -1,    -1,    -1,    -1,    -1,    78,
-      79,    -1,    -1,    82,    -1,    84,    85,    86,    -1,    -1,
-      -1,    -1,    91,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,   114,    -1,    -1,    -1,   118,   119,   120,    -1,
+      28,   123,    30,   125,    -1,    -1,    -1,   129,    36,    -1,
+      -1,    -1,    40,   135,   136,    -1,   138,    45,    -1,    -1,
+      -1,   143,   144,    -1,    -1,    53,    -1,    -1,    -1,    57,
+      58,    -1,    60,    -1,    -1,    63,    -1,    65,    -1,    -1,
+      -1,    -1,    -1,    -1,    72,   167,    -1,    -1,    -1,    -1,
+      78,   173,    -1,    -1,    82,    -1,    84,    85,    -1,    -1,
+      -1,    -1,    -1,    91,    -1,    -1,    -1,    -1,    -1,    -1,
        4,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,    -1,   114,    -1,    -1,    -1,   118,
-     119,   120,   121,    -1,    28,   124,    30,   126,    -1,    -1,
-      -1,   130,    36,    37,    -1,    -1,    40,   136,   137,    -1,
-     139,    45,    -1,    -1,    -1,   144,   145,    51,    -1,    53,
+      -1,    -1,    -1,    -1,    -1,    -1,   114,    -1,    -1,    -1,
+     118,   119,   120,    -1,    28,   123,    30,   125,    -1,    -1,
+      -1,   129,    36,    -1,    -1,    -1,    40,   135,   136,    -1,
+     138,    45,    -1,    -1,    -1,   143,   144,    -1,    -1,    53,
       -1,    -1,    -1,    57,    58,    -1,    60,    -1,    -1,    63,
-      -1,    65,    -1,    -1,    -1,    -1,    -1,    -1,    72,   168,
-      -1,    -1,    -1,    -1,    78,     4,    -1,    -1,    82,    -1,
-      84,    85,    86,    -1,    -1,    -1,    -1,    91,    -1,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    28,
-      -1,    30,    -1,    -1,    -1,    -1,    -1,    36,    -1,    -1,
-     114,    40,    -1,    -1,   118,   119,   120,   121,     4,    -1,
-     124,    -1,   126,    -1,    53,    -1,   130,    -1,    57,    58,
-      -1,    60,   136,   137,    63,   139,    65,    -1,    -1,    -1,
-     144,   145,    28,    72,    30,    -1,    -1,    -1,    -1,    -1,
-      36,    -1,    -1,    82,    40,    84,    85,    -1,    -1,    -1,
-      -1,    -1,    91,    -1,   168,    -1,    -1,    53,    -1,    -1,
-      -1,    57,    58,    -1,    60,    -1,    -1,    63,    -1,    65,
-      -1,    -1,    -1,    -1,    -1,   114,    72,    -1,    -1,   118,
-     119,   120,   121,    -1,    -1,   124,    82,   126,    84,    85,
-      -1,   130,    -1,    -1,    -1,    91,    -1,    -1,   137,    -1,
-     139,    -1,    -1,    -1,    -1,   144,   145,    12,    13,    14,
-      15,    16,    17,    18,    19,    20,    -1,    -1,   114,    -1,
-      -1,    -1,   118,   119,   120,   121,    -1,    -1,   124,   168,
-     126,    -1,    -1,    -1,   130,    -1,    -1,    -1,    -1,    -1,
-      -1,   137,    -1,   139,    -1,    -1,    -1,    -1,   144,   145,
-      12,    13,    14,    15,    16,    17,    18,    19,    20,    -1,
+      -1,    65,    -1,    -1,    -1,    -1,    -1,    -1,    72,   167,
+      -1,    -1,    -1,    -1,    78,   173,    -1,    -1,    82,    -1,
+      84,    85,    -1,    -1,    -1,    -1,    -1,    91,    -1,    -1,
+      -1,    -1,    -1,     3,     4,     5,     6,     7,     8,     9,
       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,   168,    12,    13,    14,    15,    16,    17,    18,
-      19,    20,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,    12,    13,    14,    15,
-      16,    17,    18,    19,    20,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    12,    13,
-      14,    15,    16,    17,    18,    19,    20,    -1,    -1,    -1,
+     114,    -1,    -1,    -1,   118,   119,   120,    -1,    28,   123,
+      30,   125,    -1,    -1,    -1,   129,    36,    -1,    -1,    -1,
+      -1,   135,   136,    -1,   138,    -1,    -1,    -1,    -1,   143,
+     144,    -1,    -1,    53,    -1,    -1,    -1,    57,    58,    -1,
+      -1,    61,    -1,    63,    -1,    65,    -1,    -1,    -1,    -1,
+      -1,    -1,    72,   167,    -1,    -1,    -1,    -1,    -1,   173,
+      -1,    -1,    -1,    -1,    84,    85,    -1,    -1,    -1,    -1,
+       3,    91,     5,     6,     7,     8,     9,    97,    -1,    -1,
       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,   148,    -1,   150,   151,   152,   153,   154,
-     155,   156,   157,   158,   159,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,   167,   168,    -1,    -1,    -1,   172,    12,    13,
-      14,    15,    16,    17,    18,    19,    20,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,   148,    -1,   150,   151,
-     152,   153,   154,   155,   156,   157,   158,   159,    12,    13,
-      14,    15,    16,    17,    18,   167,   168,    -1,    -1,   148,
-     172,   150,   151,   152,   153,   154,   155,   156,   157,   158,
-     159,    12,    13,    14,    15,    16,    17,    18,   167,   168,
-      -1,    -1,   148,   172,   150,   151,   152,   153,   154,   155,
-     156,   157,   158,   159,    12,    13,    14,    15,    16,    17,
-      18,   167,   168,   169,   148,   149,   150,   151,   152,   153,
-     154,   155,   156,   157,   158,   159,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,   167,   168,    12,    13,    14,    15,    16,
-      17,    18,    -1,    20,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    12,    13,    14,    15,    16,    17,    18,    -1,    -1,
-      -1,    -1,    -1,    -1,   148,    -1,   150,   151,   152,   153,
-     154,   155,   156,   157,   158,   159,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,   167,   168,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,   150,   151,   152,   153,
-     154,   155,   156,   157,   158,   159,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,   167,   168,    -1,    -1,    -1,    -1,    -1,
-     151,   152,   153,   154,   155,   156,   157,   158,   159,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,   167,   168,    -1,    -1,
-      -1,    -1,    -1,    -1,   152,   153,   154,   155,   156,   157,
-     158,   159,    -1,    -1,    -1,    -1,    -1,    -1,    -1,   167,
-     168,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,   150,   151,   152,   153,   154,   155,   156,
-     157,   158,   159,    -1,     4,    -1,    -1,    -1,    -1,    -1,
-     167,   168,   153,   154,   155,   156,   157,   158,   159,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,   167,   168,    28,    -1,
-      30,    -1,    -1,    -1,    -1,    -1,    36,    37,    -1,    -1,
-      40,    -1,    -1,    -1,    -1,    -1,    -1,     4,    -1,    -1,
-      -1,    51,    -1,    53,    -1,    -1,    -1,    57,    58,    -1,
-      60,    -1,    -1,    63,    -1,    65,    -1,    -1,    -1,    -1,
-      -1,    28,    72,    30,    -1,    -1,    -1,    -1,    -1,    36,
-      -1,    -1,    82,    40,    84,    85,    86,    -1,    -1,    89,
-      -1,    91,    -1,    93,    -1,    -1,    53,    -1,    -1,    -1,
-      57,    58,    -1,    60,    -1,    -1,    63,    -1,    65,    -1,
-      -1,    -1,    -1,    -1,   114,    72,    -1,     4,   118,   119,
-     120,   121,    -1,    -1,   124,    82,   126,    84,    85,    -1,
-     130,    -1,    -1,    -1,    91,    -1,    -1,   137,    -1,   139,
-      -1,    28,    -1,    30,   144,   145,    -1,    -1,    -1,    36,
-      -1,    -1,    -1,    -1,    -1,    -1,    -1,   114,    -1,    -1,
-      -1,   118,   119,   120,   121,    -1,    53,   124,    -1,   126,
-      57,    58,    -1,   130,    -1,    -1,    63,    -1,    65,    -1,
-     137,    -1,   139,    -1,    -1,    72,    -1,   144,   145,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,    -1,    84,    85,    -1,
-      -1,    -1,    -1,    -1,    91,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,   118,   119,
+     120,    -1,   122,   123,    -1,    -1,    -1,    -1,    -1,   129,
+      -1,    -1,    -1,    -1,   134,    -1,   136,    -1,   138,    -1,
+      -1,    -1,    -1,   143,   144,     4,    -1,    -1,    61,    -1,
+      -1,   151,    11,    -1,   154,   155,   156,    -1,    -1,   159,
+     160,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    28,
+     170,    30,    -1,    -1,    -1,    -1,    -1,    36,    37,    -1,
+      -1,    40,    -1,    -1,    97,    -1,    45,    -1,    -1,    -1,
+      -1,    -1,    51,    -1,    53,    -1,    -1,    -1,    57,    58,
+      -1,    60,    -1,    -1,    63,    -1,    65,    -1,    -1,   122,
+      -1,    -1,    -1,    72,    -1,    -1,    -1,    -1,    -1,    78,
+      79,   134,    -1,    82,    -1,    84,    85,    86,    -1,    -1,
+      -1,    -1,    91,    -1,    -1,    -1,    -1,    -1,   151,     4,
+      -1,   154,   155,   156,    -1,    -1,   159,   160,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,   114,    -1,   170,    -1,   118,
+     119,   120,    -1,    28,   123,    30,   125,    -1,    -1,    -1,
+     129,    36,    37,    -1,    -1,    40,   135,   136,    -1,   138,
+      45,    -1,    -1,    -1,   143,   144,    51,    -1,    53,    -1,
+      -1,    -1,    57,    58,    -1,    60,    -1,    -1,    63,    -1,
+      65,    -1,    -1,    -1,    -1,    -1,    -1,    72,   167,    -1,
+      -1,    -1,    -1,    78,    -1,    -1,    -1,    82,    -1,    84,
+      85,    86,    -1,    -1,    -1,    -1,    91,    -1,    -1,    -1,
+      -1,    -1,    -1,     4,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,    12,    13,    14,   114,
+      -1,    17,    18,   118,   119,   120,    -1,    28,   123,    30,
+     125,    -1,    -1,    -1,   129,    36,    -1,    -1,    -1,    40,
+     135,   136,    -1,   138,    -1,    -1,    -1,    -1,   143,   144,
+      -1,    -1,    53,     4,    -1,    -1,    57,    58,    -1,    60,
+      -1,    -1,    63,    -1,    65,    -1,    -1,    -1,    -1,    -1,
+      -1,    72,   167,    -1,    -1,    -1,    -1,    28,    -1,    30,
+      -1,    82,    -1,    84,    85,    36,    -1,    -1,    -1,    40,
+      91,    12,    13,    14,    15,    16,    17,    18,    19,    20,
+      -1,    -1,    53,    -1,    -1,    -1,    57,    58,    -1,    60,
+      -1,    -1,    63,   114,    65,    -1,    -1,   118,   119,   120,
+      -1,    72,   123,    -1,   125,    -1,    -1,    -1,   129,    -1,
+      -1,    82,    -1,    84,    85,   136,    -1,   138,    -1,    -1,
+      91,    -1,   143,   144,    12,    13,    14,    15,    16,    17,
+      18,    19,    20,    -1,    -1,    -1,   152,   153,   154,   155,
+     156,   157,   158,   114,    -1,    -1,   167,   118,   119,   120,
+     166,   167,   123,    -1,   125,    -1,    -1,    -1,   129,    -1,
+      -1,    -1,    -1,    -1,    -1,   136,    -1,   138,    -1,    -1,
+      -1,    -1,   143,   144,    12,    13,    14,    15,    16,    17,
+      18,    19,    20,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,   167,    12,    13,    14,
+      15,    16,    17,    18,    19,    20,   147,    -1,   149,   150,
+     151,   152,   153,   154,   155,   156,   157,   158,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,   166,   167,    -1,    -1,    -1,
+     171,    12,    13,    14,    15,    16,    17,    18,    19,    20,
       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      12,    13,    14,    15,    16,    17,    18,    -1,    20,   147,
+      -1,   149,   150,   151,   152,   153,   154,   155,   156,   157,
+     158,    -1,    -1,    -1,    -1,    -1,    -1,    -1,   166,   167,
+      -1,    -1,    -1,   171,    12,    13,    14,    15,    16,    17,
+      18,    19,    20,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    12,    13,    14,    15,    16,    17,    18,   147,
+      -1,   149,   150,   151,   152,   153,   154,   155,   156,   157,
+     158,    12,    13,    14,    15,    16,    17,    18,   166,   167,
+      -1,    -1,   147,   171,   149,   150,   151,   152,   153,   154,
+     155,   156,   157,   158,    12,    13,    14,    15,    16,    17,
+      18,   166,   167,   168,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,   147,   148,   149,   150,
+     151,   152,   153,   154,   155,   156,   157,   158,    12,    13,
+      14,    15,    16,    17,    18,   166,   167,   149,   150,   151,
+     152,   153,   154,   155,   156,   157,   158,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,   166,   167,    -1,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,   147,
+      -1,   149,   150,   151,   152,   153,   154,   155,   156,   157,
+     158,    -1,    -1,    -1,    -1,    -1,    -1,    -1,   166,   167,
+     150,   151,   152,   153,   154,   155,   156,   157,   158,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,   166,   167,   149,   150,
+     151,   152,   153,   154,   155,   156,   157,   158,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,   166,   167,    -1,    -1,    -1,
+      -1,     4,    -1,   151,   152,   153,   154,   155,   156,   157,
+     158,    -1,    -1,    -1,    -1,    -1,    -1,    -1,   166,   167,
+      -1,    -1,    -1,    -1,    -1,    28,    -1,    30,    -1,    -1,
+      -1,    -1,    -1,    36,    37,    -1,    -1,    40,   152,   153,
+     154,   155,   156,   157,   158,    -1,    -1,    -1,    51,    -1,
+      53,    -1,   166,   167,    57,    58,    -1,    60,    -1,    -1,
+      63,    -1,    65,    -1,    -1,    -1,    -1,    -1,    -1,    72,
+      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,     4,    82,
+      -1,    84,    85,    86,    -1,    -1,    89,    -1,    91,    -1,
+      93,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    28,    -1,    30,    -1,    -1,    -1,    -1,    -1,
+      36,   114,    -1,    -1,    40,   118,   119,   120,    -1,    -1,
+     123,     4,   125,    -1,    -1,    -1,   129,    53,    -1,    -1,
+      -1,    57,    58,   136,    60,   138,    -1,    63,    -1,    65,
+     143,   144,    -1,    -1,    -1,    28,    72,    30,    -1,    -1,
+      -1,    -1,    -1,    36,    -1,    -1,    82,    -1,    84,    85,
+      -1,    -1,    -1,    -1,    -1,    91,    -1,    -1,    -1,    -1,
+      53,    -1,    -1,    -1,    57,    58,    -1,    -1,    -1,    -1,
+      63,    -1,    65,    -1,    -1,    -1,    -1,    -1,   114,    72,
+      -1,    -1,   118,   119,   120,    -1,    -1,   123,    -1,   125,
+      -1,    84,    85,   129,    -1,    -1,    -1,    -1,    91,    -1,
+     136,    -1,   138,    -1,    -1,    -1,    -1,   143,   144,    -1,
       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,   118,   119,   120,   121,    -1,    -1,   124,    -1,    -1,
-      -1,    -1,    -1,   130,    -1,    -1,    -1,    -1,    -1,    -1,
-     137,    -1,   139,    -1,    -1,    -1,    -1,   144,   145,    21,
-      -1,    23,    24,    -1,    26,    27,    -1,    29,    -1,    -1,
-      32,    -1,    34,    -1,    -1,    -1,    -1,    -1,    -1,    41,
-      42,    43,    44,    -1,    46,    47,    48,    49,    50,    -1,
-      52,    -1,    54,    55,    56,    -1,    -1,    59,    -1,    -1,
-      -1,    -1,    64,    -1,    66,    67,    68,    69,    70,    71,
-      -1,    73,    74,    75,    76,    77,    -1,    -1,    80,    -1,
-      -1,    83,    -1,    -1,    -1,    87,    88,    -1,    90,    -1,
-      -1,    -1,    94,    95,    96,    -1,    98,    99,   100,   101,
-     102,    -1,   104,    -1,   106,   107,   108,   109,   110,   111,
-     112,   113,    -1,   115,   116,   117,    -1,    -1,    -1,    -1,
-     122,    -1,    -1,   125,    -1,    -1,   128,   129,    -1,    -1,
-     132,   133,   134,    -1,    -1,    -1,   138,    -1,   140,   141,
-     142,   143,    -1,    -1,   146
+      -1,    -1,    -1,    -1,    -1,   118,   119,   120,    -1,    -1,
+     123,    -1,    -1,    -1,    -1,    -1,   129,    -1,    -1,    -1,
+      -1,    -1,    -1,   136,    -1,   138,    -1,    -1,    -1,    -1,
+     143,   144,    21,    -1,    23,    24,    -1,    26,    27,    -1,
+      29,    -1,    -1,    32,    -1,    34,    -1,    -1,    -1,    -1,
+      -1,    -1,    41,    42,    43,    44,    -1,    46,    47,    48,
+      49,    50,    -1,    52,    -1,    54,    55,    56,    -1,    -1,
+      59,    -1,    -1,    -1,    -1,    64,    -1,    66,    67,    68,
+      69,    70,    71,    -1,    73,    74,    75,    76,    77,    -1,
+      -1,    80,    -1,    -1,    83,    -1,    -1,    -1,    87,    88,
+      -1,    90,    -1,    -1,    -1,    94,    95,    96,    -1,    98,
+      99,   100,   101,   102,    -1,   104,    -1,   106,   107,   108,
+     109,   110,   111,   112,   113,    -1,   115,   116,   117,    -1,
+      -1,    -1,   121,    -1,    -1,   124,    -1,    -1,   127,   128,
+      -1,    -1,   131,   132,   133,    -1,    -1,    -1,   137,    -1,
+     139,   140,   141,   142,    -1,    -1,   145
 };
 
 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
    symbol of state STATE-NUM.  */
-static const unsigned short int yystos[] =
+static const yytype_uint16 yystos[] =
 {
-       0,   177,   178,     0,     4,    28,    30,    36,    37,    40,
+       0,   176,   177,     0,     4,    28,    30,    36,    37,    40,
       45,    51,    53,    57,    58,    60,    63,    65,    72,    78,
-      82,    84,    85,    86,    91,   114,   118,   119,   120,   121,
-     124,   126,   130,   136,   137,   139,   144,   145,   168,   182,
-     183,   184,   185,   186,   189,   190,   197,   208,   222,   226,
-     228,   229,   230,   231,   234,   235,   238,   240,   241,   242,
-     243,   245,   246,   247,   248,   249,   251,   253,   259,   260,
-     261,   262,     3,     4,   171,     3,     4,     3,     4,   224,
-      84,   227,     8,     3,     4,   227,   171,   227,   228,     3,
-     224,   196,   197,     3,   224,   228,    21,    23,    24,    26,
-      27,    29,    32,    34,    41,    42,    43,    44,    46,    47,
-      48,    49,    50,    52,    54,    55,    56,    59,    64,    66,
-      67,    68,    69,    70,    71,    73,    74,    75,    76,    77,
-      80,    83,    87,    88,    90,    94,    95,    96,    98,    99,
-     100,   101,   102,   104,   106,   107,   108,   109,   110,   111,
-     112,   113,   115,   116,   117,   122,   125,   128,   129,   132,
-     133,   134,   138,   140,   141,   142,   143,   146,   198,   200,
-     258,   170,   179,   179,    89,    93,   188,   208,   229,   234,
-     240,   244,   251,   259,   262,   170,   170,   173,   170,   173,
-     170,   181,   170,   149,   239,   173,   252,   253,   252,   252,
-       3,     4,    35,    62,   103,   127,   157,   171,   202,   225,
-     254,   255,   257,   208,   259,   260,   262,   252,   170,     8,
-     173,   170,   260,   173,   251,   131,   173,   171,   171,   171,
-     171,   171,   171,   171,   171,   171,   171,   171,   171,   171,
-     171,   171,   171,   171,   171,   171,   171,   171,   171,   171,
-     171,   171,   147,   169,    11,    79,   182,   187,   190,   229,
-     231,   242,   243,   246,   174,     3,     3,     4,   173,   257,
-     232,   105,   236,   240,     3,     4,   173,   180,   250,   254,
-     254,   175,   168,   171,   195,   252,   172,   205,   206,   207,
-     225,   172,   215,   254,   256,   171,   218,   225,     3,     5,
-       6,     7,     8,     9,    61,    97,   123,   135,   152,   155,
-     156,   157,   160,   161,   171,   211,   212,   213,   211,   214,
-       8,     8,   199,   214,   213,     8,     8,   213,     8,   213,
-     211,    65,   213,   209,   210,   211,   258,   213,   209,   211,
-     260,   260,     8,    10,   201,     5,   263,   260,   200,   168,
-     171,   170,   181,   174,   196,   233,   149,    92,   196,   220,
-     237,   170,   173,   180,   174,   182,   197,   249,   254,   172,
-     214,   157,   210,   144,   191,   192,   193,   194,   197,   251,
-     174,   147,   175,   174,   196,   216,   147,   220,   174,   197,
-     217,   220,   172,   171,   211,   211,   211,   211,   211,   211,
-     211,   260,    12,    13,    14,    15,    16,    17,    18,    19,
-      20,   148,   150,   151,   152,   153,   154,   155,   156,   157,
-     158,   159,   167,   168,   147,   172,   172,   172,   147,   172,
-     172,   172,   172,   172,   172,   172,   172,   172,     3,   172,
-     147,   172,   172,   147,   172,   172,   172,   172,   172,   167,
-     172,   172,   200,     8,   181,   243,   149,   251,   170,   174,
-     196,   221,   174,   186,   174,   181,   169,   169,   172,   147,
-     251,   254,   207,   213,   251,   262,   254,   172,   170,   170,
-     260,   172,   172,   211,   211,     3,   211,   211,   211,   211,
-     211,   211,   211,   211,   211,   211,   211,   211,   211,   211,
-     211,   211,   211,     3,   211,   213,     8,   172,   210,   213,
-       5,   172,   254,   251,   170,   180,   181,   194,   254,   256,
-     170,   223,   225,   172,   211,   149,   169,   172,   181,   254,
-     174,   170,   173,   211,   181,   203,    34,    46,   174,   204,
-     213,   149,   149,   170,   219,   220,   219,   170
+      82,    84,    85,    86,    91,   114,   118,   119,   120,   123,
+     125,   129,   135,   136,   138,   143,   144,   167,   181,   182,
+     183,   184,   185,   188,   189,   196,   207,   221,   225,   227,
+     228,   229,   230,   233,   234,   237,   239,   240,   241,   242,
+     244,   245,   246,   247,   248,   250,   252,   258,   259,   260,
+     261,     3,     4,   170,     3,     4,     3,     4,   223,    84,
+     226,     8,     3,     4,   226,   170,   226,   227,     3,   223,
+     195,   196,     3,   223,   227,    21,    23,    24,    26,    27,
+      29,    32,    34,    41,    42,    43,    44,    46,    47,    48,
+      49,    50,    52,    54,    55,    56,    59,    64,    66,    67,
+      68,    69,    70,    71,    73,    74,    75,    76,    77,    80,
+      83,    87,    88,    90,    94,    95,    96,    98,    99,   100,
+     101,   102,   104,   106,   107,   108,   109,   110,   111,   112,
+     113,   115,   116,   117,   121,   124,   127,   128,   131,   132,
+     133,   137,   139,   140,   141,   142,   145,   197,   199,   257,
+     169,   178,   178,    89,    93,   187,   207,   228,   233,   239,
+     243,   250,   258,   261,   169,   169,   172,   169,   172,   169,
+     180,   169,   148,   238,   172,   251,   252,   251,   251,     3,
+       4,    35,    62,   103,   126,   156,   170,   201,   224,   253,
+     254,   256,   207,   258,   259,   261,   251,   169,     8,   172,
+     169,   259,   172,   250,   130,   172,   170,   170,   170,   170,
+     170,   170,   170,   170,   170,   170,   170,   170,   170,   170,
+     170,   170,   170,   170,   170,   170,   170,   170,   170,   170,
+     170,   146,   168,    11,    79,   181,   186,   189,   228,   230,
+     241,   242,   245,   173,     3,     3,     4,   172,   256,   231,
+     105,   235,   239,     3,     4,   172,   179,   249,   253,   253,
+     174,   167,   170,   194,   251,   171,   204,   205,   206,   224,
+     171,   214,   253,   255,   170,   217,   224,     3,     5,     6,
+       7,     8,     9,    61,    97,   122,   134,   151,   154,   155,
+     156,   159,   160,   170,   210,   211,   212,   210,   213,     8,
+       8,   198,   213,   212,     8,     8,   212,     8,   212,   210,
+      65,   212,   208,   209,   210,   257,   212,   208,   210,   259,
+     259,     8,    10,   200,     5,   262,   259,   199,   167,   170,
+     169,   180,   173,   195,   232,   148,    92,   195,   219,   236,
+     169,   172,   179,   173,   181,   196,   248,   253,   171,   213,
+     156,   209,   143,   190,   191,   192,   193,   196,   250,   173,
+     146,   174,   173,   195,   215,   146,   219,   173,   196,   216,
+     219,   171,   170,   210,   210,   210,   210,   210,   210,   210,
+     259,    12,    13,    14,    15,    16,    17,    18,    19,    20,
+     147,   149,   150,   151,   152,   153,   154,   155,   156,   157,
+     158,   166,   167,   146,   171,   171,   171,   146,   171,   171,
+     171,   171,   171,   171,   171,   171,   171,     3,   171,   146,
+     171,   171,   146,   171,   171,   171,   171,   171,   166,   171,
+     171,   199,     8,   180,   242,   148,   250,   169,   173,   195,
+     220,   173,   185,   173,   180,   168,   168,   171,   146,   250,
+     253,   206,   212,   250,   261,   253,   171,   169,   169,   259,
+     171,   171,   210,   210,     3,   210,   210,   210,   210,   210,
+     210,   210,   210,   210,   210,   210,   210,   210,   210,   210,
+     210,   210,     3,   210,   212,     8,   171,   209,   212,     5,
+     171,   253,   250,   169,   179,   180,   193,   253,   255,   169,
+     222,   224,   171,   210,   148,   168,   171,   180,   253,   173,
+     169,   172,   210,   180,   202,    34,    46,   173,   203,   212,
+     148,   148,   169,   218,   219,   218,   169
 };
 
 #define yyerrok		(yyerrstatus = 0)
@@ -1816,7 +1727,7 @@
       yychar = (Token);						\
       yylval = (Value);						\
       yytoken = YYTRANSLATE (yychar);				\
-      YYPOPSTACK;						\
+      YYPOPSTACK (1);						\
       goto yybackup;						\
     }								\
   else								\
@@ -1824,7 +1735,7 @@
       yyerror (YY_("syntax error: cannot back up")); \
       YYERROR;							\
     }								\
-while (0)
+while (YYID (0))
 
 
 #define YYTERROR	1
@@ -1839,7 +1750,7 @@
 #ifndef YYLLOC_DEFAULT
 # define YYLLOC_DEFAULT(Current, Rhs, N)				\
     do									\
-      if (N)								\
+      if (YYID (N))                                                    \
 	{								\
 	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\
 	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
@@ -1853,7 +1764,7 @@
 	  (Current).first_column = (Current).last_column =		\
 	    YYRHSLOC (Rhs, 0).last_column;				\
 	}								\
-    while (0)
+    while (YYID (0))
 #endif
 
 
@@ -1865,8 +1776,8 @@
 # if YYLTYPE_IS_TRIVIAL
 #  define YY_LOCATION_PRINT(File, Loc)			\
      fprintf (File, "%d.%d-%d.%d",			\
-              (Loc).first_line, (Loc).first_column,	\
-              (Loc).last_line,  (Loc).last_column)
+	      (Loc).first_line, (Loc).first_column,	\
+	      (Loc).last_line,  (Loc).last_column)
 # else
 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
 # endif
@@ -1893,37 +1804,100 @@
 do {						\
   if (yydebug)					\
     YYFPRINTF Args;				\
-} while (0)
+} while (YYID (0))
 
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)		\
-do {								\
-  if (yydebug)							\
-    {								\
-      YYFPRINTF (stderr, "%s ", Title);				\
-      yysymprint (stderr,					\
-                  Type, Value);	\
-      YYFPRINTF (stderr, "\n");					\
-    }								\
-} while (0)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)			  \
+do {									  \
+  if (yydebug)								  \
+    {									  \
+      YYFPRINTF (stderr, "%s ", Title);					  \
+      yy_symbol_print (stderr,						  \
+		  Type, Value); \
+      YYFPRINTF (stderr, "\n");						  \
+    }									  \
+} while (YYID (0))
 
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT.  |
+`--------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+#else
+static void
+yy_symbol_value_print (yyoutput, yytype, yyvaluep)
+    FILE *yyoutput;
+    int yytype;
+    YYSTYPE const * const yyvaluep;
+#endif
+{
+  if (!yyvaluep)
+    return;
+# ifdef YYPRINT
+  if (yytype < YYNTOKENS)
+    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+  YYUSE (yyoutput);
+# endif
+  switch (yytype)
+    {
+      default:
+	break;
+    }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT.  |
+`--------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+#else
+static void
+yy_symbol_print (yyoutput, yytype, yyvaluep)
+    FILE *yyoutput;
+    int yytype;
+    YYSTYPE const * const yyvaluep;
+#endif
+{
+  if (yytype < YYNTOKENS)
+    YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+  else
+    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+  yy_symbol_value_print (yyoutput, yytype, yyvaluep);
+  YYFPRINTF (yyoutput, ")");
+}
+
 /*------------------------------------------------------------------.
 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
 | TOP (included).                                                   |
 `------------------------------------------------------------------*/
 
-#if defined (__STDC__) || defined (__cplusplus)
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
 static void
-yy_stack_print (short int *bottom, short int *top)
+yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
 #else
 static void
-yy_stack_print (bottom, top)
-    short int *bottom;
-    short int *top;
+yy_stack_print (yybottom, yytop)
+    yytype_int16 *yybottom;
+    yytype_int16 *yytop;
 #endif
 {
   YYFPRINTF (stderr, "Stack now");
-  for (/* Nothing. */; bottom <= top; ++bottom)
-    YYFPRINTF (stderr, " %d", *bottom);
+  for (; yybottom <= yytop; yybottom++)
+    {
+      int yybot = *yybottom;
+      YYFPRINTF (stderr, " %d", yybot);
+    }
   YYFPRINTF (stderr, "\n");
 }
 
@@ -1931,37 +1905,45 @@
 do {								\
   if (yydebug)							\
     yy_stack_print ((Bottom), (Top));				\
-} while (0)
+} while (YYID (0))
 
 
 /*------------------------------------------------.
 | Report that the YYRULE is going to be reduced.  |
 `------------------------------------------------*/
 
-#if defined (__STDC__) || defined (__cplusplus)
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
 static void
-yy_reduce_print (int yyrule)
+yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
 #else
 static void
-yy_reduce_print (yyrule)
+yy_reduce_print (yyvsp, yyrule)
+    YYSTYPE *yyvsp;
     int yyrule;
 #endif
 {
+  int yynrhs = yyr2[yyrule];
   int yyi;
   unsigned long int yylno = yyrline[yyrule];
-  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ",
-             yyrule - 1, yylno);
-  /* Print the symbols being reduced, and their result.  */
-  for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
-    YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
-  YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]);
+  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+	     yyrule - 1, yylno);
+  /* The symbols being reduced.  */
+  for (yyi = 0; yyi < yynrhs; yyi++)
+    {
+      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
+      yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
+		       &(yyvsp[(yyi + 1) - (yynrhs)])
+		       		       );
+      YYFPRINTF (stderr, "\n");
+    }
 }
 
 # define YY_REDUCE_PRINT(Rule)		\
 do {					\
   if (yydebug)				\
-    yy_reduce_print (Rule);		\
-} while (0)
+    yy_reduce_print (yyvsp, Rule); \
+} while (YYID (0))
 
 /* Nonzero means print parse trace.  It is left uninitialized so that
    multiple parsers can coexist.  */
@@ -1995,42 +1977,44 @@
 #if YYERROR_VERBOSE
 
 # ifndef yystrlen
-#  if defined (__GLIBC__) && defined (_STRING_H)
+#  if defined __GLIBC__ && defined _STRING_H
 #   define yystrlen strlen
 #  else
 /* Return the length of YYSTR.  */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
 static YYSIZE_T
-#   if defined (__STDC__) || defined (__cplusplus)
 yystrlen (const char *yystr)
-#   else
+#else
+static YYSIZE_T
 yystrlen (yystr)
-     const char *yystr;
-#   endif
+    const char *yystr;
+#endif
 {
-  const char *yys = yystr;
-
-  while (*yys++ != '\0')
+  YYSIZE_T yylen;
+  for (yylen = 0; yystr[yylen]; yylen++)
     continue;
-
-  return yys - yystr - 1;
+  return yylen;
 }
 #  endif
 # endif
 
 # ifndef yystpcpy
-#  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
+#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
 #   define yystpcpy stpcpy
 #  else
 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
    YYDEST.  */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
 static char *
-#   if defined (__STDC__) || defined (__cplusplus)
 yystpcpy (char *yydest, const char *yysrc)
-#   else
+#else
+static char *
 yystpcpy (yydest, yysrc)
-     char *yydest;
-     const char *yysrc;
-#   endif
+    char *yydest;
+    const char *yysrc;
+#endif
 {
   char *yyd = yydest;
   const char *yys = yysrc;
@@ -2056,7 +2040,7 @@
 {
   if (*yystr == '"')
     {
-      size_t yyn = 0;
+      YYSIZE_T yyn = 0;
       char const *yyp = yystr;
 
       for (;;)
@@ -2091,53 +2075,123 @@
 }
 # endif
 
-#endif /* YYERROR_VERBOSE */
+/* Copy into YYRESULT an error message about the unexpected token
+   YYCHAR while in state YYSTATE.  Return the number of bytes copied,
+   including the terminating null byte.  If YYRESULT is null, do not
+   copy anything; just return the number of bytes that would be
+   copied.  As a special case, return 0 if an ordinary "syntax error"
+   message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
+   size calculation.  */
+static YYSIZE_T
+yysyntax_error (char *yyresult, int yystate, int yychar)
+{
+  int yyn = yypact[yystate];
 
-
+  if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
+    return 0;
+  else
+    {
+      int yytype = YYTRANSLATE (yychar);
+      YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
+      YYSIZE_T yysize = yysize0;
+      YYSIZE_T yysize1;
+      int yysize_overflow = 0;
+      enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+      char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+      int yyx;
 
-#if YYDEBUG
-/*--------------------------------.
-| Print this symbol on YYOUTPUT.  |
-`--------------------------------*/
+# if 0
+      /* This is so xgettext sees the translatable formats that are
+	 constructed on the fly.  */
+      YY_("syntax error, unexpected %s");
+      YY_("syntax error, unexpected %s, expecting %s");
+      YY_("syntax error, unexpected %s, expecting %s or %s");
+      YY_("syntax error, unexpected %s, expecting %s or %s or %s");
+      YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
+# endif
+      char *yyfmt;
+      char const *yyf;
+      static char const yyunexpected[] = "syntax error, unexpected %s";
+      static char const yyexpecting[] = ", expecting %s";
+      static char const yyor[] = " or %s";
+      char yyformat[sizeof yyunexpected
+		    + sizeof yyexpecting - 1
+		    + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
+		       * (sizeof yyor - 1))];
+      char const *yyprefix = yyexpecting;
 
-#if defined (__STDC__) || defined (__cplusplus)
-static void
-yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
-#else
-static void
-yysymprint (yyoutput, yytype, yyvaluep)
-    FILE *yyoutput;
-    int yytype;
-    YYSTYPE *yyvaluep;
-#endif
-{
-  /* Pacify ``unused variable'' warnings.  */
-  (void) yyvaluep;
+      /* Start YYX at -YYN if negative to avoid negative indexes in
+	 YYCHECK.  */
+      int yyxbegin = yyn < 0 ? -yyn : 0;
 
-  if (yytype < YYNTOKENS)
-    YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
-  else
-    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+      /* Stay within bounds of both yycheck and yytname.  */
+      int yychecklim = YYLAST - yyn + 1;
+      int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+      int yycount = 1;
 
+      yyarg[0] = yytname[yytype];
+      yyfmt = yystpcpy (yyformat, yyunexpected);
 
-# ifdef YYPRINT
-  if (yytype < YYNTOKENS)
-    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
-# endif
-  switch (yytype)
-    {
-      default:
-        break;
+      for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+	if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+	  {
+	    if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+	      {
+		yycount = 1;
+		yysize = yysize0;
+		yyformat[sizeof yyunexpected - 1] = '\0';
+		break;
+	      }
+	    yyarg[yycount++] = yytname[yyx];
+	    yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+	    yysize_overflow |= (yysize1 < yysize);
+	    yysize = yysize1;
+	    yyfmt = yystpcpy (yyfmt, yyprefix);
+	    yyprefix = yyor;
+	  }
+
+      yyf = YY_(yyformat);
+      yysize1 = yysize + yystrlen (yyf);
+      yysize_overflow |= (yysize1 < yysize);
+      yysize = yysize1;
+
+      if (yysize_overflow)
+	return YYSIZE_MAXIMUM;
+
+      if (yyresult)
+	{
+	  /* Avoid sprintf, as that infringes on the user's name space.
+	     Don't have undefined behavior even if the translation
+	     produced a string with the wrong number of "%s"s.  */
+	  char *yyp = yyresult;
+	  int yyi = 0;
+	  while ((*yyp = *yyf) != '\0')
+	    {
+	      if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
+		{
+		  yyp += yytnamerr (yyp, yyarg[yyi++]);
+		  yyf += 2;
+		}
+	      else
+		{
+		  yyp++;
+		  yyf++;
+		}
+	    }
+	}
+      return yysize;
     }
-  YYFPRINTF (yyoutput, ")");
 }
+#endif /* YYERROR_VERBOSE */
+
 
-#endif /* ! YYDEBUG */
 /*-----------------------------------------------.
 | Release the memory associated to this symbol.  |
 `-----------------------------------------------*/
 
-#if defined (__STDC__) || defined (__cplusplus)
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
 static void
 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
 #else
@@ -2148,8 +2202,7 @@
     YYSTYPE *yyvaluep;
 #endif
 {
-  /* Pacify ``unused variable'' warnings.  */
-  (void) yyvaluep;
+  YYUSE (yyvaluep);
 
   if (!yymsg)
     yymsg = "Deleting";
@@ -2159,21 +2212,19 @@
     {
 
       default:
-        break;
+	break;
     }
 }
-
 
 /* Prevent warnings from -Wmissing-prototypes.  */
-
 #ifdef YYPARSE_PARAM
-# if defined (__STDC__) || defined (__cplusplus)
+#if defined __STDC__ || defined __cplusplus
 int yyparse (void *YYPARSE_PARAM);
-# else
+#else
 int yyparse ();
-# endif
+#endif
 #else /* ! YYPARSE_PARAM */
-#if defined (__STDC__) || defined (__cplusplus)
+#if defined __STDC__ || defined __cplusplus
 int yyparse (void);
 #else
 int yyparse ();
@@ -2181,11 +2232,10 @@
 #endif /* ! YYPARSE_PARAM */
 
 
-
-/* The look-ahead symbol.  */
+/* The lookahead symbol.  */
 int yychar;
 
-/* The semantic value of the look-ahead symbol.  */
+/* The semantic value of the lookahead symbol.  */
 YYSTYPE yylval;
 
 /* Number of syntax errors so far.  */
@@ -2193,82 +2243,94 @@
 
 
 
-/*----------.
-| yyparse.  |
-`----------*/
+/*-------------------------.
+| yyparse or yypush_parse.  |
+`-------------------------*/
 
 #ifdef YYPARSE_PARAM
-# if defined (__STDC__) || defined (__cplusplus)
-int yyparse (void *YYPARSE_PARAM)
-# else
-int yyparse (YYPARSE_PARAM)
-  void *YYPARSE_PARAM;
-# endif
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void *YYPARSE_PARAM)
+#else
+int
+yyparse (YYPARSE_PARAM)
+    void *YYPARSE_PARAM;
+#endif
 #else /* ! YYPARSE_PARAM */
-#if defined (__STDC__) || defined (__cplusplus)
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
 int
 yyparse (void)
 #else
 int
 yyparse ()
-    ;
+
 #endif
 #endif
 {
-  
-  int yystate;
-  int yyn;
-  int yyresult;
-  /* Number of tokens to shift before error messages enabled.  */
-  int yyerrstatus;
-  /* Look-ahead token as an internal (translated) token number.  */
-  int yytoken = 0;
 
-  /* Three stacks and their tools:
-     `yyss': related to states,
-     `yyvs': related to semantic values,
-     `yyls': related to locations.
 
-     Refer to the stacks thru separate pointers, to allow yyoverflow
-     to reallocate them elsewhere.  */
+    int yystate;
+    /* Number of tokens to shift before error messages enabled.  */
+    int yyerrstatus;
 
-  /* The state stack.  */
-  short int yyssa[YYINITDEPTH];
-  short int *yyss = yyssa;
-  short int *yyssp;
+    /* The stacks and their tools:
+       `yyss': related to states.
+       `yyvs': related to semantic values.
 
-  /* The semantic value stack.  */
-  YYSTYPE yyvsa[YYINITDEPTH];
-  YYSTYPE *yyvs = yyvsa;
-  YYSTYPE *yyvsp;
+       Refer to the stacks thru separate pointers, to allow yyoverflow
+       to reallocate them elsewhere.  */
 
+    /* The state stack.  */
+    yytype_int16 yyssa[YYINITDEPTH];
+    yytype_int16 *yyss;
+    yytype_int16 *yyssp;
 
+    /* The semantic value stack.  */
+    YYSTYPE yyvsa[YYINITDEPTH];
+    YYSTYPE *yyvs;
+    YYSTYPE *yyvsp;
 
-#define YYPOPSTACK   (yyvsp--, yyssp--)
+    YYSIZE_T yystacksize;
 
-  YYSIZE_T yystacksize = YYINITDEPTH;
-
+  int yyn;
+  int yyresult;
+  /* Lookahead token as an internal (translated) token number.  */
+  int yytoken;
   /* The variables used to return semantic value and location from the
      action routines.  */
   YYSTYPE yyval;
 
+#if YYERROR_VERBOSE
+  /* Buffer for error messages, and its allocated size.  */
+  char yymsgbuf[128];
+  char *yymsg = yymsgbuf;
+  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
 
-  /* When reducing, the number of symbols on the RHS of the reduced
-     rule.  */
-  int yylen;
+#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
 
+  /* The number of symbols on the RHS of the reduced rule.
+     Keep to zero when no symbol should be popped.  */
+  int yylen = 0;
+
+  yytoken = 0;
+  yyss = yyssa;
+  yyvs = yyvsa;
+  yystacksize = YYINITDEPTH;
+
   YYDPRINTF ((stderr, "Starting parse\n"));
 
   yystate = 0;
   yyerrstatus = 0;
   yynerrs = 0;
-  yychar = YYEMPTY;		/* Cause a token to be read.  */
+  yychar = YYEMPTY; /* Cause a token to be read.  */
 
   /* Initialize stack pointers.
      Waste one element of value and location stack
      so that they stay on the same level as the state stack.
      The wasted elements are never initialized.  */
-
   yyssp = yyss;
   yyvsp = yyvs;
 
@@ -2279,8 +2341,7 @@
 `------------------------------------------------------------*/
  yynewstate:
   /* In all cases, when you get here, the value and location stacks
-     have just been pushed. so pushing a state here evens the stacks.
-     */
+     have just been pushed.  So pushing a state here evens the stacks.  */
   yyssp++;
 
  yysetstate:
@@ -2293,13 +2354,12 @@
 
 #ifdef yyoverflow
       {
-	/* Give user a chance to reallocate the stack. Use copies of
+	/* Give user a chance to reallocate the stack.  Use copies of
 	   these so that the &'s don't force the real ones into
 	   memory.  */
 	YYSTYPE *yyvs1 = yyvs;
-	short int *yyss1 = yyss;
+	yytype_int16 *yyss1 = yyss;
 
-
 	/* Each stack pointer address is followed by the size of the
 	   data in use in that stack, in bytes.  This used to be a
 	   conditional around just the two extra args, but that might
@@ -2307,7 +2367,6 @@
 	yyoverflow (YY_("memory exhausted"),
 		    &yyss1, yysize * sizeof (*yyssp),
 		    &yyvs1, yysize * sizeof (*yyvsp),
-
 		    &yystacksize);
 
 	yyss = yyss1;
@@ -2325,14 +2384,13 @@
 	yystacksize = YYMAXDEPTH;
 
       {
-	short int *yyss1 = yyss;
+	yytype_int16 *yyss1 = yyss;
 	union yyalloc *yyptr =
 	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
 	if (! yyptr)
 	  goto yyexhaustedlab;
-	YYSTACK_RELOCATE (yyss);
-	YYSTACK_RELOCATE (yyvs);
-
+	YYSTACK_RELOCATE (yyss_alloc, yyss);
+	YYSTACK_RELOCATE (yyvs_alloc, yyvs);
 #  undef YYSTACK_RELOCATE
 	if (yyss1 != yyssa)
 	  YYSTACK_FREE (yyss1);
@@ -2343,7 +2401,6 @@
       yyssp = yyss + yysize - 1;
       yyvsp = yyvs + yysize - 1;
 
-
       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
 		  (unsigned long int) yystacksize));
 
@@ -2353,6 +2410,9 @@
 
   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
 
+  if (yystate == YYFINAL)
+    YYACCEPT;
+
   goto yybackup;
 
 /*-----------.
@@ -2360,19 +2420,17 @@
 `-----------*/
 yybackup:
 
-/* Do appropriate processing given the current state.  */
-/* Read a look-ahead token if we need one and don't already have one.  */
-/* yyresume: */
+  /* Do appropriate processing given the current state.  Read a
+     lookahead token if we need one and don't already have one.  */
 
-  /* First try to decide what to do without reference to look-ahead token.  */
-
+  /* First try to decide what to do without reference to lookahead token.  */
   yyn = yypact[yystate];
   if (yyn == YYPACT_NINF)
     goto yydefault;
 
-  /* Not known => get a look-ahead token if don't already have one.  */
+  /* Not known => get a lookahead token if don't already have one.  */
 
-  /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
+  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
   if (yychar == YYEMPTY)
     {
       YYDPRINTF ((stderr, "Reading a token: "));
@@ -2404,25 +2462,20 @@
       goto yyreduce;
     }
 
-  if (yyn == YYFINAL)
-    YYACCEPT;
+  /* Count tokens shifted since error; after three, turn off error
+     status.  */
+  if (yyerrstatus)
+    yyerrstatus--;
 
-  /* Shift the look-ahead token.  */
+  /* Shift the lookahead token.  */
   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
 
-  /* Discard the token being shifted unless it is eof.  */
-  if (yychar != YYEOF)
-    yychar = YYEMPTY;
+  /* Discard the shifted token.  */
+  yychar = YYEMPTY;
 
+  yystate = yyn;
   *++yyvsp = yylval;
 
-
-  /* Count tokens shifted since error; after three, turn off error
-     status.  */
-  if (yyerrstatus)
-    yyerrstatus--;
-
-  yystate = yyn;
   goto yynewstate;
 
 
@@ -2458,1640 +2511,2204 @@
   switch (yyn)
     {
         case 2:
-#line 347 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 326 "parser.y"
     { fix_incomplete();
-						  check_statements((yyvsp[0].stmt_list), FALSE);
-						  check_all_user_types((yyvsp[0].stmt_list));
-						  write_header((yyvsp[0].stmt_list));
-						  write_id_data((yyvsp[0].stmt_list));
-						  write_proxies((yyvsp[0].stmt_list));
-						  write_client((yyvsp[0].stmt_list));
-						  write_server((yyvsp[0].stmt_list));
-						  write_dlldata((yyvsp[0].stmt_list));
-						  write_local_stubs((yyvsp[0].stmt_list));
+						  check_statements((yyvsp[(1) - (1)].stmt_list), FALSE);
+						  check_all_user_types((yyvsp[(1) - (1)].stmt_list));
+						  write_header((yyvsp[(1) - (1)].stmt_list));
+						  write_id_data((yyvsp[(1) - (1)].stmt_list));
+						  write_proxies((yyvsp[(1) - (1)].stmt_list));
+						  write_client((yyvsp[(1) - (1)].stmt_list));
+						  write_server((yyvsp[(1) - (1)].stmt_list));
+						  write_dlldata((yyvsp[(1) - (1)].stmt_list));
+						  write_local_stubs((yyvsp[(1) - (1)].stmt_list));
 						;}
     break;
 
   case 3:
-#line 360 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 339 "parser.y"
     { (yyval.stmt_list) = NULL; ;}
     break;
 
   case 4:
-#line 361 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_reference((yyvsp[0].type))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 340 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_reference((yyvsp[(2) - (2)].type))); ;}
     break;
 
   case 5:
-#line 362 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_type_decl((yyvsp[0].type))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 341 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_type_decl((yyvsp[(2) - (2)].type))); ;}
     break;
 
   case 6:
-#line 363 "parser.y"
-    { (yyval.stmt_list) = (yyvsp[-2].stmt_list);
-						  reg_type((yyvsp[-1].type), (yyvsp[-1].type)->name, 0);
+
+/* Line 1455 of yacc.c  */
+#line 342 "parser.y"
+    { (yyval.stmt_list) = (yyvsp[(1) - (3)].stmt_list);
+						  reg_type((yyvsp[(2) - (3)].type), (yyvsp[(2) - (3)].type)->name, 0);
 						;}
     break;
 
   case 7:
-#line 366 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_type_decl((yyvsp[0].type)));
-						  reg_type((yyvsp[0].type), (yyvsp[0].type)->name, 0);
+
+/* Line 1455 of yacc.c  */
+#line 345 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_type_decl((yyvsp[(2) - (2)].type)));
+						  reg_type((yyvsp[(2) - (2)].type), (yyvsp[(2) - (2)].type)->name, 0);
 						;}
     break;
 
   case 8:
-#line 369 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_module((yyvsp[0].type))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 348 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_module((yyvsp[(2) - (2)].type))); ;}
     break;
 
   case 9:
-#line 370 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_library((yyvsp[0].typelib))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 349 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_library((yyvsp[(2) - (2)].typelib))); ;}
     break;
 
   case 10:
-#line 371 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), (yyvsp[0].statement)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 350 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), (yyvsp[(2) - (2)].statement)); ;}
     break;
 
   case 11:
-#line 374 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 353 "parser.y"
     { (yyval.stmt_list) = NULL; ;}
     break;
 
   case 12:
-#line 375 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_reference((yyvsp[0].type))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 354 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_reference((yyvsp[(2) - (2)].type))); ;}
     break;
 
   case 13:
-#line 376 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_type_decl((yyvsp[0].type))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 355 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_type_decl((yyvsp[(2) - (2)].type))); ;}
     break;
 
   case 14:
-#line 377 "parser.y"
-    { (yyval.stmt_list) = (yyvsp[-2].stmt_list); reg_type((yyvsp[-1].type), (yyvsp[-1].type)->name, 0); ;}
+
+/* Line 1455 of yacc.c  */
+#line 356 "parser.y"
+    { (yyval.stmt_list) = (yyvsp[(1) - (3)].stmt_list); reg_type((yyvsp[(2) - (3)].type), (yyvsp[(2) - (3)].type)->name, 0); ;}
     break;
 
   case 15:
-#line 378 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_type_decl((yyvsp[0].type)));
-						  reg_type((yyvsp[0].type), (yyvsp[0].type)->name, 0);
+
+/* Line 1455 of yacc.c  */
+#line 357 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_type_decl((yyvsp[(2) - (2)].type)));
+						  reg_type((yyvsp[(2) - (2)].type), (yyvsp[(2) - (2)].type)->name, 0);
 						;}
     break;
 
   case 16:
-#line 381 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_module((yyvsp[0].type))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 360 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_module((yyvsp[(2) - (2)].type))); ;}
     break;
 
   case 17:
-#line 382 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), (yyvsp[0].statement)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 361 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), (yyvsp[(2) - (2)].statement)); ;}
     break;
 
   case 18:
-#line 383 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_importlib((yyvsp[0].str))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 362 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_importlib((yyvsp[(2) - (2)].str))); ;}
     break;
 
   case 19:
-#line 384 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), make_statement_library((yyvsp[0].typelib))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 363 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), make_statement_library((yyvsp[(2) - (2)].typelib))); ;}
     break;
 
   case 20:
-#line 387 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 366 "parser.y"
     { (yyval.stmt_list) = NULL; ;}
     break;
 
   case 21:
-#line 388 "parser.y"
-    { (yyval.stmt_list) = append_statement((yyvsp[-1].stmt_list), (yyvsp[0].statement)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 367 "parser.y"
+    { (yyval.stmt_list) = append_statement((yyvsp[(1) - (2)].stmt_list), (yyvsp[(2) - (2)].statement)); ;}
     break;
 
   case 24:
-#line 396 "parser.y"
-    { (yyval.statement) = make_statement_cppquote((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 375 "parser.y"
+    { (yyval.statement) = make_statement_cppquote((yyvsp[(1) - (1)].str)); ;}
     break;
 
   case 25:
-#line 397 "parser.y"
-    { (yyval.statement) = make_statement_type_decl((yyvsp[-1].type)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 376 "parser.y"
+    { (yyval.statement) = make_statement_type_decl((yyvsp[(1) - (2)].type)); ;}
     break;
 
   case 26:
-#line 398 "parser.y"
-    { (yyval.statement) = make_statement_declaration((yyvsp[-1].var)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 377 "parser.y"
+    { (yyval.statement) = make_statement_declaration((yyvsp[(1) - (2)].var)); ;}
     break;
 
   case 27:
-#line 399 "parser.y"
-    { (yyval.statement) = make_statement_import((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 378 "parser.y"
+    { (yyval.statement) = make_statement_import((yyvsp[(1) - (1)].str)); ;}
     break;
 
   case 28:
-#line 400 "parser.y"
-    { (yyval.statement) = (yyvsp[-1].statement); ;}
+
+/* Line 1455 of yacc.c  */
+#line 379 "parser.y"
+    { (yyval.statement) = (yyvsp[(1) - (2)].statement); ;}
     break;
 
   case 32:
-#line 407 "parser.y"
-    { (yyval.type) = (yyvsp[0].type); (yyval.type)->attrs = check_enum_attrs((yyvsp[-1].attr_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 386 "parser.y"
+    { (yyval.type) = (yyvsp[(2) - (2)].type); (yyval.type)->attrs = check_enum_attrs((yyvsp[(1) - (2)].attr_list)); ;}
     break;
 
   case 33:
-#line 408 "parser.y"
-    { (yyval.type) = (yyvsp[0].type); (yyval.type)->attrs = check_struct_attrs((yyvsp[-1].attr_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 387 "parser.y"
+    { (yyval.type) = (yyvsp[(2) - (2)].type); (yyval.type)->attrs = check_struct_attrs((yyvsp[(1) - (2)].attr_list)); ;}
     break;
 
   case 34:
-#line 409 "parser.y"
-    { (yyval.type) = (yyvsp[0].type); (yyval.type)->attrs = check_union_attrs((yyvsp[-1].attr_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 388 "parser.y"
+    { (yyval.type) = (yyvsp[(2) - (2)].type); (yyval.type)->attrs = check_union_attrs((yyvsp[(1) - (2)].attr_list)); ;}
     break;
 
   case 35:
-#line 412 "parser.y"
-    { (yyval.str) = (yyvsp[-1].str); ;}
+
+/* Line 1455 of yacc.c  */
+#line 391 "parser.y"
+    { (yyval.str) = (yyvsp[(3) - (4)].str); ;}
     break;
 
   case 36:
-#line 414 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 393 "parser.y"
     { assert(yychar == YYEMPTY);
 						  (yyval.import) = xmalloc(sizeof(struct _import_t));
-						  (yyval.import)->name = (yyvsp[-1].str);
-						  (yyval.import)->import_performed = do_import((yyvsp[-1].str));
+						  (yyval.import)->name = (yyvsp[(2) - (3)].str);
+						  (yyval.import)->import_performed = do_import((yyvsp[(2) - (3)].str));
 						  if (!(yyval.import)->import_performed) yychar = aEOF;
 						;}
     break;
 
   case 37:
-#line 422 "parser.y"
-    { (yyval.str) = (yyvsp[-2].import)->name;
-						  if ((yyvsp[-2].import)->import_performed) pop_import();
-						  free((yyvsp[-2].import));
+
+/* Line 1455 of yacc.c  */
+#line 401 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (3)].import)->name;
+						  if ((yyvsp[(1) - (3)].import)->import_performed) pop_import();
+						  free((yyvsp[(1) - (3)].import));
 						;}
     break;
 
   case 38:
-#line 429 "parser.y"
-    { (yyval.str) = (yyvsp[-2].str); if(!parse_only) add_importlib((yyvsp[-2].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 408 "parser.y"
+    { (yyval.str) = (yyvsp[(3) - (5)].str); if(!parse_only) add_importlib((yyvsp[(3) - (5)].str)); ;}
     break;
 
   case 39:
-#line 432 "parser.y"
-    { (yyval.str) = (yyvsp[0].str); ;}
+
+/* Line 1455 of yacc.c  */
+#line 411 "parser.y"
+    { (yyval.str) = (yyvsp[(2) - (2)].str); ;}
     break;
 
   case 40:
-#line 434 "parser.y"
-    { (yyval.typelib) = make_library((yyvsp[-1].str), check_library_attrs((yyvsp[-1].str), (yyvsp[-2].attr_list)));
+
+/* Line 1455 of yacc.c  */
+#line 413 "parser.y"
+    { (yyval.typelib) = make_library((yyvsp[(2) - (3)].str), check_library_attrs((yyvsp[(2) - (3)].str), (yyvsp[(1) - (3)].attr_list)));
 						  if (!parse_only) start_typelib((yyval.typelib));
 						;}
     break;
 
   case 41:
-#line 439 "parser.y"
-    { (yyval.typelib) = (yyvsp[-3].typelib);
-						  (yyval.typelib)->stmts = (yyvsp[-2].stmt_list);
+
+/* Line 1455 of yacc.c  */
+#line 418 "parser.y"
+    { (yyval.typelib) = (yyvsp[(1) - (4)].typelib);
+						  (yyval.typelib)->stmts = (yyvsp[(2) - (4)].stmt_list);
 						  if (!parse_only) end_typelib();
 						;}
     break;
 
   case 42:
-#line 445 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 424 "parser.y"
     { (yyval.var_list) = NULL; ;}
     break;
 
   case 44:
-#line 449 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 428 "parser.y"
     { (yyval.var_list) = NULL; ;}
     break;
 
   case 45:
-#line 452 "parser.y"
-    { check_arg((yyvsp[0].var)); (yyval.var_list) = append_var( NULL, (yyvsp[0].var) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 431 "parser.y"
+    { check_arg((yyvsp[(1) - (1)].var)); (yyval.var_list) = append_var( NULL, (yyvsp[(1) - (1)].var) ); ;}
     break;
 
   case 46:
-#line 453 "parser.y"
-    { check_arg((yyvsp[0].var)); (yyval.var_list) = append_var( (yyvsp[-2].var_list), (yyvsp[0].var)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 432 "parser.y"
+    { check_arg((yyvsp[(3) - (3)].var)); (yyval.var_list) = append_var( (yyvsp[(1) - (3)].var_list), (yyvsp[(3) - (3)].var)); ;}
     break;
 
   case 48:
-#line 458 "parser.y"
-    { (yyval.var) = (yyvsp[0].declarator)->var;
-						  (yyval.var)->attrs = (yyvsp[-2].attr_list);
-						  if ((yyvsp[-1].declspec)->stgclass != STG_NONE && (yyvsp[-1].declspec)->stgclass != STG_REGISTER)
+
+/* Line 1455 of yacc.c  */
+#line 437 "parser.y"
+    { (yyval.var) = (yyvsp[(3) - (3)].declarator)->var;
+						  (yyval.var)->attrs = (yyvsp[(1) - (3)].attr_list);
+						  if ((yyvsp[(2) - (3)].declspec)->stgclass != STG_NONE && (yyvsp[(2) - (3)].declspec)->stgclass != STG_REGISTER)
 						    error_loc("invalid storage class for function parameter\n");
-						  set_type((yyval.var), (yyvsp[-1].declspec), (yyvsp[0].declarator), TRUE);
-						  free((yyvsp[0].declarator));
+						  set_type((yyval.var), (yyvsp[(2) - (3)].declspec), (yyvsp[(3) - (3)].declarator), TRUE);
+						  free((yyvsp[(3) - (3)].declarator));
 						;}
     break;
 
   case 49:
-#line 465 "parser.y"
-    { (yyval.var) = (yyvsp[0].declarator)->var;
-						  if ((yyvsp[-1].declspec)->stgclass != STG_NONE && (yyvsp[-1].declspec)->stgclass != STG_REGISTER)
+
+/* Line 1455 of yacc.c  */
+#line 444 "parser.y"
+    { (yyval.var) = (yyvsp[(2) - (2)].declarator)->var;
+						  if ((yyvsp[(1) - (2)].declspec)->stgclass != STG_NONE && (yyvsp[(1) - (2)].declspec)->stgclass != STG_REGISTER)
 						    error_loc("invalid storage class for function parameter\n");
-						  set_type((yyval.var), (yyvsp[-1].declspec), (yyvsp[0].declarator), TRUE);
-						  free((yyvsp[0].declarator));
+						  set_type((yyval.var), (yyvsp[(1) - (2)].declspec), (yyvsp[(2) - (2)].declarator), TRUE);
+						  free((yyvsp[(2) - (2)].declarator));
 						;}
     break;
 
   case 50:
-#line 473 "parser.y"
-    { (yyval.expr) = (yyvsp[-1].expr); ;}
+
+/* Line 1455 of yacc.c  */
+#line 452 "parser.y"
+    { (yyval.expr) = (yyvsp[(2) - (3)].expr); ;}
     break;
 
   case 51:
-#line 474 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 453 "parser.y"
     { (yyval.expr) = make_expr(EXPR_VOID); ;}
     break;
 
   case 52:
-#line 477 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 456 "parser.y"
     { (yyval.attr_list) = NULL; ;}
     break;
 
   case 54:
-#line 482 "parser.y"
-    { (yyval.attr_list) = (yyvsp[-1].attr_list); ;}
+
+/* Line 1455 of yacc.c  */
+#line 461 "parser.y"
+    { (yyval.attr_list) = (yyvsp[(2) - (3)].attr_list); ;}
     break;
 
   case 55:
-#line 485 "parser.y"
-    { (yyval.attr_list) = append_attr( NULL, (yyvsp[0].attr) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 464 "parser.y"
+    { (yyval.attr_list) = append_attr( NULL, (yyvsp[(1) - (1)].attr) ); ;}
     break;
 
   case 56:
-#line 486 "parser.y"
-    { (yyval.attr_list) = append_attr( (yyvsp[-2].attr_list), (yyvsp[0].attr) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 465 "parser.y"
+    { (yyval.attr_list) = append_attr( (yyvsp[(1) - (3)].attr_list), (yyvsp[(3) - (3)].attr) ); ;}
     break;
 
   case 57:
-#line 487 "parser.y"
-    { (yyval.attr_list) = append_attr( (yyvsp[-3].attr_list), (yyvsp[0].attr) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 466 "parser.y"
+    { (yyval.attr_list) = append_attr( (yyvsp[(1) - (4)].attr_list), (yyvsp[(4) - (4)].attr) ); ;}
     break;
 
   case 58:
-#line 490 "parser.y"
-    { (yyval.str_list) = append_str( NULL, (yyvsp[0].str) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 469 "parser.y"
+    { (yyval.str_list) = append_str( NULL, (yyvsp[(1) - (1)].str) ); ;}
     break;
 
   case 59:
-#line 491 "parser.y"
-    { (yyval.str_list) = append_str( (yyvsp[-2].str_list), (yyvsp[0].str) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 470 "parser.y"
+    { (yyval.str_list) = append_str( (yyvsp[(1) - (3)].str_list), (yyvsp[(3) - (3)].str) ); ;}
     break;
 
   case 60:
-#line 494 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 473 "parser.y"
     { (yyval.attr) = NULL; ;}
     break;
 
   case 61:
-#line 495 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 474 "parser.y"
     { (yyval.attr) = make_attr(ATTR_AGGREGATABLE); ;}
     break;
 
   case 62:
-#line 496 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 475 "parser.y"
     { (yyval.attr) = make_attr(ATTR_APPOBJECT); ;}
     break;
 
   case 63:
-#line 497 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 476 "parser.y"
     { (yyval.attr) = make_attr(ATTR_ASYNC); ;}
     break;
 
   case 64:
-#line 498 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 477 "parser.y"
     { (yyval.attr) = make_attr(ATTR_AUTO_HANDLE); ;}
     break;
 
   case 65:
-#line 499 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 478 "parser.y"
     { (yyval.attr) = make_attr(ATTR_BINDABLE); ;}
     break;
 
   case 66:
-#line 500 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 479 "parser.y"
     { (yyval.attr) = make_attr(ATTR_BROADCAST); ;}
     break;
 
   case 67:
-#line 501 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_CALLAS, (yyvsp[-1].var)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 480 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_CALLAS, (yyvsp[(3) - (4)].var)); ;}
     break;
 
   case 68:
-#line 502 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_CASE, (yyvsp[-1].expr_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 481 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_CASE, (yyvsp[(3) - (4)].expr_list)); ;}
     break;
 
   case 69:
-#line 503 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 482 "parser.y"
     { (yyval.attr) = make_attrv(ATTR_CONTEXTHANDLE, 0); ;}
     break;
 
   case 70:
-#line 504 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 483 "parser.y"
     { (yyval.attr) = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ ;}
     break;
 
   case 71:
-#line 505 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 484 "parser.y"
     { (yyval.attr) = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ ;}
     break;
 
   case 72:
-#line 506 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 485 "parser.y"
     { (yyval.attr) = make_attr(ATTR_CONTROL); ;}
     break;
 
   case 73:
-#line 507 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 486 "parser.y"
     { (yyval.attr) = make_attr(ATTR_DEFAULT); ;}
     break;
 
   case 74:
-#line 508 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 487 "parser.y"
     { (yyval.attr) = make_attr(ATTR_DEFAULTCOLLELEM); ;}
     break;
 
   case 75:
-#line 509 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_DEFAULTVALUE, (yyvsp[-1].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 488 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_DEFAULTVALUE, (yyvsp[(3) - (4)].expr)); ;}
     break;
 
   case 76:
-#line 510 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 489 "parser.y"
     { (yyval.attr) = make_attr(ATTR_DEFAULTVTABLE); ;}
     break;
 
   case 77:
-#line 511 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 490 "parser.y"
     { (yyval.attr) = make_attr(ATTR_DISPLAYBIND); ;}
     break;
 
   case 78:
-#line 512 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_DLLNAME, (yyvsp[-1].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 491 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_DLLNAME, (yyvsp[(3) - (4)].str)); ;}
     break;
 
   case 79:
-#line 513 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 492 "parser.y"
     { (yyval.attr) = make_attr(ATTR_DUAL); ;}
     break;
 
   case 80:
-#line 514 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_ENDPOINT, (yyvsp[-1].str_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 493 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_ENDPOINT, (yyvsp[(3) - (4)].str_list)); ;}
     break;
 
   case 81:
-#line 515 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_ENTRY, (yyvsp[-1].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 494 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_ENTRY, (yyvsp[(3) - (4)].expr)); ;}
     break;
 
   case 82:
-#line 516 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 495 "parser.y"
     { (yyval.attr) = make_attr(ATTR_EXPLICIT_HANDLE); ;}
     break;
 
   case 83:
-#line 517 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 496 "parser.y"
     { (yyval.attr) = make_attr(ATTR_HANDLE); ;}
     break;
 
   case 84:
-#line 518 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_HELPCONTEXT, (yyvsp[-1].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 497 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_HELPCONTEXT, (yyvsp[(3) - (4)].expr)); ;}
     break;
 
   case 85:
-#line 519 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_HELPFILE, (yyvsp[-1].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 498 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_HELPFILE, (yyvsp[(3) - (4)].str)); ;}
     break;
 
   case 86:
-#line 520 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_HELPSTRING, (yyvsp[-1].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 499 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_HELPSTRING, (yyvsp[(3) - (4)].str)); ;}
     break;
 
   case 87:
-#line 521 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_HELPSTRINGCONTEXT, (yyvsp[-1].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 500 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_HELPSTRINGCONTEXT, (yyvsp[(3) - (4)].expr)); ;}
     break;
 
   case 88:
-#line 522 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_HELPSTRINGDLL, (yyvsp[-1].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 501 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_HELPSTRINGDLL, (yyvsp[(3) - (4)].str)); ;}
     break;
 
   case 89:
-#line 523 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 502 "parser.y"
     { (yyval.attr) = make_attr(ATTR_HIDDEN); ;}
     break;
 
   case 90:
-#line 524 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_ID, (yyvsp[-1].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 503 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_ID, (yyvsp[(3) - (4)].expr)); ;}
     break;
 
   case 91:
-#line 525 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 504 "parser.y"
     { (yyval.attr) = make_attr(ATTR_IDEMPOTENT); ;}
     break;
 
   case 92:
-#line 526 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_IIDIS, (yyvsp[-1].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 505 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_IIDIS, (yyvsp[(3) - (4)].expr)); ;}
     break;
 
   case 93:
-#line 527 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 506 "parser.y"
     { (yyval.attr) = make_attr(ATTR_IMMEDIATEBIND); ;}
     break;
 
   case 94:
-#line 528 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_IMPLICIT_HANDLE, (yyvsp[-1].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 507 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_IMPLICIT_HANDLE, (yyvsp[(4) - (5)].str)); ;}
     break;
 
   case 95:
-#line 529 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 508 "parser.y"
     { (yyval.attr) = make_attr(ATTR_IN); ;}
     break;
 
   case 96:
-#line 530 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 509 "parser.y"
     { (yyval.attr) = make_attr(ATTR_INPUTSYNC); ;}
     break;
 
   case 97:
-#line 531 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_LENGTHIS, (yyvsp[-1].expr_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 510 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_LENGTHIS, (yyvsp[(3) - (4)].expr_list)); ;}
     break;
 
   case 98:
-#line 532 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_LIBLCID, (yyvsp[-1].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 511 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_LIBLCID, (yyvsp[(3) - (4)].expr)); ;}
     break;
 
   case 99:
-#line 533 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 512 "parser.y"
     { (yyval.attr) = make_attr(ATTR_LOCAL); ;}
     break;
 
   case 100:
-#line 534 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 513 "parser.y"
     { (yyval.attr) = make_attr(ATTR_NONBROWSABLE); ;}
     break;
 
   case 101:
-#line 535 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 514 "parser.y"
     { (yyval.attr) = make_attr(ATTR_NONCREATABLE); ;}
     break;
 
   case 102:
-#line 536 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 515 "parser.y"
     { (yyval.attr) = make_attr(ATTR_NONEXTENSIBLE); ;}
     break;
 
   case 103:
-#line 537 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 516 "parser.y"
     { (yyval.attr) = make_attr(ATTR_OBJECT); ;}
     break;
 
   case 104:
-#line 538 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 517 "parser.y"
     { (yyval.attr) = make_attr(ATTR_ODL); ;}
     break;
 
   case 105:
-#line 539 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 518 "parser.y"
     { (yyval.attr) = make_attr(ATTR_OLEAUTOMATION); ;}
     break;
 
   case 106:
-#line 540 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 519 "parser.y"
     { (yyval.attr) = make_attr(ATTR_OPTIONAL); ;}
     break;
 
   case 107:
-#line 541 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 520 "parser.y"
     { (yyval.attr) = make_attr(ATTR_OUT); ;}
     break;
 
   case 108:
-#line 542 "parser.y"
-    { (yyval.attr) = make_attrv(ATTR_POINTERDEFAULT, (yyvsp[-1].num)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 521 "parser.y"
+    { (yyval.attr) = make_attrv(ATTR_POINTERDEFAULT, (yyvsp[(3) - (4)].num)); ;}
     break;
 
   case 109:
-#line 543 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 522 "parser.y"
     { (yyval.attr) = make_attr(ATTR_PROPGET); ;}
     break;
 
   case 110:
-#line 544 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 523 "parser.y"
     { (yyval.attr) = make_attr(ATTR_PROPPUT); ;}
     break;
 
   case 111:
-#line 545 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 524 "parser.y"
     { (yyval.attr) = make_attr(ATTR_PROPPUTREF); ;}
     break;
 
   case 112:
-#line 546 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 525 "parser.y"
     { (yyval.attr) = make_attr(ATTR_PUBLIC); ;}
     break;
 
   case 113:
-#line 548 "parser.y"
-    { expr_list_t *list = append_expr( NULL, (yyvsp[-3].expr) );
-						  list = append_expr( list, (yyvsp[-1].expr) );
+
+/* Line 1455 of yacc.c  */
+#line 527 "parser.y"
+    { expr_list_t *list = append_expr( NULL, (yyvsp[(3) - (6)].expr) );
+						  list = append_expr( list, (yyvsp[(5) - (6)].expr) );
 						  (yyval.attr) = make_attrp(ATTR_RANGE, list); ;}
     break;
 
   case 114:
-#line 551 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 530 "parser.y"
     { (yyval.attr) = make_attr(ATTR_READONLY); ;}
     break;
 
   case 115:
-#line 552 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 531 "parser.y"
     { (yyval.attr) = make_attr(ATTR_REQUESTEDIT); ;}
     break;
 
   case 116:
-#line 553 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 532 "parser.y"
     { (yyval.attr) = make_attr(ATTR_RESTRICTED); ;}
     break;
 
   case 117:
-#line 554 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 533 "parser.y"
     { (yyval.attr) = make_attr(ATTR_RETVAL); ;}
     break;
 
   case 118:
-#line 555 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_SIZEIS, (yyvsp[-1].expr_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 534 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_SIZEIS, (yyvsp[(3) - (4)].expr_list)); ;}
     break;
 
   case 119:
-#line 556 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 535 "parser.y"
     { (yyval.attr) = make_attr(ATTR_SOURCE); ;}
     break;
 
   case 120:
-#line 557 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 536 "parser.y"
     { (yyval.attr) = make_attr(ATTR_STRICTCONTEXTHANDLE); ;}
     break;
 
   case 121:
-#line 558 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 537 "parser.y"
     { (yyval.attr) = make_attr(ATTR_STRING); ;}
     break;
 
   case 122:
-#line 559 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_SWITCHIS, (yyvsp[-1].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 538 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_SWITCHIS, (yyvsp[(3) - (4)].expr)); ;}
     break;
 
   case 123:
-#line 560 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_SWITCHTYPE, (yyvsp[-1].type)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 539 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_SWITCHTYPE, (yyvsp[(3) - (4)].type)); ;}
     break;
 
   case 124:
-#line 561 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_TRANSMITAS, (yyvsp[-1].type)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 540 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_TRANSMITAS, (yyvsp[(3) - (4)].type)); ;}
     break;
 
   case 125:
-#line 562 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_UUID, (yyvsp[-1].uuid)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 541 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_UUID, (yyvsp[(3) - (4)].uuid)); ;}
     break;
 
   case 126:
-#line 563 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 542 "parser.y"
     { (yyval.attr) = make_attr(ATTR_V1ENUM); ;}
     break;
 
   case 127:
-#line 564 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 543 "parser.y"
     { (yyval.attr) = make_attr(ATTR_VARARG); ;}
     break;
 
   case 128:
-#line 565 "parser.y"
-    { (yyval.attr) = make_attrv(ATTR_VERSION, (yyvsp[-1].num)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 544 "parser.y"
+    { (yyval.attr) = make_attrv(ATTR_VERSION, (yyvsp[(3) - (4)].num)); ;}
     break;
 
   case 129:
-#line 566 "parser.y"
-    { (yyval.attr) = make_attrp(ATTR_WIREMARSHAL, (yyvsp[-1].type)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 545 "parser.y"
+    { (yyval.attr) = make_attrp(ATTR_WIREMARSHAL, (yyvsp[(3) - (4)].type)); ;}
     break;
 
   case 130:
-#line 567 "parser.y"
-    { (yyval.attr) = make_attrv(ATTR_POINTERTYPE, (yyvsp[0].num)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 546 "parser.y"
+    { (yyval.attr) = make_attrv(ATTR_POINTERTYPE, (yyvsp[(1) - (1)].num)); ;}
     break;
 
   case 132:
-#line 572 "parser.y"
-    { if (!is_valid_uuid((yyvsp[0].str)))
-						    error_loc("invalid UUID: %s\n", (yyvsp[0].str));
-						  (yyval.uuid) = parse_uuid((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 551 "parser.y"
+    { if (!is_valid_uuid((yyvsp[(1) - (1)].str)))
+						    error_loc("invalid UUID: %s\n", (yyvsp[(1) - (1)].str));
+						  (yyval.uuid) = parse_uuid((yyvsp[(1) - (1)].str)); ;}
     break;
 
   case 133:
-#line 577 "parser.y"
-    { (yyval.str) = (yyvsp[0].str); ;}
+
+/* Line 1455 of yacc.c  */
+#line 556 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (1)].str); ;}
     break;
 
   case 134:
-#line 578 "parser.y"
-    { (yyval.str) = (yyvsp[0].str); ;}
+
+/* Line 1455 of yacc.c  */
+#line 557 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (1)].str); ;}
     break;
 
   case 135:
-#line 579 "parser.y"
-    { (yyval.str) = (yyvsp[0].str); ;}
+
+/* Line 1455 of yacc.c  */
+#line 558 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (1)].str); ;}
     break;
 
   case 136:
-#line 580 "parser.y"
-    { (yyval.str) = (yyvsp[0].str); ;}
+
+/* Line 1455 of yacc.c  */
+#line 559 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (1)].str); ;}
     break;
 
   case 137:
-#line 583 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 562 "parser.y"
     { (yyval.var_list) = NULL; ;}
     break;
 
   case 138:
-#line 584 "parser.y"
-    { (yyval.var_list) = append_var( (yyvsp[-1].var_list), (yyvsp[0].var) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 563 "parser.y"
+    { (yyval.var_list) = append_var( (yyvsp[(1) - (2)].var_list), (yyvsp[(2) - (2)].var) ); ;}
     break;
 
   case 139:
-#line 587 "parser.y"
-    { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, (yyvsp[-2].expr) ));
-						  (yyval.var) = (yyvsp[0].var); if (!(yyval.var)) (yyval.var) = make_var(NULL);
+
+/* Line 1455 of yacc.c  */
+#line 566 "parser.y"
+    { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, (yyvsp[(2) - (4)].expr) ));
+						  (yyval.var) = (yyvsp[(4) - (4)].var); if (!(yyval.var)) (yyval.var) = make_var(NULL);
 						  (yyval.var)->attrs = append_attr( (yyval.var)->attrs, a );
 						;}
     break;
 
   case 140:
-#line 591 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 570 "parser.y"
     { attr_t *a = make_attr(ATTR_DEFAULT);
-						  (yyval.var) = (yyvsp[0].var); if (!(yyval.var)) (yyval.var) = make_var(NULL);
+						  (yyval.var) = (yyvsp[(3) - (3)].var); if (!(yyval.var)) (yyval.var) = make_var(NULL);
 						  (yyval.var)->attrs = append_attr( (yyval.var)->attrs, a );
 						;}
     break;
 
   case 141:
-#line 597 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 576 "parser.y"
     { (yyval.var_list) = NULL; ;}
     break;
 
   case 142:
-#line 598 "parser.y"
-    { (yyval.var_list) = (yyvsp[-1].var_list); ;}
+
+/* Line 1455 of yacc.c  */
+#line 577 "parser.y"
+    { (yyval.var_list) = (yyvsp[(1) - (2)].var_list); ;}
     break;
 
   case 144:
-#line 602 "parser.y"
-    { if (!(yyvsp[0].var)->eval)
-						    (yyvsp[0].var)->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
-                                                  (yyval.var_list) = append_var( NULL, (yyvsp[0].var) );
+
+/* Line 1455 of yacc.c  */
+#line 581 "parser.y"
+    { if (!(yyvsp[(1) - (1)].var)->eval)
+						    (yyvsp[(1) - (1)].var)->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
+                                                  (yyval.var_list) = append_var( NULL, (yyvsp[(1) - (1)].var) );
 						;}
     break;
 
   case 145:
-#line 606 "parser.y"
-    { if (!(yyvsp[0].var)->eval)
+
+/* Line 1455 of yacc.c  */
+#line 585 "parser.y"
+    { if (!(yyvsp[(3) - (3)].var)->eval)
                                                   {
                                                     var_t *last = LIST_ENTRY( list_tail((yyval.var_list)), var_t, entry );
-                                                    (yyvsp[0].var)->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
+                                                    (yyvsp[(3) - (3)].var)->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
                                                   }
-                                                  (yyval.var_list) = append_var( (yyvsp[-2].var_list), (yyvsp[0].var) );
+                                                  (yyval.var_list) = append_var( (yyvsp[(1) - (3)].var_list), (yyvsp[(3) - (3)].var) );
 						;}
     break;
 
   case 146:
-#line 615 "parser.y"
-    { (yyval.var) = reg_const((yyvsp[-2].var));
-						  (yyval.var)->eval = (yyvsp[0].expr);
-                                                  (yyval.var)->type = make_int(0);
+
+/* Line 1455 of yacc.c  */
+#line 594 "parser.y"
+    { (yyval.var) = reg_const((yyvsp[(1) - (3)].var));
+						  (yyval.var)->eval = (yyvsp[(3) - (3)].expr);
+                                                  (yyval.var)->type = type_new_int(TYPE_BASIC_INT, 0);
 						;}
     break;
 
   case 147:
-#line 619 "parser.y"
-    { (yyval.var) = reg_const((yyvsp[0].var));
-                                                  (yyval.var)->type = make_int(0);
+
+/* Line 1455 of yacc.c  */
+#line 598 "parser.y"
+    { (yyval.var) = reg_const((yyvsp[(1) - (1)].var));
+                                                  (yyval.var)->type = type_new_int(TYPE_BASIC_INT, 0);
 						;}
     break;
 
   case 148:
-#line 624 "parser.y"
-    { (yyval.type) = type_new_enum((yyvsp[-3].str), (yyvsp[-1].var_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 603 "parser.y"
+    { (yyval.type) = type_new_enum((yyvsp[(2) - (5)].str), TRUE, (yyvsp[(4) - (5)].var_list)); ;}
     break;
 
   case 149:
-#line 627 "parser.y"
-    { (yyval.expr_list) = append_expr( NULL, (yyvsp[0].expr) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 606 "parser.y"
+    { (yyval.expr_list) = append_expr( NULL, (yyvsp[(1) - (1)].expr) ); ;}
     break;
 
   case 150:
-#line 628 "parser.y"
-    { (yyval.expr_list) = append_expr( (yyvsp[-2].expr_list), (yyvsp[0].expr) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 607 "parser.y"
+    { (yyval.expr_list) = append_expr( (yyvsp[(1) - (3)].expr_list), (yyvsp[(3) - (3)].expr) ); ;}
     break;
 
   case 151:
-#line 641 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 620 "parser.y"
     { (yyval.expr) = make_expr(EXPR_VOID); ;}
     break;
 
   case 153:
-#line 645 "parser.y"
-    { (yyval.expr) = make_exprl(EXPR_NUM, (yyvsp[0].num)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 624 "parser.y"
+    { (yyval.expr) = make_exprl(EXPR_NUM, (yyvsp[(1) - (1)].num)); ;}
     break;
 
   case 154:
-#line 646 "parser.y"
-    { (yyval.expr) = make_exprl(EXPR_HEXNUM, (yyvsp[0].num)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 625 "parser.y"
+    { (yyval.expr) = make_exprl(EXPR_HEXNUM, (yyvsp[(1) - (1)].num)); ;}
     break;
 
   case 155:
-#line 647 "parser.y"
-    { (yyval.expr) = make_exprd(EXPR_DOUBLE, (yyvsp[0].dbl)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 626 "parser.y"
+    { (yyval.expr) = make_exprd(EXPR_DOUBLE, (yyvsp[(1) - (1)].dbl)); ;}
     break;
 
   case 156:
-#line 648 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 627 "parser.y"
     { (yyval.expr) = make_exprl(EXPR_TRUEFALSE, 0); ;}
     break;
 
   case 157:
-#line 649 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 628 "parser.y"
     { (yyval.expr) = make_exprl(EXPR_NUM, 0); ;}
     break;
 
   case 158:
-#line 650 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 629 "parser.y"
     { (yyval.expr) = make_exprl(EXPR_TRUEFALSE, 1); ;}
     break;
 
   case 159:
-#line 651 "parser.y"
-    { (yyval.expr) = make_exprs(EXPR_STRLIT, (yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 630 "parser.y"
+    { (yyval.expr) = make_exprs(EXPR_STRLIT, (yyvsp[(1) - (1)].str)); ;}
     break;
 
   case 160:
-#line 652 "parser.y"
-    { (yyval.expr) = make_exprs(EXPR_WSTRLIT, (yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 631 "parser.y"
+    { (yyval.expr) = make_exprs(EXPR_WSTRLIT, (yyvsp[(1) - (1)].str)); ;}
     break;
 
   case 161:
-#line 653 "parser.y"
-    { (yyval.expr) = make_exprs(EXPR_IDENTIFIER, (yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 632 "parser.y"
+    { (yyval.expr) = make_exprs(EXPR_IDENTIFIER, (yyvsp[(1) - (1)].str)); ;}
     break;
 
   case 162:
-#line 654 "parser.y"
-    { (yyval.expr) = make_expr3(EXPR_COND, (yyvsp[-4].expr), (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 633 "parser.y"
+    { (yyval.expr) = make_expr3(EXPR_COND, (yyvsp[(1) - (5)].expr), (yyvsp[(3) - (5)].expr), (yyvsp[(5) - (5)].expr)); ;}
     break;
 
   case 163:
-#line 655 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_LOGOR, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 634 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_LOGOR, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 164:
-#line 656 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_LOGAND, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 635 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_LOGAND, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 165:
-#line 657 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_OR , (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 636 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_OR , (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 166:
-#line 658 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_XOR, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 637 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_XOR, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 167:
-#line 659 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_AND, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 638 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_AND, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 168:
-#line 660 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_EQUALITY, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 639 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_EQUALITY, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 169:
-#line 661 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_INEQUALITY, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 640 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_INEQUALITY, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 170:
-#line 662 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_GTR, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 641 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_GTR, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 171:
-#line 663 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_LESS, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 642 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_LESS, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 172:
-#line 664 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_GTREQL, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 643 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_GTREQL, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 173:
-#line 665 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_LESSEQL, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 644 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_LESSEQL, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 174:
-#line 666 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_SHL, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 645 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_SHL, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 175:
-#line 667 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_SHR, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 646 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_SHR, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 176:
-#line 668 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_ADD, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 647 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_ADD, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 177:
-#line 669 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_SUB, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 648 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_SUB, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 178:
-#line 670 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_MOD, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 649 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_MOD, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 179:
-#line 671 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_MUL, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 650 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_MUL, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 180:
-#line 672 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_DIV, (yyvsp[-2].expr), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 651 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_DIV, (yyvsp[(1) - (3)].expr), (yyvsp[(3) - (3)].expr)); ;}
     break;
 
   case 181:
-#line 673 "parser.y"
-    { (yyval.expr) = make_expr1(EXPR_LOGNOT, (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 652 "parser.y"
+    { (yyval.expr) = make_expr1(EXPR_LOGNOT, (yyvsp[(2) - (2)].expr)); ;}
     break;
 
   case 182:
-#line 674 "parser.y"
-    { (yyval.expr) = make_expr1(EXPR_NOT, (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 653 "parser.y"
+    { (yyval.expr) = make_expr1(EXPR_NOT, (yyvsp[(2) - (2)].expr)); ;}
     break;
 
   case 183:
-#line 675 "parser.y"
-    { (yyval.expr) = make_expr1(EXPR_POS, (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 654 "parser.y"
+    { (yyval.expr) = make_expr1(EXPR_POS, (yyvsp[(2) - (2)].expr)); ;}
     break;
 
   case 184:
-#line 676 "parser.y"
-    { (yyval.expr) = make_expr1(EXPR_NEG, (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 655 "parser.y"
+    { (yyval.expr) = make_expr1(EXPR_NEG, (yyvsp[(2) - (2)].expr)); ;}
     break;
 
   case 185:
-#line 677 "parser.y"
-    { (yyval.expr) = make_expr1(EXPR_ADDRESSOF, (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 656 "parser.y"
+    { (yyval.expr) = make_expr1(EXPR_ADDRESSOF, (yyvsp[(2) - (2)].expr)); ;}
     break;
 
   case 186:
-#line 678 "parser.y"
-    { (yyval.expr) = make_expr1(EXPR_PPTR, (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 657 "parser.y"
+    { (yyval.expr) = make_expr1(EXPR_PPTR, (yyvsp[(2) - (2)].expr)); ;}
     break;
 
   case 187:
-#line 679 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_MEMBER, make_expr1(EXPR_PPTR, (yyvsp[-2].expr)), make_exprs(EXPR_IDENTIFIER, (yyvsp[0].str))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 658 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_MEMBER, make_expr1(EXPR_PPTR, (yyvsp[(1) - (3)].expr)), make_exprs(EXPR_IDENTIFIER, (yyvsp[(3) - (3)].str))); ;}
     break;
 
   case 188:
-#line 680 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_MEMBER, (yyvsp[-2].expr), make_exprs(EXPR_IDENTIFIER, (yyvsp[0].str))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 659 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_MEMBER, (yyvsp[(1) - (3)].expr), make_exprs(EXPR_IDENTIFIER, (yyvsp[(3) - (3)].str))); ;}
     break;
 
   case 189:
-#line 681 "parser.y"
-    { (yyval.expr) = make_exprt(EXPR_CAST, (yyvsp[-2].type), (yyvsp[0].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 660 "parser.y"
+    { (yyval.expr) = make_exprt(EXPR_CAST, (yyvsp[(2) - (4)].type), (yyvsp[(4) - (4)].expr)); ;}
     break;
 
   case 190:
-#line 682 "parser.y"
-    { (yyval.expr) = make_exprt(EXPR_SIZEOF, (yyvsp[-1].type), NULL); ;}
+
+/* Line 1455 of yacc.c  */
+#line 661 "parser.y"
+    { (yyval.expr) = make_exprt(EXPR_SIZEOF, (yyvsp[(3) - (4)].type), NULL); ;}
     break;
 
   case 191:
-#line 683 "parser.y"
-    { (yyval.expr) = make_expr2(EXPR_ARRAY, (yyvsp[-3].expr), (yyvsp[-1].expr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 662 "parser.y"
+    { (yyval.expr) = make_expr2(EXPR_ARRAY, (yyvsp[(1) - (4)].expr), (yyvsp[(3) - (4)].expr)); ;}
     break;
 
   case 192:
-#line 684 "parser.y"
-    { (yyval.expr) = (yyvsp[-1].expr); ;}
+
+/* Line 1455 of yacc.c  */
+#line 663 "parser.y"
+    { (yyval.expr) = (yyvsp[(2) - (3)].expr); ;}
     break;
 
   case 193:
-#line 687 "parser.y"
-    { (yyval.expr_list) = append_expr( NULL, (yyvsp[0].expr) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 666 "parser.y"
+    { (yyval.expr_list) = append_expr( NULL, (yyvsp[(1) - (1)].expr) ); ;}
     break;
 
   case 194:
-#line 688 "parser.y"
-    { (yyval.expr_list) = append_expr( (yyvsp[-2].expr_list), (yyvsp[0].expr) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 667 "parser.y"
+    { (yyval.expr_list) = append_expr( (yyvsp[(1) - (3)].expr_list), (yyvsp[(3) - (3)].expr) ); ;}
     break;
 
   case 195:
-#line 691 "parser.y"
-    { (yyval.expr) = (yyvsp[0].expr);
+
+/* Line 1455 of yacc.c  */
+#line 670 "parser.y"
+    { (yyval.expr) = (yyvsp[(1) - (1)].expr);
 						  if (!(yyval.expr)->is_const)
 						      error_loc("expression is not an integer constant\n");
 						;}
     break;
 
   case 196:
-#line 697 "parser.y"
-    { (yyval.expr) = (yyvsp[0].expr);
+
+/* Line 1455 of yacc.c  */
+#line 676 "parser.y"
+    { (yyval.expr) = (yyvsp[(1) - (1)].expr);
 						  if (!(yyval.expr)->is_const && (yyval.expr)->type != EXPR_STRLIT && (yyval.expr)->type != EXPR_WSTRLIT)
 						      error_loc("expression is not constant\n");
 						;}
     break;
 
   case 197:
-#line 703 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 682 "parser.y"
     { (yyval.var_list) = NULL; ;}
     break;
 
   case 198:
-#line 704 "parser.y"
-    { (yyval.var_list) = append_var_list((yyvsp[-1].var_list), (yyvsp[0].var_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 683 "parser.y"
+    { (yyval.var_list) = append_var_list((yyvsp[(1) - (2)].var_list), (yyvsp[(2) - (2)].var_list)); ;}
     break;
 
   case 199:
-#line 708 "parser.y"
-    { const char *first = LIST_ENTRY(list_head((yyvsp[-1].declarator_list)), declarator_t, entry)->var->name;
-						  check_field_attrs(first, (yyvsp[-3].attr_list));
-						  (yyval.var_list) = set_var_types((yyvsp[-3].attr_list), (yyvsp[-2].declspec), (yyvsp[-1].declarator_list));
+
+/* Line 1455 of yacc.c  */
+#line 687 "parser.y"
+    { const char *first = LIST_ENTRY(list_head((yyvsp[(3) - (4)].declarator_list)), declarator_t, entry)->var->name;
+						  check_field_attrs(first, (yyvsp[(1) - (4)].attr_list));
+						  (yyval.var_list) = set_var_types((yyvsp[(1) - (4)].attr_list), (yyvsp[(2) - (4)].declspec), (yyvsp[(3) - (4)].declarator_list));
 						;}
     break;
 
   case 200:
-#line 712 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 691 "parser.y"
     { var_t *v = make_var(NULL);
-						  v->type = (yyvsp[-1].type); v->attrs = (yyvsp[-2].attr_list);
+						  v->type = (yyvsp[(2) - (3)].type); v->attrs = (yyvsp[(1) - (3)].attr_list);
 						  (yyval.var_list) = append_var(NULL, v);
 						;}
     break;
 
   case 201:
-#line 719 "parser.y"
-    { (yyval.var) = (yyvsp[-1].var); ;}
+
+/* Line 1455 of yacc.c  */
+#line 698 "parser.y"
+    { (yyval.var) = (yyvsp[(1) - (2)].var); ;}
     break;
 
   case 202:
-#line 720 "parser.y"
-    { (yyval.var) = make_var(NULL); (yyval.var)->attrs = (yyvsp[-1].attr_list); ;}
+
+/* Line 1455 of yacc.c  */
+#line 699 "parser.y"
+    { (yyval.var) = make_var(NULL); (yyval.var)->attrs = (yyvsp[(1) - (2)].attr_list); ;}
     break;
 
   case 203:
-#line 723 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 702 "parser.y"
     { (yyval.var_list) = NULL; ;}
     break;
 
   case 204:
-#line 724 "parser.y"
-    { (yyval.var_list) = append_var( (yyvsp[-1].var_list), (yyvsp[0].var) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 703 "parser.y"
+    { (yyval.var_list) = append_var( (yyvsp[(1) - (2)].var_list), (yyvsp[(2) - (2)].var) ); ;}
     break;
 
   case 205:
-#line 728 "parser.y"
-    { (yyval.var) = (yyvsp[-1].var); ;}
+
+/* Line 1455 of yacc.c  */
+#line 707 "parser.y"
+    { (yyval.var) = (yyvsp[(1) - (2)].var); ;}
     break;
 
   case 206:
-#line 729 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 708 "parser.y"
     { (yyval.var) = NULL; ;}
     break;
 
   case 207:
-#line 732 "parser.y"
-    { (yyval.var) = (yyvsp[0].declarator)->var;
-						  (yyval.var)->attrs = check_field_attrs((yyval.var)->name, (yyvsp[-2].attr_list));
-						  set_type((yyval.var), (yyvsp[-1].declspec), (yyvsp[0].declarator), FALSE);
-						  free((yyvsp[0].declarator));
+
+/* Line 1455 of yacc.c  */
+#line 711 "parser.y"
+    { (yyval.var) = (yyvsp[(3) - (3)].declarator)->var;
+						  (yyval.var)->attrs = check_field_attrs((yyval.var)->name, (yyvsp[(1) - (3)].attr_list));
+						  set_type((yyval.var), (yyvsp[(2) - (3)].declspec), (yyvsp[(3) - (3)].declarator), FALSE);
+						  free((yyvsp[(3) - (3)].declarator));
 						;}
     break;
 
   case 208:
-#line 740 "parser.y"
-    { var_t *v = (yyvsp[0].declarator)->var;
-						  v->attrs = check_function_attrs(v->name, (yyvsp[-2].attr_list));
-						  set_type(v, (yyvsp[-1].declspec), (yyvsp[0].declarator), FALSE);
-						  free((yyvsp[0].declarator));
+
+/* Line 1455 of yacc.c  */
+#line 719 "parser.y"
+    { var_t *v = (yyvsp[(3) - (3)].declarator)->var;
+						  v->attrs = check_function_attrs(v->name, (yyvsp[(1) - (3)].attr_list));
+						  set_type(v, (yyvsp[(2) - (3)].declspec), (yyvsp[(3) - (3)].declarator), FALSE);
+						  free((yyvsp[(3) - (3)].declarator));
 						  (yyval.func) = make_func(v);
 						;}
     break;
 
   case 209:
-#line 750 "parser.y"
-    { (yyval.var) = (yyvsp[0].declarator)->var;
-						  (yyval.var)->attrs = (yyvsp[-2].attr_list);
-						  set_type((yyval.var), (yyvsp[-1].declspec), (yyvsp[0].declarator), FALSE);
-						  free((yyvsp[0].declarator));
+
+/* Line 1455 of yacc.c  */
+#line 729 "parser.y"
+    { (yyval.var) = (yyvsp[(3) - (3)].declarator)->var;
+						  (yyval.var)->attrs = (yyvsp[(1) - (3)].attr_list);
+						  set_type((yyval.var), (yyvsp[(2) - (3)].declspec), (yyvsp[(3) - (3)].declarator), FALSE);
+						  free((yyvsp[(3) - (3)].declarator));
 						;}
     break;
 
   case 210:
-#line 755 "parser.y"
-    { (yyval.var) = (yyvsp[0].declarator)->var;
-						  set_type((yyval.var), (yyvsp[-1].declspec), (yyvsp[0].declarator), FALSE);
-						  free((yyvsp[0].declarator));
+
+/* Line 1455 of yacc.c  */
+#line 734 "parser.y"
+    { (yyval.var) = (yyvsp[(2) - (2)].declarator)->var;
+						  set_type((yyval.var), (yyvsp[(1) - (2)].declspec), (yyvsp[(2) - (2)].declarator), FALSE);
+						  free((yyvsp[(2) - (2)].declarator));
 						;}
     break;
 
   case 211:
-#line 761 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 740 "parser.y"
     { (yyval.var) = NULL; ;}
     break;
 
   case 213:
-#line 765 "parser.y"
+
+/* Line 1455 of yacc.c  */
+#line 744 "parser.y"
     { (yyval.str) = NULL; ;}
     break;
 
   case 214:
-#line 766 "parser.y"
-    { (yyval.str) = (yyvsp[0].str); ;}
+
+/* Line 1455 of yacc.c  */
+#line 745 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (1)].str); ;}
     break;
 
   case 215:
-#line 767 "parser.y"
-    { (yyval.str) = (yyvsp[0].str); ;}
+
+/* Line 1455 of yacc.c  */
+#line 746 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (1)].str); ;}
     break;
 
   case 216:
-#line 770 "parser.y"
-    { (yyval.var) = make_var((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 749 "parser.y"
+    { (yyval.var) = make_var((yyvsp[(1) - (1)].str)); ;}
     break;
 
   case 217:
-#line 772 "parser.y"
-    { (yyval.var) = make_var((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 751 "parser.y"
+    { (yyval.var) = make_var((yyvsp[(1) - (1)].str)); ;}
     break;
 
   case 218:
-#line 775 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 754 "parser.y"
+    { (yyval.type) = find_type_or_error((yyvsp[(1) - (1)].str), 0); ;}
     break;
 
   case 219:
-#line 776 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 755 "parser.y"
+    { (yyval.type) = find_type_or_error((yyvsp[(1) - (1)].str), 0); ;}
     break;
 
   case 221:
-#line 778 "parser.y"
-    { (yyval.type) = (yyvsp[0].type); (yyval.type)->sign = 1; ;}
+
+/* Line 1455 of yacc.c  */
+#line 757 "parser.y"
+    { (yyval.type) = type_new_int(type_basic_get_type((yyvsp[(2) - (2)].type)), -1); ;}
     break;
 
   case 222:
-#line 779 "parser.y"
-    { (yyval.type) = (yyvsp[0].type); (yyval.type)->sign = -1;
-						  switch ((yyval.type)->type) {
-						  case RPC_FC_CHAR:  break;
-						  case RPC_FC_SMALL: (yyval.type)->type = RPC_FC_USMALL; break;
-						  case RPC_FC_SHORT: (yyval.type)->type = RPC_FC_USHORT; break;
-						  case RPC_FC_LONG:  (yyval.type)->type = RPC_FC_ULONG;  break;
-						  case RPC_FC_HYPER:
-						    if ((yyval.type)->name[0] == 'h') /* hyper, as opposed to __int64 */
-                                                    {
-                                                      (yyval.type) = type_new_alias((yyval.type), "MIDL_uhyper");
-                                                      (yyval.type)->sign = 0;
-                                                    }
-						    break;
-						  default: break;
-						  }
-						;}
+
+/* Line 1455 of yacc.c  */
+#line 758 "parser.y"
+    { (yyval.type) = type_new_int(type_basic_get_type((yyvsp[(2) - (2)].type)), 1); ;}
     break;
 
   case 223:
-#line 795 "parser.y"
-    { (yyval.type) = make_int(-1); ;}
+
+/* Line 1455 of yacc.c  */
+#line 759 "parser.y"
+    { (yyval.type) = type_new_int(TYPE_BASIC_INT, 1); ;}
     break;
 
   case 224:
-#line 796 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 760 "parser.y"
+    { (yyval.type) = find_type_or_error((yyvsp[(1) - (1)].str), 0); ;}
     break;
 
   case 225:
-#line 797 "parser.y"
-    { (yyval.type) = find_type("float", 0); ;}
+
+/* Line 1455 of yacc.c  */
+#line 761 "parser.y"
+    { (yyval.type) = find_type_or_error((yyvsp[(1) - (1)].str), 0); ;}
     break;
 
   case 226:
-#line 798 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 762 "parser.y"
+    { (yyval.type) = find_type_or_error((yyvsp[(1) - (1)].str), 0); ;}
     break;
 
   case 227:
-#line 799 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 763 "parser.y"
+    { (yyval.type) = find_type_or_error((yyvsp[(1) - (1)].str), 0); ;}
     break;
 
   case 228:
-#line 800 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 764 "parser.y"
+    { (yyval.type) = find_type_or_error((yyvsp[(1) - (1)].str), 0); ;}
     break;
 
-  case 229:
-#line 801 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+  case 231:
+
+/* Line 1455 of yacc.c  */
+#line 771 "parser.y"
+    { (yyval.type) = type_new_int(TYPE_BASIC_INT, 0); ;}
     break;
 
   case 232:
-#line 808 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 772 "parser.y"
+    { (yyval.type) = type_new_int(TYPE_BASIC_INT16, 0); ;}
     break;
 
   case 233:
-#line 809 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[-1].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 773 "parser.y"
+    { (yyval.type) = type_new_int(TYPE_BASIC_INT8, 0); ;}
     break;
 
   case 234:
-#line 810 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 774 "parser.y"
+    { (yyval.type) = type_new_int(TYPE_BASIC_INT32, 0); ;}
     break;
 
   case 235:
-#line 811 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[-1].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 775 "parser.y"
+    { (yyval.type) = type_new_int(TYPE_BASIC_HYPER, 0); ;}
     break;
 
   case 236:
-#line 812 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[-1].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 776 "parser.y"
+    { (yyval.type) = type_new_int(TYPE_BASIC_INT64, 0); ;}
     break;
 
   case 237:
-#line 813 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 777 "parser.y"
+    { (yyval.type) = type_new_int(TYPE_BASIC_CHAR, 0); ;}
     break;
 
   case 238:
-#line 814 "parser.y"
-    { (yyval.type) = make_builtin((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 780 "parser.y"
+    { (yyval.type) = type_new_coclass((yyvsp[(2) - (2)].str)); ;}
     break;
 
   case 239:
-#line 817 "parser.y"
-    { (yyval.type) = make_class((yyvsp[0].str)); ;}
-    break;
 
-  case 240:
-#line 818 "parser.y"
-    { (yyval.type) = find_type((yyvsp[0].str), 0);
-						  if ((yyval.type)->type != RPC_FC_COCLASS)
+/* Line 1455 of yacc.c  */
+#line 781 "parser.y"
+    { (yyval.type) = find_type((yyvsp[(2) - (2)].str), 0);
+						  if (type_get_type_detect_alias((yyval.type)) != TYPE_COCLASS)
 						    error_loc("%s was not declared a coclass at %s:%d\n",
-							      (yyvsp[0].str), (yyval.type)->loc_info.input_name,
+							      (yyvsp[(2) - (2)].str), (yyval.type)->loc_info.input_name,
 							      (yyval.type)->loc_info.line_number);
 						;}
     break;
 
-  case 241:
-#line 826 "parser.y"
-    { (yyval.type) = (yyvsp[0].type);
+  case 240:
+
+/* Line 1455 of yacc.c  */
+#line 789 "parser.y"
+    { (yyval.type) = (yyvsp[(2) - (2)].type);
 						  check_def((yyval.type));
-						  (yyval.type)->attrs = check_coclass_attrs((yyvsp[0].type)->name, (yyvsp[-1].attr_list));
+						  (yyval.type)->attrs = check_coclass_attrs((yyvsp[(2) - (2)].type)->name, (yyvsp[(1) - (2)].attr_list));
 						;}
     break;
 
+  case 241:
+
+/* Line 1455 of yacc.c  */
+#line 796 "parser.y"
+    { (yyval.type) = type_coclass_define((yyvsp[(1) - (5)].type), (yyvsp[(3) - (5)].ifref_list)); ;}
+    break;
+
   case 242:
-#line 833 "parser.y"
-    { (yyval.type) = type_coclass_define((yyvsp[-4].type), (yyvsp[-2].ifref_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 799 "parser.y"
+    { (yyval.ifref_list) = NULL; ;}
     break;
 
   case 243:
-#line 836 "parser.y"
-    { (yyval.ifref_list) = NULL; ;}
+
+/* Line 1455 of yacc.c  */
+#line 800 "parser.y"
+    { (yyval.ifref_list) = append_ifref( (yyvsp[(1) - (2)].ifref_list), (yyvsp[(2) - (2)].ifref) ); ;}
     break;
 
   case 244:
-#line 837 "parser.y"
-    { (yyval.ifref_list) = append_ifref( (yyvsp[-1].ifref_list), (yyvsp[0].ifref) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 804 "parser.y"
+    { (yyval.ifref) = make_ifref((yyvsp[(2) - (2)].type)); (yyval.ifref)->attrs = (yyvsp[(1) - (2)].attr_list); ;}
     break;
 
   case 245:
-#line 841 "parser.y"
-    { (yyval.ifref) = make_ifref((yyvsp[0].type)); (yyval.ifref)->attrs = (yyvsp[-1].attr_list); ;}
+
+/* Line 1455 of yacc.c  */
+#line 807 "parser.y"
+    { (yyval.type) = get_type(TYPE_INTERFACE, (yyvsp[(2) - (2)].str), 0); ;}
     break;
 
   case 246:
-#line 844 "parser.y"
-    { (yyval.type) = get_type(RPC_FC_IP, (yyvsp[0].str), 0); ;}
+
+/* Line 1455 of yacc.c  */
+#line 808 "parser.y"
+    { (yyval.type) = get_type(TYPE_INTERFACE, (yyvsp[(2) - (2)].str), 0); ;}
     break;
 
   case 247:
-#line 845 "parser.y"
-    { (yyval.type) = get_type(RPC_FC_IP, (yyvsp[0].str), 0); ;}
-    break;
 
-  case 248:
-#line 848 "parser.y"
+/* Line 1455 of yacc.c  */
+#line 811 "parser.y"
     { attr_t *attrs;
 						  is_object_interface = TRUE;
-						  (yyval.type) = (yyvsp[0].type);
+						  (yyval.type) = (yyvsp[(2) - (2)].type);
 						  check_def((yyval.type));
 						  attrs = make_attr(ATTR_DISPINTERFACE);
-						  (yyval.type)->attrs = append_attr( check_dispiface_attrs((yyvsp[0].type)->name, (yyvsp[-1].attr_list)), attrs );
+						  (yyval.type)->attrs = append_attr( check_dispiface_attrs((yyvsp[(2) - (2)].type)->name, (yyvsp[(1) - (2)].attr_list)), attrs );
 						  (yyval.type)->defined = TRUE;
 						;}
     break;
 
-  case 249:
-#line 858 "parser.y"
+  case 248:
+
+/* Line 1455 of yacc.c  */
+#line 821 "parser.y"
     { (yyval.var_list) = NULL; ;}
     break;
 
+  case 249:
+
+/* Line 1455 of yacc.c  */
+#line 822 "parser.y"
+    { (yyval.var_list) = append_var( (yyvsp[(1) - (3)].var_list), (yyvsp[(2) - (3)].var) ); ;}
+    break;
+
   case 250:
-#line 859 "parser.y"
-    { (yyval.var_list) = append_var( (yyvsp[-2].var_list), (yyvsp[-1].var) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 825 "parser.y"
+    { (yyval.stmt_list) = NULL; ;}
     break;
 
   case 251:
-#line 862 "parser.y"
-    { (yyval.stmt_list) = NULL; ;}
+
+/* Line 1455 of yacc.c  */
+#line 826 "parser.y"
+    { (yyval.stmt_list) = append_func( (yyvsp[(1) - (3)].stmt_list), (yyvsp[(2) - (3)].func) ); ;}
     break;
 
   case 252:
-#line 863 "parser.y"
-    { (yyval.stmt_list) = append_func( (yyvsp[-2].stmt_list), (yyvsp[-1].func) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 832 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (5)].type);
+						  type_dispinterface_define((yyval.type), (yyvsp[(3) - (5)].var_list), (yyvsp[(4) - (5)].stmt_list));
+						;}
     break;
 
   case 253:
-#line 869 "parser.y"
-    { (yyval.type) = (yyvsp[-4].type);
-						  type_dispinterface_define((yyval.type), (yyvsp[-2].var_list), (yyvsp[-1].stmt_list));
+
+/* Line 1455 of yacc.c  */
+#line 836 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (5)].type);
+						  type_dispinterface_define_from_iface((yyval.type), (yyvsp[(3) - (5)].type));
 						;}
     break;
 
   case 254:
-#line 873 "parser.y"
-    { (yyval.type) = (yyvsp[-4].type);
-						  type_dispinterface_define_from_iface((yyval.type), (yyvsp[-2].type));
-						;}
+
+/* Line 1455 of yacc.c  */
+#line 841 "parser.y"
+    { (yyval.type) = NULL; ;}
     break;
 
   case 255:
-#line 878 "parser.y"
-    { (yyval.type) = NULL; ;}
+
+/* Line 1455 of yacc.c  */
+#line 842 "parser.y"
+    { (yyval.type) = find_type_or_error2((yyvsp[(2) - (2)].str), 0); ;}
     break;
 
   case 256:
-#line 879 "parser.y"
-    { (yyval.type) = find_type_or_error2((yyvsp[0].str), 0); ;}
+
+/* Line 1455 of yacc.c  */
+#line 845 "parser.y"
+    { (yyval.type) = get_type(TYPE_INTERFACE, (yyvsp[(2) - (2)].str), 0); ;}
     break;
 
   case 257:
-#line 882 "parser.y"
-    { (yyval.type) = get_type(RPC_FC_IP, (yyvsp[0].str), 0); ;}
+
+/* Line 1455 of yacc.c  */
+#line 846 "parser.y"
+    { (yyval.type) = get_type(TYPE_INTERFACE, (yyvsp[(2) - (2)].str), 0); ;}
     break;
 
   case 258:
-#line 883 "parser.y"
-    { (yyval.type) = get_type(RPC_FC_IP, (yyvsp[0].str), 0); ;}
+
+/* Line 1455 of yacc.c  */
+#line 849 "parser.y"
+    { (yyval.ifinfo).interface = (yyvsp[(2) - (2)].type);
+						  (yyval.ifinfo).old_pointer_default = pointer_default;
+						  if (is_attr((yyvsp[(1) - (2)].attr_list), ATTR_POINTERDEFAULT))
+						    pointer_default = get_attrv((yyvsp[(1) - (2)].attr_list), ATTR_POINTERDEFAULT);
+						  is_object_interface = is_object((yyvsp[(1) - (2)].attr_list));
+						  check_def((yyvsp[(2) - (2)].type));
+						  (yyvsp[(2) - (2)].type)->attrs = check_iface_attrs((yyvsp[(2) - (2)].type)->name, (yyvsp[(1) - (2)].attr_list));
+						  (yyvsp[(2) - (2)].type)->defined = TRUE;
+						;}
     break;
 
   case 259:
-#line 886 "parser.y"
-    { (yyval.ifinfo).interface = (yyvsp[0].type);
-						  (yyval.ifinfo).old_pointer_default = pointer_default;
-						  if (is_attr((yyvsp[-1].attr_list), ATTR_POINTERDEFAULT))
-						    pointer_default = get_attrv((yyvsp[-1].attr_list), ATTR_POINTERDEFAULT);
-						  is_object_interface = is_object((yyvsp[-1].attr_list));
-						  check_def((yyvsp[0].type));
-						  (yyvsp[0].type)->attrs = check_iface_attrs((yyvsp[0].type)->name, (yyvsp[-1].attr_list));
-						  (yyvsp[0].type)->defined = TRUE;
+
+/* Line 1455 of yacc.c  */
+#line 861 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (6)].ifinfo).interface;
+						  type_interface_define((yyval.type), (yyvsp[(2) - (6)].type), (yyvsp[(4) - (6)].stmt_list));
+						  pointer_default = (yyvsp[(1) - (6)].ifinfo).old_pointer_default;
 						;}
     break;
 
   case 260:
-#line 898 "parser.y"
-    { (yyval.type) = (yyvsp[-5].ifinfo).interface;
-						  type_interface_define((yyval.type), (yyvsp[-4].type), (yyvsp[-2].stmt_list));
-						  pointer_default = (yyvsp[-5].ifinfo).old_pointer_default;
+
+/* Line 1455 of yacc.c  */
+#line 869 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (8)].ifinfo).interface;
+						  type_interface_define((yyval.type), find_type_or_error2((yyvsp[(3) - (8)].str), 0), (yyvsp[(6) - (8)].stmt_list));
+						  pointer_default = (yyvsp[(1) - (8)].ifinfo).old_pointer_default;
 						;}
     break;
 
   case 261:
-#line 906 "parser.y"
-    { (yyval.type) = (yyvsp[-7].ifinfo).interface;
-						  type_interface_define((yyval.type), find_type_or_error2((yyvsp[-5].str), 0), (yyvsp[-2].stmt_list));
-						  pointer_default = (yyvsp[-7].ifinfo).old_pointer_default;
-						;}
+
+/* Line 1455 of yacc.c  */
+#line 873 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (2)].type); ;}
     break;
 
   case 262:
-#line 910 "parser.y"
-    { (yyval.type) = (yyvsp[-1].type); ;}
+
+/* Line 1455 of yacc.c  */
+#line 877 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (2)].type); ;}
     break;
 
   case 263:
-#line 914 "parser.y"
-    { (yyval.type) = (yyvsp[-1].type); ;}
+
+/* Line 1455 of yacc.c  */
+#line 878 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (2)].type); ;}
     break;
 
   case 264:
-#line 915 "parser.y"
-    { (yyval.type) = (yyvsp[-1].type); ;}
+
+/* Line 1455 of yacc.c  */
+#line 881 "parser.y"
+    { (yyval.type) = type_new_module((yyvsp[(2) - (2)].str)); ;}
     break;
 
   case 265:
-#line 918 "parser.y"
-    { (yyval.type) = type_new_module((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 882 "parser.y"
+    { (yyval.type) = type_new_module((yyvsp[(2) - (2)].str)); ;}
     break;
 
   case 266:
-#line 919 "parser.y"
-    { (yyval.type) = type_new_module((yyvsp[0].str)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 885 "parser.y"
+    { (yyval.type) = (yyvsp[(2) - (2)].type);
+						  (yyval.type)->attrs = check_module_attrs((yyvsp[(2) - (2)].type)->name, (yyvsp[(1) - (2)].attr_list));
+						;}
     break;
 
   case 267:
-#line 922 "parser.y"
-    { (yyval.type) = (yyvsp[0].type);
-						  (yyval.type)->attrs = check_module_attrs((yyvsp[0].type)->name, (yyvsp[-1].attr_list));
+
+/* Line 1455 of yacc.c  */
+#line 891 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (5)].type);
+                                                  type_module_define((yyval.type), (yyvsp[(3) - (5)].stmt_list));
 						;}
     break;
 
   case 268:
-#line 928 "parser.y"
-    { (yyval.type) = (yyvsp[-4].type);
-                                                  type_module_define((yyval.type), (yyvsp[-2].stmt_list));
-						;}
+
+/* Line 1455 of yacc.c  */
+#line 897 "parser.y"
+    { (yyval.stgclass) = STG_EXTERN; ;}
     break;
 
   case 269:
-#line 934 "parser.y"
-    { (yyval.stgclass) = STG_EXTERN; ;}
+
+/* Line 1455 of yacc.c  */
+#line 898 "parser.y"
+    { (yyval.stgclass) = STG_STATIC; ;}
     break;
 
   case 270:
-#line 935 "parser.y"
-    { (yyval.stgclass) = STG_STATIC; ;}
+
+/* Line 1455 of yacc.c  */
+#line 899 "parser.y"
+    { (yyval.stgclass) = STG_REGISTER; ;}
     break;
 
   case 271:
-#line 936 "parser.y"
-    { (yyval.stgclass) = STG_REGISTER; ;}
+
+/* Line 1455 of yacc.c  */
+#line 903 "parser.y"
+    { (yyval.attr) = make_attr(ATTR_INLINE); ;}
     break;
 
   case 272:
-#line 940 "parser.y"
-    { (yyval.attr) = make_attr(ATTR_INLINE); ;}
+
+/* Line 1455 of yacc.c  */
+#line 907 "parser.y"
+    { (yyval.attr) = make_attr(ATTR_CONST); ;}
     break;
 
   case 273:
-#line 944 "parser.y"
-    { (yyval.attr) = make_attr(ATTR_CONST); ;}
+
+/* Line 1455 of yacc.c  */
+#line 910 "parser.y"
+    { (yyval.attr_list) = NULL; ;}
     break;
 
   case 274:
-#line 947 "parser.y"
-    { (yyval.attr_list) = NULL; ;}
+
+/* Line 1455 of yacc.c  */
+#line 911 "parser.y"
+    { (yyval.attr_list) = append_attr((yyvsp[(1) - (2)].attr_list), (yyvsp[(2) - (2)].attr)); ;}
     break;
 
   case 275:
-#line 948 "parser.y"
-    { (yyval.attr_list) = append_attr((yyvsp[-1].attr_list), (yyvsp[0].attr)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 914 "parser.y"
+    { (yyval.declspec) = make_decl_spec((yyvsp[(1) - (2)].type), (yyvsp[(2) - (2)].declspec), NULL, NULL, STG_NONE); ;}
     break;
 
   case 276:
-#line 951 "parser.y"
-    { (yyval.declspec) = make_decl_spec((yyvsp[-1].type), (yyvsp[0].declspec), NULL, NULL, STG_NONE); ;}
+
+/* Line 1455 of yacc.c  */
+#line 916 "parser.y"
+    { (yyval.declspec) = make_decl_spec((yyvsp[(2) - (3)].type), (yyvsp[(1) - (3)].declspec), (yyvsp[(3) - (3)].declspec), NULL, STG_NONE); ;}
     break;
 
   case 277:
-#line 953 "parser.y"
-    { (yyval.declspec) = make_decl_spec((yyvsp[-1].type), (yyvsp[-2].declspec), (yyvsp[0].declspec), NULL, STG_NONE); ;}
-    break;
 
-  case 278:
-#line 956 "parser.y"
+/* Line 1455 of yacc.c  */
+#line 919 "parser.y"
     { (yyval.declspec) = NULL; ;}
     break;
 
+  case 279:
+
+/* Line 1455 of yacc.c  */
+#line 924 "parser.y"
+    { (yyval.declspec) = make_decl_spec(NULL, (yyvsp[(2) - (2)].declspec), NULL, (yyvsp[(1) - (2)].attr), STG_NONE); ;}
+    break;
+
   case 280:
-#line 961 "parser.y"
-    { (yyval.declspec) = make_decl_spec(NULL, (yyvsp[0].declspec), NULL, (yyvsp[-1].attr), STG_NONE); ;}
+
+/* Line 1455 of yacc.c  */
+#line 925 "parser.y"
+    { (yyval.declspec) = make_decl_spec(NULL, (yyvsp[(2) - (2)].declspec), NULL, (yyvsp[(1) - (2)].attr), STG_NONE); ;}
     break;
 
   case 281:
-#line 962 "parser.y"
-    { (yyval.declspec) = make_decl_spec(NULL, (yyvsp[0].declspec), NULL, (yyvsp[-1].attr), STG_NONE); ;}
+
+/* Line 1455 of yacc.c  */
+#line 926 "parser.y"
+    { (yyval.declspec) = make_decl_spec(NULL, (yyvsp[(2) - (2)].declspec), NULL, NULL, (yyvsp[(1) - (2)].stgclass)); ;}
     break;
 
   case 282:
-#line 963 "parser.y"
-    { (yyval.declspec) = make_decl_spec(NULL, (yyvsp[0].declspec), NULL, NULL, (yyvsp[-1].stgclass)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 931 "parser.y"
+    { (yyval.declarator) = (yyvsp[(3) - (3)].declarator); (yyval.declarator)->type = append_ptrchain_type((yyval.declarator)->type, type_new_pointer(pointer_default, NULL, (yyvsp[(2) - (3)].attr_list))); ;}
     break;
 
   case 283:
-#line 968 "parser.y"
-    { (yyval.declarator) = (yyvsp[0].declarator); (yyval.declarator)->type = append_ptrchain_type((yyval.declarator)->type, type_new_pointer(NULL, (yyvsp[-1].attr_list))); ;}
+
+/* Line 1455 of yacc.c  */
+#line 932 "parser.y"
+    { (yyval.declarator) = (yyvsp[(2) - (2)].declarator); (yyval.declarator)->type->attrs = append_attr((yyval.declarator)->type->attrs, make_attrp(ATTR_CALLCONV, (yyvsp[(1) - (2)].str))); ;}
     break;
 
-  case 284:
-#line 969 "parser.y"
-    { (yyval.declarator) = (yyvsp[0].declarator); (yyval.declarator)->type->attrs = append_attr((yyval.declarator)->type->attrs, make_attrp(ATTR_CALLCONV, (yyvsp[-1].str))); ;}
+  case 285:
+
+/* Line 1455 of yacc.c  */
+#line 937 "parser.y"
+    { (yyval.declarator) = make_declarator((yyvsp[(1) - (1)].var)); ;}
     break;
 
   case 286:
-#line 974 "parser.y"
-    { (yyval.declarator) = make_declarator((yyvsp[0].var)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 938 "parser.y"
+    { (yyval.declarator) = (yyvsp[(2) - (3)].declarator); ;}
     break;
 
   case 287:
-#line 975 "parser.y"
-    { (yyval.declarator) = (yyvsp[-1].declarator); ;}
+
+/* Line 1455 of yacc.c  */
+#line 939 "parser.y"
+    { (yyval.declarator) = (yyvsp[(1) - (2)].declarator); (yyval.declarator)->array = append_array((yyval.declarator)->array, (yyvsp[(2) - (2)].expr)); ;}
     break;
 
   case 288:
-#line 976 "parser.y"
-    { (yyval.declarator) = (yyvsp[-1].declarator); (yyval.declarator)->array = append_array((yyval.declarator)->array, (yyvsp[0].expr)); ;}
-    break;
 
-  case 289:
-#line 977 "parser.y"
-    { (yyval.declarator) = (yyvsp[-3].declarator);
-						  (yyval.declarator)->func_type = append_ptrchain_type((yyval.declarator)->type, type_new_function((yyvsp[-1].var_list)));
+/* Line 1455 of yacc.c  */
+#line 940 "parser.y"
+    { (yyval.declarator) = (yyvsp[(1) - (4)].declarator);
+						  (yyval.declarator)->func_type = append_ptrchain_type((yyval.declarator)->type, type_new_function((yyvsp[(3) - (4)].var_list)));
 						  (yyval.declarator)->type = NULL;
 						;}
     break;
 
+  case 289:
+
+/* Line 1455 of yacc.c  */
+#line 947 "parser.y"
+    { (yyval.declarator_list) = append_declarator( NULL, (yyvsp[(1) - (1)].declarator) ); ;}
+    break;
+
   case 290:
-#line 984 "parser.y"
-    { (yyval.declarator_list) = append_declarator( NULL, (yyvsp[0].declarator) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 948 "parser.y"
+    { (yyval.declarator_list) = append_declarator( (yyvsp[(1) - (3)].declarator_list), (yyvsp[(3) - (3)].declarator) ); ;}
     break;
 
   case 291:
-#line 985 "parser.y"
-    { (yyval.declarator_list) = append_declarator( (yyvsp[-2].declarator_list), (yyvsp[0].declarator) ); ;}
+
+/* Line 1455 of yacc.c  */
+#line 952 "parser.y"
+    { (yyval.declarator) = (yyvsp[(1) - (1)].declarator); ;}
     break;
 
   case 292:
-#line 989 "parser.y"
-    { (yyval.declarator) = (yyvsp[0].declarator); ;}
+
+/* Line 1455 of yacc.c  */
+#line 953 "parser.y"
+    { (yyval.declarator) = (yyvsp[(1) - (3)].declarator); (yyvsp[(1) - (3)].declarator)->var->eval = (yyvsp[(3) - (3)].expr); ;}
     break;
 
   case 293:
-#line 990 "parser.y"
-    { (yyval.declarator) = (yyvsp[-2].declarator); (yyvsp[-2].declarator)->var->eval = (yyvsp[0].expr); ;}
+
+/* Line 1455 of yacc.c  */
+#line 957 "parser.y"
+    { (yyval.num) = RPC_FC_RP; ;}
     break;
 
   case 294:
-#line 994 "parser.y"
-    { (yyval.num) = RPC_FC_RP; ;}
+
+/* Line 1455 of yacc.c  */
+#line 958 "parser.y"
+    { (yyval.num) = RPC_FC_UP; ;}
     break;
 
   case 295:
-#line 995 "parser.y"
-    { (yyval.num) = RPC_FC_UP; ;}
+
+/* Line 1455 of yacc.c  */
+#line 959 "parser.y"
+    { (yyval.num) = RPC_FC_FP; ;}
     break;
 
   case 296:
-#line 996 "parser.y"
-    { (yyval.num) = RPC_FC_FP; ;}
+
+/* Line 1455 of yacc.c  */
+#line 962 "parser.y"
+    { (yyval.type) = type_new_struct((yyvsp[(2) - (5)].str), TRUE, (yyvsp[(4) - (5)].var_list)); ;}
     break;
 
   case 297:
-#line 999 "parser.y"
-    { (yyval.type) = type_new_struct((yyvsp[-3].str), TRUE, (yyvsp[-1].var_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 965 "parser.y"
+    { (yyval.type) = type_new_void(); ;}
     break;
 
   case 298:
-#line 1002 "parser.y"
-    { (yyval.type) = find_type_or_error("void", 0); ;}
+
+/* Line 1455 of yacc.c  */
+#line 966 "parser.y"
+    { (yyval.type) = find_type_or_error((yyvsp[(1) - (1)].str), 0); ;}
     break;
 
   case 299:
-#line 1003 "parser.y"
-    { (yyval.type) = find_type_or_error((yyvsp[0].str), 0); ;}
+
+/* Line 1455 of yacc.c  */
+#line 967 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (1)].type); ;}
     break;
 
   case 300:
-#line 1004 "parser.y"
-    { (yyval.type) = (yyvsp[0].type); ;}
+
+/* Line 1455 of yacc.c  */
+#line 968 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (1)].type); ;}
     break;
 
   case 301:
-#line 1005 "parser.y"
-    { (yyval.type) = (yyvsp[0].type); ;}
+
+/* Line 1455 of yacc.c  */
+#line 969 "parser.y"
+    { (yyval.type) = type_new_enum((yyvsp[(2) - (2)].str), FALSE, NULL); ;}
     break;
 
   case 302:
-#line 1006 "parser.y"
-    { (yyval.type) = find_type_or_error2((yyvsp[0].str), tsENUM); ;}
+
+/* Line 1455 of yacc.c  */
+#line 970 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (1)].type); ;}
     break;
 
   case 303:
-#line 1007 "parser.y"
-    { (yyval.type) = (yyvsp[0].type); ;}
+
+/* Line 1455 of yacc.c  */
+#line 971 "parser.y"
+    { (yyval.type) = type_new_struct((yyvsp[(2) - (2)].str), FALSE, NULL); ;}
     break;
 
   case 304:
-#line 1008 "parser.y"
-    { (yyval.type) = type_new_struct((yyvsp[0].str), FALSE, NULL); ;}
+
+/* Line 1455 of yacc.c  */
+#line 972 "parser.y"
+    { (yyval.type) = (yyvsp[(1) - (1)].type); ;}
     break;
 
   case 305:
-#line 1009 "parser.y"
-    { (yyval.type) = (yyvsp[0].type); ;}
+
+/* Line 1455 of yacc.c  */
+#line 973 "parser.y"
+    { (yyval.type) = type_new_nonencapsulated_union((yyvsp[(2) - (2)].str), FALSE, NULL); ;}
     break;
 
   case 306:
-#line 1010 "parser.y"
-    { (yyval.type) = find_type_or_error2((yyvsp[0].str), tsUNION); ;}
+
+/* Line 1455 of yacc.c  */
+#line 974 "parser.y"
+    { (yyval.type) = make_safearray((yyvsp[(3) - (4)].type)); ;}
     break;
 
   case 307:
-#line 1011 "parser.y"
-    { (yyval.type) = make_safearray((yyvsp[-1].type)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 978 "parser.y"
+    { reg_typedefs((yyvsp[(3) - (4)].declspec), (yyvsp[(4) - (4)].declarator_list), check_typedef_attrs((yyvsp[(2) - (4)].attr_list)));
+						  (yyval.statement) = make_statement_typedef((yyvsp[(4) - (4)].declarator_list));
+						;}
     break;
 
   case 308:
-#line 1015 "parser.y"
-    { reg_typedefs((yyvsp[-1].declspec), (yyvsp[0].declarator_list), check_typedef_attrs((yyvsp[-2].attr_list)));
-						  (yyval.statement) = make_statement_typedef((yyvsp[0].declarator_list));
-						;}
+
+/* Line 1455 of yacc.c  */
+#line 984 "parser.y"
+    { (yyval.type) = type_new_nonencapsulated_union((yyvsp[(2) - (5)].str), TRUE, (yyvsp[(4) - (5)].var_list)); ;}
     break;
 
   case 309:
-#line 1021 "parser.y"
-    { (yyval.type) = type_new_nonencapsulated_union((yyvsp[-3].str), (yyvsp[-1].var_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 987 "parser.y"
+    { (yyval.type) = type_new_encapsulated_union((yyvsp[(2) - (10)].str), (yyvsp[(5) - (10)].var), (yyvsp[(7) - (10)].var), (yyvsp[(9) - (10)].var_list)); ;}
     break;
 
   case 310:
-#line 1024 "parser.y"
-    { (yyval.type) = type_new_encapsulated_union((yyvsp[-8].str), (yyvsp[-5].var), (yyvsp[-3].var), (yyvsp[-1].var_list)); ;}
+
+/* Line 1455 of yacc.c  */
+#line 991 "parser.y"
+    { (yyval.num) = MAKEVERSION((yyvsp[(1) - (1)].num), 0); ;}
     break;
 
   case 311:
-#line 1028 "parser.y"
-    { (yyval.num) = MAKEVERSION((yyvsp[0].num), 0); ;}
-    break;
 
-  case 312:
-#line 1029 "parser.y"
-    { (yyval.num) = MAKEVERSION((yyvsp[-2].num), (yyvsp[0].num)); ;}
+/* Line 1455 of yacc.c  */
+#line 992 "parser.y"
+    { (yyval.num) = MAKEVERSION((yyvsp[(1) - (3)].num), (yyvsp[(3) - (3)].num)); ;}
     break;
 
 
+
+/* Line 1455 of yacc.c  */
+#line 4702 "parser.tab.c"
       default: break;
     }
+  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
 
-/* Line 1126 of yacc.c.  */
-#line 4085 "parser.tab.c"
-
-  yyvsp -= yylen;
-  yyssp -= yylen;
-
-
+  YYPOPSTACK (yylen);
+  yylen = 0;
   YY_STACK_PRINT (yyss, yyssp);
 
   *++yyvsp = yyval;
 
-
   /* Now `shift' the result of the reduction.  Determine what state
      that goes to, based on the state we popped back to and the rule
      number reduced by.  */
@@ -4115,133 +4732,65 @@
   if (!yyerrstatus)
     {
       ++yynerrs;
-#if YYERROR_VERBOSE
-      yyn = yypact[yystate];
-
-      if (YYPACT_NINF < yyn && yyn < YYLAST)
-	{
-	  int yytype = YYTRANSLATE (yychar);
-	  YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
-	  YYSIZE_T yysize = yysize0;
-	  YYSIZE_T yysize1;
-	  int yysize_overflow = 0;
-	  char *yymsg = 0;
-#	  define YYERROR_VERBOSE_ARGS_MAXIMUM 5
-	  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
-	  int yyx;
-
-#if 0
-	  /* This is so xgettext sees the translatable formats that are
-	     constructed on the fly.  */
-	  YY_("syntax error, unexpected %s");
-	  YY_("syntax error, unexpected %s, expecting %s");
-	  YY_("syntax error, unexpected %s, expecting %s or %s");
-	  YY_("syntax error, unexpected %s, expecting %s or %s or %s");
-	  YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
-#endif
-	  char *yyfmt;
-	  char const *yyf;
-	  static char const yyunexpected[] = "syntax error, unexpected %s";
-	  static char const yyexpecting[] = ", expecting %s";
-	  static char const yyor[] = " or %s";
-	  char yyformat[sizeof yyunexpected
-			+ sizeof yyexpecting - 1
-			+ ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
-			   * (sizeof yyor - 1))];
-	  char const *yyprefix = yyexpecting;
-
-	  /* Start YYX at -YYN if negative to avoid negative indexes in
-	     YYCHECK.  */
-	  int yyxbegin = yyn < 0 ? -yyn : 0;
-
-	  /* Stay within bounds of both yycheck and yytname.  */
-	  int yychecklim = YYLAST - yyn;
-	  int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
-	  int yycount = 1;
-
-	  yyarg[0] = yytname[yytype];
-	  yyfmt = yystpcpy (yyformat, yyunexpected);
-
-	  for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+#if ! YYERROR_VERBOSE
+      yyerror (YY_("syntax error"));
+#else
+      {
+	YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
+	if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
+	  {
+	    YYSIZE_T yyalloc = 2 * yysize;
+	    if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
+	      yyalloc = YYSTACK_ALLOC_MAXIMUM;
+	    if (yymsg != yymsgbuf)
+	      YYSTACK_FREE (yymsg);
+	    yymsg = (char *) YYSTACK_ALLOC (yyalloc);
+	    if (yymsg)
+	      yymsg_alloc = yyalloc;
+	    else
 	      {
-		if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
-		  {
-		    yycount = 1;
-		    yysize = yysize0;
-		    yyformat[sizeof yyunexpected - 1] = '\0';
-		    break;
-		  }
-		yyarg[yycount++] = yytname[yyx];
-		yysize1 = yysize + yytnamerr (0, yytname[yyx]);
-		yysize_overflow |= yysize1 < yysize;
-		yysize = yysize1;
-		yyfmt = yystpcpy (yyfmt, yyprefix);
-		yyprefix = yyor;
+		yymsg = yymsgbuf;
+		yymsg_alloc = sizeof yymsgbuf;
 	      }
+	  }
 
-	  yyf = YY_(yyformat);
-	  yysize1 = yysize + yystrlen (yyf);
-	  yysize_overflow |= yysize1 < yysize;
-	  yysize = yysize1;
-
-	  if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM)
-	    yymsg = (char *) YYSTACK_ALLOC (yysize);
-	  if (yymsg)
-	    {
-	      /* Avoid sprintf, as that infringes on the user's name space.
-		 Don't have undefined behavior even if the translation
-		 produced a string with the wrong number of "%s"s.  */
-	      char *yyp = yymsg;
-	      int yyi = 0;
-	      while ((*yyp = *yyf))
-		{
-		  if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
-		    {
-		      yyp += yytnamerr (yyp, yyarg[yyi++]);
-		      yyf += 2;
-		    }
-		  else
-		    {
-		      yyp++;
-		      yyf++;
-		    }
-		}
-	      yyerror (yymsg);
-	      YYSTACK_FREE (yymsg);
-	    }
-	  else
-	    {
-	      yyerror (YY_("syntax error"));
+	if (0 < yysize && yysize <= yymsg_alloc)
+	  {
+	    (void) yysyntax_error (yymsg, yystate, yychar);
+	    yyerror (yymsg);
+	  }
+	else
+	  {
+	    yyerror (YY_("syntax error"));
+	    if (yysize != 0)
 	      goto yyexhaustedlab;
-	    }
-	}
-      else
-#endif /* YYERROR_VERBOSE */
-	yyerror (YY_("syntax error"));
+	  }
+      }
+#endif
     }
 
 
 
   if (yyerrstatus == 3)
     {
-      /* If just tried and failed to reuse look-ahead token after an
+      /* If just tried and failed to reuse lookahead token after an
 	 error, discard it.  */
 
       if (yychar <= YYEOF)
-        {
+	{
 	  /* Return failure if at end of input.  */
 	  if (yychar == YYEOF)
 	    YYABORT;
-        }
+	}
       else
 	{
-	  yydestruct ("Error: discarding", yytoken, &yylval);
+	  yydestruct ("Error: discarding",
+		      yytoken, &yylval);
 	  yychar = YYEMPTY;
 	}
     }
 
-  /* Else will try to reuse look-ahead token after shifting the error
+  /* Else will try to reuse lookahead token after shifting the error
      token.  */
   goto yyerrlab1;
 
@@ -4254,11 +4803,14 @@
   /* Pacify compilers like GCC when the user code never invokes
      YYERROR and the label yyerrorlab therefore never appears in user
      code.  */
-  if (0)
+  if (/*CONSTCOND*/ 0)
      goto yyerrorlab;
 
-yyvsp -= yylen;
-  yyssp -= yylen;
+  /* Do not reclaim the symbols of the rule which action triggered
+     this YYERROR.  */
+  YYPOPSTACK (yylen);
+  yylen = 0;
+  YY_STACK_PRINT (yyss, yyssp);
   yystate = *yyssp;
   goto yyerrlab1;
 
@@ -4288,19 +4840,17 @@
 	YYABORT;
 
 
-      yydestruct ("Error: popping", yystos[yystate], yyvsp);
-      YYPOPSTACK;
+      yydestruct ("Error: popping",
+		  yystos[yystate], yyvsp);
+      YYPOPSTACK (1);
       yystate = *yyssp;
       YY_STACK_PRINT (yyss, yyssp);
     }
 
-  if (yyn == YYFINAL)
-    YYACCEPT;
-
   *++yyvsp = yylval;
 
 
-  /* Shift the error token. */
+  /* Shift the error token.  */
   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
 
   yystate = yyn;
@@ -4321,7 +4871,7 @@
   yyresult = 1;
   goto yyreturn;
 
-#ifndef yyoverflow
+#if !defined(yyoverflow) || YYERROR_VERBOSE
 /*-------------------------------------------------.
 | yyexhaustedlab -- memory exhaustion comes here.  |
 `-------------------------------------------------*/
@@ -4332,69 +4882,57 @@
 #endif
 
 yyreturn:
-  if (yychar != YYEOF && yychar != YYEMPTY)
+  if (yychar != YYEMPTY)
      yydestruct ("Cleanup: discarding lookahead",
 		 yytoken, &yylval);
+  /* Do not reclaim the symbols of the rule which action triggered
+     this YYABORT or YYACCEPT.  */
+  YYPOPSTACK (yylen);
+  YY_STACK_PRINT (yyss, yyssp);
   while (yyssp != yyss)
     {
       yydestruct ("Cleanup: popping",
 		  yystos[*yyssp], yyvsp);
-      YYPOPSTACK;
+      YYPOPSTACK (1);
     }
 #ifndef yyoverflow
   if (yyss != yyssa)
     YYSTACK_FREE (yyss);
 #endif
-  return yyresult;
+#if YYERROR_VERBOSE
+  if (yymsg != yymsgbuf)
+    YYSTACK_FREE (yymsg);
+#endif
+  /* Make sure YYID is used.  */
+  return YYID (yyresult);
 }
 
 
-#line 1032 "parser.y"
 
+/* Line 1675 of yacc.c  */
+#line 995 "parser.y"
 
-static void decl_builtin(const char *name, unsigned char type)
+
+static void decl_builtin_basic(const char *name, enum type_basic_type type)
 {
-  type_t *t = make_type(type, NULL);
-  t->name = xstrdup(name);
+  type_t *t = type_new_basic(type);
   reg_type(t, name, 0);
 }
 
-static type_t *make_builtin(char *name)
+static void decl_builtin_alias(const char *name, type_t *t)
 {
-  /* NAME is strdup'd in the lexer */
-  type_t *t = duptype(find_type_or_error(name, 0), 0);
-  t->name = name;
-  return t;
+  reg_type(type_new_alias(t, name), name, 0);
 }
 
-static type_t *make_int(int sign)
-{
-  type_t *t = duptype(find_type_or_error("int", 0), 1);
-
-  t->sign = sign;
-  if (sign < 0)
-    t->type = t->type == RPC_FC_LONG ? RPC_FC_ULONG : RPC_FC_USHORT;
-
-  return t;
-}
-
 void init_types(void)
 {
-  decl_builtin("void", 0);
-  decl_builtin("byte", RPC_FC_BYTE);
-  decl_builtin("wchar_t", RPC_FC_WCHAR);
-  decl_builtin("int", RPC_FC_LONG);     /* win32 */
-  decl_builtin("short", RPC_FC_SHORT);
-  decl_builtin("small", RPC_FC_SMALL);
-  decl_builtin("long", RPC_FC_LONG);
-  decl_builtin("hyper", RPC_FC_HYPER);
-  decl_builtin("__int64", RPC_FC_HYPER);
-  decl_builtin("char", RPC_FC_CHAR);
-  decl_builtin("float", RPC_FC_FLOAT);
-  decl_builtin("double", RPC_FC_DOUBLE);
-  decl_builtin("boolean", RPC_FC_BYTE);
-  decl_builtin("error_status_t", RPC_FC_ERROR_STATUS_T);
-  decl_builtin("handle_t", RPC_FC_BIND_PRIMITIVE);
+  decl_builtin_basic("byte", TYPE_BASIC_BYTE);
+  decl_builtin_basic("wchar_t", TYPE_BASIC_WCHAR);
+  decl_builtin_basic("float", TYPE_BASIC_FLOAT);
+  decl_builtin_basic("double", TYPE_BASIC_DOUBLE);
+  decl_builtin_basic("error_status_t", TYPE_BASIC_ERROR_STATUS_T);
+  decl_builtin_basic("handle_t", TYPE_BASIC_HANDLE);
+  decl_builtin_alias("boolean", type_new_basic(TYPE_BASIC_BYTE));
 }
 
 static str_list_t *append_str(str_list_t *list, char *str)
@@ -4607,98 +5145,6 @@
     node->data.typestring_offset = node->data.ptrdesc = 0;
 }
 
-type_t *make_type(unsigned char type, type_t *ref)
-{
-  type_t *t = alloc_type();
-  t->name = NULL;
-  t->type = type;
-  t->ref = ref;
-  t->attrs = NULL;
-  t->orig = NULL;
-  memset(&t->details, 0, sizeof(t->details));
-  t->typestring_offset = 0;
-  t->ptrdesc = 0;
-  t->declarray = FALSE;
-  t->ignore = (parse_only != 0);
-  t->sign = 0;
-  t->defined = FALSE;
-  t->written = FALSE;
-  t->user_types_registered = FALSE;
-  t->tfswrite = FALSE;
-  t->checked = FALSE;
-  t->is_alias = FALSE;
-  t->typelib_idx = -1;
-  init_loc_info(&t->loc_info);
-  return t;
-}
-
-static type_t *type_new_enum(char *name, var_list_t *enums)
-{
-    type_t *t = get_type(RPC_FC_ENUM16, name, tsENUM);
-    if (enums)
-    {
-        t->details.enumeration = xmalloc(sizeof(*t->details.enumeration));
-        t->details.enumeration->enums = enums;
-    }
-    else
-        t->details.enumeration = NULL;
-    t->defined = TRUE;
-    return t;
-}
-
-static type_t *type_new_struct(char *name, int defined, var_list_t *fields)
-{
-  type_t *tag_type = name ? find_type(name, tsSTRUCT) : NULL;
-  type_t *t = make_type(RPC_FC_STRUCT, NULL);
-  t->name = name;
-  if (defined || (tag_type && tag_type->details.structure))
-  {
-    if (tag_type && tag_type->details.structure)
-    {
-      t->details.structure = tag_type->details.structure;
-      t->type = tag_type->type;
-    }
-    else if (defined)
-    {
-      t->details.structure = xmalloc(sizeof(*t->details.structure));
-      t->details.structure->fields = fields;
-      t->defined = TRUE;
-    }
-  }
-  if (name)
-  {
-    if (fields)
-      reg_type(t, name, tsSTRUCT);
-    else
-      add_incomplete(t);
-  }
-  return t;
-}
-
-static type_t *type_new_nonencapsulated_union(char *name, var_list_t *fields)
-{
-  type_t *t = get_type(RPC_FC_NON_ENCAPSULATED_UNION, name, tsUNION);
-  t->details.structure = xmalloc(sizeof(*t->details.structure));
-  t->details.structure->fields = fields;
-  t->defined = TRUE;
-  return t;
-}
-
-static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases)
-{
-  type_t *t = get_type(RPC_FC_ENCAPSULATED_UNION, name, tsUNION);
-  if (!union_field) union_field = make_var( xstrdup("tagged_union") );
-  union_field->type = make_type(RPC_FC_NON_ENCAPSULATED_UNION, NULL);
-  union_field->type->details.structure = xmalloc(sizeof(*union_field->type->details.structure));
-  union_field->type->details.structure->fields = cases;
-  union_field->type->defined = TRUE;
-  t->details.structure = xmalloc(sizeof(*t->details.structure));
-  t->details.structure->fields = append_var( NULL, switch_field );
-  t->details.structure->fields = append_var( t->details.structure->fields, union_field );
-  t->defined = TRUE;
-  return t;
-}
-
 static void type_function_add_head_arg(type_t *type, var_t *arg)
 {
     if (!type->details.function->args)
@@ -4714,9 +5160,10 @@
   type_t *ptrchain_type;
   if (!ptrchain)
     return type;
-  for (ptrchain_type = ptrchain; ptrchain_type->ref; ptrchain_type = ptrchain_type->ref)
+  for (ptrchain_type = ptrchain; type_pointer_get_ref(ptrchain_type); ptrchain_type = type_pointer_get_ref(ptrchain_type))
     ;
-  ptrchain_type->ref = type;
+  assert(ptrchain_type->type_type == TYPE_POINTER);
+  ptrchain_type->details.pointer.ref = type;
   return ptrchain;
 }
 
@@ -4750,9 +5197,8 @@
   v->type = append_ptrchain_type(decl ? decl->type : NULL, type);
   v->stgclass = decl_spec->stgclass;
 
-  /* the highest level of pointer specified should default to the var's ptr attr
-   * or (RPC_FC_RP if not specified and it's a top level ptr), not
-   * pointer_default so we need to fix that up here */
+  /* check for pointer attribute being applied to non-pointer, non-array
+   * type */
   if (!arr)
   {
     int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
@@ -4768,11 +5214,21 @@
       else
         break;
     }
-    if (ptr && is_ptr(ptr) && (ptr_attr || top))
+    if (is_ptr(ptr))
     {
-      /* duplicate type to avoid changing original type */
-      *pt = duptype(*pt, 1);
-      (*pt)->type = ptr_attr ? ptr_attr : RPC_FC_RP;
+      if (ptr_attr && ptr_attr != RPC_FC_UP &&
+          type_get_type(type_pointer_get_ref(ptr)) == TYPE_INTERFACE)
+          warning_loc_info(&v->loc_info,
+                           "%s: pointer attribute applied to interface "
+                           "pointer type has no effect\n", v->name);
+      if (!ptr_attr && top && (*pt)->details.pointer.def_fc != RPC_FC_RP)
+      {
+        /* FIXME: this is a horrible hack to cope with the issue that we
+         * store an offset to the typeformat string in the type object, but
+         * two typeformat strings may be written depending on whether the
+         * pointer is a toplevel parameter or not */
+        *pt = duptype(*pt, 1);
+      }
     }
     else if (ptr_attr)
        error_loc("%s: pointer attribute applied to non-pointer type\n", v->name);
@@ -4784,9 +5240,7 @@
 
   if (is_attr(v->attrs, ATTR_V1ENUM))
   {
-    if (v->type->type == RPC_FC_ENUM16)
-      v->type->type = RPC_FC_ENUM32;
-    else
+    if (type_get_type_detect_alias(v->type) != TYPE_ENUM)
       error_loc("'%s': [v1_enum] attribute applied to non-enum type\n", v->name);
   }
 
@@ -4806,18 +5260,19 @@
       if (0)
       {
         unsigned int align = 0;
-        size_t size = type_memsize(v->type, &align);
+        unsigned int size = type_memsize(v->type, &align);
 
-        if (0xffffffffuL / size < (unsigned long) dim->cval)
+        if (0xffffffffu / size < dim->cval)
           error_loc("%s: total array size is too large\n", v->name);
       }
     }
     else
       sizeless = TRUE;
 
-    *ptype = type_new_array(NULL, *ptype, TRUE,
+    *ptype = type_new_array(NULL, *ptype, FALSE,
                             dim->is_const ? dim->cval : 0,
-                            dim->is_const ? NULL : dim, NULL);
+                            dim->is_const ? NULL : dim, NULL,
+                            pointer_default);
   }
 
   ptype = &v->type;
@@ -4831,18 +5286,21 @@
           error_loc("%s: cannot specify size_is for a fixed sized array\n", v->name);
         else
           *ptype = type_new_array((*ptype)->name,
-                                  type_array_get_element(*ptype), TRUE,
-                                  0, dim, NULL);
+                                  type_array_get_element(*ptype), FALSE,
+                                  0, dim, NULL, 0);
       }
       else if (is_ptr(*ptype))
-        *ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), FALSE,
-                                0, dim, NULL);
+        *ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), TRUE,
+                                0, dim, NULL, pointer_default);
       else
         error_loc("%s: size_is attribute applied to illegal type\n", v->name);
     }
 
-    ptype = &(*ptype)->ref;
-    if (*ptype == NULL)
+    if (is_ptr(*ptype))
+      ptype = &(*ptype)->details.pointer.ref;
+    else if (is_array(*ptype))
+      ptype = &(*ptype)->details.array.elem;
+    else
       error_loc("%s: too many expressions in size_is attribute\n", v->name);
   }
 
@@ -4855,17 +5313,20 @@
       {
         *ptype = type_new_array((*ptype)->name,
                                 type_array_get_element(*ptype),
-                                (*ptype)->declarray,
+                                type_array_is_decl_as_ptr(*ptype),
                                 type_array_get_dim(*ptype),
                                 type_array_get_conformance(*ptype),
-                                dim);
+                                dim, type_array_get_ptr_default_fc(*ptype));
       }
       else
         error_loc("%s: length_is attribute applied to illegal type\n", v->name);
     }
 
-    ptype = &(*ptype)->ref;
-    if (*ptype == NULL)
+    if (is_ptr(*ptype))
+      ptype = &(*ptype)->details.pointer.ref;
+    else if (is_array(*ptype))
+      ptype = &(*ptype)->details.array.elem;
+    else
       error_loc("%s: too many expressions in length_is attribute\n", v->name);
   }
 
@@ -4879,8 +5340,8 @@
     v->type = func_type;
     for (ft = v->type; is_ptr(ft); ft = type_pointer_get_ref(ft))
       ;
-    assert(ft->type == RPC_FC_FUNCTION);
-    ft->ref = return_type;
+    assert(type_get_type_detect_alias(ft) == TYPE_FUNCTION);
+    ft->details.function->rettype = return_type;
     /* move calling convention attribute, if present, from pointer nodes to
      * function node */
     for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
@@ -4938,7 +5399,7 @@
   return l;
 }
 
-static var_list_t *append_var(var_list_t *list, var_t *var)
+var_list_t *append_var(var_list_t *list, var_t *var)
 {
     if (!var) return list;
     if (!list)
@@ -4962,7 +5423,7 @@
     return list;
 }
 
-static var_t *make_var(char *name)
+var_t *make_var(char *name)
 {
   var_t *v = xmalloc(sizeof(var_t));
   v->name = name;
@@ -5014,18 +5475,10 @@
   return f;
 }
 
-static type_t *make_class(char *name)
-{
-  type_t *c = make_type(RPC_FC_COCLASS, NULL);
-  c->name = name;
-  return c;
-}
-
 static type_t *make_safearray(type_t *type)
 {
-  type_t *sa = find_type_or_error("SAFEARRAY", 0);
-  sa->ref = type;
-  return make_type(pointer_default, sa);
+  return type_new_array(NULL, type_new_alias(type, "SAFEARRAY"), TRUE, 0,
+                        NULL, NULL, RPC_FC_RP);
 }
 
 static typelib_t *make_library(const char *name, const attr_list_t *attrs)
@@ -5063,7 +5516,7 @@
 
 struct rtype *type_hash[HASHMAX];
 
-static type_t *reg_type(type_t *type, const char *name, int t)
+type_t *reg_type(type_t *type, const char *name, int t)
 {
   struct rtype *nt;
   int hash;
@@ -5085,10 +5538,13 @@
 
 static int is_incomplete(const type_t *t)
 {
-  return !t->defined && (is_struct(t->type) || is_union(t->type));
+  return !t->defined &&
+    (type_get_type_detect_alias(t) == TYPE_STRUCT ||
+     type_get_type_detect_alias(t) == TYPE_UNION ||
+     type_get_type_detect_alias(t) == TYPE_ENCAPSULATED_UNION);
 }
 
-static void add_incomplete(type_t *t)
+void add_incomplete(type_t *t)
 {
   struct typenode *tn = xmalloc(sizeof *tn);
   tn->type = t;
@@ -5100,7 +5556,9 @@
   if (type_is_alias(t) && is_incomplete(t)) {
     type_t *ot = type_alias_get_aliasee(t);
     fix_type(ot);
-    if (is_struct(ot->type) || is_union(ot->type))
+    if (type_get_type_detect_alias(ot) == TYPE_STRUCT ||
+        type_get_type_detect_alias(ot) == TYPE_UNION ||
+        type_get_type_detect_alias(ot) == TYPE_ENCAPSULATED_UNION)
       t->details.structure = ot->details.structure;
     t->defined = ot->defined;
   }
@@ -5123,12 +5581,9 @@
 
   LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry)
   {
-    if (((is_struct(complete_type->type) && is_struct(tn->type->type)) ||
-         (is_union(complete_type->type) && is_union(tn->type->type))) &&
-        !strcmp(complete_type->name, tn->type->name))
+    if (type_is_equal(complete_type, tn->type))
     {
       tn->type->details.structure = complete_type->details.structure;
-      tn->type->type = complete_type->type;
       list_remove(&tn->entry);
       free(tn);
     }
@@ -5144,13 +5599,14 @@
   if (is_str)
   {
     type_t *t = decl_spec->type;
-    unsigned char c;
 
     while (is_ptr(t))
       t = type_pointer_get_ref(t);
 
-    c = t->type;
-    if (c != RPC_FC_CHAR && c != RPC_FC_BYTE && c != RPC_FC_WCHAR)
+    if (type_get_type(t) != TYPE_BASIC &&
+        (get_basic_fc(t) != RPC_FC_CHAR &&
+         get_basic_fc(t) != RPC_FC_BYTE &&
+         get_basic_fc(t) != RPC_FC_WCHAR))
     {
       decl = LIST_ENTRY( list_head( decls ), const declarator_t, entry );
       error_loc("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
@@ -5161,8 +5617,10 @@
   /* We must generate names for tagless enum, struct or union.
      Typedef-ing a tagless enum, struct or union means we want the typedef
      to be included in a library hence the public attribute.  */
-  if ((type->type == RPC_FC_ENUM16 || type->type == RPC_FC_ENUM32 ||
-       is_struct(type->type) || is_union(type->type)) &&
+  if ((type_get_type_detect_alias(type) == TYPE_ENUM ||
+       type_get_type_detect_alias(type) == TYPE_STRUCT ||
+       type_get_type_detect_alias(type) == TYPE_UNION ||
+       type_get_type_detect_alias(type) == TYPE_ENCAPSULATED_UNION) &&
       !type->name && !parse_only)
   {
     if (! is_attr(attrs, ATTR_PUBLIC))
@@ -5229,7 +5687,7 @@
   return find_type(name, 0) != NULL;
 }
 
-static type_t *get_type(unsigned char type, char *name, int t)
+type_t *get_type(enum type_type type, char *name, int t)
 {
   type_t *tp;
   if (name) {
@@ -5239,7 +5697,7 @@
       return tp;
     }
   }
-  tp = make_type(type, NULL);
+  tp = make_type(type);
   tp->name = name;
   if (!name) return tp;
   return reg_type(tp, name, t);
@@ -5441,7 +5899,7 @@
   const type_t *t = arg->type;
   const attr_t *attr;
 
-  if (t->type == 0 && ! is_var_ptr(arg))
+  if (type_get_type(t) == TYPE_VOID)
     error_loc("argument '%s' has void type\n", arg->name);
 
   if (arg->attrs)
@@ -5574,23 +6032,44 @@
 
 static int is_allowed_conf_type(const type_t *type)
 {
-    switch (type->type)
+    switch (type_get_type(type))
     {
-    case RPC_FC_CHAR:
-    case RPC_FC_SMALL:
-    case RPC_FC_BYTE:
-    case RPC_FC_USMALL:
-    case RPC_FC_WCHAR:
-    case RPC_FC_SHORT:
-    case RPC_FC_ENUM16:
-    case RPC_FC_USHORT:
-    case RPC_FC_LONG:
-    case RPC_FC_ENUM32:
-    case RPC_FC_ULONG:
+    case TYPE_ENUM:
         return TRUE;
-    default:
+    case TYPE_BASIC:
+        switch (type_basic_get_type(type))
+        {
+        case TYPE_BASIC_INT8:
+        case TYPE_BASIC_INT16:
+        case TYPE_BASIC_INT32:
+        case TYPE_BASIC_INT64:
+        case TYPE_BASIC_INT:
+        case TYPE_BASIC_CHAR:
+        case TYPE_BASIC_HYPER:
+        case TYPE_BASIC_BYTE:
+        case TYPE_BASIC_WCHAR:
+        case TYPE_BASIC_ERROR_STATUS_T:
+            return TRUE;
+        default:
+            return FALSE;
+        }
+    case TYPE_ALIAS:
+        /* shouldn't get here because of type_get_type call above */
+        assert(0);
+        /* fall through */
+    case TYPE_STRUCT:
+    case TYPE_UNION:
+    case TYPE_ENCAPSULATED_UNION:
+    case TYPE_ARRAY:
+    case TYPE_POINTER:
+    case TYPE_VOID:
+    case TYPE_MODULE:
+    case TYPE_COCLASS:
+    case TYPE_FUNCTION:
+    case TYPE_INTERFACE:
         return FALSE;
     }
+    return FALSE;
 }
 
 static int is_ptr_guid_type(const type_t *type)
@@ -5630,16 +6109,26 @@
                                const char *container_name, const var_t *arg)
 {
     type_t *type = arg->type;
-    int is_wire_marshal = 0;
-    int is_context_handle = 0;
+    int more_to_do;
     const char *container_type_name = NULL;
 
-    if (is_struct(container_type->type))
+    switch (type_get_type_detect_alias(type))
+    {
+    case TYPE_STRUCT:
         container_type_name = "struct";
-    else if (is_union(container_type->type))
+        break;
+    case TYPE_UNION:
         container_type_name = "union";
-    else if (container_type->type == RPC_FC_FUNCTION)
+        break;
+    case TYPE_ENCAPSULATED_UNION:
+        container_type_name = "encapsulated union";
+        break;
+    case TYPE_FUNCTION:
         container_type_name = "function";
+        break;
+    default:
+        break;
+    }
 
     if (is_attr(arg->attrs, ATTR_LENGTHIS) &&
         (is_attr(arg->attrs, ATTR_STRING) || is_aliaschain_attr(arg->type, ATTR_STRING)))
@@ -5687,35 +6176,56 @@
         }
     }
 
-    /* get fundamental type for the argument */
-    for (;;)
+    do
     {
-        if (is_attr(type->attrs, ATTR_WIREMARSHAL))
+        more_to_do = FALSE;
+
+        switch (typegen_detect_type(type, arg->attrs, TDT_IGNORE_STRINGS))
         {
-            is_wire_marshal = 1;
+        case TGT_STRUCT:
+        case TGT_UNION:
+            check_remoting_fields(arg, type);
             break;
-        }
-        if (is_attr(type->attrs, ATTR_CONTEXTHANDLE))
-        {
-            is_context_handle = 1;
+        case TGT_INVALID:
+            switch (type_get_type(type))
+            {
+            case TYPE_VOID:
+                error_loc_info(&arg->loc_info, "parameter \'%s\' of %s \'%s\' cannot derive from void *\n",
+                               arg->name, container_type_name, container_name);
+                break;
+            case TYPE_FUNCTION:
+                error_loc_info(&arg->loc_info, "parameter \'%s\' of %s \'%s\' cannot be a function pointer\n",
+                               arg->name, container_type_name, container_name);
+                break;
+            case TYPE_COCLASS:
+            case TYPE_INTERFACE:
+            case TYPE_MODULE:
+                /* FIXME */
+                break;
+            default:
+                break;
+            }
+        case TGT_CTXT_HANDLE:
+        case TGT_CTXT_HANDLE_POINTER:
+            /* FIXME */
             break;
-        }
-        if (type_is_alias(type))
-            type = type_alias_get_aliasee(type);
-        else if (is_ptr(type))
+        case TGT_POINTER:
             type = type_pointer_get_ref(type);
-        else if (is_array(type))
+            more_to_do = TRUE;
+            break;
+        case TGT_ARRAY:
             type = type_array_get_element(type);
-        else
+            more_to_do = TRUE;
             break;
-    }
-
-    if (type->type == 0 && !is_attr(arg->attrs, ATTR_IIDIS) && !is_wire_marshal && !is_context_handle)
-        error_loc_info(&arg->loc_info, "parameter \'%s\' of %s \'%s\' cannot derive from void *\n", arg->name, container_type_name, container_name);
-    else if (type->type == RPC_FC_FUNCTION)
-        error_loc_info(&arg->loc_info, "parameter \'%s\' of %s \'%s\' cannot be a function pointer\n", arg->name, container_type_name, container_name);
-    else if (!is_wire_marshal && (is_struct(type->type) || is_union(type->type)))
-        check_remoting_fields(arg, type);
+        case TGT_USER_TYPE:
+        case TGT_STRING:
+        case TGT_IFACE_POINTER:
+        case TGT_BASIC:
+        case TGT_ENUM:
+            /* nothing to do */
+            break;
+        }
+    } while (more_to_do);
 }
 
 static void check_remoting_fields(const var_t *var, type_t *type)
@@ -5730,14 +6240,14 @@
 
     type->checked = TRUE;
 
-    if (is_struct(type->type))
+    if (type_get_type(type) == TYPE_STRUCT)
     {
         if (type_is_complete(type))
             fields = type_struct_get_fields(type);
         else
             error_loc_info(&var->loc_info, "undefined type declaration %s\n", type->name);
     }
-    else if (is_union(type->type))
+    else if (type_get_type(type) == TYPE_UNION || type_get_type(type) == TYPE_ENCAPSULATED_UNION)
         fields = type_union_get_cases(type);
 
     if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
@@ -5752,36 +6262,37 @@
 
     if (func->type->details.function->args) LIST_FOR_EACH_ENTRY( arg, func->type->details.function->args, const var_t, entry )
     {
-        int ptr_level = 0;
         const type_t *type = arg->type;
 
-        /* get pointer level and fundamental type for the argument */
-        for (;;)
+        /* check that [out] parameters have enough pointer levels */
+        if (is_attr(arg->attrs, ATTR_OUT))
         {
-            if (is_attr(type->attrs, ATTR_WIREMARSHAL))
+            switch (typegen_detect_type(type, arg->attrs, TDT_ALL_TYPES))
+            {
+            case TGT_BASIC:
+            case TGT_ENUM:
+            case TGT_STRUCT:
+            case TGT_UNION:
+            case TGT_CTXT_HANDLE:
+            case TGT_USER_TYPE:
+                error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg->name, funcname);
                 break;
-            if (is_attr(type->attrs, ATTR_CONTEXTHANDLE))
+            case TGT_IFACE_POINTER:
+                error_loc_info(&arg->loc_info, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg->name, funcname);
                 break;
-            if (type_is_alias(type))
-                type = type_alias_get_aliasee(type);
-            else if (is_ptr(type))
-            {
-                ptr_level++;
-                type = type_pointer_get_ref(type);
-            }
-            else
+            case TGT_STRING:
+                if (!is_array(type))
+                {
+                    /* FIXME */
+                }
                 break;
-        }
-
-        /* check that [out] parameters have enough pointer levels */
-        if (is_attr(arg->attrs, ATTR_OUT))
-        {
-            if (!is_array(type))
-            {
-                if (!ptr_level)
-                    error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg->name, funcname);
-                if (type->type == RPC_FC_IP && ptr_level == 1)
-                    error_loc_info(&arg->loc_info, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg->name, funcname);
+            case TGT_INVALID:
+                /* already error'd before we get here */
+            case TGT_CTXT_HANDLE_POINTER:
+            case TGT_POINTER:
+            case TGT_ARRAY:
+                /* OK */
+                break;
             }
         }
 
@@ -5847,7 +6358,7 @@
     {
       if (stmt->type == STMT_LIBRARY)
           check_statements(stmt->u.lib->stmts, TRUE);
-      else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
+      else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
           check_functions(stmt->u.type, is_inside_library);
     }
 }
@@ -5860,7 +6371,7 @@
   {
     if (stmt->type == STMT_LIBRARY)
       check_all_user_types(stmt->u.lib->stmts);
-    else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP &&
+    else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE &&
              !is_local(stmt->u.type->attrs))
     {
       const statement_t *stmt_func;
@@ -5921,8 +6432,9 @@
         if (var->eval)
             reg_const(var);
     }
-    else if ((var->stgclass == STG_NONE || var->stgclass == STG_REGISTER) &&
-	     var->type->type != RPC_FC_FUNCTION)
+    else if (type_get_type(var->type) == TYPE_FUNCTION)
+        check_function_attrs(var->name, var->attrs);
+    else if (var->stgclass == STG_NONE || var->stgclass == STG_REGISTER)
         error_loc("instantiation of data is illegal\n");
     return stmt;
 }
Index: tools/widl/parser.tab.h
===================================================================
--- tools/widl/parser.tab.h	(revision 41348)
+++ tools/widl/parser.tab.h	(working copy)
@@ -1,28 +1,38 @@
-/* A Bison parser, made by GNU Bison 2.1.  */
 
-/* Skeleton parser for Yacc-like parsing with Bison,
-   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+/* A Bison parser, made by GNU Bison 2.4.1.  */
 
-   This program is free software; you can redistribute it and/or modify
+/* Skeleton interface for Bison's Yacc-like parsers in C
+   
+      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
+   
+   This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+   
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-
+   
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* As a special exception, when this file is copied by Bison into a
-   Bison output file, you may use that output file without restriction.
-   This special exception was added by the Free Software Foundation
-   in version 1.24 of Bison.  */
+/* As a special exception, you may create a larger work that contains
+   part or all of the Bison parser skeleton and distribute that work
+   under terms of your choice, so long as that work isn't itself a
+   parser generator using the skeleton or a modified version thereof
+   as a parser skeleton.  Alternatively, if you modify or redistribute
+   the parser skeleton itself, you may (at your option) remove this
+   special exception, which will cause the skeleton and the resulting
+   Bison output files to be licensed under the GNU General Public
+   License without this special exception.
+   
+   This special exception was added by the Free Software Foundation in
+   version 2.2 of Bison.  */
 
+
 /* Tokens.  */
 #ifndef YYTOKENTYPE
 # define YYTOKENTYPE
@@ -147,196 +157,48 @@
      tSAFEARRAY = 373,
      tSHORT = 374,
      tSIGNED = 375,
-     tSINGLE = 376,
-     tSIZEIS = 377,
-     tSIZEOF = 378,
-     tSMALL = 379,
-     tSOURCE = 380,
-     tSTATIC = 381,
-     tSTDCALL = 382,
-     tSTRICTCONTEXTHANDLE = 383,
-     tSTRING = 384,
-     tSTRUCT = 385,
-     tSWITCH = 386,
-     tSWITCHIS = 387,
-     tSWITCHTYPE = 388,
-     tTRANSMITAS = 389,
-     tTRUE = 390,
-     tTYPEDEF = 391,
-     tUNION = 392,
-     tUNIQUE = 393,
-     tUNSIGNED = 394,
-     tUUID = 395,
-     tV1ENUM = 396,
-     tVARARG = 397,
-     tVERSION = 398,
-     tVOID = 399,
-     tWCHAR = 400,
-     tWIREMARSHAL = 401,
-     ADDRESSOF = 402,
-     NEG = 403,
-     POS = 404,
-     PPTR = 405,
-     CAST = 406
+     tSIZEIS = 376,
+     tSIZEOF = 377,
+     tSMALL = 378,
+     tSOURCE = 379,
+     tSTATIC = 380,
+     tSTDCALL = 381,
+     tSTRICTCONTEXTHANDLE = 382,
+     tSTRING = 383,
+     tSTRUCT = 384,
+     tSWITCH = 385,
+     tSWITCHIS = 386,
+     tSWITCHTYPE = 387,
+     tTRANSMITAS = 388,
+     tTRUE = 389,
+     tTYPEDEF = 390,
+     tUNION = 391,
+     tUNIQUE = 392,
+     tUNSIGNED = 393,
+     tUUID = 394,
+     tV1ENUM = 395,
+     tVARARG = 396,
+     tVERSION = 397,
+     tVOID = 398,
+     tWCHAR = 399,
+     tWIREMARSHAL = 400,
+     ADDRESSOF = 401,
+     NEG = 402,
+     POS = 403,
+     PPTR = 404,
+     CAST = 405
    };
 #endif
-/* Tokens.  */
-#define aIDENTIFIER 258
-#define aKNOWNTYPE 259
-#define aNUM 260
-#define aHEXNUM 261
-#define aDOUBLE 262
-#define aSTRING 263
-#define aWSTRING 264
-#define aUUID 265
-#define aEOF 266
-#define SHL 267
-#define SHR 268
-#define MEMBERPTR 269
-#define EQUALITY 270
-#define INEQUALITY 271
-#define GREATEREQUAL 272
-#define LESSEQUAL 273
-#define LOGICALOR 274
-#define LOGICALAND 275
-#define tAGGREGATABLE 276
-#define tALLOCATE 277
-#define tAPPOBJECT 278
-#define tASYNC 279
-#define tASYNCUUID 280
-#define tAUTOHANDLE 281
-#define tBINDABLE 282
-#define tBOOLEAN 283
-#define tBROADCAST 284
-#define tBYTE 285
-#define tBYTECOUNT 286
-#define tCALLAS 287
-#define tCALLBACK 288
-#define tCASE 289
-#define tCDECL 290
-#define tCHAR 291
-#define tCOCLASS 292
-#define tCODE 293
-#define tCOMMSTATUS 294
-#define tCONST 295
-#define tCONTEXTHANDLE 296
-#define tCONTEXTHANDLENOSERIALIZE 297
-#define tCONTEXTHANDLESERIALIZE 298
-#define tCONTROL 299
-#define tCPPQUOTE 300
-#define tDEFAULT 301
-#define tDEFAULTCOLLELEM 302
-#define tDEFAULTVALUE 303
-#define tDEFAULTVTABLE 304
-#define tDISPLAYBIND 305
-#define tDISPINTERFACE 306
-#define tDLLNAME 307
-#define tDOUBLE 308
-#define tDUAL 309
-#define tENDPOINT 310
-#define tENTRY 311
-#define tENUM 312
-#define tERRORSTATUST 313
-#define tEXPLICITHANDLE 314
-#define tEXTERN 315
-#define tFALSE 316
-#define tFASTCALL 317
-#define tFLOAT 318
-#define tHANDLE 319
-#define tHANDLET 320
-#define tHELPCONTEXT 321
-#define tHELPFILE 322
-#define tHELPSTRING 323
-#define tHELPSTRINGCONTEXT 324
-#define tHELPSTRINGDLL 325
-#define tHIDDEN 326
-#define tHYPER 327
-#define tID 328
-#define tIDEMPOTENT 329
-#define tIIDIS 330
-#define tIMMEDIATEBIND 331
-#define tIMPLICITHANDLE 332
-#define tIMPORT 333
-#define tIMPORTLIB 334
-#define tIN 335
-#define tIN_LINE 336
-#define tINLINE 337
-#define tINPUTSYNC 338
-#define tINT 339
-#define tINT64 340
-#define tINTERFACE 341
-#define tLCID 342
-#define tLENGTHIS 343
-#define tLIBRARY 344
-#define tLOCAL 345
-#define tLONG 346
-#define tMETHODS 347
-#define tMODULE 348
-#define tNONBROWSABLE 349
-#define tNONCREATABLE 350
-#define tNONEXTENSIBLE 351
-#define tNULL 352
-#define tOBJECT 353
-#define tODL 354
-#define tOLEAUTOMATION 355
-#define tOPTIONAL 356
-#define tOUT 357
-#define tPASCAL 358
-#define tPOINTERDEFAULT 359
-#define tPROPERTIES 360
-#define tPROPGET 361
-#define tPROPPUT 362
-#define tPROPPUTREF 363
-#define tPTR 364
-#define tPUBLIC 365
-#define tRANGE 366
-#define tREADONLY 367
-#define tREF 368
-#define tREGISTER 369
-#define tREQUESTEDIT 370
-#define tRESTRICTED 371
-#define tRETVAL 372
-#define tSAFEARRAY 373
-#define tSHORT 374
-#define tSIGNED 375
-#define tSINGLE 376
-#define tSIZEIS 377
-#define tSIZEOF 378
-#define tSMALL 379
-#define tSOURCE 380
-#define tSTATIC 381
-#define tSTDCALL 382
-#define tSTRICTCONTEXTHANDLE 383
-#define tSTRING 384
-#define tSTRUCT 385
-#define tSWITCH 386
-#define tSWITCHIS 387
-#define tSWITCHTYPE 388
-#define tTRANSMITAS 389
-#define tTRUE 390
-#define tTYPEDEF 391
-#define tUNION 392
-#define tUNIQUE 393
-#define tUNSIGNED 394
-#define tUUID 395
-#define tV1ENUM 396
-#define tVARARG 397
-#define tVERSION 398
-#define tVOID 399
-#define tWCHAR 400
-#define tWIREMARSHAL 401
-#define ADDRESSOF 402
-#define NEG 403
-#define POS 404
-#define PPTR 405
-#define CAST 406
 
 
 
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+{
 
-#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
-#line 176 "parser.y"
-typedef union YYSTYPE {
+/* Line 1676 of yacc.c  */
+#line 156 "parser.y"
+
 	attr_t *attr;
 	attr_list_t *attr_list;
 	str_list_t *str_list;
@@ -363,15 +225,17 @@
 	struct _import_t *import;
 	struct _decl_spec_t *declspec;
 	enum storage_class stgclass;
+
+
+
+/* Line 1676 of yacc.c  */
+#line 233 "parser.tab.h"
 } YYSTYPE;
-/* Line 1447 of yacc.c.  */
-#line 369 "parser.tab.h"
+# define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
 #endif
 
 extern YYSTYPE parser_lval;
 
 
-
Index: tools/widl/parser.y
===================================================================
--- tools/widl/parser.y	(revision 41348)
+++ tools/widl/parser.y	(working copy)
@@ -28,9 +28,6 @@
 #include <assert.h>
 #include <ctype.h>
 #include <string.h>
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
 
 #include "widl.h"
 #include "utils.h"
@@ -68,7 +65,7 @@
 
 #define YYERROR_VERBOSE
 
-unsigned char pointer_default = RPC_FC_UP;
+static unsigned char pointer_default = RPC_FC_UP;
 static int is_object_interface = FALSE;
 
 typedef struct list typelist_t;
@@ -92,7 +89,6 @@
 
 typelist_t incomplete_types = LIST_INIT(incomplete_types);
 
-static void add_incomplete(type_t *t);
 static void fix_incomplete(void);
 static void fix_incomplete_types(type_t *complete_type);
 
@@ -109,30 +105,18 @@
 static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls);
 static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
 static ifref_t *make_ifref(type_t *iface);
-static var_list_t *append_var(var_list_t *list, var_t *var);
 static var_list_t *append_var_list(var_list_t *list, var_list_t *vars);
-static var_t *make_var(char *name);
 static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *p);
 static declarator_t *make_declarator(var_t *var);
 static func_list_t *append_func(func_list_t *list, func_t *func);
 static func_t *make_func(var_t *def);
-static type_t *make_class(char *name);
 static type_t *make_safearray(type_t *type);
-static type_t *make_builtin(char *name);
-static type_t *make_int(int sign);
 static typelib_t *make_library(const char *name, const attr_list_t *attrs);
 static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type);
 
-static type_t *type_new_enum(char *name, var_list_t *enums);
-static type_t *type_new_struct(char *name, int defined, var_list_t *fields);
-static type_t *type_new_nonencapsulated_union(char *name, var_list_t *fields);
-static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases);
-
-static type_t *reg_type(type_t *type, const char *name, int t);
 static type_t *reg_typedefs(decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs);
 static type_t *find_type_or_error(const char *name, int t);
 static type_t *find_type_or_error2(char *name, int t);
-static type_t *get_type(unsigned char type, char *name, int t);
 
 static var_t *reg_const(var_t *var);
 
@@ -168,10 +152,6 @@
 static statement_t *make_statement_typedef(var_list_t *names);
 static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt);
 
-#define tsENUM   1
-#define tsSTRUCT 2
-#define tsUNION  3
-
 %}
 %union {
 	attr_t *attr;
@@ -274,7 +254,6 @@
 %token tSAFEARRAY
 %token tSHORT
 %token tSIGNED
-%token tSINGLE
 %token tSIZEIS tSIZEOF
 %token tSMALL
 %token tSOURCE
@@ -614,14 +593,14 @@
 
 enum:	  ident '=' expr_int_const		{ $$ = reg_const($1);
 						  $$->eval = $3;
-                                                  $$->type = make_int(0);
+                                                  $$->type = type_new_int(TYPE_BASIC_INT, 0);
 						}
 	| ident					{ $$ = reg_const($1);
-                                                  $$->type = make_int(0);
+                                                  $$->type = type_new_int(TYPE_BASIC_INT, 0);
 						}
 	;
 
-enumdef: tENUM t_ident '{' enums '}'		{ $$ = type_new_enum($2, $4); }
+enumdef: tENUM t_ident '{' enums '}'		{ $$ = type_new_enum($2, TRUE, $4); }
 	;
 
 m_exprs:  m_expr                                { $$ = append_expr( NULL, $1 ); }
@@ -772,51 +751,35 @@
 	| aKNOWNTYPE				{ $$ = make_var($<str>1); }
 	;
 
-base_type: tBYTE				{ $$ = make_builtin($<str>1); }
-	| tWCHAR				{ $$ = make_builtin($<str>1); }
+base_type: tBYTE				{ $$ = find_type_or_error($<str>1, 0); }
+	| tWCHAR				{ $$ = find_type_or_error($<str>1, 0); }
 	| int_std
-	| tSIGNED int_std			{ $$ = $2; $$->sign = 1; }
-	| tUNSIGNED int_std			{ $$ = $2; $$->sign = -1;
-						  switch ($$->type) {
-						  case RPC_FC_CHAR:  break;
-						  case RPC_FC_SMALL: $$->type = RPC_FC_USMALL; break;
-						  case RPC_FC_SHORT: $$->type = RPC_FC_USHORT; break;
-						  case RPC_FC_LONG:  $$->type = RPC_FC_ULONG;  break;
-						  case RPC_FC_HYPER:
-						    if ($$->name[0] == 'h') /* hyper, as opposed to __int64 */
-                                                    {
-                                                      $$ = type_new_alias($$, "MIDL_uhyper");
-                                                      $$->sign = 0;
-                                                    }
-						    break;
-						  default: break;
-						  }
-						}
-	| tUNSIGNED				{ $$ = make_int(-1); }
-	| tFLOAT				{ $$ = make_builtin($<str>1); }
-	| tSINGLE				{ $$ = find_type("float", 0); }
-	| tDOUBLE				{ $$ = make_builtin($<str>1); }
-	| tBOOLEAN				{ $$ = make_builtin($<str>1); }
-	| tERRORSTATUST				{ $$ = make_builtin($<str>1); }
-	| tHANDLET				{ $$ = make_builtin($<str>1); }
+	| tSIGNED int_std			{ $$ = type_new_int(type_basic_get_type($2), -1); }
+	| tUNSIGNED int_std			{ $$ = type_new_int(type_basic_get_type($2), 1); }
+	| tUNSIGNED				{ $$ = type_new_int(TYPE_BASIC_INT, 1); }
+	| tFLOAT				{ $$ = find_type_or_error($<str>1, 0); }
+	| tDOUBLE				{ $$ = find_type_or_error($<str>1, 0); }
+	| tBOOLEAN				{ $$ = find_type_or_error($<str>1, 0); }
+	| tERRORSTATUST				{ $$ = find_type_or_error($<str>1, 0); }
+	| tHANDLET				{ $$ = find_type_or_error($<str>1, 0); }
 	;
 
 m_int:
 	| tINT
 	;
 
-int_std:  tINT					{ $$ = make_builtin($<str>1); }
-	| tSHORT m_int				{ $$ = make_builtin($<str>1); }
-	| tSMALL				{ $$ = make_builtin($<str>1); }
-	| tLONG m_int				{ $$ = make_builtin($<str>1); }
-	| tHYPER m_int				{ $$ = make_builtin($<str>1); }
-	| tINT64				{ $$ = make_builtin($<str>1); }
-	| tCHAR					{ $$ = make_builtin($<str>1); }
+int_std:  tINT					{ $$ = type_new_int(TYPE_BASIC_INT, 0); }
+	| tSHORT m_int				{ $$ = type_new_int(TYPE_BASIC_INT16, 0); }
+	| tSMALL				{ $$ = type_new_int(TYPE_BASIC_INT8, 0); }
+	| tLONG m_int				{ $$ = type_new_int(TYPE_BASIC_INT32, 0); }
+	| tHYPER m_int				{ $$ = type_new_int(TYPE_BASIC_HYPER, 0); }
+	| tINT64				{ $$ = type_new_int(TYPE_BASIC_INT64, 0); }
+	| tCHAR					{ $$ = type_new_int(TYPE_BASIC_CHAR, 0); }
 	;
 
-coclass:  tCOCLASS aIDENTIFIER			{ $$ = make_class($2); }
+coclass:  tCOCLASS aIDENTIFIER			{ $$ = type_new_coclass($2); }
 	| tCOCLASS aKNOWNTYPE			{ $$ = find_type($2, 0);
-						  if ($$->type != RPC_FC_COCLASS)
+						  if (type_get_type_detect_alias($$) != TYPE_COCLASS)
 						    error_loc("%s was not declared a coclass at %s:%d\n",
 							      $2, $$->loc_info.input_name,
 							      $$->loc_info.line_number);
@@ -841,8 +804,8 @@
 	  m_attributes interfacedec		{ $$ = make_ifref($2); $$->attrs = $1; }
 	;
 
-dispinterface: tDISPINTERFACE aIDENTIFIER	{ $$ = get_type(RPC_FC_IP, $2, 0); }
-	|      tDISPINTERFACE aKNOWNTYPE	{ $$ = get_type(RPC_FC_IP, $2, 0); }
+dispinterface: tDISPINTERFACE aIDENTIFIER	{ $$ = get_type(TYPE_INTERFACE, $2, 0); }
+	|      tDISPINTERFACE aKNOWNTYPE	{ $$ = get_type(TYPE_INTERFACE, $2, 0); }
 	;
 
 dispinterfacehdr: attributes dispinterface	{ attr_t *attrs;
@@ -879,8 +842,8 @@
 	| ':' aKNOWNTYPE			{ $$ = find_type_or_error2($2, 0); }
 	;
 
-interface: tINTERFACE aIDENTIFIER		{ $$ = get_type(RPC_FC_IP, $2, 0); }
-	|  tINTERFACE aKNOWNTYPE		{ $$ = get_type(RPC_FC_IP, $2, 0); }
+interface: tINTERFACE aIDENTIFIER		{ $$ = get_type(TYPE_INTERFACE, $2, 0); }
+	|  tINTERFACE aKNOWNTYPE		{ $$ = get_type(TYPE_INTERFACE, $2, 0); }
 	;
 
 interfacehdr: attributes interface		{ $$.interface = $2;
@@ -965,7 +928,7 @@
 
 declarator:
 	  '*' m_type_qual_list declarator %prec PPTR
-						{ $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(NULL, $2)); }
+						{ $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
 	| callconv declarator			{ $$ = $2; $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
 	| direct_declarator
 	;
@@ -999,15 +962,15 @@
 structdef: tSTRUCT t_ident '{' fields '}'	{ $$ = type_new_struct($2, TRUE, $4); }
 	;
 
-type:	  tVOID					{ $$ = find_type_or_error("void", 0); }
+type:	  tVOID					{ $$ = type_new_void(); }
 	| aKNOWNTYPE				{ $$ = find_type_or_error($1, 0); }
 	| base_type				{ $$ = $1; }
 	| enumdef				{ $$ = $1; }
-	| tENUM aIDENTIFIER			{ $$ = find_type_or_error2($2, tsENUM); }
+	| tENUM aIDENTIFIER			{ $$ = type_new_enum($2, FALSE, NULL); }
 	| structdef				{ $$ = $1; }
 	| tSTRUCT aIDENTIFIER			{ $$ = type_new_struct($2, FALSE, NULL); }
 	| uniondef				{ $$ = $1; }
-	| tUNION aIDENTIFIER			{ $$ = find_type_or_error2($2, tsUNION); }
+	| tUNION aIDENTIFIER			{ $$ = type_new_nonencapsulated_union($2, FALSE, NULL); }
 	| tSAFEARRAY '(' type ')'		{ $$ = make_safearray($3); }
 	;
 
@@ -1018,7 +981,7 @@
 	;
 
 uniondef: tUNION t_ident '{' ne_union_fields '}'
-						{ $$ = type_new_nonencapsulated_union($2, $4); }
+						{ $$ = type_new_nonencapsulated_union($2, TRUE, $4); }
 	| tUNION t_ident
 	  tSWITCH '(' s_field ')'
 	  m_ident '{' cases '}'			{ $$ = type_new_encapsulated_union($2, $5, $7, $9); }
@@ -1031,49 +994,26 @@
 
 %%
 
-static void decl_builtin(const char *name, unsigned char type)
+static void decl_builtin_basic(const char *name, enum type_basic_type type)
 {
-  type_t *t = make_type(type, NULL);
-  t->name = xstrdup(name);
+  type_t *t = type_new_basic(type);
   reg_type(t, name, 0);
 }
 
-static type_t *make_builtin(char *name)
+static void decl_builtin_alias(const char *name, type_t *t)
 {
-  /* NAME is strdup'd in the lexer */
-  type_t *t = duptype(find_type_or_error(name, 0), 0);
-  t->name = name;
-  return t;
+  reg_type(type_new_alias(t, name), name, 0);
 }
 
-static type_t *make_int(int sign)
-{
-  type_t *t = duptype(find_type_or_error("int", 0), 1);
-
-  t->sign = sign;
-  if (sign < 0)
-    t->type = t->type == RPC_FC_LONG ? RPC_FC_ULONG : RPC_FC_USHORT;
-
-  return t;
-}
-
 void init_types(void)
 {
-  decl_builtin("void", 0);
-  decl_builtin("byte", RPC_FC_BYTE);
-  decl_builtin("wchar_t", RPC_FC_WCHAR);
-  decl_builtin("int", RPC_FC_LONG);     /* win32 */
-  decl_builtin("short", RPC_FC_SHORT);
-  decl_builtin("small", RPC_FC_SMALL);
-  decl_builtin("long", RPC_FC_LONG);
-  decl_builtin("hyper", RPC_FC_HYPER);
-  decl_builtin("__int64", RPC_FC_HYPER);
-  decl_builtin("char", RPC_FC_CHAR);
-  decl_builtin("float", RPC_FC_FLOAT);
-  decl_builtin("double", RPC_FC_DOUBLE);
-  decl_builtin("boolean", RPC_FC_BYTE);
-  decl_builtin("error_status_t", RPC_FC_ERROR_STATUS_T);
-  decl_builtin("handle_t", RPC_FC_BIND_PRIMITIVE);
+  decl_builtin_basic("byte", TYPE_BASIC_BYTE);
+  decl_builtin_basic("wchar_t", TYPE_BASIC_WCHAR);
+  decl_builtin_basic("float", TYPE_BASIC_FLOAT);
+  decl_builtin_basic("double", TYPE_BASIC_DOUBLE);
+  decl_builtin_basic("error_status_t", TYPE_BASIC_ERROR_STATUS_T);
+  decl_builtin_basic("handle_t", TYPE_BASIC_HANDLE);
+  decl_builtin_alias("boolean", type_new_basic(TYPE_BASIC_BYTE));
 }
 
 static str_list_t *append_str(str_list_t *list, char *str)
@@ -1286,98 +1226,6 @@
     node->data.typestring_offset = node->data.ptrdesc = 0;
 }
 
-type_t *make_type(unsigned char type, type_t *ref)
-{
-  type_t *t = alloc_type();
-  t->name = NULL;
-  t->type = type;
-  t->ref = ref;
-  t->attrs = NULL;
-  t->orig = NULL;
-  memset(&t->details, 0, sizeof(t->details));
-  t->typestring_offset = 0;
-  t->ptrdesc = 0;
-  t->declarray = FALSE;
-  t->ignore = (parse_only != 0);
-  t->sign = 0;
-  t->defined = FALSE;
-  t->written = FALSE;
-  t->user_types_registered = FALSE;
-  t->tfswrite = FALSE;
-  t->checked = FALSE;
-  t->is_alias = FALSE;
-  t->typelib_idx = -1;
-  init_loc_info(&t->loc_info);
-  return t;
-}
-
-static type_t *type_new_enum(char *name, var_list_t *enums)
-{
-    type_t *t = get_type(RPC_FC_ENUM16, name, tsENUM);
-    if (enums)
-    {
-        t->details.enumeration = xmalloc(sizeof(*t->details.enumeration));
-        t->details.enumeration->enums = enums;
-    }
-    else
-        t->details.enumeration = NULL;
-    t->defined = TRUE;
-    return t;
-}
-
-static type_t *type_new_struct(char *name, int defined, var_list_t *fields)
-{
-  type_t *tag_type = name ? find_type(name, tsSTRUCT) : NULL;
-  type_t *t = make_type(RPC_FC_STRUCT, NULL);
-  t->name = name;
-  if (defined || (tag_type && tag_type->details.structure))
-  {
-    if (tag_type && tag_type->details.structure)
-    {
-      t->details.structure = tag_type->details.structure;
-      t->type = tag_type->type;
-    }
-    else if (defined)
-    {
-      t->details.structure = xmalloc(sizeof(*t->details.structure));
-      t->details.structure->fields = fields;
-      t->defined = TRUE;
-    }
-  }
-  if (name)
-  {
-    if (fields)
-      reg_type(t, name, tsSTRUCT);
-    else
-      add_incomplete(t);
-  }
-  return t;
-}
-
-static type_t *type_new_nonencapsulated_union(char *name, var_list_t *fields)
-{
-  type_t *t = get_type(RPC_FC_NON_ENCAPSULATED_UNION, name, tsUNION);
-  t->details.structure = xmalloc(sizeof(*t->details.structure));
-  t->details.structure->fields = fields;
-  t->defined = TRUE;
-  return t;
-}
-
-static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases)
-{
-  type_t *t = get_type(RPC_FC_ENCAPSULATED_UNION, name, tsUNION);
-  if (!union_field) union_field = make_var( xstrdup("tagged_union") );
-  union_field->type = make_type(RPC_FC_NON_ENCAPSULATED_UNION, NULL);
-  union_field->type->details.structure = xmalloc(sizeof(*union_field->type->details.structure));
-  union_field->type->details.structure->fields = cases;
-  union_field->type->defined = TRUE;
-  t->details.structure = xmalloc(sizeof(*t->details.structure));
-  t->details.structure->fields = append_var( NULL, switch_field );
-  t->details.structure->fields = append_var( t->details.structure->fields, union_field );
-  t->defined = TRUE;
-  return t;
-}
-
 static void type_function_add_head_arg(type_t *type, var_t *arg)
 {
     if (!type->details.function->args)
@@ -1393,9 +1241,10 @@
   type_t *ptrchain_type;
   if (!ptrchain)
     return type;
-  for (ptrchain_type = ptrchain; ptrchain_type->ref; ptrchain_type = ptrchain_type->ref)
+  for (ptrchain_type = ptrchain; type_pointer_get_ref(ptrchain_type); ptrchain_type = type_pointer_get_ref(ptrchain_type))
     ;
-  ptrchain_type->ref = type;
+  assert(ptrchain_type->type_type == TYPE_POINTER);
+  ptrchain_type->details.pointer.ref = type;
   return ptrchain;
 }
 
@@ -1429,9 +1278,8 @@
   v->type = append_ptrchain_type(decl ? decl->type : NULL, type);
   v->stgclass = decl_spec->stgclass;
 
-  /* the highest level of pointer specified should default to the var's ptr attr
-   * or (RPC_FC_RP if not specified and it's a top level ptr), not
-   * pointer_default so we need to fix that up here */
+  /* check for pointer attribute being applied to non-pointer, non-array
+   * type */
   if (!arr)
   {
     int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
@@ -1447,11 +1295,21 @@
       else
         break;
     }
-    if (ptr && is_ptr(ptr) && (ptr_attr || top))
+    if (is_ptr(ptr))
     {
-      /* duplicate type to avoid changing original type */
-      *pt = duptype(*pt, 1);
-      (*pt)->type = ptr_attr ? ptr_attr : RPC_FC_RP;
+      if (ptr_attr && ptr_attr != RPC_FC_UP &&
+          type_get_type(type_pointer_get_ref(ptr)) == TYPE_INTERFACE)
+          warning_loc_info(&v->loc_info,
+                           "%s: pointer attribute applied to interface "
+                           "pointer type has no effect\n", v->name);
+      if (!ptr_attr && top && (*pt)->details.pointer.def_fc != RPC_FC_RP)
+      {
+        /* FIXME: this is a horrible hack to cope with the issue that we
+         * store an offset to the typeformat string in the type object, but
+         * two typeformat strings may be written depending on whether the
+         * pointer is a toplevel parameter or not */
+        *pt = duptype(*pt, 1);
+      }
     }
     else if (ptr_attr)
        error_loc("%s: pointer attribute applied to non-pointer type\n", v->name);
@@ -1463,9 +1321,7 @@
 
   if (is_attr(v->attrs, ATTR_V1ENUM))
   {
-    if (v->type->type == RPC_FC_ENUM16)
-      v->type->type = RPC_FC_ENUM32;
-    else
+    if (type_get_type_detect_alias(v->type) != TYPE_ENUM)
       error_loc("'%s': [v1_enum] attribute applied to non-enum type\n", v->name);
   }
 
@@ -1485,18 +1341,19 @@
       if (0)
       {
         unsigned int align = 0;
-        size_t size = type_memsize(v->type, &align);
+        unsigned int size = type_memsize(v->type, &align);
 
-        if (0xffffffffuL / size < (unsigned long) dim->cval)
+        if (0xffffffffu / size < dim->cval)
           error_loc("%s: total array size is too large\n", v->name);
       }
     }
     else
       sizeless = TRUE;
 
-    *ptype = type_new_array(NULL, *ptype, TRUE,
+    *ptype = type_new_array(NULL, *ptype, FALSE,
                             dim->is_const ? dim->cval : 0,
-                            dim->is_const ? NULL : dim, NULL);
+                            dim->is_const ? NULL : dim, NULL,
+                            pointer_default);
   }
 
   ptype = &v->type;
@@ -1510,18 +1367,21 @@
           error_loc("%s: cannot specify size_is for a fixed sized array\n", v->name);
         else
           *ptype = type_new_array((*ptype)->name,
-                                  type_array_get_element(*ptype), TRUE,
-                                  0, dim, NULL);
+                                  type_array_get_element(*ptype), FALSE,
+                                  0, dim, NULL, 0);
       }
       else if (is_ptr(*ptype))
-        *ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), FALSE,
-                                0, dim, NULL);
+        *ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), TRUE,
+                                0, dim, NULL, pointer_default);
       else
         error_loc("%s: size_is attribute applied to illegal type\n", v->name);
     }
 
-    ptype = &(*ptype)->ref;
-    if (*ptype == NULL)
+    if (is_ptr(*ptype))
+      ptype = &(*ptype)->details.pointer.ref;
+    else if (is_array(*ptype))
+      ptype = &(*ptype)->details.array.elem;
+    else
       error_loc("%s: too many expressions in size_is attribute\n", v->name);
   }
 
@@ -1534,17 +1394,20 @@
       {
         *ptype = type_new_array((*ptype)->name,
                                 type_array_get_element(*ptype),
-                                (*ptype)->declarray,
+                                type_array_is_decl_as_ptr(*ptype),
                                 type_array_get_dim(*ptype),
                                 type_array_get_conformance(*ptype),
-                                dim);
+                                dim, type_array_get_ptr_default_fc(*ptype));
       }
       else
         error_loc("%s: length_is attribute applied to illegal type\n", v->name);
     }
 
-    ptype = &(*ptype)->ref;
-    if (*ptype == NULL)
+    if (is_ptr(*ptype))
+      ptype = &(*ptype)->details.pointer.ref;
+    else if (is_array(*ptype))
+      ptype = &(*ptype)->details.array.elem;
+    else
       error_loc("%s: too many expressions in length_is attribute\n", v->name);
   }
 
@@ -1558,8 +1421,8 @@
     v->type = func_type;
     for (ft = v->type; is_ptr(ft); ft = type_pointer_get_ref(ft))
       ;
-    assert(ft->type == RPC_FC_FUNCTION);
-    ft->ref = return_type;
+    assert(type_get_type_detect_alias(ft) == TYPE_FUNCTION);
+    ft->details.function->rettype = return_type;
     /* move calling convention attribute, if present, from pointer nodes to
      * function node */
     for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
@@ -1617,7 +1480,7 @@
   return l;
 }
 
-static var_list_t *append_var(var_list_t *list, var_t *var)
+var_list_t *append_var(var_list_t *list, var_t *var)
 {
     if (!var) return list;
     if (!list)
@@ -1641,7 +1504,7 @@
     return list;
 }
 
-static var_t *make_var(char *name)
+var_t *make_var(char *name)
 {
   var_t *v = xmalloc(sizeof(var_t));
   v->name = name;
@@ -1693,18 +1556,10 @@
   return f;
 }
 
-static type_t *make_class(char *name)
-{
-  type_t *c = make_type(RPC_FC_COCLASS, NULL);
-  c->name = name;
-  return c;
-}
-
 static type_t *make_safearray(type_t *type)
 {
-  type_t *sa = find_type_or_error("SAFEARRAY", 0);
-  sa->ref = type;
-  return make_type(pointer_default, sa);
+  return type_new_array(NULL, type_new_alias(type, "SAFEARRAY"), TRUE, 0,
+                        NULL, NULL, RPC_FC_RP);
 }
 
 static typelib_t *make_library(const char *name, const attr_list_t *attrs)
@@ -1742,7 +1597,7 @@
 
 struct rtype *type_hash[HASHMAX];
 
-static type_t *reg_type(type_t *type, const char *name, int t)
+type_t *reg_type(type_t *type, const char *name, int t)
 {
   struct rtype *nt;
   int hash;
@@ -1764,10 +1619,13 @@
 
 static int is_incomplete(const type_t *t)
 {
-  return !t->defined && (is_struct(t->type) || is_union(t->type));
+  return !t->defined &&
+    (type_get_type_detect_alias(t) == TYPE_STRUCT ||
+     type_get_type_detect_alias(t) == TYPE_UNION ||
+     type_get_type_detect_alias(t) == TYPE_ENCAPSULATED_UNION);
 }
 
-static void add_incomplete(type_t *t)
+void add_incomplete(type_t *t)
 {
   struct typenode *tn = xmalloc(sizeof *tn);
   tn->type = t;
@@ -1779,7 +1637,9 @@
   if (type_is_alias(t) && is_incomplete(t)) {
     type_t *ot = type_alias_get_aliasee(t);
     fix_type(ot);
-    if (is_struct(ot->type) || is_union(ot->type))
+    if (type_get_type_detect_alias(ot) == TYPE_STRUCT ||
+        type_get_type_detect_alias(ot) == TYPE_UNION ||
+        type_get_type_detect_alias(ot) == TYPE_ENCAPSULATED_UNION)
       t->details.structure = ot->details.structure;
     t->defined = ot->defined;
   }
@@ -1
