-
Notifications
You must be signed in to change notification settings - Fork 79
Parsing of member bounds declarations. #23
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 all commits
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 |
---|---|---|
|
@@ -664,9 +664,12 @@ class DeclaratorDecl : public ValueDecl { | |
DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L, | ||
DeclarationName N, QualType T, TypeSourceInfo *TInfo, | ||
SourceLocation StartL) | ||
: ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) { | ||
: ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL), | ||
Bounds(nullptr) { | ||
} | ||
|
||
BoundsExpr *Bounds; | ||
|
||
public: | ||
TypeSourceInfo *getTypeSourceInfo() const { | ||
return hasExtInfo() | ||
|
@@ -731,6 +734,28 @@ class DeclaratorDecl : public ValueDecl { | |
|
||
friend class ASTDeclReader; | ||
friend class ASTDeclWriter; | ||
|
||
// Checked C bounds information | ||
// For function declarations, this is the return bounds of the function. | ||
|
||
/// \brief Return true if this declaration has bounds declared for it. | ||
bool hasBoundsExpr() const; | ||
|
||
/// \brief The declared bounds for this declaration. For function | ||
/// declarations, this is the return bounds of the function. Null if no | ||
/// bounds have been declared. | ||
const BoundsExpr *getBoundsExpr() const { | ||
return const_cast<DeclaratorDecl *>(this)->getBoundsExpr(); | ||
} | ||
|
||
/// \brief The declared bounds for this declaration. For function | ||
/// declarations, this is the return bounds of the function. Null if no | ||
/// bounds have been declared. | ||
BoundsExpr *getBoundsExpr(); | ||
|
||
/// \brief Set the declared bounds for this declaration. For function | ||
/// declarations, this is the return bounds of the function. | ||
void setBoundsExpr(BoundsExpr *E); | ||
}; | ||
|
||
/// \brief Structure used to store a statement, the constant value to | ||
|
@@ -801,15 +826,6 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> { | |
/// C++ default argument. | ||
mutable InitType Init; | ||
|
||
// TODO: like the Init member above, it wastes space to have a pointer to a | ||
// BoundsExpr in every VarDecl when many of them won't have bounds | ||
// declarations. We could move the Init member and the Bounds to an | ||
// "extension" object that is allocated on demand, at least not increasing | ||
// the space usage of every single VarDecl. | ||
|
||
/// \brief The bounds expression for the variable, if any. | ||
BoundsExpr *Bounds; | ||
|
||
private: | ||
class VarDeclBitfields { | ||
friend class VarDecl; | ||
|
@@ -1130,21 +1146,6 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> { | |
return false; | ||
} | ||
|
||
/// \brief Return true if this variable has bounds declared for it. | ||
bool hasBoundsExpr() const; | ||
|
||
/// \brief The declared bounds for this variable. Null if no | ||
/// bounds have been declared. | ||
const BoundsExpr *getBoundsExpr() const { | ||
return const_cast<VarDecl *>(this)->getBoundsExpr(); | ||
} | ||
|
||
/// \brief The declared bounds for this variable. Null if no | ||
/// bounds have been declared. | ||
BoundsExpr *getBoundsExpr(); | ||
|
||
void setBoundsExpr(BoundsExpr *E); | ||
|
||
/// getAnyInitializer - Get the initializer for this variable, no matter which | ||
/// declaration it is attached to. | ||
const Expr *getAnyInitializer() const { | ||
|
@@ -1584,8 +1585,6 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext, | |
/// 'enum Y' in 'void f(enum Y {AA} x) {}'. | ||
ArrayRef<NamedDecl *> DeclsInPrototypeScope; | ||
|
||
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'm not sure where it would go, but it might be helpful to have a comment somewhere explain the intended meaning of 'Bounds' for FunctionDecls--that it's intended to describe the return value of the function. #Resolved 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. There are already comments on the getter functions in the superclass of FunctionDecl. These will be picked up the automatic doc generation and by IDE tool tips (for IDEs that understand /brief comments). I've add a comment to the setter function too. #Resolved |
||
BoundsExpr *ReturnBoundsExpr; | ||
|
||
LazyDeclStmtPtr Body; | ||
|
||
// FIXME: This can be packed into the bitfields in DeclContext. | ||
|
@@ -1689,7 +1688,7 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext, | |
StartLoc), | ||
DeclContext(DK), | ||
redeclarable_base(C), | ||
ParamInfo(nullptr), ReturnBoundsExpr(nullptr), Body(), | ||
ParamInfo(nullptr), Body(), | ||
SClass(S), | ||
IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified), | ||
IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false), | ||
|
@@ -2067,11 +2066,6 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext, | |
/// computed linkage of symbol, see getLinkage. | ||
StorageClass getStorageClass() const { return StorageClass(SClass); } | ||
|
||
/// \brief Returns the bounds expression for the return value of this function, if | ||
/// any. | ||
BoundsExpr *getReturnBoundsExpr() { return ReturnBoundsExpr; } | ||
void setReturnBoundsExpr(BoundsExpr *E) { ReturnBoundsExpr = E; } | ||
|
||
/// \brief Determine whether the "inline" keyword was specified for this | ||
/// function. | ||
bool isInlineSpecified() const { return IsInlineSpecified; } | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Does clang have a general standard for how to indicate that certain members in base classes may not be applicable to certain derived classes? Would it, say, be appropriate to add an assertion on setBoundsExpr() that it's only being set on an object on which it makes sense? #Resolved
Uh oh!
There was an error while loading. Please reload this page.
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.
There are only 3 subclasses of DeclaratorDecl and it makes sense to set the bounds on all of them.
#WontFix
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.
I don't there is a standard, but I've seen asserts using dynamic types that guard against the misuse of members for derived classes.
In reply to: 72876100 [](ancestors = 72876100)