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

D: parse template instance types #3716

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Units/parser-d.r/templates.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Template input.d /^template Template(alias a, T...)$/;" T file:
TemplateAlias input.d /^ alias TemplateAlias = a!T;$/;" a template:Template file:
memb input.d /^ int memb;$/;" m template:Template file:
b input.d /^Foo!x b;$/;" v
c input.d /^Foo!(x) c;$/;" v
d input.d /^Foo!(x < 2) d;$/;" v
g input.d /^void g(Foo!x) {}$/;" f
each input.d /^template each(alias fun = "a")$/;" T file:
child input.d /^ template child(){}$/;" T template:each file:
tmethod input.d /^ void tmethod()(){}$/;" f template:each
Expand Down
7 changes: 4 additions & 3 deletions Units/parser-d.r/templates.d/input.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ private:
}

Foo!x b;
Foo!(x) c; // FIXME
Foo!(x < 2) d; // FIXME
void f(Foo!x); // FIXME
Foo!(x) c;
Foo!(x < 2) d;
void f(Foo!x); // FIXME prototypes
void g(Foo!x) {}

template each(alias fun = "a")
{
Expand Down
15 changes: 15 additions & 0 deletions parsers/c-based.c
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,10 @@ static int parseParens (statementInfo *const st, parenInfo *const info)
{
parseAtMarkStyleAnnotation (st);
}
else if (isInputLanguage (Lang_d) && c == '!')
{ /* template instantiation */
info->isNameCandidate = false;
}
else if (cppIsident1 (c))
{
readIdentifier (token, c);
Expand Down Expand Up @@ -2712,6 +2716,17 @@ static void nextToken (statementInfo *const st)
case '[': skipToMatch ("[]"); break;
case '{': setToken (st, TOKEN_BRACE_OPEN); break;
case '}': setToken (st, TOKEN_BRACE_CLOSE); break;
case '!':
if (isInputLanguage (Lang_d))
{
c = skipToNonWhite ();
if (c == '(')
{
// template instance with parameter list
skipToMatch("()");
break;
}
}
default: parseGeneralToken (st, c); break;
}
token = activeToken (st);
Expand Down