Fix for br979 part 1 - strip leading/trailing space from macro actual args.

Although the IEEE standard doesn't explicitly state this is required,
the examples added in the SystemVerilog standard show that this is
expected.

Also add a preprocessor lexical rule to recognise `` inside a macro
definition when it is not immediately followed by an identifier.
This commit is contained in:
Martin Whitaker 2015-05-22 18:11:24 +01:00
parent ab688613cc
commit 0fc10e3e70
1 changed files with 28 additions and 6 deletions

View File

@ -1,7 +1,7 @@
%option prefix="yy"
%{
/*
* Copyright (c) 1999-2014 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2015 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -532,6 +532,8 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif)
}
}
`` { if (istack->file != NULL) ECHO; }
<MA_START>\( { BEGIN(MA_ADD); macro_start_args(); }
<MA_START>{W} {}
@ -568,8 +570,12 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif)
<MA_ADD>"(" { macro_add_to_arg(0); ma_parenthesis_level++; }
<MA_ADD>"," { if (ma_parenthesis_level > 0) macro_add_to_arg(0);
else macro_finish_arg(); }
<MA_ADD>"," {
if (ma_parenthesis_level > 0)
macro_add_to_arg(0);
else
macro_finish_arg();
}
<MA_ADD>")" {
if (ma_parenthesis_level > 0) {
@ -1300,14 +1306,30 @@ static void macro_add_to_arg(int is_white_space)
static void macro_finish_arg(void)
{
char* tail = &def_buf[def_buf_size - def_buf_free];
int offs;
char* head;
char* tail;
check_for_max_args();
offs = def_argo[def_argc-1] + def_argl[def_argc-1] + 1;
head = &def_buf[offs];
tail = &def_buf[def_buf_size - def_buf_free];
/* Eat any leading and trailing white space. */
if ((head < tail) && (*head == ' ')) {
offs++;
head++;
}
if ((tail > head) && (*(tail-1) == ' ')) {
def_buf_free++;
tail--;
}
*tail = 0;
def_argo[def_argc] = def_argo[def_argc-1] + def_argl[def_argc-1] + 1;
def_argl[def_argc] = tail - def_argv(def_argc);
def_argo[def_argc] = offs;
def_argl[def_argc] = tail - head;
def_buf_free -= 1;
def_argc++;