From 0fc10e3e70d4d65e5f31db66fcf710dc97411de5 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Fri, 22 May 2015 18:11:24 +0100 Subject: [PATCH] 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. --- ivlpp/lexor.lex | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 5a95e4f6a..56022aa72 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -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; } + \( { BEGIN(MA_ADD); macro_start_args(); } {W} {} @@ -568,8 +570,12 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) "(" { macro_add_to_arg(0); ma_parenthesis_level++; } -"," { if (ma_parenthesis_level > 0) macro_add_to_arg(0); - else macro_finish_arg(); } +"," { + if (ma_parenthesis_level > 0) + macro_add_to_arg(0); + else + macro_finish_arg(); +} ")" { 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++;