Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- Sema.cpp - AST Builder and Semantic Analysis Implementation ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the actions class which performs semantic analysis and |
| 11 | // builds an AST out of a parse stream. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "Sema.h" |
| 16 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | 64789f8 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
Daniel Dunbar | de30073 | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 19 | #include "clang/Lex/Preprocessor.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Chris Lattner | da5c087 | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 22 | /// ConvertQualTypeToStringFn - This function is used to pretty print the |
| 23 | /// specified QualType as a string in diagnostics. |
Chris Lattner | 254de7d | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 24 | static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, |
Chris Lattner | 2bd4a5a | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 25 | const char *Modifier, unsigned ModLen, |
| 26 | const char *Argument, unsigned ArgLen, |
Chris Lattner | 0b53af2 | 2009-02-19 23:53:20 +0000 | [diff] [blame] | 27 | llvm::SmallVectorImpl<char> &Output, |
| 28 | void *Cookie) { |
| 29 | ASTContext &Context = *static_cast<ASTContext*>(Cookie); |
Chris Lattner | f5b269a | 2008-11-23 09:21:17 +0000 | [diff] [blame] | 30 | |
Chris Lattner | 254de7d | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 31 | std::string S; |
| 32 | if (Kind == Diagnostic::ak_qualtype) { |
Chris Lattner | 2bd4a5a | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 33 | assert(ModLen == 0 && ArgLen == 0 && |
| 34 | "Invalid modifier for QualType argument"); |
| 35 | |
Chris Lattner | 254de7d | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 36 | QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast<void*>(Val))); |
Chris Lattner | 3a8f294 | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 37 | |
Chris Lattner | 254de7d | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 38 | // FIXME: Playing with std::string is really slow. |
| 39 | S = Ty.getAsString(); |
Chris Lattner | 2bd4a5a | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 40 | |
| 41 | // If this is a sugared type (like a typedef, typeof, etc), then unwrap one |
| 42 | // level of the sugar so that the type is more obvious to the user. |
| 43 | QualType DesugaredTy = Ty->getDesugaredType(); |
| 44 | DesugaredTy.setCVRQualifiers(DesugaredTy.getCVRQualifiers() | |
| 45 | Ty.getCVRQualifiers()); |
Chris Lattner | 3a8f294 | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 2bd4a5a | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 47 | if (Ty != DesugaredTy && |
| 48 | // If the desugared type is a vector type, we don't want to expand it, |
| 49 | // it will turn into an attribute mess. People want their "vec4". |
| 50 | !isa<VectorType>(DesugaredTy) && |
| 51 | |
Chris Lattner | 0b53af2 | 2009-02-19 23:53:20 +0000 | [diff] [blame] | 52 | // Don't desugar magic Objective-C types. |
| 53 | Ty.getUnqualifiedType() != Context.getObjCIdType() && |
| 54 | Ty.getUnqualifiedType() != Context.getObjCSelType() && |
| 55 | Ty.getUnqualifiedType() != Context.getObjCProtoType() && |
| 56 | Ty.getUnqualifiedType() != Context.getObjCClassType() && |
| 57 | |
| 58 | // Not va_list. |
| 59 | Ty.getUnqualifiedType() != Context.getBuiltinVaListType()) { |
Chris Lattner | 2bd4a5a | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 60 | S = "'"+S+"' (aka '"; |
| 61 | S += DesugaredTy.getAsString(); |
| 62 | S += "')"; |
| 63 | Output.append(S.begin(), S.end()); |
| 64 | return; |
| 65 | } |
Chris Lattner | 3a8f294 | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 66 | |
Douglas Gregor | 09be81b | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 67 | } else if (Kind == Diagnostic::ak_declarationname) { |
Chris Lattner | 254de7d | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 68 | |
| 69 | DeclarationName N = DeclarationName::getFromOpaqueInteger(Val); |
| 70 | S = N.getAsString(); |
Chris Lattner | 3a8f294 | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 71 | |
| 72 | if (ModLen == 9 && !memcmp(Modifier, "objcclass", 9) && ArgLen == 0) |
| 73 | S = '+' + S; |
| 74 | else if (ModLen == 12 && !memcmp(Modifier, "objcinstance", 12) && ArgLen==0) |
| 75 | S = '-' + S; |
| 76 | else |
| 77 | assert(ModLen == 0 && ArgLen == 0 && |
| 78 | "Invalid modifier for DeclarationName argument"); |
Douglas Gregor | 09be81b | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 79 | } else { |
| 80 | assert(Kind == Diagnostic::ak_nameddecl); |
Douglas Gregor | be69b16 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 81 | if (ModLen == 1 && Modifier[0] == 'q' && ArgLen == 0) |
| 82 | S = reinterpret_cast<NamedDecl*>(Val)->getQualifiedNameAsString(); |
| 83 | else { |
| 84 | assert(ModLen == 0 && ArgLen == 0 && |
Douglas Gregor | 09be81b | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 85 | "Invalid modifier for NamedDecl* argument"); |
Douglas Gregor | be69b16 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 86 | S = reinterpret_cast<NamedDecl*>(Val)->getNameAsString(); |
| 87 | } |
Chris Lattner | 254de7d | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 88 | } |
Chris Lattner | 2bd4a5a | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 89 | |
| 90 | Output.push_back('\''); |
Chris Lattner | da5c087 | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 91 | Output.append(S.begin(), S.end()); |
Chris Lattner | 2bd4a5a | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 92 | Output.push_back('\''); |
Chris Lattner | da5c087 | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | |
Chris Lattner | 6948ae6 | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 96 | static inline RecordDecl *CreateStructDecl(ASTContext &C, const char *Name) { |
Anders Carlsson | 8930fb5 | 2008-08-23 22:20:38 +0000 | [diff] [blame] | 97 | if (C.getLangOptions().CPlusPlus) |
| 98 | return CXXRecordDecl::Create(C, TagDecl::TK_struct, |
| 99 | C.getTranslationUnitDecl(), |
Ted Kremenek | 2c98404 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 100 | SourceLocation(), &C.Idents.get(Name)); |
Chris Lattner | 8ba580c | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 101 | |
| 102 | return RecordDecl::Create(C, TagDecl::TK_struct, |
| 103 | C.getTranslationUnitDecl(), |
| 104 | SourceLocation(), &C.Idents.get(Name)); |
Anders Carlsson | 8930fb5 | 2008-08-23 22:20:38 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Steve Naroff | 9637a9b | 2007-10-09 22:01:59 +0000 | [diff] [blame] | 107 | void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { |
| 108 | TUScope = S; |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 109 | PushDeclContext(S, Context.getTranslationUnitDecl()); |
Chris Lattner | a8c2d59 | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 110 | if (!PP.getLangOptions().ObjC1) return; |
| 111 | |
Steve Naroff | 8f635e0 | 2008-02-24 16:25:02 +0000 | [diff] [blame] | 112 | // Synthesize "typedef struct objc_selector *SEL;" |
Anders Carlsson | 8930fb5 | 2008-08-23 22:20:38 +0000 | [diff] [blame] | 113 | RecordDecl *SelTag = CreateStructDecl(Context, "objc_selector"); |
Argiris Kirtzidis | 951f25b | 2008-04-12 00:47:19 +0000 | [diff] [blame] | 114 | PushOnScopeChains(SelTag, TUScope); |
Steve Naroff | 8f635e0 | 2008-02-24 16:25:02 +0000 | [diff] [blame] | 115 | |
| 116 | QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag)); |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 117 | TypedefDecl *SelTypedef = TypedefDecl::Create(Context, CurContext, |
| 118 | SourceLocation(), |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 119 | &Context.Idents.get("SEL"), |
Douglas Gregor | af8ad2b | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 120 | SelT); |
Argiris Kirtzidis | 951f25b | 2008-04-12 00:47:19 +0000 | [diff] [blame] | 121 | PushOnScopeChains(SelTypedef, TUScope); |
Steve Naroff | 8f635e0 | 2008-02-24 16:25:02 +0000 | [diff] [blame] | 122 | Context.setObjCSelType(SelTypedef); |
Chris Lattner | 4e9553a | 2008-06-21 20:20:39 +0000 | [diff] [blame] | 123 | |
Chris Lattner | 1062d3a | 2008-06-21 22:44:51 +0000 | [diff] [blame] | 124 | // FIXME: Make sure these don't leak! |
Anders Carlsson | 8930fb5 | 2008-08-23 22:20:38 +0000 | [diff] [blame] | 125 | RecordDecl *ClassTag = CreateStructDecl(Context, "objc_class"); |
Chris Lattner | 4e9553a | 2008-06-21 20:20:39 +0000 | [diff] [blame] | 126 | QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag)); |
| 127 | TypedefDecl *ClassTypedef = |
| 128 | TypedefDecl::Create(Context, CurContext, SourceLocation(), |
Douglas Gregor | af8ad2b | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 129 | &Context.Idents.get("Class"), ClassT); |
Chris Lattner | 4e9553a | 2008-06-21 20:20:39 +0000 | [diff] [blame] | 130 | PushOnScopeChains(ClassTag, TUScope); |
| 131 | PushOnScopeChains(ClassTypedef, TUScope); |
| 132 | Context.setObjCClassType(ClassTypedef); |
| 133 | // Synthesize "@class Protocol; |
| 134 | ObjCInterfaceDecl *ProtocolDecl = |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 135 | ObjCInterfaceDecl::Create(Context, CurContext, SourceLocation(), |
Chris Lattner | 4e9553a | 2008-06-21 20:20:39 +0000 | [diff] [blame] | 136 | &Context.Idents.get("Protocol"), |
| 137 | SourceLocation(), true); |
| 138 | Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); |
| 139 | PushOnScopeChains(ProtocolDecl, TUScope); |
| 140 | |
| 141 | // Synthesize "typedef struct objc_object { Class isa; } *id;" |
Anders Carlsson | 8930fb5 | 2008-08-23 22:20:38 +0000 | [diff] [blame] | 142 | RecordDecl *ObjectTag = CreateStructDecl(Context, "objc_object"); |
| 143 | |
Chris Lattner | 4e9553a | 2008-06-21 20:20:39 +0000 | [diff] [blame] | 144 | QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag)); |
| 145 | PushOnScopeChains(ObjectTag, TUScope); |
| 146 | TypedefDecl *IdTypedef = TypedefDecl::Create(Context, CurContext, |
| 147 | SourceLocation(), |
| 148 | &Context.Idents.get("id"), |
Douglas Gregor | af8ad2b | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 149 | ObjT); |
Chris Lattner | 4e9553a | 2008-06-21 20:20:39 +0000 | [diff] [blame] | 150 | PushOnScopeChains(IdTypedef, TUScope); |
| 151 | Context.setObjCIdType(IdTypedef); |
Steve Naroff | ee1de13 | 2007-10-10 21:53:07 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Chris Lattner | a8c2d59 | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 154 | Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer) |
Chris Lattner | 6d89a8a | 2009-01-22 19:21:44 +0000 | [diff] [blame] | 155 | : LangOpts(pp.getLangOptions()), PP(pp), Context(ctxt), Consumer(consumer), |
| 156 | Diags(PP.getDiagnostics()), |
Chris Lattner | f9ea6a4 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 157 | SourceMgr(PP.getSourceManager()), CurContext(0), PreDeclaratorDC(0), |
Sebastian Redl | b5ee874 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 158 | CurBlock(0), PackContext(0), IdResolver(pp.getLangOptions()), |
| 159 | GlobalNewDeleteDeclared(false) { |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 160 | |
| 161 | // Get IdentifierInfo objects for known functions for which we |
| 162 | // do extra checking. |
Chris Lattner | a8c2d59 | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 163 | IdentifierTable &IT = PP.getIdentifierTable(); |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 164 | |
Daniel Dunbar | 0ab03e6 | 2008-10-02 18:44:07 +0000 | [diff] [blame] | 165 | KnownFunctionIDs[id_NSLog] = &IT.get("NSLog"); |
Douglas Gregor | b5af738 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 166 | KnownFunctionIDs[id_NSLogv] = &IT.get("NSLogv"); |
Douglas Gregor | 1742903 | 2009-02-14 00:32:47 +0000 | [diff] [blame] | 167 | KnownFunctionIDs[id_asprintf] = &IT.get("asprintf"); |
Daniel Dunbar | 0ab03e6 | 2008-10-02 18:44:07 +0000 | [diff] [blame] | 168 | KnownFunctionIDs[id_vasprintf] = &IT.get("vasprintf"); |
Steve Naroff | ae84af8 | 2007-10-31 18:42:27 +0000 | [diff] [blame] | 169 | |
Sebastian Redl | b93b49c | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 170 | StdNamespace = 0; |
Steve Naroff | ee1de13 | 2007-10-10 21:53:07 +0000 | [diff] [blame] | 171 | TUScope = 0; |
Steve Naroff | 313c416 | 2009-02-28 16:48:43 +0000 | [diff] [blame^] | 172 | ActiveScope = 0; |
| 173 | |
Argiris Kirtzidis | 38f1671 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 174 | if (getLangOptions().CPlusPlus) |
| 175 | FieldCollector.reset(new CXXFieldCollector()); |
Chris Lattner | da5c087 | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 176 | |
| 177 | // Tell diagnostics how to render things from the AST library. |
Chris Lattner | 0b53af2 | 2009-02-19 23:53:20 +0000 | [diff] [blame] | 178 | PP.getDiagnostics().SetArgToStringFn(ConvertArgToStringFn, &Context); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Chris Lattner | e992d6c | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 181 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. |
| 182 | /// If there is already an implicit cast, merge into the existing one. |
Nate Begeman | 7903d05 | 2009-01-18 06:42:49 +0000 | [diff] [blame] | 183 | /// If isLvalue, the result of the cast is an lvalue. |
Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 184 | void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, bool isLvalue) { |
Mon P Wang | c6c9274 | 2008-09-04 08:38:01 +0000 | [diff] [blame] | 185 | QualType ExprTy = Context.getCanonicalType(Expr->getType()); |
| 186 | QualType TypeTy = Context.getCanonicalType(Ty); |
| 187 | |
| 188 | if (ExprTy == TypeTy) |
| 189 | return; |
| 190 | |
| 191 | if (Expr->getType().getTypePtr()->isPointerType() && |
| 192 | Ty.getTypePtr()->isPointerType()) { |
| 193 | QualType ExprBaseType = |
| 194 | cast<PointerType>(ExprTy.getUnqualifiedType())->getPointeeType(); |
| 195 | QualType BaseType = |
| 196 | cast<PointerType>(TypeTy.getUnqualifiedType())->getPointeeType(); |
| 197 | if (ExprBaseType.getAddressSpace() != BaseType.getAddressSpace()) { |
Chris Lattner | 9d2cf08 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 198 | Diag(Expr->getExprLoc(), diag::err_implicit_pointer_address_space_cast) |
| 199 | << Expr->getSourceRange(); |
Mon P Wang | c6c9274 | 2008-09-04 08:38:01 +0000 | [diff] [blame] | 200 | } |
| 201 | } |
Chris Lattner | e992d6c | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 202 | |
Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 203 | if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) { |
Mon P Wang | c6c9274 | 2008-09-04 08:38:01 +0000 | [diff] [blame] | 204 | ImpCast->setType(Ty); |
Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 205 | ImpCast->setLvalueCast(isLvalue); |
| 206 | } else |
Ted Kremenek | 0c97e04 | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 207 | Expr = new (Context) ImplicitCastExpr(Ty, Expr, isLvalue); |
Chris Lattner | e992d6c | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Chris Lattner | b26b7ad | 2007-08-31 04:53:24 +0000 | [diff] [blame] | 210 | void Sema::DeleteExpr(ExprTy *E) { |
Douglas Gregor | c5a6bdc | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 211 | if (E) static_cast<Expr*>(E)->Destroy(Context); |
Chris Lattner | b26b7ad | 2007-08-31 04:53:24 +0000 | [diff] [blame] | 212 | } |
| 213 | void Sema::DeleteStmt(StmtTy *S) { |
Douglas Gregor | c5a6bdc | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 214 | if (S) static_cast<Stmt*>(S)->Destroy(Context); |
Chris Lattner | b26b7ad | 2007-08-31 04:53:24 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Chris Lattner | c1aea81 | 2008-08-23 03:19:52 +0000 | [diff] [blame] | 217 | /// ActOnEndOfTranslationUnit - This is called at the very end of the |
| 218 | /// translation unit when EOF is reached and all but the top-level scope is |
| 219 | /// popped. |
| 220 | void Sema::ActOnEndOfTranslationUnit() { |
| 221 | |
| 222 | } |
| 223 | |
| 224 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 225 | //===----------------------------------------------------------------------===// |
| 226 | // Helper functions. |
| 227 | //===----------------------------------------------------------------------===// |
| 228 | |
Chris Lattner | e5cb586 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 229 | /// getCurFunctionDecl - If inside of a function body, this returns a pointer |
| 230 | /// to the function decl for the function being parsed. If we're currently |
| 231 | /// in a 'block', this returns the containing context. |
| 232 | FunctionDecl *Sema::getCurFunctionDecl() { |
| 233 | DeclContext *DC = CurContext; |
| 234 | while (isa<BlockDecl>(DC)) |
| 235 | DC = DC->getParent(); |
| 236 | return dyn_cast<FunctionDecl>(DC); |
| 237 | } |
| 238 | |
Daniel Dunbar | 64789f8 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 239 | ObjCMethodDecl *Sema::getCurMethodDecl() { |
Steve Naroff | 55debea | 2008-11-17 16:28:52 +0000 | [diff] [blame] | 240 | DeclContext *DC = CurContext; |
| 241 | while (isa<BlockDecl>(DC)) |
| 242 | DC = DC->getParent(); |
| 243 | return dyn_cast<ObjCMethodDecl>(DC); |
Daniel Dunbar | 64789f8 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 244 | } |
Chris Lattner | e5cb586 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 245 | |
| 246 | NamedDecl *Sema::getCurFunctionOrMethodDecl() { |
| 247 | DeclContext *DC = CurContext; |
| 248 | while (isa<BlockDecl>(DC)) |
| 249 | DC = DC->getParent(); |
| 250 | if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC)) |
Douglas Gregor | af8ad2b | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 251 | return cast<NamedDecl>(DC); |
Chris Lattner | e5cb586 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | |