From 47b13a79e8ca414ac878c566dad991d2ff247be6 Mon Sep 17 00:00:00 2001 From: borutr Date: Thu, 30 Oct 2003 21:58:57 +0000 Subject: [PATCH] support/cpp2/cpphash.h, support/cpp2/cpplib.h, support/cpp2/cpplex.c, support/cpp2/cppmain.c, support/cpp2/cppinit.c: fixed bug #828015 - Syntax variation for _asm character constants git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2968 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 8 ++++ support/cpp2/cpphash.h | 2 + support/cpp2/cppinit.c | 2 + support/cpp2/cpplex.c | 92 ++++++++++++++++++++++++++++++++++++++++++ support/cpp2/cpplib.h | 5 ++- support/cpp2/cppmain.c | 4 +- 6 files changed, 111 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ebc3ad7..c08ae37f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-10-30 Borut Razem + + * support/cpp2/cpphash.h, + * support/cpp2/cpplib.h + * support/cpp2/cpplex.c, + * support/cpp2/cppmain.c, + * support/cpp2/cppinit.c: fixed bug #828015 - Syntax variation for _asm character constants + 2003-10-30 Erik Petrich Fixed a number of problems revealed by bug #827883. diff --git a/support/cpp2/cpphash.h b/support/cpp2/cpphash.h index 56d90681..d9b89f16 100644 --- a/support/cpp2/cpphash.h +++ b/support/cpp2/cpphash.h @@ -166,6 +166,8 @@ struct spec_nodes cpp_hashnode *n__STRICT_ANSI__; /* STDC_0_IN_SYSTEM_HEADERS */ cpp_hashnode *n__CHAR_UNSIGNED__; /* plain char is unsigned */ cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */ + /* SDCC _asm specific */ + cpp_hashnode *n__asm; /* _asm ... _endasm ; */ }; struct cpp_buffer diff --git a/support/cpp2/cppinit.c b/support/cpp2/cppinit.c index ac826bdf..18a1b005 100644 --- a/support/cpp2/cppinit.c +++ b/support/cpp2/cppinit.c @@ -558,6 +558,8 @@ cpp_create_reader (table, lang) s->n__CHAR_UNSIGNED__ = cpp_lookup (pfile, DSC("__CHAR_UNSIGNED__")); s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__")); s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC; + /* SDCC _asm specific */ + s->n__asm = cpp_lookup (pfile, DSC("_asm")); return pfile; } diff --git a/support/cpp2/cpplex.c b/support/cpp2/cpplex.c index 74248272..c174648c 100644 --- a/support/cpp2/cpplex.c +++ b/support/cpp2/cpplex.c @@ -300,6 +300,57 @@ get_effective_char (buffer) return next; } +/* SDCC _asm specific */ +/* Skip an _asm ... _endasm block. We find the end of the comment by + seeing _endasm. Returns non-zero if _asm terminated by EOF, zero + otherwise. */ +static int +skip_asm_block (pfile) + cpp_reader *pfile; +{ +#define _ENDASM_STR "endasm" +#define _ENDASM_LEN ((sizeof _ENDASM_STR) - 1) + + cpp_buffer *buffer = pfile->buffer; + cppchar_t c = EOF; + int prev_space = 0; + int ret = 1; + + pfile->state.lexing_comment = 1; + while (buffer->cur != buffer->rlimit) + { + prev_space = is_space(c), c = *buffer->cur++; + + next_char: + /* FIXME: For speed, create a new character class of characters + of interest inside block comments. */ + if (c == '?' || c == '\\') + c = skip_escaped_newlines (buffer, c); + + if (prev_space && c == '_') + { + if (buffer->cur + _ENDASM_LEN <= buffer->rlimit && + strncmp(buffer->cur, _ENDASM_STR, _ENDASM_LEN) == 0) + { + buffer->cur += _ENDASM_LEN; + ret = 0; + break; + } + } + else if (is_vspace (c)) + { + prev_space = is_space(c), c = handle_newline (buffer, c); + goto next_char; + } + else if (c == '\t') + adjust_column (pfile); + } + + pfile->state.lexing_comment = 0; + buffer->read_ahead = EOF; + return ret; +} + /* Skip a C-style block comment. We find the end of the comment by seeing if an asterisk is before every '/' we encounter. Returns non-zero if comment terminated by EOF, zero otherwise. */ @@ -728,6 +779,35 @@ parse_string (pfile, token, terminator) POOL_COMMIT (pool, token->val.str.len + 1); } +/* SDCC _asm specific */ +/* The stored comment includes the comment start and any terminator. */ +static void +save_asm (pfile, token, from) + cpp_reader *pfile; + cpp_token *token; + const unsigned char *from; +{ +#define _ASM_STR "_asm" +#define _ASM_LEN ((sizeof _ASM_STR) - 1) + + unsigned char *buffer; + unsigned int len; + + len = pfile->buffer->cur - from + _ASM_LEN; /* + _ASM_LEN for the initial '_asm'. */ + /* C++ _asm block probably (not definitely) has moved past a new + line, which we don't want to save in the comment. */ + if (pfile->buffer->read_ahead != EOF) + len--; + buffer = _cpp_pool_alloc (&pfile->ident_pool, len); + + token->type = CPP_ASM; + token->val.str.len = len; + token->val.str.text = buffer; + + memcpy (buffer, _ASM_STR, _ASM_LEN); + memcpy (buffer + _ASM_LEN, from, len - _ASM_LEN); +} + /* The stored comment includes the comment start and any terminator. */ static void save_comment (pfile, token, from) @@ -977,6 +1057,18 @@ _cpp_lex_token (pfile, result) goto make_string; } } + /* SDCC _asm specific */ + /* handle _asm ... _endasm ; */ + else if (result->val.node == pfile->spec_nodes.n__asm) + { + comment_start = buffer->cur; + result->type = CPP_ASM; + skip_asm_block (pfile); + /* Save the _asm block as a token in its own right. */ + save_asm (pfile, result, comment_start); + /* Don't do MI optimisation. */ + return; + } /* Convert named operators to their proper types. */ else if (result->val.node->flags & NODE_OPERATOR) { diff --git a/support/cpp2/cpplib.h b/support/cpp2/cpplib.h index 337d7d76..a6602b51 100644 --- a/support/cpp2/cpplib.h +++ b/support/cpp2/cpplib.h @@ -138,7 +138,10 @@ struct ht; \ TK(CPP_COMMENT, SPELL_STRING) /* Only if output comments. */ \ TK(CPP_MACRO_ARG, SPELL_NONE) /* Macro argument. */ \ - OP(CPP_EOF, "EOL") /* End of line or file. */ + OP(CPP_EOF, "EOL") /* End of line or file. */ \ +\ + /* SDCC _asm specific */ + TK(CPP_ASM, SPELL_STRING) /* _asm ... _endasm ; */ #define OP(e, s) e, #define TK(e, s) e, diff --git a/support/cpp2/cppmain.c b/support/cpp2/cppmain.c index 4d33e221..d01b4c25 100644 --- a/support/cpp2/cppmain.c +++ b/support/cpp2/cppmain.c @@ -249,7 +249,9 @@ scan_buffer (pfile) cpp_output_token (token, print.outf); print.printed = 1; if (token->type == CPP_STRING || token->type == CPP_WSTRING - || token->type == CPP_COMMENT) + || token->type == CPP_COMMENT + /* SDCC _asm specific */ + || token->type == CPP_ASM) check_multiline_token (&token->val.str); } } -- 2.47.2