mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Allow variables with a getter or setter to be declared in a
struct/oneof/class extension, making them instance methods. Normal variables are still not allowed in these contexts, however. The fact that we set DeclContexts late causes some consternation here, because it's not clear just how far we need to recurse in DeclContext. I've done enough to make properties work, but I'm still rather uneasy about the current state of affairs. Swift SVN r1423
This commit is contained in:
@@ -104,7 +104,7 @@ public:
|
||||
DeclKind getKind() const { return DeclKind(DeclBits.Kind); }
|
||||
|
||||
DeclContext *getDeclContext() const { return Context; }
|
||||
void setDeclContext(DeclContext *DC) { Context = DC; }
|
||||
void setDeclContext(DeclContext *DC);
|
||||
|
||||
/// getASTContext - Return the ASTContext that this decl lives in.
|
||||
ASTContext &getASTContext() const {
|
||||
@@ -218,6 +218,12 @@ class PatternBindingDecl : public Decl {
|
||||
Pattern *Pat; // The pattern which this decl binds
|
||||
Expr *Init; // Initializer for the variables
|
||||
|
||||
friend class Decl;
|
||||
|
||||
/// \brief Update the DeclContext for any variables in the pattern to
|
||||
/// refer to the same DeclContext as this declaration.
|
||||
void updateDeclContextForVars();
|
||||
|
||||
public:
|
||||
PatternBindingDecl(SourceLoc VarLoc, Pattern *Pat, Expr *E,
|
||||
DeclContext *Parent)
|
||||
@@ -425,6 +431,9 @@ private:
|
||||
|
||||
GetSetRecord *GetSet;
|
||||
|
||||
friend class Decl;
|
||||
void updateDeclContextForGetSet();
|
||||
|
||||
public:
|
||||
VarDecl(SourceLoc VarLoc, Identifier Name, Type Ty, DeclContext *DC,
|
||||
bool IsModuleScope)
|
||||
@@ -540,6 +549,14 @@ public:
|
||||
|
||||
};
|
||||
|
||||
inline void Decl::setDeclContext(DeclContext *DC) {
|
||||
Context = DC;
|
||||
if (PatternBindingDecl *PBD = dyn_cast<PatternBindingDecl>(this))
|
||||
PBD->updateDeclContextForVars();
|
||||
else if (VarDecl *Var = dyn_cast<VarDecl>(this))
|
||||
Var->updateDeclContextForGetSet();
|
||||
}
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user