Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rbf2438c rf7cb0bc  
    1414//
    1515
    16 #include <cassert>                   // for assert, assertf
    17 #include <list>                      // for _List_iterator, list, list<>::it...
     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"
    1832
    1933#include "CodeGenerator.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...
     34#include "OperatorTable.h"
     35#include "GenType.h"
     36
     37#include "InitTweak/InitTweak.h"
    3638
    3739using namespace std;
     
    6365                } // if
    6466        } // 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         }
    7367
    7468        CodeGenerator::LabelPrinter & CodeGenerator::LabelPrinter::operator()( std::list< Label > & l ) {
     
    109103        }
    110104
    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 ) {}
     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 ) {}
    112106
    113107        string CodeGenerator::mangleName( DeclarationWithType * decl ) {
     
    200194                        output << " {" << endl;
    201195
    202                         cur_indent += CodeGenerator::tabsize;
     196                        ++indent;
    203197                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    204198                                output << lineDirective( *i ) << indent;
     
    207201                        } // for
    208202
    209                         cur_indent -= CodeGenerator::tabsize;
     203                        --indent;
    210204
    211205                        output << indent << "}";
     
    237231                        output << " {" << endl;
    238232
    239                         cur_indent += CodeGenerator::tabsize;
     233                        ++indent;
    240234                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    241235                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
     
    249243                        } // for
    250244
    251                         cur_indent -= CodeGenerator::tabsize;
     245                        --indent;
    252246
    253247                        output << indent << "}";
     
    753747                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    754748                output << lineDirective( stmtExpr) << "({" << std::endl;
    755                 cur_indent += CodeGenerator::tabsize;
     749                ++indent;
    756750                unsigned int numStmts = stmts.size();
    757751                unsigned int i = 0;
     
    776770                        ++i;
    777771                }
    778                 cur_indent -= CodeGenerator::tabsize;
     772                --indent;
    779773                output << indent << "})";
    780774        }
     
    785779                output << "{" << endl;
    786780
    787                 cur_indent += CodeGenerator::tabsize;
     781                ++indent;
    788782
    789783                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++ ) {
     
    796790                        } // if
    797791                } // for
    798                 cur_indent -= CodeGenerator::tabsize;
     792                --indent;
    799793
    800794                output << indent << "}";
     
    864858
    865859                output << "{" << std::endl;
    866                 cur_indent += CodeGenerator::tabsize;
     860                ++indent;
    867861                acceptAll( switchStmt->get_statements(), *this );
    868                 cur_indent -= CodeGenerator::tabsize;
     862                --indent;
    869863                output << indent << "}";
    870864        }
     
    883877                std::list<Statement *> sts = caseStmt->get_statements();
    884878
    885                 cur_indent += CodeGenerator::tabsize;
     879                ++indent;
    886880                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    887881                        output << indent << printLabels( (*i)->get_labels() )  ;
     
    889883                        output << endl;
    890884                } // for
    891                 cur_indent -= CodeGenerator::tabsize;
     885                --indent;
    892886        }
    893887
Note: See TracChangeset for help on using the changeset viewer.