Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- 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" |
| 15 | #include "clang/AST/ASTContext.h" |
| 16 | #include "clang/AST/Decl.h" |
| 17 | #include "clang/AST/Expr.h" |
| 18 | #include "clang/Lex/Preprocessor.h" |
| 19 | #include "clang/Lex/LiteralSupport.h" |
| 20 | #include "clang/Basic/SourceManager.h" |
| 21 | #include "clang/Basic/Diagnostic.h" |
| 22 | #include "clang/Basic/LangOptions.h" |
| 23 | #include "clang/Basic/TargetInfo.h" |
| 24 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 26 | using namespace clang; |
| 27 | |
| 28 | /// ParseStringLiteral - The specified tokens were lexed as pasted string |
| 29 | /// fragments (e.g. "foo" "bar" L"baz"). The result string has to handle string |
| 30 | /// concatenation ([C99 5.1.1.2, translation phase #6]), so it may come from |
| 31 | /// multiple tokens. However, the common case is that StringToks points to one |
| 32 | /// string. |
| 33 | /// |
| 34 | Action::ExprResult |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 35 | Sema::ParseStringLiteral(const Token *StringToks, unsigned NumStringToks) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 36 | assert(NumStringToks && "Must have at least one string!"); |
| 37 | |
| 38 | StringLiteralParser Literal(StringToks, NumStringToks, PP, Context.Target); |
| 39 | if (Literal.hadError) |
| 40 | return ExprResult(true); |
| 41 | |
| 42 | llvm::SmallVector<SourceLocation, 4> StringTokLocs; |
| 43 | for (unsigned i = 0; i != NumStringToks; ++i) |
| 44 | StringTokLocs.push_back(StringToks[i].getLocation()); |
| 45 | |
| 46 | // FIXME: handle wchar_t |
| 47 | QualType t = Context.getPointerType(Context.CharTy); |
| 48 | |
| 49 | // Pass &StringTokLocs[0], StringTokLocs.size() to factory! |
| 50 | return new StringLiteral(Literal.GetString(), Literal.GetStringLength(), |
| 51 | Literal.AnyWide, t, StringToks[0].getLocation(), |
| 52 | StringToks[NumStringToks-1].getLocation()); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /// ParseIdentifierExpr - The parser read an identifier in expression context, |
| 57 | /// validate it per-C99 6.5.1. HasTrailingLParen indicates whether this |
| 58 | /// identifier is used in an function call context. |
| 59 | Sema::ExprResult Sema::ParseIdentifierExpr(Scope *S, SourceLocation Loc, |
| 60 | IdentifierInfo &II, |
| 61 | bool HasTrailingLParen) { |
| 62 | // Could be enum-constant or decl. |
| 63 | Decl *D = LookupScopedDecl(&II, Decl::IDNS_Ordinary, Loc, S); |
| 64 | if (D == 0) { |
| 65 | // Otherwise, this could be an implicitly declared function reference (legal |
| 66 | // in C90, extension in C99). |
| 67 | if (HasTrailingLParen && |
| 68 | // Not in C++. |
| 69 | !getLangOptions().CPlusPlus) |
| 70 | D = ImplicitlyDefineFunction(Loc, II, S); |
| 71 | else { |
| 72 | // If this name wasn't predeclared and if this is not a function call, |
| 73 | // diagnose the problem. |
| 74 | return Diag(Loc, diag::err_undeclared_var_use, II.getName()); |
| 75 | } |
| 76 | } |
Steve Naroff | e1223f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 77 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
Steve Naroff | 53a3234 | 2007-08-28 18:45:29 +0000 | [diff] [blame] | 78 | // Only create DeclRefExpr's for valid Decl's. |
Steve Naroff | 5912a35 | 2007-08-28 20:14:24 +0000 | [diff] [blame] | 79 | if (VD->isInvalidDecl()) |
Steve Naroff | e1223f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 80 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 81 | return new DeclRefExpr(VD, VD->getType(), Loc); |
Steve Naroff | e1223f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 82 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 83 | if (isa<TypedefDecl>(D)) |
| 84 | return Diag(Loc, diag::err_unexpected_typedef, II.getName()); |
| 85 | |
| 86 | assert(0 && "Invalid decl"); |
Chris Lattner | eddbe03 | 2007-07-21 04:57:45 +0000 | [diff] [blame] | 87 | abort(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 90 | Sema::ExprResult Sema::ParsePreDefinedExpr(SourceLocation Loc, |
| 91 | tok::TokenKind Kind) { |
| 92 | PreDefinedExpr::IdentType IT; |
| 93 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 94 | switch (Kind) { |
| 95 | default: |
| 96 | assert(0 && "Unknown simple primary expr!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 97 | case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2] |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 98 | IT = PreDefinedExpr::Func; |
| 99 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 100 | case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU] |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 101 | IT = PreDefinedExpr::Function; |
| 102 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 103 | case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU] |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 104 | IT = PreDefinedExpr::PrettyFunction; |
| 105 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 106 | } |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 107 | |
| 108 | // Pre-defined identifiers are always of type char *. |
| 109 | return new PreDefinedExpr(Loc, Context.getPointerType(Context.CharTy), IT); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 112 | Sema::ExprResult Sema::ParseCharacterConstant(const Token &Tok) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 113 | llvm::SmallString<16> CharBuffer; |
| 114 | CharBuffer.resize(Tok.getLength()); |
| 115 | const char *ThisTokBegin = &CharBuffer[0]; |
| 116 | unsigned ActualLength = PP.getSpelling(Tok, ThisTokBegin); |
| 117 | |
| 118 | CharLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength, |
| 119 | Tok.getLocation(), PP); |
| 120 | if (Literal.hadError()) |
| 121 | return ExprResult(true); |
| 122 | return new CharacterLiteral(Literal.getValue(), Context.IntTy, |
| 123 | Tok.getLocation()); |
| 124 | } |
| 125 | |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 126 | Action::ExprResult Sema::ParseNumericConstant(const Token &Tok) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 127 | // fast path for a single digit (which is quite common). A single digit |
| 128 | // cannot have a trigraph, escaped newline, radix prefix, or type suffix. |
| 129 | if (Tok.getLength() == 1) { |
| 130 | const char *t = PP.getSourceManager().getCharacterData(Tok.getLocation()); |
| 131 | |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 132 | unsigned IntSize = Context.getTypeSize(Context.IntTy, Tok.getLocation()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 133 | return ExprResult(new IntegerLiteral(llvm::APInt(IntSize, *t-'0'), |
| 134 | Context.IntTy, |
| 135 | Tok.getLocation())); |
| 136 | } |
| 137 | llvm::SmallString<512> IntegerBuffer; |
| 138 | IntegerBuffer.resize(Tok.getLength()); |
| 139 | const char *ThisTokBegin = &IntegerBuffer[0]; |
| 140 | |
| 141 | // Get the spelling of the token, which eliminates trigraphs, etc. |
| 142 | unsigned ActualLength = PP.getSpelling(Tok, ThisTokBegin); |
| 143 | NumericLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength, |
| 144 | Tok.getLocation(), PP); |
| 145 | if (Literal.hadError) |
| 146 | return ExprResult(true); |
| 147 | |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 148 | Expr *Res; |
| 149 | |
| 150 | if (Literal.isFloatingLiteral()) { |
| 151 | // FIXME: handle float values > 32 (including compute the real type...). |
| 152 | QualType Ty = Literal.isFloat ? Context.FloatTy : Context.DoubleTy; |
| 153 | Res = new FloatingLiteral(Literal.GetFloatValue(), Ty, Tok.getLocation()); |
| 154 | } else if (!Literal.isIntegerLiteral()) { |
| 155 | return ExprResult(true); |
| 156 | } else { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 157 | QualType t; |
| 158 | |
Neil Booth | b944951 | 2007-08-29 22:00:19 +0000 | [diff] [blame] | 159 | // long long is a C99 feature. |
| 160 | if (!getLangOptions().C99 && !getLangOptions().CPlusPlus0x && |
Neil Booth | 79859c3 | 2007-08-29 22:13:52 +0000 | [diff] [blame] | 161 | Literal.isLongLong) |
Neil Booth | b944951 | 2007-08-29 22:00:19 +0000 | [diff] [blame] | 162 | Diag(Tok.getLocation(), diag::ext_longlong); |
| 163 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 164 | // Get the value in the widest-possible width. |
| 165 | llvm::APInt ResultVal(Context.Target.getIntMaxTWidth(Tok.getLocation()), 0); |
| 166 | |
| 167 | if (Literal.GetIntegerValue(ResultVal)) { |
| 168 | // If this value didn't fit into uintmax_t, warn and force to ull. |
| 169 | Diag(Tok.getLocation(), diag::warn_integer_too_large); |
| 170 | t = Context.UnsignedLongLongTy; |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 171 | assert(Context.getTypeSize(t, Tok.getLocation()) == |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 172 | ResultVal.getBitWidth() && "long long is not intmax_t?"); |
| 173 | } else { |
| 174 | // If this value fits into a ULL, try to figure out what else it fits into |
| 175 | // according to the rules of C99 6.4.4.1p5. |
| 176 | |
| 177 | // Octal, Hexadecimal, and integers with a U suffix are allowed to |
| 178 | // be an unsigned int. |
| 179 | bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10; |
| 180 | |
| 181 | // Check from smallest to largest, picking the smallest type we can. |
Chris Lattner | 97c5156 | 2007-08-23 21:58:08 +0000 | [diff] [blame] | 182 | if (!Literal.isLong && !Literal.isLongLong) { |
| 183 | // Are int/unsigned possibilities? |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 184 | unsigned IntSize = Context.getTypeSize(Context.IntTy,Tok.getLocation()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 185 | // Does it fit in a unsigned int? |
| 186 | if (ResultVal.isIntN(IntSize)) { |
| 187 | // Does it fit in a signed int? |
| 188 | if (!Literal.isUnsigned && ResultVal[IntSize-1] == 0) |
| 189 | t = Context.IntTy; |
| 190 | else if (AllowUnsigned) |
| 191 | t = Context.UnsignedIntTy; |
| 192 | } |
| 193 | |
| 194 | if (!t.isNull()) |
| 195 | ResultVal.trunc(IntSize); |
| 196 | } |
| 197 | |
| 198 | // Are long/unsigned long possibilities? |
| 199 | if (t.isNull() && !Literal.isLongLong) { |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 200 | unsigned LongSize = Context.getTypeSize(Context.LongTy, |
| 201 | Tok.getLocation()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 202 | |
| 203 | // Does it fit in a unsigned long? |
| 204 | if (ResultVal.isIntN(LongSize)) { |
| 205 | // Does it fit in a signed long? |
| 206 | if (!Literal.isUnsigned && ResultVal[LongSize-1] == 0) |
| 207 | t = Context.LongTy; |
| 208 | else if (AllowUnsigned) |
| 209 | t = Context.UnsignedLongTy; |
| 210 | } |
| 211 | if (!t.isNull()) |
| 212 | ResultVal.trunc(LongSize); |
| 213 | } |
| 214 | |
| 215 | // Finally, check long long if needed. |
| 216 | if (t.isNull()) { |
| 217 | unsigned LongLongSize = |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 218 | Context.getTypeSize(Context.LongLongTy, Tok.getLocation()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 219 | |
| 220 | // Does it fit in a unsigned long long? |
| 221 | if (ResultVal.isIntN(LongLongSize)) { |
| 222 | // Does it fit in a signed long long? |
| 223 | if (!Literal.isUnsigned && ResultVal[LongLongSize-1] == 0) |
| 224 | t = Context.LongLongTy; |
| 225 | else if (AllowUnsigned) |
| 226 | t = Context.UnsignedLongLongTy; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // If we still couldn't decide a type, we probably have something that |
| 231 | // does not fit in a signed long long, but has no U suffix. |
| 232 | if (t.isNull()) { |
| 233 | Diag(Tok.getLocation(), diag::warn_integer_too_large_for_signed); |
| 234 | t = Context.UnsignedLongLongTy; |
| 235 | } |
| 236 | } |
| 237 | |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 238 | Res = new IntegerLiteral(ResultVal, t, Tok.getLocation()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 239 | } |
Chris Lattner | 5d66145 | 2007-08-26 03:42:43 +0000 | [diff] [blame] | 240 | |
| 241 | // If this is an imaginary literal, create the ImaginaryLiteral wrapper. |
| 242 | if (Literal.isImaginary) |
| 243 | Res = new ImaginaryLiteral(Res, Context.getComplexType(Res->getType())); |
| 244 | |
| 245 | return Res; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | Action::ExprResult Sema::ParseParenExpr(SourceLocation L, SourceLocation R, |
| 249 | ExprTy *Val) { |
| 250 | Expr *e = (Expr *)Val; |
| 251 | assert((e != 0) && "ParseParenExpr() missing expr"); |
| 252 | return new ParenExpr(L, R, e); |
| 253 | } |
| 254 | |
| 255 | /// The UsualUnaryConversions() function is *not* called by this routine. |
| 256 | /// See C99 6.3.2.1p[2-4] for more details. |
| 257 | QualType Sema::CheckSizeOfAlignOfOperand(QualType exprType, |
| 258 | SourceLocation OpLoc, bool isSizeof) { |
| 259 | // C99 6.5.3.4p1: |
| 260 | if (isa<FunctionType>(exprType) && isSizeof) |
| 261 | // alignof(function) is allowed. |
| 262 | Diag(OpLoc, diag::ext_sizeof_function_type); |
| 263 | else if (exprType->isVoidType()) |
| 264 | Diag(OpLoc, diag::ext_sizeof_void_type, isSizeof ? "sizeof" : "__alignof"); |
| 265 | else if (exprType->isIncompleteType()) { |
| 266 | Diag(OpLoc, isSizeof ? diag::err_sizeof_incomplete_type : |
| 267 | diag::err_alignof_incomplete_type, |
| 268 | exprType.getAsString()); |
| 269 | return QualType(); // error |
| 270 | } |
| 271 | // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t. |
| 272 | return Context.getSizeType(); |
| 273 | } |
| 274 | |
| 275 | Action::ExprResult Sema:: |
| 276 | ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof, |
| 277 | SourceLocation LPLoc, TypeTy *Ty, |
| 278 | SourceLocation RPLoc) { |
| 279 | // If error parsing type, ignore. |
| 280 | if (Ty == 0) return true; |
| 281 | |
| 282 | // Verify that this is a valid expression. |
| 283 | QualType ArgTy = QualType::getFromOpaquePtr(Ty); |
| 284 | |
| 285 | QualType resultType = CheckSizeOfAlignOfOperand(ArgTy, OpLoc, isSizeof); |
| 286 | |
| 287 | if (resultType.isNull()) |
| 288 | return true; |
| 289 | return new SizeOfAlignOfTypeExpr(isSizeof, ArgTy, resultType, OpLoc, RPLoc); |
| 290 | } |
| 291 | |
Chris Lattner | 5d79425 | 2007-08-24 21:41:10 +0000 | [diff] [blame] | 292 | QualType Sema::CheckRealImagOperand(Expr *&V, SourceLocation Loc) { |
Chris Lattner | dbb3697 | 2007-08-24 21:16:53 +0000 | [diff] [blame] | 293 | DefaultFunctionArrayConversion(V); |
| 294 | |
Chris Lattner | cc26ed7 | 2007-08-26 05:39:26 +0000 | [diff] [blame] | 295 | // These operators return the element type of a complex type. |
Chris Lattner | dbb3697 | 2007-08-24 21:16:53 +0000 | [diff] [blame] | 296 | if (const ComplexType *CT = V->getType()->getAsComplexType()) |
| 297 | return CT->getElementType(); |
Chris Lattner | cc26ed7 | 2007-08-26 05:39:26 +0000 | [diff] [blame] | 298 | |
| 299 | // Otherwise they pass through real integer and floating point types here. |
| 300 | if (V->getType()->isArithmeticType()) |
| 301 | return V->getType(); |
| 302 | |
| 303 | // Reject anything else. |
| 304 | Diag(Loc, diag::err_realimag_invalid_type, V->getType().getAsString()); |
| 305 | return QualType(); |
Chris Lattner | dbb3697 | 2007-08-24 21:16:53 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 309 | |
| 310 | Action::ExprResult Sema::ParsePostfixUnaryOp(SourceLocation OpLoc, |
| 311 | tok::TokenKind Kind, |
| 312 | ExprTy *Input) { |
| 313 | UnaryOperator::Opcode Opc; |
| 314 | switch (Kind) { |
| 315 | default: assert(0 && "Unknown unary op!"); |
| 316 | case tok::plusplus: Opc = UnaryOperator::PostInc; break; |
| 317 | case tok::minusminus: Opc = UnaryOperator::PostDec; break; |
| 318 | } |
| 319 | QualType result = CheckIncrementDecrementOperand((Expr *)Input, OpLoc); |
| 320 | if (result.isNull()) |
| 321 | return true; |
| 322 | return new UnaryOperator((Expr *)Input, Opc, result, OpLoc); |
| 323 | } |
| 324 | |
| 325 | Action::ExprResult Sema:: |
| 326 | ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc, |
| 327 | ExprTy *Idx, SourceLocation RLoc) { |
Chris Lattner | 727a80d | 2007-07-15 23:59:53 +0000 | [diff] [blame] | 328 | Expr *LHSExp = static_cast<Expr*>(Base), *RHSExp = static_cast<Expr*>(Idx); |
Chris Lattner | 12d9ff6 | 2007-07-16 00:14:47 +0000 | [diff] [blame] | 329 | |
| 330 | // Perform default conversions. |
| 331 | DefaultFunctionArrayConversion(LHSExp); |
| 332 | DefaultFunctionArrayConversion(RHSExp); |
Chris Lattner | 727a80d | 2007-07-15 23:59:53 +0000 | [diff] [blame] | 333 | |
Chris Lattner | 12d9ff6 | 2007-07-16 00:14:47 +0000 | [diff] [blame] | 334 | QualType LHSTy = LHSExp->getType(), RHSTy = RHSExp->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 335 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 336 | // C99 6.5.2.1p2: the expression e1[e2] is by definition precisely equivalent |
| 337 | // to the expression *((e1)+(e2)). This means the array "Base" may actually be |
| 338 | // in the subscript position. As a result, we need to derive the array base |
| 339 | // and index from the expression types. |
Chris Lattner | 12d9ff6 | 2007-07-16 00:14:47 +0000 | [diff] [blame] | 340 | Expr *BaseExpr, *IndexExpr; |
| 341 | QualType ResultType; |
Chris Lattner | befee48 | 2007-07-31 16:53:04 +0000 | [diff] [blame] | 342 | if (const PointerType *PTy = LHSTy->getAsPointerType()) { |
Chris Lattner | 12d9ff6 | 2007-07-16 00:14:47 +0000 | [diff] [blame] | 343 | BaseExpr = LHSExp; |
| 344 | IndexExpr = RHSExp; |
| 345 | // FIXME: need to deal with const... |
| 346 | ResultType = PTy->getPointeeType(); |
Chris Lattner | befee48 | 2007-07-31 16:53:04 +0000 | [diff] [blame] | 347 | } else if (const PointerType *PTy = RHSTy->getAsPointerType()) { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 348 | // Handle the uncommon case of "123[Ptr]". |
Chris Lattner | 12d9ff6 | 2007-07-16 00:14:47 +0000 | [diff] [blame] | 349 | BaseExpr = RHSExp; |
| 350 | IndexExpr = LHSExp; |
| 351 | // FIXME: need to deal with const... |
| 352 | ResultType = PTy->getPointeeType(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 353 | } else if (const VectorType *VTy = LHSTy->getAsVectorType()) { |
| 354 | BaseExpr = LHSExp; // vectors: V[123] |
Chris Lattner | 12d9ff6 | 2007-07-16 00:14:47 +0000 | [diff] [blame] | 355 | IndexExpr = RHSExp; |
Steve Naroff | 608e0ee | 2007-08-03 22:40:33 +0000 | [diff] [blame] | 356 | |
| 357 | // Component access limited to variables (reject vec4.rg[1]). |
| 358 | if (!isa<DeclRefExpr>(BaseExpr)) |
| 359 | return Diag(LLoc, diag::err_ocuvector_component_access, |
| 360 | SourceRange(LLoc, RLoc)); |
Chris Lattner | 12d9ff6 | 2007-07-16 00:14:47 +0000 | [diff] [blame] | 361 | // FIXME: need to deal with const... |
| 362 | ResultType = VTy->getElementType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 363 | } else { |
Chris Lattner | 727a80d | 2007-07-15 23:59:53 +0000 | [diff] [blame] | 364 | return Diag(LHSExp->getLocStart(), diag::err_typecheck_subscript_value, |
| 365 | RHSExp->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 366 | } |
| 367 | // C99 6.5.2.1p1 |
Chris Lattner | 12d9ff6 | 2007-07-16 00:14:47 +0000 | [diff] [blame] | 368 | if (!IndexExpr->getType()->isIntegerType()) |
| 369 | return Diag(IndexExpr->getLocStart(), diag::err_typecheck_subscript, |
| 370 | IndexExpr->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 371 | |
Chris Lattner | 12d9ff6 | 2007-07-16 00:14:47 +0000 | [diff] [blame] | 372 | // C99 6.5.2.1p1: "shall have type "pointer to *object* type". In practice, |
| 373 | // the following check catches trying to index a pointer to a function (e.g. |
| 374 | // void (*)(int)). Functions are not objects in C99. |
| 375 | if (!ResultType->isObjectType()) |
| 376 | return Diag(BaseExpr->getLocStart(), |
| 377 | diag::err_typecheck_subscript_not_object, |
| 378 | BaseExpr->getType().getAsString(), BaseExpr->getSourceRange()); |
| 379 | |
| 380 | return new ArraySubscriptExpr(LHSExp, RHSExp, ResultType, RLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 383 | QualType Sema:: |
| 384 | CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc, |
| 385 | IdentifierInfo &CompName, SourceLocation CompLoc) { |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 386 | const OCUVectorType *vecType = baseType->getAsOCUVectorType(); |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 387 | |
| 388 | // The vector accessor can't exceed the number of elements. |
| 389 | const char *compStr = CompName.getName(); |
| 390 | if (strlen(compStr) > vecType->getNumElements()) { |
| 391 | Diag(OpLoc, diag::err_ocuvector_component_exceeds_length, |
| 392 | baseType.getAsString(), SourceRange(CompLoc)); |
| 393 | return QualType(); |
| 394 | } |
| 395 | // The component names must come from the same set. |
Chris Lattner | 88dca04 | 2007-08-02 22:33:49 +0000 | [diff] [blame] | 396 | if (vecType->getPointAccessorIdx(*compStr) != -1) { |
| 397 | do |
| 398 | compStr++; |
| 399 | while (*compStr && vecType->getPointAccessorIdx(*compStr) != -1); |
| 400 | } else if (vecType->getColorAccessorIdx(*compStr) != -1) { |
| 401 | do |
| 402 | compStr++; |
| 403 | while (*compStr && vecType->getColorAccessorIdx(*compStr) != -1); |
| 404 | } else if (vecType->getTextureAccessorIdx(*compStr) != -1) { |
| 405 | do |
| 406 | compStr++; |
| 407 | while (*compStr && vecType->getTextureAccessorIdx(*compStr) != -1); |
| 408 | } |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 409 | |
| 410 | if (*compStr) { |
| 411 | // We didn't get to the end of the string. This means the component names |
| 412 | // didn't come from the same set *or* we encountered an illegal name. |
| 413 | Diag(OpLoc, diag::err_ocuvector_component_name_illegal, |
| 414 | std::string(compStr,compStr+1), SourceRange(CompLoc)); |
| 415 | return QualType(); |
| 416 | } |
| 417 | // Each component accessor can't exceed the vector type. |
| 418 | compStr = CompName.getName(); |
| 419 | while (*compStr) { |
| 420 | if (vecType->isAccessorWithinNumElements(*compStr)) |
| 421 | compStr++; |
| 422 | else |
| 423 | break; |
| 424 | } |
| 425 | if (*compStr) { |
| 426 | // We didn't get to the end of the string. This means a component accessor |
| 427 | // exceeds the number of elements in the vector. |
| 428 | Diag(OpLoc, diag::err_ocuvector_component_exceeds_length, |
| 429 | baseType.getAsString(), SourceRange(CompLoc)); |
| 430 | return QualType(); |
| 431 | } |
| 432 | // The component accessor looks fine - now we need to compute the actual type. |
| 433 | // The vector type is implied by the component accessor. For example, |
| 434 | // vec4.b is a float, vec4.xy is a vec2, vec4.rgb is a vec3, etc. |
| 435 | unsigned CompSize = strlen(CompName.getName()); |
| 436 | if (CompSize == 1) |
| 437 | return vecType->getElementType(); |
Steve Naroff | bea0b34 | 2007-07-29 16:33:31 +0000 | [diff] [blame] | 438 | |
| 439 | QualType VT = Context.getOCUVectorType(vecType->getElementType(), CompSize); |
| 440 | // Now look up the TypeDefDecl from the vector type. Without this, |
| 441 | // diagostics look bad. We want OCU vector types to appear built-in. |
| 442 | for (unsigned i = 0, e = OCUVectorDecls.size(); i != e; ++i) { |
| 443 | if (OCUVectorDecls[i]->getUnderlyingType() == VT) |
| 444 | return Context.getTypedefType(OCUVectorDecls[i]); |
| 445 | } |
| 446 | return VT; // should never get here (a typedef type should always be found). |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 449 | Action::ExprResult Sema:: |
| 450 | ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc, |
| 451 | tok::TokenKind OpKind, SourceLocation MemberLoc, |
| 452 | IdentifierInfo &Member) { |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 453 | Expr *BaseExpr = static_cast<Expr *>(Base); |
| 454 | assert(BaseExpr && "no record expression"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 455 | |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 456 | QualType BaseType = BaseExpr->getType(); |
| 457 | assert(!BaseType.isNull() && "no type for member expression"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 458 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 459 | if (OpKind == tok::arrow) { |
Chris Lattner | befee48 | 2007-07-31 16:53:04 +0000 | [diff] [blame] | 460 | if (const PointerType *PT = BaseType->getAsPointerType()) |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 461 | BaseType = PT->getPointeeType(); |
| 462 | else |
| 463 | return Diag(OpLoc, diag::err_typecheck_member_reference_arrow, |
| 464 | SourceRange(MemberLoc)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 465 | } |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 466 | // The base type is either a record or an OCUVectorType. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 467 | if (const RecordType *RTy = BaseType->getAsRecordType()) { |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 468 | RecordDecl *RDecl = RTy->getDecl(); |
| 469 | if (RTy->isIncompleteType()) |
| 470 | return Diag(OpLoc, diag::err_typecheck_incomplete_tag, RDecl->getName(), |
| 471 | BaseExpr->getSourceRange()); |
| 472 | // The record definition is complete, now make sure the member is valid. |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 473 | FieldDecl *MemberDecl = RDecl->getMember(&Member); |
| 474 | if (!MemberDecl) |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 475 | return Diag(OpLoc, diag::err_typecheck_no_member, Member.getName(), |
| 476 | SourceRange(MemberLoc)); |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 477 | return new MemberExpr(BaseExpr, OpKind==tok::arrow, MemberDecl, MemberLoc); |
| 478 | } else if (BaseType->isOCUVectorType() && OpKind == tok::period) { |
Steve Naroff | 608e0ee | 2007-08-03 22:40:33 +0000 | [diff] [blame] | 479 | // Component access limited to variables (reject vec4.rg.g). |
| 480 | if (!isa<DeclRefExpr>(BaseExpr)) |
| 481 | return Diag(OpLoc, diag::err_ocuvector_component_access, |
| 482 | SourceRange(MemberLoc)); |
Steve Naroff | e1b31fe | 2007-07-27 22:15:19 +0000 | [diff] [blame] | 483 | QualType ret = CheckOCUVectorComponent(BaseType, OpLoc, Member, MemberLoc); |
| 484 | if (ret.isNull()) |
| 485 | return true; |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 486 | return new OCUVectorElementExpr(ret, BaseExpr, Member, MemberLoc); |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 487 | } else |
| 488 | return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion, |
| 489 | SourceRange(MemberLoc)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /// ParseCallExpr - Handle a call to Fn with the specified array of arguments. |
| 493 | /// This provides the location of the left/right parens and a list of comma |
| 494 | /// locations. |
| 495 | Action::ExprResult Sema:: |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 496 | ParseCallExpr(ExprTy *fn, SourceLocation LParenLoc, |
| 497 | ExprTy **args, unsigned NumArgsInCall, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 498 | SourceLocation *CommaLocs, SourceLocation RParenLoc) { |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 499 | Expr *Fn = static_cast<Expr *>(fn); |
| 500 | Expr **Args = reinterpret_cast<Expr**>(args); |
| 501 | assert(Fn && "no function call expression"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 502 | |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 503 | UsualUnaryConversions(Fn); |
| 504 | QualType funcType = Fn->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 505 | |
| 506 | // C99 6.5.2.2p1 - "The expression that denotes the called function shall have |
| 507 | // type pointer to function". |
Chris Lattner | 2dcb6bb | 2007-07-31 21:27:01 +0000 | [diff] [blame] | 508 | const PointerType *PT = funcType->getAsPointerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 509 | if (PT == 0) |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 510 | return Diag(Fn->getLocStart(), diag::err_typecheck_call_not_function, |
| 511 | SourceRange(Fn->getLocStart(), RParenLoc)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 512 | |
Chris Lattner | 2dcb6bb | 2007-07-31 21:27:01 +0000 | [diff] [blame] | 513 | const FunctionType *funcT = PT->getPointeeType()->getAsFunctionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 514 | if (funcT == 0) |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 515 | return Diag(Fn->getLocStart(), diag::err_typecheck_call_not_function, |
| 516 | SourceRange(Fn->getLocStart(), RParenLoc)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 517 | |
| 518 | // If a prototype isn't declared, the parser implicitly defines a func decl |
| 519 | QualType resultType = funcT->getResultType(); |
| 520 | |
| 521 | if (const FunctionTypeProto *proto = dyn_cast<FunctionTypeProto>(funcT)) { |
| 522 | // C99 6.5.2.2p7 - the arguments are implicitly converted, as if by |
| 523 | // assignment, to the types of the corresponding parameter, ... |
| 524 | |
| 525 | unsigned NumArgsInProto = proto->getNumArgs(); |
| 526 | unsigned NumArgsToCheck = NumArgsInCall; |
| 527 | |
| 528 | if (NumArgsInCall < NumArgsInProto) |
| 529 | Diag(RParenLoc, diag::err_typecheck_call_too_few_args, |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 530 | Fn->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 531 | else if (NumArgsInCall > NumArgsInProto) { |
| 532 | if (!proto->isVariadic()) { |
Chris Lattner | d472b31 | 2007-07-21 03:09:58 +0000 | [diff] [blame] | 533 | Diag(Args[NumArgsInProto]->getLocStart(), |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 534 | diag::err_typecheck_call_too_many_args, Fn->getSourceRange(), |
Chris Lattner | d472b31 | 2007-07-21 03:09:58 +0000 | [diff] [blame] | 535 | SourceRange(Args[NumArgsInProto]->getLocStart(), |
| 536 | Args[NumArgsInCall-1]->getLocEnd())); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 537 | } |
| 538 | NumArgsToCheck = NumArgsInProto; |
| 539 | } |
| 540 | // Continue to check argument types (even if we have too few/many args). |
| 541 | for (unsigned i = 0; i < NumArgsToCheck; i++) { |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 542 | Expr *argExpr = Args[i]; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 543 | assert(argExpr && "ParseCallExpr(): missing argument expression"); |
| 544 | |
| 545 | QualType lhsType = proto->getArgType(i); |
| 546 | QualType rhsType = argExpr->getType(); |
Steve Naroff | 700204c | 2007-07-24 21:46:40 +0000 | [diff] [blame] | 547 | |
Steve Naroff | 82c7e6d | 2007-07-25 20:45:33 +0000 | [diff] [blame] | 548 | // If necessary, apply function/array conversion. C99 6.7.5.3p[7,8]. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 549 | if (const ArrayType *ary = lhsType->getAsArrayType()) |
Steve Naroff | 700204c | 2007-07-24 21:46:40 +0000 | [diff] [blame] | 550 | lhsType = Context.getPointerType(ary->getElementType()); |
Steve Naroff | 82c7e6d | 2007-07-25 20:45:33 +0000 | [diff] [blame] | 551 | else if (lhsType->isFunctionType()) |
Steve Naroff | 700204c | 2007-07-24 21:46:40 +0000 | [diff] [blame] | 552 | lhsType = Context.getPointerType(lhsType); |
| 553 | |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 554 | AssignmentCheckResult result = CheckSingleAssignmentConstraints(lhsType, |
| 555 | argExpr); |
Steve Naroff | f1120de | 2007-08-24 22:33:52 +0000 | [diff] [blame] | 556 | if (Args[i] != argExpr) // The expression was converted. |
| 557 | Args[i] = argExpr; // Make sure we store the converted expression. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 558 | SourceLocation l = argExpr->getLocStart(); |
| 559 | |
| 560 | // decode the result (notice that AST's are still created for extensions). |
| 561 | switch (result) { |
| 562 | case Compatible: |
| 563 | break; |
| 564 | case PointerFromInt: |
| 565 | // check for null pointer constant (C99 6.3.2.3p3) |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 566 | if (!argExpr->isNullPointerConstant(Context)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 567 | Diag(l, diag::ext_typecheck_passing_pointer_int, |
| 568 | lhsType.getAsString(), rhsType.getAsString(), |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 569 | Fn->getSourceRange(), argExpr->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 570 | } |
| 571 | break; |
| 572 | case IntFromPointer: |
| 573 | Diag(l, diag::ext_typecheck_passing_pointer_int, |
| 574 | lhsType.getAsString(), rhsType.getAsString(), |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 575 | Fn->getSourceRange(), argExpr->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 576 | break; |
| 577 | case IncompatiblePointer: |
| 578 | Diag(l, diag::ext_typecheck_passing_incompatible_pointer, |
| 579 | rhsType.getAsString(), lhsType.getAsString(), |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 580 | Fn->getSourceRange(), argExpr->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 581 | break; |
| 582 | case CompatiblePointerDiscardsQualifiers: |
| 583 | Diag(l, diag::ext_typecheck_passing_discards_qualifiers, |
| 584 | rhsType.getAsString(), lhsType.getAsString(), |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 585 | Fn->getSourceRange(), argExpr->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 586 | break; |
| 587 | case Incompatible: |
| 588 | return Diag(l, diag::err_typecheck_passing_incompatible, |
| 589 | rhsType.getAsString(), lhsType.getAsString(), |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 590 | Fn->getSourceRange(), argExpr->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 591 | } |
| 592 | } |
Steve Naroff | b291ab6 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 593 | if (NumArgsInCall > NumArgsInProto && proto->isVariadic()) { |
| 594 | // Promote the arguments (C99 6.5.2.2p7). |
| 595 | for (unsigned i = NumArgsInProto; i < NumArgsInCall; i++) { |
| 596 | Expr *argExpr = Args[i]; |
| 597 | assert(argExpr && "ParseCallExpr(): missing argument expression"); |
| 598 | |
| 599 | DefaultArgumentPromotion(argExpr); |
| 600 | if (Args[i] != argExpr) // The expression was converted. |
| 601 | Args[i] = argExpr; // Make sure we store the converted expression. |
| 602 | } |
| 603 | } else if (NumArgsInCall != NumArgsInProto && !proto->isVariadic()) { |
| 604 | // Even if the types checked, bail if the number of arguments don't match. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 605 | return true; |
Steve Naroff | b291ab6 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 606 | } |
| 607 | } else if (isa<FunctionTypeNoProto>(funcT)) { |
| 608 | // Promote the arguments (C99 6.5.2.2p6). |
| 609 | for (unsigned i = 0; i < NumArgsInCall; i++) { |
| 610 | Expr *argExpr = Args[i]; |
| 611 | assert(argExpr && "ParseCallExpr(): missing argument expression"); |
| 612 | |
| 613 | DefaultArgumentPromotion(argExpr); |
| 614 | if (Args[i] != argExpr) // The expression was converted. |
| 615 | Args[i] = argExpr; // Make sure we store the converted expression. |
| 616 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 617 | } |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 618 | // Do special checking on direct calls to functions. |
| 619 | if (ImplicitCastExpr *IcExpr = dyn_cast<ImplicitCastExpr>(Fn)) |
| 620 | if (DeclRefExpr *DRExpr = dyn_cast<DeclRefExpr>(IcExpr->getSubExpr())) |
| 621 | if (FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRExpr->getDecl())) |
Anders Carlsson | 9cdc4d3 | 2007-08-17 15:44:17 +0000 | [diff] [blame] | 622 | if (CheckFunctionCall(Fn, LParenLoc, RParenLoc, FDecl, Args, NumArgsInCall)) |
Anders Carlsson | 71993dd | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 623 | return true; |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 624 | |
Chris Lattner | 74c469f | 2007-07-21 03:03:59 +0000 | [diff] [blame] | 625 | return new CallExpr(Fn, Args, NumArgsInCall, resultType, RParenLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | Action::ExprResult Sema:: |
Steve Naroff | 4aa88f8 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 629 | ParseCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, |
Steve Naroff | aff1edd | 2007-07-19 21:32:11 +0000 | [diff] [blame] | 630 | SourceLocation RParenLoc, ExprTy *InitExpr) { |
Steve Naroff | 4aa88f8 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 631 | assert((Ty != 0) && "ParseCompoundLiteral(): missing type"); |
| 632 | QualType literalType = QualType::getFromOpaquePtr(Ty); |
Steve Naroff | aff1edd | 2007-07-19 21:32:11 +0000 | [diff] [blame] | 633 | // FIXME: put back this assert when initializers are worked out. |
| 634 | //assert((InitExpr != 0) && "ParseCompoundLiteral(): missing expression"); |
| 635 | Expr *literalExpr = static_cast<Expr*>(InitExpr); |
Steve Naroff | 4aa88f8 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 636 | |
| 637 | // FIXME: add semantic analysis (C99 6.5.2.5). |
Steve Naroff | aff1edd | 2007-07-19 21:32:11 +0000 | [diff] [blame] | 638 | return new CompoundLiteralExpr(literalType, literalExpr); |
Steve Naroff | 4aa88f8 | 2007-07-19 01:06:55 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | Action::ExprResult Sema:: |
| 642 | ParseInitList(SourceLocation LParenLoc, ExprTy **InitList, unsigned NumInit, |
| 643 | SourceLocation RParenLoc) { |
| 644 | // FIXME: add semantic analysis (C99 6.7.8). This involves |
| 645 | // knowledge of the object being intialized. As a result, the code for |
| 646 | // doing the semantic analysis will likely be located elsewhere (i.e. in |
| 647 | // consumers of InitListExpr (e.g. ParseDeclarator, ParseCompoundLiteral). |
| 648 | return false; // FIXME instantiate an InitListExpr. |
| 649 | } |
| 650 | |
| 651 | Action::ExprResult Sema:: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 652 | ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty, |
| 653 | SourceLocation RParenLoc, ExprTy *Op) { |
Steve Naroff | 16beff8 | 2007-07-16 23:25:18 +0000 | [diff] [blame] | 654 | assert((Ty != 0) && (Op != 0) && "ParseCastExpr(): missing type or expr"); |
| 655 | |
| 656 | Expr *castExpr = static_cast<Expr*>(Op); |
| 657 | QualType castType = QualType::getFromOpaquePtr(Ty); |
| 658 | |
Chris Lattner | 75af480 | 2007-07-18 16:00:06 +0000 | [diff] [blame] | 659 | // C99 6.5.4p2: the cast type needs to be void or scalar and the expression |
| 660 | // type needs to be scalar. |
| 661 | if (!castType->isScalarType() && !castType->isVoidType()) { |
Steve Naroff | 16beff8 | 2007-07-16 23:25:18 +0000 | [diff] [blame] | 662 | return Diag(LParenLoc, diag::err_typecheck_cond_expect_scalar, |
| 663 | castType.getAsString(), SourceRange(LParenLoc, RParenLoc)); |
| 664 | } |
| 665 | if (!castExpr->getType()->isScalarType()) { |
| 666 | return Diag(castExpr->getLocStart(), |
| 667 | diag::err_typecheck_expect_scalar_operand, |
| 668 | castExpr->getType().getAsString(), castExpr->getSourceRange()); |
| 669 | } |
| 670 | return new CastExpr(castType, castExpr, LParenLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | inline QualType Sema::CheckConditionalOperands( // C99 6.5.15 |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 674 | Expr *&cond, Expr *&lex, Expr *&rex, SourceLocation questionLoc) { |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 675 | UsualUnaryConversions(cond); |
| 676 | UsualUnaryConversions(lex); |
| 677 | UsualUnaryConversions(rex); |
| 678 | QualType condT = cond->getType(); |
| 679 | QualType lexT = lex->getType(); |
| 680 | QualType rexT = rex->getType(); |
| 681 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 682 | // first, check the condition. |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 683 | if (!condT->isScalarType()) { // C99 6.5.15p2 |
| 684 | Diag(cond->getLocStart(), diag::err_typecheck_cond_expect_scalar, |
| 685 | condT.getAsString()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 686 | return QualType(); |
| 687 | } |
| 688 | // now check the two expressions. |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 689 | if (lexT->isArithmeticType() && rexT->isArithmeticType()) { // C99 6.5.15p3,5 |
| 690 | UsualArithmeticConversions(lex, rex); |
| 691 | return lex->getType(); |
| 692 | } |
Chris Lattner | 2dcb6bb | 2007-07-31 21:27:01 +0000 | [diff] [blame] | 693 | if (const RecordType *LHSRT = lexT->getAsRecordType()) { // C99 6.5.15p3 |
| 694 | if (const RecordType *RHSRT = rexT->getAsRecordType()) { |
| 695 | |
| 696 | if (LHSRT->getDecl()->getIdentifier() ==RHSRT->getDecl()->getIdentifier()) |
| 697 | return lexT; |
| 698 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 699 | Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands, |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 700 | lexT.getAsString(), rexT.getAsString(), |
| 701 | lex->getSourceRange(), rex->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 702 | return QualType(); |
| 703 | } |
| 704 | } |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 705 | // C99 6.5.15p3 |
| 706 | if (lexT->isPointerType() && rex->isNullPointerConstant(Context)) |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 707 | return lexT; |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 708 | if (rexT->isPointerType() && lex->isNullPointerConstant(Context)) |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 709 | return rexT; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 710 | |
Chris Lattner | 2dcb6bb | 2007-07-31 21:27:01 +0000 | [diff] [blame] | 711 | if (const PointerType *LHSPT = lexT->getAsPointerType()) { // C99 6.5.15p3,6 |
| 712 | if (const PointerType *RHSPT = rexT->getAsPointerType()) { |
| 713 | // get the "pointed to" types |
| 714 | QualType lhptee = LHSPT->getPointeeType(); |
| 715 | QualType rhptee = RHSPT->getPointeeType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 716 | |
Chris Lattner | 2dcb6bb | 2007-07-31 21:27:01 +0000 | [diff] [blame] | 717 | // ignore qualifiers on void (C99 6.5.15p3, clause 6) |
| 718 | if (lhptee->isVoidType() && |
| 719 | (rhptee->isObjectType() || rhptee->isIncompleteType())) |
| 720 | return lexT; |
| 721 | if (rhptee->isVoidType() && |
| 722 | (lhptee->isObjectType() || lhptee->isIncompleteType())) |
| 723 | return rexT; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 724 | |
Chris Lattner | 2dcb6bb | 2007-07-31 21:27:01 +0000 | [diff] [blame] | 725 | if (!Type::typesAreCompatible(lhptee.getUnqualifiedType(), |
| 726 | rhptee.getUnqualifiedType())) { |
| 727 | Diag(questionLoc, diag::ext_typecheck_cond_incompatible_pointers, |
| 728 | lexT.getAsString(), rexT.getAsString(), |
| 729 | lex->getSourceRange(), rex->getSourceRange()); |
| 730 | return lexT; // FIXME: this is an _ext - is this return o.k? |
| 731 | } |
| 732 | // The pointer types are compatible. |
| 733 | // C99 6.5.15p6: If both operands are pointers to compatible types *or* to |
| 734 | // differently qualified versions of compatible types, the result type is a |
| 735 | // pointer to an appropriately qualified version of the *composite* type. |
| 736 | return lexT; // FIXME: Need to return the composite type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 737 | } |
| 738 | } |
Chris Lattner | 2dcb6bb | 2007-07-31 21:27:01 +0000 | [diff] [blame] | 739 | |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 740 | if (lexT->isVoidType() && rexT->isVoidType()) // C99 6.5.15p3 |
| 741 | return lexT; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 742 | |
| 743 | Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands, |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 744 | lexT.getAsString(), rexT.getAsString(), |
| 745 | lex->getSourceRange(), rex->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 746 | return QualType(); |
| 747 | } |
| 748 | |
| 749 | /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
| 750 | /// in the case of a the GNU conditional expr extension. |
| 751 | Action::ExprResult Sema::ParseConditionalOp(SourceLocation QuestionLoc, |
| 752 | SourceLocation ColonLoc, |
| 753 | ExprTy *Cond, ExprTy *LHS, |
| 754 | ExprTy *RHS) { |
Chris Lattner | 2682490 | 2007-07-16 21:39:03 +0000 | [diff] [blame] | 755 | Expr *CondExpr = (Expr *) Cond; |
| 756 | Expr *LHSExpr = (Expr *) LHS, *RHSExpr = (Expr *) RHS; |
| 757 | QualType result = CheckConditionalOperands(CondExpr, LHSExpr, |
| 758 | RHSExpr, QuestionLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 759 | if (result.isNull()) |
| 760 | return true; |
Chris Lattner | 2682490 | 2007-07-16 21:39:03 +0000 | [diff] [blame] | 761 | return new ConditionalOperator(CondExpr, LHSExpr, RHSExpr, result); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Steve Naroff | fa2eaab | 2007-07-15 02:02:06 +0000 | [diff] [blame] | 764 | // promoteExprToType - a helper function to ensure we create exactly one |
| 765 | // ImplicitCastExpr. As a convenience (to the caller), we return the type. |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 766 | static void promoteExprToType(Expr *&expr, QualType type) { |
Steve Naroff | fa2eaab | 2007-07-15 02:02:06 +0000 | [diff] [blame] | 767 | if (ImplicitCastExpr *impCast = dyn_cast<ImplicitCastExpr>(expr)) |
| 768 | impCast->setType(type); |
| 769 | else |
| 770 | expr = new ImplicitCastExpr(type, expr); |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 771 | return; |
Steve Naroff | fa2eaab | 2007-07-15 02:02:06 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Steve Naroff | b291ab6 | 2007-08-28 23:30:39 +0000 | [diff] [blame] | 774 | /// DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
| 775 | /// do not have a prototype. Integer promotions are performed on each |
| 776 | /// argument, and arguments that have type float are promoted to double. |
| 777 | void Sema::DefaultArgumentPromotion(Expr *&expr) { |
| 778 | QualType t = expr->getType(); |
| 779 | assert(!t.isNull() && "DefaultArgumentPromotion - missing type"); |
| 780 | |
| 781 | if (t->isPromotableIntegerType()) // C99 6.3.1.1p2 |
| 782 | promoteExprToType(expr, Context.IntTy); |
| 783 | if (t == Context.FloatTy) |
| 784 | promoteExprToType(expr, Context.DoubleTy); |
| 785 | } |
| 786 | |
Steve Naroff | fa2eaab | 2007-07-15 02:02:06 +0000 | [diff] [blame] | 787 | /// DefaultFunctionArrayConversion (C99 6.3.2.1p3, C99 6.3.2.1p4). |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 788 | void Sema::DefaultFunctionArrayConversion(Expr *&e) { |
Steve Naroff | fa2eaab | 2007-07-15 02:02:06 +0000 | [diff] [blame] | 789 | QualType t = e->getType(); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 790 | assert(!t.isNull() && "DefaultFunctionArrayConversion - missing type"); |
Bill Wendling | 08ad47c | 2007-07-17 03:52:31 +0000 | [diff] [blame] | 791 | |
Chris Lattner | a1d9fde | 2007-07-31 16:56:34 +0000 | [diff] [blame] | 792 | if (const ReferenceType *ref = t->getAsReferenceType()) { |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +0000 | [diff] [blame] | 793 | promoteExprToType(e, ref->getReferenceeType()); // C++ [expr] |
| 794 | t = e->getType(); |
| 795 | } |
Steve Naroff | fa2eaab | 2007-07-15 02:02:06 +0000 | [diff] [blame] | 796 | if (t->isFunctionType()) |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 797 | promoteExprToType(e, Context.getPointerType(t)); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 798 | else if (const ArrayType *ary = t->getAsArrayType()) |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 799 | promoteExprToType(e, Context.getPointerType(ary->getElementType())); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /// UsualUnaryConversion - Performs various conversions that are common to most |
| 803 | /// operators (C99 6.3). The conversions of array and function types are |
| 804 | /// sometimes surpressed. For example, the array->pointer conversion doesn't |
| 805 | /// apply if the array is an argument to the sizeof or address (&) operators. |
| 806 | /// In these instances, this routine should *not* be called. |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 807 | void Sema::UsualUnaryConversions(Expr *&expr) { |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 808 | QualType t = expr->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 809 | assert(!t.isNull() && "UsualUnaryConversions - missing type"); |
| 810 | |
Chris Lattner | a1d9fde | 2007-07-31 16:56:34 +0000 | [diff] [blame] | 811 | if (const ReferenceType *ref = t->getAsReferenceType()) { |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +0000 | [diff] [blame] | 812 | promoteExprToType(expr, ref->getReferenceeType()); // C++ [expr] |
| 813 | t = expr->getType(); |
| 814 | } |
Steve Naroff | fa2eaab | 2007-07-15 02:02:06 +0000 | [diff] [blame] | 815 | if (t->isPromotableIntegerType()) // C99 6.3.1.1p2 |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 816 | promoteExprToType(expr, Context.IntTy); |
| 817 | else |
| 818 | DefaultFunctionArrayConversion(expr); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /// UsualArithmeticConversions - Performs various conversions that are common to |
| 822 | /// binary operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
| 823 | /// routine returns the first non-arithmetic type found. The client is |
| 824 | /// responsible for emitting appropriate error diagnostics. |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 825 | QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr, |
| 826 | bool isCompAssign) { |
Steve Naroff | 8702a0f | 2007-08-25 19:54:59 +0000 | [diff] [blame] | 827 | if (!isCompAssign) { |
| 828 | UsualUnaryConversions(lhsExpr); |
| 829 | UsualUnaryConversions(rhsExpr); |
| 830 | } |
Steve Naroff | 3e5e556 | 2007-07-16 22:23:01 +0000 | [diff] [blame] | 831 | QualType lhs = lhsExpr->getType(); |
| 832 | QualType rhs = rhsExpr->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 833 | |
| 834 | // If both types are identical, no conversion is needed. |
| 835 | if (lhs == rhs) |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 836 | return lhs; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 837 | |
| 838 | // If either side is a non-arithmetic type (e.g. a pointer), we are done. |
| 839 | // The caller can deal with this (e.g. pointer + int). |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 840 | if (!lhs->isArithmeticType() || !rhs->isArithmeticType()) |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 841 | return lhs; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 842 | |
| 843 | // At this point, we have two different arithmetic types. |
| 844 | |
| 845 | // Handle complex types first (C99 6.3.1.8p1). |
| 846 | if (lhs->isComplexType() || rhs->isComplexType()) { |
| 847 | // if we have an integer operand, the result is the complex type. |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 848 | if (rhs->isIntegerType()) { // convert the rhs to the lhs complex type. |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 849 | if (!isCompAssign) promoteExprToType(rhsExpr, lhs); |
| 850 | return lhs; |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 851 | } |
| 852 | if (lhs->isIntegerType()) { // convert the lhs to the rhs complex type. |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 853 | if (!isCompAssign) promoteExprToType(lhsExpr, rhs); |
| 854 | return rhs; |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 855 | } |
Steve Naroff | f1448a0 | 2007-08-27 01:27:54 +0000 | [diff] [blame] | 856 | // This handles complex/complex, complex/float, or float/complex. |
| 857 | // When both operands are complex, the shorter operand is converted to the |
| 858 | // type of the longer, and that is the type of the result. This corresponds |
| 859 | // to what is done when combining two real floating-point operands. |
| 860 | // The fun begins when size promotion occur across type domains. |
| 861 | // From H&S 6.3.4: When one operand is complex and the other is a real |
| 862 | // floating-point type, the less precise type is converted, within it's |
| 863 | // real or complex domain, to the precision of the other type. For example, |
| 864 | // when combining a "long double" with a "double _Complex", the |
| 865 | // "double _Complex" is promoted to "long double _Complex". |
Steve Naroff | fb0d496 | 2007-08-27 15:30:22 +0000 | [diff] [blame] | 866 | int result = Context.compareFloatingType(lhs, rhs); |
| 867 | |
| 868 | if (result > 0) { // The left side is bigger, convert rhs. |
Steve Naroff | 55fe455 | 2007-08-27 21:32:55 +0000 | [diff] [blame] | 869 | rhs = Context.getFloatingTypeOfSizeWithinDomain(lhs, rhs); |
| 870 | if (!isCompAssign) |
| 871 | promoteExprToType(rhsExpr, rhs); |
| 872 | } else if (result < 0) { // The right side is bigger, convert lhs. |
| 873 | lhs = Context.getFloatingTypeOfSizeWithinDomain(rhs, lhs); |
| 874 | if (!isCompAssign) |
| 875 | promoteExprToType(lhsExpr, lhs); |
| 876 | } |
| 877 | // At this point, lhs and rhs have the same rank/size. Now, make sure the |
| 878 | // domains match. This is a requirement for our implementation, C99 |
| 879 | // does not require this promotion. |
| 880 | if (lhs != rhs) { // Domains don't match, we have complex/float mix. |
| 881 | if (lhs->isRealFloatingType()) { // handle "double, _Complex double". |
Steve Naroff | 2996036 | 2007-08-27 21:43:43 +0000 | [diff] [blame] | 882 | if (!isCompAssign) |
| 883 | promoteExprToType(lhsExpr, rhs); |
| 884 | return rhs; |
Steve Naroff | 55fe455 | 2007-08-27 21:32:55 +0000 | [diff] [blame] | 885 | } else { // handle "_Complex double, double". |
Steve Naroff | 2996036 | 2007-08-27 21:43:43 +0000 | [diff] [blame] | 886 | if (!isCompAssign) |
| 887 | promoteExprToType(rhsExpr, lhs); |
| 888 | return lhs; |
Steve Naroff | 55fe455 | 2007-08-27 21:32:55 +0000 | [diff] [blame] | 889 | } |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 890 | } |
Steve Naroff | 2996036 | 2007-08-27 21:43:43 +0000 | [diff] [blame] | 891 | return lhs; // The domain/size match exactly. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 892 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 893 | // Now handle "real" floating types (i.e. float, double, long double). |
| 894 | if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) { |
| 895 | // if we have an integer operand, the result is the real floating type. |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 896 | if (rhs->isIntegerType()) { // convert rhs to the lhs floating point type. |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 897 | if (!isCompAssign) promoteExprToType(rhsExpr, lhs); |
| 898 | return lhs; |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 899 | } |
| 900 | if (lhs->isIntegerType()) { // convert lhs to the rhs floating point type. |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 901 | if (!isCompAssign) promoteExprToType(lhsExpr, rhs); |
| 902 | return rhs; |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 903 | } |
Steve Naroff | fa2eaab | 2007-07-15 02:02:06 +0000 | [diff] [blame] | 904 | // We have two real floating types, float/complex combos were handled above. |
| 905 | // Convert the smaller operand to the bigger result. |
Steve Naroff | fb0d496 | 2007-08-27 15:30:22 +0000 | [diff] [blame] | 906 | int result = Context.compareFloatingType(lhs, rhs); |
| 907 | |
| 908 | if (result > 0) { // convert the rhs |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 909 | if (!isCompAssign) promoteExprToType(rhsExpr, lhs); |
| 910 | return lhs; |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 911 | } |
Steve Naroff | fb0d496 | 2007-08-27 15:30:22 +0000 | [diff] [blame] | 912 | if (result < 0) { // convert the lhs |
| 913 | if (!isCompAssign) promoteExprToType(lhsExpr, rhs); // convert the lhs |
| 914 | return rhs; |
| 915 | } |
| 916 | assert(0 && "Sema::UsualArithmeticConversions(): illegal float comparison"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 917 | } |
Steve Naroff | fa2eaab | 2007-07-15 02:02:06 +0000 | [diff] [blame] | 918 | // Finally, we have two differing integer types. |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 919 | if (Context.maxIntegerType(lhs, rhs) == lhs) { // convert the rhs |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 920 | if (!isCompAssign) promoteExprToType(rhsExpr, lhs); |
| 921 | return lhs; |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 922 | } |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 923 | if (!isCompAssign) promoteExprToType(lhsExpr, rhs); // convert the lhs |
| 924 | return rhs; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | // CheckPointerTypesForAssignment - This is a very tricky routine (despite |
| 928 | // being closely modeled after the C99 spec:-). The odd characteristic of this |
| 929 | // routine is it effectively iqnores the qualifiers on the top level pointee. |
| 930 | // This circumvents the usual type rules specified in 6.2.7p1 & 6.7.5.[1-3]. |
| 931 | // FIXME: add a couple examples in this comment. |
| 932 | Sema::AssignmentCheckResult |
| 933 | Sema::CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType) { |
| 934 | QualType lhptee, rhptee; |
| 935 | |
| 936 | // get the "pointed to" type (ignoring qualifiers at the top level) |
Chris Lattner | 2dcb6bb | 2007-07-31 21:27:01 +0000 | [diff] [blame] | 937 | lhptee = lhsType->getAsPointerType()->getPointeeType(); |
| 938 | rhptee = rhsType->getAsPointerType()->getPointeeType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 939 | |
| 940 | // make sure we operate on the canonical type |
| 941 | lhptee = lhptee.getCanonicalType(); |
| 942 | rhptee = rhptee.getCanonicalType(); |
| 943 | |
| 944 | AssignmentCheckResult r = Compatible; |
| 945 | |
| 946 | // C99 6.5.16.1p1: This following citation is common to constraints |
| 947 | // 3 & 4 (below). ...and the type *pointed to* by the left has all the |
| 948 | // qualifiers of the type *pointed to* by the right; |
| 949 | if ((lhptee.getQualifiers() & rhptee.getQualifiers()) != |
| 950 | rhptee.getQualifiers()) |
| 951 | r = CompatiblePointerDiscardsQualifiers; |
| 952 | |
| 953 | // C99 6.5.16.1p1 (constraint 4): If one operand is a pointer to an object or |
| 954 | // incomplete type and the other is a pointer to a qualified or unqualified |
| 955 | // version of void... |
| 956 | if (lhptee.getUnqualifiedType()->isVoidType() && |
| 957 | (rhptee->isObjectType() || rhptee->isIncompleteType())) |
| 958 | ; |
| 959 | else if (rhptee.getUnqualifiedType()->isVoidType() && |
| 960 | (lhptee->isObjectType() || lhptee->isIncompleteType())) |
| 961 | ; |
| 962 | // C99 6.5.16.1p1 (constraint 3): both operands are pointers to qualified or |
| 963 | // unqualified versions of compatible types, ... |
| 964 | else if (!Type::typesAreCompatible(lhptee.getUnqualifiedType(), |
| 965 | rhptee.getUnqualifiedType())) |
| 966 | r = IncompatiblePointer; // this "trumps" PointerAssignDiscardsQualifiers |
| 967 | return r; |
| 968 | } |
| 969 | |
| 970 | /// CheckAssignmentConstraints (C99 6.5.16) - This routine currently |
| 971 | /// has code to accommodate several GCC extensions when type checking |
| 972 | /// pointers. Here are some objectionable examples that GCC considers warnings: |
| 973 | /// |
| 974 | /// int a, *pint; |
| 975 | /// short *pshort; |
| 976 | /// struct foo *pfoo; |
| 977 | /// |
| 978 | /// pint = pshort; // warning: assignment from incompatible pointer type |
| 979 | /// a = pint; // warning: assignment makes integer from pointer without a cast |
| 980 | /// pint = a; // warning: assignment makes pointer from integer without a cast |
| 981 | /// pint = pfoo; // warning: assignment from incompatible pointer type |
| 982 | /// |
| 983 | /// As a result, the code for dealing with pointers is more complex than the |
| 984 | /// C99 spec dictates. |
| 985 | /// Note: the warning above turn into errors when -pedantic-errors is enabled. |
| 986 | /// |
| 987 | Sema::AssignmentCheckResult |
| 988 | Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { |
Steve Naroff | 700204c | 2007-07-24 21:46:40 +0000 | [diff] [blame] | 989 | if (lhsType == rhsType) // common case, fast path... |
| 990 | return Compatible; |
| 991 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 992 | if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) { |
| 993 | if (lhsType->isVectorType() || rhsType->isVectorType()) { |
| 994 | if (lhsType.getCanonicalType() != rhsType.getCanonicalType()) |
| 995 | return Incompatible; |
| 996 | } |
| 997 | return Compatible; |
| 998 | } else if (lhsType->isPointerType()) { |
| 999 | if (rhsType->isIntegerType()) |
| 1000 | return PointerFromInt; |
| 1001 | |
| 1002 | if (rhsType->isPointerType()) |
| 1003 | return CheckPointerTypesForAssignment(lhsType, rhsType); |
| 1004 | } else if (rhsType->isPointerType()) { |
| 1005 | // C99 6.5.16.1p1: the left operand is _Bool and the right is a pointer. |
| 1006 | if ((lhsType->isIntegerType()) && (lhsType != Context.BoolTy)) |
| 1007 | return IntFromPointer; |
| 1008 | |
| 1009 | if (lhsType->isPointerType()) |
| 1010 | return CheckPointerTypesForAssignment(lhsType, rhsType); |
| 1011 | } else if (isa<TagType>(lhsType) && isa<TagType>(rhsType)) { |
| 1012 | if (Type::tagTypesAreCompatible(lhsType, rhsType)) |
| 1013 | return Compatible; |
| 1014 | } else if (lhsType->isReferenceType() || rhsType->isReferenceType()) { |
| 1015 | if (Type::referenceTypesAreCompatible(lhsType, rhsType)) |
| 1016 | return Compatible; |
| 1017 | } |
| 1018 | return Incompatible; |
| 1019 | } |
| 1020 | |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 1021 | Sema::AssignmentCheckResult |
| 1022 | Sema::CheckSingleAssignmentConstraints(QualType lhsType, Expr *&rExpr) { |
| 1023 | // This check seems unnatural, however it is necessary to insure the proper |
| 1024 | // conversion of functions/arrays. If the conversion were done for all |
| 1025 | // DeclExpr's (created by ParseIdentifierExpr), it would mess up the unary |
| 1026 | // expressions that surpress this implicit conversion (&, sizeof). |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 1027 | DefaultFunctionArrayConversion(rExpr); |
Steve Naroff | f1120de | 2007-08-24 22:33:52 +0000 | [diff] [blame] | 1028 | |
| 1029 | Sema::AssignmentCheckResult result; |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 1030 | |
Steve Naroff | f1120de | 2007-08-24 22:33:52 +0000 | [diff] [blame] | 1031 | result = CheckAssignmentConstraints(lhsType, rExpr->getType()); |
| 1032 | |
| 1033 | // C99 6.5.16.1p2: The value of the right operand is converted to the |
| 1034 | // type of the assignment expression. |
| 1035 | if (rExpr->getType() != lhsType) |
| 1036 | promoteExprToType(rExpr, lhsType); |
| 1037 | return result; |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | Sema::AssignmentCheckResult |
| 1041 | Sema::CheckCompoundAssignmentConstraints(QualType lhsType, QualType rhsType) { |
| 1042 | return CheckAssignmentConstraints(lhsType, rhsType); |
| 1043 | } |
| 1044 | |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 1045 | inline void Sema::InvalidOperands(SourceLocation loc, Expr *&lex, Expr *&rex) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1046 | Diag(loc, diag::err_typecheck_invalid_operands, |
| 1047 | lex->getType().getAsString(), rex->getType().getAsString(), |
| 1048 | lex->getSourceRange(), rex->getSourceRange()); |
| 1049 | } |
| 1050 | |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 1051 | inline QualType Sema::CheckVectorOperands(SourceLocation loc, Expr *&lex, |
| 1052 | Expr *&rex) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1053 | QualType lhsType = lex->getType(), rhsType = rex->getType(); |
| 1054 | |
| 1055 | // make sure the vector types are identical. |
| 1056 | if (lhsType == rhsType) |
| 1057 | return lhsType; |
| 1058 | // You cannot convert between vector values of different size. |
| 1059 | Diag(loc, diag::err_typecheck_vector_not_convertable, |
| 1060 | lex->getType().getAsString(), rex->getType().getAsString(), |
| 1061 | lex->getSourceRange(), rex->getSourceRange()); |
| 1062 | return QualType(); |
| 1063 | } |
| 1064 | |
| 1065 | inline QualType Sema::CheckMultiplyDivideOperands( |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1066 | Expr *&lex, Expr *&rex, SourceLocation loc, bool isCompAssign) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1067 | { |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 1068 | QualType lhsType = lex->getType(), rhsType = rex->getType(); |
| 1069 | |
| 1070 | if (lhsType->isVectorType() || rhsType->isVectorType()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1071 | return CheckVectorOperands(loc, lex, rex); |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 1072 | |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1073 | QualType compType = UsualArithmeticConversions(lex, rex, isCompAssign); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1074 | |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 1075 | if (lex->getType()->isArithmeticType() && rex->getType()->isArithmeticType()) |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1076 | return compType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1077 | InvalidOperands(loc, lex, rex); |
| 1078 | return QualType(); |
| 1079 | } |
| 1080 | |
| 1081 | inline QualType Sema::CheckRemainderOperands( |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1082 | Expr *&lex, Expr *&rex, SourceLocation loc, bool isCompAssign) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1083 | { |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 1084 | QualType lhsType = lex->getType(), rhsType = rex->getType(); |
| 1085 | |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1086 | QualType compType = UsualArithmeticConversions(lex, rex, isCompAssign); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1087 | |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 1088 | if (lex->getType()->isIntegerType() && rex->getType()->isIntegerType()) |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1089 | return compType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1090 | InvalidOperands(loc, lex, rex); |
| 1091 | return QualType(); |
| 1092 | } |
| 1093 | |
| 1094 | inline QualType Sema::CheckAdditionOperands( // C99 6.5.6 |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1095 | Expr *&lex, Expr *&rex, SourceLocation loc, bool isCompAssign) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1096 | { |
Steve Naroff | 3e5e556 | 2007-07-16 22:23:01 +0000 | [diff] [blame] | 1097 | if (lex->getType()->isVectorType() || rex->getType()->isVectorType()) |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 1098 | return CheckVectorOperands(loc, lex, rex); |
| 1099 | |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1100 | QualType compType = UsualArithmeticConversions(lex, rex, isCompAssign); |
Steve Naroff | 3e5e556 | 2007-07-16 22:23:01 +0000 | [diff] [blame] | 1101 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1102 | // handle the common case first (both operands are arithmetic). |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 1103 | if (lex->getType()->isArithmeticType() && rex->getType()->isArithmeticType()) |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1104 | return compType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1105 | |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 1106 | if (lex->getType()->isPointerType() && rex->getType()->isIntegerType()) |
| 1107 | return lex->getType(); |
| 1108 | if (lex->getType()->isIntegerType() && rex->getType()->isPointerType()) |
| 1109 | return rex->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1110 | InvalidOperands(loc, lex, rex); |
| 1111 | return QualType(); |
| 1112 | } |
| 1113 | |
| 1114 | inline QualType Sema::CheckSubtractionOperands( // C99 6.5.6 |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1115 | Expr *&lex, Expr *&rex, SourceLocation loc, bool isCompAssign) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1116 | { |
Steve Naroff | 3e5e556 | 2007-07-16 22:23:01 +0000 | [diff] [blame] | 1117 | if (lex->getType()->isVectorType() || rex->getType()->isVectorType()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1118 | return CheckVectorOperands(loc, lex, rex); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 1119 | |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1120 | QualType compType = UsualArithmeticConversions(lex, rex, isCompAssign); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1121 | |
| 1122 | // handle the common case first (both operands are arithmetic). |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 1123 | if (lex->getType()->isArithmeticType() && rex->getType()->isArithmeticType()) |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1124 | return compType; |
Steve Naroff | 3e5e556 | 2007-07-16 22:23:01 +0000 | [diff] [blame] | 1125 | |
| 1126 | if (lex->getType()->isPointerType() && rex->getType()->isIntegerType()) |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1127 | return compType; |
Steve Naroff | 3e5e556 | 2007-07-16 22:23:01 +0000 | [diff] [blame] | 1128 | if (lex->getType()->isPointerType() && rex->getType()->isPointerType()) |
Chris Lattner | 8b9023b | 2007-07-13 03:05:23 +0000 | [diff] [blame] | 1129 | return Context.getPointerDiffType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1130 | InvalidOperands(loc, lex, rex); |
| 1131 | return QualType(); |
| 1132 | } |
| 1133 | |
| 1134 | inline QualType Sema::CheckShiftOperands( // C99 6.5.7 |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1135 | Expr *&lex, Expr *&rex, SourceLocation loc, bool isCompAssign) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1136 | { |
| 1137 | // FIXME: Shifts don't perform usual arithmetic conversions. This is wrong |
| 1138 | // for int << longlong -> the result type should be int, not long long. |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1139 | QualType compType = UsualArithmeticConversions(lex, rex, isCompAssign); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1140 | |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 1141 | // handle the common case first (both operands are arithmetic). |
| 1142 | if (lex->getType()->isIntegerType() && rex->getType()->isIntegerType()) |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1143 | return compType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1144 | InvalidOperands(loc, lex, rex); |
| 1145 | return QualType(); |
| 1146 | } |
| 1147 | |
Chris Lattner | a5937dd | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 1148 | inline QualType Sema::CheckCompareOperands( // C99 6.5.8 |
| 1149 | Expr *&lex, Expr *&rex, SourceLocation loc, bool isRelational) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1150 | { |
Chris Lattner | a5937dd | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 1151 | // C99 6.5.8p3 / C99 6.5.9p4 |
Steve Naroff | 30bf771 | 2007-08-10 18:26:40 +0000 | [diff] [blame] | 1152 | if (lex->getType()->isArithmeticType() && rex->getType()->isArithmeticType()) |
| 1153 | UsualArithmeticConversions(lex, rex); |
| 1154 | else { |
| 1155 | UsualUnaryConversions(lex); |
| 1156 | UsualUnaryConversions(rex); |
| 1157 | } |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 1158 | QualType lType = lex->getType(); |
| 1159 | QualType rType = rex->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1160 | |
Chris Lattner | a5937dd | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 1161 | if (isRelational) { |
| 1162 | if (lType->isRealType() && rType->isRealType()) |
| 1163 | return Context.IntTy; |
| 1164 | } else { |
Chris Lattner | 915311c | 2007-08-30 06:10:41 +0000 | [diff] [blame^] | 1165 | if (lType->isFloatingType() && rType->isFloatingType()) |
Ted Kremenek | 9b3d3a9 | 2007-08-29 18:06:12 +0000 | [diff] [blame] | 1166 | Diag(loc, diag::warn_floatingpoint_eq); |
| 1167 | |
Chris Lattner | a5937dd | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 1168 | if (lType->isArithmeticType() && rType->isArithmeticType()) |
| 1169 | return Context.IntTy; |
| 1170 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1171 | |
Chris Lattner | d28f815 | 2007-08-26 01:10:14 +0000 | [diff] [blame] | 1172 | bool LHSIsNull = lex->isNullPointerConstant(Context); |
| 1173 | bool RHSIsNull = rex->isNullPointerConstant(Context); |
| 1174 | |
Chris Lattner | a5937dd | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 1175 | // All of the following pointer related warnings are GCC extensions, except |
| 1176 | // when handling null pointer constants. One day, we can consider making them |
| 1177 | // errors (when -pedantic-errors is enabled). |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 1178 | if (lType->isPointerType() && rType->isPointerType()) { // C99 6.5.8p2 |
Chris Lattner | d28f815 | 2007-08-26 01:10:14 +0000 | [diff] [blame] | 1179 | if (!LHSIsNull && !RHSIsNull && |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 1180 | !Type::pointerTypesAreCompatible(lType.getUnqualifiedType(), |
| 1181 | rType.getUnqualifiedType())) { |
Steve Naroff | e77fd3c | 2007-08-16 21:48:38 +0000 | [diff] [blame] | 1182 | Diag(loc, diag::ext_typecheck_comparison_of_distinct_pointers, |
| 1183 | lType.getAsString(), rType.getAsString(), |
| 1184 | lex->getSourceRange(), rex->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1185 | } |
Chris Lattner | d28f815 | 2007-08-26 01:10:14 +0000 | [diff] [blame] | 1186 | promoteExprToType(rex, lType); // promote the pointer to pointer |
Steve Naroff | e77fd3c | 2007-08-16 21:48:38 +0000 | [diff] [blame] | 1187 | return Context.IntTy; |
| 1188 | } |
| 1189 | if (lType->isPointerType() && rType->isIntegerType()) { |
Chris Lattner | d28f815 | 2007-08-26 01:10:14 +0000 | [diff] [blame] | 1190 | if (!RHSIsNull) |
Steve Naroff | e77fd3c | 2007-08-16 21:48:38 +0000 | [diff] [blame] | 1191 | Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer, |
| 1192 | lType.getAsString(), rType.getAsString(), |
| 1193 | lex->getSourceRange(), rex->getSourceRange()); |
Chris Lattner | d28f815 | 2007-08-26 01:10:14 +0000 | [diff] [blame] | 1194 | promoteExprToType(rex, lType); // promote the integer to pointer |
Steve Naroff | e77fd3c | 2007-08-16 21:48:38 +0000 | [diff] [blame] | 1195 | return Context.IntTy; |
| 1196 | } |
| 1197 | if (lType->isIntegerType() && rType->isPointerType()) { |
Chris Lattner | d28f815 | 2007-08-26 01:10:14 +0000 | [diff] [blame] | 1198 | if (!LHSIsNull) |
Steve Naroff | e77fd3c | 2007-08-16 21:48:38 +0000 | [diff] [blame] | 1199 | Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer, |
| 1200 | lType.getAsString(), rType.getAsString(), |
| 1201 | lex->getSourceRange(), rex->getSourceRange()); |
Chris Lattner | d28f815 | 2007-08-26 01:10:14 +0000 | [diff] [blame] | 1202 | promoteExprToType(lex, rType); // promote the integer to pointer |
Steve Naroff | e77fd3c | 2007-08-16 21:48:38 +0000 | [diff] [blame] | 1203 | return Context.IntTy; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1204 | } |
| 1205 | InvalidOperands(loc, lex, rex); |
| 1206 | return QualType(); |
| 1207 | } |
| 1208 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1209 | inline QualType Sema::CheckBitwiseOperands( |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1210 | Expr *&lex, Expr *&rex, SourceLocation loc, bool isCompAssign) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1211 | { |
Steve Naroff | 3e5e556 | 2007-07-16 22:23:01 +0000 | [diff] [blame] | 1212 | if (lex->getType()->isVectorType() || rex->getType()->isVectorType()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1213 | return CheckVectorOperands(loc, lex, rex); |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 1214 | |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1215 | QualType compType = UsualArithmeticConversions(lex, rex, isCompAssign); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1216 | |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 1217 | if (lex->getType()->isIntegerType() && rex->getType()->isIntegerType()) |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1218 | return compType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1219 | InvalidOperands(loc, lex, rex); |
| 1220 | return QualType(); |
| 1221 | } |
| 1222 | |
| 1223 | inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14] |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 1224 | Expr *&lex, Expr *&rex, SourceLocation loc) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1225 | { |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 1226 | UsualUnaryConversions(lex); |
| 1227 | UsualUnaryConversions(rex); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1228 | |
Steve Naroff | a4332e2 | 2007-07-17 00:58:39 +0000 | [diff] [blame] | 1229 | if (lex->getType()->isScalarType() || rex->getType()->isScalarType()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1230 | return Context.IntTy; |
| 1231 | InvalidOperands(loc, lex, rex); |
| 1232 | return QualType(); |
| 1233 | } |
| 1234 | |
| 1235 | inline QualType Sema::CheckAssignmentOperands( // C99 6.5.16.1 |
Steve Naroff | f1120de | 2007-08-24 22:33:52 +0000 | [diff] [blame] | 1236 | Expr *lex, Expr *&rex, SourceLocation loc, QualType compoundType) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1237 | { |
| 1238 | QualType lhsType = lex->getType(); |
| 1239 | QualType rhsType = compoundType.isNull() ? rex->getType() : compoundType; |
| 1240 | bool hadError = false; |
| 1241 | Expr::isModifiableLvalueResult mlval = lex->isModifiableLvalue(); |
| 1242 | |
| 1243 | switch (mlval) { // C99 6.5.16p2 |
| 1244 | case Expr::MLV_Valid: |
| 1245 | break; |
| 1246 | case Expr::MLV_ConstQualified: |
| 1247 | Diag(loc, diag::err_typecheck_assign_const, lex->getSourceRange()); |
| 1248 | hadError = true; |
| 1249 | break; |
| 1250 | case Expr::MLV_ArrayType: |
| 1251 | Diag(loc, diag::err_typecheck_array_not_modifiable_lvalue, |
| 1252 | lhsType.getAsString(), lex->getSourceRange()); |
| 1253 | return QualType(); |
| 1254 | case Expr::MLV_NotObjectType: |
| 1255 | Diag(loc, diag::err_typecheck_non_object_not_modifiable_lvalue, |
| 1256 | lhsType.getAsString(), lex->getSourceRange()); |
| 1257 | return QualType(); |
| 1258 | case Expr::MLV_InvalidExpression: |
| 1259 | Diag(loc, diag::err_typecheck_expression_not_modifiable_lvalue, |
| 1260 | lex->getSourceRange()); |
| 1261 | return QualType(); |
| 1262 | case Expr::MLV_IncompleteType: |
| 1263 | case Expr::MLV_IncompleteVoidType: |
| 1264 | Diag(loc, diag::err_typecheck_incomplete_type_not_modifiable_lvalue, |
| 1265 | lhsType.getAsString(), lex->getSourceRange()); |
| 1266 | return QualType(); |
Steve Naroff | fec0b49 | 2007-07-30 03:29:09 +0000 | [diff] [blame] | 1267 | case Expr::MLV_DuplicateVectorComponents: |
| 1268 | Diag(loc, diag::err_typecheck_duplicate_vector_components_not_mlvalue, |
| 1269 | lex->getSourceRange()); |
| 1270 | return QualType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1271 | } |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 1272 | AssignmentCheckResult result; |
| 1273 | |
| 1274 | if (compoundType.isNull()) |
| 1275 | result = CheckSingleAssignmentConstraints(lhsType, rex); |
| 1276 | else |
| 1277 | result = CheckCompoundAssignmentConstraints(lhsType, rhsType); |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1278 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1279 | // decode the result (notice that extensions still return a type). |
| 1280 | switch (result) { |
| 1281 | case Compatible: |
| 1282 | break; |
| 1283 | case Incompatible: |
| 1284 | Diag(loc, diag::err_typecheck_assign_incompatible, |
| 1285 | lhsType.getAsString(), rhsType.getAsString(), |
| 1286 | lex->getSourceRange(), rex->getSourceRange()); |
| 1287 | hadError = true; |
| 1288 | break; |
| 1289 | case PointerFromInt: |
| 1290 | // check for null pointer constant (C99 6.3.2.3p3) |
Chris Lattner | 590b664 | 2007-07-15 23:26:56 +0000 | [diff] [blame] | 1291 | if (compoundType.isNull() && !rex->isNullPointerConstant(Context)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1292 | Diag(loc, diag::ext_typecheck_assign_pointer_int, |
| 1293 | lhsType.getAsString(), rhsType.getAsString(), |
| 1294 | lex->getSourceRange(), rex->getSourceRange()); |
| 1295 | } |
| 1296 | break; |
| 1297 | case IntFromPointer: |
| 1298 | Diag(loc, diag::ext_typecheck_assign_pointer_int, |
| 1299 | lhsType.getAsString(), rhsType.getAsString(), |
| 1300 | lex->getSourceRange(), rex->getSourceRange()); |
| 1301 | break; |
| 1302 | case IncompatiblePointer: |
| 1303 | Diag(loc, diag::ext_typecheck_assign_incompatible_pointer, |
| 1304 | lhsType.getAsString(), rhsType.getAsString(), |
| 1305 | lex->getSourceRange(), rex->getSourceRange()); |
| 1306 | break; |
| 1307 | case CompatiblePointerDiscardsQualifiers: |
| 1308 | Diag(loc, diag::ext_typecheck_assign_discards_qualifiers, |
| 1309 | lhsType.getAsString(), rhsType.getAsString(), |
| 1310 | lex->getSourceRange(), rex->getSourceRange()); |
| 1311 | break; |
| 1312 | } |
| 1313 | // C99 6.5.16p3: The type of an assignment expression is the type of the |
| 1314 | // left operand unless the left operand has qualified type, in which case |
| 1315 | // it is the unqualified version of the type of the left operand. |
| 1316 | // C99 6.5.16.1p2: In simple assignment, the value of the right operand |
| 1317 | // is converted to the type of the assignment expression (above). |
| 1318 | // C++ 5.17p1: the type of the assignment expression is that of its left oprdu. |
| 1319 | return hadError ? QualType() : lhsType.getUnqualifiedType(); |
| 1320 | } |
| 1321 | |
| 1322 | inline QualType Sema::CheckCommaOperands( // C99 6.5.17 |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 1323 | Expr *&lex, Expr *&rex, SourceLocation loc) { |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 1324 | UsualUnaryConversions(rex); |
| 1325 | return rex->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 1328 | /// CheckIncrementDecrementOperand - unlike most "Check" methods, this routine |
| 1329 | /// doesn't need to call UsualUnaryConversions or UsualArithmeticConversions. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1330 | QualType Sema::CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc) { |
Steve Naroff | 49b4526 | 2007-07-13 16:58:59 +0000 | [diff] [blame] | 1331 | QualType resType = op->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1332 | assert(!resType.isNull() && "no type for increment/decrement expression"); |
| 1333 | |
Steve Naroff | 084f9ed | 2007-08-24 17:20:07 +0000 | [diff] [blame] | 1334 | // C99 6.5.2.4p1: We allow complex as a GCC extension. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1335 | if (const PointerType *pt = dyn_cast<PointerType>(resType)) { |
| 1336 | if (!pt->getPointeeType()->isObjectType()) { // C99 6.5.2.4p2, 6.5.6p2 |
| 1337 | Diag(OpLoc, diag::err_typecheck_arithmetic_incomplete_type, |
| 1338 | resType.getAsString(), op->getSourceRange()); |
| 1339 | return QualType(); |
| 1340 | } |
Steve Naroff | 084f9ed | 2007-08-24 17:20:07 +0000 | [diff] [blame] | 1341 | } else if (!resType->isRealType()) { |
| 1342 | if (resType->isComplexType()) |
| 1343 | // C99 does not support ++/-- on complex types. |
| 1344 | Diag(OpLoc, diag::ext_integer_increment_complex, |
| 1345 | resType.getAsString(), op->getSourceRange()); |
| 1346 | else { |
| 1347 | Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement, |
| 1348 | resType.getAsString(), op->getSourceRange()); |
| 1349 | return QualType(); |
| 1350 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1351 | } |
Steve Naroff | dd10e02 | 2007-08-23 21:37:33 +0000 | [diff] [blame] | 1352 | // At this point, we know we have a real, complex or pointer type. |
| 1353 | // Now make sure the operand is a modifiable lvalue. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1354 | Expr::isModifiableLvalueResult mlval = op->isModifiableLvalue(); |
| 1355 | if (mlval != Expr::MLV_Valid) { |
| 1356 | // FIXME: emit a more precise diagnostic... |
| 1357 | Diag(OpLoc, diag::err_typecheck_invalid_lvalue_incr_decr, |
| 1358 | op->getSourceRange()); |
| 1359 | return QualType(); |
| 1360 | } |
| 1361 | return resType; |
| 1362 | } |
| 1363 | |
| 1364 | /// getPrimaryDeclaration - Helper function for CheckAddressOfOperand(). |
| 1365 | /// This routine allows us to typecheck complex/recursive expressions |
| 1366 | /// where the declaration is needed for type checking. Here are some |
| 1367 | /// examples: &s.xx, &s.zz[1].yy, &(1+2), &(XX), &"123"[2]. |
| 1368 | static Decl *getPrimaryDeclaration(Expr *e) { |
| 1369 | switch (e->getStmtClass()) { |
| 1370 | case Stmt::DeclRefExprClass: |
| 1371 | return cast<DeclRefExpr>(e)->getDecl(); |
| 1372 | case Stmt::MemberExprClass: |
| 1373 | return getPrimaryDeclaration(cast<MemberExpr>(e)->getBase()); |
| 1374 | case Stmt::ArraySubscriptExprClass: |
| 1375 | return getPrimaryDeclaration(cast<ArraySubscriptExpr>(e)->getBase()); |
| 1376 | case Stmt::CallExprClass: |
| 1377 | return getPrimaryDeclaration(cast<CallExpr>(e)->getCallee()); |
| 1378 | case Stmt::UnaryOperatorClass: |
| 1379 | return getPrimaryDeclaration(cast<UnaryOperator>(e)->getSubExpr()); |
| 1380 | case Stmt::ParenExprClass: |
| 1381 | return getPrimaryDeclaration(cast<ParenExpr>(e)->getSubExpr()); |
| 1382 | default: |
| 1383 | return 0; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | /// CheckAddressOfOperand - The operand of & must be either a function |
| 1388 | /// designator or an lvalue designating an object. If it is an lvalue, the |
| 1389 | /// object cannot be declared with storage class register or be a bit field. |
| 1390 | /// Note: The usual conversions are *not* applied to the operand of the & |
| 1391 | /// operator (C99 6.3.2.1p[2-4]), and its result is never an lvalue. |
| 1392 | QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { |
| 1393 | Decl *dcl = getPrimaryDeclaration(op); |
| 1394 | Expr::isLvalueResult lval = op->isLvalue(); |
| 1395 | |
| 1396 | if (lval != Expr::LV_Valid) { // C99 6.5.3.2p1 |
| 1397 | if (dcl && isa<FunctionDecl>(dcl)) // allow function designators |
| 1398 | ; |
| 1399 | else { // FIXME: emit more specific diag... |
| 1400 | Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof, |
| 1401 | op->getSourceRange()); |
| 1402 | return QualType(); |
| 1403 | } |
| 1404 | } else if (dcl) { |
| 1405 | // We have an lvalue with a decl. Make sure the decl is not declared |
| 1406 | // with the register storage-class specifier. |
| 1407 | if (const VarDecl *vd = dyn_cast<VarDecl>(dcl)) { |
| 1408 | if (vd->getStorageClass() == VarDecl::Register) { |
| 1409 | Diag(OpLoc, diag::err_typecheck_address_of_register, |
| 1410 | op->getSourceRange()); |
| 1411 | return QualType(); |
| 1412 | } |
| 1413 | } else |
| 1414 | assert(0 && "Unknown/unexpected decl type"); |
| 1415 | |
| 1416 | // FIXME: add check for bitfields! |
| 1417 | } |
| 1418 | // If the operand has type "type", the result has type "pointer to type". |
| 1419 | return Context.getPointerType(op->getType()); |
| 1420 | } |
| 1421 | |
| 1422 | QualType Sema::CheckIndirectionOperand(Expr *op, SourceLocation OpLoc) { |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 1423 | UsualUnaryConversions(op); |
| 1424 | QualType qType = op->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1425 | |
Chris Lattner | befee48 | 2007-07-31 16:53:04 +0000 | [diff] [blame] | 1426 | if (const PointerType *PT = qType->getAsPointerType()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1427 | QualType ptype = PT->getPointeeType(); |
| 1428 | // C99 6.5.3.2p4. "if it points to an object,...". |
| 1429 | if (ptype->isIncompleteType()) { // An incomplete type is not an object |
| 1430 | // GCC compat: special case 'void *' (treat as warning). |
| 1431 | if (ptype->isVoidType()) { |
| 1432 | Diag(OpLoc, diag::ext_typecheck_deref_ptr_to_void, |
| 1433 | qType.getAsString(), op->getSourceRange()); |
| 1434 | } else { |
| 1435 | Diag(OpLoc, diag::err_typecheck_deref_incomplete_type, |
| 1436 | ptype.getAsString(), op->getSourceRange()); |
| 1437 | return QualType(); |
| 1438 | } |
| 1439 | } |
| 1440 | return ptype; |
| 1441 | } |
| 1442 | Diag(OpLoc, diag::err_typecheck_indirection_requires_pointer, |
| 1443 | qType.getAsString(), op->getSourceRange()); |
| 1444 | return QualType(); |
| 1445 | } |
| 1446 | |
| 1447 | static inline BinaryOperator::Opcode ConvertTokenKindToBinaryOpcode( |
| 1448 | tok::TokenKind Kind) { |
| 1449 | BinaryOperator::Opcode Opc; |
| 1450 | switch (Kind) { |
| 1451 | default: assert(0 && "Unknown binop!"); |
| 1452 | case tok::star: Opc = BinaryOperator::Mul; break; |
| 1453 | case tok::slash: Opc = BinaryOperator::Div; break; |
| 1454 | case tok::percent: Opc = BinaryOperator::Rem; break; |
| 1455 | case tok::plus: Opc = BinaryOperator::Add; break; |
| 1456 | case tok::minus: Opc = BinaryOperator::Sub; break; |
| 1457 | case tok::lessless: Opc = BinaryOperator::Shl; break; |
| 1458 | case tok::greatergreater: Opc = BinaryOperator::Shr; break; |
| 1459 | case tok::lessequal: Opc = BinaryOperator::LE; break; |
| 1460 | case tok::less: Opc = BinaryOperator::LT; break; |
| 1461 | case tok::greaterequal: Opc = BinaryOperator::GE; break; |
| 1462 | case tok::greater: Opc = BinaryOperator::GT; break; |
| 1463 | case tok::exclaimequal: Opc = BinaryOperator::NE; break; |
| 1464 | case tok::equalequal: Opc = BinaryOperator::EQ; break; |
| 1465 | case tok::amp: Opc = BinaryOperator::And; break; |
| 1466 | case tok::caret: Opc = BinaryOperator::Xor; break; |
| 1467 | case tok::pipe: Opc = BinaryOperator::Or; break; |
| 1468 | case tok::ampamp: Opc = BinaryOperator::LAnd; break; |
| 1469 | case tok::pipepipe: Opc = BinaryOperator::LOr; break; |
| 1470 | case tok::equal: Opc = BinaryOperator::Assign; break; |
| 1471 | case tok::starequal: Opc = BinaryOperator::MulAssign; break; |
| 1472 | case tok::slashequal: Opc = BinaryOperator::DivAssign; break; |
| 1473 | case tok::percentequal: Opc = BinaryOperator::RemAssign; break; |
| 1474 | case tok::plusequal: Opc = BinaryOperator::AddAssign; break; |
| 1475 | case tok::minusequal: Opc = BinaryOperator::SubAssign; break; |
| 1476 | case tok::lesslessequal: Opc = BinaryOperator::ShlAssign; break; |
| 1477 | case tok::greatergreaterequal: Opc = BinaryOperator::ShrAssign; break; |
| 1478 | case tok::ampequal: Opc = BinaryOperator::AndAssign; break; |
| 1479 | case tok::caretequal: Opc = BinaryOperator::XorAssign; break; |
| 1480 | case tok::pipeequal: Opc = BinaryOperator::OrAssign; break; |
| 1481 | case tok::comma: Opc = BinaryOperator::Comma; break; |
| 1482 | } |
| 1483 | return Opc; |
| 1484 | } |
| 1485 | |
| 1486 | static inline UnaryOperator::Opcode ConvertTokenKindToUnaryOpcode( |
| 1487 | tok::TokenKind Kind) { |
| 1488 | UnaryOperator::Opcode Opc; |
| 1489 | switch (Kind) { |
| 1490 | default: assert(0 && "Unknown unary op!"); |
| 1491 | case tok::plusplus: Opc = UnaryOperator::PreInc; break; |
| 1492 | case tok::minusminus: Opc = UnaryOperator::PreDec; break; |
| 1493 | case tok::amp: Opc = UnaryOperator::AddrOf; break; |
| 1494 | case tok::star: Opc = UnaryOperator::Deref; break; |
| 1495 | case tok::plus: Opc = UnaryOperator::Plus; break; |
| 1496 | case tok::minus: Opc = UnaryOperator::Minus; break; |
| 1497 | case tok::tilde: Opc = UnaryOperator::Not; break; |
| 1498 | case tok::exclaim: Opc = UnaryOperator::LNot; break; |
| 1499 | case tok::kw_sizeof: Opc = UnaryOperator::SizeOf; break; |
| 1500 | case tok::kw___alignof: Opc = UnaryOperator::AlignOf; break; |
| 1501 | case tok::kw___real: Opc = UnaryOperator::Real; break; |
| 1502 | case tok::kw___imag: Opc = UnaryOperator::Imag; break; |
| 1503 | case tok::kw___extension__: Opc = UnaryOperator::Extension; break; |
| 1504 | } |
| 1505 | return Opc; |
| 1506 | } |
| 1507 | |
| 1508 | // Binary Operators. 'Tok' is the token for the operator. |
| 1509 | Action::ExprResult Sema::ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind, |
| 1510 | ExprTy *LHS, ExprTy *RHS) { |
| 1511 | BinaryOperator::Opcode Opc = ConvertTokenKindToBinaryOpcode(Kind); |
| 1512 | Expr *lhs = (Expr *)LHS, *rhs = (Expr*)RHS; |
| 1513 | |
| 1514 | assert((lhs != 0) && "ParseBinOp(): missing left expression"); |
| 1515 | assert((rhs != 0) && "ParseBinOp(): missing right expression"); |
| 1516 | |
| 1517 | QualType ResultTy; // Result type of the binary operator. |
| 1518 | QualType CompTy; // Computation type for compound assignments (e.g. '+=') |
| 1519 | |
| 1520 | switch (Opc) { |
| 1521 | default: |
| 1522 | assert(0 && "Unknown binary expr!"); |
| 1523 | case BinaryOperator::Assign: |
| 1524 | ResultTy = CheckAssignmentOperands(lhs, rhs, TokLoc, QualType()); |
| 1525 | break; |
| 1526 | case BinaryOperator::Mul: |
| 1527 | case BinaryOperator::Div: |
| 1528 | ResultTy = CheckMultiplyDivideOperands(lhs, rhs, TokLoc); |
| 1529 | break; |
| 1530 | case BinaryOperator::Rem: |
| 1531 | ResultTy = CheckRemainderOperands(lhs, rhs, TokLoc); |
| 1532 | break; |
| 1533 | case BinaryOperator::Add: |
| 1534 | ResultTy = CheckAdditionOperands(lhs, rhs, TokLoc); |
| 1535 | break; |
| 1536 | case BinaryOperator::Sub: |
| 1537 | ResultTy = CheckSubtractionOperands(lhs, rhs, TokLoc); |
| 1538 | break; |
| 1539 | case BinaryOperator::Shl: |
| 1540 | case BinaryOperator::Shr: |
| 1541 | ResultTy = CheckShiftOperands(lhs, rhs, TokLoc); |
| 1542 | break; |
| 1543 | case BinaryOperator::LE: |
| 1544 | case BinaryOperator::LT: |
| 1545 | case BinaryOperator::GE: |
| 1546 | case BinaryOperator::GT: |
Chris Lattner | a5937dd | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 1547 | ResultTy = CheckCompareOperands(lhs, rhs, TokLoc, true); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1548 | break; |
| 1549 | case BinaryOperator::EQ: |
| 1550 | case BinaryOperator::NE: |
Chris Lattner | a5937dd | 2007-08-26 01:18:55 +0000 | [diff] [blame] | 1551 | ResultTy = CheckCompareOperands(lhs, rhs, TokLoc, false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1552 | break; |
| 1553 | case BinaryOperator::And: |
| 1554 | case BinaryOperator::Xor: |
| 1555 | case BinaryOperator::Or: |
| 1556 | ResultTy = CheckBitwiseOperands(lhs, rhs, TokLoc); |
| 1557 | break; |
| 1558 | case BinaryOperator::LAnd: |
| 1559 | case BinaryOperator::LOr: |
| 1560 | ResultTy = CheckLogicalOperands(lhs, rhs, TokLoc); |
| 1561 | break; |
| 1562 | case BinaryOperator::MulAssign: |
| 1563 | case BinaryOperator::DivAssign: |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1564 | CompTy = CheckMultiplyDivideOperands(lhs, rhs, TokLoc, true); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1565 | if (!CompTy.isNull()) |
| 1566 | ResultTy = CheckAssignmentOperands(lhs, rhs, TokLoc, CompTy); |
| 1567 | break; |
| 1568 | case BinaryOperator::RemAssign: |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1569 | CompTy = CheckRemainderOperands(lhs, rhs, TokLoc, true); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1570 | if (!CompTy.isNull()) |
| 1571 | ResultTy = CheckAssignmentOperands(lhs, rhs, TokLoc, CompTy); |
| 1572 | break; |
| 1573 | case BinaryOperator::AddAssign: |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1574 | CompTy = CheckAdditionOperands(lhs, rhs, TokLoc, true); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1575 | if (!CompTy.isNull()) |
| 1576 | ResultTy = CheckAssignmentOperands(lhs, rhs, TokLoc, CompTy); |
| 1577 | break; |
| 1578 | case BinaryOperator::SubAssign: |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1579 | CompTy = CheckSubtractionOperands(lhs, rhs, TokLoc, true); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1580 | if (!CompTy.isNull()) |
| 1581 | ResultTy = CheckAssignmentOperands(lhs, rhs, TokLoc, CompTy); |
| 1582 | break; |
| 1583 | case BinaryOperator::ShlAssign: |
| 1584 | case BinaryOperator::ShrAssign: |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1585 | CompTy = CheckShiftOperands(lhs, rhs, TokLoc, true); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1586 | if (!CompTy.isNull()) |
| 1587 | ResultTy = CheckAssignmentOperands(lhs, rhs, TokLoc, CompTy); |
| 1588 | break; |
| 1589 | case BinaryOperator::AndAssign: |
| 1590 | case BinaryOperator::XorAssign: |
| 1591 | case BinaryOperator::OrAssign: |
Steve Naroff | 9f5fa9b | 2007-08-24 19:07:16 +0000 | [diff] [blame] | 1592 | CompTy = CheckBitwiseOperands(lhs, rhs, TokLoc, true); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1593 | if (!CompTy.isNull()) |
| 1594 | ResultTy = CheckAssignmentOperands(lhs, rhs, TokLoc, CompTy); |
| 1595 | break; |
| 1596 | case BinaryOperator::Comma: |
| 1597 | ResultTy = CheckCommaOperands(lhs, rhs, TokLoc); |
| 1598 | break; |
| 1599 | } |
| 1600 | if (ResultTy.isNull()) |
| 1601 | return true; |
| 1602 | if (CompTy.isNull()) |
Chris Lattner | 17d1b2a | 2007-08-28 18:36:55 +0000 | [diff] [blame] | 1603 | return new BinaryOperator(lhs, rhs, Opc, ResultTy, TokLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1604 | else |
Chris Lattner | 17d1b2a | 2007-08-28 18:36:55 +0000 | [diff] [blame] | 1605 | return new CompoundAssignOperator(lhs, rhs, Opc, ResultTy, CompTy, TokLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | // Unary Operators. 'Tok' is the token for the operator. |
| 1609 | Action::ExprResult Sema::ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op, |
| 1610 | ExprTy *input) { |
| 1611 | Expr *Input = (Expr*)input; |
| 1612 | UnaryOperator::Opcode Opc = ConvertTokenKindToUnaryOpcode(Op); |
| 1613 | QualType resultType; |
| 1614 | switch (Opc) { |
| 1615 | default: |
| 1616 | assert(0 && "Unimplemented unary expr!"); |
| 1617 | case UnaryOperator::PreInc: |
| 1618 | case UnaryOperator::PreDec: |
| 1619 | resultType = CheckIncrementDecrementOperand(Input, OpLoc); |
| 1620 | break; |
| 1621 | case UnaryOperator::AddrOf: |
| 1622 | resultType = CheckAddressOfOperand(Input, OpLoc); |
| 1623 | break; |
| 1624 | case UnaryOperator::Deref: |
| 1625 | resultType = CheckIndirectionOperand(Input, OpLoc); |
| 1626 | break; |
| 1627 | case UnaryOperator::Plus: |
| 1628 | case UnaryOperator::Minus: |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 1629 | UsualUnaryConversions(Input); |
| 1630 | resultType = Input->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1631 | if (!resultType->isArithmeticType()) // C99 6.5.3.3p1 |
| 1632 | return Diag(OpLoc, diag::err_typecheck_unary_expr, |
| 1633 | resultType.getAsString()); |
| 1634 | break; |
| 1635 | case UnaryOperator::Not: // bitwise complement |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 1636 | UsualUnaryConversions(Input); |
| 1637 | resultType = Input->getType(); |
Steve Naroff | 084f9ed | 2007-08-24 17:20:07 +0000 | [diff] [blame] | 1638 | // C99 6.5.3.3p1. We allow complex as a GCC extension. |
| 1639 | if (!resultType->isIntegerType()) { |
| 1640 | if (resultType->isComplexType()) |
| 1641 | // C99 does not support '~' for complex conjugation. |
| 1642 | Diag(OpLoc, diag::ext_integer_complement_complex, |
| 1643 | resultType.getAsString()); |
| 1644 | else |
| 1645 | return Diag(OpLoc, diag::err_typecheck_unary_expr, |
| 1646 | resultType.getAsString()); |
| 1647 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1648 | break; |
| 1649 | case UnaryOperator::LNot: // logical negation |
| 1650 | // Unlike +/-/~, integer promotions aren't done here (C99 6.5.3.3p5). |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 1651 | DefaultFunctionArrayConversion(Input); |
| 1652 | resultType = Input->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1653 | if (!resultType->isScalarType()) // C99 6.5.3.3p1 |
| 1654 | return Diag(OpLoc, diag::err_typecheck_unary_expr, |
| 1655 | resultType.getAsString()); |
| 1656 | // LNot always has type int. C99 6.5.3.3p5. |
| 1657 | resultType = Context.IntTy; |
| 1658 | break; |
| 1659 | case UnaryOperator::SizeOf: |
| 1660 | resultType = CheckSizeOfAlignOfOperand(Input->getType(), OpLoc, true); |
| 1661 | break; |
| 1662 | case UnaryOperator::AlignOf: |
| 1663 | resultType = CheckSizeOfAlignOfOperand(Input->getType(), OpLoc, false); |
| 1664 | break; |
Chris Lattner | dbb3697 | 2007-08-24 21:16:53 +0000 | [diff] [blame] | 1665 | case UnaryOperator::Real: |
Chris Lattner | dbb3697 | 2007-08-24 21:16:53 +0000 | [diff] [blame] | 1666 | case UnaryOperator::Imag: |
Chris Lattner | 5d79425 | 2007-08-24 21:41:10 +0000 | [diff] [blame] | 1667 | resultType = CheckRealImagOperand(Input, OpLoc); |
Chris Lattner | dbb3697 | 2007-08-24 21:16:53 +0000 | [diff] [blame] | 1668 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1669 | case UnaryOperator::Extension: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1670 | resultType = Input->getType(); |
| 1671 | break; |
| 1672 | } |
| 1673 | if (resultType.isNull()) |
| 1674 | return true; |
| 1675 | return new UnaryOperator(Input, Opc, resultType, OpLoc); |
| 1676 | } |
| 1677 | |
| 1678 | /// ParseAddrLabel - Parse the GNU address of label extension: "&&foo". |
| 1679 | Sema::ExprResult Sema::ParseAddrLabel(SourceLocation OpLoc, |
| 1680 | SourceLocation LabLoc, |
| 1681 | IdentifierInfo *LabelII) { |
| 1682 | // Look up the record for this label identifier. |
| 1683 | LabelStmt *&LabelDecl = LabelMap[LabelII]; |
| 1684 | |
| 1685 | // If we haven't seen this label yet, create a forward reference. |
| 1686 | if (LabelDecl == 0) |
| 1687 | LabelDecl = new LabelStmt(LabLoc, LabelII, 0); |
| 1688 | |
| 1689 | // Create the AST node. The address of a label always has type 'void*'. |
Chris Lattner | 6481a57 | 2007-08-03 17:31:20 +0000 | [diff] [blame] | 1690 | return new AddrLabelExpr(OpLoc, LabLoc, LabelDecl, |
| 1691 | Context.getPointerType(Context.VoidTy)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Chris Lattner | ab18c4c | 2007-07-24 16:58:17 +0000 | [diff] [blame] | 1694 | Sema::ExprResult Sema::ParseStmtExpr(SourceLocation LPLoc, StmtTy *substmt, |
| 1695 | SourceLocation RPLoc) { // "({..})" |
| 1696 | Stmt *SubStmt = static_cast<Stmt*>(substmt); |
| 1697 | assert(SubStmt && isa<CompoundStmt>(SubStmt) && "Invalid action invocation!"); |
| 1698 | CompoundStmt *Compound = cast<CompoundStmt>(SubStmt); |
| 1699 | |
| 1700 | // FIXME: there are a variety of strange constraints to enforce here, for |
| 1701 | // example, it is not possible to goto into a stmt expression apparently. |
| 1702 | // More semantic analysis is needed. |
| 1703 | |
| 1704 | // FIXME: the last statement in the compount stmt has its value used. We |
| 1705 | // should not warn about it being unused. |
| 1706 | |
| 1707 | // If there are sub stmts in the compound stmt, take the type of the last one |
| 1708 | // as the type of the stmtexpr. |
| 1709 | QualType Ty = Context.VoidTy; |
| 1710 | |
| 1711 | if (!Compound->body_empty()) |
| 1712 | if (Expr *LastExpr = dyn_cast<Expr>(Compound->body_back())) |
| 1713 | Ty = LastExpr->getType(); |
| 1714 | |
| 1715 | return new StmtExpr(Compound, Ty, LPLoc, RPLoc); |
| 1716 | } |
Steve Naroff | d34e915 | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 1717 | |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1718 | Sema::ExprResult Sema::ParseTypesCompatibleExpr(SourceLocation BuiltinLoc, |
Steve Naroff | d34e915 | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 1719 | TypeTy *arg1, TypeTy *arg2, |
| 1720 | SourceLocation RPLoc) { |
| 1721 | QualType argT1 = QualType::getFromOpaquePtr(arg1); |
| 1722 | QualType argT2 = QualType::getFromOpaquePtr(arg2); |
| 1723 | |
| 1724 | assert((!argT1.isNull() && !argT2.isNull()) && "Missing type argument(s)"); |
| 1725 | |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1726 | return new TypesCompatibleExpr(Context.IntTy, BuiltinLoc, argT1, argT2, RPLoc); |
Steve Naroff | d34e915 | 2007-08-01 22:05:33 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
Steve Naroff | d04fdd5 | 2007-08-03 21:21:27 +0000 | [diff] [blame] | 1729 | Sema::ExprResult Sema::ParseChooseExpr(SourceLocation BuiltinLoc, ExprTy *cond, |
| 1730 | ExprTy *expr1, ExprTy *expr2, |
| 1731 | SourceLocation RPLoc) { |
| 1732 | Expr *CondExpr = static_cast<Expr*>(cond); |
| 1733 | Expr *LHSExpr = static_cast<Expr*>(expr1); |
| 1734 | Expr *RHSExpr = static_cast<Expr*>(expr2); |
| 1735 | |
| 1736 | assert((CondExpr && LHSExpr && RHSExpr) && "Missing type argument(s)"); |
| 1737 | |
| 1738 | // The conditional expression is required to be a constant expression. |
| 1739 | llvm::APSInt condEval(32); |
| 1740 | SourceLocation ExpLoc; |
| 1741 | if (!CondExpr->isIntegerConstantExpr(condEval, Context, &ExpLoc)) |
| 1742 | return Diag(ExpLoc, diag::err_typecheck_choose_expr_requires_constant, |
| 1743 | CondExpr->getSourceRange()); |
| 1744 | |
| 1745 | // If the condition is > zero, then the AST type is the same as the LSHExpr. |
| 1746 | QualType resType = condEval.getZExtValue() ? LHSExpr->getType() : |
| 1747 | RHSExpr->getType(); |
| 1748 | return new ChooseExpr(BuiltinLoc, CondExpr, LHSExpr, RHSExpr, resType, RPLoc); |
| 1749 | } |
| 1750 | |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1751 | // TODO: Move this to SemaObjC.cpp |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1752 | Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string) { |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1753 | StringLiteral* S = static_cast<StringLiteral *>(string); |
| 1754 | |
| 1755 | if (CheckBuiltinCFStringArgument(S)) |
| 1756 | return true; |
| 1757 | |
| 1758 | QualType t = Context.getCFConstantStringType(); |
| 1759 | t = t.getQualifiedType(QualType::Const); |
| 1760 | t = Context.getPointerType(t); |
| 1761 | |
| 1762 | return new ObjCStringLiteral(S, t); |
| 1763 | } |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1764 | |
| 1765 | Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc, |
| 1766 | SourceLocation LParenLoc, |
| 1767 | TypeTy *Ty, |
| 1768 | SourceLocation RParenLoc) { |
| 1769 | QualType EncodedType = QualType::getFromOpaquePtr(Ty); |
| 1770 | |
| 1771 | QualType t = Context.getPointerType(Context.CharTy); |
| 1772 | return new ObjCEncodeExpr(t, EncodedType, AtLoc, RParenLoc); |
| 1773 | } |