Expr.h revision 83efb151a0c1df8cb8fb25d6dbb6c0f12f07f60a
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The LLVM Compiler Infrastructure 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file was developed by Chris Lattner and is distributed under 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the University of Illinois Open Source License. See LICENSE.TXT for details. 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file defines the Expr interface and subclasses. 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef LLVM_CLANG_AST_EXPR_H 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define LLVM_CLANG_AST_EXPR_H 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Stmt.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Type.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Decl.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/Basic/IdentifierTable.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/APSInt.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/APFloat.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace clang { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class IdentifierInfo; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class Selector; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class Decl; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class ASTContext; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Expr - This represents one expression. Note that Expr's are subclasses of 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Stmt. This allows an expression to be transparently used any place a Stmt 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// is required. 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Expr : public Stmt { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType TR; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)protected: 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr(StmtClass SC, QualType T) : Stmt(SC), TR(T) {} 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getType() const { return TR; } 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void setType(QualType t) { TR = t; } 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// SourceLocation tokens are not useful in isolation - they are low level 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// value objects created/interpreted by SourceManager. We assume AST 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// clients will have a pointer to the respective SourceManager. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const = 0; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getExprLoc - Return the preferred location for the arrow when diagnosing 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// a problem with a generic expression. 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceLocation getExprLoc() const { return getLocStart(); } 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// hasLocalSideEffect - Return true if this immediate expression has side 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// effects, not counting any sub-expressions. 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool hasLocalSideEffect() const; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// incomplete type other than void. Nonarray expressions that can be lvalues: 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// - name, where name must be a variable 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// - e[i] 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// - (e), where e must be an lvalue 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// - e.name, where e must be an lvalue 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// - e->name 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// - *e, the type of e cannot be a function type 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// - string-constant 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// - reference type [C++ [expr]] 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum isLvalueResult { 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LV_Valid, 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LV_NotObjectType, 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LV_IncompleteVoidType, 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LV_DuplicateVectorComponents, 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LV_InvalidExpression 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) isLvalueResult isLvalue() const; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// does not have an incomplete type, does not have a const-qualified type, 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// and if it is a structure or union, does not have any member (including, 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// recursively, any member or element of all contained aggregates or unions) 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// with a const-qualified type. 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum isModifiableLvalueResult { 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MLV_Valid, 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MLV_NotObjectType, 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MLV_IncompleteVoidType, 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MLV_DuplicateVectorComponents, 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MLV_InvalidExpression, 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MLV_IncompleteType, 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MLV_ConstQualified, 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MLV_ArrayType 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) isModifiableLvalueResult isModifiableLvalue() const; 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool isNullPointerConstant(ASTContext &Ctx) const; 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// isIntegerConstantExpr - Return true if this expression is a valid integer 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// constant expression, and, if so, return its value in Result. If not a 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// valid i-c-e, return false and fill in Loc (if specified) with the location 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// of the invalid expression. 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation *Loc = 0, 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool isEvaluated = true) const; 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::APSInt X(32); 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return isIntegerConstantExpr(X, Ctx, Loc); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// isConstantExpr - Return true if this expression is a valid constant expr. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() >= firstExprConstant && 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) T->getStmtClass() <= lastExprConstant; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Expr *) { return true; } 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static inline Expr* Materialize(llvm::Deserializer& D) { 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return cast<Expr>(Stmt::Materialize(D)); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Primary Expressions. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// enum, etc. 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DeclRefExpr : public Expr { 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ValueDecl *D; 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation Loc; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) : 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr(DeclRefExprClass, t), D(d), Loc(l) {} 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ValueDecl *getDecl() { return D; } 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ValueDecl *getDecl() const { return D; } 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == DeclRefExprClass; 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const DeclRefExpr *) { return true; } 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_begin(); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_end(); 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void directEmit(llvm::Serializer& S) const; 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static DeclRefExpr* directMaterialize(llvm::Deserializer& D); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// PreDefinedExpr - [C99 6.4.2.2] - A pre-defined identifier such as __func__. 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PreDefinedExpr : public Expr { 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum IdentType { 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Func, 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Function, 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PrettyFunction 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private: 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation Loc; 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IdentType Type; 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PreDefinedExpr(SourceLocation l, QualType type, IdentType IT) 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(PreDefinedExprClass, type), Loc(l), Type(IT) {} 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IdentType getIdentType() const { return Type; } 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == PreDefinedExprClass; 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const PreDefinedExpr *) { return true; } 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_begin(); 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_end(); 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void directEmit(llvm::Serializer& S) const; 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static PreDefinedExpr* directMaterialize(llvm::Deserializer& D); 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IntegerLiteral : public Expr { 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::APInt Value; 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation Loc; 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // or UnsignedLongLongTy 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(IntegerLiteralClass, type), Value(V), Loc(l) { 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const llvm::APInt &getValue() const { return Value; } 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == IntegerLiteralClass; 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const IntegerLiteral *) { return true; } 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_begin(); 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_end(); 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void directEmit(llvm::Serializer& S) const; 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static IntegerLiteral* directMaterialize(llvm::Deserializer& D); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CharacterLiteral : public Expr { 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned Value; 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation Loc; 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // type should be IntTy 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CharacterLiteral(unsigned value, QualType type, SourceLocation l) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(CharacterLiteralClass, type), Value(value), Loc(l) { 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getLoc() const { return Loc; } 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned getValue() const { return Value; } 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == CharacterLiteralClass; 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const CharacterLiteral *) { return true; } 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_begin(); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_end(); 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void directEmit(llvm::Serializer& S) const; 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static CharacterLiteral* directMaterialize(llvm::Deserializer& D); 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FloatingLiteral : public Expr { 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::APFloat Value; 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation Loc; 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FloatingLiteral(const llvm::APFloat &V, QualType Type, SourceLocation L) 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(FloatingLiteralClass, Type), Value(V), Loc(L) {} 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const llvm::APFloat &getValue() const { return Value; } 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getValueAsDouble - This returns the value as an inaccurate double. Note 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// that this may cause loss of precision, but is useful for debugging dumps 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// etc. 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) double getValueAsDouble() const { 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // FIXME: We need something for long double here. 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (cast<BuiltinType>(getType())->getKind() == BuiltinType::Float) 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Value.convertToFloat(); 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Value.convertToDouble(); 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == FloatingLiteralClass; 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const FloatingLiteral *) { return true; } 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_begin(); 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_end(); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void directEmit(llvm::Serializer& S) const; 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static FloatingLiteral* directMaterialize(llvm::Deserializer& D); 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ImaginaryLiteral - We support imaginary integer and floating point literals, 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// IntegerLiteral classes. Instances of this class always have a Complex type 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// whose element type matches the subexpression. 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ImaginaryLiteral : public Expr { 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *Val; 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ImaginaryLiteral(Expr *val, QualType Ty) 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(ImaginaryLiteralClass, Ty), Val(val) {} 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Expr *getSubExpr() const { return Val; } 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *getSubExpr() { return Val; } 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == ImaginaryLiteralClass; 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const ImaginaryLiteral *) { return true; } 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_begin(); 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_end(); 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void directEmit(llvm::Serializer& S) const; 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static ImaginaryLiteral* directMaterialize(llvm::Deserializer& D); 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// StringLiteral - This represents a string literal expression, e.g. "foo" 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// or L"bar" (wide strings). The actual string is returned by getStrData() 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// is NOT null-terminated, and the length of the string is determined by 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// calling getByteLength(). 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class StringLiteral : public Expr { 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *StrData; 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned ByteLength; 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsWide; 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if the StringLiteral was composed using token pasting, both locations 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // are needed. If not (the common case), firstTokLoc == lastTokLoc. 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // FIXME: if space becomes an issue, we should create a sub-class. 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation firstTokLoc, lastTokLoc; 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StringLiteral(const char *strData, unsigned byteLength, bool Wide, 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType t, SourceLocation b, SourceLocation e); 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~StringLiteral(); 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *getStrData() const { return StrData; } 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned getByteLength() const { return ByteLength; } 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool isWide() const { return IsWide; } 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual SourceRange getSourceRange() const { 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return SourceRange(firstTokLoc,lastTokLoc); 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == StringLiteralClass; 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const StringLiteral *) { return true; } 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_begin(); 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_end(); 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void directEmit(llvm::Serializer& S) const; 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static StringLiteral* directMaterialize(llvm::Deserializer& D); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// AST node is only formed if full location information is requested. 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ParenExpr : public Expr { 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation L, R; 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *Val; 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(ParenExprClass, val->getType()), L(l), R(r), Val(val) {} 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Expr *getSubExpr() const { return Val; } 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *getSubExpr() { return Val; } 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange getSourceRange() const { return SourceRange(L, R); } 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == ParenExprClass; 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const ParenExpr *) { return true; } 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_begin(); 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual child_iterator child_end(); 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void directEmit(llvm::Serializer& S) const; 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static ParenExpr* directMaterialize(llvm::Deserializer& D); 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// UnaryOperator - This represents the unary-expression's (except sizeof of 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// types), the postinc/postdec operators from postfix-expression, and various 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// extensions. 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Notes on various nodes: 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Real/Imag - These return the real/imag part of a complex operand. If 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// applied to a non-complex value, the former returns its operand and the 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// later returns zero in the type of the operand. 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// subexpression is a compound literal with the various MemberExpr and 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ArraySubscriptExpr's applied to it. 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class UnaryOperator : public Expr { 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 379 // Note that additions to this should also update the StmtVisitor class. 380 enum Opcode { 381 PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators 382 PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. 383 AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators. 384 Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators. 385 Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators. 386 SizeOf, AlignOf, // [C99 6.5.3.4] Sizeof (expr, not type) operator. 387 Real, Imag, // "__real expr"/"__imag expr" Extension. 388 Extension, // __extension__ marker. 389 OffsetOf // __builtin_offsetof 390 }; 391private: 392 Expr *Val; 393 Opcode Opc; 394 SourceLocation Loc; 395public: 396 397 UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 398 : Expr(UnaryOperatorClass, type), Val(input), Opc(opc), Loc(l) {} 399 400 Opcode getOpcode() const { return Opc; } 401 Expr *getSubExpr() const { return Val; } 402 403 /// getOperatorLoc - Return the location of the operator. 404 SourceLocation getOperatorLoc() const { return Loc; } 405 406 /// isPostfix - Return true if this is a postfix operation, like x++. 407 static bool isPostfix(Opcode Op); 408 409 bool isPostfix() const { return isPostfix(Opc); } 410 bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 411 bool isSizeOfAlignOfOp() const { return Opc == SizeOf || Opc == AlignOf; } 412 static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 413 414 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 415 /// corresponds to, e.g. "sizeof" or "[pre]++" 416 static const char *getOpcodeStr(Opcode Op); 417 418 virtual SourceRange getSourceRange() const { 419 if (isPostfix()) 420 return SourceRange(Val->getLocStart(), Loc); 421 else 422 return SourceRange(Loc, Val->getLocEnd()); 423 } 424 virtual SourceLocation getExprLoc() const { return Loc; } 425 426 static bool classof(const Stmt *T) { 427 return T->getStmtClass() == UnaryOperatorClass; 428 } 429 static bool classof(const UnaryOperator *) { return true; } 430 431 // Iterators 432 virtual child_iterator child_begin(); 433 virtual child_iterator child_end(); 434 435 virtual void directEmit(llvm::Serializer& S) const; 436 static UnaryOperator* directMaterialize(llvm::Deserializer& D); 437}; 438 439/// SizeOfAlignOfTypeExpr - [C99 6.5.3.4] - This is only for sizeof/alignof of 440/// *types*. sizeof(expr) is handled by UnaryOperator. 441class SizeOfAlignOfTypeExpr : public Expr { 442 bool isSizeof; // true if sizeof, false if alignof. 443 QualType Ty; 444 SourceLocation OpLoc, RParenLoc; 445public: 446 SizeOfAlignOfTypeExpr(bool issizeof, QualType argType, QualType resultType, 447 SourceLocation op, SourceLocation rp) : 448 Expr(SizeOfAlignOfTypeExprClass, resultType), 449 isSizeof(issizeof), Ty(argType), OpLoc(op), RParenLoc(rp) {} 450 451 bool isSizeOf() const { return isSizeof; } 452 QualType getArgumentType() const { return Ty; } 453 454 SourceLocation getOperatorLoc() const { return OpLoc; } 455 SourceRange getSourceRange() const { return SourceRange(OpLoc, RParenLoc); } 456 457 static bool classof(const Stmt *T) { 458 return T->getStmtClass() == SizeOfAlignOfTypeExprClass; 459 } 460 static bool classof(const SizeOfAlignOfTypeExpr *) { return true; } 461 462 // Iterators 463 virtual child_iterator child_begin(); 464 virtual child_iterator child_end(); 465}; 466 467//===----------------------------------------------------------------------===// 468// Postfix Operators. 469//===----------------------------------------------------------------------===// 470 471/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 472class ArraySubscriptExpr : public Expr { 473 enum { LHS, RHS, END_EXPR=2 }; 474 Expr* SubExprs[END_EXPR]; 475 SourceLocation RBracketLoc; 476public: 477 ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 478 SourceLocation rbracketloc) 479 : Expr(ArraySubscriptExprClass, t), RBracketLoc(rbracketloc) { 480 SubExprs[LHS] = lhs; 481 SubExprs[RHS] = rhs; 482 } 483 484 /// An array access can be written A[4] or 4[A] (both are equivalent). 485 /// - getBase() and getIdx() always present the normalized view: A[4]. 486 /// In this case getBase() returns "A" and getIdx() returns "4". 487 /// - getLHS() and getRHS() present the syntactic view. e.g. for 488 /// 4[A] getLHS() returns "4". 489 490 Expr *getLHS() { return SubExprs[LHS]; } 491 const Expr *getLHS() const { return SubExprs[LHS]; } 492 493 Expr *getRHS() { return SubExprs[RHS]; } 494 const Expr *getRHS() const { return SubExprs[RHS]; } 495 496 Expr *getBase() { 497 return (getLHS()->getType()->isIntegerType()) ? getRHS() : getLHS(); 498 } 499 500 const Expr *getBase() const { 501 return (getLHS()->getType()->isIntegerType()) ? getRHS() : getLHS(); 502 } 503 504 Expr *getIdx() { 505 return (getLHS()->getType()->isIntegerType()) ? getLHS() : getRHS(); 506 } 507 508 const Expr *getIdx() const { 509 return (getLHS()->getType()->isIntegerType()) ? getLHS() : getRHS(); 510 } 511 512 513 SourceRange getSourceRange() const { 514 return SourceRange(getLHS()->getLocStart(), RBracketLoc); 515 } 516 virtual SourceLocation getExprLoc() const { return RBracketLoc; } 517 518 static bool classof(const Stmt *T) { 519 return T->getStmtClass() == ArraySubscriptExprClass; 520 } 521 static bool classof(const ArraySubscriptExpr *) { return true; } 522 523 // Iterators 524 virtual child_iterator child_begin(); 525 virtual child_iterator child_end(); 526 527 virtual void directEmit(llvm::Serializer& S) const; 528 static ArraySubscriptExpr* directMaterialize(llvm::Deserializer& D); 529}; 530 531 532/// CallExpr - [C99 6.5.2.2] Function Calls. 533/// 534class CallExpr : public Expr { 535 enum { FN=0, ARGS_START=1 }; 536 Expr **SubExprs; 537 unsigned NumArgs; 538 SourceLocation RParenLoc; 539 540 // This version of the ctor is for deserialization. 541 CallExpr(Expr** subexprs, unsigned numargs, QualType t, 542 SourceLocation rparenloc) 543 : Expr(CallExprClass,t), SubExprs(subexprs), 544 NumArgs(numargs), RParenLoc(rparenloc) {} 545 546public: 547 CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t, 548 SourceLocation rparenloc); 549 ~CallExpr() { 550 delete [] SubExprs; 551 } 552 553 const Expr *getCallee() const { return SubExprs[FN]; } 554 Expr *getCallee() { return SubExprs[FN]; } 555 556 /// getNumArgs - Return the number of actual arguments to this call. 557 /// 558 unsigned getNumArgs() const { return NumArgs; } 559 560 /// getArg - Return the specified argument. 561 Expr *getArg(unsigned Arg) { 562 assert(Arg < NumArgs && "Arg access out of range!"); 563 return SubExprs[Arg+ARGS_START]; 564 } 565 const Expr *getArg(unsigned Arg) const { 566 assert(Arg < NumArgs && "Arg access out of range!"); 567 return SubExprs[Arg+ARGS_START]; 568 } 569 /// setArg - Set the specified argument. 570 void setArg(unsigned Arg, Expr *ArgExpr) { 571 assert(Arg < NumArgs && "Arg access out of range!"); 572 SubExprs[Arg+ARGS_START] = ArgExpr; 573 } 574 /// getNumCommas - Return the number of commas that must have been present in 575 /// this function call. 576 unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 577 578 bool isBuiltinClassifyType(llvm::APSInt &Result) const; 579 580 SourceRange getSourceRange() const { 581 return SourceRange(getCallee()->getLocStart(), RParenLoc); 582 } 583 584 static bool classof(const Stmt *T) { 585 return T->getStmtClass() == CallExprClass; 586 } 587 static bool classof(const CallExpr *) { return true; } 588 589 // Iterators 590 virtual child_iterator child_begin(); 591 virtual child_iterator child_end(); 592 593 virtual void directEmit(llvm::Serializer& S) const; 594 static CallExpr* directMaterialize(llvm::Deserializer& D); 595}; 596 597/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. 598/// 599class MemberExpr : public Expr { 600 Expr *Base; 601 FieldDecl *MemberDecl; 602 SourceLocation MemberLoc; 603 bool IsArrow; // True if this is "X->F", false if this is "X.F". 604public: 605 MemberExpr(Expr *base, bool isarrow, FieldDecl *memberdecl, SourceLocation l) 606 : Expr(MemberExprClass, memberdecl->getType()), 607 Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {} 608 609 Expr *getBase() const { return Base; } 610 FieldDecl *getMemberDecl() const { return MemberDecl; } 611 bool isArrow() const { return IsArrow; } 612 613 virtual SourceRange getSourceRange() const { 614 return SourceRange(getBase()->getLocStart(), MemberLoc); 615 } 616 virtual SourceLocation getExprLoc() const { return MemberLoc; } 617 618 static bool classof(const Stmt *T) { 619 return T->getStmtClass() == MemberExprClass; 620 } 621 static bool classof(const MemberExpr *) { return true; } 622 623 // Iterators 624 virtual child_iterator child_begin(); 625 virtual child_iterator child_end(); 626}; 627 628/// OCUVectorElementExpr - This represents access to specific elements of a 629/// vector, and may occur on the left hand side or right hand side. For example 630/// the following is legal: "V.xy = V.zw" if V is a 4 element ocu vector. 631/// 632class OCUVectorElementExpr : public Expr { 633 Expr *Base; 634 IdentifierInfo &Accessor; 635 SourceLocation AccessorLoc; 636public: 637 enum ElementType { 638 Point, // xywz 639 Color, // rgba 640 Texture // stpq 641 }; 642 OCUVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 643 SourceLocation loc) 644 : Expr(OCUVectorElementExprClass, ty), 645 Base(base), Accessor(accessor), AccessorLoc(loc) {} 646 647 const Expr *getBase() const { return Base; } 648 Expr *getBase() { return Base; } 649 650 IdentifierInfo &getAccessor() const { return Accessor; } 651 652 /// getNumElements - Get the number of components being selected. 653 unsigned getNumElements() const; 654 655 /// getElementType - Determine whether the components of this access are 656 /// "point" "color" or "texture" elements. 657 ElementType getElementType() const; 658 659 /// containsDuplicateElements - Return true if any element access is 660 /// repeated. 661 bool containsDuplicateElements() const; 662 663 /// getEncodedElementAccess - Encode the elements accessed into a bit vector. 664 /// The encoding currently uses 2-bit bitfields, but clients should use the 665 /// accessors below to access them. 666 /// 667 unsigned getEncodedElementAccess() const; 668 669 /// getAccessedFieldNo - Given an encoded value and a result number, return 670 /// the input field number being accessed. 671 static unsigned getAccessedFieldNo(unsigned Idx, unsigned EncodedVal) { 672 return (EncodedVal >> (Idx*2)) & 3; 673 } 674 675 virtual SourceRange getSourceRange() const { 676 return SourceRange(getBase()->getLocStart(), AccessorLoc); 677 } 678 static bool classof(const Stmt *T) { 679 return T->getStmtClass() == OCUVectorElementExprClass; 680 } 681 static bool classof(const OCUVectorElementExpr *) { return true; } 682 683 // Iterators 684 virtual child_iterator child_begin(); 685 virtual child_iterator child_end(); 686}; 687 688/// CompoundLiteralExpr - [C99 6.5.2.5] 689/// 690class CompoundLiteralExpr : public Expr { 691 Expr *Init; 692public: 693 CompoundLiteralExpr(QualType ty, Expr *init) : 694 Expr(CompoundLiteralExprClass, ty), Init(init) {} 695 696 const Expr *getInitializer() const { return Init; } 697 Expr *getInitializer() { return Init; } 698 699 virtual SourceRange getSourceRange() const { 700 if (Init) 701 return Init->getSourceRange(); 702 return SourceRange(); 703 } 704 705 static bool classof(const Stmt *T) { 706 return T->getStmtClass() == CompoundLiteralExprClass; 707 } 708 static bool classof(const CompoundLiteralExpr *) { return true; } 709 710 // Iterators 711 virtual child_iterator child_begin(); 712 virtual child_iterator child_end(); 713}; 714 715/// ImplicitCastExpr - Allows us to explicitly represent implicit type 716/// conversions. For example: converting T[]->T*, void f()->void (*f)(), 717/// float->double, short->int, etc. 718/// 719class ImplicitCastExpr : public Expr { 720 Expr *Op; 721public: 722 ImplicitCastExpr(QualType ty, Expr *op) : 723 Expr(ImplicitCastExprClass, ty), Op(op) {} 724 725 Expr *getSubExpr() { return Op; } 726 const Expr *getSubExpr() const { return Op; } 727 728 virtual SourceRange getSourceRange() const { return Op->getSourceRange(); } 729 730 static bool classof(const Stmt *T) { 731 return T->getStmtClass() == ImplicitCastExprClass; 732 } 733 static bool classof(const ImplicitCastExpr *) { return true; } 734 735 // Iterators 736 virtual child_iterator child_begin(); 737 virtual child_iterator child_end(); 738 739 virtual void directEmit(llvm::Serializer& S) const; 740 static ImplicitCastExpr* directMaterialize(llvm::Deserializer& D); 741}; 742 743/// CastExpr - [C99 6.5.4] Cast Operators. 744/// 745class CastExpr : public Expr { 746 Expr *Op; 747 SourceLocation Loc; // the location of the left paren 748public: 749 CastExpr(QualType ty, Expr *op, SourceLocation l) : 750 Expr(CastExprClass, ty), Op(op), Loc(l) {} 751 752 SourceLocation getLParenLoc() const { return Loc; } 753 754 Expr *getSubExpr() const { return Op; } 755 756 virtual SourceRange getSourceRange() const { 757 return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); 758 } 759 static bool classof(const Stmt *T) { 760 return T->getStmtClass() == CastExprClass; 761 } 762 static bool classof(const CastExpr *) { return true; } 763 764 // Iterators 765 virtual child_iterator child_begin(); 766 virtual child_iterator child_end(); 767 768 virtual void directEmit(llvm::Serializer& S) const; 769 static CastExpr* directMaterialize(llvm::Deserializer& D); 770}; 771 772class BinaryOperator : public Expr { 773public: 774 enum Opcode { 775 // Operators listed in order of precedence. 776 // Note that additions to this should also update the StmtVisitor class. 777 Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators. 778 Add, Sub, // [C99 6.5.6] Additive operators. 779 Shl, Shr, // [C99 6.5.7] Bitwise shift operators. 780 LT, GT, LE, GE, // [C99 6.5.8] Relational operators. 781 EQ, NE, // [C99 6.5.9] Equality operators. 782 And, // [C99 6.5.10] Bitwise AND operator. 783 Xor, // [C99 6.5.11] Bitwise XOR operator. 784 Or, // [C99 6.5.12] Bitwise OR operator. 785 LAnd, // [C99 6.5.13] Logical AND operator. 786 LOr, // [C99 6.5.14] Logical OR operator. 787 Assign, MulAssign,// [C99 6.5.16] Assignment operators. 788 DivAssign, RemAssign, 789 AddAssign, SubAssign, 790 ShlAssign, ShrAssign, 791 AndAssign, XorAssign, 792 OrAssign, 793 Comma // [C99 6.5.17] Comma operator. 794 }; 795private: 796 enum { LHS, RHS, END_EXPR }; 797 Expr* SubExprs[END_EXPR]; 798 Opcode Opc; 799 SourceLocation OpLoc; 800public: 801 802 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 803 SourceLocation opLoc) 804 : Expr(BinaryOperatorClass, ResTy), Opc(opc), OpLoc(opLoc) { 805 SubExprs[LHS] = lhs; 806 SubExprs[RHS] = rhs; 807 assert(!isCompoundAssignmentOp() && 808 "Use ArithAssignBinaryOperator for compound assignments"); 809 } 810 811 SourceLocation getOperatorLoc() const { return OpLoc; } 812 Opcode getOpcode() const { return Opc; } 813 Expr *getLHS() const { return SubExprs[LHS]; } 814 Expr *getRHS() const { return SubExprs[RHS]; } 815 virtual SourceRange getSourceRange() const { 816 return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 817 } 818 819 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 820 /// corresponds to, e.g. "<<=". 821 static const char *getOpcodeStr(Opcode Op); 822 823 /// predicates to categorize the respective opcodes. 824 bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 825 bool isAdditiveOp() const { return Opc == Add || Opc == Sub; } 826 bool isShiftOp() const { return Opc == Shl || Opc == Shr; } 827 bool isBitwiseOp() const { return Opc >= And && Opc <= Or; } 828 bool isRelationalOp() const { return Opc >= LT && Opc <= GE; } 829 bool isEqualityOp() const { return Opc == EQ || Opc == NE; } 830 bool isLogicalOp() const { return Opc == LAnd || Opc == LOr; } 831 bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 832 bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 833 bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 834 835 static bool classof(const Stmt *S) { 836 return S->getStmtClass() == BinaryOperatorClass || 837 S->getStmtClass() == CompoundAssignOperatorClass; 838 } 839 static bool classof(const BinaryOperator *) { return true; } 840 841 // Iterators 842 virtual child_iterator child_begin(); 843 virtual child_iterator child_end(); 844 845 virtual void directEmit(llvm::Serializer& S) const; 846 static BinaryOperator* directMaterialize(llvm::Deserializer& D); 847 848protected: 849 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 850 SourceLocation oploc, bool dead) 851 : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) { 852 SubExprs[LHS] = lhs; 853 SubExprs[RHS] = rhs; 854 } 855}; 856 857/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 858/// track of the type the operation is performed in. Due to the semantics of 859/// these operators, the operands are promoted, the aritmetic performed, an 860/// implicit conversion back to the result type done, then the assignment takes 861/// place. This captures the intermediate type which the computation is done 862/// in. 863class CompoundAssignOperator : public BinaryOperator { 864 QualType ComputationType; 865public: 866 CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 867 QualType ResType, QualType CompType, 868 SourceLocation OpLoc) 869 : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 870 ComputationType(CompType) { 871 assert(isCompoundAssignmentOp() && 872 "Only should be used for compound assignments"); 873 } 874 875 QualType getComputationType() const { return ComputationType; } 876 877 static bool classof(const CompoundAssignOperator *) { return true; } 878 static bool classof(const Stmt *S) { 879 return S->getStmtClass() == CompoundAssignOperatorClass; 880 } 881 882 virtual void directEmit(llvm::Serializer& S) const; 883 static CompoundAssignOperator* directMaterialize(llvm::Deserializer& D); 884}; 885 886/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 887/// GNU "missing LHS" extension is in use. 888/// 889class ConditionalOperator : public Expr { 890 enum { COND, LHS, RHS, END_EXPR }; 891 Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 892public: 893 ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t) 894 : Expr(ConditionalOperatorClass, t) { 895 SubExprs[COND] = cond; 896 SubExprs[LHS] = lhs; 897 SubExprs[RHS] = rhs; 898 } 899 900 Expr *getCond() const { return SubExprs[COND]; } 901 Expr *getLHS() const { return SubExprs[LHS]; } 902 Expr *getRHS() const { return SubExprs[RHS]; } 903 904 virtual SourceRange getSourceRange() const { 905 return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 906 } 907 static bool classof(const Stmt *T) { 908 return T->getStmtClass() == ConditionalOperatorClass; 909 } 910 static bool classof(const ConditionalOperator *) { return true; } 911 912 // Iterators 913 virtual child_iterator child_begin(); 914 virtual child_iterator child_end(); 915}; 916 917/// AddrLabelExpr - The GNU address of label extension, representing &&label. 918class AddrLabelExpr : public Expr { 919 SourceLocation AmpAmpLoc, LabelLoc; 920 LabelStmt *Label; 921public: 922 AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 923 QualType t) 924 : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 925 926 virtual SourceRange getSourceRange() const { 927 return SourceRange(AmpAmpLoc, LabelLoc); 928 } 929 930 LabelStmt *getLabel() const { return Label; } 931 932 static bool classof(const Stmt *T) { 933 return T->getStmtClass() == AddrLabelExprClass; 934 } 935 static bool classof(const AddrLabelExpr *) { return true; } 936 937 // Iterators 938 virtual child_iterator child_begin(); 939 virtual child_iterator child_end(); 940}; 941 942/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 943/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 944/// takes the value of the last subexpression. 945class StmtExpr : public Expr { 946 CompoundStmt *SubStmt; 947 SourceLocation LParenLoc, RParenLoc; 948public: 949 StmtExpr(CompoundStmt *substmt, QualType T, 950 SourceLocation lp, SourceLocation rp) : 951 Expr(StmtExprClass, T), SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 952 953 CompoundStmt *getSubStmt() { return SubStmt; } 954 const CompoundStmt *getSubStmt() const { return SubStmt; } 955 956 virtual SourceRange getSourceRange() const { 957 return SourceRange(LParenLoc, RParenLoc); 958 } 959 960 static bool classof(const Stmt *T) { 961 return T->getStmtClass() == StmtExprClass; 962 } 963 static bool classof(const StmtExpr *) { return true; } 964 965 // Iterators 966 virtual child_iterator child_begin(); 967 virtual child_iterator child_end(); 968}; 969 970/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p. 971/// This AST node represents a function that returns 1 if two *types* (not 972/// expressions) are compatible. The result of this built-in function can be 973/// used in integer constant expressions. 974class TypesCompatibleExpr : public Expr { 975 QualType Type1; 976 QualType Type2; 977 SourceLocation BuiltinLoc, RParenLoc; 978public: 979 TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 980 QualType t1, QualType t2, SourceLocation RP) : 981 Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2), 982 BuiltinLoc(BLoc), RParenLoc(RP) {} 983 984 QualType getArgType1() const { return Type1; } 985 QualType getArgType2() const { return Type2; } 986 987 virtual SourceRange getSourceRange() const { 988 return SourceRange(BuiltinLoc, RParenLoc); 989 } 990 static bool classof(const Stmt *T) { 991 return T->getStmtClass() == TypesCompatibleExprClass; 992 } 993 static bool classof(const TypesCompatibleExpr *) { return true; } 994 995 // Iterators 996 virtual child_iterator child_begin(); 997 virtual child_iterator child_end(); 998}; 999 1000/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 1001/// This AST node is similar to the conditional operator (?:) in C, with 1002/// the following exceptions: 1003/// - the test expression much be a constant expression. 1004/// - the expression returned has it's type unaltered by promotion rules. 1005/// - does not evaluate the expression that was not chosen. 1006class ChooseExpr : public Expr { 1007 enum { COND, LHS, RHS, END_EXPR }; 1008 Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 1009 SourceLocation BuiltinLoc, RParenLoc; 1010public: 1011 ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 1012 SourceLocation RP) 1013 : Expr(ChooseExprClass, t), 1014 BuiltinLoc(BLoc), RParenLoc(RP) { 1015 SubExprs[COND] = cond; 1016 SubExprs[LHS] = lhs; 1017 SubExprs[RHS] = rhs; 1018 } 1019 1020 /// isConditionTrue - Return true if the condition is true. This is always 1021 /// statically knowable for a well-formed choosexpr. 1022 bool isConditionTrue(ASTContext &C) const; 1023 1024 Expr *getCond() const { return SubExprs[COND]; } 1025 Expr *getLHS() const { return SubExprs[LHS]; } 1026 Expr *getRHS() const { return SubExprs[RHS]; } 1027 1028 virtual SourceRange getSourceRange() const { 1029 return SourceRange(BuiltinLoc, RParenLoc); 1030 } 1031 static bool classof(const Stmt *T) { 1032 return T->getStmtClass() == ChooseExprClass; 1033 } 1034 static bool classof(const ChooseExpr *) { return true; } 1035 1036 // Iterators 1037 virtual child_iterator child_begin(); 1038 virtual child_iterator child_end(); 1039}; 1040 1041/// VAArgExpr, used for the builtin function __builtin_va_start. 1042class VAArgExpr : public Expr { 1043 Expr *Val; 1044 SourceLocation BuiltinLoc, RParenLoc; 1045public: 1046 VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc) 1047 : Expr(VAArgExprClass, t), 1048 Val(e), 1049 BuiltinLoc(BLoc), 1050 RParenLoc(RPLoc) { } 1051 1052 const Expr *getSubExpr() const { return Val; } 1053 Expr *getSubExpr() { return Val; } 1054 virtual SourceRange getSourceRange() const { 1055 return SourceRange(BuiltinLoc, RParenLoc); 1056 } 1057 static bool classof(const Stmt *T) { 1058 return T->getStmtClass() == VAArgExprClass; 1059 } 1060 static bool classof(const VAArgExpr *) { return true; } 1061 1062 // Iterators 1063 virtual child_iterator child_begin(); 1064 virtual child_iterator child_end(); 1065}; 1066 1067/// InitListExpr, used for struct and array initializers. 1068class InitListExpr : public Expr { 1069 Expr **InitExprs; 1070 unsigned NumInits; 1071 SourceLocation LBraceLoc, RBraceLoc; 1072public: 1073 InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits, 1074 SourceLocation rbraceloc); 1075 ~InitListExpr() { 1076 delete [] InitExprs; 1077 } 1078 1079 unsigned getNumInits() const { return NumInits; } 1080 1081 const Expr* getInit(unsigned Init) const { 1082 assert(Init < NumInits && "Initializer access out of range!"); 1083 return InitExprs[Init]; 1084 } 1085 1086 Expr* getInit(unsigned Init) { 1087 assert(Init < NumInits && "Initializer access out of range!"); 1088 return InitExprs[Init]; 1089 } 1090 1091 void setInit(unsigned Init, Expr *expr) { 1092 assert(Init < NumInits && "Initializer access out of range!"); 1093 InitExprs[Init] = expr; 1094 } 1095 1096 virtual SourceRange getSourceRange() const { 1097 return SourceRange(LBraceLoc, RBraceLoc); 1098 } 1099 static bool classof(const Stmt *T) { 1100 return T->getStmtClass() == InitListExprClass; 1101 } 1102 static bool classof(const InitListExpr *) { return true; } 1103 1104 // Iterators 1105 virtual child_iterator child_begin(); 1106 virtual child_iterator child_end(); 1107}; 1108 1109/// ObjCStringLiteral, used for Objective-C string literals 1110/// i.e. @"foo". 1111class ObjCStringLiteral : public Expr { 1112 StringLiteral *String; 1113 SourceLocation AtLoc; 1114public: 1115 ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L) 1116 : Expr(ObjCStringLiteralClass, T), String(SL), AtLoc(L) {} 1117 1118 StringLiteral* getString() { return String; } 1119 1120 const StringLiteral* getString() const { return String; } 1121 1122 virtual SourceRange getSourceRange() const { 1123 return SourceRange(AtLoc, String->getLocEnd()); 1124 } 1125 1126 static bool classof(const Stmt *T) { 1127 return T->getStmtClass() == ObjCStringLiteralClass; 1128 } 1129 static bool classof(const ObjCStringLiteral *) { return true; } 1130 1131 // Iterators 1132 virtual child_iterator child_begin(); 1133 virtual child_iterator child_end(); 1134}; 1135 1136/// ObjCEncodeExpr, used for @encode in Objective-C. 1137class ObjCEncodeExpr : public Expr { 1138 QualType EncType; 1139 SourceLocation AtLoc, RParenLoc; 1140public: 1141 ObjCEncodeExpr(QualType T, QualType ET, 1142 SourceLocation at, SourceLocation rp) 1143 : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {} 1144 1145 SourceLocation getAtLoc() const { return AtLoc; } 1146 SourceLocation getRParenLoc() const { return RParenLoc; } 1147 1148 SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); } 1149 1150 QualType getEncodedType() const { return EncType; } 1151 1152 static bool classof(const Stmt *T) { 1153 return T->getStmtClass() == ObjCEncodeExprClass; 1154 } 1155 static bool classof(const ObjCEncodeExpr *) { return true; } 1156 1157 // Iterators 1158 virtual child_iterator child_begin(); 1159 virtual child_iterator child_end(); 1160}; 1161 1162/// ObjCSelectorExpr used for @selector in Objective-C. 1163class ObjCSelectorExpr : public Expr { 1164 1165 Selector SelName; 1166 1167 SourceLocation AtLoc, RParenLoc; 1168public: 1169 ObjCSelectorExpr(QualType T, Selector selInfo, 1170 SourceLocation at, SourceLocation rp) 1171 : Expr(ObjCSelectorExprClass, T), SelName(selInfo), 1172 AtLoc(at), RParenLoc(rp) {} 1173 1174 const Selector &getSelector() const { return SelName; } 1175 Selector &getSelector() { return SelName; } 1176 1177 SourceLocation getAtLoc() const { return AtLoc; } 1178 SourceLocation getRParenLoc() const { return RParenLoc; } 1179 SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); } 1180 1181 /// getNumArgs - Return the number of actual arguments to this call. 1182 unsigned getNumArgs() const { return SelName.getNumArgs(); } 1183 1184 static bool classof(const Stmt *T) { 1185 return T->getStmtClass() == ObjCSelectorExprClass; 1186 } 1187 static bool classof(const ObjCSelectorExpr *) { return true; } 1188 1189 // Iterators 1190 virtual child_iterator child_begin(); 1191 virtual child_iterator child_end(); 1192 1193}; 1194 1195/// ObjCProtocolExpr used for protocol in Objective-C. 1196class ObjCProtocolExpr : public Expr { 1197 1198 ObjcProtocolDecl *Protocol; 1199 1200 SourceLocation AtLoc, RParenLoc; 1201 public: 1202 ObjCProtocolExpr(QualType T, ObjcProtocolDecl *protocol, 1203 SourceLocation at, SourceLocation rp) 1204 : Expr(ObjCProtocolExprClass, T), Protocol(protocol), 1205 AtLoc(at), RParenLoc(rp) {} 1206 1207 ObjcProtocolDecl *getProtocol() const { return Protocol; } 1208 1209 SourceLocation getAtLoc() const { return AtLoc; } 1210 SourceLocation getRParenLoc() const { return RParenLoc; } 1211 SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); } 1212 1213 static bool classof(const Stmt *T) { 1214 return T->getStmtClass() == ObjCProtocolExprClass; 1215 } 1216 static bool classof(const ObjCProtocolExpr *) { return true; } 1217 1218 // Iterators 1219 virtual child_iterator child_begin(); 1220 virtual child_iterator child_end(); 1221 1222}; 1223 1224class ObjCMessageExpr : public Expr { 1225 enum { RECEIVER=0, ARGS_START=1 }; 1226 1227 Expr **SubExprs; 1228 1229 // A unigue name for this message. 1230 Selector SelName; 1231 1232 // A method prototype for this message (optional). 1233 // FIXME: Since method decls contain the selector, and most messages have a 1234 // prototype, consider devising a scheme for unifying SelName/MethodProto. 1235 ObjcMethodDecl *MethodProto; 1236 1237 IdentifierInfo *ClassName; // optional - 0 for instance messages. 1238 1239 SourceLocation LBracloc, RBracloc; 1240public: 1241 // constructor for class messages. 1242 // FIXME: clsName should be typed to ObjCInterfaceType 1243 ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo, 1244 QualType retType, ObjcMethodDecl *methDecl, 1245 SourceLocation LBrac, SourceLocation RBrac, 1246 Expr **ArgExprs); 1247 // constructor for instance messages. 1248 ObjCMessageExpr(Expr *receiver, Selector selInfo, 1249 QualType retType, ObjcMethodDecl *methDecl, 1250 SourceLocation LBrac, SourceLocation RBrac, 1251 Expr **ArgExprs); 1252 ~ObjCMessageExpr() { 1253 delete [] SubExprs; 1254 } 1255 1256 const Expr *getReceiver() const { return SubExprs[RECEIVER]; } 1257 Expr *getReceiver() { return SubExprs[RECEIVER]; } 1258 1259 const Selector &getSelector() const { return SelName; } 1260 Selector &getSelector() { return SelName; } 1261 1262 const ObjcMethodDecl *getMethodDecl() const { return MethodProto; } 1263 ObjcMethodDecl *getMethodDecl() { return MethodProto; } 1264 1265 const IdentifierInfo *getClassName() const { return ClassName; } 1266 IdentifierInfo *getClassName() { return ClassName; } 1267 1268 /// getNumArgs - Return the number of actual arguments to this call. 1269 unsigned getNumArgs() const { return SelName.getNumArgs(); } 1270 1271/// getArg - Return the specified argument. 1272 Expr *getArg(unsigned Arg) { 1273 assert(Arg < SelName.getNumArgs() && "Arg access out of range!"); 1274 return SubExprs[Arg+ARGS_START]; 1275 } 1276 const Expr *getArg(unsigned Arg) const { 1277 assert(Arg < SelName.getNumArgs() && "Arg access out of range!"); 1278 return SubExprs[Arg+ARGS_START]; 1279 } 1280 /// setArg - Set the specified argument. 1281 void setArg(unsigned Arg, Expr *ArgExpr) { 1282 assert(Arg < SelName.getNumArgs() && "Arg access out of range!"); 1283 SubExprs[Arg+ARGS_START] = ArgExpr; 1284 } 1285 SourceRange getSourceRange() const { return SourceRange(LBracloc, RBracloc); } 1286 1287 static bool classof(const Stmt *T) { 1288 return T->getStmtClass() == ObjCMessageExprClass; 1289 } 1290 static bool classof(const ObjCMessageExpr *) { return true; } 1291 1292 // Iterators 1293 virtual child_iterator child_begin(); 1294 virtual child_iterator child_end(); 1295}; 1296 1297} // end namespace clang 1298 1299#endif 1300