blob: e56a680f26f40f90ee9884778b6a2517d8660ab7 [file] [log] [blame]
Chris Lattner5b183d82006-11-10 05:03:26 +00001//===--- SemaExpr.cpp - Semantic Analysis for Expressions -----------------===//
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 semantic analysis for expressions.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Sema.h"
Chris Lattnercb6a3822006-11-10 06:20:45 +000015#include "clang/AST/ASTContext.h"
Chris Lattner17ed4872006-11-20 04:58:19 +000016#include "clang/AST/Decl.h"
Chris Lattner5b183d82006-11-10 05:03:26 +000017#include "clang/AST/Expr.h"
18#include "clang/Lex/Preprocessor.h"
Steve Naroff09ef4742007-03-09 23:16:33 +000019#include "clang/Lex/LiteralSupport.h"
Steve Narofff2fb89e2007-03-13 20:29:44 +000020#include "clang/Basic/SourceManager.h"
Chris Lattner5b183d82006-11-10 05:03:26 +000021#include "clang/Basic/Diagnostic.h"
Chris Lattnerac18be92006-11-20 06:49:47 +000022#include "clang/Basic/LangOptions.h"
Chris Lattner5b183d82006-11-10 05:03:26 +000023#include "clang/Basic/TargetInfo.h"
24#include "llvm/ADT/SmallString.h"
25#include "llvm/ADT/StringExtras.h"
26using namespace llvm;
27using namespace clang;
28
Steve Naroff09ef4742007-03-09 23:16:33 +000029#include <iostream>
Chris Lattner5b183d82006-11-10 05:03:26 +000030
31/// HexDigitValue - Return the value of the specified hex digit, or -1 if it's
32/// not valid.
33static int HexDigitValue(char C) {
34 if (C >= '0' && C <= '9') return C-'0';
35 if (C >= 'a' && C <= 'f') return C-'a'+10;
36 if (C >= 'A' && C <= 'F') return C-'A'+10;
37 return -1;
38}
39
Steve Naroffdf7855b2007-02-21 23:46:25 +000040/// ParseStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner5b183d82006-11-10 05:03:26 +000041/// fragments (e.g. "foo" "bar" L"baz"). The result string has to handle string
42/// concatenation ([C99 5.1.1.2, translation phase #6]), so it may come from
43/// multiple tokens. However, the common case is that StringToks points to one
44/// string.
45///
46Action::ExprResult
Steve Naroffdf7855b2007-02-21 23:46:25 +000047Sema::ParseStringLiteral(const LexerToken *StringToks, unsigned NumStringToks) {
Chris Lattner5b183d82006-11-10 05:03:26 +000048 assert(NumStringToks && "Must have at least one string!");
49
50 // Scan all of the string portions, remember the max individual token length,
51 // computing a bound on the concatenated string length, and see whether any
52 // piece is a wide-string. If any of the string portions is a wide-string
53 // literal, the result is a wide-string literal [C99 6.4.5p4].
54 unsigned MaxTokenLength = StringToks[0].getLength();
55 unsigned SizeBound = StringToks[0].getLength()-2; // -2 for "".
56 bool AnyWide = StringToks[0].getKind() == tok::wide_string_literal;
57
58 // The common case is that there is only one string fragment.
59 for (unsigned i = 1; i != NumStringToks; ++i) {
60 // The string could be shorter than this if it needs cleaning, but this is a
61 // reasonable bound, which is all we need.
62 SizeBound += StringToks[i].getLength()-2; // -2 for "".
63
64 // Remember maximum string piece length.
65 if (StringToks[i].getLength() > MaxTokenLength)
66 MaxTokenLength = StringToks[i].getLength();
67
68 // Remember if we see any wide strings.
69 AnyWide |= StringToks[i].getKind() == tok::wide_string_literal;
70 }
71
72
73 // Include space for the null terminator.
74 ++SizeBound;
75
76 // TODO: K&R warning: "traditional C rejects string constant concatenation"
77
78 // Get the width in bytes of wchar_t. If no wchar_t strings are used, do not
79 // query the target. As such, wchar_tByteWidth is only valid if AnyWide=true.
80 unsigned wchar_tByteWidth = ~0U;
81 if (AnyWide)
Chris Lattnerddc135e2006-11-10 06:34:16 +000082 wchar_tByteWidth =Context.Target.getWCharWidth(StringToks[0].getLocation());
Chris Lattner5b183d82006-11-10 05:03:26 +000083
84 // The output buffer size needs to be large enough to hold wide characters.
85 // This is a worst-case assumption which basically corresponds to L"" "long".
86 if (AnyWide)
87 SizeBound *= wchar_tByteWidth;
88
89 // Create a temporary buffer to hold the result string data.
90 SmallString<512> ResultBuf;
91 ResultBuf.resize(SizeBound);
92
93 // Likewise, but for each string piece.
94 SmallString<512> TokenBuf;
95 TokenBuf.resize(MaxTokenLength);
96
97 // Loop over all the strings, getting their spelling, and expanding them to
98 // wide strings as appropriate.
99 char *ResultPtr = &ResultBuf[0]; // Next byte to fill in.
100
101 for (unsigned i = 0, e = NumStringToks; i != e; ++i) {
102 const char *ThisTokBuf = &TokenBuf[0];
103 // Get the spelling of the token, which eliminates trigraphs, etc. We know
104 // that ThisTokBuf points to a buffer that is big enough for the whole token
105 // and 'spelled' tokens can only shrink.
Steve Naroff38d31b42007-02-28 01:22:02 +0000106 unsigned ThisTokLen = PP.getSpelling(StringToks[i], ThisTokBuf);
Chris Lattner5b183d82006-11-10 05:03:26 +0000107 const char *ThisTokEnd = ThisTokBuf+ThisTokLen-1; // Skip end quote.
108
109 // TODO: Input character set mapping support.
110
111 // Skip L marker for wide strings.
112 if (ThisTokBuf[0] == 'L') ++ThisTokBuf;
113
114 assert(ThisTokBuf[0] == '"' && "Expected quote, lexer broken?");
115 ++ThisTokBuf;
116
117 while (ThisTokBuf != ThisTokEnd) {
118 // Is this a span of non-escape characters?
119 if (ThisTokBuf[0] != '\\') {
120 const char *InStart = ThisTokBuf;
121 do {
122 ++ThisTokBuf;
123 } while (ThisTokBuf != ThisTokEnd && ThisTokBuf[0] != '\\');
124
125 // Copy the character span over.
126 unsigned Len = ThisTokBuf-InStart;
127 if (!AnyWide) {
128 memcpy(ResultPtr, InStart, Len);
129 ResultPtr += Len;
130 } else {
131 // Note: our internal rep of wide char tokens is always little-endian.
132 for (; Len; --Len, ++InStart) {
133 *ResultPtr++ = InStart[0];
134 // Add zeros at the end.
135 for (unsigned i = 1, e = wchar_tByteWidth; i != e; ++i)
136 *ResultPtr++ = 0;
137 }
138 }
139 continue;
140 }
141
142 // Otherwise, this is an escape character. Skip the '\' char.
143 ++ThisTokBuf;
144
145 // We know that this character can't be off the end of the buffer, because
146 // that would have been \", which would not have been the end of string.
147 unsigned ResultChar = *ThisTokBuf++;
148 switch (ResultChar) {
149 // These map to themselves.
150 case '\\': case '\'': case '"': case '?': break;
151
152 // These have fixed mappings.
153 case 'a':
154 // TODO: K&R: the meaning of '\\a' is different in traditional C
155 ResultChar = 7;
156 break;
157 case 'b':
158 ResultChar = 8;
159 break;
160 case 'e':
Chris Lattnercb6a3822006-11-10 06:20:45 +0000161 Diag(StringToks[i].getLocation(), diag::ext_nonstandard_escape, "e");
Chris Lattner5b183d82006-11-10 05:03:26 +0000162 ResultChar = 27;
163 break;
164 case 'f':
165 ResultChar = 12;
166 break;
167 case 'n':
168 ResultChar = 10;
169 break;
170 case 'r':
171 ResultChar = 13;
172 break;
173 case 't':
174 ResultChar = 9;
175 break;
176 case 'v':
177 ResultChar = 11;
178 break;
179
180 //case 'u': case 'U': // FIXME: UCNs.
181 case 'x': // Hex escape.
182 if (ThisTokBuf == ThisTokEnd ||
183 (ResultChar = HexDigitValue(*ThisTokBuf)) == ~0U) {
Chris Lattnercb6a3822006-11-10 06:20:45 +0000184 Diag(StringToks[i].getLocation(), diag::err_hex_escape_no_digits);
Chris Lattner5b183d82006-11-10 05:03:26 +0000185 ResultChar = 0;
186 break;
187 }
188 ++ThisTokBuf; // Consumed one hex digit.
189
190 assert(0 && "hex escape: unimp!");
191 break;
192 case '0': case '1': case '2': case '3':
193 case '4': case '5': case '6': case '7':
194 // Octal escapes.
195 assert(0 && "octal escape: unimp!");
196 break;
197
198 // Otherwise, these are not valid escapes.
199 case '(': case '{': case '[': case '%':
200 // GCC accepts these as extensions. We warn about them as such though.
Steve Naroff38d31b42007-02-28 01:22:02 +0000201 if (!PP.getLangOptions().NoExtensions) {
Chris Lattnercb6a3822006-11-10 06:20:45 +0000202 Diag(StringToks[i].getLocation(), diag::ext_nonstandard_escape,
203 std::string()+(char)ResultChar);
Chris Lattner5b183d82006-11-10 05:03:26 +0000204 break;
205 }
206 // FALL THROUGH.
207 default:
208 if (isgraph(ThisTokBuf[0])) {
Chris Lattnercb6a3822006-11-10 06:20:45 +0000209 Diag(StringToks[i].getLocation(), diag::ext_unknown_escape,
210 std::string()+(char)ResultChar);
Chris Lattner5b183d82006-11-10 05:03:26 +0000211 } else {
Chris Lattnercb6a3822006-11-10 06:20:45 +0000212 Diag(StringToks[i].getLocation(), diag::ext_unknown_escape,
213 "x"+utohexstr(ResultChar));
Chris Lattner5b183d82006-11-10 05:03:26 +0000214 }
215 }
216
217 // Note: our internal rep of wide char tokens is always little-endian.
218 *ResultPtr++ = ResultChar & 0xFF;
219
220 if (AnyWide) {
221 for (unsigned i = 1, e = wchar_tByteWidth; i != e; ++i)
222 *ResultPtr++ = ResultChar >> i*8;
223 }
224 }
225 }
226
227 // Add zero terminator.
228 *ResultPtr = 0;
229 if (AnyWide) {
230 for (unsigned i = 1, e = wchar_tByteWidth; i != e; ++i)
231 *ResultPtr++ = 0;
232 }
233
234 SmallVector<SourceLocation, 4> StringTokLocs;
235 for (unsigned i = 0; i != NumStringToks; ++i)
236 StringTokLocs.push_back(StringToks[i].getLocation());
237
238 // FIXME: use factory.
239
240 // Pass &StringTokLocs[0], StringTokLocs.size() to factory!
Steve Naroffdf7855b2007-02-21 23:46:25 +0000241 return new StringLiteral(&ResultBuf[0], ResultPtr-&ResultBuf[0], AnyWide);
Chris Lattner5b183d82006-11-10 05:03:26 +0000242}
243
Chris Lattnere168f762006-11-10 05:29:30 +0000244
Chris Lattnerac18be92006-11-20 06:49:47 +0000245/// ParseIdentifierExpr - The parser read an identifier in expression context,
246/// validate it per-C99 6.5.1. HasTrailingLParen indicates whether this
247/// identifier is used in an function call context.
248Sema::ExprResult Sema::ParseIdentifierExpr(Scope *S, SourceLocation Loc,
249 IdentifierInfo &II,
250 bool HasTrailingLParen) {
Chris Lattner17ed4872006-11-20 04:58:19 +0000251 // Could be enum-constant or decl.
Chris Lattner9561a0b2007-01-28 08:20:04 +0000252 Decl *D = LookupScopedDecl(&II, Decl::IDNS_Ordinary, Loc, S);
Chris Lattner17ed4872006-11-20 04:58:19 +0000253 if (D == 0) {
Bill Wendling4073ed52007-02-13 01:51:42 +0000254 // Otherwise, this could be an implicitly declared function reference (legal
Chris Lattner9561a0b2007-01-28 08:20:04 +0000255 // in C90, extension in C99).
Chris Lattnerac18be92006-11-20 06:49:47 +0000256 if (HasTrailingLParen &&
257 // Not in C++.
258 !getLangOptions().CPlusPlus) {
259 D = ImplicitlyDefineFunction(Loc, II, S);
260 } else {
261 // If this name wasn't predeclared and if this is not a function call,
262 // diagnose the problem.
263 Diag(Loc, diag::err_undeclared_var_use, II.getName());
264 return true;
265 }
Chris Lattner17ed4872006-11-20 04:58:19 +0000266 }
267
Chris Lattner32d920b2007-01-26 02:01:53 +0000268 if (isa<TypedefDecl>(D)) {
Chris Lattner17ed4872006-11-20 04:58:19 +0000269 Diag(Loc, diag::err_unexpected_typedef, II.getName());
270 return true;
271 }
272
Chris Lattner5efbb332006-11-20 05:01:40 +0000273 return new DeclRefExpr(D);
Chris Lattner17ed4872006-11-20 04:58:19 +0000274}
Chris Lattnere168f762006-11-10 05:29:30 +0000275
Chris Lattner17ed4872006-11-20 04:58:19 +0000276Sema::ExprResult Sema::ParseSimplePrimaryExpr(SourceLocation Loc,
277 tok::TokenKind Kind) {
Chris Lattnere168f762006-11-10 05:29:30 +0000278 switch (Kind) {
279 default:
280 assert(0 && "Unknown simple primary expr!");
Chris Lattnere168f762006-11-10 05:29:30 +0000281 case tok::char_constant: // constant: character-constant
Chris Lattner17ed4872006-11-20 04:58:19 +0000282 // TODO: MOVE this to be some other callback.
Chris Lattnere168f762006-11-10 05:29:30 +0000283 case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2]
284 case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU]
285 case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU]
Chris Lattner17ed4872006-11-20 04:58:19 +0000286 return 0;
Chris Lattnere168f762006-11-10 05:29:30 +0000287 }
288}
289
Steve Naroff8160ea22007-03-06 01:09:46 +0000290Action::ExprResult Sema::ParseNumericConstant(const LexerToken &Tok) {
Steve Narofff2fb89e2007-03-13 20:29:44 +0000291 // fast path for a single digit (which is quite common). A single digit
292 // cannot have a trigraph, escaped newline, radix prefix, or type suffix.
293 if (Tok.getLength() == 1) {
294 const char *t = PP.getSourceManager().getCharacterData(Tok.getLocation());
295 return ExprResult(new IntegerLiteral(*t-'0', Context.IntTy));
296 }
Steve Naroff8160ea22007-03-06 01:09:46 +0000297 SmallString<512> IntegerBuffer;
298 IntegerBuffer.resize(Tok.getLength());
299 const char *ThisTokBegin = &IntegerBuffer[0];
300
301 // Get the spelling of the token, which eliminates trigraphs, etc. Notes:
302 // - We know that ThisTokBuf points to a buffer that is big enough for the
303 // whole token and 'spelled' tokens can only shrink.
304 // - In practice, the local buffer is only used when the spelling doesn't
305 // match the original token (which is rare). The common case simply returns
306 // a pointer to a *constant* buffer (avoiding a copy).
307
308 unsigned ActualLength = PP.getSpelling(Tok, ThisTokBegin);
Steve Naroff09ef4742007-03-09 23:16:33 +0000309 NumericLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength,
Steve Naroff451d8f162007-03-12 23:22:38 +0000310 Tok.getLocation(), PP);
Steve Narofff2fb89e2007-03-13 20:29:44 +0000311 if (Literal.hadError)
312 return ExprResult(true);
313
Steve Naroff09ef4742007-03-09 23:16:33 +0000314 if (Literal.isIntegerLiteral()) {
315 TypeRef t;
316 if (Literal.hasSuffix()) {
317 if (Literal.isLong)
318 t = Literal.isUnsigned ? Context.UnsignedLongTy : Context.LongTy;
319 else if (Literal.isLongLong)
320 t = Literal.isUnsigned ? Context.UnsignedLongLongTy : Context.LongLongTy;
321 else
322 t = Context.UnsignedIntTy;
323 } else {
324 t = Context.IntTy; // implicit type is "int"
325 }
Steve Naroff451d8f162007-03-12 23:22:38 +0000326 uintmax_t val;
327 if (Literal.GetIntegerValue(val)) {
Steve Narofff2fb89e2007-03-13 20:29:44 +0000328 return new IntegerLiteral(val, t);
Steve Naroff09ef4742007-03-09 23:16:33 +0000329 }
330 } else if (Literal.isFloatingLiteral()) {
331 // TODO: add floating point processing...
332 }
Steve Narofff2fb89e2007-03-13 20:29:44 +0000333 return ExprResult(true);
Chris Lattnere168f762006-11-10 05:29:30 +0000334}
335
336Action::ExprResult Sema::ParseParenExpr(SourceLocation L, SourceLocation R,
337 ExprTy *Val) {
338 return Val;
339}
340
341
342// Unary Operators. 'Tok' is the token for the operator.
343Action::ExprResult Sema::ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
344 ExprTy *Input) {
345 UnaryOperator::Opcode Opc;
346 switch (Op) {
347 default: assert(0 && "Unknown unary op!");
348 case tok::plusplus: Opc = UnaryOperator::PreInc; break;
349 case tok::minusminus: Opc = UnaryOperator::PreDec; break;
350 case tok::amp: Opc = UnaryOperator::AddrOf; break;
351 case tok::star: Opc = UnaryOperator::Deref; break;
352 case tok::plus: Opc = UnaryOperator::Plus; break;
353 case tok::minus: Opc = UnaryOperator::Minus; break;
354 case tok::tilde: Opc = UnaryOperator::Not; break;
355 case tok::exclaim: Opc = UnaryOperator::LNot; break;
356 case tok::kw_sizeof: Opc = UnaryOperator::SizeOf; break;
357 case tok::kw___alignof: Opc = UnaryOperator::AlignOf; break;
358 case tok::kw___real: Opc = UnaryOperator::Real; break;
359 case tok::kw___imag: Opc = UnaryOperator::Imag; break;
360 case tok::ampamp: Opc = UnaryOperator::AddrLabel; break;
361 case tok::kw___extension__:
362 return Input;
363 //Opc = UnaryOperator::Extension;
364 //break;
365 }
366
367 return new UnaryOperator((Expr*)Input, Opc);
368}
369
370Action::ExprResult Sema::
371ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
372 SourceLocation LParenLoc, TypeTy *Ty,
373 SourceLocation RParenLoc) {
Chris Lattner0d8b1a12006-11-20 04:34:45 +0000374 // If error parsing type, ignore.
375 if (Ty == 0) return true;
Chris Lattner6531c102007-01-23 22:29:49 +0000376
377 // Verify that this is a valid expression.
378 TypeRef ArgTy = TypeRef::getFromOpaquePtr(Ty);
379
380 if (isa<FunctionType>(ArgTy) && isSizeof) {
381 // alignof(function) is allowed.
382 Diag(OpLoc, diag::ext_sizeof_function_type);
Steve Naroffdf7855b2007-02-21 23:46:25 +0000383 return new IntegerLiteral(/*1*/);
Chris Lattner6531c102007-01-23 22:29:49 +0000384 } else if (ArgTy->isVoidType()) {
385 Diag(OpLoc, diag::ext_sizeof_void_type, isSizeof ? "sizeof" : "__alignof");
386 } else if (ArgTy->isIncompleteType()) {
387 std::string TypeName;
388 ArgTy->getAsString(TypeName);
389 Diag(OpLoc, isSizeof ? diag::err_sizeof_incomplete_type :
390 diag::err_alignof_incomplete_type, TypeName);
Steve Naroffdf7855b2007-02-21 23:46:25 +0000391 return new IntegerLiteral(/*0*/);
Chris Lattner6531c102007-01-23 22:29:49 +0000392 }
393
394 return new SizeOfAlignOfTypeExpr(isSizeof, ArgTy);
Chris Lattnere168f762006-11-10 05:29:30 +0000395}
396
397
398Action::ExprResult Sema::ParsePostfixUnaryOp(SourceLocation OpLoc,
399 tok::TokenKind Kind,
400 ExprTy *Input) {
401 UnaryOperator::Opcode Opc;
402 switch (Kind) {
403 default: assert(0 && "Unknown unary op!");
404 case tok::plusplus: Opc = UnaryOperator::PostInc; break;
405 case tok::minusminus: Opc = UnaryOperator::PostDec; break;
406 }
407
408 return new UnaryOperator((Expr*)Input, Opc);
409}
410
411Action::ExprResult Sema::
412ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
413 ExprTy *Idx, SourceLocation RLoc) {
414 return new ArraySubscriptExpr((Expr*)Base, (Expr*)Idx);
415}
416
417Action::ExprResult Sema::
418ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
419 tok::TokenKind OpKind, SourceLocation MemberLoc,
420 IdentifierInfo &Member) {
421 Decl *MemberDecl = 0;
422 // TODO: Look up MemberDecl.
423 return new MemberExpr((Expr*)Base, OpKind == tok::arrow, MemberDecl);
424}
425
426/// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
427/// This provides the location of the left/right parens and a list of comma
428/// locations.
429Action::ExprResult Sema::
430ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
431 ExprTy **Args, unsigned NumArgs,
432 SourceLocation *CommaLocs, SourceLocation RParenLoc) {
433 return new CallExpr((Expr*)Fn, (Expr**)Args, NumArgs);
434}
435
436Action::ExprResult Sema::
437ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
438 SourceLocation RParenLoc, ExprTy *Op) {
Chris Lattner0d8b1a12006-11-20 04:34:45 +0000439 // If error parsing type, ignore.
440 if (Ty == 0) return true;
441 return new CastExpr(TypeRef::getFromOpaquePtr(Ty), (Expr*)Op);
Chris Lattnere168f762006-11-10 05:29:30 +0000442}
443
444
445
446// Binary Operators. 'Tok' is the token for the operator.
447Action::ExprResult Sema::ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
448 ExprTy *LHS, ExprTy *RHS) {
449 BinaryOperator::Opcode Opc;
450 switch (Kind) {
451 default: assert(0 && "Unknown binop!");
452 case tok::star: Opc = BinaryOperator::Mul; break;
453 case tok::slash: Opc = BinaryOperator::Div; break;
454 case tok::percent: Opc = BinaryOperator::Rem; break;
455 case tok::plus: Opc = BinaryOperator::Add; break;
456 case tok::minus: Opc = BinaryOperator::Sub; break;
457 case tok::lessless: Opc = BinaryOperator::Shl; break;
458 case tok::greatergreater: Opc = BinaryOperator::Shr; break;
459 case tok::lessequal: Opc = BinaryOperator::LE; break;
460 case tok::less: Opc = BinaryOperator::LT; break;
461 case tok::greaterequal: Opc = BinaryOperator::GE; break;
462 case tok::greater: Opc = BinaryOperator::GT; break;
463 case tok::exclaimequal: Opc = BinaryOperator::NE; break;
464 case tok::equalequal: Opc = BinaryOperator::EQ; break;
465 case tok::amp: Opc = BinaryOperator::And; break;
466 case tok::caret: Opc = BinaryOperator::Xor; break;
467 case tok::pipe: Opc = BinaryOperator::Or; break;
468 case tok::ampamp: Opc = BinaryOperator::LAnd; break;
469 case tok::pipepipe: Opc = BinaryOperator::LOr; break;
470 case tok::equal: Opc = BinaryOperator::Assign; break;
471 case tok::starequal: Opc = BinaryOperator::MulAssign; break;
472 case tok::slashequal: Opc = BinaryOperator::DivAssign; break;
473 case tok::percentequal: Opc = BinaryOperator::RemAssign; break;
474 case tok::plusequal: Opc = BinaryOperator::AddAssign; break;
475 case tok::minusequal: Opc = BinaryOperator::SubAssign; break;
476 case tok::lesslessequal: Opc = BinaryOperator::ShlAssign; break;
477 case tok::greatergreaterequal: Opc = BinaryOperator::ShrAssign; break;
478 case tok::ampequal: Opc = BinaryOperator::AndAssign; break;
479 case tok::caretequal: Opc = BinaryOperator::XorAssign; break;
480 case tok::pipeequal: Opc = BinaryOperator::OrAssign; break;
481 case tok::comma: Opc = BinaryOperator::Comma; break;
482 }
483
484 return new BinaryOperator((Expr*)LHS, (Expr*)RHS, Opc);
485}
486
487/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
488/// in the case of a the GNU conditional expr extension.
489Action::ExprResult Sema::ParseConditionalOp(SourceLocation QuestionLoc,
490 SourceLocation ColonLoc,
491 ExprTy *Cond, ExprTy *LHS,
492 ExprTy *RHS) {
493 return new ConditionalOperator((Expr*)Cond, (Expr*)LHS, (Expr*)RHS);
494}
495