Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.cc

    rba3706f ree3c93d  
    3434Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {}
    3535
    36 void Statement::print( std::ostream & os, Indenter ) const {
     36void Statement::print( std::ostream & os, Indenter indent ) const {
    3737        if ( ! labels.empty() ) {
    38                 os << "Labels: {";
     38                os << indent << "... Labels: {";
    3939                for ( const Label & l : labels ) {
    4040                        os << l << ",";
     
    9494
    9595
     96DirectiveStmt::DirectiveStmt( const std::string & directive ) : Statement(), directive( directive ) {}
     97
     98void DirectiveStmt::print( std::ostream &os, Indenter ) const {
     99        os << "GCC Directive:" << directive << endl;
     100}
     101
     102
    96103const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
    97104
    98 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticError ) :
     105BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) :
    99106        Statement(), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) {
    100107        //actually this is a syntactic error signaled by the parser
    101108        if ( type == BranchStmt::Goto && target.empty() ) {
    102                 throw SemanticError("goto without target");
    103         }
    104 }
    105 
    106 BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticError ) :
     109                SemanticError( target.get_statement()->location, "goto without target");
     110        }
     111}
     112
     113BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticErrorException ) :
    107114        Statement(), computedTarget( computedTarget ), type( type ) {
    108115        if ( type != BranchStmt::Goto || computedTarget == nullptr ) {
    109                 throw SemanticError("Computed target not valid in branch statement");
     116                SemanticError( computedTarget->location, "Computed target not valid in branch statement");
    110117        }
    111118}
     
    201208}
    202209
    203 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
     210CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) :
    204211        Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    205         if ( isDefault() && condition != 0 ) throw SemanticError("default case with condition: ", condition);
     212        if ( isDefault() && condition != 0 ) SemanticError( condition, "default case with condition: " );
    206213}
    207214
     
    223230
    224231void CaseStmt::print( std::ostream &os, Indenter indent ) const {
    225         if ( isDefault() ) os << "Default ";
     232        if ( isDefault() ) os << indent << "Default ";
    226233        else {
    227                 os << "Case ";
     234                os << indent << "Case ";
    228235                condition->print( os, indent );
    229236        } // if
     
    231238
    232239        for ( Statement * stmt : stmts ) {
     240                os << indent+1;
    233241                stmt->print( os, indent+1 );
    234242        }
    235243}
    236244
    237 WhileStmt::WhileStmt( Expression *condition, Statement *body, bool isDoWhile ):
    238         Statement(), condition( condition), body( body), isDoWhile( isDoWhile) {
     245WhileStmt::WhileStmt( Expression *condition, Statement *body, std::list< Statement * > & initialization, bool isDoWhile ):
     246        Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) {
    239247}
    240248
     
    452460void WaitForStmt::print( std::ostream &os, Indenter indent ) const {
    453461        os << "Waitfor Statement" << endl;
    454         os << indent << "... with block:" << endl << indent+1;
    455         // block->print( os, indent + 4 );
    456 }
     462        indent += 1;
     463        for( auto & clause : clauses ) {
     464                os << indent << "target function :";
     465                if(clause.target.function) { clause.target.function->print(os, indent + 1); }
     466                os << endl << indent << "with arguments :" << endl;
     467                for( auto & thing : clause.target.arguments) {
     468                        if(thing) { thing->print(os, indent + 1); }
     469                }
     470                os << indent << " with statment :" << endl;
     471                if(clause.statement) { clause.statement->print(os, indent + 1); }
     472
     473                os << indent << " with condition :" << endl;
     474                if(clause.condition) { clause.condition->print(os, indent + 1); }
     475        }
     476
     477        os << indent << " timeout of :" << endl;
     478        if(timeout.time) { timeout.time->print(os, indent + 1); }
     479
     480        os << indent << " with statment :" << endl;
     481        if(timeout.statement) { timeout.statement->print(os, indent + 1); }
     482
     483        os << indent << " with condition :" << endl;
     484        if(timeout.condition) { timeout.condition->print(os, indent + 1); }
     485
     486
     487        os << indent << " else :" << endl;
     488        if(orelse.statement) { orelse.statement->print(os, indent + 1); }
     489
     490        os << indent << " with condition :" << endl;
     491        if(orelse.condition) { orelse.condition->print(os, indent + 1); }
     492}
     493
     494
     495WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Statement(), exprs( exprs ), stmt( stmt ) {}
     496WithStmt::WithStmt( const WithStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) {
     497        cloneAll( other.exprs, exprs );
     498}
     499WithStmt::~WithStmt() {
     500        deleteAll( exprs );
     501        delete stmt;
     502}
     503
     504void WithStmt::print( std::ostream & os, Indenter indent ) const {
     505        os << "With statement" << endl;
     506        os << indent << "... with expressions: " << endl;
     507        printAll( exprs, os, indent+1 );
     508        os << indent << "... with statement:" << endl << indent+1;
     509        stmt->print( os, indent+1 );
     510}
     511
    457512
    458513NullStmt::NullStmt( const std::list<Label> & labels ) : Statement( labels ) {
    459514}
    460515
    461 void NullStmt::print( std::ostream &os, Indenter ) const {
     516void NullStmt::print( std::ostream &os, Indenter indent ) const {
    462517        os << "Null Statement" << endl;
     518        Statement::print( os, indent );
    463519}
    464520
Note: See TracChangeset for help on using the changeset viewer.