-
Notifications
You must be signed in to change notification settings - Fork 19
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
Parse bounds declarations for variable declarations. #18
Comments
Comment from @msftclas: Hi @dtarditi, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
Comment from @reubeno: Modulo my one comment comment :), looks good to me! |
Comment from @dtarditi: Good idea - I've added a comment explaining the case for Checked C. |
This issue was copied from checkedc/checkedc-clang#18
This change adds parsing of variable declarations with bounds declarations (issue #13).
For each declarator in a declaration, the declarator is parsed and then the
optional Checked C bounds declaration is parsed. The bounds declaration is
parsed before the optional initializing expression for the declarator. Because
the declarator has already been parsed and added to the current scope, the
bounds expression can be eagerly parsed.
One surprise with clang was that placing declarators for a declaration
on multiple lines caused a parsing error in the initial implementation,
while having all the declarators on one line did not. I traced this back to
special case code that looks for typographical mistakes
at line endings by calling MightBeDeclarator and generating an
error if MightBeDeclarator is false. MightBeDeclarator returns true
for syntactic items that might start a declarator. It has special
case checks to make sure that an identifier is followed by something
that might also be part of a declarator. For Checked C, an identifier
that starts a declarator may be followed by ':' and a bounds expression,
so allow ':' when the language options include Checked C.
This change also improves error handling during the parsing of bounds
expressions.
always scan for the matching right parenthesis. The scan for the matching
right parenthesis was only happening in one specific case, leading to
hard-to-understand spurious parsing errors.
bounds expression of the form bounds '(' e1 ',' e2, ')'. clang does not
differentiate during parsing of expressions between semantic errors and
parsing failures. It is important to continue parsing so that a semantic
error does not cause a cascade of parsing errors.
These problems were uncovered during testing of parsing of variable declarations
with bounds expressions. Specifically, using an incorrect bounds expression
in a variable declaration with an initializer caused a spurious parsing
errors.
Testing:
(parsing_bounds_var_declarations.c). This will be committed separately to the
checkedc repo.
The text was updated successfully, but these errors were encountered: