Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file 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 | 2a1e2ed | 2008-04-11 07:00:53 +0000 | [diff] [blame] | 18 | #include "IdentifierResolver.h" |
Argiris Kirtzidis | 38f1671 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 19 | #include "CXXFieldCollector.h" |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 20 | #include "SemaOverload.h" |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclBase.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 22 | #include "clang/Parse/Action.h" |
Chris Lattner | f9ea6a4 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 23 | #include "clang/Basic/Diagnostic.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/SmallVector.h" |
Fariborz Jahanian | 67907bd | 2007-10-05 18:00:57 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/DenseSet.h" |
Chris Lattner | a7a191c | 2007-10-07 01:13:46 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/SmallPtrSet.h" |
Argiris Kirtzidis | 38f1671 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/OwningPtr.h" |
Douglas Gregor | b9ef055 | 2009-01-16 00:38:09 +0000 | [diff] [blame] | 28 | #include <string> |
Douglas Gregor | bb46150 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 29 | #include <vector> |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 30 | |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 31 | namespace llvm { |
| 32 | class APSInt; |
| 33 | } |
| 34 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 35 | namespace clang { |
| 36 | class ASTContext; |
Chris Lattner | a8c2d59 | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 37 | class ASTConsumer; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 38 | class Preprocessor; |
| 39 | class Decl; |
Chris Lattner | f3874bc | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 40 | class DeclContext; |
Daniel Dunbar | 8d03cbe | 2008-08-11 03:27:53 +0000 | [diff] [blame] | 41 | class DeclSpec; |
Steve Naroff | e57c21a | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 42 | class NamedDecl; |
Steve Naroff | d21bc0d | 2007-09-13 18:10:37 +0000 | [diff] [blame] | 43 | class ScopedDecl; |
Sebastian Redl | 91f9b0a | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 44 | class Stmt; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 45 | class Expr; |
Steve Naroff | 9091f3f | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 46 | class InitListExpr; |
Chris Lattner | 83bd5eb | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 47 | class CallExpr; |
Douglas Gregor | 566782a | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 48 | class DeclRefExpr; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 49 | class VarDecl; |
| 50 | class ParmVarDecl; |
| 51 | class TypedefDecl; |
| 52 | class FunctionDecl; |
| 53 | class QualType; |
Chris Lattner | 3496d52 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 54 | struct LangOptions; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 55 | class Token; |
| 56 | class IntegerLiteral; |
Steve Naroff | 0d4e6ad | 2008-01-22 00:55:40 +0000 | [diff] [blame] | 57 | class StringLiteral; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 58 | class ArrayType; |
| 59 | class LabelStmt; |
| 60 | class SwitchStmt; |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 61 | class ExtVectorType; |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 62 | class TypedefDecl; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 63 | class ObjCInterfaceDecl; |
Steve Naroff | e57c21a | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 64 | class ObjCCompatibleAliasDecl; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 65 | class ObjCProtocolDecl; |
| 66 | class ObjCImplementationDecl; |
| 67 | class ObjCCategoryImplDecl; |
| 68 | class ObjCCategoryDecl; |
| 69 | class ObjCIvarDecl; |
| 70 | class ObjCMethodDecl; |
Fariborz Jahanian | ed98660 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 71 | class ObjCPropertyDecl; |
Steve Naroff | ab63fd6 | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 72 | class ObjCContainerDecl; |
Steve Naroff | 52a81c0 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 73 | struct BlockSemaInfo; |
Douglas Gregor | bb46150 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 74 | class BasePaths; |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 75 | class MemberLookupCriteria; |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 76 | |
Daniel Dunbar | 81c7d47 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 77 | /// PragmaPackStack - Simple class to wrap the stack used by #pragma |
| 78 | /// pack. |
| 79 | class PragmaPackStack { |
Daniel Dunbar | c13c54c | 2008-11-19 10:32:38 +0000 | [diff] [blame] | 80 | typedef std::vector< std::pair<unsigned, IdentifierInfo*> > stack_ty; |
Daniel Dunbar | 81c7d47 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 81 | |
| 82 | /// Alignment - The current user specified alignment. |
| 83 | unsigned Alignment; |
| 84 | |
Daniel Dunbar | c13c54c | 2008-11-19 10:32:38 +0000 | [diff] [blame] | 85 | /// Stack - Entries in the #pragma pack stack, consisting of saved |
| 86 | /// alignments and optional names. |
Daniel Dunbar | 81c7d47 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 87 | stack_ty Stack; |
| 88 | |
| 89 | public: |
| 90 | PragmaPackStack(unsigned A) : Alignment(A) {} |
| 91 | |
| 92 | void setAlignment(unsigned A) { Alignment = A; } |
| 93 | unsigned getAlignment() { return Alignment; } |
| 94 | |
| 95 | /// push - Push the current alignment onto the stack, optionally |
Daniel Dunbar | c13c54c | 2008-11-19 10:32:38 +0000 | [diff] [blame] | 96 | /// using the given \arg Name for the record, if non-zero. |
Daniel Dunbar | 81c7d47 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 97 | void push(IdentifierInfo *Name) { |
Daniel Dunbar | c13c54c | 2008-11-19 10:32:38 +0000 | [diff] [blame] | 98 | Stack.push_back(std::make_pair(Alignment, Name)); |
Daniel Dunbar | 81c7d47 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /// pop - Pop a record from the stack and restore the current |
| 102 | /// alignment to the previous value. If \arg Name is non-zero then |
| 103 | /// the first such named record is popped, otherwise the top record |
| 104 | /// is popped. Returns true if the pop succeeded. |
| 105 | bool pop(IdentifierInfo *Name); |
| 106 | }; |
| 107 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 108 | /// Sema - This implements semantic analysis and AST building for C. |
| 109 | class Sema : public Action { |
Chris Lattner | f669015 | 2008-06-29 00:28:59 +0000 | [diff] [blame] | 110 | public: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 111 | Preprocessor &PP; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 112 | ASTContext &Context; |
Chris Lattner | a8c2d59 | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 113 | ASTConsumer &Consumer; |
Chris Lattner | f9ea6a4 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 114 | Diagnostic &Diags; |
| 115 | SourceManager &SourceMgr; |
Steve Naroff | dd2e26c | 2007-11-12 13:56:41 +0000 | [diff] [blame] | 116 | |
Argiris Kirtzidis | 95256e6 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 117 | /// CurContext - This is the current declaration context of parsing. |
Chris Lattner | f3874bc | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 118 | DeclContext *CurContext; |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 119 | |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 120 | /// PreDeclaratorDC - Keeps the declaration context before switching to the |
| 121 | /// context of a declarator's nested-name-specifier. |
| 122 | DeclContext *PreDeclaratorDC; |
| 123 | |
Steve Naroff | 52a81c0 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 124 | /// CurBlock - If inside of a block definition, this contains a pointer to |
| 125 | /// the active block object that represents it. |
| 126 | BlockSemaInfo *CurBlock; |
| 127 | |
Daniel Dunbar | 81c7d47 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 128 | /// PackContext - Manages the stack for #pragma pack. An alignment |
| 129 | /// of 0 indicates default alignment. |
| 130 | PragmaPackStack PackContext; |
| 131 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 132 | /// LabelMap - This is a mapping from label identifiers to the LabelStmt for |
| 133 | /// it (which acts like the label decl in some ways). Forward referenced |
| 134 | /// labels have a LabelStmt created for them with a null location & SubStmt. |
| 135 | llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap; |
| 136 | |
| 137 | llvm::SmallVector<SwitchStmt*, 8> SwitchStack; |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 138 | |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 139 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
| 140 | /// us to associate a raw vector type with one of the ext_vector type names. |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 141 | /// This is only necessary for issuing pretty diagnostics. |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 142 | llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls; |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 143 | |
Steve Naroff | 4b9846d | 2008-09-28 14:55:53 +0000 | [diff] [blame] | 144 | /// ObjCImplementations - Keep track of all class @implementations |
| 145 | /// so we can emit errors on duplicates. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 146 | llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations; |
Chris Lattner | a7a191c | 2007-10-07 01:13:46 +0000 | [diff] [blame] | 147 | |
Steve Naroff | 4b9846d | 2008-09-28 14:55:53 +0000 | [diff] [blame] | 148 | /// ObjCCategoryImpls - Maintain a list of category implementations so |
| 149 | /// we can check for duplicates and find local method declarations. |
| 150 | llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls; |
| 151 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 152 | /// ObjCProtocols - Keep track of all protocol declarations declared |
Fariborz Jahanian | ac142de | 2007-10-09 18:03:53 +0000 | [diff] [blame] | 153 | /// with @protocol keyword, so that we can emit errors on duplicates and |
Chris Lattner | 042e6e8 | 2007-10-09 18:18:24 +0000 | [diff] [blame] | 154 | /// find the declarations when needed. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 155 | llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols; |
Steve Naroff | 1520816 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 156 | |
| 157 | /// ObjCInterfaceDecls - Keep track of all class declarations declared |
| 158 | /// with @interface, so that we can emit errors on duplicates and |
| 159 | /// find the declarations when needed. |
| 160 | typedef llvm::DenseMap<const IdentifierInfo*, |
| 161 | ObjCInterfaceDecl*> ObjCInterfaceDeclsTy; |
| 162 | ObjCInterfaceDeclsTy ObjCInterfaceDecls; |
| 163 | |
Steve Naroff | e57c21a | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 164 | /// ObjCAliasDecls - Keep track of all class declarations declared |
| 165 | /// with @compatibility_alias, so that we can emit errors on duplicates and |
| 166 | /// find the declarations when needed. This construct is ancient and will |
| 167 | /// likely never be seen. Nevertheless, it is here for compatibility. |
Steve Naroff | 64334ea | 2008-04-02 00:39:51 +0000 | [diff] [blame] | 168 | typedef llvm::DenseMap<const IdentifierInfo*, |
| 169 | ObjCCompatibleAliasDecl*> ObjCAliasTy; |
Steve Naroff | e57c21a | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 170 | ObjCAliasTy ObjCAliasDecls; |
Steve Naroff | 1520816 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 171 | |
Argiris Kirtzidis | 38f1671 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 172 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
| 173 | llvm::OwningPtr<CXXFieldCollector> FieldCollector; |
| 174 | |
Chris Lattner | 2a1e2ed | 2008-04-11 07:00:53 +0000 | [diff] [blame] | 175 | IdentifierResolver IdResolver; |
| 176 | |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 177 | // Enum values used by KnownFunctionIDs (see below). |
| 178 | enum { |
Ted Kremenek | 225a14c | 2008-06-16 18:00:42 +0000 | [diff] [blame] | 179 | id_NSLog, |
Daniel Dunbar | 0ab03e6 | 2008-10-02 18:44:07 +0000 | [diff] [blame] | 180 | id_asprintf, |
| 181 | id_fprintf, |
| 182 | id_printf, |
| 183 | id_snprintf, |
| 184 | id_snprintf_chk, |
| 185 | id_sprintf, |
| 186 | id_sprintf_chk, |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 187 | id_vasprintf, |
Daniel Dunbar | 0ab03e6 | 2008-10-02 18:44:07 +0000 | [diff] [blame] | 188 | id_vfprintf, |
| 189 | id_vsnprintf, |
| 190 | id_vsnprintf_chk, |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 191 | id_vsprintf, |
Daniel Dunbar | 0ab03e6 | 2008-10-02 18:44:07 +0000 | [diff] [blame] | 192 | id_vsprintf_chk, |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 193 | id_vprintf, |
| 194 | id_num_known_functions |
| 195 | }; |
| 196 | |
| 197 | /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set |
| 198 | /// of known functions used by the semantic analysis to do various |
| 199 | /// kinds of checking (e.g. checking format string errors in printf calls). |
| 200 | /// This list is populated upon the creation of a Sema object. |
Chris Lattner | f7df4d1 | 2008-08-23 02:00:52 +0000 | [diff] [blame] | 201 | IdentifierInfo* KnownFunctionIDs[id_num_known_functions]; |
Daniel Dunbar | 4837ae7 | 2008-08-14 22:04:54 +0000 | [diff] [blame] | 202 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 203 | /// Translation Unit Scope - useful to Objective-C actions that need |
| 204 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
| 205 | /// For example, user-defined classes, built-in "id" type, etc. |
Steve Naroff | 9637a9b | 2007-10-09 22:01:59 +0000 | [diff] [blame] | 206 | Scope *TUScope; |
Sebastian Redl | b93b49c | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 207 | |
| 208 | /// The C++ "std" namespace, where the standard library resides. Cached here |
| 209 | /// by GetStdNamespace |
| 210 | NamespaceDecl *StdNamespace; |
Sebastian Redl | b5ee874 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 211 | |
| 212 | /// A flag to remember whether the implicit forms of operator new and delete |
| 213 | /// have been declared. |
| 214 | bool GlobalNewDeleteDeclared; |
Steve Naroff | ee1de13 | 2007-10-10 21:53:07 +0000 | [diff] [blame] | 215 | |
Steve Naroff | 8255b04 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 216 | /// ObjCMethodList - a linked list of methods with different signatures. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 217 | struct ObjCMethodList { |
| 218 | ObjCMethodDecl *Method; |
| 219 | ObjCMethodList *Next; |
Steve Naroff | 8255b04 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 220 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 221 | ObjCMethodList() { |
Steve Naroff | 8255b04 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 222 | Method = 0; |
| 223 | Next = 0; |
| 224 | } |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 225 | ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) { |
Steve Naroff | 8255b04 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 226 | Method = M; |
| 227 | Next = C; |
| 228 | } |
| 229 | }; |
| 230 | /// Instance/Factory Method Pools - allows efficient lookup when typechecking |
| 231 | /// messages to "id". We need to maintain a list, since selectors can have |
| 232 | /// differing signatures across classes. In Cocoa, this happens to be |
| 233 | /// extremely uncommon (only 1% of selectors are "overloaded"). |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 234 | llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool; |
| 235 | llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 236 | public: |
Chris Lattner | a8c2d59 | 2008-02-06 00:46:58 +0000 | [diff] [blame] | 237 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 238 | |
| 239 | const LangOptions &getLangOptions() const; |
Chris Lattner | f9ea6a4 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 240 | Diagnostic &getDiagnostics() const { return Diags; } |
| 241 | SourceManager &getSourceManager() const { return SourceMgr; } |
| 242 | |
Chris Lattner | 429558c | 2008-11-18 21:53:24 +0000 | [diff] [blame] | 243 | /// The primitive diagnostic helpers. |
Chris Lattner | f9ea6a4 | 2008-11-22 08:28:49 +0000 | [diff] [blame] | 244 | DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { |
| 245 | return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID); |
| 246 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 247 | |
Chris Lattner | b26b7ad | 2007-08-31 04:53:24 +0000 | [diff] [blame] | 248 | virtual void DeleteExpr(ExprTy *E); |
| 249 | virtual void DeleteStmt(StmtTy *S); |
| 250 | |
Sebastian Redl | 91f9b0a | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 251 | OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); } |
| 252 | OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); } |
| 253 | |
Chris Lattner | c1aea81 | 2008-08-23 03:19:52 +0000 | [diff] [blame] | 254 | virtual void ActOnEndOfTranslationUnit(); |
| 255 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 256 | //===--------------------------------------------------------------------===// |
| 257 | // Type Analysis / Processing: SemaType.cpp. |
| 258 | // |
Chris Lattner | 99dbc96 | 2008-06-26 06:27:57 +0000 | [diff] [blame] | 259 | QualType ConvertDeclSpecToType(const DeclSpec &DS); |
Chris Lattner | 65a5704 | 2008-06-29 00:50:08 +0000 | [diff] [blame] | 260 | void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL); |
Sebastian Redl | 66df3ef | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 261 | QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0); |
Douglas Gregor | 6704b31 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 262 | DeclarationName GetNameForDeclarator(Declarator &D); |
| 263 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 264 | QualType ObjCGetTypeForMethodDefinition(DeclTy *D); |
Fariborz Jahanian | dfb1c37 | 2007-11-08 23:49:49 +0000 | [diff] [blame] | 265 | |
Douglas Gregor | ccc0ccc | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 266 | bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2); |
| 267 | |
Sebastian Redl | 66df3ef | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 268 | virtual TypeResult ActOnTypeName(Scope *S, Declarator &D); |
Sebastian Redl | f831eeb | 2008-11-08 13:00:26 +0000 | [diff] [blame] | 269 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 270 | //===--------------------------------------------------------------------===// |
| 271 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
| 272 | // |
Douglas Gregor | b0212bd | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 273 | virtual TypeTy *isTypeName(IdentifierInfo &II, Scope *S, |
Argiris Kirtzidis | 311db8c | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 274 | const CXXScopeSpec *SS); |
Douglas Gregor | c5cbc24 | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 275 | virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) { |
| 276 | return ActOnDeclarator(S, D, LastInGroup, false); |
| 277 | } |
| 278 | DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup, |
| 279 | bool IsFunctionDefinition); |
Zhongxing Xu | 511d45b | 2009-01-16 02:36:34 +0000 | [diff] [blame^] | 280 | ScopedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
| 281 | QualType R, ScopedDecl* LastDeclarator, |
| 282 | Decl* PrevDecl, bool& InvalidDecl); |
Zhongxing Xu | 7502dec | 2009-01-16 01:13:29 +0000 | [diff] [blame] | 283 | ScopedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
| 284 | QualType R, ScopedDecl *LastDeclarator, |
Zhongxing Xu | 511d45b | 2009-01-16 02:36:34 +0000 | [diff] [blame^] | 285 | Decl* PrevDecl, bool IsFunctionDefinition, |
Zhongxing Xu | 7502dec | 2009-01-16 01:13:29 +0000 | [diff] [blame] | 286 | bool& InvalidDecl); |
Chris Lattner | 3e254fb | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 287 | virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D); |
| 288 | virtual void ActOnParamDefaultArgument(DeclTy *param, |
| 289 | SourceLocation EqualLoc, |
| 290 | ExprTy *defarg); |
Douglas Gregor | 62ae25a | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 291 | virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param, |
| 292 | SourceLocation EqualLoc); |
Douglas Gregor | 605de8d | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 293 | virtual void ActOnParamDefaultArgumentError(DeclTy *param); |
Douglas Gregor | 6214d8a | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 294 | virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init); |
| 295 | void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit); |
Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 296 | void ActOnUninitializedDecl(DeclTy *dcl); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 297 | virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group); |
| 298 | |
Chris Lattner | ea14870 | 2007-10-09 17:14:05 +0000 | [diff] [blame] | 299 | virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D); |
Argiris Kirtzidis | 38f1671 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 300 | virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 301 | virtual void ObjCActOnStartOfMethodDef(Scope *S, DeclTy *D); |
Steve Naroff | 99ee430 | 2007-11-11 23:20:51 +0000 | [diff] [blame] | 302 | |
Sebastian Redl | 91f9b0a | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 303 | virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body); |
Sebastian Redl | 91f9b0a | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 304 | virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr); |
Anders Carlsson | 4f7f441 | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 305 | |
Steve Naroff | 9637a9b | 2007-10-09 22:01:59 +0000 | [diff] [blame] | 306 | /// Scope actions. |
| 307 | virtual void ActOnPopScope(SourceLocation Loc, Scope *S); |
| 308 | virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 309 | |
| 310 | /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with |
| 311 | /// no declarator (e.g. "struct foo;") is parsed. |
Sebastian Redl | b7605e8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 312 | virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 313 | |
Douglas Gregor | 723d333 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 314 | bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, |
| 315 | RecordDecl *AnonRecord); |
| 316 | virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
| 317 | RecordDecl *Record); |
| 318 | |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 319 | virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK, |
Argiris Kirtzidis | 311db8c | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 320 | SourceLocation KWLoc, const CXXScopeSpec &SS, |
| 321 | IdentifierInfo *Name, SourceLocation NameLoc, |
Douglas Gregor | 5247343 | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 322 | AttributeList *Attr, |
| 323 | MultiTemplateParamsArg TemplateParameterLists); |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 324 | |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 325 | virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart, |
Chris Lattner | f7df4d1 | 2008-08-23 02:00:52 +0000 | [diff] [blame] | 326 | IdentifierInfo *ClassName, |
| 327 | llvm::SmallVectorImpl<DeclTy*> &Decls); |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 328 | virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 329 | Declarator &D, ExprTy *BitfieldWidth); |
Fariborz Jahanian | 751c617 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 330 | |
| 331 | virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart, |
| 332 | Declarator &D, ExprTy *BitfieldWidth, |
Fariborz Jahanian | 4e0bb98 | 2008-04-11 16:55:42 +0000 | [diff] [blame] | 333 | tok::ObjCKeywordKind visibility); |
Fariborz Jahanian | 751c617 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 334 | |
Steve Naroff | ffeaa55 | 2007-09-14 23:09:53 +0000 | [diff] [blame] | 335 | // This is used for both record definitions and ObjC interface declarations. |
Fariborz Jahanian | 0c5affb | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 336 | virtual void ActOnFields(Scope* S, |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 337 | SourceLocation RecLoc, DeclTy *TagDecl, |
| 338 | DeclTy **Fields, unsigned NumFields, |
Daniel Dunbar | f394444 | 2008-10-03 02:03:53 +0000 | [diff] [blame] | 339 | SourceLocation LBrac, SourceLocation RBrac, |
| 340 | AttributeList *AttrList); |
Douglas Gregor | db568cf | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 341 | |
| 342 | /// ActOnTagStartDefinition - Invoked when we have entered the |
| 343 | /// scope of a tag's definition (e.g., for an enumeration, class, |
| 344 | /// struct, or union). |
| 345 | virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl); |
| 346 | |
| 347 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
| 348 | /// the definition of a tag (enumeration, class, struct, or union). |
| 349 | virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl); |
| 350 | |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 351 | virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 352 | DeclTy *LastEnumConstant, |
| 353 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 354 | SourceLocation EqualLoc, ExprTy *Val); |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 355 | virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 356 | DeclTy **Elements, unsigned NumElements); |
Sebastian Redl | f831eeb | 2008-11-08 13:00:26 +0000 | [diff] [blame] | 357 | |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 358 | DeclContext *getContainingDC(DeclContext *DC); |
Argiris Kirtzidis | 38f1671 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 359 | |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 360 | /// Set the current declaration context until it gets popped. |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 361 | void PushDeclContext(Scope *S, DeclContext *DC); |
Chris Lattner | f3874bc | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 362 | void PopDeclContext(); |
Argiris Kirtzidis | 95256e6 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 363 | |
Chris Lattner | e5cb586 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 364 | /// getCurFunctionDecl - If inside of a function body, this returns a pointer |
| 365 | /// to the function decl for the function being parsed. If we're currently |
| 366 | /// in a 'block', this returns the containing context. |
| 367 | FunctionDecl *getCurFunctionDecl(); |
| 368 | |
| 369 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
| 370 | /// the method decl for the method being parsed. If we're currently |
| 371 | /// in a 'block', this returns the containing context. |
Daniel Dunbar | 64789f8 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 372 | ObjCMethodDecl *getCurMethodDecl(); |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 373 | |
Chris Lattner | e5cb586 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 374 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
| 375 | /// or C function we're in, otherwise return null. If we're currently |
| 376 | /// in a 'block', this returns the containing context. |
| 377 | NamedDecl *getCurFunctionOrMethodDecl(); |
| 378 | |
Argiris Kirtzidis | 951f25b | 2008-04-12 00:47:19 +0000 | [diff] [blame] | 379 | /// Add this decl to the scope shadowed decl chains. |
| 380 | void PushOnScopeChains(NamedDecl *D, Scope *S); |
| 381 | |
Argiris Kirtzidis | 90842b6 | 2008-09-09 21:18:04 +0000 | [diff] [blame] | 382 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
| 383 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
| 384 | /// true if 'D' belongs to the given declaration context. |
| 385 | bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) { |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 386 | return IdResolver.isDeclInScope(D, Ctx, Context, S); |
Argiris Kirtzidis | 90842b6 | 2008-09-09 21:18:04 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Chris Lattner | 9e98250 | 2008-02-21 01:07:18 +0000 | [diff] [blame] | 389 | /// Subroutines of ActOnDeclarator(). |
Chris Lattner | 82bb479 | 2007-11-14 06:34:38 +0000 | [diff] [blame] | 390 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
| 391 | ScopedDecl *LastDecl); |
Steve Naroff | e57c21a | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 392 | TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old); |
Douglas Gregor | 42214c5 | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 393 | FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old, |
| 394 | bool &Redeclaration); |
Steve Naroff | e57c21a | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 395 | VarDecl *MergeVarDecl(VarDecl *New, Decl *Old); |
Chris Lattner | 3e254fb | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 396 | FunctionDecl *MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old); |
Steve Naroff | b5e7815 | 2008-08-08 17:50:35 +0000 | [diff] [blame] | 397 | void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD); |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 398 | |
| 399 | /// C++ Overloading. |
| 400 | bool IsOverload(FunctionDecl *New, Decl* OldD, |
| 401 | OverloadedFunctionDecl::function_iterator &MatchedDecl); |
Douglas Gregor | a3b34bb | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 402 | ImplicitConversionSequence |
| 403 | TryImplicitConversion(Expr* From, QualType ToType, |
Douglas Gregor | 6214d8a | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 404 | bool SuppressUserConversions = false, |
| 405 | bool AllowExplicit = false); |
Douglas Gregor | b72e9da | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 406 | bool IsStandardConversion(Expr *From, QualType ToType, |
| 407 | StandardConversionSequence& SCS); |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 408 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
| 409 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
| 410 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
Douglas Gregor | 6fd3557 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 411 | QualType& ConvertedType, bool &IncompatibleObjC); |
Douglas Gregor | 932778b | 2008-12-19 19:13:09 +0000 | [diff] [blame] | 412 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
| 413 | QualType& ConvertedType, bool &IncompatibleObjC); |
Douglas Gregor | bb46150 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 414 | bool CheckPointerConversion(Expr *From, QualType ToType); |
Douglas Gregor | 6573cfd | 2008-10-21 23:43:52 +0000 | [diff] [blame] | 415 | bool IsQualificationConversion(QualType FromType, QualType ToType); |
Douglas Gregor | b72e9da | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 416 | bool IsUserDefinedConversion(Expr *From, QualType ToType, |
Douglas Gregor | 6214d8a | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 417 | UserDefinedConversionSequence& User, |
| 418 | bool AllowExplicit = false); |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 419 | |
| 420 | ImplicitConversionSequence::CompareKind |
| 421 | CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1, |
| 422 | const ImplicitConversionSequence& ICS2); |
| 423 | |
| 424 | ImplicitConversionSequence::CompareKind |
| 425 | CompareStandardConversionSequences(const StandardConversionSequence& SCS1, |
| 426 | const StandardConversionSequence& SCS2); |
| 427 | |
Douglas Gregor | ccc0ccc | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 428 | ImplicitConversionSequence::CompareKind |
| 429 | CompareQualificationConversions(const StandardConversionSequence& SCS1, |
| 430 | const StandardConversionSequence& SCS2); |
| 431 | |
Douglas Gregor | 1404650 | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 432 | ImplicitConversionSequence::CompareKind |
| 433 | CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1, |
| 434 | const StandardConversionSequence& SCS2); |
| 435 | |
Douglas Gregor | a3b34bb | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 436 | ImplicitConversionSequence |
| 437 | TryCopyInitialization(Expr* From, QualType ToType, |
| 438 | bool SuppressUserConversions = false); |
Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 439 | bool PerformCopyInitialization(Expr *&From, QualType ToType, |
| 440 | const char *Flavor); |
| 441 | |
Douglas Gregor | 5ed1504 | 2008-11-18 23:14:02 +0000 | [diff] [blame] | 442 | ImplicitConversionSequence |
| 443 | TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method); |
| 444 | bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method); |
| 445 | |
Douglas Gregor | 6214d8a | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 446 | ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From); |
| 447 | bool PerformContextuallyConvertToBool(Expr *&From); |
| 448 | |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 449 | /// OverloadingResult - Capture the result of performing overload |
| 450 | /// resolution. |
| 451 | enum OverloadingResult { |
| 452 | OR_Success, ///< Overload resolution succeeded. |
| 453 | OR_No_Viable_Function, ///< No viable function found. |
| 454 | OR_Ambiguous ///< Ambiguous candidates found. |
| 455 | }; |
| 456 | |
| 457 | void AddOverloadCandidate(FunctionDecl *Function, |
| 458 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | a3b34bb | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 459 | OverloadCandidateSet& CandidateSet, |
| 460 | bool SuppressUserConversions = false); |
Douglas Gregor | 5ed1504 | 2008-11-18 23:14:02 +0000 | [diff] [blame] | 461 | void AddMethodCandidate(CXXMethodDecl *Method, |
| 462 | Expr *Object, Expr **Args, unsigned NumArgs, |
| 463 | OverloadCandidateSet& CandidateSet, |
Douglas Gregor | 3257fb5 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 464 | bool SuppressUserConversions = false); |
Douglas Gregor | 60714f9 | 2008-11-07 22:36:19 +0000 | [diff] [blame] | 465 | void AddConversionCandidate(CXXConversionDecl *Conversion, |
| 466 | Expr *From, QualType ToType, |
| 467 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | 67fdb5b | 2008-11-19 22:57:39 +0000 | [diff] [blame] | 468 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
| 469 | const FunctionTypeProto *Proto, |
| 470 | Expr *Object, Expr **Args, unsigned NumArgs, |
| 471 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | 5ed1504 | 2008-11-18 23:14:02 +0000 | [diff] [blame] | 472 | void AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S, |
| 473 | Expr **Args, unsigned NumArgs, |
| 474 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 475 | void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, |
| 476 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | ab14111 | 2009-01-13 00:52:54 +0000 | [diff] [blame] | 477 | OverloadCandidateSet& CandidateSet, |
Douglas Gregor | 6214d8a | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 478 | bool IsAssignmentOperator = false, |
| 479 | unsigned NumContextualBoolArguments = 0); |
Douglas Gregor | 4f6904d | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 480 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
| 481 | Expr **Args, unsigned NumArgs, |
| 482 | OverloadCandidateSet& CandidateSet); |
Douglas Gregor | 5870a95 | 2008-11-03 20:45:27 +0000 | [diff] [blame] | 483 | void AddOverloadCandidates(const OverloadedFunctionDecl *Ovl, |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 484 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | a3b34bb | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 485 | OverloadCandidateSet& CandidateSet, |
| 486 | bool SuppressUserConversions = false); |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 487 | bool isBetterOverloadCandidate(const OverloadCandidate& Cand1, |
| 488 | const OverloadCandidate& Cand2); |
| 489 | OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet, |
| 490 | OverloadCandidateSet::iterator& Best); |
| 491 | void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, |
| 492 | bool OnlyViable); |
| 493 | |
Douglas Gregor | 45014fd | 2008-11-10 20:40:00 +0000 | [diff] [blame] | 494 | FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, |
| 495 | bool Complain); |
| 496 | void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn); |
| 497 | |
Douglas Gregor | bf4f058 | 2008-11-26 06:01:48 +0000 | [diff] [blame] | 498 | FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, OverloadedFunctionDecl *Ovl, |
| 499 | SourceLocation LParenLoc, |
| 500 | Expr **Args, unsigned NumArgs, |
| 501 | SourceLocation *CommaLocs, |
| 502 | SourceLocation RParenLoc); |
Douglas Gregor | 3257fb5 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 503 | ExprResult |
| 504 | BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
| 505 | SourceLocation LParenLoc, Expr **Args, |
| 506 | unsigned NumArgs, SourceLocation *CommaLocs, |
| 507 | SourceLocation RParenLoc); |
Douglas Gregor | 10f3c50 | 2008-11-19 21:05:33 +0000 | [diff] [blame] | 508 | ExprResult |
Douglas Gregor | a133e26 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 509 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
Douglas Gregor | 10f3c50 | 2008-11-19 21:05:33 +0000 | [diff] [blame] | 510 | Expr **Args, unsigned NumArgs, |
| 511 | SourceLocation *CommaLocs, |
| 512 | SourceLocation RParenLoc); |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 513 | |
Douglas Gregor | ddfd9d5 | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 514 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc, |
Douglas Gregor | 7f3fec5 | 2008-11-20 16:27:02 +0000 | [diff] [blame] | 515 | SourceLocation MemberLoc, |
| 516 | IdentifierInfo &Member); |
Douglas Gregor | 6214d8a | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 517 | |
Chris Lattner | 7898bf6 | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 518 | /// Helpers for dealing with function parameters. |
Chris Lattner | 3e254fb | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 519 | bool CheckParmsForFunctionDef(FunctionDecl *FD); |
Chris Lattner | 3e254fb | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 520 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
Douglas Gregor | 2b9422f | 2008-05-07 04:49:29 +0000 | [diff] [blame] | 521 | void CheckExtraCXXDefaultArguments(Declarator &D); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 522 | |
Douglas Gregor | 5ff0ee5 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 523 | // FIXME: NamespaceNameOnly parameter is added temporarily |
| 524 | // we will need a better way to specify lookup criteria for things |
Chris Lattner | 7898bf6 | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 525 | // like template specializations, explicit template instantiations, etc. |
Douglas Gregor | 5ff0ee5 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 526 | |
Douglas Gregor | 5eca99e | 2009-01-12 18:45:55 +0000 | [diff] [blame] | 527 | Scope *getNonFieldDeclScope(Scope *S); |
| 528 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 529 | /// \name Name lookup |
| 530 | /// |
| 531 | /// These routines provide name lookup that is used during semantic |
| 532 | /// analysis to resolve the various kinds of names (identifiers, |
| 533 | /// overloaded operator names, constructor names, etc.) into zero or |
| 534 | /// more declarations within a particular scope. The major entry |
| 535 | /// points are LookupName, which performs unqualified name lookup, |
| 536 | /// and LookupQualifiedName, which performs qualified name lookup. |
| 537 | /// |
| 538 | /// All name lookup is performed based on some specific criteria, |
| 539 | /// which specify what names will be visible to name lookup and how |
| 540 | /// far name lookup should work. These criteria are important both |
| 541 | /// for capturing language semantics (certain lookups will ignore |
| 542 | /// certain names, for example) and for performance, since name |
| 543 | /// lookup is often a bottleneck in the compilation of C++. Name |
| 544 | /// lookup criteria is specified via the LookupCriteria class. |
| 545 | /// |
| 546 | /// The results of name lookup can vary based on the kind of name |
| 547 | /// lookup performed, the current language, and the translation |
| 548 | /// unit. In C, for example, name lookup will either return nothing |
| 549 | /// (no entity found) or a single declaration. In C++, name lookup |
| 550 | /// can additionally refer to a set of overloaded functions or |
| 551 | /// result in an ambiguity. All of the possible results of name |
| 552 | /// lookup are captured by the LookupResult class, which provides |
| 553 | /// the ability to distinguish among them. |
| 554 | //@{ |
Douglas Gregor | 5ff0ee5 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 555 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 556 | /// @brief Describes the criteria by which name lookup will |
| 557 | /// determine whether a given name will be found. |
| 558 | /// |
| 559 | /// The LookupCriteria class captures the information required to |
| 560 | /// direct name lookup to find the appropriate kind of name. It |
| 561 | /// includes information about which kinds of names to consider |
| 562 | /// (ordinary names, tag names, class/struct/union member names, |
| 563 | /// namespace names, etc.) and where to look for those |
| 564 | /// names. LookupCriteria is used throughout semantic analysis to |
| 565 | /// specify how to search for a name, e.g., with the LookupName and |
| 566 | /// LookupQualifiedName functions. |
| 567 | struct LookupCriteria { |
| 568 | /// NameKind - The kinds of names that we are looking for. |
| 569 | enum NameKind { |
| 570 | /// Ordinary - Ordinary name lookup, which finds ordinary names |
| 571 | /// (functions, variables, typedefs, etc.) in C and most kinds |
| 572 | /// of names (functions, variables, members, types, etc.) in |
| 573 | /// C++. |
| 574 | Ordinary, |
| 575 | /// Tag - Tag name lookup, which finds the names of enums, |
| 576 | /// classes, structs, and unions. |
| 577 | Tag, |
| 578 | /// Member - Member name lookup, which finds the names of |
| 579 | /// class/struct/union members. |
| 580 | Member, |
| 581 | /// NestedNameSpecifier - Look up of a name that precedes the |
| 582 | /// '::' scope resolution operator in C++. This lookup |
| 583 | /// completely ignores operator, function, and enumerator names |
| 584 | /// (C++ [basic.lookup.qual]p1). |
| 585 | NestedNameSpecifier, |
| 586 | /// Namespace - Look up a namespace name within a C++ |
| 587 | /// using directive or namespace alias definition, ignoring |
| 588 | /// non-namespace names (C++ [basic.lookup.udir]p1). |
| 589 | Namespace |
| 590 | } Kind; |
| 591 | |
| 592 | /// AllowLazyBuiltinCreation - If true, permits name lookup to |
| 593 | /// lazily build declarations for built-in names, e.g., |
| 594 | /// __builtin_expect. |
| 595 | bool AllowLazyBuiltinCreation; |
| 596 | |
| 597 | /// RedeclarationOnly - If true, the lookup will only |
| 598 | /// consider entities within the scope where the lookup |
| 599 | /// began. Entities that might otherwise meet the lookup criteria |
| 600 | /// but are not within the original lookup scope will be ignored. |
| 601 | bool RedeclarationOnly; |
| 602 | |
| 603 | /// IDNS - Bitwise OR of the appropriate Decl::IDNS_* flags that |
| 604 | /// describe the namespaces where we should look for names. This |
| 605 | /// field is determined by the kind of name we're searching for. |
| 606 | unsigned IDNS; |
| 607 | |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 608 | LookupCriteria() |
| 609 | : Kind(Ordinary), AllowLazyBuiltinCreation(true), |
| 610 | RedeclarationOnly(false), IDNS(Decl::IDNS_Ordinary) { } |
| 611 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 612 | LookupCriteria(NameKind K, bool RedeclarationOnly, bool CPlusPlus); |
| 613 | |
| 614 | bool isLookupResult(Decl *D) const; |
| 615 | }; |
| 616 | |
| 617 | /// @brief Represents the results of name lookup. |
| 618 | /// |
| 619 | /// An instance of the LookupResult class captures the results of a |
| 620 | /// single name lookup, which can return no result (nothing found), |
| 621 | /// a single declaration, a set of overloaded functions, or an |
| 622 | /// ambiguity. Use the getKind() method to determine which of these |
| 623 | /// results occurred for a given lookup. |
| 624 | /// |
| 625 | /// Any non-ambiguous lookup can be converted into a single |
| 626 | /// (possibly NULL) @c Decl* via a conversion function or the |
| 627 | /// getAsDecl() method. This conversion permits the common-case |
| 628 | /// usage in C and Objective-C where name lookup will always return |
| 629 | /// a single declaration. |
| 630 | class LookupResult { |
| 631 | /// The kind of entity that is actually stored within the |
| 632 | /// LookupResult object. |
| 633 | mutable enum { |
| 634 | /// First is a single declaration (a Decl*), which may be NULL. |
| 635 | SingleDecl, |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 636 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 637 | /// [First, Last) is an iterator range represented as opaque |
| 638 | /// pointers used to reconstruct IdentifierResolver::iterators. |
| 639 | OverloadedDeclFromIdResolver, |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 640 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 641 | /// [First, Last) is an iterator range represented as opaque |
| 642 | /// pointers used to reconstruct DeclContext::lookup_iterators. |
| 643 | OverloadedDeclFromDeclContext, |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 644 | |
| 645 | /// First is a pointer to a BasePaths structure, which is owned |
| 646 | /// by the LookupResult. Last is non-zero to indicate that the |
| 647 | /// ambiguity is caused by two names found in base class |
| 648 | /// subobjects of different types. |
Douglas Gregor | 6beddfe | 2009-01-15 02:19:31 +0000 | [diff] [blame] | 649 | AmbiguousLookup, |
| 650 | |
| 651 | /// We've moved from this object. There should not be any |
| 652 | /// attempts to look at its state. |
| 653 | Dead |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 654 | } StoredKind; |
| 655 | |
| 656 | /// The first lookup result, whose contents depend on the kind of |
| 657 | /// lookup result. This may be a Decl* (if StoredKind == |
| 658 | /// SingleDecl), the opaque pointer from an |
| 659 | /// IdentifierResolver::iterator (if StoredKind == |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 660 | /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator |
| 661 | /// (if StoredKind == OverloadedDeclFromDeclContext), or a |
| 662 | /// BasePaths pointer (if StoredKind == AmbiguousLookup). |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 663 | mutable uintptr_t First; |
| 664 | |
| 665 | /// The last lookup result, whose contents depend on the kind of |
| 666 | /// lookup result. This may be unused (if StoredKind == |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 667 | /// SingleDecl), it may have the same type as First (for |
| 668 | /// overloaded function declarations), or is may be used as a |
| 669 | /// Boolean value (if StoredKind == AmbiguousLookup). |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 670 | mutable uintptr_t Last; |
| 671 | |
| 672 | /// Context - The context in which we will build any |
| 673 | /// OverloadedFunctionDecl nodes needed by the conversion to |
| 674 | /// Decl*. |
| 675 | ASTContext *Context; |
| 676 | |
| 677 | public: |
| 678 | /// @brief The kind of entity found by name lookup. |
| 679 | enum LookupKind { |
| 680 | /// @brief No entity found met the criteria. |
| 681 | NotFound = 0, |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 682 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 683 | /// @brief Name lookup found a single declaration that met the |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 684 | /// criteria. getAsDecl will return this declaration. |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 685 | Found, |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 686 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 687 | /// @brief Name lookup found a set of overloaded functions that |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 688 | /// met the criteria. getAsDecl will turn this set of overloaded |
| 689 | /// functions into an OverloadedFunctionDecl. |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 690 | FoundOverloaded, |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 691 | |
| 692 | /// Name lookup results in an ambiguity because multiple |
| 693 | /// entities that meet the lookup criteria were found in |
| 694 | /// subobjects of different types. For example: |
| 695 | /// @code |
| 696 | /// struct A { void f(int); } |
| 697 | /// struct B { void f(double); } |
| 698 | /// struct C : A, B { }; |
| 699 | /// void test(C c) { |
| 700 | /// c.f(0); // error: A::f and B::f come from subobjects of different |
| 701 | /// // types. overload resolution is not performed. |
| 702 | /// } |
| 703 | /// @endcode |
| 704 | AmbiguousBaseSubobjectTypes, |
| 705 | |
| 706 | /// Name lookup results in an ambiguity because multiple |
| 707 | /// nonstatic entities that meet the lookup criteria were found |
| 708 | /// in different subobjects of the same type. For example: |
| 709 | /// @code |
| 710 | /// struct A { int x; }; |
| 711 | /// struct B : A { }; |
| 712 | /// struct C : A { }; |
| 713 | /// struct D : B, C { }; |
| 714 | /// int test(D d) { |
| 715 | /// return d.x; // error: 'x' is found in two A subobjects (of B and C) |
| 716 | /// } |
| 717 | /// @endcode |
| 718 | AmbiguousBaseSubobjects |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 719 | }; |
| 720 | |
Douglas Gregor | 6beddfe | 2009-01-15 02:19:31 +0000 | [diff] [blame] | 721 | LookupResult() : StoredKind(Dead), First(0), Last(0), Context(0) { } |
| 722 | |
| 723 | LookupResult(const LookupResult& Other); |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 724 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 725 | LookupResult(ASTContext &Context, Decl *D) |
| 726 | : StoredKind(SingleDecl), First(reinterpret_cast<uintptr_t>(D)), |
| 727 | Last(0), Context(&Context) { } |
| 728 | |
| 729 | LookupResult(ASTContext &Context, |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 730 | IdentifierResolver::iterator F, IdentifierResolver::iterator L); |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 731 | |
| 732 | LookupResult(ASTContext &Context, |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 733 | DeclContext::lookup_iterator F, DeclContext::lookup_iterator L); |
| 734 | |
| 735 | LookupResult(ASTContext &Context, BasePaths *Paths, |
| 736 | bool DifferentSubobjectTypes) |
| 737 | : StoredKind(AmbiguousLookup), |
| 738 | First(reinterpret_cast<uintptr_t>(Paths)), |
| 739 | Last(DifferentSubobjectTypes? 1 : 0), |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 740 | Context(&Context) { } |
| 741 | |
Douglas Gregor | 6beddfe | 2009-01-15 02:19:31 +0000 | [diff] [blame] | 742 | ~LookupResult(); |
| 743 | |
| 744 | LookupResult& operator=(const LookupResult& Other); |
| 745 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 746 | LookupKind getKind() const; |
| 747 | |
| 748 | /// @brief Determine whether name look found something. |
| 749 | operator bool() const { return getKind() != NotFound; } |
| 750 | |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 751 | /// @brief Determines whether the lookup resulted in an ambiguity. |
| 752 | bool isAmbiguous() const { return StoredKind == AmbiguousLookup; } |
| 753 | |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 754 | /// @brief Allows conversion of a lookup result into a |
| 755 | /// declaration, with the same behavior as getAsDecl. |
| 756 | operator Decl*() const { return getAsDecl(); } |
| 757 | |
| 758 | Decl* getAsDecl() const; |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 759 | |
| 760 | BasePaths *getBasePaths() const; |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 761 | }; |
| 762 | |
| 763 | LookupResult LookupName(Scope *S, DeclarationName Name, |
| 764 | LookupCriteria Criteria); |
| 765 | LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name, |
| 766 | LookupCriteria Criteria); |
| 767 | LookupResult LookupParsedName(Scope *S, const CXXScopeSpec &SS, |
| 768 | DeclarationName Name, LookupCriteria Criteria); |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 769 | LookupResult LookupDecl(DeclarationName Name, unsigned NSI, Scope *S, |
| 770 | const DeclContext *LookupCtx = 0, |
| 771 | bool enableLazyBuiltinCreation = true, |
| 772 | bool LookInParent = true, |
| 773 | bool NamespaceNameOnly = false); |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 774 | |
| 775 | bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name, |
| 776 | SourceLocation NameLoc, |
| 777 | SourceRange LookupRange = SourceRange()); |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 778 | //@} |
| 779 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 780 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id); |
Steve Naroff | 6384a01 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 781 | ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
| 782 | Scope *S); |
Steve Naroff | f0c31dd | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 783 | ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 784 | Scope *S); |
Douglas Gregor | 78d7013 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 785 | |
| 786 | // More parsing and symbol table subroutines. |
| 787 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 788 | // Decl attributes - this routine is the top level dispatcher. |
Chris Lattner | 2024f0a | 2008-06-29 00:16:31 +0000 | [diff] [blame] | 789 | void ProcessDeclAttributes(Decl *D, const Declarator &PD); |
Chris Lattner | d7e83d8 | 2008-06-28 23:58:55 +0000 | [diff] [blame] | 790 | void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 791 | |
Steve Naroff | b4f4851 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 792 | void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, |
| 793 | bool &IncompleteImpl); |
Fariborz Jahanian | 4e0f645 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 794 | void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod, |
| 795 | ObjCMethodDecl *IntfMethod); |
Sebastian Redl | b93b49c | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 796 | |
| 797 | NamespaceDecl *GetStdNamespace(); |
Fariborz Jahanian | f96ee9e | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 798 | |
| 799 | bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, |
| 800 | ObjCInterfaceDecl *IDecl) const; |
Steve Naroff | b4f4851 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 801 | |
Chris Lattner | 7898bf6 | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 802 | /// CheckProtocolMethodDefs - This routine checks unimplemented |
Daniel Dunbar | 1d706e9 | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 803 | /// methods declared in protocol, and those referenced by it. |
| 804 | /// \param IDecl - Used for checking for methods which may have been |
| 805 | /// inherited. |
Steve Naroff | b268d2a | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 806 | void CheckProtocolMethodDefs(SourceLocation ImpLoc, |
| 807 | ObjCProtocolDecl *PDecl, |
Fariborz Jahanian | d3952f3 | 2007-10-02 20:06:01 +0000 | [diff] [blame] | 808 | bool& IncompleteImpl, |
Steve Naroff | 7711ee3 | 2007-10-08 21:05:34 +0000 | [diff] [blame] | 809 | const llvm::DenseSet<Selector> &InsMap, |
Daniel Dunbar | 1d706e9 | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 810 | const llvm::DenseSet<Selector> &ClsMap, |
| 811 | ObjCInterfaceDecl *IDecl); |
Fariborz Jahanian | f7cf3a6 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 812 | |
Steve Naroff | 89529b1 | 2007-10-02 21:43:37 +0000 | [diff] [blame] | 813 | /// CheckImplementationIvars - This routine checks if the instance variables |
| 814 | /// listed in the implelementation match those listed in the interface. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 815 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
| 816 | ObjCIvarDecl **Fields, unsigned nIvars, |
Steve Naroff | b4f4851 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 817 | SourceLocation Loc); |
Steve Naroff | 89529b1 | 2007-10-02 21:43:37 +0000 | [diff] [blame] | 818 | |
Fariborz Jahanian | f7cf3a6 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 819 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
| 820 | /// remains unimplemented in the @implementation class. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 821 | void ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl, |
| 822 | ObjCInterfaceDecl* IDecl); |
Fariborz Jahanian | f7cf3a6 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 823 | |
Fariborz Jahanian | a91aa32 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 824 | /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the |
| 825 | /// category interface is implemented in the category @implementation. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 826 | void ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl, |
| 827 | ObjCCategoryDecl *CatClassDecl); |
Fariborz Jahanian | 67907bd | 2007-10-05 18:00:57 +0000 | [diff] [blame] | 828 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
| 829 | /// true, or false, accordingly. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 830 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
Steve Naroff | b91afca | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 831 | const ObjCMethodDecl *PrevMethod, |
| 832 | bool matchBasedOnSizeAndAlignment = false); |
Steve Naroff | ee1de13 | 2007-10-10 21:53:07 +0000 | [diff] [blame] | 833 | |
Steve Naroff | 8255b04 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 834 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
| 835 | /// unit are added to a global pool. This allows us to efficiently associate |
| 836 | /// a selector with a method declaraation for purposes of typechecking |
| 837 | /// messages sent to "id" (where the class of the object is unknown). |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 838 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method); |
Steve Naroff | 8255b04 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 839 | |
Steve Naroff | 68354f3 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 840 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
| 841 | /// there are multiple signatures. |
| 842 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R); |
| 843 | |
Steve Naroff | 8255b04 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 844 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 845 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 846 | //===--------------------------------------------------------------------===// |
| 847 | // Statement Parsing Callbacks: SemaStmt.cpp. |
| 848 | public: |
Sebastian Redl | 76b9ddb | 2008-12-21 12:04:03 +0000 | [diff] [blame] | 849 | virtual OwningStmtResult ActOnExprStmt(ExprArg Expr); |
| 850 | |
| 851 | virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc); |
| 852 | virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
| 853 | MultiStmtArg Elts, |
| 854 | bool isStmtExpr); |
| 855 | virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc, |
| 856 | SourceLocation EndLoc); |
Sebastian Redl | 0a23e8f | 2008-12-28 16:13:43 +0000 | [diff] [blame] | 857 | virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal, |
| 858 | SourceLocation DotDotDotLoc, ExprArg RHSVal, |
| 859 | SourceLocation ColonLoc, StmtArg SubStmt); |
| 860 | virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
| 861 | SourceLocation ColonLoc, |
| 862 | StmtArg SubStmt, Scope *CurScope); |
Sebastian Redl | 2437ec6 | 2009-01-11 00:38:46 +0000 | [diff] [blame] | 863 | virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc, |
| 864 | IdentifierInfo *II, |
| 865 | SourceLocation ColonLoc, |
| 866 | StmtArg SubStmt); |
| 867 | virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal, |
| 868 | StmtArg ThenVal, SourceLocation ElseLoc, |
| 869 | StmtArg ElseVal); |
| 870 | virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond); |
| 871 | virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
| 872 | StmtArg Switch, StmtArg Body); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 873 | virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 874 | StmtTy *Body); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 875 | virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 876 | SourceLocation WhileLoc, ExprTy *Cond); |
| 877 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 878 | virtual StmtResult ActOnForStmt(SourceLocation ForLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 879 | SourceLocation LParenLoc, |
| 880 | StmtTy *First, ExprTy *Second, ExprTy *Third, |
| 881 | SourceLocation RParenLoc, StmtTy *Body); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 882 | virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
Fariborz Jahanian | 1300bc7 | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 883 | SourceLocation LParenLoc, |
| 884 | StmtTy *First, ExprTy *Second, |
| 885 | SourceLocation RParenLoc, StmtTy *Body); |
| 886 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 887 | virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 888 | SourceLocation LabelLoc, |
| 889 | IdentifierInfo *LabelII); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 890 | virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 891 | SourceLocation StarLoc, |
| 892 | ExprTy *DestExp); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 893 | virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 894 | Scope *CurScope); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 895 | virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 896 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 897 | virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 898 | ExprTy *RetValExp); |
Steve Naroff | 52a81c0 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 899 | StmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 900 | |
Anders Carlsson | 076c111 | 2007-11-20 19:21:03 +0000 | [diff] [blame] | 901 | virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | de6a9c4 | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 902 | bool IsSimple, |
Anders Carlsson | 759f45d | 2007-11-23 23:12:25 +0000 | [diff] [blame] | 903 | bool IsVolatile, |
Anders Carlsson | 965d520 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 904 | unsigned NumOutputs, |
| 905 | unsigned NumInputs, |
| 906 | std::string *Names, |
| 907 | ExprTy **Constraints, |
| 908 | ExprTy **Exprs, |
Anders Carlsson | 076c111 | 2007-11-20 19:21:03 +0000 | [diff] [blame] | 909 | ExprTy *AsmString, |
Anders Carlsson | 965d520 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 910 | unsigned NumClobbers, |
| 911 | ExprTy **Clobbers, |
Chris Lattner | 8a40a83 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 912 | SourceLocation RParenLoc); |
| 913 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 914 | virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 915 | SourceLocation RParen, StmtTy *Parm, |
| 916 | StmtTy *Body, StmtTy *CatchList); |
| 917 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 918 | virtual StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, |
Fariborz Jahanian | de3abf8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 919 | StmtTy *Body); |
| 920 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 921 | virtual StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, |
Fariborz Jahanian | b8bf607 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 922 | StmtTy *Try, |
| 923 | StmtTy *Catch, StmtTy *Finally); |
| 924 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 925 | virtual StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, |
Fariborz Jahanian | 08df2c6 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 926 | StmtTy *Throw); |
Fariborz Jahanian | c9fd4d1 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 927 | virtual StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 928 | ExprTy *SynchExpr, |
| 929 | StmtTy *SynchBody); |
Sebastian Redl | b12ac33 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 930 | |
Sebastian Redl | 743c816 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 931 | virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
| 932 | virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
| 933 | DeclTy *ExDecl, |
| 934 | StmtArg HandlerBlock); |
Sebastian Redl | 237116b | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 935 | virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc, |
| 936 | StmtArg TryBlock, |
| 937 | MultiStmtArg Handlers); |
Sebastian Redl | b12ac33 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 938 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 939 | //===--------------------------------------------------------------------===// |
| 940 | // Expression Parsing Callbacks: SemaExpr.cpp. |
| 941 | |
| 942 | // Primary Expressions. |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 943 | virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 944 | IdentifierInfo &II, |
Argiris Kirtzidis | 311db8c | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 945 | bool HasTrailingLParen, |
| 946 | const CXXScopeSpec *SS = 0); |
Douglas Gregor | 2409477 | 2008-11-19 19:09:45 +0000 | [diff] [blame] | 947 | virtual ExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S, |
| 948 | SourceLocation OperatorLoc, |
| 949 | OverloadedOperatorKind Op, |
| 950 | bool HasTrailingLParen, |
| 951 | const CXXScopeSpec &SS); |
| 952 | virtual ExprResult ActOnCXXConversionFunctionExpr(Scope *S, |
| 953 | SourceLocation OperatorLoc, |
| 954 | TypeTy *Ty, |
| 955 | bool HasTrailingLParen, |
| 956 | const CXXScopeSpec &SS); |
Douglas Gregor | 566782a | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 957 | DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc, |
| 958 | bool TypeDependent, bool ValueDependent, |
| 959 | const CXXScopeSpec *SS = 0); |
Douglas Gregor | 723d333 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 960 | ExprResult |
| 961 | BuildAnonymousStructUnionMemberReference(SourceLocation Loc, |
| 962 | FieldDecl *Field, |
| 963 | Expr *BaseObjectExpr = 0, |
| 964 | SourceLocation OpLoc = SourceLocation()); |
Douglas Gregor | aee3bf8 | 2008-11-18 15:03:34 +0000 | [diff] [blame] | 965 | ExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, |
| 966 | DeclarationName Name, |
| 967 | bool HasTrailingLParen, |
Douglas Gregor | a133e26 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 968 | const CXXScopeSpec *SS, |
| 969 | bool ForceResolution = false); |
Douglas Gregor | aee3bf8 | 2008-11-18 15:03:34 +0000 | [diff] [blame] | 970 | |
| 971 | |
Chris Lattner | 6990929 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 972 | virtual ExprResult ActOnPredefinedExpr(SourceLocation Loc, |
| 973 | tok::TokenKind Kind); |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 974 | virtual ExprResult ActOnNumericConstant(const Token &); |
| 975 | virtual ExprResult ActOnCharacterConstant(const Token &); |
| 976 | virtual ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 977 | ExprTy *Val); |
| 978 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 979 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 980 | /// fragments (e.g. "foo" "bar" L"baz"). |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 981 | virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 982 | |
| 983 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
Douglas Gregor | 4f6904d | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 984 | virtual ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, |
| 985 | tok::TokenKind Op, ExprTy *Input); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 986 | virtual ExprResult |
Sebastian Redl | 0cb7c87 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 987 | ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType, |
| 988 | void *TyOrEx, const SourceRange &ArgRange); |
| 989 | |
| 990 | bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc, |
| 991 | const SourceRange &R, bool isSizeof); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 992 | |
Douglas Gregor | 4f6904d | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 993 | virtual ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 994 | tok::TokenKind Kind, ExprTy *Input); |
| 995 | |
Douglas Gregor | 80723c5 | 2008-11-19 17:17:41 +0000 | [diff] [blame] | 996 | virtual ExprResult ActOnArraySubscriptExpr(Scope *S, ExprTy *Base, |
| 997 | SourceLocation LLoc, ExprTy *Idx, |
| 998 | SourceLocation RLoc); |
Douglas Gregor | ddfd9d5 | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 999 | virtual ExprResult ActOnMemberReferenceExpr(Scope *S, ExprTy *Base, |
| 1000 | SourceLocation OpLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1001 | tok::TokenKind OpKind, |
| 1002 | SourceLocation MemberLoc, |
| 1003 | IdentifierInfo &Member); |
Douglas Gregor | 3257fb5 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 1004 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
| 1005 | FunctionDecl *FDecl, |
| 1006 | const FunctionTypeProto *Proto, |
| 1007 | Expr **Args, unsigned NumArgs, |
| 1008 | SourceLocation RParenLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1009 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1010 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1011 | /// This provides the location of the left/right parens and a list of comma |
| 1012 | /// locations. |
Douglas Gregor | a133e26 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 1013 | virtual ExprResult ActOnCallExpr(Scope *S, ExprTy *Fn, |
| 1014 | SourceLocation LParenLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1015 | ExprTy **Args, unsigned NumArgs, |
| 1016 | SourceLocation *CommaLocs, |
| 1017 | SourceLocation RParenLoc); |
| 1018 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1019 | virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1020 | SourceLocation RParenLoc, ExprTy *Op); |
| 1021 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1022 | virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1023 | SourceLocation RParenLoc, ExprTy *Op); |
| 1024 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1025 | virtual ExprResult ActOnInitList(SourceLocation LParenLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1026 | ExprTy **InitList, unsigned NumInit, |
Chris Lattner | ce236e7 | 2008-10-26 23:35:51 +0000 | [diff] [blame] | 1027 | InitListDesignations &Designators, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1028 | SourceLocation RParenLoc); |
| 1029 | |
Douglas Gregor | d7f915e | 2008-11-06 23:29:22 +0000 | [diff] [blame] | 1030 | virtual ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
| 1031 | tok::TokenKind Kind, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1032 | ExprTy *LHS,ExprTy *RHS); |
Douglas Gregor | d7f915e | 2008-11-06 23:29:22 +0000 | [diff] [blame] | 1033 | ExprResult CreateBuiltinBinOp(SourceLocation TokLoc, |
| 1034 | unsigned Opc, |
| 1035 | Expr *lhs, Expr *rhs); |
| 1036 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1037 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1038 | /// in the case of a the GNU conditional expr extension. |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1039 | virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1040 | SourceLocation ColonLoc, |
| 1041 | ExprTy *Cond, ExprTy *LHS, ExprTy *RHS); |
| 1042 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1043 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
| 1044 | virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1045 | IdentifierInfo *LabelII); |
| 1046 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1047 | virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1048 | SourceLocation RPLoc); // "({..})" |
Chris Lattner | 0d9bcea | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 1049 | |
| 1050 | /// __builtin_offsetof(type, a.b[123][456].c) |
Douglas Gregor | ddfd9d5 | 2008-12-23 00:26:44 +0000 | [diff] [blame] | 1051 | virtual ExprResult ActOnBuiltinOffsetOf(Scope *S, |
| 1052 | SourceLocation BuiltinLoc, |
Chris Lattner | 0d9bcea | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 1053 | SourceLocation TypeLoc, TypeTy *Arg1, |
| 1054 | OffsetOfComponent *CompPtr, |
| 1055 | unsigned NumComponents, |
| 1056 | SourceLocation RParenLoc); |
| 1057 | |
Steve Naroff | 63bad2d | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 1058 | // __builtin_types_compatible_p(type1, type2) |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1059 | virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, |
Steve Naroff | 63bad2d | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 1060 | TypeTy *arg1, TypeTy *arg2, |
| 1061 | SourceLocation RPLoc); |
Steve Naroff | 93c5301 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 1062 | |
| 1063 | // __builtin_choose_expr(constExpr, expr1, expr2) |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1064 | virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
Steve Naroff | 93c5301 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 1065 | ExprTy *cond, ExprTy *expr1, ExprTy *expr2, |
| 1066 | SourceLocation RPLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1067 | |
Nate Begeman | 9f3bfb7 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 1068 | // __builtin_overload(...) |
| 1069 | virtual ExprResult ActOnOverloadExpr(ExprTy **Args, unsigned NumArgs, |
| 1070 | SourceLocation *CommaLocs, |
| 1071 | SourceLocation BuiltinLoc, |
| 1072 | SourceLocation RParenLoc); |
Nate Begeman | d75d28b | 2008-03-07 20:04:22 +0000 | [diff] [blame] | 1073 | |
Anders Carlsson | 3676033 | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 1074 | // __builtin_va_arg(expr, type) |
| 1075 | virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc, |
| 1076 | ExprTy *expr, TypeTy *type, |
| 1077 | SourceLocation RPLoc); |
Steve Naroff | 52a81c0 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1078 | |
Douglas Gregor | ad4b379 | 2008-11-29 04:51:27 +0000 | [diff] [blame] | 1079 | // __null |
| 1080 | virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
| 1081 | |
Steve Naroff | 52a81c0 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1082 | //===------------------------- "Block" Extension ------------------------===// |
| 1083 | |
| 1084 | /// ActOnBlockStart - This callback is invoked when a block literal is |
| 1085 | /// started. |
Steve Naroff | 5205938 | 2008-10-10 01:28:17 +0000 | [diff] [blame] | 1086 | virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
| 1087 | |
| 1088 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
| 1089 | /// If there are no arguments, this is still invoked. |
| 1090 | virtual void ActOnBlockArguments(Declarator &ParamInfo); |
Steve Naroff | 52a81c0 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1091 | |
| 1092 | /// ActOnBlockError - If there is an error parsing a block, this callback |
| 1093 | /// is invoked to pop the information about the block from the action impl. |
| 1094 | virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
| 1095 | |
| 1096 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
| 1097 | /// literal was successfully completed. ^(int x){...} |
| 1098 | virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body, |
| 1099 | Scope *CurScope); |
| 1100 | |
Argiris Kirtzidis | 03e6aaf | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 1101 | // Act on C++ namespaces |
| 1102 | virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc, |
| 1103 | IdentifierInfo *Ident, |
| 1104 | SourceLocation LBrace); |
| 1105 | virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace); |
| 1106 | |
Douglas Gregor | 5ff0ee5 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 1107 | virtual DeclTy *ActOnUsingDirective(Scope *CurScope, |
| 1108 | SourceLocation UsingLoc, |
| 1109 | SourceLocation NamespcLoc, |
| 1110 | const CXXScopeSpec &SS, |
| 1111 | SourceLocation IdentLoc, |
| 1112 | IdentifierInfo *NamespcName, |
| 1113 | AttributeList *AttrList); |
| 1114 | |
Argiris Kirtzidis | 9e55d46 | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 1115 | /// AddCXXDirectInitializerToDecl - This action is called immediately after |
| 1116 | /// ActOnDeclarator, when a C++ direct initializer is present. |
| 1117 | /// e.g: "int x(1);" |
| 1118 | virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl, |
| 1119 | SourceLocation LParenLoc, |
| 1120 | ExprTy **Exprs, unsigned NumExprs, |
| 1121 | SourceLocation *CommaLocs, |
| 1122 | SourceLocation RParenLoc); |
| 1123 | |
Douglas Gregor | 6428e76 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1124 | /// InitializationKind - Represents which kind of C++ initialization |
| 1125 | /// [dcl.init] a routine is to perform. |
| 1126 | enum InitializationKind { |
| 1127 | IK_Direct, ///< Direct initialization |
| 1128 | IK_Copy, ///< Copy initialization |
| 1129 | IK_Default ///< Default initialization |
| 1130 | }; |
| 1131 | |
Douglas Gregor | 5870a95 | 2008-11-03 20:45:27 +0000 | [diff] [blame] | 1132 | CXXConstructorDecl * |
Douglas Gregor | 6428e76 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1133 | PerformInitializationByConstructor(QualType ClassType, |
| 1134 | Expr **Args, unsigned NumArgs, |
| 1135 | SourceLocation Loc, SourceRange Range, |
Chris Lattner | 271d4c2 | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 1136 | DeclarationName InitEntity, |
Douglas Gregor | 6428e76 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1137 | InitializationKind Kind); |
Douglas Gregor | 5870a95 | 2008-11-03 20:45:27 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | 21a04f3 | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 1139 | /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. |
| 1140 | virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, |
| 1141 | SourceLocation LAngleBracketLoc, TypeTy *Ty, |
| 1142 | SourceLocation RAngleBracketLoc, |
| 1143 | SourceLocation LParenLoc, ExprTy *E, |
| 1144 | SourceLocation RParenLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1145 | |
Sebastian Redl | b93b49c | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1146 | /// ActOnCXXTypeidOfType - Parse typeid( type-id ). |
| 1147 | virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
| 1148 | SourceLocation LParenLoc, bool isType, |
| 1149 | void *TyOrExpr, SourceLocation RParenLoc); |
| 1150 | |
Argiris Kirtzidis | 38f1671 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1151 | //// ActOnCXXThis - Parse 'this' pointer. |
| 1152 | virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc); |
| 1153 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1154 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
| 1155 | virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1156 | tok::TokenKind Kind); |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1157 | |
Chris Lattner | a7447ba | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1158 | //// ActOnCXXThrow - Parse throw expressions. |
| 1159 | virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc, |
| 1160 | ExprTy *expr); |
| 1161 | |
Argiris Kirtzidis | 7a1e741 | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1162 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
| 1163 | /// Can be interpreted either as function-style casting ("int(x)") |
| 1164 | /// or class type construction ("ClassType(x,y,z)") |
| 1165 | /// or creation of a value-initialized type ("int()"). |
| 1166 | virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange, |
| 1167 | TypeTy *TypeRep, |
| 1168 | SourceLocation LParenLoc, |
| 1169 | ExprTy **Exprs, |
| 1170 | unsigned NumExprs, |
| 1171 | SourceLocation *CommaLocs, |
| 1172 | SourceLocation RParenLoc); |
| 1173 | |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1174 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
| 1175 | virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
| 1176 | SourceLocation PlacementLParen, |
| 1177 | ExprTy **PlacementArgs, unsigned NumPlaceArgs, |
| 1178 | SourceLocation PlacementRParen, |
Sebastian Redl | 66df3ef | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 1179 | bool ParenTypeId, Declarator &D, |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1180 | SourceLocation ConstructorLParen, |
| 1181 | ExprTy **ConstructorArgs, unsigned NumConsArgs, |
| 1182 | SourceLocation ConstructorRParen); |
Sebastian Redl | 66df3ef | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 1183 | bool CheckAllocatedType(QualType AllocType, const Declarator &D); |
Sebastian Redl | b5ee874 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 1184 | bool FindAllocationFunctions(SourceLocation StartLoc, bool UseGlobal, |
| 1185 | QualType AllocType, bool IsArray, |
| 1186 | Expr **PlaceArgs, unsigned NumPlaceArgs, |
| 1187 | FunctionDecl *&OperatorNew, |
| 1188 | FunctionDecl *&OperatorDelete); |
Sebastian Redl | ec5f326 | 2008-12-04 22:20:51 +0000 | [diff] [blame] | 1189 | bool FindAllocationOverload(SourceLocation StartLoc, DeclarationName Name, |
| 1190 | Expr** Args, unsigned NumArgs, DeclContext *Ctx, |
| 1191 | bool AllowMissing, FunctionDecl *&Operator); |
Sebastian Redl | b5ee874 | 2008-12-03 20:26:15 +0000 | [diff] [blame] | 1192 | void DeclareGlobalNewDelete(); |
| 1193 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
| 1194 | QualType Argument); |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1195 | |
| 1196 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
| 1197 | virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, |
| 1198 | bool ArrayForm, ExprTy *Operand); |
| 1199 | |
Argiris Kirtzidis | 810c0f7 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 1200 | /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a |
| 1201 | /// C++ if/switch/while/for statement. |
| 1202 | /// e.g: "if (int x = f()) {...}" |
| 1203 | virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S, |
| 1204 | SourceLocation StartLoc, |
| 1205 | Declarator &D, |
| 1206 | SourceLocation EqualLoc, |
| 1207 | ExprTy *AssignExprVal); |
| 1208 | |
Sebastian Redl | 39c0f6f | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1209 | /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support |
| 1210 | /// pseudo-functions. |
| 1211 | virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, |
| 1212 | SourceLocation KWLoc, |
| 1213 | SourceLocation LParen, |
| 1214 | TypeTy *Ty, |
| 1215 | SourceLocation RParen); |
| 1216 | |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1217 | /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the |
| 1218 | /// global scope ('::'). |
| 1219 | virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S, |
| 1220 | SourceLocation CCLoc); |
| 1221 | |
| 1222 | /// ActOnCXXNestedNameSpecifier - Called during parsing of a |
| 1223 | /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now |
| 1224 | /// we want to resolve "bar::". 'SS' is empty or the previously parsed |
| 1225 | /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar', |
| 1226 | /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'. |
| 1227 | /// Returns a CXXScopeTy* object representing the C++ scope. |
| 1228 | virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S, |
| 1229 | const CXXScopeSpec &SS, |
| 1230 | SourceLocation IdLoc, |
| 1231 | SourceLocation CCLoc, |
Douglas Gregor | b0212bd | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 1232 | IdentifierInfo &II); |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1233 | |
| 1234 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
| 1235 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
| 1236 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
| 1237 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
| 1238 | /// ActOnCXXExitDeclaratorScope is called. |
| 1239 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
| 1240 | virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
| 1241 | |
| 1242 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
| 1243 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
| 1244 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
| 1245 | /// Used to indicate that names should revert to being looked up in the |
| 1246 | /// defining scope. |
Douglas Gregor | 24effa8 | 2008-12-16 00:38:16 +0000 | [diff] [blame] | 1247 | virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 1248 | |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1249 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
Chris Lattner | ddd3e63 | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1250 | virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
| 1251 | ExprTy **Strings, |
| 1252 | unsigned NumStrings); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1253 | virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1254 | SourceLocation EncodeLoc, |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1255 | SourceLocation LParenLoc, |
| 1256 | TypeTy *Ty, |
| 1257 | SourceLocation RParenLoc); |
| 1258 | |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1259 | // ParseObjCSelectorExpression - Build selector expression for @selector |
| 1260 | virtual ExprResult ParseObjCSelectorExpression(Selector Sel, |
| 1261 | SourceLocation AtLoc, |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1262 | SourceLocation SelLoc, |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1263 | SourceLocation LParenLoc, |
| 1264 | SourceLocation RParenLoc); |
| 1265 | |
Fariborz Jahanian | b391e6e | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1266 | // ParseObjCProtocolExpression - Build protocol expression for @protocol |
| 1267 | virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, |
| 1268 | SourceLocation AtLoc, |
| 1269 | SourceLocation ProtoLoc, |
| 1270 | SourceLocation LParenLoc, |
| 1271 | SourceLocation RParenLoc); |
Douglas Gregor | ec93f44 | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1272 | |
| 1273 | //===--------------------------------------------------------------------===// |
Douglas Gregor | d802838 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 1274 | // C++ Declarations |
| 1275 | // |
| 1276 | virtual DeclTy *ActOnStartLinkageSpecification(Scope *S, |
| 1277 | SourceLocation ExternLoc, |
| 1278 | SourceLocation LangLoc, |
| 1279 | const char *Lang, |
| 1280 | unsigned StrSize, |
| 1281 | SourceLocation LBraceLoc); |
| 1282 | virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S, |
| 1283 | DeclTy *LinkageSpec, |
| 1284 | SourceLocation RBraceLoc); |
| 1285 | |
| 1286 | |
| 1287 | //===--------------------------------------------------------------------===// |
Douglas Gregor | ec93f44 | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1288 | // C++ Classes |
| 1289 | // |
Argiris Kirtzidis | 311db8c | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1290 | virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
| 1291 | const CXXScopeSpec *SS); |
Douglas Gregor | f15ac4b | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1292 | |
Argiris Kirtzidis | 38f1671 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1293 | virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, |
| 1294 | Declarator &D, ExprTy *BitfieldWidth, |
| 1295 | ExprTy *Init, DeclTy *LastInGroup); |
| 1296 | |
Douglas Gregor | a65e8dd | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1297 | virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD, |
| 1298 | Scope *S, |
| 1299 | IdentifierInfo *MemberOrBase, |
| 1300 | SourceLocation IdLoc, |
| 1301 | SourceLocation LParenLoc, |
| 1302 | ExprTy **Args, unsigned NumArgs, |
| 1303 | SourceLocation *CommaLocs, |
| 1304 | SourceLocation RParenLoc); |
| 1305 | |
Douglas Gregor | e640ab6 | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 1306 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
| 1307 | |
Argiris Kirtzidis | 38f1671 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1308 | virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, |
| 1309 | DeclTy *TagDecl, |
| 1310 | SourceLocation LBrac, |
| 1311 | SourceLocation RBrac); |
| 1312 | |
Douglas Gregor | 605de8d | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1313 | virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method); |
| 1314 | virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param); |
| 1315 | virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method); |
| 1316 | |
Douglas Gregor | 8210a8e | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1317 | bool CheckConstructorDeclarator(Declarator &D, QualType &R, |
| 1318 | FunctionDecl::StorageClass& SC); |
Douglas Gregor | 605de8d | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1319 | bool CheckConstructor(CXXConstructorDecl *Constructor); |
Douglas Gregor | 8210a8e | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1320 | bool CheckDestructorDeclarator(Declarator &D, QualType &R, |
| 1321 | FunctionDecl::StorageClass& SC); |
Douglas Gregor | 3ef6c97 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1322 | bool CheckConversionDeclarator(Declarator &D, QualType &R, |
| 1323 | FunctionDecl::StorageClass& SC); |
Douglas Gregor | 3ef6c97 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1324 | DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
Douglas Gregor | f15ac4b | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1325 | |
Douglas Gregor | 1404650 | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 1326 | //===--------------------------------------------------------------------===// |
| 1327 | // C++ Derived Classes |
| 1328 | // |
| 1329 | |
| 1330 | /// ActOnBaseSpecifier - Parsed a base specifier |
| 1331 | virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl, |
| 1332 | SourceRange SpecifierRange, |
| 1333 | bool Virtual, AccessSpecifier Access, |
| 1334 | TypeTy *basetype, SourceLocation BaseLoc); |
| 1335 | |
| 1336 | virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases, |
| 1337 | unsigned NumBases); |
| 1338 | |
| 1339 | bool IsDerivedFrom(QualType Derived, QualType Base); |
Douglas Gregor | bb46150 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 1340 | bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths); |
Douglas Gregor | 29dfa2f | 2009-01-15 00:26:24 +0000 | [diff] [blame] | 1341 | bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria, |
| 1342 | BasePaths &Paths); |
Douglas Gregor | 651d1cc | 2008-10-24 16:17:19 +0000 | [diff] [blame] | 1343 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
| 1344 | SourceLocation Loc, SourceRange Range); |
Douglas Gregor | b9ef055 | 2009-01-16 00:38:09 +0000 | [diff] [blame] | 1345 | std::string getAmbiguousPathsDisplayString(BasePaths &Paths); |
Douglas Gregor | ec93f44 | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1346 | |
Douglas Gregor | e60e5d3 | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 1347 | //===--------------------------------------------------------------------===// |
| 1348 | // C++ Overloaded Operators [C++ 13.5] |
| 1349 | // |
| 1350 | |
| 1351 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
| 1352 | |
Douglas Gregor | dd86106 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1353 | //===--------------------------------------------------------------------===// |
| 1354 | // C++ Templates [C++ 14] |
| 1355 | // |
Douglas Gregor | 2fa1044 | 2008-12-18 19:37:40 +0000 | [diff] [blame] | 1356 | virtual DeclTy *isTemplateName(IdentifierInfo &II, Scope *S, |
| 1357 | const CXXScopeSpec *SS = 0); |
Douglas Gregor | dd86106 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1358 | bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); |
| 1359 | virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename, |
| 1360 | SourceLocation KeyLoc, |
| 1361 | IdentifierInfo *ParamName, |
Douglas Gregor | 5247343 | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 1362 | SourceLocation ParamNameLoc, |
| 1363 | unsigned Depth, unsigned Position); |
| 1364 | virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
| 1365 | unsigned Depth, |
| 1366 | unsigned Position); |
| 1367 | virtual TemplateParamsTy * |
| 1368 | ActOnTemplateParameterList(unsigned Depth, |
| 1369 | SourceLocation ExportLoc, |
| 1370 | SourceLocation TemplateLoc, |
| 1371 | SourceLocation LAngleLoc, |
| 1372 | DeclTy **Params, unsigned NumParams, |
| 1373 | SourceLocation RAngleLoc); |
| 1374 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1375 | // Objective-C declarations. |
Chris Lattner | ae1ae49 | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 1376 | virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, |
| 1377 | IdentifierInfo *ClassName, |
| 1378 | SourceLocation ClassLoc, |
| 1379 | IdentifierInfo *SuperName, |
| 1380 | SourceLocation SuperLoc, |
| 1381 | DeclTy * const *ProtoRefs, |
| 1382 | unsigned NumProtoRefs, |
| 1383 | SourceLocation EndProtoLoc, |
| 1384 | AttributeList *AttrList); |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1385 | |
| 1386 | virtual DeclTy *ActOnCompatiblityAlias( |
| 1387 | SourceLocation AtCompatibilityAliasLoc, |
| 1388 | IdentifierInfo *AliasName, SourceLocation AliasLocation, |
| 1389 | IdentifierInfo *ClassName, SourceLocation ClassLocation); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1390 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1391 | virtual DeclTy *ActOnStartProtocolInterface( |
Nate Begeman | 43f307d | 2008-02-20 22:57:40 +0000 | [diff] [blame] | 1392 | SourceLocation AtProtoInterfaceLoc, |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 1393 | IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, |
Chris Lattner | 2bdedd6 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1394 | DeclTy * const *ProtoRefNames, unsigned NumProtoRefs, |
Daniel Dunbar | 28680d1 | 2008-09-26 04:48:09 +0000 | [diff] [blame] | 1395 | SourceLocation EndProtoLoc, |
| 1396 | AttributeList *AttrList); |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 1397 | |
Chris Lattner | 45142b9 | 2008-07-26 04:07:02 +0000 | [diff] [blame] | 1398 | virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, |
| 1399 | IdentifierInfo *ClassName, |
| 1400 | SourceLocation ClassLoc, |
| 1401 | IdentifierInfo *CategoryName, |
| 1402 | SourceLocation CategoryLoc, |
| 1403 | DeclTy * const *ProtoRefs, |
| 1404 | unsigned NumProtoRefs, |
| 1405 | SourceLocation EndProtoLoc); |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 1406 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1407 | virtual DeclTy *ActOnStartClassImplementation( |
Nate Begeman | 43f307d | 2008-02-20 22:57:40 +0000 | [diff] [blame] | 1408 | SourceLocation AtClassImplLoc, |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1409 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 1410 | IdentifierInfo *SuperClassname, |
| 1411 | SourceLocation SuperClassLoc); |
| 1412 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1413 | virtual DeclTy *ActOnStartCategoryImplementation( |
Fariborz Jahanian | a91aa32 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 1414 | SourceLocation AtCatImplLoc, |
| 1415 | IdentifierInfo *ClassName, |
| 1416 | SourceLocation ClassLoc, |
| 1417 | IdentifierInfo *CatName, |
| 1418 | SourceLocation CatLoc); |
| 1419 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1420 | virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc, |
Steve Naroff | b4dfe36 | 2007-10-02 22:39:18 +0000 | [diff] [blame] | 1421 | IdentifierInfo **IdentList, |
| 1422 | unsigned NumElts); |
Fariborz Jahanian | c716c94 | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 1423 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1424 | virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, |
Chris Lattner | e705e5e | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1425 | const IdentifierLocPair *IdentList, |
Fariborz Jahanian | 8f9b1b2 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 1426 | unsigned NumElts, |
| 1427 | AttributeList *attrList); |
Fariborz Jahanian | a096e1d | 2007-10-05 21:01:53 +0000 | [diff] [blame] | 1428 | |
Chris Lattner | 2bdedd6 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1429 | virtual void FindProtocolDeclaration(bool WarnOnDeclarations, |
Chris Lattner | e705e5e | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1430 | const IdentifierLocPair *ProtocolId, |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1431 | unsigned NumProtocols, |
Chris Lattner | e705e5e | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1432 | llvm::SmallVectorImpl<DeclTy *> &Protocols); |
Fariborz Jahanian | ed98660 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 1433 | |
Daniel Dunbar | 540ff47 | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1434 | /// Ensure attributes are consistent with type. |
| 1435 | /// \param [in, out] Attributes The attributes to check; they will |
| 1436 | /// be modified to be consistent with \arg PropertyTy. |
| 1437 | void CheckObjCPropertyAttributes(QualType PropertyTy, |
| 1438 | SourceLocation Loc, |
| 1439 | unsigned &Attributes); |
Steve Naroff | ab63fd6 | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 1440 | void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC); |
Fariborz Jahanian | ed98660 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 1441 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
| 1442 | ObjCPropertyDecl *SuperProperty, |
Chris Lattner | d120b9e | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 1443 | const IdentifierInfo *Name); |
Fariborz Jahanian | ed98660 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 1444 | void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); |
Fariborz Jahanian | 1e89de3 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 1445 | |
Fariborz Jahanian | acad6d1 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 1446 | void MergeProtocolPropertiesIntoClass(Decl *CDecl, |
Fariborz Jahanian | 33973a2 | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 1447 | DeclTy *MergeProtocols); |
| 1448 | |
Fariborz Jahanian | acad6d1 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 1449 | void MergeOneProtocolPropertiesIntoClass(Decl *CDecl, |
Fariborz Jahanian | 33973a2 | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 1450 | ObjCProtocolDecl *PDecl); |
| 1451 | |
Steve Naroff | b82c50f | 2007-11-11 17:19:15 +0000 | [diff] [blame] | 1452 | virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, |
| 1453 | DeclTy **allMethods = 0, unsigned allNum = 0, |
| 1454 | DeclTy **allProperties = 0, unsigned pNum = 0); |
Fariborz Jahanian | d34caf9 | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 1455 | |
Fariborz Jahanian | 0ceb4be | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 1456 | virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc, |
Fariborz Jahanian | 4aa72a7 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 1457 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
Fariborz Jahanian | b7080ae | 2008-05-06 18:09:04 +0000 | [diff] [blame] | 1458 | Selector GetterSel, Selector SetterSel, |
Fariborz Jahanian | bcda0b4 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1459 | DeclTy *ClassCategory, bool *OverridingProperty, |
Fariborz Jahanian | 4aa72a7 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 1460 | tok::ObjCKeywordKind MethodImplKind); |
| 1461 | |
Fariborz Jahanian | 78f7e31 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1462 | virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc, |
| 1463 | SourceLocation PropertyLoc, |
| 1464 | bool ImplKind, DeclTy *ClassImplDecl, |
| 1465 | IdentifierInfo *PropertyId, |
| 1466 | IdentifierInfo *PropertyIvar); |
| 1467 | |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 1468 | virtual DeclTy *ActOnMethodDeclaration( |
| 1469 | SourceLocation BeginLoc, // location of the + or -. |
| 1470 | SourceLocation EndLoc, // location of the ; or {. |
Fariborz Jahanian | 8473b22 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 1471 | tok::TokenKind MethodType, |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1472 | DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, |
Fariborz Jahanian | 2fd0daa | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 1473 | Selector Sel, |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1474 | // optional arguments. The number of types/arguments is obtained |
| 1475 | // from the Sel.getNumArgs(). |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1476 | ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames, |
Fariborz Jahanian | 89d5304 | 2009-01-09 00:38:19 +0000 | [diff] [blame] | 1477 | llvm::SmallVectorImpl<Declarator> &Cdecls, |
Steve Naroff | 29fe746 | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 1478 | AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, |
| 1479 | bool isVariadic = false); |
Steve Naroff | 5266418 | 2007-10-16 23:12:48 +0000 | [diff] [blame] | 1480 | |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1481 | // ActOnClassMessage - used for both unary and keyword messages. |
| 1482 | // ArgExprs is optional - if it is present, the number of expressions |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1483 | // is obtained from NumArgs. |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1484 | virtual ExprResult ActOnClassMessage( |
Fariborz Jahanian | 2ce5dc5 | 2007-11-12 20:13:27 +0000 | [diff] [blame] | 1485 | Scope *S, |
Steve Naroff | 6cb1d36 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 1486 | IdentifierInfo *receivingClassName, Selector Sel, |
Steve Naroff | c64a53d | 2008-11-19 15:54:23 +0000 | [diff] [blame] | 1487 | SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac, |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1488 | ExprTy **ArgExprs, unsigned NumArgs); |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1489 | |
| 1490 | // ActOnInstanceMessage - used for both unary and keyword messages. |
| 1491 | // ArgExprs is optional - if it is present, the number of expressions |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1492 | // is obtained from NumArgs. |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1493 | virtual ExprResult ActOnInstanceMessage( |
Steve Naroff | 6cb1d36 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 1494 | ExprTy *receiver, Selector Sel, |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1495 | SourceLocation lbrac, SourceLocation rbrac, |
| 1496 | ExprTy **ArgExprs, unsigned NumArgs); |
Daniel Dunbar | 81c7d47 | 2008-10-14 05:35:18 +0000 | [diff] [blame] | 1497 | |
| 1498 | /// ActOnPragmaPack - Called on well formed #pragma pack(...). |
| 1499 | virtual void ActOnPragmaPack(PragmaPackKind Kind, |
| 1500 | IdentifierInfo *Name, |
| 1501 | ExprTy *Alignment, |
| 1502 | SourceLocation PragmaLoc, |
| 1503 | SourceLocation LParenLoc, |
| 1504 | SourceLocation RParenLoc); |
| 1505 | |
Chris Lattner | e992d6c | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 1506 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
| 1507 | /// cast. If there is already an implicit cast, merge into the existing one. |
Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 1508 | /// If isLvalue, the result of the cast is an lvalue. |
| 1509 | void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false); |
Chris Lattner | e992d6c | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 1510 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1511 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
Chris Lattner | 83bd5eb | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 1512 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
| 1513 | Expr *UsualUnaryConversions(Expr *&expr); |
Eli Friedman | 86ad522 | 2008-05-27 03:33:27 +0000 | [diff] [blame] | 1514 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1515 | // DefaultFunctionArrayConversion - converts functions and arrays |
| 1516 | // to their respective pointers (C99 6.3.2.1). |
| 1517 | void DefaultFunctionArrayConversion(Expr *&expr); |
| 1518 | |
Steve Naroff | db65e05 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 1519 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
| 1520 | // do not have a prototype. Integer promotions are performed on each |
| 1521 | // argument, and arguments that have type float are promoted to double. |
Chris Lattner | 83bd5eb | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 1522 | void DefaultArgumentPromotion(Expr *&Expr); |
Steve Naroff | db65e05 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 1523 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1524 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
| 1525 | // operands and then handles various conversions that are common to binary |
| 1526 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
| 1527 | // routine returns the first non-arithmetic type found. The client is |
| 1528 | // responsible for emitting appropriate error diagnostics. |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1529 | QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr, |
| 1530 | bool isCompAssign = false); |
Chris Lattner | d951b7b | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1531 | |
Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 1532 | /// UsualArithmeticConversionsType - handles the various conversions |
| 1533 | /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9) |
| 1534 | /// and returns the result type of that conversion. |
| 1535 | QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs); |
| 1536 | |
| 1537 | |
Chris Lattner | d951b7b | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1538 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
| 1539 | /// enum to indicate whether the assignment was allowed. These checks are |
| 1540 | /// done for simple assignments, as well as initialization, return from |
| 1541 | /// function, argument passing, etc. The query is phrased in terms of a |
| 1542 | /// source and destination type. |
Chris Lattner | 005ed75 | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 1543 | enum AssignConvertType { |
Chris Lattner | d951b7b | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1544 | /// Compatible - the types are compatible according to the standard. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1545 | Compatible, |
Chris Lattner | d951b7b | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1546 | |
| 1547 | /// PointerToInt - The assignment converts a pointer to an int, which we |
| 1548 | /// accept as an extension. |
| 1549 | PointerToInt, |
| 1550 | |
| 1551 | /// IntToPointer - The assignment converts an int to a pointer, which we |
| 1552 | /// accept as an extension. |
| 1553 | IntToPointer, |
| 1554 | |
| 1555 | /// FunctionVoidPointer - The assignment is between a function pointer and |
| 1556 | /// void*, which the standard doesn't allow, but we accept as an extension. |
Chris Lattner | 4ca3d77 | 2008-01-03 22:56:36 +0000 | [diff] [blame] | 1557 | FunctionVoidPointer, |
Chris Lattner | d951b7b | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1558 | |
| 1559 | /// IncompatiblePointer - The assignment is between two pointers types that |
| 1560 | /// are not compatible, but we accept them as an extension. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1561 | IncompatiblePointer, |
Chris Lattner | d951b7b | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1562 | |
| 1563 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
| 1564 | /// c/v/r qualifiers, which we accept as an extension. |
| 1565 | CompatiblePointerDiscardsQualifiers, |
Steve Naroff | 3454b6c | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 1566 | |
Steve Naroff | 6f37333 | 2008-09-04 15:31:07 +0000 | [diff] [blame] | 1567 | /// IntToBlockPointer - The assignment converts an int to a block |
Steve Naroff | 3454b6c | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 1568 | /// pointer. We disallow this. |
| 1569 | IntToBlockPointer, |
| 1570 | |
Steve Naroff | 6f37333 | 2008-09-04 15:31:07 +0000 | [diff] [blame] | 1571 | /// IncompatibleBlockPointer - The assignment is between two block |
Steve Naroff | 3454b6c | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 1572 | /// pointers types that are not compatible. |
| 1573 | IncompatibleBlockPointer, |
| 1574 | |
Steve Naroff | 1960843 | 2008-10-14 22:18:38 +0000 | [diff] [blame] | 1575 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
| 1576 | /// id type and something else (that is incompatible with it). For example, |
| 1577 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
| 1578 | IncompatibleObjCQualifiedId, |
| 1579 | |
Chris Lattner | d951b7b | 2008-01-04 18:22:42 +0000 | [diff] [blame] | 1580 | /// Incompatible - We reject this conversion outright, it is invalid to |
| 1581 | /// represent it in the AST. |
| 1582 | Incompatible |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1583 | }; |
Chris Lattner | 005ed75 | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 1584 | |
| 1585 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
| 1586 | /// assignment conversion type specified by ConvTy. This returns true if the |
| 1587 | /// conversion was invalid or false if the conversion was accepted. |
| 1588 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, |
| 1589 | SourceLocation Loc, |
| 1590 | QualType DstType, QualType SrcType, |
| 1591 | Expr *SrcExpr, const char *Flavor); |
| 1592 | |
| 1593 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
| 1594 | /// argument passing, variable initialization, and function return values. |
| 1595 | /// This routine is only used by the following two methods. C99 6.5.16. |
| 1596 | AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1597 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1598 | // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr, |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 1599 | // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1600 | // this routine performs the default function/array converions. |
Chris Lattner | 005ed75 | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 1601 | AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, |
| 1602 | Expr *&rExpr); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1603 | // CheckCompoundAssignmentConstraints - Type check without performing any |
| 1604 | // conversions. For compound assignments, the "Check...Operands" methods |
| 1605 | // perform the necessary conversions. |
Chris Lattner | 005ed75 | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 1606 | AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs, |
| 1607 | QualType rhs); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1608 | |
| 1609 | // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1) |
Chris Lattner | 005ed75 | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 1610 | AssignConvertType CheckPointerTypesForAssignment(QualType lhsType, |
| 1611 | QualType rhsType); |
Steve Naroff | 3454b6c | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 1612 | |
| 1613 | // Helper function for CheckAssignmentConstraints involving two |
| 1614 | // blcok pointer types. |
| 1615 | AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType, |
| 1616 | QualType rhsType); |
Douglas Gregor | 1815b3b | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 1617 | |
| 1618 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
Douglas Gregor | bb46150 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 1619 | |
Douglas Gregor | 6fd3557 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 1620 | bool PerformImplicitConversion(Expr *&From, QualType ToType, |
Douglas Gregor | 6214d8a | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 1621 | const char *Flavor, bool AllowExplicit = false); |
| 1622 | bool PerformImplicitConversion(Expr *&From, QualType ToType, |
| 1623 | const ImplicitConversionSequence& ICS, |
Douglas Gregor | 6fd3557 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 1624 | const char *Flavor); |
Douglas Gregor | bb46150 | 2008-10-24 04:54:22 +0000 | [diff] [blame] | 1625 | bool PerformImplicitConversion(Expr *&From, QualType ToType, |
Douglas Gregor | 6fd3557 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 1626 | const StandardConversionSequence& SCS, |
| 1627 | const char *Flavor); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1628 | |
| 1629 | /// the following "Check" methods will return a valid/converted QualType |
| 1630 | /// or a null QualType (indicating an error diagnostic was issued). |
| 1631 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1632 | /// type checking binary operators (subroutines of ActOnBinOp). |
Chris Lattner | 2c8bff7 | 2007-12-12 05:47:28 +0000 | [diff] [blame] | 1633 | inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1634 | inline QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1635 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1636 | inline QualType CheckRemainderOperands( // C99 6.5.5 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1637 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1638 | inline QualType CheckAdditionOperands( // C99 6.5.6 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1639 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1640 | inline QualType CheckSubtractionOperands( // C99 6.5.6 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1641 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1642 | inline QualType CheckShiftOperands( // C99 6.5.7 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1643 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 254f3bc | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 1644 | inline QualType CheckCompareOperands( // C99 6.5.8/9 |
| 1645 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1646 | inline QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1647 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1648 | inline QualType CheckLogicalOperands( // C99 6.5.[13,14] |
| 1649 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 1650 | // CheckAssignmentOperands is used for both simple and compound assignment. |
| 1651 | // For simple assignment, pass both expressions and a null converted type. |
| 1652 | // For compound assignment, pass both expressions and the converted type. |
| 1653 | inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
Steve Naroff | 0f32f43 | 2007-08-24 22:33:52 +0000 | [diff] [blame] | 1654 | Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1655 | inline QualType CheckCommaOperands( // C99 6.5.17 |
Chris Lattner | 1eafdea | 2008-11-18 01:30:42 +0000 | [diff] [blame] | 1656 | Expr *lex, Expr *&rex, SourceLocation OpLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1657 | inline QualType CheckConditionalOperands( // C99 6.5.15 |
| 1658 | Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc); |
Nate Begeman | c5f0f65 | 2008-07-14 18:02:46 +0000 | [diff] [blame] | 1659 | |
| 1660 | /// type checking for vector binary operators. |
| 1661 | inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
| 1662 | inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx, |
| 1663 | SourceLocation l, bool isRel); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1664 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 1665 | /// type checking unary operators (subroutines of ActOnUnaryOp). |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1666 | /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4 |
Sebastian Redl | 0440c8c | 2008-12-20 09:35:34 +0000 | [diff] [blame] | 1667 | QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc, |
| 1668 | bool isInc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1669 | QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc); |
| 1670 | QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc); |
Chris Lattner | 5110ad5 | 2007-08-24 21:41:10 +0000 | [diff] [blame] | 1671 | QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc); |
Steve Naroff | 1b8a46c | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 1672 | |
| 1673 | /// type checking primary expressions. |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1674 | QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc, |
Steve Naroff | 1b8a46c | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 1675 | IdentifierInfo &Comp, SourceLocation CmpLoc); |
| 1676 | |
Steve Naroff | e14e554 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 1677 | /// type checking declaration initializers (C99 6.7.8) |
Steve Naroff | c4d4a48 | 2008-05-01 22:18:59 +0000 | [diff] [blame] | 1678 | friend class InitListChecker; |
Douglas Gregor | 6428e76 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 1679 | bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType, |
Douglas Gregor | 6214d8a | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 1680 | SourceLocation InitLoc,DeclarationName InitEntity, |
| 1681 | bool DirectInit); |
| 1682 | bool CheckSingleInitializer(Expr *&simpleInit, QualType declType, |
| 1683 | bool DirectInit); |
Steve Naroff | f0b2354 | 2008-01-10 22:15:12 +0000 | [diff] [blame] | 1684 | bool CheckForConstantInitializer(Expr *e, QualType t); |
Eli Friedman | 02c22ce | 2008-05-20 13:48:25 +0000 | [diff] [blame] | 1685 | bool CheckArithmeticConstantExpression(const Expr* e); |
| 1686 | bool CheckAddressConstantExpression(const Expr* e); |
| 1687 | bool CheckAddressConstantExpressionLValue(const Expr* e); |
Steve Naroff | fc08f5e | 2008-10-27 11:34:16 +0000 | [diff] [blame] | 1688 | void InitializerElementNotConstant(const Expr *e); |
Steve Naroff | cb69fb7 | 2007-12-10 22:44:33 +0000 | [diff] [blame] | 1689 | |
Steve Naroff | 0d4e6ad | 2008-01-22 00:55:40 +0000 | [diff] [blame] | 1690 | StringLiteral *IsStringLiteralInit(Expr *Init, QualType DeclType); |
| 1691 | bool CheckStringLiteralInit(StringLiteral *strLiteral, QualType &DeclT); |
Argiris Kirtzidis | 95de23a | 2008-08-16 20:27:34 +0000 | [diff] [blame] | 1692 | |
Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 1693 | // type checking C++ declaration initializers (C++ [dcl.init]). |
| 1694 | |
| 1695 | /// ReferenceCompareResult - Expresses the result of comparing two |
| 1696 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
| 1697 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
| 1698 | enum ReferenceCompareResult { |
| 1699 | /// Ref_Incompatible - The two types are incompatible, so direct |
| 1700 | /// reference binding is not possible. |
| 1701 | Ref_Incompatible = 0, |
| 1702 | /// Ref_Related - The two types are reference-related, which means |
| 1703 | /// that their unqualified forms (T1 and T2) are either the same |
| 1704 | /// or T1 is a base class of T2. |
| 1705 | Ref_Related, |
| 1706 | /// Ref_Compatible_With_Added_Qualification - The two types are |
| 1707 | /// reference-compatible with added qualification, meaning that |
| 1708 | /// they are reference-compatible and the qualifiers on T1 (cv1) |
| 1709 | /// are greater than the qualifiers on T2 (cv2). |
| 1710 | Ref_Compatible_With_Added_Qualification, |
| 1711 | /// Ref_Compatible - The two types are reference-compatible and |
| 1712 | /// have equivalent qualifiers (cv1 == cv2). |
| 1713 | Ref_Compatible |
| 1714 | }; |
| 1715 | |
Douglas Gregor | 2aecd1f | 2008-10-29 02:00:59 +0000 | [diff] [blame] | 1716 | ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2, |
| 1717 | bool& DerivedToBase); |
Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 1718 | |
| 1719 | bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType, |
Douglas Gregor | a3b34bb | 2008-11-03 19:09:14 +0000 | [diff] [blame] | 1720 | ImplicitConversionSequence *ICS = 0, |
Douglas Gregor | 6214d8a | 2009-01-14 15:45:31 +0000 | [diff] [blame] | 1721 | bool SuppressUserConversions = false, |
| 1722 | bool AllowExplicit = false); |
Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 1723 | |
Argiris Kirtzidis | 95de23a | 2008-08-16 20:27:34 +0000 | [diff] [blame] | 1724 | /// CheckCastTypes - Check type constraints for casting between types. |
Daniel Dunbar | 5ad49de | 2008-08-20 03:55:42 +0000 | [diff] [blame] | 1725 | bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr); |
Steve Naroff | 0d4e6ad | 2008-01-22 00:55:40 +0000 | [diff] [blame] | 1726 | |
Anders Carlsson | 7437562 | 2007-11-27 07:16:40 +0000 | [diff] [blame] | 1727 | // CheckVectorCast - check type constraints for vectors. |
| 1728 | // Since vectors are an extension, there are no C standard reference for this. |
| 1729 | // We allow casting between vectors and integer datatypes of the same size. |
Anders Carlsson | f257b4c | 2007-11-27 05:51:55 +0000 | [diff] [blame] | 1730 | // returns true if the cast is invalid |
| 1731 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty); |
| 1732 | |
Daniel Dunbar | 842b5e2 | 2008-09-11 00:01:56 +0000 | [diff] [blame] | 1733 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
| 1734 | /// \param Method - May be null. |
| 1735 | /// \param [out] ReturnType - The return type of the send. |
| 1736 | /// \return true iff there were any incompatible types. |
Daniel Dunbar | 7776e10 | 2008-09-11 00:50:25 +0000 | [diff] [blame] | 1737 | bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, |
Chris Lattner | 3a8f294 | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 1738 | ObjCMethodDecl *Method, bool isClassMessage, |
Daniel Dunbar | 842b5e2 | 2008-09-11 00:01:56 +0000 | [diff] [blame] | 1739 | SourceLocation lbrac, SourceLocation rbrac, |
| 1740 | QualType &ReturnType); |
Argiris Kirtzidis | 810c0f7 | 2008-09-10 02:17:11 +0000 | [diff] [blame] | 1741 | |
| 1742 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
| 1743 | bool CheckCXXBooleanCondition(Expr *&CondExpr); |
Steve Naroff | 5266418 | 2007-10-16 23:12:48 +0000 | [diff] [blame] | 1744 | |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 1745 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
| 1746 | /// the specified width and sign. If an overflow occurs, detect it and emit |
| 1747 | /// the specified diagnostic. |
| 1748 | void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, |
| 1749 | unsigned NewWidth, bool NewSign, |
| 1750 | SourceLocation Loc, unsigned DiagID); |
| 1751 | |
Chris Lattner | fe1f403 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 1752 | bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, |
| 1753 | bool ForCompare); |
| 1754 | |
Anders Carlsson | 0a6ab17 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 1755 | /// Checks that the Objective-C declaration is declared in the global scope. |
| 1756 | /// Emits an error and marks the declaration as invalid if it's not declared |
| 1757 | /// in the global scope. |
| 1758 | bool CheckObjCDeclScope(Decl *D); |
| 1759 | |
Anders Carlsson | 3676033 | 2007-10-15 20:28:48 +0000 | [diff] [blame] | 1760 | void InitBuiltinVaListType(); |
Eli Friedman | 48fb3ee | 2008-06-03 21:01:11 +0000 | [diff] [blame] | 1761 | |
Anders Carlsson | d5201b9 | 2008-11-30 19:50:32 +0000 | [diff] [blame] | 1762 | /// VerifyIntegerConstantExpression - verifies that an expression is an ICE, |
| 1763 | /// and reports the appropriate diagnostics. Returns false on success. |
| 1764 | /// Can optionally return the value of the expression. |
Anders Carlsson | 108229a | 2008-12-06 20:33:04 +0000 | [diff] [blame] | 1765 | bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0); |
Anders Carlsson | 511425a | 2008-12-01 02:17:22 +0000 | [diff] [blame] | 1766 | |
Anders Carlsson | 108229a | 2008-12-06 20:33:04 +0000 | [diff] [blame] | 1767 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
| 1768 | /// the correct width, and that the field type is valid. |
| 1769 | /// Returns false on success. |
| 1770 | bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, |
| 1771 | QualType FieldTy, const Expr *BitWidth); |
| 1772 | |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 1773 | //===--------------------------------------------------------------------===// |
| 1774 | // Extra semantic analysis beyond the C type system |
Chris Lattner | 83bd5eb | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 1775 | private: |
Eli Friedman | d0e9d09 | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 1776 | Action::ExprResult CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall); |
Chris Lattner | 83bd5eb | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 1777 | bool CheckBuiltinCFStringArgument(Expr* Arg); |
| 1778 | bool SemaBuiltinVAStart(CallExpr *TheCall); |
| 1779 | bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); |
Eli Friedman | 8c50c62 | 2008-05-20 08:23:37 +0000 | [diff] [blame] | 1780 | bool SemaBuiltinStackAddress(CallExpr *TheCall); |
Eli Friedman | d0e9d09 | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 1781 | Action::ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); |
Daniel Dunbar | 5b0de85 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 1782 | bool SemaBuiltinPrefetch(CallExpr *TheCall); |
Daniel Dunbar | 30ad42d | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 1783 | bool SemaBuiltinObjectSize(CallExpr *TheCall); |
Ted Kremenek | 8c797c0 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 1784 | bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg, |
| 1785 | unsigned format_idx); |
| 1786 | void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr, |
| 1787 | CallExpr *TheCall, bool HasVAListArg, |
| 1788 | unsigned format_idx); |
Chris Lattner | 83bd5eb | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 1789 | void CheckPrintfArguments(CallExpr *TheCall, |
| 1790 | bool HasVAListArg, unsigned format_idx); |
Ted Kremenek | 45925ab | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 1791 | void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, |
| 1792 | SourceLocation ReturnLoc); |
Ted Kremenek | 30c6675 | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1793 | void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1794 | }; |
| 1795 | |
Steve Naroff | c4d4a48 | 2008-05-01 22:18:59 +0000 | [diff] [blame] | 1796 | class InitListChecker { |
| 1797 | Sema *SemaRef; |
| 1798 | bool hadError; |
| 1799 | |
| 1800 | void CheckImplicitInitList(InitListExpr *ParentIList, QualType T, |
| 1801 | unsigned &Index); |
Steve Naroff | 5609952 | 2008-05-06 00:23:44 +0000 | [diff] [blame] | 1802 | void CheckExplicitInitList(InitListExpr *IList, QualType &T, |
Steve Naroff | c4d4a48 | 2008-05-01 22:18:59 +0000 | [diff] [blame] | 1803 | unsigned &Index); |
| 1804 | |
Eli Friedman | 683cedf | 2008-05-19 19:16:24 +0000 | [diff] [blame] | 1805 | void CheckListElementTypes(InitListExpr *IList, QualType &DeclType, |
| 1806 | unsigned &Index); |
| 1807 | void CheckSubElementType(InitListExpr *IList, QualType ElemType, |
| 1808 | unsigned &Index); |
Steve Naroff | c4d4a48 | 2008-05-01 22:18:59 +0000 | [diff] [blame] | 1809 | // FIXME: Does DeclType need to be a reference type? |
| 1810 | void CheckScalarType(InitListExpr *IList, QualType &DeclType, |
| 1811 | unsigned &Index); |
| 1812 | void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index); |
| 1813 | void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType, |
Eli Friedman | 683cedf | 2008-05-19 19:16:24 +0000 | [diff] [blame] | 1814 | unsigned &Index); |
Steve Naroff | c4d4a48 | 2008-05-01 22:18:59 +0000 | [diff] [blame] | 1815 | void CheckArrayType(InitListExpr *IList, QualType &DeclType, unsigned &Index); |
| 1816 | |
| 1817 | int numArrayElements(QualType DeclType); |
| 1818 | int numStructUnionElements(QualType DeclType); |
| 1819 | public: |
| 1820 | InitListChecker(Sema *S, InitListExpr *IL, QualType &T); |
| 1821 | bool HadError() { return hadError; } |
| 1822 | }; |
| 1823 | |
Steve Naroff | 52a81c0 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1824 | /// BlockSemaInfo - When a block is being parsed, this contains information |
| 1825 | /// about the block. It is pointed to from Sema::CurBlock. |
| 1826 | struct BlockSemaInfo { |
| 1827 | llvm::SmallVector<ParmVarDecl*, 8> Params; |
Steve Naroff | 52a81c0 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1828 | bool hasPrototype; |
| 1829 | bool isVariadic; |
| 1830 | |
Steve Naroff | 95029d9 | 2008-10-08 18:44:00 +0000 | [diff] [blame] | 1831 | BlockDecl *TheDecl; |
| 1832 | |
Steve Naroff | 52a81c0 | 2008-09-03 18:15:37 +0000 | [diff] [blame] | 1833 | /// TheScope - This is the scope for the block itself, which contains |
| 1834 | /// arguments etc. |
| 1835 | Scope *TheScope; |
| 1836 | |
| 1837 | /// ReturnType - This will get set to block result type, by looking at |
| 1838 | /// return types, if any, in the block body. |
| 1839 | Type *ReturnType; |
| 1840 | |
| 1841 | /// PrevBlockInfo - If this is nested inside another block, this points |
| 1842 | /// to the outer block. |
| 1843 | BlockSemaInfo *PrevBlockInfo; |
| 1844 | }; |
| 1845 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1846 | |
| 1847 | } // end namespace clang |
| 1848 | |
| 1849 | #endif |