forked from OSchip/llvm-project
AST generation for objc2's property declarations.
llvm-svn: 49565
This commit is contained in:
parent
8784a7c006
commit
4572b45574
|
@ -320,7 +320,7 @@ void DeclPrinter::PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
|
||||||
ObjCPropertyDecl::propdecl_iterator
|
ObjCPropertyDecl::propdecl_iterator
|
||||||
I = PDecl->propdecl_begin(), E = PDecl->propdecl_end();
|
I = PDecl->propdecl_begin(), E = PDecl->propdecl_end();
|
||||||
|
|
||||||
Out << ' ' << (*I)->getType().getAsString()
|
Out << ' ' << PDecl->getType().getAsString()
|
||||||
<< ' ' << (*I)->getName();
|
<< ' ' << (*I)->getName();
|
||||||
|
|
||||||
for (++I; I != E; ++I)
|
for (++I; I != E; ++I)
|
||||||
|
|
|
@ -27,6 +27,7 @@ class ObjCMethodDecl;
|
||||||
class ObjCProtocolDecl;
|
class ObjCProtocolDecl;
|
||||||
class ObjCCategoryDecl;
|
class ObjCCategoryDecl;
|
||||||
class ObjCPropertyDecl;
|
class ObjCPropertyDecl;
|
||||||
|
class FieldDeclarator;
|
||||||
|
|
||||||
/// ObjCMethodDecl - Represents an instance or class method declaration.
|
/// ObjCMethodDecl - Represents an instance or class method declaration.
|
||||||
/// ObjC methods can be declared within 4 contexts: class interfaces,
|
/// ObjC methods can be declared within 4 contexts: class interfaces,
|
||||||
|
@ -833,7 +834,7 @@ public:
|
||||||
/// from the class interface to the class implementation (but I digress:-)
|
/// from the class interface to the class implementation (but I digress:-)
|
||||||
///
|
///
|
||||||
class ObjCImplementationDecl : public NamedDecl {
|
class ObjCImplementationDecl : public NamedDecl {
|
||||||
/// Class interface for this category implementation
|
/// Class interface for this implementation
|
||||||
ObjCInterfaceDecl *ClassInterface;
|
ObjCInterfaceDecl *ClassInterface;
|
||||||
|
|
||||||
/// Implementation Class's super class.
|
/// Implementation Class's super class.
|
||||||
|
@ -954,33 +955,32 @@ public:
|
||||||
OBJC_PR_setter = 0x80
|
OBJC_PR_setter = 0x80
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
|
QualType DeclType;
|
||||||
// List of property name declarations
|
// List of property name declarations
|
||||||
// FIXME: Property is not an ivar.
|
NamedDecl **PropertyDecls;
|
||||||
ObjCIvarDecl **PropertyDecls;
|
|
||||||
unsigned NumPropertyDecls;
|
unsigned NumPropertyDecls;
|
||||||
unsigned PropertyAttributes : 8;
|
unsigned PropertyAttributes : 8;
|
||||||
|
|
||||||
IdentifierInfo *GetterName; // getter name of NULL if no getter
|
IdentifierInfo *GetterName; // getter name of NULL if no getter
|
||||||
IdentifierInfo *SetterName; // setter name of NULL if no setter
|
IdentifierInfo *SetterName; // setter name of NULL if no setter
|
||||||
|
|
||||||
ObjCPropertyDecl(SourceLocation L)
|
ObjCPropertyDecl(SourceLocation L, QualType T)
|
||||||
: Decl(ObjCProperty, L), PropertyDecls(0), NumPropertyDecls(0),
|
: Decl(ObjCProperty, L), DeclType(T),
|
||||||
|
PropertyDecls(0), NumPropertyDecls(0),
|
||||||
PropertyAttributes(OBJC_PR_noattr), GetterName(0), SetterName(0) {}
|
PropertyAttributes(OBJC_PR_noattr), GetterName(0), SetterName(0) {}
|
||||||
public:
|
public:
|
||||||
static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L);
|
static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L, QualType T);
|
||||||
|
QualType getType() const { return DeclType; }
|
||||||
typedef ObjCIvarDecl * const *propdecl_iterator;
|
typedef NamedDecl * const *propdecl_iterator;
|
||||||
propdecl_iterator propdecl_begin() const { return PropertyDecls; }
|
propdecl_iterator propdecl_begin() const { return PropertyDecls; }
|
||||||
propdecl_iterator propdecl_end() const {
|
propdecl_iterator propdecl_end() const {
|
||||||
return PropertyDecls+NumPropertyDecls;
|
return PropertyDecls+NumPropertyDecls;
|
||||||
}
|
}
|
||||||
unsigned propdecl_size() const { return NumPropertyDecls; }
|
unsigned propdecl_size() const { return NumPropertyDecls; }
|
||||||
bool propdecl_empty() const { return NumPropertyDecls == 0; }
|
bool propdecl_empty() const { return NumPropertyDecls == 0; }
|
||||||
|
NamedDecl **getPropertyDecls() { return PropertyDecls; }
|
||||||
/// setPropertyDeclLists - Set the property decl list to the specified array
|
void setNumPropertyDecls(unsigned num) { NumPropertyDecls = num; }
|
||||||
/// of decls.
|
void setPropertyDecls(NamedDecl **Nd) { PropertyDecls = Nd; }
|
||||||
void setPropertyDeclLists(ObjCIvarDecl **Properties, unsigned NumProp);
|
|
||||||
|
|
||||||
PropertyAttributeKind getPropertyAttributes() const {
|
PropertyAttributeKind getPropertyAttributes() const {
|
||||||
return PropertyAttributeKind(PropertyAttributes);
|
return PropertyAttributeKind(PropertyAttributes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace clang {
|
||||||
class ObjCDeclSpec;
|
class ObjCDeclSpec;
|
||||||
class Declarator;
|
class Declarator;
|
||||||
class AttributeList;
|
class AttributeList;
|
||||||
|
class FieldDeclarator;
|
||||||
// Parse.
|
// Parse.
|
||||||
class Scope;
|
class Scope;
|
||||||
class Action;
|
class Action;
|
||||||
|
@ -648,8 +649,9 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// ActOnAddObjCProperties - called to build one property AST
|
// ActOnAddObjCProperties - called to build one property AST
|
||||||
virtual DeclTy *ActOnAddObjCProperties (SourceLocation AtLoc,
|
virtual DeclTy *ActOnAddObjCProperties (Scope *S, SourceLocation AtLoc,
|
||||||
DeclTy **allProperties, unsigned NumProperties, ObjCDeclSpec &DS) {
|
FieldDeclarator *PropertyDeclarators, unsigned NumPropertyDeclarators,
|
||||||
|
ObjCDeclSpec &ODS) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,9 +110,10 @@ ObjCCompatibleAliasDecl::Create(ASTContext &C,
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C,
|
ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C,
|
||||||
SourceLocation L) {
|
SourceLocation L,
|
||||||
|
QualType T) {
|
||||||
void *Mem = C.getAllocator().Allocate<ObjCPropertyDecl>();
|
void *Mem = C.getAllocator().Allocate<ObjCPropertyDecl>();
|
||||||
return new (Mem) ObjCPropertyDecl(L);
|
return new (Mem) ObjCPropertyDecl(L, T);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -432,15 +433,5 @@ ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjCPropertyDecl::setPropertyDeclLists(ObjCIvarDecl **Properties,
|
|
||||||
unsigned NumProp) {
|
|
||||||
assert(PropertyDecls == 0 && "Properties already set");
|
|
||||||
if (NumProp == 0) return;
|
|
||||||
NumPropertyDecls = NumProp;
|
|
||||||
|
|
||||||
PropertyDecls = new ObjCIvarDecl*[NumProp];
|
|
||||||
memcpy(PropertyDecls, Properties, NumProp*sizeof(ObjCIvarDecl*));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -392,26 +392,15 @@ Parser::DeclTy *Parser::ParseObjCPropertyDecl(DeclTy *interfaceDecl,
|
||||||
DeclSpec DS;
|
DeclSpec DS;
|
||||||
llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators;
|
llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators;
|
||||||
ParseStructDeclaration(DS, FieldDeclarators);
|
ParseStructDeclaration(DS, FieldDeclarators);
|
||||||
|
|
||||||
// Convert them all to fields.
|
|
||||||
for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) {
|
|
||||||
FieldDeclarator &FD = FieldDeclarators[i];
|
|
||||||
// Install the declarator into interfaceDecl.
|
|
||||||
DeclTy *Field = Actions.ActOnIvar(CurScope,
|
|
||||||
DS.getSourceRange().getBegin(),
|
|
||||||
FD.D, FD.BitfieldSize,
|
|
||||||
tok::objc_not_keyword);
|
|
||||||
PropertyDecls.push_back(Field);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Tok.is(tok::semi))
|
if (Tok.is(tok::semi))
|
||||||
ConsumeToken();
|
ConsumeToken();
|
||||||
else {
|
else {
|
||||||
Diag(Tok, diag::err_expected_semi_decl_list);
|
Diag(Tok, diag::err_expected_semi_decl_list);
|
||||||
SkipUntil(tok::r_brace, true, true);
|
SkipUntil(tok::r_brace, true, true);
|
||||||
}
|
}
|
||||||
return Actions.ActOnAddObjCProperties(AtLoc, &PropertyDecls[0],
|
return Actions.ActOnAddObjCProperties(CurScope, AtLoc, &FieldDeclarators[0],
|
||||||
PropertyDecls.size(), OCDS);
|
FieldDeclarators.size(), OCDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// objc-method-proto:
|
/// objc-method-proto:
|
||||||
|
|
|
@ -643,11 +643,10 @@ public:
|
||||||
DeclTy **allMethods = 0, unsigned allNum = 0,
|
DeclTy **allMethods = 0, unsigned allNum = 0,
|
||||||
DeclTy **allProperties = 0, unsigned pNum = 0);
|
DeclTy **allProperties = 0, unsigned pNum = 0);
|
||||||
|
|
||||||
virtual DeclTy *ActOnAddObjCProperties(SourceLocation AtLoc,
|
virtual DeclTy *ActOnAddObjCProperties(Scope *S, SourceLocation AtLoc,
|
||||||
DeclTy **allProperties,
|
FieldDeclarator *allProperties,
|
||||||
unsigned NumProperties,
|
unsigned NumProperties,
|
||||||
ObjCDeclSpec &DS);
|
ObjCDeclSpec &ODS);
|
||||||
|
|
||||||
virtual DeclTy *ActOnMethodDeclaration(
|
virtual DeclTy *ActOnMethodDeclaration(
|
||||||
SourceLocation BeginLoc, // location of the + or -.
|
SourceLocation BeginLoc, // location of the + or -.
|
||||||
SourceLocation EndLoc, // location of the ; or {.
|
SourceLocation EndLoc, // location of the ; or {.
|
||||||
|
|
|
@ -886,43 +886,52 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration(
|
||||||
return ObjCMethod;
|
return ObjCMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sema::DeclTy *Sema::ActOnAddObjCProperties(SourceLocation AtLoc,
|
Sema::DeclTy *Sema::ActOnAddObjCProperties(Scope *S, SourceLocation AtLoc,
|
||||||
DeclTy **allProperties,
|
FieldDeclarator *propertyDeclarators,
|
||||||
unsigned NumProperties,
|
unsigned NumPropertyDeclarators,
|
||||||
ObjCDeclSpec &DS) {
|
ObjCDeclSpec &ODS) {
|
||||||
ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc);
|
FieldDeclarator &FD = propertyDeclarators[0];
|
||||||
|
QualType T = GetTypeForDeclarator(FD.D, S);
|
||||||
|
ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc, T);
|
||||||
|
|
||||||
if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readonly)
|
if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readonly)
|
||||||
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
|
||||||
|
|
||||||
if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_getter) {
|
if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_getter) {
|
||||||
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter);
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter);
|
||||||
PDecl->setGetterName(DS.getGetterName());
|
PDecl->setGetterName(ODS.getGetterName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_setter) {
|
if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_setter) {
|
||||||
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter);
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter);
|
||||||
PDecl->setSetterName(DS.getSetterName());
|
PDecl->setSetterName(ODS.getSetterName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_assign)
|
if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_assign)
|
||||||
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
|
||||||
|
|
||||||
if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readwrite)
|
if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readwrite)
|
||||||
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite);
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite);
|
||||||
|
|
||||||
if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_retain)
|
if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_retain)
|
||||||
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain);
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain);
|
||||||
|
|
||||||
if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_copy)
|
if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_copy)
|
||||||
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
|
||||||
|
|
||||||
if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nonatomic)
|
if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nonatomic)
|
||||||
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic);
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic);
|
||||||
|
|
||||||
if (NumProperties != 0)
|
if (NumPropertyDeclarators != 0) {
|
||||||
PDecl->setPropertyDeclLists((ObjCIvarDecl**)allProperties, NumProperties);
|
NamedDecl **propertyName = new NamedDecl*[NumPropertyDeclarators];
|
||||||
|
PDecl->setPropertyDecls(propertyName);
|
||||||
|
PDecl->setNumPropertyDecls(NumPropertyDeclarators);
|
||||||
|
for (unsigned i = 0; i < NumPropertyDeclarators; i++) {
|
||||||
|
Declarator &D = propertyDeclarators[i].D;
|
||||||
|
propertyName[i] = new NamedDecl(Decl::ObjCProperty,
|
||||||
|
D.getIdentifierLoc(), D.getIdentifier());
|
||||||
|
}
|
||||||
|
}
|
||||||
return PDecl;
|
return PDecl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue