mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	LibCpp: Support 'auto' Type
This commit is contained in:
		
							parent
							
								
									eeb98335d5
								
							
						
					
					
						commit
						f28d944122
					
				
					 3 changed files with 27 additions and 9 deletions
				
			
		|  | @ -76,7 +76,14 @@ String Type::to_string() const | |||
|     String qualifiers_string; | ||||
|     if (!m_qualifiers.is_empty()) | ||||
|         qualifiers_string = String::formatted("[{}] ", String::join(" ", m_qualifiers)); | ||||
|     return String::formatted("{}{}", qualifiers_string, m_name.is_null() ? "" : m_name->full_name()); | ||||
| 
 | ||||
|     String name; | ||||
|     if (m_is_auto) | ||||
|         name = "auto"; | ||||
|     else | ||||
|         name = m_name.is_null() ? "" : m_name->full_name(); | ||||
| 
 | ||||
|     return String::formatted("{}{}", qualifiers_string, name); | ||||
| } | ||||
| 
 | ||||
| String Pointer::to_string() const | ||||
|  |  | |||
|  | @ -206,6 +206,7 @@ public: | |||
|     { | ||||
|     } | ||||
| 
 | ||||
|     bool m_is_auto { false }; | ||||
|     RefPtr<Name> m_name; | ||||
|     Vector<StringView> m_qualifiers; | ||||
| }; | ||||
|  |  | |||
|  | @ -235,6 +235,10 @@ bool Parser::match_type() | |||
|     ScopeGuard state_guard = [this] { load_state(); }; | ||||
| 
 | ||||
|     parse_type_qualifiers(); | ||||
|     if (match_keyword("auto")) { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     if (match_keyword("struct")) { | ||||
|         consume(Token::Type::Keyword); // Consume struct prefix
 | ||||
|     } | ||||
|  | @ -1104,16 +1108,22 @@ NonnullRefPtr<Type> Parser::parse_type(ASTNode& parent) | |||
|     auto qualifiers = parse_type_qualifiers(); | ||||
|     type->m_qualifiers = move(qualifiers); | ||||
| 
 | ||||
|     if (match_keyword("struct")) { | ||||
|         consume(Token::Type::Keyword); // Consume struct prefix
 | ||||
|     } | ||||
|     if (match_keyword("auto")) { | ||||
|         consume(Token::Type::Keyword); | ||||
|         type->m_is_auto = true; | ||||
|     } else { | ||||
| 
 | ||||
|     if (!match_name()) { | ||||
|         type->set_end(position()); | ||||
|         error(String::formatted("expected name instead of: {}", peek().text())); | ||||
|         return type; | ||||
|         if (match_keyword("struct")) { | ||||
|             consume(Token::Type::Keyword); // Consume struct prefix
 | ||||
|         } | ||||
| 
 | ||||
|         if (!match_name()) { | ||||
|             type->set_end(position()); | ||||
|             error(String::formatted("expected name instead of: {}", peek().text())); | ||||
|             return type; | ||||
|         } | ||||
|         type->m_name = parse_name(*type); | ||||
|     } | ||||
|     type->m_name = parse_name(*type); | ||||
| 
 | ||||
|     while (!eof() && peek().type() == Token::Type::Asterisk) { | ||||
|         type->set_end(position()); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Itamar
						Itamar