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

Update the specification section about metadata #3787

Merged
merged 2 commits into from
May 8, 2024
Merged
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
41 changes: 35 additions & 6 deletions specification/dartLangSpec.tex
Original file line number Diff line number Diff line change
Expand Up @@ -8304,16 +8304,43 @@ \section{Metadata}
}

\LMHash{}%
Metadata is associated with the abstract syntax tree
of the program construct $p$ that immediately follows the metadata,
and which is not itself metadata or a comment.
Metadata that occurs as the first element of
the right hand side of a grammar rule
is associated with the abstract syntax tree for the non-terminal
on the left hand side of said grammar rule
\commentary{(that is, it is associated with its parent)}.
Otherwise, metadata is associated with the abstract syntax tree
of the program construct $p$ that immediately follows the metadata
in the grammar rule.

\rationale{%
These rules are intended to ensure a minimal level of consistency
in the association that binds each metadatum to a program construct.
The structure of the abstract syntax tree is implementation specific,
and it is not even guaranteed that a tool will use anything
which is known as an abstract syntax tree.
In that case the phrase `abstract syntax tree' should be interpreted as
the program representation entities which are actually used.

This implies that the fine details of the association between metadata
and an abstract syntax tree node is also implementation specific.
In particular, an implementation can choose to associate a given metadatum
with more than one abstract syntax tree node.%
}

\LMHash{}%
Metadata can be retrieved at run time via a reflective call,
provided the annotated program construct $p$ is accessible via reflection.

\commentary{%
Obviously, metadata can also be retrieved statically by
parsing the program and evaluating the constants via a suitable interpreter.
In fact, many if not most uses of metadata are entirely static.%
In fact, many if not most uses of metadata are entirely static.
In this case the binding of each metadatum to an abstract syntax tree node
is determined by the given static analysis tool,
which is of course not subject to any constraints in this document.
Surely it will still be useful to strive for consistency among all tools
with respect to the binding from metadata to abstract syntax tree nodes.%
}

\rationale{%
Expand Down Expand Up @@ -18189,8 +18216,10 @@ \subsection{For}
<forStatement> ::= \AWAIT? \FOR{} `(' <forLoopParts> `)' <statement>

<forLoopParts> ::= <forInitializerStatement> <expression>? `;' <expressionList>?
\alt <metadata> <declaredIdentifier> \IN{} <expression>
\alt <identifier> \IN{} <expression>
\alt <forInLoopPrefix> \IN{} <expression>

<forInLoopPrefix> ::= <metadata> <declaredIdentifier>
\alt <identifier>

<forInitializerStatement> ::= <localVariableDeclaration>
\alt <expression>? `;'
Expand Down