Changes in / [bfbf97f:a8541d9]


Ignore:
Location:
src
Files:
404 added
121 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rbfbf97f ra8541d9  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jun 04 15:00:00 2015
    13 // Update Count     : 125
     12// Last Modified On : Thu Jun 11 13:22:39 2015
     13// Update Count     : 137
    1414//
    1515
     
    4343        }
    4444
    45         CodeGenerator::CodeGenerator( std::ostream &os ) : cur_indent( 0 ), insideFunction( false ), output( os ) { }
    46 
    47         CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indent, bool infunp )
    48                         : cur_indent( indent ), insideFunction( infunp ), output( os ) {
     45        ostream & CodeGenerator::Indenter::operator()( ostream & output ) {
     46          return output << string( cg.cur_indent, ' ' );
     47        }
     48
     49        ostream & operator<<( ostream & output, CodeGenerator::Indenter &indent ) {
     50                return indent( output );
     51        }
     52
     53        CodeGenerator::CodeGenerator( std::ostream &os ) : indent(*this), cur_indent( 0 ), insideFunction( false ), output( os ) { }
     54
     55        CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp )
     56                        : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
    4957                //output << std::string( init );
    5058        }
    5159
    52         CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indent, bool infunp )
    53                         : cur_indent( indent ), insideFunction( infunp ), output( os ) {
     60        CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp )
     61                        : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
    5462                //output << std::string( init );
    5563        }
     
    6270                } // if
    6371        }
    64   
     72 
    6573        //*** Declarations
    6674        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
     
    104112
    105113                if ( ! memb.empty() ) {
    106                         output << endl << string( cur_indent, ' ' ) << "{" << endl;
     114                        output << endl << indent << "{" << endl;
    107115
    108116                        cur_indent += CodeGenerator::tabsize;
    109117                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    110                                 output << string( cur_indent, ' ' );
     118                                output << indent;
    111119                                (*i)->accept(*this );
    112120                                output << ";" << endl;
     
    115123                        cur_indent -= CodeGenerator::tabsize;
    116124
    117                         output << string( cur_indent, ' ' ) << "}";
     125                        output << indent << "}";
    118126                } // if
    119127        }
     
    138146
    139147                if ( ! memb.empty() ) {
    140                         output << endl << "{" << endl;
     148                        output << " {" << endl;
    141149
    142150                        cur_indent += CodeGenerator::tabsize;
     
    144152                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    145153                                assert( obj );
    146                                 output << string( cur_indent, ' ' ) << mangleName( obj );
     154                                output << indent << mangleName( obj );
    147155                                if ( obj->get_init() ) {
    148156                                        output << " = ";
     
    154162                        cur_indent -= CodeGenerator::tabsize;
    155163
    156                         output << "}" << endl;
     164                        output << indent << "}";
    157165                } // if
    158166        }
     
    444452
    445453                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
    446                         output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() );
     454                        output << indent << printLabels( (*i)->get_labels() );
    447455                        (*i)->accept(*this );
    448456
     
    454462                cur_indent -= CodeGenerator::tabsize;
    455463
    456                 output << string( cur_indent, ' ' ) << "}";
     464                output << indent << "}";
    457465        }
    458466
     
    494502                cur_indent -= CodeGenerator::tabsize;
    495503
    496                 output << string( cur_indent, ' ' ) << "}";
     504                output << indent << "}";
    497505        }
    498506
    499507        void CodeGenerator::visit( CaseStmt *caseStmt ) {
    500                 output << string( cur_indent, ' ' );
     508                output << indent;
    501509                if ( caseStmt->isDefault()) {
    502510                        output << "default";
     
    511519                cur_indent += CodeGenerator::tabsize;
    512520                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    513                         output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
     521                        output << indent << printLabels( (*i)->get_labels() )  ;
    514522                        (*i)->accept(*this );
    515523                        output << endl;
     
    564572                whileStmt->get_body()->accept( *this );
    565573
    566                 output << string( cur_indent, ' ' );
     574                output << indent;
    567575
    568576                if ( whileStmt->get_isDoWhile() ) {
     
    596604
    597605        void CodeGenerator::visit( NullStmt *nullStmt ) {
    598                 //output << string( cur_indent, ' ' ) << CodeGenerator::printLabels( nullStmt->get_labels() );
     606                //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() );
    599607                output << "/* null statement */ ;";
    600608        }
  • src/CodeGen/CodeGenerator.h

    rbfbf97f ra8541d9  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun  8 14:34:43 2015
    13 // Update Count     : 15
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Thu Jun 11 13:24:23 2015
     13// Update Count     : 23
    1414//
    1515
     
    8080
    8181                template< class Iterator > void genCommaList( Iterator begin, Iterator end );
     82
     83                struct Indenter {
     84                        Indenter(CodeGenerator &cg) : cg(cg) {}
     85                        CodeGenerator & cg;
     86                        std::ostream& operator()(std::ostream & os);
     87                };
    8288          private:
     89
     90                Indenter indent;
    8391                int cur_indent;
    8492                bool insideFunction;
  • src/Parser/parser.cc

    rbfbf97f ra8541d9  
    92729272            std::cout << "in file " << yyfilename << " ";
    92739273        } // if
    9274 //      std::cout << "at line " << yylineno << " reading token \"" << *(yylval.tok.str) << "\"" << std::endl;
    9275         std::cout << "at line " << yylineno << " reading token \"" << yytext << "\"" << std::endl;
     9274        std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl;
    92769275}
    92779276
  • src/Parser/parser.yy

    rbfbf97f ra8541d9  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 10 14:22:15 2015
    13 // Update Count     : 1039
     12// Last Modified On : Wed Jun 10 20:31:54 2015
     13// Update Count     : 1040
    1414//
    1515
     
    27232723            std::cout << "in file " << yyfilename << " ";
    27242724        } // if
    2725         std::cout << "at line " << yylineno << " reading token \"" << yytext << "\"" << std::endl;
     2725        std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl;
    27262726}
    27272727
  • src/main.cc

    rbfbf97f ra8541d9  
    99// Author           : Richard C. Bilson
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jun 09 15:10:05 2015
    13 // Update Count     : 68
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jun 11 11:06:04 2015
     13// Update Count     : 69
    1414//
    1515
     
    7171        errorp = false;
    7272
    73 enum { Ast, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Prototypes, Resolver, Symbol, Parse, };
     73enum { Ast, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Validate, };
    7474
    7575static struct option long_opts[] = {
     
    8080        { "libcfa", no_argument, 0, LibCFA },
    8181        { "nopreamble", no_argument, 0, Nopreamble },
     82        { "parse", no_argument, 0, Parse },
    8283        { "prototypes", no_argument, 0, Prototypes },
    8384        { "resolver", no_argument, 0, Resolver },
    8485        { "symbol", no_argument, 0, Symbol },
    85         { "parse", no_argument, 0, Parse },
     86        { "validate", no_argument, 0, Validate },
    8687        { 0, 0, 0, 0 }
    8788};
     
    9697       
    9798        int c;
    98         while ( (c = getopt_long( argc, argv, "aefglnpqrsxyzD:", long_opts, &long_index )) != -1 ) {
     99        while ( (c = getopt_long( argc, argv, "aefglnpqrsvyzD:", long_opts, &long_index )) != -1 ) {
    99100                switch ( c ) {
    100101                  case Ast:
     
    138139                        symtabp = true;
    139140                        break;
    140                   case 'x':                                                                             // dump AST after decl validation pass
     141                  case 'v':                                                                             // dump AST after decl validation pass
    141142                        validp = true;
    142143                        break;
Note: See TracChangeset for help on using the changeset viewer.