[PATCH 4/5] d3dcompiler: Always use vkd3d-shader's preprocessor.
Matteo Bruni
mbruni at codeweavers.com
Mon Mar 28 07:12:18 CDT 2022
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
dlls/d3dcompiler_33/Makefile.in | 9 +-
dlls/d3dcompiler_34/Makefile.in | 9 +-
dlls/d3dcompiler_35/Makefile.in | 9 +-
dlls/d3dcompiler_36/Makefile.in | 9 +-
dlls/d3dcompiler_37/Makefile.in | 9 +-
dlls/d3dcompiler_38/Makefile.in | 9 +-
dlls/d3dcompiler_39/Makefile.in | 9 +-
dlls/d3dcompiler_40/Makefile.in | 9 +-
dlls/d3dcompiler_41/Makefile.in | 9 +-
dlls/d3dcompiler_42/Makefile.in | 9 +-
dlls/d3dcompiler_43/Makefile.in | 7 +-
dlls/d3dcompiler_43/compiler.c | 652 ++---------
dlls/d3dcompiler_43/ppl.l | 1547 -------------------------
dlls/d3dcompiler_43/ppy.y | 689 -----------
dlls/d3dcompiler_43/preproc.c | 447 -------
dlls/d3dcompiler_43/tests/asm.c | 15 +-
dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 3 +-
dlls/d3dcompiler_43/wpp_private.h | 251 ----
dlls/d3dcompiler_46/Makefile.in | 9 +-
dlls/d3dcompiler_47/Makefile.in | 9 +-
dlls/d3dx9_36/tests/asm.c | 2 +-
21 files changed, 154 insertions(+), 3567 deletions(-)
delete mode 100644 dlls/d3dcompiler_43/ppl.l
delete mode 100644 dlls/d3dcompiler_43/ppy.y
delete mode 100644 dlls/d3dcompiler_43/preproc.c
delete mode 100644 dlls/d3dcompiler_43/wpp_private.h
diff --git a/dlls/d3dcompiler_33/Makefile.in b/dlls/d3dcompiler_33/Makefile.in
index 988230890d8..c9aff6e7edd 100644
--- a/dlls/d3dcompiler_33/Makefile.in
+++ b/dlls/d3dcompiler_33/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_33.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=33
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_34/Makefile.in b/dlls/d3dcompiler_34/Makefile.in
index fb5ff5d0489..9d8f48e48ee 100644
--- a/dlls/d3dcompiler_34/Makefile.in
+++ b/dlls/d3dcompiler_34/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_34.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=34
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_35/Makefile.in b/dlls/d3dcompiler_35/Makefile.in
index 5e94da0e14b..1da7eca6c01 100644
--- a/dlls/d3dcompiler_35/Makefile.in
+++ b/dlls/d3dcompiler_35/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_35.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=35
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_36/Makefile.in b/dlls/d3dcompiler_36/Makefile.in
index 3a1f13a064e..62be7b22281 100644
--- a/dlls/d3dcompiler_36/Makefile.in
+++ b/dlls/d3dcompiler_36/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_36.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=36
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_37/Makefile.in b/dlls/d3dcompiler_37/Makefile.in
index 4afb74e419a..e8759d9e577 100644
--- a/dlls/d3dcompiler_37/Makefile.in
+++ b/dlls/d3dcompiler_37/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_37.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=37
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_38/Makefile.in b/dlls/d3dcompiler_38/Makefile.in
index 304548baadd..da528cc0509 100644
--- a/dlls/d3dcompiler_38/Makefile.in
+++ b/dlls/d3dcompiler_38/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_38.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=38
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_39/Makefile.in b/dlls/d3dcompiler_39/Makefile.in
index 87cb11b9572..94ec5aae839 100644
--- a/dlls/d3dcompiler_39/Makefile.in
+++ b/dlls/d3dcompiler_39/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_39.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=39
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_40/Makefile.in b/dlls/d3dcompiler_40/Makefile.in
index 443132d7002..10665d863ca 100644
--- a/dlls/d3dcompiler_40/Makefile.in
+++ b/dlls/d3dcompiler_40/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_40.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=40
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_41/Makefile.in b/dlls/d3dcompiler_41/Makefile.in
index a71dca88e6c..5d522857173 100644
--- a/dlls/d3dcompiler_41/Makefile.in
+++ b/dlls/d3dcompiler_41/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_41.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=41
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_42/Makefile.in b/dlls/d3dcompiler_42/Makefile.in
index ea9f0fc3faa..613ddee223e 100644
--- a/dlls/d3dcompiler_42/Makefile.in
+++ b/dlls/d3dcompiler_42/Makefile.in
@@ -1,5 +1,5 @@
MODULE = d3dcompiler_42.dll
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=42
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_43/Makefile.in b/dlls/d3dcompiler_43/Makefile.in
index b69f3749626..d02280305e8 100644
--- a/dlls/d3dcompiler_43/Makefile.in
+++ b/dlls/d3dcompiler_43/Makefile.in
@@ -11,16 +11,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_43/compiler.c b/dlls/d3dcompiler_43/compiler.c
index ba7789f45a8..2bbcb56c7ad 100644
--- a/dlls/d3dcompiler_43/compiler.c
+++ b/dlls/d3dcompiler_43/compiler.c
@@ -24,7 +24,6 @@
#include "wine/debug.h"
#include "d3dcompiler_private.h"
-#include "wpp_private.h"
#include <vkd3d_shader.h>
@@ -55,49 +54,8 @@ static HRESULT hresult_from_vkd3d_result(int vkd3d_result)
#define D3DXERR_INVALIDDATA 0x88760b59
-#define BUFFER_INITIAL_CAPACITY 256
-
-struct mem_file_desc
-{
- const char *buffer;
- unsigned int size;
- unsigned int pos;
-};
-
-static struct mem_file_desc current_shader;
-static ID3DInclude *current_include;
-static const char *initial_filename;
-
-#define INCLUDES_INITIAL_CAPACITY 4
-
-struct loaded_include
-{
- const char *name;
- const char *data;
-};
-
-static struct loaded_include *includes;
-static int includes_capacity, includes_size;
-static const char *parent_include;
-
-static char *wpp_output;
-static int wpp_output_capacity, wpp_output_size;
-
-static char *wpp_messages;
-static int wpp_messages_capacity, wpp_messages_size;
-
-struct define
-{
- struct define *next;
- char *name;
- char *value;
-};
-
-static struct define *cmdline_defines;
-
-/* Mutex used to guarantee a single invocation
- of the D3DXAssembleShader function (or its variants) at a time.
- This is needed as wpp isn't thread-safe */
+/* Mutex used to guarantee a single invocation of the D3DAssemble function at
+ * a time. This is needed as the assembler isn't thread-safe. */
static CRITICAL_SECTION wpp_mutex;
static CRITICAL_SECTION_DEBUG wpp_mutex_debug =
{
@@ -108,409 +66,21 @@ static CRITICAL_SECTION_DEBUG wpp_mutex_debug =
};
static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 };
-/* Preprocessor error reporting functions */
-static void wpp_write_message(const char *fmt, va_list args)
-{
- char* newbuffer;
- int rc, newsize;
-
- if(wpp_messages_capacity == 0)
- {
- wpp_messages = HeapAlloc(GetProcessHeap(), 0, MESSAGEBUFFER_INITIAL_SIZE);
- if(wpp_messages == NULL)
- return;
-
- wpp_messages_capacity = MESSAGEBUFFER_INITIAL_SIZE;
- }
-
- while(1)
- {
- rc = vsnprintf(wpp_messages + wpp_messages_size,
- wpp_messages_capacity - wpp_messages_size, fmt, args);
-
- if (rc < 0 || /* C89 */
- rc >= wpp_messages_capacity - wpp_messages_size) { /* C99 */
- /* Resize the buffer */
- newsize = wpp_messages_capacity * 2;
- newbuffer = HeapReAlloc(GetProcessHeap(), 0, wpp_messages, newsize);
- if(newbuffer == NULL)
- {
- ERR("Error reallocating memory for parser messages\n");
- return;
- }
- wpp_messages = newbuffer;
- wpp_messages_capacity = newsize;
- }
- else
- {
- wpp_messages_size += rc;
- return;
- }
- }
-}
-
-static void WINAPIV PRINTF_ATTR(1,2) wpp_write_message_var(const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- wpp_write_message(fmt, args);
- va_end(args);
-}
-
-int WINAPIV ppy_error(const char *msg, ...)
-{
- va_list ap;
- va_start(ap, msg);
- wpp_write_message_var("%s:%d:%d: %s: ",
- pp_status.input ? pp_status.input : "'main file'",
- pp_status.line_number, pp_status.char_number, "Error");
- wpp_write_message(msg, ap);
- wpp_write_message_var("\n");
- va_end(ap);
- pp_status.state = 1;
- return 1;
-}
-
-int WINAPIV ppy_warning(const char *msg, ...)
-{
- va_list ap;
- va_start(ap, msg);
- wpp_write_message_var("%s:%d:%d: %s: ",
- pp_status.input ? pp_status.input : "'main file'",
- pp_status.line_number, pp_status.char_number, "Warning");
- wpp_write_message(msg, ap);
- wpp_write_message_var("\n");
- va_end(ap);
- return 0;
-}
-
-char *wpp_lookup(const char *filename, int type, const char *parent_name)
-{
- /* We don't check for file existence here. We will potentially fail on
- * the following wpp_open_mem(). */
- char *path;
- int i;
-
- TRACE("Looking for include %s, parent %s.\n", debugstr_a(filename), debugstr_a(parent_name));
-
- parent_include = NULL;
- if (strcmp(parent_name, initial_filename))
- {
- for(i = 0; i < includes_size; i++)
- {
- if(!strcmp(parent_name, includes[i].name))
- {
- parent_include = includes[i].data;
- break;
- }
- }
- if(parent_include == NULL)
- {
- ERR("Parent include %s missing.\n", debugstr_a(parent_name));
- return NULL;
- }
- }
-
- path = malloc(strlen(filename) + 1);
- if(path)
- memcpy(path, filename, strlen(filename) + 1);
- return path;
-}
-
-void *wpp_open(const char *filename, int type)
-{
- struct mem_file_desc *desc;
- HRESULT hr;
-
- TRACE("Opening include %s.\n", debugstr_a(filename));
-
- if(!strcmp(filename, initial_filename))
- {
- current_shader.pos = 0;
- return ¤t_shader;
- }
-
- if(current_include == NULL) return NULL;
- desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
- if(!desc)
- return NULL;
-
- if (FAILED(hr = ID3DInclude_Open(current_include, type ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
- filename, parent_include, (const void **)&desc->buffer, &desc->size)))
- {
- HeapFree(GetProcessHeap(), 0, desc);
- return NULL;
- }
-
- if(includes_capacity == includes_size)
- {
- if(includes_capacity == 0)
- {
- includes = HeapAlloc(GetProcessHeap(), 0, INCLUDES_INITIAL_CAPACITY * sizeof(*includes));
- if(includes == NULL)
- {
- ERR("Error allocating memory for the loaded includes structure\n");
- goto error;
- }
- includes_capacity = INCLUDES_INITIAL_CAPACITY * sizeof(*includes);
- }
- else
- {
- int newcapacity = includes_capacity * 2;
- struct loaded_include *newincludes =
- HeapReAlloc(GetProcessHeap(), 0, includes, newcapacity);
- if(newincludes == NULL)
- {
- ERR("Error reallocating memory for the loaded includes structure\n");
- goto error;
- }
- includes = newincludes;
- includes_capacity = newcapacity;
- }
- }
- includes[includes_size].name = filename;
- includes[includes_size++].data = desc->buffer;
-
- desc->pos = 0;
- return desc;
-
-error:
- ID3DInclude_Close(current_include, desc->buffer);
- HeapFree(GetProcessHeap(), 0, desc);
- return NULL;
-}
-
-void wpp_close(void *file)
-{
- struct mem_file_desc *desc = file;
-
- if(desc != ¤t_shader)
- {
- if(current_include)
- ID3DInclude_Close(current_include, desc->buffer);
- else
- ERR("current_include == NULL, desc == %p, buffer = %s\n",
- desc, desc->buffer);
-
- HeapFree(GetProcessHeap(), 0, desc);
- }
-}
-
-int wpp_read(void *file, char *buffer, unsigned int len)
-{
- struct mem_file_desc *desc = file;
-
- len = min(len, desc->size - desc->pos);
- memcpy(buffer, desc->buffer + desc->pos, len);
- desc->pos += len;
- return len;
-}
-
-void wpp_write(const char *buffer, unsigned int len)
-{
- char *new_wpp_output;
-
- if(wpp_output_capacity == 0)
- {
- wpp_output = HeapAlloc(GetProcessHeap(), 0, BUFFER_INITIAL_CAPACITY);
- if(!wpp_output)
- return;
-
- wpp_output_capacity = BUFFER_INITIAL_CAPACITY;
- }
- if(len > wpp_output_capacity - wpp_output_size)
- {
- while(len > wpp_output_capacity - wpp_output_size)
- {
- wpp_output_capacity *= 2;
- }
- new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
- wpp_output_capacity);
- if(!new_wpp_output)
- {
- ERR("Error allocating memory\n");
- return;
- }
- wpp_output = new_wpp_output;
- }
- memcpy(wpp_output + wpp_output_size, buffer, len);
- wpp_output_size += len;
-}
-
-static int wpp_close_output(void)
-{
- char *new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
- wpp_output_size + 1);
- if(!new_wpp_output) return 0;
- wpp_output = new_wpp_output;
- wpp_output[wpp_output_size]='\0';
- wpp_output_size++;
- return 1;
-}
-
-static void add_cmdline_defines(void)
-{
- struct define *def;
-
- for (def = cmdline_defines; def; def = def->next)
- {
- if (def->value) pp_add_define( def->name, def->value );
- }
-}
-
-static void del_cmdline_defines(void)
-{
- struct define *def;
-
- for (def = cmdline_defines; def; def = def->next)
- {
- if (def->value) pp_del_define( def->name );
- }
-}
-
-static void add_special_defines(void)
-{
- time_t now = time(NULL);
- pp_entry_t *ppp;
- char buf[32];
-
- strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now));
- pp_add_define( "__DATE__", buf );
-
- strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
- pp_add_define( "__TIME__", buf );
-
- ppp = pp_add_define( "__FILE__", "" );
- if(ppp)
- ppp->type = def_special;
-
- ppp = pp_add_define( "__LINE__", "" );
- if(ppp)
- ppp->type = def_special;
-}
-
-static void del_special_defines(void)
-{
- pp_del_define( "__DATE__" );
- pp_del_define( "__TIME__" );
- pp_del_define( "__FILE__" );
- pp_del_define( "__LINE__" );
-}
-
-
-/* add a define to the preprocessor list */
-int wpp_add_define( const char *name, const char *value )
-{
- struct define *def;
-
- if (!value) value = "";
-
- for (def = cmdline_defines; def; def = def->next)
- {
- if (!strcmp( def->name, name ))
- {
- char *new_value = pp_xstrdup(value);
- if(!new_value)
- return 1;
- free( def->value );
- def->value = new_value;
-
- return 0;
- }
- }
-
- def = pp_xmalloc( sizeof(*def) );
- if(!def)
- return 1;
- def->next = cmdline_defines;
- def->name = pp_xstrdup(name);
- if(!def->name)
- {
- free(def);
- return 1;
- }
- def->value = pp_xstrdup(value);
- if(!def->value)
- {
- free(def->name);
- free(def);
- return 1;
- }
- cmdline_defines = def;
- return 0;
-}
-
-
-/* undefine a previously added definition */
-void wpp_del_define( const char *name )
+struct d3dcompiler_include_from_file
{
- struct define *def;
-
- for (def = cmdline_defines; def; def = def->next)
- {
- if (!strcmp( def->name, name ))
- {
- free( def->value );
- def->value = NULL;
- return;
- }
- }
-}
-
+ ID3DInclude ID3DInclude_iface;
+ const char *initial_filename;
+};
-/* the main preprocessor parsing loop */
-int wpp_parse( const char *input, FILE *output )
+static inline struct d3dcompiler_include_from_file *impl_from_ID3DInclude(ID3DInclude *iface)
{
- int ret;
-
- pp_status.input = NULL;
- pp_status.line_number = 1;
- pp_status.char_number = 1;
- pp_status.state = 0;
-
- ret = pp_push_define_state();
- if(ret)
- return ret;
- add_cmdline_defines();
- add_special_defines();
-
- if (!input) pp_status.file = stdin;
- else if (!(pp_status.file = wpp_open(input, 1)))
- {
- ppy_error("Could not open %s\n", input);
- del_special_defines();
- del_cmdline_defines();
- pp_pop_define_state();
- return 2;
- }
-
- pp_status.input = input ? pp_xstrdup(input) : NULL;
-
- ppy_out = output;
- pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
-
- ret = ppy_parse();
- /* If there were errors during processing, return an error code */
- if (!ret && pp_status.state) ret = pp_status.state;
-
- if (input)
- {
- wpp_close(pp_status.file);
- free(pp_status.input);
- }
- /* Clean if_stack, it could remain dirty on errors */
- while (pp_get_if_depth()) pp_pop_if();
- ppy_lex_destroy();
- del_special_defines();
- del_cmdline_defines();
- pp_pop_define_state();
- return ret;
+ return CONTAINING_RECORD(iface, struct d3dcompiler_include_from_file, ID3DInclude_iface);
}
static HRESULT WINAPI d3dcompiler_include_from_file_open(ID3DInclude *iface, D3D_INCLUDE_TYPE include_type,
const char *filename, const void *parent_data, const void **data, UINT *bytes)
{
+ struct d3dcompiler_include_from_file *include = impl_from_ID3DInclude(iface);
char *fullpath, *buffer = NULL, current_dir[MAX_PATH + 1];
const char *initial_dir;
SIZE_T size;
@@ -518,10 +88,10 @@ static HRESULT WINAPI d3dcompiler_include_from_file_open(ID3DInclude *iface, D3D
ULONG read;
DWORD len;
- if ((initial_dir = strrchr(initial_filename, '\\')))
+ if ((initial_dir = strrchr(include->initial_filename, '\\')))
{
- len = initial_dir - initial_filename + 1;
- initial_dir = initial_filename;
+ len = initial_dir - include->initial_filename + 1;
+ initial_dir = include->initial_filename;
}
else
{
@@ -578,85 +148,106 @@ const struct ID3DIncludeVtbl d3dcompiler_include_from_file_vtbl =
d3dcompiler_include_from_file_close
};
-struct d3dcompiler_include_from_file
+static int open_include(const char *filename, bool local, const char *parent_data, void *context,
+ struct vkd3d_shader_code *code)
{
- ID3DInclude ID3DInclude_iface;
-};
+ ID3DInclude *iface = context;
+ unsigned int size = 0;
+
+ if (!iface)
+ return VKD3D_ERROR;
+
+ memset(code, 0, sizeof(*code));
+ if (FAILED(ID3DInclude_Open(iface, local ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
+ filename, parent_data, &code->code, &size)))
+ return VKD3D_ERROR;
+
+ code->size = size;
+ return VKD3D_OK;
+}
+
+static void close_include(const struct vkd3d_shader_code *code, void *context)
+{
+ ID3DInclude *iface = context;
+
+ ID3DInclude_Close(iface, code->code);
+}
static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char *filename,
- const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **error_messages)
+ const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **shader_blob,
+ ID3DBlob **messages_blob)
{
struct d3dcompiler_include_from_file include_from_file;
- int ret;
- HRESULT hr = S_OK;
+ struct vkd3d_shader_preprocess_info preprocess_info;
+ struct vkd3d_shader_compile_info compile_info;
const D3D_SHADER_MACRO *def = defines;
+ struct vkd3d_shader_code byte_code;
+ char *messages;
+ HRESULT hr;
+ int ret;
if (include == D3D_COMPILE_STANDARD_FILE_INCLUDE)
{
include_from_file.ID3DInclude_iface.lpVtbl = &d3dcompiler_include_from_file_vtbl;
+ include_from_file.initial_filename = filename ? filename : "";
include = &include_from_file.ID3DInclude_iface;
}
- if (def != NULL)
+ compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
+ compile_info.next = &preprocess_info;
+ compile_info.source.code = data;
+ compile_info.source.size = data_size;
+ compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL;
+ compile_info.target_type = VKD3D_SHADER_TARGET_NONE;
+ compile_info.options = NULL;
+ compile_info.option_count = 0;
+ compile_info.log_level = VKD3D_SHADER_LOG_INFO;
+ compile_info.source_name = filename;
+
+ preprocess_info.type = VKD3D_SHADER_STRUCTURE_TYPE_PREPROCESS_INFO;
+ preprocess_info.next = NULL;
+ preprocess_info.macros = (const struct vkd3d_shader_macro *)defines;
+ preprocess_info.macro_count = 0;
+ if (defines)
{
- while (def->Name != NULL)
- {
- wpp_add_define(def->Name, def->Definition);
- def++;
- }
+ for (def = defines; def->Name; ++def)
+ ++preprocess_info.macro_count;
}
- current_include = include;
- includes_size = 0;
-
- wpp_output_size = wpp_output_capacity = 0;
- wpp_output = NULL;
-
- wpp_messages_size = wpp_messages_capacity = 0;
- wpp_messages = NULL;
- current_shader.buffer = data;
- current_shader.size = data_size;
- initial_filename = filename ? filename : "";
-
- ret = wpp_parse(initial_filename, NULL);
- if (!wpp_close_output())
- ret = 1;
- if (ret)
+ preprocess_info.pfn_open_include = open_include;
+ preprocess_info.pfn_close_include = close_include;
+ preprocess_info.include_context = include;
+
+ ret = vkd3d_shader_preprocess(&compile_info, &byte_code, &messages);
+ if (messages)
{
- TRACE("Error during shader preprocessing\n");
- if (wpp_messages)
+ if (messages_blob)
{
- int size;
- ID3DBlob *buffer;
-
- TRACE("Preprocessor messages:\n%s\n", debugstr_a(wpp_messages));
-
- if (error_messages)
+ size_t size = strlen(messages);
+ if (FAILED(hr = D3DCreateBlob(size, messages_blob)))
{
- size = strlen(wpp_messages) + 1;
- hr = D3DCreateBlob(size, &buffer);
- if (FAILED(hr))
- goto cleanup;
- CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_messages, size);
- *error_messages = buffer;
+ vkd3d_shader_free_messages(messages);
+ vkd3d_shader_free_shader_code(&byte_code);
+ return hr;
}
+ memcpy(ID3D10Blob_GetBufferPointer(*messages_blob), messages, size);
+ }
+ else
+ {
+ vkd3d_shader_free_messages(messages);
}
- if (data)
- TRACE("Shader source:\n%s\n", debugstr_an(data, data_size));
- hr = E_FAIL;
}
-cleanup:
- /* Remove the previously added defines */
- if (defines != NULL)
+ if (!ret)
{
- while (defines->Name != NULL)
+ if (FAILED(hr = D3DCreateBlob(byte_code.size, shader_blob)))
{
- wpp_del_define(defines->Name);
- defines++;
+ vkd3d_shader_free_shader_code(&byte_code);
+ return hr;
}
+ memcpy(ID3D10Blob_GetBufferPointer(*shader_blob), byte_code.code, byte_code.size);
}
- HeapFree(GetProcessHeap(), 0, wpp_messages);
- return hr;
+
+ return hresult_from_vkd3d_result(ret);
}
static HRESULT assemble_shader(const char *preproc_shader, ID3DBlob **shader_blob, ID3DBlob **error_messages)
@@ -739,6 +330,9 @@ HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filena
const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags,
ID3DBlob **shader, ID3DBlob **error_messages)
{
+ unsigned int preproc_size;
+ ID3DBlob *preproc_shader;
+ char *preproc_terminated;
HRESULT hr;
TRACE("data %p, datasize %Iu, filename %s, defines %p, include %p, sflags %#x, "
@@ -753,40 +347,24 @@ HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filena
if (shader) *shader = NULL;
if (error_messages) *error_messages = NULL;
- hr = preprocess_shader(data, datasize, filename, defines, include, error_messages);
+ hr = preprocess_shader(data, datasize, filename, defines, include, &preproc_shader, error_messages);
if (SUCCEEDED(hr))
- hr = assemble_shader(wpp_output, shader, error_messages);
+ {
+ preproc_size = ID3D10Blob_GetBufferSize(preproc_shader);
+ if ((preproc_terminated = malloc(preproc_size + 1)))
+ {
+ memcpy(preproc_terminated, ID3D10Blob_GetBufferPointer(preproc_shader), preproc_size);
+ ID3D10Blob_Release(preproc_shader);
+ preproc_terminated[preproc_size] = 0;
- HeapFree(GetProcessHeap(), 0, wpp_output);
+ hr = assemble_shader(preproc_terminated, shader, error_messages);
+ free(preproc_terminated);
+ }
+ }
LeaveCriticalSection(&wpp_mutex);
return hr;
}
-static int open_include(const char *filename, bool local, const char *parent_data, void *context,
- struct vkd3d_shader_code *code)
-{
- ID3DInclude *iface = context;
- unsigned int size = 0;
-
- if (!iface)
- return VKD3D_ERROR;
-
- memset(code, 0, sizeof(*code));
- if (FAILED(ID3DInclude_Open(iface, local ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
- filename, parent_data, &code->code, &size)))
- return VKD3D_ERROR;
-
- code->size = size;
- return VKD3D_OK;
-}
-
-static void close_include(const struct vkd3d_shader_code *code, void *context)
-{
- ID3DInclude *iface = context;
-
- ID3DInclude_Close(iface, code->code);
-}
-
HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename,
const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point,
const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags,
@@ -839,6 +417,7 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen
if (include == D3D_COMPILE_STANDARD_FILE_INCLUDE)
{
include_from_file.ID3DInclude_iface.lpVtbl = &d3dcompiler_include_from_file_vtbl;
+ include_from_file.initial_filename = filename ? filename : "";
include = &include_from_file.ID3DInclude_iface;
}
@@ -891,7 +470,6 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen
preprocess_info.pfn_open_include = open_include;
preprocess_info.pfn_close_include = close_include;
preprocess_info.include_context = include;
- initial_filename = filename ? filename : "";
hlsl_info.type = VKD3D_SHADER_STRUCTURE_TYPE_HLSL_SOURCE_INFO;
hlsl_info.next = NULL;
@@ -955,40 +533,16 @@ HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename
const D3D_SHADER_MACRO *defines, ID3DInclude *include,
ID3DBlob **shader, ID3DBlob **error_messages)
{
- HRESULT hr;
- ID3DBlob *buffer;
-
TRACE("data %p, size %Iu, filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
data, size, debugstr_a(filename), defines, include, shader, error_messages);
if (!data)
return E_INVALIDARG;
- EnterCriticalSection(&wpp_mutex);
-
if (shader) *shader = NULL;
if (error_messages) *error_messages = NULL;
- hr = preprocess_shader(data, size, filename, defines, include, error_messages);
-
- if (SUCCEEDED(hr))
- {
- if (shader)
- {
- hr = D3DCreateBlob(wpp_output_size, &buffer);
- if (FAILED(hr))
- goto cleanup;
- CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_output, wpp_output_size);
- *shader = buffer;
- }
- else
- hr = E_INVALIDARG;
- }
-
-cleanup:
- HeapFree(GetProcessHeap(), 0, wpp_output);
- LeaveCriticalSection(&wpp_mutex);
- return hr;
+ return preprocess_shader(data, size, filename, defines, include, shader, error_messages);
}
HRESULT WINAPI D3DDisassemble(const void *data, SIZE_T size, UINT flags, const char *comments, ID3DBlob **disassembly)
diff --git a/dlls/d3dcompiler_43/ppl.l b/dlls/d3dcompiler_43/ppl.l
deleted file mode 100644
index a1f5298a1ab..00000000000
--- a/dlls/d3dcompiler_43/ppl.l
+++ /dev/null
@@ -1,1547 +0,0 @@
-/* -*-C-*-
- * Wrc preprocessor lexical analysis
- *
- * Copyright 1999-2000 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- *
- *-------------------------------------------------------------------------
- * The preprocessor's lexographical grammar (approximately):
- *
- * pp := {ws} # {ws} if {ws} {expr} {ws} \n
- * | {ws} # {ws} ifdef {ws} {id} {ws} \n
- * | {ws} # {ws} ifndef {ws} {id} {ws} \n
- * | {ws} # {ws} elif {ws} {expr} {ws} \n
- * | {ws} # {ws} else {ws} \n
- * | {ws} # {ws} endif {ws} \n
- * | {ws} # {ws} include {ws} < {anytext} > \n
- * | {ws} # {ws} include {ws} " {anytext} " \n
- * | {ws} # {ws} define {ws} {anytext} \n
- * | {ws} # {ws} define( {arglist} ) {ws} {expansion} \n
- * | {ws} # {ws} pragma {ws} {anytext} \n
- * | {ws} # {ws} ident {ws} {anytext} \n
- * | {ws} # {ws} error {ws} {anytext} \n
- * | {ws} # {ws} warning {ws} {anytext} \n
- * | {ws} # {ws} line {ws} " {anytext} " {number} \n
- * | {ws} # {ws} {number} " {anytext} " {number} [ {number} [{number}] ] \n
- * | {ws} # {ws} \n
- *
- * ws := [ \t\r\f\v]*
- *
- * expr := {expr} [+-*%^/|&] {expr}
- * | {expr} {logor|logand} {expr}
- * | [!~+-] {expr}
- * | {expr} ? {expr} : {expr}
- *
- * logor := ||
- *
- * logand := &&
- *
- * id := [a-zA-Z_][a-zA-Z0-9_]*
- *
- * anytext := [^\n]* (see note)
- *
- * arglist :=
- * | {id}
- * | {arglist} , {id}
- * | {arglist} , {id} ...
- *
- * expansion := {id}
- * | # {id}
- * | {anytext}
- * | {anytext} ## {anytext}
- *
- * number := [0-9]+
- *
- * Note: "anytext" is not always "[^\n]*". This is because the
- * trailing context must be considered as well.
- *
- * The only certain assumption for the preprocessor to make is that
- * directives start at the beginning of the line, followed by a '#'
- * and end with a newline.
- * Any directive may be suffixed with a line-continuation. Also
- * classical comment / *...* / (note: no comments within comments,
- * therefore spaces) is considered to be a line-continuation
- * (according to gcc and egcs AFAIK, ANSI is a bit vague).
- * Comments have not been added to the above grammar for simplicity
- * reasons. However, it is allowed to enter comment anywhere within
- * the directives as long as they do not interfere with the context.
- * All comments are considered to be deletable whitespace (both
- * classical form "/ *...* /" and C++ form "//...\n").
- *
- * All recursive scans, except for macro-expansion, are done by the
- * parser, whereas the simple state transitions of non-recursive
- * directives are done in the scanner. This results in the many
- * exclusive start-conditions of the scanner.
- *
- * Macro expansions are slightly more difficult because they have to
- * prescan the arguments. Parameter substitution is literal if the
- * substitution is # or ## (either side). This enables new identifiers
- * to be created (see 'info cpp' node Macro|Pitfalls|Prescan for more
- * information).
- *
- * FIXME: Variable macro parameters is recognized, but not yet
- * expanded. I have to reread the ANSI standard on the subject (yes,
- * ANSI defines it).
- *
- * The following special defines are supported:
- * __FILE__ -> "thissource.c"
- * __LINE__ -> 123
- * __DATE__ -> "May 1 2000"
- * __TIME__ -> "23:59:59"
- * These macros expand, as expected, into their ANSI defined values.
- *
- * The same include prevention is implemented as gcc and egcs does.
- * This results in faster processing because we do not read the text
- * at all. Some wine-sources attempt to include the same file 4 or 5
- * times. This strategy also saves a lot blank output-lines, which in
- * its turn improves the real resource scanner/parser.
- *
- */
-
-/*
- * Special flex options and exclusive scanner start-conditions
- */
-%option stack
-%option 8bit never-interactive
-%option noinput nounput
-%option prefix="ppy_"
-
-%x pp_pp
-%x pp_eol
-%x pp_inc
-%x pp_dqs
-%x pp_sqs
-%x pp_iqs
-%x pp_comment
-%x pp_def
-%x pp_define
-%x pp_macro
-%x pp_mbody
-%x pp_macign
-%x pp_macscan
-%x pp_macexp
-%x pp_if
-%x pp_ifd
-%x pp_ifignored
-%x pp_endif
-%x pp_line
-%x pp_defined
-%x pp_ignore
-%x RCINCL
-
-ws [ \v\f\t\r]
-cident [a-zA-Z_][0-9a-zA-Z_]*
-ul [uUlL]|[uUlL][lL]|[lL][uU]|[lL][lL][uU]|[uU][lL][lL]|[lL][uU][lL]
-
-%{
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <assert.h>
-#include <errno.h>
-#include <limits.h>
-
-#define YY_NO_UNISTD_H
-
-#include "wpp_private.h"
-#include "ppy.tab.h"
-
-/*
- * Make sure that we are running an appropriate version of flex.
- */
-#if !defined(YY_FLEX_MAJOR_VERSION) || (1000 * YY_FLEX_MAJOR_VERSION + YY_FLEX_MINOR_VERSION < 2005)
-#error Must use flex version 2.5.1 or higher (yy_scan_* routines are required).
-#endif
-
-#define YY_READ_BUF_SIZE 65536 /* So we read most of a file at once */
-
-#define yy_current_state() YY_START
-#define yy_pp_state(x) yy_pop_state(); yy_push_state(x)
-
-/*
- * Always update the current character position within a line
- */
-#define YY_USER_ACTION pp_status.char_number+=ppy_leng;
-
-/*
- * Buffer management for includes and expansions
- */
-#define MAXBUFFERSTACK 128 /* Nesting more than 128 includes or macro expansion textss is insane */
-
-typedef struct bufferstackentry {
- YY_BUFFER_STATE bufferstate; /* Buffer to switch back to */
- void *filehandle; /* Handle to be used with wpp_callbacks->read */
- pp_entry_t *define; /* Points to expanding define or NULL if handling includes */
- int line_number; /* Line that we were handling */
- int char_number; /* The current position on that line */
- char *filename; /* Filename that we were handling */
- int if_depth; /* How many #if:s deep to check matching #endif:s */
- int ncontinuations; /* Remember the continuation state */
- int should_pop; /* Set if we must pop the start-state on EOF */
- /* Include management */
- include_state_t incl;
- char *include_filename;
-} bufferstackentry_t;
-
-#define ALLOCBLOCKSIZE (1 << 10) /* Allocate these chunks at a time for string-buffers */
-
-/*
- * Macro expansion nesting
- * We need the stack to handle expansions while scanning
- * a macro's arguments. The TOS must always be the macro
- * that receives the current expansion from the scanner.
- */
-#define MAXMACEXPSTACK 128 /* Nesting more than 128 macro expansions is insane */
-
-typedef struct macexpstackentry {
- pp_entry_t *ppp; /* This macro we are scanning */
- char **args; /* With these arguments */
- char **ppargs; /* Resulting in these preprocessed arguments */
- int *nnls; /* Number of newlines per argument */
- int nargs; /* And this many arguments scanned */
- int parentheses; /* Nesting level of () */
- int curargsize; /* Current scanning argument's size */
- int curargalloc; /* Current scanning argument's block allocated */
- char *curarg; /* Current scanning argument's content */
-} macexpstackentry_t;
-
-#define MACROPARENTHESES() (top_macro()->parentheses)
-
-/*
- * Prototypes
- */
-static void newline(int);
-static int make_number(int radix, PPY_STYPE *val, const char *str, int len);
-static void put_buffer(const char *s, int len);
-/* Buffer management */
-static void push_buffer(pp_entry_t *ppp, char *filename, char *incname, int pop);
-static bufferstackentry_t *pop_buffer(void);
-/* String functions */
-static void new_string(void);
-static void add_string(const char *str, int len);
-static char *get_string(void);
-static void put_string(void);
-static int string_start(void);
-/* Macro functions */
-static void push_macro(pp_entry_t *ppp);
-static macexpstackentry_t *top_macro(void);
-static macexpstackentry_t *pop_macro(void);
-static void free_macro(macexpstackentry_t *mep);
-static void add_text_to_macro(const char *text, int len);
-static void macro_add_arg(int last);
-static void macro_add_expansion(void);
-/* Expansion */
-static void expand_special(pp_entry_t *ppp);
-static void expand_define(pp_entry_t *ppp);
-static void expand_macro(macexpstackentry_t *mep);
-
-/*
- * Local variables
- */
-static int ncontinuations;
-
-static int strbuf_idx = 0;
-static int strbuf_alloc = 0;
-static char *strbuffer = NULL;
-static int str_startline;
-
-static macexpstackentry_t *macexpstack[MAXMACEXPSTACK];
-static int macexpstackidx = 0;
-
-static bufferstackentry_t bufferstack[MAXBUFFERSTACK];
-static int bufferstackidx = 0;
-
-/*
- * Global variables
- */
-include_state_t pp_incl_state =
-{
- -1, /* state */
- NULL, /* ppp */
- 0, /* ifdepth */
- 0 /* seen_junk */
-};
-
-includelogicentry_t *pp_includelogiclist = NULL;
-
-#define YY_INPUT(buf,result,max_size) \
- { \
- result = wpp_read(pp_status.file, buf, max_size); \
- }
-
-#define BUFFERINITIALCAPACITY 256
-
-void WINAPIV pp_writestring(const char *format, ...)
-{
- va_list valist;
- int len;
- static char *buffer;
- static int buffercapacity;
- char *new_buffer;
-
- if(buffercapacity == 0)
- {
- buffer = pp_xmalloc(BUFFERINITIALCAPACITY);
- if(buffer == NULL)
- return;
- buffercapacity = BUFFERINITIALCAPACITY;
- }
-
- va_start(valist, format);
- len = vsnprintf(buffer, buffercapacity,
- format, valist);
- va_end(valist);
- /* If the string is longer than buffersize, vsnprintf returns
- * the string length with glibc >= 2.1, -1 with glibc < 2.1 */
- while(len > buffercapacity || len < 0)
- {
- do
- {
- buffercapacity *= 2;
- } while(len > buffercapacity);
-
- new_buffer = pp_xrealloc(buffer, buffercapacity);
- if(new_buffer == NULL)
- return;
- buffer = new_buffer;
- va_start(valist, format);
- len = vsnprintf(buffer, buffercapacity,
- format, valist);
- va_end(valist);
- }
-
- wpp_write(buffer, len);
-}
-
-%}
-
-/*
- **************************************************************************
- * The scanner starts here
- **************************************************************************
- */
-
-%%
- /*
- * Catch line-continuations.
- * Note: Gcc keeps the line-continuations in, for example, strings
- * intact. However, I prefer to remove them all so that the next
- * scanner will not need to reduce the continuation state.
- *
- * <*>\\\n newline(0);
- */
-
- /*
- * Detect the leading # of a preprocessor directive.
- */
-<INITIAL,pp_ignore>^{ws}*# pp_incl_state.seen_junk++; yy_push_state(pp_pp);
-
- /*
- * Scan for the preprocessor directives
- */
-<pp_pp>{ws}*include{ws}* if(yy_top_state() != pp_ignore) {yy_pp_state(pp_inc); return tINCLUDE;} else {yy_pp_state(pp_eol);}
-<pp_pp>{ws}*define{ws}* yy_pp_state(yy_current_state() != pp_ignore ? pp_def : pp_eol);
-<pp_pp>{ws}*error{ws}* yy_pp_state(pp_eol); if(yy_top_state() != pp_ignore) return tERROR;
-<pp_pp>{ws}*warning{ws}* yy_pp_state(pp_eol); if(yy_top_state() != pp_ignore) return tWARNING;
-<pp_pp>{ws}*pragma{ws}* yy_pp_state(pp_eol); if(yy_top_state() != pp_ignore) return tPRAGMA;
-<pp_pp>{ws}*ident{ws}* yy_pp_state(pp_eol); if(yy_top_state() != pp_ignore) return tPPIDENT;
-<pp_pp>{ws}*undef{ws}* if(yy_top_state() != pp_ignore) {yy_pp_state(pp_ifd); return tUNDEF;} else {yy_pp_state(pp_eol);}
-<pp_pp>{ws}*ifdef{ws}* yy_pp_state(pp_ifd); return tIFDEF;
-<pp_pp>{ws}*ifndef{ws}* pp_incl_state.seen_junk--; yy_pp_state(pp_ifd); return tIFNDEF;
-<pp_pp>{ws}*if{ws}* if(yy_top_state() != pp_ignore) {yy_pp_state(pp_if);} else {yy_pp_state(pp_ifignored);} return tIF;
-<pp_pp>{ws}*elif{ws}* yy_pp_state(pp_if); return tELIF;
-<pp_pp>{ws}*else{ws}* yy_pp_state(pp_endif); return tELSE;
-<pp_pp>{ws}*endif{ws}* yy_pp_state(pp_endif); return tENDIF;
-<pp_pp>{ws}*line{ws}* if(yy_top_state() != pp_ignore) {yy_pp_state(pp_line); return tLINE;} else {yy_pp_state(pp_eol);}
-<pp_pp>{ws}+ if(yy_top_state() != pp_ignore) {yy_pp_state(pp_line); return tGCCLINE;} else {yy_pp_state(pp_eol);}
-<pp_pp>{ws}*[a-z]+ ppy_error("Invalid preprocessor token '%s'", ppy_text);
-<pp_pp>\r?\n newline(1); yy_pop_state(); return tNL; /* This could be the null-token */
-<pp_pp>\\\r?\n newline(0);
-<pp_pp>\\\r? ppy_error("Preprocessor junk '%s'", ppy_text);
-<pp_pp>. return *ppy_text;
-
- /*
- * Handle #include and #line
- */
-<pp_line>[0-9]+ return make_number(10, &ppy_lval, ppy_text, ppy_leng);
-<pp_inc>\< new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_iqs);
-<pp_inc,pp_line>\" new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_dqs);
-<pp_inc,pp_line>{ws}+ ;
-<pp_inc,pp_line>\n newline(1); yy_pop_state(); return tNL;
-<pp_inc,pp_line>\\\r?\n newline(0);
-<pp_inc,pp_line>(\\\r?)|(.) ppy_error(yy_current_state() == pp_inc ? "Trailing junk in #include" : "Trailing junk in #line");
-
- /*
- * Ignore all input when a false clause is parsed
- */
-<pp_ignore>[^#/\\\n]+ ;
-<pp_ignore>\n newline(1);
-<pp_ignore>\\\r?\n newline(0);
-<pp_ignore>(\\\r?)|(.) ;
-
- /*
- * Handle #if and #elif.
- * These require conditionals to be evaluated, but we do not
- * want to jam the scanner normally when we see these tokens.
- * Note: tIDENT is handled below.
- */
-
-<pp_if>0[0-7]*{ul}? return make_number(8, &ppy_lval, ppy_text, ppy_leng);
-<pp_if>0[0-7]*[8-9]+{ul}? ppy_error("Invalid octal digit");
-<pp_if>[1-9][0-9]*{ul}? return make_number(10, &ppy_lval, ppy_text, ppy_leng);
-<pp_if>0[xX][0-9a-fA-F]+{ul}? return make_number(16, &ppy_lval, ppy_text, ppy_leng);
-<pp_if>0[xX] ppy_error("Invalid hex number");
-<pp_if>defined yy_push_state(pp_defined); return tDEFINED;
-<pp_if>"<<" return tLSHIFT;
-<pp_if>">>" return tRSHIFT;
-<pp_if>"&&" return tLOGAND;
-<pp_if>"||" return tLOGOR;
-<pp_if>"==" return tEQ;
-<pp_if>"!=" return tNE;
-<pp_if>"<=" return tLTE;
-<pp_if>">=" return tGTE;
-<pp_if>\n newline(1); yy_pop_state(); return tNL;
-<pp_if>\\\r?\n newline(0);
-<pp_if>\\\r? ppy_error("Junk in conditional expression");
-<pp_if>{ws}+ ;
-<pp_if>\' new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_sqs);
-<pp_if>\" ppy_error("String constants not allowed in conditionals");
-<pp_if>. return *ppy_text;
-
-<pp_ifignored>[^\n]+ ppy_lval.sint = 0; return tSINT;
-<pp_ifignored>\n newline(1); yy_pop_state(); return tNL;
-
- /*
- * Handle #ifdef, #ifndef and #undef
- * to get only an untranslated/unexpanded identifier
- */
-<pp_ifd>{cident} ppy_lval.cptr = pp_xstrdup(ppy_text); return tIDENT;
-<pp_ifd>{ws}+ ;
-<pp_ifd>\n newline(1); yy_pop_state(); return tNL;
-<pp_ifd>\\\r?\n newline(0);
-<pp_ifd>(\\\r?)|(.) ppy_error("Identifier expected");
-
- /*
- * Handle #else and #endif.
- */
-<pp_endif>{ws}+ ;
-<pp_endif>\n newline(1); yy_pop_state(); return tNL;
-<pp_endif>\\\r?\n newline(0);
-<pp_endif>. ppy_error("Garbage after #else or #endif.");
-
- /*
- * Handle the special 'defined' keyword.
- * This is necessary to get the identifier prior to any
- * substitutions.
- */
-<pp_defined>{cident} yy_pop_state(); ppy_lval.cptr = pp_xstrdup(ppy_text); return tIDENT;
-<pp_defined>{ws}+ ;
-<pp_defined>(\()|(\)) return *ppy_text;
-<pp_defined>\\\r?\n newline(0);
-<pp_defined>(\\.)|(\n)|(.) ppy_error("Identifier expected");
-
- /*
- * Handle #error, #warning, #pragma and #ident.
- * Pass everything literally to the parser, which
- * will act appropriately.
- * Comments are stripped from the literal text.
- */
-<pp_eol>[^/\\\n]+ if(yy_top_state() != pp_ignore) { ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL; }
-<pp_eol>\/[^/\\\n*]* if(yy_top_state() != pp_ignore) { ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL; }
-<pp_eol>(\\\r?)|(\/[^/*]) if(yy_top_state() != pp_ignore) { ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL; }
-<pp_eol>\n newline(1); yy_pop_state(); if(yy_current_state() != pp_ignore) { return tNL; }
-<pp_eol>\\\r?\n newline(0);
-
- /*
- * Handle left side of #define
- */
-<pp_def>{cident}\( ppy_lval.cptr = pp_xstrdup(ppy_text); if(ppy_lval.cptr) ppy_lval.cptr[ppy_leng-1] = '\0'; yy_pp_state(pp_macro); return tMACRO;
-<pp_def>{cident} ppy_lval.cptr = pp_xstrdup(ppy_text); yy_pp_state(pp_define); return tDEFINE;
-<pp_def>{ws}+ ;
-<pp_def>\\\r?\n newline(0);
-<pp_def>(\\\r?)|(\n)|(.) perror("Identifier expected");
-
- /*
- * Scan the substitution of a define
- */
-<pp_define>[^'"/\\\n]+ ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
-<pp_define>(\\\r?)|(\/[^/*]) ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
-<pp_define>\\\r?\n{ws}+ newline(0); ppy_lval.cptr = pp_xstrdup(" "); return tLITERAL;
-<pp_define>\\\r?\n newline(0);
-<pp_define>\n newline(1); yy_pop_state(); return tNL;
-<pp_define>\' new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_sqs);
-<pp_define>\" new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_dqs);
-
- /*
- * Scan the definition macro arguments
- */
-<pp_macro>\){ws}* yy_pp_state(pp_mbody); return tMACROEND;
-<pp_macro>{ws}+ ;
-<pp_macro>{cident} ppy_lval.cptr = pp_xstrdup(ppy_text); return tIDENT;
-<pp_macro>, return ',';
-<pp_macro>"..." return tELIPSIS;
-<pp_macro>(\\\r?)|(\n)|(.)|(\.\.?) ppy_error("Argument identifier expected");
-<pp_macro>\\\r?\n newline(0);
-
- /*
- * Scan the substitution of a macro
- */
-<pp_mbody>[^a-zA-Z0-9'"#/\\\n]+ ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
-<pp_mbody>{cident} ppy_lval.cptr = pp_xstrdup(ppy_text); return tIDENT;
-<pp_mbody>\#\# return tCONCAT;
-<pp_mbody>\# return tSTRINGIZE;
-<pp_mbody>[0-9][a-zA-Z0-9]*[^a-zA-Z0-9'"#/\\\n]* ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
-<pp_mbody>(\\\r?)|(\/[^/*'"#\\\n]*) ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
-<pp_mbody>\\\r?\n{ws}+ newline(0); ppy_lval.cptr = pp_xstrdup(" "); return tLITERAL;
-<pp_mbody>\\\r?\n newline(0);
-<pp_mbody>\n newline(1); yy_pop_state(); return tNL;
-<pp_mbody>\' new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_sqs);
-<pp_mbody>\" new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_dqs);
-
- /*
- * Macro expansion text scanning.
- * This state is active just after the identifier is scanned
- * that triggers an expansion. We *must* delete the leading
- * whitespace before we can start scanning for arguments.
- *
- * If we do not see a '(' as next trailing token, then we have
- * a false alarm. We just continue with a nose-bleed...
- */
-<pp_macign>{ws}*/\( yy_pp_state(pp_macscan);
-<pp_macign>{ws}*\n {
- if(yy_top_state() != pp_macscan)
- newline(0);
- }
-<pp_macign>{ws}*\\\r?\n newline(0);
-<pp_macign>{ws}+|{ws}*\\\r?|. {
- macexpstackentry_t *mac = pop_macro();
- yy_pop_state();
- put_buffer(mac->ppp->ident, strlen(mac->ppp->ident));
- put_buffer(ppy_text, ppy_leng);
- free_macro(mac);
- }
-
- /*
- * Macro expansion argument text scanning.
- * This state is active when a macro's arguments are being read for expansion.
- */
-<pp_macscan>\( {
- if(++MACROPARENTHESES() > 1)
- add_text_to_macro(ppy_text, ppy_leng);
- }
-<pp_macscan>\) {
- if(--MACROPARENTHESES() == 0)
- {
- yy_pop_state();
- macro_add_arg(1);
- }
- else
- add_text_to_macro(ppy_text, ppy_leng);
- }
-<pp_macscan>, {
- if(MACROPARENTHESES() > 1)
- add_text_to_macro(ppy_text, ppy_leng);
- else
- macro_add_arg(0);
- }
-<pp_macscan>\" new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_dqs);
-<pp_macscan>\' new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_sqs);
-<pp_macscan>"/*" yy_push_state(pp_comment); add_text_to_macro(" ", 1);
-<pp_macscan>\n pp_status.line_number++; pp_status.char_number = 1; add_text_to_macro(ppy_text, ppy_leng);
-<pp_macscan>([^/(),\\\n"']+)|(\/[^/*(),\\\n'"]*)|(\\\r?)|(.) add_text_to_macro(ppy_text, ppy_leng);
-<pp_macscan>\\\r?\n newline(0);
-
- /*
- * Comment handling (almost all start-conditions)
- */
-<INITIAL,pp_pp,pp_ignore,pp_eol,pp_inc,pp_if,pp_ifd,pp_endif,pp_defined,pp_def,pp_define,pp_macro,pp_mbody,RCINCL>"/*" yy_push_state(pp_comment);
-<pp_comment>[^*\n]*|"*"+[^*/\n]* ;
-<pp_comment>\n newline(0);
-<pp_comment>"*"+"/" yy_pop_state();
-
- /*
- * Remove C++ style comment (almost all start-conditions)
- */
-<INITIAL,pp_pp,pp_ignore,pp_eol,pp_inc,pp_if,pp_ifd,pp_endif,pp_defined,pp_def,pp_define,pp_macro,pp_mbody,pp_macscan,RCINCL>"//"[^\n]* {
- if(ppy_text[ppy_leng-1] == '\\')
- ppy_warning("C++ style comment ends with an escaped newline (escape ignored)");
- }
-
- /*
- * Single, double and <> quoted constants
- */
-<INITIAL,pp_macexp>\" pp_incl_state.seen_junk++; new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_dqs);
-<INITIAL,pp_macexp>\' pp_incl_state.seen_junk++; new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_sqs);
-<pp_dqs>[^"\\\n]+ add_string(ppy_text, ppy_leng);
-<pp_dqs>\" {
- add_string(ppy_text, ppy_leng);
- yy_pop_state();
- switch(yy_current_state())
- {
- case pp_pp:
- case pp_define:
- case pp_mbody:
- case pp_inc:
- case RCINCL:
- if (yy_current_state()==RCINCL) yy_pop_state();
- ppy_lval.cptr = get_string();
- return tDQSTRING;
- case pp_line:
- ppy_lval.cptr = get_string();
- return tDQSTRING;
- default:
- put_string();
- }
- }
-<pp_sqs>[^'\\\n]+ add_string(ppy_text, ppy_leng);
-<pp_sqs>\' {
- add_string(ppy_text, ppy_leng);
- yy_pop_state();
- switch(yy_current_state())
- {
- case pp_if:
- case pp_define:
- case pp_mbody:
- ppy_lval.cptr = get_string();
- return tSQSTRING;
- default:
- put_string();
- }
- }
-<pp_iqs>[^\>\\\n]+ add_string(ppy_text, ppy_leng);
-<pp_iqs>\> {
- add_string(ppy_text, ppy_leng);
- yy_pop_state();
- ppy_lval.cptr = get_string();
- return tIQSTRING;
- }
-<pp_dqs>\\\r?\n {
- /*
- * This is tricky; we need to remove the line-continuation
- * from preprocessor strings, but OTOH retain them in all
- * other strings. This is because the resource grammar is
- * even more braindead than initially analysed and line-
- * continuations in strings introduce, sigh, newlines in
- * the output. There goes the concept of non-breaking, non-
- * spacing whitespace.
- */
- switch(yy_top_state())
- {
- case pp_pp:
- case pp_define:
- case pp_mbody:
- case pp_inc:
- case pp_line:
- newline(0);
- break;
- default:
- add_string(ppy_text, ppy_leng);
- newline(-1);
- }
- }
-<pp_iqs,pp_dqs,pp_sqs>\\. add_string(ppy_text, ppy_leng);
-<pp_iqs,pp_dqs,pp_sqs>\n {
- newline(1);
- add_string(ppy_text, ppy_leng);
- ppy_warning("Newline in string constant encountered (started line %d)", string_start());
- }
-
- /*
- * Identifier scanning
- */
-<INITIAL,pp_if,pp_inc,pp_macexp>{cident} {
- pp_entry_t *ppp;
- pp_incl_state.seen_junk++;
- if(!(ppp = pplookup(ppy_text)))
- {
- if(yy_current_state() == pp_inc)
- ppy_error("Expected include filename");
-
- else if(yy_current_state() == pp_if)
- {
- ppy_lval.cptr = pp_xstrdup(ppy_text);
- return tIDENT;
- }
- else {
- if((yy_current_state()==INITIAL) && (strcasecmp(ppy_text,"RCINCLUDE")==0)){
- yy_push_state(RCINCL);
- return tRCINCLUDE;
- }
- else put_buffer(ppy_text, ppy_leng);
- }
- }
- else if(!ppp->expanding)
- {
- switch(ppp->type)
- {
- case def_special:
- expand_special(ppp);
- break;
- case def_define:
- expand_define(ppp);
- break;
- case def_macro:
- yy_push_state(pp_macign);
- push_macro(ppp);
- break;
- default:
- pp_internal_error(__FILE__, __LINE__, "Invalid define type %d\n", ppp->type);
- }
- }
- else put_buffer(ppy_text, ppy_leng);
- }
-
- /*
- * Everything else that needs to be passed and
- * newline and continuation handling
- */
-<INITIAL,pp_macexp>[^a-zA-Z_#'"/\\\n \r\t\f\v]+|(\/|\\)[^a-zA-Z_/*'"\\\n \r\t\v\f]* pp_incl_state.seen_junk++; put_buffer(ppy_text, ppy_leng);
-<INITIAL,pp_macexp>{ws}+ put_buffer(ppy_text, ppy_leng);
-<INITIAL>\n newline(1);
-<INITIAL>\\\r?\n newline(0);
-<INITIAL>\\\r? pp_incl_state.seen_junk++; put_buffer(ppy_text, ppy_leng);
-
- /*
- * Special catcher for macro argmument expansion to prevent
- * newlines to propagate to the output or admin.
- */
-<pp_macexp>(\n)|(.)|(\\\r?(\n|.)) put_buffer(ppy_text, ppy_leng);
-
-<RCINCL>[A-Za-z0-9_\.\\/]+ {
- ppy_lval.cptr=pp_xstrdup(ppy_text);
- yy_pop_state();
- return tRCINCLUDEPATH;
- }
-
-<RCINCL>{ws}+ ;
-
-<RCINCL>\" {
- new_string(); add_string(ppy_text,ppy_leng);yy_push_state(pp_dqs);
- }
-
- /*
- * This is a 'catch-all' rule to discover errors in the scanner
- * in an orderly manner.
- */
-<*>. pp_incl_state.seen_junk++; ppy_warning("Unmatched text '%c' (0x%02x); please report\n", isprint(*ppy_text & 0xff) ? *ppy_text : ' ', *ppy_text);
-
-<<EOF>> {
- YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
- bufferstackentry_t *bep = pop_buffer();
-
- if((!bep && pp_get_if_depth()) || (bep && pp_get_if_depth() != bep->if_depth))
- ppy_warning("Unmatched #if/#endif at end of file");
-
- if(!bep)
- {
- if(YY_START != INITIAL)
- {
- ppy_error("Unexpected end of file during preprocessing");
- BEGIN(INITIAL);
- }
- yyterminate();
- }
- else if(bep->should_pop == 2)
- {
- macexpstackentry_t *mac;
- mac = pop_macro();
- expand_macro(mac);
- }
- ppy__delete_buffer(b);
- }
-
-%%
-/*
- **************************************************************************
- * Support functions
- **************************************************************************
- */
-
-#ifndef ppy_wrap
-int ppy_wrap(void)
-{
- return 1;
-}
-#endif
-
-
-/*
- *-------------------------------------------------------------------------
- * Output newlines or set them as continuations
- *
- * Input: -1 - Don't count this one, but update local position (see pp_dqs)
- * 0 - Line-continuation seen and cache output
- * 1 - Newline seen and flush output
- *-------------------------------------------------------------------------
- */
-static void newline(int dowrite)
-{
- pp_status.line_number++;
- pp_status.char_number = 1;
-
- if(dowrite == -1)
- return;
-
- ncontinuations++;
- if(dowrite)
- {
- for(;ncontinuations; ncontinuations--)
- put_buffer("\n", 1);
- }
-}
-
-
-/*
- *-------------------------------------------------------------------------
- * Make a number out of an any-base and suffixed string
- *
- * Possible number extensions:
- * - "" int
- * - "L" long int
- * - "LL" long long int
- * - "U" unsigned int
- * - "UL" unsigned long int
- * - "ULL" unsigned long long int
- * - "LU" unsigned long int
- * - "LLU" unsigned long long int
- * - "LUL" invalid
- *
- * FIXME:
- * The sizes of resulting 'int' and 'long' are compiler specific.
- * I depend on sizeof(int) > 2 here (although a relatively safe
- * assumption).
- * Long longs are not yet implemented because this is very compiler
- * specific and I don't want to think too much about the problems.
- *
- *-------------------------------------------------------------------------
- */
-static int make_number(int radix, PPY_STYPE *val, const char *str, int len)
-{
- int is_l = 0;
- int is_ll = 0;
- int is_u = 0;
- char ext[4];
- long l;
-
- ext[3] = '\0';
- ext[2] = toupper(str[len-1]);
- ext[1] = len > 1 ? toupper(str[len-2]) : ' ';
- ext[0] = len > 2 ? toupper(str[len-3]) : ' ';
-
- if(!strcmp(ext, "LUL"))
- {
- ppy_error("Invalid constant suffix");
- return 0;
- }
- else if(!strcmp(ext, "LLU") || !strcmp(ext, "ULL"))
- {
- is_ll++;
- is_u++;
- }
- else if(!strcmp(ext+1, "LU") || !strcmp(ext+1, "UL"))
- {
- is_l++;
- is_u++;
- }
- else if(!strcmp(ext+1, "LL"))
- {
- is_ll++;
- }
- else if(!strcmp(ext+2, "L"))
- {
- is_l++;
- }
- else if(!strcmp(ext+2, "U"))
- {
- is_u++;
- }
-
- if(is_u && is_ll)
- {
- errno = 0;
- val->ull = strtoull(str, NULL, radix);
- if (val->ull == ULLONG_MAX && errno == ERANGE)
- ppy_error("integer constant %s is too large\n", str);
- return tULONGLONG;
- }
- else if(!is_u && is_ll)
- {
- errno = 0;
- val->sll = strtoll(str, NULL, radix);
- if ((val->sll == LLONG_MIN || val->sll == LLONG_MAX) && errno == ERANGE)
- ppy_error("integer constant %s is too large\n", str);
- return tSLONGLONG;
- }
- else if(is_u && is_l)
- {
- errno = 0;
- val->ulong = strtoul(str, NULL, radix);
- if (val->ulong == ULONG_MAX && errno == ERANGE)
- ppy_error("integer constant %s is too large\n", str);
- return tULONG;
- }
- else if(!is_u && is_l)
- {
- errno = 0;
- val->slong = strtol(str, NULL, radix);
- if ((val->slong == LONG_MIN || val->slong == LONG_MAX) && errno == ERANGE)
- ppy_error("integer constant %s is too large\n", str);
- return tSLONG;
- }
- else if(is_u && !is_l)
- {
- unsigned long ul;
- errno = 0;
- ul = strtoul(str, NULL, radix);
- if ((ul == ULONG_MAX && errno == ERANGE) || (ul > UINT_MAX))
- ppy_error("integer constant %s is too large\n", str);
- val->uint = (unsigned int)ul;
- return tUINT;
- }
-
- /* Else it must be an int... */
- errno = 0;
- l = strtol(str, NULL, radix);
- if (((l == LONG_MIN || l == LONG_MAX) && errno == ERANGE) ||
- (l > INT_MAX) || (l < INT_MIN))
- ppy_error("integer constant %s is too large\n", str);
- val->sint = (int)l;
- return tSINT;
-}
-
-
-/*
- *-------------------------------------------------------------------------
- * Macro and define expansion support
- *
- * FIXME: Variable macro arguments.
- *-------------------------------------------------------------------------
- */
-static void expand_special(pp_entry_t *ppp)
-{
- static char *buf = NULL;
- char *new_buf;
-
- assert(ppp->type == def_special);
-
- if(!strcmp(ppp->ident, "__LINE__"))
- {
- new_buf = pp_xrealloc(buf, 32);
- if(!new_buf)
- return;
- buf = new_buf;
- sprintf(buf, "%d", pp_status.line_number);
- }
- else if(!strcmp(ppp->ident, "__FILE__"))
- {
- new_buf = pp_xrealloc(buf, strlen(pp_status.input) + 3);
- if(!new_buf)
- return;
- buf = new_buf;
- sprintf(buf, "\"%s\"", pp_status.input);
- }
- else
- pp_internal_error(__FILE__, __LINE__, "Special macro '%s' not found...\n", ppp->ident);
-
- if(buf && buf[0])
- {
- push_buffer(ppp, NULL, NULL, 0);
- yy_scan_string(buf);
- }
-}
-
-static void expand_define(pp_entry_t *ppp)
-{
- assert(ppp->type == def_define);
-
- if(ppp->subst.text && ppp->subst.text[0])
- {
- push_buffer(ppp, NULL, NULL, 0);
- yy_scan_string(ppp->subst.text);
- }
-}
-
-static int curdef_idx = 0;
-static int curdef_alloc = 0;
-static char *curdef_text = NULL;
-
-static void add_text(const char *str, int len)
-{
- int new_alloc;
- char *new_text;
-
- if(len == 0)
- return;
- if(curdef_idx >= curdef_alloc || curdef_alloc - curdef_idx < len)
- {
- new_alloc = curdef_alloc + ((len + ALLOCBLOCKSIZE-1) & ~(ALLOCBLOCKSIZE-1));
- new_text = pp_xrealloc(curdef_text, new_alloc * sizeof(curdef_text[0]));
- if(!new_text)
- return;
- curdef_text = new_text;
- curdef_alloc = new_alloc;
- if(curdef_alloc > 65536)
- ppy_warning("Reallocating macro-expansion buffer larger than 64kB");
- }
- memcpy(&curdef_text[curdef_idx], str, len);
- curdef_idx += len;
-}
-
-static mtext_t *add_expand_text(mtext_t *mtp, macexpstackentry_t *mep, int *nnl)
-{
- char *cptr;
- char *exp;
- int tag;
- int n;
-
- if(mtp == NULL)
- return NULL;
-
- switch(mtp->type)
- {
- case exp_text:
- add_text(mtp->subst.text, strlen(mtp->subst.text));
- break;
-
- case exp_stringize:
- cptr = mep->args[mtp->subst.argidx];
- add_text("\"", 1);
- while(*cptr)
- {
- if(*cptr == '"' || *cptr == '\\')
- add_text("\\", 1);
- add_text(cptr, 1);
- cptr++;
- }
- add_text("\"", 1);
- break;
-
- case exp_concat:
- /* Remove trailing whitespace from current expansion text */
- while(curdef_idx)
- {
- if(isspace(curdef_text[curdef_idx-1] & 0xff))
- curdef_idx--;
- else
- break;
- }
- /* tag current position and recursively expand the next part */
- tag = curdef_idx;
- mtp = add_expand_text(mtp->next, mep, nnl);
-
- /* Now get rid of the leading space of the expansion */
- cptr = &curdef_text[tag];
- n = curdef_idx - tag;
- while(n)
- {
- if(isspace(*cptr & 0xff))
- {
- cptr++;
- n--;
- }
- else
- break;
- }
- if(cptr != &curdef_text[tag])
- {
- memmove(&curdef_text[tag], cptr, n);
- curdef_idx -= (curdef_idx - tag) - n;
- }
- break;
-
- case exp_subst:
- if((mtp->next && mtp->next->type == exp_concat) || (mtp->prev && mtp->prev->type == exp_concat))
- exp = mep->args[mtp->subst.argidx];
- else
- exp = mep->ppargs[mtp->subst.argidx];
- if(exp)
- {
- add_text(exp, strlen(exp));
- *nnl -= mep->nnls[mtp->subst.argidx];
- cptr = strchr(exp, '\n');
- while(cptr)
- {
- *cptr = ' ';
- cptr = strchr(cptr+1, '\n');
- }
- mep->nnls[mtp->subst.argidx] = 0;
- }
- break;
-
- default:
- pp_internal_error(__FILE__, __LINE__, "Invalid expansion type (%d) in macro expansion\n", mtp->type);
- }
- return mtp;
-}
-
-static void expand_macro(macexpstackentry_t *mep)
-{
- mtext_t *mtp;
- int n, k;
- char *cptr;
- int nnl = 0;
- pp_entry_t *ppp = mep->ppp;
- int nargs = mep->nargs;
-
- assert(ppp->type == def_macro);
- assert(ppp->expanding == 0);
-
- if((ppp->nargs >= 0 && nargs != ppp->nargs) || (ppp->nargs < 0 && nargs < -ppp->nargs))
- {
- ppy_error("Too %s macro arguments (%d)", nargs < abs(ppp->nargs) ? "few" : "many", nargs);
- return;
- }
-
- for(n = 0; n < nargs; n++)
- nnl += mep->nnls[n];
-
- curdef_idx = 0;
-
- for(mtp = ppp->subst.mtext; mtp; mtp = mtp->next)
- {
- if(!(mtp = add_expand_text(mtp, mep, &nnl)))
- break;
- }
-
- for(n = 0; n < nnl; n++)
- add_text("\n", 1);
-
- /* To make sure there is room and termination (see below) */
- add_text(" \0", 2);
-
- /* Strip trailing whitespace from expansion */
- for(k = curdef_idx, cptr = &curdef_text[curdef_idx-1]; k > 0; k--, cptr--)
- {
- if(!isspace(*cptr & 0xff))
- break;
- }
-
- /*
- * We must add *one* whitespace to make sure that there
- * is a token-separation after the expansion.
- */
- *(++cptr) = ' ';
- *(++cptr) = '\0';
- k++;
-
- /* Strip leading whitespace from expansion */
- for(n = 0, cptr = curdef_text; n < k; n++, cptr++)
- {
- if(!isspace(*cptr & 0xff))
- break;
- }
-
- if(k - n > 0)
- {
- push_buffer(ppp, NULL, NULL, 0);
- /*yy_scan_bytes(curdef_text + n, k - n);*/
- yy_scan_string(curdef_text + n);
- }
-}
-
-/*
- *-------------------------------------------------------------------------
- * String collection routines
- *-------------------------------------------------------------------------
- */
-static void new_string(void)
-{
-#ifdef DEBUG
- if(strbuf_idx)
- ppy_warning("new_string: strbuf_idx != 0");
-#endif
- strbuf_idx = 0;
- str_startline = pp_status.line_number;
-}
-
-static void add_string(const char *str, int len)
-{
- int new_alloc;
- char *new_buffer;
-
- if(len == 0)
- return;
- if(strbuf_idx >= strbuf_alloc || strbuf_alloc - strbuf_idx < len)
- {
- new_alloc = strbuf_alloc + ((len + ALLOCBLOCKSIZE-1) & ~(ALLOCBLOCKSIZE-1));
- new_buffer = pp_xrealloc(strbuffer, new_alloc * sizeof(strbuffer[0]));
- if(!new_buffer)
- return;
- strbuffer = new_buffer;
- strbuf_alloc = new_alloc;
- if(strbuf_alloc > 65536)
- ppy_warning("Reallocating string buffer larger than 64kB");
- }
- memcpy(&strbuffer[strbuf_idx], str, len);
- strbuf_idx += len;
-}
-
-static char *get_string(void)
-{
- char *str = pp_xmalloc(strbuf_idx + 1);
- if(!str)
- return NULL;
- memcpy(str, strbuffer, strbuf_idx);
- str[strbuf_idx] = '\0';
-#ifdef DEBUG
- strbuf_idx = 0;
-#endif
- return str;
-}
-
-static void put_string(void)
-{
- put_buffer(strbuffer, strbuf_idx);
-#ifdef DEBUG
- strbuf_idx = 0;
-#endif
-}
-
-static int string_start(void)
-{
- return str_startline;
-}
-
-
-/*
- *-------------------------------------------------------------------------
- * Buffer management
- *-------------------------------------------------------------------------
- */
-static void push_buffer(pp_entry_t *ppp, char *filename, char *incname, int pop)
-{
- if(bufferstackidx >= MAXBUFFERSTACK)
- pp_internal_error(__FILE__, __LINE__, "Buffer stack overflow");
-
- memset(&bufferstack[bufferstackidx], 0, sizeof(bufferstack[0]));
- bufferstack[bufferstackidx].bufferstate = YY_CURRENT_BUFFER;
- bufferstack[bufferstackidx].filehandle = pp_status.file;
- bufferstack[bufferstackidx].define = ppp;
- bufferstack[bufferstackidx].line_number = pp_status.line_number;
- bufferstack[bufferstackidx].char_number = pp_status.char_number;
- bufferstack[bufferstackidx].if_depth = pp_get_if_depth();
- bufferstack[bufferstackidx].should_pop = pop;
- bufferstack[bufferstackidx].filename = pp_status.input;
- bufferstack[bufferstackidx].ncontinuations = ncontinuations;
- bufferstack[bufferstackidx].incl = pp_incl_state;
- bufferstack[bufferstackidx].include_filename = incname;
-
- if(ppp)
- ppp->expanding = 1;
- else if(filename)
- {
- /* These will track the ppy_error to the correct file and line */
- pp_status.line_number = 1;
- pp_status.char_number = 1;
- pp_status.input = filename;
- ncontinuations = 0;
- }
- else if(!pop)
- pp_internal_error(__FILE__, __LINE__, "Pushing buffer without knowing where to go to");
- bufferstackidx++;
-}
-
-static bufferstackentry_t *pop_buffer(void)
-{
- if(bufferstackidx < 0)
- pp_internal_error(__FILE__, __LINE__, "Bufferstack underflow?");
-
- if(bufferstackidx == 0)
- return NULL;
-
- bufferstackidx--;
-
- if(bufferstack[bufferstackidx].define)
- bufferstack[bufferstackidx].define->expanding = 0;
- else
- {
- includelogicentry_t *iep = NULL;
-
- if(!bufferstack[bufferstackidx].should_pop)
- {
- wpp_close(pp_status.file);
- pp_writestring("# %d \"%s\" 2\n", bufferstack[bufferstackidx].line_number, bufferstack[bufferstackidx].filename);
-
- /* We have EOF, check the include logic */
- if(pp_incl_state.state == 2 && !pp_incl_state.seen_junk && pp_incl_state.ppp)
- {
- pp_entry_t *ppp = pplookup(pp_incl_state.ppp);
- if(ppp)
- {
- iep = pp_xmalloc(sizeof(includelogicentry_t));
- if (iep)
- {
- iep->ppp = ppp;
- ppp->iep = iep;
- iep->filename = bufferstack[bufferstackidx].include_filename;
- iep->prev = NULL;
- iep->next = pp_includelogiclist;
- if(iep->next)
- iep->next->prev = iep;
- pp_includelogiclist = iep;
- }
- }
- }
- free(pp_incl_state.ppp);
- pp_incl_state = bufferstack[bufferstackidx].incl;
-
- }
- if (bufferstack[bufferstackidx].include_filename)
- {
- free(pp_status.input);
- pp_status.input = bufferstack[bufferstackidx].filename;
- }
- pp_status.line_number = bufferstack[bufferstackidx].line_number;
- pp_status.char_number = bufferstack[bufferstackidx].char_number;
- ncontinuations = bufferstack[bufferstackidx].ncontinuations;
- if (!iep)
- free(bufferstack[bufferstackidx].include_filename);
- }
-
- pp_status.file = bufferstack[bufferstackidx].filehandle;
- ppy__switch_to_buffer(bufferstack[bufferstackidx].bufferstate);
-
- if(bufferstack[bufferstackidx].should_pop)
- {
- if(yy_current_state() == pp_macexp)
- macro_add_expansion();
- else
- pp_internal_error(__FILE__, __LINE__, "Pop buffer and state without macro expansion state");
- yy_pop_state();
- }
-
- return &bufferstack[bufferstackidx];
-}
-
-
-/*
- *-------------------------------------------------------------------------
- * Macro nestng support
- *-------------------------------------------------------------------------
- */
-static void push_macro(pp_entry_t *ppp)
-{
- if(macexpstackidx >= MAXMACEXPSTACK)
- {
- ppy_error("Too many nested macros");
- return;
- }
-
- macexpstack[macexpstackidx] = pp_xmalloc(sizeof(macexpstack[0][0]));
- if(!macexpstack[macexpstackidx])
- return;
- memset( macexpstack[macexpstackidx], 0, sizeof(macexpstack[0][0]));
- macexpstack[macexpstackidx]->ppp = ppp;
- macexpstackidx++;
-}
-
-static macexpstackentry_t *top_macro(void)
-{
- return macexpstackidx > 0 ? macexpstack[macexpstackidx-1] : NULL;
-}
-
-static macexpstackentry_t *pop_macro(void)
-{
- if(macexpstackidx <= 0)
- pp_internal_error(__FILE__, __LINE__, "Macro expansion stack underflow\n");
- return macexpstack[--macexpstackidx];
-}
-
-static void free_macro(macexpstackentry_t *mep)
-{
- int i;
-
- for(i = 0; i < mep->nargs; i++)
- free(mep->args[i]);
- free(mep->args);
- free(mep->nnls);
- free(mep->curarg);
- free(mep);
-}
-
-static void add_text_to_macro(const char *text, int len)
-{
- macexpstackentry_t *mep = top_macro();
-
- assert(mep->ppp->expanding == 0);
-
- if(mep->curargalloc - mep->curargsize <= len+1) /* +1 for '\0' */
- {
- char *new_curarg;
- int new_alloc = mep->curargalloc + ((ALLOCBLOCKSIZE > len+1) ? ALLOCBLOCKSIZE : len+1);
- new_curarg = pp_xrealloc(mep->curarg, new_alloc * sizeof(mep->curarg[0]));
- if(!new_curarg)
- return;
- mep->curarg = new_curarg;
- mep->curargalloc = new_alloc;
- }
- memcpy(mep->curarg + mep->curargsize, text, len);
- mep->curargsize += len;
- mep->curarg[mep->curargsize] = '\0';
-}
-
-static void macro_add_arg(int last)
-{
- int nnl = 0;
- char *cptr;
- char **new_args, **new_ppargs;
- int *new_nnls;
- macexpstackentry_t *mep = top_macro();
-
- assert(mep->ppp->expanding == 0);
-
- new_args = pp_xrealloc(mep->args, (mep->nargs+1) * sizeof(mep->args[0]));
- if(!new_args)
- return;
- mep->args = new_args;
-
- new_ppargs = pp_xrealloc(mep->ppargs, (mep->nargs+1) * sizeof(mep->ppargs[0]));
- if(!new_ppargs)
- return;
- mep->ppargs = new_ppargs;
-
- new_nnls = pp_xrealloc(mep->nnls, (mep->nargs+1) * sizeof(mep->nnls[0]));
- if(!new_nnls)
- return;
- mep->nnls = new_nnls;
-
- mep->args[mep->nargs] = pp_xstrdup(mep->curarg ? mep->curarg : "");
- if(!mep->args[mep->nargs])
- return;
- cptr = mep->args[mep->nargs]-1;
- while((cptr = strchr(cptr+1, '\n')))
- {
- nnl++;
- }
- mep->nnls[mep->nargs] = nnl;
- mep->nargs++;
- free(mep->curarg);
- mep->curargalloc = mep->curargsize = 0;
- mep->curarg = NULL;
-
- /* Each macro argument must be expanded to cope with stingize */
- if(last || mep->args[mep->nargs-1][0])
- {
- yy_push_state(pp_macexp);
- push_buffer(NULL, NULL, NULL, last ? 2 : 1);
- yy_scan_string(mep->args[mep->nargs-1]);
- /*mep->bufferstackidx = bufferstackidx; But not nested! */
- }
-}
-
-static void macro_add_expansion(void)
-{
- macexpstackentry_t *mep = top_macro();
-
- assert(mep->ppp->expanding == 0);
-
- mep->ppargs[mep->nargs-1] = pp_xstrdup(mep->curarg ? mep->curarg : "");
- free(mep->curarg);
- mep->curargalloc = mep->curargsize = 0;
- mep->curarg = NULL;
-}
-
-
-/*
- *-------------------------------------------------------------------------
- * Output management
- *-------------------------------------------------------------------------
- */
-static void put_buffer(const char *s, int len)
-{
- if(top_macro())
- add_text_to_macro(s, len);
- else
- wpp_write(s, len);
-}
-
-
-/*
- *-------------------------------------------------------------------------
- * Include management
- *-------------------------------------------------------------------------
- */
-void pp_do_include(char *fname, int type)
-{
- char *newpath;
- int n;
- includelogicentry_t *iep;
- void *fp;
-
- if(!fname)
- return;
-
- for(iep = pp_includelogiclist; iep; iep = iep->next)
- {
- if(!strcmp(iep->filename, fname))
- {
- /*
- * We are done. The file was included before.
- * If the define was deleted, then this entry would have
- * been deleted too.
- */
- free(fname);
- return;
- }
- }
-
- n = strlen(fname);
-
- if(n <= 2)
- {
- ppy_error("Empty include filename");
- free(fname);
- return;
- }
-
- /* Undo the effect of the quotation */
- fname[n-1] = '\0';
-
- if((fp = pp_open_include(fname+1, type, pp_status.input, &newpath)) == NULL)
- {
- ppy_error("Unable to open include file %s", fname+1);
- free(fname);
- return;
- }
-
- fname[n-1] = *fname; /* Redo the quotes */
- push_buffer(NULL, newpath, fname, 0);
- pp_incl_state.seen_junk = 0;
- pp_incl_state.state = 0;
- pp_incl_state.ppp = NULL;
-
- pp_status.file = fp;
- ppy__switch_to_buffer(ppy__create_buffer(NULL, YY_BUF_SIZE));
-
- pp_writestring("# 1 \"%s\" 1%s\n", newpath, type ? "" : " 3");
-}
-
-/*
- *-------------------------------------------------------------------------
- * Push/pop preprocessor ignore state when processing conditionals
- * which are false.
- *-------------------------------------------------------------------------
- */
-void pp_push_ignore_state(void)
-{
- yy_push_state(pp_ignore);
-}
-
-void pp_pop_ignore_state(void)
-{
- yy_pop_state();
-}
diff --git a/dlls/d3dcompiler_43/ppy.y b/dlls/d3dcompiler_43/ppy.y
deleted file mode 100644
index 77c8dfd6190..00000000000
--- a/dlls/d3dcompiler_43/ppy.y
+++ /dev/null
@@ -1,689 +0,0 @@
-/*
- * Wrc preprocessor syntax analysis
- *
- * Copyright 1999-2000 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-%{
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <assert.h>
-#include <ctype.h>
-#include <string.h>
-#include "wpp_private.h"
-
-
-#define UNARY_OP(r, v, OP) \
- switch(v.type) \
- { \
- case cv_sint: r.val.si = OP v.val.si; break; \
- case cv_uint: r.val.ui = OP v.val.ui; break; \
- case cv_slong: r.val.sl = OP v.val.sl; break; \
- case cv_ulong: r.val.ul = OP v.val.ul; break; \
- case cv_sll: r.val.sll = OP v.val.sll; break; \
- case cv_ull: r.val.ull = OP v.val.ull; break; \
- }
-
-#define cv_signed(v) ((v.type & FLAG_SIGNED) != 0)
-
-#define BIN_OP_INT(r, v1, v2, OP) \
- r.type = v1.type; \
- if(cv_signed(v1) && cv_signed(v2)) \
- r.val.si = v1.val.si OP v2.val.si; \
- else if(cv_signed(v1) && !cv_signed(v2)) \
- r.val.si = v1.val.si OP (signed) v2.val.ui; \
- else if(!cv_signed(v1) && cv_signed(v2)) \
- r.val.si = (signed) v1.val.ui OP v2.val.si; \
- else \
- r.val.ui = v1.val.ui OP v2.val.ui;
-
-#define BIN_OP_LONG(r, v1, v2, OP) \
- r.type = v1.type; \
- if(cv_signed(v1) && cv_signed(v2)) \
- r.val.sl = v1.val.sl OP v2.val.sl; \
- else if(cv_signed(v1) && !cv_signed(v2)) \
- r.val.sl = v1.val.sl OP (signed long) v2.val.ul; \
- else if(!cv_signed(v1) && cv_signed(v2)) \
- r.val.sl = (signed long) v1.val.ul OP v2.val.sl; \
- else \
- r.val.ul = v1.val.ul OP v2.val.ul;
-
-#define BIN_OP_LONGLONG(r, v1, v2, OP) \
- r.type = v1.type; \
- if(cv_signed(v1) && cv_signed(v2)) \
- r.val.sll = v1.val.sll OP v2.val.sll; \
- else if(cv_signed(v1) && !cv_signed(v2)) \
- r.val.sll = v1.val.sll OP (__int64) v2.val.ull; \
- else if(!cv_signed(v1) && cv_signed(v2)) \
- r.val.sll = (__int64) v1.val.ull OP v2.val.sll; \
- else \
- r.val.ull = v1.val.ull OP v2.val.ull;
-
-#define BIN_OP(r, v1, v2, OP) \
- switch(v1.type & SIZE_MASK) \
- { \
- case SIZE_INT: BIN_OP_INT(r, v1, v2, OP); break; \
- case SIZE_LONG: BIN_OP_LONG(r, v1, v2, OP); break; \
- case SIZE_LONGLONG: BIN_OP_LONGLONG(r, v1, v2, OP); break; \
- default: pp_internal_error(__FILE__, __LINE__, "Invalid type indicator (0x%04x)", v1.type); \
- }
-
-
-/*
- * Prototypes
- */
-static int boolean(cval_t *v);
-static void promote_equal_size(cval_t *v1, cval_t *v2);
-static void cast_to_sint(cval_t *v);
-static void cast_to_uint(cval_t *v);
-static void cast_to_slong(cval_t *v);
-static void cast_to_ulong(cval_t *v);
-static void cast_to_sll(cval_t *v);
-static void cast_to_ull(cval_t *v);
-static marg_t *new_marg(char *str, def_arg_t type);
-static marg_t *add_new_marg(char *str, def_arg_t type);
-static int marg_index(char *id);
-static mtext_t *new_mtext(char *str, int idx, def_exp_t type);
-static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp);
-static char *merge_text(char *s1, char *s2);
-
-/*
- * Local variables
- */
-static marg_t **macro_args; /* Macro parameters array while parsing */
-static int nmacro_args;
-
-%}
-
-%define api.prefix {ppy_}
-
-%union{
- int sint;
- unsigned int uint;
- long slong;
- unsigned long ulong;
- __int64 sll;
- unsigned __int64 ull;
- int *iptr;
- char *cptr;
- cval_t cval;
- marg_t *marg;
- mtext_t *mtext;
-}
-
-%token tRCINCLUDE
-%token tIF tIFDEF tIFNDEF tELSE tELIF tENDIF tDEFINED tNL
-%token tINCLUDE tLINE tGCCLINE tERROR tWARNING tPRAGMA tPPIDENT
-%token tUNDEF tMACROEND tCONCAT tELIPSIS tSTRINGIZE
-%token <cptr> tIDENT tLITERAL tMACRO tDEFINE
-%token <cptr> tDQSTRING tSQSTRING tIQSTRING
-%token <uint> tUINT
-%token <sint> tSINT
-%token <ulong> tULONG
-%token <slong> tSLONG
-%token <ull> tULONGLONG
-%token <sll> tSLONGLONG
-%token <cptr> tRCINCLUDEPATH
-
-%right '?' ':'
-%left tLOGOR
-%left tLOGAND
-%left '|'
-%left '^'
-%left '&'
-%left tEQ tNE
-%left '<' tLTE '>' tGTE
-%left tLSHIFT tRSHIFT
-%left '+' '-'
-%left '*' '/'
-%right '~' '!'
-
-%type <cval> pp_expr
-%type <marg> emargs margs
-%type <mtext> opt_mtexts mtexts mtext
-%type <sint> allmargs
-%type <cptr> opt_text text
-
-/*
- **************************************************************************
- * The parser starts here
- **************************************************************************
- */
-
-%%
-
-pp_file : /* Empty */
- | pp_file preprocessor
- ;
-
-preprocessor
- : tINCLUDE tDQSTRING tNL { pp_do_include($2, 1); }
- | tINCLUDE tIQSTRING tNL { pp_do_include($2, 0); }
- | tIF pp_expr tNL { pp_next_if_state(boolean(&$2)); }
- | tIFDEF tIDENT tNL { pp_next_if_state(pplookup($2) != NULL); free($2); }
- | tIFNDEF tIDENT tNL {
- int t = pplookup($2) == NULL;
- if(pp_incl_state.state == 0 && t && !pp_incl_state.seen_junk)
- {
- pp_incl_state.state = 1;
- pp_incl_state.ppp = $2;
- pp_incl_state.ifdepth = pp_get_if_depth();
- }
- else if(pp_incl_state.state != 1)
- {
- pp_incl_state.state = -1;
- free($2);
- }
- else
- free($2);
- pp_next_if_state(t);
- }
- | tELIF pp_expr tNL {
- pp_if_state_t s = pp_pop_if();
- switch(s)
- {
- case if_true:
- case if_elif:
- pp_push_if(if_elif);
- break;
- case if_false:
- pp_push_if(boolean(&$2) ? if_true : if_false);
- break;
- case if_ignore:
- pp_push_if(if_ignore);
- break;
- case if_elsetrue:
- case if_elsefalse:
- ppy_error("#elif cannot follow #else");
- break;
- case if_error:
- break;
- default:
- pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #elif directive", s);
- }
- }
- | tELSE tNL {
- pp_if_state_t s = pp_pop_if();
- switch(s)
- {
- case if_true:
- pp_push_if(if_elsefalse);
- break;
- case if_elif:
- pp_push_if(if_elif);
- break;
- case if_false:
- pp_push_if(if_elsetrue);
- break;
- case if_ignore:
- pp_push_if(if_ignore);
- break;
- case if_elsetrue:
- case if_elsefalse:
- ppy_error("#else clause already defined");
- break;
- case if_error:
- break;
- default:
- pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #else directive", s);
- }
- }
- | tENDIF tNL {
- if(pp_pop_if() != if_error)
- {
- if(pp_incl_state.ifdepth == pp_get_if_depth() && pp_incl_state.state == 1)
- {
- pp_incl_state.state = 2;
- pp_incl_state.seen_junk = 0;
- }
- else if(pp_incl_state.state != 1)
- {
- pp_incl_state.state = -1;
- }
- }
- }
- | tUNDEF tIDENT tNL { pp_del_define($2); free($2); }
- | tDEFINE opt_text tNL { pp_add_define($1, $2); free($1); free($2); }
- | tMACRO res_arg allmargs tMACROEND opt_mtexts tNL {
- pp_add_macro($1, macro_args, nmacro_args, $5);
- }
- | tLINE tSINT tDQSTRING tNL { if($3) pp_writestring("# %d %s\n", $2 , $3); free($3); }
- | tGCCLINE tSINT tDQSTRING tNL { if($3) pp_writestring("# %d %s\n", $2 , $3); free($3); }
- | tGCCLINE tSINT tDQSTRING tSINT tNL
- { if($3) pp_writestring("# %d %s %d\n", $2, $3, $4); free($3); }
- | tGCCLINE tSINT tDQSTRING tSINT tSINT tNL
- { if($3) pp_writestring("# %d %s %d %d\n", $2 ,$3, $4, $5); free($3); }
- | tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tNL
- { if($3) pp_writestring("# %d %s %d %d %d\n", $2 ,$3 ,$4 ,$5, $6); free($3); }
- | tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tSINT tNL
- { if($3) pp_writestring("# %d %s %d %d %d %d\n", $2 ,$3 ,$4 ,$5, $6, $7); free($3); }
- | tGCCLINE tNL /* The null-token */
- | tERROR opt_text tNL { ppy_error("#error directive: '%s'", $2); free($2); }
- | tWARNING opt_text tNL { ppy_warning("#warning directive: '%s'", $2); free($2); }
- | tPRAGMA opt_text tNL { pp_writestring("#pragma %s\n", $2 ? $2 : ""); free($2); }
- | tPPIDENT opt_text tNL { if(pp_status.pedantic) ppy_warning("#ident ignored (arg: '%s')", $2); free($2); }
- | tRCINCLUDE tRCINCLUDEPATH {
- if($2)
- {
- int nl=strlen($2) +3;
- char *fn=pp_xmalloc(nl);
- if(fn)
- {
- sprintf(fn,"\"%s\"",$2);
- pp_do_include(fn,1);
- }
- free($2);
- }
- }
- | tRCINCLUDE tDQSTRING {
- pp_do_include($2,1);
- }
- /*| tNL*/
- ;
-
-opt_text: /* Empty */ { $$ = NULL; }
- | text { $$ = $1; }
- ;
-
-text : tLITERAL { $$ = $1; }
- | tDQSTRING { $$ = $1; }
- | tSQSTRING { $$ = $1; }
- | text tLITERAL { $$ = merge_text($1, $2); }
- | text tDQSTRING { $$ = merge_text($1, $2); }
- | text tSQSTRING { $$ = merge_text($1, $2); }
- ;
-
-res_arg : /* Empty */ { macro_args = NULL; nmacro_args = 0; }
- ;
-
-allmargs: /* Empty */ { $$ = 0; macro_args = NULL; nmacro_args = 0; }
- | emargs { $$ = nmacro_args; }
- ;
-
-emargs : margs { $$ = $1; }
- | margs ',' tELIPSIS { $$ = add_new_marg(NULL, arg_list); nmacro_args *= -1; }
- ;
-
-margs : margs ',' tIDENT { $$ = add_new_marg($3, arg_single); }
- | tIDENT { $$ = add_new_marg($1, arg_single); }
- ;
-
-opt_mtexts
- : /* Empty */ { $$ = NULL; }
- | mtexts {
- for($$ = $1; $$ && $$->prev; $$ = $$->prev)
- ;
- }
- ;
-
-mtexts : mtext { $$ = $1; }
- | mtexts mtext { $$ = combine_mtext($1, $2); }
- ;
-
-mtext : tLITERAL { $$ = new_mtext($1, 0, exp_text); }
- | tDQSTRING { $$ = new_mtext($1, 0, exp_text); }
- | tSQSTRING { $$ = new_mtext($1, 0, exp_text); }
- | tCONCAT { $$ = new_mtext(NULL, 0, exp_concat); }
- | tSTRINGIZE tIDENT {
- int mat = marg_index($2);
- if(mat < 0)
- ppy_error("Stringification identifier must be an argument parameter");
- else
- $$ = new_mtext(NULL, mat, exp_stringize);
- }
- | tIDENT {
- int mat = marg_index($1);
- if(mat >= 0)
- $$ = new_mtext(NULL, mat, exp_subst);
- else if($1)
- $$ = new_mtext($1, 0, exp_text);
- }
- ;
-
-pp_expr : tSINT { $$.type = cv_sint; $$.val.si = $1; }
- | tUINT { $$.type = cv_uint; $$.val.ui = $1; }
- | tSLONG { $$.type = cv_slong; $$.val.sl = $1; }
- | tULONG { $$.type = cv_ulong; $$.val.ul = $1; }
- | tSLONGLONG { $$.type = cv_sll; $$.val.sll = $1; }
- | tULONGLONG { $$.type = cv_ull; $$.val.ull = $1; }
- | tDEFINED tIDENT { $$.type = cv_sint; $$.val.si = pplookup($2) != NULL; }
- | tDEFINED '(' tIDENT ')' { $$.type = cv_sint; $$.val.si = pplookup($3) != NULL; }
- | tIDENT { $$.type = cv_sint; $$.val.si = 0; }
- | pp_expr tLOGOR pp_expr { $$.type = cv_sint; $$.val.si = boolean(&$1) || boolean(&$3); }
- | pp_expr tLOGAND pp_expr { $$.type = cv_sint; $$.val.si = boolean(&$1) && boolean(&$3); }
- | pp_expr tEQ pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, ==); }
- | pp_expr tNE pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, !=); }
- | pp_expr '<' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, <); }
- | pp_expr '>' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, >); }
- | pp_expr tLTE pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, <=); }
- | pp_expr tGTE pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, >=); }
- | pp_expr '+' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, +); }
- | pp_expr '-' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, -); }
- | pp_expr '^' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, ^); }
- | pp_expr '&' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, &); }
- | pp_expr '|' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, |); }
- | pp_expr '*' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, *); }
- | pp_expr '/' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, /); }
- | pp_expr tLSHIFT pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, <<); }
- | pp_expr tRSHIFT pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, >>); }
- | '+' pp_expr { $$ = $2; }
- | '-' pp_expr { UNARY_OP($$, $2, -); }
- | '~' pp_expr { UNARY_OP($$, $2, ~); }
- | '!' pp_expr { $$.type = cv_sint; $$.val.si = !boolean(&$2); }
- | '(' pp_expr ')' { $$ = $2; }
- | pp_expr '?' pp_expr ':' pp_expr { $$ = boolean(&$1) ? $3 : $5; }
- ;
-
-%%
-
-/*
- **************************************************************************
- * Support functions
- **************************************************************************
- */
-
-static void cast_to_sint(cval_t *v)
-{
- switch(v->type)
- {
- case cv_sint: break;
- case cv_uint: break;
- case cv_slong: v->val.si = v->val.sl; break;
- case cv_ulong: v->val.si = v->val.ul; break;
- case cv_sll: v->val.si = v->val.sll; break;
- case cv_ull: v->val.si = v->val.ull; break;
- }
- v->type = cv_sint;
-}
-
-static void cast_to_uint(cval_t *v)
-{
- switch(v->type)
- {
- case cv_sint: break;
- case cv_uint: break;
- case cv_slong: v->val.ui = v->val.sl; break;
- case cv_ulong: v->val.ui = v->val.ul; break;
- case cv_sll: v->val.ui = v->val.sll; break;
- case cv_ull: v->val.ui = v->val.ull; break;
- }
- v->type = cv_uint;
-}
-
-static void cast_to_slong(cval_t *v)
-{
- switch(v->type)
- {
- case cv_sint: v->val.sl = v->val.si; break;
- case cv_uint: v->val.sl = v->val.ui; break;
- case cv_slong: break;
- case cv_ulong: break;
- case cv_sll: v->val.sl = v->val.sll; break;
- case cv_ull: v->val.sl = v->val.ull; break;
- }
- v->type = cv_slong;
-}
-
-static void cast_to_ulong(cval_t *v)
-{
- switch(v->type)
- {
- case cv_sint: v->val.ul = v->val.si; break;
- case cv_uint: v->val.ul = v->val.ui; break;
- case cv_slong: break;
- case cv_ulong: break;
- case cv_sll: v->val.ul = v->val.sll; break;
- case cv_ull: v->val.ul = v->val.ull; break;
- }
- v->type = cv_ulong;
-}
-
-static void cast_to_sll(cval_t *v)
-{
- switch(v->type)
- {
- case cv_sint: v->val.sll = v->val.si; break;
- case cv_uint: v->val.sll = v->val.ui; break;
- case cv_slong: v->val.sll = v->val.sl; break;
- case cv_ulong: v->val.sll = v->val.ul; break;
- case cv_sll: break;
- case cv_ull: break;
- }
- v->type = cv_sll;
-}
-
-static void cast_to_ull(cval_t *v)
-{
- switch(v->type)
- {
- case cv_sint: v->val.ull = v->val.si; break;
- case cv_uint: v->val.ull = v->val.ui; break;
- case cv_slong: v->val.ull = v->val.sl; break;
- case cv_ulong: v->val.ull = v->val.ul; break;
- case cv_sll: break;
- case cv_ull: break;
- }
- v->type = cv_ull;
-}
-
-
-static void promote_equal_size(cval_t *v1, cval_t *v2)
-{
-#define cv_sizeof(v) ((int)(v->type & SIZE_MASK))
- int s1 = cv_sizeof(v1);
- int s2 = cv_sizeof(v2);
-#undef cv_sizeof
-
- if(s1 == s2)
- return;
- else if(s1 > s2)
- {
- switch(v1->type)
- {
- case cv_sint: cast_to_sint(v2); break;
- case cv_uint: cast_to_uint(v2); break;
- case cv_slong: cast_to_slong(v2); break;
- case cv_ulong: cast_to_ulong(v2); break;
- case cv_sll: cast_to_sll(v2); break;
- case cv_ull: cast_to_ull(v2); break;
- }
- }
- else
- {
- switch(v2->type)
- {
- case cv_sint: cast_to_sint(v1); break;
- case cv_uint: cast_to_uint(v1); break;
- case cv_slong: cast_to_slong(v1); break;
- case cv_ulong: cast_to_ulong(v1); break;
- case cv_sll: cast_to_sll(v1); break;
- case cv_ull: cast_to_ull(v1); break;
- }
- }
-}
-
-
-static int boolean(cval_t *v)
-{
- switch(v->type)
- {
- case cv_sint: return v->val.si != 0;
- case cv_uint: return v->val.ui != 0;
- case cv_slong: return v->val.sl != 0;
- case cv_ulong: return v->val.ul != 0;
- case cv_sll: return v->val.sll != 0;
- case cv_ull: return v->val.ull != 0;
- }
- return 0;
-}
-
-static marg_t *new_marg(char *str, def_arg_t type)
-{
- marg_t *ma = pp_xmalloc(sizeof(marg_t));
- if(!ma)
- return NULL;
- ma->arg = str;
- ma->type = type;
- ma->nnl = 0;
- return ma;
-}
-
-static marg_t *add_new_marg(char *str, def_arg_t type)
-{
- marg_t **new_macro_args;
- marg_t *ma;
- if(!str)
- return NULL;
- new_macro_args = pp_xrealloc(macro_args, (nmacro_args+1) * sizeof(macro_args[0]));
- if(!new_macro_args)
- return NULL;
- macro_args = new_macro_args;
- ma = new_marg(str, type);
- if(!ma)
- return NULL;
- macro_args[nmacro_args] = ma;
- nmacro_args++;
- return ma;
-}
-
-static int marg_index(char *id)
-{
- int t;
- if(!id)
- return -1;
- for(t = 0; t < nmacro_args; t++)
- {
- if(!strcmp(id, macro_args[t]->arg))
- break;
- }
- return t < nmacro_args ? t : -1;
-}
-
-static mtext_t *new_mtext(char *str, int idx, def_exp_t type)
-{
- mtext_t *mt = pp_xmalloc(sizeof(mtext_t));
- if(!mt)
- return NULL;
- if(str == NULL)
- mt->subst.argidx = idx;
- else
- mt->subst.text = str;
- mt->type = type;
- mt->next = mt->prev = NULL;
- return mt;
-}
-
-static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp)
-{
- if(!tail)
- return mtp;
-
- if(!mtp)
- return tail;
-
- if(tail->type == exp_text && mtp->type == exp_text)
- {
- char *new_text;
- new_text = pp_xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
- if(!new_text)
- return mtp;
- tail->subst.text = new_text;
- strcat(tail->subst.text, mtp->subst.text);
- free(mtp->subst.text);
- free(mtp);
- return tail;
- }
-
- if(tail->type == exp_concat && mtp->type == exp_concat)
- {
- free(mtp);
- return tail;
- }
-
- if(tail->type == exp_concat && mtp->type == exp_text)
- {
- int len = strlen(mtp->subst.text);
- while(len)
- {
-/* FIXME: should delete space from head of string */
- if(isspace(mtp->subst.text[len-1] & 0xff))
- mtp->subst.text[--len] = '\0';
- else
- break;
- }
-
- if(!len)
- {
- free(mtp->subst.text);
- free(mtp);
- return tail;
- }
- }
-
- if(tail->type == exp_text && mtp->type == exp_concat)
- {
- int len = strlen(tail->subst.text);
- while(len)
- {
- if(isspace(tail->subst.text[len-1] & 0xff))
- tail->subst.text[--len] = '\0';
- else
- break;
- }
-
- if(!len)
- {
- mtp->prev = tail->prev;
- mtp->next = tail->next;
- if(tail->prev)
- tail->prev->next = mtp;
- free(tail->subst.text);
- free(tail);
- return mtp;
- }
- }
-
- tail->next = mtp;
- mtp->prev = tail;
-
- return mtp;
-}
-
-static char *merge_text(char *s1, char *s2)
-{
- int l1;
- int l2;
- char *snew;
- if(!s1)
- return s2;
- if(!s2)
- return s1;
- l1 = strlen(s1);
- l2 = strlen(s2);
- snew = pp_xrealloc(s1, l1+l2+1);
- if(!snew)
- {
- free(s2);
- return s1;
- }
- s1 = snew;
- memcpy(s1+l1, s2, l2+1);
- free(s2);
- return s1;
-}
diff --git a/dlls/d3dcompiler_43/preproc.c b/dlls/d3dcompiler_43/preproc.c
deleted file mode 100644
index 3ea05a00a26..00000000000
--- a/dlls/d3dcompiler_43/preproc.c
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#include <assert.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "wpp_private.h"
-
-struct pp_status pp_status;
-
-#define HASHKEY 2039
-
-typedef struct pp_def_state
-{
- struct pp_def_state *next;
- pp_entry_t *defines[HASHKEY];
-} pp_def_state_t;
-
-static pp_def_state_t *pp_def_state;
-
-#define MAXIFSTACK 64
-static pp_if_state_t if_stack[MAXIFSTACK];
-static int if_stack_idx = 0;
-
-void *pp_xmalloc(size_t size)
-{
- void *res;
-
- assert(size > 0);
- res = malloc(size);
- if(res == NULL)
- {
- /* Set the error flag */
- pp_status.state = 1;
- }
- return res;
-}
-
-void *pp_xrealloc(void *p, size_t size)
-{
- void *res;
-
- assert(size > 0);
- res = realloc(p, size);
- if(res == NULL)
- {
- /* Set the error flag */
- pp_status.state = 1;
- }
- return res;
-}
-
-char *pp_xstrdup(const char *str)
-{
- char *s;
- int len;
-
- assert(str != NULL);
- len = strlen(str)+1;
- s = pp_xmalloc(len);
- if(!s)
- return NULL;
- return memcpy(s, str, len);
-}
-
-/* Don't comment on the hash, it's primitive but functional... */
-static int pphash(const char *str)
-{
- int sum = 0;
- while(*str)
- sum += *str++;
- return sum % HASHKEY;
-}
-
-pp_entry_t *pplookup(const char *ident)
-{
- int idx;
- pp_entry_t *ppp;
-
- if(!ident)
- return NULL;
- idx = pphash(ident);
- for(ppp = pp_def_state->defines[idx]; ppp; ppp = ppp->next)
- {
- if(!strcmp(ident, ppp->ident))
- return ppp;
- }
- return NULL;
-}
-
-static void free_pp_entry( pp_entry_t *ppp, int idx )
-{
- if(ppp->iep)
- {
- if(ppp->iep == pp_includelogiclist)
- {
- pp_includelogiclist = ppp->iep->next;
- if(pp_includelogiclist)
- pp_includelogiclist->prev = NULL;
- }
- else
- {
- ppp->iep->prev->next = ppp->iep->next;
- if(ppp->iep->next)
- ppp->iep->next->prev = ppp->iep->prev;
- }
- free(ppp->iep->filename);
- free(ppp->iep);
- }
-
- if(pp_def_state->defines[idx] == ppp)
- {
- pp_def_state->defines[idx] = ppp->next;
- if(pp_def_state->defines[idx])
- pp_def_state->defines[idx]->prev = NULL;
- }
- else
- {
- ppp->prev->next = ppp->next;
- if(ppp->next)
- ppp->next->prev = ppp->prev;
- }
-
- free(ppp);
-}
-
-/* push a new (empty) define state */
-int pp_push_define_state(void)
-{
- pp_def_state_t *state = pp_xmalloc( sizeof(*state) );
- if(!state)
- return 1;
-
- memset( state->defines, 0, sizeof(state->defines) );
- state->next = pp_def_state;
- pp_def_state = state;
- return 0;
-}
-
-/* pop the current define state */
-void pp_pop_define_state(void)
-{
- int i;
- pp_entry_t *ppp;
- pp_def_state_t *state;
-
- for (i = 0; i < HASHKEY; i++)
- {
- while ((ppp = pp_def_state->defines[i]) != NULL) pp_del_define( ppp->ident );
- }
- state = pp_def_state;
- pp_def_state = state->next;
- free( state );
-}
-
-void pp_del_define(const char *name)
-{
- pp_entry_t *ppp;
- int idx = pphash(name);
-
- if((ppp = pplookup(name)) == NULL)
- {
- if(pp_status.pedantic)
- ppy_warning("%s was not defined", name);
- return;
- }
-
- free( ppp->ident );
- free( ppp->subst.text );
- free( ppp->filename );
- free_pp_entry( ppp, idx );
-}
-
-pp_entry_t *pp_add_define(const char *def, const char *text)
-{
- int len;
- char *cptr;
- int idx;
- pp_entry_t *ppp;
-
- if(!def)
- return NULL;
- idx = pphash(def);
- if((ppp = pplookup(def)) != NULL)
- {
- if(pp_status.pedantic)
- ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", def, ppp->filename, ppp->linenumber);
- pp_del_define(def);
- }
- ppp = pp_xmalloc(sizeof(pp_entry_t));
- if(!ppp)
- return NULL;
- memset( ppp, 0, sizeof(*ppp) );
- ppp->ident = pp_xstrdup(def);
- if(!ppp->ident)
- goto error;
- ppp->type = def_define;
- ppp->subst.text = text ? pp_xstrdup(text) : NULL;
- if(text && !ppp->subst.text)
- goto error;
- ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
- if(!ppp->filename)
- goto error;
- ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
- ppp->next = pp_def_state->defines[idx];
- pp_def_state->defines[idx] = ppp;
- if(ppp->next)
- ppp->next->prev = ppp;
- if(ppp->subst.text)
- {
- /* Strip trailing white space from subst text */
- len = strlen(ppp->subst.text);
- while(len && strchr(" \t\r\n", ppp->subst.text[len-1]))
- {
- ppp->subst.text[--len] = '\0';
- }
- /* Strip leading white space from subst text */
- for(cptr = ppp->subst.text; *cptr && strchr(" \t\r", *cptr); cptr++)
- ;
- if(ppp->subst.text != cptr)
- memmove(ppp->subst.text, cptr, strlen(cptr)+1);
- }
- return ppp;
-
-error:
- free(ppp->ident);
- free(ppp->subst.text);
- free(ppp);
- return NULL;
-}
-
-pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
-{
- int idx;
- pp_entry_t *ppp;
-
- if(!id)
- return NULL;
- idx = pphash(id);
- if((ppp = pplookup(id)) != NULL)
- {
- if(pp_status.pedantic)
- ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", id, ppp->filename, ppp->linenumber);
- pp_del_define(id);
- }
- ppp = pp_xmalloc(sizeof(pp_entry_t));
- if(!ppp)
- return NULL;
- memset( ppp, 0, sizeof(*ppp) );
- ppp->ident = id;
- ppp->type = def_macro;
- ppp->margs = args;
- ppp->nargs = nargs;
- ppp->subst.mtext= exp;
- ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
- if(!ppp->filename)
- {
- free(ppp);
- return NULL;
- }
- ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
- ppp->next = pp_def_state->defines[idx];
- pp_def_state->defines[idx] = ppp;
- if(ppp->next)
- ppp->next->prev = ppp;
- return ppp;
-}
-
-
-void *pp_open_include(const char *name, int type, const char *parent_name, char **newpath)
-{
- char *path;
- void *fp;
-
- if (!(path = wpp_lookup(name, type, parent_name))) return NULL;
- fp = wpp_open(path, type);
-
- if (fp)
- {
- if (newpath) *newpath = path;
- else free( path );
- return fp;
- }
- free( path );
- return NULL;
-}
-
-/*
- *-------------------------------------------------------------------------
- * #if, #ifdef, #ifndef, #else, #elif and #endif state management
- *
- * #if state transitions are made on basis of the current TOS and the next
- * required state. The state transitions are required to housekeep because
- * #if:s can be nested. The ignore case is activated to prevent output from
- * within a false clause.
- * Some special cases come from the fact that the #elif cases are not
- * binary, but three-state. The problem is that all other elif-cases must
- * be false when one true one has been found. A second problem is that the
- * #else clause is a final clause. No extra #else:s may follow.
- *
- * The states mean:
- * if_true Process input to output
- * if_false Process input but no output
- * if_ignore Process input but no output
- * if_elif Process input but no output
- * if_elsefalse Process input but no output
- * if_elsettrue Process input to output
- *
- * The possible state-sequences are [state(stack depth)] (rest can be deduced):
- * TOS #if 1 #else #endif
- * if_true(n) if_true(n+1) if_elsefalse(n+1)
- * if_false(n) if_ignore(n+1) if_ignore(n+1)
- * if_elsetrue(n) if_true(n+1) if_elsefalse(n+1)
- * if_elsefalse(n) if_ignore(n+1) if_ignore(n+1)
- * if_elif(n) if_ignore(n+1) if_ignore(n+1)
- * if_ignore(n) if_ignore(n+1) if_ignore(n+1)
- *
- * TOS #if 1 #elif 0 #else #endif
- * if_true(n) if_true(n+1) if_elif(n+1) if_elif(n+1)
- * if_false(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
- * if_elsetrue(n) if_true(n+1) if_elif(n+1) if_elif(n+1)
- * if_elsefalse(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
- * if_elif(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
- * if_ignore(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
- *
- * TOS #if 0 #elif 1 #else #endif
- * if_true(n) if_false(n+1) if_true(n+1) if_elsefalse(n+1)
- * if_false(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
- * if_elsetrue(n) if_false(n+1) if_true(n+1) if_elsefalse(n+1)
- * if_elsefalse(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
- * if_elif(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
- * if_ignore(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
- *
- *-------------------------------------------------------------------------
- */
-
-void pp_push_if(pp_if_state_t s)
-{
- if(if_stack_idx >= MAXIFSTACK)
- pp_internal_error(__FILE__, __LINE__, "#if-stack overflow; #{if,ifdef,ifndef} nested too deeply (> %d)", MAXIFSTACK);
-
- if_stack[if_stack_idx++] = s;
-
- switch(s)
- {
- case if_true:
- case if_elsetrue:
- break;
- case if_false:
- case if_elsefalse:
- case if_elif:
- case if_ignore:
- pp_push_ignore_state();
- break;
- default:
- pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
- }
-}
-
-pp_if_state_t pp_pop_if(void)
-{
- if(if_stack_idx <= 0)
- {
- ppy_error("#{endif,else,elif} without #{if,ifdef,ifndef} (#if-stack underflow)");
- return if_error;
- }
-
- switch(pp_if_state())
- {
- case if_true:
- case if_elsetrue:
- break;
- case if_false:
- case if_elsefalse:
- case if_elif:
- case if_ignore:
- pp_pop_ignore_state();
- break;
- default:
- pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
- }
- return if_stack[--if_stack_idx];
-}
-
-pp_if_state_t pp_if_state(void)
-{
- if(!if_stack_idx)
- return if_true;
- else
- return if_stack[if_stack_idx-1];
-}
-
-
-void pp_next_if_state(int i)
-{
- switch(pp_if_state())
- {
- case if_true:
- case if_elsetrue:
- pp_push_if(i ? if_true : if_false);
- break;
- case if_false:
- case if_elsefalse:
- case if_elif:
- case if_ignore:
- pp_push_if(if_ignore);
- break;
- default:
- pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #{if,ifdef,ifndef} directive", (int)pp_if_state());
- }
-}
-
-int pp_get_if_depth(void)
-{
- return if_stack_idx;
-}
-
-void WINAPIV pp_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);
-}
diff --git a/dlls/d3dcompiler_43/tests/asm.c b/dlls/d3dcompiler_43/tests/asm.c
index 61a6f3e2bc3..25471b51673 100644
--- a/dlls/d3dcompiler_43/tests/asm.c
+++ b/dlls/d3dcompiler_43/tests/asm.c
@@ -34,6 +34,7 @@ HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filena
struct shader_test {
const char *text;
const DWORD bytes[128];
+ BOOL todo;
};
static void dump_shader(DWORD *shader) {
@@ -59,6 +60,7 @@ static void exec_tests(const char *name, struct shader_test tests[], unsigned in
messages = NULL;
hr = D3DAssemble(tests[i].text, strlen(tests[i].text), NULL, NULL,
NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages);
+ todo_wine_if(tests[i].todo)
ok(hr == S_OK, "Test %s, shader %u: D3DAssemble failed with error %#lx - %ld.\n", name, i, hr, hr & 0xffff);
if(messages) {
trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
@@ -211,7 +213,8 @@ static void vs_1_1_test(void) {
"vs_1_1\n"
"def c12, 0, -1, -0.5, 1024\n",
{0xfffe0101, 0x00000051, 0xa00f000c, 0x00000000, 0xbf800000, 0xbf000000,
- 0x44800000, 0x0000ffff}
+ 0x44800000, 0x0000ffff},
+ TRUE
},
{ /* shader 14: writemasks, swizzles */
"vs_1_1\n"
@@ -759,7 +762,8 @@ static void vs_2_0_test(void) {
"defi i1, 0, 40, 30, 10\n",
{0xfffe0200, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
- 0x0000000a, 0x0000ffff}
+ 0x0000000a, 0x0000ffff},
+ TRUE
},
{ /* shader 23 */
"vs_2_0\n"
@@ -971,7 +975,8 @@ static void ps_2_x_test(void) {
"defi i1, 0, 40, 30, 10\n",
{0xffff0201, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
- 0x0000000a, 0x0000ffff}
+ 0x0000000a, 0x0000ffff},
+ TRUE
},
{ /* shader 2 */
"ps_2_x\n"
@@ -1660,7 +1665,7 @@ static void d3dpreprocess_test(void)
/* NULL shader test */
messages = NULL;
hr = D3DPreprocess(test1, strlen(test1), NULL, defines, NULL, NULL, &messages);
- ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
+ todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
if (messages)
{
trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
@@ -1671,7 +1676,7 @@ static void d3dpreprocess_test(void)
shader = NULL;
messages = NULL;
hr = D3DPreprocess(quotation_marks_test, strlen(quotation_marks_test), NULL, NULL, NULL, &shader, &messages);
- todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
+ ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
if (messages)
{
trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
index cbf32695625..e9da65c6bc2 100644
--- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
+++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
@@ -1620,7 +1620,8 @@ static void test_include(void)
#if D3D_COMPILER_VERSION >= 46
hr = tests[i](NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, &blob, &errors);
- todo_wine_if (i != 1) ok(hr == (i == 0 ? D3DXERR_INVALIDDATA : E_FAIL), "Got unexpected hr %#lx.\n", hr);
+ todo_wine_if (!i)
+ ok(hr == (i == 0 ? D3DXERR_INVALIDDATA : E_FAIL), "Got unexpected hr %#lx.\n", hr);
ok(!blob, "Got unexpected blob.\n");
ok(!!errors, "Got unexpected errors.\n");
ID3D10Blob_Release(errors);
diff --git a/dlls/d3dcompiler_43/wpp_private.h b/dlls/d3dcompiler_43/wpp_private.h
deleted file mode 100644
index 3b6d947d8a8..00000000000
--- a/dlls/d3dcompiler_43/wpp_private.h
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright 1998 Bertho A. Stultiens (BS)
- * Copyright 2002 Alexandre Julliard
- *
- * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#ifndef __WPP_PRIVATE_H
-#define __WPP_PRIVATE_H
-
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include "windef.h"
-
-/* Return value == 0 means successful execution */
-extern int wpp_add_define( const char *name, const char *value );
-extern void wpp_del_define( const char *name );
-extern char *wpp_lookup(const char *filename, int type, const char *parent_name);
-extern void *wpp_open(const char *filename, int type);
-extern void wpp_close(void *file);
-extern int wpp_read(void *file, char *buffer, unsigned int len);
-extern void wpp_write(const char *buffer, unsigned int len);
-extern int wpp_parse( const char *input, FILE *output );
-
-struct pp_entry; /* forward */
-/*
- * Include logic
- * A stack of files which are already included and
- * are protected in the #ifndef/#endif way.
- */
-typedef struct includelogicentry {
- struct includelogicentry *next;
- struct includelogicentry *prev;
- struct pp_entry *ppp; /* The define which protects the file */
- char *filename; /* The filename of the include */
-} includelogicentry_t;
-
-/*
- * The arguments of a macrodefinition
- */
-typedef enum {
- arg_single,
- arg_list
-} def_arg_t;
-
-typedef struct marg {
- def_arg_t type; /* Normal or ... argument */
- char *arg; /* The textual argument */
- int nnl; /* Number of newlines in the text to subst */
-} marg_t;
-
-/*
- * The expansiontext of a macro
- */
-typedef enum {
- exp_text, /* Simple text substitution */
- exp_concat, /* Concat (##) operator requested */
- exp_stringize, /* Stringize (#) operator requested */
- exp_subst /* Substitute argument */
-} def_exp_t;
-
-typedef struct mtext {
- struct mtext *next;
- struct mtext *prev;
- def_exp_t type;
- union {
- char *text;
- int argidx; /* For exp_subst and exp_stringize reference */
- } subst;
-} mtext_t;
-
-/*
- * The define descriptor
- */
-typedef enum {
- def_none, /* Not-a-define; used as return value */
- def_define, /* Simple defines */
- def_macro, /* Macro defines */
- def_special /* Special expansions like __LINE__ and __FILE__ */
-} def_type_t;
-
-typedef struct pp_entry {
- struct pp_entry *next;
- struct pp_entry *prev;
- def_type_t type; /* Define or macro */
- char *ident; /* The key */
- marg_t **margs; /* Macro arguments array or NULL if none */
- int nargs;
- union {
- mtext_t *mtext; /* The substitution sequence or NULL if none */
- char *text;
- } subst;
- int expanding; /* Set when feeding substitution into the input */
- char *filename; /* Filename where it was defined */
- int linenumber; /* Linenumber where it was defined */
- includelogicentry_t *iep; /* Points to the include it protects */
-} pp_entry_t;
-
-
-/*
- * If logic
- */
-#define MAXIFSTACK 64 /* If this isn't enough you should alter the source... */
-
-typedef enum {
- if_false,
- if_true,
- if_elif,
- if_elsefalse,
- if_elsetrue,
- if_ignore,
- if_error
-} pp_if_state_t;
-
-
-/*
- * Trace the include files to prevent double reading.
- * This save 20..30% of processing time for most stuff
- * that uses complex includes.
- * States:
- * -1 Don't track or seen junk
- * 0 New include, waiting for "#ifndef __xxx_h"
- * 1 Seen #ifndef, waiting for "#define __xxx_h ..."
- * 2 Seen #endif, waiting for EOF
- */
-typedef struct
-{
- int state;
- char *ppp; /* The define to be set from the #ifndef */
- int ifdepth; /* The level of ifs at the #ifdef */
- int seen_junk; /* Set when junk is seen */
-} include_state_t;
-
-#define SIZE_CHAR 1
-#define SIZE_SHORT 2
-#define SIZE_INT 3
-#define SIZE_LONG 4
-#define SIZE_LONGLONG 5
-#define SIZE_MASK 0x00ff
-#define FLAG_SIGNED 0x0100
-
-typedef enum {
-#if 0
- cv_schar = SIZE_CHAR + FLAG_SIGNED,
- cv_uchar = SIZE_CHAR,
- cv_sshort = SIZE_SHORT + FLAG_SIGNED,
- cv_ushort = SIZE_SHORT,
-#endif
- cv_sint = SIZE_INT + FLAG_SIGNED,
- cv_uint = SIZE_INT,
- cv_slong = SIZE_LONG + FLAG_SIGNED,
- cv_ulong = SIZE_LONG,
- cv_sll = SIZE_LONGLONG + FLAG_SIGNED,
- cv_ull = SIZE_LONGLONG
-} ctype_t;
-
-typedef struct cval {
- ctype_t type;
- union {
-#if 0
- signed char sc; /* Explicitly signed because compilers are stupid */
- unsigned char uc;
- short ss;
- unsigned short us;
-#endif
- int si;
- unsigned int ui;
- long sl;
- unsigned long ul;
- __int64 sll;
- unsigned __int64 ull;
- } val;
-} cval_t;
-
-
-
-void *pp_xmalloc(size_t);
-void *pp_xrealloc(void *, size_t);
-char *pp_xstrdup(const char *str);
-pp_entry_t *pplookup(const char *ident);
-int pp_push_define_state(void);
-void pp_pop_define_state(void);
-pp_entry_t *pp_add_define(const char *def, const char *text);
-pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
-void pp_del_define(const char *name);
-void *pp_open_include(const char *name, int type, const char *parent_name, char **newpath);
-void pp_push_if(pp_if_state_t s);
-void pp_next_if_state(int);
-pp_if_state_t pp_pop_if(void);
-pp_if_state_t pp_if_state(void);
-int pp_get_if_depth(void);
-
-#ifndef __GNUC__
-#define __attribute__(x) /*nothing*/
-#endif
-
-extern const struct wpp_callbacks *wpp_callbacks;
-
-int WINAPIV ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
-int WINAPIV ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
-void WINAPIV pp_internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));
-
-/* current preprocessor state */
-/* everything is in this structure to avoid polluting the global symbol space */
-struct pp_status
-{
- char *input; /* current input file name */
- void *file; /* current input file descriptor */
- int line_number; /* current line number */
- int char_number; /* current char number in line */
- int state; /* current error state */
- int pedantic; /* pedantic option */
-};
-
-extern struct pp_status pp_status;
-extern include_state_t pp_incl_state;
-extern includelogicentry_t *pp_includelogiclist;
-
-/*
- * From ppl.l
- */
-extern FILE *ppy_out;
-extern char *ppy_text;
-int ppy_lex(void);
-int ppy_lex_destroy(void);
-
-void pp_do_include(char *fname, int type);
-void pp_push_ignore_state(void);
-void pp_pop_ignore_state(void);
-
-void WINAPIV pp_writestring(const char *format, ...) __attribute__((format (printf, 1, 2)));
-
-/*
- * From ppy.y
- */
-int ppy_parse(void);
-
-#endif /* __WPP_PRIVATE_H */
diff --git a/dlls/d3dcompiler_46/Makefile.in b/dlls/d3dcompiler_46/Makefile.in
index 187535772be..1d82dfed1d9 100644
--- a/dlls/d3dcompiler_46/Makefile.in
+++ b/dlls/d3dcompiler_46/Makefile.in
@@ -1,6 +1,6 @@
MODULE = d3dcompiler_46.dll
IMPORTLIB = d3dcompiler_46
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=46
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -12,16 +12,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dcompiler_47/Makefile.in b/dlls/d3dcompiler_47/Makefile.in
index bc6ce091108..e7df065061c 100644
--- a/dlls/d3dcompiler_47/Makefile.in
+++ b/dlls/d3dcompiler_47/Makefile.in
@@ -1,6 +1,6 @@
MODULE = d3dcompiler_47.dll
IMPORTLIB = d3dcompiler
-IMPORTS = wined3d dxguid uuid
+IMPORTS = wined3d
EXTRADEFS = -DD3D_COMPILER_VERSION=47
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
@@ -12,16 +12,13 @@ C_SRCS = \
blob.c \
bytecodewriter.c \
compiler.c \
- preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
- asmshader.l \
- ppl.l
+ asmshader.l
BISON_SRCS = \
- asmshader.y \
- ppy.y
+ asmshader.y
RC_SRCS = version.rc
diff --git a/dlls/d3dx9_36/tests/asm.c b/dlls/d3dx9_36/tests/asm.c
index 9b4e82f218a..bfc84b2f9c2 100644
--- a/dlls/d3dx9_36/tests/asm.c
+++ b/dlls/d3dx9_36/tests/asm.c
@@ -259,7 +259,7 @@ static void assembleshader_test(void)
messages = NULL;
hr = D3DXAssembleShader(testshader2, strlen(testshader2), NULL, &include.ID3DXInclude_iface,
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
- ok(hr == D3D_OK, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
+ todo_wine ok(hr == D3D_OK, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
if(messages) {
trace("recursive D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
ID3DXBuffer_Release(messages);
--
2.34.1
More information about the wine-devel
mailing list