Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 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. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the Sema class, which performs semantic analysis and |
| 11 | // builds ASTs. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_CLANG_AST_SEMA_H |
| 16 | #define LLVM_CLANG_AST_SEMA_H |
| 17 | |
Chris Lattner | 7f925cc | 2008-04-11 07:00:53 +0000 | [diff] [blame] | 18 | #include "IdentifierResolver.h" |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 19 | #include "CXXFieldCollector.h" |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 20 | #include "SemaOverload.h" |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclBase.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | #include "clang/Parse/Action.h" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 23 | #include "clang/Sema/SemaDiagnostic.h" |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/SmallVector.h" |
Fariborz Jahanian | 85ff264 | 2007-10-05 18:00:57 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/DenseSet.h" |
Chris Lattner | f387668 | 2007-10-07 01:13:46 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/SmallPtrSet.h" |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/OwningPtr.h" |
Steve Naroff | 61d6852 | 2009-03-05 15:22:01 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 4dc6b1c | 2009-01-16 00:38:09 +0000 | [diff] [blame] | 29 | #include <string> |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 30 | #include <vector> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 31 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 32 | namespace llvm { |
| 33 | class APSInt; |
| 34 | } |
| 35 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 36 | namespace clang { |
| 37 | class ASTContext; |
Chris Lattner | 2ae34ed | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 38 | class ASTConsumer; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 39 | class Preprocessor; |
| 40 | class Decl; |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 41 | class DeclContext; |
Daniel Dunbar | 12bc692 | 2008-08-11 03:27:53 +0000 | [diff] [blame] | 42 | class DeclSpec; |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 43 | class NamedDecl; |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 44 | class Stmt; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 45 | class Expr; |
Steve Naroff | 6f9f307 | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 46 | class InitListExpr; |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 47 | class DesignatedInitExpr; |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 48 | class CallExpr; |
Douglas Gregor | 1a49af9 | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 49 | class DeclRefExpr; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 50 | class VarDecl; |
| 51 | class ParmVarDecl; |
| 52 | class TypedefDecl; |
| 53 | class FunctionDecl; |
| 54 | class QualType; |
Sebastian Redl | 43af76e | 2009-03-07 12:16:37 +0000 | [diff] [blame] | 55 | class LangOptions; |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 56 | class Token; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 57 | class IntegerLiteral; |
Steve Naroff | a49e1fa | 2008-01-22 00:55:40 +0000 | [diff] [blame] | 58 | class StringLiteral; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 59 | class ArrayType; |
| 60 | class LabelStmt; |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 61 | class SwitchStmt; |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 62 | class ExtVectorType; |
Steve Naroff | bea0b34 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 63 | class TypedefDecl; |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 64 | class TemplateDecl; |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 65 | class TemplateArgument; |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 66 | class TemplateParameterList; |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 67 | class TemplateTemplateParmDecl; |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 68 | class ClassTemplateDecl; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 69 | class ObjCInterfaceDecl; |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 70 | class ObjCCompatibleAliasDecl; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 71 | class ObjCProtocolDecl; |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 72 | class ObjCImplDecl; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 73 | class ObjCImplementationDecl; |
| 74 | class ObjCCategoryImplDecl; |
| 75 | class ObjCCategoryDecl; |
| 76 | class ObjCIvarDecl; |
| 77 | class ObjCMethodDecl; |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 78 | class ObjCPropertyDecl; |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 79 | class ObjCContainerDecl; |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 80 | struct BlockSemaInfo; |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 81 | class BasePaths; |
Sebastian Redl | 43af76e | 2009-03-07 12:16:37 +0000 | [diff] [blame] | 82 | struct MemberLookupCriteria; |
Steve Naroff | bea0b34 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 83 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 84 | /// Sema - This implements semantic analysis and AST building for C. |
| 85 | class Sema : public Action { |
Chris Lattner | f50adff | 2009-02-17 00:58:30 +0000 | [diff] [blame] | 86 | Sema(const Sema&); // DO NOT IMPLEMENT |
| 87 | void operator=(const Sema&); // DO NOT IMPLEMENT |
Chris Lattner | 0b2f4da | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 88 | public: |
Chris Lattner | 53ebff3 | 2009-01-22 19:21:44 +0000 | [diff] [blame] | 89 | const LangOptions &LangOpts; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 90 | Preprocessor &PP; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 91 | ASTContext &Context; |
Chris Lattner | 2ae34ed | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 92 | ASTConsumer &Consumer; |
Chris Lattner | 3cfa928 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 93 | Diagnostic &Diags; |
| 94 | SourceManager &SourceMgr; |
Steve Naroff | 0330071 | 2007-11-12 13:56:41 +0000 | [diff] [blame] | 95 | |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 96 | /// CurContext - This is the current declaration context of parsing. |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 97 | DeclContext *CurContext; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 98 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 99 | /// PreDeclaratorDC - Keeps the declaration context before switching to the |
| 100 | /// context of a declarator's nested-name-specifier. |
| 101 | DeclContext *PreDeclaratorDC; |
| 102 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 103 | /// CurBlock - If inside of a block definition, this contains a pointer to |
| 104 | /// the active block object that represents it. |
| 105 | BlockSemaInfo *CurBlock; |
| 106 | |
Steve Naroff | f3cf897 | 2009-02-28 16:48:43 +0000 | [diff] [blame] | 107 | /// ActiveScope - If inside of a function, method, or block definition, |
| 108 | /// this contains a pointer to the active scope that represents it. |
| 109 | Scope *ActiveScope; |
| 110 | |
Daniel Dunbar | 4cde927 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 111 | /// PackContext - Manages the stack for #pragma pack. An alignment |
| 112 | /// of 0 indicates default alignment. |
Chris Lattner | 574aa40 | 2009-02-17 01:09:29 +0000 | [diff] [blame] | 113 | void *PackContext; // Really a "PragmaPackStack*" |
Daniel Dunbar | 4cde927 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 114 | |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 115 | llvm::SmallVector<SwitchStmt*, 8> SwitchStack; |
Steve Naroff | bea0b34 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 116 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 117 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
| 118 | /// us to associate a raw vector type with one of the ext_vector type names. |
Steve Naroff | bea0b34 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 119 | /// This is only necessary for issuing pretty diagnostics. |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 120 | llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls; |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 121 | |
Steve Naroff | e84a864 | 2008-09-28 14:55:53 +0000 | [diff] [blame] | 122 | /// ObjCImplementations - Keep track of all class @implementations |
| 123 | /// so we can emit errors on duplicates. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 124 | llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations; |
Chris Lattner | f387668 | 2007-10-07 01:13:46 +0000 | [diff] [blame] | 125 | |
Steve Naroff | e84a864 | 2008-09-28 14:55:53 +0000 | [diff] [blame] | 126 | /// ObjCCategoryImpls - Maintain a list of category implementations so |
| 127 | /// we can check for duplicates and find local method declarations. |
| 128 | llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls; |
| 129 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 130 | /// ObjCProtocols - Keep track of all protocol declarations declared |
Fariborz Jahanian | 05672a0 | 2007-10-09 18:03:53 +0000 | [diff] [blame] | 131 | /// with @protocol keyword, so that we can emit errors on duplicates and |
Chris Lattner | 4de884d | 2007-10-09 18:18:24 +0000 | [diff] [blame] | 132 | /// find the declarations when needed. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 133 | llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols; |
Steve Naroff | 3110251 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 134 | |
| 135 | /// ObjCInterfaceDecls - Keep track of all class declarations declared |
| 136 | /// with @interface, so that we can emit errors on duplicates and |
| 137 | /// find the declarations when needed. |
| 138 | typedef llvm::DenseMap<const IdentifierInfo*, |
| 139 | ObjCInterfaceDecl*> ObjCInterfaceDeclsTy; |
| 140 | ObjCInterfaceDeclsTy ObjCInterfaceDecls; |
| 141 | |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 142 | /// ObjCAliasDecls - Keep track of all class declarations declared |
| 143 | /// with @compatibility_alias, so that we can emit errors on duplicates and |
| 144 | /// find the declarations when needed. This construct is ancient and will |
| 145 | /// likely never be seen. Nevertheless, it is here for compatibility. |
Steve Naroff | c822ff4 | 2008-04-02 00:39:51 +0000 | [diff] [blame] | 146 | typedef llvm::DenseMap<const IdentifierInfo*, |
| 147 | ObjCCompatibleAliasDecl*> ObjCAliasTy; |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 148 | ObjCAliasTy ObjCAliasDecls; |
Steve Naroff | 3110251 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 149 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 150 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
| 151 | llvm::OwningPtr<CXXFieldCollector> FieldCollector; |
| 152 | |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 153 | /// \brief A mapping from external names to the most recent |
| 154 | /// locally-scoped external declaration with that name. |
| 155 | /// |
| 156 | /// This map contains external declarations introduced in local |
| 157 | /// scoped, e.g., |
| 158 | /// |
| 159 | /// \code |
| 160 | /// void f() { |
| 161 | /// void foo(int, int); |
| 162 | /// } |
| 163 | /// \endcode |
| 164 | /// |
| 165 | /// Here, the name "foo" will be associated with the declaration on |
| 166 | /// "foo" within f. This name is not visible outside of |
| 167 | /// "f". However, we still find it in two cases: |
| 168 | /// |
| 169 | /// - If we are declaring another external with the name "foo", we |
| 170 | /// can find "foo" as a previous declaration, so that the types |
| 171 | /// of this external declaration can be checked for |
| 172 | /// compatibility. |
| 173 | /// |
| 174 | /// - If we would implicitly declare "foo" (e.g., due to a call to |
| 175 | /// "foo" in C when no prototype or definition is visible), then |
| 176 | /// we find this declaration of "foo" and complain that it is |
| 177 | /// not visible. |
| 178 | llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls; |
| 179 | |
Chris Lattner | 7f925cc | 2008-04-11 07:00:53 +0000 | [diff] [blame] | 180 | IdentifierResolver IdResolver; |
| 181 | |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 182 | // Enum values used by KnownFunctionIDs (see below). |
| 183 | enum { |
Ted Kremenek | 7ff22b2 | 2008-06-16 18:00:42 +0000 | [diff] [blame] | 184 | id_NSLog, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 185 | id_NSLogv, |
Daniel Dunbar | de45428 | 2008-10-02 18:44:07 +0000 | [diff] [blame] | 186 | id_asprintf, |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 187 | id_vasprintf, |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 188 | id_num_known_functions |
| 189 | }; |
| 190 | |
| 191 | /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set |
| 192 | /// of known functions used by the semantic analysis to do various |
| 193 | /// kinds of checking (e.g. checking format string errors in printf calls). |
| 194 | /// This list is populated upon the creation of a Sema object. |
Chris Lattner | 06f5485 | 2008-08-23 02:00:52 +0000 | [diff] [blame] | 195 | IdentifierInfo* KnownFunctionIDs[id_num_known_functions]; |
Daniel Dunbar | 662e8b5 | 2008-08-14 22:04:54 +0000 | [diff] [blame] | 196 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 197 | /// Translation Unit Scope - useful to Objective-C actions that need |
| 198 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
| 199 | /// For example, user-defined classes, built-in "id" type, etc. |
Steve Naroff | b216c88 | 2007-10-09 22:01:59 +0000 | [diff] [blame] | 200 | Scope *TUScope; |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 201 | |
| 202 | /// The C++ "std" namespace, where the standard library resides. Cached here |
| 203 | /// by GetStdNamespace |
| 204 | NamespaceDecl *StdNamespace; |
Sebastian Redl | b5a57a6 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 205 | |
| 206 | /// A flag to remember whether the implicit forms of operator new and delete |
| 207 | /// have been declared. |
| 208 | bool GlobalNewDeleteDeclared; |
Steve Naroff | 3b95017 | 2007-10-10 21:53:07 +0000 | [diff] [blame] | 209 | |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 210 | /// ObjCMethodList - a linked list of methods with different signatures. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 211 | struct ObjCMethodList { |
| 212 | ObjCMethodDecl *Method; |
| 213 | ObjCMethodList *Next; |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 214 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 215 | ObjCMethodList() { |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 216 | Method = 0; |
| 217 | Next = 0; |
| 218 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 219 | ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) { |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 220 | Method = M; |
| 221 | Next = C; |
| 222 | } |
| 223 | }; |
| 224 | /// Instance/Factory Method Pools - allows efficient lookup when typechecking |
| 225 | /// messages to "id". We need to maintain a list, since selectors can have |
| 226 | /// differing signatures across classes. In Cocoa, this happens to be |
| 227 | /// extremely uncommon (only 1% of selectors are "overloaded"). |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 228 | llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool; |
| 229 | llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool; |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 230 | |
| 231 | /// Private Helper predicate to check for 'self'. |
| 232 | bool isSelfExpr(Expr *RExpr); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 233 | public: |
Chris Lattner | 2ae34ed | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 234 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer); |
Chris Lattner | 574aa40 | 2009-02-17 01:09:29 +0000 | [diff] [blame] | 235 | ~Sema() { |
| 236 | if (PackContext) FreePackedContext(); |
| 237 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 238 | |
Chris Lattner | 53ebff3 | 2009-01-22 19:21:44 +0000 | [diff] [blame] | 239 | const LangOptions &getLangOptions() const { return LangOpts; } |
Chris Lattner | 3cfa928 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 240 | Diagnostic &getDiagnostics() const { return Diags; } |
| 241 | SourceManager &getSourceManager() const { return SourceMgr; } |
| 242 | |
Chris Lattner | ebf5ddf | 2008-11-18 21:53:24 +0000 | [diff] [blame] | 243 | /// The primitive diagnostic helpers. |
Chris Lattner | 3cfa928 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 244 | DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 245 | DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID); |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame^] | 246 | if (!Diags.isBuiltinNote(DiagID) && |
| 247 | !ActiveTemplateInstantiations.empty() && |
| 248 | ActiveTemplateInstantiations.back().Entity |
| 249 | != LastTemplateInstantiationErrorContext) |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 250 | DB << PostDiagnosticHook(PrintInstantiationStackHook, this); |
| 251 | return DB; |
Chris Lattner | 3cfa928 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 252 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 253 | |
Chris Lattner | 394a3fd | 2007-08-31 04:53:24 +0000 | [diff] [blame] | 254 | virtual void DeleteExpr(ExprTy *E); |
| 255 | virtual void DeleteStmt(StmtTy *S); |
| 256 | |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 257 | OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); } |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 258 | OwningExprResult Owned(ExprResult R) { |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 259 | if (R.isInvalid()) |
Steve Naroff | 872b9ac | 2009-01-21 22:32:33 +0000 | [diff] [blame] | 260 | return ExprError(); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 261 | return OwningExprResult(*this, R.get()); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 262 | } |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 263 | OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); } |
| 264 | |
Chris Lattner | 9299f3f | 2008-08-23 03:19:52 +0000 | [diff] [blame] | 265 | virtual void ActOnEndOfTranslationUnit(); |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 266 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 267 | //===--------------------------------------------------------------------===// |
| 268 | // Type Analysis / Processing: SemaType.cpp. |
| 269 | // |
Chris Lattner | fca0ddd | 2008-06-26 06:27:57 +0000 | [diff] [blame] | 270 | QualType ConvertDeclSpecToType(const DeclSpec &DS); |
Chris Lattner | c9b346d | 2008-06-29 00:50:08 +0000 | [diff] [blame] | 271 | void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 272 | QualType BuildPointerType(QualType T, unsigned Quals, |
| 273 | SourceLocation Loc, DeclarationName Entity); |
| 274 | QualType BuildReferenceType(QualType T, unsigned Quals, |
| 275 | SourceLocation Loc, DeclarationName Entity); |
| 276 | QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, |
| 277 | Expr *ArraySize, unsigned Quals, |
| 278 | SourceLocation Loc, DeclarationName Entity); |
Douglas Gregor | 724651c | 2009-02-28 01:04:19 +0000 | [diff] [blame] | 279 | QualType BuildFunctionType(QualType T, |
| 280 | QualType *ParamTypes, unsigned NumParamTypes, |
| 281 | bool Variadic, unsigned Quals, |
| 282 | SourceLocation Loc, DeclarationName Entity); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 283 | QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0); |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 284 | DeclarationName GetNameForDeclarator(Declarator &D); |
| 285 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 286 | QualType ObjCGetTypeForMethodDefinition(DeclTy *D); |
Fariborz Jahanian | 306d68f | 2007-11-08 23:49:49 +0000 | [diff] [blame] | 287 | |
Douglas Gregor | 5737326 | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 288 | bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2); |
| 289 | |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 290 | virtual TypeResult ActOnTypeName(Scope *S, Declarator &D); |
Sebastian Redl | 37d6de3 | 2008-11-08 13:00:26 +0000 | [diff] [blame] | 291 | |
Douglas Gregor | 86447ec | 2009-03-09 16:13:40 +0000 | [diff] [blame] | 292 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned diag, |
Douglas Gregor | 4ec339f | 2009-01-19 19:26:10 +0000 | [diff] [blame] | 293 | SourceRange Range1 = SourceRange(), |
| 294 | SourceRange Range2 = SourceRange(), |
| 295 | QualType PrintType = QualType()); |
| 296 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 297 | //===--------------------------------------------------------------------===// |
| 298 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
| 299 | // |
Chris Lattner | 21ff9c9 | 2009-03-05 01:25:28 +0000 | [diff] [blame] | 300 | |
| 301 | /// getDeclName - Return a pretty name for the specified decl if possible, or |
| 302 | /// an empty string if not. This is used for pretty crash reporting. |
| 303 | virtual std::string getDeclName(DeclTy *D); |
| 304 | |
Douglas Gregor | 1a51b4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 305 | virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, |
Douglas Gregor | b696ea3 | 2009-02-04 17:00:24 +0000 | [diff] [blame] | 306 | Scope *S, const CXXScopeSpec *SS); |
Chris Lattner | 76a642f | 2009-02-15 22:43:40 +0000 | [diff] [blame] | 307 | virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){ |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 308 | return ActOnDeclarator(S, D, LastInGroup, false); |
| 309 | } |
| 310 | DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup, |
| 311 | bool IsFunctionDefinition); |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 312 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl, |
| 313 | Scope *S); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 314 | NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
| 315 | QualType R, Decl* LastDeclarator, |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 316 | Decl* PrevDecl, bool& InvalidDecl, |
| 317 | bool &Redeclaration); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 318 | NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 319 | QualType R, Decl* LastDeclarator, |
Douglas Gregor | 8f30105 | 2009-02-24 19:23:27 +0000 | [diff] [blame] | 320 | NamedDecl* PrevDecl, bool& InvalidDecl, |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 321 | bool &Redeclaration); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 322 | NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
| 323 | QualType R, Decl *LastDeclarator, |
Douglas Gregor | 04495c8 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 324 | NamedDecl* PrevDecl, |
| 325 | bool IsFunctionDefinition, |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 326 | bool& InvalidDecl, bool &Redeclaration); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 327 | virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D); |
| 328 | virtual void ActOnParamDefaultArgument(DeclTy *param, |
| 329 | SourceLocation EqualLoc, |
| 330 | ExprTy *defarg); |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 331 | virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param, |
| 332 | SourceLocation EqualLoc); |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 333 | virtual void ActOnParamDefaultArgumentError(DeclTy *param); |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 334 | virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init); |
| 335 | void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit); |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 336 | void ActOnUninitializedDecl(DeclTy *dcl); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 337 | virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group); |
| 338 | |
Douglas Gregor | be109b3 | 2009-01-23 16:23:13 +0000 | [diff] [blame] | 339 | virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D); |
Chris Lattner | b652cea | 2007-10-09 17:14:05 +0000 | [diff] [blame] | 340 | virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D); |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 341 | virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D); |
Steve Naroff | ebf6443 | 2009-02-28 16:59:13 +0000 | [diff] [blame] | 342 | virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D); |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 343 | |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 344 | virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body); |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 345 | virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr); |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 346 | |
Steve Naroff | b216c88 | 2007-10-09 22:01:59 +0000 | [diff] [blame] | 347 | /// Scope actions. |
| 348 | virtual void ActOnPopScope(SourceLocation Loc, Scope *S); |
| 349 | virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 350 | |
| 351 | /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with |
| 352 | /// no declarator (e.g. "struct foo;") is parsed. |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 353 | virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 354 | |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 355 | bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, |
| 356 | RecordDecl *AnonRecord); |
| 357 | virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
| 358 | RecordDecl *Record); |
| 359 | |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 360 | virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK, |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 361 | SourceLocation KWLoc, const CXXScopeSpec &SS, |
| 362 | IdentifierInfo *Name, SourceLocation NameLoc, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 363 | AttributeList *Attr); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 364 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 365 | virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart, |
Chris Lattner | 06f5485 | 2008-08-23 02:00:52 +0000 | [diff] [blame] | 366 | IdentifierInfo *ClassName, |
| 367 | llvm::SmallVectorImpl<DeclTy*> &Decls); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 368 | virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 369 | Declarator &D, ExprTy *BitfieldWidth); |
Chris Lattner | 2479366 | 2009-03-05 22:45:59 +0000 | [diff] [blame] | 370 | |
| 371 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
| 372 | Declarator &D, Expr *BitfieldWidth); |
| 373 | |
Fariborz Jahanian | 1d78cc4 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 374 | |
| 375 | virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart, |
| 376 | Declarator &D, ExprTy *BitfieldWidth, |
Fariborz Jahanian | 45bc03f | 2008-04-11 16:55:42 +0000 | [diff] [blame] | 377 | tok::ObjCKeywordKind visibility); |
Fariborz Jahanian | 1d78cc4 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 378 | |
Steve Naroff | f13271f | 2007-09-14 23:09:53 +0000 | [diff] [blame] | 379 | // This is used for both record definitions and ObjC interface declarations. |
Fariborz Jahanian | 9d048ff | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 380 | virtual void ActOnFields(Scope* S, |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 381 | SourceLocation RecLoc, DeclTy *TagDecl, |
| 382 | DeclTy **Fields, unsigned NumFields, |
Daniel Dunbar | 1bfe1c2 | 2008-10-03 02:03:53 +0000 | [diff] [blame] | 383 | SourceLocation LBrac, SourceLocation RBrac, |
| 384 | AttributeList *AttrList); |
Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 385 | |
| 386 | /// ActOnTagStartDefinition - Invoked when we have entered the |
| 387 | /// scope of a tag's definition (e.g., for an enumeration, class, |
| 388 | /// struct, or union). |
| 389 | virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl); |
| 390 | |
| 391 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
| 392 | /// the definition of a tag (enumeration, class, struct, or union). |
| 393 | virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl); |
| 394 | |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 395 | virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 396 | DeclTy *LastEnumConstant, |
| 397 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 398 | SourceLocation EqualLoc, ExprTy *Val); |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 399 | virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 400 | DeclTy **Elements, unsigned NumElements); |
Sebastian Redl | 37d6de3 | 2008-11-08 13:00:26 +0000 | [diff] [blame] | 401 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 402 | DeclContext *getContainingDC(DeclContext *DC); |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 403 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 404 | /// Set the current declaration context until it gets popped. |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 405 | void PushDeclContext(Scope *S, DeclContext *DC); |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 406 | void PopDeclContext(); |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 407 | |
Chris Lattner | 371f258 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 408 | /// getCurFunctionDecl - If inside of a function body, this returns a pointer |
| 409 | /// to the function decl for the function being parsed. If we're currently |
| 410 | /// in a 'block', this returns the containing context. |
| 411 | FunctionDecl *getCurFunctionDecl(); |
| 412 | |
| 413 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
| 414 | /// the method decl for the method being parsed. If we're currently |
| 415 | /// in a 'block', this returns the containing context. |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 416 | ObjCMethodDecl *getCurMethodDecl(); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 417 | |
Chris Lattner | 371f258 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 418 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
| 419 | /// or C function we're in, otherwise return null. If we're currently |
| 420 | /// in a 'block', this returns the containing context. |
| 421 | NamedDecl *getCurFunctionOrMethodDecl(); |
| 422 | |
Argyrios Kyrtzidis | 87f3ff0 | 2008-04-12 00:47:19 +0000 | [diff] [blame] | 423 | /// Add this decl to the scope shadowed decl chains. |
| 424 | void PushOnScopeChains(NamedDecl *D, Scope *S); |
| 425 | |
Argyrios Kyrtzidis | 15a12d0 | 2008-09-09 21:18:04 +0000 | [diff] [blame] | 426 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
| 427 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
| 428 | /// true if 'D' belongs to the given declaration context. |
| 429 | bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) { |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 430 | return IdResolver.isDeclInScope(D, Ctx, Context, S); |
Argyrios Kyrtzidis | 15a12d0 | 2008-09-09 21:18:04 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Eli Friedman | 8f17b66 | 2009-02-28 05:41:13 +0000 | [diff] [blame] | 433 | |
| 434 | void RecursiveCalcJumpScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap, |
| 435 | llvm::DenseMap<void*, Stmt*>& PopScopeMap, |
| 436 | llvm::DenseMap<Stmt*, void*>& GotoScopeMap, |
| 437 | std::vector<void*>& ScopeStack, |
| 438 | Stmt* CurStmt); |
| 439 | |
| 440 | void RecursiveCalcLabelScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap, |
| 441 | llvm::DenseMap<void*, Stmt*>& PopScopeMap, |
| 442 | std::vector<void*>& ScopeStack, |
| 443 | Stmt* CurStmt, |
| 444 | Stmt* ParentCompoundStmt); |
| 445 | |
Chris Lattner | f1d705c | 2008-02-21 01:07:18 +0000 | [diff] [blame] | 446 | /// Subroutines of ActOnDeclarator(). |
Chris Lattner | 41af093 | 2007-11-14 06:34:38 +0000 | [diff] [blame] | 447 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 448 | Decl *LastDecl); |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 449 | bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old); |
| 450 | bool MergeFunctionDecl(FunctionDecl *New, Decl *Old); |
Douglas Gregor | 04495c8 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 451 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old); |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 452 | bool MergeVarDecl(VarDecl *New, Decl *Old); |
| 453 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old); |
Steve Naroff | ff9eb1f | 2008-08-08 17:50:35 +0000 | [diff] [blame] | 454 | void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 455 | |
| 456 | /// C++ Overloading. |
| 457 | bool IsOverload(FunctionDecl *New, Decl* OldD, |
| 458 | OverloadedFunctionDecl::function_iterator &MatchedDecl); |
Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 459 | ImplicitConversionSequence |
| 460 | TryImplicitConversion(Expr* From, QualType ToType, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 461 | bool SuppressUserConversions = false, |
| 462 | bool AllowExplicit = false); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 463 | bool IsStandardConversion(Expr *From, QualType ToType, |
| 464 | StandardConversionSequence& SCS); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 465 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
| 466 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
Douglas Gregor | 5cdf821 | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 467 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 468 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 469 | QualType& ConvertedType, bool &IncompatibleObjC); |
Douglas Gregor | c788751 | 2008-12-19 19:13:09 +0000 | [diff] [blame] | 470 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
| 471 | QualType& ConvertedType, bool &IncompatibleObjC); |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 472 | bool CheckPointerConversion(Expr *From, QualType ToType); |
Sebastian Redl | 4433aaf | 2009-01-25 19:43:20 +0000 | [diff] [blame] | 473 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
| 474 | QualType &ConvertedType); |
| 475 | bool CheckMemberPointerConversion(Expr *From, QualType ToType); |
Douglas Gregor | 98cd599 | 2008-10-21 23:43:52 +0000 | [diff] [blame] | 476 | bool IsQualificationConversion(QualType FromType, QualType ToType); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 477 | bool IsUserDefinedConversion(Expr *From, QualType ToType, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 478 | UserDefinedConversionSequence& User, |
Douglas Gregor | 734d986 | 2009-01-30 23:27:23 +0000 | [diff] [blame] | 479 | bool AllowConversionFunctions, |
| 480 | bool AllowExplicit); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 481 | |
| 482 | ImplicitConversionSequence::CompareKind |
| 483 | CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1, |
| 484 | const ImplicitConversionSequence& ICS2); |
| 485 | |
| 486 | ImplicitConversionSequence::CompareKind |
| 487 | CompareStandardConversionSequences(const StandardConversionSequence& SCS1, |
| 488 | const StandardConversionSequence& SCS2); |
| 489 | |
Douglas Gregor | 5737326 | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 490 | ImplicitConversionSequence::CompareKind |
| 491 | CompareQualificationConversions(const StandardConversionSequence& SCS1, |
| 492 | const StandardConversionSequence& SCS2); |
| 493 | |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 494 | ImplicitConversionSequence::CompareKind |
| 495 | CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1, |
| 496 | const StandardConversionSequence& SCS2); |
| 497 | |
Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 498 | ImplicitConversionSequence |
| 499 | TryCopyInitialization(Expr* From, QualType ToType, |
| 500 | bool SuppressUserConversions = false); |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 501 | bool PerformCopyInitialization(Expr *&From, QualType ToType, |
| 502 | const char *Flavor); |
| 503 | |
Douglas Gregor | 96176b3 | 2008-11-18 23:14:02 +0000 | [diff] [blame] | 504 | ImplicitConversionSequence |
| 505 | TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method); |
| 506 | bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method); |
| 507 | |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 508 | ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From); |
| 509 | bool PerformContextuallyConvertToBool(Expr *&From); |
| 510 | |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 511 | /// OverloadingResult - Capture the result of performing overload |
| 512 | /// resolution. |
| 513 | enum OverloadingResult { |
| 514 | OR_Success, ///< Overload resolution succeeded. |
| 515 | OR_No_Viable_Function, ///< No viable function found. |
Douglas Gregor | 48f3bb9 | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 516 | OR_Ambiguous, ///< Ambiguous candidates found. |
| 517 | OR_Deleted ///< Overload resoltuion refers to a deleted function. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | void AddOverloadCandidate(FunctionDecl *Function, |
| 521 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 522 | OverloadCandidateSet& CandidateSet, |
| 523 | bool SuppressUserConversions = false); |
Douglas Gregor | 96176b3 | 2008-11-18 23:14:02 +0000 | [diff] [blame] | 524 | void AddMethodCandidate(CXXMethodDecl *Method, |
| 525 | Expr *Object, Expr **Args, unsigned NumArgs, |
| 526 | OverloadCandidateSet& CandidateSet, |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 527 | bool SuppressUserConversions = false); |
Douglas Gregor | f1991ea | 2008-11-07 22:36:19 +0000 | [diff] [blame] | 528 | void AddConversionCandidate(CXXConversionDecl *Conversion, |
| 529 | Expr *From, QualType ToType, |
| 530 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | 106c6eb | 2008-11-19 22:57:39 +0000 | [diff] [blame] | 531 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 532 | const FunctionProtoType *Proto, |
Douglas Gregor | 106c6eb | 2008-11-19 22:57:39 +0000 | [diff] [blame] | 533 | Expr *Object, Expr **Args, unsigned NumArgs, |
| 534 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | f680a0f | 2009-02-04 16:44:47 +0000 | [diff] [blame] | 535 | bool AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S, |
| 536 | SourceLocation OpLoc, |
Douglas Gregor | 96176b3 | 2008-11-18 23:14:02 +0000 | [diff] [blame] | 537 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | f680a0f | 2009-02-04 16:44:47 +0000 | [diff] [blame] | 538 | OverloadCandidateSet& CandidateSet, |
| 539 | SourceRange OpRange = SourceRange()); |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 540 | void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, |
| 541 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | 88b4bf2 | 2009-01-13 00:52:54 +0000 | [diff] [blame] | 542 | OverloadCandidateSet& CandidateSet, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 543 | bool IsAssignmentOperator = false, |
| 544 | unsigned NumContextualBoolArguments = 0); |
Douglas Gregor | 7425373 | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 545 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
| 546 | Expr **Args, unsigned NumArgs, |
| 547 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 548 | void AddArgumentDependentLookupCandidates(DeclarationName Name, |
| 549 | Expr **Args, unsigned NumArgs, |
| 550 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 551 | bool isBetterOverloadCandidate(const OverloadCandidate& Cand1, |
| 552 | const OverloadCandidate& Cand2); |
| 553 | OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet, |
| 554 | OverloadCandidateSet::iterator& Best); |
| 555 | void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, |
| 556 | bool OnlyViable); |
| 557 | |
Douglas Gregor | 904eed3 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 558 | FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, |
| 559 | bool Complain); |
| 560 | void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn); |
| 561 | |
Douglas Gregor | 1733001 | 2009-02-04 15:01:18 +0000 | [diff] [blame] | 562 | FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee, |
| 563 | DeclarationName UnqualifiedName, |
Douglas Gregor | 0a39668 | 2008-11-26 06:01:48 +0000 | [diff] [blame] | 564 | SourceLocation LParenLoc, |
| 565 | Expr **Args, unsigned NumArgs, |
| 566 | SourceLocation *CommaLocs, |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 567 | SourceLocation RParenLoc, |
Douglas Gregor | 1733001 | 2009-02-04 15:01:18 +0000 | [diff] [blame] | 568 | bool &ArgumentDependentLookup); |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 569 | ExprResult |
| 570 | BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
| 571 | SourceLocation LParenLoc, Expr **Args, |
| 572 | unsigned NumArgs, SourceLocation *CommaLocs, |
| 573 | SourceLocation RParenLoc); |
Douglas Gregor | f9eb905 | 2008-11-19 21:05:33 +0000 | [diff] [blame] | 574 | ExprResult |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 575 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
Douglas Gregor | f9eb905 | 2008-11-19 21:05:33 +0000 | [diff] [blame] | 576 | Expr **Args, unsigned NumArgs, |
| 577 | SourceLocation *CommaLocs, |
| 578 | SourceLocation RParenLoc); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 579 | |
Douglas Gregor | 3fc749d | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 580 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc, |
Douglas Gregor | 8ba1074 | 2008-11-20 16:27:02 +0000 | [diff] [blame] | 581 | SourceLocation MemberLoc, |
| 582 | IdentifierInfo &Member); |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 583 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 584 | /// Helpers for dealing with function parameters. |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 585 | bool CheckParmsForFunctionDef(FunctionDecl *FD); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 586 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
Douglas Gregor | 6d6eb57 | 2008-05-07 04:49:29 +0000 | [diff] [blame] | 587 | void CheckExtraCXXDefaultArguments(Declarator &D); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 588 | |
Douglas Gregor | 1a0d31a | 2009-01-12 18:45:55 +0000 | [diff] [blame] | 589 | Scope *getNonFieldDeclScope(Scope *S); |
| 590 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 591 | /// \name Name lookup |
| 592 | /// |
| 593 | /// These routines provide name lookup that is used during semantic |
| 594 | /// analysis to resolve the various kinds of names (identifiers, |
| 595 | /// overloaded operator names, constructor names, etc.) into zero or |
| 596 | /// more declarations within a particular scope. The major entry |
| 597 | /// points are LookupName, which performs unqualified name lookup, |
| 598 | /// and LookupQualifiedName, which performs qualified name lookup. |
| 599 | /// |
| 600 | /// All name lookup is performed based on some specific criteria, |
| 601 | /// which specify what names will be visible to name lookup and how |
| 602 | /// far name lookup should work. These criteria are important both |
| 603 | /// for capturing language semantics (certain lookups will ignore |
| 604 | /// certain names, for example) and for performance, since name |
| 605 | /// lookup is often a bottleneck in the compilation of C++. Name |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 606 | /// lookup criteria is specified via the LookupCriteria enumeration. |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 607 | /// |
| 608 | /// The results of name lookup can vary based on the kind of name |
| 609 | /// lookup performed, the current language, and the translation |
| 610 | /// unit. In C, for example, name lookup will either return nothing |
| 611 | /// (no entity found) or a single declaration. In C++, name lookup |
| 612 | /// can additionally refer to a set of overloaded functions or |
| 613 | /// result in an ambiguity. All of the possible results of name |
| 614 | /// lookup are captured by the LookupResult class, which provides |
| 615 | /// the ability to distinguish among them. |
| 616 | //@{ |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 617 | |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 618 | /// @brief Describes the kind of name lookup to perform. |
| 619 | enum LookupNameKind { |
| 620 | /// Ordinary name lookup, which finds ordinary names (functions, |
| 621 | /// variables, typedefs, etc.) in C and most kinds of names |
| 622 | /// (functions, variables, members, types, etc.) in C++. |
| 623 | LookupOrdinaryName = 0, |
| 624 | /// Tag name lookup, which finds the names of enums, classes, |
| 625 | /// structs, and unions. |
| 626 | LookupTagName, |
| 627 | /// Member name lookup, which finds the names of |
| 628 | /// class/struct/union members. |
| 629 | LookupMemberName, |
Douglas Gregor | f680a0f | 2009-02-04 16:44:47 +0000 | [diff] [blame] | 630 | // Look up of an operator name (e.g., operator+) for use with |
| 631 | // operator overloading. This lookup is similar to ordinary name |
| 632 | // lookup, but will ignore any declarations that are class |
| 633 | // members. |
| 634 | LookupOperatorName, |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 635 | /// Look up of a name that precedes the '::' scope resolution |
| 636 | /// operator in C++. This lookup completely ignores operator, |
| 637 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
| 638 | LookupNestedNameSpecifierName, |
| 639 | /// Look up a namespace name within a C++ using directive or |
| 640 | /// namespace alias definition, ignoring non-namespace names (C++ |
| 641 | /// [basic.lookup.udir]p1). |
Douglas Gregor | d6f7e9d | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 642 | LookupNamespaceName, |
| 643 | // Look up an ordinary name that is going to be redeclared as a |
| 644 | // name with linkage. This lookup ignores any declarations that |
| 645 | // are outside of the current scope unless they have linkage. See |
| 646 | // C99 6.2.2p4-5 and C++ [basic.link]p6. |
| 647 | LookupRedeclarationWithLinkage |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 648 | }; |
| 649 | |
| 650 | /// @brief Represents the results of name lookup. |
| 651 | /// |
| 652 | /// An instance of the LookupResult class captures the results of a |
| 653 | /// single name lookup, which can return no result (nothing found), |
| 654 | /// a single declaration, a set of overloaded functions, or an |
| 655 | /// ambiguity. Use the getKind() method to determine which of these |
| 656 | /// results occurred for a given lookup. |
| 657 | /// |
| 658 | /// Any non-ambiguous lookup can be converted into a single |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 659 | /// (possibly NULL) @c NamedDecl* via a conversion function or the |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 660 | /// getAsDecl() method. This conversion permits the common-case |
| 661 | /// usage in C and Objective-C where name lookup will always return |
| 662 | /// a single declaration. |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 663 | struct LookupResult { |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 664 | /// The kind of entity that is actually stored within the |
| 665 | /// LookupResult object. |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 666 | enum { |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 667 | /// First is a single declaration (a NamedDecl*), which may be NULL. |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 668 | SingleDecl, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 669 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 670 | /// First is a single declaration (an OverloadedFunctionDecl*). |
| 671 | OverloadedDeclSingleDecl, |
| 672 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 673 | /// [First, Last) is an iterator range represented as opaque |
| 674 | /// pointers used to reconstruct IdentifierResolver::iterators. |
| 675 | OverloadedDeclFromIdResolver, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 676 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 677 | /// [First, Last) is an iterator range represented as opaque |
| 678 | /// pointers used to reconstruct DeclContext::lookup_iterators. |
| 679 | OverloadedDeclFromDeclContext, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 680 | |
| 681 | /// First is a pointer to a BasePaths structure, which is owned |
| 682 | /// by the LookupResult. Last is non-zero to indicate that the |
| 683 | /// ambiguity is caused by two names found in base class |
| 684 | /// subobjects of different types. |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 685 | AmbiguousLookupStoresBasePaths, |
| 686 | |
| 687 | /// [First, Last) is an iterator range represented as opaque |
| 688 | /// pointers used to reconstruct new'ed Decl*[] array containing |
| 689 | /// found ambiguous decls. LookupResult is owner of this array. |
| 690 | AmbiguousLookupStoresDecls |
| 691 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 692 | } StoredKind; |
| 693 | |
| 694 | /// The first lookup result, whose contents depend on the kind of |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 695 | /// lookup result. This may be a NamedDecl* (if StoredKind == |
| 696 | /// SingleDecl), OverloadedFunctionDecl* (if StoredKind == |
| 697 | /// OverloadedDeclSingleDecl), the opaque pointer from an |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 698 | /// IdentifierResolver::iterator (if StoredKind == |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 699 | /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator |
| 700 | /// (if StoredKind == OverloadedDeclFromDeclContext), or a |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 701 | /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths). |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 702 | mutable uintptr_t First; |
| 703 | |
| 704 | /// The last lookup result, whose contents depend on the kind of |
| 705 | /// lookup result. This may be unused (if StoredKind == |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 706 | /// SingleDecl), it may have the same type as First (for |
| 707 | /// overloaded function declarations), or is may be used as a |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 708 | /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths). |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 709 | mutable uintptr_t Last; |
| 710 | |
| 711 | /// Context - The context in which we will build any |
| 712 | /// OverloadedFunctionDecl nodes needed by the conversion to |
| 713 | /// Decl*. |
| 714 | ASTContext *Context; |
| 715 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 716 | /// @brief The kind of entity found by name lookup. |
| 717 | enum LookupKind { |
| 718 | /// @brief No entity found met the criteria. |
| 719 | NotFound = 0, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 720 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 721 | /// @brief Name lookup found a single declaration that met the |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 722 | /// criteria. getAsDecl will return this declaration. |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 723 | Found, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 724 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 725 | /// @brief Name lookup found a set of overloaded functions that |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 726 | /// met the criteria. getAsDecl will turn this set of overloaded |
| 727 | /// functions into an OverloadedFunctionDecl. |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 728 | FoundOverloaded, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 729 | |
| 730 | /// Name lookup results in an ambiguity because multiple |
| 731 | /// entities that meet the lookup criteria were found in |
| 732 | /// subobjects of different types. For example: |
| 733 | /// @code |
| 734 | /// struct A { void f(int); } |
| 735 | /// struct B { void f(double); } |
| 736 | /// struct C : A, B { }; |
| 737 | /// void test(C c) { |
| 738 | /// c.f(0); // error: A::f and B::f come from subobjects of different |
| 739 | /// // types. overload resolution is not performed. |
| 740 | /// } |
| 741 | /// @endcode |
| 742 | AmbiguousBaseSubobjectTypes, |
| 743 | |
| 744 | /// Name lookup results in an ambiguity because multiple |
| 745 | /// nonstatic entities that meet the lookup criteria were found |
| 746 | /// in different subobjects of the same type. For example: |
| 747 | /// @code |
| 748 | /// struct A { int x; }; |
| 749 | /// struct B : A { }; |
| 750 | /// struct C : A { }; |
| 751 | /// struct D : B, C { }; |
| 752 | /// int test(D d) { |
| 753 | /// return d.x; // error: 'x' is found in two A subobjects (of B and C) |
| 754 | /// } |
| 755 | /// @endcode |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 756 | AmbiguousBaseSubobjects, |
| 757 | |
| 758 | /// Name lookup results in an ambiguity because multiple definitions |
| 759 | /// of entity that meet the lookup criteria were found in different |
| 760 | /// declaration contexts. |
| 761 | /// @code |
| 762 | /// namespace A { |
| 763 | /// int i; |
| 764 | /// namespace B { int i; } |
| 765 | /// int test() { |
| 766 | /// using namespace B; |
| 767 | /// return i; // error 'i' is found in namespace A and A::B |
| 768 | /// } |
| 769 | /// } |
| 770 | /// @endcode |
| 771 | AmbiguousReference |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 772 | }; |
| 773 | |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 774 | static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D); |
Douglas Gregor | 4bb64e7 | 2009-01-15 02:19:31 +0000 | [diff] [blame] | 775 | |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 776 | static LookupResult CreateLookupResult(ASTContext &Context, |
| 777 | IdentifierResolver::iterator F, |
| 778 | IdentifierResolver::iterator L); |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 779 | |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 780 | static LookupResult CreateLookupResult(ASTContext &Context, |
| 781 | DeclContext::lookup_iterator F, |
| 782 | DeclContext::lookup_iterator L); |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 783 | |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 784 | static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths, |
| 785 | bool DifferentSubobjectTypes) { |
| 786 | LookupResult Result; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 787 | Result.StoredKind = AmbiguousLookupStoresBasePaths; |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 788 | Result.First = reinterpret_cast<uintptr_t>(Paths); |
| 789 | Result.Last = DifferentSubobjectTypes? 1 : 0; |
| 790 | Result.Context = &Context; |
| 791 | return Result; |
| 792 | } |
Douglas Gregor | 4bb64e7 | 2009-01-15 02:19:31 +0000 | [diff] [blame] | 793 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 794 | template <typename Iterator> |
| 795 | static LookupResult CreateLookupResult(ASTContext &Context, |
| 796 | Iterator B, std::size_t Len) { |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 797 | NamedDecl ** Array = new NamedDecl*[Len]; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 798 | for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B) |
| 799 | Array[Idx] = *B; |
| 800 | LookupResult Result; |
| 801 | Result.StoredKind = AmbiguousLookupStoresDecls; |
| 802 | Result.First = reinterpret_cast<uintptr_t>(Array); |
| 803 | Result.Last = reinterpret_cast<uintptr_t>(Array + Len); |
| 804 | Result.Context = &Context; |
| 805 | return Result; |
| 806 | } |
| 807 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 808 | LookupKind getKind() const; |
| 809 | |
| 810 | /// @brief Determine whether name look found something. |
| 811 | operator bool() const { return getKind() != NotFound; } |
| 812 | |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 813 | /// @brief Determines whether the lookup resulted in an ambiguity. |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 814 | bool isAmbiguous() const { |
| 815 | return StoredKind == AmbiguousLookupStoresBasePaths || |
| 816 | StoredKind == AmbiguousLookupStoresDecls; |
| 817 | } |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 818 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 819 | /// @brief Allows conversion of a lookup result into a |
| 820 | /// declaration, with the same behavior as getAsDecl. |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 821 | operator NamedDecl*() const { return getAsDecl(); } |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 822 | |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 823 | NamedDecl* getAsDecl() const; |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 824 | |
| 825 | BasePaths *getBasePaths() const; |
Douglas Gregor | d863517 | 2009-02-02 21:35:47 +0000 | [diff] [blame] | 826 | |
| 827 | /// \brief Iterate over the results of name lookup. |
| 828 | /// |
| 829 | /// The @c iterator class provides iteration over the results of a |
| 830 | /// non-ambiguous name lookup. |
| 831 | class iterator { |
| 832 | /// The LookupResult structure we're iterating through. |
| 833 | LookupResult *Result; |
| 834 | |
| 835 | /// The current position of this iterator within the sequence of |
| 836 | /// results. This value will have the same representation as the |
| 837 | /// @c First field in the LookupResult structure. |
| 838 | mutable uintptr_t Current; |
| 839 | |
| 840 | public: |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 841 | typedef NamedDecl * value_type; |
| 842 | typedef NamedDecl * reference; |
| 843 | typedef NamedDecl * pointer; |
Douglas Gregor | d863517 | 2009-02-02 21:35:47 +0000 | [diff] [blame] | 844 | typedef std::ptrdiff_t difference_type; |
| 845 | typedef std::forward_iterator_tag iterator_category; |
| 846 | |
| 847 | iterator() : Result(0), Current(0) { } |
| 848 | |
| 849 | iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { } |
| 850 | |
| 851 | reference operator*() const; |
| 852 | |
| 853 | pointer operator->() const { return **this; } |
| 854 | |
| 855 | iterator &operator++(); |
| 856 | |
| 857 | iterator operator++(int) { |
| 858 | iterator tmp(*this); |
| 859 | ++(*this); |
| 860 | return tmp; |
| 861 | } |
| 862 | |
| 863 | friend inline bool operator==(iterator const& x, iterator const& y) { |
| 864 | return x.Current == y.Current; |
| 865 | } |
| 866 | |
| 867 | friend inline bool operator!=(iterator const& x, iterator const& y) { |
| 868 | return x.Current != y.Current; |
| 869 | } |
| 870 | }; |
| 871 | friend class iterator; |
| 872 | |
| 873 | iterator begin(); |
| 874 | iterator end(); |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 875 | }; |
| 876 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 877 | private: |
| 878 | typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy; |
| 879 | |
| 880 | std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name, |
| 881 | LookupNameKind NameKind, |
| 882 | bool RedeclarationOnly); |
| 883 | |
| 884 | public: |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 885 | /// Determines whether D is a suitable lookup result according to the |
| 886 | /// lookup criteria. |
Douglas Gregor | d6f7e9d | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 887 | static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind, |
Douglas Gregor | 7dda67d | 2009-02-05 19:25:20 +0000 | [diff] [blame] | 888 | unsigned IDNS) { |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 889 | switch (NameKind) { |
| 890 | case Sema::LookupOrdinaryName: |
| 891 | case Sema::LookupTagName: |
| 892 | case Sema::LookupMemberName: |
Douglas Gregor | d6f7e9d | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 893 | case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 894 | return D->isInIdentifierNamespace(IDNS); |
| 895 | |
Douglas Gregor | f680a0f | 2009-02-04 16:44:47 +0000 | [diff] [blame] | 896 | case Sema::LookupOperatorName: |
| 897 | return D->isInIdentifierNamespace(IDNS) && |
| 898 | !D->getDeclContext()->isRecord(); |
| 899 | |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 900 | case Sema::LookupNestedNameSpecifierName: |
| 901 | return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag); |
| 902 | |
| 903 | case Sema::LookupNamespaceName: |
| 904 | return isa<NamespaceDecl>(D); |
| 905 | } |
| 906 | |
| 907 | assert(false && |
Douglas Gregor | 7dda67d | 2009-02-05 19:25:20 +0000 | [diff] [blame] | 908 | "isAcceptableLookupResult always returns before this point"); |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 909 | return false; |
| 910 | } |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 911 | |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 912 | LookupResult LookupName(Scope *S, DeclarationName Name, |
| 913 | LookupNameKind NameKind, |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 914 | bool RedeclarationOnly = false, |
| 915 | bool AllowBuiltinCreation = true, |
| 916 | SourceLocation Loc = SourceLocation()); |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 917 | LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, |
| 918 | LookupNameKind NameKind, |
| 919 | bool RedeclarationOnly = false); |
| 920 | LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS, |
| 921 | DeclarationName Name, |
| 922 | LookupNameKind NameKind, |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 923 | bool RedeclarationOnly = false, |
| 924 | bool AllowBuiltinCreation = true, |
| 925 | SourceLocation Loc = SourceLocation()); |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 926 | |
| 927 | typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet; |
| 928 | typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; |
| 929 | |
| 930 | void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs, |
| 931 | AssociatedNamespaceSet &AssociatedNamespaces, |
| 932 | AssociatedClassSet &AssociatedClasses); |
| 933 | |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 934 | bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name, |
| 935 | SourceLocation NameLoc, |
| 936 | SourceRange LookupRange = SourceRange()); |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 937 | //@} |
| 938 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 939 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 940 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 941 | Scope *S, bool ForRedeclaration, |
| 942 | SourceLocation Loc); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 943 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
| 944 | Scope *S); |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 945 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 946 | |
| 947 | // More parsing and symbol table subroutines. |
| 948 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 949 | // Decl attributes - this routine is the top level dispatcher. |
Chris Lattner | e5c5ee1 | 2008-06-29 00:16:31 +0000 | [diff] [blame] | 950 | void ProcessDeclAttributes(Decl *D, const Declarator &PD); |
Chris Lattner | f2e4bd5 | 2008-06-28 23:58:55 +0000 | [diff] [blame] | 951 | void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 952 | |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 953 | void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, |
| 954 | bool &IncompleteImpl); |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 955 | void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod, |
| 956 | ObjCMethodDecl *IntfMethod); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 957 | |
| 958 | NamespaceDecl *GetStdNamespace(); |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 959 | |
| 960 | bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, |
Steve Naroff | 22dc0b0 | 2009-02-26 19:11:32 +0000 | [diff] [blame] | 961 | ObjCInterfaceDecl *IDecl); |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 962 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 963 | /// CheckProtocolMethodDefs - This routine checks unimplemented |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 964 | /// methods declared in protocol, and those referenced by it. |
| 965 | /// \param IDecl - Used for checking for methods which may have been |
| 966 | /// inherited. |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 967 | void CheckProtocolMethodDefs(SourceLocation ImpLoc, |
| 968 | ObjCProtocolDecl *PDecl, |
Fariborz Jahanian | ca3adf7 | 2007-10-02 20:06:01 +0000 | [diff] [blame] | 969 | bool& IncompleteImpl, |
Steve Naroff | eefc418 | 2007-10-08 21:05:34 +0000 | [diff] [blame] | 970 | const llvm::DenseSet<Selector> &InsMap, |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 971 | const llvm::DenseSet<Selector> &ClsMap, |
| 972 | ObjCInterfaceDecl *IDecl); |
Fariborz Jahanian | 8c74fa4 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 973 | |
Steve Naroff | a5997c4 | 2007-10-02 21:43:37 +0000 | [diff] [blame] | 974 | /// CheckImplementationIvars - This routine checks if the instance variables |
| 975 | /// listed in the implelementation match those listed in the interface. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 976 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
| 977 | ObjCIvarDecl **Fields, unsigned nIvars, |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 978 | SourceLocation Loc); |
Steve Naroff | a5997c4 | 2007-10-02 21:43:37 +0000 | [diff] [blame] | 979 | |
Fariborz Jahanian | 8c74fa4 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 980 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 981 | /// remains unimplemented in the class or category @implementation. |
| 982 | void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, |
| 983 | ObjCContainerDecl* IDecl, |
| 984 | bool IncompleteImpl = false); |
Fariborz Jahanian | 8c74fa4 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 985 | |
Fariborz Jahanian | 85ff264 | 2007-10-05 18:00:57 +0000 | [diff] [blame] | 986 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
| 987 | /// true, or false, accordingly. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 988 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 989 | const ObjCMethodDecl *PrevMethod, |
| 990 | bool matchBasedOnSizeAndAlignment = false); |
Steve Naroff | 3b95017 | 2007-10-10 21:53:07 +0000 | [diff] [blame] | 991 | |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 992 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
| 993 | /// unit are added to a global pool. This allows us to efficiently associate |
| 994 | /// a selector with a method declaraation for purposes of typechecking |
| 995 | /// messages sent to "id" (where the class of the object is unknown). |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 996 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method); |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 997 | |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 998 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
| 999 | /// there are multiple signatures. |
| 1000 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R); |
| 1001 | |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 1002 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1003 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1004 | //===--------------------------------------------------------------------===// |
| 1005 | // Statement Parsing Callbacks: SemaStmt.cpp. |
| 1006 | public: |
Sebastian Redl | a60528c | 2008-12-21 12:04:03 +0000 | [diff] [blame] | 1007 | virtual OwningStmtResult ActOnExprStmt(ExprArg Expr); |
| 1008 | |
| 1009 | virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc); |
| 1010 | virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
| 1011 | MultiStmtArg Elts, |
| 1012 | bool isStmtExpr); |
| 1013 | virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc, |
| 1014 | SourceLocation EndLoc); |
Sebastian Redl | 117054a | 2008-12-28 16:13:43 +0000 | [diff] [blame] | 1015 | virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal, |
| 1016 | SourceLocation DotDotDotLoc, ExprArg RHSVal, |
Chris Lattner | 24e1e70 | 2009-03-04 04:23:07 +0000 | [diff] [blame] | 1017 | SourceLocation ColonLoc); |
| 1018 | virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt); |
| 1019 | |
Sebastian Redl | 117054a | 2008-12-28 16:13:43 +0000 | [diff] [blame] | 1020 | virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
| 1021 | SourceLocation ColonLoc, |
| 1022 | StmtArg SubStmt, Scope *CurScope); |
Sebastian Redl | de30747 | 2009-01-11 00:38:46 +0000 | [diff] [blame] | 1023 | virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc, |
| 1024 | IdentifierInfo *II, |
| 1025 | SourceLocation ColonLoc, |
| 1026 | StmtArg SubStmt); |
| 1027 | virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal, |
| 1028 | StmtArg ThenVal, SourceLocation ElseLoc, |
| 1029 | StmtArg ElseVal); |
| 1030 | virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond); |
| 1031 | virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
| 1032 | StmtArg Switch, StmtArg Body); |
Sebastian Redl | f05b152 | 2009-01-16 23:28:06 +0000 | [diff] [blame] | 1033 | virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, |
| 1034 | StmtArg Body); |
| 1035 | virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 1036 | SourceLocation WhileLoc, ExprArg Cond); |
| 1037 | |
| 1038 | virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc, |
| 1039 | SourceLocation LParenLoc, |
| 1040 | StmtArg First, ExprArg Second, |
| 1041 | ExprArg Third, SourceLocation RParenLoc, |
| 1042 | StmtArg Body); |
| 1043 | virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
| 1044 | SourceLocation LParenLoc, |
| 1045 | StmtArg First, ExprArg Second, |
| 1046 | SourceLocation RParenLoc, StmtArg Body); |
Sebastian Redl | 4cffe2f | 2009-01-18 13:19:59 +0000 | [diff] [blame] | 1047 | |
| 1048 | virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
| 1049 | SourceLocation LabelLoc, |
| 1050 | IdentifierInfo *LabelII); |
| 1051 | virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
| 1052 | SourceLocation StarLoc, |
| 1053 | ExprArg DestExp); |
| 1054 | virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc, |
| 1055 | Scope *CurScope); |
| 1056 | virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc, |
| 1057 | Scope *CurScope); |
| 1058 | |
| 1059 | virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc, |
| 1060 | ExprArg RetValExp); |
| 1061 | OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, |
| 1062 | Expr *RetValExp); |
| 1063 | |
Sebastian Redl | 3037ed0 | 2009-01-18 16:53:17 +0000 | [diff] [blame] | 1064 | virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc, |
| 1065 | bool IsSimple, |
| 1066 | bool IsVolatile, |
| 1067 | unsigned NumOutputs, |
| 1068 | unsigned NumInputs, |
| 1069 | std::string *Names, |
| 1070 | MultiExprArg Constraints, |
| 1071 | MultiExprArg Exprs, |
| 1072 | ExprArg AsmString, |
| 1073 | MultiExprArg Clobbers, |
| 1074 | SourceLocation RParenLoc); |
Sebastian Redl | 431e90e | 2009-01-18 17:43:11 +0000 | [diff] [blame] | 1075 | |
| 1076 | virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, |
| 1077 | SourceLocation RParen, |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1078 | DeclTy *Parm, StmtArg Body, |
Sebastian Redl | 431e90e | 2009-01-18 17:43:11 +0000 | [diff] [blame] | 1079 | StmtArg CatchList); |
| 1080 | |
| 1081 | virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, |
| 1082 | StmtArg Body); |
| 1083 | |
| 1084 | virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, |
| 1085 | StmtArg Try, |
| 1086 | StmtArg Catch, StmtArg Finally); |
| 1087 | |
| 1088 | virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, |
Steve Naroff | e21dd6f | 2009-02-11 20:05:44 +0000 | [diff] [blame] | 1089 | ExprArg Throw, |
| 1090 | Scope *CurScope); |
Sebastian Redl | 431e90e | 2009-01-18 17:43:11 +0000 | [diff] [blame] | 1091 | virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 1092 | ExprArg SynchExpr, |
| 1093 | StmtArg SynchBody); |
Sebastian Redl | a0fd865 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 1094 | |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 1095 | virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
| 1096 | virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
| 1097 | DeclTy *ExDecl, |
| 1098 | StmtArg HandlerBlock); |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 1099 | virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc, |
| 1100 | StmtArg TryBlock, |
| 1101 | MultiStmtArg Handlers); |
Sebastian Redl | a0fd865 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 1102 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1103 | //===--------------------------------------------------------------------===// |
| 1104 | // Expression Parsing Callbacks: SemaExpr.cpp. |
| 1105 | |
Douglas Gregor | 48f3bb9 | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 1106 | bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc); |
Chris Lattner | 76a642f | 2009-02-15 22:43:40 +0000 | [diff] [blame] | 1107 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1108 | // Primary Expressions. |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 1109 | virtual SourceRange getExprRange(ExprTy *E) const; |
| 1110 | |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1111 | virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc, |
| 1112 | IdentifierInfo &II, |
| 1113 | bool HasTrailingLParen, |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 1114 | const CXXScopeSpec *SS = 0, |
| 1115 | bool isAddressOfOperand = false); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1116 | virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S, |
Douglas Gregor | 487a75a | 2008-11-19 19:09:45 +0000 | [diff] [blame] | 1117 | SourceLocation OperatorLoc, |
| 1118 | OverloadedOperatorKind Op, |
| 1119 | bool HasTrailingLParen, |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 1120 | const CXXScopeSpec &SS, |
| 1121 | bool isAddressOfOperand); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1122 | virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S, |
Douglas Gregor | 487a75a | 2008-11-19 19:09:45 +0000 | [diff] [blame] | 1123 | SourceLocation OperatorLoc, |
| 1124 | TypeTy *Ty, |
| 1125 | bool HasTrailingLParen, |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 1126 | const CXXScopeSpec &SS, |
| 1127 | bool isAddressOfOperand); |
Douglas Gregor | 1a49af9 | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 1128 | DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc, |
| 1129 | bool TypeDependent, bool ValueDependent, |
| 1130 | const CXXScopeSpec *SS = 0); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1131 | OwningExprResult |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 1132 | BuildAnonymousStructUnionMemberReference(SourceLocation Loc, |
| 1133 | FieldDecl *Field, |
| 1134 | Expr *BaseObjectExpr = 0, |
| 1135 | SourceLocation OpLoc = SourceLocation()); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1136 | OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, |
| 1137 | DeclarationName Name, |
| 1138 | bool HasTrailingLParen, |
| 1139 | const CXXScopeSpec *SS, |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 1140 | bool isAddressOfOperand = false); |
Douglas Gregor | 10c4262 | 2008-11-18 15:03:34 +0000 | [diff] [blame] | 1141 | |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1142 | virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc, |
| 1143 | tok::TokenKind Kind); |
| 1144 | virtual OwningExprResult ActOnNumericConstant(const Token &); |
| 1145 | virtual OwningExprResult ActOnCharacterConstant(const Token &); |
| 1146 | virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, |
| 1147 | ExprArg Val); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1148 | |
Steve Naroff | f69936d | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1149 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1150 | /// fragments (e.g. "foo" "bar" L"baz"). |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1151 | virtual OwningExprResult ActOnStringLiteral(const Token *Toks, |
| 1152 | unsigned NumToks); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1153 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1154 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1155 | virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, |
| 1156 | tok::TokenKind Op, ExprArg Input); |
| 1157 | virtual OwningExprResult |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 1158 | ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType, |
| 1159 | void *TyOrEx, const SourceRange &ArgRange); |
| 1160 | |
Chris Lattner | 31e21e0 | 2009-01-24 20:17:12 +0000 | [diff] [blame] | 1161 | bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R); |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 1162 | bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc, |
| 1163 | const SourceRange &R, bool isSizeof); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1164 | |
| 1165 | virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
| 1166 | tok::TokenKind Kind, |
| 1167 | ExprArg Input); |
| 1168 | |
| 1169 | virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base, |
| 1170 | SourceLocation LLoc, |
| 1171 | ExprArg Idx, |
| 1172 | SourceLocation RLoc); |
| 1173 | virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base, |
| 1174 | SourceLocation OpLoc, |
| 1175 | tok::TokenKind OpKind, |
| 1176 | SourceLocation MemberLoc, |
Fariborz Jahanian | a6e3ac5 | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1177 | IdentifierInfo &Member, |
| 1178 | DeclTy *ImplDecl=0); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1179 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 1180 | FunctionDecl *FDecl, |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1181 | const FunctionProtoType *Proto, |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 1182 | Expr **Args, unsigned NumArgs, |
| 1183 | SourceLocation RParenLoc); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1184 | |
Steve Naroff | f69936d | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1185 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1186 | /// This provides the location of the left/right parens and a list of comma |
| 1187 | /// locations. |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1188 | virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn, |
| 1189 | SourceLocation LParenLoc, |
| 1190 | MultiExprArg Args, |
| 1191 | SourceLocation *CommaLocs, |
| 1192 | SourceLocation RParenLoc); |
| 1193 | |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 1194 | virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
| 1195 | SourceLocation RParenLoc, ExprArg Op); |
| 1196 | |
| 1197 | virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, |
| 1198 | TypeTy *Ty, |
| 1199 | SourceLocation RParenLoc, |
| 1200 | ExprArg Op); |
| 1201 | |
| 1202 | virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc, |
| 1203 | MultiExprArg InitList, |
| 1204 | InitListDesignations &Designators, |
| 1205 | SourceLocation RParenLoc); |
| 1206 | |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 1207 | virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig, |
| 1208 | SourceLocation Loc, |
| 1209 | bool UsedColonSyntax, |
| 1210 | OwningExprResult Init); |
| 1211 | |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 1212 | virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
| 1213 | tok::TokenKind Kind, |
| 1214 | ExprArg LHS, ExprArg RHS); |
| 1215 | OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc, |
| 1216 | unsigned Opc, Expr *lhs, Expr *rhs); |
Douglas Gregor | eaebc75 | 2008-11-06 23:29:22 +0000 | [diff] [blame] | 1217 | |
Steve Naroff | f69936d | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1218 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1219 | /// in the case of a the GNU conditional expr extension. |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 1220 | virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
| 1221 | SourceLocation ColonLoc, |
| 1222 | ExprArg Cond, ExprArg LHS, |
| 1223 | ExprArg RHS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1224 | |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1225 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
| 1226 | virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1227 | IdentifierInfo *LabelII); |
| 1228 | |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1229 | virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt, |
Chris Lattner | ab18c4c | 2007-07-24 16:58:17 +0000 | [diff] [blame] | 1230 | SourceLocation RPLoc); // "({..})" |
Chris Lattner | 73d0d4f | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 1231 | |
| 1232 | /// __builtin_offsetof(type, a.b[123][456].c) |
Douglas Gregor | 3fc749d | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 1233 | virtual ExprResult ActOnBuiltinOffsetOf(Scope *S, |
| 1234 | SourceLocation BuiltinLoc, |
Chris Lattner | 73d0d4f | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 1235 | SourceLocation TypeLoc, TypeTy *Arg1, |
| 1236 | OffsetOfComponent *CompPtr, |
| 1237 | unsigned NumComponents, |
| 1238 | SourceLocation RParenLoc); |
| 1239 | |
Steve Naroff | d34e915 | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 1240 | // __builtin_types_compatible_p(type1, type2) |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1241 | virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, |
Steve Naroff | d34e915 | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 1242 | TypeTy *arg1, TypeTy *arg2, |
| 1243 | SourceLocation RPLoc); |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 1244 | |
| 1245 | // __builtin_choose_expr(constExpr, expr1, expr2) |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1246 | virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 1247 | ExprTy *cond, ExprTy *expr1, ExprTy *expr2, |
| 1248 | SourceLocation RPLoc); |
Chris Lattner | ab18c4c | 2007-07-24 16:58:17 +0000 | [diff] [blame] | 1249 | |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 1250 | // __builtin_va_arg(expr, type) |
| 1251 | virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc, |
| 1252 | ExprTy *expr, TypeTy *type, |
| 1253 | SourceLocation RPLoc); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 1255 | // __null |
| 1256 | virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
| 1257 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1258 | //===------------------------- "Block" Extension ------------------------===// |
| 1259 | |
| 1260 | /// ActOnBlockStart - This callback is invoked when a block literal is |
| 1261 | /// started. |
Steve Naroff | 090276f | 2008-10-10 01:28:17 +0000 | [diff] [blame] | 1262 | virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
| 1263 | |
| 1264 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
| 1265 | /// If there are no arguments, this is still invoked. |
Mike Stump | 98eb8a7 | 2009-02-04 22:31:32 +0000 | [diff] [blame] | 1266 | virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1267 | |
| 1268 | /// ActOnBlockError - If there is an error parsing a block, this callback |
| 1269 | /// is invoked to pop the information about the block from the action impl. |
| 1270 | virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
| 1271 | |
| 1272 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
| 1273 | /// literal was successfully completed. ^(int x){...} |
| 1274 | virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body, |
| 1275 | Scope *CurScope); |
| 1276 | |
Chris Lattner | 76a642f | 2009-02-15 22:43:40 +0000 | [diff] [blame] | 1277 | //===---------------------------- C++ Features --------------------------===// |
| 1278 | |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 1279 | // Act on C++ namespaces |
| 1280 | virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc, |
| 1281 | IdentifierInfo *Ident, |
| 1282 | SourceLocation LBrace); |
| 1283 | virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace); |
| 1284 | |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 1285 | virtual DeclTy *ActOnUsingDirective(Scope *CurScope, |
| 1286 | SourceLocation UsingLoc, |
| 1287 | SourceLocation NamespcLoc, |
| 1288 | const CXXScopeSpec &SS, |
| 1289 | SourceLocation IdentLoc, |
| 1290 | IdentifierInfo *NamespcName, |
| 1291 | AttributeList *AttrList); |
| 1292 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1293 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
| 1294 | |
Argyrios Kyrtzidis | 73a0d88 | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 1295 | /// AddCXXDirectInitializerToDecl - This action is called immediately after |
| 1296 | /// ActOnDeclarator, when a C++ direct initializer is present. |
| 1297 | /// e.g: "int x(1);" |
| 1298 | virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl, |
| 1299 | SourceLocation LParenLoc, |
| 1300 | ExprTy **Exprs, unsigned NumExprs, |
| 1301 | SourceLocation *CommaLocs, |
| 1302 | SourceLocation RParenLoc); |
| 1303 | |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1304 | /// InitializationKind - Represents which kind of C++ initialization |
| 1305 | /// [dcl.init] a routine is to perform. |
| 1306 | enum InitializationKind { |
| 1307 | IK_Direct, ///< Direct initialization |
| 1308 | IK_Copy, ///< Copy initialization |
| 1309 | IK_Default ///< Default initialization |
| 1310 | }; |
| 1311 | |
Douglas Gregor | 18fe568 | 2008-11-03 20:45:27 +0000 | [diff] [blame] | 1312 | CXXConstructorDecl * |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1313 | PerformInitializationByConstructor(QualType ClassType, |
| 1314 | Expr **Args, unsigned NumArgs, |
| 1315 | SourceLocation Loc, SourceRange Range, |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 1316 | DeclarationName InitEntity, |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1317 | InitializationKind Kind); |
Douglas Gregor | 18fe568 | 2008-11-03 20:45:27 +0000 | [diff] [blame] | 1318 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 1319 | /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. |
| 1320 | virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, |
| 1321 | SourceLocation LAngleBracketLoc, TypeTy *Ty, |
| 1322 | SourceLocation RAngleBracketLoc, |
| 1323 | SourceLocation LParenLoc, ExprTy *E, |
| 1324 | SourceLocation RParenLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1325 | |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1326 | /// ActOnCXXTypeidOfType - Parse typeid( type-id ). |
| 1327 | virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
| 1328 | SourceLocation LParenLoc, bool isType, |
| 1329 | void *TyOrExpr, SourceLocation RParenLoc); |
| 1330 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1331 | //// ActOnCXXThis - Parse 'this' pointer. |
| 1332 | virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc); |
| 1333 | |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1334 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
| 1335 | virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1336 | tok::TokenKind Kind); |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1337 | |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1338 | //// ActOnCXXThrow - Parse throw expressions. |
| 1339 | virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc, |
| 1340 | ExprTy *expr); |
| 1341 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1342 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
| 1343 | /// Can be interpreted either as function-style casting ("int(x)") |
| 1344 | /// or class type construction ("ClassType(x,y,z)") |
| 1345 | /// or creation of a value-initialized type ("int()"). |
| 1346 | virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange, |
| 1347 | TypeTy *TypeRep, |
| 1348 | SourceLocation LParenLoc, |
| 1349 | ExprTy **Exprs, |
| 1350 | unsigned NumExprs, |
| 1351 | SourceLocation *CommaLocs, |
| 1352 | SourceLocation RParenLoc); |
| 1353 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1354 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
| 1355 | virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
| 1356 | SourceLocation PlacementLParen, |
| 1357 | ExprTy **PlacementArgs, unsigned NumPlaceArgs, |
| 1358 | SourceLocation PlacementRParen, |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 1359 | bool ParenTypeId, Declarator &D, |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1360 | SourceLocation ConstructorLParen, |
| 1361 | ExprTy **ConstructorArgs, unsigned NumConsArgs, |
| 1362 | SourceLocation ConstructorRParen); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 1363 | bool CheckAllocatedType(QualType AllocType, const Declarator &D); |
Sebastian Redl | 00e68e2 | 2009-02-09 18:24:27 +0000 | [diff] [blame] | 1364 | bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, |
| 1365 | bool UseGlobal, QualType AllocType, bool IsArray, |
Sebastian Redl | b5a57a6 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 1366 | Expr **PlaceArgs, unsigned NumPlaceArgs, |
| 1367 | FunctionDecl *&OperatorNew, |
| 1368 | FunctionDecl *&OperatorDelete); |
Sebastian Redl | 00e68e2 | 2009-02-09 18:24:27 +0000 | [diff] [blame] | 1369 | bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, |
| 1370 | DeclarationName Name, Expr** Args, |
| 1371 | unsigned NumArgs, DeclContext *Ctx, |
Sebastian Redl | 7f66239 | 2008-12-04 22:20:51 +0000 | [diff] [blame] | 1372 | bool AllowMissing, FunctionDecl *&Operator); |
Sebastian Redl | b5a57a6 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 1373 | void DeclareGlobalNewDelete(); |
| 1374 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
| 1375 | QualType Argument); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1376 | |
| 1377 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
| 1378 | virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, |
| 1379 | bool ArrayForm, ExprTy *Operand); |
| 1380 | |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 1381 | /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a |
| 1382 | /// C++ if/switch/while/for statement. |
| 1383 | /// e.g: "if (int x = f()) {...}" |
| 1384 | virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S, |
| 1385 | SourceLocation StartLoc, |
| 1386 | Declarator &D, |
| 1387 | SourceLocation EqualLoc, |
| 1388 | ExprTy *AssignExprVal); |
| 1389 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1390 | /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support |
| 1391 | /// pseudo-functions. |
| 1392 | virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, |
| 1393 | SourceLocation KWLoc, |
| 1394 | SourceLocation LParen, |
| 1395 | TypeTy *Ty, |
| 1396 | SourceLocation RParen); |
| 1397 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1398 | /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the |
| 1399 | /// global scope ('::'). |
| 1400 | virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S, |
| 1401 | SourceLocation CCLoc); |
| 1402 | |
| 1403 | /// ActOnCXXNestedNameSpecifier - Called during parsing of a |
| 1404 | /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now |
| 1405 | /// we want to resolve "bar::". 'SS' is empty or the previously parsed |
| 1406 | /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar', |
| 1407 | /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'. |
| 1408 | /// Returns a CXXScopeTy* object representing the C++ scope. |
| 1409 | virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S, |
| 1410 | const CXXScopeSpec &SS, |
| 1411 | SourceLocation IdLoc, |
| 1412 | SourceLocation CCLoc, |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 1413 | IdentifierInfo &II); |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1414 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1415 | /// ActOnCXXNestedNameSpecifier - Called during parsing of a |
| 1416 | /// nested-name-specifier that involves a template-id, e.g., |
| 1417 | /// "foo::bar<int, float>::", and now we need to build a scope |
| 1418 | /// specifier. \p SS is empty or the previously parsed nested-name |
| 1419 | /// part ("foo::"), \p Type is the already-parsed class template |
| 1420 | /// specialization (or other template-id that names a type), \p |
| 1421 | /// TypeRange is the source range where the type is located, and \p |
| 1422 | /// CCLoc is the location of the trailing '::'. |
| 1423 | virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S, |
| 1424 | const CXXScopeSpec &SS, |
| 1425 | TypeTy *Type, |
| 1426 | SourceRange TypeRange, |
| 1427 | SourceLocation CCLoc); |
| 1428 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1429 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
| 1430 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
| 1431 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
| 1432 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
| 1433 | /// ActOnCXXExitDeclaratorScope is called. |
| 1434 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
| 1435 | virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
| 1436 | |
| 1437 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
| 1438 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
| 1439 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
| 1440 | /// Used to indicate that names should revert to being looked up in the |
| 1441 | /// defining scope. |
Douglas Gregor | 0a59acb | 2008-12-16 00:38:16 +0000 | [diff] [blame] | 1442 | virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1443 | |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1444 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1445 | virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
| 1446 | ExprTy **Strings, |
| 1447 | unsigned NumStrings); |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1448 | virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
Chris Lattner | 674af95 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1449 | SourceLocation EncodeLoc, |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1450 | SourceLocation LParenLoc, |
| 1451 | TypeTy *Ty, |
| 1452 | SourceLocation RParenLoc); |
| 1453 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1454 | // ParseObjCSelectorExpression - Build selector expression for @selector |
| 1455 | virtual ExprResult ParseObjCSelectorExpression(Selector Sel, |
| 1456 | SourceLocation AtLoc, |
Fariborz Jahanian | 2a35fa9 | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1457 | SourceLocation SelLoc, |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1458 | SourceLocation LParenLoc, |
| 1459 | SourceLocation RParenLoc); |
| 1460 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1461 | // ParseObjCProtocolExpression - Build protocol expression for @protocol |
| 1462 | virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, |
| 1463 | SourceLocation AtLoc, |
| 1464 | SourceLocation ProtoLoc, |
| 1465 | SourceLocation LParenLoc, |
| 1466 | SourceLocation RParenLoc); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1467 | |
| 1468 | //===--------------------------------------------------------------------===// |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 1469 | // C++ Declarations |
| 1470 | // |
| 1471 | virtual DeclTy *ActOnStartLinkageSpecification(Scope *S, |
| 1472 | SourceLocation ExternLoc, |
| 1473 | SourceLocation LangLoc, |
| 1474 | const char *Lang, |
| 1475 | unsigned StrSize, |
| 1476 | SourceLocation LBraceLoc); |
| 1477 | virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S, |
| 1478 | DeclTy *LinkageSpec, |
| 1479 | SourceLocation RBraceLoc); |
| 1480 | |
| 1481 | |
| 1482 | //===--------------------------------------------------------------------===// |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1483 | // C++ Classes |
| 1484 | // |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1485 | virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
| 1486 | const CXXScopeSpec *SS); |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1487 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1488 | virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, |
| 1489 | Declarator &D, ExprTy *BitfieldWidth, |
| 1490 | ExprTy *Init, DeclTy *LastInGroup); |
| 1491 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1492 | virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD, |
| 1493 | Scope *S, |
| 1494 | IdentifierInfo *MemberOrBase, |
| 1495 | SourceLocation IdLoc, |
| 1496 | SourceLocation LParenLoc, |
| 1497 | ExprTy **Args, unsigned NumArgs, |
| 1498 | SourceLocation *CommaLocs, |
| 1499 | SourceLocation RParenLoc); |
| 1500 | |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 1501 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
| 1502 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1503 | virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, |
| 1504 | DeclTy *TagDecl, |
| 1505 | SourceLocation LBrac, |
| 1506 | SourceLocation RBrac); |
| 1507 | |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1508 | virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method); |
| 1509 | virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param); |
| 1510 | virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method); |
| 1511 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1512 | bool CheckConstructorDeclarator(Declarator &D, QualType &R, |
| 1513 | FunctionDecl::StorageClass& SC); |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1514 | bool CheckConstructor(CXXConstructorDecl *Constructor); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1515 | bool CheckDestructorDeclarator(Declarator &D, QualType &R, |
| 1516 | FunctionDecl::StorageClass& SC); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1517 | bool CheckConversionDeclarator(Declarator &D, QualType &R, |
| 1518 | FunctionDecl::StorageClass& SC); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1519 | DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1520 | |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 1521 | //===--------------------------------------------------------------------===// |
| 1522 | // C++ Derived Classes |
| 1523 | // |
| 1524 | |
| 1525 | /// ActOnBaseSpecifier - Parsed a base specifier |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1526 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
| 1527 | SourceRange SpecifierRange, |
| 1528 | bool Virtual, AccessSpecifier Access, |
| 1529 | QualType BaseType, |
| 1530 | SourceLocation BaseLoc); |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 1531 | virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl, |
| 1532 | SourceRange SpecifierRange, |
| 1533 | bool Virtual, AccessSpecifier Access, |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1534 | TypeTy *basetype, SourceLocation |
| 1535 | BaseLoc); |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 1536 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1537 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, |
| 1538 | unsigned NumBases); |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 1539 | virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases, |
| 1540 | unsigned NumBases); |
| 1541 | |
| 1542 | bool IsDerivedFrom(QualType Derived, QualType Base); |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 1543 | bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths); |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 1544 | bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria, |
| 1545 | BasePaths &Paths); |
Douglas Gregor | 0575d4a | 2008-10-24 16:17:19 +0000 | [diff] [blame] | 1546 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
| 1547 | SourceLocation Loc, SourceRange Range); |
Douglas Gregor | 4dc6b1c | 2009-01-16 00:38:09 +0000 | [diff] [blame] | 1548 | std::string getAmbiguousPathsDisplayString(BasePaths &Paths); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1549 | |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 1550 | //===--------------------------------------------------------------------===// |
| 1551 | // C++ Overloaded Operators [C++ 13.5] |
| 1552 | // |
| 1553 | |
| 1554 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
| 1555 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1556 | //===--------------------------------------------------------------------===// |
| 1557 | // C++ Templates [C++ 14] |
| 1558 | // |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1559 | virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S, |
| 1560 | DeclTy *&TemplateDecl, |
| 1561 | const CXXScopeSpec *SS = 0); |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1562 | bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 1563 | TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl); |
| 1564 | |
| 1565 | virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename, |
| 1566 | SourceLocation KeyLoc, |
| 1567 | IdentifierInfo *ParamName, |
| 1568 | SourceLocation ParamNameLoc, |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 1569 | unsigned Depth, unsigned Position); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 1570 | virtual void ActOnTypeParameterDefault(DeclTy *TypeParam, |
| 1571 | SourceLocation EqualLoc, |
| 1572 | SourceLocation DefaultLoc, |
| 1573 | TypeTy *Default); |
| 1574 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1575 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 1576 | virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 1577 | unsigned Depth, |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 1578 | unsigned Position); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 1579 | virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam, |
| 1580 | SourceLocation EqualLoc, |
| 1581 | ExprArg Default); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 1582 | virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S, |
| 1583 | SourceLocation TmpLoc, |
| 1584 | TemplateParamsTy *Params, |
| 1585 | IdentifierInfo *ParamName, |
| 1586 | SourceLocation ParamNameLoc, |
| 1587 | unsigned Depth, |
| 1588 | unsigned Position); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 1589 | virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam, |
| 1590 | SourceLocation EqualLoc, |
| 1591 | ExprArg Default); |
| 1592 | |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 1593 | virtual TemplateParamsTy * |
| 1594 | ActOnTemplateParameterList(unsigned Depth, |
| 1595 | SourceLocation ExportLoc, |
| 1596 | SourceLocation TemplateLoc, |
| 1597 | SourceLocation LAngleLoc, |
| 1598 | DeclTy **Params, unsigned NumParams, |
| 1599 | SourceLocation RAngleLoc); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 1600 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
| 1601 | TemplateParameterList *OldParams); |
| 1602 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1603 | virtual DeclTy * |
| 1604 | ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK, |
| 1605 | SourceLocation KWLoc, const CXXScopeSpec &SS, |
| 1606 | IdentifierInfo *Name, SourceLocation NameLoc, |
| 1607 | AttributeList *Attr, |
| 1608 | MultiTemplateParamsArg TemplateParameterLists); |
| 1609 | |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1610 | QualType CheckClassTemplateId(ClassTemplateDecl *ClassTemplate, |
| 1611 | SourceLocation TemplateLoc, |
| 1612 | SourceLocation LAngleLoc, |
| 1613 | const TemplateArgument *TemplateArgs, |
| 1614 | unsigned NumTemplateArgs, |
| 1615 | SourceLocation RAngleLoc); |
| 1616 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1617 | virtual TypeResult |
| 1618 | ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc, |
| 1619 | SourceLocation LAngleLoc, |
| 1620 | ASTTemplateArgsPtr TemplateArgs, |
| 1621 | SourceLocation *TemplateArgLocs, |
| 1622 | SourceLocation RAngleLoc, |
| 1623 | const CXXScopeSpec *SS); |
| 1624 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 1625 | bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate, |
| 1626 | ClassTemplateSpecializationDecl *PrevDecl, |
| 1627 | SourceLocation TemplateNameLoc, |
| 1628 | SourceRange ScopeSpecifierRange); |
| 1629 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1630 | virtual DeclTy * |
| 1631 | ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK, |
| 1632 | SourceLocation KWLoc, |
| 1633 | const CXXScopeSpec &SS, |
| 1634 | DeclTy *Template, |
| 1635 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1636 | SourceLocation LAngleLoc, |
Douglas Gregor | 5908e9f | 2009-02-09 19:34:22 +0000 | [diff] [blame] | 1637 | ASTTemplateArgsPtr TemplateArgs, |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 1638 | SourceLocation *TemplateArgLocs, |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1639 | SourceLocation RAngleLoc, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1640 | AttributeList *Attr, |
| 1641 | MultiTemplateParamsArg TemplateParameterLists); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1642 | |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 1643 | bool CheckTemplateArgumentList(TemplateDecl *Template, |
| 1644 | SourceLocation TemplateLoc, |
| 1645 | SourceLocation LAngleLoc, |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1646 | const TemplateArgument *TemplateArgs, |
| 1647 | unsigned NumTemplateArgs, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 1648 | SourceLocation RAngleLoc, |
| 1649 | llvm::SmallVectorImpl<TemplateArgument> &Converted); |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 1650 | |
| 1651 | bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg, |
| 1652 | SourceLocation ArgLoc); |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 1653 | bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, |
| 1654 | NamedDecl *&Entity); |
| 1655 | bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1656 | bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param, |
| 1657 | QualType InstantiatedParamType, Expr *&Arg, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 1658 | llvm::SmallVectorImpl<TemplateArgument> *Converted = 0); |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 1659 | bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1660 | bool TemplateParameterListsAreEqual(TemplateParameterList *New, |
| 1661 | TemplateParameterList *Old, |
| 1662 | bool Complain, |
Douglas Gregor | dd0574e | 2009-02-10 00:24:35 +0000 | [diff] [blame] | 1663 | bool IsTemplateTemplateParm = false, |
| 1664 | SourceLocation TemplateArgLoc |
| 1665 | = SourceLocation()); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1666 | |
| 1667 | bool CheckTemplateDeclScope(Scope *S, |
| 1668 | MultiTemplateParamsArg &TemplateParameterLists); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 1669 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1670 | //===--------------------------------------------------------------------===// |
| 1671 | // C++ Template Instantiation |
| 1672 | // |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 1673 | |
| 1674 | /// \brief A template instantiation that is currently in progress. |
| 1675 | struct ActiveTemplateInstantiation { |
| 1676 | /// \brief The point of instantiation within the source code. |
| 1677 | SourceLocation PointOfInstantiation; |
| 1678 | |
| 1679 | /// \brief The entity that is being instantiated. |
| 1680 | ClassTemplateSpecializationDecl *Entity; |
| 1681 | |
| 1682 | /// \brief The source range that covers the construct that cause |
| 1683 | /// the instantiation, e.g., the template-id that causes a class |
| 1684 | /// template instantiation. |
| 1685 | SourceRange InstantiationRange; |
| 1686 | }; |
| 1687 | |
| 1688 | /// \brief List of active template instantiations. |
| 1689 | /// |
| 1690 | /// This vector is treated as a stack. As one template instantiation |
| 1691 | /// requires another template instantiation, additional |
| 1692 | /// instantiations are pushed onto the stack up to a |
| 1693 | /// user-configurable limit LangOptions::InstantiationDepth. |
| 1694 | llvm::SmallVector<ActiveTemplateInstantiation, 16> |
| 1695 | ActiveTemplateInstantiations; |
| 1696 | |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame^] | 1697 | /// \brief The last template from which a template instantiation |
| 1698 | /// error or warning was produced. |
| 1699 | /// |
| 1700 | /// This value is used to suppress printing of redundant template |
| 1701 | /// instantiation backtraces when there are multiple errors in the |
| 1702 | /// same instantiation. FIXME: Does this belong in Sema? It's tough |
| 1703 | /// to implement it anywhere else. |
| 1704 | ClassTemplateSpecializationDecl *LastTemplateInstantiationErrorContext; |
| 1705 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 1706 | /// \brief A stack object to be created when performing template |
| 1707 | /// instantiation. |
| 1708 | /// |
| 1709 | /// Construction of an object of type \c InstantiatingTemplate |
| 1710 | /// pushes the current instantiation onto the stack of active |
| 1711 | /// instantiations. If the size of this stack exceeds the maximum |
| 1712 | /// number of recursive template instantiations, construction |
| 1713 | /// produces an error and evaluates true. |
| 1714 | /// |
| 1715 | /// Destruction of this object will pop the named instantiation off |
| 1716 | /// the stack. |
| 1717 | struct InstantiatingTemplate { |
| 1718 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 1719 | ClassTemplateSpecializationDecl *Entity, |
| 1720 | SourceRange InstantiationRange = SourceRange()); |
| 1721 | ~InstantiatingTemplate(); |
| 1722 | |
| 1723 | /// \brief Determines whether we have exceeded the maximum |
| 1724 | /// recursive template instantiations. |
| 1725 | operator bool() const { return Invalid; } |
| 1726 | |
| 1727 | private: |
| 1728 | Sema &SemaRef; |
| 1729 | bool Invalid; |
| 1730 | |
| 1731 | InstantiatingTemplate(const InstantiatingTemplate&); // not implemented |
| 1732 | |
| 1733 | InstantiatingTemplate& |
| 1734 | operator=(const InstantiatingTemplate&); // not implemented |
| 1735 | }; |
| 1736 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 1737 | static void PrintInstantiationStackHook(unsigned DiagID, void *Cookie); |
| 1738 | void PrintInstantiationStack(); |
| 1739 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1740 | QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs, |
| 1741 | unsigned NumTemplateArgs, |
| 1742 | SourceLocation Loc, DeclarationName Entity); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1743 | bool |
| 1744 | InstantiateBaseSpecifiers(ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 1745 | ClassTemplateDecl *ClassTemplate); |
| 1746 | bool |
| 1747 | InstantiateClassTemplateSpecialization( |
| 1748 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 1749 | bool ExplicitInstantiation); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1750 | |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1751 | // Objective-C declarations. |
Chris Lattner | 06036d3 | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 1752 | virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, |
| 1753 | IdentifierInfo *ClassName, |
| 1754 | SourceLocation ClassLoc, |
| 1755 | IdentifierInfo *SuperName, |
| 1756 | SourceLocation SuperLoc, |
| 1757 | DeclTy * const *ProtoRefs, |
| 1758 | unsigned NumProtoRefs, |
| 1759 | SourceLocation EndProtoLoc, |
| 1760 | AttributeList *AttrList); |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1761 | |
| 1762 | virtual DeclTy *ActOnCompatiblityAlias( |
| 1763 | SourceLocation AtCompatibilityAliasLoc, |
| 1764 | IdentifierInfo *AliasName, SourceLocation AliasLocation, |
| 1765 | IdentifierInfo *ClassName, SourceLocation ClassLocation); |
Steve Naroff | 61d6852 | 2009-03-05 15:22:01 +0000 | [diff] [blame] | 1766 | |
| 1767 | void CheckForwardProtocolDeclarationForCircularDependency( |
| 1768 | IdentifierInfo *PName, |
| 1769 | SourceLocation &PLoc, SourceLocation PrevLoc, |
| 1770 | const ObjCList<ObjCProtocolDecl> &PList); |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1771 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1772 | virtual DeclTy *ActOnStartProtocolInterface( |
Nate Begeman | 1abc7f6 | 2008-02-20 22:57:40 +0000 | [diff] [blame] | 1773 | SourceLocation AtProtoInterfaceLoc, |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 1774 | IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1775 | DeclTy * const *ProtoRefNames, unsigned NumProtoRefs, |
Daniel Dunbar | 246e70f | 2008-09-26 04:48:09 +0000 | [diff] [blame] | 1776 | SourceLocation EndProtoLoc, |
| 1777 | AttributeList *AttrList); |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 1778 | |
Chris Lattner | 6bd6d0b | 2008-07-26 04:07:02 +0000 | [diff] [blame] | 1779 | virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, |
| 1780 | IdentifierInfo *ClassName, |
| 1781 | SourceLocation ClassLoc, |
| 1782 | IdentifierInfo *CategoryName, |
| 1783 | SourceLocation CategoryLoc, |
| 1784 | DeclTy * const *ProtoRefs, |
| 1785 | unsigned NumProtoRefs, |
| 1786 | SourceLocation EndProtoLoc); |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 1787 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1788 | virtual DeclTy *ActOnStartClassImplementation( |
Nate Begeman | 1abc7f6 | 2008-02-20 22:57:40 +0000 | [diff] [blame] | 1789 | SourceLocation AtClassImplLoc, |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1790 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 1791 | IdentifierInfo *SuperClassname, |
| 1792 | SourceLocation SuperClassLoc); |
| 1793 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1794 | virtual DeclTy *ActOnStartCategoryImplementation( |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 1795 | SourceLocation AtCatImplLoc, |
| 1796 | IdentifierInfo *ClassName, |
| 1797 | SourceLocation ClassLoc, |
| 1798 | IdentifierInfo *CatName, |
| 1799 | SourceLocation CatLoc); |
| 1800 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1801 | virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc, |
Steve Naroff | 37e58d1 | 2007-10-02 22:39:18 +0000 | [diff] [blame] | 1802 | IdentifierInfo **IdentList, |
| 1803 | unsigned NumElts); |
Fariborz Jahanian | 894c57f | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 1804 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1805 | virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1806 | const IdentifierLocPair *IdentList, |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 1807 | unsigned NumElts, |
| 1808 | AttributeList *attrList); |
Fariborz Jahanian | 245f92a | 2007-10-05 21:01:53 +0000 | [diff] [blame] | 1809 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1810 | virtual void FindProtocolDeclaration(bool WarnOnDeclarations, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1811 | const IdentifierLocPair *ProtocolId, |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1812 | unsigned NumProtocols, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1813 | llvm::SmallVectorImpl<DeclTy *> &Protocols); |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 1814 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1815 | /// Ensure attributes are consistent with type. |
| 1816 | /// \param [in, out] Attributes The attributes to check; they will |
| 1817 | /// be modified to be consistent with \arg PropertyTy. |
| 1818 | void CheckObjCPropertyAttributes(QualType PropertyTy, |
| 1819 | SourceLocation Loc, |
| 1820 | unsigned &Attributes); |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 1821 | void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC); |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 1822 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
| 1823 | ObjCPropertyDecl *SuperProperty, |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 1824 | const IdentifierInfo *Name); |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 1825 | void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 1826 | |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 1827 | void MergeProtocolPropertiesIntoClass(Decl *CDecl, |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 1828 | DeclTy *MergeProtocols); |
| 1829 | |
Fariborz Jahanian | b7f95f5 | 2009-03-02 19:05:07 +0000 | [diff] [blame] | 1830 | void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
| 1831 | ObjCInterfaceDecl *ID); |
| 1832 | |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 1833 | void MergeOneProtocolPropertiesIntoClass(Decl *CDecl, |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 1834 | ObjCProtocolDecl *PDecl); |
| 1835 | |
Steve Naroff | 0416fb9 | 2007-11-11 17:19:15 +0000 | [diff] [blame] | 1836 | virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, |
| 1837 | DeclTy **allMethods = 0, unsigned allNum = 0, |
| 1838 | DeclTy **allProperties = 0, unsigned pNum = 0); |
Fariborz Jahanian | d0b90bf | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 1839 | |
Fariborz Jahanian | 1de1e74 | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 1840 | virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc, |
Fariborz Jahanian | 46b55e5 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 1841 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
Fariborz Jahanian | 5251e13 | 2008-05-06 18:09:04 +0000 | [diff] [blame] | 1842 | Selector GetterSel, Selector SetterSel, |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1843 | DeclTy *ClassCategory, bool *OverridingProperty, |
Fariborz Jahanian | 46b55e5 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 1844 | tok::ObjCKeywordKind MethodImplKind); |
| 1845 | |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1846 | virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc, |
| 1847 | SourceLocation PropertyLoc, |
| 1848 | bool ImplKind, DeclTy *ClassImplDecl, |
| 1849 | IdentifierInfo *PropertyId, |
| 1850 | IdentifierInfo *PropertyIvar); |
| 1851 | |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 1852 | virtual DeclTy *ActOnMethodDeclaration( |
| 1853 | SourceLocation BeginLoc, // location of the + or -. |
| 1854 | SourceLocation EndLoc, // location of the ; or {. |
Fariborz Jahanian | 1f7b6f8 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 1855 | tok::TokenKind MethodType, |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1856 | DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, |
Fariborz Jahanian | f1de0ca | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 1857 | Selector Sel, |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1858 | // optional arguments. The number of types/arguments is obtained |
| 1859 | // from the Sel.getNumArgs(). |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1860 | ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames, |
Fariborz Jahanian | 439c658 | 2009-01-09 00:38:19 +0000 | [diff] [blame] | 1861 | llvm::SmallVectorImpl<Declarator> &Cdecls, |
Steve Naroff | 335eafa | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 1862 | AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, |
| 1863 | bool isVariadic = false); |
Steve Naroff | 81bfde9 | 2007-10-16 23:12:48 +0000 | [diff] [blame] | 1864 | |
Steve Naroff | f1afaf6 | 2009-02-26 15:55:06 +0000 | [diff] [blame] | 1865 | // Helper method for ActOnClassMethod/ActOnInstanceMethod. |
| 1866 | // Will search "local" class/category implementations for a method decl. |
Fariborz Jahanian | 175ba1e | 2009-03-04 18:15:57 +0000 | [diff] [blame] | 1867 | // Will also search in class's root looking for instance method. |
Steve Naroff | f1afaf6 | 2009-02-26 15:55:06 +0000 | [diff] [blame] | 1868 | // Returns 0 if no method is found. |
Steve Naroff | 5609ec0 | 2009-03-08 18:56:13 +0000 | [diff] [blame] | 1869 | ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, |
| 1870 | ObjCInterfaceDecl *CDecl); |
| 1871 | ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, |
| 1872 | ObjCInterfaceDecl *ClassDecl); |
Steve Naroff | f1afaf6 | 2009-02-26 15:55:06 +0000 | [diff] [blame] | 1873 | |
Steve Naroff | 61f72cb | 2009-03-09 21:12:44 +0000 | [diff] [blame] | 1874 | virtual OwningExprResult ActOnClassPropertyRefExpr( |
| 1875 | IdentifierInfo &receiverName, |
| 1876 | IdentifierInfo &propertyName, |
| 1877 | SourceLocation &receiverNameLoc, |
| 1878 | SourceLocation &propertyNameLoc); |
| 1879 | |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1880 | // ActOnClassMessage - used for both unary and keyword messages. |
| 1881 | // ArgExprs is optional - if it is present, the number of expressions |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1882 | // is obtained from NumArgs. |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1883 | virtual ExprResult ActOnClassMessage( |
Fariborz Jahanian | 0523aaf | 2007-11-12 20:13:27 +0000 | [diff] [blame] | 1884 | Scope *S, |
Anders Carlsson | ff975cf | 2009-02-14 18:21:46 +0000 | [diff] [blame] | 1885 | IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac, |
| 1886 | SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac, |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1887 | ExprTy **ArgExprs, unsigned NumArgs); |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1888 | |
| 1889 | // ActOnInstanceMessage - used for both unary and keyword messages. |
| 1890 | // ArgExprs is optional - if it is present, the number of expressions |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1891 | // is obtained from NumArgs. |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1892 | virtual ExprResult ActOnInstanceMessage( |
Steve Naroff | bcfb06a | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 1893 | ExprTy *receiver, Selector Sel, |
Anders Carlsson | ff975cf | 2009-02-14 18:21:46 +0000 | [diff] [blame] | 1894 | SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac, |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1895 | ExprTy **ArgExprs, unsigned NumArgs); |
Daniel Dunbar | 4cde927 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 1896 | |
| 1897 | /// ActOnPragmaPack - Called on well formed #pragma pack(...). |
| 1898 | virtual void ActOnPragmaPack(PragmaPackKind Kind, |
| 1899 | IdentifierInfo *Name, |
| 1900 | ExprTy *Alignment, |
| 1901 | SourceLocation PragmaLoc, |
| 1902 | SourceLocation LParenLoc, |
| 1903 | SourceLocation RParenLoc); |
Chris Lattner | 574aa40 | 2009-02-17 01:09:29 +0000 | [diff] [blame] | 1904 | |
| 1905 | /// getPragmaPackAlignment() - Return the current alignment as specified by |
| 1906 | /// the current #pragma pack directive, or 0 if none is currently active. |
| 1907 | unsigned getPragmaPackAlignment() const; |
| 1908 | |
| 1909 | /// FreePackedContext - Deallocate and null out PackContext. |
| 1910 | void FreePackedContext(); |
Daniel Dunbar | 4cde927 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 1911 | |
Chris Lattner | 1e0a390 | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 1912 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
| 1913 | /// cast. If there is already an implicit cast, merge into the existing one. |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 1914 | /// If isLvalue, the result of the cast is an lvalue. |
| 1915 | void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false); |
Chris Lattner | 1e0a390 | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 1916 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1917 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 1918 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
| 1919 | Expr *UsualUnaryConversions(Expr *&expr); |
Eli Friedman | 3c0eb16 | 2008-05-27 03:33:27 +0000 | [diff] [blame] | 1920 | |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 1921 | // DefaultFunctionArrayConversion - converts functions and arrays |
| 1922 | // to their respective pointers (C99 6.3.2.1). |
| 1923 | void DefaultFunctionArrayConversion(Expr *&expr); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 1924 | |
Steve Naroff | b291ab6 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 1925 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
| 1926 | // do not have a prototype. Integer promotions are performed on each |
| 1927 | // argument, and arguments that have type float are promoted to double. |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 1928 | void DefaultArgumentPromotion(Expr *&Expr); |
Anders Carlsson | dce5e2c | 2009-01-16 16:48:51 +0000 | [diff] [blame] | 1929 | |
| 1930 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
| 1931 | enum VariadicCallType { |
| 1932 | VariadicFunction, |
| 1933 | VariadicBlock, |
| 1934 | VariadicMethod |
| 1935 | }; |
| 1936 | |
| 1937 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
| 1938 | // will warn if the resulting type is not a POD type. |
| 1939 | void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT); |
Steve Naroff | b291ab6 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 1940 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1941 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
| 1942 | // operands and then handles various conversions that are common to binary |
| 1943 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
| 1944 | // routine returns the first non-arithmetic type found. The client is |
| 1945 | // responsible for emitting appropriate error diagnostics. |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1946 | QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr, |
| 1947 | bool isCompAssign = false); |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1948 | |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 1949 | /// UsualArithmeticConversionsType - handles the various conversions |
| 1950 | /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9) |
| 1951 | /// and returns the result type of that conversion. |
| 1952 | QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs); |
| 1953 | |
| 1954 | |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1955 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
| 1956 | /// enum to indicate whether the assignment was allowed. These checks are |
| 1957 | /// done for simple assignments, as well as initialization, return from |
| 1958 | /// function, argument passing, etc. The query is phrased in terms of a |
| 1959 | /// source and destination type. |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 1960 | enum AssignConvertType { |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1961 | /// Compatible - the types are compatible according to the standard. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1962 | Compatible, |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1963 | |
| 1964 | /// PointerToInt - The assignment converts a pointer to an int, which we |
| 1965 | /// accept as an extension. |
| 1966 | PointerToInt, |
| 1967 | |
| 1968 | /// IntToPointer - The assignment converts an int to a pointer, which we |
| 1969 | /// accept as an extension. |
| 1970 | IntToPointer, |
| 1971 | |
| 1972 | /// FunctionVoidPointer - The assignment is between a function pointer and |
| 1973 | /// void*, which the standard doesn't allow, but we accept as an extension. |
Chris Lattner | bfe639e | 2008-01-03 22:56:36 +0000 | [diff] [blame] | 1974 | FunctionVoidPointer, |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1975 | |
| 1976 | /// IncompatiblePointer - The assignment is between two pointers types that |
| 1977 | /// are not compatible, but we accept them as an extension. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1978 | IncompatiblePointer, |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1979 | |
| 1980 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
| 1981 | /// c/v/r qualifiers, which we accept as an extension. |
| 1982 | CompatiblePointerDiscardsQualifiers, |
Steve Naroff | 1c7d067 | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 1983 | |
Anders Carlsson | b0f90cc | 2009-01-30 23:17:46 +0000 | [diff] [blame] | 1984 | /// IncompatibleVectors - The assignment is between two vector types that |
| 1985 | /// have the same size, which we accept as an extension. |
| 1986 | IncompatibleVectors, |
| 1987 | |
Steve Naroff | bfdcae6 | 2008-09-04 15:31:07 +0000 | [diff] [blame] | 1988 | /// IntToBlockPointer - The assignment converts an int to a block |
Steve Naroff | 1c7d067 | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 1989 | /// pointer. We disallow this. |
| 1990 | IntToBlockPointer, |
| 1991 | |
Steve Naroff | bfdcae6 | 2008-09-04 15:31:07 +0000 | [diff] [blame] | 1992 | /// IncompatibleBlockPointer - The assignment is between two block |
Steve Naroff | 1c7d067 | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 1993 | /// pointers types that are not compatible. |
| 1994 | IncompatibleBlockPointer, |
| 1995 | |
Steve Naroff | 3957907 | 2008-10-14 22:18:38 +0000 | [diff] [blame] | 1996 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
| 1997 | /// id type and something else (that is incompatible with it). For example, |
| 1998 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
| 1999 | IncompatibleObjCQualifiedId, |
| 2000 | |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 2001 | /// Incompatible - We reject this conversion outright, it is invalid to |
| 2002 | /// represent it in the AST. |
| 2003 | Incompatible |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2004 | }; |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 2005 | |
| 2006 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
| 2007 | /// assignment conversion type specified by ConvTy. This returns true if the |
| 2008 | /// conversion was invalid or false if the conversion was accepted. |
| 2009 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, |
| 2010 | SourceLocation Loc, |
| 2011 | QualType DstType, QualType SrcType, |
| 2012 | Expr *SrcExpr, const char *Flavor); |
| 2013 | |
| 2014 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
| 2015 | /// argument passing, variable initialization, and function return values. |
| 2016 | /// This routine is only used by the following two methods. C99 6.5.16. |
| 2017 | AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 2018 | |
Steve Naroff | f69936d | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 2019 | // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr, |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 2020 | // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 2021 | // this routine performs the default function/array converions. |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 2022 | AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, |
| 2023 | Expr *&rExpr); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 2024 | // CheckCompoundAssignmentConstraints - Type check without performing any |
| 2025 | // conversions. For compound assignments, the "Check...Operands" methods |
| 2026 | // perform the necessary conversions. |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 2027 | AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs, |
| 2028 | QualType rhs); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 2029 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2030 | // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1) |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 2031 | AssignConvertType CheckPointerTypesForAssignment(QualType lhsType, |
| 2032 | QualType rhsType); |
Steve Naroff | 1c7d067 | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 2033 | |
| 2034 | // Helper function for CheckAssignmentConstraints involving two |
| 2035 | // blcok pointer types. |
| 2036 | AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType, |
| 2037 | QualType rhsType); |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 2038 | |
| 2039 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 2040 | |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 2041 | bool PerformImplicitConversion(Expr *&From, QualType ToType, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 2042 | const char *Flavor, bool AllowExplicit = false); |
| 2043 | bool PerformImplicitConversion(Expr *&From, QualType ToType, |
| 2044 | const ImplicitConversionSequence& ICS, |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 2045 | const char *Flavor); |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 2046 | bool PerformImplicitConversion(Expr *&From, QualType ToType, |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 2047 | const StandardConversionSequence& SCS, |
| 2048 | const char *Flavor); |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2049 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2050 | /// the following "Check" methods will return a valid/converted QualType |
| 2051 | /// or a null QualType (indicating an error diagnostic was issued). |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2052 | |
| 2053 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
Chris Lattner | ca5eede | 2007-12-12 05:47:28 +0000 | [diff] [blame] | 2054 | inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
Sebastian Redl | 7c8bd60 | 2009-02-07 20:10:22 +0000 | [diff] [blame] | 2055 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2056 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2057 | inline QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2058 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2059 | inline QualType CheckRemainderOperands( // C99 6.5.5 |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2060 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2061 | inline QualType CheckAdditionOperands( // C99 6.5.6 |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 2062 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2063 | inline QualType CheckSubtractionOperands( // C99 6.5.6 |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 2064 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2065 | inline QualType CheckShiftOperands( // C99 6.5.7 |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 2066 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | a5937dd | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 2067 | inline QualType CheckCompareOperands( // C99 6.5.8/9 |
| 2068 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2069 | inline QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2070 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2071 | inline QualType CheckLogicalOperands( // C99 6.5.[13,14] |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 2072 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2073 | // CheckAssignmentOperands is used for both simple and compound assignment. |
| 2074 | // For simple assignment, pass both expressions and a null converted type. |
| 2075 | // For compound assignment, pass both expressions and the converted type. |
| 2076 | inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
Steve Naroff | f1120de | 2007-08-24 22:33:52 +0000 | [diff] [blame] | 2077 | Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2078 | inline QualType CheckCommaOperands( // C99 6.5.17 |
Chris Lattner | 29a1cfb | 2008-11-18 01:30:42 +0000 | [diff] [blame] | 2079 | Expr *lex, Expr *&rex, SourceLocation OpLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2080 | inline QualType CheckConditionalOperands( // C99 6.5.15 |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 2081 | Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc); |
Nate Begeman | be2341d | 2008-07-14 18:02:46 +0000 | [diff] [blame] | 2082 | |
| 2083 | /// type checking for vector binary operators. |
| 2084 | inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
| 2085 | inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx, |
| 2086 | SourceLocation l, bool isRel); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2087 | |
Steve Naroff | f69936d | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 2088 | /// type checking unary operators (subroutines of ActOnUnaryOp). |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2089 | /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4 |
Sebastian Redl | e6d5a4a | 2008-12-20 09:35:34 +0000 | [diff] [blame] | 2090 | QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc, |
| 2091 | bool isInc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2092 | QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc); |
| 2093 | QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc); |
Chris Lattner | ba27e2a | 2009-02-17 08:12:06 +0000 | [diff] [blame] | 2094 | QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal); |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 2095 | |
| 2096 | /// type checking primary expressions. |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2097 | QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc, |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 2098 | IdentifierInfo &Comp, SourceLocation CmpLoc); |
| 2099 | |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 2100 | /// type checking declaration initializers (C99 6.7.8) |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 2101 | bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 2102 | SourceLocation InitLoc,DeclarationName InitEntity, |
| 2103 | bool DirectInit); |
Douglas Gregor | c34ee5e | 2009-01-29 00:45:39 +0000 | [diff] [blame] | 2104 | bool CheckInitList(InitListExpr *&InitList, QualType &DeclType); |
Steve Naroff | d0091aa | 2008-01-10 22:15:12 +0000 | [diff] [blame] | 2105 | bool CheckForConstantInitializer(Expr *e, QualType t); |
Steve Naroff | 2fdc374 | 2007-12-10 22:44:33 +0000 | [diff] [blame] | 2106 | |
Douglas Gregor | 87fd703 | 2009-02-02 17:43:21 +0000 | [diff] [blame] | 2107 | bool CheckValueInitialization(QualType Type, SourceLocation Loc); |
Argyrios Kyrtzidis | 6c2dc4d | 2008-08-16 20:27:34 +0000 | [diff] [blame] | 2108 | |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2109 | // type checking C++ declaration initializers (C++ [dcl.init]). |
| 2110 | |
| 2111 | /// ReferenceCompareResult - Expresses the result of comparing two |
| 2112 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
| 2113 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
| 2114 | enum ReferenceCompareResult { |
| 2115 | /// Ref_Incompatible - The two types are incompatible, so direct |
| 2116 | /// reference binding is not possible. |
| 2117 | Ref_Incompatible = 0, |
| 2118 | /// Ref_Related - The two types are reference-related, which means |
| 2119 | /// that their unqualified forms (T1 and T2) are either the same |
| 2120 | /// or T1 is a base class of T2. |
| 2121 | Ref_Related, |
| 2122 | /// Ref_Compatible_With_Added_Qualification - The two types are |
| 2123 | /// reference-compatible with added qualification, meaning that |
| 2124 | /// they are reference-compatible and the qualifiers on T1 (cv1) |
| 2125 | /// are greater than the qualifiers on T2 (cv2). |
| 2126 | Ref_Compatible_With_Added_Qualification, |
| 2127 | /// Ref_Compatible - The two types are reference-compatible and |
| 2128 | /// have equivalent qualifiers (cv1 == cv2). |
| 2129 | Ref_Compatible |
| 2130 | }; |
| 2131 | |
Douglas Gregor | 15da57e | 2008-10-29 02:00:59 +0000 | [diff] [blame] | 2132 | ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2, |
| 2133 | bool& DerivedToBase); |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2134 | |
| 2135 | bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType, |
Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 2136 | ImplicitConversionSequence *ICS = 0, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 2137 | bool SuppressUserConversions = false, |
| 2138 | bool AllowExplicit = false); |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2139 | |
Argyrios Kyrtzidis | 6c2dc4d | 2008-08-16 20:27:34 +0000 | [diff] [blame] | 2140 | /// CheckCastTypes - Check type constraints for casting between types. |
Daniel Dunbar | 58d5ebb | 2008-08-20 03:55:42 +0000 | [diff] [blame] | 2141 | bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr); |
Steve Naroff | a49e1fa | 2008-01-22 00:55:40 +0000 | [diff] [blame] | 2142 | |
Anders Carlsson | 584b247 | 2007-11-27 07:16:40 +0000 | [diff] [blame] | 2143 | // CheckVectorCast - check type constraints for vectors. |
| 2144 | // Since vectors are an extension, there are no C standard reference for this. |
| 2145 | // We allow casting between vectors and integer datatypes of the same size. |
Anders Carlsson | a64db8f | 2007-11-27 05:51:55 +0000 | [diff] [blame] | 2146 | // returns true if the cast is invalid |
| 2147 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty); |
| 2148 | |
Daniel Dunbar | 637cebb | 2008-09-11 00:01:56 +0000 | [diff] [blame] | 2149 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
| 2150 | /// \param Method - May be null. |
| 2151 | /// \param [out] ReturnType - The return type of the send. |
| 2152 | /// \return true iff there were any incompatible types. |
Daniel Dunbar | 91e19b2 | 2008-09-11 00:50:25 +0000 | [diff] [blame] | 2153 | bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 2154 | ObjCMethodDecl *Method, bool isClassMessage, |
Daniel Dunbar | 637cebb | 2008-09-11 00:01:56 +0000 | [diff] [blame] | 2155 | SourceLocation lbrac, SourceLocation rbrac, |
| 2156 | QualType &ReturnType); |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 2157 | |
| 2158 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
| 2159 | bool CheckCXXBooleanCondition(Expr *&CondExpr); |
Steve Naroff | 81bfde9 | 2007-10-16 23:12:48 +0000 | [diff] [blame] | 2160 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 2161 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
| 2162 | /// the specified width and sign. If an overflow occurs, detect it and emit |
| 2163 | /// the specified diagnostic. |
| 2164 | void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, |
| 2165 | unsigned NewWidth, bool NewSign, |
| 2166 | SourceLocation Loc, unsigned DiagID); |
| 2167 | |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 2168 | bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, |
| 2169 | bool ForCompare); |
| 2170 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 2171 | /// Checks that the Objective-C declaration is declared in the global scope. |
| 2172 | /// Emits an error and marks the declaration as invalid if it's not declared |
| 2173 | /// in the global scope. |
| 2174 | bool CheckObjCDeclScope(Decl *D); |
| 2175 | |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 2176 | void InitBuiltinVaListType(); |
Eli Friedman | 1b76ada | 2008-06-03 21:01:11 +0000 | [diff] [blame] | 2177 | |
Anders Carlsson | e21555e | 2008-11-30 19:50:32 +0000 | [diff] [blame] | 2178 | /// VerifyIntegerConstantExpression - verifies that an expression is an ICE, |
| 2179 | /// and reports the appropriate diagnostics. Returns false on success. |
| 2180 | /// Can optionally return the value of the expression. |
Anders Carlsson | 9f1e572 | 2008-12-06 20:33:04 +0000 | [diff] [blame] | 2181 | bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0); |
Anders Carlsson | 4000ea6 | 2008-12-01 02:17:22 +0000 | [diff] [blame] | 2182 | |
Anders Carlsson | 9f1e572 | 2008-12-06 20:33:04 +0000 | [diff] [blame] | 2183 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
| 2184 | /// the correct width, and that the field type is valid. |
| 2185 | /// Returns false on success. |
| 2186 | bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, |
| 2187 | QualType FieldTy, const Expr *BitWidth); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 2188 | |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 2189 | //===--------------------------------------------------------------------===// |
| 2190 | // Extra semantic analysis beyond the C type system |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 2191 | private: |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 2192 | Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl, |
| 2193 | CallExpr *TheCall); |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 2194 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
| 2195 | unsigned ByteNo) const; |
Chris Lattner | 6903981 | 2009-02-18 06:01:06 +0000 | [diff] [blame] | 2196 | bool CheckObjCString(Expr *Arg); |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 2197 | bool SemaBuiltinVAStart(CallExpr *TheCall); |
| 2198 | bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); |
Eli Friedman | 6cfda23 | 2008-05-20 08:23:37 +0000 | [diff] [blame] | 2199 | bool SemaBuiltinStackAddress(CallExpr *TheCall); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 2200 | Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 2201 | bool SemaBuiltinPrefetch(CallExpr *TheCall); |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 2202 | bool SemaBuiltinObjectSize(CallExpr *TheCall); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 2203 | bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 2204 | unsigned format_idx, unsigned firstDataArg); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 2205 | void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr, |
| 2206 | CallExpr *TheCall, bool HasVAListArg, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 2207 | unsigned format_idx, unsigned firstDataArg); |
| 2208 | void CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg, |
| 2209 | unsigned format_idx, unsigned firstDataArg); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 2210 | void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, |
| 2211 | SourceLocation ReturnLoc); |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 2212 | void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2213 | }; |
| 2214 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 2215 | /// BlockSemaInfo - When a block is being parsed, this contains information |
| 2216 | /// about the block. It is pointed to from Sema::CurBlock. |
| 2217 | struct BlockSemaInfo { |
| 2218 | llvm::SmallVector<ParmVarDecl*, 8> Params; |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 2219 | bool hasPrototype; |
| 2220 | bool isVariadic; |
Mike Stump | b83d287 | 2009-02-19 22:01:56 +0000 | [diff] [blame] | 2221 | bool hasBlockDeclRefExprs; |
| 2222 | |
Steve Naroff | 1c90bfc | 2008-10-08 18:44:00 +0000 | [diff] [blame] | 2223 | BlockDecl *TheDecl; |
| 2224 | |
Chris Lattner | da425eb | 2009-02-18 07:09:44 +0000 | [diff] [blame] | 2225 | /// TheScope - This is the scope for the block itself, which contains |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 2226 | /// arguments etc. |
| 2227 | Scope *TheScope; |
| 2228 | |
| 2229 | /// ReturnType - This will get set to block result type, by looking at |
| 2230 | /// return types, if any, in the block body. |
| 2231 | Type *ReturnType; |
| 2232 | |
| 2233 | /// PrevBlockInfo - If this is nested inside another block, this points |
| 2234 | /// to the outer block. |
| 2235 | BlockSemaInfo *PrevBlockInfo; |
| 2236 | }; |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 2237 | |
| 2238 | //===--------------------------------------------------------------------===// |
| 2239 | // Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers). |
| 2240 | template <typename T> |
| 2241 | class ExprOwningPtr : public Action::ExprArg { |
| 2242 | public: |
| 2243 | ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {}; |
| 2244 | |
| 2245 | void reset(T* p) { Action::ExprArg::operator=(p); } |
| 2246 | T* get() const { return static_cast<T*>(Action::ExprArg::get()); } |
| 2247 | T* take() { return static_cast<T*>(Action::ExprArg::take()); } |
| 2248 | T* release() { return take(); } |
| 2249 | |
| 2250 | T& operator*() const { return *get(); } |
| 2251 | T* operator->() const { return get(); } |
| 2252 | }; |
| 2253 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2254 | } // end namespace clang |
| 2255 | |
| 2256 | #endif |