]> git.gag.com Git - fw/sdcc/commitdiff
support/cpp2/cpphash.h, support/cpp2/cpplib.h, support/cpp2/cpplex.c,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 30 Oct 2003 21:58:57 +0000 (21:58 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 30 Oct 2003 21:58:57 +0000 (21:58 +0000)
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
support/cpp2/cpphash.h
support/cpp2/cppinit.c
support/cpp2/cpplex.c
support/cpp2/cpplib.h
support/cpp2/cppmain.c

index 7ebc3ad7e791a2fe4ac4c75ca2ae471a153c2b00..c08ae37ffbc1283dad19336094203407a3af5bbc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-10-30  Borut Razem <borut.razem@siol.net>
+
+       * 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 <epetrich@ivorytower.norman.ok.us>
 
        Fixed a number of problems revealed by bug #827883.
index 56d90681dcbbcccb2848fe1d7cc13b903db9e2cf..d9b89f16e2b996aa4b5d17e0428b87321e2dd6c5 100644 (file)
@@ -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
index ac826bdf98ef6a3add637150a911d09a10c6c33b..18a1b0053042c8a7ea15562cd3ba2cdbac402f42 100644 (file)
@@ -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;
 }
index 7424827228fcc62ba697e4c0d52644c5c7e6398b..c174648cd366b79ff2d42595fdfd28bfe1a560b8 100644 (file)
@@ -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)
        {
index 337d7d766402d1b12d28a02faa5faac33981fb5d..a6602b51db04fcf527cf352de3a8a08b8faa647d 100644 (file)
@@ -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,
index 4d33e2210772753f10ebacd98e4e9d6ca4f9873b..d01b4c25b2585355b5547322b76a32b6970c4499 100644 (file)
@@ -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);
        }
     }