blob: e62de8bd609b50aa3bc4d655989a2127e5aadf40 [file] [log] [blame]
Chris Lattner3e7bd4e2006-08-17 05:51:27 +00001//===--- 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 Lattnerc11438c2006-08-18 05:17:52 +000015#include "clang/Parse/Action.h"
Chris Lattnerc11438c2006-08-18 05:17:52 +000016#include "clang/AST/Decl.h"
Chris Lattner9b6d4cb2006-08-23 05:17:46 +000017#include "clang/AST/Expr.h"
18#include "clang/Parse/Scope.h"
Chris Lattnerc11438c2006-08-18 05:17:52 +000019#include "clang/Lex/IdentifierTable.h"
Chris Lattnerd3e98952006-10-06 05:22:26 +000020#include "clang/Lex/Preprocessor.h"
21#include "llvm/Support/Compiler.h"
Chris Lattnerc11438c2006-08-18 05:17:52 +000022using namespace llvm;
23using namespace clang;
24
25/// ASTBuilder
26namespace {
27class VISIBILITY_HIDDEN ASTBuilder : public Action {
Chris Lattnerd3e98952006-10-06 05:22:26 +000028 Preprocessor &PP;
29
Chris Lattner9b6d4cb2006-08-23 05:17:46 +000030 /// FullLocInfo - If this is true, the ASTBuilder constructs AST Nodes that
31 /// capture maximal location information for each source-language construct.
32 bool FullLocInfo;
Chris Lattner2dacc3f2006-10-16 00:33:54 +000033
34 /// LastInGroupList - This vector is populated when there are multiple
35 /// declarators in a single decl group (e.g. "int A, B, C"). In this case,
36 /// all but the last decl will be entered into this. This is used by the
37 /// ASTStreamer.
38 std::vector<Decl*> &LastInGroupList;
Chris Lattnerc11438c2006-08-18 05:17:52 +000039public:
Chris Lattner2dacc3f2006-10-16 00:33:54 +000040 ASTBuilder(Preprocessor &pp, bool fullLocInfo,
41 std::vector<Decl*> &prevInGroup)
42 : PP(pp), FullLocInfo(fullLocInfo), LastInGroupList(prevInGroup) {}
Chris Lattnerd3e98952006-10-06 05:22:26 +000043
Chris Lattnerc11438c2006-08-18 05:17:52 +000044 //===--------------------------------------------------------------------===//
45 // Symbol table tracking callbacks.
46 //
47 virtual bool isTypedefName(const IdentifierInfo &II, Scope *S) const;
Chris Lattner2dacc3f2006-10-16 00:33:54 +000048 virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
49 DeclTy *LastInGroup);
50 virtual DeclTy *ParseFunctionDefinition(Scope *S, Declarator &D,
51 StmtTy *Body);
Chris Lattnerc11438c2006-08-18 05:17:52 +000052 virtual void PopScope(SourceLocation Loc, Scope *S);
Chris Lattner9b6d4cb2006-08-23 05:17:46 +000053
54 //===--------------------------------------------------------------------===//
Chris Lattnere5cca062006-10-25 04:29:46 +000055 // Statement Parsing Callbacks.
56
57 virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R,
58 StmtTy **Elts, unsigned NumElts);
59 virtual StmtResult ParseExprStmt(ExprTy *Expr) {
60 // TODO: Full info should track this with a node.
61 return Expr; // Exprs are Stmts.
62 }
63
64 virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
65 ExprTy *RetValExp);
66
67 //===--------------------------------------------------------------------===//
Chris Lattner9b6d4cb2006-08-23 05:17:46 +000068 // Expression Parsing Callbacks.
Chris Lattner1b926492006-08-23 06:42:10 +000069
70 // Primary Expressions.
Chris Lattnerae319692006-10-25 03:49:28 +000071 virtual ExprResult ParseSimplePrimaryExpr(SourceLocation Loc,
72 tok::TokenKind Kind);
73 virtual ExprResult ParseIntegerConstant(SourceLocation Loc);
74 virtual ExprResult ParseFloatingConstant(SourceLocation Loc);
Chris Lattner98286a42006-08-24 05:02:11 +000075 virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
76 ExprTy *Val);
Chris Lattnerd3e98952006-10-06 05:22:26 +000077 virtual ExprResult ParseStringExpr(const char *StrData, unsigned StrLen,
78 bool isWide,
Chris Lattnerae319692006-10-25 03:49:28 +000079 SourceLocation *TokLocs, unsigned NumToks);
Chris Lattner9b6d4cb2006-08-23 05:17:46 +000080
Chris Lattner1b926492006-08-23 06:42:10 +000081 // Binary/Unary Operators. 'Tok' is the token for the operator.
Chris Lattner0ba3dc42006-10-25 03:38:23 +000082 virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
83 ExprTy *Input);
Chris Lattner26da7302006-08-24 06:49:19 +000084 virtual ExprResult
85 ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
86 SourceLocation LParenLoc, TypeTy *Ty,
87 SourceLocation RParenLoc);
88
Chris Lattnerae319692006-10-25 03:49:28 +000089 virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
90 tok::TokenKind Kind, ExprTy *Input);
Chris Lattner1b926492006-08-23 06:42:10 +000091
Chris Lattner98286a42006-08-24 05:02:11 +000092 virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
93 ExprTy *Idx, SourceLocation RLoc);
94 virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
95 tok::TokenKind OpKind,
96 SourceLocation MemberLoc,
97 IdentifierInfo &Member);
Chris Lattnere165d942006-08-24 04:40:38 +000098
99 /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
100 /// This provides the location of the left/right parens and a list of comma
101 /// locations.
Chris Lattner98286a42006-08-24 05:02:11 +0000102 virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
103 ExprTy **Args, unsigned NumArgs,
104 SourceLocation *CommaLocs,
105 SourceLocation RParenLoc);
Chris Lattnere165d942006-08-24 04:40:38 +0000106
Chris Lattnere550a4e2006-08-24 06:37:51 +0000107 virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
108 SourceLocation RParenLoc, ExprTy *Op);
Chris Lattnere165d942006-08-24 04:40:38 +0000109
Chris Lattnerae319692006-10-25 03:49:28 +0000110 virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
111 ExprTy *LHS,ExprTy *RHS);
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000112
113 /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
114 /// in the case of a the GNU conditional expr extension.
Chris Lattner98286a42006-08-24 05:02:11 +0000115 virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc,
116 SourceLocation ColonLoc,
117 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
Chris Lattnerc11438c2006-08-18 05:17:52 +0000118};
119} // end anonymous namespace
120
121
122//===----------------------------------------------------------------------===//
123// Symbol table tracking callbacks.
124//===----------------------------------------------------------------------===//
125
126bool ASTBuilder::isTypedefName(const IdentifierInfo &II, Scope *S) const {
127 Decl *D = II.getFETokenInfo<Decl>();
Chris Lattnera11999d2006-10-15 22:34:45 +0000128 return D != 0 && D->getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef;
Chris Lattnerc11438c2006-08-18 05:17:52 +0000129}
130
Chris Lattner2dacc3f2006-10-16 00:33:54 +0000131Action::DeclTy *
132ASTBuilder::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
133 DeclTy *LastInGroup) {
Chris Lattnerc11438c2006-08-18 05:17:52 +0000134 IdentifierInfo *II = D.getIdentifier();
135 Decl *PrevDecl = II ? II->getFETokenInfo<Decl>() : 0;
136
Chris Lattnera11999d2006-10-15 22:34:45 +0000137 Decl *New;
138 if (D.isFunctionDeclarator())
Chris Lattner2dacc3f2006-10-16 00:33:54 +0000139 New = new FunctionDecl(II, D, PrevDecl);
Chris Lattnera11999d2006-10-15 22:34:45 +0000140 else
Chris Lattner2dacc3f2006-10-16 00:33:54 +0000141 New = new VarDecl(II, D, PrevDecl);
Chris Lattnerc11438c2006-08-18 05:17:52 +0000142
143 // If this has an identifier, add it to the scope stack.
144 if (II) {
145 // If PrevDecl includes conflicting name here, emit a diagnostic.
146 II->setFETokenInfo(New);
147 S->AddDecl(II);
148 }
Chris Lattner2dacc3f2006-10-16 00:33:54 +0000149
150 if (LastInGroup) LastInGroupList.push_back((Decl*)LastInGroup);
151
152 return New;
153}
154
155Action::DeclTy *
156ASTBuilder::ParseFunctionDefinition(Scope *S, Declarator &D, StmtTy *Body) {
157 FunctionDecl *FD = (FunctionDecl *)ParseDeclarator(S, D, 0, 0);
Chris Lattner30f910e2006-10-16 05:52:41 +0000158
159 FD->setBody((Stmt*)Body);
160
Chris Lattner2dacc3f2006-10-16 00:33:54 +0000161 return FD;
Chris Lattnerc11438c2006-08-18 05:17:52 +0000162}
163
164void ASTBuilder::PopScope(SourceLocation Loc, Scope *S) {
165 for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
166 I != E; ++I) {
167 IdentifierInfo &II = *static_cast<IdentifierInfo*>(*I);
168 Decl *D = II.getFETokenInfo<Decl>();
169 assert(D && "This decl didn't get pushed??");
170
171 Decl *Next = D->getNext();
172
173 // FIXME: Push the decl on the parent function list if in a function.
174 delete D;
175
176 II.setFETokenInfo(Next);
177 }
178}
179
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000180//===--------------------------------------------------------------------===//
Chris Lattnere5cca062006-10-25 04:29:46 +0000181// Statement Parsing Callbacks.
182//===--------------------------------------------------------------------===//
183
184Action::StmtResult
185ASTBuilder::ParseCompoundStmt(SourceLocation L, SourceLocation R,
186 StmtTy **Elts, unsigned NumElts) {
187 if (FullLocInfo || NumElts > 1)
188 return new CompoundStmt((Stmt**)Elts, NumElts);
189 else if (NumElts == 1)
190 return Elts[0]; // {stmt} -> stmt
191 else
192 return 0; // {} -> ;
193}
194
195
196Action::StmtResult
197ASTBuilder::ParseReturnStmt(SourceLocation ReturnLoc,
198 ExprTy *RetValExp) {
199
200}
201
202//===--------------------------------------------------------------------===//
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000203// Expression Parsing Callbacks.
204//===--------------------------------------------------------------------===//
205
Chris Lattnerae319692006-10-25 03:49:28 +0000206Action::ExprResult ASTBuilder::ParseSimplePrimaryExpr(SourceLocation Loc,
207 tok::TokenKind Kind) {
208 switch (Kind) {
Chris Lattner879b9ad2006-08-24 04:53:44 +0000209 default:
210 assert(0 && "Unknown simple primary expr!");
211 case tok::identifier: {
212 // Could be enum-constant or decl.
213 //Tok.getIdentifierInfo()
Chris Lattnerf42cce72006-10-25 04:09:21 +0000214 return new DeclRefExpr(*(Decl*)0);
Chris Lattner879b9ad2006-08-24 04:53:44 +0000215 }
216
217 case tok::char_constant: // constant: character-constant
218 case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2]
219 case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU]
220 case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU]
Chris Lattner94b4ce32006-10-06 05:51:35 +0000221 //assert(0 && "FIXME: Unimp so far!");
Chris Lattnerf42cce72006-10-25 04:09:21 +0000222 return new DeclRefExpr(*(Decl*)0);
Chris Lattner879b9ad2006-08-24 04:53:44 +0000223 }
224}
225
Chris Lattnerae319692006-10-25 03:49:28 +0000226Action::ExprResult ASTBuilder::ParseIntegerConstant(SourceLocation Loc) {
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000227 return new IntegerConstant();
228}
Chris Lattnerae319692006-10-25 03:49:28 +0000229Action::ExprResult ASTBuilder::ParseFloatingConstant(SourceLocation Loc) {
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000230 return new FloatingConstant();
231}
232
Chris Lattner98286a42006-08-24 05:02:11 +0000233Action::ExprResult ASTBuilder::ParseParenExpr(SourceLocation L,
234 SourceLocation R,
235 ExprTy *Val) {
Chris Lattner1b926492006-08-23 06:42:10 +0000236 if (!FullLocInfo) return Val;
237
238 return new ParenExpr(L, R, (Expr*)Val);
239}
240
Chris Lattnerd3e98952006-10-06 05:22:26 +0000241/// ParseStringExpr - This accepts a string after semantic analysis. This string
242/// may be the result of string concatenation ([C99 5.1.1.2, translation phase
243/// #6]), so it may come from multiple tokens.
244///
245Action::ExprResult ASTBuilder::
246ParseStringExpr(const char *StrData, unsigned StrLen, bool isWide,
Chris Lattnerae319692006-10-25 03:49:28 +0000247 SourceLocation *TokLocs, unsigned NumToks) {
Chris Lattnerd3e98952006-10-06 05:22:26 +0000248 assert(NumToks && "Must have at least one string!");
249
250 if (!FullLocInfo)
251 return new StringExpr(StrData, StrLen, isWide);
Chris Lattnerae319692006-10-25 03:49:28 +0000252 else
253 return new StringExprLOC(StrData, StrLen, isWide, TokLocs, NumToks);
Chris Lattnerd3e98952006-10-06 05:22:26 +0000254}
255
256
Chris Lattner1b926492006-08-23 06:42:10 +0000257// Unary Operators. 'Tok' is the token for the operator.
Chris Lattner0ba3dc42006-10-25 03:38:23 +0000258Action::ExprResult ASTBuilder::ParseUnaryOp(SourceLocation OpLoc,
259 tok::TokenKind Op,
Chris Lattner98286a42006-08-24 05:02:11 +0000260 ExprTy *Input) {
Chris Lattner1b926492006-08-23 06:42:10 +0000261 UnaryOperator::Opcode Opc;
Chris Lattner0ba3dc42006-10-25 03:38:23 +0000262 switch (Op) {
Chris Lattner1b926492006-08-23 06:42:10 +0000263 default: assert(0 && "Unknown unary op!");
Chris Lattner26115ac2006-08-24 06:10:04 +0000264 case tok::plusplus: Opc = UnaryOperator::PreInc; break;
265 case tok::minusminus: Opc = UnaryOperator::PreDec; break;
266 case tok::amp: Opc = UnaryOperator::AddrOf; break;
267 case tok::star: Opc = UnaryOperator::Deref; break;
268 case tok::plus: Opc = UnaryOperator::Plus; break;
269 case tok::minus: Opc = UnaryOperator::Minus; break;
270 case tok::tilde: Opc = UnaryOperator::Not; break;
271 case tok::exclaim: Opc = UnaryOperator::LNot; break;
Chris Lattner26115ac2006-08-24 06:10:04 +0000272 case tok::kw_sizeof: Opc = UnaryOperator::SizeOf; break;
273 case tok::kw___alignof: Opc = UnaryOperator::AlignOf; break;
Chris Lattnera11999d2006-10-15 22:34:45 +0000274 case tok::kw___real: Opc = UnaryOperator::Real; break;
275 case tok::kw___imag: Opc = UnaryOperator::Imag; break;
276 case tok::ampamp: Opc = UnaryOperator::AddrLabel; break;
Chris Lattner1b926492006-08-23 06:42:10 +0000277 }
278
279 if (!FullLocInfo)
280 return new UnaryOperator((Expr*)Input, Opc);
281 else
Chris Lattner0ba3dc42006-10-25 03:38:23 +0000282 return new UnaryOperatorLOC(OpLoc, (Expr*)Input, Opc);
Chris Lattner1b926492006-08-23 06:42:10 +0000283}
284
Chris Lattner26da7302006-08-24 06:49:19 +0000285Action::ExprResult ASTBuilder::
286ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
287 SourceLocation LParenLoc, TypeTy *Ty,
288 SourceLocation RParenLoc) {
289 if (!FullLocInfo)
290 return new SizeOfAlignOfTypeExpr(isSizeof, (Type*)Ty);
291 else
292 return new SizeOfAlignOfTypeExprLOC(OpLoc, isSizeof, LParenLoc, (Type*)Ty,
293 RParenLoc);
294}
295
296
Chris Lattnerae319692006-10-25 03:49:28 +0000297Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(SourceLocation OpLoc,
298 tok::TokenKind Kind,
Chris Lattner98286a42006-08-24 05:02:11 +0000299 ExprTy *Input) {
Chris Lattner1b926492006-08-23 06:42:10 +0000300 UnaryOperator::Opcode Opc;
Chris Lattnerae319692006-10-25 03:49:28 +0000301 switch (Kind) {
Chris Lattner1b926492006-08-23 06:42:10 +0000302 default: assert(0 && "Unknown unary op!");
303 case tok::plusplus: Opc = UnaryOperator::PostInc; break;
304 case tok::minusminus: Opc = UnaryOperator::PostDec; break;
305 }
306
307 if (!FullLocInfo)
308 return new UnaryOperator((Expr*)Input, Opc);
309 else
Chris Lattnerae319692006-10-25 03:49:28 +0000310 return new UnaryOperatorLOC(OpLoc, (Expr*)Input, Opc);
Chris Lattner1b926492006-08-23 06:42:10 +0000311}
312
Chris Lattner98286a42006-08-24 05:02:11 +0000313Action::ExprResult ASTBuilder::
Chris Lattnere165d942006-08-24 04:40:38 +0000314ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
315 ExprTy *Idx, SourceLocation RLoc) {
316 if (!FullLocInfo)
317 return new ArraySubscriptExpr((Expr*)Base, (Expr*)Idx);
318 else
319 return new ArraySubscriptExprLOC((Expr*)Base, LLoc, (Expr*)Idx, RLoc);
320}
321
Chris Lattner98286a42006-08-24 05:02:11 +0000322Action::ExprResult ASTBuilder::
Chris Lattnere165d942006-08-24 04:40:38 +0000323ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
324 tok::TokenKind OpKind, SourceLocation MemberLoc,
325 IdentifierInfo &Member) {
Chris Lattner6f3a1172006-08-24 05:19:28 +0000326 Decl *MemberDecl = 0;
327 // TODO: Look up MemberDecl.
Chris Lattnere165d942006-08-24 04:40:38 +0000328 if (!FullLocInfo)
Chris Lattner6f3a1172006-08-24 05:19:28 +0000329 return new MemberExpr((Expr*)Base, OpKind == tok::arrow, MemberDecl);
Chris Lattnere165d942006-08-24 04:40:38 +0000330 else
331 return new MemberExprLOC((Expr*)Base, OpLoc, OpKind == tok::arrow,
Chris Lattner6f3a1172006-08-24 05:19:28 +0000332 MemberLoc, MemberDecl);
Chris Lattnere165d942006-08-24 04:40:38 +0000333}
334
335/// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
336/// This provides the location of the left/right parens and a list of comma
337/// locations.
Chris Lattner98286a42006-08-24 05:02:11 +0000338Action::ExprResult ASTBuilder::
Chris Lattnere165d942006-08-24 04:40:38 +0000339ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
340 ExprTy **Args, unsigned NumArgs,
341 SourceLocation *CommaLocs, SourceLocation RParenLoc) {
342 if (!FullLocInfo)
343 return new CallExpr((Expr*)Fn, (Expr**)Args, NumArgs);
344 else
345 return new CallExprLOC((Expr*)Fn, LParenLoc, (Expr**)Args, NumArgs,
346 CommaLocs, RParenLoc);
347}
348
Chris Lattnere550a4e2006-08-24 06:37:51 +0000349Action::ExprResult ASTBuilder::
350ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
351 SourceLocation RParenLoc, ExprTy *Op) {
352 if (!FullLocInfo)
353 return new CastExpr((Type*)Ty, (Expr*)Op);
354 else
355 return new CastExprLOC(LParenLoc, (Type*)Ty, RParenLoc, (Expr*)Op);
356}
357
358
Chris Lattnere165d942006-08-24 04:40:38 +0000359
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000360// Binary Operators. 'Tok' is the token for the operator.
Chris Lattnerae319692006-10-25 03:49:28 +0000361Action::ExprResult ASTBuilder::ParseBinOp(SourceLocation TokLoc,
362 tok::TokenKind Kind, ExprTy *LHS,
Chris Lattner98286a42006-08-24 05:02:11 +0000363 ExprTy *RHS) {
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000364 BinaryOperator::Opcode Opc;
Chris Lattnerae319692006-10-25 03:49:28 +0000365 switch (Kind) {
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000366 default: assert(0 && "Unknown binop!");
367 case tok::star: Opc = BinaryOperator::Mul; break;
368 case tok::slash: Opc = BinaryOperator::Div; break;
369 case tok::percent: Opc = BinaryOperator::Rem; break;
370 case tok::plus: Opc = BinaryOperator::Add; break;
371 case tok::minus: Opc = BinaryOperator::Sub; break;
372 case tok::lessless: Opc = BinaryOperator::Shl; break;
373 case tok::greatergreater: Opc = BinaryOperator::Shr; break;
374 case tok::lessequal: Opc = BinaryOperator::LE; break;
375 case tok::less: Opc = BinaryOperator::LT; break;
376 case tok::greaterequal: Opc = BinaryOperator::GE; break;
377 case tok::greater: Opc = BinaryOperator::GT; break;
378 case tok::exclaimequal: Opc = BinaryOperator::NE; break;
379 case tok::equalequal: Opc = BinaryOperator::EQ; break;
380 case tok::amp: Opc = BinaryOperator::And; break;
381 case tok::caret: Opc = BinaryOperator::Xor; break;
382 case tok::pipe: Opc = BinaryOperator::Or; break;
383 case tok::ampamp: Opc = BinaryOperator::LAnd; break;
384 case tok::pipepipe: Opc = BinaryOperator::LOr; break;
385 case tok::equal: Opc = BinaryOperator::Assign; break;
386 case tok::starequal: Opc = BinaryOperator::MulAssign; break;
387 case tok::slashequal: Opc = BinaryOperator::DivAssign; break;
388 case tok::percentequal: Opc = BinaryOperator::RemAssign; break;
389 case tok::plusequal: Opc = BinaryOperator::AddAssign; break;
390 case tok::minusequal: Opc = BinaryOperator::SubAssign; break;
391 case tok::lesslessequal: Opc = BinaryOperator::ShlAssign; break;
392 case tok::greatergreaterequal: Opc = BinaryOperator::ShrAssign; break;
393 case tok::ampequal: Opc = BinaryOperator::AndAssign; break;
394 case tok::caretequal: Opc = BinaryOperator::XorAssign; break;
395 case tok::pipeequal: Opc = BinaryOperator::OrAssign; break;
396 case tok::comma: Opc = BinaryOperator::Comma; break;
397 }
398
399 if (!FullLocInfo)
400 return new BinaryOperator((Expr*)LHS, (Expr*)RHS, Opc);
401 else
Chris Lattnerae319692006-10-25 03:49:28 +0000402 return new BinaryOperatorLOC((Expr*)LHS, TokLoc, (Expr*)RHS, Opc);
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000403}
404
405/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
406/// in the case of a the GNU conditional expr extension.
Chris Lattner98286a42006-08-24 05:02:11 +0000407Action::ExprResult ASTBuilder::ParseConditionalOp(SourceLocation QuestionLoc,
408 SourceLocation ColonLoc,
409 ExprTy *Cond, ExprTy *LHS,
410 ExprTy *RHS) {
Chris Lattner9b6d4cb2006-08-23 05:17:46 +0000411 if (!FullLocInfo)
412 return new ConditionalOperator((Expr*)Cond, (Expr*)LHS, (Expr*)RHS);
413 else
414 return new ConditionalOperatorLOC((Expr*)Cond, QuestionLoc, (Expr*)LHS,
415 ColonLoc, (Expr*)RHS);
416}
417
Chris Lattnerc11438c2006-08-18 05:17:52 +0000418
419/// Interface to the Builder.cpp file.
420///
Chris Lattner2dacc3f2006-10-16 00:33:54 +0000421Action *CreateASTBuilderActions(Preprocessor &PP, bool FullLocInfo,
422 std::vector<Decl*> &LastInGroupList) {
423 return new ASTBuilder(PP, FullLocInfo, LastInGroupList);
Chris Lattnerc11438c2006-08-18 05:17:52 +0000424}
425