stage4/stage4.cc
changeset 546 8cc4c51c4bfc
parent 522 f9cff11ae622
child 580 b6350d9f204d
equal deleted inserted replaced
545:5440b65c96e9 546:8cc4c51c4bfc
    44 #include <iostream>
    44 #include <iostream>
    45 #include <fstream>
    45 #include <fstream>
    46 #include <stdlib.h>
    46 #include <stdlib.h>
    47 
    47 
    48 #include "stage4.hh"
    48 #include "stage4.hh"
       
    49 
       
    50 
       
    51 #define ERROR error_exit(__FILE__,__LINE__)
       
    52 /* function defined in main.cc */
       
    53 extern void error_exit(const char *file_name, int line_no);
    49 
    54 
    50 
    55 
    51 #define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
    56 #define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
    52 #define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
    57 #define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
    53 #include <stdarg.h>
    58 #include <stdarg.h>
    71 stage4out_c::stage4out_c(std::string indent_level):
    76 stage4out_c::stage4out_c(std::string indent_level):
    72 	m_file(NULL) {
    77 	m_file(NULL) {
    73   out = &std::cout;
    78   out = &std::cout;
    74   this->indent_level = indent_level;
    79   this->indent_level = indent_level;
    75   this->indent_spaces = "";
    80   this->indent_spaces = "";
       
    81   allow_output = true;
    76 }
    82 }
    77 
    83 
    78 stage4out_c::stage4out_c(const char *dir, const char *radix, const char *extension, std::string indent_level) {	
    84 stage4out_c::stage4out_c(const char *dir, const char *radix, const char *extension, std::string indent_level) {	
    79   std::string filename(radix);
    85   std::string filename(radix);
    80   filename += ".";
    86   filename += ".";
   241 
   247 
   242 int stage4(symbol_c *tree_root, const char *builddir) {
   248 int stage4(symbol_c *tree_root, const char *builddir) {
   243   stage4out_c s4o;
   249   stage4out_c s4o;
   244   visitor_c *generate_code = new_code_generator(&s4o, builddir);
   250   visitor_c *generate_code = new_code_generator(&s4o, builddir);
   245 
   251 
   246   if (NULL == generate_code)
   252   if (NULL == generate_code) ERROR;
   247     return -1;
       
   248 
   253 
   249   tree_root->accept(*generate_code);
   254   tree_root->accept(*generate_code);
   250 
   255 
   251   delete_code_generator(generate_code);
   256   delete_code_generator(generate_code);
   252 
   257