diff options
Diffstat (limited to 'include/clang/AST/ExprCXX.h')
-rw-r--r-- | include/clang/AST/ExprCXX.h | 206 |
1 files changed, 192 insertions, 14 deletions
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 6ef837a2fc..05574c2312 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1,9 +1,8 @@ //===- ExprCXX.h - Classes for representing expressions ---------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -588,6 +587,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// The null pointer literal (C++11 [lex.nullptr]) @@ -617,6 +620,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Implicit construction of a std::initializer_list<T> object from an @@ -659,6 +666,10 @@ public: } child_range children() { return child_range(&SubExpr, &SubExpr + 1); } + + const_child_range children() const { + return const_child_range(&SubExpr, &SubExpr + 1); + } }; /// A C++ \c typeid expression (C++ [expr.typeid]), which gets @@ -749,6 +760,15 @@ public: auto **begin = reinterpret_cast<Stmt **>(&Operand); return child_range(begin, begin + 1); } + + const_child_range children() const { + if (isTypeOperand()) + return const_child_range(const_child_iterator(), const_child_iterator()); + + auto **begin = + reinterpret_cast<Stmt **>(&const_cast<CXXTypeidExpr *>(this)->Operand); + return const_child_range(begin, begin + 1); + } }; /// A member reference to an MSPropertyDecl. @@ -803,6 +823,11 @@ public: return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1); } + const_child_range children() const { + auto Children = const_cast<MSPropertyRefExpr *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == MSPropertyRefExprClass; } @@ -878,6 +903,10 @@ public: child_range children() { return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); } + + const_child_range children() const { + return const_child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); + } }; /// A Microsoft C++ @c __uuidof expression, which gets @@ -959,6 +988,14 @@ public: auto **begin = reinterpret_cast<Stmt **>(&Operand); return child_range(begin, begin + 1); } + + const_child_range children() const { + if (isTypeOperand()) + return const_child_range(const_child_iterator(), const_child_iterator()); + auto **begin = + reinterpret_cast<Stmt **>(&const_cast<CXXUuidofExpr *>(this)->Operand); + return const_child_range(begin, begin + 1); + } }; /// Represents the \c this expression in C++. @@ -1005,6 +1042,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// A C++ throw-expression (C++ [except.throw]). @@ -1063,6 +1104,10 @@ public: child_range children() { return child_range(&Operand, Operand ? &Operand + 1 : &Operand); } + + const_child_range children() const { + return const_child_range(&Operand, Operand ? &Operand + 1 : &Operand); + } }; /// A default argument (C++ [dcl.fct.default]). @@ -1124,6 +1169,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// A use of a default initializer in a constructor or in aggregate @@ -1179,6 +1228,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents a C++ temporary. @@ -1256,6 +1309,10 @@ public: // Iterators child_range children() { return child_range(&SubExpr, &SubExpr + 1); } + + const_child_range children() const { + return const_child_range(&SubExpr, &SubExpr + 1); + } }; /// Represents a call to a C++ constructor. @@ -1439,6 +1496,11 @@ public: child_range children() { return child_range(getTrailingArgs(), getTrailingArgs() + getNumArgs()); } + + const_child_range children() const { + auto Children = const_cast<CXXConstructExpr *>(this)->children(); + return const_child_range(Children.begin(), Children.end()); + } }; /// Represents a call to an inherited base class constructor from an @@ -1507,6 +1569,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents an explicit C++ type conversion that uses "functional" @@ -1833,6 +1899,10 @@ public: /// parameter list associated with it, or else return null. TemplateParameterList *getTemplateParameterList() const; + /// Get the template parameters were explicitly specified (as opposed to being + /// invented by use of an auto parameter). + ArrayRef<NamedDecl *> getExplicitTemplateParameters() const; + /// Whether this is a generic lambda. bool isGenericLambda() const { return getTemplateParameterList(); } @@ -1864,6 +1934,11 @@ public: // Includes initialization exprs plus body stmt return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); } + + const_child_range children() const { + return const_child_range(getStoredStmts(), + getStoredStmts() + NumCaptures + 1); + } }; /// An expression "T()" which creates a value-initialized rvalue of type @@ -1907,6 +1982,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents a new-expression for memory allocation and constructor @@ -1979,7 +2058,7 @@ private: CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, - SourceRange TypeIdParens, Expr *ArraySize, + SourceRange TypeIdParens, Optional<Expr *> ArraySize, InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -1994,7 +2073,7 @@ public: Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, - SourceRange TypeIdParens, Expr *ArraySize, + SourceRange TypeIdParens, Optional<Expr *> ArraySize, InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2037,15 +2116,15 @@ public: bool isArray() const { return CXXNewExprBits.IsArray; } - Expr *getArraySize() { - return isArray() - ? cast<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]) - : nullptr; + Optional<Expr *> getArraySize() { + if (!isArray()) + return None; + return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]); } - const Expr *getArraySize() const { - return isArray() - ? cast<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]) - : nullptr; + Optional<const Expr *> getArraySize() const { + if (!isArray()) + return None; + return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]); } unsigned getNumPlacementArgs() const { @@ -2163,6 +2242,10 @@ public: // Iterators child_range children() { return child_range(raw_arg_begin(), raw_arg_end()); } + + const_child_range children() const { + return const_child_range(const_cast<CXXNewExpr *>(this)->children()); + } }; /// Represents a \c delete expression for memory deallocation and @@ -2229,6 +2312,10 @@ public: // Iterators child_range children() { return child_range(&Argument, &Argument + 1); } + + const_child_range children() const { + return const_child_range(&Argument, &Argument + 1); + } }; /// Stores the type being destroyed by a pseudo-destructor expression. @@ -2417,6 +2504,10 @@ public: // Iterators child_range children() { return child_range(&Base, &Base + 1); } + + const_child_range children() const { + return const_child_range(&Base, &Base + 1); + } }; /// A type trait used in the implementation of various C++11 and @@ -2501,6 +2592,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// An Embarcadero array type trait, as used in the implementation of @@ -2568,6 +2663,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// An expression trait intrinsic. @@ -2628,6 +2727,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// A reference to an overloaded function set, either an @@ -2920,6 +3023,10 @@ public: return child_range(child_iterator(), child_iterator()); } + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == UnresolvedLookupExprClass; } @@ -3074,6 +3181,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents an expression -- generally a full-expression -- that @@ -3143,6 +3254,10 @@ public: // Iterators child_range children() { return child_range(&SubExpr, &SubExpr + 1); } + + const_child_range children() const { + return const_child_range(&SubExpr, &SubExpr + 1); + } }; /// Describes an explicit type conversion that uses functional @@ -3272,6 +3387,12 @@ public: auto **begin = reinterpret_cast<Stmt **>(arg_begin()); return child_range(begin, begin + arg_size()); } + + const_child_range children() const { + auto **begin = reinterpret_cast<Stmt **>( + const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin()); + return const_child_range(begin, begin + arg_size()); + } }; /// Represents a C++ member access expression where the actual @@ -3518,6 +3639,12 @@ public: return child_range(child_iterator(), child_iterator()); return child_range(&Base, &Base + 1); } + + const_child_range children() const { + if (isImplicitAccess()) + return const_child_range(const_child_iterator(), const_child_iterator()); + return const_child_range(&Base, &Base + 1); + } }; /// Represents a C++ member access expression for which lookup @@ -3681,6 +3808,12 @@ public: return child_range(child_iterator(), child_iterator()); return child_range(&Base, &Base + 1); } + + const_child_range children() const { + if (isImplicitAccess()) + return const_child_range(const_child_iterator(), const_child_iterator()); + return const_child_range(&Base, &Base + 1); + } }; DeclAccessPair *OverloadExpr::getTrailingResults() { @@ -3750,6 +3883,10 @@ public: // Iterators child_range children() { return child_range(&Operand, &Operand + 1); } + + const_child_range children() const { + return const_child_range(&Operand, &Operand + 1); + } }; /// Represents a C++11 pack expansion that produces a sequence of @@ -3830,6 +3967,10 @@ public: child_range children() { return child_range(&Pattern, &Pattern + 1); } + + const_child_range children() const { + return const_child_range(&Pattern, &Pattern + 1); + } }; /// Represents an expression that computes the length of a parameter @@ -3951,6 +4092,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents a reference to a non-type template parameter @@ -3997,6 +4142,10 @@ public: // Iterators child_range children() { return child_range(&Replacement, &Replacement + 1); } + + const_child_range children() const { + return const_child_range(&Replacement, &Replacement + 1); + } }; /// Represents a reference to a non-type template parameter pack that @@ -4059,6 +4208,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents a reference to a function parameter pack that has been @@ -4131,6 +4284,10 @@ public: child_range children() { return child_range(child_iterator(), child_iterator()); } + + const_child_range children() const { + return const_child_range(const_child_iterator(), const_child_iterator()); + } }; /// Represents a prvalue temporary that is written into memory so that @@ -4253,6 +4410,15 @@ public: auto ES = State.get<ExtraState *>(); return child_range(&ES->Temporary, &ES->Temporary + 1); } + + const_child_range children() const { + if (State.is<Stmt *>()) + return const_child_range(State.getAddrOfPtr1(), + State.getAddrOfPtr1() + 1); + + auto ES = State.get<ExtraState *>(); + return const_child_range(&ES->Temporary, &ES->Temporary + 1); + } }; /// Represents a folding of a pack over an operator. @@ -4318,6 +4484,10 @@ public: // Iterators child_range children() { return child_range(SubExprs, SubExprs + 2); } + + const_child_range children() const { + return const_child_range(SubExprs, SubExprs + 2); + } }; /// Represents an expression that might suspend coroutine execution; @@ -4409,6 +4579,10 @@ public: return child_range(SubExprs, SubExprs + SubExpr::Count); } + const_child_range children() const { + return const_child_range(SubExprs, SubExprs + SubExpr::Count); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == CoawaitExprClass || T->getStmtClass() == CoyieldExprClass; @@ -4493,6 +4667,10 @@ public: child_range children() { return child_range(SubExprs, SubExprs + 2); } + const_child_range children() const { + return const_child_range(SubExprs, SubExprs + 2); + } + static bool classof(const Stmt *T) { return T->getStmtClass() == DependentCoawaitExprClass; } |