Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Does ambiguity resolution do unnecessary work?

> The statement 
>  
>    A<INT> latest = waldo([](int data) { return false; }); 
>  
> contains an ambiguity between CPPASTDeclarationStatement and  
> CPPASTExpressionStatement. This ambiguity is currently resolved by  
> counting problems in the whole statement and choosing the alternative  
> that produces fewer problems. This means that the parser makes two  
> attempts to resolve waldo, both for the declaration and for the  
> expression alternatives.  This looks excessive since absence of  
> problems in the type specifier should be sufficient to conclude that  
> the statement is a declaration. Name resolution in the initializer  
> should not be necessary. Likewise, absence of problems in the first  
> operand of the binary expression contained in the expression statement  
> alternative should be sufficient to conclude that the statement is an  
> expression. 
>  
> Does anybody know why ambiguity resolution always tries to resolve all  
> names under the ambiguous node? 

I don't know, but I can make a guess:

Perhaps it's simply because we have common code in 
ASTAmbiguousNode.doResolveAmbiguity() that handles all ambiguities
that do not override doResolveAmbiguity(), and since this common code
works for CPPASTAmbiguousStatement, nobody has bothered to override
doResolveAmbiguity() for it to provide a more efficient implementation?

If overriding CPPASTAmbiguousStatement.doResolveAmbiguity() to do what
you propose does not regress the test suite and codebases we have
available to test on, I say we go for it.

While we're on the topic of revising how ambiguity resolution works,
it might be worth taking another look at the changes suggested in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=347527. I'd love to see
those changes at some point!

Regards,
Nate 		 	   		  

Back to the top