Ignore:
Timestamp:
Nov 8, 2017, 5:43:33 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
954908d
Parents:
78315272 (diff), e35f30a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r78315272 r3f7e12cb  
    287287        void CodeGenerator::postvisit( TypeDecl * typeDecl ) {
    288288                assertf( ! genC, "TypeDecls should not reach code generation." );
    289                 output << typeDecl->genTypeString() << " " << typeDecl->get_name();
    290                 if ( typeDecl->get_kind() != TypeDecl::Any && typeDecl->get_sized() ) {
    291                         output << " | sized(" << typeDecl->get_name() << ")";
    292                 }
    293                 if ( ! typeDecl->get_assertions().empty() ) {
     289                output << typeDecl->genTypeString() << " " << typeDecl->name;
     290                if ( typeDecl->sized ) {
     291                        output << " | sized(" << typeDecl->name << ")";
     292                }
     293                if ( ! typeDecl->assertions.empty() ) {
    294294                        output << " | { ";
    295                         genCommaList( typeDecl->get_assertions().begin(), typeDecl->get_assertions().end() );
     295                        for ( DeclarationWithType * assert :  typeDecl->assertions ) {
     296                                assert->accept( *visitor );
     297                                output << "; ";
     298                        }
    296299                        output << " }";
    297300                }
     
    443446        void CodeGenerator::postvisit( UntypedExpr * untypedExpr ) {
    444447                extension( untypedExpr );
    445                 if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
     448                if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->function ) ) {
    446449                        OperatorInfo opInfo;
    447                         if ( operatorLookup( nameExpr->get_name(), opInfo ) ) {
    448                                 std::list< Expression* >::iterator arg = untypedExpr->get_args().begin();
     450                        if ( operatorLookup( nameExpr->name, opInfo ) ) {
     451                                std::list< Expression* >::iterator arg = untypedExpr->args.begin();
    449452                                switch ( opInfo.type ) {
    450453                                  case OT_INDEX:
    451                                         assert( untypedExpr->get_args().size() == 2 );
     454                                        assert( untypedExpr->args.size() == 2 );
    452455                                        (*arg++)->accept( *visitor );
    453456                                        output << "[";
     
    461464                                  case OT_CTOR:
    462465                                  case OT_DTOR:
    463                                         if ( untypedExpr->get_args().size() == 1 ) {
     466                                        if ( untypedExpr->args.size() == 1 ) {
    464467                                                // the expression fed into a single parameter constructor or destructor may contain side
    465468                                                // effects, so must still output this expression
     
    480483                                                (*arg++)->accept( *visitor );
    481484                                                output << opInfo.symbol << "{ ";
    482                                                 genCommaList( arg, untypedExpr->get_args().end() );
     485                                                genCommaList( arg, untypedExpr->args.end() );
    483486                                                output << "}) /* " << opInfo.inputName << " */";
    484487                                        } // if
     
    488491                                  case OT_PREFIXASSIGN:
    489492                                  case OT_LABELADDRESS:
    490                                         assert( untypedExpr->get_args().size() == 1 );
     493                                        assert( untypedExpr->args.size() == 1 );
    491494                                        output << "(";
    492495                                        output << opInfo.symbol;
     
    497500                                  case OT_POSTFIX:
    498501                                  case OT_POSTFIXASSIGN:
    499                                         assert( untypedExpr->get_args().size() == 1 );
     502                                        assert( untypedExpr->args.size() == 1 );
    500503                                        (*arg)->accept( *visitor );
    501504                                        output << opInfo.symbol;
     
    504507                                  case OT_INFIX:
    505508                                  case OT_INFIXASSIGN:
    506                                         assert( untypedExpr->get_args().size() == 2 );
     509                                        assert( untypedExpr->args.size() == 2 );
    507510                                        output << "(";
    508511                                        (*arg++)->accept( *visitor );
     
    517520                                } // switch
    518521                        } else {
    519                                 if ( nameExpr->get_name() == "..." ) { // case V1 ... V2 or case V1~V2
    520                                         assert( untypedExpr->get_args().size() == 2 );
    521                                         (*untypedExpr->get_args().begin())->accept( *visitor );
    522                                         output << " ... ";
    523                                         (*--untypedExpr->get_args().end())->accept( *visitor );
    524                                 } else {                                                                // builtin routines
    525                                         nameExpr->accept( *visitor );
    526                                         output << "(";
    527                                         genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
    528                                         output << ")";
    529                                 } // if
     522                                // builtin routines
     523                                nameExpr->accept( *visitor );
     524                                output << "(";
     525                                genCommaList( untypedExpr->args.begin(), untypedExpr->args.end() );
     526                                output << ")";
    530527                        } // if
    531528                } else {
    532                         untypedExpr->get_function()->accept( *visitor );
     529                        untypedExpr->function->accept( *visitor );
    533530                        output << "(";
    534                         genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
     531                        genCommaList( untypedExpr->args.begin(), untypedExpr->args.end() );
    535532                        output << ")";
    536533                } // if
     
    538535
    539536        void CodeGenerator::postvisit( RangeExpr * rangeExpr ) {
    540                 rangeExpr->get_low()->accept( *visitor );
     537                rangeExpr->low->accept( *visitor );
    541538                output << " ... ";
    542                 rangeExpr->get_high()->accept( *visitor );
     539                rangeExpr->high->accept( *visitor );
    543540        }
    544541
     
    546543                extension( nameExpr );
    547544                OperatorInfo opInfo;
    548                 if ( operatorLookup( nameExpr->get_name(), opInfo ) ) {
    549                         assert( opInfo.type == OT_CONSTANT );
    550                         output << opInfo.symbol;
     545                if ( operatorLookup( nameExpr->name, opInfo ) ) {
     546                        if ( opInfo.type == OT_CONSTANT ) {
     547                                output << opInfo.symbol;
     548                        } else {
     549                                output << opInfo.outputName;
     550                        }
    551551                } else {
    552552                        output << nameExpr->get_name();
     
    885885
    886886        void CodeGenerator::postvisit( CaseStmt * caseStmt ) {
     887                updateLocation( caseStmt );
     888                output << indent;
    887889                if ( caseStmt->isDefault()) {
    888890                        output << "default";
     
    947949                output << ";";
    948950        }
     951        void CodeGenerator::postvisit( CatchStmt * stmt ) {
     952                assertf( ! genC, "Catch statements should not reach code generation." );
     953
     954                output << ((stmt->get_kind() == CatchStmt::Terminate) ?
     955                "catch" : "catchResume");
     956                output << "( ";
     957                stmt->decl->accept( *visitor );
     958                output << " ) ";
     959
     960                if( stmt->cond ) {
     961                        output << "if/when(?) (";
     962                        stmt->cond->accept( *visitor );
     963                        output << ") ";
     964                }
     965                stmt->body->accept( *visitor );
     966        }
     967
     968        void CodeGenerator::postvisit( WaitForStmt * stmt ) {
     969                assertf( ! genC, "Waitfor statements should not reach code generation." );
     970
     971                bool first = true;
     972                for( auto & clause : stmt->clauses ) {
     973                        if(first) { output << "or "; first = false; }
     974                        if( clause.condition ) {
     975                                output << "when(";
     976                                stmt->timeout.condition->accept( *visitor );
     977                                output << ") ";
     978                        }
     979                        output << "waitfor(";
     980                        clause.target.function->accept( *visitor );
     981                        for( Expression * expr : clause.target.arguments ) {
     982                                output << ",";
     983                                expr->accept( *visitor );
     984                        }
     985                        output << ") ";
     986                        clause.statement->accept( *visitor );
     987                }
     988
     989                if( stmt->timeout.statement ) {
     990                        output << "or ";
     991                        if( stmt->timeout.condition ) {
     992                                output << "when(";
     993                                stmt->timeout.condition->accept( *visitor );
     994                                output << ") ";
     995                        }
     996                        output << "timeout(";
     997                        stmt->timeout.time->accept( *visitor );
     998                        output << ") ";
     999                        stmt->timeout.statement->accept( *visitor );
     1000                }
     1001
     1002                if( stmt->orelse.statement ) {
     1003                        output << "or ";
     1004                        if( stmt->orelse.condition ) {
     1005                                output << "when(";
     1006                                stmt->orelse.condition->accept( *visitor );
     1007                                output << ")";
     1008                        }
     1009                        output << "else ";
     1010                        stmt->orelse.statement->accept( *visitor );
     1011                }
     1012        }
     1013
    9491014
    9501015        void CodeGenerator::postvisit( WhileStmt * whileStmt ) {
     
    10251090        }
    10261091} // namespace CodeGen
     1092
     1093
     1094unsigned Indenter::tabsize = 2;
     1095
     1096std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) {
     1097        if ( node ) {
     1098                node->print( out );
     1099        } else {
     1100                out << "nullptr";
     1101        }
     1102        return out;
     1103}
    10271104
    10281105// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.