Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 1 | //===--- Builder.cpp - AST Builder Implementation -------------------------===// |
| 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 implements the actions class which builds an AST out of a parse |
| 11 | // stream. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | c11438c | 2006-08-18 05:17:52 +0000 | [diff] [blame] | 15 | #include "clang/Parse/Action.h" |
Chris Lattner | c11438c | 2006-08-18 05:17:52 +0000 | [diff] [blame] | 16 | #include "clang/AST/Decl.h" |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
| 18 | #include "clang/Parse/Scope.h" |
Chris Lattner | c11438c | 2006-08-18 05:17:52 +0000 | [diff] [blame] | 19 | #include "clang/Lex/IdentifierTable.h" |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 20 | #include "clang/Lex/LexerToken.h" |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame^] | 21 | #include "clang/Lex/Preprocessor.h" |
| 22 | #include "llvm/Support/Compiler.h" |
Chris Lattner | c11438c | 2006-08-18 05:17:52 +0000 | [diff] [blame] | 23 | using namespace llvm; |
| 24 | using namespace clang; |
| 25 | |
| 26 | /// ASTBuilder |
| 27 | namespace { |
| 28 | class VISIBILITY_HIDDEN ASTBuilder : public Action { |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame^] | 29 | Preprocessor &PP; |
| 30 | |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 31 | /// FullLocInfo - If this is true, the ASTBuilder constructs AST Nodes that |
| 32 | /// capture maximal location information for each source-language construct. |
| 33 | bool FullLocInfo; |
Chris Lattner | c11438c | 2006-08-18 05:17:52 +0000 | [diff] [blame] | 34 | public: |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame^] | 35 | ASTBuilder(Preprocessor &pp, bool fullLocInfo) |
| 36 | : PP(pp), FullLocInfo(fullLocInfo) {} |
| 37 | |
Chris Lattner | c11438c | 2006-08-18 05:17:52 +0000 | [diff] [blame] | 38 | //===--------------------------------------------------------------------===// |
| 39 | // Symbol table tracking callbacks. |
| 40 | // |
| 41 | virtual bool isTypedefName(const IdentifierInfo &II, Scope *S) const; |
| 42 | virtual void ParseDeclarator(SourceLocation Loc, Scope *S, Declarator &D, |
| 43 | ExprTy *Init); |
| 44 | virtual void PopScope(SourceLocation Loc, Scope *S); |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 45 | |
| 46 | //===--------------------------------------------------------------------===// |
| 47 | // Expression Parsing Callbacks. |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 48 | |
| 49 | // Primary Expressions. |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 50 | virtual ExprResult ParseSimplePrimaryExpr(const LexerToken &Tok); |
| 51 | virtual ExprResult ParseIntegerConstant(const LexerToken &Tok); |
| 52 | virtual ExprResult ParseFloatingConstant(const LexerToken &Tok); |
| 53 | virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R, |
| 54 | ExprTy *Val); |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame^] | 55 | virtual ExprResult ParseStringExpr(const char *StrData, unsigned StrLen, |
| 56 | bool isWide, |
| 57 | const LexerToken *Toks, unsigned NumToks); |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 58 | |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 59 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 60 | virtual ExprResult ParseUnaryOp(const LexerToken &Tok, ExprTy *Input); |
Chris Lattner | 26da730 | 2006-08-24 06:49:19 +0000 | [diff] [blame] | 61 | virtual ExprResult |
| 62 | ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof, |
| 63 | SourceLocation LParenLoc, TypeTy *Ty, |
| 64 | SourceLocation RParenLoc); |
| 65 | |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 66 | virtual ExprResult ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input); |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 67 | |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 68 | virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc, |
| 69 | ExprTy *Idx, SourceLocation RLoc); |
| 70 | virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc, |
| 71 | tok::TokenKind OpKind, |
| 72 | SourceLocation MemberLoc, |
| 73 | IdentifierInfo &Member); |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 74 | |
| 75 | /// ParseCallExpr - Handle a call to Fn with the specified array of arguments. |
| 76 | /// This provides the location of the left/right parens and a list of comma |
| 77 | /// locations. |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 78 | virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc, |
| 79 | ExprTy **Args, unsigned NumArgs, |
| 80 | SourceLocation *CommaLocs, |
| 81 | SourceLocation RParenLoc); |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 82 | |
Chris Lattner | e550a4e | 2006-08-24 06:37:51 +0000 | [diff] [blame] | 83 | virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
| 84 | SourceLocation RParenLoc, ExprTy *Op); |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 85 | |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 86 | virtual ExprResult ParseBinOp(const LexerToken &Tok, ExprTy *LHS,ExprTy *RHS); |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 87 | |
| 88 | /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
| 89 | /// in the case of a the GNU conditional expr extension. |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 90 | virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc, |
| 91 | SourceLocation ColonLoc, |
| 92 | ExprTy *Cond, ExprTy *LHS, ExprTy *RHS); |
Chris Lattner | c11438c | 2006-08-18 05:17:52 +0000 | [diff] [blame] | 93 | }; |
| 94 | } // end anonymous namespace |
| 95 | |
| 96 | |
| 97 | //===----------------------------------------------------------------------===// |
| 98 | // Symbol table tracking callbacks. |
| 99 | //===----------------------------------------------------------------------===// |
| 100 | |
| 101 | bool ASTBuilder::isTypedefName(const IdentifierInfo &II, Scope *S) const { |
| 102 | Decl *D = II.getFETokenInfo<Decl>(); |
| 103 | return D != 0 && D->getDeclSpecs().StorageClassSpec == DeclSpec::SCS_typedef; |
| 104 | } |
| 105 | |
| 106 | void ASTBuilder::ParseDeclarator(SourceLocation Loc, Scope *S, Declarator &D, |
| 107 | ExprTy *Init) { |
| 108 | IdentifierInfo *II = D.getIdentifier(); |
| 109 | Decl *PrevDecl = II ? II->getFETokenInfo<Decl>() : 0; |
| 110 | |
| 111 | Decl *New = new Decl(II, D.getDeclSpec(), Loc, PrevDecl); |
| 112 | |
| 113 | // If this has an identifier, add it to the scope stack. |
| 114 | if (II) { |
| 115 | // If PrevDecl includes conflicting name here, emit a diagnostic. |
| 116 | II->setFETokenInfo(New); |
| 117 | S->AddDecl(II); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void ASTBuilder::PopScope(SourceLocation Loc, Scope *S) { |
| 122 | for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end(); |
| 123 | I != E; ++I) { |
| 124 | IdentifierInfo &II = *static_cast<IdentifierInfo*>(*I); |
| 125 | Decl *D = II.getFETokenInfo<Decl>(); |
| 126 | assert(D && "This decl didn't get pushed??"); |
| 127 | |
| 128 | Decl *Next = D->getNext(); |
| 129 | |
| 130 | // FIXME: Push the decl on the parent function list if in a function. |
| 131 | delete D; |
| 132 | |
| 133 | II.setFETokenInfo(Next); |
| 134 | } |
| 135 | } |
| 136 | |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 137 | //===--------------------------------------------------------------------===// |
| 138 | // Expression Parsing Callbacks. |
| 139 | //===--------------------------------------------------------------------===// |
| 140 | |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 141 | Action::ExprResult ASTBuilder::ParseSimplePrimaryExpr(const LexerToken &Tok) { |
Chris Lattner | 879b9ad | 2006-08-24 04:53:44 +0000 | [diff] [blame] | 142 | switch (Tok.getKind()) { |
| 143 | default: |
| 144 | assert(0 && "Unknown simple primary expr!"); |
| 145 | case tok::identifier: { |
| 146 | // Could be enum-constant or decl. |
| 147 | //Tok.getIdentifierInfo() |
| 148 | return new DeclExpr(*(Decl*)0); |
| 149 | } |
| 150 | |
| 151 | case tok::char_constant: // constant: character-constant |
| 152 | case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2] |
| 153 | case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU] |
| 154 | case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU] |
| 155 | assert(0 && "Unimp so far!"); |
| 156 | return 0; |
| 157 | } |
| 158 | } |
| 159 | |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 160 | Action::ExprResult ASTBuilder::ParseIntegerConstant(const LexerToken &Tok) { |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 161 | return new IntegerConstant(); |
| 162 | } |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 163 | Action::ExprResult ASTBuilder::ParseFloatingConstant(const LexerToken &Tok) { |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 164 | return new FloatingConstant(); |
| 165 | } |
| 166 | |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 167 | Action::ExprResult ASTBuilder::ParseParenExpr(SourceLocation L, |
| 168 | SourceLocation R, |
| 169 | ExprTy *Val) { |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 170 | // FIXME: This is obviously just for testing. |
| 171 | ((Expr*)Val)->dump(); |
| 172 | if (!FullLocInfo) return Val; |
| 173 | |
| 174 | return new ParenExpr(L, R, (Expr*)Val); |
| 175 | } |
| 176 | |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame^] | 177 | /// ParseStringExpr - This accepts a string after semantic analysis. This string |
| 178 | /// may be the result of string concatenation ([C99 5.1.1.2, translation phase |
| 179 | /// #6]), so it may come from multiple tokens. |
| 180 | /// |
| 181 | Action::ExprResult ASTBuilder:: |
| 182 | ParseStringExpr(const char *StrData, unsigned StrLen, bool isWide, |
| 183 | const LexerToken *Toks, unsigned NumToks) { |
| 184 | assert(NumToks && "Must have at least one string!"); |
| 185 | |
| 186 | if (!FullLocInfo) |
| 187 | return new StringExpr(StrData, StrLen, isWide); |
| 188 | else { |
| 189 | SmallVector<SourceLocation, 4> Locs; |
| 190 | for (unsigned i = 0; i != NumToks; ++i) |
| 191 | Locs.push_back(Toks[i].getLocation()); |
| 192 | return new StringExprLOC(StrData, StrLen, isWide, &Locs[0], Locs.size()); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 197 | // Unary Operators. 'Tok' is the token for the operator. |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 198 | Action::ExprResult ASTBuilder::ParseUnaryOp(const LexerToken &Tok, |
| 199 | ExprTy *Input) { |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 200 | UnaryOperator::Opcode Opc; |
| 201 | switch (Tok.getKind()) { |
| 202 | default: assert(0 && "Unknown unary op!"); |
Chris Lattner | 26115ac | 2006-08-24 06:10:04 +0000 | [diff] [blame] | 203 | case tok::plusplus: Opc = UnaryOperator::PreInc; break; |
| 204 | case tok::minusminus: Opc = UnaryOperator::PreDec; break; |
| 205 | case tok::amp: Opc = UnaryOperator::AddrOf; break; |
| 206 | case tok::star: Opc = UnaryOperator::Deref; break; |
| 207 | case tok::plus: Opc = UnaryOperator::Plus; break; |
| 208 | case tok::minus: Opc = UnaryOperator::Minus; break; |
| 209 | case tok::tilde: Opc = UnaryOperator::Not; break; |
| 210 | case tok::exclaim: Opc = UnaryOperator::LNot; break; |
| 211 | case tok::kw___real: Opc = UnaryOperator::Real; break; |
| 212 | case tok::kw___imag: Opc = UnaryOperator::Imag; break; |
| 213 | case tok::kw_sizeof: Opc = UnaryOperator::SizeOf; break; |
| 214 | case tok::kw___alignof: Opc = UnaryOperator::AlignOf; break; |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | if (!FullLocInfo) |
| 218 | return new UnaryOperator((Expr*)Input, Opc); |
| 219 | else |
| 220 | return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc); |
| 221 | } |
| 222 | |
Chris Lattner | 26da730 | 2006-08-24 06:49:19 +0000 | [diff] [blame] | 223 | Action::ExprResult ASTBuilder:: |
| 224 | ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof, |
| 225 | SourceLocation LParenLoc, TypeTy *Ty, |
| 226 | SourceLocation RParenLoc) { |
| 227 | if (!FullLocInfo) |
| 228 | return new SizeOfAlignOfTypeExpr(isSizeof, (Type*)Ty); |
| 229 | else |
| 230 | return new SizeOfAlignOfTypeExprLOC(OpLoc, isSizeof, LParenLoc, (Type*)Ty, |
| 231 | RParenLoc); |
| 232 | } |
| 233 | |
| 234 | |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 235 | Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(const LexerToken &Tok, |
| 236 | ExprTy *Input) { |
Chris Lattner | 1b92649 | 2006-08-23 06:42:10 +0000 | [diff] [blame] | 237 | UnaryOperator::Opcode Opc; |
| 238 | switch (Tok.getKind()) { |
| 239 | default: assert(0 && "Unknown unary op!"); |
| 240 | case tok::plusplus: Opc = UnaryOperator::PostInc; break; |
| 241 | case tok::minusminus: Opc = UnaryOperator::PostDec; break; |
| 242 | } |
| 243 | |
| 244 | if (!FullLocInfo) |
| 245 | return new UnaryOperator((Expr*)Input, Opc); |
| 246 | else |
| 247 | return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc); |
| 248 | } |
| 249 | |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 250 | Action::ExprResult ASTBuilder:: |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 251 | ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc, |
| 252 | ExprTy *Idx, SourceLocation RLoc) { |
| 253 | if (!FullLocInfo) |
| 254 | return new ArraySubscriptExpr((Expr*)Base, (Expr*)Idx); |
| 255 | else |
| 256 | return new ArraySubscriptExprLOC((Expr*)Base, LLoc, (Expr*)Idx, RLoc); |
| 257 | } |
| 258 | |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 259 | Action::ExprResult ASTBuilder:: |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 260 | ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc, |
| 261 | tok::TokenKind OpKind, SourceLocation MemberLoc, |
| 262 | IdentifierInfo &Member) { |
Chris Lattner | 6f3a117 | 2006-08-24 05:19:28 +0000 | [diff] [blame] | 263 | Decl *MemberDecl = 0; |
| 264 | // TODO: Look up MemberDecl. |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 265 | if (!FullLocInfo) |
Chris Lattner | 6f3a117 | 2006-08-24 05:19:28 +0000 | [diff] [blame] | 266 | return new MemberExpr((Expr*)Base, OpKind == tok::arrow, MemberDecl); |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 267 | else |
| 268 | return new MemberExprLOC((Expr*)Base, OpLoc, OpKind == tok::arrow, |
Chris Lattner | 6f3a117 | 2006-08-24 05:19:28 +0000 | [diff] [blame] | 269 | MemberLoc, MemberDecl); |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 270 | } |
| 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. |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 275 | Action::ExprResult ASTBuilder:: |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 276 | ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc, |
| 277 | ExprTy **Args, unsigned NumArgs, |
| 278 | SourceLocation *CommaLocs, SourceLocation RParenLoc) { |
| 279 | if (!FullLocInfo) |
| 280 | return new CallExpr((Expr*)Fn, (Expr**)Args, NumArgs); |
| 281 | else |
| 282 | return new CallExprLOC((Expr*)Fn, LParenLoc, (Expr**)Args, NumArgs, |
| 283 | CommaLocs, RParenLoc); |
| 284 | } |
| 285 | |
Chris Lattner | e550a4e | 2006-08-24 06:37:51 +0000 | [diff] [blame] | 286 | Action::ExprResult ASTBuilder:: |
| 287 | ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
| 288 | SourceLocation RParenLoc, ExprTy *Op) { |
| 289 | if (!FullLocInfo) |
| 290 | return new CastExpr((Type*)Ty, (Expr*)Op); |
| 291 | else |
| 292 | return new CastExprLOC(LParenLoc, (Type*)Ty, RParenLoc, (Expr*)Op); |
| 293 | } |
| 294 | |
| 295 | |
Chris Lattner | e165d94 | 2006-08-24 04:40:38 +0000 | [diff] [blame] | 296 | |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 297 | // Binary Operators. 'Tok' is the token for the operator. |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 298 | Action::ExprResult ASTBuilder::ParseBinOp(const LexerToken &Tok, ExprTy *LHS, |
| 299 | ExprTy *RHS) { |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 300 | BinaryOperator::Opcode Opc; |
| 301 | switch (Tok.getKind()) { |
| 302 | default: assert(0 && "Unknown binop!"); |
| 303 | case tok::star: Opc = BinaryOperator::Mul; break; |
| 304 | case tok::slash: Opc = BinaryOperator::Div; break; |
| 305 | case tok::percent: Opc = BinaryOperator::Rem; break; |
| 306 | case tok::plus: Opc = BinaryOperator::Add; break; |
| 307 | case tok::minus: Opc = BinaryOperator::Sub; break; |
| 308 | case tok::lessless: Opc = BinaryOperator::Shl; break; |
| 309 | case tok::greatergreater: Opc = BinaryOperator::Shr; break; |
| 310 | case tok::lessequal: Opc = BinaryOperator::LE; break; |
| 311 | case tok::less: Opc = BinaryOperator::LT; break; |
| 312 | case tok::greaterequal: Opc = BinaryOperator::GE; break; |
| 313 | case tok::greater: Opc = BinaryOperator::GT; break; |
| 314 | case tok::exclaimequal: Opc = BinaryOperator::NE; break; |
| 315 | case tok::equalequal: Opc = BinaryOperator::EQ; break; |
| 316 | case tok::amp: Opc = BinaryOperator::And; break; |
| 317 | case tok::caret: Opc = BinaryOperator::Xor; break; |
| 318 | case tok::pipe: Opc = BinaryOperator::Or; break; |
| 319 | case tok::ampamp: Opc = BinaryOperator::LAnd; break; |
| 320 | case tok::pipepipe: Opc = BinaryOperator::LOr; break; |
| 321 | case tok::equal: Opc = BinaryOperator::Assign; break; |
| 322 | case tok::starequal: Opc = BinaryOperator::MulAssign; break; |
| 323 | case tok::slashequal: Opc = BinaryOperator::DivAssign; break; |
| 324 | case tok::percentequal: Opc = BinaryOperator::RemAssign; break; |
| 325 | case tok::plusequal: Opc = BinaryOperator::AddAssign; break; |
| 326 | case tok::minusequal: Opc = BinaryOperator::SubAssign; break; |
| 327 | case tok::lesslessequal: Opc = BinaryOperator::ShlAssign; break; |
| 328 | case tok::greatergreaterequal: Opc = BinaryOperator::ShrAssign; break; |
| 329 | case tok::ampequal: Opc = BinaryOperator::AndAssign; break; |
| 330 | case tok::caretequal: Opc = BinaryOperator::XorAssign; break; |
| 331 | case tok::pipeequal: Opc = BinaryOperator::OrAssign; break; |
| 332 | case tok::comma: Opc = BinaryOperator::Comma; break; |
| 333 | } |
| 334 | |
| 335 | if (!FullLocInfo) |
| 336 | return new BinaryOperator((Expr*)LHS, (Expr*)RHS, Opc); |
| 337 | else |
| 338 | return new BinaryOperatorLOC((Expr*)LHS, Tok.getLocation(), (Expr*)RHS,Opc); |
| 339 | } |
| 340 | |
| 341 | /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
| 342 | /// in the case of a the GNU conditional expr extension. |
Chris Lattner | 98286a4 | 2006-08-24 05:02:11 +0000 | [diff] [blame] | 343 | Action::ExprResult ASTBuilder::ParseConditionalOp(SourceLocation QuestionLoc, |
| 344 | SourceLocation ColonLoc, |
| 345 | ExprTy *Cond, ExprTy *LHS, |
| 346 | ExprTy *RHS) { |
Chris Lattner | 9b6d4cb | 2006-08-23 05:17:46 +0000 | [diff] [blame] | 347 | if (!FullLocInfo) |
| 348 | return new ConditionalOperator((Expr*)Cond, (Expr*)LHS, (Expr*)RHS); |
| 349 | else |
| 350 | return new ConditionalOperatorLOC((Expr*)Cond, QuestionLoc, (Expr*)LHS, |
| 351 | ColonLoc, (Expr*)RHS); |
| 352 | } |
| 353 | |
Chris Lattner | c11438c | 2006-08-18 05:17:52 +0000 | [diff] [blame] | 354 | |
| 355 | /// Interface to the Builder.cpp file. |
| 356 | /// |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame^] | 357 | Action *CreateASTBuilderActions(Preprocessor &PP, bool FullLocInfo) { |
| 358 | return new ASTBuilder(PP, FullLocInfo); |
Chris Lattner | c11438c | 2006-08-18 05:17:52 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | |
| 362 | |