Changes in src/CodeGen/CodeGenerator.cc [29cf9c8:5f642e38]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r29cf9c8 r5f642e38 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : T us May 9 16:50:00201713 // Update Count : 48 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 30 16:38:01 2017 13 // Update Count : 482 14 14 // 15 15 … … 41 41 namespace CodeGen { 42 42 int CodeGenerator::tabsize = 4; 43 44 // Pseudo Function: output << lineDirective(currentNode);45 struct lineDirective {46 CodeLocation const & loc;47 lineDirective(CodeLocation const & location) : loc(location) {}48 lineDirective(BaseSyntaxNode const * node) : loc(node->location) {}49 };50 std::ostream & operator<<(std::ostream & out, lineDirective const & ld) {51 if (ld.loc.isSet())52 return out << "\n# " << ld.loc.linenumber << " \""53 << ld.loc.filename << "\"\n";54 return out << "\n// Unset Location\n";55 }56 43 57 44 // the kinds of statements that would ideally be followed by whitespace … … 141 128 142 129 143 // 130 //*** Declarations 144 131 void CodeGenerator::visit( FunctionDecl * functionDecl ) { 145 output << lineDirective( functionDecl );146 147 132 extension( functionDecl ); 148 133 genAttributes( functionDecl->get_attributes() ); … … 168 153 } 169 154 170 output << lineDirective( objectDecl );171 172 155 extension( objectDecl ); 173 156 genAttributes( objectDecl->get_attributes() ); … … 209 192 cur_indent += CodeGenerator::tabsize; 210 193 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 211 output << lineDirective( *i ) <<indent;194 output << indent; 212 195 (*i)->accept( *this ); 213 196 output << ";" << endl; … … 221 204 222 205 void CodeGenerator::visit( StructDecl * structDecl ) { 223 output << lineDirective( structDecl );224 225 206 extension( structDecl ); 226 207 handleAggregate( structDecl, "struct " ); … … 228 209 229 210 void CodeGenerator::visit( UnionDecl * unionDecl ) { 230 output << lineDirective( unionDecl );231 232 211 extension( unionDecl ); 233 212 handleAggregate( unionDecl, "union " ); … … 236 215 void CodeGenerator::visit( EnumDecl * enumDecl ) { 237 216 extension( enumDecl ); 238 output << lineDirective ( enumDecl );239 217 output << "enum "; 240 218 genAttributes( enumDecl->get_attributes() ); … … 252 230 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 253 231 assert( obj ); 254 output << lineDirective( obj ) <<indent << mangleName( obj );232 output << indent << mangleName( obj ); 255 233 if ( obj->get_init() ) { 256 234 output << " = "; … … 270 248 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 271 249 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 272 output << lineDirective( typeDecl );273 250 output << "typedef "; 274 251 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 285 262 } // if 286 263 } else { 287 output << typeDecl->genTypeString() << " " << typeDecl->get_name(); 288 if ( typeDecl->get_kind() != TypeDecl::Any && typeDecl->get_sized() ) { 289 output << " | sized(" << typeDecl->get_name() << ")"; 290 } 264 output << typeDecl->typeString() << " " << typeDecl->get_name(); 291 265 if ( ! typeDecl->get_assertions().empty() ) { 292 266 output << " | { "; … … 342 316 } 343 317 344 // 318 //*** Expressions 345 319 void CodeGenerator::visit( ApplicationExpr * applicationExpr ) { 346 320 extension( applicationExpr ); … … 745 719 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 746 720 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 747 output << lineDirective( stmtExpr) <<"({" << std::endl;721 output << "({" << std::endl; 748 722 cur_indent += CodeGenerator::tabsize; 749 723 unsigned int numStmts = stmts.size(); 750 724 unsigned int i = 0; 751 725 for ( Statement * stmt : stmts ) { 752 output << lineDirective( stmt ) << indent; 753 output << printLabels( stmt->get_labels() ); 726 output << indent << printLabels( stmt->get_labels() ); 754 727 if ( i+1 == numStmts ) { 755 728 // last statement in a statement expression needs to be handled specially - … … 773 746 } 774 747 775 // 748 //*** Statements 776 749 void CodeGenerator::visit( CompoundStmt * compoundStmt ) { 777 750 std::list<Statement*> ks = compoundStmt->get_kids(); … … 796 769 void CodeGenerator::visit( ExprStmt * exprStmt ) { 797 770 assert( exprStmt ); 798 Expression * expr = exprStmt->get_expr(); 799 if ( genC ) { 800 // cast the top-level expression to void to reduce gcc warnings. 801 expr = new CastExpr( expr ); 802 } 771 // cast the top-level expression to void to reduce gcc warnings. 772 Expression * expr = new CastExpr( exprStmt->get_expr() ); 803 773 expr->accept( *this ); 804 774 output << ";"; … … 837 807 838 808 void CodeGenerator::visit( IfStmt * ifStmt ) { 839 output << lineDirective( ifStmt );840 809 output << "if ( "; 841 810 ifStmt->get_condition()->accept( *this ); … … 851 820 852 821 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 853 output << lineDirective( switchStmt );854 822 output << "switch ( " ; 855 823 switchStmt->get_condition()->accept( *this ); … … 864 832 865 833 void CodeGenerator::visit( CaseStmt * caseStmt ) { 866 output << lineDirective( caseStmt );867 834 output << indent; 868 835 if ( caseStmt->isDefault()) {
Note: See TracChangeset
for help on using the changeset viewer.