| Chris Lattner | cc67ec1 | 2006-11-09 06:54:47 +0000 | [diff] [blame] | 1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| Chris Lattner | cc67ec1 | 2006-11-09 06:54:47 +0000 | [diff] [blame] | 10 | // This file defines the Sema class, which performs semantic analysis and |
| 11 | // builds ASTs. |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| Chris Lattner | cc67ec1 | 2006-11-09 06:54:47 +0000 | [diff] [blame] | 15 | #ifndef LLVM_CLANG_AST_SEMA_H |
| 16 | #define LLVM_CLANG_AST_SEMA_H |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 17 | |
| 18 | #include "clang/Parse/Action.h" |
| Chris Lattner | e247306 | 2007-05-28 06:28:18 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/DenseMap.h" |
| Anders Carlsson | 51873c2 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 21 | #include <vector> |
| Chris Lattner | eaafe122 | 2006-11-10 05:17:58 +0000 | [diff] [blame] | 22 | #include <string> |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 23 | |
| Chris Lattner | fc1c44a | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | class APSInt; |
| 26 | } |
| 27 | |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 28 | namespace clang { |
| Chris Lattner | cb6a382 | 2006-11-10 06:20:45 +0000 | [diff] [blame] | 29 | class ASTContext; |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 30 | class Preprocessor; |
| 31 | class Decl; |
| Steve Naroff | 9324db1 | 2007-09-13 18:10:37 +0000 | [diff] [blame] | 32 | class ScopedDecl; |
| Steve Naroff | 7840336 | 2007-04-02 22:55:05 +0000 | [diff] [blame] | 33 | class Expr; |
| Steve Naroff | f33527a | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 34 | class InitListExpr; |
| Chris Lattner | c5cdf4d | 2007-01-21 07:42:07 +0000 | [diff] [blame] | 35 | class VarDecl; |
| Chris Lattner | 53621a5 | 2007-06-13 20:44:40 +0000 | [diff] [blame] | 36 | class ParmVarDecl; |
| Chris Lattner | 01564d9 | 2007-01-27 19:27:06 +0000 | [diff] [blame] | 37 | class TypedefDecl; |
| 38 | class FunctionDecl; |
| Steve Naroff | e5aa9be | 2007-04-05 22:36:20 +0000 | [diff] [blame] | 39 | class QualType; |
| Chris Lattner | 9cf21c5 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 40 | struct LangOptions; |
| 41 | struct DeclaratorChunk; |
| Chris Lattner | 146762e | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 42 | class Token; |
| Steve Naroff | 35d8515 | 2007-05-07 00:24:15 +0000 | [diff] [blame] | 43 | class IntegerLiteral; |
| Steve Naroff | 8eeeb13 | 2007-05-08 21:09:37 +0000 | [diff] [blame] | 44 | class ArrayType; |
| Chris Lattner | e247306 | 2007-05-28 06:28:18 +0000 | [diff] [blame] | 45 | class LabelStmt; |
| Anders Carlsson | 51873c2 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 46 | class SwitchStmt; |
| Steve Naroff | f8fd09e | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 47 | class OCUVectorType; |
| Steve Naroff | ddf5a1d | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 48 | class TypedefDecl; |
| Fariborz Jahanian | 343f709 | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 49 | class ObjcInterfaceDecl; |
| Fariborz Jahanian | fa0667b | 2007-09-29 17:04:06 +0000 | [diff] [blame] | 50 | class ObjcProtocolDecl; |
| Fariborz Jahanian | ec7b333 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 51 | class ObjcImplementationDecl; |
| Fariborz Jahanian | 89b8ef9 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 52 | class ObjcCategoryImplDecl; |
| 53 | class ObjcCategoryDecl; |
| Steve Naroff | ddf5a1d | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 54 | |
| Chris Lattner | cc67ec1 | 2006-11-09 06:54:47 +0000 | [diff] [blame] | 55 | /// Sema - This implements semantic analysis and AST building for C. |
| 56 | class Sema : public Action { |
| Steve Naroff | 38d31b4 | 2007-02-28 01:22:02 +0000 | [diff] [blame] | 57 | Preprocessor &PP; |
| 58 | |
| Chris Lattner | cb6a382 | 2006-11-10 06:20:45 +0000 | [diff] [blame] | 59 | ASTContext &Context; |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 60 | |
| Chris Lattner | 229ce60 | 2006-11-21 01:21:07 +0000 | [diff] [blame] | 61 | /// CurFunctionDecl - If inside of a function body, this contains a pointer to |
| 62 | /// the function decl for the function being parsed. |
| 63 | FunctionDecl *CurFunctionDecl; |
| 64 | |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 65 | /// LastInGroupList - This vector is populated when there are multiple |
| 66 | /// declarators in a single decl group (e.g. "int A, B, C"). In this case, |
| 67 | /// all but the last decl will be entered into this. This is used by the |
| 68 | /// ASTStreamer. |
| 69 | std::vector<Decl*> &LastInGroupList; |
| Chris Lattner | e247306 | 2007-05-28 06:28:18 +0000 | [diff] [blame] | 70 | |
| 71 | /// LabelMap - This is a mapping from label identifiers to the LabelStmt for |
| 72 | /// it (which acts like the label decl in some ways). Forward referenced |
| 73 | /// labels have a LabelStmt created for them with a null location & SubStmt. |
| Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 74 | llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap; |
| Anders Carlsson | 51873c2 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 75 | |
| 76 | llvm::SmallVector<SwitchStmt*, 8> SwitchStack; |
| Steve Naroff | ddf5a1d | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 77 | |
| 78 | /// OCUVectorDecls - This is a list all the OCU vector types. This allows |
| 79 | /// us to associate a raw vector type with one of the OCU type names. |
| 80 | /// This is only necessary for issuing pretty diagnostics. |
| 81 | llvm::SmallVector<TypedefDecl*, 24> OCUVectorDecls; |
| Chris Lattner | b87b1b3 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 82 | |
| 83 | // Enum values used by KnownFunctionIDs (see below). |
| 84 | enum { |
| 85 | id_printf, |
| 86 | id_fprintf, |
| 87 | id_sprintf, |
| 88 | id_snprintf, |
| Chris Lattner | b87b1b3 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 89 | id_asprintf, |
| Ted Kremenek | cfc9419 | 2007-08-10 21:13:51 +0000 | [diff] [blame] | 90 | id_vsnprintf, |
| Chris Lattner | b87b1b3 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 91 | id_vasprintf, |
| 92 | id_vfprintf, |
| 93 | id_vsprintf, |
| 94 | id_vprintf, |
| 95 | id_num_known_functions |
| 96 | }; |
| 97 | |
| 98 | /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set |
| 99 | /// of known functions used by the semantic analysis to do various |
| 100 | /// kinds of checking (e.g. checking format string errors in printf calls). |
| 101 | /// This list is populated upon the creation of a Sema object. |
| 102 | IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ]; |
| 103 | |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 104 | public: |
| Steve Naroff | 2c055d2 | 2007-02-28 19:32:13 +0000 | [diff] [blame] | 105 | Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup); |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 106 | |
| Chris Lattner | ac18be9 | 2006-11-20 06:49:47 +0000 | [diff] [blame] | 107 | const LangOptions &getLangOptions() const; |
| 108 | |
| Steve Naroff | 71ce2e0 | 2007-05-18 22:53:50 +0000 | [diff] [blame] | 109 | /// The primitive diagnostic helpers - always returns true, which simplifies |
| 110 | /// error handling (i.e. less code). |
| Chris Lattner | d6647d3 | 2007-05-16 17:56:50 +0000 | [diff] [blame] | 111 | bool Diag(SourceLocation Loc, unsigned DiagID); |
| 112 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg); |
| 113 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, |
| 114 | const std::string &Msg2); |
| Steve Naroff | 71ce2e0 | 2007-05-18 22:53:50 +0000 | [diff] [blame] | 115 | |
| 116 | /// More expressive diagnostic helpers for expressions (say that 6 times:-) |
| 117 | bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1); |
| 118 | bool Diag(SourceLocation Loc, unsigned DiagID, |
| 119 | SourceRange R1, SourceRange R2); |
| 120 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, |
| 121 | SourceRange R1); |
| 122 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, |
| 123 | SourceRange R1, SourceRange R2); |
| 124 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, |
| 125 | const std::string &Msg2, SourceRange R1); |
| 126 | bool Diag(SourceLocation Loc, unsigned DiagID, |
| 127 | const std::string &Msg1, const std::string &Msg2, |
| 128 | SourceRange R1, SourceRange R2); |
| Fariborz Jahanian | 343f709 | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 129 | |
| Chris Lattner | 57c523f | 2007-08-31 04:53:24 +0000 | [diff] [blame] | 130 | virtual void DeleteExpr(ExprTy *E); |
| 131 | virtual void DeleteStmt(StmtTy *S); |
| 132 | |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 133 | //===--------------------------------------------------------------------===// |
| Chris Lattner | f84a79c | 2006-11-11 22:59:23 +0000 | [diff] [blame] | 134 | // Type Analysis / Processing: SemaType.cpp. |
| 135 | // |
| Steve Naroff | e5aa9be | 2007-04-05 22:36:20 +0000 | [diff] [blame] | 136 | QualType GetTypeForDeclarator(Declarator &D, Scope *S); |
| Chris Lattner | f84a79c | 2006-11-11 22:59:23 +0000 | [diff] [blame] | 137 | |
| Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 138 | virtual TypeResult ActOnTypeName(Scope *S, Declarator &D); |
| Chris Lattner | f84a79c | 2006-11-11 22:59:23 +0000 | [diff] [blame] | 139 | |
| Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 140 | virtual TypeResult ActOnParamDeclaratorType(Scope *S, Declarator &D); |
| Steve Naroff | 26c8ea5 | 2007-03-21 21:08:52 +0000 | [diff] [blame] | 141 | private: |
| Chris Lattner | f84a79c | 2006-11-11 22:59:23 +0000 | [diff] [blame] | 142 | //===--------------------------------------------------------------------===// |
| Chris Lattner | e168f76 | 2006-11-10 05:29:30 +0000 | [diff] [blame] | 143 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 144 | // |
| Chris Lattner | 2ebe4bb | 2006-11-20 01:29:42 +0000 | [diff] [blame] | 145 | virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const; |
| Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 146 | virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup); |
| Steve Naroff | 6109140 | 2007-09-12 14:07:44 +0000 | [diff] [blame] | 147 | void AddInitializerToDecl(DeclTy *dcl, ExprTy *init); |
| Chris Lattner | 776fac8 | 2007-06-09 00:53:06 +0000 | [diff] [blame] | 148 | virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group); |
| 149 | |
| Chris Lattner | c5cdf4d | 2007-01-21 07:42:07 +0000 | [diff] [blame] | 150 | virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D); |
| Chris Lattner | 229ce60 | 2006-11-21 01:21:07 +0000 | [diff] [blame] | 151 | virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body); |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 152 | virtual void PopScope(SourceLocation Loc, Scope *S); |
| Chris Lattner | 01564d9 | 2007-01-27 19:27:06 +0000 | [diff] [blame] | 153 | |
| Chris Lattner | 200bdc3 | 2006-11-19 02:43:37 +0000 | [diff] [blame] | 154 | /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with |
| 155 | /// no declarator (e.g. "struct foo;") is parsed. |
| 156 | virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS); |
| 157 | |
| Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 158 | virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK, |
| Chris Lattner | f34c4da | 2007-01-23 04:08:05 +0000 | [diff] [blame] | 159 | SourceLocation KWLoc, IdentifierInfo *Name, |
| Steve Naroff | b309644 | 2007-06-09 03:47:53 +0000 | [diff] [blame] | 160 | SourceLocation NameLoc, AttributeList *Attr); |
| Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 161 | virtual DeclTy *ActOnField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart, |
| Chris Lattner | 1300fb9 | 2007-01-23 23:42:53 +0000 | [diff] [blame] | 162 | Declarator &D, ExprTy *BitfieldWidth); |
| Steve Naroff | 2e688fd | 2007-09-14 23:09:53 +0000 | [diff] [blame] | 163 | |
| 164 | // This is used for both record definitions and ObjC interface declarations. |
| Fariborz Jahanian | 343f709 | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 165 | virtual void ActOnFields(Scope* S, |
| 166 | SourceLocation RecLoc, DeclTy *TagDecl, |
| Steve Naroff | 2e688fd | 2007-09-14 23:09:53 +0000 | [diff] [blame] | 167 | DeclTy **Fields, unsigned NumFields, |
| 168 | tok::ObjCKeywordKind *visibility = 0); |
| Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 169 | virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl, |
| Chris Lattner | 4ef4001 | 2007-06-11 01:28:17 +0000 | [diff] [blame] | 170 | DeclTy *LastEnumConstant, |
| Chris Lattner | c1915e2 | 2007-01-25 07:29:02 +0000 | [diff] [blame] | 171 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 172 | SourceLocation EqualLoc, ExprTy *Val); |
| Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 173 | virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl, |
| Chris Lattner | c1915e2 | 2007-01-25 07:29:02 +0000 | [diff] [blame] | 174 | DeclTy **Elements, unsigned NumElements); |
| Steve Naroff | 3273c22 | 2007-03-14 21:52:03 +0000 | [diff] [blame] | 175 | private: |
| Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 176 | /// Subroutines of ActOnDeclarator()... |
| Steve Naroff | a23cc79 | 2007-09-13 23:52:58 +0000 | [diff] [blame] | 177 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, ScopedDecl *LastDecl); |
| Steve Naroff | 9def2b1 | 2007-09-13 21:41:19 +0000 | [diff] [blame] | 178 | TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old); |
| 179 | FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old); |
| 180 | VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old); |
| Steve Naroff | 26c8ea5 | 2007-03-21 21:08:52 +0000 | [diff] [blame] | 181 | /// AddTopLevelDecl - called after the decl has been fully processed. |
| 182 | /// Allows for bookkeeping and post-processing of each declaration. |
| 183 | void AddTopLevelDecl(Decl *current, Decl *last); |
| Steve Naroff | 6fbf0dc | 2007-03-16 00:33:25 +0000 | [diff] [blame] | 184 | |
| Steve Naroff | 3273c22 | 2007-03-14 21:52:03 +0000 | [diff] [blame] | 185 | /// More parsing and symbol table subroutines... |
| Chris Lattner | 53621a5 | 2007-06-13 20:44:40 +0000 | [diff] [blame] | 186 | ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo, |
| 187 | Scope *FnBodyScope); |
| Steve Naroff | 9324db1 | 2007-09-13 18:10:37 +0000 | [diff] [blame] | 188 | ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, |
| 189 | SourceLocation IdLoc, Scope *S); |
| Steve Naroff | c6814ea | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 190 | ObjcInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id); |
| Fariborz Jahanian | fa0667b | 2007-09-29 17:04:06 +0000 | [diff] [blame] | 191 | ObjcProtocolDecl *getObjCProtocolDecl(Scope *S, |
| 192 | IdentifierInfo *Id, SourceLocation IdLoc); |
| Steve Naroff | 9324db1 | 2007-09-13 18:10:37 +0000 | [diff] [blame] | 193 | ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S); |
| Steve Naroff | 2f74208 | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 194 | ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
| Steve Naroff | 3273c22 | 2007-03-14 21:52:03 +0000 | [diff] [blame] | 195 | Scope *S); |
| Steve Naroff | a8fd973 | 2007-06-11 00:35:03 +0000 | [diff] [blame] | 196 | // Decl attributes - this routine is the top level dispatcher. |
| 197 | void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix, |
| 198 | AttributeList *declarator_postfix); |
| 199 | void HandleDeclAttribute(Decl *New, AttributeList *rawAttr); |
| 200 | |
| 201 | // HandleVectorTypeAttribute - this attribute is only applicable to |
| 202 | // integral and float scalars, although arrays, pointers, and function |
| 203 | // return values are allowed in conjunction with this construct. Aggregates |
| 204 | // with this attribute are invalid, even if they are of the same size as a |
| 205 | // corresponding scalar. |
| 206 | // The raw attribute should contain precisely 1 argument, the vector size |
| 207 | // for the variable, measured in bytes. If curType and rawAttr are well |
| 208 | // formed, this routine will return a new vector type. |
| Steve Naroff | 4ae0ac6 | 2007-07-06 23:09:18 +0000 | [diff] [blame] | 209 | QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr); |
| Steve Naroff | ddf5a1d | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 210 | void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr); |
| Chris Lattner | 1300fb9 | 2007-01-23 23:42:53 +0000 | [diff] [blame] | 211 | |
| Fariborz Jahanian | ec7b333 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 212 | /// CheckProtocolMethodDefs - This routine checks unimpletented methods |
| 213 | /// Declared in protocol, and those referenced by it. |
| 214 | void CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl, |
| Fariborz Jahanian | adf84f3 | 2007-10-02 20:06:01 +0000 | [diff] [blame^] | 215 | bool& IncompleteImpl, |
| Fariborz Jahanian | ec7b333 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 216 | const llvm::DenseMap<void *, char>& InsMap, |
| 217 | const llvm::DenseMap<void *, char>& ClsMap); |
| 218 | |
| 219 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
| 220 | /// remains unimplemented in the @implementation class. |
| 221 | void ImplMethodsVsClassMethods(ObjcImplementationDecl* IMPDecl, |
| 222 | ObjcInterfaceDecl* IDecl); |
| 223 | |
| Fariborz Jahanian | 89b8ef9 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 224 | /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the |
| 225 | /// category interface is implemented in the category @implementation. |
| 226 | void ImplCategoryMethodsVsIntfMethods(ObjcCategoryImplDecl *CatImplDecl, |
| Fariborz Jahanian | adf84f3 | 2007-10-02 20:06:01 +0000 | [diff] [blame^] | 227 | ObjcCategoryDecl *CatClassDecl); |
| Fariborz Jahanian | 89b8ef9 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 228 | |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 229 | //===--------------------------------------------------------------------===// |
| Chris Lattner | e168f76 | 2006-11-10 05:29:30 +0000 | [diff] [blame] | 230 | // Statement Parsing Callbacks: SemaStmt.cpp. |
| Steve Naroff | 3273c22 | 2007-03-14 21:52:03 +0000 | [diff] [blame] | 231 | public: |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 232 | virtual StmtResult ActOnExprStmt(ExprTy *Expr); |
| Chris Lattner | 1ec5f56 | 2007-06-27 05:38:08 +0000 | [diff] [blame] | 233 | |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 234 | virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc); |
| 235 | virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
| Chris Lattner | cac27a5 | 2007-08-31 21:49:55 +0000 | [diff] [blame] | 236 | StmtTy **Elts, unsigned NumElts, |
| 237 | bool isStmtExpr); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 238 | virtual StmtResult ActOnDeclStmt(DeclTy *Decl); |
| 239 | virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal, |
| Chris Lattner | 6c0ff13 | 2006-11-05 00:19:50 +0000 | [diff] [blame] | 240 | SourceLocation DotDotDotLoc, ExprTy *RHSVal, |
| 241 | SourceLocation ColonLoc, StmtTy *SubStmt); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 242 | virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
| Chris Lattner | 46eeb22 | 2007-07-18 02:28:47 +0000 | [diff] [blame] | 243 | SourceLocation ColonLoc, StmtTy *SubStmt, |
| 244 | Scope *CurScope); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 245 | virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, |
| Chris Lattner | 6c0ff13 | 2006-11-05 00:19:50 +0000 | [diff] [blame] | 246 | SourceLocation ColonLoc, StmtTy *SubStmt); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 247 | virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 248 | StmtTy *ThenVal, SourceLocation ElseLoc, |
| 249 | StmtTy *ElseVal); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 250 | virtual StmtResult ActOnStartOfSwitchStmt(ExprTy *Cond); |
| 251 | virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, |
| Anders Carlsson | 51873c2 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 252 | ExprTy *Body); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 253 | virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, |
| Chris Lattner | 85ed873 | 2006-11-04 20:40:44 +0000 | [diff] [blame] | 254 | StmtTy *Body); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 255 | virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body, |
| Chris Lattner | 85ed873 | 2006-11-04 20:40:44 +0000 | [diff] [blame] | 256 | SourceLocation WhileLoc, ExprTy *Cond); |
| 257 | |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 258 | virtual StmtResult ActOnForStmt(SourceLocation ForLoc, |
| Chris Lattner | 71e23ce | 2006-11-04 20:18:38 +0000 | [diff] [blame] | 259 | SourceLocation LParenLoc, |
| 260 | StmtTy *First, ExprTy *Second, ExprTy *Third, |
| 261 | SourceLocation RParenLoc, StmtTy *Body); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 262 | virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
| Chris Lattner | 16976d3 | 2006-11-05 01:46:01 +0000 | [diff] [blame] | 263 | SourceLocation LabelLoc, |
| 264 | IdentifierInfo *LabelII); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 265 | virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
| Chris Lattner | 16976d3 | 2006-11-05 01:46:01 +0000 | [diff] [blame] | 266 | SourceLocation StarLoc, |
| 267 | ExprTy *DestExp); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 268 | virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, |
| Chris Lattner | eaafe122 | 2006-11-10 05:17:58 +0000 | [diff] [blame] | 269 | Scope *CurScope); |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 270 | virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope); |
| Chris Lattner | 71e23ce | 2006-11-04 20:18:38 +0000 | [diff] [blame] | 271 | |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 272 | virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 273 | ExprTy *RetValExp); |
| 274 | |
| 275 | //===--------------------------------------------------------------------===// |
| Chris Lattner | e168f76 | 2006-11-10 05:29:30 +0000 | [diff] [blame] | 276 | // Expression Parsing Callbacks: SemaExpr.cpp. |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 277 | |
| 278 | // Primary Expressions. |
| Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 279 | virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc, |
| Chris Lattner | ac18be9 | 2006-11-20 06:49:47 +0000 | [diff] [blame] | 280 | IdentifierInfo &II, |
| 281 | bool HasTrailingLParen); |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 282 | virtual ExprResult ActOnPreDefinedExpr(SourceLocation Loc, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 283 | tok::TokenKind Kind); |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 284 | virtual ExprResult ActOnNumericConstant(const Token &); |
| 285 | virtual ExprResult ActOnCharacterConstant(const Token &); |
| 286 | virtual ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 287 | ExprTy *Val); |
| Chris Lattner | 697e5d6 | 2006-11-09 06:32:27 +0000 | [diff] [blame] | 288 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 289 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
| Chris Lattner | 697e5d6 | 2006-11-09 06:32:27 +0000 | [diff] [blame] | 290 | /// fragments (e.g. "foo" "bar" L"baz"). |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 291 | virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks); |
| Chris Lattner | 697e5d6 | 2006-11-09 06:32:27 +0000 | [diff] [blame] | 292 | |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 293 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 294 | virtual ExprResult ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 295 | ExprTy *Input); |
| 296 | virtual ExprResult |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 297 | ActOnSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 298 | SourceLocation LParenLoc, TypeTy *Ty, |
| 299 | SourceLocation RParenLoc); |
| 300 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 301 | virtual ExprResult ActOnPostfixUnaryOp(SourceLocation OpLoc, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 302 | tok::TokenKind Kind, ExprTy *Input); |
| 303 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 304 | virtual ExprResult ActOnArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 305 | ExprTy *Idx, SourceLocation RLoc); |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 306 | virtual ExprResult ActOnMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 307 | tok::TokenKind OpKind, |
| 308 | SourceLocation MemberLoc, |
| 309 | IdentifierInfo &Member); |
| 310 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 311 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 312 | /// This provides the location of the left/right parens and a list of comma |
| 313 | /// locations. |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 314 | virtual ExprResult ActOnCallExpr(ExprTy *Fn, SourceLocation LParenLoc, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 315 | ExprTy **Args, unsigned NumArgs, |
| 316 | SourceLocation *CommaLocs, |
| 317 | SourceLocation RParenLoc); |
| 318 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 319 | virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 320 | SourceLocation RParenLoc, ExprTy *Op); |
| Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 321 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 322 | virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, |
| Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 323 | SourceLocation RParenLoc, ExprTy *Op); |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 324 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 325 | virtual ExprResult ActOnInitList(SourceLocation LParenLoc, |
| Steve Naroff | fbd0983 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 326 | ExprTy **InitList, unsigned NumInit, |
| 327 | SourceLocation RParenLoc); |
| 328 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 329 | virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 330 | ExprTy *LHS,ExprTy *RHS); |
| 331 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 332 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 333 | /// in the case of a the GNU conditional expr extension. |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 334 | virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 335 | SourceLocation ColonLoc, |
| 336 | ExprTy *Cond, ExprTy *LHS, ExprTy *RHS); |
| Chris Lattner | 2937565 | 2006-12-04 18:06:35 +0000 | [diff] [blame] | 337 | |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 338 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
| 339 | virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
| Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 340 | IdentifierInfo *LabelII); |
| 341 | |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 342 | virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt, |
| Chris Lattner | 366727f | 2007-07-24 16:58:17 +0000 | [diff] [blame] | 343 | SourceLocation RPLoc); // "({..})" |
| Chris Lattner | f17bd42 | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 344 | |
| 345 | /// __builtin_offsetof(type, a.b[123][456].c) |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 346 | virtual ExprResult ActOnBuiltinOffsetOf(SourceLocation BuiltinLoc, |
| Chris Lattner | f17bd42 | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 347 | SourceLocation TypeLoc, TypeTy *Arg1, |
| 348 | OffsetOfComponent *CompPtr, |
| 349 | unsigned NumComponents, |
| 350 | SourceLocation RParenLoc); |
| 351 | |
| Steve Naroff | 7886467 | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 352 | // __builtin_types_compatible_p(type1, type2) |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 353 | virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| Steve Naroff | 7886467 | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 354 | TypeTy *arg1, TypeTy *arg2, |
| 355 | SourceLocation RPLoc); |
| Steve Naroff | 9efdabc | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 356 | |
| 357 | // __builtin_choose_expr(constExpr, expr1, expr2) |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 358 | virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
| Steve Naroff | 9efdabc | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 359 | ExprTy *cond, ExprTy *expr1, ExprTy *expr2, |
| 360 | SourceLocation RPLoc); |
| Chris Lattner | 366727f | 2007-07-24 16:58:17 +0000 | [diff] [blame] | 361 | |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 362 | /// ActOnCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's. |
| 363 | virtual ExprResult ActOnCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind, |
| Chris Lattner | 2937565 | 2006-12-04 18:06:35 +0000 | [diff] [blame] | 364 | SourceLocation LAngleBracketLoc, TypeTy *Ty, |
| 365 | SourceLocation RAngleBracketLoc, |
| 366 | SourceLocation LParenLoc, ExprTy *E, |
| 367 | SourceLocation RParenLoc); |
| Bill Wendling | 4073ed5 | 2007-02-13 01:51:42 +0000 | [diff] [blame] | 368 | |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 369 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
| 370 | virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, |
| Bill Wendling | bf313b0 | 2007-02-13 20:09:46 +0000 | [diff] [blame] | 371 | tok::TokenKind Kind); |
| Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 372 | |
| 373 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
| 374 | virtual ExprResult ParseObjCStringLiteral(ExprTy *string); |
| Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 375 | virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
| 376 | SourceLocation LParenLoc, |
| 377 | TypeTy *Ty, |
| 378 | SourceLocation RParenLoc); |
| 379 | |
| Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 380 | // Objective-C declarations. |
| Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 381 | virtual DeclTy *ObjcStartClassInterface(Scope* S, |
| 382 | SourceLocation AtInterafceLoc, |
| Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 383 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 384 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
| 385 | IdentifierInfo **ProtocolNames, unsigned NumProtocols, |
| 386 | AttributeList *AttrList); |
| 387 | |
| Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 388 | virtual DeclTy *ObjcStartProtoInterface(Scope* S, |
| 389 | SourceLocation AtProtoInterfaceLoc, |
| Fariborz Jahanian | 39d641f | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 390 | IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, |
| 391 | IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs); |
| 392 | |
| Fariborz Jahanian | 343f709 | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 393 | virtual DeclTy *ObjcStartCatInterface(Scope* S, |
| 394 | SourceLocation AtInterfaceLoc, |
| Fariborz Jahanian | 867a7eb | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 395 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 396 | IdentifierInfo *CategoryName, SourceLocation CategoryLoc, |
| 397 | IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs); |
| 398 | |
| Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 399 | virtual DeclTy *ObjcStartClassImplementation(Scope* S, |
| 400 | SourceLocation AtClassImplLoc, |
| 401 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 402 | IdentifierInfo *SuperClassname, |
| 403 | SourceLocation SuperClassLoc); |
| 404 | |
| Fariborz Jahanian | 89b8ef9 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 405 | virtual DeclTy *ObjcStartCategoryImplementation(Scope* S, |
| 406 | SourceLocation AtCatImplLoc, |
| 407 | IdentifierInfo *ClassName, |
| 408 | SourceLocation ClassLoc, |
| 409 | IdentifierInfo *CatName, |
| 410 | SourceLocation CatLoc); |
| 411 | |
| Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 412 | virtual DeclTy *ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc, |
| 413 | IdentifierInfo **IdentList, |
| 414 | unsigned NumElts); |
| Fariborz Jahanian | 876e27d | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 415 | |
| 416 | virtual DeclTy *ObjcForwardProtocolDeclaration(Scope *S, |
| 417 | SourceLocation AtProtocolLoc, |
| 418 | IdentifierInfo **IdentList, |
| 419 | unsigned NumElts); |
| Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 420 | |
| Fariborz Jahanian | 343f709 | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 421 | virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl, |
| Steve Naroff | f2fb4ad | 2007-09-11 21:17:26 +0000 | [diff] [blame] | 422 | DeclTy **allMethods, unsigned allNum); |
| Fariborz Jahanian | 2a4dd31 | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 423 | |
| 424 | virtual void ActOnImpleIvarVsClassIvars(DeclTy *ClassDecl, |
| 425 | DeclTy **Fields, unsigned NumFields); |
| 426 | |
| Fariborz Jahanian | 0c74e9d | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 427 | virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc, |
| Steve Naroff | 8017506 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 428 | tok::TokenKind MethodType, TypeTy *ReturnType, Selector Sel, |
| Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 429 | // optional arguments. The number of types/arguments is obtained |
| 430 | // from the Sel.getNumArgs(). |
| 431 | TypeTy **ArgTypes, IdentifierInfo **ArgNames, |
| 432 | AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind); |
| Steve Naroff | f0f2afc | 2007-09-17 21:01:15 +0000 | [diff] [blame] | 433 | |
| Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 434 | // ActOnClassMessage - used for both unary and keyword messages. |
| 435 | // ArgExprs is optional - if it is present, the number of expressions |
| 436 | // is obtained from Sel.getNumArgs(). |
| 437 | virtual ExprResult ActOnClassMessage( |
| Steve Naroff | 8017506 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 438 | IdentifierInfo *receivingClassName, Selector Sel, |
| Steve Naroff | c6814ea | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 439 | SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs); |
| Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 440 | |
| 441 | // ActOnInstanceMessage - used for both unary and keyword messages. |
| 442 | // ArgExprs is optional - if it is present, the number of expressions |
| 443 | // is obtained from Sel.getNumArgs(). |
| 444 | virtual ExprResult ActOnInstanceMessage( |
| Steve Naroff | 8017506 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 445 | ExprTy *receiver, Selector Sel, |
| Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 446 | SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs); |
| Steve Naroff | 26c8ea5 | 2007-03-21 21:08:52 +0000 | [diff] [blame] | 447 | private: |
| Steve Naroff | 71b59a9 | 2007-06-04 22:22:31 +0000 | [diff] [blame] | 448 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
| Steve Naroff | 3109001 | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 449 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
| 450 | void UsualUnaryConversions(Expr *&expr); |
| 451 | |
| 452 | // DefaultFunctionArrayConversion - converts functions and arrays |
| 453 | // to their respective pointers (C99 6.3.2.1). |
| 454 | void DefaultFunctionArrayConversion(Expr *&expr); |
| Steve Naroff | b8ea4fb | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 455 | |
| Steve Naroff | 0b66158 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 456 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
| 457 | // do not have a prototype. Integer promotions are performed on each |
| 458 | // argument, and arguments that have type float are promoted to double. |
| 459 | void DefaultArgumentPromotion(Expr *&expr); |
| 460 | |
| Steve Naroff | 71b59a9 | 2007-06-04 22:22:31 +0000 | [diff] [blame] | 461 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
| 462 | // operands and then handles various conversions that are common to binary |
| 463 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
| 464 | // routine returns the first non-arithmetic type found. The client is |
| 465 | // responsible for emitting appropriate error diagnostics. |
| Steve Naroff | be4c4d1 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 466 | QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr, |
| 467 | bool isCompAssign = false); |
| Steve Naroff | 98cf3e9 | 2007-06-06 18:38:38 +0000 | [diff] [blame] | 468 | enum AssignmentCheckResult { |
| Steve Naroff | 17f76e0 | 2007-05-03 21:03:48 +0000 | [diff] [blame] | 469 | Compatible, |
| 470 | Incompatible, |
| 471 | PointerFromInt, |
| 472 | IntFromPointer, |
| Steve Naroff | 1f4d727 | 2007-05-11 04:00:31 +0000 | [diff] [blame] | 473 | IncompatiblePointer, |
| 474 | CompatiblePointerDiscardsQualifiers |
| Steve Naroff | 17f76e0 | 2007-05-03 21:03:48 +0000 | [diff] [blame] | 475 | }; |
| Steve Naroff | b8ea4fb | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 476 | // CheckAssignmentConstraints - Perform type checking for assignment, |
| 477 | // argument passing, variable initialization, and function return values. |
| 478 | // This routine is only used by the following two methods. C99 6.5.16. |
| Steve Naroff | 98cf3e9 | 2007-06-06 18:38:38 +0000 | [diff] [blame] | 479 | AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs); |
| Steve Naroff | b8ea4fb | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 480 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 481 | // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr, |
| Steve Naroff | 66356bd | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 482 | // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, |
| Steve Naroff | b8ea4fb | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 483 | // this routine performs the default function/array converions. |
| 484 | AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs, |
| 485 | Expr *&rExpr); |
| 486 | // CheckCompoundAssignmentConstraints - Type check without performing any |
| 487 | // conversions. For compound assignments, the "Check...Operands" methods |
| 488 | // perform the necessary conversions. |
| 489 | AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs, |
| 490 | QualType rhs); |
| 491 | |
| Steve Naroff | 98cf3e9 | 2007-06-06 18:38:38 +0000 | [diff] [blame] | 492 | // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1) |
| 493 | AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType, |
| 494 | QualType rhsType); |
| Steve Naroff | 9eb2465 | 2007-05-02 21:58:15 +0000 | [diff] [blame] | 495 | |
| Steve Naroff | 8eeeb13 | 2007-05-08 21:09:37 +0000 | [diff] [blame] | 496 | /// the following "Check" methods will return a valid/converted QualType |
| 497 | /// or a null QualType (indicating an error diagnostic was issued). |
| 498 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 499 | /// type checking binary operators (subroutines of ActOnBinOp). |
| Steve Naroff | 7a5af78 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 500 | inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
| 501 | inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
| Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 502 | inline QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
| Steve Naroff | be4c4d1 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 503 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
| Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 504 | inline QualType CheckRemainderOperands( // C99 6.5.5 |
| Steve Naroff | be4c4d1 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 505 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
| Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 506 | inline QualType CheckAdditionOperands( // C99 6.5.6 |
| Steve Naroff | be4c4d1 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 507 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
| Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 508 | inline QualType CheckSubtractionOperands( // C99 6.5.6 |
| Steve Naroff | be4c4d1 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 509 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
| Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 510 | inline QualType CheckShiftOperands( // C99 6.5.7 |
| Steve Naroff | be4c4d1 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 511 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
| Chris Lattner | b620c34 | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 512 | inline QualType CheckCompareOperands( // C99 6.5.8/9 |
| 513 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational); |
| Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 514 | inline QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
| Steve Naroff | be4c4d1 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 515 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
| Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 516 | inline QualType CheckLogicalOperands( // C99 6.5.[13,14] |
| Steve Naroff | 7a5af78 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 517 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| Steve Naroff | 35d8515 | 2007-05-07 00:24:15 +0000 | [diff] [blame] | 518 | // CheckAssignmentOperands is used for both simple and compound assignment. |
| 519 | // For simple assignment, pass both expressions and a null converted type. |
| 520 | // For compound assignment, pass both expressions and the converted type. |
| 521 | inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
| Steve Naroff | 0c1c7ed | 2007-08-24 22:33:52 +0000 | [diff] [blame] | 522 | Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType); |
| Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 523 | inline QualType CheckCommaOperands( // C99 6.5.17 |
| Steve Naroff | 7a5af78 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 524 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| Steve Naroff | f8a28c5 | 2007-05-15 20:29:32 +0000 | [diff] [blame] | 525 | inline QualType CheckConditionalOperands( // C99 6.5.15 |
| Steve Naroff | 7a5af78 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 526 | Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc); |
| Steve Naroff | 95af013 | 2007-03-30 23:47:58 +0000 | [diff] [blame] | 527 | |
| Steve Naroff | 83895f7 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 528 | /// type checking unary operators (subroutines of ActOnUnaryOp). |
| Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 529 | /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4 |
| Steve Naroff | 71ce2e0 | 2007-05-18 22:53:50 +0000 | [diff] [blame] | 530 | QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc); |
| 531 | QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc); |
| 532 | QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc); |
| 533 | QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc, |
| 534 | bool isSizeof); |
| Chris Lattner | 74ed76b | 2007-08-24 21:41:10 +0000 | [diff] [blame] | 535 | QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc); |
| Steve Naroff | f8fd09e | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 536 | |
| 537 | /// type checking primary expressions. |
| 538 | QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc, |
| 539 | IdentifierInfo &Comp, SourceLocation CmpLoc); |
| 540 | |
| Steve Naroff | 2fea139 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 541 | /// type checking declaration initializers (C99 6.7.8) |
| Steve Naroff | 77b9700 | 2007-09-04 14:36:54 +0000 | [diff] [blame] | 542 | bool CheckInitializer(Expr *&simpleInit_or_initList, QualType &declType, |
| Steve Naroff | 7d2c5ed | 2007-09-03 01:24:23 +0000 | [diff] [blame] | 543 | bool isStatic); |
| Steve Naroff | 77b9700 | 2007-09-04 14:36:54 +0000 | [diff] [blame] | 544 | bool CheckSingleInitializer(Expr *&simpleInit, QualType declType); |
| 545 | bool CheckInitExpr(Expr *expr, InitListExpr *IList, unsigned slot, |
| 546 | bool isStatic, QualType ElementType); |
| Steve Naroff | ac074b4 | 2007-09-04 02:20:04 +0000 | [diff] [blame] | 547 | void CheckVariableInitList(QualType DeclType, InitListExpr *IList, |
| 548 | QualType ElementType, bool isStatic, |
| 549 | int &nInitializers, bool &hadError); |
| 550 | void CheckConstantInitList(QualType DeclType, InitListExpr *IList, |
| 551 | QualType ElementType, bool isStatic, |
| 552 | int &nInitializers, bool &hadError); |
| 553 | |
| Chris Lattner | fc1c44a | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 554 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
| 555 | /// the specified width and sign. If an overflow occurs, detect it and emit |
| 556 | /// the specified diagnostic. |
| 557 | void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, |
| 558 | unsigned NewWidth, bool NewSign, |
| 559 | SourceLocation Loc, unsigned DiagID); |
| 560 | |
| Chris Lattner | b87b1b3 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 561 | //===--------------------------------------------------------------------===// |
| 562 | // Extra semantic analysis beyond the C type system |
| 563 | private: |
| 564 | |
| Anders Carlsson | 98f0790 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 565 | bool CheckFunctionCall(Expr *Fn, |
| Ted Kremenek | e68f1aa | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 566 | SourceLocation LParenLoc, SourceLocation RParenLoc, |
| 567 | FunctionDecl *FDecl, |
| Chris Lattner | b87b1b3 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 568 | Expr** Args, unsigned NumArgsInCall); |
| 569 | |
| Ted Kremenek | e68f1aa | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 570 | void CheckPrintfArguments(Expr *Fn, |
| 571 | SourceLocation LParenLoc, SourceLocation RParenLoc, |
| 572 | bool HasVAListArg, FunctionDecl *FDecl, |
| Ted Kremenek | 56c864e | 2007-08-10 21:21:05 +0000 | [diff] [blame] | 573 | unsigned format_idx, Expr** Args, |
| 574 | unsigned NumArgsInCall); |
| Ted Kremenek | cff94fa | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 575 | |
| 576 | void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, |
| 577 | SourceLocation ReturnLoc); |
| 578 | |
| Anders Carlsson | 98f0790 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 579 | |
| 580 | bool CheckBuiltinCFStringArgument(Expr* Arg); |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 581 | }; |
| 582 | |
| 583 | |
| 584 | } // end namespace clang |
| Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 585 | |
| 586 | #endif |