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 | // |
| 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 | // |
| 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 | |
| 18 | #include "clang/Parse/Action.h" |
| 19 | #include "llvm/ADT/DenseMap.h" |
| 20 | #include "llvm/ADT/SmallVector.h" |
| 21 | #include <vector> |
| 22 | #include <string> |
| 23 | |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | class APSInt; |
| 26 | } |
| 27 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 28 | namespace clang { |
| 29 | class ASTContext; |
| 30 | class Preprocessor; |
| 31 | class Decl; |
Steve Naroff | d21bc0d | 2007-09-13 18:10:37 +0000 | [diff] [blame] | 32 | class ScopedDecl; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 33 | class Expr; |
Steve Naroff | 9091f3f | 2007-09-02 15:34:30 +0000 | [diff] [blame] | 34 | class InitListExpr; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 35 | class VarDecl; |
| 36 | class ParmVarDecl; |
| 37 | class TypedefDecl; |
| 38 | class FunctionDecl; |
| 39 | class QualType; |
Chris Lattner | 3496d52 | 2007-09-04 02:45:27 +0000 | [diff] [blame] | 40 | struct LangOptions; |
| 41 | struct DeclaratorChunk; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 42 | class Token; |
| 43 | class IntegerLiteral; |
| 44 | class ArrayType; |
| 45 | class LabelStmt; |
| 46 | class SwitchStmt; |
Steve Naroff | 1b8a46c | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 47 | class OCUVectorType; |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 48 | class TypedefDecl; |
Fariborz Jahanian | 0c5affb | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 49 | class ObjcInterfaceDecl; |
Fariborz Jahanian | dd243ef | 2007-09-29 17:04:06 +0000 | [diff] [blame] | 50 | class ObjcProtocolDecl; |
Fariborz Jahanian | f7cf3a6 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 51 | class ObjcImplementationDecl; |
Fariborz Jahanian | a91aa32 | 2007-10-02 16:38:50 +0000 | [diff] [blame^] | 52 | class ObjcCategoryImplDecl; |
| 53 | class ObjcCategoryDecl; |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 55 | /// Sema - This implements semantic analysis and AST building for C. |
| 56 | class Sema : public Action { |
| 57 | Preprocessor &PP; |
| 58 | |
| 59 | ASTContext &Context; |
| 60 | |
| 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 | |
| 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; |
| 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. |
| 74 | llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap; |
| 75 | |
| 76 | llvm::SmallVector<SwitchStmt*, 8> SwitchStack; |
Steve Naroff | 82113e3 | 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 | 2e64c07 | 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 | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 89 | id_asprintf, |
Ted Kremenek | 2d7e953 | 2007-08-10 21:13:51 +0000 | [diff] [blame] | 90 | id_vsnprintf, |
Chris Lattner | 2e64c07 | 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 | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 104 | public: |
| 105 | Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup); |
| 106 | |
| 107 | const LangOptions &getLangOptions() const; |
| 108 | |
| 109 | /// The primitive diagnostic helpers - always returns true, which simplifies |
| 110 | /// error handling (i.e. less code). |
| 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); |
| 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 | 0c5affb | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 129 | |
Chris Lattner | b26b7ad | 2007-08-31 04:53:24 +0000 | [diff] [blame] | 130 | virtual void DeleteExpr(ExprTy *E); |
| 131 | virtual void DeleteStmt(StmtTy *S); |
| 132 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 133 | //===--------------------------------------------------------------------===// |
| 134 | // Type Analysis / Processing: SemaType.cpp. |
| 135 | // |
| 136 | QualType GetTypeForDeclarator(Declarator &D, Scope *S); |
| 137 | |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 138 | virtual TypeResult ActOnTypeName(Scope *S, Declarator &D); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 139 | |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 140 | virtual TypeResult ActOnParamDeclaratorType(Scope *S, Declarator &D); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 141 | private: |
| 142 | //===--------------------------------------------------------------------===// |
| 143 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
| 144 | // |
| 145 | virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const; |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 146 | virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup); |
Steve Naroff | 6a0e209 | 2007-09-12 14:07:44 +0000 | [diff] [blame] | 147 | void AddInitializerToDecl(DeclTy *dcl, ExprTy *init); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 148 | virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group); |
| 149 | |
| 150 | virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D); |
| 151 | virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body); |
| 152 | virtual void PopScope(SourceLocation Loc, Scope *S); |
| 153 | |
| 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 | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 158 | virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 159 | SourceLocation KWLoc, IdentifierInfo *Name, |
| 160 | SourceLocation NameLoc, AttributeList *Attr); |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 161 | virtual DeclTy *ActOnField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 162 | Declarator &D, ExprTy *BitfieldWidth); |
Steve Naroff | ffeaa55 | 2007-09-14 23:09:53 +0000 | [diff] [blame] | 163 | |
| 164 | // This is used for both record definitions and ObjC interface declarations. |
Fariborz Jahanian | 0c5affb | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 165 | virtual void ActOnFields(Scope* S, |
| 166 | SourceLocation RecLoc, DeclTy *TagDecl, |
Steve Naroff | ffeaa55 | 2007-09-14 23:09:53 +0000 | [diff] [blame] | 167 | DeclTy **Fields, unsigned NumFields, |
| 168 | tok::ObjCKeywordKind *visibility = 0); |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 169 | virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 170 | DeclTy *LastEnumConstant, |
| 171 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 172 | SourceLocation EqualLoc, ExprTy *Val); |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 173 | virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 174 | DeclTy **Elements, unsigned NumElements); |
| 175 | private: |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 176 | /// Subroutines of ActOnDeclarator()... |
Steve Naroff | 2591e1b | 2007-09-13 23:52:58 +0000 | [diff] [blame] | 177 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, ScopedDecl *LastDecl); |
Steve Naroff | cb59747 | 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); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +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); |
| 184 | |
| 185 | /// More parsing and symbol table subroutines... |
| 186 | ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo, |
| 187 | Scope *FnBodyScope); |
Steve Naroff | d21bc0d | 2007-09-13 18:10:37 +0000 | [diff] [blame] | 188 | ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, |
| 189 | SourceLocation IdLoc, Scope *S); |
Fariborz Jahanian | 0c5affb | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 190 | ObjcInterfaceDecl *getObjCInterfaceDecl(Scope *S, |
| 191 | IdentifierInfo *Id, SourceLocation IdLoc); |
Fariborz Jahanian | dd243ef | 2007-09-29 17:04:06 +0000 | [diff] [blame] | 192 | ObjcProtocolDecl *getObjCProtocolDecl(Scope *S, |
| 193 | IdentifierInfo *Id, SourceLocation IdLoc); |
Steve Naroff | d21bc0d | 2007-09-13 18:10:37 +0000 | [diff] [blame] | 194 | ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S); |
Steve Naroff | f0c31dd | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 195 | ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 196 | Scope *S); |
| 197 | // Decl attributes - this routine is the top level dispatcher. |
| 198 | void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix, |
| 199 | AttributeList *declarator_postfix); |
| 200 | void HandleDeclAttribute(Decl *New, AttributeList *rawAttr); |
| 201 | |
| 202 | // HandleVectorTypeAttribute - this attribute is only applicable to |
| 203 | // integral and float scalars, although arrays, pointers, and function |
| 204 | // return values are allowed in conjunction with this construct. Aggregates |
| 205 | // with this attribute are invalid, even if they are of the same size as a |
| 206 | // corresponding scalar. |
| 207 | // The raw attribute should contain precisely 1 argument, the vector size |
| 208 | // for the variable, measured in bytes. If curType and rawAttr are well |
| 209 | // formed, this routine will return a new vector type. |
| 210 | QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr); |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 211 | void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 212 | |
Fariborz Jahanian | f7cf3a6 | 2007-09-29 17:14:55 +0000 | [diff] [blame] | 213 | /// CheckProtocolMethodDefs - This routine checks unimpletented methods |
| 214 | /// Declared in protocol, and those referenced by it. |
| 215 | void CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl, |
| 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 | a91aa32 | 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, |
| 227 | ObjcCategoryDecl *CatClassDecl); |
| 228 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 229 | //===--------------------------------------------------------------------===// |
| 230 | // Statement Parsing Callbacks: SemaStmt.cpp. |
| 231 | public: |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 232 | virtual StmtResult ActOnExprStmt(ExprTy *Expr); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 233 | |
Steve Naroff | 5cbb02f | 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 | f2b0757 | 2007-08-31 21:49:55 +0000 | [diff] [blame] | 236 | StmtTy **Elts, unsigned NumElts, |
| 237 | bool isStmtExpr); |
Steve Naroff | 5cbb02f | 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 | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 240 | SourceLocation DotDotDotLoc, ExprTy *RHSVal, |
| 241 | SourceLocation ColonLoc, StmtTy *SubStmt); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 242 | virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 243 | SourceLocation ColonLoc, StmtTy *SubStmt, |
| 244 | Scope *CurScope); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 245 | virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 246 | SourceLocation ColonLoc, StmtTy *SubStmt); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 247 | virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 248 | StmtTy *ThenVal, SourceLocation ElseLoc, |
| 249 | StmtTy *ElseVal); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 250 | virtual StmtResult ActOnStartOfSwitchStmt(ExprTy *Cond); |
| 251 | virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 252 | ExprTy *Body); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 253 | virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 254 | StmtTy *Body); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 255 | virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 256 | SourceLocation WhileLoc, ExprTy *Cond); |
| 257 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 258 | virtual StmtResult ActOnForStmt(SourceLocation ForLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 259 | SourceLocation LParenLoc, |
| 260 | StmtTy *First, ExprTy *Second, ExprTy *Third, |
| 261 | SourceLocation RParenLoc, StmtTy *Body); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 262 | virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 263 | SourceLocation LabelLoc, |
| 264 | IdentifierInfo *LabelII); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 265 | virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 266 | SourceLocation StarLoc, |
| 267 | ExprTy *DestExp); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 268 | virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 269 | Scope *CurScope); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 270 | virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 271 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 272 | virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 273 | ExprTy *RetValExp); |
| 274 | |
| 275 | //===--------------------------------------------------------------------===// |
| 276 | // Expression Parsing Callbacks: SemaExpr.cpp. |
| 277 | |
| 278 | // Primary Expressions. |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 279 | virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 280 | IdentifierInfo &II, |
| 281 | bool HasTrailingLParen); |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 282 | virtual ExprResult ActOnPreDefinedExpr(SourceLocation Loc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 283 | tok::TokenKind Kind); |
Steve Naroff | 87d58b4 | 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 | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 287 | ExprTy *Val); |
| 288 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 289 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 290 | /// fragments (e.g. "foo" "bar" L"baz"). |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 291 | virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 292 | |
| 293 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 294 | virtual ExprResult ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 295 | ExprTy *Input); |
| 296 | virtual ExprResult |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 297 | ActOnSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 298 | SourceLocation LParenLoc, TypeTy *Ty, |
| 299 | SourceLocation RParenLoc); |
| 300 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 301 | virtual ExprResult ActOnPostfixUnaryOp(SourceLocation OpLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 302 | tok::TokenKind Kind, ExprTy *Input); |
| 303 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 304 | virtual ExprResult ActOnArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 305 | ExprTy *Idx, SourceLocation RLoc); |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 306 | virtual ExprResult ActOnMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 307 | tok::TokenKind OpKind, |
| 308 | SourceLocation MemberLoc, |
| 309 | IdentifierInfo &Member); |
| 310 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 311 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 312 | /// This provides the location of the left/right parens and a list of comma |
| 313 | /// locations. |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 314 | virtual ExprResult ActOnCallExpr(ExprTy *Fn, SourceLocation LParenLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 315 | ExprTy **Args, unsigned NumArgs, |
| 316 | SourceLocation *CommaLocs, |
| 317 | SourceLocation RParenLoc); |
| 318 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 319 | virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 320 | SourceLocation RParenLoc, ExprTy *Op); |
| 321 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 322 | virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 323 | SourceLocation RParenLoc, ExprTy *Op); |
| 324 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 325 | virtual ExprResult ActOnInitList(SourceLocation LParenLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 326 | ExprTy **InitList, unsigned NumInit, |
| 327 | SourceLocation RParenLoc); |
| 328 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 329 | virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 330 | ExprTy *LHS,ExprTy *RHS); |
| 331 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 332 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 333 | /// in the case of a the GNU conditional expr extension. |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 334 | virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 335 | SourceLocation ColonLoc, |
| 336 | ExprTy *Cond, ExprTy *LHS, ExprTy *RHS); |
| 337 | |
Steve Naroff | 5cbb02f | 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 | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 340 | IdentifierInfo *LabelII); |
| 341 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 342 | virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 343 | SourceLocation RPLoc); // "({..})" |
Chris Lattner | 0d9bcea | 2007-08-30 17:45:32 +0000 | [diff] [blame] | 344 | |
| 345 | /// __builtin_offsetof(type, a.b[123][456].c) |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 346 | virtual ExprResult ActOnBuiltinOffsetOf(SourceLocation BuiltinLoc, |
Chris Lattner | 0d9bcea | 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 | 63bad2d | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 352 | // __builtin_types_compatible_p(type1, type2) |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 353 | virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, |
Steve Naroff | 63bad2d | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 354 | TypeTy *arg1, TypeTy *arg2, |
| 355 | SourceLocation RPLoc); |
Steve Naroff | 93c5301 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 356 | |
| 357 | // __builtin_choose_expr(constExpr, expr1, expr2) |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 358 | virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
Steve Naroff | 93c5301 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 359 | ExprTy *cond, ExprTy *expr1, ExprTy *expr2, |
| 360 | SourceLocation RPLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 361 | |
Steve Naroff | 5cbb02f | 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 | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 364 | SourceLocation LAngleBracketLoc, TypeTy *Ty, |
| 365 | SourceLocation RAngleBracketLoc, |
| 366 | SourceLocation LParenLoc, ExprTy *E, |
| 367 | SourceLocation RParenLoc); |
| 368 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 369 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
| 370 | virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 371 | tok::TokenKind Kind); |
Anders Carlsson | a66cad4 | 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 | 8be1d40 | 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 | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 380 | // Objective-C declarations. |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 381 | virtual DeclTy *ObjcStartClassInterface(Scope* S, |
| 382 | SourceLocation AtInterafceLoc, |
Steve Naroff | 81f1bba | 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 | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 388 | virtual DeclTy *ObjcStartProtoInterface(Scope* S, |
| 389 | SourceLocation AtProtoInterfaceLoc, |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 390 | IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, |
| 391 | IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs); |
| 392 | |
Fariborz Jahanian | 0c5affb | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 393 | virtual DeclTy *ObjcStartCatInterface(Scope* S, |
| 394 | SourceLocation AtInterfaceLoc, |
Fariborz Jahanian | f25220e | 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 | c091b5d | 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 | a91aa32 | 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 | 81f1bba | 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 | c716c94 | 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 | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 420 | |
Fariborz Jahanian | 0c5affb | 2007-09-29 00:54:24 +0000 | [diff] [blame] | 421 | virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl, |
Steve Naroff | 7549489 | 2007-09-11 21:17:26 +0000 | [diff] [blame] | 422 | DeclTy **allMethods, unsigned allNum); |
Fariborz Jahanian | d34caf9 | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 423 | |
| 424 | virtual void ActOnImpleIvarVsClassIvars(DeclTy *ClassDecl, |
| 425 | DeclTy **Fields, unsigned NumFields); |
| 426 | |
Fariborz Jahanian | 8b5ab6f | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 427 | virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc, |
Steve Naroff | 6cb1d36 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 428 | tok::TokenKind MethodType, TypeTy *ReturnType, Selector Sel, |
Steve Naroff | 4ed9d66 | 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 | d3f5ee4 | 2007-09-17 21:01:15 +0000 | [diff] [blame] | 433 | |
Steve Naroff | 4ed9d66 | 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 | 6cb1d36 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 438 | IdentifierInfo *receivingClassName, Selector Sel, |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 439 | SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs); |
| 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 | 6cb1d36 | 2007-09-28 22:22:11 +0000 | [diff] [blame] | 445 | ExprTy *receiver, Selector Sel, |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 446 | SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 447 | private: |
| 448 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
| 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); |
| 455 | |
Steve Naroff | db65e05 | 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 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +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 | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 466 | QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr, |
| 467 | bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 468 | enum AssignmentCheckResult { |
| 469 | Compatible, |
| 470 | Incompatible, |
| 471 | PointerFromInt, |
| 472 | IntFromPointer, |
| 473 | IncompatiblePointer, |
| 474 | CompatiblePointerDiscardsQualifiers |
| 475 | }; |
| 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. |
| 479 | AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs); |
| 480 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 481 | // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr, |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 482 | // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +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 | |
| 492 | // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1) |
| 493 | AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType, |
| 494 | QualType rhsType); |
| 495 | |
| 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 | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 499 | /// type checking binary operators (subroutines of ActOnBinOp). |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 500 | inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
| 501 | inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
| 502 | inline QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 503 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 504 | inline QualType CheckRemainderOperands( // C99 6.5.5 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 505 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 506 | inline QualType CheckAdditionOperands( // C99 6.5.6 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 507 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 508 | inline QualType CheckSubtractionOperands( // C99 6.5.6 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 509 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 510 | inline QualType CheckShiftOperands( // C99 6.5.7 |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 511 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 254f3bc | 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); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 514 | inline QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
Steve Naroff | 8f70836 | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 515 | Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 516 | inline QualType CheckLogicalOperands( // C99 6.5.[13,14] |
| 517 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 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 | 0f32f43 | 2007-08-24 22:33:52 +0000 | [diff] [blame] | 522 | Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 523 | inline QualType CheckCommaOperands( // C99 6.5.17 |
| 524 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 525 | inline QualType CheckConditionalOperands( // C99 6.5.15 |
| 526 | Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc); |
| 527 | |
Steve Naroff | 87d58b4 | 2007-09-16 03:34:24 +0000 | [diff] [blame] | 528 | /// type checking unary operators (subroutines of ActOnUnaryOp). |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 529 | /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4 |
| 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 | 5110ad5 | 2007-08-24 21:41:10 +0000 | [diff] [blame] | 535 | QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc); |
Steve Naroff | 1b8a46c | 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 | e14e554 | 2007-09-02 02:04:30 +0000 | [diff] [blame] | 541 | /// type checking declaration initializers (C99 6.7.8) |
Steve Naroff | e6a8c9b | 2007-09-04 14:36:54 +0000 | [diff] [blame] | 542 | bool CheckInitializer(Expr *&simpleInit_or_initList, QualType &declType, |
Steve Naroff | 1c9de71 | 2007-09-03 01:24:23 +0000 | [diff] [blame] | 543 | bool isStatic); |
Steve Naroff | e6a8c9b | 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 | 509d0b5 | 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 | 3429a81 | 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 | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 561 | //===--------------------------------------------------------------------===// |
| 562 | // Extra semantic analysis beyond the C type system |
| 563 | private: |
| 564 | |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 565 | bool CheckFunctionCall(Expr *Fn, |
Ted Kremenek | 081ed87 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 566 | SourceLocation LParenLoc, SourceLocation RParenLoc, |
| 567 | FunctionDecl *FDecl, |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 568 | Expr** Args, unsigned NumArgsInCall); |
| 569 | |
Ted Kremenek | 081ed87 | 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 | 3059654 | 2007-08-10 21:21:05 +0000 | [diff] [blame] | 573 | unsigned format_idx, Expr** Args, |
| 574 | unsigned NumArgsInCall); |
Ted Kremenek | 45925ab | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 575 | |
| 576 | void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, |
| 577 | SourceLocation ReturnLoc); |
| 578 | |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 579 | |
| 580 | bool CheckBuiltinCFStringArgument(Expr* Arg); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 581 | }; |
| 582 | |
| 583 | |
| 584 | } // end namespace clang |
| 585 | |
| 586 | #endif |