Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rf7cb0bc rbf2438c  
    1414//
    1515
    16 #include <algorithm>
    17 #include <iostream>
    18 #include <cassert>
    19 #include <list>
    20 
    21 #include "Parser/ParseNode.h"
    22 
    23 #include "SynTree/Declaration.h"
    24 #include "SynTree/Expression.h"
    25 #include "SynTree/Initializer.h"
    26 #include "SynTree/Statement.h"
    27 #include "SynTree/Type.h"
    28 #include "SynTree/Attribute.h"
    29 
    30 #include "Common/utility.h"
    31 #include "Common/UnimplementedError.h"
     16#include <cassert>                   // for assert, assertf
     17#include <list>                      // for _List_iterator, list, list<>::it...
    3218
    3319#include "CodeGenerator.h"
    34 #include "OperatorTable.h"
    35 #include "GenType.h"
    36 
    37 #include "InitTweak/InitTweak.h"
     20#include "Common/SemanticError.h"    // for SemanticError
     21#include "Common/UniqueName.h"       // for UniqueName
     22#include "Common/utility.h"          // for CodeLocation, toString
     23#include "GenType.h"                 // for genType
     24#include "InitTweak/InitTweak.h"     // for getPointerBase
     25#include "OperatorTable.h"           // for OperatorInfo, operatorLookup
     26#include "Parser/LinkageSpec.h"      // for Spec, Intrinsic
     27#include "SynTree/Attribute.h"       // for Attribute
     28#include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
     29#include "SynTree/Constant.h"        // for Constant
     30#include "SynTree/Declaration.h"     // for DeclarationWithType, TypeDecl
     31#include "SynTree/Expression.h"      // for Expression, UntypedExpr, Applica...
     32#include "SynTree/Initializer.h"     // for Initializer, ListInit, Designation
     33#include "SynTree/Label.h"           // for Label, operator<<
     34#include "SynTree/Statement.h"       // for Statement, AsmStmt, BranchStmt
     35#include "SynTree/Type.h"            // for Type, Type::StorageClasses, Func...
    3836
    3937using namespace std;
     
    6563                } // if
    6664        } // extension
     65
     66        ostream & CodeGenerator::Indenter::operator()( ostream & output ) const {
     67          return output << string( cg.cur_indent, ' ' );
     68        }
     69
     70        ostream & operator<<( ostream & output, const CodeGenerator::Indenter &indent ) {
     71                return indent( output );
     72        }
    6773
    6874        CodeGenerator::LabelPrinter & CodeGenerator::LabelPrinter::operator()( std::list< Label > & l ) {
     
    103109        }
    104110
    105         CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( CodeGenerator::tabsize ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {}
     111        CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {}
    106112
    107113        string CodeGenerator::mangleName( DeclarationWithType * decl ) {
     
    194200                        output << " {" << endl;
    195201
    196                         ++indent;
     202                        cur_indent += CodeGenerator::tabsize;
    197203                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    198204                                output << lineDirective( *i ) << indent;
     
    201207                        } // for
    202208
    203                         --indent;
     209                        cur_indent -= CodeGenerator::tabsize;
    204210
    205211                        output << indent << "}";
     
    231237                        output << " {" << endl;
    232238
    233                         ++indent;
     239                        cur_indent += CodeGenerator::tabsize;
    234240                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    235241                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
     
    243249                        } // for
    244250
    245                         --indent;
     251                        cur_indent -= CodeGenerator::tabsize;
    246252
    247253                        output << indent << "}";
     
    747753                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    748754                output << lineDirective( stmtExpr) << "({" << std::endl;
    749                 ++indent;
     755                cur_indent += CodeGenerator::tabsize;
    750756                unsigned int numStmts = stmts.size();
    751757                unsigned int i = 0;
     
    770776                        ++i;
    771777                }
    772                 --indent;
     778                cur_indent -= CodeGenerator::tabsize;
    773779                output << indent << "})";
    774780        }
     
    779785                output << "{" << endl;
    780786
    781                 ++indent;
     787                cur_indent += CodeGenerator::tabsize;
    782788
    783789                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++ ) {
     
    790796                        } // if
    791797                } // for
    792                 --indent;
     798                cur_indent -= CodeGenerator::tabsize;
    793799
    794800                output << indent << "}";
     
    858864
    859865                output << "{" << std::endl;
    860                 ++indent;
     866                cur_indent += CodeGenerator::tabsize;
    861867                acceptAll( switchStmt->get_statements(), *this );
    862                 --indent;
     868                cur_indent -= CodeGenerator::tabsize;
    863869                output << indent << "}";
    864870        }
     
    877883                std::list<Statement *> sts = caseStmt->get_statements();
    878884
    879                 ++indent;
     885                cur_indent += CodeGenerator::tabsize;
    880886                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    881887                        output << indent << printLabels( (*i)->get_labels() )  ;
     
    883889                        output << endl;
    884890                } // for
    885                 --indent;
     891                cur_indent -= CodeGenerator::tabsize;
    886892        }
    887893
Note: See TracChangeset for help on using the changeset viewer.