Chris Lattner | cc67ec1 | 2006-11-09 06:54:47 +0000 | [diff] [blame] | 1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | cc67ec1 | 2006-11-09 06:54:47 +0000 | [diff] [blame] | 10 | // This file defines the Sema class, which performs semantic analysis and |
| 11 | // builds ASTs. |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | cc67ec1 | 2006-11-09 06:54:47 +0000 | [diff] [blame] | 15 | #ifndef LLVM_CLANG_AST_SEMA_H |
| 16 | #define LLVM_CLANG_AST_SEMA_H |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 17 | |
| 18 | #include "clang/Parse/Action.h" |
Chris Lattner | e247306 | 2007-05-28 06:28:18 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 20 | #include <vector> |
Chris Lattner | eaafe122 | 2006-11-10 05:17:58 +0000 | [diff] [blame] | 21 | #include <string> |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | namespace clang { |
Chris Lattner | cb6a382 | 2006-11-10 06:20:45 +0000 | [diff] [blame] | 25 | class ASTContext; |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 26 | class Preprocessor; |
| 27 | class Decl; |
Steve Naroff | 7840336 | 2007-04-02 22:55:05 +0000 | [diff] [blame] | 28 | class Expr; |
Chris Lattner | c5cdf4d | 2007-01-21 07:42:07 +0000 | [diff] [blame] | 29 | class VarDecl; |
Chris Lattner | 01564d9 | 2007-01-27 19:27:06 +0000 | [diff] [blame] | 30 | class TypedefDecl; |
| 31 | class FunctionDecl; |
Steve Naroff | e5aa9be | 2007-04-05 22:36:20 +0000 | [diff] [blame] | 32 | class QualType; |
Chris Lattner | ac18be9 | 2006-11-20 06:49:47 +0000 | [diff] [blame] | 33 | class LangOptions; |
Chris Lattner | c5cdf4d | 2007-01-21 07:42:07 +0000 | [diff] [blame] | 34 | class DeclaratorChunk; |
Steve Naroff | 8160ea2 | 2007-03-06 01:09:46 +0000 | [diff] [blame] | 35 | class LexerToken; |
Steve Naroff | 35d8515 | 2007-05-07 00:24:15 +0000 | [diff] [blame] | 36 | class IntegerLiteral; |
Steve Naroff | 8eeeb13 | 2007-05-08 21:09:37 +0000 | [diff] [blame] | 37 | class ArrayType; |
Chris Lattner | e247306 | 2007-05-28 06:28:18 +0000 | [diff] [blame] | 38 | class LabelStmt; |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 39 | |
Chris Lattner | cc67ec1 | 2006-11-09 06:54:47 +0000 | [diff] [blame] | 40 | /// Sema - This implements semantic analysis and AST building for C. |
| 41 | class Sema : public Action { |
Steve Naroff | 38d31b4 | 2007-02-28 01:22:02 +0000 | [diff] [blame] | 42 | Preprocessor &PP; |
| 43 | |
Chris Lattner | cb6a382 | 2006-11-10 06:20:45 +0000 | [diff] [blame] | 44 | ASTContext &Context; |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 45 | |
Chris Lattner | 229ce60 | 2006-11-21 01:21:07 +0000 | [diff] [blame] | 46 | /// CurFunctionDecl - If inside of a function body, this contains a pointer to |
| 47 | /// the function decl for the function being parsed. |
| 48 | FunctionDecl *CurFunctionDecl; |
| 49 | |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 50 | /// LastInGroupList - This vector is populated when there are multiple |
| 51 | /// declarators in a single decl group (e.g. "int A, B, C"). In this case, |
| 52 | /// all but the last decl will be entered into this. This is used by the |
| 53 | /// ASTStreamer. |
| 54 | std::vector<Decl*> &LastInGroupList; |
Chris Lattner | e247306 | 2007-05-28 06:28:18 +0000 | [diff] [blame] | 55 | |
| 56 | /// LabelMap - This is a mapping from label identifiers to the LabelStmt for |
| 57 | /// it (which acts like the label decl in some ways). Forward referenced |
| 58 | /// labels have a LabelStmt created for them with a null location & SubStmt. |
| 59 | DenseMap<IdentifierInfo*, LabelStmt*> LabelMap; |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 60 | public: |
Steve Naroff | 2c055d2 | 2007-02-28 19:32:13 +0000 | [diff] [blame] | 61 | Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup); |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 62 | |
Chris Lattner | ac18be9 | 2006-11-20 06:49:47 +0000 | [diff] [blame] | 63 | const LangOptions &getLangOptions() const; |
| 64 | |
Steve Naroff | 71ce2e0 | 2007-05-18 22:53:50 +0000 | [diff] [blame] | 65 | /// The primitive diagnostic helpers - always returns true, which simplifies |
| 66 | /// error handling (i.e. less code). |
Chris Lattner | d6647d3 | 2007-05-16 17:56:50 +0000 | [diff] [blame] | 67 | bool Diag(SourceLocation Loc, unsigned DiagID); |
| 68 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg); |
| 69 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, |
| 70 | const std::string &Msg2); |
Steve Naroff | 71ce2e0 | 2007-05-18 22:53:50 +0000 | [diff] [blame] | 71 | |
| 72 | /// More expressive diagnostic helpers for expressions (say that 6 times:-) |
| 73 | bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1); |
| 74 | bool Diag(SourceLocation Loc, unsigned DiagID, |
| 75 | SourceRange R1, SourceRange R2); |
| 76 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, |
| 77 | SourceRange R1); |
| 78 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg, |
| 79 | SourceRange R1, SourceRange R2); |
| 80 | bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, |
| 81 | const std::string &Msg2, SourceRange R1); |
| 82 | bool Diag(SourceLocation Loc, unsigned DiagID, |
| 83 | const std::string &Msg1, const std::string &Msg2, |
| 84 | SourceRange R1, SourceRange R2); |
| 85 | |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 86 | //===--------------------------------------------------------------------===// |
Chris Lattner | f84a79c | 2006-11-11 22:59:23 +0000 | [diff] [blame] | 87 | // Type Analysis / Processing: SemaType.cpp. |
| 88 | // |
Steve Naroff | e5aa9be | 2007-04-05 22:36:20 +0000 | [diff] [blame] | 89 | QualType GetTypeForDeclarator(Declarator &D, Scope *S); |
Chris Lattner | f84a79c | 2006-11-11 22:59:23 +0000 | [diff] [blame] | 90 | |
Chris Lattner | 33e8a55 | 2006-11-19 01:48:02 +0000 | [diff] [blame] | 91 | virtual TypeResult ParseTypeName(Scope *S, Declarator &D); |
Chris Lattner | f84a79c | 2006-11-11 22:59:23 +0000 | [diff] [blame] | 92 | |
Chris Lattner | 216d865 | 2006-12-02 06:47:41 +0000 | [diff] [blame] | 93 | virtual TypeResult ParseParamDeclaratorType(Scope *S, Declarator &D); |
Steve Naroff | 26c8ea5 | 2007-03-21 21:08:52 +0000 | [diff] [blame] | 94 | private: |
Chris Lattner | f84a79c | 2006-11-11 22:59:23 +0000 | [diff] [blame] | 95 | //===--------------------------------------------------------------------===// |
Chris Lattner | e168f76 | 2006-11-10 05:29:30 +0000 | [diff] [blame] | 96 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 97 | // |
Chris Lattner | 2ebe4bb | 2006-11-20 01:29:42 +0000 | [diff] [blame] | 98 | virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const; |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 99 | virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init, |
| 100 | DeclTy *LastInGroup); |
Chris Lattner | c5cdf4d | 2007-01-21 07:42:07 +0000 | [diff] [blame] | 101 | virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D); |
Chris Lattner | 229ce60 | 2006-11-21 01:21:07 +0000 | [diff] [blame] | 102 | virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body); |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 103 | virtual void PopScope(SourceLocation Loc, Scope *S); |
Chris Lattner | 01564d9 | 2007-01-27 19:27:06 +0000 | [diff] [blame] | 104 | |
Chris Lattner | 200bdc3 | 2006-11-19 02:43:37 +0000 | [diff] [blame] | 105 | /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with |
| 106 | /// no declarator (e.g. "struct foo;") is parsed. |
| 107 | virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS); |
| 108 | |
Chris Lattner | 7b9ace6 | 2007-01-23 20:11:08 +0000 | [diff] [blame] | 109 | virtual DeclTy *ParseTag(Scope *S, unsigned TagType, TagKind TK, |
Chris Lattner | f34c4da | 2007-01-23 04:08:05 +0000 | [diff] [blame] | 110 | SourceLocation KWLoc, IdentifierInfo *Name, |
| 111 | SourceLocation NameLoc); |
Chris Lattner | 1300fb9 | 2007-01-23 23:42:53 +0000 | [diff] [blame] | 112 | virtual DeclTy *ParseField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart, |
| 113 | Declarator &D, ExprTy *BitfieldWidth); |
| 114 | virtual void ParseRecordBody(SourceLocation RecLoc, DeclTy *TagDecl, |
| 115 | DeclTy **Fields, unsigned NumFields); |
Chris Lattner | c1915e2 | 2007-01-25 07:29:02 +0000 | [diff] [blame] | 116 | virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl, |
| 117 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 118 | SourceLocation EqualLoc, ExprTy *Val); |
| 119 | virtual void ParseEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl, |
| 120 | DeclTy **Elements, unsigned NumElements); |
Steve Naroff | 3273c22 | 2007-03-14 21:52:03 +0000 | [diff] [blame] | 121 | private: |
| 122 | /// Subroutines of ParseDeclarator()... |
| 123 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D); |
| 124 | TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old); |
| 125 | FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old); |
| 126 | VarDecl *MergeVarDecl(VarDecl *New, Decl *Old); |
Steve Naroff | 26c8ea5 | 2007-03-21 21:08:52 +0000 | [diff] [blame] | 127 | /// AddTopLevelDecl - called after the decl has been fully processed. |
| 128 | /// Allows for bookkeeping and post-processing of each declaration. |
| 129 | void AddTopLevelDecl(Decl *current, Decl *last); |
Steve Naroff | 6fbf0dc | 2007-03-16 00:33:25 +0000 | [diff] [blame] | 130 | |
Steve Naroff | 3273c22 | 2007-03-14 21:52:03 +0000 | [diff] [blame] | 131 | /// More parsing and symbol table subroutines... |
| 132 | VarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo, |
| 133 | Scope *FnBodyScope); |
| 134 | Decl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, SourceLocation IdLoc, |
| 135 | Scope *S); |
| 136 | Decl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S); |
| 137 | Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
| 138 | Scope *S); |
Chris Lattner | 1300fb9 | 2007-01-23 23:42:53 +0000 | [diff] [blame] | 139 | |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 140 | //===--------------------------------------------------------------------===// |
Chris Lattner | e168f76 | 2006-11-10 05:29:30 +0000 | [diff] [blame] | 141 | // Statement Parsing Callbacks: SemaStmt.cpp. |
Steve Naroff | 3273c22 | 2007-03-14 21:52:03 +0000 | [diff] [blame] | 142 | public: |
Chris Lattner | 0f203a7 | 2007-05-28 01:45:28 +0000 | [diff] [blame] | 143 | virtual StmtResult ParseNullStmt(SourceLocation SemiLoc); |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 144 | virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R, |
| 145 | StmtTy **Elts, unsigned NumElts); |
Steve Naroff | 2a8ad18 | 2007-05-29 22:59:26 +0000 | [diff] [blame^] | 146 | virtual StmtResult ParseDeclStmt(DeclTy *Decl); |
Chris Lattner | 6c0ff13 | 2006-11-05 00:19:50 +0000 | [diff] [blame] | 147 | virtual StmtResult ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal, |
| 148 | SourceLocation DotDotDotLoc, ExprTy *RHSVal, |
| 149 | SourceLocation ColonLoc, StmtTy *SubStmt); |
| 150 | virtual StmtResult ParseDefaultStmt(SourceLocation DefaultLoc, |
| 151 | SourceLocation ColonLoc, StmtTy *SubStmt); |
| 152 | virtual StmtResult ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, |
| 153 | SourceLocation ColonLoc, StmtTy *SubStmt); |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 154 | virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal, |
| 155 | StmtTy *ThenVal, SourceLocation ElseLoc, |
| 156 | StmtTy *ElseVal); |
Chris Lattner | f2174b6 | 2006-11-04 20:59:27 +0000 | [diff] [blame] | 157 | virtual StmtResult ParseSwitchStmt(SourceLocation SwitchLoc, ExprTy *Cond, |
| 158 | StmtTy *Body); |
Chris Lattner | 85ed873 | 2006-11-04 20:40:44 +0000 | [diff] [blame] | 159 | virtual StmtResult ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, |
| 160 | StmtTy *Body); |
| 161 | virtual StmtResult ParseDoStmt(SourceLocation DoLoc, StmtTy *Body, |
| 162 | SourceLocation WhileLoc, ExprTy *Cond); |
| 163 | |
Chris Lattner | 71e23ce | 2006-11-04 20:18:38 +0000 | [diff] [blame] | 164 | virtual StmtResult ParseForStmt(SourceLocation ForLoc, |
| 165 | SourceLocation LParenLoc, |
| 166 | StmtTy *First, ExprTy *Second, ExprTy *Third, |
| 167 | SourceLocation RParenLoc, StmtTy *Body); |
Chris Lattner | 16976d3 | 2006-11-05 01:46:01 +0000 | [diff] [blame] | 168 | virtual StmtResult ParseGotoStmt(SourceLocation GotoLoc, |
| 169 | SourceLocation LabelLoc, |
| 170 | IdentifierInfo *LabelII); |
| 171 | virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc, |
| 172 | SourceLocation StarLoc, |
| 173 | ExprTy *DestExp); |
Chris Lattner | eaafe122 | 2006-11-10 05:17:58 +0000 | [diff] [blame] | 174 | virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc, |
| 175 | Scope *CurScope); |
| 176 | virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope); |
Chris Lattner | 71e23ce | 2006-11-04 20:18:38 +0000 | [diff] [blame] | 177 | |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 178 | virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc, |
| 179 | ExprTy *RetValExp); |
| 180 | |
| 181 | //===--------------------------------------------------------------------===// |
Chris Lattner | e168f76 | 2006-11-10 05:29:30 +0000 | [diff] [blame] | 182 | // Expression Parsing Callbacks: SemaExpr.cpp. |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 183 | |
| 184 | // Primary Expressions. |
Chris Lattner | ac18be9 | 2006-11-20 06:49:47 +0000 | [diff] [blame] | 185 | virtual ExprResult ParseIdentifierExpr(Scope *S, SourceLocation Loc, |
| 186 | IdentifierInfo &II, |
| 187 | bool HasTrailingLParen); |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 188 | virtual ExprResult ParseSimplePrimaryExpr(SourceLocation Loc, |
| 189 | tok::TokenKind Kind); |
Steve Naroff | 8160ea2 | 2007-03-06 01:09:46 +0000 | [diff] [blame] | 190 | virtual ExprResult ParseNumericConstant(const LexerToken &); |
Steve Naroff | ae4143e | 2007-04-26 20:39:23 +0000 | [diff] [blame] | 191 | virtual ExprResult ParseCharacterConstant(const LexerToken &); |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 192 | virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R, |
| 193 | ExprTy *Val); |
Chris Lattner | 697e5d6 | 2006-11-09 06:32:27 +0000 | [diff] [blame] | 194 | |
Steve Naroff | df7855b | 2007-02-21 23:46:25 +0000 | [diff] [blame] | 195 | /// ParseStringLiteral - The specified tokens were lexed as pasted string |
Chris Lattner | 697e5d6 | 2006-11-09 06:32:27 +0000 | [diff] [blame] | 196 | /// fragments (e.g. "foo" "bar" L"baz"). |
Steve Naroff | df7855b | 2007-02-21 23:46:25 +0000 | [diff] [blame] | 197 | virtual ExprResult ParseStringLiteral(const LexerToken *Toks, unsigned NumToks); |
Chris Lattner | 697e5d6 | 2006-11-09 06:32:27 +0000 | [diff] [blame] | 198 | |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 199 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
| 200 | virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op, |
| 201 | ExprTy *Input); |
| 202 | virtual ExprResult |
| 203 | ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof, |
| 204 | SourceLocation LParenLoc, TypeTy *Ty, |
| 205 | SourceLocation RParenLoc); |
| 206 | |
| 207 | virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc, |
| 208 | tok::TokenKind Kind, ExprTy *Input); |
| 209 | |
| 210 | virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc, |
| 211 | ExprTy *Idx, SourceLocation RLoc); |
| 212 | virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc, |
| 213 | tok::TokenKind OpKind, |
| 214 | SourceLocation MemberLoc, |
| 215 | IdentifierInfo &Member); |
| 216 | |
| 217 | /// ParseCallExpr - Handle a call to Fn with the specified array of arguments. |
| 218 | /// This provides the location of the left/right parens and a list of comma |
| 219 | /// locations. |
| 220 | virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc, |
| 221 | ExprTy **Args, unsigned NumArgs, |
| 222 | SourceLocation *CommaLocs, |
| 223 | SourceLocation RParenLoc); |
| 224 | |
| 225 | virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
| 226 | SourceLocation RParenLoc, ExprTy *Op); |
| 227 | |
| 228 | virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind, |
| 229 | ExprTy *LHS,ExprTy *RHS); |
| 230 | |
| 231 | /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
| 232 | /// in the case of a the GNU conditional expr extension. |
| 233 | virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc, |
| 234 | SourceLocation ColonLoc, |
| 235 | ExprTy *Cond, ExprTy *LHS, ExprTy *RHS); |
Chris Lattner | 2937565 | 2006-12-04 18:06:35 +0000 | [diff] [blame] | 236 | |
Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 237 | /// ParseAddrLabel - Parse the GNU address of label extension: "&&foo". |
| 238 | virtual ExprResult ParseAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
| 239 | IdentifierInfo *LabelII); |
| 240 | |
Chris Lattner | 2937565 | 2006-12-04 18:06:35 +0000 | [diff] [blame] | 241 | /// ParseCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's. |
| 242 | virtual ExprResult ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind, |
| 243 | SourceLocation LAngleBracketLoc, TypeTy *Ty, |
| 244 | SourceLocation RAngleBracketLoc, |
| 245 | SourceLocation LParenLoc, ExprTy *E, |
| 246 | SourceLocation RParenLoc); |
Bill Wendling | 4073ed5 | 2007-02-13 01:51:42 +0000 | [diff] [blame] | 247 | |
| 248 | /// ParseCXXBoolLiteral - Parse {true,false} literals. |
| 249 | virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc, |
Bill Wendling | bf313b0 | 2007-02-13 20:09:46 +0000 | [diff] [blame] | 250 | tok::TokenKind Kind); |
Steve Naroff | 26c8ea5 | 2007-03-21 21:08:52 +0000 | [diff] [blame] | 251 | private: |
Steve Naroff | 1926c83 | 2007-04-24 00:23:05 +0000 | [diff] [blame] | 252 | QualType UsualUnaryConversion(QualType t); // C99 6.3 |
| 253 | QualType UsualArithmeticConversions(QualType t1, QualType t2); // C99 6.3.1.8 |
| 254 | |
Steve Naroff | 17f76e0 | 2007-05-03 21:03:48 +0000 | [diff] [blame] | 255 | enum AssignmentConversionResult { |
| 256 | Compatible, |
| 257 | Incompatible, |
| 258 | PointerFromInt, |
| 259 | IntFromPointer, |
Steve Naroff | 1f4d727 | 2007-05-11 04:00:31 +0000 | [diff] [blame] | 260 | IncompatiblePointer, |
| 261 | CompatiblePointerDiscardsQualifiers |
Steve Naroff | 17f76e0 | 2007-05-03 21:03:48 +0000 | [diff] [blame] | 262 | }; |
Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 263 | // Conversions for assignment, argument passing, initialization, and |
| 264 | // function return values. UsualAssignmentConversions is currently used by |
| 265 | // CheckSimpleAssignment, CheckCompoundAssignment and ParseCallExpr. |
| 266 | QualType UsualAssignmentConversions(QualType lhs, QualType rhs, // C99 6.5.16 |
Steve Naroff | 1f4d727 | 2007-05-11 04:00:31 +0000 | [diff] [blame] | 267 | AssignmentConversionResult &r); |
Steve Naroff | 3f59729 | 2007-05-11 22:18:03 +0000 | [diff] [blame] | 268 | // Helper function for UsualAssignmentConversions (C99 6.5.16.1p1) |
| 269 | QualType CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType, |
| 270 | AssignmentConversionResult &r); |
Steve Naroff | 9eb2465 | 2007-05-02 21:58:15 +0000 | [diff] [blame] | 271 | |
Steve Naroff | 8eeeb13 | 2007-05-08 21:09:37 +0000 | [diff] [blame] | 272 | /// the following "Check" methods will return a valid/converted QualType |
| 273 | /// or a null QualType (indicating an error diagnostic was issued). |
| 274 | |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 275 | /// type checking binary operators (subroutines of ParseBinOp). |
Steve Naroff | 6f49f5d | 2007-05-29 14:23:36 +0000 | [diff] [blame] | 276 | inline void InvalidOperands(SourceLocation l, Expr *lex, Expr *rex); |
Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 277 | inline QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
| 278 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
| 279 | inline QualType CheckRemainderOperands( // C99 6.5.5 |
| 280 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
| 281 | inline QualType CheckAdditionOperands( // C99 6.5.6 |
| 282 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
| 283 | inline QualType CheckSubtractionOperands( // C99 6.5.6 |
| 284 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
| 285 | inline QualType CheckShiftOperands( // C99 6.5.7 |
| 286 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
| 287 | inline QualType CheckRelationalOperands( // C99 6.5.8 |
| 288 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
| 289 | inline QualType CheckEqualityOperands( // C99 6.5.9 |
| 290 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
| 291 | inline QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
| 292 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
| 293 | inline QualType CheckLogicalOperands( // C99 6.5.[13,14] |
| 294 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
Steve Naroff | 35d8515 | 2007-05-07 00:24:15 +0000 | [diff] [blame] | 295 | // CheckAssignmentOperands is used for both simple and compound assignment. |
| 296 | // For simple assignment, pass both expressions and a null converted type. |
| 297 | // For compound assignment, pass both expressions and the converted type. |
| 298 | inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
| 299 | Expr *lex, Expr *rex, SourceLocation OpLoc, QualType convertedType); |
Steve Naroff | 218bc2b | 2007-05-04 21:54:46 +0000 | [diff] [blame] | 300 | inline QualType CheckCommaOperands( // C99 6.5.17 |
Steve Naroff | ae4143e | 2007-04-26 20:39:23 +0000 | [diff] [blame] | 301 | Expr *lex, Expr *rex, SourceLocation OpLoc); |
Steve Naroff | f8a28c5 | 2007-05-15 20:29:32 +0000 | [diff] [blame] | 302 | inline QualType CheckConditionalOperands( // C99 6.5.15 |
| 303 | Expr *cond, Expr *lhs, Expr *rhs, SourceLocation questionLoc); |
Steve Naroff | 95af013 | 2007-03-30 23:47:58 +0000 | [diff] [blame] | 304 | |
Steve Naroff | 4750051 | 2007-04-19 23:00:49 +0000 | [diff] [blame] | 305 | /// type checking unary operators (subroutines of ParseUnaryOp). |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 306 | /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4 |
Steve Naroff | 71ce2e0 | 2007-05-18 22:53:50 +0000 | [diff] [blame] | 307 | QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc); |
| 308 | QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc); |
| 309 | QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc); |
| 310 | QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc, |
| 311 | bool isSizeof); |
Steve Naroff | 8eeeb13 | 2007-05-08 21:09:37 +0000 | [diff] [blame] | 312 | |
| 313 | // C99: 6.7.5p3: Used by ParseDeclarator/ParseField to make sure we have |
| 314 | // a constant expression of type int with a value greater than zero. |
| 315 | bool isConstantArrayType(ArrayType *ary, SourceLocation loc); |
Chris Lattner | 7cee11f | 2006-11-03 06:42:29 +0000 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | |
| 319 | } // end namespace clang |
| 320 | } // end namespace llvm |
| 321 | |
| 322 | #endif |