Early-exitify ClangASTContext::AddObjCClassProperty() (NFC)

This commit is contained in:
Adrian Prantl 2019-11-21 15:40:50 -08:00
parent 7bf721e59c
commit bc8e88e974
1 changed files with 146 additions and 162 deletions

View File

@ -8339,8 +8339,9 @@ bool ClangASTContext::AddObjCClassProperty(
clang::ASTContext *clang_ast = ast->getASTContext(); clang::ASTContext *clang_ast = ast->getASTContext();
clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type);
if (!class_interface_decl)
return false;
if (class_interface_decl) {
CompilerType property_clang_type_to_access; CompilerType property_clang_type_to_access;
if (property_clang_type.IsValid()) if (property_clang_type.IsValid())
@ -8349,7 +8350,9 @@ bool ClangASTContext::AddObjCClassProperty(
property_clang_type_to_access = property_clang_type_to_access =
CompilerType(ast, ivar_decl->getType().getAsOpaquePtr()); CompilerType(ast, ivar_decl->getType().getAsOpaquePtr());
if (class_interface_decl && property_clang_type_to_access.IsValid()) { if (!class_interface_decl || !property_clang_type_to_access.IsValid())
return false;
clang::TypeSourceInfo *prop_type_source; clang::TypeSourceInfo *prop_type_source;
if (ivar_decl) if (ivar_decl)
prop_type_source = prop_type_source =
@ -8368,7 +8371,9 @@ bool ClangASTContext::AddObjCClassProperty(
: ClangUtil::GetQualType(property_clang_type), : ClangUtil::GetQualType(property_clang_type),
prop_type_source); prop_type_source);
if (property_decl) { if (!property_decl)
return false;
if (metadata) if (metadata)
ClangASTContext::SetMetadata(clang_ast, property_decl, *metadata); ClangASTContext::SetMetadata(clang_ast, property_decl, *metadata);
@ -8376,9 +8381,9 @@ bool ClangASTContext::AddObjCClassProperty(
clang::Selector setter_sel, getter_sel; clang::Selector setter_sel, getter_sel;
if (property_setter_name != nullptr) { if (property_setter_name) {
std::string property_setter_no_colon( std::string property_setter_no_colon(property_setter_name,
property_setter_name, strlen(property_setter_name) - 1); strlen(property_setter_name) - 1);
clang::IdentifierInfo *setter_ident = clang::IdentifierInfo *setter_ident =
&clang_ast->Idents.get(property_setter_no_colon); &clang_ast->Idents.get(property_setter_no_colon);
setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident);
@ -8391,60 +8396,47 @@ bool ClangASTContext::AddObjCClassProperty(
setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident);
} }
property_decl->setSetterName(setter_sel); property_decl->setSetterName(setter_sel);
property_decl->setPropertyAttributes( property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter);
clang::ObjCPropertyDecl::OBJC_PR_setter);
if (property_getter_name != nullptr) { if (property_getter_name != nullptr) {
clang::IdentifierInfo *getter_ident = clang::IdentifierInfo *getter_ident =
&clang_ast->Idents.get(property_getter_name); &clang_ast->Idents.get(property_getter_name);
getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident);
} else { } else {
clang::IdentifierInfo *getter_ident = clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_name);
&clang_ast->Idents.get(property_name);
getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident);
} }
property_decl->setGetterName(getter_sel); property_decl->setGetterName(getter_sel);
property_decl->setPropertyAttributes( property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter);
clang::ObjCPropertyDecl::OBJC_PR_getter);
if (ivar_decl) if (ivar_decl)
property_decl->setPropertyIvarDecl(ivar_decl); property_decl->setPropertyIvarDecl(ivar_decl);
if (property_attributes & DW_APPLE_PROPERTY_readonly) if (property_attributes & DW_APPLE_PROPERTY_readonly)
property_decl->setPropertyAttributes( property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
clang::ObjCPropertyDecl::OBJC_PR_readonly);
if (property_attributes & DW_APPLE_PROPERTY_readwrite) if (property_attributes & DW_APPLE_PROPERTY_readwrite)
property_decl->setPropertyAttributes( property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite);
clang::ObjCPropertyDecl::OBJC_PR_readwrite);
if (property_attributes & DW_APPLE_PROPERTY_assign) if (property_attributes & DW_APPLE_PROPERTY_assign)
property_decl->setPropertyAttributes( property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
clang::ObjCPropertyDecl::OBJC_PR_assign);
if (property_attributes & DW_APPLE_PROPERTY_retain) if (property_attributes & DW_APPLE_PROPERTY_retain)
property_decl->setPropertyAttributes( property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain);
clang::ObjCPropertyDecl::OBJC_PR_retain);
if (property_attributes & DW_APPLE_PROPERTY_copy) if (property_attributes & DW_APPLE_PROPERTY_copy)
property_decl->setPropertyAttributes( property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
clang::ObjCPropertyDecl::OBJC_PR_copy);
if (property_attributes & DW_APPLE_PROPERTY_nonatomic) if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic);
if (property_attributes & ObjCPropertyDecl::OBJC_PR_nullability)
property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nullability);
if (property_attributes & ObjCPropertyDecl::OBJC_PR_null_resettable)
property_decl->setPropertyAttributes( property_decl->setPropertyAttributes(
clang::ObjCPropertyDecl::OBJC_PR_nonatomic); ObjCPropertyDecl::OBJC_PR_null_resettable);
if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_nullability) if (property_attributes & ObjCPropertyDecl::OBJC_PR_class)
property_decl->setPropertyAttributes( property_decl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_class);
clang::ObjCPropertyDecl::OBJC_PR_nullability);
if (property_attributes &
clang::ObjCPropertyDecl::OBJC_PR_null_resettable)
property_decl->setPropertyAttributes(
clang::ObjCPropertyDecl::OBJC_PR_null_resettable);
if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class)
property_decl->setPropertyAttributes(
clang::ObjCPropertyDecl::OBJC_PR_class);
const bool isInstance = const bool isInstance =
(property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class) == 0; (property_attributes & ObjCPropertyDecl::OBJC_PR_class) == 0;
if (!getter_sel.isNull() && if (!getter_sel.isNull() &&
!(isInstance !(isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
? class_interface_decl->lookupInstanceMethod(getter_sel)
: class_interface_decl->lookupClassMethod(getter_sel))) { : class_interface_decl->lookupClassMethod(getter_sel))) {
const bool isVariadic = false; const bool isVariadic = false;
const bool isPropertyAccessor = false; const bool isPropertyAccessor = false;
@ -8459,9 +8451,8 @@ bool ClangASTContext::AddObjCClassProperty(
*clang_ast, clang::SourceLocation(), clang::SourceLocation(), *clang_ast, clang::SourceLocation(), clang::SourceLocation(),
getter_sel, ClangUtil::GetQualType(property_clang_type_to_access), getter_sel, ClangUtil::GetQualType(property_clang_type_to_access),
nullptr, class_interface_decl, isInstance, isVariadic, nullptr, class_interface_decl, isInstance, isVariadic,
isPropertyAccessor, isSynthesizedAccessorStub, isPropertyAccessor, isSynthesizedAccessorStub, isImplicitlyDeclared,
isImplicitlyDeclared, isDefined, impControl, isDefined, impControl, HasRelatedResultType);
HasRelatedResultType);
if (getter && metadata) if (getter && metadata)
ClangASTContext::SetMetadata(clang_ast, getter, *metadata); ClangASTContext::SetMetadata(clang_ast, getter, *metadata);
@ -8476,8 +8467,7 @@ bool ClangASTContext::AddObjCClassProperty(
} }
if (!setter_sel.isNull() && if (!setter_sel.isNull() &&
!(isInstance !(isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
? class_interface_decl->lookupInstanceMethod(setter_sel)
: class_interface_decl->lookupClassMethod(setter_sel))) { : class_interface_decl->lookupClassMethod(setter_sel))) {
clang::QualType result_type = clang_ast->VoidTy; clang::QualType result_type = clang_ast->VoidTy;
const bool isVariadic = false; const bool isVariadic = false;
@ -8491,10 +8481,9 @@ bool ClangASTContext::AddObjCClassProperty(
clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create( clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create(
*clang_ast, clang::SourceLocation(), clang::SourceLocation(), *clang_ast, clang::SourceLocation(), clang::SourceLocation(),
setter_sel, result_type, nullptr, class_interface_decl, setter_sel, result_type, nullptr, class_interface_decl, isInstance,
isInstance, isVariadic, isPropertyAccessor, isVariadic, isPropertyAccessor, isSynthesizedAccessorStub,
isSynthesizedAccessorStub, isImplicitlyDeclared, isDefined, isImplicitlyDeclared, isDefined, impControl, HasRelatedResultType);
impControl, HasRelatedResultType);
if (setter && metadata) if (setter && metadata)
ClangASTContext::SetMetadata(clang_ast, setter, *metadata); ClangASTContext::SetMetadata(clang_ast, setter, *metadata);
@ -8502,15 +8491,14 @@ bool ClangASTContext::AddObjCClassProperty(
llvm::SmallVector<clang::ParmVarDecl *, 1> params; llvm::SmallVector<clang::ParmVarDecl *, 1> params;
params.push_back(clang::ParmVarDecl::Create( params.push_back(clang::ParmVarDecl::Create(
*clang_ast, setter, clang::SourceLocation(), *clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
clang::SourceLocation(),
nullptr, // anonymous nullptr, // anonymous
ClangUtil::GetQualType(property_clang_type_to_access), nullptr, ClangUtil::GetQualType(property_clang_type_to_access), nullptr,
clang::SC_Auto, nullptr)); clang::SC_Auto, nullptr));
if (setter) { if (setter) {
setter->setMethodParams( setter->setMethodParams(*clang_ast,
*clang_ast, llvm::ArrayRef<clang::ParmVarDecl *>(params), llvm::ArrayRef<clang::ParmVarDecl *>(params),
llvm::ArrayRef<clang::SourceLocation>()); llvm::ArrayRef<clang::SourceLocation>());
class_interface_decl->addDecl(setter); class_interface_decl->addDecl(setter);
@ -8519,10 +8507,6 @@ bool ClangASTContext::AddObjCClassProperty(
return true; return true;
} }
}
}
return false;
}
bool ClangASTContext::IsObjCClassTypeAndHasIVars(const CompilerType &type, bool ClangASTContext::IsObjCClassTypeAndHasIVars(const CompilerType &type,
bool check_superclass) { bool check_superclass) {