Changeset 71f4e4f for src/CodeGen


Ignore:
Timestamp:
Jan 13, 2016, 5:19:47 PM (10 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
f1e012b
Parents:
02c7d04
Message:

added ConstructorInit, simple constructors and destructors work correctly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r02c7d04 r71f4e4f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // CodeGenerator.cc -- 
     7// CodeGenerator.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Sep 17 15:25:58 2015
    13 // Update Count     : 233
     12// Last Modified On : Wed Jan 13 16:26:59 2016
     13// Update Count     : 234
    1414//
    1515
     
    9898                handleStorageClass( objectDecl );
    9999                output << genType( objectDecl->get_type(), mangleName( objectDecl ) );
    100        
     100
    101101                if ( objectDecl->get_init() ) {
    102102                        output << " = ";
     
    112112                if ( aggDecl->get_name() != "" )
    113113                        output << aggDecl->get_name();
    114        
     114
    115115                std::list< Declaration * > &memb = aggDecl->get_members();
    116116
     
    118118                        output << " {" << endl;
    119119
    120                         cur_indent += CodeGenerator::tabsize; 
     120                        cur_indent += CodeGenerator::tabsize;
    121121                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    122                                 output << indent; 
     122                                output << indent;
    123123                                (*i)->accept( *this );
    124124                                output << ";" << endl;
    125125                        }
    126126
    127                         cur_indent -= CodeGenerator::tabsize; 
     127                        cur_indent -= CodeGenerator::tabsize;
    128128
    129129                        output << indent << "}";
     
    140140                handleAggregate( aggregateDecl );
    141141        }
    142  
     142
    143143        void CodeGenerator::visit( EnumDecl *aggDecl ) {
    144144                output << "enum ";
     
    146146                if ( aggDecl->get_name() != "" )
    147147                        output << aggDecl->get_name();
    148        
     148
    149149                std::list< Declaration* > &memb = aggDecl->get_members();
    150150
     
    152152                        output << " {" << endl;
    153153
    154                         cur_indent += CodeGenerator::tabsize; 
     154                        cur_indent += CodeGenerator::tabsize;
    155155                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    156156                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    157157                                assert( obj );
    158                                 output << indent << mangleName( obj ); 
     158                                output << indent << mangleName( obj );
    159159                                if ( obj->get_init() ) {
    160160                                        output << " = ";
     
    164164                        } // for
    165165
    166                         cur_indent -= CodeGenerator::tabsize; 
     166                        cur_indent -= CodeGenerator::tabsize;
    167167
    168168                        output << indent << "}";
    169169                } // if
    170170        }
    171  
     171
    172172        void CodeGenerator::visit( ContextDecl *aggregateDecl ) {}
    173  
     173
    174174        void CodeGenerator::visit( TypedefDecl *typeDecl ) {
    175175                output << "typedef ";
    176176                output << genType( typeDecl->get_base(), typeDecl->get_name() );
    177177        }
    178  
     178
    179179        void CodeGenerator::visit( TypeDecl *typeDecl ) {
    180180                // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
     
    216216        }
    217217
    218         void CodeGenerator::visit( Constant *constant ) { 
     218        void CodeGenerator::visit( Constant *constant ) {
    219219                output << constant->get_value() ;
    220220        }
     
    233233                                                assert( arg != applicationExpr->get_args().end() );
    234234                                                if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    235                
     235
    236236                                                        *arg = addrExpr->get_arg();
    237237                                                } else {
     
    242242                                                break;
    243243                                        }
    244              
     244
    245245                                  default:
    246246                                        // do nothing
    247247                                        ;
    248248                                }
    249            
     249
    250250                                switch ( opInfo.type ) {
    251251                                  case OT_INDEX:
     
    256256                                        output << "]";
    257257                                        break;
    258              
     258
    259259                                  case OT_CALL:
    260260                                  case OT_CTOR:
     
    263263                                        assert( false );
    264264                                        break;
    265              
     265
    266266                                  case OT_PREFIX:
    267267                                  case OT_PREFIXASSIGN:
     
    272272                                        output << ")";
    273273                                        break;
    274              
     274
    275275                                  case OT_POSTFIX:
    276276                                  case OT_POSTFIXASSIGN:
     
    289289                                        output << ")";
    290290                                        break;
    291              
     291
    292292                                  case OT_CONSTANT:
    293293                                  case OT_LABELADDRESS:
     
    308308                } // if
    309309        }
    310  
     310
    311311        void CodeGenerator::visit( UntypedExpr *untypedExpr ) {
    312312                if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
     
    322322                                        output << "]";
    323323                                        break;
    324              
     324
    325325                                  case OT_CALL:
    326326                                        case OT_CTOR:
     
    328328                                        assert( false );
    329329                                        break;
    330              
     330
    331331                                  case OT_PREFIX:
    332332                                  case OT_PREFIXASSIGN:
     
    338338                                        output << ")";
    339339                                        break;
    340              
     340
    341341                                  case OT_POSTFIX:
    342342                                  case OT_POSTFIXASSIGN:
     
    345345                                        output << opInfo.symbol;
    346346                                        break;
    347  
     347
    348348                                  case OT_INFIX:
    349349                                  case OT_INFIXASSIGN:
     
    355355                                        output << ")";
    356356                                        break;
    357                                        
     357
    358358                                  case OT_CONSTANT:
    359359                                        // there are no intrinsic definitions of 0 or 1 as functions
     
    373373                } // if
    374374        }
    375  
     375
    376376        void CodeGenerator::visit( NameExpr *nameExpr ) {
    377377                OperatorInfo opInfo;
     
    383383                } // if
    384384        }
    385  
     385
    386386        void CodeGenerator::visit( AddressExpr *addressExpr ) {
    387387                output << "(&";
     
    410410                        output << ")";
    411411                        castExpr->get_arg()->accept( *this );
    412                         output << ")";                 
     412                        output << ")";
    413413                }
    414414        }
    415  
     415
    416416        void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) {
    417417                assert( false );
    418418        }
    419  
     419
    420420        void CodeGenerator::visit( MemberExpr *memberExpr ) {
    421421                memberExpr->get_aggregate()->accept( *this );
    422422                output << "." << mangleName( memberExpr->get_member() );
    423423        }
    424  
     424
    425425        void CodeGenerator::visit( VariableExpr *variableExpr ) {
    426426                OperatorInfo opInfo;
     
    431431                } // if
    432432        }
    433  
     433
    434434        void CodeGenerator::visit( ConstantExpr *constantExpr ) {
    435435                assert( constantExpr->get_constant() );
    436436                constantExpr->get_constant()->accept( *this );
    437437        }
    438  
     438
    439439        void CodeGenerator::visit( SizeofExpr *sizeofExpr ) {
    440440                output << "sizeof(";
     
    457457                output << ")";
    458458        }
    459  
     459
    460460        void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
    461461                output << "(";
     
    469469                output << ")";
    470470        }
    471  
     471
    472472        void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) {
    473473                output << "(";
     
    479479                output << ")";
    480480        }
    481  
     481
    482482        void CodeGenerator::visit( CommaExpr *commaExpr ) {
    483483                output << "(";
     
    487487                output << ")";
    488488        }
    489  
     489
    490490        void CodeGenerator::visit( TupleExpr *tupleExpr ) {}
    491  
     491
    492492        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    493493
     
    520520                        }
    521521                }
    522                 cur_indent -= CodeGenerator::tabsize; 
     522                cur_indent -= CodeGenerator::tabsize;
    523523
    524524                output << indent << "}";
     
    526526
    527527        void CodeGenerator::visit( ExprStmt *exprStmt ) {
    528                 // I don't see why this check is necessary. 
    529                 // If this starts to cause problems then put it back in, 
     528                // I don't see why this check is necessary.
     529                // If this starts to cause problems then put it back in,
    530530                // with an explanation
    531531                assert( exprStmt );
     
    577577                switchStmt->get_condition()->accept( *this );
    578578                output << " ) ";
    579                
     579
    580580                output << "{" << std::endl;
    581581                cur_indent += CodeGenerator::tabsize;
     
    597597                } // if
    598598                output << ":\n";
    599                
     599
    600600                std::list<Statement *> sts = caseStmt->get_statements();
    601601
     
    614614                        if ( ! branchStmt->get_target().empty() )
    615615                                output << "goto " << branchStmt->get_target();
    616                         else { 
     616                        else {
    617617                                if ( branchStmt->get_computedTarget() != 0 ) {
    618618                                        output << "goto *";
     
    665665
    666666        void CodeGenerator::visit( ForStmt *forStmt ) {
    667                 // initialization is always hoisted, so don't 
    668                 // bother doing anything with that 
     667                // initialization is always hoisted, so don't
     668                // bother doing anything with that
    669669                output << "for (;";
    670670
     
    690690        void CodeGenerator::visit( DeclStmt *declStmt ) {
    691691                declStmt->get_decl()->accept( *this );
    692        
     692
    693693                if ( doSemicolon( declStmt->get_decl() ) ) {
    694694                        output << ";";
Note: See TracChangeset for help on using the changeset viewer.