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 user-defined attributes #3701

Merged
merged 2 commits into from
Apr 30, 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
2 changes: 2 additions & 0 deletions Units/parser-d.r/simple.d.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ TemplateAlias input.d /^ alias TemplateAlias = a!T;$/;" a file:
UT input.d /^union UT(T){}$/;" u file:
Union input.d /^ union Union$/;" u struct:Struct file:
_bar input.d /^ private AliasInt _bar;$/;" m class:Class file:
attr_anon input.d /^@(obj) T attr_anon;$/;" v
attr_decl input.d /^@attr(i) int attr_decl = 1;$/;" v
bar input.d /^ bar,$/;" e enum:Enum file:
bar input.d /^ public AliasInt bar()$/;" f class:Class
conditional input.d /^ T conditional;$/;" v file:
Expand Down
5 changes: 5 additions & 0 deletions Units/parser-d.r/simple.d.d/input.d
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ int i;
int error;
+/

@attr(i) int attr_decl = 1;
@attr(i) attr_decl_infer = 1; // FIXME
@(obj) T attr_anon;
void attr_post() @attr(obj); // FIXME

static if (is(typeof(__traits(getMember, a, name)) == function))
T conditional;

Expand Down
21 changes: 15 additions & 6 deletions parsers/c-based.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ static const keywordDesc KeywordTable [] = {
* FUNCTION PROTOTYPES
*/
static void createTags (const unsigned int nestLevel, statementInfo *const parent);
static void parseAtMarkStyleAnnotation (statementInfo *const st);

/*
* FUNCTION DEFINITIONS
Expand Down Expand Up @@ -2122,6 +2123,10 @@ static bool skipPostArgumentStuff (
break;
}
}
else if (isInputLanguage (Lang_d) && c == '@')
{
parseAtMarkStyleAnnotation (st);
}
}
if (! end)
{
Expand Down Expand Up @@ -2213,7 +2218,7 @@ static void processAngleBracket (void)
}
}

static void parseJavaAnnotation (statementInfo *const st)
static void parseAtMarkStyleAnnotation (statementInfo *const st)
{
/*
* @Override
Expand All @@ -2225,7 +2230,11 @@ static void parseJavaAnnotation (statementInfo *const st)
tokenInfo *const token = activeToken (st);

int c = skipToNonWhite ();
readIdentifier (token, c);
if (cppIsident1 (c))
readIdentifier (token, c);
else
cppUngetc (c); // D allows: @ ( ArgumentList )

if (token->keyword == KEYWORD_INTERFACE)
{
/* Oops. This was actually "@interface" defining a new annotation. */
Expand Down Expand Up @@ -2346,9 +2355,9 @@ static int parseParens (statementInfo *const st, parenInfo *const info)
break;

default:
if (c == '@' && isInputLanguage (Lang_java))
if (c == '@' && (isInputLanguage (Lang_d) || isInputLanguage (Lang_java)))
{
parseJavaAnnotation(st);
parseAtMarkStyleAnnotation (st);
}
else if (cppIsident1 (c))
{
Expand Down Expand Up @@ -2637,9 +2646,9 @@ static void parseGeneralToken (statementInfo *const st, const int c)
if (c2 != '=')
cppUngetc (c2);
}
else if (c == '@' && isInputLanguage (Lang_java))
else if (c == '@' && (isInputLanguage (Lang_d) || isInputLanguage (Lang_java)))
{
parseJavaAnnotation (st);
parseAtMarkStyleAnnotation (st);
}
else if (c == STRING_SYMBOL) {
setToken(st, TOKEN_NONE);
Expand Down