mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 06:52:45 +00:00 
			
		
		
		
	LibCpp: Parse empty for loops
This commit is contained in:
		
							parent
							
								
									fc503b1368
								
							
						
					
					
						commit
						d482b3fd60
					
				
					 2 changed files with 15 additions and 5 deletions
				
			
		|  | @ -394,8 +394,11 @@ NonnullRefPtrVector<Declaration> Statement::declarations() const | |||
| 
 | ||||
| NonnullRefPtrVector<Declaration> ForStatement::declarations() const | ||||
| { | ||||
|     auto declarations = m_init->declarations(); | ||||
|     declarations.append(m_body->declarations()); | ||||
|     NonnullRefPtrVector<Declaration> declarations; | ||||
|     if (m_init) | ||||
|         declarations.append(m_init->declarations()); | ||||
|     if (m_body) | ||||
|         declarations.append(m_body->declarations()); | ||||
|     return declarations; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1204,13 +1204,20 @@ NonnullRefPtr<ForStatement> Parser::parse_for_statement(ASTNode& parent) | |||
|     auto for_statement = create_ast_node<ForStatement>(parent, position(), {}); | ||||
|     consume(Token::Type::Keyword); | ||||
|     consume(Token::Type::LeftParen); | ||||
|     for_statement->m_init = parse_variable_declaration(*for_statement); | ||||
|     if (peek().type() != Token::Type::Semicolon) | ||||
|         for_statement->m_init = parse_variable_declaration(*for_statement, false); | ||||
|     consume(Token::Type::Semicolon); | ||||
|     for_statement->m_test = parse_expression(*for_statement); | ||||
| 
 | ||||
|     if (peek().type() != Token::Type::Semicolon) | ||||
|         for_statement->m_test = parse_expression(*for_statement); | ||||
|     consume(Token::Type::Semicolon); | ||||
|     for_statement->m_update = parse_expression(*for_statement); | ||||
| 
 | ||||
|     if (peek().type() != Token::Type::RightParen) | ||||
|         for_statement->m_update = parse_expression(*for_statement); | ||||
|     consume(Token::Type::RightParen); | ||||
| 
 | ||||
|     for_statement->m_body = parse_statement(*for_statement); | ||||
| 
 | ||||
|     for_statement->set_end(for_statement->m_body->end()); | ||||
|     return for_statement; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Itamar
						Itamar