Changeset 4acd1f8
- Timestamp:
- Mar 11, 2026, 5:40:49 PM (14 hours ago)
- Branches:
- master
- Children:
- 42bce4e
- Parents:
- 1b6ec23
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cpp
r1b6ec23 r4acd1f8 10 10 // Created On : Tue Oct 17 15:54:00 2023 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jan 17 14:19:22 202513 // Update Count : 112 // Last Modified On : Wed Mar 11 11:13:10 2026 13 // Update Count : 28 14 14 // 15 15 … … 49 49 } 50 50 51 CodeGenerator::LabelPrinter & CodeGenerator::LabelPrinter::operator()( 52 std::vector<ast::Label> const & l ) { 51 CodeGenerator::LabelPrinter & CodeGenerator::LabelPrinter::operator()( std::vector<ast::Label> const & l ) { 53 52 labels = &l; 54 53 return *this; … … 1245 1244 output << "do"; 1246 1245 } else { 1247 output << "while ( ";1246 output << "while ( "; 1248 1247 stmt->cond->accept( *visitor ); 1249 output << " )";1248 output << " )"; 1250 1249 } 1251 1250 output << " "; … … 1255 1254 1256 1255 if ( stmt->isDoWhile ) { 1257 output << " while ( ";1256 output << " while ( "; 1258 1257 stmt->cond->accept( *visitor ); 1259 output << ( ( nullptr == stmt->else_ ) ? ");" : ")" ); 1260 } 1258 output << " );"; // always terminate with semi-colon 1259 } 1260 1261 1261 if ( stmt->else_ ) { 1262 output << " else "; 1263 stmt->else_->accept( *visitor ); 1262 stmt->else_->accept( *visitor ); // not converted in AST pass 1264 1263 } 1265 1264 } 1266 1265 1267 1266 void CodeGenerator::postvisit( ast::ForStmt const * stmt ) { 1268 // Initializer is always hoised so don't generate it. 1269 // TODO: Do an assertion check? 1270 output << "for (;"; 1267 assert( stmt->inits.empty() ); // initializer is hoisted 1268 output << "for ( ; "; // empty initializer 1271 1269 1272 1270 if ( nullptr != stmt->cond ) { 1273 1271 stmt->cond->accept( *visitor ); 1274 1272 } 1275 output << "; ";1273 output << "; "; // separator 1276 1274 1277 1275 if ( nullptr != stmt->inc ) { … … 1280 1278 expr->accept( *visitor ); 1281 1279 } 1282 output << " ) ";1280 output << " ) "; 1283 1281 1284 1282 if ( nullptr != stmt->body ) { … … 1288 1286 1289 1287 if ( nullptr != stmt->else_ ) { 1290 assertf( !options.genC, "Loop else should not reach code generation." ); 1291 output << " else "; 1292 stmt->else_->accept( *visitor ); 1288 stmt->else_->accept( *visitor ); // not converted in AST pass 1293 1289 } 1294 1290 }
Note:
See TracChangeset
for help on using the changeset viewer.