mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Generate break and continue statements inside for loop body.
This commit is contained in:
		
							parent
							
								
									1feefa1ccc
								
							
						
					
					
						commit
						6f673f5e81
					
				| @ -311,7 +311,9 @@ void ProtoConverter::visit(ForStmt const& _x) | ||||
| 	m_output << "for { let " << loopVarName << " := 0 } " | ||||
| 		<< "lt(" << loopVarName << ", 0x60) " | ||||
| 		<< "{ " << loopVarName << " := add(" << loopVarName << ", 0x20) } "; | ||||
| 	m_inForScope.push(true); | ||||
| 	visit(_x.for_body()); | ||||
| 	m_inForScope.pop(); | ||||
| 	--m_numNestedForLoops; | ||||
| } | ||||
| 
 | ||||
| @ -365,6 +367,14 @@ void ProtoConverter::visit(Statement const& _x) | ||||
| 		case Statement::kSwitchstmt: | ||||
| 			visit(_x.switchstmt()); | ||||
| 			break; | ||||
| 		case Statement::kBreakstmt: | ||||
| 			if (m_inForScope.top()) | ||||
| 				m_output << "break\n"; | ||||
| 			break; | ||||
| 		case Statement::kContstmt: | ||||
| 			if (m_inForScope.top()) | ||||
| 				m_output << "continue\n"; | ||||
| 			break; | ||||
| 		case Statement::STMT_ONEOF_NOT_SET: | ||||
| 			break; | ||||
| 	} | ||||
|  | ||||
| @ -39,6 +39,7 @@ public: | ||||
| 		m_numLiveVars = 10; | ||||
| 		m_numVarsPerScope.push(m_numLiveVars); | ||||
| 		m_numNestedForLoops = 0; | ||||
| 		m_inForScope.push(false); | ||||
| 	} | ||||
| 	ProtoConverter(ProtoConverter const&) = delete; | ||||
| 	ProtoConverter(ProtoConverter&&) = delete; | ||||
| @ -72,6 +73,7 @@ private: | ||||
| 	std::stack<uint8_t> m_numVarsPerScope; | ||||
| 	int32_t m_numLiveVars; | ||||
| 	int32_t m_numNestedForLoops; | ||||
| 	std::stack<bool> m_inForScope; | ||||
| }; | ||||
| } | ||||
| } | ||||
|  | ||||
| @ -141,7 +141,7 @@ message IfStmt { | ||||
| } | ||||
| 
 | ||||
| message ForStmt { | ||||
|   required Block for_body = 2; | ||||
|   required Block for_body = 1; | ||||
| } | ||||
| 
 | ||||
| message CaseStmt { | ||||
| @ -155,6 +155,9 @@ message SwitchStmt { | ||||
|   optional Block default_block = 3; | ||||
| } | ||||
| 
 | ||||
| message BreakStmt {} | ||||
| message ContinueStmt {} | ||||
| 
 | ||||
| message Statement { | ||||
|   oneof stmt_oneof { | ||||
|     VarDecl             decl          = 1; | ||||
| @ -164,6 +167,8 @@ message Statement { | ||||
|     Block               blockstmt     = 5; | ||||
|     ForStmt             forstmt       = 6; | ||||
|     SwitchStmt          switchstmt    = 7; | ||||
|     BreakStmt           breakstmt     = 8; | ||||
|     ContinueStmt        contstmt      = 9; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user