-
Notifications
You must be signed in to change notification settings - Fork 79
Parse bounds declarations for function return values. #21
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1287,11 +1287,18 @@ struct DeclaratorChunk { | |
/// \brief The end location of the exception specification, if any. | ||
unsigned ExceptionSpecLocEnd; | ||
|
||
/// The location of the ':' for the return bounds expression in the source | ||
unsigned ReturnBoundsColon; | ||
|
||
/// Params - This is a pointer to a new[]'d array of ParamInfo objects that | ||
/// describe the parameters specified by this function declarator. null if | ||
/// there are no parameters specified. | ||
ParamInfo *Params; | ||
|
||
/// The bounds for the value returned by the function. Null if there is | ||
/// no bounds specified. | ||
BoundsExpr *ReturnBounds; | ||
|
||
union { | ||
/// \brief Pointer to a new[]'d array of TypeAndRange objects that | ||
/// contain the types in the function's dynamic exception specification | ||
|
@@ -1352,6 +1359,10 @@ struct DeclaratorChunk { | |
return SourceLocation::getFromRawEncoding(RParenLoc); | ||
} | ||
|
||
SourceLocation getReturnBoundsColon() const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[Nit] Ditto from above -- suggest including Loc in the name. |
||
return SourceLocation::getFromRawEncoding(ReturnBoundsColon); | ||
} | ||
|
||
SourceLocation getExceptionSpecLocBeg() const { | ||
return SourceLocation::getFromRawEncoding(ExceptionSpecLocBeg); | ||
} | ||
|
@@ -1408,6 +1419,9 @@ struct DeclaratorChunk { | |
|
||
/// \brief Get the trailing-return-type for this function declarator. | ||
ParsedType getTrailingReturnType() const { return TrailingReturnType; } | ||
|
||
/// \brief The bounds expression for the return value | ||
BoundsExpr *getReturnBounds() const { return ReturnBounds; } | ||
}; | ||
|
||
struct BlockPointerTypeInfo : TypeInfoCommon { | ||
|
@@ -1552,6 +1566,8 @@ struct DeclaratorChunk { | |
CachedTokens *ExceptionSpecTokens, | ||
SourceLocation LocalRangeBegin, | ||
SourceLocation LocalRangeEnd, | ||
SourceLocation ReturnBoundsColonLoc, | ||
BoundsExpr *ReturnBoundsExpr, | ||
Declarator &TheDeclarator, | ||
TypeResult TrailingReturnType = | ||
TypeResult()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5586,6 +5586,10 @@ void Parser::ParseParenDeclarator(Declarator &D) { | |
/// dynamic-exception-specification | ||
/// noexcept-specification | ||
/// | ||
/// For Checked C, after the parameter-list, it also parses the optional return | ||
/// bounds expression for the function declarator: | ||
/// [Checked C] ':' bounds-expression | ||
//// | ||
void Parser::ParseFunctionDeclarator(Declarator &D, | ||
ParsedAttributes &FirstArgAttrs, | ||
BalancedDelimiterTracker &Tracker, | ||
|
@@ -5626,6 +5630,8 @@ void Parser::ParseFunctionDeclarator(Declarator &D, | |
SourceLocation LParenLoc, RParenLoc; | ||
LParenLoc = Tracker.getOpenLocation(); | ||
StartLoc = LParenLoc; | ||
SourceLocation BoundsColonLoc; | ||
BoundsExpr *ReturnBoundsExpr = nullptr; | ||
|
||
if (isFunctionDeclaratorIdentifierList()) { | ||
if (RequiresArg) | ||
|
@@ -5741,6 +5747,17 @@ void Parser::ParseFunctionDeclarator(Declarator &D, | |
} | ||
} | ||
|
||
if (getLangOpts().CheckedC && Tok.is(tok::colon)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I know you called it out in the header comment for this function, but a quick brief comment calling out that this is for the return bounds expression might be nice (similar to the ones in the few code chunks directly above). |
||
BoundsColonLoc = Tok.getLocation(); | ||
ConsumeToken(); | ||
ExprResult BoundsExprResult = ParseBoundsExpression(); | ||
if (BoundsExprResult.isInvalid()) { | ||
ReturnBoundsExpr = Actions.CreateInvalidBoundsExpr(); | ||
SkipUntil(tok::l_brace, SkipUntilFlags::StopAtSemi | SkipUntilFlags::StopBeforeMatch); | ||
} else | ||
ReturnBoundsExpr = cast<BoundsExpr>(BoundsExprResult.get()); | ||
} | ||
|
||
// Remember that we parsed a function type, and remember the attributes. | ||
D.AddTypeInfo(DeclaratorChunk::getFunction(HasProto, | ||
IsAmbiguous, | ||
|
@@ -5760,7 +5777,9 @@ void Parser::ParseFunctionDeclarator(Declarator &D, | |
NoexceptExpr.isUsable() ? | ||
NoexceptExpr.get() : nullptr, | ||
ExceptionSpecTokens, | ||
StartLoc, LocalEndLoc, D, | ||
StartLoc, LocalEndLoc, | ||
BoundsColonLoc, ReturnBoundsExpr, | ||
D, | ||
TrailingReturnType), | ||
FnAttrs, EndLoc); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Nit] I'd suggest including 'Loc' in the name to make it clear that this is a location.