Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing of nested templates is slow #2128

Merged
merged 1 commit into from
May 2, 2021

Conversation

guwirth
Copy link
Collaborator

@guwirth guwirth commented May 2, 2021

Previously, nested templates with >> at the end were handled via a grammar extension (N1757/Approach 3). For deeper nested templates this led to many look-ahead symbols and exponentially increasing execution time. The treatment has now been moved to the Lexer: Solving the problem amounts to decreeing that under some circumstances a >> token is treated as two right angle brackets instead of a right shift operator (N1757/Approach 1).

Some samples which are much faster now:

using List= TypeA<A, TypeB<B, TypeC<C, TypeD<D, TypeE<E, TypeF<F, TypeG<G, TypeH<H, I>>>>>>>>;
UARTTask<BL6523GXController<UART<UART_NUM_2, 4800, 8, 'N', 1>>> uartTask;

void f1() {
   TypeA<A, TypeB<B, TypeC<C, TypeD<D;
}

void f2() {
   TypeA<A, TypeB<B, TypeC<C, TypeD<D>>>> t;
}

This change is Reviewable

Previously, nested templates with >> at the end were handled via a grammar extension (N1757/Approach 3). For deeper nested templates this led to many look-ahead symbols and exponentially increasing execution time. The treatment has now been moved to the Lexer: Solving the problem amounts to decreeing that under some circumstances a >> token is treated as two right angle brackets instead of a right shift operator (N1757/Approach 1).

- add 'Right Angle Brackets N1757' document
- close SonarOpenCommunity#1685

Some samples which are much faster now:

```C++
using List= TypeA<A, TypeB<B, TypeC<C, TypeD<D, TypeE<E, TypeF<F, TypeG<G, TypeH<H, I>>>>>>>>;
UARTTask<BL6523GXController<UART<UART_NUM_2, 4800, 8, 'N', 1>>> uartTask;

void f1() {
   TypeA<A, TypeB<B, TypeC<C, TypeD<D;
}

void f2() {
   TypeA<A, TypeB<B, TypeC<C, TypeD<D>>>> t;
}

```
@guwirth guwirth added the bug label May 2, 2021
@guwirth guwirth added this to the 2.0.0 milestone May 2, 2021
@guwirth guwirth self-assigned this May 2, 2021
@guwirth guwirth merged commit fa5575c into SonarOpenCommunity:master May 2, 2021
@guwirth guwirth deleted the right-angle-brackets branch May 4, 2021 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

Parsing of nested templates is slow: template <... template<...>>
1 participant