* doc/sdccman.lyx: documented #pragma sdcc_hash
[fw/sdcc] / support / cpp2 / sdcpp.c
index def45e24128752e965771d27a898558fd9d262b9..76931cf94fcdc9dcdc377bafd6acf240b5b6e071 100644 (file)
@@ -25,7 +25,7 @@
 #include "config.h"
 #include "system.h"
 #include "cpplib.h"
-#include "cpphash.h"
+#include "internal.h"
 #include "version.h"
 #include "mkdeps.h"
 #include "opts.h"
@@ -53,7 +53,7 @@ const char *progname;         /* Needs to be global.  */
 }
 
 /* From c-lang.c */
-#define LANG_HOOKS_INIT_OPTIONS sdcpp_common_init_options
+#define LANG_HOOKS_INIT_OPTIONS sdcpp_init_options
 #define LANG_HOOKS_INITIALIZE_DIAGNOSTICS sdcpp_initialize_diagnostics
 #define LANG_HOOKS_HANDLE_OPTION sdcpp_common_handle_option
 #define LANG_HOOKS_MISSING_ARGUMENT sdcpp_common_missing_argument
@@ -62,6 +62,7 @@ const char *progname;         /* Needs to be global.  */
 #define LANG_HOOKS_FINISH sdcpp_common_finish
 #define LANG_HOOKS_PRINT_ERROR_FUNCTION sdcpp_print_error_function
 
+static unsigned int sdcpp_init_options (unsigned int argc, const char **argv);
 static void sdcpp_initialize_diagnostics (diagnostic_context *context);
 static void sdcpp_print_error_function (diagnostic_context *context, const char *file);
 
@@ -74,10 +75,16 @@ const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
 
 const char *main_input_filename;
 
+#ifndef USE_MAPPED_LOCATION
+location_t unknown_location = { NULL, 0 };
+#endif
+
 /* Current position in real source file.  */
 
 location_t input_location;
 
+struct line_maps line_table;
+
 /* Stack of currently pending input files.  */
 
 struct file_stack *input_file_stack;
@@ -137,6 +144,14 @@ static const char *src_pwd;
    be called with a NULL argument to test whether src_pwd has NOT been
    initialized yet.  */
 
+/* From intl.c */
+/* Opening quotation mark for diagnostics.  */
+const char *open_quote = "'";
+
+/* Closing quotation mark for diagnostics.  */
+const char *close_quote = "'";
+/* ----------- */
+
 bool
 set_src_pwd (const char *pwd)
 {
@@ -160,6 +175,97 @@ get_src_pwd (void)
    return src_pwd;
 }
 
+/* SDCPP specific pragmas */
+/* SDCC specific
+   sdcc_hash pragma */
+static void
+do_pragma_sdcc_hash (cpp_reader *pfile)
+{
+    const cpp_token *tok = _cpp_lex_token (pfile);
+
+    if (tok->type == CPP_PLUS)
+    {
+       CPP_OPTION(pfile, allow_naked_hash)++;
+    }
+    else if (tok->type == CPP_MINUS)
+    {
+       CPP_OPTION(pfile, allow_naked_hash)--;
+    }
+    else
+    {
+       cpp_error (pfile, CPP_DL_ERROR,
+                  "invalid #pragma sdcc_hash directive, need '+' or '-'");
+    }
+}
+
+/* SDCC specific
+   pedantic_parse_number pragma */
+static void
+do_pragma_pedantic_parse_number (cpp_reader *pfile)
+{
+    const cpp_token *tok = _cpp_lex_token (pfile);
+
+  if (tok->type == CPP_PLUS)
+    {
+      CPP_OPTION(pfile, pedantic_parse_number)++;
+    }
+  else if (tok->type == CPP_MINUS)
+    {
+      CPP_OPTION(pfile, pedantic_parse_number)--;
+    }
+  else
+    {
+      cpp_error (pfile, CPP_DL_ERROR,
+                 "invalid #pragma pedantic_parse_number directive, need '+' or '-'");
+    }
+}
+
+/* SDCC _asm specific
+   switch _asm block preprocessing on / off */
+static void
+do_pragma_preproc_asm (cpp_reader *pfile)
+{
+  const cpp_token *tok = _cpp_lex_token (pfile);
+
+  if (tok->type == CPP_PLUS)
+    {
+      CPP_OPTION(pfile, preproc_asm)++;
+    }
+  else if (tok->type == CPP_MINUS)
+    {
+      CPP_OPTION(pfile, preproc_asm)--;
+    }
+  else
+    {
+      cpp_error (pfile, CPP_DL_ERROR,
+                "invalid #pragma preproc_asm directive, need '+' or '-'");
+    }
+}
+
+/* SDCPP specific option initialization */
+static unsigned int
+sdcpp_init_options (unsigned int argc, const char **argv)
+{
+  unsigned int ret = sdcpp_common_init_options(argc, argv);
+
+  CPP_OPTION (parse_in, allow_naked_hash) = 0;
+  CPP_OPTION (parse_in, preproc_asm) = 1;
+  CPP_OPTION (parse_in, pedantic_parse_number) = 0;
+  CPP_OPTION (parse_in, obj_ext) = NULL;
+
+  /* Kevin abuse for SDCC. */
+  cpp_register_pragma(parse_in, 0, "sdcc_hash", do_pragma_sdcc_hash, false);
+  /* SDCC _asm specific */
+  cpp_register_pragma(parse_in, 0, "preproc_asm", do_pragma_preproc_asm, false);
+  /* SDCC specific */
+  cpp_register_pragma(parse_in, 0, "pedantic_parse_number", do_pragma_pedantic_parse_number, false);
+
+  /* SDCC _asm specific */
+  parse_in->spec_nodes.n__asm = cpp_lookup (parse_in, DSC("_asm"));
+
+  return ret;
+}
+
 static void
 sdcpp_initialize_diagnostics (diagnostic_context *context)
 {
@@ -292,7 +398,7 @@ decode_d_option (const char *arg)
        break;
 
       default:
-       warning ("unrecognized gcc debugging option: %c", c);
+       warning (0, "unrecognized gcc debugging option: %c", c);
        break;
       }
 }