#include "treelang.h"
#include "treetree.h"
+#include "opts.h"
+#include "options.h"
+#include "c-common.h"
+
+enum c_language_kind c_language = clk_c;
extern int yyparse (void);
/* Local variables. */
-unsigned char *in_fname = NULL; /* Input file name. */
-
/* This is 1 if we have output the version string. */
static int version_done = 0;
static unsigned int work_nesting_level = 0;
-/* Process one switch - called by toplev.c. */
+/* Prepare to handle switches. */
+int
+treelang_init_options (void)
+{
+ return CL_Treelang;
+}
+/* Process a switch - called by opts.c. */
int
-treelang_decode_option (num_options_left, first_option_left)
- int num_options_left ATTRIBUTE_UNUSED;
- char** first_option_left;
+treelang_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED,
+ int value)
{
-
- /*
- Process options - bear in mind I may get options that are really
- meant for someone else (eg the main compiler) so I have to be very
- permissive.
-
- */
-
- if (first_option_left[0][0] != '-')
- return 0;
-
- switch (first_option_left[0][1])
+ enum opt_code code = (enum opt_code) scode;
+
+ switch (code)
{
- case '-':
- if (!strcmp (first_option_left[0],"--help"))
- {
- if (!version_done)
- {
- fputs (language_string, stdout);
- fputs (version_string, stdout);
- fputs ("\n", stdout);
- version_done = 1;
- }
- fprintf (stdout, "Usage: tree1 [switches] -o output input\n");
- return 1;
- }
- case 'v':
- if (!strcmp (first_option_left[0],"-v"))
- {
- if (!version_done)
- {
- fputs (language_string, stdout);
- fputs (version_string, stdout);
- fputs ("\n", stdout);
- version_done = 1;
- }
- return 1;
- }
- case 'y':
- if (!strcmp (first_option_left[0],"-y"))
- {
- option_lexer_trace = 1;
- option_parser_trace = 1;
- return 1;
- }
- case 'f':
- if (!strcmp (first_option_left[0],"-fparser-trace"))
- {
- option_parser_trace = 1;
- return 1;
- }
- if (!strcmp (first_option_left[0],"-flexer-trace"))
- {
- option_lexer_trace = 1;
- return 1;
- }
- return 0;
+ default:
+ abort();
- case 'w':
- if (!strcmp (first_option_left[0],"-w"))
- {
- /* Tolerate this option but ignore it - we always put out
- all warnings. */
- return 1;
- }
- return 0;
+ case OPT__help:
+ if (!version_done)
+ {
+ fputs (language_string, stdout);
+ fputs (version_string, stdout);
+ fputs ("\n", stdout);
+ version_done = 1;
+ }
+ fprintf (stdout, "Usage: tree1 [switches] -o output input\n");
+ break;
- case 'W':
- if (!strcmp (first_option_left[0],"-Wall"))
- {
- return 1;
- }
- return 0;
+ case OPT_v:
+ if (!version_done)
+ {
+ fputs (language_string, stdout);
+ fputs (version_string, stdout);
+ fputs ("\n", stdout);
+ version_done = 1;
+ }
+ break;
- default:
- return 0;
- }
+ case OPT_y:
+ option_lexer_trace = 1;
+ option_parser_trace = 1;
+ break;
- return 0;
+ case OPT_fparser_trace:
+ option_parser_trace = value;
+ break;
+ case OPT_flexer_trace:
+ option_lexer_trace = value;
+ break;
+ }
+
+ return 1;
}
/* Language dependent parser setup. */
-const char*
-treelang_init (const char* filename)
+bool
+treelang_init ()
{
- /* Set up the declarations needed for this front end. */
-
- input_filename = "";
- lineno = 0;
+ input_filename = main_input_filename;
+ input_line = 0;
/* Init decls etc. */
/* This error will not happen from GCC as it will always create a
fake input file. */
- if (!filename || (filename[0] == ' ') || (!filename[0]))
+ if (!input_filename || input_filename[0] == ' ' || !input_filename[0])
{
if (!version_done)
{
exit (1);
}
- in_fname = NULL;
- return NULL;
+ return false;
}
- yyin = fopen (filename, "r");
+
+ yyin = fopen (input_filename, "r");
if (!yyin)
{
- fprintf (stderr, "Unable to open input file %s\n", filename);
+ fprintf (stderr, "Unable to open input file %s\n", input_filename);
exit (1);
}
- input_filename = filename;
- return (char*) (in_fname = (unsigned char*)filename);
+
+ return true;
}
/* Language dependent wrapup. */
if (memcmp (tok->tp.tok.chars, this_tok->tp.tok.chars, this_tok->tp.tok.length))
continue;
if (option_parser_trace)
- fprintf (stderr, "Found symbol %s (%i:%i) as %i \n", tok->tp.tok.chars,
- tok->tp.tok.lineno, tok->tp.tok.charno, NUMERIC_TYPE (this));
+ fprintf (stderr, "Found symbol %s (%i:%i) as %i \n",
+ tok->tp.tok.chars,
+ tok->tp.tok.location.line, tok->tp.tok.charno,
+ NUMERIC_TYPE (this));
return this;
}
if (option_parser_trace)
- fprintf (stderr, "Not found symbol %s (%i:%i) as %i \n", tok->tp.tok.chars,
- tok->tp.tok.lineno, tok->tp.tok.charno, tok->type);
+ fprintf (stderr, "Not found symbol %s (%i:%i) as %i \n",
+ tok->tp.tok.chars,
+ tok->tp.tok.location.line, tok->tp.tok.charno, tok->type);
return NULL;
}
sanity_check (prod);
if (lookup_tree_name (prod))
{
- fprintf (stderr, "%s:%i:%i duplicate name %s\n", in_fname, tok->tp.tok.lineno,
+ fprintf (stderr, "%s:%i:%i duplicate name %s\n",
+ tok->tp.tok.location.file, tok->tp.tok.location.line,
tok->tp.tok.charno, tok->tp.tok.chars);
errorcount++;
return 1;