You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change adds parsing of member bounds declarations (issue #19). Member bounds
declarations use member bounds expressions, which can only use other
members of the structure. The changes include:
IR: no change is needed to represent member bounds expressions. Because
clang handles C++, it already can represent members directly in
the IR for expressions. Bounds expressions are a subclass of expressions.
We need to attach bounds expressions to member declarations. We already
have bounds expressions on function declarations and variable declarations,
which have the same base class as member declarations. Instead of having
a 3rd copy of the code, we factor the common code for representing bounds
expressions and move it to the common base.
Parsing: we modify the parsing of member declarators that are followed
by ':' to parse either a bounds expression or a constant-expression
that is a bit-field size. We check whether the first token after the
':' is an identifier that is contextual keyword for bounds expressions.
The parsing of bounds expressions is deferred until all members of the
structure have been seen. This is so that member bounds expressions may
refer to any member of the structure. Constant expressions for bitfield
sizes continue to be eagerly parsed.
The decision to just look for a bounds expression keyword can lead
to several error messages from clang if there is a spelling
error in a contextual keyword. Clang interprets the misspelled keyword
as an implicit function declaration and issues unknown identifier errors
for uses of members.
For now, we'll live this because this specific case is a fairly
low priority to address. The type for the identifier in the declarator
hasn't been built yet at the time that we make the parsing decision.
We could move that up or defer parsing of constant expressions. Either
change is largely orthogonal to this change.
Semantic processing: member bounds expressions are restricted to accessing
only members. We add a state flag to Sema that changes the lookup of C
identifiers during expression parsing to look up identifiers in the
member namespace instead of the ordinary namespace. The state flag is
protected by an RAII class.
Testing:
Wrote new feature tests of parsing member bounds
declaration. These will be checked in separately to the Checked C
repo in parsing\member_bounds.c.
Passes existing clang test baseline.
The text was updated successfully, but these errors were encountered:
Hi @dtarditi, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
It looks like you're a Microsoft contributor (David Tarditi). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.
This issue was copied from checkedc/checkedc-clang#23
This change adds parsing of member bounds declarations (issue #19). Member bounds
declarations use member bounds expressions, which can only use other
members of the structure. The changes include:
IR: no change is needed to represent member bounds expressions. Because
clang handles C++, it already can represent members directly in
the IR for expressions. Bounds expressions are a subclass of expressions.
We need to attach bounds expressions to member declarations. We already
have bounds expressions on function declarations and variable declarations,
which have the same base class as member declarations. Instead of having
a 3rd copy of the code, we factor the common code for representing bounds
expressions and move it to the common base.
Parsing: we modify the parsing of member declarators that are followed
by ':' to parse either a bounds expression or a constant-expression
that is a bit-field size. We check whether the first token after the
':' is an identifier that is contextual keyword for bounds expressions.
The parsing of bounds expressions is deferred until all members of the
structure have been seen. This is so that member bounds expressions may
refer to any member of the structure. Constant expressions for bitfield
sizes continue to be eagerly parsed.
The decision to just look for a bounds expression keyword can lead
to several error messages from clang if there is a spelling
error in a contextual keyword. Clang interprets the misspelled keyword
as an implicit function declaration and issues unknown identifier errors
for uses of members.
For now, we'll live this because this specific case is a fairly
low priority to address. The type for the identifier in the declarator
hasn't been built yet at the time that we make the parsing decision.
We could move that up or defer parsing of constant expressions. Either
change is largely orthogonal to this change.
Semantic processing: member bounds expressions are restricted to accessing
only members. We add a state flag to Sema that changes the lookup of C
identifiers during expression parsing to look up identifiers in the
member namespace instead of the ordinary namespace. The state flag is
protected by an RAII class.
Testing:
declaration. These will be checked in separately to the Checked C
repo in parsing\member_bounds.c.
The text was updated successfully, but these errors were encountered: