Commit 7d4ee77c authored by Alexandre Julliard's avatar Alexandre Julliard

Merged the IDL compiler written by Ove Kaaven.

parent b7d3c79b
......@@ -13314,7 +13314,7 @@ MAKE_DLL_RULES=dlls/Makedll.rules
MAKE_PROG_RULES=programs/Makeprog.rules
ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules programs/Makeprog.rules Makefile debugger/Makefile dlls/Makefile dlls/advapi32/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/comcat/Makefile dlls/comctl32/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/d3d8/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dinput8/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dsound/Makefile dlls/gdi/Makefile dlls/glu32/Makefile dlls/icmp/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/kernel/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msadp32/Makefile dlls/msacm/msg711/Makefile dlls/msacm/winemp3/Makefile dlls/msdmo/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt20/Makefile dlls/msvideo/Makefile dlls/netapi32/Makefile dlls/ntdll/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleaut32/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/snmpapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/user/Makefile dlls/version/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winealsa/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winspool/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile include/Makefile library/Makefile miscemu/Makefile ole/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/expand/Makefile programs/notepad/Makefile programs/osversioncheck/Makefile programs/progman/Makefile programs/regapi/Makefile programs/regedit/Makefile programs/regsvr32/Makefile programs/regtest/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineconsole/Makefile programs/winefile/Makefile programs/winemine/Makefile programs/winepath/Makefile programs/winetest/Makefile programs/winhelp/Makefile programs/winver/Makefile server/Makefile tools/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/wmc/Makefile tools/wpp/Makefile tools/wrc/Makefile tsx11/Makefile unicode/Makefile"
ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules programs/Makeprog.rules Makefile debugger/Makefile dlls/Makefile dlls/advapi32/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/comcat/Makefile dlls/comctl32/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/d3d8/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dinput8/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dsound/Makefile dlls/gdi/Makefile dlls/glu32/Makefile dlls/icmp/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/kernel/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msadp32/Makefile dlls/msacm/msg711/Makefile dlls/msacm/winemp3/Makefile dlls/msdmo/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt20/Makefile dlls/msvideo/Makefile dlls/netapi32/Makefile dlls/ntdll/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleaut32/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/snmpapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/user/Makefile dlls/version/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winealsa/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winspool/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile include/Makefile library/Makefile miscemu/Makefile ole/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/expand/Makefile programs/notepad/Makefile programs/osversioncheck/Makefile programs/progman/Makefile programs/regapi/Makefile programs/regedit/Makefile programs/regsvr32/Makefile programs/regtest/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineconsole/Makefile programs/winefile/Makefile programs/winemine/Makefile programs/winepath/Makefile programs/winetest/Makefile programs/winhelp/Makefile programs/winver/Makefile server/Makefile tools/Makefile tools/widl/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/wmc/Makefile tools/wpp/Makefile tools/wrc/Makefile tsx11/Makefile unicode/Makefile"
cat >confcache <<\_ACEOF
......@@ -13921,6 +13921,7 @@ do
"programs/winver/Makefile" ) CONFIG_FILES="$CONFIG_FILES programs/winver/Makefile" ;;
"server/Makefile" ) CONFIG_FILES="$CONFIG_FILES server/Makefile" ;;
"tools/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/Makefile" ;;
"tools/widl/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/widl/Makefile" ;;
"tools/winapi/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/winapi/Makefile" ;;
"tools/winebuild/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/winebuild/Makefile" ;;
"tools/winedump/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/winedump/Makefile" ;;
......
......@@ -1374,6 +1374,7 @@ programs/winhelp/Makefile
programs/winver/Makefile
server/Makefile
tools/Makefile
tools/widl/Makefile
tools/winapi/Makefile
tools/winebuild/Makefile
tools/winedump/Makefile
......
/*
* RPC format chars, as found by studying MIDL output.
*/
#ifndef __WINE_RPCFC_H
#define __WINE_RPCFC_H
/* base types */
#define RPC_FC_BYTE 0x01
#define RPC_FC_CHAR 0x02
#define RPC_FC_SMALL 0x03
#define RPC_FC_USMALL 0x04
#define RPC_FC_WCHAR 0x05
#define RPC_FC_SHORT 0x06
#define RPC_FC_USHORT 0x07
#define RPC_FC_LONG 0x08
#define RPC_FC_ULONG 0x09
#define RPC_FC_FLOAT 0x0a
#define RPC_FC_HYPER 0x0b
#define RPC_FC_DOUBLE 0x0c
#define RPC_FC_ENUM32 0x0e
/* other stuff */
#define RPC_FC_RP 0x11 /* ? */
#define RPC_FC_UP 0x12 /* unique pointer */
#define RPC_FC_OP 0x13 /* ? */
#define RPC_FC_FP 0x14 /* full pointer */
/* FC_RP/UP/OP/FP: flags, NdrFcShort(typeofs) */
#define RPC_FC_P_ONSTACK 0x4 /* [alloced_on_stack] */
#define RPC_FC_P_SIMPLEPOINTER 0x8 /* [simple_pointer] */
/* flag 10 is not tagged */
#define RPC_FC_STRUCT 0x15
/* FC_STRUCT: fieldcount-1, NdrFcShort(size), fields */
#define RPC_FC_PSTRUCT 0x16
#define RPC_FC_CSTRUCT 0x17
#define RPC_FC_BOGUS_STRUCT 0x1a
#define RPC_FC_CARRAY 0x1b /* conformant array? */
#define RPC_FC_CVARRAY 0x1c /* conformant varying array? */
#define RPC_FC_SMFARRAY 0x1d /* simple fixed array? */
/* FC_SMFARRAY: fieldcount-1, NdrFcShort(count), type */
#define RPC_FC_BOGUS_ARRAY 0x21
#define RPC_FC_C_WSTRING 0x25
#define RPC_FC_ENCAPSULATED_UNION 0x2a
#define RPC_FC_NON_ENCAPSULATED_UNION 0x2b
#define RPC_FC_IP 0x2f /* interface pointer */
#define RPC_FC_AUTO_HANDLE 0x33
/* FC_AUTO_HANDLE: oldflags, NdrFcLong(?), NdrFcShort(vtbl_idx), NdrFcShort(stacksiz),
* NdrFcShort(?), NdrFcShort(?), oi2flags, parmcount
* parameters: NdrFcShort(flags), NdrFcShort(stackofs), NdrFcShort(typeofs)/basetype */
/* oldflags: 6c = object + oi2 */
#define RPC_FC_AH_OI2F_SRVMUSTSIZE 0x01
#define RPC_FC_AH_OI2F_CLTMUSTSIZE 0x02
#define RPC_FC_AH_OI2F_HASRETURN 0x04
#define RPC_FC_AH_PF_IN 0x0008
#define RPC_FC_AH_PF_OUT 0x0010
#define RPC_FC_AH_PF_RETURN 0x0020
#define RPC_FC_AH_PF_BASETYPE 0x0040
#define RPC_FC_AH_PF_BYVAL 0x0080
#define RPC_FC_AH_PF_SIMPLEREF 0x0100
/* PF: 03 = mustsize + mustfree */
/* 2000 = srv alloc size=8, 4000 = srv alloc size=16 */
#define RPC_FC_POINTER 0x36
#define RPC_FC_ALIGNM4 0x38
#define RPC_FC_ALIGNM8 0x39
#define RPC_FC_STRUCTPAD2 0x3e
#define RPC_FC_NO_REPEAT 0x46
#define RPC_FC_VARIABLE_REPEAT 0x48
#define RPC_FC_FIXED_OFFSET 0x49
#define RPC_FC_PP 0x4b
#define RPC_FC_EMBEDDED_COMPLEX 0x4c
/* FC_EMBEDDED_COMPLEX: fieldcount-1, NdrFcShort(typeofs) */
#define RPC_FC_IN_PARAM 0x4d
/* FC_IN_PARAM: stacksiz, NdrFcShort(typeofs) */
#define RPC_FC_IN_PARAM_BASETYPE 0x4e
/* FC_IN_PARAM_BASETYPE: basetype */
#define RPC_FC_OUT_PARAM 0x51
/* FC_OUT_PARAM: stacksiz, NdrFcShort(typeofs) */
#define RPC_FC_RETURN_PARAM_BASETYPE 0x53
/* FC_RETURN_PARAM_BASETYPE: basetype */
#define RPC_FC_DEREFERENCE 0x54
#define RPC_FC_CONSTANT_IID 0x5a
/* FC_CONSTANT_IID: NdrFcLong(), NdrFcShort(), NdrFcShort(), 8x () */
#define RPC_FC_END 0x5b
#define RPC_FC_PAD 0x5c
#define RPC_FC_USER_MARSHAL 0xb4
#endif /* __WINE_RPCFC_H */
......@@ -10,6 +10,7 @@ MODULE = none
C_SRCS = makedep.c fnt2bdf.c bin2res.c
SUBDIRS = \
widl \
winebuild \
winedump \
wmc \
......@@ -28,7 +29,7 @@ all: $(PROGRAMS) $(SUBDIRS)
@MAKE_RULES@
wrc: wpp
widl wrc: wpp
makedep: makedep.o
$(CC) $(CFLAGS) -o makedep makedep.o
......
Makefile
lex.yy.c
widl
y.tab.c
y.tab.h
DEFS = -D__WINE__
TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ../..
SRCDIR = @srcdir@
VPATH = @srcdir@
LEXOPT = -Cf #-w -b
YACCOPT = #-v
EXEEXT = @EXEEXT@
EXTRAINCL = -I$(TOPSRCDIR)/tools/wpp
EXTRALIBS = -L$(TOPOBJDIR)/tools/wpp -lwpp
PROGRAMS = widl$(EXEEXT)
MODULE = none
C_SRCS = \
header.c \
proxy.c \
utils.c \
widl.c
EXTRA_SRCS = parser.y parser.l
EXTRA_OBJS = y.tab.o @LEX_OUTPUT_ROOT@.o
all: $(PROGRAMS)
@MAKE_RULES@
widl: $(OBJS) $(TOPOBJDIR)/tools/wpp/libwpp.a
$(CC) $(CFLAGS) -o widl $(OBJS) $(EXTRALIBS) $(LIBWINE) $(LIBUNICODE) $(LEXLIB) $(LDFLAGS)
widl.exe: $(OBJS) $(TOPOBJDIR)/tools/wpp/libwpp.a
$(CC) $(CFLAGS) -o widl.exe $(OBJS) $(EXTRALIBS) $(LIBWINE) $(LIBUNICODE) $(LEXLIB) -liberty $(LDFLAGS)
y.tab.c y.tab.h: parser.y
$(YACC) $(YACCOPT) -d -t $(SRCDIR)/parser.y
@LEX_OUTPUT_ROOT@.c: parser.l
$(LEX) $(LEXOPT) -d -8 $(SRCDIR)/parser.l
clean::
$(RM) parser.output parser.tab.h lex.backup y.output
install:: $(PROGRAMS)
$(MKINSTALLDIRS) $(bindir)
$(INSTALL_PROGRAM) widl$(EXEEXT) $(bindir)/widl$(EXEEXT)
uninstall::
$(RM) $(bindir)/widl$(EXEEXT)
### Dependencies:
/*
* IDL Compiler
*
* Copyright 2002 Ove Kaaven
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WIDL_HEADER_H
#define __WIDL_HEADER_H
extern int is_void(type_t *t, var_t *v);
extern void write_name(FILE *h, var_t *v);
extern char* get_name(var_t *v);
extern void write_type(FILE *h, type_t *t, var_t *v, char *n);
extern int is_object(attr_t *a);
extern int is_local(attr_t *a);
extern var_t *is_callas(attr_t *a);
extern void write_method_args(FILE *h, var_t *arg, char *name);
extern void write_forward(type_t *iface);
extern void write_interface(type_t *iface);
extern void write_typedef(type_t *type, var_t *names);
#endif
/*
* IDL Compiler
*
* Copyright 2002 Ove Kaaven
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WIDL_PARSER_H
#define __WIDL_PARSER_H
int yyparse(void);
extern FILE *yyin;
extern char *yytext;
extern int yydebug;
extern int yy_flex_debug;
int yylex(void);
extern int import_stack_ptr;
void do_import(char *fname);
void abort_import(void);
#define parse_only import_stack_ptr
int is_type(const char *name);
#endif
/*
* IDL Compiler
*
* Copyright 2002 Ove Kaaven
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%option stack
%option never-interactive
nl \r?\n
ws [ \f\t\r]
cident [a-zA-Z_][0-9a-zA-Z_]*
int [0-9]+
hexd [0-9a-fA-F]
hex 0x{hexd}+
uuid {hexd}{8}-{hexd}{4}-{hexd}{4}-{hexd}{4}-{hexd}{12}
%x QUOTE
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "widl.h"
#include "utils.h"
#include "parser.h"
#include "wpp.h"
#include "y.tab.h"
#define YY_USE_PROTOS
#define YY_NO_UNPUT
#define YY_NO_TOP_STATE
extern char *temp_name;
static void addcchar(char c);
static char *get_buffered_cstring(void);
static char *cbuffer;
static int cbufidx;
static int cbufalloc = 0;
static int kw_token(const char *kw);
#define MAX_IMPORT_DEPTH 10
struct {
YY_BUFFER_STATE state;
char *temp_name;
} import_stack[MAX_IMPORT_DEPTH];
int import_stack_ptr = 0;
static void pop_import(void);
%}
/*
**************************************************************************
* The flexer starts here
**************************************************************************
*/
%%
^#.*
\" yy_push_state(QUOTE); cbufidx = 0;
<QUOTE>\" {
yy_pop_state();
yylval.str = get_buffered_cstring();
return aSTRING;
}
<QUOTE>\\\\ |
<QUOTE>\\\" addcchar(yytext[1]);
<QUOTE>\\. addcchar('\\'); addcchar(yytext[1]);
<QUOTE>. addcchar(yytext[0]);
{uuid} return aUUID;
{hex} return aNUM;
{int} return aNUM;
{cident} return kw_token(yytext);
\n
{ws}
\<\< return SHL;
\>\> return SHR;
. return yytext[0];
<<EOF>> {
if (import_stack_ptr) pop_import();
else yyterminate();
}
%%
#ifndef yywrap
int yywrap(void)
{
return 1;
}
#endif
static struct {
const char *kw;
int token;
int val;
} keywords[] = {
{"__cdecl", tCDECL},
{"__int64", tINT64},
{"__stdcall", tSTDCALL},
{"_stdcall", tSTDCALL},
{"aggregatable", tAGGREGATABLE},
{"allocate", tALLOCATE},
{"appobject", tAPPOBJECT},
{"arrays", tARRAYS},
{"async", tASYNC},
{"async_uuid", tASYNCUUID},
{"auto_handle", tAUTOHANDLE},
{"bindable", tBINDABLE},
{"boolean", tBOOLEAN},
{"broadcast", tBROADCAST},
{"byte", tBYTE},
{"byte_count", tBYTECOUNT},
{"call_as", tCALLAS},
{"callback", tCALLBACK},
{"case", tCASE},
{"char", tCHAR},
{"coclass", tCOCLASS},
{"code", tCODE},
{"comm_status", tCOMMSTATUS},
{"const", tCONST},
{"context_handle", tCONTEXTHANDLE},
{"context_handle_noserialize", tCONTEXTHANDLENOSERIALIZE},
{"context_handle_serialize", tCONTEXTHANDLENOSERIALIZE},
{"control", tCONTROL},
{"cpp_quote", tCPPQUOTE},
/* ... */
{"default", tDEFAULT},
/* ... */
{"double", tDOUBLE},
/* ... */
{"enum", tENUM},
/* ... */
{"extern", tEXTERN},
/* ... */
{"float", tFLOAT},
/* ... */
{"hyper", tHYPER},
/* ... */
{"iid_is", tIIDIS},
/* ... */
{"import", tIMPORT},
{"importlib", tIMPORTLIB},
{"in", tIN},
{"include", tINCLUDE},
{"in_line", tINLINE},
{"int", tINT},
/* ... */
{"interface", tINTERFACE},
/* ... */
{"length_is", tLENGTHIS},
/* ... */
{"local", tLOCAL},
{"long", tLONG},
/* ... */
{"object", tOBJECT},
{"odl", tODL},
{"oleautomation", tOLEAUTOMATION},
/* ... */
{"out", tOUT},
/* ... */
{"pointer_default", tPOINTERDEFAULT},
/* ... */
{"ref", tREF},
/* ... */
{"short", tSHORT},
{"signed", tSIGNED},
{"size_is", tSIZEIS},
{"sizeof", tSIZEOF},
/* ... */
{"string", tSTRING},
{"struct", tSTRUCT},
{"switch", tSWITCH},
{"switch_is", tSWITCHIS},
{"switch_type", tSWITCHTYPE},
/* ... */
{"typedef", tTYPEDEF},
{"union", tUNION},
/* ... */
{"unique", tUNIQUE},
{"unsigned", tUNSIGNED},
/* ... */
{"uuid", tUUID},
{"v1_enum", tV1ENUM},
/* ... */
{"version", tVERSION},
{"void", tVOID},
{"wchar_t", tWCHAR},
{"wire_marshal", tWIREMARSHAL},
{NULL}
};
static int kw_token(const char *kw)
{
int i;
for (i=0; keywords[i].kw; i++)
if (strcmp(kw, keywords[i].kw) == 0)
return keywords[i].token;
yylval.str = xstrdup(kw);
return is_type(kw) ? aKNOWNTYPE : aIDENTIFIER;
}
static void addcchar(char c)
{
if(cbufidx >= cbufalloc)
{
cbufalloc += 1024;
cbuffer = xrealloc(cbuffer, cbufalloc * sizeof(cbuffer[0]));
if(cbufalloc > 65536)
yywarning("Reallocating string buffer larger than 64kB");
}
cbuffer[cbufidx++] = c;
}
static char *get_buffered_cstring(void)
{
addcchar(0);
return xstrdup(cbuffer);
}
static void pop_import(void)
{
int ptr = import_stack_ptr-1;
fclose(yyin);
yy_delete_buffer( YY_CURRENT_BUFFER );
yy_switch_to_buffer( import_stack[ptr].state );
if (temp_name) {
unlink(temp_name);
free(temp_name);
}
temp_name = import_stack[ptr].temp_name;
import_stack_ptr--;
}
struct imports {
char *name;
struct imports *next;
} *first_import;
void do_import(char *fname)
{
FILE *f;
char *hname, *path;
struct imports *import;
int ptr = import_stack_ptr;
int ret;
if (!parse_only) {
hname = dup_basename(fname, ".idl");
strcat(hname, ".h");
fprintf(header, "#include \"%s\"\n", hname);
free(hname);
}
import = first_import;
while (import && strcmp(import->name, fname))
import = import->next;
if (import) return; /* already imported */
import = xmalloc(sizeof(struct imports));
import->name = xstrdup(fname);
import->next = first_import;
first_import = import;
if (!(path = wpp_find_include( fname, 1 )))
yyerror("Unable to open include file %s", fname);
import_stack[ptr].temp_name = temp_name;
import_stack_ptr++;
ret = wpp_parse_temp( path, &temp_name );
free( path );
if (ret) exit(1);
if((f = fopen(temp_name, "r")) == NULL)
yyerror("Unable to open %s", temp_name);
import_stack[ptr].state = YY_CURRENT_BUFFER;
yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
}
void abort_import(void)
{
int ptr;
for (ptr=0; ptr<import_stack_ptr; ptr++)
unlink(import_stack[ptr].temp_name);
}
/*
* IDL Compiler
*
* Copyright 2002 Ove Kaaven
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WIDL_PROXY_H
#define __WIDL_PROXY_H
extern void write_proxy(type_t *iface);
extern void finish_proxy(void);
#endif
/*
* Utility routines
*
* Copyright 1998 Bertho A. Stultiens
* Copyright 2002 Ove Kaaven
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include "wine/unicode.h"
#include "widl.h"
#include "utils.h"
#include "parser.h"
/* #define WANT_NEAR_INDICATION */
#ifdef WANT_NEAR_INDICATION
void make_print(char *str)
{
while(*str)
{
if(!isprint(*str))
*str = ' ';
str++;
}
}
#endif
static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
{
fprintf(stderr, "%s:%d:%d: %s: ", input_name ? input_name : "stdin", line_number, char_number, t);
vfprintf(stderr, s, ap);
#ifdef WANT_NEAR_INDICATION
{
char *cpy;
if(n)
{
cpy = xstrdup(n);
make_print(cpy);
fprintf(stderr, " near '%s'", cpy);
free(cpy);
}
}
#endif
fprintf(stderr, "\n");
}
int yyerror(const char *s, ...)
{
va_list ap;
va_start(ap, s);
generic_msg(s, "Error", yytext, ap);
va_end(ap);
exit(1);
return 1;
}
int yywarning(const char *s, ...)
{
va_list ap;
va_start(ap, s);
generic_msg(s, "Warning", yytext, ap);
va_end(ap);
return 0;
}
void internal_error(const char *file, int line, const char *s, ...)
{
va_list ap;
va_start(ap, s);
fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(3);
}
void error(const char *s, ...)
{
va_list ap;
va_start(ap, s);
fprintf(stderr, "Error: ");
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(2);
}
void warning(const char *s, ...)
{
va_list ap;
va_start(ap, s);
fprintf(stderr, "Warning: ");
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
va_end(ap);
}
void chat(const char *s, ...)
{
if(debuglevel & DEBUGLEVEL_CHAT)
{
va_list ap;
va_start(ap, s);
fprintf(stderr, "FYI: ");
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
va_end(ap);
}
}
char *dup_basename(const char *name, const char *ext)
{
int namelen;
int extlen = strlen(ext);
char *base;
char *slash;
if(!name)
name = "widl.tab";
slash = strrchr(name, '/');
if (slash)
name = slash + 1;
namelen = strlen(name);
/* +4 for later extension and +1 for '\0' */
base = (char *)xmalloc(namelen +4 +1);
strcpy(base, name);
if(!strcasecmp(name + namelen-extlen, ext))
{
base[namelen - extlen] = '\0';
}
return base;
}
void *xmalloc(size_t size)
{
void *res;
assert(size > 0);
res = malloc(size);
if(res == NULL)
{
error("Virtual memory exhausted.\n");
}
/*
* We set it to 0.
* This is *paramount* because we depend on it
* just about everywhere in the rest of the code.
*/
memset(res, 0, size);
return res;
}
void *xrealloc(void *p, size_t size)
{
void *res;
assert(size > 0);
res = realloc(p, size);
if(res == NULL)
{
error("Virtual memory exhausted.\n");
}
return res;
}
char *xstrdup(const char *str)
{
char *s;
assert(str != NULL);
s = (char *)xmalloc(strlen(str)+1);
return strcpy(s, str);
}
/*
* Utility routines' prototypes etc.
*
* Copyright 1998 Bertho A. Stultiens (BS)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WIDL_UTILS_H
#define __WIDL_UTILS_H
#include "widltypes.h"
#include <stddef.h> /* size_t */
void *xmalloc(size_t);
void *xrealloc(void *, size_t);
char *xstrdup(const char *str);
int yyerror(const char *s, ...) __attribute__((format (printf, 1, 2)));
int yywarning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));
void error(const char *s, ...) __attribute__((format (printf, 1, 2)));
void warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void chat(const char *s, ...) __attribute__((format (printf, 1, 2)));
char *dup_basename(const char *name, const char *ext);
#endif
/*
* IDL Compiler
*
* Copyright 2002 Ove Kaaven
* based on WRC code by Bertho Stultiens
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <signal.h>
#define WIDL_FULLVERSION "0.1"
#include "widl.h"
#include "utils.h"
#include "parser.h"
#include "proxy.h"
#include "wpp.h"
static char usage[] =
"Usage: widl [options...] infile.idl\n"
" -d n Set debug level to 'n'\n"
" -D id[=val] Define preprocessor identifier id=val\n"
" -E Preprocess only\n"
" -H file Name of header file (default is infile.h)\n"
" -I path Set include search dir to path (multiple -I allowed)\n"
" -N Do not preprocess input\n"
" -V Print version and exit\n"
" -W Enable pedantic warnings\n"
"Debug level 'n' is a bitmask with following meaning:\n"
" * 0x01 Tell which resource is parsed (verbose mode)\n"
" * 0x02 Dump internal structures\n"
" * 0x04 Create a parser trace (yydebug=1)\n"
" * 0x08 Preprocessor messages\n"
" * 0x10 Preprocessor lex messages\n"
" * 0x20 Preprocessor yacc trace\n"
;
char version_string[] = "Wine IDL Compiler Version " WIDL_FULLVERSION "\n"
"Copyright 2002 Ove Kaaven\n";
int win32 = 1;
int debuglevel = DEBUGLEVEL_NONE;
int pedantic = 0;
int preprocess_only = 0;
int no_preprocess = 0;
char *input_name;
char *header_name;
char *proxy_name;
char *temp_name;
int line_number = 1;
int char_number = 1;
FILE *header;
FILE *proxy;
time_t now;
int getopt (int argc, char *const *argv, const char *optstring);
static void rm_tempfile(void);
static void segvhandler(int sig);
int main(int argc,char *argv[])
{
extern char* optarg;
extern int optind;
int optc;
int ret;
signal(SIGSEGV, segvhandler);
now = time(NULL);
while((optc = getopt(argc, argv, "d:D:EH:I:NVW")) != EOF) {
switch(optc) {
case 'd':
debuglevel = strtol(optarg, NULL, 0);
break;
case 'D':
wpp_add_cmdline_define(optarg);
break;
case 'E':
preprocess_only = 1;
break;
case 'H':
header_name = strdup(optarg);
break;
case 'I':
wpp_add_include_path(optarg);
break;
case 'N':
no_preprocess = 1;
break;
case 'V':
printf(version_string);
return 0;
case 'W':
pedantic = 1;
break;
default:
fprintf(stderr, usage);
return 1;
}
}
if(optind < argc) {
input_name = argv[optind];
}
else {
fprintf(stderr, usage);
return 1;
}
if(debuglevel)
{
setbuf(stdout,0);
setbuf(stderr,0);
}
yydebug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
wpp_set_debug( (debuglevel & DEBUGLEVEL_PPLEX) != 0,
(debuglevel & DEBUGLEVEL_PPTRACE) != 0,
(debuglevel & DEBUGLEVEL_PPMSG) != 0 );
if (!header_name) {
header_name = dup_basename(input_name, ".idl");
strcat(header_name, ".h");
}
if (!proxy_name) {
proxy_name = dup_basename(input_name, ".idl");
strcat(proxy_name, "_p.c");
}
atexit(rm_tempfile);
if (!no_preprocess)
{
chat("Starting preprocess");
if (!preprocess_only)
{
ret = wpp_parse_temp( input_name, &temp_name );
}
else
{
ret = wpp_parse( input_name, stdout );
}
if(ret) exit(1);
if(preprocess_only) exit(0);
input_name = temp_name;
}
if(!(yyin = fopen(input_name, "r"))) {
fprintf(stderr, "Could not open %s for input\n", input_name);
return 1;
}
header = fopen(header_name, "w");
fprintf(header, "/*** Autogenerated by WIDL %s - Do not edit ***/\n", WIDL_FULLVERSION);
ret = yyparse();
finish_proxy();
fclose(header);
fclose(yyin);
if(ret) {
exit(1);
}
return 0;
}
static void rm_tempfile(void)
{
abort_import();
if(temp_name)
unlink(temp_name);
}
static void segvhandler(int sig)
{
fprintf(stderr, "\n%s:%d: Oops, segment violation\n", input_name, line_number);
fflush(stdout);
fflush(stderr);
abort();
}
/*
* IDL Compiler
*
* Copyright 2002 Ove Kaaven
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WIDL_WIDL_H
#define __WIDL_WIDL_H
#include "widltypes.h"
#include <time.h>
#define WIDL_FULLVERSION "0.1"
extern int debuglevel;
#define DEBUGLEVEL_NONE 0x0000
#define DEBUGLEVEL_CHAT 0x0001
#define DEBUGLEVEL_DUMP 0x0002
#define DEBUGLEVEL_TRACE 0x0004
#define DEBUGLEVEL_PPMSG 0x0008
#define DEBUGLEVEL_PPLEX 0x0010
#define DEBUGLEVEL_PPTRACE 0x0020
extern int win32;
extern int pedantic;
extern char *input_name;
extern char *header_name;
extern char *proxy_name;
extern time_t now;
extern int line_number;
extern int char_number;
extern FILE* header;
extern FILE* proxy;
#endif
/*
* IDL Compiler
*
* Copyright 2002 Ove Kaaven
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WIDL_WIDLTYPES_H
#define __WIDL_WIDLTYPES_H
#include "windef.h"
#include "oleauto.h"
#include "wine/rpcfc.h"
typedef struct _attr_t attr_t;
typedef struct _type_t type_t;
typedef struct _typeref_t typeref_t;
typedef struct _var_t var_t;
typedef struct _func_t func_t;
#define DECL_LINK(type) \
type *l_next; \
type *l_prev;
#define LINK(x,y) do { x->l_next = y; if (y) y->l_prev = x; } while (0)
#define LINK_LAST(x,y) do { if (y) { typeof(x) _c = x; while (_c->l_next) _c = _c->l_next; LINK(_c, y); } } while (0)
#define LINK_SAFE(x,y) do { if (x) LINK_LAST(x,y); else { x = y; } } while (0)
#define INIT_LINK(x) do { x->l_next = NULL; x->l_prev = NULL; } while (0)
#define NEXT_LINK(x) ((x)->l_next)
#define PREV_LINK(x) ((x)->l_prev)
struct _attr_t {
int type;
union {
DWORD ival;
void *pval;
} u;
/* parser-internal */
DECL_LINK(attr_t)
};
struct _type_t {
char *name;
BYTE type;
struct _type_t *ref;
char *rname;
attr_t *attrs;
func_t *funcs;
var_t *fields;
int ignore, is_const;
int defined, written;
/* parser-internal */
DECL_LINK(type_t)
};
struct _typeref_t {
char *name;
type_t *ref;
int uniq;
};
struct _var_t {
char *name;
int ptr_level;
type_t *type;
char *tname;
attr_t *attrs;
/* parser-internal */
DECL_LINK(var_t)
};
struct _func_t {
var_t *def;
var_t *args;
int ignore, idx;
/* parser-internal */
DECL_LINK(func_t)
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment