//===--- SemaDeclAttr.cpp - Declaration Attribute Handling ----------------===////// The LLVM Compiler Infrastructure//// This file is distributed under the University of Illinois Open Source// License. See LICENSE.TXT for details.////===----------------------------------------------------------------------===////// This file implements decl-related attribute processing.////===----------------------------------------------------------------------===//#include"Sema.h"#include"clang/AST/ASTContext.h"#include"clang/AST/DeclObjC.h"#include"clang/AST/Expr.h"#include"clang/Basic/Diagnostic.h"#include"clang/Basic/TargetInfo.h"#include"clang/Parse/DeclSpec.h"#include<llvm/ADT/StringExtras.h>usingnamespaceclang;//===----------------------------------------------------------------------===//// Helper functions//===----------------------------------------------------------------------===//staticconstFunctionType*getFunctionType(Decl*d){QualTypeTy;if(ValueDecl*decl=dyn_cast<ValueDecl>(d))Ty=decl->getType();elseif(FieldDecl*decl=dyn_cast<FieldDecl>(d))Ty=decl->getType();elseif(TypedefDecl*decl=dyn_cast<TypedefDecl>(d))Ty=decl->getUnderlyingType();elsereturn0;if(Ty->isFunctionPointerType())Ty=Ty->getAsPointerType()->getPointeeType();returnTy->getAsFunctionType();}// FIXME: We should provide an abstraction around a method or function// to provide the following bits of information./// isFunctionOrMethod - Return true if the given decl has function/// type (function or function-typed variable) or an Objective-C/// method.staticboolisFunctionOrMethod(Decl*d){returngetFunctionType(d)||isa<ObjCMethodDecl>(d);}/// hasFunctionProto - Return true if the given decl has a argument/// information. This decl should have already passed/// isFunctionOrMethod.staticboolhasFunctionProto(Decl*d){if(constFunctionType*FnTy=getFunctionType(d)){returnisa<FunctionTypeProto>(FnTy);}else{assert(isa<ObjCMethodDecl>(d));returntrue;}}/// getFunctionOrMethodNumArgs - Return number of function or method/// arguments. It is an error to call this on a K&R function (use/// hasFunctionProto first).staticunsignedgetFunctionOrMethodNumArgs(Decl*d){if(constFunctionType*FnTy=getFunctionType(d)){constFunctionTypeProto*proto=cast<FunctionTypeProto>(FnTy);returnproto->getNumArgs();}else{returncast<ObjCMethodDecl>(d)->getNumParams();}}staticQualTypegetFunctionOrMethodArgType(Decl*d,unsignedIdx){if(constFunctionType*FnTy=getFunctionType(d)){constFunctionTypeProto*proto=cast<FunctionTypeProto>(FnTy);returnproto->getArgType(Idx);