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 | |
| 24 | namespace clang { |
| 25 | class ASTContext; |
| 26 | class Preprocessor; |
| 27 | class Decl; |
| 28 | class Expr; |
| 29 | class VarDecl; |
| 30 | class ParmVarDecl; |
| 31 | class TypedefDecl; |
| 32 | class FunctionDecl; |
| 33 | class QualType; |
| 34 | class LangOptions; |
| 35 | class DeclaratorChunk; |
| 36 | class Token; |
| 37 | class IntegerLiteral; |
| 38 | class ArrayType; |
| 39 | class LabelStmt; |
| 40 | class SwitchStmt; |
Steve Naroff | 1b8a46c | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 41 | class OCUVectorType; |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 42 | class TypedefDecl; |
| 43 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 44 | /// Sema - This implements semantic analysis and AST building for C. |
| 45 | class Sema : public Action { |
| 46 | Preprocessor &PP; |
| 47 | |
| 48 | ASTContext &Context; |
| 49 | |
| 50 | /// CurFunctionDecl - If inside of a function body, this contains a pointer to |
| 51 | /// the function decl for the function being parsed. |
| 52 | FunctionDecl *CurFunctionDecl; |
| 53 | |
| 54 | /// LastInGroupList - This vector is populated when there are multiple |
| 55 | /// declarators in a single decl group (e.g. "int A, B, C"). In this case, |
| 56 | /// all but the last decl will be entered into this. This is used by the |
| 57 | /// ASTStreamer. |
| 58 | std::vector<Decl*> &LastInGroupList; |
| 59 | |
| 60 | /// LabelMap - This is a mapping from label identifiers to the LabelStmt for |
| 61 | /// it (which acts like the label decl in some ways). Forward referenced |
| 62 | /// labels have a LabelStmt created for them with a null location & SubStmt. |
| 63 | llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap; |
| 64 | |
| 65 | llvm::SmallVector<SwitchStmt*, 8> SwitchStack; |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 66 | |
| 67 | /// OCUVectorDecls - This is a list all the OCU vector types. This allows |
| 68 | /// us to associate a raw vector type with one of the OCU type names. |
| 69 | /// This is only necessary for issuing pretty diagnostics. |
| 70 | llvm::SmallVector<TypedefDecl*, 24> OCUVectorDecls; |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 71 | |
| 72 | // Enum values used by KnownFunctionIDs (see below). |
| 73 | enum { |
| 74 | id_printf, |
| 75 | id_fprintf, |
| 76 | id_sprintf, |
| 77 | id_snprintf, |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 78 | id_asprintf, |
Ted Kremenek | 2d7e953 | 2007-08-10 21:13:51 +0000 | [diff] [blame] | 79 | id_vsnprintf, |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 80 | id_vasprintf, |
| 81 | id_vfprintf, |
| 82 | id_vsprintf, |
| 83 | id_vprintf, |
| 84 | id_num_known_functions |
| 85 | }; |
| 86 | |
| 87 | /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set |
| 88 | /// of known functions used by the semantic analysis to do various |
| 89 | /// kinds of checking (e.g. checking format string errors in printf calls). |
| 90 | /// This list is populated upon the creation of a Sema object. |
| 91 | IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ]; |
| 92 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 93 | public: |
| 94 | Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup); |
| 95 | |
| 96 | const LangOptions &getLangOptions() const; |
| 97 | |
| 98 | /// The primitive diagnostic helpers - always returns true, which simplifies |
| 99 | /// error handling (i.e. less code). |
| 100 | bool Diag(SourceLocation Loc, unsigned DiagID); |
| 101 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg); |
| 102 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, |
| 103 | const std::string &Msg2); |
| 104 | |
| 105 | /// More expressive diagnostic helpers for expressions (say that 6 times:-) |
| 106 | bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1); |
| 107 | bool Diag(SourceLocation Loc, unsigned DiagID, |
| 108 | SourceRange R1, SourceRange R2); |
| 109 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, |
| 110 | SourceRange R1); |
| 111 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, |
| 112 | SourceRange R1, SourceRange R2); |
| 113 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, |
| 114 | const std::string &Msg2, SourceRange R1); |
| 115 | bool Diag(SourceLocation Loc, unsigned DiagID, |
| 116 | const std::string &Msg1, const std::string &Msg2, |
| 117 | SourceRange R1, SourceRange R2); |
| 118 | |
| 119 | //===--------------------------------------------------------------------===// |
| 120 | // Type Analysis / Processing: SemaType.cpp. |
| 121 | // |
| 122 | QualType GetTypeForDeclarator(Declarator &D, Scope *S); |
| 123 | |
| 124 | virtual TypeResult ParseTypeName(Scope *S, Declarator &D); |
| 125 | |
| 126 | virtual TypeResult ParseParamDeclaratorType(Scope *S, Declarator &D); |
| 127 | private: |
| 128 | //===--------------------------------------------------------------------===// |
| 129 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
| 130 | // |
| 131 | virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const; |
| 132 | virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init, |
| 133 | DeclTy *LastInGroup); |
| 134 | virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group); |
| 135 | |
| 136 | virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D); |
| 137 | virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body); |
| 138 | virtual void PopScope(SourceLocation Loc, Scope *S); |
| 139 | |
| 140 | /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with |
| 141 | /// no declarator (e.g. "struct foo;") is parsed. |
| 142 | virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS); |
| 143 | |
| 144 | virtual DeclTy *ParseTag(Scope *S, unsigned TagType, TagKind TK, |
| 145 | SourceLocation KWLoc, IdentifierInfo *Name, |
| 146 | SourceLocation NameLoc, AttributeList *Attr); |
| 147 | virtual DeclTy *ParseField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart, |
| 148 | Declarator &D, ExprTy *BitfieldWidth); |
| 149 | virtual void ParseRecordBody(SourceLocation RecLoc, DeclTy *TagDecl, |
| 150 | DeclTy **Fields, unsigned NumFields); |
| 151 | virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl, |
| 152 | DeclTy *LastEnumConstant, |
| 153 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 154 | SourceLocation EqualLoc, ExprTy *Val); |
| 155 | virtual void ParseEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl, |
| 156 | DeclTy **Elements, unsigned NumElements); |
| 157 | private: |
| 158 | /// Subroutines of ParseDeclarator()... |
| 159 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *LastDeclarator); |
| 160 | TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old); |
| 161 | FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old); |
| 162 | VarDecl *MergeVarDecl(VarDecl *New, Decl *Old); |
| 163 | /// AddTopLevelDecl - called after the decl has been fully processed. |
| 164 | /// Allows for bookkeeping and post-processing of each declaration. |
| 165 | void AddTopLevelDecl(Decl *current, Decl *last); |
| 166 | |
| 167 | /// More parsing and symbol table subroutines... |
| 168 | ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo, |
| 169 | Scope *FnBodyScope); |
| 170 | Decl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, SourceLocation IdLoc, |
| 171 | Scope *S); |
| 172 | Decl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S); |
| 173 | Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
| 174 | Scope *S); |
| 175 | // Decl attributes - this routine is the top level dispatcher. |
| 176 | void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix, |
| 177 | AttributeList *declarator_postfix); |
| 178 | void HandleDeclAttribute(Decl *New, AttributeList *rawAttr); |
| 179 | |
| 180 | // HandleVectorTypeAttribute - this attribute is only applicable to |
| 181 | // integral and float scalars, although arrays, pointers, and function |
| 182 | // return values are allowed in conjunction with this construct. Aggregates |
| 183 | // with this attribute are invalid, even if they are of the same size as a |
| 184 | // corresponding scalar. |
| 185 | // The raw attribute should contain precisely 1 argument, the vector size |
| 186 | // for the variable, measured in bytes. If curType and rawAttr are well |
| 187 | // formed, this routine will return a new vector type. |
| 188 | QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr); |
Steve Naroff | 82113e3 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 189 | void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 190 | |
| 191 | //===--------------------------------------------------------------------===// |
| 192 | // Statement Parsing Callbacks: SemaStmt.cpp. |
| 193 | public: |
| 194 | virtual StmtResult ParseExprStmt(ExprTy *Expr); |
| 195 | |
| 196 | virtual StmtResult ParseNullStmt(SourceLocation SemiLoc); |
| 197 | virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R, |
| 198 | StmtTy **Elts, unsigned NumElts); |
| 199 | virtual StmtResult ParseDeclStmt(DeclTy *Decl); |
| 200 | virtual StmtResult ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal, |
| 201 | SourceLocation DotDotDotLoc, ExprTy *RHSVal, |
| 202 | SourceLocation ColonLoc, StmtTy *SubStmt); |
| 203 | virtual StmtResult ParseDefaultStmt(SourceLocation DefaultLoc, |
| 204 | SourceLocation ColonLoc, StmtTy *SubStmt, |
| 205 | Scope *CurScope); |
| 206 | virtual StmtResult ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, |
| 207 | SourceLocation ColonLoc, StmtTy *SubStmt); |
| 208 | virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal, |
| 209 | StmtTy *ThenVal, SourceLocation ElseLoc, |
| 210 | StmtTy *ElseVal); |
| 211 | virtual StmtResult StartSwitchStmt(ExprTy *Cond); |
| 212 | virtual StmtResult FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, |
| 213 | ExprTy *Body); |
| 214 | virtual StmtResult ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, |
| 215 | StmtTy *Body); |
| 216 | virtual StmtResult ParseDoStmt(SourceLocation DoLoc, StmtTy *Body, |
| 217 | SourceLocation WhileLoc, ExprTy *Cond); |
| 218 | |
| 219 | virtual StmtResult ParseForStmt(SourceLocation ForLoc, |
| 220 | SourceLocation LParenLoc, |
| 221 | StmtTy *First, ExprTy *Second, ExprTy *Third, |
| 222 | SourceLocation RParenLoc, StmtTy *Body); |
| 223 | virtual StmtResult ParseGotoStmt(SourceLocation GotoLoc, |
| 224 | SourceLocation LabelLoc, |
| 225 | IdentifierInfo *LabelII); |
| 226 | virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc, |
| 227 | SourceLocation StarLoc, |
| 228 | ExprTy *DestExp); |
| 229 | virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc, |
| 230 | Scope *CurScope); |
| 231 | virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope); |
| 232 | |
| 233 | virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc, |
| 234 | ExprTy *RetValExp); |
| 235 | |
| 236 | //===--------------------------------------------------------------------===// |
| 237 | // Expression Parsing Callbacks: SemaExpr.cpp. |
| 238 | |
| 239 | // Primary Expressions. |
| 240 | virtual ExprResult ParseIdentifierExpr(Scope *S, SourceLocation Loc, |
| 241 | IdentifierInfo &II, |
| 242 | bool HasTrailingLParen); |
| 243 | virtual ExprResult ParsePreDefinedExpr(SourceLocation Loc, |
| 244 | tok::TokenKind Kind); |
| 245 | virtual ExprResult ParseNumericConstant(const Token &); |
| 246 | virtual ExprResult ParseCharacterConstant(const Token &); |
| 247 | virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R, |
| 248 | ExprTy *Val); |
| 249 | |
| 250 | /// ParseStringLiteral - The specified tokens were lexed as pasted string |
| 251 | /// fragments (e.g. "foo" "bar" L"baz"). |
| 252 | virtual ExprResult ParseStringLiteral(const Token *Toks, unsigned NumToks); |
| 253 | |
| 254 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
| 255 | virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op, |
| 256 | ExprTy *Input); |
| 257 | virtual ExprResult |
| 258 | ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof, |
| 259 | SourceLocation LParenLoc, TypeTy *Ty, |
| 260 | SourceLocation RParenLoc); |
| 261 | |
| 262 | virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc, |
| 263 | tok::TokenKind Kind, ExprTy *Input); |
| 264 | |
| 265 | virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc, |
| 266 | ExprTy *Idx, SourceLocation RLoc); |
| 267 | virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc, |
| 268 | tok::TokenKind OpKind, |
| 269 | SourceLocation MemberLoc, |
| 270 | IdentifierInfo &Member); |
| 271 | |
| 272 | /// ParseCallExpr - Handle a call to Fn with the specified array of arguments. |
| 273 | /// This provides the location of the left/right parens and a list of comma |
| 274 | /// locations. |
| 275 | virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc, |
| 276 | ExprTy **Args, unsigned NumArgs, |
| 277 | SourceLocation *CommaLocs, |
| 278 | SourceLocation RParenLoc); |
| 279 | |
| 280 | virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
| 281 | SourceLocation RParenLoc, ExprTy *Op); |
| 282 | |
| 283 | virtual ExprResult ParseCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, |
| 284 | SourceLocation RParenLoc, ExprTy *Op); |
| 285 | |
| 286 | virtual ExprResult ParseInitList(SourceLocation LParenLoc, |
| 287 | ExprTy **InitList, unsigned NumInit, |
| 288 | SourceLocation RParenLoc); |
| 289 | |
| 290 | virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind, |
| 291 | ExprTy *LHS,ExprTy *RHS); |
| 292 | |
| 293 | /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
| 294 | /// in the case of a the GNU conditional expr extension. |
| 295 | virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc, |
| 296 | SourceLocation ColonLoc, |
| 297 | ExprTy *Cond, ExprTy *LHS, ExprTy *RHS); |
| 298 | |
| 299 | /// ParseAddrLabel - Parse the GNU address of label extension: "&&foo". |
| 300 | virtual ExprResult ParseAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
| 301 | IdentifierInfo *LabelII); |
| 302 | |
| 303 | virtual ExprResult ParseStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt, |
| 304 | SourceLocation RPLoc); // "({..})" |
Steve Naroff | 63bad2d | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 305 | |
| 306 | // __builtin_types_compatible_p(type1, type2) |
Steve Naroff | 5b52892 | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 307 | virtual ExprResult ParseTypesCompatibleExpr(SourceLocation BuiltinLoc, |
Steve Naroff | 63bad2d | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 308 | TypeTy *arg1, TypeTy *arg2, |
| 309 | SourceLocation RPLoc); |
Steve Naroff | 93c5301 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 310 | |
| 311 | // __builtin_choose_expr(constExpr, expr1, expr2) |
| 312 | virtual ExprResult ParseChooseExpr(SourceLocation BuiltinLoc, |
| 313 | ExprTy *cond, ExprTy *expr1, ExprTy *expr2, |
| 314 | SourceLocation RPLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 315 | |
| 316 | /// ParseCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's. |
| 317 | virtual ExprResult ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind, |
| 318 | SourceLocation LAngleBracketLoc, TypeTy *Ty, |
| 319 | SourceLocation RAngleBracketLoc, |
| 320 | SourceLocation LParenLoc, ExprTy *E, |
| 321 | SourceLocation RParenLoc); |
| 322 | |
| 323 | /// ParseCXXBoolLiteral - Parse {true,false} literals. |
| 324 | virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc, |
| 325 | tok::TokenKind Kind); |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame^] | 326 | |
| 327 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
| 328 | virtual ExprResult ParseObjCStringLiteral(ExprTy *string); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 329 | private: |
| 330 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
| 331 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
| 332 | void UsualUnaryConversions(Expr *&expr); |
| 333 | |
| 334 | // DefaultFunctionArrayConversion - converts functions and arrays |
| 335 | // to their respective pointers (C99 6.3.2.1). |
| 336 | void DefaultFunctionArrayConversion(Expr *&expr); |
| 337 | |
| 338 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
| 339 | // operands and then handles various conversions that are common to binary |
| 340 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
| 341 | // routine returns the first non-arithmetic type found. The client is |
| 342 | // responsible for emitting appropriate error diagnostics. |
| 343 | void UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr); |
| 344 | |
| 345 | enum AssignmentCheckResult { |
| 346 | Compatible, |
| 347 | Incompatible, |
| 348 | PointerFromInt, |
| 349 | IntFromPointer, |
| 350 | IncompatiblePointer, |
| 351 | CompatiblePointerDiscardsQualifiers |
| 352 | }; |
| 353 | // CheckAssignmentConstraints - Perform type checking for assignment, |
| 354 | // argument passing, variable initialization, and function return values. |
| 355 | // This routine is only used by the following two methods. C99 6.5.16. |
| 356 | AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs); |
| 357 | |
| 358 | // CheckSingleAssignmentConstraints - Currently used by ParseCallExpr, |
| 359 | // CheckAssignmentOperands, and ParseReturnStmt. Prior to type checking, |
| 360 | // this routine performs the default function/array converions. |
| 361 | AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs, |
| 362 | Expr *&rExpr); |
| 363 | // CheckCompoundAssignmentConstraints - Type check without performing any |
| 364 | // conversions. For compound assignments, the "Check...Operands" methods |
| 365 | // perform the necessary conversions. |
| 366 | AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs, |
| 367 | QualType rhs); |
| 368 | |
| 369 | // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1) |
| 370 | AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType, |
| 371 | QualType rhsType); |
| 372 | |
| 373 | /// the following "Check" methods will return a valid/converted QualType |
| 374 | /// or a null QualType (indicating an error diagnostic was issued). |
| 375 | |
| 376 | /// type checking binary operators (subroutines of ParseBinOp). |
| 377 | inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
| 378 | inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex); |
| 379 | inline QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
| 380 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 381 | inline QualType CheckRemainderOperands( // C99 6.5.5 |
| 382 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 383 | inline QualType CheckAdditionOperands( // C99 6.5.6 |
| 384 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 385 | inline QualType CheckSubtractionOperands( // C99 6.5.6 |
| 386 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 387 | inline QualType CheckShiftOperands( // C99 6.5.7 |
| 388 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 389 | inline QualType CheckRelationalOperands( // C99 6.5.8 |
| 390 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 391 | inline QualType CheckEqualityOperands( // C99 6.5.9 |
| 392 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 393 | inline QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
| 394 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 395 | inline QualType CheckLogicalOperands( // C99 6.5.[13,14] |
| 396 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 397 | // CheckAssignmentOperands is used for both simple and compound assignment. |
| 398 | // For simple assignment, pass both expressions and a null converted type. |
| 399 | // For compound assignment, pass both expressions and the converted type. |
| 400 | inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
| 401 | Expr *lex, Expr *rex, SourceLocation OpLoc, QualType convertedType); |
| 402 | inline QualType CheckCommaOperands( // C99 6.5.17 |
| 403 | Expr *&lex, Expr *&rex, SourceLocation OpLoc); |
| 404 | inline QualType CheckConditionalOperands( // C99 6.5.15 |
| 405 | Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc); |
| 406 | |
| 407 | /// type checking unary operators (subroutines of ParseUnaryOp). |
| 408 | /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4 |
| 409 | QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc); |
| 410 | QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc); |
| 411 | QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc); |
| 412 | QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc, |
| 413 | bool isSizeof); |
Steve Naroff | 1b8a46c | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 414 | |
| 415 | /// type checking primary expressions. |
| 416 | QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc, |
| 417 | IdentifierInfo &Comp, SourceLocation CmpLoc); |
| 418 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 419 | /// C99: 6.7.5p3: Used by ParseDeclarator/ParseField to make sure we have |
| 420 | /// a constant expression of type int with a value greater than zero. If the |
| 421 | /// array has an incomplete type or a valid constant size, return false, |
| 422 | /// otherwise emit a diagnostic and return true. |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 423 | bool VerifyConstantArrayType(const ArrayType *ary, SourceLocation loc); |
| 424 | |
| 425 | //===--------------------------------------------------------------------===// |
| 426 | // Extra semantic analysis beyond the C type system |
| 427 | private: |
| 428 | |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 429 | bool CheckFunctionCall(Expr *Fn, |
Ted Kremenek | 081ed87 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 430 | SourceLocation LParenLoc, SourceLocation RParenLoc, |
| 431 | FunctionDecl *FDecl, |
Chris Lattner | 2e64c07 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 432 | Expr** Args, unsigned NumArgsInCall); |
| 433 | |
Ted Kremenek | 081ed87 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 434 | void CheckPrintfArguments(Expr *Fn, |
| 435 | SourceLocation LParenLoc, SourceLocation RParenLoc, |
| 436 | bool HasVAListArg, FunctionDecl *FDecl, |
Ted Kremenek | 3059654 | 2007-08-10 21:21:05 +0000 | [diff] [blame] | 437 | unsigned format_idx, Expr** Args, |
| 438 | unsigned NumArgsInCall); |
Ted Kremenek | 45925ab | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 439 | |
| 440 | void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, |
| 441 | SourceLocation ReturnLoc); |
| 442 | |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 443 | |
| 444 | bool CheckBuiltinCFStringArgument(Expr* Arg); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | |
| 448 | } // end namespace clang |
| 449 | |
| 450 | #endif |