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