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" |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclObjC.h" |
Anders Carlsson | 1c5976e | 2009-06-05 03:43:12 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclTemplate.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 24 | #include "clang/Parse/Action.h" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 25 | #include "clang/Sema/SemaDiagnostic.h" |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/SmallVector.h" |
Fariborz Jahanian | 85ff264 | 2007-10-05 18:00:57 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/DenseSet.h" |
Chris Lattner | f387668 | 2007-10-07 01:13:46 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SmallPtrSet.h" |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/OwningPtr.h" |
Douglas Gregor | 4dc6b1c | 2009-01-16 00:38:09 +0000 | [diff] [blame] | 30 | #include <string> |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 31 | #include <vector> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 33 | namespace llvm { |
| 34 | class APSInt; |
| 35 | } |
| 36 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 37 | namespace clang { |
| 38 | class ASTContext; |
Chris Lattner | 2ae34ed | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 39 | class ASTConsumer; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 40 | class Preprocessor; |
| 41 | class Decl; |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 42 | class DeclContext; |
Daniel Dunbar | 12bc692 | 2008-08-11 03:27:53 +0000 | [diff] [blame] | 43 | class DeclSpec; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 44 | class ExternalSemaSource; |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 45 | class NamedDecl; |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 46 | class Stmt; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 47 | class Expr; |
Steve Naroff | 6f9f307 | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 48 | class InitListExpr; |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 49 | class DesignatedInitExpr; |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 50 | class CallExpr; |
Douglas Gregor | 1a49af9 | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 51 | class DeclRefExpr; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 52 | class VarDecl; |
| 53 | class ParmVarDecl; |
| 54 | class TypedefDecl; |
| 55 | class FunctionDecl; |
| 56 | class QualType; |
Sebastian Redl | 43af76e | 2009-03-07 12:16:37 +0000 | [diff] [blame] | 57 | class LangOptions; |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 58 | class Token; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 59 | class IntegerLiteral; |
Steve Naroff | a49e1fa | 2008-01-22 00:55:40 +0000 | [diff] [blame] | 60 | class StringLiteral; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 61 | class ArrayType; |
| 62 | class LabelStmt; |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 63 | class SwitchStmt; |
Sebastian Redl | 13e8854 | 2009-04-27 21:33:24 +0000 | [diff] [blame] | 64 | class CXXTryStmt; |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 65 | class ExtVectorType; |
Steve Naroff | bea0b34 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 66 | class TypedefDecl; |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 67 | class TemplateDecl; |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 68 | class TemplateArgument; |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 69 | class TemplateArgumentList; |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 70 | class TemplateParameterList; |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 71 | class TemplateTemplateParmDecl; |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 72 | class ClassTemplatePartialSpecializationDecl; |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 73 | class ClassTemplateDecl; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 74 | class ObjCInterfaceDecl; |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 75 | class ObjCCompatibleAliasDecl; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 76 | class ObjCProtocolDecl; |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 77 | class ObjCImplDecl; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 78 | class ObjCImplementationDecl; |
| 79 | class ObjCCategoryImplDecl; |
| 80 | class ObjCCategoryDecl; |
| 81 | class ObjCIvarDecl; |
| 82 | class ObjCMethodDecl; |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 83 | class ObjCPropertyDecl; |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 84 | class ObjCContainerDecl; |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 85 | class BasePaths; |
Sebastian Redl | 43af76e | 2009-03-07 12:16:37 +0000 | [diff] [blame] | 86 | struct MemberLookupCriteria; |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 87 | class CXXTemporary; |
Steve Naroff | bea0b34 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 88 | |
Chris Lattner | ea29a3a | 2009-04-18 20:01:55 +0000 | [diff] [blame] | 89 | /// BlockSemaInfo - When a block is being parsed, this contains information |
| 90 | /// about the block. It is pointed to from Sema::CurBlock. |
| 91 | struct BlockSemaInfo { |
| 92 | llvm::SmallVector<ParmVarDecl*, 8> Params; |
| 93 | bool hasPrototype; |
| 94 | bool isVariadic; |
| 95 | bool hasBlockDeclRefExprs; |
| 96 | |
| 97 | BlockDecl *TheDecl; |
| 98 | |
| 99 | /// TheScope - This is the scope for the block itself, which contains |
| 100 | /// arguments etc. |
| 101 | Scope *TheScope; |
| 102 | |
| 103 | /// ReturnType - This will get set to block result type, by looking at |
| 104 | /// return types, if any, in the block body. |
| 105 | Type *ReturnType; |
| 106 | |
| 107 | /// LabelMap - This is a mapping from label identifiers to the LabelStmt for |
| 108 | /// it (which acts like the label decl in some ways). Forward referenced |
| 109 | /// labels have a LabelStmt created for them with a null location & SubStmt. |
| 110 | llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap; |
| 111 | |
Chris Lattner | bcfce66 | 2009-04-18 20:10:59 +0000 | [diff] [blame] | 112 | /// SwitchStack - This is the current set of active switch statements in the |
| 113 | /// block. |
| 114 | llvm::SmallVector<SwitchStmt*, 8> SwitchStack; |
| 115 | |
Chris Lattner | 17a7830 | 2009-04-19 05:28:12 +0000 | [diff] [blame] | 116 | /// SavedFunctionNeedsScopeChecking - This is the value of |
| 117 | /// CurFunctionNeedsScopeChecking at the point when the block started. |
| 118 | bool SavedFunctionNeedsScopeChecking; |
| 119 | |
Chris Lattner | ea29a3a | 2009-04-18 20:01:55 +0000 | [diff] [blame] | 120 | /// PrevBlockInfo - If this is nested inside another block, this points |
| 121 | /// to the outer block. |
| 122 | BlockSemaInfo *PrevBlockInfo; |
| 123 | }; |
| 124 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 125 | /// Sema - This implements semantic analysis and AST building for C. |
| 126 | class Sema : public Action { |
Chris Lattner | f50adff | 2009-02-17 00:58:30 +0000 | [diff] [blame] | 127 | Sema(const Sema&); // DO NOT IMPLEMENT |
| 128 | void operator=(const Sema&); // DO NOT IMPLEMENT |
Chris Lattner | 0b2f4da | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 129 | public: |
Chris Lattner | 53ebff3 | 2009-01-22 19:21:44 +0000 | [diff] [blame] | 130 | const LangOptions &LangOpts; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 131 | Preprocessor &PP; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 132 | ASTContext &Context; |
Chris Lattner | 2ae34ed | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 133 | ASTConsumer &Consumer; |
Chris Lattner | 3cfa928 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 134 | Diagnostic &Diags; |
| 135 | SourceManager &SourceMgr; |
Steve Naroff | 0330071 | 2007-11-12 13:56:41 +0000 | [diff] [blame] | 136 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 137 | /// \brief Source of additional semantic information. |
| 138 | ExternalSemaSource *ExternalSource; |
| 139 | |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 140 | /// CurContext - This is the current declaration context of parsing. |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 141 | DeclContext *CurContext; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 142 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 143 | /// PreDeclaratorDC - Keeps the declaration context before switching to the |
| 144 | /// context of a declarator's nested-name-specifier. |
| 145 | DeclContext *PreDeclaratorDC; |
| 146 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 147 | /// CurBlock - If inside of a block definition, this contains a pointer to |
| 148 | /// the active block object that represents it. |
| 149 | BlockSemaInfo *CurBlock; |
| 150 | |
Daniel Dunbar | 4cde927 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 151 | /// PackContext - Manages the stack for #pragma pack. An alignment |
| 152 | /// of 0 indicates default alignment. |
Chris Lattner | 574aa40 | 2009-02-17 01:09:29 +0000 | [diff] [blame] | 153 | void *PackContext; // Really a "PragmaPackStack*" |
Daniel Dunbar | 4cde927 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 154 | |
Chris Lattner | ea29a3a | 2009-04-18 20:01:55 +0000 | [diff] [blame] | 155 | /// FunctionLabelMap - This is a mapping from label identifiers to the |
| 156 | /// LabelStmt for it (which acts like the label decl in some ways). Forward |
| 157 | /// referenced labels have a LabelStmt created for them with a null location & |
| 158 | /// SubStmt. |
| 159 | /// |
| 160 | /// Note that this should always be accessed through getLabelMap() in order |
| 161 | /// to handle blocks properly. |
| 162 | llvm::DenseMap<IdentifierInfo*, LabelStmt*> FunctionLabelMap; |
Steve Naroff | caaacec | 2009-03-13 15:38:40 +0000 | [diff] [blame] | 163 | |
Chris Lattner | bcfce66 | 2009-04-18 20:10:59 +0000 | [diff] [blame] | 164 | /// FunctionSwitchStack - This is the current set of active switch statements |
| 165 | /// in the top level function. Clients should always use getSwitchStack() to |
| 166 | /// handle the case when they are in a block. |
| 167 | llvm::SmallVector<SwitchStmt*, 8> FunctionSwitchStack; |
Anders Carlsson | 165a0a0 | 2009-05-17 18:41:29 +0000 | [diff] [blame] | 168 | |
| 169 | /// ExprTemporaries - This is the stack of temporaries that are created by |
| 170 | /// the current full expression. |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 171 | llvm::SmallVector<CXXTemporary*, 8> ExprTemporaries; |
Anders Carlsson | 165a0a0 | 2009-05-17 18:41:29 +0000 | [diff] [blame] | 172 | |
Chris Lattner | 38c5ebd | 2009-04-19 05:21:20 +0000 | [diff] [blame] | 173 | /// CurFunctionNeedsScopeChecking - This is set to true when a function or |
| 174 | /// ObjC method body contains a VLA or an ObjC try block, which introduce |
| 175 | /// scopes that need to be checked for goto conditions. If a function does |
| 176 | /// not contain this, then it need not have the jump checker run on it. |
| 177 | bool CurFunctionNeedsScopeChecking; |
| 178 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 179 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
| 180 | /// 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] | 181 | /// This is only necessary for issuing pretty diagnostics. |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 182 | llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls; |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 183 | |
Steve Naroff | e84a864 | 2008-09-28 14:55:53 +0000 | [diff] [blame] | 184 | /// ObjCCategoryImpls - Maintain a list of category implementations so |
| 185 | /// we can check for duplicates and find local method declarations. |
| 186 | llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls; |
| 187 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 188 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
| 189 | llvm::OwningPtr<CXXFieldCollector> FieldCollector; |
| 190 | |
Anders Carlsson | 4681ebd | 2009-03-22 20:18:17 +0000 | [diff] [blame] | 191 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; |
| 192 | |
| 193 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
| 194 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
| 195 | /// same list more than once. |
| 196 | llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet; |
| 197 | |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 198 | /// \brief A mapping from external names to the most recent |
| 199 | /// locally-scoped external declaration with that name. |
| 200 | /// |
| 201 | /// This map contains external declarations introduced in local |
| 202 | /// scoped, e.g., |
| 203 | /// |
| 204 | /// \code |
| 205 | /// void f() { |
| 206 | /// void foo(int, int); |
| 207 | /// } |
| 208 | /// \endcode |
| 209 | /// |
| 210 | /// Here, the name "foo" will be associated with the declaration on |
| 211 | /// "foo" within f. This name is not visible outside of |
| 212 | /// "f". However, we still find it in two cases: |
| 213 | /// |
| 214 | /// - If we are declaring another external with the name "foo", we |
| 215 | /// can find "foo" as a previous declaration, so that the types |
| 216 | /// of this external declaration can be checked for |
| 217 | /// compatibility. |
| 218 | /// |
| 219 | /// - If we would implicitly declare "foo" (e.g., due to a call to |
| 220 | /// "foo" in C when no prototype or definition is visible), then |
| 221 | /// we find this declaration of "foo" and complain that it is |
| 222 | /// not visible. |
| 223 | llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls; |
| 224 | |
Douglas Gregor | b6c8c8b | 2009-04-21 17:11:58 +0000 | [diff] [blame] | 225 | /// \brief The set of tentative declarations seen so far in this |
| 226 | /// translation unit for which no definition has been seen. |
| 227 | /// |
| 228 | /// The tentative declarations are indexed by the name of the |
| 229 | /// declaration, and only the most recent tentative declaration for |
| 230 | /// a given variable will be recorded here. |
| 231 | llvm::DenseMap<DeclarationName, VarDecl *> TentativeDefinitions; |
| 232 | |
Chris Lattner | 7f925cc | 2008-04-11 07:00:53 +0000 | [diff] [blame] | 233 | IdentifierResolver IdResolver; |
| 234 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 235 | /// Translation Unit Scope - useful to Objective-C actions that need |
| 236 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
| 237 | /// For example, user-defined classes, built-in "id" type, etc. |
Steve Naroff | b216c88 | 2007-10-09 22:01:59 +0000 | [diff] [blame] | 238 | Scope *TUScope; |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 239 | |
| 240 | /// The C++ "std" namespace, where the standard library resides. Cached here |
| 241 | /// by GetStdNamespace |
| 242 | NamespaceDecl *StdNamespace; |
Sebastian Redl | b5a57a6 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 243 | |
| 244 | /// A flag to remember whether the implicit forms of operator new and delete |
| 245 | /// have been declared. |
| 246 | bool GlobalNewDeleteDeclared; |
Douglas Gregor | f807fe0 | 2009-04-14 16:27:31 +0000 | [diff] [blame] | 247 | |
| 248 | /// \brief Whether the code handled by Sema should be considered a |
| 249 | /// complete translation unit or not. |
| 250 | /// |
| 251 | /// When true (which is generally the case), Sema will perform |
| 252 | /// end-of-translation-unit semantic tasks (such as creating |
| 253 | /// initializers for tentative definitions in C) once parsing has |
| 254 | /// completed. This flag will be false when building PCH files, |
| 255 | /// since a PCH file is by definition not a complete translation |
| 256 | /// unit. |
| 257 | bool CompleteTranslationUnit; |
| 258 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 259 | typedef llvm::DenseMap<Selector, ObjCMethodList> MethodPool; |
| 260 | |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 261 | /// Instance/Factory Method Pools - allows efficient lookup when typechecking |
| 262 | /// messages to "id". We need to maintain a list, since selectors can have |
| 263 | /// differing signatures across classes. In Cocoa, this happens to be |
| 264 | /// extremely uncommon (only 1% of selectors are "overloaded"). |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 265 | MethodPool InstanceMethodPool; |
| 266 | MethodPool FactoryMethodPool; |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 267 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 268 | MethodPool::iterator ReadMethodPool(Selector Sel, bool isInstance); |
| 269 | |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 270 | /// Private Helper predicate to check for 'self'. |
| 271 | bool isSelfExpr(Expr *RExpr); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 272 | public: |
Douglas Gregor | f807fe0 | 2009-04-14 16:27:31 +0000 | [diff] [blame] | 273 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
| 274 | bool CompleteTranslationUnit = true); |
Chris Lattner | 574aa40 | 2009-02-17 01:09:29 +0000 | [diff] [blame] | 275 | ~Sema() { |
| 276 | if (PackContext) FreePackedContext(); |
| 277 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 278 | |
Chris Lattner | 53ebff3 | 2009-01-22 19:21:44 +0000 | [diff] [blame] | 279 | const LangOptions &getLangOptions() const { return LangOpts; } |
Chris Lattner | 3cfa928 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 280 | Diagnostic &getDiagnostics() const { return Diags; } |
| 281 | SourceManager &getSourceManager() const { return SourceMgr; } |
| 282 | |
Douglas Gregor | 25a88bb | 2009-03-20 22:48:49 +0000 | [diff] [blame] | 283 | /// \brief Helper class that creates diagnostics with optional |
| 284 | /// template instantiation stacks. |
| 285 | /// |
| 286 | /// This class provides a wrapper around the basic DiagnosticBuilder |
| 287 | /// class that emits diagnostics. SemaDiagnosticBuilder is |
| 288 | /// responsible for emitting the diagnostic (as DiagnosticBuilder |
| 289 | /// does) and, if the diagnostic comes from inside a template |
| 290 | /// instantiation, printing the template instantiation stack as |
| 291 | /// well. |
| 292 | class SemaDiagnosticBuilder : public DiagnosticBuilder { |
| 293 | Sema &SemaRef; |
| 294 | unsigned DiagID; |
| 295 | |
| 296 | public: |
| 297 | SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) |
| 298 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { } |
| 299 | |
| 300 | ~SemaDiagnosticBuilder(); |
| 301 | }; |
| 302 | |
| 303 | /// \brief Emit a diagnostic. |
| 304 | SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 305 | DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID); |
Douglas Gregor | 25a88bb | 2009-03-20 22:48:49 +0000 | [diff] [blame] | 306 | return SemaDiagnosticBuilder(DB, *this, DiagID); |
Chris Lattner | 3cfa928 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 307 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 308 | |
Chris Lattner | 394a3fd | 2007-08-31 04:53:24 +0000 | [diff] [blame] | 309 | virtual void DeleteExpr(ExprTy *E); |
| 310 | virtual void DeleteStmt(StmtTy *S); |
| 311 | |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 312 | OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); } |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 313 | OwningExprResult Owned(ExprResult R) { |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 314 | if (R.isInvalid()) |
Steve Naroff | 872b9ac | 2009-01-21 22:32:33 +0000 | [diff] [blame] | 315 | return ExprError(); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 316 | return OwningExprResult(*this, R.get()); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 317 | } |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 318 | OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); } |
| 319 | |
Chris Lattner | 9299f3f | 2008-08-23 03:19:52 +0000 | [diff] [blame] | 320 | virtual void ActOnEndOfTranslationUnit(); |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 321 | |
Chris Lattner | ea29a3a | 2009-04-18 20:01:55 +0000 | [diff] [blame] | 322 | /// getLabelMap() - Return the current label map. If we're in a block, we |
| 323 | /// return it. |
| 324 | llvm::DenseMap<IdentifierInfo*, LabelStmt*> &getLabelMap() { |
| 325 | return CurBlock ? CurBlock->LabelMap : FunctionLabelMap; |
| 326 | } |
| 327 | |
Chris Lattner | bcfce66 | 2009-04-18 20:10:59 +0000 | [diff] [blame] | 328 | /// getSwitchStack - This is returns the switch stack for the current block or |
| 329 | /// function. |
| 330 | llvm::SmallVector<SwitchStmt*,8> &getSwitchStack() { |
| 331 | return CurBlock ? CurBlock->SwitchStack : FunctionSwitchStack; |
| 332 | } |
| 333 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 334 | //===--------------------------------------------------------------------===// |
| 335 | // Type Analysis / Processing: SemaType.cpp. |
| 336 | // |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 337 | QualType adjustParameterType(QualType T); |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 338 | QualType ConvertDeclSpecToType(const DeclSpec &DS, SourceLocation DeclLoc, |
| 339 | bool &IsInvalid); |
Chris Lattner | c9b346d | 2008-06-29 00:50:08 +0000 | [diff] [blame] | 340 | void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 341 | QualType BuildPointerType(QualType T, unsigned Quals, |
| 342 | SourceLocation Loc, DeclarationName Entity); |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 343 | QualType BuildReferenceType(QualType T, bool LValueRef, unsigned Quals, |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 344 | SourceLocation Loc, DeclarationName Entity); |
| 345 | QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, |
| 346 | Expr *ArraySize, unsigned Quals, |
| 347 | SourceLocation Loc, DeclarationName Entity); |
Douglas Gregor | 724651c | 2009-02-28 01:04:19 +0000 | [diff] [blame] | 348 | QualType BuildFunctionType(QualType T, |
| 349 | QualType *ParamTypes, unsigned NumParamTypes, |
| 350 | bool Variadic, unsigned Quals, |
| 351 | SourceLocation Loc, DeclarationName Entity); |
Douglas Gregor | 949bf69 | 2009-06-09 22:17:39 +0000 | [diff] [blame] | 352 | QualType BuildMemberPointerType(QualType T, QualType Class, |
| 353 | unsigned Quals, SourceLocation Loc, |
| 354 | DeclarationName Entity); |
Douglas Gregor | 402abb5 | 2009-05-28 23:31:59 +0000 | [diff] [blame] | 355 | QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0, |
| 356 | TagDecl **OwnedDecl = 0); |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 357 | DeclarationName GetNameForDeclarator(Declarator &D); |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 358 | bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range); |
Sebastian Redl | 6a7330c | 2009-05-29 15:01:05 +0000 | [diff] [blame] | 359 | bool CheckDistantExceptionSpec(QualType T); |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 360 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 361 | QualType ObjCGetTypeForMethodDefinition(DeclPtrTy D); |
Fariborz Jahanian | 306d68f | 2007-11-08 23:49:49 +0000 | [diff] [blame] | 362 | |
Douglas Gregor | 5737326 | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 363 | bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2); |
| 364 | |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 365 | virtual TypeResult ActOnTypeName(Scope *S, Declarator &D); |
Sebastian Redl | 37d6de3 | 2008-11-08 13:00:26 +0000 | [diff] [blame] | 366 | |
Douglas Gregor | 86447ec | 2009-03-09 16:13:40 +0000 | [diff] [blame] | 367 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned diag, |
Douglas Gregor | 4ec339f | 2009-01-19 19:26:10 +0000 | [diff] [blame] | 368 | SourceRange Range1 = SourceRange(), |
| 369 | SourceRange Range2 = SourceRange(), |
| 370 | QualType PrintType = QualType()); |
| 371 | |
Douglas Gregor | e625893 | 2009-03-19 00:39:20 +0000 | [diff] [blame] | 372 | QualType getQualifiedNameType(const CXXScopeSpec &SS, QualType T); |
| 373 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 374 | //===--------------------------------------------------------------------===// |
| 375 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
| 376 | // |
Chris Lattner | 21ff9c9 | 2009-03-05 01:25:28 +0000 | [diff] [blame] | 377 | |
| 378 | /// getDeclName - Return a pretty name for the specified decl if possible, or |
| 379 | /// an empty string if not. This is used for pretty crash reporting. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 380 | virtual std::string getDeclName(DeclPtrTy D); |
Chris Lattner | 21ff9c9 | 2009-03-05 01:25:28 +0000 | [diff] [blame] | 381 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 382 | DeclGroupPtrTy ConvertDeclToDeclGroup(DeclPtrTy Ptr); |
| 383 | |
Douglas Gregor | 1a51b4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 384 | virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, |
Douglas Gregor | b696ea3 | 2009-02-04 17:00:24 +0000 | [diff] [blame] | 385 | Scope *S, const CXXScopeSpec *SS); |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 386 | virtual DeclSpec::TST isTagName(IdentifierInfo &II, Scope *S); |
| 387 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 388 | virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D) { |
| 389 | return ActOnDeclarator(S, D, false); |
Douglas Gregor | 584049d | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 390 | } |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 391 | DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D, bool IsFunctionDefinition); |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 392 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl, |
| 393 | Scope *S); |
Eli Friedman | 85a5319 | 2009-04-07 19:37:57 +0000 | [diff] [blame] | 394 | void DiagnoseFunctionSpecifiers(Declarator& D); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 395 | NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 396 | QualType R, Decl* PrevDecl, |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 397 | bool &Redeclaration); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 398 | NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 399 | QualType R, NamedDecl* PrevDecl, |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 400 | bool &Redeclaration); |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 401 | void CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl, |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 402 | bool &Redeclaration); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 403 | NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 404 | QualType R, NamedDecl* PrevDecl, |
Douglas Gregor | 04495c8 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 405 | bool IsFunctionDefinition, |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 406 | bool &Redeclaration); |
| 407 | void CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl, |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 408 | bool &Redeclaration, |
| 409 | bool &OverloadableAttrRequired); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 410 | virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D); |
| 411 | virtual void ActOnParamDefaultArgument(DeclPtrTy param, |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 412 | SourceLocation EqualLoc, |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 413 | ExprArg defarg); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 414 | virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param, |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 415 | SourceLocation EqualLoc); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 416 | virtual void ActOnParamDefaultArgumentError(DeclPtrTy param); |
Anders Carlsson | f5dcd38 | 2009-05-30 21:37:25 +0000 | [diff] [blame] | 417 | virtual void AddInitializerToDecl(DeclPtrTy dcl, FullExprArg init); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 418 | void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit); |
| 419 | void ActOnUninitializedDecl(DeclPtrTy dcl); |
| 420 | virtual void SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc); |
Eli Friedman | c1dc653 | 2009-05-29 01:49:24 +0000 | [diff] [blame] | 421 | virtual DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
| 422 | DeclPtrTy *Group, |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 423 | unsigned NumDecls); |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 424 | virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, |
| 425 | SourceLocation LocAfterDecls); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 426 | virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, Declarator &D); |
| 427 | virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, DeclPtrTy D); |
| 428 | virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclPtrTy D); |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 429 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 430 | virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body); |
Douglas Gregor | e2c31ff | 2009-05-15 17:59:04 +0000 | [diff] [blame] | 431 | DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body, |
| 432 | bool IsInstantiation); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 433 | void DiagnoseInvalidJumps(Stmt *Body); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 434 | virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr); |
Anders Carlsson | dfab6cb | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 435 | |
Steve Naroff | b216c88 | 2007-10-09 22:01:59 +0000 | [diff] [blame] | 436 | /// Scope actions. |
| 437 | virtual void ActOnPopScope(SourceLocation Loc, Scope *S); |
| 438 | virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 439 | |
| 440 | /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with |
| 441 | /// no declarator (e.g. "struct foo;") is parsed. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 442 | virtual DeclPtrTy ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 443 | |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 444 | bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, |
| 445 | RecordDecl *AnonRecord); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 446 | virtual DeclPtrTy BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
| 447 | RecordDecl *Record); |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 448 | |
Douglas Gregor | 501c5ce | 2009-05-14 16:41:31 +0000 | [diff] [blame] | 449 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, |
| 450 | TagDecl::TagKind NewTag, |
| 451 | SourceLocation NewTagLoc, |
| 452 | const IdentifierInfo &Name); |
Douglas Gregor | ed4ec8f | 2009-05-03 17:18:57 +0000 | [diff] [blame] | 453 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 454 | virtual DeclPtrTy ActOnTag(Scope *S, unsigned TagSpec, TagKind TK, |
| 455 | SourceLocation KWLoc, const CXXScopeSpec &SS, |
| 456 | IdentifierInfo *Name, SourceLocation NameLoc, |
Douglas Gregor | 402abb5 | 2009-05-28 23:31:59 +0000 | [diff] [blame] | 457 | AttributeList *Attr, AccessSpecifier AS, |
| 458 | bool &OwnedDecl); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 459 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 460 | virtual void ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, |
Chris Lattner | 06f5485 | 2008-08-23 02:00:52 +0000 | [diff] [blame] | 461 | IdentifierInfo *ClassName, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 462 | llvm::SmallVectorImpl<DeclPtrTy> &Decls); |
| 463 | virtual DeclPtrTy ActOnField(Scope *S, DeclPtrTy TagD, |
| 464 | SourceLocation DeclStart, |
| 465 | Declarator &D, ExprTy *BitfieldWidth); |
Chris Lattner | 2479366 | 2009-03-05 22:45:59 +0000 | [diff] [blame] | 466 | |
| 467 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
Douglas Gregor | 4dd55f5 | 2009-03-11 20:50:30 +0000 | [diff] [blame] | 468 | Declarator &D, Expr *BitfieldWidth, |
| 469 | AccessSpecifier AS); |
Chris Lattner | 2479366 | 2009-03-05 22:45:59 +0000 | [diff] [blame] | 470 | |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 471 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
| 472 | RecordDecl *Record, SourceLocation Loc, |
| 473 | bool Mutable, Expr *BitfieldWidth, |
Douglas Gregor | 4dd55f5 | 2009-03-11 20:50:30 +0000 | [diff] [blame] | 474 | AccessSpecifier AS, NamedDecl *PrevDecl, |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 475 | Declarator *D = 0); |
Fariborz Jahanian | 1d78cc4 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 476 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 477 | virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart, |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 478 | DeclPtrTy IntfDecl, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 479 | Declarator &D, ExprTy *BitfieldWidth, |
| 480 | tok::ObjCKeywordKind visibility); |
Fariborz Jahanian | 1d78cc4 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 481 | |
Steve Naroff | f13271f | 2007-09-14 23:09:53 +0000 | [diff] [blame] | 482 | // This is used for both record definitions and ObjC interface declarations. |
Fariborz Jahanian | 9d048ff | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 483 | virtual void ActOnFields(Scope* S, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 484 | SourceLocation RecLoc, DeclPtrTy TagDecl, |
| 485 | DeclPtrTy *Fields, unsigned NumFields, |
Daniel Dunbar | 1bfe1c2 | 2008-10-03 02:03:53 +0000 | [diff] [blame] | 486 | SourceLocation LBrac, SourceLocation RBrac, |
| 487 | AttributeList *AttrList); |
Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 488 | |
| 489 | /// ActOnTagStartDefinition - Invoked when we have entered the |
| 490 | /// scope of a tag's definition (e.g., for an enumeration, class, |
| 491 | /// struct, or union). |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 492 | virtual void ActOnTagStartDefinition(Scope *S, DeclPtrTy TagDecl); |
Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 493 | |
| 494 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
| 495 | /// the definition of a tag (enumeration, class, struct, or union). |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 496 | virtual void ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagDecl); |
Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 497 | |
Douglas Gregor | 879fd49 | 2009-03-17 19:05:46 +0000 | [diff] [blame] | 498 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
| 499 | EnumConstantDecl *LastEnumConst, |
| 500 | SourceLocation IdLoc, |
| 501 | IdentifierInfo *Id, |
| 502 | ExprArg val); |
| 503 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 504 | virtual DeclPtrTy ActOnEnumConstant(Scope *S, DeclPtrTy EnumDecl, |
| 505 | DeclPtrTy LastEnumConstant, |
| 506 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 507 | SourceLocation EqualLoc, ExprTy *Val); |
Mike Stump | c6e35aa | 2009-05-16 07:06:02 +0000 | [diff] [blame] | 508 | virtual void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, |
| 509 | SourceLocation RBraceLoc, DeclPtrTy EnumDecl, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 510 | DeclPtrTy *Elements, unsigned NumElements); |
Sebastian Redl | 37d6de3 | 2008-11-08 13:00:26 +0000 | [diff] [blame] | 511 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 512 | DeclContext *getContainingDC(DeclContext *DC); |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 513 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 514 | /// Set the current declaration context until it gets popped. |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 515 | void PushDeclContext(Scope *S, DeclContext *DC); |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 516 | void PopDeclContext(); |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 517 | |
Chris Lattner | 371f258 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 518 | /// getCurFunctionDecl - If inside of a function body, this returns a pointer |
| 519 | /// to the function decl for the function being parsed. If we're currently |
| 520 | /// in a 'block', this returns the containing context. |
| 521 | FunctionDecl *getCurFunctionDecl(); |
| 522 | |
| 523 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
| 524 | /// the method decl for the method being parsed. If we're currently |
| 525 | /// in a 'block', this returns the containing context. |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 526 | ObjCMethodDecl *getCurMethodDecl(); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 527 | |
Chris Lattner | 371f258 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 528 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
| 529 | /// or C function we're in, otherwise return null. If we're currently |
| 530 | /// in a 'block', this returns the containing context. |
| 531 | NamedDecl *getCurFunctionOrMethodDecl(); |
| 532 | |
Argyrios Kyrtzidis | 87f3ff0 | 2008-04-12 00:47:19 +0000 | [diff] [blame] | 533 | /// Add this decl to the scope shadowed decl chains. |
| 534 | void PushOnScopeChains(NamedDecl *D, Scope *S); |
| 535 | |
Argyrios Kyrtzidis | 15a12d0 | 2008-09-09 21:18:04 +0000 | [diff] [blame] | 536 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
| 537 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
| 538 | /// true if 'D' belongs to the given declaration context. |
| 539 | bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) { |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 540 | return IdResolver.isDeclInScope(D, Ctx, Context, S); |
Argyrios Kyrtzidis | 15a12d0 | 2008-09-09 21:18:04 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Eli Friedman | 8f17b66 | 2009-02-28 05:41:13 +0000 | [diff] [blame] | 543 | |
Chris Lattner | f1d705c | 2008-02-21 01:07:18 +0000 | [diff] [blame] | 544 | /// Subroutines of ActOnDeclarator(). |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 545 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T); |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 546 | void MergeTypeDefDecl(TypedefDecl *New, Decl *Old); |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 547 | bool MergeFunctionDecl(FunctionDecl *New, Decl *Old); |
Douglas Gregor | 04495c8 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 548 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old); |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 549 | void MergeVarDecl(VarDecl *New, Decl *Old); |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 550 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 551 | |
| 552 | /// C++ Overloading. |
| 553 | bool IsOverload(FunctionDecl *New, Decl* OldD, |
| 554 | OverloadedFunctionDecl::function_iterator &MatchedDecl); |
Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 555 | ImplicitConversionSequence |
| 556 | TryImplicitConversion(Expr* From, QualType ToType, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 557 | bool SuppressUserConversions = false, |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 558 | bool AllowExplicit = false, |
| 559 | bool ForceRValue = false); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 560 | bool IsStandardConversion(Expr *From, QualType ToType, |
| 561 | StandardConversionSequence& SCS); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 562 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
| 563 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
Douglas Gregor | 5cdf821 | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 564 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 565 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 566 | QualType& ConvertedType, bool &IncompatibleObjC); |
Douglas Gregor | c788751 | 2008-12-19 19:13:09 +0000 | [diff] [blame] | 567 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
| 568 | QualType& ConvertedType, bool &IncompatibleObjC); |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 569 | bool CheckPointerConversion(Expr *From, QualType ToType); |
Sebastian Redl | 4433aaf | 2009-01-25 19:43:20 +0000 | [diff] [blame] | 570 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
| 571 | QualType &ConvertedType); |
| 572 | bool CheckMemberPointerConversion(Expr *From, QualType ToType); |
Douglas Gregor | 98cd599 | 2008-10-21 23:43:52 +0000 | [diff] [blame] | 573 | bool IsQualificationConversion(QualType FromType, QualType ToType); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 574 | bool IsUserDefinedConversion(Expr *From, QualType ToType, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 575 | UserDefinedConversionSequence& User, |
Douglas Gregor | 734d986 | 2009-01-30 23:27:23 +0000 | [diff] [blame] | 576 | bool AllowConversionFunctions, |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 577 | bool AllowExplicit, bool ForceRValue); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 578 | |
| 579 | ImplicitConversionSequence::CompareKind |
| 580 | CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1, |
| 581 | const ImplicitConversionSequence& ICS2); |
| 582 | |
| 583 | ImplicitConversionSequence::CompareKind |
| 584 | CompareStandardConversionSequences(const StandardConversionSequence& SCS1, |
| 585 | const StandardConversionSequence& SCS2); |
| 586 | |
Douglas Gregor | 5737326 | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 587 | ImplicitConversionSequence::CompareKind |
| 588 | CompareQualificationConversions(const StandardConversionSequence& SCS1, |
| 589 | const StandardConversionSequence& SCS2); |
| 590 | |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 591 | ImplicitConversionSequence::CompareKind |
| 592 | CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1, |
| 593 | const StandardConversionSequence& SCS2); |
| 594 | |
Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 595 | ImplicitConversionSequence |
| 596 | TryCopyInitialization(Expr* From, QualType ToType, |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 597 | bool SuppressUserConversions = false, |
| 598 | bool ForceRValue = false); |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 599 | bool PerformCopyInitialization(Expr *&From, QualType ToType, |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 600 | const char *Flavor, bool Elidable = false); |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 601 | |
Douglas Gregor | 96176b3 | 2008-11-18 23:14:02 +0000 | [diff] [blame] | 602 | ImplicitConversionSequence |
| 603 | TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method); |
| 604 | bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method); |
| 605 | |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 606 | ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From); |
| 607 | bool PerformContextuallyConvertToBool(Expr *&From); |
| 608 | |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 609 | /// OverloadingResult - Capture the result of performing overload |
| 610 | /// resolution. |
| 611 | enum OverloadingResult { |
| 612 | OR_Success, ///< Overload resolution succeeded. |
| 613 | OR_No_Viable_Function, ///< No viable function found. |
Douglas Gregor | 48f3bb9 | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 614 | OR_Ambiguous, ///< Ambiguous candidates found. |
| 615 | OR_Deleted ///< Overload resoltuion refers to a deleted function. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 616 | }; |
| 617 | |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 618 | typedef llvm::SmallPtrSet<FunctionDecl *, 16> FunctionSet; |
| 619 | typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet; |
| 620 | typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; |
| 621 | |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 622 | void AddOverloadCandidate(FunctionDecl *Function, |
| 623 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 624 | OverloadCandidateSet& CandidateSet, |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 625 | bool SuppressUserConversions = false, |
| 626 | bool ForceRValue = false); |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 627 | void AddFunctionCandidates(const FunctionSet &Functions, |
| 628 | Expr **Args, unsigned NumArgs, |
| 629 | OverloadCandidateSet& CandidateSet, |
| 630 | bool SuppressUserConversions = false); |
Douglas Gregor | 96176b3 | 2008-11-18 23:14:02 +0000 | [diff] [blame] | 631 | void AddMethodCandidate(CXXMethodDecl *Method, |
| 632 | Expr *Object, Expr **Args, unsigned NumArgs, |
| 633 | OverloadCandidateSet& CandidateSet, |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 634 | bool SuppressUserConversions = false, |
| 635 | bool ForceRValue = false); |
Douglas Gregor | f1991ea | 2008-11-07 22:36:19 +0000 | [diff] [blame] | 636 | void AddConversionCandidate(CXXConversionDecl *Conversion, |
| 637 | Expr *From, QualType ToType, |
| 638 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | 106c6eb | 2008-11-19 22:57:39 +0000 | [diff] [blame] | 639 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 640 | const FunctionProtoType *Proto, |
Douglas Gregor | 106c6eb | 2008-11-19 22:57:39 +0000 | [diff] [blame] | 641 | Expr *Object, Expr **Args, unsigned NumArgs, |
| 642 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 643 | void AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S, |
Douglas Gregor | f680a0f | 2009-02-04 16:44:47 +0000 | [diff] [blame] | 644 | SourceLocation OpLoc, |
Douglas Gregor | 96176b3 | 2008-11-18 23:14:02 +0000 | [diff] [blame] | 645 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | f680a0f | 2009-02-04 16:44:47 +0000 | [diff] [blame] | 646 | OverloadCandidateSet& CandidateSet, |
| 647 | SourceRange OpRange = SourceRange()); |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 648 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
| 649 | SourceLocation OpLoc, |
| 650 | Expr **Args, unsigned NumArgs, |
| 651 | OverloadCandidateSet& CandidateSet, |
| 652 | SourceRange OpRange = SourceRange()); |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 653 | void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, |
| 654 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | 88b4bf2 | 2009-01-13 00:52:54 +0000 | [diff] [blame] | 655 | OverloadCandidateSet& CandidateSet, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 656 | bool IsAssignmentOperator = false, |
| 657 | unsigned NumContextualBoolArguments = 0); |
Douglas Gregor | 7425373 | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 658 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
| 659 | Expr **Args, unsigned NumArgs, |
| 660 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 661 | void AddArgumentDependentLookupCandidates(DeclarationName Name, |
| 662 | Expr **Args, unsigned NumArgs, |
| 663 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 664 | bool isBetterOverloadCandidate(const OverloadCandidate& Cand1, |
| 665 | const OverloadCandidate& Cand2); |
| 666 | OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet, |
| 667 | OverloadCandidateSet::iterator& Best); |
| 668 | void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, |
| 669 | bool OnlyViable); |
| 670 | |
Douglas Gregor | 904eed3 | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 671 | FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, |
| 672 | bool Complain); |
| 673 | void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn); |
| 674 | |
Douglas Gregor | 1733001 | 2009-02-04 15:01:18 +0000 | [diff] [blame] | 675 | FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee, |
| 676 | DeclarationName UnqualifiedName, |
Douglas Gregor | 0a39668 | 2008-11-26 06:01:48 +0000 | [diff] [blame] | 677 | SourceLocation LParenLoc, |
| 678 | Expr **Args, unsigned NumArgs, |
| 679 | SourceLocation *CommaLocs, |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 680 | SourceLocation RParenLoc, |
Douglas Gregor | 1733001 | 2009-02-04 15:01:18 +0000 | [diff] [blame] | 681 | bool &ArgumentDependentLookup); |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 682 | |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 683 | OwningExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
| 684 | unsigned Opc, |
| 685 | FunctionSet &Functions, |
| 686 | ExprArg input); |
| 687 | |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 688 | OwningExprResult CreateOverloadedBinOp(SourceLocation OpLoc, |
| 689 | unsigned Opc, |
| 690 | FunctionSet &Functions, |
| 691 | Expr *LHS, Expr *RHS); |
| 692 | |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 693 | ExprResult |
| 694 | BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
| 695 | SourceLocation LParenLoc, Expr **Args, |
| 696 | unsigned NumArgs, SourceLocation *CommaLocs, |
| 697 | SourceLocation RParenLoc); |
Douglas Gregor | f9eb905 | 2008-11-19 21:05:33 +0000 | [diff] [blame] | 698 | ExprResult |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 699 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
Douglas Gregor | f9eb905 | 2008-11-19 21:05:33 +0000 | [diff] [blame] | 700 | Expr **Args, unsigned NumArgs, |
| 701 | SourceLocation *CommaLocs, |
| 702 | SourceLocation RParenLoc); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 703 | |
Douglas Gregor | 3fc749d | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 704 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc, |
Douglas Gregor | 8ba1074 | 2008-11-20 16:27:02 +0000 | [diff] [blame] | 705 | SourceLocation MemberLoc, |
| 706 | IdentifierInfo &Member); |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 707 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 708 | /// Helpers for dealing with function parameters. |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 709 | bool CheckParmsForFunctionDef(FunctionDecl *FD); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 710 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
Douglas Gregor | 6d6eb57 | 2008-05-07 04:49:29 +0000 | [diff] [blame] | 711 | void CheckExtraCXXDefaultArguments(Declarator &D); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 712 | |
Douglas Gregor | 1a0d31a | 2009-01-12 18:45:55 +0000 | [diff] [blame] | 713 | Scope *getNonFieldDeclScope(Scope *S); |
| 714 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 715 | /// \name Name lookup |
| 716 | /// |
| 717 | /// These routines provide name lookup that is used during semantic |
| 718 | /// analysis to resolve the various kinds of names (identifiers, |
| 719 | /// overloaded operator names, constructor names, etc.) into zero or |
| 720 | /// more declarations within a particular scope. The major entry |
| 721 | /// points are LookupName, which performs unqualified name lookup, |
| 722 | /// and LookupQualifiedName, which performs qualified name lookup. |
| 723 | /// |
| 724 | /// All name lookup is performed based on some specific criteria, |
| 725 | /// which specify what names will be visible to name lookup and how |
| 726 | /// far name lookup should work. These criteria are important both |
| 727 | /// for capturing language semantics (certain lookups will ignore |
| 728 | /// certain names, for example) and for performance, since name |
| 729 | /// lookup is often a bottleneck in the compilation of C++. Name |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 730 | /// lookup criteria is specified via the LookupCriteria enumeration. |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 731 | /// |
| 732 | /// The results of name lookup can vary based on the kind of name |
| 733 | /// lookup performed, the current language, and the translation |
| 734 | /// unit. In C, for example, name lookup will either return nothing |
| 735 | /// (no entity found) or a single declaration. In C++, name lookup |
| 736 | /// can additionally refer to a set of overloaded functions or |
| 737 | /// result in an ambiguity. All of the possible results of name |
| 738 | /// lookup are captured by the LookupResult class, which provides |
| 739 | /// the ability to distinguish among them. |
| 740 | //@{ |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 741 | |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 742 | /// @brief Describes the kind of name lookup to perform. |
| 743 | enum LookupNameKind { |
| 744 | /// Ordinary name lookup, which finds ordinary names (functions, |
| 745 | /// variables, typedefs, etc.) in C and most kinds of names |
| 746 | /// (functions, variables, members, types, etc.) in C++. |
| 747 | LookupOrdinaryName = 0, |
| 748 | /// Tag name lookup, which finds the names of enums, classes, |
| 749 | /// structs, and unions. |
| 750 | LookupTagName, |
| 751 | /// Member name lookup, which finds the names of |
| 752 | /// class/struct/union members. |
| 753 | LookupMemberName, |
Douglas Gregor | f680a0f | 2009-02-04 16:44:47 +0000 | [diff] [blame] | 754 | // Look up of an operator name (e.g., operator+) for use with |
| 755 | // operator overloading. This lookup is similar to ordinary name |
| 756 | // lookup, but will ignore any declarations that are class |
| 757 | // members. |
| 758 | LookupOperatorName, |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 759 | /// Look up of a name that precedes the '::' scope resolution |
| 760 | /// operator in C++. This lookup completely ignores operator, |
| 761 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
| 762 | LookupNestedNameSpecifierName, |
| 763 | /// Look up a namespace name within a C++ using directive or |
| 764 | /// namespace alias definition, ignoring non-namespace names (C++ |
| 765 | /// [basic.lookup.udir]p1). |
Douglas Gregor | d6f7e9d | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 766 | LookupNamespaceName, |
Douglas Gregor | 6e378de | 2009-04-23 23:18:26 +0000 | [diff] [blame] | 767 | /// Look up an ordinary name that is going to be redeclared as a |
| 768 | /// name with linkage. This lookup ignores any declarations that |
| 769 | /// are outside of the current scope unless they have linkage. See |
| 770 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
| 771 | LookupRedeclarationWithLinkage, |
| 772 | /// Look up the name of an Objective-C protocol. |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 773 | LookupObjCProtocolName, |
| 774 | /// Look up the name of an Objective-C implementation |
| 775 | LookupObjCImplementationName, |
| 776 | /// Look up the name of an Objective-C category implementation |
| 777 | LookupObjCCategoryImplName |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 778 | }; |
| 779 | |
| 780 | /// @brief Represents the results of name lookup. |
| 781 | /// |
| 782 | /// An instance of the LookupResult class captures the results of a |
| 783 | /// single name lookup, which can return no result (nothing found), |
| 784 | /// a single declaration, a set of overloaded functions, or an |
| 785 | /// ambiguity. Use the getKind() method to determine which of these |
| 786 | /// results occurred for a given lookup. |
| 787 | /// |
| 788 | /// Any non-ambiguous lookup can be converted into a single |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 789 | /// (possibly NULL) @c NamedDecl* via a conversion function or the |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 790 | /// getAsDecl() method. This conversion permits the common-case |
| 791 | /// usage in C and Objective-C where name lookup will always return |
| 792 | /// a single declaration. |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 793 | struct LookupResult { |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 794 | /// The kind of entity that is actually stored within the |
| 795 | /// LookupResult object. |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 796 | enum { |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 797 | /// First is a single declaration (a NamedDecl*), which may be NULL. |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 798 | SingleDecl, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 799 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 800 | /// First is a single declaration (an OverloadedFunctionDecl*). |
| 801 | OverloadedDeclSingleDecl, |
| 802 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 803 | /// [First, Last) is an iterator range represented as opaque |
| 804 | /// pointers used to reconstruct IdentifierResolver::iterators. |
| 805 | OverloadedDeclFromIdResolver, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 806 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 807 | /// [First, Last) is an iterator range represented as opaque |
| 808 | /// pointers used to reconstruct DeclContext::lookup_iterators. |
| 809 | OverloadedDeclFromDeclContext, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 810 | |
| 811 | /// First is a pointer to a BasePaths structure, which is owned |
| 812 | /// by the LookupResult. Last is non-zero to indicate that the |
| 813 | /// ambiguity is caused by two names found in base class |
| 814 | /// subobjects of different types. |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 815 | AmbiguousLookupStoresBasePaths, |
| 816 | |
| 817 | /// [First, Last) is an iterator range represented as opaque |
| 818 | /// pointers used to reconstruct new'ed Decl*[] array containing |
| 819 | /// found ambiguous decls. LookupResult is owner of this array. |
| 820 | AmbiguousLookupStoresDecls |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 821 | } StoredKind; |
| 822 | |
| 823 | /// The first lookup result, whose contents depend on the kind of |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 824 | /// lookup result. This may be a NamedDecl* (if StoredKind == |
| 825 | /// SingleDecl), OverloadedFunctionDecl* (if StoredKind == |
| 826 | /// OverloadedDeclSingleDecl), the opaque pointer from an |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 827 | /// IdentifierResolver::iterator (if StoredKind == |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 828 | /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator |
| 829 | /// (if StoredKind == OverloadedDeclFromDeclContext), or a |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 830 | /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths). |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 831 | mutable uintptr_t First; |
| 832 | |
| 833 | /// The last lookup result, whose contents depend on the kind of |
| 834 | /// lookup result. This may be unused (if StoredKind == |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 835 | /// SingleDecl), it may have the same type as First (for |
| 836 | /// overloaded function declarations), or is may be used as a |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 837 | /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths). |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 838 | mutable uintptr_t Last; |
| 839 | |
| 840 | /// Context - The context in which we will build any |
| 841 | /// OverloadedFunctionDecl nodes needed by the conversion to |
| 842 | /// Decl*. |
| 843 | ASTContext *Context; |
| 844 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 845 | /// @brief The kind of entity found by name lookup. |
| 846 | enum LookupKind { |
| 847 | /// @brief No entity found met the criteria. |
| 848 | NotFound = 0, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 849 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 850 | /// @brief Name lookup found a single declaration that met the |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 851 | /// criteria. getAsDecl will return this declaration. |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 852 | Found, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 854 | /// @brief Name lookup found a set of overloaded functions that |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 855 | /// met the criteria. getAsDecl will turn this set of overloaded |
| 856 | /// functions into an OverloadedFunctionDecl. |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 857 | FoundOverloaded, |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 858 | |
| 859 | /// Name lookup results in an ambiguity because multiple |
| 860 | /// entities that meet the lookup criteria were found in |
| 861 | /// subobjects of different types. For example: |
| 862 | /// @code |
| 863 | /// struct A { void f(int); } |
| 864 | /// struct B { void f(double); } |
| 865 | /// struct C : A, B { }; |
| 866 | /// void test(C c) { |
| 867 | /// c.f(0); // error: A::f and B::f come from subobjects of different |
| 868 | /// // types. overload resolution is not performed. |
| 869 | /// } |
| 870 | /// @endcode |
| 871 | AmbiguousBaseSubobjectTypes, |
| 872 | |
| 873 | /// Name lookup results in an ambiguity because multiple |
| 874 | /// nonstatic entities that meet the lookup criteria were found |
| 875 | /// in different subobjects of the same type. For example: |
| 876 | /// @code |
| 877 | /// struct A { int x; }; |
| 878 | /// struct B : A { }; |
| 879 | /// struct C : A { }; |
| 880 | /// struct D : B, C { }; |
| 881 | /// int test(D d) { |
| 882 | /// return d.x; // error: 'x' is found in two A subobjects (of B and C) |
| 883 | /// } |
| 884 | /// @endcode |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 885 | AmbiguousBaseSubobjects, |
| 886 | |
| 887 | /// Name lookup results in an ambiguity because multiple definitions |
| 888 | /// of entity that meet the lookup criteria were found in different |
| 889 | /// declaration contexts. |
| 890 | /// @code |
| 891 | /// namespace A { |
| 892 | /// int i; |
| 893 | /// namespace B { int i; } |
| 894 | /// int test() { |
| 895 | /// using namespace B; |
| 896 | /// return i; // error 'i' is found in namespace A and A::B |
| 897 | /// } |
| 898 | /// } |
| 899 | /// @endcode |
| 900 | AmbiguousReference |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 901 | }; |
| 902 | |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 903 | static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D); |
Douglas Gregor | 4bb64e7 | 2009-01-15 02:19:31 +0000 | [diff] [blame] | 904 | |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 905 | static LookupResult CreateLookupResult(ASTContext &Context, |
| 906 | IdentifierResolver::iterator F, |
| 907 | IdentifierResolver::iterator L); |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 908 | |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 909 | static LookupResult CreateLookupResult(ASTContext &Context, |
| 910 | DeclContext::lookup_iterator F, |
| 911 | DeclContext::lookup_iterator L); |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 912 | |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 913 | static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths, |
| 914 | bool DifferentSubobjectTypes) { |
| 915 | LookupResult Result; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 916 | Result.StoredKind = AmbiguousLookupStoresBasePaths; |
Douglas Gregor | 69d993a | 2009-01-17 01:13:24 +0000 | [diff] [blame] | 917 | Result.First = reinterpret_cast<uintptr_t>(Paths); |
| 918 | Result.Last = DifferentSubobjectTypes? 1 : 0; |
| 919 | Result.Context = &Context; |
| 920 | return Result; |
| 921 | } |
Douglas Gregor | 4bb64e7 | 2009-01-15 02:19:31 +0000 | [diff] [blame] | 922 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 923 | template <typename Iterator> |
| 924 | static LookupResult CreateLookupResult(ASTContext &Context, |
| 925 | Iterator B, std::size_t Len) { |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 926 | NamedDecl ** Array = new NamedDecl*[Len]; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 927 | for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B) |
| 928 | Array[Idx] = *B; |
| 929 | LookupResult Result; |
| 930 | Result.StoredKind = AmbiguousLookupStoresDecls; |
| 931 | Result.First = reinterpret_cast<uintptr_t>(Array); |
| 932 | Result.Last = reinterpret_cast<uintptr_t>(Array + Len); |
| 933 | Result.Context = &Context; |
| 934 | return Result; |
| 935 | } |
| 936 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 937 | LookupKind getKind() const; |
| 938 | |
| 939 | /// @brief Determine whether name look found something. |
| 940 | operator bool() const { return getKind() != NotFound; } |
| 941 | |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 942 | /// @brief Determines whether the lookup resulted in an ambiguity. |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 943 | bool isAmbiguous() const { |
| 944 | return StoredKind == AmbiguousLookupStoresBasePaths || |
| 945 | StoredKind == AmbiguousLookupStoresDecls; |
| 946 | } |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 947 | |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 948 | /// @brief Allows conversion of a lookup result into a |
| 949 | /// declaration, with the same behavior as getAsDecl. |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 950 | operator NamedDecl*() const { return getAsDecl(); } |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 951 | |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 952 | NamedDecl* getAsDecl() const; |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 953 | |
| 954 | BasePaths *getBasePaths() const; |
Douglas Gregor | d863517 | 2009-02-02 21:35:47 +0000 | [diff] [blame] | 955 | |
| 956 | /// \brief Iterate over the results of name lookup. |
| 957 | /// |
| 958 | /// The @c iterator class provides iteration over the results of a |
| 959 | /// non-ambiguous name lookup. |
| 960 | class iterator { |
| 961 | /// The LookupResult structure we're iterating through. |
| 962 | LookupResult *Result; |
| 963 | |
| 964 | /// The current position of this iterator within the sequence of |
| 965 | /// results. This value will have the same representation as the |
| 966 | /// @c First field in the LookupResult structure. |
| 967 | mutable uintptr_t Current; |
| 968 | |
| 969 | public: |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 970 | typedef NamedDecl * value_type; |
| 971 | typedef NamedDecl * reference; |
| 972 | typedef NamedDecl * pointer; |
Douglas Gregor | d863517 | 2009-02-02 21:35:47 +0000 | [diff] [blame] | 973 | typedef std::ptrdiff_t difference_type; |
| 974 | typedef std::forward_iterator_tag iterator_category; |
| 975 | |
| 976 | iterator() : Result(0), Current(0) { } |
| 977 | |
| 978 | iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { } |
| 979 | |
| 980 | reference operator*() const; |
| 981 | |
| 982 | pointer operator->() const { return **this; } |
| 983 | |
| 984 | iterator &operator++(); |
| 985 | |
| 986 | iterator operator++(int) { |
| 987 | iterator tmp(*this); |
| 988 | ++(*this); |
| 989 | return tmp; |
| 990 | } |
| 991 | |
| 992 | friend inline bool operator==(iterator const& x, iterator const& y) { |
| 993 | return x.Current == y.Current; |
| 994 | } |
| 995 | |
| 996 | friend inline bool operator!=(iterator const& x, iterator const& y) { |
| 997 | return x.Current != y.Current; |
| 998 | } |
| 999 | }; |
| 1000 | friend class iterator; |
| 1001 | |
| 1002 | iterator begin(); |
| 1003 | iterator end(); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 1004 | |
| 1005 | /// \brief Free the memory associated with this lookup. |
| 1006 | void Destroy(); |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 1007 | }; |
| 1008 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1009 | private: |
| 1010 | typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy; |
| 1011 | |
| 1012 | std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name, |
| 1013 | LookupNameKind NameKind, |
| 1014 | bool RedeclarationOnly); |
Fariborz Jahanian | ef79bc9 | 2009-04-07 18:28:06 +0000 | [diff] [blame] | 1015 | ObjCMethodDecl *FindMethodInNestedImplementations( |
| 1016 | const ObjCInterfaceDecl *IFace, |
| 1017 | const Selector &Sel); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1018 | |
| 1019 | public: |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 1020 | /// Determines whether D is a suitable lookup result according to the |
| 1021 | /// lookup criteria. |
Douglas Gregor | d6f7e9d | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 1022 | static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind, |
Douglas Gregor | 7dda67d | 2009-02-05 19:25:20 +0000 | [diff] [blame] | 1023 | unsigned IDNS) { |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 1024 | switch (NameKind) { |
| 1025 | case Sema::LookupOrdinaryName: |
| 1026 | case Sema::LookupTagName: |
| 1027 | case Sema::LookupMemberName: |
Douglas Gregor | d6f7e9d | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 1028 | case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 1029 | case Sema::LookupObjCProtocolName: |
| 1030 | case Sema::LookupObjCImplementationName: |
| 1031 | case Sema::LookupObjCCategoryImplName: |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 1032 | return D->isInIdentifierNamespace(IDNS); |
| 1033 | |
Douglas Gregor | f680a0f | 2009-02-04 16:44:47 +0000 | [diff] [blame] | 1034 | case Sema::LookupOperatorName: |
| 1035 | return D->isInIdentifierNamespace(IDNS) && |
| 1036 | !D->getDeclContext()->isRecord(); |
| 1037 | |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 1038 | case Sema::LookupNestedNameSpecifierName: |
| 1039 | return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag); |
| 1040 | |
| 1041 | case Sema::LookupNamespaceName: |
Anders Carlsson | 81c85c4 | 2009-03-28 23:53:49 +0000 | [diff] [blame] | 1042 | return isa<NamespaceDecl>(D) || isa<NamespaceAliasDecl>(D); |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | assert(false && |
Douglas Gregor | 7dda67d | 2009-02-05 19:25:20 +0000 | [diff] [blame] | 1046 | "isAcceptableLookupResult always returns before this point"); |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 1047 | return false; |
| 1048 | } |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 1049 | |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 1050 | LookupResult LookupName(Scope *S, DeclarationName Name, |
| 1051 | LookupNameKind NameKind, |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 1052 | bool RedeclarationOnly = false, |
Eli Friedman | 6eb32f4 | 2009-06-06 02:08:44 +0000 | [diff] [blame] | 1053 | bool AllowBuiltinCreation = false, |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 1054 | SourceLocation Loc = SourceLocation()); |
Douglas Gregor | 4c921ae | 2009-01-30 01:04:22 +0000 | [diff] [blame] | 1055 | LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, |
| 1056 | LookupNameKind NameKind, |
| 1057 | bool RedeclarationOnly = false); |
| 1058 | LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS, |
| 1059 | DeclarationName Name, |
| 1060 | LookupNameKind NameKind, |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 1061 | bool RedeclarationOnly = false, |
Eli Friedman | 6eb32f4 | 2009-06-06 02:08:44 +0000 | [diff] [blame] | 1062 | bool AllowBuiltinCreation = false, |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 1063 | SourceLocation Loc = SourceLocation()); |
Douglas Gregor | 3fd95ce | 2009-03-13 00:33:25 +0000 | [diff] [blame] | 1064 | |
Douglas Gregor | 6e378de | 2009-04-23 23:18:26 +0000 | [diff] [blame] | 1065 | ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II); |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 1066 | ObjCImplementationDecl *LookupObjCImplementation(IdentifierInfo *II); |
| 1067 | ObjCCategoryImplDecl *LookupObjCCategoryImpl(IdentifierInfo *II); |
Douglas Gregor | 6e378de | 2009-04-23 23:18:26 +0000 | [diff] [blame] | 1068 | |
Douglas Gregor | 3fd95ce | 2009-03-13 00:33:25 +0000 | [diff] [blame] | 1069 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
| 1070 | QualType T1, QualType T2, |
| 1071 | FunctionSet &Functions); |
| 1072 | |
| 1073 | void ArgumentDependentLookup(DeclarationName Name, |
| 1074 | Expr **Args, unsigned NumArgs, |
| 1075 | FunctionSet &Functions); |
| 1076 | |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 1077 | void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs, |
| 1078 | AssociatedNamespaceSet &AssociatedNamespaces, |
| 1079 | AssociatedClassSet &AssociatedClasses); |
| 1080 | |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 1081 | bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name, |
| 1082 | SourceLocation NameLoc, |
| 1083 | SourceRange LookupRange = SourceRange()); |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 1084 | //@} |
| 1085 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1086 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 1087 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 1088 | Scope *S, bool ForRedeclaration, |
| 1089 | SourceLocation Loc); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 1090 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
| 1091 | Scope *S); |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 1092 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 1093 | |
| 1094 | // More parsing and symbol table subroutines. |
| 1095 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1096 | // Decl attributes - this routine is the top level dispatcher. |
Chris Lattner | e5c5ee1 | 2008-06-29 00:16:31 +0000 | [diff] [blame] | 1097 | void ProcessDeclAttributes(Decl *D, const Declarator &PD); |
Chris Lattner | f2e4bd5 | 2008-06-28 23:58:55 +0000 | [diff] [blame] | 1098 | void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 1099 | |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 1100 | void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, |
| 1101 | bool &IncompleteImpl); |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 1102 | void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod, |
| 1103 | ObjCMethodDecl *IntfMethod); |
Fariborz Jahanian | 2574a68 | 2009-05-14 23:52:54 +0000 | [diff] [blame] | 1104 | bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1105 | |
| 1106 | NamespaceDecl *GetStdNamespace(); |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 1107 | |
| 1108 | bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, |
Steve Naroff | 22dc0b0 | 2009-02-26 19:11:32 +0000 | [diff] [blame] | 1109 | ObjCInterfaceDecl *IDecl); |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 1110 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 1111 | /// CheckProtocolMethodDefs - This routine checks unimplemented |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 1112 | /// methods declared in protocol, and those referenced by it. |
| 1113 | /// \param IDecl - Used for checking for methods which may have been |
| 1114 | /// inherited. |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 1115 | void CheckProtocolMethodDefs(SourceLocation ImpLoc, |
| 1116 | ObjCProtocolDecl *PDecl, |
Fariborz Jahanian | ca3adf7 | 2007-10-02 20:06:01 +0000 | [diff] [blame] | 1117 | bool& IncompleteImpl, |
Steve Naroff | eefc418 | 2007-10-08 21:05:34 +0000 | [diff] [blame] | 1118 | const llvm::DenseSet<Selector> &InsMap, |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 1119 | const llvm::DenseSet<Selector> &ClsMap, |
| 1120 | ObjCInterfaceDecl *IDecl); |
Fariborz Jahanian | 8c74fa4 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 1121 | |
Steve Naroff | a5997c4 | 2007-10-02 21:43:37 +0000 | [diff] [blame] | 1122 | /// CheckImplementationIvars - This routine checks if the instance variables |
| 1123 | /// listed in the implelementation match those listed in the interface. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1124 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
| 1125 | ObjCIvarDecl **Fields, unsigned nIvars, |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 1126 | SourceLocation Loc); |
Steve Naroff | a5997c4 | 2007-10-02 21:43:37 +0000 | [diff] [blame] | 1127 | |
Fariborz Jahanian | 8c74fa4 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 1128 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 1129 | /// remains unimplemented in the class or category @implementation. |
| 1130 | void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, |
| 1131 | ObjCContainerDecl* IDecl, |
| 1132 | bool IncompleteImpl = false); |
Fariborz Jahanian | 8c74fa4 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 1133 | |
Fariborz Jahanian | 85ff264 | 2007-10-05 18:00:57 +0000 | [diff] [blame] | 1134 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
| 1135 | /// true, or false, accordingly. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1136 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 1137 | const ObjCMethodDecl *PrevMethod, |
| 1138 | bool matchBasedOnSizeAndAlignment = false); |
Steve Naroff | 3b95017 | 2007-10-10 21:53:07 +0000 | [diff] [blame] | 1139 | |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1140 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
| 1141 | /// or protocol against those declared in their implementations. |
| 1142 | void MatchAllMethodDeclarations(const llvm::DenseSet<Selector> &InsMap, |
| 1143 | const llvm::DenseSet<Selector> &ClsMap, |
| 1144 | llvm::DenseSet<Selector> &InsMapSeen, |
| 1145 | llvm::DenseSet<Selector> &ClsMapSeen, |
| 1146 | ObjCImplDecl* IMPDecl, |
| 1147 | ObjCContainerDecl* IDecl, |
| 1148 | bool &IncompleteImpl, |
| 1149 | bool ImmediateClass); |
| 1150 | |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 1151 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
| 1152 | /// unit are added to a global pool. This allows us to efficiently associate |
| 1153 | /// a selector with a method declaraation for purposes of typechecking |
| 1154 | /// messages sent to "id" (where the class of the object is unknown). |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1155 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method); |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 1156 | |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 1157 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
| 1158 | /// there are multiple signatures. |
| 1159 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1160 | |
| 1161 | /// LookupFactoryMethodInGlobalPool - Returns the method and warns if |
| 1162 | /// there are multiple signatures. |
| 1163 | ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R); |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 1164 | |
Steve Naroff | 58ff9e8 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 1165 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1166 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1167 | //===--------------------------------------------------------------------===// |
| 1168 | // Statement Parsing Callbacks: SemaStmt.cpp. |
| 1169 | public: |
Anders Carlsson | 6b1d283 | 2009-05-17 21:11:30 +0000 | [diff] [blame] | 1170 | virtual OwningStmtResult ActOnExprStmt(FullExprArg Expr); |
Sebastian Redl | a60528c | 2008-12-21 12:04:03 +0000 | [diff] [blame] | 1171 | |
| 1172 | virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc); |
| 1173 | virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
| 1174 | MultiStmtArg Elts, |
| 1175 | bool isStmtExpr); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1176 | virtual OwningStmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1177 | SourceLocation StartLoc, |
Sebastian Redl | a60528c | 2008-12-21 12:04:03 +0000 | [diff] [blame] | 1178 | SourceLocation EndLoc); |
Sebastian Redl | 117054a | 2008-12-28 16:13:43 +0000 | [diff] [blame] | 1179 | virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal, |
| 1180 | SourceLocation DotDotDotLoc, ExprArg RHSVal, |
Chris Lattner | 24e1e70 | 2009-03-04 04:23:07 +0000 | [diff] [blame] | 1181 | SourceLocation ColonLoc); |
| 1182 | virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt); |
| 1183 | |
Sebastian Redl | 117054a | 2008-12-28 16:13:43 +0000 | [diff] [blame] | 1184 | virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
| 1185 | SourceLocation ColonLoc, |
| 1186 | StmtArg SubStmt, Scope *CurScope); |
Sebastian Redl | de30747 | 2009-01-11 00:38:46 +0000 | [diff] [blame] | 1187 | virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc, |
| 1188 | IdentifierInfo *II, |
| 1189 | SourceLocation ColonLoc, |
| 1190 | StmtArg SubStmt); |
Anders Carlsson | a99fad8 | 2009-05-17 18:26:53 +0000 | [diff] [blame] | 1191 | virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, |
| 1192 | FullExprArg CondVal, StmtArg ThenVal, |
| 1193 | SourceLocation ElseLoc, StmtArg ElseVal); |
Sebastian Redl | de30747 | 2009-01-11 00:38:46 +0000 | [diff] [blame] | 1194 | virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond); |
| 1195 | virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
| 1196 | StmtArg Switch, StmtArg Body); |
Anders Carlsson | 7f537c1 | 2009-05-17 21:22:26 +0000 | [diff] [blame] | 1197 | virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, |
| 1198 | FullExprArg Cond, StmtArg Body); |
Sebastian Redl | f05b152 | 2009-01-16 23:28:06 +0000 | [diff] [blame] | 1199 | virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 1200 | SourceLocation WhileLoc, ExprArg Cond); |
| 1201 | |
| 1202 | virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc, |
| 1203 | SourceLocation LParenLoc, |
| 1204 | StmtArg First, ExprArg Second, |
| 1205 | ExprArg Third, SourceLocation RParenLoc, |
| 1206 | StmtArg Body); |
| 1207 | virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
| 1208 | SourceLocation LParenLoc, |
| 1209 | StmtArg First, ExprArg Second, |
| 1210 | SourceLocation RParenLoc, StmtArg Body); |
Sebastian Redl | 4cffe2f | 2009-01-18 13:19:59 +0000 | [diff] [blame] | 1211 | |
| 1212 | virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
| 1213 | SourceLocation LabelLoc, |
| 1214 | IdentifierInfo *LabelII); |
| 1215 | virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
| 1216 | SourceLocation StarLoc, |
| 1217 | ExprArg DestExp); |
| 1218 | virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc, |
| 1219 | Scope *CurScope); |
| 1220 | virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc, |
| 1221 | Scope *CurScope); |
| 1222 | |
| 1223 | virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc, |
Anders Carlsson | a0ab25d | 2009-05-30 21:42:34 +0000 | [diff] [blame] | 1224 | FullExprArg RetValExp); |
Sebastian Redl | 4cffe2f | 2009-01-18 13:19:59 +0000 | [diff] [blame] | 1225 | OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, |
| 1226 | Expr *RetValExp); |
| 1227 | |
Sebastian Redl | 3037ed0 | 2009-01-18 16:53:17 +0000 | [diff] [blame] | 1228 | virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc, |
| 1229 | bool IsSimple, |
| 1230 | bool IsVolatile, |
| 1231 | unsigned NumOutputs, |
| 1232 | unsigned NumInputs, |
| 1233 | std::string *Names, |
| 1234 | MultiExprArg Constraints, |
| 1235 | MultiExprArg Exprs, |
| 1236 | ExprArg AsmString, |
| 1237 | MultiExprArg Clobbers, |
| 1238 | SourceLocation RParenLoc); |
Sebastian Redl | 431e90e | 2009-01-18 17:43:11 +0000 | [diff] [blame] | 1239 | |
| 1240 | virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, |
| 1241 | SourceLocation RParen, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1242 | DeclPtrTy Parm, StmtArg Body, |
Sebastian Redl | 431e90e | 2009-01-18 17:43:11 +0000 | [diff] [blame] | 1243 | StmtArg CatchList); |
| 1244 | |
| 1245 | virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, |
| 1246 | StmtArg Body); |
| 1247 | |
| 1248 | virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, |
| 1249 | StmtArg Try, |
| 1250 | StmtArg Catch, StmtArg Finally); |
| 1251 | |
| 1252 | virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, |
Steve Naroff | e21dd6f | 2009-02-11 20:05:44 +0000 | [diff] [blame] | 1253 | ExprArg Throw, |
| 1254 | Scope *CurScope); |
Sebastian Redl | 431e90e | 2009-01-18 17:43:11 +0000 | [diff] [blame] | 1255 | virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 1256 | ExprArg SynchExpr, |
| 1257 | StmtArg SynchBody); |
Sebastian Redl | a0fd865 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 1258 | |
Douglas Gregor | d308e62 | 2009-05-18 20:51:54 +0000 | [diff] [blame] | 1259 | VarDecl *BuildExceptionDeclaration(Scope *S, QualType ExDeclType, |
| 1260 | IdentifierInfo *Name, |
| 1261 | SourceLocation Loc, |
| 1262 | SourceRange Range); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1263 | virtual DeclPtrTy ActOnExceptionDeclarator(Scope *S, Declarator &D); |
Douglas Gregor | d308e62 | 2009-05-18 20:51:54 +0000 | [diff] [blame] | 1264 | |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 1265 | virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1266 | DeclPtrTy ExDecl, |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 1267 | StmtArg HandlerBlock); |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 1268 | virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc, |
| 1269 | StmtArg TryBlock, |
| 1270 | MultiStmtArg Handlers); |
Sebastian Redl | 13e8854 | 2009-04-27 21:33:24 +0000 | [diff] [blame] | 1271 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
Sebastian Redl | a0fd865 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 1272 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1273 | //===--------------------------------------------------------------------===// |
| 1274 | // Expression Parsing Callbacks: SemaExpr.cpp. |
| 1275 | |
Douglas Gregor | 48f3bb9 | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 1276 | bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc); |
Fariborz Jahanian | c001e89 | 2009-05-08 20:20:55 +0000 | [diff] [blame] | 1277 | bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, |
| 1278 | ObjCMethodDecl *Getter, |
| 1279 | SourceLocation Loc); |
Fariborz Jahanian | 5b53005 | 2009-05-13 18:09:35 +0000 | [diff] [blame] | 1280 | void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, |
| 1281 | Expr **Args, unsigned NumArgs); |
Chris Lattner | 76a642f | 2009-02-15 22:43:40 +0000 | [diff] [blame] | 1282 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1283 | // Primary Expressions. |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 1284 | virtual SourceRange getExprRange(ExprTy *E) const; |
| 1285 | |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1286 | virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc, |
| 1287 | IdentifierInfo &II, |
| 1288 | bool HasTrailingLParen, |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 1289 | const CXXScopeSpec *SS = 0, |
| 1290 | bool isAddressOfOperand = false); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1291 | virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S, |
Douglas Gregor | 487a75a | 2008-11-19 19:09:45 +0000 | [diff] [blame] | 1292 | SourceLocation OperatorLoc, |
| 1293 | OverloadedOperatorKind Op, |
| 1294 | bool HasTrailingLParen, |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 1295 | const CXXScopeSpec &SS, |
| 1296 | bool isAddressOfOperand); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1297 | virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S, |
Douglas Gregor | 487a75a | 2008-11-19 19:09:45 +0000 | [diff] [blame] | 1298 | SourceLocation OperatorLoc, |
| 1299 | TypeTy *Ty, |
| 1300 | bool HasTrailingLParen, |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 1301 | const CXXScopeSpec &SS, |
| 1302 | bool isAddressOfOperand); |
Douglas Gregor | 1a49af9 | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 1303 | DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc, |
| 1304 | bool TypeDependent, bool ValueDependent, |
| 1305 | const CXXScopeSpec *SS = 0); |
Douglas Gregor | ffb4b6e | 2009-04-15 06:41:24 +0000 | [diff] [blame] | 1306 | VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field, |
| 1307 | llvm::SmallVectorImpl<FieldDecl *> &Path); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1308 | OwningExprResult |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 1309 | BuildAnonymousStructUnionMemberReference(SourceLocation Loc, |
| 1310 | FieldDecl *Field, |
| 1311 | Expr *BaseObjectExpr = 0, |
| 1312 | SourceLocation OpLoc = SourceLocation()); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1313 | OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, |
| 1314 | DeclarationName Name, |
| 1315 | bool HasTrailingLParen, |
| 1316 | const CXXScopeSpec *SS, |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 1317 | bool isAddressOfOperand = false); |
Douglas Gregor | 10c4262 | 2008-11-18 15:03:34 +0000 | [diff] [blame] | 1318 | |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1319 | virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc, |
| 1320 | tok::TokenKind Kind); |
| 1321 | virtual OwningExprResult ActOnNumericConstant(const Token &); |
| 1322 | virtual OwningExprResult ActOnCharacterConstant(const Token &); |
| 1323 | virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, |
| 1324 | ExprArg Val); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1325 | |
Steve Naroff | f69936d | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1326 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1327 | /// fragments (e.g. "foo" "bar" L"baz"). |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1328 | virtual OwningExprResult ActOnStringLiteral(const Token *Toks, |
| 1329 | unsigned NumToks); |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 1330 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1331 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 1332 | OwningExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, |
| 1333 | unsigned OpcIn, |
| 1334 | ExprArg InputArg); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1335 | virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, |
| 1336 | tok::TokenKind Op, ExprArg Input); |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 1337 | |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 1338 | OwningExprResult CreateSizeOfAlignOfExpr(QualType T, SourceLocation OpLoc, |
| 1339 | bool isSizeOf, SourceRange R); |
| 1340 | OwningExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc, |
| 1341 | bool isSizeOf, SourceRange R); |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 1342 | virtual OwningExprResult |
| 1343 | ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType, |
| 1344 | void *TyOrEx, const SourceRange &ArgRange); |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 1345 | |
Chris Lattner | 31e21e0 | 2009-01-24 20:17:12 +0000 | [diff] [blame] | 1346 | bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R); |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 1347 | bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc, |
| 1348 | const SourceRange &R, bool isSizeof); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1349 | |
| 1350 | virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
| 1351 | tok::TokenKind Kind, |
| 1352 | ExprArg Input); |
| 1353 | |
| 1354 | virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base, |
| 1355 | SourceLocation LLoc, |
| 1356 | ExprArg Idx, |
| 1357 | SourceLocation RLoc); |
| 1358 | virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base, |
| 1359 | SourceLocation OpLoc, |
| 1360 | tok::TokenKind OpKind, |
| 1361 | SourceLocation MemberLoc, |
Fariborz Jahanian | a6e3ac5 | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1362 | IdentifierInfo &Member, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1363 | DeclPtrTy ImplDecl); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1364 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 1365 | FunctionDecl *FDecl, |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1366 | const FunctionProtoType *Proto, |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 1367 | Expr **Args, unsigned NumArgs, |
| 1368 | SourceLocation RParenLoc); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1369 | |
Steve Naroff | f69936d | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1370 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1371 | /// This provides the location of the left/right parens and a list of comma |
| 1372 | /// locations. |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1373 | virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn, |
| 1374 | SourceLocation LParenLoc, |
| 1375 | MultiExprArg Args, |
| 1376 | SourceLocation *CommaLocs, |
| 1377 | SourceLocation RParenLoc); |
| 1378 | |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 1379 | virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
| 1380 | SourceLocation RParenLoc, ExprArg Op); |
| 1381 | |
| 1382 | virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, |
| 1383 | TypeTy *Ty, |
| 1384 | SourceLocation RParenLoc, |
| 1385 | ExprArg Op); |
| 1386 | |
| 1387 | virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc, |
| 1388 | MultiExprArg InitList, |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 1389 | SourceLocation RParenLoc); |
| 1390 | |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 1391 | virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig, |
| 1392 | SourceLocation Loc, |
Douglas Gregor | eeae8f0 | 2009-03-28 00:41:23 +0000 | [diff] [blame] | 1393 | bool GNUSyntax, |
Douglas Gregor | 05c13a3 | 2009-01-22 00:58:24 +0000 | [diff] [blame] | 1394 | OwningExprResult Init); |
| 1395 | |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 1396 | virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
| 1397 | tok::TokenKind Kind, |
| 1398 | ExprArg LHS, ExprArg RHS); |
| 1399 | OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc, |
| 1400 | unsigned Opc, Expr *lhs, Expr *rhs); |
Douglas Gregor | eaebc75 | 2008-11-06 23:29:22 +0000 | [diff] [blame] | 1401 | |
Steve Naroff | f69936d | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1402 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1403 | /// in the case of a the GNU conditional expr extension. |
Sebastian Redl | b8a6aca | 2009-01-19 22:31:54 +0000 | [diff] [blame] | 1404 | virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
| 1405 | SourceLocation ColonLoc, |
| 1406 | ExprArg Cond, ExprArg LHS, |
| 1407 | ExprArg RHS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1408 | |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1409 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1410 | virtual OwningExprResult ActOnAddrLabel(SourceLocation OpLoc, |
| 1411 | SourceLocation LabLoc, |
| 1412 | IdentifierInfo *LabelII); |
| 1413 | |
| 1414 | virtual OwningExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtArg SubStmt, |
| 1415 | SourceLocation RPLoc); // "({..})" |
Chris Lattner | 73d0d4f | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 1416 | |
| 1417 | /// __builtin_offsetof(type, a.b[123][456].c) |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1418 | virtual OwningExprResult ActOnBuiltinOffsetOf(Scope *S, |
| 1419 | SourceLocation BuiltinLoc, |
| 1420 | SourceLocation TypeLoc, |
| 1421 | TypeTy *Arg1, |
| 1422 | OffsetOfComponent *CompPtr, |
| 1423 | unsigned NumComponents, |
| 1424 | SourceLocation RParenLoc); |
| 1425 | |
Steve Naroff | d34e915 | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 1426 | // __builtin_types_compatible_p(type1, type2) |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1427 | virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1428 | TypeTy *arg1, TypeTy *arg2, |
| 1429 | SourceLocation RPLoc); |
| 1430 | |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 1431 | // __builtin_choose_expr(constExpr, expr1, expr2) |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1432 | virtual OwningExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
| 1433 | ExprArg cond, ExprArg expr1, |
| 1434 | ExprArg expr2, SourceLocation RPLoc); |
| 1435 | |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 1436 | // __builtin_va_arg(expr, type) |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1437 | virtual OwningExprResult ActOnVAArg(SourceLocation BuiltinLoc, |
| 1438 | ExprArg expr, TypeTy *type, |
| 1439 | SourceLocation RPLoc); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1440 | |
Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 1441 | // __null |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1442 | virtual OwningExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
Douglas Gregor | 2d8b273 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 1443 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1444 | //===------------------------- "Block" Extension ------------------------===// |
| 1445 | |
| 1446 | /// ActOnBlockStart - This callback is invoked when a block literal is |
| 1447 | /// started. |
Steve Naroff | 090276f | 2008-10-10 01:28:17 +0000 | [diff] [blame] | 1448 | virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1449 | |
Steve Naroff | 090276f | 2008-10-10 01:28:17 +0000 | [diff] [blame] | 1450 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
| 1451 | /// If there are no arguments, this is still invoked. |
Mike Stump | 98eb8a7 | 2009-02-04 22:31:32 +0000 | [diff] [blame] | 1452 | virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1453 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1454 | /// ActOnBlockError - If there is an error parsing a block, this callback |
| 1455 | /// is invoked to pop the information about the block from the action impl. |
| 1456 | virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1457 | |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1458 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
| 1459 | /// literal was successfully completed. ^(int x){...} |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1460 | virtual OwningExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, |
| 1461 | StmtArg Body, Scope *CurScope); |
Steve Naroff | 4eb206b | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1462 | |
Chris Lattner | 76a642f | 2009-02-15 22:43:40 +0000 | [diff] [blame] | 1463 | //===---------------------------- C++ Features --------------------------===// |
| 1464 | |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 1465 | // Act on C++ namespaces |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1466 | virtual DeclPtrTy ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc, |
| 1467 | IdentifierInfo *Ident, |
| 1468 | SourceLocation LBrace); |
| 1469 | virtual void ActOnFinishNamespaceDef(DeclPtrTy Dcl, SourceLocation RBrace); |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 1470 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1471 | virtual DeclPtrTy ActOnUsingDirective(Scope *CurScope, |
| 1472 | SourceLocation UsingLoc, |
| 1473 | SourceLocation NamespcLoc, |
| 1474 | const CXXScopeSpec &SS, |
| 1475 | SourceLocation IdentLoc, |
| 1476 | IdentifierInfo *NamespcName, |
| 1477 | AttributeList *AttrList); |
Anders Carlsson | dbb0094 | 2009-03-28 05:27:17 +0000 | [diff] [blame] | 1478 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1479 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
| 1480 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1481 | virtual DeclPtrTy ActOnNamespaceAliasDef(Scope *CurScope, |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 1482 | SourceLocation NamespaceLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1483 | SourceLocation AliasLoc, |
| 1484 | IdentifierInfo *Alias, |
| 1485 | const CXXScopeSpec &SS, |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 1486 | SourceLocation IdentLoc, |
| 1487 | IdentifierInfo *Ident); |
Anders Carlsson | dbb0094 | 2009-03-28 05:27:17 +0000 | [diff] [blame] | 1488 | |
Argyrios Kyrtzidis | 73a0d88 | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 1489 | /// AddCXXDirectInitializerToDecl - This action is called immediately after |
| 1490 | /// ActOnDeclarator, when a C++ direct initializer is present. |
| 1491 | /// e.g: "int x(1);" |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1492 | virtual void AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, |
Argyrios Kyrtzidis | 73a0d88 | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 1493 | SourceLocation LParenLoc, |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1494 | MultiExprArg Exprs, |
Argyrios Kyrtzidis | 73a0d88 | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 1495 | SourceLocation *CommaLocs, |
| 1496 | SourceLocation RParenLoc); |
| 1497 | |
Anders Carlsson | 49d4401 | 2009-04-24 05:16:06 +0000 | [diff] [blame] | 1498 | /// InitializeVarWithConstructor - Creates an CXXConstructExpr |
| 1499 | /// and sets it as the initializer for the the passed in VarDecl. |
Anders Carlsson | 930e8d0 | 2009-04-16 23:50:50 +0000 | [diff] [blame] | 1500 | void InitializeVarWithConstructor(VarDecl *VD, |
| 1501 | CXXConstructorDecl *Constructor, |
| 1502 | QualType DeclInitType, |
| 1503 | Expr **Exprs, unsigned NumExprs); |
Anders Carlsson | def1199 | 2009-05-30 20:36:53 +0000 | [diff] [blame] | 1504 | |
| 1505 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
| 1506 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
| 1507 | /// it simply returns the passed in expression. |
| 1508 | OwningExprResult MaybeBindToTemporary(Expr *E); |
| 1509 | |
Anders Carlsson | b27615a | 2009-05-30 22:47:03 +0000 | [diff] [blame] | 1510 | /// RemoveOutermostTemporaryBinding - Remove and destroy the outermost |
| 1511 | /// CXXBindToTemporaryExpr if necessary. This is used when we want to not |
| 1512 | /// destroy a temporary when a full expression has been evaluated. |
| 1513 | /// For example: |
| 1514 | /// |
| 1515 | /// const T& t = T(10, T()); |
| 1516 | /// |
| 1517 | /// Here the outermost T needs to be destroyed when t goes out of scope, but |
| 1518 | /// the innermost T needs to be destroyed when the expr has been evaluated. |
| 1519 | Expr *RemoveOutermostTemporaryBinding(Expr *E); |
| 1520 | |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1521 | /// InitializationKind - Represents which kind of C++ initialization |
| 1522 | /// [dcl.init] a routine is to perform. |
| 1523 | enum InitializationKind { |
| 1524 | IK_Direct, ///< Direct initialization |
| 1525 | IK_Copy, ///< Copy initialization |
| 1526 | IK_Default ///< Default initialization |
| 1527 | }; |
| 1528 | |
Douglas Gregor | 18fe568 | 2008-11-03 20:45:27 +0000 | [diff] [blame] | 1529 | CXXConstructorDecl * |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1530 | PerformInitializationByConstructor(QualType ClassType, |
| 1531 | Expr **Args, unsigned NumArgs, |
| 1532 | SourceLocation Loc, SourceRange Range, |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 1533 | DeclarationName InitEntity, |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1534 | InitializationKind Kind); |
Douglas Gregor | 18fe568 | 2008-11-03 20:45:27 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 1536 | /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1537 | virtual OwningExprResult ActOnCXXNamedCast(SourceLocation OpLoc, |
| 1538 | tok::TokenKind Kind, |
| 1539 | SourceLocation LAngleBracketLoc, |
| 1540 | TypeTy *Ty, |
| 1541 | SourceLocation RAngleBracketLoc, |
| 1542 | SourceLocation LParenLoc, |
| 1543 | ExprArg E, |
| 1544 | SourceLocation RParenLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1545 | |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1546 | /// ActOnCXXTypeid - Parse typeid( something ). |
| 1547 | virtual OwningExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
| 1548 | SourceLocation LParenLoc, bool isType, |
| 1549 | void *TyOrExpr, |
| 1550 | SourceLocation RParenLoc); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1551 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1552 | //// ActOnCXXThis - Parse 'this' pointer. |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1553 | virtual OwningExprResult ActOnCXXThis(SourceLocation ThisLoc); |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1554 | |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1555 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1556 | virtual OwningExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, |
| 1557 | tok::TokenKind Kind); |
| 1558 | |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 1559 | /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. |
| 1560 | virtual OwningExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); |
| 1561 | |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1562 | //// ActOnCXXThrow - Parse throw expressions. |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1563 | virtual OwningExprResult ActOnCXXThrow(SourceLocation OpLoc, |
| 1564 | ExprArg expr); |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 1565 | bool CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E); |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1566 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1567 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
| 1568 | /// Can be interpreted either as function-style casting ("int(x)") |
| 1569 | /// or class type construction ("ClassType(x,y,z)") |
| 1570 | /// or creation of a value-initialized type ("int()"). |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1571 | virtual OwningExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange, |
| 1572 | TypeTy *TypeRep, |
| 1573 | SourceLocation LParenLoc, |
| 1574 | MultiExprArg Exprs, |
| 1575 | SourceLocation *CommaLocs, |
| 1576 | SourceLocation RParenLoc); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1577 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1578 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1579 | virtual OwningExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
| 1580 | SourceLocation PlacementLParen, |
| 1581 | MultiExprArg PlacementArgs, |
| 1582 | SourceLocation PlacementRParen, |
| 1583 | bool ParenTypeId, Declarator &D, |
| 1584 | SourceLocation ConstructorLParen, |
| 1585 | MultiExprArg ConstructorArgs, |
| 1586 | SourceLocation ConstructorRParen); |
Douglas Gregor | 3433cf7 | 2009-05-21 00:00:09 +0000 | [diff] [blame] | 1587 | OwningExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, |
| 1588 | SourceLocation PlacementLParen, |
| 1589 | MultiExprArg PlacementArgs, |
| 1590 | SourceLocation PlacementRParen, |
| 1591 | bool ParenTypeId, |
| 1592 | QualType AllocType, |
| 1593 | SourceLocation TypeLoc, |
| 1594 | SourceRange TypeRange, |
| 1595 | ExprArg ArraySize, |
| 1596 | SourceLocation ConstructorLParen, |
| 1597 | MultiExprArg ConstructorArgs, |
| 1598 | SourceLocation ConstructorRParen); |
| 1599 | |
| 1600 | bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, |
| 1601 | SourceRange R); |
Sebastian Redl | 00e68e2 | 2009-02-09 18:24:27 +0000 | [diff] [blame] | 1602 | bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, |
| 1603 | bool UseGlobal, QualType AllocType, bool IsArray, |
Sebastian Redl | b5a57a6 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 1604 | Expr **PlaceArgs, unsigned NumPlaceArgs, |
| 1605 | FunctionDecl *&OperatorNew, |
| 1606 | FunctionDecl *&OperatorDelete); |
Sebastian Redl | 00e68e2 | 2009-02-09 18:24:27 +0000 | [diff] [blame] | 1607 | bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, |
| 1608 | DeclarationName Name, Expr** Args, |
| 1609 | unsigned NumArgs, DeclContext *Ctx, |
Sebastian Redl | 7f66239 | 2008-12-04 22:20:51 +0000 | [diff] [blame] | 1610 | bool AllowMissing, FunctionDecl *&Operator); |
Sebastian Redl | b5a57a6 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 1611 | void DeclareGlobalNewDelete(); |
| 1612 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
| 1613 | QualType Argument); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1614 | |
| 1615 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1616 | virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc, |
| 1617 | bool UseGlobal, bool ArrayForm, |
| 1618 | ExprArg Operand); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1619 | |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 1620 | /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a |
| 1621 | /// C++ if/switch/while/for statement. |
| 1622 | /// e.g: "if (int x = f()) {...}" |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1623 | virtual OwningExprResult ActOnCXXConditionDeclarationExpr(Scope *S, |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 1624 | SourceLocation StartLoc, |
| 1625 | Declarator &D, |
| 1626 | SourceLocation EqualLoc, |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1627 | ExprArg AssignExprVal); |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 1628 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1629 | /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support |
| 1630 | /// pseudo-functions. |
| 1631 | virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, |
| 1632 | SourceLocation KWLoc, |
| 1633 | SourceLocation LParen, |
| 1634 | TypeTy *Ty, |
| 1635 | SourceLocation RParen); |
| 1636 | |
Anders Carlsson | 99ba36d | 2009-06-05 15:38:08 +0000 | [diff] [blame] | 1637 | /// MaybeCreateCXXExprWithTemporaries - If the list of temporaries is |
| 1638 | /// non-empty, will create a new CXXExprWithTemporaries expression. |
| 1639 | /// Otherwise, just returs the passed in expression. |
| 1640 | Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr, |
| 1641 | bool DestroyTemps = true); |
| 1642 | |
Anders Carlsson | 165a0a0 | 2009-05-17 18:41:29 +0000 | [diff] [blame] | 1643 | virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr); |
| 1644 | |
Douglas Gregor | 4fdf1fa | 2009-03-11 16:48:53 +0000 | [diff] [blame] | 1645 | bool RequireCompleteDeclContext(const CXXScopeSpec &SS); |
Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 1646 | |
| 1647 | DeclContext *computeDeclContext(const CXXScopeSpec &SS); |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 1648 | bool isDependentScopeSpecifier(const CXXScopeSpec &SS); |
Douglas Gregor | 42af25f | 2009-05-11 19:58:34 +0000 | [diff] [blame] | 1649 | CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); |
| 1650 | bool isUnknownSpecialization(const CXXScopeSpec &SS); |
Douglas Gregor | ca5e77f | 2009-03-18 00:36:05 +0000 | [diff] [blame] | 1651 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1652 | /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the |
| 1653 | /// global scope ('::'). |
| 1654 | virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S, |
| 1655 | SourceLocation CCLoc); |
| 1656 | |
| 1657 | /// ActOnCXXNestedNameSpecifier - Called during parsing of a |
| 1658 | /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now |
| 1659 | /// we want to resolve "bar::". 'SS' is empty or the previously parsed |
| 1660 | /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar', |
| 1661 | /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'. |
| 1662 | /// Returns a CXXScopeTy* object representing the C++ scope. |
| 1663 | virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S, |
| 1664 | const CXXScopeSpec &SS, |
| 1665 | SourceLocation IdLoc, |
| 1666 | SourceLocation CCLoc, |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 1667 | IdentifierInfo &II); |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1668 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1669 | /// ActOnCXXNestedNameSpecifier - Called during parsing of a |
| 1670 | /// nested-name-specifier that involves a template-id, e.g., |
| 1671 | /// "foo::bar<int, float>::", and now we need to build a scope |
| 1672 | /// specifier. \p SS is empty or the previously parsed nested-name |
| 1673 | /// part ("foo::"), \p Type is the already-parsed class template |
| 1674 | /// specialization (or other template-id that names a type), \p |
| 1675 | /// TypeRange is the source range where the type is located, and \p |
| 1676 | /// CCLoc is the location of the trailing '::'. |
| 1677 | virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S, |
| 1678 | const CXXScopeSpec &SS, |
| 1679 | TypeTy *Type, |
| 1680 | SourceRange TypeRange, |
| 1681 | SourceLocation CCLoc); |
| 1682 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1683 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
| 1684 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
| 1685 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
| 1686 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
| 1687 | /// ActOnCXXExitDeclaratorScope is called. |
| 1688 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
| 1689 | virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
| 1690 | |
| 1691 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
| 1692 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
| 1693 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
| 1694 | /// Used to indicate that names should revert to being looked up in the |
| 1695 | /// defining scope. |
Douglas Gregor | 0a59acb | 2008-12-16 00:38:16 +0000 | [diff] [blame] | 1696 | virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1697 | |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1698 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1699 | virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
| 1700 | ExprTy **Strings, |
| 1701 | unsigned NumStrings); |
Anders Carlsson | fc0f021 | 2009-06-07 18:45:35 +0000 | [diff] [blame] | 1702 | |
| 1703 | Expr *BuildObjCEncodeExpression(SourceLocation AtLoc, |
| 1704 | QualType EncodedType, |
| 1705 | SourceLocation RParenLoc); |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1706 | virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
Chris Lattner | 674af95 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1707 | SourceLocation EncodeLoc, |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1708 | SourceLocation LParenLoc, |
| 1709 | TypeTy *Ty, |
| 1710 | SourceLocation RParenLoc); |
| 1711 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1712 | // ParseObjCSelectorExpression - Build selector expression for @selector |
| 1713 | virtual ExprResult ParseObjCSelectorExpression(Selector Sel, |
| 1714 | SourceLocation AtLoc, |
Fariborz Jahanian | 2a35fa9 | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1715 | SourceLocation SelLoc, |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1716 | SourceLocation LParenLoc, |
| 1717 | SourceLocation RParenLoc); |
| 1718 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1719 | // ParseObjCProtocolExpression - Build protocol expression for @protocol |
| 1720 | virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, |
| 1721 | SourceLocation AtLoc, |
| 1722 | SourceLocation ProtoLoc, |
| 1723 | SourceLocation LParenLoc, |
| 1724 | SourceLocation RParenLoc); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1725 | |
| 1726 | //===--------------------------------------------------------------------===// |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 1727 | // C++ Declarations |
| 1728 | // |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1729 | virtual DeclPtrTy ActOnStartLinkageSpecification(Scope *S, |
| 1730 | SourceLocation ExternLoc, |
| 1731 | SourceLocation LangLoc, |
| 1732 | const char *Lang, |
| 1733 | unsigned StrSize, |
| 1734 | SourceLocation LBraceLoc); |
| 1735 | virtual DeclPtrTy ActOnFinishLinkageSpecification(Scope *S, |
| 1736 | DeclPtrTy LinkageSpec, |
| 1737 | SourceLocation RBraceLoc); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 1738 | |
| 1739 | |
| 1740 | //===--------------------------------------------------------------------===// |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1741 | // C++ Classes |
| 1742 | // |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1743 | virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
| 1744 | const CXXScopeSpec *SS); |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1745 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1746 | virtual DeclPtrTy ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, |
| 1747 | Declarator &D, |
| 1748 | ExprTy *BitfieldWidth, |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1749 | ExprTy *Init, |
| 1750 | bool Deleted = false); |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1751 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1752 | virtual MemInitResult ActOnMemInitializer(DeclPtrTy ConstructorD, |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1753 | Scope *S, |
| 1754 | IdentifierInfo *MemberOrBase, |
| 1755 | SourceLocation IdLoc, |
| 1756 | SourceLocation LParenLoc, |
| 1757 | ExprTy **Args, unsigned NumArgs, |
| 1758 | SourceLocation *CommaLocs, |
| 1759 | SourceLocation RParenLoc); |
| 1760 | |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 1761 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
| 1762 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1763 | virtual void ActOnMemInitializers(DeclPtrTy ConstructorDecl, |
Anders Carlsson | a7b3521 | 2009-03-25 02:58:17 +0000 | [diff] [blame] | 1764 | SourceLocation ColonLoc, |
| 1765 | MemInitTy **MemInits, unsigned NumMemInits); |
| 1766 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1767 | virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1768 | DeclPtrTy TagDecl, |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1769 | SourceLocation LBrac, |
| 1770 | SourceLocation RBrac); |
| 1771 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1772 | virtual void ActOnReenterTemplateScope(Scope *S, DeclPtrTy Template); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1773 | virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, |
| 1774 | DeclPtrTy Method); |
| 1775 | virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy Param); |
| 1776 | virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, |
| 1777 | DeclPtrTy Method); |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1778 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1779 | virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc, |
| 1780 | ExprArg AssertExpr, |
| 1781 | ExprArg AssertMessageExpr); |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 1782 | |
Anders Carlsson | 0033836 | 2009-05-11 22:55:49 +0000 | [diff] [blame] | 1783 | virtual bool ActOnFriendDecl(Scope *S, SourceLocation FriendLoc, |
| 1784 | DeclPtrTy Dcl); |
| 1785 | |
Chris Lattner | 6540180 | 2009-04-25 08:28:21 +0000 | [diff] [blame] | 1786 | QualType CheckConstructorDeclarator(Declarator &D, QualType R, |
| 1787 | FunctionDecl::StorageClass& SC); |
Chris Lattner | 6e47501 | 2009-04-25 08:35:12 +0000 | [diff] [blame] | 1788 | void CheckConstructor(CXXConstructorDecl *Constructor); |
Chris Lattner | 6540180 | 2009-04-25 08:28:21 +0000 | [diff] [blame] | 1789 | QualType CheckDestructorDeclarator(Declarator &D, |
| 1790 | FunctionDecl::StorageClass& SC); |
Chris Lattner | 6e47501 | 2009-04-25 08:35:12 +0000 | [diff] [blame] | 1791 | void CheckConversionDeclarator(Declarator &D, QualType &R, |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1792 | FunctionDecl::StorageClass& SC); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1793 | DeclPtrTy ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1794 | |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 1795 | //===--------------------------------------------------------------------===// |
| 1796 | // C++ Derived Classes |
| 1797 | // |
| 1798 | |
| 1799 | /// ActOnBaseSpecifier - Parsed a base specifier |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1800 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
| 1801 | SourceRange SpecifierRange, |
| 1802 | bool Virtual, AccessSpecifier Access, |
| 1803 | QualType BaseType, |
| 1804 | SourceLocation BaseLoc); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1805 | virtual BaseResult ActOnBaseSpecifier(DeclPtrTy classdecl, |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 1806 | SourceRange SpecifierRange, |
| 1807 | bool Virtual, AccessSpecifier Access, |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1808 | TypeTy *basetype, SourceLocation |
| 1809 | BaseLoc); |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 1810 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1811 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, |
| 1812 | unsigned NumBases); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1813 | virtual void ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases, |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 1814 | unsigned NumBases); |
| 1815 | |
| 1816 | bool IsDerivedFrom(QualType Derived, QualType Base); |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 1817 | bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths); |
Douglas Gregor | 7176fff | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 1818 | bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria, |
| 1819 | BasePaths &Paths); |
Douglas Gregor | 0575d4a | 2008-10-24 16:17:19 +0000 | [diff] [blame] | 1820 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
| 1821 | SourceLocation Loc, SourceRange Range); |
Anders Carlsson | d8f9cb0 | 2009-05-13 21:11:42 +0000 | [diff] [blame] | 1822 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
| 1823 | unsigned InaccessibleBaseID, |
| 1824 | unsigned AmbigiousBaseConvID, |
| 1825 | SourceLocation Loc, SourceRange Range, |
| 1826 | DeclarationName Name); |
| 1827 | |
Douglas Gregor | 4dc6b1c | 2009-01-16 00:38:09 +0000 | [diff] [blame] | 1828 | std::string getAmbiguousPathsDisplayString(BasePaths &Paths); |
Anders Carlsson | d7ba27d | 2009-05-14 01:09:04 +0000 | [diff] [blame] | 1829 | |
| 1830 | /// CheckReturnTypeCovariance - Checks whether two types are covariant, |
| 1831 | /// according to C++ [class.virtual]p5. |
| 1832 | bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, |
| 1833 | const CXXMethodDecl *Old); |
| 1834 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1835 | |
Anders Carlsson | 29f006b | 2009-03-27 05:05:05 +0000 | [diff] [blame] | 1836 | //===--------------------------------------------------------------------===// |
| 1837 | // C++ Access Control |
| 1838 | // |
| 1839 | |
| 1840 | bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
| 1841 | NamedDecl *PrevMemberDecl, |
| 1842 | AccessSpecifier LexicalAS); |
| 1843 | |
| 1844 | bool CheckBaseClassAccess(QualType Derived, QualType Base, |
Anders Carlsson | d8f9cb0 | 2009-05-13 21:11:42 +0000 | [diff] [blame] | 1845 | unsigned InaccessibleBaseID, |
| 1846 | BasePaths& Paths, SourceLocation AccessLoc, |
| 1847 | DeclarationName Name); |
Anders Carlsson | 29f006b | 2009-03-27 05:05:05 +0000 | [diff] [blame] | 1848 | |
| 1849 | |
Anders Carlsson | 8211eff | 2009-03-24 01:19:16 +0000 | [diff] [blame] | 1850 | enum AbstractDiagSelID { |
| 1851 | AbstractNone = -1, |
| 1852 | AbstractReturnType, |
| 1853 | AbstractParamType, |
| 1854 | AbstractVariableType, |
| 1855 | AbstractFieldType |
| 1856 | }; |
| 1857 | |
| 1858 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, |
Anders Carlsson | e65a3c8 | 2009-03-24 17:23:42 +0000 | [diff] [blame] | 1859 | AbstractDiagSelID SelID = AbstractNone, |
| 1860 | const CXXRecordDecl *CurrentRD = 0); |
Anders Carlsson | 4681ebd | 2009-03-22 20:18:17 +0000 | [diff] [blame] | 1861 | |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 1862 | //===--------------------------------------------------------------------===// |
| 1863 | // C++ Overloaded Operators [C++ 13.5] |
| 1864 | // |
| 1865 | |
| 1866 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
| 1867 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1868 | //===--------------------------------------------------------------------===// |
| 1869 | // C++ Templates [C++ 14] |
| 1870 | // |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 1871 | virtual TemplateNameKind isTemplateName(const IdentifierInfo &II, Scope *S, |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1872 | TemplateTy &Template, |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1873 | const CXXScopeSpec *SS = 0); |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1874 | bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1875 | TemplateDecl *AdjustDeclIfTemplate(DeclPtrTy &Decl); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 1876 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1877 | virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename, |
| 1878 | SourceLocation KeyLoc, |
| 1879 | IdentifierInfo *ParamName, |
| 1880 | SourceLocation ParamNameLoc, |
| 1881 | unsigned Depth, unsigned Position); |
| 1882 | virtual void ActOnTypeParameterDefault(DeclPtrTy TypeParam, |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 1883 | SourceLocation EqualLoc, |
| 1884 | SourceLocation DefaultLoc, |
| 1885 | TypeTy *Default); |
| 1886 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1887 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1888 | virtual DeclPtrTy ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
| 1889 | unsigned Depth, |
| 1890 | unsigned Position); |
| 1891 | virtual void ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParam, |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 1892 | SourceLocation EqualLoc, |
| 1893 | ExprArg Default); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1894 | virtual DeclPtrTy ActOnTemplateTemplateParameter(Scope *S, |
| 1895 | SourceLocation TmpLoc, |
| 1896 | TemplateParamsTy *Params, |
| 1897 | IdentifierInfo *ParamName, |
| 1898 | SourceLocation ParamNameLoc, |
| 1899 | unsigned Depth, |
| 1900 | unsigned Position); |
| 1901 | virtual void ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParam, |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 1902 | SourceLocation EqualLoc, |
| 1903 | ExprArg Default); |
| 1904 | |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 1905 | virtual TemplateParamsTy * |
| 1906 | ActOnTemplateParameterList(unsigned Depth, |
| 1907 | SourceLocation ExportLoc, |
| 1908 | SourceLocation TemplateLoc, |
| 1909 | SourceLocation LAngleLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1910 | DeclPtrTy *Params, unsigned NumParams, |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 1911 | SourceLocation RAngleLoc); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 1912 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
| 1913 | TemplateParameterList *OldParams); |
| 1914 | |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 1915 | virtual DeclResult |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1916 | ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK, |
| 1917 | SourceLocation KWLoc, const CXXScopeSpec &SS, |
| 1918 | IdentifierInfo *Name, SourceLocation NameLoc, |
| 1919 | AttributeList *Attr, |
Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 1920 | MultiTemplateParamsArg TemplateParameterLists, |
| 1921 | AccessSpecifier AS); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1922 | |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1923 | QualType CheckTemplateIdType(TemplateName Template, |
| 1924 | SourceLocation TemplateLoc, |
| 1925 | SourceLocation LAngleLoc, |
| 1926 | const TemplateArgument *TemplateArgs, |
| 1927 | unsigned NumTemplateArgs, |
| 1928 | SourceLocation RAngleLoc); |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1929 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1930 | virtual TypeResult |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1931 | ActOnTemplateIdType(TemplateTy Template, SourceLocation TemplateLoc, |
| 1932 | SourceLocation LAngleLoc, |
| 1933 | ASTTemplateArgsPtr TemplateArgs, |
| 1934 | SourceLocation *TemplateArgLocs, |
| 1935 | SourceLocation RAngleLoc); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1936 | |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 1937 | virtual TemplateTy ActOnDependentTemplateName(SourceLocation TemplateKWLoc, |
| 1938 | const IdentifierInfo &Name, |
| 1939 | SourceLocation NameLoc, |
| 1940 | const CXXScopeSpec &SS); |
| 1941 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 1942 | bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate, |
| 1943 | ClassTemplateSpecializationDecl *PrevDecl, |
| 1944 | SourceLocation TemplateNameLoc, |
Douglas Gregor | ff66803 | 2009-05-13 18:28:20 +0000 | [diff] [blame] | 1945 | SourceRange ScopeSpecifierRange, |
| 1946 | bool ExplicitInstantiation); |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 1947 | |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 1948 | virtual DeclResult |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1949 | ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK, |
| 1950 | SourceLocation KWLoc, |
| 1951 | const CXXScopeSpec &SS, |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1952 | TemplateTy Template, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1953 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1954 | SourceLocation LAngleLoc, |
Douglas Gregor | 5908e9f | 2009-02-09 19:34:22 +0000 | [diff] [blame] | 1955 | ASTTemplateArgsPtr TemplateArgs, |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 1956 | SourceLocation *TemplateArgLocs, |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1957 | SourceLocation RAngleLoc, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1958 | AttributeList *Attr, |
| 1959 | MultiTemplateParamsArg TemplateParameterLists); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1960 | |
Douglas Gregor | 93dfdb1 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 1961 | virtual DeclResult |
| 1962 | ActOnExplicitInstantiation(Scope *S, SourceLocation TemplateLoc, |
| 1963 | unsigned TagSpec, |
| 1964 | SourceLocation KWLoc, |
| 1965 | const CXXScopeSpec &SS, |
| 1966 | TemplateTy Template, |
| 1967 | SourceLocation TemplateNameLoc, |
| 1968 | SourceLocation LAngleLoc, |
| 1969 | ASTTemplateArgsPtr TemplateArgs, |
| 1970 | SourceLocation *TemplateArgLocs, |
| 1971 | SourceLocation RAngleLoc, |
| 1972 | AttributeList *Attr); |
| 1973 | |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1974 | virtual DeclResult |
| 1975 | ActOnExplicitInstantiation(Scope *S, SourceLocation TemplateLoc, |
| 1976 | unsigned TagSpec, |
| 1977 | SourceLocation KWLoc, |
| 1978 | const CXXScopeSpec &SS, |
| 1979 | IdentifierInfo *Name, |
| 1980 | SourceLocation NameLoc, |
| 1981 | AttributeList *Attr); |
| 1982 | |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 1983 | bool CheckTemplateArgumentList(TemplateDecl *Template, |
| 1984 | SourceLocation TemplateLoc, |
| 1985 | SourceLocation LAngleLoc, |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1986 | const TemplateArgument *TemplateArgs, |
| 1987 | unsigned NumTemplateArgs, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 1988 | SourceLocation RAngleLoc, |
Anders Carlsson | 1c5976e | 2009-06-05 03:43:12 +0000 | [diff] [blame] | 1989 | TemplateArgumentListBuilder &Converted); |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 1990 | |
| 1991 | bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg, |
| 1992 | SourceLocation ArgLoc); |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 1993 | bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, |
| 1994 | NamedDecl *&Entity); |
| 1995 | bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1996 | bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param, |
| 1997 | QualType InstantiatedParamType, Expr *&Arg, |
Anders Carlsson | 1c5976e | 2009-06-05 03:43:12 +0000 | [diff] [blame] | 1998 | TemplateArgumentListBuilder *Converted = 0); |
Douglas Gregor | c15cb38 | 2009-02-09 23:23:08 +0000 | [diff] [blame] | 1999 | bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 2000 | bool TemplateParameterListsAreEqual(TemplateParameterList *New, |
| 2001 | TemplateParameterList *Old, |
| 2002 | bool Complain, |
Douglas Gregor | dd0574e | 2009-02-10 00:24:35 +0000 | [diff] [blame] | 2003 | bool IsTemplateTemplateParm = false, |
| 2004 | SourceLocation TemplateArgLoc |
| 2005 | = SourceLocation()); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 2006 | |
| 2007 | bool CheckTemplateDeclScope(Scope *S, |
| 2008 | MultiTemplateParamsArg &TemplateParameterLists); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 2009 | |
Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 2010 | /// \brief Called when the parser has parsed a C++ typename |
| 2011 | /// specifier, e.g., "typename T::type". |
| 2012 | /// |
| 2013 | /// \param TypenameLoc the location of the 'typename' keyword |
| 2014 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
| 2015 | /// \param II the identifier we're retrieving (e.g., 'type' in the example). |
| 2016 | /// \param IdLoc the location of the identifier. |
| 2017 | virtual TypeResult |
| 2018 | ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS, |
| 2019 | const IdentifierInfo &II, SourceLocation IdLoc); |
Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 2020 | |
| 2021 | /// \brief Called when the parser has parsed a C++ typename |
| 2022 | /// specifier that ends in a template-id, e.g., |
| 2023 | /// "typename MetaFun::template apply<T1, T2>". |
| 2024 | /// |
| 2025 | /// \param TypenameLoc the location of the 'typename' keyword |
| 2026 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
| 2027 | /// \param TemplateLoc the location of the 'template' keyword, if any. |
| 2028 | /// \param Ty the type that the typename specifier refers to. |
| 2029 | virtual TypeResult |
| 2030 | ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS, |
| 2031 | SourceLocation TemplateLoc, TypeTy *Ty); |
| 2032 | |
Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 2033 | QualType CheckTypenameType(NestedNameSpecifier *NNS, |
| 2034 | const IdentifierInfo &II, |
| 2035 | SourceRange Range); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 2036 | |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 2037 | TemplateArgumentList * |
| 2038 | DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, |
| 2039 | const TemplateArgumentList &TemplateArgs); |
Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 2040 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 2041 | //===--------------------------------------------------------------------===// |
| 2042 | // C++ Template Instantiation |
| 2043 | // |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2044 | |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 2045 | const TemplateArgumentList &getTemplateInstantiationArgs(NamedDecl *D); |
| 2046 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2047 | /// \brief A template instantiation that is currently in progress. |
| 2048 | struct ActiveTemplateInstantiation { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2049 | /// \brief The kind of template instantiation we are performing |
| 2050 | enum { |
| 2051 | /// We are instantiating a template declaration. The entity is |
Douglas Gregor | b9f1b8d | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 2052 | /// the declaration we're instantiating (e.g., a CXXRecordDecl). |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2053 | TemplateInstantiation, |
| 2054 | |
| 2055 | /// We are instantiating a default argument for a template |
| 2056 | /// parameter. The Entity is the template, and |
| 2057 | /// TemplateArgs/NumTemplateArguments provides the template |
| 2058 | /// arguments as specified. |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame^] | 2059 | /// FIXME: Use a TemplateArgumentList |
| 2060 | DefaultTemplateArgumentInstantiation, |
| 2061 | |
| 2062 | /// We are performing template argument deduction for a class |
| 2063 | /// template partial specialization. The Entity is the class |
| 2064 | /// template partial specialization, and |
| 2065 | /// TemplateArgs/NumTemplateArgs provides the deduced template |
| 2066 | /// arguments. |
| 2067 | /// FIXME: Use a TemplateArgumentList |
| 2068 | PartialSpecDeductionInstantiation |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2069 | } Kind; |
| 2070 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2071 | /// \brief The point of instantiation within the source code. |
| 2072 | SourceLocation PointOfInstantiation; |
| 2073 | |
| 2074 | /// \brief The entity that is being instantiated. |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2075 | uintptr_t Entity; |
| 2076 | |
| 2077 | // \brief If this the instantiation of a default template |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 2078 | // argument, the list of template arguments. |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2079 | const TemplateArgument *TemplateArgs; |
| 2080 | |
| 2081 | /// \brief The number of template arguments in TemplateArgs. |
| 2082 | unsigned NumTemplateArgs; |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2083 | |
| 2084 | /// \brief The source range that covers the construct that cause |
| 2085 | /// the instantiation, e.g., the template-id that causes a class |
| 2086 | /// template instantiation. |
| 2087 | SourceRange InstantiationRange; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2088 | |
| 2089 | friend bool operator==(const ActiveTemplateInstantiation &X, |
| 2090 | const ActiveTemplateInstantiation &Y) { |
| 2091 | if (X.Kind != Y.Kind) |
| 2092 | return false; |
| 2093 | |
| 2094 | if (X.Entity != Y.Entity) |
| 2095 | return false; |
| 2096 | |
| 2097 | switch (X.Kind) { |
| 2098 | case TemplateInstantiation: |
| 2099 | return true; |
| 2100 | |
| 2101 | case DefaultTemplateArgumentInstantiation: |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame^] | 2102 | case PartialSpecDeductionInstantiation: |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2103 | return X.TemplateArgs == Y.TemplateArgs; |
| 2104 | } |
| 2105 | |
| 2106 | return true; |
| 2107 | } |
| 2108 | |
| 2109 | friend bool operator!=(const ActiveTemplateInstantiation &X, |
| 2110 | const ActiveTemplateInstantiation &Y) { |
| 2111 | return !(X == Y); |
| 2112 | } |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2113 | }; |
| 2114 | |
| 2115 | /// \brief List of active template instantiations. |
| 2116 | /// |
| 2117 | /// This vector is treated as a stack. As one template instantiation |
| 2118 | /// requires another template instantiation, additional |
| 2119 | /// instantiations are pushed onto the stack up to a |
| 2120 | /// user-configurable limit LangOptions::InstantiationDepth. |
| 2121 | llvm::SmallVector<ActiveTemplateInstantiation, 16> |
| 2122 | ActiveTemplateInstantiations; |
| 2123 | |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 2124 | /// \brief The last template from which a template instantiation |
| 2125 | /// error or warning was produced. |
| 2126 | /// |
| 2127 | /// This value is used to suppress printing of redundant template |
| 2128 | /// instantiation backtraces when there are multiple errors in the |
| 2129 | /// same instantiation. FIXME: Does this belong in Sema? It's tough |
| 2130 | /// to implement it anywhere else. |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2131 | ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 2132 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2133 | /// \brief A stack object to be created when performing template |
| 2134 | /// instantiation. |
| 2135 | /// |
| 2136 | /// Construction of an object of type \c InstantiatingTemplate |
| 2137 | /// pushes the current instantiation onto the stack of active |
| 2138 | /// instantiations. If the size of this stack exceeds the maximum |
| 2139 | /// number of recursive template instantiations, construction |
| 2140 | /// produces an error and evaluates true. |
| 2141 | /// |
| 2142 | /// Destruction of this object will pop the named instantiation off |
| 2143 | /// the stack. |
| 2144 | struct InstantiatingTemplate { |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 2145 | /// \brief Note that we are instantiating a class template, |
| 2146 | /// function template, or a member thereof. |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2147 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 2148 | Decl *Entity, |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2149 | SourceRange InstantiationRange = SourceRange()); |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2150 | |
| 2151 | /// \brief Note that we are instantiating a default argument in a |
| 2152 | /// template-id. |
| 2153 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 2154 | TemplateDecl *Template, |
| 2155 | const TemplateArgument *TemplateArgs, |
| 2156 | unsigned NumTemplateArgs, |
| 2157 | SourceRange InstantiationRange = SourceRange()); |
| 2158 | |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame^] | 2159 | /// \brief Note that we are instantiating as part of template |
| 2160 | /// argument deduction for a class template partial |
| 2161 | /// specialization. |
| 2162 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 2163 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
| 2164 | const TemplateArgument *TemplateArgs, |
| 2165 | unsigned NumTemplateArgs, |
| 2166 | SourceRange InstantiationRange = SourceRange()); |
| 2167 | |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 2168 | /// \brief Note that we have finished instantiating this template. |
| 2169 | void Clear(); |
| 2170 | |
| 2171 | ~InstantiatingTemplate() { Clear(); } |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2172 | |
| 2173 | /// \brief Determines whether we have exceeded the maximum |
| 2174 | /// recursive template instantiations. |
| 2175 | operator bool() const { return Invalid; } |
| 2176 | |
| 2177 | private: |
| 2178 | Sema &SemaRef; |
| 2179 | bool Invalid; |
| 2180 | |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 2181 | bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, |
| 2182 | SourceRange InstantiationRange); |
| 2183 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 2184 | InstantiatingTemplate(const InstantiatingTemplate&); // not implemented |
| 2185 | |
| 2186 | InstantiatingTemplate& |
| 2187 | operator=(const InstantiatingTemplate&); // not implemented |
| 2188 | }; |
| 2189 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 2190 | void PrintInstantiationStack(); |
| 2191 | |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 2192 | /// \brief A stack-allocated class that identifies which local |
| 2193 | /// variable declaration instantiations are present in this scope. |
| 2194 | /// |
| 2195 | /// A new instance of this class type will be created whenever we |
| 2196 | /// instantiate a new function declaration, which will have its own |
| 2197 | /// set of parameter declarations. |
| 2198 | class LocalInstantiationScope { |
| 2199 | /// \brief Reference to the semantic analysis that is performing |
| 2200 | /// this template instantiation. |
| 2201 | Sema &SemaRef; |
| 2202 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 2203 | /// \brief A mapping from local declarations that occur |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 2204 | /// within a template to their instantiations. |
| 2205 | /// |
| 2206 | /// This mapping is used during instantiation to keep track of, |
| 2207 | /// e.g., function parameter and variable declarations. For example, |
| 2208 | /// given: |
| 2209 | /// |
| 2210 | /// \code |
| 2211 | /// template<typename T> T add(T x, T y) { return x + y; } |
| 2212 | /// \endcode |
| 2213 | /// |
| 2214 | /// when we instantiate add<int>, we will introduce a mapping from |
| 2215 | /// the ParmVarDecl for 'x' that occurs in the template to the |
| 2216 | /// instantiated ParmVarDecl for 'x'. |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 2217 | llvm::DenseMap<const Decl *, Decl *> LocalDecls; |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 2218 | |
| 2219 | /// \brief The outer scope, in which contains local variable |
| 2220 | /// definitions from some other instantiation (that is not |
| 2221 | /// relevant to this particular scope). |
| 2222 | LocalInstantiationScope *Outer; |
| 2223 | |
| 2224 | // This class is non-copyable |
| 2225 | LocalInstantiationScope(const LocalInstantiationScope &); |
| 2226 | LocalInstantiationScope &operator=(const LocalInstantiationScope &); |
| 2227 | |
| 2228 | public: |
| 2229 | LocalInstantiationScope(Sema &SemaRef) |
| 2230 | : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope) { |
| 2231 | SemaRef.CurrentInstantiationScope = this; |
| 2232 | } |
| 2233 | |
| 2234 | ~LocalInstantiationScope() { |
| 2235 | SemaRef.CurrentInstantiationScope = Outer; |
| 2236 | } |
| 2237 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 2238 | Decl *getInstantiationOf(const Decl *D) { |
| 2239 | Decl *Result = LocalDecls[D]; |
| 2240 | assert(Result && "declaration was not instantiated in this scope!"); |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 2241 | return Result; |
| 2242 | } |
| 2243 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 2244 | VarDecl *getInstantiationOf(const VarDecl *Var) { |
| 2245 | return cast<VarDecl>(getInstantiationOf(cast<Decl>(Var))); |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 2248 | ParmVarDecl *getInstantiationOf(const ParmVarDecl *Var) { |
| 2249 | return cast<ParmVarDecl>(getInstantiationOf(cast<Decl>(Var))); |
| 2250 | } |
| 2251 | |
| 2252 | void InstantiatedLocal(const Decl *D, Decl *Inst) { |
| 2253 | Decl *&Stored = LocalDecls[D]; |
| 2254 | assert(!Stored && "Already instantiated this local"); |
| 2255 | Stored = Inst; |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 2256 | } |
| 2257 | }; |
| 2258 | |
| 2259 | /// \brief The current instantiation scope used to store local |
| 2260 | /// variables. |
| 2261 | LocalInstantiationScope *CurrentInstantiationScope; |
| 2262 | |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 2263 | QualType InstantiateType(QualType T, const TemplateArgumentList &TemplateArgs, |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 2264 | SourceLocation Loc, DeclarationName Entity); |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 2265 | |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 2266 | OwningExprResult InstantiateExpr(Expr *E, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 2267 | const TemplateArgumentList &TemplateArgs); |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 2268 | |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 2269 | OwningStmtResult InstantiateStmt(Stmt *S, |
| 2270 | const TemplateArgumentList &TemplateArgs); |
Douglas Gregor | 66b46be | 2009-05-20 22:57:03 +0000 | [diff] [blame] | 2271 | OwningStmtResult InstantiateCompoundStmt(CompoundStmt *S, |
| 2272 | const TemplateArgumentList &TemplateArgs, |
| 2273 | bool isStmtExpr); |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 2274 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 2275 | Decl *InstantiateDecl(Decl *D, DeclContext *Owner, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 2276 | const TemplateArgumentList &TemplateArgs); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 2277 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 2278 | bool |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2279 | InstantiateBaseSpecifiers(CXXRecordDecl *Instantiation, |
| 2280 | CXXRecordDecl *Pattern, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 2281 | const TemplateArgumentList &TemplateArgs); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2282 | |
| 2283 | bool |
| 2284 | InstantiateClass(SourceLocation PointOfInstantiation, |
| 2285 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
Douglas Gregor | 93dfdb1 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 2286 | const TemplateArgumentList &TemplateArgs, |
| 2287 | bool ExplicitInstantiation); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 2288 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 2289 | bool |
| 2290 | InstantiateClassTemplateSpecialization( |
| 2291 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 2292 | bool ExplicitInstantiation); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 2293 | |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 2294 | void InstantiateClassMembers(SourceLocation PointOfInstantiation, |
| 2295 | CXXRecordDecl *Instantiation, |
| 2296 | const TemplateArgumentList &TemplateArgs); |
| 2297 | |
| 2298 | void InstantiateClassTemplateSpecializationMembers( |
| 2299 | SourceLocation PointOfInstantiation, |
| 2300 | ClassTemplateSpecializationDecl *ClassTemplateSpec); |
| 2301 | |
Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 2302 | NestedNameSpecifier * |
| 2303 | InstantiateNestedNameSpecifier(NestedNameSpecifier *NNS, |
| 2304 | SourceRange Range, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 2305 | const TemplateArgumentList &TemplateArgs); |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 2306 | |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 2307 | TemplateName |
| 2308 | InstantiateTemplateName(TemplateName Name, SourceLocation Loc, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 2309 | const TemplateArgumentList &TemplateArgs); |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 2310 | |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 2311 | void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
| 2312 | FunctionDecl *Function); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 2313 | void InstantiateVariableDefinition(VarDecl *Var); |
| 2314 | |
Douglas Gregor | ed961e7 | 2009-05-27 17:54:46 +0000 | [diff] [blame] | 2315 | NamedDecl *InstantiateCurrentDeclRef(NamedDecl *D); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 2316 | |
Anders Carlsson | a135fb4 | 2009-03-15 18:34:13 +0000 | [diff] [blame] | 2317 | // Simple function for cloning expressions. |
| 2318 | template<typename T> |
| 2319 | OwningExprResult Clone(T *E) { |
| 2320 | assert(!E->isValueDependent() && !E->isTypeDependent() && |
| 2321 | "expression is value or type dependent!"); |
| 2322 | return Owned(E->Clone(Context)); |
| 2323 | } |
| 2324 | |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 2325 | // Objective-C declarations. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2326 | virtual DeclPtrTy ActOnStartClassInterface(SourceLocation AtInterfaceLoc, |
| 2327 | IdentifierInfo *ClassName, |
| 2328 | SourceLocation ClassLoc, |
| 2329 | IdentifierInfo *SuperName, |
| 2330 | SourceLocation SuperLoc, |
| 2331 | const DeclPtrTy *ProtoRefs, |
| 2332 | unsigned NumProtoRefs, |
| 2333 | SourceLocation EndProtoLoc, |
| 2334 | AttributeList *AttrList); |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 2335 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2336 | virtual DeclPtrTy ActOnCompatiblityAlias( |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 2337 | SourceLocation AtCompatibilityAliasLoc, |
| 2338 | IdentifierInfo *AliasName, SourceLocation AliasLocation, |
| 2339 | IdentifierInfo *ClassName, SourceLocation ClassLocation); |
Steve Naroff | 61d6852 | 2009-03-05 15:22:01 +0000 | [diff] [blame] | 2340 | |
| 2341 | void CheckForwardProtocolDeclarationForCircularDependency( |
| 2342 | IdentifierInfo *PName, |
| 2343 | SourceLocation &PLoc, SourceLocation PrevLoc, |
| 2344 | const ObjCList<ObjCProtocolDecl> &PList); |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 2345 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2346 | virtual DeclPtrTy ActOnStartProtocolInterface( |
Nate Begeman | 1abc7f6 | 2008-02-20 22:57:40 +0000 | [diff] [blame] | 2347 | SourceLocation AtProtoInterfaceLoc, |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 2348 | IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2349 | const DeclPtrTy *ProtoRefNames, unsigned NumProtoRefs, |
Daniel Dunbar | 246e70f | 2008-09-26 04:48:09 +0000 | [diff] [blame] | 2350 | SourceLocation EndProtoLoc, |
| 2351 | AttributeList *AttrList); |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 2352 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2353 | virtual DeclPtrTy ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, |
| 2354 | IdentifierInfo *ClassName, |
| 2355 | SourceLocation ClassLoc, |
| 2356 | IdentifierInfo *CategoryName, |
| 2357 | SourceLocation CategoryLoc, |
| 2358 | const DeclPtrTy *ProtoRefs, |
| 2359 | unsigned NumProtoRefs, |
| 2360 | SourceLocation EndProtoLoc); |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 2361 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2362 | virtual DeclPtrTy ActOnStartClassImplementation( |
Nate Begeman | 1abc7f6 | 2008-02-20 22:57:40 +0000 | [diff] [blame] | 2363 | SourceLocation AtClassImplLoc, |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 2364 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 2365 | IdentifierInfo *SuperClassname, |
| 2366 | SourceLocation SuperClassLoc); |
| 2367 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2368 | virtual DeclPtrTy ActOnStartCategoryImplementation( |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 2369 | SourceLocation AtCatImplLoc, |
| 2370 | IdentifierInfo *ClassName, |
| 2371 | SourceLocation ClassLoc, |
| 2372 | IdentifierInfo *CatName, |
| 2373 | SourceLocation CatLoc); |
| 2374 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2375 | virtual DeclPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, |
Steve Naroff | 37e58d1 | 2007-10-02 22:39:18 +0000 | [diff] [blame] | 2376 | IdentifierInfo **IdentList, |
| 2377 | unsigned NumElts); |
Fariborz Jahanian | 894c57f | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 2378 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2379 | virtual DeclPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 2380 | const IdentifierLocPair *IdentList, |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 2381 | unsigned NumElts, |
| 2382 | AttributeList *attrList); |
Fariborz Jahanian | 245f92a | 2007-10-05 21:01:53 +0000 | [diff] [blame] | 2383 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 2384 | virtual void FindProtocolDeclaration(bool WarnOnDeclarations, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 2385 | const IdentifierLocPair *ProtocolId, |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 2386 | unsigned NumProtocols, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2387 | llvm::SmallVectorImpl<DeclPtrTy> &Protocols); |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 2388 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2389 | /// Ensure attributes are consistent with type. |
| 2390 | /// \param [in, out] Attributes The attributes to check; they will |
| 2391 | /// be modified to be consistent with \arg PropertyTy. |
| 2392 | void CheckObjCPropertyAttributes(QualType PropertyTy, |
| 2393 | SourceLocation Loc, |
| 2394 | unsigned &Attributes); |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 2395 | void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC); |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 2396 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
| 2397 | ObjCPropertyDecl *SuperProperty, |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 2398 | const IdentifierInfo *Name); |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 2399 | void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 2400 | |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 2401 | void MergeProtocolPropertiesIntoClass(Decl *CDecl, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2402 | DeclPtrTy MergeProtocols); |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 2403 | |
Fariborz Jahanian | b7f95f5 | 2009-03-02 19:05:07 +0000 | [diff] [blame] | 2404 | void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
| 2405 | ObjCInterfaceDecl *ID); |
| 2406 | |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 2407 | void MergeOneProtocolPropertiesIntoClass(Decl *CDecl, |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 2408 | ObjCProtocolDecl *PDecl); |
| 2409 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2410 | virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, |
| 2411 | DeclPtrTy *allMethods = 0, unsigned allNum = 0, |
| 2412 | DeclPtrTy *allProperties = 0, unsigned pNum = 0, |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2413 | DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); |
Fariborz Jahanian | d0b90bf | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 2414 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2415 | virtual DeclPtrTy ActOnProperty(Scope *S, SourceLocation AtLoc, |
| 2416 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
| 2417 | Selector GetterSel, Selector SetterSel, |
| 2418 | DeclPtrTy ClassCategory, |
| 2419 | bool *OverridingProperty, |
| 2420 | tok::ObjCKeywordKind MethodImplKind); |
Fariborz Jahanian | 46b55e5 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 2421 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2422 | virtual DeclPtrTy ActOnPropertyImplDecl(SourceLocation AtLoc, |
| 2423 | SourceLocation PropertyLoc, |
| 2424 | bool ImplKind,DeclPtrTy ClassImplDecl, |
| 2425 | IdentifierInfo *PropertyId, |
| 2426 | IdentifierInfo *PropertyIvar); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2427 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2428 | virtual DeclPtrTy ActOnMethodDeclaration( |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 2429 | SourceLocation BeginLoc, // location of the + or -. |
| 2430 | SourceLocation EndLoc, // location of the ; or {. |
Fariborz Jahanian | 1f7b6f8 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 2431 | tok::TokenKind MethodType, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2432 | DeclPtrTy ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, |
Fariborz Jahanian | f1de0ca | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 2433 | Selector Sel, |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2434 | // optional arguments. The number of types/arguments is obtained |
| 2435 | // from the Sel.getNumArgs(). |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 2436 | ObjCArgInfo *ArgInfo, |
Fariborz Jahanian | 439c658 | 2009-01-09 00:38:19 +0000 | [diff] [blame] | 2437 | llvm::SmallVectorImpl<Declarator> &Cdecls, |
Steve Naroff | 335eafa | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 2438 | AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, |
| 2439 | bool isVariadic = false); |
Steve Naroff | 81bfde9 | 2007-10-16 23:12:48 +0000 | [diff] [blame] | 2440 | |
Steve Naroff | f1afaf6 | 2009-02-26 15:55:06 +0000 | [diff] [blame] | 2441 | // Helper method for ActOnClassMethod/ActOnInstanceMethod. |
| 2442 | // Will search "local" class/category implementations for a method decl. |
Fariborz Jahanian | 175ba1e | 2009-03-04 18:15:57 +0000 | [diff] [blame] | 2443 | // Will also search in class's root looking for instance method. |
Steve Naroff | f1afaf6 | 2009-02-26 15:55:06 +0000 | [diff] [blame] | 2444 | // Returns 0 if no method is found. |
Steve Naroff | 5609ec0 | 2009-03-08 18:56:13 +0000 | [diff] [blame] | 2445 | ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, |
| 2446 | ObjCInterfaceDecl *CDecl); |
| 2447 | ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, |
| 2448 | ObjCInterfaceDecl *ClassDecl); |
Steve Naroff | f1afaf6 | 2009-02-26 15:55:06 +0000 | [diff] [blame] | 2449 | |
Steve Naroff | 61f72cb | 2009-03-09 21:12:44 +0000 | [diff] [blame] | 2450 | virtual OwningExprResult ActOnClassPropertyRefExpr( |
| 2451 | IdentifierInfo &receiverName, |
| 2452 | IdentifierInfo &propertyName, |
| 2453 | SourceLocation &receiverNameLoc, |
| 2454 | SourceLocation &propertyNameLoc); |
| 2455 | |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2456 | // ActOnClassMessage - used for both unary and keyword messages. |
| 2457 | // ArgExprs is optional - if it is present, the number of expressions |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2458 | // is obtained from NumArgs. |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2459 | virtual ExprResult ActOnClassMessage( |
Fariborz Jahanian | 0523aaf | 2007-11-12 20:13:27 +0000 | [diff] [blame] | 2460 | Scope *S, |
Anders Carlsson | ff975cf | 2009-02-14 18:21:46 +0000 | [diff] [blame] | 2461 | IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac, |
| 2462 | SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac, |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2463 | ExprTy **ArgExprs, unsigned NumArgs); |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2464 | |
| 2465 | // ActOnInstanceMessage - used for both unary and keyword messages. |
| 2466 | // ArgExprs is optional - if it is present, the number of expressions |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2467 | // is obtained from NumArgs. |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2468 | virtual ExprResult ActOnInstanceMessage( |
Steve Naroff | bcfb06a | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 2469 | ExprTy *receiver, Selector Sel, |
Anders Carlsson | ff975cf | 2009-02-14 18:21:46 +0000 | [diff] [blame] | 2470 | SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac, |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2471 | ExprTy **ArgExprs, unsigned NumArgs); |
Daniel Dunbar | 4cde927 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 2472 | |
| 2473 | /// ActOnPragmaPack - Called on well formed #pragma pack(...). |
| 2474 | virtual void ActOnPragmaPack(PragmaPackKind Kind, |
| 2475 | IdentifierInfo *Name, |
| 2476 | ExprTy *Alignment, |
| 2477 | SourceLocation PragmaLoc, |
| 2478 | SourceLocation LParenLoc, |
| 2479 | SourceLocation RParenLoc); |
Chris Lattner | 574aa40 | 2009-02-17 01:09:29 +0000 | [diff] [blame] | 2480 | |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 2481 | /// ActOnPragmaUnused - Called on well-formed '#pragma unused'. |
| 2482 | virtual void ActOnPragmaUnused(ExprTy **Exprs, unsigned NumExprs, |
| 2483 | SourceLocation PragmaLoc, |
| 2484 | SourceLocation LParenLoc, |
| 2485 | SourceLocation RParenLoc); |
Eli Friedman | c49f19b | 2009-06-05 02:44:36 +0000 | [diff] [blame] | 2486 | |
Eli Friedman | dec7c76 | 2009-06-05 06:28:29 +0000 | [diff] [blame] | 2487 | /// ActOnPragmaWeakID - Called on well formed #pragma weak ident. |
Eli Friedman | c49f19b | 2009-06-05 02:44:36 +0000 | [diff] [blame] | 2488 | virtual void ActOnPragmaWeakID(IdentifierInfo* WeakName, |
| 2489 | SourceLocation PragmaLoc, |
| 2490 | SourceLocation WeakNameLoc); |
| 2491 | |
Eli Friedman | dec7c76 | 2009-06-05 06:28:29 +0000 | [diff] [blame] | 2492 | /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident. |
Eli Friedman | c49f19b | 2009-06-05 02:44:36 +0000 | [diff] [blame] | 2493 | virtual void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, |
| 2494 | IdentifierInfo* AliasName, |
| 2495 | SourceLocation PragmaLoc, |
| 2496 | SourceLocation WeakNameLoc, |
| 2497 | SourceLocation AliasNameLoc); |
| 2498 | |
Chris Lattner | 574aa40 | 2009-02-17 01:09:29 +0000 | [diff] [blame] | 2499 | /// getPragmaPackAlignment() - Return the current alignment as specified by |
| 2500 | /// the current #pragma pack directive, or 0 if none is currently active. |
| 2501 | unsigned getPragmaPackAlignment() const; |
| 2502 | |
| 2503 | /// FreePackedContext - Deallocate and null out PackContext. |
| 2504 | void FreePackedContext(); |
Daniel Dunbar | 4cde927 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 2505 | |
Chris Lattner | 1e0a390 | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 2506 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
| 2507 | /// 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] | 2508 | /// If isLvalue, the result of the cast is an lvalue. |
| 2509 | void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false); |
Chris Lattner | 1e0a390 | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 2510 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2511 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 2512 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
| 2513 | Expr *UsualUnaryConversions(Expr *&expr); |
Eli Friedman | 3c0eb16 | 2008-05-27 03:33:27 +0000 | [diff] [blame] | 2514 | |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 2515 | // DefaultFunctionArrayConversion - converts functions and arrays |
| 2516 | // to their respective pointers (C99 6.3.2.1). |
| 2517 | void DefaultFunctionArrayConversion(Expr *&expr); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 2518 | |
Steve Naroff | b291ab6 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 2519 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
| 2520 | // do not have a prototype. Integer promotions are performed on each |
| 2521 | // argument, and arguments that have type float are promoted to double. |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 2522 | void DefaultArgumentPromotion(Expr *&Expr); |
Anders Carlsson | dce5e2c | 2009-01-16 16:48:51 +0000 | [diff] [blame] | 2523 | |
| 2524 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
| 2525 | enum VariadicCallType { |
| 2526 | VariadicFunction, |
| 2527 | VariadicBlock, |
| 2528 | VariadicMethod |
| 2529 | }; |
| 2530 | |
| 2531 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
| 2532 | // will warn if the resulting type is not a POD type. |
Chris Lattner | 312531a | 2009-04-12 08:11:20 +0000 | [diff] [blame] | 2533 | bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT); |
Steve Naroff | b291ab6 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 2534 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2535 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
| 2536 | // operands and then handles various conversions that are common to binary |
| 2537 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
| 2538 | // routine returns the first non-arithmetic type found. The client is |
| 2539 | // responsible for emitting appropriate error diagnostics. |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 2540 | QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr, |
| 2541 | bool isCompAssign = false); |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 2542 | |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 2543 | /// UsualArithmeticConversionsType - handles the various conversions |
| 2544 | /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9) |
| 2545 | /// and returns the result type of that conversion. |
| 2546 | QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs); |
| 2547 | |
| 2548 | |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 2549 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
| 2550 | /// enum to indicate whether the assignment was allowed. These checks are |
| 2551 | /// done for simple assignments, as well as initialization, return from |
| 2552 | /// function, argument passing, etc. The query is phrased in terms of a |
| 2553 | /// source and destination type. |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 2554 | enum AssignConvertType { |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 2555 | /// Compatible - the types are compatible according to the standard. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2556 | Compatible, |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 2557 | |
| 2558 | /// PointerToInt - The assignment converts a pointer to an int, which we |
| 2559 | /// accept as an extension. |
| 2560 | PointerToInt, |
| 2561 | |
| 2562 | /// IntToPointer - The assignment converts an int to a pointer, which we |
| 2563 | /// accept as an extension. |
| 2564 | IntToPointer, |
| 2565 | |
| 2566 | /// FunctionVoidPointer - The assignment is between a function pointer and |
| 2567 | /// 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] | 2568 | FunctionVoidPointer, |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 2569 | |
| 2570 | /// IncompatiblePointer - The assignment is between two pointers types that |
| 2571 | /// are not compatible, but we accept them as an extension. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2572 | IncompatiblePointer, |
Eli Friedman | f05c05d | 2009-03-22 23:59:44 +0000 | [diff] [blame] | 2573 | |
| 2574 | /// IncompatiblePointer - The assignment is between two pointers types which |
| 2575 | /// point to integers which have a different sign, but are otherwise identical. |
| 2576 | /// This is a subset of the above, but broken out because it's by far the most |
| 2577 | /// common case of incompatible pointers. |
| 2578 | IncompatiblePointerSign, |
| 2579 | |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 2580 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
| 2581 | /// c/v/r qualifiers, which we accept as an extension. |
| 2582 | CompatiblePointerDiscardsQualifiers, |
Steve Naroff | 1c7d067 | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 2583 | |
Anders Carlsson | b0f90cc | 2009-01-30 23:17:46 +0000 | [diff] [blame] | 2584 | /// IncompatibleVectors - The assignment is between two vector types that |
| 2585 | /// have the same size, which we accept as an extension. |
| 2586 | IncompatibleVectors, |
| 2587 | |
Steve Naroff | bfdcae6 | 2008-09-04 15:31:07 +0000 | [diff] [blame] | 2588 | /// IntToBlockPointer - The assignment converts an int to a block |
Steve Naroff | 1c7d067 | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 2589 | /// pointer. We disallow this. |
| 2590 | IntToBlockPointer, |
| 2591 | |
Steve Naroff | bfdcae6 | 2008-09-04 15:31:07 +0000 | [diff] [blame] | 2592 | /// IncompatibleBlockPointer - The assignment is between two block |
Steve Naroff | 1c7d067 | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 2593 | /// pointers types that are not compatible. |
| 2594 | IncompatibleBlockPointer, |
| 2595 | |
Steve Naroff | 3957907 | 2008-10-14 22:18:38 +0000 | [diff] [blame] | 2596 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
| 2597 | /// id type and something else (that is incompatible with it). For example, |
| 2598 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
| 2599 | IncompatibleObjCQualifiedId, |
| 2600 | |
Chris Lattner | b7b6115 | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 2601 | /// Incompatible - We reject this conversion outright, it is invalid to |
| 2602 | /// represent it in the AST. |
| 2603 | Incompatible |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2604 | }; |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 2605 | |
| 2606 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
| 2607 | /// assignment conversion type specified by ConvTy. This returns true if the |
| 2608 | /// conversion was invalid or false if the conversion was accepted. |
| 2609 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, |
| 2610 | SourceLocation Loc, |
| 2611 | QualType DstType, QualType SrcType, |
| 2612 | Expr *SrcExpr, const char *Flavor); |
| 2613 | |
| 2614 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
| 2615 | /// argument passing, variable initialization, and function return values. |
| 2616 | /// This routine is only used by the following two methods. C99 6.5.16. |
| 2617 | AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 2618 | |
Douglas Gregor | 0c74e8a | 2009-04-29 22:16:16 +0000 | [diff] [blame] | 2619 | // CheckSingleAssignmentConstraints - Currently used by |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 2620 | // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 2621 | // this routine performs the default function/array converions. |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 2622 | AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, |
| 2623 | Expr *&rExpr); |
Douglas Gregor | 0c74e8a | 2009-04-29 22:16:16 +0000 | [diff] [blame] | 2624 | |
| 2625 | // \brief If the lhs type is a transparent union, check whether we |
| 2626 | // can initialize the transparent union with the given expression. |
| 2627 | AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs, |
| 2628 | Expr *&rExpr); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 2629 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2630 | // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1) |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 2631 | AssignConvertType CheckPointerTypesForAssignment(QualType lhsType, |
| 2632 | QualType rhsType); |
Steve Naroff | 1c7d067 | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 2633 | |
| 2634 | // Helper function for CheckAssignmentConstraints involving two |
Sebastian Redl | d1bd7fc | 2009-04-19 19:26:31 +0000 | [diff] [blame] | 2635 | // block pointer types. |
Steve Naroff | 1c7d067 | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 2636 | AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType, |
| 2637 | QualType rhsType); |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 2638 | |
| 2639 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 2640 | |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 2641 | bool PerformImplicitConversion(Expr *&From, QualType ToType, |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 2642 | const char *Flavor, |
| 2643 | bool AllowExplicit = false, |
| 2644 | bool Elidable = false); |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 2645 | bool PerformImplicitConversion(Expr *&From, QualType ToType, |
| 2646 | const ImplicitConversionSequence& ICS, |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 2647 | const char *Flavor); |
Douglas Gregor | 94b1dd2 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 2648 | bool PerformImplicitConversion(Expr *&From, QualType ToType, |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 2649 | const StandardConversionSequence& SCS, |
| 2650 | const char *Flavor); |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2651 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2652 | /// the following "Check" methods will return a valid/converted QualType |
| 2653 | /// or a null QualType (indicating an error diagnostic was issued). |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2654 | |
| 2655 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2656 | QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
Sebastian Redl | 7c8bd60 | 2009-02-07 20:10:22 +0000 | [diff] [blame] | 2657 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2658 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2659 | QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2660 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2661 | QualType CheckRemainderOperands( // C99 6.5.5 |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2662 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2663 | QualType CheckAdditionOperands( // C99 6.5.6 |
Eli Friedman | ab3a852 | 2009-03-28 01:22:36 +0000 | [diff] [blame] | 2664 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2665 | QualType CheckSubtractionOperands( // C99 6.5.6 |
Eli Friedman | ab3a852 | 2009-03-28 01:22:36 +0000 | [diff] [blame] | 2666 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2667 | QualType CheckShiftOperands( // C99 6.5.7 |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 2668 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2669 | QualType CheckCompareOperands( // C99 6.5.8/9 |
Douglas Gregor | a86b832 | 2009-04-06 18:45:53 +0000 | [diff] [blame] | 2670 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc, bool isRelational); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2671 | QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
Sebastian Redl | 2246050 | 2009-02-07 00:15:38 +0000 | [diff] [blame] | 2672 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2673 | QualType CheckLogicalOperands( // C99 6.5.[13,14] |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 2674 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2675 | // CheckAssignmentOperands is used for both simple and compound assignment. |
| 2676 | // For simple assignment, pass both expressions and a null converted type. |
| 2677 | // For compound assignment, pass both expressions and the converted type. |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2678 | QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
Steve Naroff | f1120de | 2007-08-24 22:33:52 +0000 | [diff] [blame] | 2679 | Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2680 | QualType CheckCommaOperands( // C99 6.5.17 |
Chris Lattner | 29a1cfb | 2008-11-18 01:30:42 +0000 | [diff] [blame] | 2681 | Expr *lex, Expr *&rex, SourceLocation OpLoc); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 2682 | QualType CheckConditionalOperands( // C99 6.5.15 |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 2683 | Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc); |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 2684 | QualType CXXCheckConditionalOperands( // C++ 5.16 |
| 2685 | Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc); |
Sebastian Redl | d1bd7fc | 2009-04-19 19:26:31 +0000 | [diff] [blame] | 2686 | QualType FindCompositePointerType(Expr *&E1, Expr *&E2); // C++ 5.9 |
Nate Begeman | be2341d | 2008-07-14 18:02:46 +0000 | [diff] [blame] | 2687 | |
| 2688 | /// type checking for vector binary operators. |
| 2689 | inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
| 2690 | inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx, |
| 2691 | SourceLocation l, bool isRel); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2692 | |
Steve Naroff | f69936d | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 2693 | /// type checking unary operators (subroutines of ActOnUnaryOp). |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2694 | /// 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] | 2695 | QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc, |
| 2696 | bool isInc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2697 | QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc); |
| 2698 | QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc); |
Chris Lattner | ba27e2a | 2009-02-17 08:12:06 +0000 | [diff] [blame] | 2699 | QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal); |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 2700 | |
| 2701 | /// type checking primary expressions. |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2702 | QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc, |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 2703 | IdentifierInfo &Comp, SourceLocation CmpLoc); |
| 2704 | |
Steve Naroff | f009063 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 2705 | /// type checking declaration initializers (C99 6.7.8) |
Anders Carlsson | 2078bb9 | 2009-05-27 16:10:08 +0000 | [diff] [blame] | 2706 | |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 2707 | bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 2708 | SourceLocation InitLoc,DeclarationName InitEntity, |
Anders Carlsson | 0f5f2c6 | 2009-05-30 20:41:30 +0000 | [diff] [blame] | 2709 | bool DirectInit); |
Douglas Gregor | c34ee5e | 2009-01-29 00:45:39 +0000 | [diff] [blame] | 2710 | bool CheckInitList(InitListExpr *&InitList, QualType &DeclType); |
Steve Naroff | d0091aa | 2008-01-10 22:15:12 +0000 | [diff] [blame] | 2711 | bool CheckForConstantInitializer(Expr *e, QualType t); |
Steve Naroff | 2fdc374 | 2007-12-10 22:44:33 +0000 | [diff] [blame] | 2712 | |
Douglas Gregor | 87fd703 | 2009-02-02 17:43:21 +0000 | [diff] [blame] | 2713 | bool CheckValueInitialization(QualType Type, SourceLocation Loc); |
Argyrios Kyrtzidis | 6c2dc4d | 2008-08-16 20:27:34 +0000 | [diff] [blame] | 2714 | |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2715 | // type checking C++ declaration initializers (C++ [dcl.init]). |
| 2716 | |
| 2717 | /// ReferenceCompareResult - Expresses the result of comparing two |
| 2718 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
| 2719 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
| 2720 | enum ReferenceCompareResult { |
| 2721 | /// Ref_Incompatible - The two types are incompatible, so direct |
| 2722 | /// reference binding is not possible. |
| 2723 | Ref_Incompatible = 0, |
| 2724 | /// Ref_Related - The two types are reference-related, which means |
| 2725 | /// that their unqualified forms (T1 and T2) are either the same |
| 2726 | /// or T1 is a base class of T2. |
| 2727 | Ref_Related, |
| 2728 | /// Ref_Compatible_With_Added_Qualification - The two types are |
| 2729 | /// reference-compatible with added qualification, meaning that |
| 2730 | /// they are reference-compatible and the qualifiers on T1 (cv1) |
| 2731 | /// are greater than the qualifiers on T2 (cv2). |
| 2732 | Ref_Compatible_With_Added_Qualification, |
| 2733 | /// Ref_Compatible - The two types are reference-compatible and |
| 2734 | /// have equivalent qualifiers (cv1 == cv2). |
| 2735 | Ref_Compatible |
| 2736 | }; |
| 2737 | |
Douglas Gregor | 15da57e | 2008-10-29 02:00:59 +0000 | [diff] [blame] | 2738 | ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2, |
| 2739 | bool& DerivedToBase); |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2740 | |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 2741 | bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType declType, |
Douglas Gregor | 225c41e | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 2742 | ImplicitConversionSequence *ICS = 0, |
Douglas Gregor | 09f41cf | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 2743 | bool SuppressUserConversions = false, |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 2744 | bool AllowExplicit = false, |
| 2745 | bool ForceRValue = false); |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 2746 | |
Argyrios Kyrtzidis | 6c2dc4d | 2008-08-16 20:27:34 +0000 | [diff] [blame] | 2747 | /// CheckCastTypes - Check type constraints for casting between types. |
Daniel Dunbar | 58d5ebb | 2008-08-20 03:55:42 +0000 | [diff] [blame] | 2748 | bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr); |
Steve Naroff | a49e1fa | 2008-01-22 00:55:40 +0000 | [diff] [blame] | 2749 | |
Anders Carlsson | 584b247 | 2007-11-27 07:16:40 +0000 | [diff] [blame] | 2750 | // CheckVectorCast - check type constraints for vectors. |
| 2751 | // Since vectors are an extension, there are no C standard reference for this. |
| 2752 | // We allow casting between vectors and integer datatypes of the same size. |
Anders Carlsson | a64db8f | 2007-11-27 05:51:55 +0000 | [diff] [blame] | 2753 | // returns true if the cast is invalid |
| 2754 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty); |
| 2755 | |
Daniel Dunbar | 637cebb | 2008-09-11 00:01:56 +0000 | [diff] [blame] | 2756 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
| 2757 | /// \param Method - May be null. |
| 2758 | /// \param [out] ReturnType - The return type of the send. |
| 2759 | /// \return true iff there were any incompatible types. |
Daniel Dunbar | 91e19b2 | 2008-09-11 00:50:25 +0000 | [diff] [blame] | 2760 | bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 2761 | ObjCMethodDecl *Method, bool isClassMessage, |
Daniel Dunbar | 637cebb | 2008-09-11 00:01:56 +0000 | [diff] [blame] | 2762 | SourceLocation lbrac, SourceLocation rbrac, |
| 2763 | QualType &ReturnType); |
Argyrios Kyrtzidis | 5921093 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 2764 | |
| 2765 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
| 2766 | bool CheckCXXBooleanCondition(Expr *&CondExpr); |
Steve Naroff | 81bfde9 | 2007-10-16 23:12:48 +0000 | [diff] [blame] | 2767 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 2768 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
| 2769 | /// the specified width and sign. If an overflow occurs, detect it and emit |
| 2770 | /// the specified diagnostic. |
| 2771 | void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, |
| 2772 | unsigned NewWidth, bool NewSign, |
| 2773 | SourceLocation Loc, unsigned DiagID); |
| 2774 | |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 2775 | bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, |
| 2776 | bool ForCompare); |
| 2777 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 2778 | /// Checks that the Objective-C declaration is declared in the global scope. |
| 2779 | /// Emits an error and marks the declaration as invalid if it's not declared |
| 2780 | /// in the global scope. |
| 2781 | bool CheckObjCDeclScope(Decl *D); |
| 2782 | |
Anders Carlsson | 7c50aca | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 2783 | void InitBuiltinVaListType(); |
Eli Friedman | 1b76ada | 2008-06-03 21:01:11 +0000 | [diff] [blame] | 2784 | |
Anders Carlsson | e21555e | 2008-11-30 19:50:32 +0000 | [diff] [blame] | 2785 | /// VerifyIntegerConstantExpression - verifies that an expression is an ICE, |
| 2786 | /// and reports the appropriate diagnostics. Returns false on success. |
| 2787 | /// Can optionally return the value of the expression. |
Anders Carlsson | 9f1e572 | 2008-12-06 20:33:04 +0000 | [diff] [blame] | 2788 | bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0); |
Anders Carlsson | 4000ea6 | 2008-12-01 02:17:22 +0000 | [diff] [blame] | 2789 | |
Anders Carlsson | 9f1e572 | 2008-12-06 20:33:04 +0000 | [diff] [blame] | 2790 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
| 2791 | /// the correct width, and that the field type is valid. |
| 2792 | /// Returns false on success. |
| 2793 | bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, |
| 2794 | QualType FieldTy, const Expr *BitWidth); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 2795 | |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 2796 | //===--------------------------------------------------------------------===// |
| 2797 | // Extra semantic analysis beyond the C type system |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 2798 | private: |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 2799 | Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl, |
| 2800 | CallExpr *TheCall); |
Fariborz Jahanian | 725165f | 2009-05-18 21:05:18 +0000 | [diff] [blame] | 2801 | |
| 2802 | Action::OwningExprResult CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall); |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 2803 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
| 2804 | unsigned ByteNo) const; |
Chris Lattner | 6903981 | 2009-02-18 06:01:06 +0000 | [diff] [blame] | 2805 | bool CheckObjCString(Expr *Arg); |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 2806 | bool SemaBuiltinVAStart(CallExpr *TheCall); |
| 2807 | bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); |
Eli Friedman | 6cfda23 | 2008-05-20 08:23:37 +0000 | [diff] [blame] | 2808 | bool SemaBuiltinStackAddress(CallExpr *TheCall); |
Douglas Gregor | cde0173 | 2009-05-19 22:10:17 +0000 | [diff] [blame] | 2809 | |
| 2810 | public: |
| 2811 | // Used by C++ template instantiation. |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 2812 | Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); |
Douglas Gregor | cde0173 | 2009-05-19 22:10:17 +0000 | [diff] [blame] | 2813 | |
| 2814 | private: |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 2815 | bool SemaBuiltinPrefetch(CallExpr *TheCall); |
Eli Friedman | d875fed | 2009-05-03 04:46:36 +0000 | [diff] [blame] | 2816 | bool SemaBuiltinObjectSize(CallExpr *TheCall); |
| 2817 | bool SemaBuiltinLongjmp(CallExpr *TheCall); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 2818 | bool SemaBuiltinAtomicOverloaded(CallExpr *TheCall); |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 2819 | bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, |
| 2820 | bool HasVAListArg, unsigned format_idx, |
| 2821 | unsigned firstDataArg); |
| 2822 | void CheckPrintfString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, |
| 2823 | const CallExpr *TheCall, bool HasVAListArg, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 2824 | unsigned format_idx, unsigned firstDataArg); |
Fariborz Jahanian | e898f8a | 2009-05-21 18:48:51 +0000 | [diff] [blame] | 2825 | void CheckNonNullArguments(const NonNullAttr *NonNull, |
| 2826 | const CallExpr *TheCall); |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 2827 | void CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 2828 | unsigned format_idx, unsigned firstDataArg); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 2829 | void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, |
| 2830 | SourceLocation ReturnLoc); |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 2831 | void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2832 | }; |
| 2833 | |
Mike Stump | b83d287 | 2009-02-19 22:01:56 +0000 | [diff] [blame] | 2834 | |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 2835 | //===--------------------------------------------------------------------===// |
| 2836 | // Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers). |
| 2837 | template <typename T> |
| 2838 | class ExprOwningPtr : public Action::ExprArg { |
| 2839 | public: |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 2840 | ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {} |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 2841 | |
| 2842 | void reset(T* p) { Action::ExprArg::operator=(p); } |
| 2843 | T* get() const { return static_cast<T*>(Action::ExprArg::get()); } |
| 2844 | T* take() { return static_cast<T*>(Action::ExprArg::take()); } |
| 2845 | T* release() { return take(); } |
| 2846 | |
| 2847 | T& operator*() const { return *get(); } |
| 2848 | T* operator->() const { return get(); } |
| 2849 | }; |
Douglas Gregor | d7e2705 | 2009-05-20 22:33:37 +0000 | [diff] [blame] | 2850 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2851 | } // end namespace clang |
| 2852 | |
| 2853 | #endif |