@@ -191,41 +191,27 @@ ASTNodeUP DILParser::ParsePrimaryExpression() {
191191 return std::make_unique<IdentifierNode>(loc, identifier);
192192 }
193193
194- if (CurToken ().Is (Token::l_paren)) {
195- // Check in case this is an anonynmous namespace
196- if (m_dil_lexer.LookAhead (1 ).Is (Token::identifier) &&
197- (m_dil_lexer.LookAhead (1 ).GetSpelling () == " anonymous" ) &&
198- m_dil_lexer.LookAhead (2 ).Is (Token::identifier) &&
199- (m_dil_lexer.LookAhead (2 ).GetSpelling () == " namespace" ) &&
200- m_dil_lexer.LookAhead (3 ).Is (Token::r_paren) &&
201- m_dil_lexer.LookAhead (4 ).Is (Token::coloncolon)) {
202- m_dil_lexer.Advance (4 );
194+ uint32_t loc = CurToken ().GetLocation ();
195+ std::string nested_name_specifier;
203196
204- std::string identifier = " (anonymous namespace)" ;
205- Expect (Token::coloncolon);
206- // Save the source location for the diagnostics message.
207- uint32_t loc = CurToken ().GetLocation ();
208- m_dil_lexer.Advance ();
209- assert (
210- (CurToken ().Is (Token::identifier) || CurToken ().Is (Token::l_paren)) &&
211- " Expected an identifier or anonymous namespeace, but not found." );
212- std::string identifier2 = ParseNestedNameSpecifier ();
213- if (identifier2.empty ()) {
214- // There was only an identifer, no more levels of nesting. Or there
215- // was an invalid expression starting with a left parenthesis.
216- Expect (Token::identifier);
217- identifier2 = CurToken ().GetSpelling ();
218- m_dil_lexer.Advance ();
219- }
220- identifier = identifier + " ::" + identifier2;
221- return std::make_unique<IdentifierNode>(loc, identifier);
222- } else {
223- m_dil_lexer.Advance ();
224- auto expr = ParseExpression ();
225- Expect (Token::r_paren);
226- m_dil_lexer.Advance ();
227- return expr;
197+ if (CurToken ().Is (Token::l_paren))
198+ nested_name_specifier = ParseNestedNameSpecifier ();
199+
200+ if (!nested_name_specifier.empty ()) {
201+ if (!CurToken ().Is (Token::identifier)) {
202+ BailOut (" Expected an identifier, but not found." ,
203+ CurToken ().GetLocation (), CurToken ().GetSpelling ().length ());
228204 }
205+
206+ std::string unqualified_id = ParseUnqualifiedId ();
207+ return std::make_unique<IdentifierNode>(loc, nested_name_specifier +
208+ unqualified_id);
209+ } else {
210+ m_dil_lexer.Advance ();
211+ auto expr = ParseExpression ();
212+ Expect (Token::r_paren);
213+ m_dil_lexer.Advance ();
214+ return expr;
229215 }
230216
231217 BailOut (llvm::formatv (" Unexpected token: {0}" , CurToken ()),
@@ -261,16 +247,16 @@ std::string DILParser::ParseNestedNameSpecifier() {
261247 m_dil_lexer.LookAhead (4 ).Is (Token::coloncolon)) {
262248 m_dil_lexer.Advance (4 );
263249
264- assert (
265- (CurToken ().Is (Token::identifier) || CurToken ().Is (Token::l_paren)) &&
266- " Expected an identifier or anonymous namespace, but not found." );
250+ Expect (Token::coloncolon);
251+ m_dil_lexer.Advance ();
252+ if (!CurToken ().Is (Token::identifier) && !CurToken ().Is (Token::l_paren)) {
253+ BailOut (
254+ " Expected an identifier or anonymous namespeace, but not found." ,
255+ CurToken ().GetLocation (), CurToken ().GetSpelling ().length ());
256+ }
267257 // Continue parsing the nested_namespace_specifier.
268258 std::string identifier2 = ParseNestedNameSpecifier ();
269- if (identifier2.empty ()) {
270- Expect (Token::identifier);
271- identifier2 = CurToken ().GetSpelling ();
272- m_dil_lexer.Advance ();
273- }
259+
274260 return " (anonymous namespace)::" + identifier2;
275261 }
276262
0 commit comments