-
Notifications
You must be signed in to change notification settings - Fork 19
Description
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.
- When an error occurs after having parsed an identifier and a left parenthesis,
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. - Make a best effort to continue if an error occurs while parsing a
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:
- Created a new feature test for parsing of declarations with bounds
(parsing_bounds_var_declarations.c). This will be committed separately to the
checkedc repo. - Passes existing Checked C tests.
- Passes existing clang base line tests.