Vendor import of stripped clang trunk r366426 (just before the

release_90 branch point):

https://llvm.org/svn/llvm-project/cfe/trunk@366426
This commit is contained in:
dim 2019-08-20 20:50:49 +00:00
parent c37ebd9d97
commit 5481597553
1530 changed files with 83363 additions and 36619 deletions

View File

@ -1,5 +1,240 @@
==============================================================================
LLVM Release License
The LLVM Project is under the Apache License v2.0 with LLVM Exceptions:
==============================================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
---- LLVM Exceptions to the Apache 2.0 License ----
As an exception, if, as a result of your compiling your source code, portions
of this Software are embedded into an Object form of such source code, you
may redistribute such embedded portions in such Object form without complying
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
In addition, if you combine or link compiled forms of this Software with
software that is licensed under the GPLv2 ("Combined Software") and if a
court of competent jurisdiction determines that the patent provision (Section
3), the indemnity provision (Section 9) or other Section of the License
conflicts with the conditions of the GPLv2, you may retroactively and
prospectively choose to deem waived or otherwise exclude such Section(s) of
the License, but only in their entirety and only with respect to the Combined
Software.
==============================================================================
Software from third parties included in the LLVM Project:
==============================================================================
The LLVM Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
==============================================================================
Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy):
==============================================================================
University of Illinois/NCSA
Open Source License
@ -41,23 +276,3 @@ CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
SOFTWARE.
==============================================================================
The LLVM software contains code written by third parties. Such software will
have its own individual LICENSE.TXT file in the directory in which it appears.
This file will describe the copyrights, license, and restrictions which apply
to that code.
The disclaimer of warranty in the University of Illinois Open Source License
applies to all code in the LLVM Distribution, and nothing in any of the
other licenses gives permission to use the names of the LLVM Team or the
University of Illinois to endorse or promote products derived from this
Software.
The following pieces of software have additional or alternate copyrights,
licenses, and/or restrictions:
Program Directory
------- ---------
<none yet>

View File

@ -1,9 +1,9 @@
/*==-- clang-c/BuildSystem.h - Utilities for use by build systems -*- 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 *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|

View File

@ -1,9 +1,9 @@
/*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- 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 *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|

View File

@ -1,9 +1,9 @@
/*===-- clang-c/CXErrorCode.h - C Index Error Codes --------------*- 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 *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|

View File

@ -1,9 +1,9 @@
/*===-- clang-c/CXString.h - C Index strings --------------------*- 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 *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|

View File

@ -1,9 +1,9 @@
/*==-- clang-c/Documentation.h - Utilities for comment processing -*- 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 *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|

View File

@ -1,9 +1,9 @@
/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- 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 *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
@ -32,7 +32,7 @@
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
*/
#define CINDEX_VERSION_MAJOR 0
#define CINDEX_VERSION_MINOR 50
#define CINDEX_VERSION_MINOR 59
#define CINDEX_VERSION_ENCODE(major, minor) ( \
((major) * 10000) \
@ -221,7 +221,12 @@ enum CXCursor_ExceptionSpecificationKind {
/**
* The exception specification has not been parsed yet.
*/
CXCursor_ExceptionSpecificationKind_Unparsed
CXCursor_ExceptionSpecificationKind_Unparsed,
/**
* The cursor has a __declspec(nothrow) exception specification.
*/
CXCursor_ExceptionSpecificationKind_NoThrow
};
/**
@ -1341,7 +1346,17 @@ enum CXTranslationUnit_Flags {
/**
* Used to indicate that implicit attributes should be visited.
*/
CXTranslationUnit_VisitImplicitAttributes = 0x2000
CXTranslationUnit_VisitImplicitAttributes = 0x2000,
/**
* Used to indicate that non-errors from included files should be ignored.
*
* If set, clang_getDiagnosticSetFromTU() will not report e.g. warnings from
* included files anymore. This speeds up clang_getDiagnosticSetFromTU() for
* the case where these warnings are not of interest, as for an IDE for
* example, which typically shows only the diagnostics in the main file.
*/
CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles = 0x4000
};
/**
@ -2531,7 +2546,11 @@ enum CXCursorKind {
*/
CXCursor_OMPTargetTeamsDistributeSimdDirective = 279,
CXCursor_LastStmt = CXCursor_OMPTargetTeamsDistributeSimdDirective,
/** C++2a std::bit_cast expression.
*/
CXCursor_BuiltinBitCastExpr = 280,
CXCursor_LastStmt = CXCursor_BuiltinBitCastExpr,
/**
* Cursor that represents the translation unit itself.
@ -2586,7 +2605,11 @@ enum CXCursorKind {
CXCursor_ObjCRuntimeVisible = 435,
CXCursor_ObjCBoxable = 436,
CXCursor_FlagEnum = 437,
CXCursor_LastAttr = CXCursor_FlagEnum,
CXCursor_ConvergentAttr = 438,
CXCursor_WarnUnusedAttr = 439,
CXCursor_WarnUnusedResultAttr = 440,
CXCursor_AlignedAttr = 441,
CXCursor_LastAttr = CXCursor_AlignedAttr,
/* Preprocessing */
CXCursor_PreprocessingDirective = 500,
@ -3311,7 +3334,9 @@ enum CXTypeKind {
CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout = 173,
CXType_OCLIntelSubgroupAVCImeSingleRefStreamin = 174,
CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175
CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175,
CXType_ExtVector = 176
};
/**
@ -3838,7 +3863,11 @@ enum CXTypeLayoutError {
/**
* The Field name is not valid for this record.
*/
CXTypeLayoutError_InvalidFieldName = -5
CXTypeLayoutError_InvalidFieldName = -5,
/**
* The type is undeduced.
*/
CXTypeLayoutError_Undeduced = -6
};
/**
@ -3910,11 +3939,23 @@ CINDEX_LINKAGE CXType clang_Type_getModifiedType(CXType T);
*/
CINDEX_LINKAGE long long clang_Cursor_getOffsetOfField(CXCursor C);
/**
* Determine whether the given cursor represents an anonymous
* tag or namespace
*/
CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
/**
* Determine whether the given cursor represents an anonymous record
* declaration.
*/
CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
CINDEX_LINKAGE unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C);
/**
* Determine whether the given cursor represents an inline namespace
* declaration.
*/
CINDEX_LINKAGE unsigned clang_Cursor_isInlineNamespace(CXCursor C);
enum CXRefQualifierKind {
/** No ref-qualifier was provided. */

View File

@ -1,9 +1,9 @@
/*===-- clang-c/Platform.h - C Index platform decls -------------*- 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 *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|

View File

@ -1,9 +1,8 @@
//===-- ARCMT.h - ARC Migration Rewriter ------------------------*- 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
//
//===----------------------------------------------------------------------===//

View File

@ -1,9 +1,8 @@
//===--- ARCMTActions.h - ARC Migrate Tool Frontend Actions -----*- 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
//
//===----------------------------------------------------------------------===//

View File

@ -1,9 +1,8 @@
//===-- FileRemapper.h - File Remapping Helper ------------------*- 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
//
//===----------------------------------------------------------------------===//

View File

@ -1,9 +1,8 @@
//===--- APValue.h - Union class for APFloat/APSInt/Complex -----*- 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
//
//===----------------------------------------------------------------------===//
//
@ -14,6 +13,7 @@
#ifndef LLVM_CLANG_AST_APVALUE_H
#define LLVM_CLANG_AST_APVALUE_H
#include "clang/Basic/FixedPoint.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APSInt.h"
@ -24,14 +24,52 @@ namespace clang {
class AddrLabelExpr;
class ASTContext;
class CharUnits;
class CXXRecordDecl;
class Decl;
class DiagnosticBuilder;
class Expr;
class FieldDecl;
class Decl;
struct PrintingPolicy;
class Type;
class ValueDecl;
class CXXRecordDecl;
class QualType;
/// Symbolic representation of typeid(T) for some type T.
class TypeInfoLValue {
const Type *T;
public:
TypeInfoLValue() : T() {}
explicit TypeInfoLValue(const Type *T);
const Type *getType() const { return T; }
explicit operator bool() const { return T; }
void *getOpaqueValue() { return const_cast<Type*>(T); }
static TypeInfoLValue getFromOpaqueValue(void *Value) {
TypeInfoLValue V;
V.T = reinterpret_cast<const Type*>(Value);
return V;
}
void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const;
};
}
namespace llvm {
template<> struct PointerLikeTypeTraits<clang::TypeInfoLValue> {
static void *getAsVoidPointer(clang::TypeInfoLValue V) {
return V.getOpaqueValue();
}
static clang::TypeInfoLValue getFromVoidPointer(void *P) {
return clang::TypeInfoLValue::getFromOpaqueValue(P);
}
// Validated by static_assert in APValue.cpp; hardcoded to avoid needing
// to include Type.h.
static constexpr int NumLowBitsAvailable = 3;
};
}
namespace clang {
/// APValue - This class implements a discriminated union of [uninitialized]
/// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
/// [Vector: N * APValue], [Array: N * APValue]
@ -40,9 +78,13 @@ class APValue {
typedef llvm::APFloat APFloat;
public:
enum ValueKind {
Uninitialized,
/// There is no such object (it's outside its lifetime).
None,
/// This object has an indeterminate value (C++ [basic.indet]).
Indeterminate,
Int,
Float,
FixedPoint,
ComplexInt,
ComplexFloat,
LValue,
@ -55,14 +97,14 @@ public:
};
class LValueBase {
typedef llvm::PointerUnion<const ValueDecl *, const Expr *, TypeInfoLValue>
PtrTy;
public:
typedef llvm::PointerUnion<const ValueDecl *, const Expr *> PtrTy;
LValueBase() : CallIndex(0), Version(0) {}
template <class T>
LValueBase(T P, unsigned I = 0, unsigned V = 0)
: Ptr(P), CallIndex(I), Version(V) {}
LValueBase() : Local{} {}
LValueBase(const ValueDecl *P, unsigned I = 0, unsigned V = 0);
LValueBase(const Expr *P, unsigned I = 0, unsigned V = 0);
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo);
template <class T>
bool is() const { return Ptr.is<T>(); }
@ -77,45 +119,73 @@ public:
bool isNull() const;
explicit operator bool () const;
explicit operator bool() const;
PtrTy getPointer() const {
return Ptr;
}
unsigned getCallIndex() const;
unsigned getVersion() const;
QualType getTypeInfoType() const;
unsigned getCallIndex() const {
return CallIndex;
}
void setCallIndex(unsigned Index) {
CallIndex = Index;
}
unsigned getVersion() const {
return Version;
}
bool operator==(const LValueBase &Other) const {
return Ptr == Other.Ptr && CallIndex == Other.CallIndex &&
Version == Other.Version;
friend bool operator==(const LValueBase &LHS, const LValueBase &RHS);
friend bool operator!=(const LValueBase &LHS, const LValueBase &RHS) {
return !(LHS == RHS);
}
friend llvm::hash_code hash_value(const LValueBase &Base);
private:
PtrTy Ptr;
unsigned CallIndex, Version;
struct LocalState {
unsigned CallIndex, Version;
};
union {
LocalState Local;
/// The type std::type_info, if this is a TypeInfoLValue.
void *TypeInfoType;
};
};
/// A FieldDecl or CXXRecordDecl, along with a flag indicating whether we
/// mean a virtual or non-virtual base class subobject.
typedef llvm::PointerIntPair<const Decl *, 1, bool> BaseOrMemberType;
union LValuePathEntry {
/// BaseOrMember - The FieldDecl or CXXRecordDecl indicating the next item
/// in the path. An opaque value of type BaseOrMemberType.
void *BaseOrMember;
/// ArrayIndex - The array index of the next item in the path.
uint64_t ArrayIndex;
/// A non-discriminated union of a base, field, or array index.
class LValuePathEntry {
static_assert(sizeof(uintptr_t) <= sizeof(uint64_t),
"pointer doesn't fit in 64 bits?");
uint64_t Value;
public:
LValuePathEntry() : Value() {}
LValuePathEntry(BaseOrMemberType BaseOrMember)
: Value{reinterpret_cast<uintptr_t>(BaseOrMember.getOpaqueValue())} {}
static LValuePathEntry ArrayIndex(uint64_t Index) {
LValuePathEntry Result;
Result.Value = Index;
return Result;
}
BaseOrMemberType getAsBaseOrMember() const {
return BaseOrMemberType::getFromOpaqueValue(
reinterpret_cast<void *>(Value));
}
uint64_t getAsArrayIndex() const { return Value; }
friend bool operator==(LValuePathEntry A, LValuePathEntry B) {
return A.Value == B.Value;
}
friend bool operator!=(LValuePathEntry A, LValuePathEntry B) {
return A.Value != B.Value;
}
friend llvm::hash_code hash_value(LValuePathEntry A) {
return llvm::hash_value(A.Value);
}
};
struct NoLValuePath {};
struct UninitArray {};
struct UninitStruct {};
friend class ASTReader;
friend class ASTWriter;
private:
ValueKind Kind;
@ -168,55 +238,64 @@ private:
DataType Data;
public:
APValue() : Kind(Uninitialized) {}
explicit APValue(APSInt I) : Kind(Uninitialized) {
APValue() : Kind(None) {}
explicit APValue(APSInt I) : Kind(None) {
MakeInt(); setInt(std::move(I));
}
explicit APValue(APFloat F) : Kind(Uninitialized) {
explicit APValue(APFloat F) : Kind(None) {
MakeFloat(); setFloat(std::move(F));
}
explicit APValue(const APValue *E, unsigned N) : Kind(Uninitialized) {
explicit APValue(APFixedPoint FX) : Kind(None) {
MakeFixedPoint(std::move(FX));
}
explicit APValue(const APValue *E, unsigned N) : Kind(None) {
MakeVector(); setVector(E, N);
}
APValue(APSInt R, APSInt I) : Kind(Uninitialized) {
APValue(APSInt R, APSInt I) : Kind(None) {
MakeComplexInt(); setComplexInt(std::move(R), std::move(I));
}
APValue(APFloat R, APFloat I) : Kind(Uninitialized) {
APValue(APFloat R, APFloat I) : Kind(None) {
MakeComplexFloat(); setComplexFloat(std::move(R), std::move(I));
}
APValue(const APValue &RHS);
APValue(APValue &&RHS) : Kind(Uninitialized) { swap(RHS); }
APValue(APValue &&RHS) : Kind(None) { swap(RHS); }
APValue(LValueBase B, const CharUnits &O, NoLValuePath N,
bool IsNullPtr = false)
: Kind(Uninitialized) {
: Kind(None) {
MakeLValue(); setLValue(B, O, N, IsNullPtr);
}
APValue(LValueBase B, const CharUnits &O, ArrayRef<LValuePathEntry> Path,
bool OnePastTheEnd, bool IsNullPtr = false)
: Kind(Uninitialized) {
: Kind(None) {
MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, IsNullPtr);
}
APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(Uninitialized) {
APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(None) {
MakeArray(InitElts, Size);
}
APValue(UninitStruct, unsigned B, unsigned M) : Kind(Uninitialized) {
APValue(UninitStruct, unsigned B, unsigned M) : Kind(None) {
MakeStruct(B, M);
}
explicit APValue(const FieldDecl *D, const APValue &V = APValue())
: Kind(Uninitialized) {
: Kind(None) {
MakeUnion(); setUnion(D, V);
}
APValue(const ValueDecl *Member, bool IsDerivedMember,
ArrayRef<const CXXRecordDecl*> Path) : Kind(Uninitialized) {
ArrayRef<const CXXRecordDecl*> Path) : Kind(None) {
MakeMemberPointer(Member, IsDerivedMember, Path);
}
APValue(const AddrLabelExpr* LHSExpr, const AddrLabelExpr* RHSExpr)
: Kind(Uninitialized) {
: Kind(None) {
MakeAddrLabelDiff(); setAddrLabelDiff(LHSExpr, RHSExpr);
}
static APValue IndeterminateValue() {
APValue Result;
Result.Kind = Indeterminate;
return Result;
}
~APValue() {
MakeUninit();
if (Kind != None && Kind != Indeterminate)
DestroyDataAndMakeUninit();
}
/// Returns whether the object performed allocations.
@ -230,9 +309,14 @@ public:
void swap(APValue &RHS);
ValueKind getKind() const { return Kind; }
bool isUninit() const { return Kind == Uninitialized; }
bool isAbsent() const { return Kind == None; }
bool isIndeterminate() const { return Kind == Indeterminate; }
bool hasValue() const { return Kind != None && Kind != Indeterminate; }
bool isInt() const { return Kind == Int; }
bool isFloat() const { return Kind == Float; }
bool isFixedPoint() const { return Kind == FixedPoint; }
bool isComplexInt() const { return Kind == ComplexInt; }
bool isComplexFloat() const { return Kind == ComplexFloat; }
bool isLValue() const { return Kind == LValue; }
@ -246,8 +330,8 @@ public:
void dump() const;
void dump(raw_ostream &OS) const;
void printPretty(raw_ostream &OS, ASTContext &Ctx, QualType Ty) const;
std::string getAsString(ASTContext &Ctx, QualType Ty) const;
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const;
std::string getAsString(const ASTContext &Ctx, QualType Ty) const;
APSInt &getInt() {
assert(isInt() && "Invalid accessor");
@ -257,6 +341,12 @@ public:
return const_cast<APValue*>(this)->getInt();
}
/// Try to convert this value to an integral constant. This works if it's an
/// integer, null pointer, or offset from a null pointer. Returns true on
/// success.
bool toIntegralConstant(APSInt &Result, QualType SrcTy,
const ASTContext &Ctx) const;
APFloat &getFloat() {
assert(isFloat() && "Invalid accessor");
return *(APFloat*)(char*)Data.buffer;
@ -265,6 +355,14 @@ public:
return const_cast<APValue*>(this)->getFloat();
}
APFixedPoint &getFixedPoint() {
assert(isFixedPoint() && "Invalid accessor");
return *(APFixedPoint *)(char *)Data.buffer;
}
const APFixedPoint &getFixedPoint() const {
return const_cast<APValue *>(this)->getFixedPoint();
}
APSInt &getComplexIntReal() {
assert(isComplexInt() && "Invalid accessor");
return ((ComplexAPSInt*)(char*)Data.buffer)->Real;
@ -406,6 +504,10 @@ public:
assert(isFloat() && "Invalid accessor");
*(APFloat *)(char *)Data.buffer = std::move(F);
}
void setFixedPoint(APFixedPoint FX) {
assert(isFixedPoint() && "Invalid accessor");
*(APFixedPoint *)(char *)Data.buffer = std::move(FX);
}
void setVector(const APValue *E, unsigned N) {
assert(isVector() && "Invalid accessor");
((Vec*)(char*)Data.buffer)->Elts = new APValue[N];
@ -451,51 +553,52 @@ public:
private:
void DestroyDataAndMakeUninit();
void MakeUninit() {
if (Kind != Uninitialized)
DestroyDataAndMakeUninit();
}
void MakeInt() {
assert(isUninit() && "Bad state change");
assert(isAbsent() && "Bad state change");
new ((void*)Data.buffer) APSInt(1);
Kind = Int;
}
void MakeFloat() {
assert(isUninit() && "Bad state change");
assert(isAbsent() && "Bad state change");
new ((void*)(char*)Data.buffer) APFloat(0.0);
Kind = Float;
}
void MakeFixedPoint(APFixedPoint &&FX) {
assert(isAbsent() && "Bad state change");
new ((void *)(char *)Data.buffer) APFixedPoint(std::move(FX));
Kind = FixedPoint;
}
void MakeVector() {
assert(isUninit() && "Bad state change");
assert(isAbsent() && "Bad state change");
new ((void*)(char*)Data.buffer) Vec();
Kind = Vector;
}
void MakeComplexInt() {
assert(isUninit() && "Bad state change");
assert(isAbsent() && "Bad state change");
new ((void*)(char*)Data.buffer) ComplexAPSInt();
Kind = ComplexInt;
}
void MakeComplexFloat() {
assert(isUninit() && "Bad state change");
assert(isAbsent() && "Bad state change");
new ((void*)(char*)Data.buffer) ComplexAPFloat();
Kind = ComplexFloat;
}
void MakeLValue();
void MakeArray(unsigned InitElts, unsigned Size);
void MakeStruct(unsigned B, unsigned M) {
assert(isUninit() && "Bad state change");
assert(isAbsent() && "Bad state change");
new ((void*)(char*)Data.buffer) StructData(B, M);
Kind = Struct;
}
void MakeUnion() {
assert(isUninit() && "Bad state change");
assert(isAbsent() && "Bad state change");
new ((void*)(char*)Data.buffer) UnionData();
Kind = Union;
}
void MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
ArrayRef<const CXXRecordDecl*> Path);
void MakeAddrLabelDiff() {
assert(isUninit() && "Bad state change");
assert(isAbsent() && "Bad state change");
new ((void*)(char*)Data.buffer) AddrLabelDiffData();
Kind = AddrLabelDiff;
}

View File

@ -1,9 +1,8 @@
//===--- AST.h - "Umbrella" header for AST library --------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- ASTContext.h - Context to hold long-lived AST nodes ------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -266,17 +265,21 @@ private:
/// Mapping from __block VarDecls to BlockVarCopyInit.
llvm::DenseMap<const VarDecl *, BlockVarCopyInit> BlockVarCopyInits;
/// Mapping from class scope functions specialization to their
/// template patterns.
llvm::DenseMap<const FunctionDecl*, FunctionDecl*>
ClassScopeSpecializationPattern;
/// Mapping from materialized temporaries with static storage duration
/// that appear in constant initializers to their evaluated values. These are
/// allocated in a std::map because their address must be stable.
llvm::DenseMap<const MaterializeTemporaryExpr *, APValue *>
MaterializedTemporaryValues;
/// Used to cleanups APValues stored in the AST.
mutable llvm::SmallVector<APValue *, 0> APValueCleanups;
/// A cache mapping a string value to a StringLiteral object with the same
/// value.
///
/// This is lazily created. This is intentionally not serialized.
mutable llvm::StringMap<StringLiteral *> StringLiteralCache;
/// Representation of a "canonical" template template parameter that
/// is used in canonical template names.
class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
@ -892,11 +895,6 @@ public:
TemplateOrSpecializationInfo
getTemplateOrSpecializationInfo(const VarDecl *Var);
FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD);
void setClassScopeSpecializationPattern(FunctionDecl *FD,
FunctionDecl *Pattern);
/// Note that the static data member \p Inst is an instantiation of
/// the static data member template \p Tmpl of a class template.
void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
@ -1334,6 +1332,10 @@ public:
ArrayType::ArraySizeModifier ASM,
unsigned IndexTypeQuals) const;
/// Return a type for a constant array for a string literal of the
/// specified element type and length.
QualType getStringLiteralArrayType(QualType EltTy, unsigned Length) const;
/// Returns a vla type where known sizes are replaced with [*].
QualType getVariableArrayDecayedType(QualType Ty) const;
@ -1452,6 +1454,9 @@ public:
QualType getParenType(QualType NamedType) const;
QualType getMacroQualifiedType(QualType UnderlyingTy,
const IdentifierInfo *MacroII) const;
QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *NNS, QualType NamedType,
TagDecl *OwnedTagDecl = nullptr) const;
@ -1520,7 +1525,7 @@ public:
/// C++11 deduced auto type.
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword,
bool IsDependent) const;
bool IsDependent, bool IsPack = false) const;
/// C++11 deduction pattern for 'auto' type.
QualType getAutoDeductType() const;
@ -1985,6 +1990,7 @@ public:
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
UnresolvedSetIterator End) const;
TemplateName getAssumedTemplateName(DeclarationName Name) const;
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
bool TemplateKeyword,
@ -2003,6 +2009,9 @@ public:
/// No error
GE_None,
/// Missing a type
GE_Missing_type,
/// Missing a type from <stdio.h>
GE_Missing_stdio,
@ -2086,6 +2095,16 @@ public:
CharUnits getTypeSizeInChars(QualType T) const;
CharUnits getTypeSizeInChars(const Type *T) const;
Optional<CharUnits> getTypeSizeInCharsIfKnown(QualType Ty) const {
if (Ty->isIncompleteType() || Ty->isDependentType())
return None;
return getTypeSizeInChars(Ty);
}
Optional<CharUnits> getTypeSizeInCharsIfKnown(const Type *Ty) const {
return getTypeSizeInCharsIfKnown(QualType(Ty, 0));
}
/// Return the ABI-specified alignment of a (complete) type \p T, in
/// bits.
unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; }
@ -2160,6 +2179,13 @@ public:
/// pointers and large arrays get extra alignment.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof = false) const;
/// Return the alignment (in bytes) of the thrown exception object. This is
/// only meaningful for targets that allocate C++ exceptions in a system
/// runtime, such as those using the Itanium C++ ABI.
CharUnits getExnObjectAlignment() const {
return toCharUnitsFromBits(Target->getExnObjectAlignment());
}
/// Get or compute information about the layout of the specified
/// record (struct/union/class) \p D, which indicates its size and field
/// position information.
@ -2225,7 +2251,8 @@ public:
VTableContextBase *getVTableContext();
MangleContext *createMangleContext();
/// If \p T is null pointer, assume the target in ASTContext.
MangleContext *createMangleContext(const TargetInfo *T = nullptr);
void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const;
@ -2371,7 +2398,8 @@ public:
/// Retrieves the default calling convention for the current target.
CallingConv getDefaultCallingConvention(bool IsVariadic,
bool IsCXXMethod) const;
bool IsCXXMethod,
bool IsBuiltin = false) const;
/// Retrieves the "canonical" template name that refers to a
/// given template.
@ -2488,6 +2516,11 @@ public:
/// \p LHS < \p RHS, return -1.
int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
/// Compare the rank of two floating point types as above, but compare equal
/// if both types have the same floating-point semantics on the target (i.e.
/// long double and double on AArch64 will return 0).
int getFloatingTypeSemanticOrder(QualType LHS, QualType RHS) const;
/// Return a real floating point or a complex type (based on
/// \p typeDomain/\p typeSize).
///
@ -2624,6 +2657,12 @@ public:
// corresponding saturated type for a given fixed point type.
QualType getCorrespondingSaturatedType(QualType Ty) const;
// This method accepts fixed point types and returns the corresponding signed
// type. Unlike getCorrespondingUnsignedType(), this only accepts unsigned
// fixed point types because there are unsigned integer types like bool and
// char8_t that don't have signed equivalents.
QualType getCorrespondingSignedFixedPointType(QualType Ty) const;
//===--------------------------------------------------------------------===//
// Integer Values
//===--------------------------------------------------------------------===//
@ -2677,7 +2716,7 @@ public:
/// otherwise returns null.
const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const;
/// Set the copy inialization expression of a block var decl. \p CanThrow
/// Set the copy initialization expression of a block var decl. \p CanThrow
/// indicates whether the copy expression can throw or not.
void setBlockVarCopyInit(const VarDecl* VD, Expr *CopyExpr, bool CanThrow);
@ -2712,12 +2751,11 @@ public:
///
/// \param Data Pointer data that will be provided to the callback function
/// when it is called.
void AddDeallocation(void (*Callback)(void*), void *Data);
void AddDeallocation(void (*Callback)(void *), void *Data) const;
/// If T isn't trivially destructible, calls AddDeallocation to register it
/// for destruction.
template <typename T>
void addDestruction(T *Ptr) {
template <typename T> void addDestruction(T *Ptr) const {
if (!std::is_trivially_destructible<T>::value) {
auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
AddDeallocation(DestroyPtr, Ptr);
@ -2780,51 +2818,56 @@ public:
APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E,
bool MayCreate);
/// Return a string representing the human readable name for the specified
/// function declaration or file name. Used by SourceLocExpr and
/// PredefinedExpr to cache evaluated results.
StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const;
//===--------------------------------------------------------------------===//
// Statistics
//===--------------------------------------------------------------------===//
/// The number of implicitly-declared default constructors.
static unsigned NumImplicitDefaultConstructors;
unsigned NumImplicitDefaultConstructors = 0;
/// The number of implicitly-declared default constructors for
/// which declarations were built.
static unsigned NumImplicitDefaultConstructorsDeclared;
unsigned NumImplicitDefaultConstructorsDeclared = 0;
/// The number of implicitly-declared copy constructors.
static unsigned NumImplicitCopyConstructors;
unsigned NumImplicitCopyConstructors = 0;
/// The number of implicitly-declared copy constructors for
/// which declarations were built.
static unsigned NumImplicitCopyConstructorsDeclared;
unsigned NumImplicitCopyConstructorsDeclared = 0;
/// The number of implicitly-declared move constructors.
static unsigned NumImplicitMoveConstructors;
unsigned NumImplicitMoveConstructors = 0;
/// The number of implicitly-declared move constructors for
/// which declarations were built.
static unsigned NumImplicitMoveConstructorsDeclared;
unsigned NumImplicitMoveConstructorsDeclared = 0;
/// The number of implicitly-declared copy assignment operators.
static unsigned NumImplicitCopyAssignmentOperators;
unsigned NumImplicitCopyAssignmentOperators = 0;
/// The number of implicitly-declared copy assignment operators for
/// which declarations were built.
static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
unsigned NumImplicitCopyAssignmentOperatorsDeclared = 0;
/// The number of implicitly-declared move assignment operators.
static unsigned NumImplicitMoveAssignmentOperators;
unsigned NumImplicitMoveAssignmentOperators = 0;
/// The number of implicitly-declared move assignment operators for
/// which declarations were built.
static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
unsigned NumImplicitMoveAssignmentOperatorsDeclared = 0;
/// The number of implicitly-declared destructors.
static unsigned NumImplicitDestructors;
unsigned NumImplicitDestructors = 0;
/// The number of implicitly-declared destructors for which
/// declarations were built.
static unsigned NumImplicitDestructorsDeclared;
unsigned NumImplicitDestructorsDeclared = 0;
public:
/// Initialize built-in types.
@ -2839,18 +2882,51 @@ public:
private:
void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
class ObjCEncOptions {
unsigned Bits;
ObjCEncOptions(unsigned Bits) : Bits(Bits) {}
public:
ObjCEncOptions() : Bits(0) {}
ObjCEncOptions(const ObjCEncOptions &RHS) : Bits(RHS.Bits) {}
#define OPT_LIST(V) \
V(ExpandPointedToStructures, 0) \
V(ExpandStructures, 1) \
V(IsOutermostType, 2) \
V(EncodingProperty, 3) \
V(IsStructField, 4) \
V(EncodeBlockParameters, 5) \
V(EncodeClassNames, 6) \
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
OPT_LIST(V)
#undef V
#define V(N,I) bool N() const { return Bits & 1 << I; }
OPT_LIST(V)
#undef V
#undef OPT_LIST
LLVM_NODISCARD ObjCEncOptions keepingOnly(ObjCEncOptions Mask) const {
return Bits & Mask.Bits;
}
LLVM_NODISCARD ObjCEncOptions forComponentType() const {
ObjCEncOptions Mask = ObjCEncOptions()
.setIsOutermostType()
.setIsStructField();
return Bits & ~Mask.Bits;
}
};
// Return the Objective-C type encoding for a given type.
void getObjCEncodingForTypeImpl(QualType t, std::string &S,
bool ExpandPointedToStructures,
bool ExpandStructures,
ObjCEncOptions Options,
const FieldDecl *Field,
bool OutermostType = false,
bool EncodingProperty = false,
bool StructField = false,
bool EncodeBlockParameters = false,
bool EncodeClassNames = false,
bool EncodePointerToObjCTypedef = false,
QualType *NotEncodedT=nullptr) const;
QualType *NotEncodedT = nullptr) const;
// Adds the encoding of the structure's members.
void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S,
@ -2908,7 +2984,7 @@ private:
// in order to track and run destructors while we're tearing things down.
using DeallocationFunctionsAndArguments =
llvm::SmallVector<std::pair<void (*)(void *), void *>, 16>;
DeallocationFunctionsAndArguments Deallocations;
mutable DeallocationFunctionsAndArguments Deallocations;
// FIXME: This currently contains the set of StoredDeclMaps used
// by DeclContext objects. This probably should not be in ASTContext,

View File

@ -1,9 +1,8 @@
//===- ASTContextAllocate.h - ASTContext allocate functions -----*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- ASTDiagnostic.h - Diagnostics for the AST library ------*- 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
//
//===----------------------------------------------------------------------===//

View File

@ -0,0 +1,56 @@
//===--- ASTDumper.h - Dumping implementation for ASTs --------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_ASTDUMPER_H
#define LLVM_CLANG_AST_ASTDUMPER_H
#include "clang/AST/ASTNodeTraverser.h"
#include "clang/AST/TextNodeDumper.h"
namespace clang {
class ASTDumper : public ASTNodeTraverser<ASTDumper, TextNodeDumper> {
TextNodeDumper NodeDumper;
raw_ostream &OS;
const bool ShowColors;
public:
ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
const SourceManager *SM)
: ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) {}
ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
const SourceManager *SM, bool ShowColors)
: ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
const SourceManager *SM, bool ShowColors,
const PrintingPolicy &PrintPolicy)
: NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
ShowColors(ShowColors) {}
TextNodeDumper &doGetNodeDelegate() { return NodeDumper; }
void dumpLookups(const DeclContext *DC, bool DumpDecls);
template <typename SpecializationDecl>
void dumpTemplateDeclSpecialization(const SpecializationDecl *D,
bool DumpExplicitInst, bool DumpRefOnly);
template <typename TemplateDecl>
void dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
void VisitClassTemplateDecl(const ClassTemplateDecl *D);
void VisitVarTemplateDecl(const VarTemplateDecl *D);
};
} // namespace clang
#endif

View File

@ -1,9 +1,8 @@
//===--- ASTDumperUtils.h - Printing of AST nodes -------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
@ -18,6 +17,12 @@
namespace clang {
/// Used to specify the format for printing AST dump information.
enum ASTDumpOutputFormat {
ADOF_Default,
ADOF_JSON
};
// Colors used for various parts of the AST dump
// Do not use bold yellow for any text. It is hard to read on white screens.

View File

@ -1,9 +1,8 @@
//===--- ASTFwd.h ----------------------------------------*- 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
//
//===--------------------------------------------------------------===//
///

View File

@ -1,9 +1,8 @@
//===- ASTImporter.h - Importing ASTs from other Contexts -------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -15,6 +14,7 @@
#ifndef LLVM_CLANG_AST_ASTIMPORTER_H
#define LLVM_CLANG_AST_ASTIMPORTER_H
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/TemplateName.h"
@ -33,7 +33,8 @@
namespace clang {
class ASTContext;
class ASTImporterLookupTable;
class ASTImporterSharedState;
class Attr;
class CXXBaseSpecifier;
class CXXCtorInitializer;
class Decl;
@ -43,8 +44,8 @@ class FileManager;
class NamedDecl;
class Stmt;
class TagDecl;
class TranslationUnitDecl;
class TypeSourceInfo;
class Attr;
class ImportError : public llvm::ErrorInfo<ImportError> {
public:
@ -87,14 +88,140 @@ class Attr;
using ImportedCXXBaseSpecifierMap =
llvm::DenseMap<const CXXBaseSpecifier *, CXXBaseSpecifier *>;
private:
// An ImportPath is the list of the AST nodes which we visit during an
// Import call.
// If node `A` depends on node `B` then the path contains an `A`->`B` edge.
// From the call stack of the import functions we can read the very same
// path.
//
// Now imagine the following AST, where the `->` represents dependency in
// therms of the import.
// ```
// A->B->C->D
// `->E
// ```
// We would like to import A.
// The import behaves like a DFS, so we will visit the nodes in this order:
// ABCDE.
// During the visitation we will have the following ImportPaths:
// ```
// A
// AB
// ABC
// ABCD
// ABC
// AB
// ABE
// AB
// A
// ```
// If during the visit of E there is an error then we set an error for E,
// then as the call stack shrinks for B, then for A:
// ```
// A
// AB
// ABC
// ABCD
// ABC
// AB
// ABE // Error! Set an error to E
// AB // Set an error to B
// A // Set an error to A
// ```
// However, during the import we could import C and D without any error and
// they are independent from A,B and E.
// We must not set up an error for C and D.
// So, at the end of the import we have an entry in `ImportDeclErrors` for
// A,B,E but not for C,D.
//
// Now what happens if there is a cycle in the import path?
// Let's consider this AST:
// ```
// A->B->C->A
// `->E
// ```
// During the visitation we will have the below ImportPaths and if during
// the visit of E there is an error then we will set up an error for E,B,A.
// But what's up with C?
// ```
// A
// AB
// ABC
// ABCA
// ABC
// AB
// ABE // Error! Set an error to E
// AB // Set an error to B
// A // Set an error to A
// ```
// This time we know that both B and C are dependent on A.
// This means we must set up an error for C too.
// As the call stack reverses back we get to A and we must set up an error
// to all nodes which depend on A (this includes C).
// But C is no longer on the import path, it just had been previously.
// Such situation can happen only if during the visitation we had a cycle.
// If we didn't have any cycle, then the normal way of passing an Error
// object through the call stack could handle the situation.
// This is why we must track cycles during the import process for each
// visited declaration.
class ImportPathTy {
public:
using VecTy = llvm::SmallVector<Decl *, 32>;
/// Pointer to the import specific lookup table, which may be shared
/// amongst several ASTImporter objects.
/// This is an externally managed resource (and should exist during the
/// lifetime of the ASTImporter object)
/// If not set then the original C/C++ lookup is used.
ASTImporterLookupTable *LookupTable = nullptr;
void push(Decl *D) {
Nodes.push_back(D);
++Aux[D];
}
void pop() {
if (Nodes.empty())
return;
--Aux[Nodes.back()];
Nodes.pop_back();
}
/// Returns true if the last element can be found earlier in the path.
bool hasCycleAtBack() const {
auto Pos = Aux.find(Nodes.back());
return Pos != Aux.end() && Pos->second > 1;
}
using Cycle = llvm::iterator_range<VecTy::const_reverse_iterator>;
Cycle getCycleAtBack() const {
assert(Nodes.size() >= 2);
return Cycle(Nodes.rbegin(),
std::find(Nodes.rbegin() + 1, Nodes.rend(), Nodes.back()) +
1);
}
/// Returns the copy of the cycle.
VecTy copyCycleAtBack() const {
auto R = getCycleAtBack();
return VecTy(R.begin(), R.end());
}
private:
// All nodes of the path.
VecTy Nodes;
// Auxiliary container to be able to answer "Do we have a cycle ending
// at last element?" as fast as possible.
// We count each Decl's occurrence over the path.
llvm::SmallDenseMap<Decl *, int, 32> Aux;
};
private:
std::shared_ptr<ASTImporterSharedState> SharedState = nullptr;
/// The path which we go through during the import of a given AST node.
ImportPathTy ImportPath;
/// Sometimes we have to save some part of an import path, so later we can
/// set up properties to the saved nodes.
/// We may have several of these import paths associated to one Decl.
using SavedImportPathsForOneDecl =
llvm::SmallVector<ImportPathTy::VecTy, 32>;
using SavedImportPathsTy =
llvm::SmallDenseMap<Decl *, SavedImportPathsForOneDecl, 32>;
SavedImportPathsTy SavedImportPaths;
/// The contexts we're importing to and from.
ASTContext &ToContext, &FromContext;
@ -116,6 +243,18 @@ class Attr;
/// context to the corresponding declarations in the "to" context.
llvm::DenseMap<Decl *, Decl *> ImportedDecls;
/// Mapping from the already-imported declarations in the "from"
/// context to the error status of the import of that declaration.
/// This map contains only the declarations that were not correctly
/// imported. The same declaration may or may not be included in
/// ImportedDecls. This map is updated continuously during imports and never
/// cleared (like ImportedDecls).
llvm::DenseMap<Decl *, ImportError> ImportDeclErrors;
/// Mapping from the already-imported declarations in the "to"
/// context to the corresponding declarations in the "from" context.
llvm::DenseMap<Decl *, Decl *> ImportedFromDecls;
/// Mapping from the already-imported statements in the "from"
/// context to the corresponding statements in the "to" context.
llvm::DenseMap<Stmt *, Stmt *> ImportedStmts;
@ -138,6 +277,15 @@ class Attr;
void AddToLookupTable(Decl *ToD);
protected:
/// Can be overwritten by subclasses to implement their own import logic.
/// The overwritten method should call this method if it didn't import the
/// decl on its own.
virtual Expected<Decl *> ImportImpl(Decl *From);
/// Used only in unittests to verify the behaviour of the error handling.
virtual bool returnWithErrorInTest() { return false; };
public:
/// \param ToContext The context we'll be importing into.
@ -152,13 +300,13 @@ class Attr;
/// as little as it can, e.g., by importing declarations as forward
/// declarations that can be completed at a later point.
///
/// \param LookupTable The importer specific lookup table which may be
/// \param SharedState The importer specific lookup table which may be
/// shared amongst several ASTImporter objects.
/// If not set then the original C/C++ lookup is used.
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
ASTContext &FromContext, FileManager &FromFileManager,
bool MinimalImport,
ASTImporterLookupTable *LookupTable = nullptr);
std::shared_ptr<ASTImporterSharedState> SharedState = nullptr);
virtual ~ASTImporter();
@ -173,63 +321,51 @@ class Attr;
/// \return Error information (success or error).
template <typename ImportT>
LLVM_NODISCARD llvm::Error importInto(ImportT &To, const ImportT &From) {
To = Import(From);
if (From && !To)
return llvm::make_error<ImportError>();
return llvm::Error::success();
// FIXME: this should be the final code
//auto ToOrErr = Import(From);
//if (ToOrErr)
// To = *ToOrErr;
//return ToOrErr.takeError();
auto ToOrErr = Import(From);
if (ToOrErr)
To = *ToOrErr;
return ToOrErr.takeError();
}
/// Import the given type from the "from" context into the "to"
/// context. A null type is imported as a null type (no error).
///
/// \returns The equivalent type in the "to" context, or the import error.
llvm::Expected<QualType> Import_New(QualType FromT);
// FIXME: Remove this version.
QualType Import(QualType FromT);
llvm::Expected<QualType> Import(QualType FromT);
/// Import the given type source information from the
/// "from" context into the "to" context.
///
/// \returns The equivalent type source information in the "to"
/// context, or the import error.
llvm::Expected<TypeSourceInfo *> Import_New(TypeSourceInfo *FromTSI);
// FIXME: Remove this version.
TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
llvm::Expected<TypeSourceInfo *> Import(TypeSourceInfo *FromTSI);
/// Import the given attribute from the "from" context into the
/// "to" context.
///
/// \returns The equivalent attribute in the "to" context, or the import
/// error.
llvm::Expected<Attr *> Import_New(const Attr *FromAttr);
// FIXME: Remove this version.
Attr *Import(const Attr *FromAttr);
llvm::Expected<Attr *> Import(const Attr *FromAttr);
/// Import the given declaration from the "from" context into the
/// "to" context.
///
/// \returns The equivalent declaration in the "to" context, or the import
/// error.
llvm::Expected<Decl *> Import_New(Decl *FromD);
llvm::Expected<Decl *> Import_New(const Decl *FromD) {
return Import_New(const_cast<Decl *>(FromD));
}
// FIXME: Remove this version.
Decl *Import(Decl *FromD);
Decl *Import(const Decl *FromD) {
llvm::Expected<Decl *> Import(Decl *FromD);
llvm::Expected<const Decl *> Import(const Decl *FromD) {
return Import(const_cast<Decl *>(FromD));
}
/// Return the copy of the given declaration in the "to" context if
/// it has already been imported from the "from" context. Otherwise return
/// NULL.
/// nullptr.
Decl *GetAlreadyImportedOrNull(const Decl *FromD) const;
/// Return the translation unit from where the declaration was
/// imported. If it does not exist nullptr is returned.
TranslationUnitDecl *GetFromTU(Decl *ToD);
/// Import the given declaration context from the "from"
/// AST context into the "to" AST context.
///
@ -242,28 +378,21 @@ class Attr;
///
/// \returns The equivalent expression in the "to" context, or the import
/// error.
llvm::Expected<Expr *> Import_New(Expr *FromE);
// FIXME: Remove this version.
Expr *Import(Expr *FromE);
llvm::Expected<Expr *> Import(Expr *FromE);
/// Import the given statement from the "from" context into the
/// "to" context.
///
/// \returns The equivalent statement in the "to" context, or the import
/// error.
llvm::Expected<Stmt *> Import_New(Stmt *FromS);
// FIXME: Remove this version.
Stmt *Import(Stmt *FromS);
llvm::Expected<Stmt *> Import(Stmt *FromS);
/// Import the given nested-name-specifier from the "from"
/// context into the "to" context.
///
/// \returns The equivalent nested-name-specifier in the "to"
/// context, or the import error.
llvm::Expected<NestedNameSpecifier *>
Import_New(NestedNameSpecifier *FromNNS);
// FIXME: Remove this version.
NestedNameSpecifier *Import(NestedNameSpecifier *FromNNS);
llvm::Expected<NestedNameSpecifier *> Import(NestedNameSpecifier *FromNNS);
/// Import the given nested-name-specifier-loc from the "from"
/// context into the "to" context.
@ -271,42 +400,32 @@ class Attr;
/// \returns The equivalent nested-name-specifier-loc in the "to"
/// context, or the import error.
llvm::Expected<NestedNameSpecifierLoc>
Import_New(NestedNameSpecifierLoc FromNNS);
// FIXME: Remove this version.
NestedNameSpecifierLoc Import(NestedNameSpecifierLoc FromNNS);
Import(NestedNameSpecifierLoc FromNNS);
/// Import the given template name from the "from" context into the
/// "to" context, or the import error.
llvm::Expected<TemplateName> Import_New(TemplateName From);
// FIXME: Remove this version.
TemplateName Import(TemplateName From);
llvm::Expected<TemplateName> Import(TemplateName From);
/// Import the given source location from the "from" context into
/// the "to" context.
///
/// \returns The equivalent source location in the "to" context, or the
/// import error.
llvm::Expected<SourceLocation> Import_New(SourceLocation FromLoc);
// FIXME: Remove this version.
SourceLocation Import(SourceLocation FromLoc);
llvm::Expected<SourceLocation> Import(SourceLocation FromLoc);
/// Import the given source range from the "from" context into
/// the "to" context.
///
/// \returns The equivalent source range in the "to" context, or the import
/// error.
llvm::Expected<SourceRange> Import_New(SourceRange FromRange);
// FIXME: Remove this version.
SourceRange Import(SourceRange FromRange);
llvm::Expected<SourceRange> Import(SourceRange FromRange);
/// Import the given declaration name from the "from"
/// context into the "to" context.
///
/// \returns The equivalent declaration name in the "to" context, or the
/// import error.
llvm::Expected<DeclarationName> Import_New(DeclarationName FromName);
// FIXME: Remove this version.
DeclarationName Import(DeclarationName FromName);
llvm::Expected<DeclarationName> Import(DeclarationName FromName);
/// Import the given identifier from the "from" context
/// into the "to" context.
@ -320,46 +439,32 @@ class Attr;
///
/// \returns The equivalent selector in the "to" context, or the import
/// error.
llvm::Expected<Selector> Import_New(Selector FromSel);
// FIXME: Remove this version.
Selector Import(Selector FromSel);
llvm::Expected<Selector> Import(Selector FromSel);
/// Import the given file ID from the "from" context into the
/// "to" context.
///
/// \returns The equivalent file ID in the source manager of the "to"
/// context, or the import error.
llvm::Expected<FileID> Import_New(FileID);
// FIXME: Remove this version.
FileID Import(FileID);
llvm::Expected<FileID> Import(FileID, bool IsBuiltin = false);
/// Import the given C++ constructor initializer from the "from"
/// context into the "to" context.
///
/// \returns The equivalent initializer in the "to" context, or the import
/// error.
llvm::Expected<CXXCtorInitializer *>
Import_New(CXXCtorInitializer *FromInit);
// FIXME: Remove this version.
CXXCtorInitializer *Import(CXXCtorInitializer *FromInit);
llvm::Expected<CXXCtorInitializer *> Import(CXXCtorInitializer *FromInit);
/// Import the given CXXBaseSpecifier from the "from" context into
/// the "to" context.
///
/// \returns The equivalent CXXBaseSpecifier in the source manager of the
/// "to" context, or the import error.
llvm::Expected<CXXBaseSpecifier *>
Import_New(const CXXBaseSpecifier *FromSpec);
// FIXME: Remove this version.
CXXBaseSpecifier *Import(const CXXBaseSpecifier *FromSpec);
llvm::Expected<CXXBaseSpecifier *> Import(const CXXBaseSpecifier *FromSpec);
/// Import the definition of the given declaration, including all of
/// the declarations it contains.
LLVM_NODISCARD llvm::Error ImportDefinition_New(Decl *From);
// FIXME: Compatibility function.
// Usages of this should be changed to ImportDefinition_New.
void ImportDefinition(Decl *From);
LLVM_NODISCARD llvm::Error ImportDefinition(Decl *From);
/// Cope with a name conflict when importing a declaration into the
/// given context.
@ -422,9 +527,13 @@ class Attr;
/// Subclasses can override this function to observe all of the \c From ->
/// \c To declaration mappings as they are imported.
virtual Decl *Imported(Decl *From, Decl *To) { return To; }
virtual void Imported(Decl *From, Decl *To) {}
void RegisterImportedDecl(Decl *FromD, Decl *ToD);
/// Store and assign the imported declaration to its counterpart.
/// It may happen that several decls from the 'from' context are mapped to
/// the same decl in the 'to' context.
Decl *MapImported(Decl *From, Decl *To);
/// Called by StructuralEquivalenceContext. If a RecordDecl is
@ -435,6 +544,14 @@ class Attr;
/// importation, eliminating this loop.
virtual Decl *GetOriginalDecl(Decl *To) { return nullptr; }
/// Return if import of the given declaration has failed and if yes
/// the kind of the problem. This gives the first error encountered with
/// the node.
llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *FromD) const;
/// Mark (newly) imported declaration with error.
void setImportDeclError(Decl *From, ImportError Error);
/// Determine whether the given types are structurally
/// equivalent.
bool IsStructurallyEquivalent(QualType From, QualType To,
@ -445,7 +562,6 @@ class Attr;
/// \returns The index of the field in its parent context (starting from 0).
/// On error `None` is returned (parent context is non-record).
static llvm::Optional<unsigned> getFieldIndex(Decl *F);
};
} // namespace clang

View File

@ -1,9 +1,8 @@
//===- ASTImporterLookupTable.h - ASTImporter specific lookup--*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -0,0 +1,81 @@
//===- ASTImporterSharedState.h - ASTImporter specific state --*- C++ -*---===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the ASTImporter specific state, which may be shared
// amongst several ASTImporter objects.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
#define LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H
#include "clang/AST/ASTImporterLookupTable.h"
#include "clang/AST/Decl.h"
#include "llvm/ADT/DenseMap.h"
// FIXME We need this because of ImportError.
#include "clang/AST/ASTImporter.h"
namespace clang {
class TranslationUnitDecl;
/// Importer specific state, which may be shared amongst several ASTImporter
/// objects.
class ASTImporterSharedState {
/// Pointer to the import specific lookup table.
std::unique_ptr<ASTImporterLookupTable> LookupTable;
/// Mapping from the already-imported declarations in the "to"
/// context to the error status of the import of that declaration.
/// This map contains only the declarations that were not correctly
/// imported. The same declaration may or may not be included in
/// ImportedFromDecls. This map is updated continuously during imports and
/// never cleared (like ImportedFromDecls).
llvm::DenseMap<Decl *, ImportError> ImportErrors;
// FIXME put ImportedFromDecls here!
// And from that point we can better encapsulate the lookup table.
public:
ASTImporterSharedState() = default;
ASTImporterSharedState(TranslationUnitDecl &ToTU) {
LookupTable = llvm::make_unique<ASTImporterLookupTable>(ToTU);
}
ASTImporterLookupTable *getLookupTable() { return LookupTable.get(); }
void addDeclToLookup(Decl *D) {
if (LookupTable)
if (auto *ND = dyn_cast<NamedDecl>(D))
LookupTable->add(ND);
}
void removeDeclFromLookup(Decl *D) {
if (LookupTable)
if (auto *ND = dyn_cast<NamedDecl>(D))
LookupTable->remove(ND);
}
llvm::Optional<ImportError> getImportDeclErrorIfAny(Decl *ToD) const {
auto Pos = ImportErrors.find(ToD);
if (Pos != ImportErrors.end())
return Pos->second;
else
return Optional<ImportError>();
}
void setImportDeclError(Decl *To, ImportError Error) {
ImportErrors[To] = Error;
}
};
} // namespace clang
#endif // LLVM_CLANG_AST_ASTIMPORTERSHAREDSTATE_H

View File

@ -1,9 +1,8 @@
//===--- ASTLambda.h - Lambda Helper Functions --------------*- 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
//
//===----------------------------------------------------------------------===//
///

View File

@ -1,9 +1,8 @@
//===--- ASTMutationListener.h - AST Mutation Interface --------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -128,6 +127,11 @@ public:
virtual void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
const Attr *Attr) {}
/// A declaration is marked as a variable with OpenMP allocator.
///
/// \param D the declaration marked as a variable with OpenMP allocator.
virtual void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) {}
/// A definition has been made visible by being redefined locally.
///
/// \param D The definition that was previously not visible.

View File

@ -0,0 +1,654 @@
//===--- ASTNodeTraverser.h - Traversal of AST nodes ----------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file implements the AST traversal facilities. Other users
// of this class may make use of the same traversal logic by inheriting it,
// similar to RecursiveASTVisitor.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_ASTNODETRAVERSER_H
#define LLVM_CLANG_AST_ASTNODETRAVERSER_H
#include "clang/AST/AttrVisitor.h"
#include "clang/AST/CommentVisitor.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/LocInfoType.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/TemplateArgumentVisitor.h"
#include "clang/AST/TypeVisitor.h"
namespace clang {
/**
ASTNodeTraverser traverses the Clang AST for dumping purposes.
The `Derived::doGetNodeDelegate()` method is required to be an accessible member
which returns a reference of type `NodeDelegateType &` which implements the
following interface:
struct {
template <typename Fn> void AddChild(Fn DoAddChild);
template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild);
void Visit(const comments::Comment *C, const comments::FullComment *FC);
void Visit(const Attr *A);
void Visit(const TemplateArgument &TA, SourceRange R = {},
const Decl *From = nullptr, StringRef Label = {});
void Visit(const Stmt *Node);
void Visit(const Type *T);
void Visit(QualType T);
void Visit(const Decl *D);
void Visit(const CXXCtorInitializer *Init);
void Visit(const OMPClause *C);
void Visit(const BlockDecl::Capture &C);
void Visit(const GenericSelectionExpr::ConstAssociation &A);
};
*/
template <typename Derived, typename NodeDelegateType>
class ASTNodeTraverser
: public ConstDeclVisitor<Derived>,
public ConstStmtVisitor<Derived>,
public comments::ConstCommentVisitor<Derived, void,
const comments::FullComment *>,
public TypeVisitor<Derived>,
public ConstAttrVisitor<Derived>,
public ConstTemplateArgumentVisitor<Derived> {
/// Indicates whether we should trigger deserialization of nodes that had
/// not already been loaded.
bool Deserialize = false;
NodeDelegateType &getNodeDelegate() {
return getDerived().doGetNodeDelegate();
}
Derived &getDerived() { return *static_cast<Derived *>(this); }
public:
void setDeserialize(bool D) { Deserialize = D; }
bool getDeserialize() const { return Deserialize; }
void Visit(const Decl *D) {
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(D);
if (!D)
return;
ConstDeclVisitor<Derived>::Visit(D);
for (const auto &A : D->attrs())
Visit(A);
if (const comments::FullComment *Comment =
D->getASTContext().getLocalCommentForDeclUncached(D))
Visit(Comment, Comment);
// Decls within functions are visited by the body.
if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D)) {
if (const auto *DC = dyn_cast<DeclContext>(D))
dumpDeclContext(DC);
}
});
}
void Visit(const Stmt *S, StringRef Label = {}) {
getNodeDelegate().AddChild(Label, [=] {
getNodeDelegate().Visit(S);
if (!S) {
return;
}
ConstStmtVisitor<Derived>::Visit(S);
// Some statements have custom mechanisms for dumping their children.
if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S)) {
return;
}
for (const Stmt *SubStmt : S->children())
Visit(SubStmt);
});
}
void Visit(QualType T) {
SplitQualType SQT = T.split();
if (!SQT.Quals.hasQualifiers())
return Visit(SQT.Ty);
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(T);
Visit(T.split().Ty);
});
}
void Visit(const Type *T) {
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(T);
if (!T)
return;
TypeVisitor<Derived>::Visit(T);
QualType SingleStepDesugar =
T->getLocallyUnqualifiedSingleStepDesugaredType();
if (SingleStepDesugar != QualType(T, 0))
Visit(SingleStepDesugar);
});
}
void Visit(const Attr *A) {
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(A);
ConstAttrVisitor<Derived>::Visit(A);
});
}
void Visit(const CXXCtorInitializer *Init) {
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(Init);
Visit(Init->getInit());
});
}
void Visit(const TemplateArgument &A, SourceRange R = {},
const Decl *From = nullptr, const char *Label = nullptr) {
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(A, R, From, Label);
ConstTemplateArgumentVisitor<Derived>::Visit(A);
});
}
void Visit(const BlockDecl::Capture &C) {
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(C);
if (C.hasCopyExpr())
Visit(C.getCopyExpr());
});
}
void Visit(const OMPClause *C) {
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(C);
for (const auto *S : C->children())
Visit(S);
});
}
void Visit(const GenericSelectionExpr::ConstAssociation &A) {
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(A);
if (const TypeSourceInfo *TSI = A.getTypeSourceInfo())
Visit(TSI->getType());
Visit(A.getAssociationExpr());
});
}
void Visit(const comments::Comment *C, const comments::FullComment *FC) {
getNodeDelegate().AddChild([=] {
getNodeDelegate().Visit(C, FC);
if (!C) {
return;
}
comments::ConstCommentVisitor<Derived, void,
const comments::FullComment *>::visit(C,
FC);
for (comments::Comment::child_iterator I = C->child_begin(),
E = C->child_end();
I != E; ++I)
Visit(*I, FC);
});
}
void Visit(const ast_type_traits::DynTypedNode &N) {
// FIXME: Improve this with a switch or a visitor pattern.
if (const auto *D = N.get<Decl>())
Visit(D);
else if (const auto *S = N.get<Stmt>())
Visit(S);
else if (const auto *QT = N.get<QualType>())
Visit(*QT);
else if (const auto *T = N.get<Type>())
Visit(T);
else if (const auto *C = N.get<CXXCtorInitializer>())
Visit(C);
else if (const auto *C = N.get<OMPClause>())
Visit(C);
else if (const auto *T = N.get<TemplateArgument>())
Visit(*T);
}
void dumpDeclContext(const DeclContext *DC) {
if (!DC)
return;
for (const auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Visit(D);
}
void dumpTemplateParameters(const TemplateParameterList *TPL) {
if (!TPL)
return;
for (const auto &TP : *TPL)
Visit(TP);
}
void
dumpASTTemplateArgumentListInfo(const ASTTemplateArgumentListInfo *TALI) {
if (!TALI)
return;
for (const auto &TA : TALI->arguments())
dumpTemplateArgumentLoc(TA);
}
void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A,
const Decl *From = nullptr,
const char *Label = nullptr) {
Visit(A.getArgument(), A.getSourceRange(), From, Label);
}
void dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
for (unsigned i = 0, e = TAL.size(); i < e; ++i)
Visit(TAL[i]);
}
void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
if (!typeParams)
return;
for (const auto &typeParam : *typeParams) {
Visit(typeParam);
}
}
void VisitComplexType(const ComplexType *T) { Visit(T->getElementType()); }
void VisitLocInfoType(const LocInfoType *T) {
Visit(T->getTypeSourceInfo()->getType());
}
void VisitPointerType(const PointerType *T) { Visit(T->getPointeeType()); }
void VisitBlockPointerType(const BlockPointerType *T) {
Visit(T->getPointeeType());
}
void VisitReferenceType(const ReferenceType *T) {
Visit(T->getPointeeType());
}
void VisitMemberPointerType(const MemberPointerType *T) {
Visit(T->getClass());
Visit(T->getPointeeType());
}
void VisitArrayType(const ArrayType *T) { Visit(T->getElementType()); }
void VisitVariableArrayType(const VariableArrayType *T) {
VisitArrayType(T);
Visit(T->getSizeExpr());
}
void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
Visit(T->getElementType());
Visit(T->getSizeExpr());
}
void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T) {
Visit(T->getElementType());
Visit(T->getSizeExpr());
}
void VisitVectorType(const VectorType *T) { Visit(T->getElementType()); }
void VisitFunctionType(const FunctionType *T) { Visit(T->getReturnType()); }
void VisitFunctionProtoType(const FunctionProtoType *T) {
VisitFunctionType(T);
for (const QualType &PT : T->getParamTypes())
Visit(PT);
}
void VisitTypeOfExprType(const TypeOfExprType *T) {
Visit(T->getUnderlyingExpr());
}
void VisitDecltypeType(const DecltypeType *T) {
Visit(T->getUnderlyingExpr());
}
void VisitUnaryTransformType(const UnaryTransformType *T) {
Visit(T->getBaseType());
}
void VisitAttributedType(const AttributedType *T) {
// FIXME: AttrKind
Visit(T->getModifiedType());
}
void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
Visit(T->getReplacedParameter());
}
void
VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T) {
Visit(T->getReplacedParameter());
Visit(T->getArgumentPack());
}
void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
for (const auto &Arg : *T)
Visit(Arg);
if (T->isTypeAlias())
Visit(T->getAliasedType());
}
void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
Visit(T->getPointeeType());
}
void VisitAtomicType(const AtomicType *T) { Visit(T->getValueType()); }
void VisitPipeType(const PipeType *T) { Visit(T->getElementType()); }
void VisitAdjustedType(const AdjustedType *T) { Visit(T->getOriginalType()); }
void VisitPackExpansionType(const PackExpansionType *T) {
if (!T->isSugared())
Visit(T->getPattern());
}
// FIXME: ElaboratedType, DependentNameType,
// DependentTemplateSpecializationType, ObjCObjectType
void VisitTypedefDecl(const TypedefDecl *D) { Visit(D->getUnderlyingType()); }
void VisitEnumConstantDecl(const EnumConstantDecl *D) {
if (const Expr *Init = D->getInitExpr())
Visit(Init);
}
void VisitFunctionDecl(const FunctionDecl *D) {
if (const auto *FTSI = D->getTemplateSpecializationInfo())
dumpTemplateArgumentList(*FTSI->TemplateArguments);
if (D->param_begin())
for (const auto *Parameter : D->parameters())
Visit(Parameter);
if (const auto *C = dyn_cast<CXXConstructorDecl>(D))
for (const auto *I : C->inits())
Visit(I);
if (D->doesThisDeclarationHaveABody())
Visit(D->getBody());
}
void VisitFieldDecl(const FieldDecl *D) {
if (D->isBitField())
Visit(D->getBitWidth());
if (Expr *Init = D->getInClassInitializer())
Visit(Init);
}
void VisitVarDecl(const VarDecl *D) {
if (D->hasInit())
Visit(D->getInit());
}
void VisitDecompositionDecl(const DecompositionDecl *D) {
VisitVarDecl(D);
for (const auto *B : D->bindings())
Visit(B);
}
void VisitBindingDecl(const BindingDecl *D) {
if (const auto *E = D->getBinding())
Visit(E);
}
void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Visit(D->getAsmString());
}
void VisitCapturedDecl(const CapturedDecl *D) { Visit(D->getBody()); }
void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
for (const auto *E : D->varlists())
Visit(E);
}
void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
Visit(D->getCombiner());
if (const auto *Initializer = D->getInitializer())
Visit(Initializer);
}
void VisitOMPDeclareMapperDecl(const OMPDeclareMapperDecl *D) {
for (const auto *C : D->clauselists())
Visit(C);
}
void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
Visit(D->getInit());
}
void VisitOMPAllocateDecl(const OMPAllocateDecl *D) {
for (const auto *E : D->varlists())
Visit(E);
for (const auto *C : D->clauselists())
Visit(C);
}
template <typename SpecializationDecl>
void dumpTemplateDeclSpecialization(const SpecializationDecl *D) {
for (const auto *RedeclWithBadType : D->redecls()) {
// FIXME: The redecls() range sometimes has elements of a less-specific
// type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
// us TagDecls, and should give CXXRecordDecls).
auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
if (!Redecl) {
// Found the injected-class-name for a class template. This will be
// dumped as part of its surrounding class so we don't need to dump it
// here.
assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
"expected an injected-class-name");
continue;
}
Visit(Redecl);
}
}
template <typename TemplateDecl>
void dumpTemplateDecl(const TemplateDecl *D) {
dumpTemplateParameters(D->getTemplateParameters());
Visit(D->getTemplatedDecl());
for (const auto *Child : D->specializations())
dumpTemplateDeclSpecialization(Child);
}
void VisitTypeAliasDecl(const TypeAliasDecl *D) {
Visit(D->getUnderlyingType());
}
void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
dumpTemplateParameters(D->getTemplateParameters());
Visit(D->getTemplatedDecl());
}
void VisitStaticAssertDecl(const StaticAssertDecl *D) {
Visit(D->getAssertExpr());
Visit(D->getMessage());
}
void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
dumpTemplateDecl(D);
}
void VisitClassTemplateDecl(const ClassTemplateDecl *D) {
dumpTemplateDecl(D);
}
void VisitClassTemplateSpecializationDecl(
const ClassTemplateSpecializationDecl *D) {
dumpTemplateArgumentList(D->getTemplateArgs());
}
void VisitClassTemplatePartialSpecializationDecl(
const ClassTemplatePartialSpecializationDecl *D) {
VisitClassTemplateSpecializationDecl(D);
dumpTemplateParameters(D->getTemplateParameters());
}
void VisitClassScopeFunctionSpecializationDecl(
const ClassScopeFunctionSpecializationDecl *D) {
Visit(D->getSpecialization());
dumpASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
}
void VisitVarTemplateDecl(const VarTemplateDecl *D) { dumpTemplateDecl(D); }
void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
dumpTemplateParameters(D->getTemplateParameters());
}
void
VisitVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl *D) {
dumpTemplateArgumentList(D->getTemplateArgs());
VisitVarDecl(D);
}
void VisitVarTemplatePartialSpecializationDecl(
const VarTemplatePartialSpecializationDecl *D) {
dumpTemplateParameters(D->getTemplateParameters());
VisitVarTemplateSpecializationDecl(D);
}
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
if (D->hasDefaultArgument())
Visit(D->getDefaultArgument(), SourceRange(),
D->getDefaultArgStorage().getInheritedFrom(),
D->defaultArgumentWasInherited() ? "inherited from" : "previous");
}
void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
if (D->hasDefaultArgument())
Visit(D->getDefaultArgument(), SourceRange(),
D->getDefaultArgStorage().getInheritedFrom(),
D->defaultArgumentWasInherited() ? "inherited from" : "previous");
}
void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) {
dumpTemplateParameters(D->getTemplateParameters());
if (D->hasDefaultArgument())
dumpTemplateArgumentLoc(
D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(),
D->defaultArgumentWasInherited() ? "inherited from" : "previous");
}
void VisitConceptDecl(const ConceptDecl *D) {
dumpTemplateParameters(D->getTemplateParameters());
Visit(D->getConstraintExpr());
}
void VisitUsingShadowDecl(const UsingShadowDecl *D) {
if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
Visit(TD->getTypeForDecl());
}
void VisitFriendDecl(const FriendDecl *D) {
if (!D->getFriendType())
Visit(D->getFriendDecl());
}
void VisitObjCMethodDecl(const ObjCMethodDecl *D) {
if (D->isThisDeclarationADefinition())
dumpDeclContext(D);
else
for (const ParmVarDecl *Parameter : D->parameters())
Visit(Parameter);
if (D->hasBody())
Visit(D->getBody());
}
void VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
dumpObjCTypeParamList(D->getTypeParamList());
}
void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
dumpObjCTypeParamList(D->getTypeParamListAsWritten());
}
void VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
for (const auto &I : D->inits())
Visit(I);
}
void VisitBlockDecl(const BlockDecl *D) {
for (const auto &I : D->parameters())
Visit(I);
for (const auto &I : D->captures())
Visit(I);
Visit(D->getBody());
}
void VisitDeclStmt(const DeclStmt *Node) {
for (const auto &D : Node->decls())
Visit(D);
}
void VisitAttributedStmt(const AttributedStmt *Node) {
for (const auto *A : Node->getAttrs())
Visit(A);
}
void VisitCXXCatchStmt(const CXXCatchStmt *Node) {
Visit(Node->getExceptionDecl());
}
void VisitCapturedStmt(const CapturedStmt *Node) {
Visit(Node->getCapturedDecl());
}
void VisitOMPExecutableDirective(const OMPExecutableDirective *Node) {
for (const auto *C : Node->clauses())
Visit(C);
}
void VisitInitListExpr(const InitListExpr *ILE) {
if (auto *Filler = ILE->getArrayFiller()) {
Visit(Filler, "array_filler");
}
}
void VisitBlockExpr(const BlockExpr *Node) { Visit(Node->getBlockDecl()); }
void VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
if (Expr *Source = Node->getSourceExpr())
Visit(Source);
}
void VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
Visit(E->getControllingExpr());
Visit(E->getControllingExpr()->getType()); // FIXME: remove
for (const auto &Assoc : E->associations()) {
Visit(Assoc);
}
}
void VisitLambdaExpr(const LambdaExpr *Node) {
Visit(Node->getLambdaClass());
}
void VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
if (Node->isPartiallySubstituted())
for (const auto &A : Node->getPartialArguments())
Visit(A);
}
void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Visit(CatchParam);
}
void VisitExpressionTemplateArgument(const TemplateArgument &TA) {
Visit(TA.getAsExpr());
}
void VisitPackTemplateArgument(const TemplateArgument &TA) {
for (const auto &TArg : TA.pack_elements())
Visit(TArg);
}
// Implements Visit methods for Attrs.
#include "clang/AST/AttrNodeTraverse.inc"
};
} // namespace clang
#endif // LLVM_CLANG_AST_ASTNODETRAVERSER_H

View File

@ -1,9 +1,8 @@
//===- ASTStructuralEquivalence.h -------------------------------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -112,6 +111,10 @@ struct StructuralEquivalenceContext {
static llvm::Optional<unsigned>
findUntaggedStructOrUnionIndex(RecordDecl *Anon);
// If ErrorOnTagTypeMismatch is set, return the the error, otherwise get the
// relevant warning for the input error diagnostic.
unsigned getApplicableDiagnostic(unsigned ErrorDiagnostic);
private:
/// Finish checking all of the structural equivalences.
///

View File

@ -1,9 +1,8 @@
//===--- ASTTypeTraits.h ----------------------------------------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -19,6 +18,7 @@
#include "clang/AST/ASTFwd.h"
#include "clang/AST/Decl.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/OpenMPClause.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/TypeLoc.h"
@ -38,6 +38,17 @@ struct PrintingPolicy;
namespace ast_type_traits {
/// Defines how we descend a level in the AST when we pass
/// through expressions.
enum TraversalKind {
/// Will traverse all child nodes.
TK_AsIs,
/// Will not traverse implicit casts and parentheses.
/// Corresponds to Expr::IgnoreParenImpCasts()
TK_IgnoreImplicitCastsAndParentheses
};
/// Kind identifier.
///
/// It can be constructed from any node kind and allows for runtime type
@ -59,6 +70,7 @@ public:
static ASTNodeKind getFromNode(const Decl &D);
static ASTNodeKind getFromNode(const Stmt &S);
static ASTNodeKind getFromNode(const Type &T);
static ASTNodeKind getFromNode(const OMPClause &C);
/// \}
/// Returns \c true if \c this and \c Other represent the same kind.
@ -137,6 +149,9 @@ private:
NKI_Type,
#define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
#include "clang/AST/TypeNodes.def"
NKI_OMPClause,
#define OPENMP_CLAUSE(TextualSpelling, Class) NKI_##Class,
#include "clang/Basic/OpenMPKinds.def"
NKI_NumberOfKinds
};
@ -184,12 +199,15 @@ KIND_TO_KIND_ID(TypeLoc)
KIND_TO_KIND_ID(Decl)
KIND_TO_KIND_ID(Stmt)
KIND_TO_KIND_ID(Type)
KIND_TO_KIND_ID(OMPClause)
#define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl)
#include "clang/AST/DeclNodes.inc"
#define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED)
#include "clang/AST/StmtNodes.inc"
#define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
#include "clang/AST/TypeNodes.def"
#define OPENMP_CLAUSE(TextualSpelling, Class) KIND_TO_KIND_ID(Class)
#include "clang/Basic/OpenMPKinds.def"
#undef KIND_TO_KIND_ID
inline raw_ostream &operator<<(raw_ostream &OS, ASTNodeKind K) {
@ -460,6 +478,11 @@ struct DynTypedNode::BaseConverter<
T, typename std::enable_if<std::is_base_of<Type, T>::value>::type>
: public DynCastPtrConverter<T, Type> {};
template <typename T>
struct DynTypedNode::BaseConverter<
T, typename std::enable_if<std::is_base_of<OMPClause, T>::value>::type>
: public DynCastPtrConverter<T, OMPClause> {};
template <>
struct DynTypedNode::BaseConverter<
NestedNameSpecifier, void> : public PtrConverter<NestedNameSpecifier> {};

View File

@ -1,9 +1,8 @@
//===- ASTUnresolvedSet.h - Unresolved sets of declarations -----*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- ASTVector.h - Vector that uses ASTContext for allocation ---*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- Attr.h - Classes for representing attributes ----------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- AttrIterator.h - Classes for attribute iteration ---------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- AttrVisitor.h - Visitor for Attr subclasses --------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- Availability.h - Classes for availability --------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- BaseSubobject.h - BaseSubobject class --------------------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -81,11 +80,6 @@ template<> struct DenseMapInfo<clang::BaseSubobject> {
}
};
// It's OK to treat BaseSubobject as a POD type.
template <> struct isPodLike<clang::BaseSubobject> {
static const bool value = true;
};
} // namespace llvm
#endif // LLVM_CLANG_AST_BASESUBOBJECT_H

View File

@ -1,9 +1,8 @@
//===-- BuiltinTypes.def - Metadata about BuiltinTypes ----------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- CXXInheritance.h - C++ Inheritance -----------------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- CanonicalType.h - C Language Family Type Representation --*- 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
//
//===----------------------------------------------------------------------===//
//
@ -510,7 +509,7 @@ struct CanProxyAdaptor<FunctionProtoType>
}
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVariadic)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Qualifiers, getTypeQuals)
LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(Qualifiers, getMethodQuals)
using param_type_iterator =
CanTypeIterator<FunctionProtoType::param_type_iterator>;

View File

@ -1,9 +1,8 @@
//===--- CharUnits.h - Character units for sizes and offsets ----*- 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
//
//===----------------------------------------------------------------------===//
//
@ -238,10 +237,6 @@ template<> struct DenseMapInfo<clang::CharUnits> {
}
};
template <> struct isPodLike<clang::CharUnits> {
static const bool value = true;
};
} // end namespace llvm
#endif // LLVM_CLANG_AST_CHARUNITS_H

View File

@ -1,9 +1,8 @@
//===--- Comment.h - Comment AST nodes --------------------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- CommentBriefParser.h - Dumb comment parser -------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- CommentCommandTraits.h - Comment command properties ----*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- CommentDiagnostic.h - Diagnostics for the AST library --*- 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
//
//===----------------------------------------------------------------------===//

View File

@ -1,9 +1,8 @@
//===--- CommentLexer.h - Lexer for structured comments ---------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- CommentParser.h - Doxygen comment parser ---------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- CommentSema.h - Doxygen comment semantic analysis ------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- CommentVisitor.h - Visitor for Comment subclasses --------*- 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
//
//===----------------------------------------------------------------------===//

View File

@ -1,9 +1,8 @@
//===- ComparisonCategories.h - Three Way Comparison Data -------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -0,0 +1,75 @@
//===--- CurrentSourceLocExprScope.h ----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines types used to track the current context needed to evaluate
// a SourceLocExpr.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H
#define LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H
#include <cassert>
namespace clang {
class Expr;
/// Represents the current source location and context used to determine the
/// value of the source location builtins (ex. __builtin_LINE), including the
/// context of default argument and default initializer expressions.
class CurrentSourceLocExprScope {
/// The CXXDefaultArgExpr or CXXDefaultInitExpr we're currently evaluating.
const Expr *DefaultExpr = nullptr;
public:
/// A RAII style scope guard used for tracking the current source
/// location and context as used by the source location builtins
/// (ex. __builtin_LINE).
class SourceLocExprScopeGuard;
const Expr *getDefaultExpr() const { return DefaultExpr; }
explicit CurrentSourceLocExprScope() = default;
private:
explicit CurrentSourceLocExprScope(const Expr *DefaultExpr)
: DefaultExpr(DefaultExpr) {}
CurrentSourceLocExprScope(CurrentSourceLocExprScope const &) = default;
CurrentSourceLocExprScope &
operator=(CurrentSourceLocExprScope const &) = default;
};
class CurrentSourceLocExprScope::SourceLocExprScopeGuard {
public:
SourceLocExprScopeGuard(const Expr *DefaultExpr,
CurrentSourceLocExprScope &Current)
: Current(Current), OldVal(Current), Enable(false) {
assert(DefaultExpr && "the new scope should not be empty");
if ((Enable = (Current.getDefaultExpr() == nullptr)))
Current = CurrentSourceLocExprScope(DefaultExpr);
}
~SourceLocExprScopeGuard() {
if (Enable)
Current = OldVal;
}
private:
SourceLocExprScopeGuard(SourceLocExprScopeGuard const &) = delete;
SourceLocExprScopeGuard &operator=(SourceLocExprScopeGuard const &) = delete;
CurrentSourceLocExprScope &Current;
CurrentSourceLocExprScope OldVal;
bool Enable;
};
} // end namespace clang
#endif // LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H

View File

@ -1,9 +1,8 @@
//===--- DatatCollection.h --------------------------------------*- 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
//
//===----------------------------------------------------------------------===//
/// \file

View File

@ -1,9 +1,8 @@
//===- Decl.h - Classes for representing declarations -----------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -1227,10 +1226,15 @@ public:
void setInit(Expr *I);
/// Determine whether this variable's value can be used in a
/// Determine whether this variable's value might be usable in a
/// constant expression, according to the relevant language standard.
/// This only checks properties of the declaration, and does not check
/// whether the initializer is in fact a constant expression.
bool mightBeUsableInConstantExpressions(ASTContext &C) const;
/// Determine whether this variable's value can be used in a
/// constant expression, according to the relevant language standard,
/// including checking whether it was initialized by a constant expression.
bool isUsableInConstantExpressions(ASTContext &C) const;
EvaluatedStmt *ensureEvaluatedStmt() const;
@ -1396,6 +1400,10 @@ public:
NonParmVarDeclBits.IsInitCapture = IC;
}
/// Determine whether this variable is actually a function parameter pack or
/// init-capture pack.
bool isParameterPack() const;
/// Whether this local extern variable declaration's previous declaration
/// was declared in the same block scope. Only correct in C++.
bool isPreviousDeclInSameBlockScope() const {
@ -1435,6 +1443,12 @@ public:
/// template specialization or instantiation this is.
TemplateSpecializationKind getTemplateSpecializationKind() const;
/// Get the template specialization kind of this variable for the purposes of
/// template instantiation. This differs from getTemplateSpecializationKind()
/// for an instantiation of a class-scope explicit specialization.
TemplateSpecializationKind
getTemplateSpecializationKindForInstantiation() const;
/// If this variable is an instantiation of a variable template or a
/// static data member of a class template, determine its point of
/// instantiation.
@ -1683,10 +1697,6 @@ public:
QualType getOriginalType() const;
/// Determine whether this parameter is actually a function
/// parameter pack.
bool isParameterPack() const;
/// Sets the function declaration that owns this
/// ParmVarDecl. Since ParmVarDecls are often created before the
/// FunctionDecls that own them, this routine is required to update
@ -1743,10 +1753,19 @@ class FunctionDecl : public DeclaratorDecl,
public:
/// The kind of templated function a FunctionDecl can be.
enum TemplatedKind {
// Not templated.
TK_NonTemplate,
// The pattern in a function template declaration.
TK_FunctionTemplate,
// A non-template function that is an instantiation or explicit
// specialization of a member of a templated class.
TK_MemberSpecialization,
// An instantiation or explicit specialization of a function template.
// Note: this might have been instantiated from a templated class if it
// is a class-scope explicit specialization.
TK_FunctionTemplateSpecialization,
// A function template specialization that hasn't yet been resolved to a
// particular specialized function template.
TK_DependentFunctionTemplateSpecialization
};
@ -1842,7 +1861,7 @@ protected:
FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified,
bool isConstexprSpecified);
ConstexprSpecKind ConstexprKind);
using redeclarable_base = Redeclarable<FunctionDecl>;
@ -1872,29 +1891,24 @@ public:
using redeclarable_base::getMostRecentDecl;
using redeclarable_base::isFirstDecl;
static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc, SourceLocation NLoc,
DeclarationName N, QualType T,
TypeSourceInfo *TInfo,
StorageClass SC,
bool isInlineSpecified = false,
bool hasWrittenPrototype = true,
bool isConstexprSpecified = false) {
static FunctionDecl *
Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
SourceLocation NLoc, DeclarationName N, QualType T,
TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified = false,
bool hasWrittenPrototype = true,
ConstexprSpecKind ConstexprKind = CSK_unspecified) {
DeclarationNameInfo NameInfo(N, NLoc);
return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo,
SC,
return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
isInlineSpecified, hasWrittenPrototype,
isConstexprSpecified);
ConstexprKind);
}
static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
StorageClass SC,
bool isInlineSpecified,
bool hasWrittenPrototype,
bool isConstexprSpecified = false);
const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, StorageClass SC,
bool isInlineSpecified, bool hasWrittenPrototype,
ConstexprSpecKind ConstexprKind);
static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
@ -2091,8 +2105,21 @@ public:
}
/// Whether this is a (C++11) constexpr function or constexpr constructor.
bool isConstexpr() const { return FunctionDeclBits.IsConstexpr; }
void setConstexpr(bool IC) { FunctionDeclBits.IsConstexpr = IC; }
bool isConstexpr() const {
return FunctionDeclBits.ConstexprKind != CSK_unspecified;
}
void setConstexprKind(ConstexprSpecKind CSK) {
FunctionDeclBits.ConstexprKind = CSK;
}
ConstexprSpecKind getConstexprKind() const {
return static_cast<ConstexprSpecKind>(FunctionDeclBits.ConstexprKind);
}
bool isConstexprSpecified() const {
return FunctionDeclBits.ConstexprKind == CSK_constexpr;
}
bool isConsteval() const {
return FunctionDeclBits.ConstexprKind == CSK_consteval;
}
/// Whether the instantiation of this function is pending.
/// This bit is set when the decision to instantiate this function is made
@ -2256,7 +2283,7 @@ public:
return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
}
unsigned getBuiltinID() const;
unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const;
// ArrayRef interface to parameters.
ArrayRef<ParmVarDecl *> parameters() const {
@ -2316,6 +2343,14 @@ public:
return T->castAs<FunctionType>()->getReturnType();
}
/// Gets the ExceptionSpecificationType as declared.
ExceptionSpecificationType getExceptionSpecType() const {
auto *TSI = getTypeSourceInfo();
QualType T = TSI ? TSI->getType() : getType();
const auto *FPT = T->getAs<FunctionProtoType>();
return FPT ? FPT->getExceptionSpecType() : EST_None;
}
/// Attempt to compute an informative source range covering the
/// function exception specification, if any.
SourceRange getExceptionSpecSourceRange() const;
@ -2355,22 +2390,14 @@ public:
/// that was defined in the class body.
bool isInlined() const { return FunctionDeclBits.IsInline; }
/// Whether this function is marked as explicit explicitly.
bool isExplicitSpecified() const {
return FunctionDeclBits.IsExplicitSpecified;
}
/// State that this function is marked as explicit explicitly.
void setExplicitSpecified(bool ExpSpec = true) {
FunctionDeclBits.IsExplicitSpecified = ExpSpec;
}
bool isInlineDefinitionExternallyVisible() const;
bool isMSExternInline() const;
bool doesDeclarationForceExternallyVisibleDefinition() const;
bool isStatic() const { return getStorageClass() == SC_Static; }
/// Whether this function declaration represents an C++ overloaded
/// operator, e.g., "operator+".
bool isOverloadedOperator() const {
@ -2441,10 +2468,6 @@ public:
return getPrimaryTemplate() != nullptr;
}
/// Retrieve the class scope template pattern that this function
/// template specialization is instantiated from.
FunctionDecl *getClassScopeSpecializationPattern() const;
/// If this function is actually a function template specialization,
/// retrieve information about this function template specialization.
/// Otherwise, returns NULL.
@ -2531,6 +2554,11 @@ public:
/// represents.
TemplateSpecializationKind getTemplateSpecializationKind() const;
/// Determine the kind of template specialization this function represents
/// for the purpose of template instantiation.
TemplateSpecializationKind
getTemplateSpecializationKindForInstantiation() const;
/// Determine what kind of template instantiation this function
/// represents.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
@ -2703,6 +2731,11 @@ public:
/// bit-fields.
bool isZeroLengthBitField(const ASTContext &Ctx) const;
/// Determine if this field is a subobject of zero size, that is, either a
/// zero-length bit-field or a field of empty class type with the
/// [[no_unique_address]] attribute.
bool isZeroSize(const ASTContext &Ctx) const;
/// Get the kind of (C++11) default member initializer that this field has.
InClassInitStyle getInClassInitStyle() const {
InitStorageKind storageKind = InitStorage.getInt();
@ -3713,6 +3746,30 @@ public:
RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
}
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const {
return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
}
void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V) {
RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
}
bool hasNonTrivialToPrimitiveDestructCUnion() const {
return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
}
void setHasNonTrivialToPrimitiveDestructCUnion(bool V) {
RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
}
bool hasNonTrivialToPrimitiveCopyCUnion() const {
return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
}
void setHasNonTrivialToPrimitiveCopyCUnion(bool V) {
RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
}
/// Determine whether this class can be passed in registers. In C++ mode,
/// it must have at least one trivial, non-deleted copy or move constructor.
/// FIXME: This should be set as part of completeDefinition.
@ -3852,7 +3909,7 @@ public:
static bool classofKind(Kind K) { return K == FileScopeAsm; }
};
/// Pepresents a block literal declaration, which is like an
/// Represents a block literal declaration, which is like an
/// unnamed FunctionDecl. For example:
/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
class BlockDecl : public Decl, public DeclContext {
@ -4009,6 +4066,13 @@ public:
bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
bool canAvoidCopyToHeap() const {
return BlockDeclBits.CanAvoidCopyToHeap;
}
void setCanAvoidCopyToHeap(bool B = true) {
BlockDeclBits.CanAvoidCopyToHeap = B;
}
bool capturesVariable(const VarDecl *var) const;
void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
@ -4233,8 +4297,10 @@ public:
SourceLocation getRBraceLoc() const { return RBraceLoc; }
void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
bool hasBraces() const { return RBraceLoc.isValid(); }
SourceLocation getEndLoc() const LLVM_READONLY {
if (RBraceLoc.isValid())
if (hasBraces())
return RBraceLoc;
// No braces: get the end location of the (only) declaration in context
// (if present).

View File

@ -1,9 +1,8 @@
//===--- DeclAccessPair.h - A decl bundled with its path access -*- 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
//
//===----------------------------------------------------------------------===//
//
@ -61,12 +60,4 @@ public:
};
}
// Take a moment to tell SmallVector that DeclAccessPair is POD.
namespace llvm {
template<typename> struct isPodLike;
template<> struct isPodLike<clang::DeclAccessPair> {
static const bool value = true;
};
}
#endif

View File

@ -1,9 +1,8 @@
//===- DeclBase.h - Base Classes for representing declarations --*- 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
//
//===----------------------------------------------------------------------===//
//
@ -14,6 +13,7 @@
#ifndef LLVM_CLANG_AST_DECLBASE_H
#define LLVM_CLANG_AST_DECLBASE_H
#include "clang/AST/ASTDumperUtils.h"
#include "clang/AST/AttrIterator.h"
#include "clang/AST/DeclarationName.h"
#include "clang/Basic/IdentifierTable.h"
@ -42,6 +42,7 @@ namespace clang {
class ASTContext;
class ASTMutationListener;
class Attr;
class BlockDecl;
class DeclContext;
class ExternalSourceSymbolAttr;
class FunctionDecl;
@ -176,7 +177,10 @@ public:
IDNS_LocalExtern = 0x0800,
/// This declaration is an OpenMP user defined reduction construction.
IDNS_OMPReduction = 0x1000
IDNS_OMPReduction = 0x1000,
/// This declaration is an OpenMP user defined mapper.
IDNS_OMPMapper = 0x2000,
};
/// ObjCDeclQualifier - 'Qualifiers' written next to the return and
@ -324,7 +328,7 @@ protected:
unsigned FromASTFile : 1;
/// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
unsigned IdentifierNamespace : 13;
unsigned IdentifierNamespace : 14;
/// If 0, we have not computed the linkage of this declaration.
/// Otherwise, it is the linkage + 1.
@ -364,6 +368,13 @@ private:
return ModuleOwnershipKind::Unowned;
}
public:
Decl() = delete;
Decl(const Decl&) = delete;
Decl(Decl &&) = delete;
Decl &operator=(const Decl&) = delete;
Decl &operator=(Decl&&) = delete;
protected:
Decl(Kind DK, DeclContext *DC, SourceLocation L)
: NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
@ -597,10 +608,6 @@ public:
return getModuleOwnershipKind() == ModuleOwnershipKind::ModulePrivate;
}
/// Whether this declaration is exported (by virtue of being lexically
/// within an ExportDecl or by being a NamespaceDecl).
bool isExported() const;
/// Return true if this declaration has an attribute which acts as
/// definition of the entity, such as 'alias' or 'ifunc'.
bool hasDefiningAttr() const;
@ -1135,7 +1142,8 @@ public:
// Same as dump(), but forces color printing.
void dumpColor() const;
void dump(raw_ostream &Out, bool Deserialize = false) const;
void dump(raw_ostream &Out, bool Deserialize = false,
ASTDumpOutputFormat OutputFormat = ADOF_Default) const;
/// \return Unique reproducible object identifier
int64_t getID() const;
@ -1252,6 +1260,7 @@ public:
/// NamespaceDecl
/// TagDecl
/// OMPDeclareReductionDecl
/// OMPDeclareMapperDecl
/// FunctionDecl
/// ObjCMethodDecl
/// ObjCContainerDecl
@ -1431,6 +1440,13 @@ class DeclContext {
uint64_t NonTrivialToPrimitiveCopy : 1;
uint64_t NonTrivialToPrimitiveDestroy : 1;
/// The following bits indicate whether this is or contains a C union that
/// is non-trivial to default-initialize, destruct, or copy. These bits
/// imply the associated basic non-triviality predicates declared above.
uint64_t HasNonTrivialToPrimitiveDefaultInitializeCUnion : 1;
uint64_t HasNonTrivialToPrimitiveDestructCUnion : 1;
uint64_t HasNonTrivialToPrimitiveCopyCUnion : 1;
/// Indicates whether this struct is destroyed in the callee.
uint64_t ParamDestroyedInCallee : 1;
@ -1439,7 +1455,7 @@ class DeclContext {
};
/// Number of non-inherited bits in RecordDeclBitfields.
enum { NumRecordDeclBits = 11 };
enum { NumRecordDeclBits = 14 };
/// Stores the bits used by OMPDeclareReductionDecl.
/// If modified NumOMPDeclareReductionDeclBits and the accessor
@ -1472,10 +1488,6 @@ class DeclContext {
uint64_t IsInline : 1;
uint64_t IsInlineSpecified : 1;
/// This is shared by CXXConstructorDecl,
/// CXXConversionDecl, and CXXDeductionGuideDecl.
uint64_t IsExplicitSpecified : 1;
uint64_t IsVirtualAsWritten : 1;
uint64_t IsPure : 1;
uint64_t HasInheritedPrototype : 1;
@ -1495,7 +1507,9 @@ class DeclContext {
uint64_t IsExplicitlyDefaulted : 1;
uint64_t HasImplicitReturnZero : 1;
uint64_t IsLateTemplateParsed : 1;
uint64_t IsConstexpr : 1;
/// Kind of contexpr specifier as defined by ConstexprSpecKind.
uint64_t ConstexprKind : 2;
uint64_t InstantiationIsPending : 1;
/// Indicates if the function uses __try.
@ -1535,17 +1549,25 @@ class DeclContext {
/// For the bits in FunctionDeclBitfields.
uint64_t : NumFunctionDeclBits;
/// 25 bits to fit in the remaining availible space.
/// 24 bits to fit in the remaining available space.
/// Note that this makes CXXConstructorDeclBitfields take
/// exactly 64 bits and thus the width of NumCtorInitializers
/// will need to be shrunk if some bit is added to NumDeclContextBitfields,
/// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
uint64_t NumCtorInitializers : 25;
uint64_t NumCtorInitializers : 23;
uint64_t IsInheritingConstructor : 1;
/// Whether this constructor has a trail-allocated explicit specifier.
uint64_t HasTrailingExplicitSpecifier : 1;
/// If this constructor does't have a trail-allocated explicit specifier.
/// Whether this constructor is explicit specified.
uint64_t IsSimpleExplicit : 1;
};
/// Number of non-inherited bits in CXXConstructorDeclBitfields.
enum { NumCXXConstructorDeclBits = 26 };
enum {
NumCXXConstructorDeclBits = 64 - NumDeclContextBits - NumFunctionDeclBits
};
/// Stores the bits used by ObjCMethodDecl.
/// If modified NumObjCMethodDeclBits and the accessor
@ -1662,6 +1684,11 @@ class DeclContext {
/// A bit that indicates this block is passed directly to a function as a
/// non-escaping parameter.
uint64_t DoesNotEscape : 1;
/// A bit that indicates whether it's possible to avoid coying this block to
/// the heap when it initializes or is assigned to a local variable with
/// automatic storage.
uint64_t CanAvoidCopyToHeap : 1;
};
/// Number of non-inherited bits in BlockDeclBitfields.
@ -1784,6 +1811,10 @@ public:
bool isClosure() const { return getDeclKind() == Decl::Block; }
/// Return this DeclContext if it is a BlockDecl. Otherwise, return the
/// innermost enclosing BlockDecl or null if there are no enclosing blocks.
const BlockDecl *getInnermostBlockDecl() const;
bool isObjCContainer() const {
switch (getDeclKind()) {
case Decl::ObjCCategory:

View File

@ -1,9 +1,8 @@
//===- DeclCXX.h - Classes for representing C++ declarations --*- 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
//
//===----------------------------------------------------------------------===//
//
@ -64,6 +63,7 @@ class CXXDestructorDecl;
class CXXFinalOverriderMap;
class CXXIndirectPrimaryBaseSet;
class CXXMethodDecl;
class DecompositionDecl;
class DiagnosticBuilder;
class FriendDecl;
class FunctionTemplateDecl;
@ -334,10 +334,12 @@ class CXXRecordDecl : public RecordDecl {
/// True when this class is a POD-type.
unsigned PlainOldData : 1;
/// true when this class is empty for traits purposes,
/// i.e. has no data members other than 0-width bit-fields, has no
/// virtual function/base, and doesn't inherit from a non-empty
/// class. Doesn't take union-ness into account.
/// True when this class is empty for traits purposes, that is:
/// * has no data members other than 0-width bit-fields and empty fields
/// marked [[no_unique_address]]
/// * has no virtual function/base, and
/// * doesn't inherit from a non-empty class.
/// Doesn't take union-ness into account.
unsigned Empty : 1;
/// True when this class is polymorphic, i.e., has at
@ -1222,6 +1224,9 @@ public:
/// lambda.
TemplateParameterList *getGenericLambdaTemplateParameterList() const;
/// Retrieve the lambda template parameters that were specified explicitly.
ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const;
LambdaCaptureDefault getLambdaCaptureDefault() const {
assert(isLambda());
return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
@ -1326,6 +1331,14 @@ public:
/// \note This does NOT include a check for union-ness.
bool isEmpty() const { return data().Empty; }
bool hasPrivateFields() const {
return data().HasPrivateFields;
}
bool hasProtectedFields() const {
return data().HasProtectedFields;
}
/// Determine whether this class has direct non-static data members.
bool hasDirectFields() const {
auto &D = data();
@ -1828,6 +1841,14 @@ public:
static bool FindOMPReductionMember(const CXXBaseSpecifier *Specifier,
CXXBasePath &Path, DeclarationName Name);
/// Base-class lookup callback that determines whether there exists
/// an OpenMP declare mapper member with the given name.
///
/// This callback can be used with \c lookupInBases() to find members
/// of the given name within a C++ class hierarchy.
static bool FindOMPMapperMember(const CXXBaseSpecifier *Specifier,
CXXBasePath &Path, DeclarationName Name);
/// Base-class lookup callback that determines whether there exists
/// a member with the given name that can be used in a nested-name-specifier.
///
@ -1975,6 +1996,53 @@ public:
}
};
/// Store information needed for an explicit specifier.
/// used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl.
class ExplicitSpecifier {
llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{
nullptr, ExplicitSpecKind::ResolvedFalse};
public:
ExplicitSpecifier() = default;
ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind)
: ExplicitSpec(Expression, Kind) {}
ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); }
const Expr *getExpr() const { return ExplicitSpec.getPointer(); }
Expr *getExpr() { return ExplicitSpec.getPointer(); }
/// Return true if the ExplicitSpecifier isn't defaulted.
bool isSpecified() const {
return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse ||
ExplicitSpec.getPointer();
}
/// Check for Equivalence of explicit specifiers.
/// Return True if the explicit specifier are equivalent false otherwise.
bool isEquivalent(const ExplicitSpecifier Other) const;
/// Return true if the explicit specifier is already resolved to be explicit.
bool isExplicit() const {
return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue;
}
/// Return true if the ExplicitSpecifier isn't valid.
/// This state occurs after a substitution failures.
bool isInvalid() const {
return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved &&
!ExplicitSpec.getPointer();
}
void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); }
void setExpr(Expr *E) { ExplicitSpec.setPointer(E); }
// getFromDecl - retrieve the explicit specifier in the given declaration.
// if the given declaration has no explicit. the returned explicit specifier
// is defaulted. .isSpecified() will be false.
static ExplicitSpecifier getFromDecl(FunctionDecl *Function);
static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) {
return getFromDecl(const_cast<FunctionDecl *>(Function));
}
static ExplicitSpecifier Invalid() {
return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved);
}
};
/// Represents a C++ deduction guide declaration.
///
/// \code
@ -1990,31 +2058,36 @@ class CXXDeductionGuideDecl : public FunctionDecl {
private:
CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
bool IsExplicit, const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
SourceLocation EndLocation)
ExplicitSpecifier ES,
const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, SourceLocation EndLocation)
: FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
SC_None, false, false) {
SC_None, false, CSK_unspecified),
ExplicitSpec(ES) {
if (EndLocation.isValid())
setRangeEnd(EndLocation);
setExplicitSpecified(IsExplicit);
setIsCopyDeductionCandidate(false);
}
ExplicitSpecifier ExplicitSpec;
void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
public:
friend class ASTDeclReader;
friend class ASTDeclWriter;
static CXXDeductionGuideDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation StartLoc, bool IsExplicit,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
SourceLocation EndLocation);
static CXXDeductionGuideDecl *
Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, SourceLocation EndLocation);
static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID);
/// Whether this deduction guide is explicit.
bool isExplicit() const { return isExplicitSpecified(); }
ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; }
const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; }
/// Return true if the declartion is already resolved to be explicit.
bool isExplicit() const { return ExplicitSpec.isExplicit(); }
/// Get the template for which this guide performs deduction.
TemplateDecl *getDeducedTemplate() const {
@ -2044,11 +2117,11 @@ class CXXMethodDecl : public FunctionDecl {
protected:
CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
StorageClass SC, bool isInline,
bool isConstexpr, SourceLocation EndLocation)
: FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo,
SC, isInline, isConstexpr) {
QualType T, TypeSourceInfo *TInfo, StorageClass SC,
bool isInline, ConstexprSpecKind ConstexprKind,
SourceLocation EndLocation)
: FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, isInline,
ConstexprKind) {
if (EndLocation.isValid())
setRangeEnd(EndLocation);
}
@ -2056,11 +2129,9 @@ protected:
public:
static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
StorageClass SC,
bool isInline,
bool isConstexpr,
const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, StorageClass SC,
bool isInline, ConstexprSpecKind ConstexprKind,
SourceLocation EndLocation);
static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
@ -2161,20 +2232,20 @@ public:
overridden_method_range overridden_methods() const;
/// Returns the parent of this method declaration, which
/// Return the parent of this method declaration, which
/// is the class in which this method is defined.
const CXXRecordDecl *getParent() const {
return cast<CXXRecordDecl>(FunctionDecl::getParent());
}
/// Returns the parent of this method declaration, which
/// Return the parent of this method declaration, which
/// is the class in which this method is defined.
CXXRecordDecl *getParent() {
return const_cast<CXXRecordDecl *>(
cast<CXXRecordDecl>(FunctionDecl::getParent()));
}
/// Returns the type of the \c this pointer.
/// Return the type of the \c this pointer.
///
/// Should only be called for instance (i.e., non-static) methods. Note
/// that for the call operator of a lambda closure type, this returns the
@ -2182,11 +2253,19 @@ public:
/// 'this' type.
QualType getThisType() const;
/// Return the type of the object pointed by \c this.
///
/// See getThisType() for usage restriction.
QualType getThisObjectType() const;
static QualType getThisType(const FunctionProtoType *FPT,
const CXXRecordDecl *Decl);
Qualifiers getTypeQualifiers() const {
return getType()->getAs<FunctionProtoType>()->getTypeQuals();
static QualType getThisObjectType(const FunctionProtoType *FPT,
const CXXRecordDecl *Decl);
Qualifiers getMethodQualifiers() const {
return getType()->getAs<FunctionProtoType>()->getMethodQuals();
}
/// Retrieve the ref-qualifier associated with this method.
@ -2231,6 +2310,17 @@ public:
->getCorrespondingMethodInClass(RD, MayBeBase);
}
/// Find if \p RD declares a function that overrides this function, and if so,
/// return it. Does not search base classes.
CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD,
bool MayBeBase = false);
const CXXMethodDecl *
getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD,
bool MayBeBase = false) const {
return const_cast<CXXMethodDecl *>(this)
->getCorrespondingMethodDeclaredInClass(RD, MayBeBase);
}
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) {
@ -2483,7 +2573,8 @@ public:
/// \endcode
class CXXConstructorDecl final
: public CXXMethodDecl,
private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor> {
private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor,
ExplicitSpecifier> {
// This class stores some data in DeclContext::CXXConstructorDeclBits
// to save some space. Use the provided accessors to access it.
@ -2493,28 +2584,74 @@ class CXXConstructorDecl final
LazyCXXCtorInitializersPtr CtorInitializers;
CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isExplicitSpecified, bool isInline,
bool isImplicitlyDeclared, bool isConstexpr,
const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline,
bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
InheritedConstructor Inherited);
void anchor() override;
size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const {
return CXXConstructorDeclBits.IsInheritingConstructor;
}
size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const {
return CXXConstructorDeclBits.HasTrailingExplicitSpecifier;
}
ExplicitSpecifier getExplicitSpecifierInternal() const {
if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier)
return *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>();
return ExplicitSpecifier(
nullptr, getCanonicalDecl()->CXXConstructorDeclBits.IsSimpleExplicit
? ExplicitSpecKind::ResolvedTrue
: ExplicitSpecKind::ResolvedFalse);
}
void setExplicitSpecifier(ExplicitSpecifier ES) {
assert((!ES.getExpr() ||
CXXConstructorDeclBits.HasTrailingExplicitSpecifier) &&
"cannot set this explicit specifier. no trail-allocated space for "
"explicit");
if (ES.getExpr())
*getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES;
else
CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit();
}
enum TraillingAllocKind {
TAKInheritsConstructor = 1,
TAKHasTailExplicit = 1 << 1,
};
uint64_t getTraillingAllocKind() const {
return numTrailingObjects(OverloadToken<InheritedConstructor>()) |
(numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1);
}
public:
friend class ASTDeclReader;
friend class ASTDeclWriter;
friend TrailingObjects;
static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID,
bool InheritsConstructor);
uint64_t AllocKind);
static CXXConstructorDecl *
Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
bool isExplicit, bool isInline, bool isImplicitlyDeclared,
bool isConstexpr,
ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared,
ConstexprSpecKind ConstexprKind,
InheritedConstructor Inherited = InheritedConstructor());
ExplicitSpecifier getExplicitSpecifier() {
return getExplicitSpecifierInternal();
}
const ExplicitSpecifier getExplicitSpecifier() const {
return getExplicitSpecifierInternal();
}
/// Return true if the declartion is already resolved to be explicit.
bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
/// Iterates through the member/base initializer list.
using init_iterator = CXXCtorInitializer **;
@ -2585,11 +2722,6 @@ public:
CtorInitializers = Initializers;
}
/// Whether this function is explicit.
bool isExplicit() const {
return getCanonicalDecl()->isExplicitSpecified();
}
/// Determine whether this constructor is a delegating constructor.
bool isDelegatingConstructor() const {
return (getNumCtorInitializers() == 1) &&
@ -2713,12 +2845,11 @@ class CXXDestructorDecl : public CXXMethodDecl {
Expr *OperatorDeleteThisArg = nullptr;
CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isInline, bool isImplicitlyDeclared)
: CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
SC_None, isInline, /*isConstexpr=*/false, SourceLocation())
{
const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, bool isInline,
bool isImplicitlyDeclared)
: CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
SC_None, isInline, CSK_unspecified, SourceLocation()) {
setImplicit(isImplicitlyDeclared);
}
@ -2768,34 +2899,39 @@ public:
class CXXConversionDecl : public CXXMethodDecl {
CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, bool isInline,
bool isExplicitSpecified, bool isConstexpr,
SourceLocation EndLocation)
TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES,
ConstexprSpecKind ConstexprKind, SourceLocation EndLocation)
: CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
SC_None, isInline, isConstexpr, EndLocation) {
setExplicitSpecified(isExplicitSpecified);
}
SC_None, isInline, ConstexprKind, EndLocation),
ExplicitSpec(ES) {}
void anchor() override;
ExplicitSpecifier ExplicitSpec;
void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
public:
friend class ASTDeclReader;
friend class ASTDeclWriter;
static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo,
QualType T, TypeSourceInfo *TInfo,
bool isInline, bool isExplicit,
bool isConstexpr,
SourceLocation EndLocation);
static CXXConversionDecl *
Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind,
SourceLocation EndLocation);
static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
/// Whether this function is explicit.
bool isExplicit() const {
return getCanonicalDecl()->isExplicitSpecified();
ExplicitSpecifier getExplicitSpecifier() {
return getCanonicalDecl()->ExplicitSpec;
}
const ExplicitSpecifier getExplicitSpecifier() const {
return getCanonicalDecl()->ExplicitSpec;
}
/// Return true if the declartion is already resolved to be explicit.
bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
/// Returns the type that this conversion function is converting to.
QualType getConversionType() const {
return getType()->getAs<FunctionType>()->getReturnType();
@ -3793,6 +3929,8 @@ public:
/// x[0], x[1], and x[2] respectively, where x is the implicit
/// DecompositionDecl of type 'int (&)[3]'.
class BindingDecl : public ValueDecl {
/// The declaration that this binding binds to part of.
LazyDeclPtr Decomp;
/// The binding represented by this declaration. References to this
/// declaration are effectively equivalent to this expression (except
/// that it is only evaluated once at the point of declaration of the
@ -3816,6 +3954,10 @@ public:
/// decomposition declaration, and when the initializer is type-dependent.
Expr *getBinding() const { return Binding; }
/// Get the decomposition declaration that this binding represents a
/// decomposition of.
ValueDecl *getDecomposedDecl() const;
/// Get the variable (if any) that holds the value of evaluating the binding.
/// Only present for user-defined bindings for tuple-like types.
VarDecl *getHoldingVar() const;
@ -3828,6 +3970,9 @@ public:
this->Binding = Binding;
}
/// Set the decomposed variable for this BindingDecl.
void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; }
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == Decl::Binding; }
};
@ -3855,6 +4000,8 @@ class DecompositionDecl final
NumBindings(Bindings.size()) {
std::uninitialized_copy(Bindings.begin(), Bindings.end(),
getTrailingObjects<BindingDecl *>());
for (auto *B : Bindings)
B->setDecomposedDecl(this);
}
void anchor() override;

View File

@ -1,9 +1,8 @@
//===- DeclContextInternals.h - DeclContext Representation ------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -114,12 +113,11 @@ public:
}
DeclsTy &Vec = *getAsVector();
DeclsTy::iterator I = std::find(Vec.begin(), Vec.end(), D);
DeclsTy::iterator I = llvm::find(Vec, D);
assert(I != Vec.end() && "list does not contain decl");
Vec.erase(I);
assert(std::find(Vec.begin(), Vec.end(), D)
== Vec.end() && "list still contains decl");
assert(llvm::find(Vec, D) == Vec.end() && "list still contains decl");
}
/// Remove any declarations which were imported from an external

View File

@ -1,9 +1,8 @@
//===- DeclFriend.h - Classes for C++ friend declarations -------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- DeclGroup.h - Classes for representing groups of Decls ---*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- DeclLookups.h - Low-level interface to all names in a DC -*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- DeclObjC.h - Classes for representing declarations -------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- DeclOpenMP.h - Classes for representing OpenMP directives -*- 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
//
//===----------------------------------------------------------------------===//
///
@ -207,6 +206,102 @@ public:
}
};
/// This represents '#pragma omp declare mapper ...' directive. Map clauses are
/// allowed to use with this directive. The following example declares a user
/// defined mapper for the type 'struct vec'. This example instructs the fields
/// 'len' and 'data' should be mapped when mapping instances of 'struct vec'.
///
/// \code
/// #pragma omp declare mapper(mid: struct vec v) map(v.len, v.data[0:N])
/// \endcode
class OMPDeclareMapperDecl final : public ValueDecl, public DeclContext {
friend class ASTDeclReader;
/// Clauses associated with this mapper declaration
MutableArrayRef<OMPClause *> Clauses;
/// Mapper variable, which is 'v' in the example above
Expr *MapperVarRef = nullptr;
/// Name of the mapper variable
DeclarationName VarName;
LazyDeclPtr PrevDeclInScope;
virtual void anchor();
OMPDeclareMapperDecl(Kind DK, DeclContext *DC, SourceLocation L,
DeclarationName Name, QualType Ty,
DeclarationName VarName,
OMPDeclareMapperDecl *PrevDeclInScope)
: ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), VarName(VarName),
PrevDeclInScope(PrevDeclInScope) {}
void setPrevDeclInScope(OMPDeclareMapperDecl *Prev) {
PrevDeclInScope = Prev;
}
/// Sets an array of clauses to this mapper declaration
void setClauses(ArrayRef<OMPClause *> CL);
public:
/// Creates declare mapper node.
static OMPDeclareMapperDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, DeclarationName Name,
QualType T, DeclarationName VarName,
OMPDeclareMapperDecl *PrevDeclInScope);
/// Creates deserialized declare mapper node.
static OMPDeclareMapperDecl *CreateDeserialized(ASTContext &C, unsigned ID,
unsigned N);
/// Creates an array of clauses to this mapper declaration and intializes
/// them.
void CreateClauses(ASTContext &C, ArrayRef<OMPClause *> CL);
using clauselist_iterator = MutableArrayRef<OMPClause *>::iterator;
using clauselist_const_iterator = ArrayRef<const OMPClause *>::iterator;
using clauselist_range = llvm::iterator_range<clauselist_iterator>;
using clauselist_const_range =
llvm::iterator_range<clauselist_const_iterator>;
unsigned clauselist_size() const { return Clauses.size(); }
bool clauselist_empty() const { return Clauses.empty(); }
clauselist_range clauselists() {
return clauselist_range(clauselist_begin(), clauselist_end());
}
clauselist_const_range clauselists() const {
return clauselist_const_range(clauselist_begin(), clauselist_end());
}
clauselist_iterator clauselist_begin() { return Clauses.begin(); }
clauselist_iterator clauselist_end() { return Clauses.end(); }
clauselist_const_iterator clauselist_begin() const { return Clauses.begin(); }
clauselist_const_iterator clauselist_end() const { return Clauses.end(); }
/// Get the variable declared in the mapper
Expr *getMapperVarRef() { return MapperVarRef; }
const Expr *getMapperVarRef() const { return MapperVarRef; }
/// Set the variable declared in the mapper
void setMapperVarRef(Expr *MapperVarRefE) { MapperVarRef = MapperVarRefE; }
/// Get the name of the variable declared in the mapper
DeclarationName getVarName() { return VarName; }
/// Get reference to previous declare mapper construct in the same
/// scope with the same name.
OMPDeclareMapperDecl *getPrevDeclInScope();
const OMPDeclareMapperDecl *getPrevDeclInScope() const;
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == OMPDeclareMapper; }
static DeclContext *castToDeclContext(const OMPDeclareMapperDecl *D) {
return static_cast<DeclContext *>(const_cast<OMPDeclareMapperDecl *>(D));
}
static OMPDeclareMapperDecl *castFromDeclContext(const DeclContext *DC) {
return static_cast<OMPDeclareMapperDecl *>(const_cast<DeclContext *>(DC));
}
};
/// Pseudo declaration for capturing expressions. Also is used for capturing of
/// non-static data members in non-static member functions.
///
@ -310,6 +405,119 @@ public:
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == OMPRequires; }
};
/// This represents '#pragma omp allocate ...' directive.
/// For example, in the following, the default allocator is used for both 'a'
/// and 'A::b':
///
/// \code
/// int a;
/// #pragma omp allocate(a)
/// struct A {
/// static int b;
/// #pragma omp allocate(b)
/// };
/// \endcode
///
class OMPAllocateDecl final
: public Decl,
private llvm::TrailingObjects<OMPAllocateDecl, Expr *, OMPClause *> {
friend class ASTDeclReader;
friend TrailingObjects;
/// Number of variable within the allocate directive.
unsigned NumVars = 0;
/// Number of clauses associated with the allocate directive.
unsigned NumClauses = 0;
size_t numTrailingObjects(OverloadToken<Expr *>) const {
return NumVars;
}
size_t numTrailingObjects(OverloadToken<OMPClause *>) const {
return NumClauses;
}
virtual void anchor();
OMPAllocateDecl(Kind DK, DeclContext *DC, SourceLocation L)
: Decl(DK, DC, L) {}
ArrayRef<const Expr *> getVars() const {
return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumVars);
}
MutableArrayRef<Expr *> getVars() {
return MutableArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumVars);
}
void setVars(ArrayRef<Expr *> VL);
/// Returns an array of immutable clauses associated with this directive.
ArrayRef<OMPClause *> getClauses() const {
return llvm::makeArrayRef(getTrailingObjects<OMPClause *>(), NumClauses);
}
/// Returns an array of clauses associated with this directive.
MutableArrayRef<OMPClause *> getClauses() {
return MutableArrayRef<OMPClause *>(getTrailingObjects<OMPClause *>(),
NumClauses);
}
/// Sets an array of clauses to this requires declaration
void setClauses(ArrayRef<OMPClause *> CL);
public:
static OMPAllocateDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, ArrayRef<Expr *> VL,
ArrayRef<OMPClause *> CL);
static OMPAllocateDecl *CreateDeserialized(ASTContext &C, unsigned ID,
unsigned NVars, unsigned NClauses);
typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
typedef llvm::iterator_range<varlist_iterator> varlist_range;
typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
using clauselist_iterator = MutableArrayRef<OMPClause *>::iterator;
using clauselist_const_iterator = ArrayRef<const OMPClause *>::iterator;
using clauselist_range = llvm::iterator_range<clauselist_iterator>;
using clauselist_const_range = llvm::iterator_range<clauselist_const_iterator>;
unsigned varlist_size() const { return NumVars; }
bool varlist_empty() const { return NumVars == 0; }
unsigned clauselist_size() const { return NumClauses; }
bool clauselist_empty() const { return NumClauses == 0; }
varlist_range varlists() {
return varlist_range(varlist_begin(), varlist_end());
}
varlist_const_range varlists() const {
return varlist_const_range(varlist_begin(), varlist_end());
}
varlist_iterator varlist_begin() { return getVars().begin(); }
varlist_iterator varlist_end() { return getVars().end(); }
varlist_const_iterator varlist_begin() const { return getVars().begin(); }
varlist_const_iterator varlist_end() const { return getVars().end(); }
clauselist_range clauselists() {
return clauselist_range(clauselist_begin(), clauselist_end());
}
clauselist_const_range clauselists() const {
return clauselist_const_range(clauselist_begin(), clauselist_end());
}
clauselist_iterator clauselist_begin() { return getClauses().begin(); }
clauselist_iterator clauselist_end() { return getClauses().end(); }
clauselist_const_iterator clauselist_begin() const {
return getClauses().begin();
}
clauselist_const_iterator clauselist_end() const {
return getClauses().end();
}
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == OMPAllocate; }
};
} // end namespace clang
#endif

View File

@ -1,9 +1,8 @@
//===- DeclTemplate.h - Classes for representing C++ templates --*- 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
//
//===----------------------------------------------------------------------===//
//
@ -177,6 +176,11 @@ public:
return SourceRange(TemplateLoc, RAngleLoc);
}
void print(raw_ostream &Out, const ASTContext &Context,
bool OmitTemplateKW = false) const;
void print(raw_ostream &Out, const ASTContext &Context,
const PrintingPolicy &Policy, bool OmitTemplateKW = false) const;
public:
// FIXME: workaround for MSVC 2013; remove when no longer needed
using FixedSizeStorageOwner = TrailingObjects::FixedSizeStorageOwner;
@ -505,29 +509,13 @@ public:
/// Provides information about a function template specialization,
/// which is a FunctionDecl that has been explicitly specialization or
/// instantiated from a function template.
class FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode {
FunctionTemplateSpecializationInfo(FunctionDecl *FD,
FunctionTemplateDecl *Template,
TemplateSpecializationKind TSK,
const TemplateArgumentList *TemplateArgs,
const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
SourceLocation POI)
: Function(FD), Template(Template, TSK - 1),
TemplateArguments(TemplateArgs),
TemplateArgumentsAsWritten(TemplateArgsAsWritten),
PointOfInstantiation(POI) {}
public:
static FunctionTemplateSpecializationInfo *
Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
TemplateSpecializationKind TSK,
const TemplateArgumentList *TemplateArgs,
const TemplateArgumentListInfo *TemplateArgsAsWritten,
SourceLocation POI);
/// The function template specialization that this structure
/// describes.
FunctionDecl *Function;
class FunctionTemplateSpecializationInfo final
: public llvm::FoldingSetNode,
private llvm::TrailingObjects<FunctionTemplateSpecializationInfo,
MemberSpecializationInfo *> {
/// The function template specialization that this structure describes and a
/// flag indicating if the function is a member specialization.
llvm::PointerIntPair<FunctionDecl *, 1, bool> Function;
/// The function template from which this function template
/// specialization was generated.
@ -535,17 +523,50 @@ public:
/// The two bits contain the top 4 values of TemplateSpecializationKind.
llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template;
public:
/// The template arguments used to produce the function template
/// specialization from the function template.
const TemplateArgumentList *TemplateArguments;
/// The template arguments as written in the sources, if provided.
/// FIXME: Normally null; tail-allocate this.
const ASTTemplateArgumentListInfo *TemplateArgumentsAsWritten;
/// The point at which this function template specialization was
/// first instantiated.
SourceLocation PointOfInstantiation;
private:
FunctionTemplateSpecializationInfo(
FunctionDecl *FD, FunctionTemplateDecl *Template,
TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs,
const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
SourceLocation POI, MemberSpecializationInfo *MSInfo)
: Function(FD, MSInfo ? 1 : 0), Template(Template, TSK - 1),
TemplateArguments(TemplateArgs),
TemplateArgumentsAsWritten(TemplateArgsAsWritten),
PointOfInstantiation(POI) {
if (MSInfo)
getTrailingObjects<MemberSpecializationInfo *>()[0] = MSInfo;
}
size_t numTrailingObjects(OverloadToken<MemberSpecializationInfo*>) const {
return Function.getInt();
}
public:
friend TrailingObjects;
static FunctionTemplateSpecializationInfo *
Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
TemplateSpecializationKind TSK,
const TemplateArgumentList *TemplateArgs,
const TemplateArgumentListInfo *TemplateArgsAsWritten,
SourceLocation POI, MemberSpecializationInfo *MSInfo);
/// Retrieve the declaration of the function template specialization.
FunctionDecl *getFunction() const { return Function.getPointer(); }
/// Retrieve the template from which this function was specialized.
FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); }
@ -588,9 +609,44 @@ public:
PointOfInstantiation = POI;
}
/// Get the specialization info if this function template specialization is
/// also a member specialization:
///
/// \code
/// template<typename> struct A {
/// template<typename> void f();
/// template<> void f<int>(); // ClassScopeFunctionSpecializationDecl
/// };
/// \endcode
///
/// Here, A<int>::f<int> is a function template specialization that is
/// an explicit specialization of A<int>::f, but it's also a member
/// specialization (an implicit instantiation in this case) of A::f<int>.
/// Further:
///
/// \code
/// template<> template<> void A<int>::f<int>() {}
/// \endcode
///
/// ... declares a function template specialization that is an explicit
/// specialization of A<int>::f, and is also an explicit member
/// specialization of A::f<int>.
///
/// Note that the TemplateSpecializationKind of the MemberSpecializationInfo
/// need not be the same as that returned by getTemplateSpecializationKind(),
/// and represents the relationship between the function and the class-scope
/// explicit specialization in the original templated class -- whereas our
/// TemplateSpecializationKind represents the relationship between the
/// function and the function template, and should always be
/// TSK_ExplicitSpecialization whenever we have MemberSpecializationInfo.
MemberSpecializationInfo *getMemberSpecializationInfo() const {
return numTrailingObjects(OverloadToken<MemberSpecializationInfo *>())
? getTrailingObjects<MemberSpecializationInfo *>()[0]
: nullptr;
}
void Profile(llvm::FoldingSetNodeID &ID) {
Profile(ID, TemplateArguments->asArray(),
Function->getASTContext());
Profile(ID, TemplateArguments->asArray(), getFunction()->getASTContext());
}
static void
@ -956,7 +1012,7 @@ SpecEntryTraits<FunctionTemplateSpecializationInfo> {
using DeclType = FunctionDecl;
static DeclType *getDecl(FunctionTemplateSpecializationInfo *I) {
return I->Function;
return I->getFunction();
}
static ArrayRef<TemplateArgument>
@ -1747,6 +1803,20 @@ public:
return getSpecializationKind() == TSK_ExplicitSpecialization;
}
/// Is this an explicit specialization at class scope (within the class that
/// owns the primary template)? For example:
///
/// \code
/// template<typename T> struct Outer {
/// template<typename U> struct Inner;
/// template<> struct Inner; // class-scope explicit specialization
/// };
/// \endcode
bool isClassScopeExplicitSpecialization() const {
return isExplicitSpecialization() &&
isa<CXXRecordDecl>(getLexicalDeclContext());
}
/// True if this declaration is an explicit specialization,
/// explicit instantiation declaration, or explicit instantiation
/// definition.
@ -2395,8 +2465,6 @@ public:
/// Declaration of a function specialization at template class scope.
///
/// This is a non-standard extension needed to support MSVC.
///
/// For example:
/// \code
/// template <class T>
@ -2409,17 +2477,18 @@ public:
/// "template<> foo(int a)" will be saved in Specialization as a normal
/// CXXMethodDecl. Then during an instantiation of class A, it will be
/// transformed into an actual function specialization.
///
/// FIXME: This is redundant; we could store the same information directly on
/// the CXXMethodDecl as a DependentFunctionTemplateSpecializationInfo.
class ClassScopeFunctionSpecializationDecl : public Decl {
CXXMethodDecl *Specialization;
bool HasExplicitTemplateArgs;
TemplateArgumentListInfo TemplateArgs;
const ASTTemplateArgumentListInfo *TemplateArgs;
ClassScopeFunctionSpecializationDecl(DeclContext *DC, SourceLocation Loc,
CXXMethodDecl *FD, bool Args,
TemplateArgumentListInfo TemplArgs)
ClassScopeFunctionSpecializationDecl(
DeclContext *DC, SourceLocation Loc, CXXMethodDecl *FD,
const ASTTemplateArgumentListInfo *TemplArgs)
: Decl(Decl::ClassScopeFunctionSpecialization, DC, Loc),
Specialization(FD), HasExplicitTemplateArgs(Args),
TemplateArgs(std::move(TemplArgs)) {}
Specialization(FD), TemplateArgs(TemplArgs) {}
ClassScopeFunctionSpecializationDecl(EmptyShell Empty)
: Decl(Decl::ClassScopeFunctionSpecialization, Empty) {}
@ -2431,17 +2500,20 @@ public:
friend class ASTDeclWriter;
CXXMethodDecl *getSpecialization() const { return Specialization; }
bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
const TemplateArgumentListInfo& templateArgs() const { return TemplateArgs; }
bool hasExplicitTemplateArgs() const { return TemplateArgs; }
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
return TemplateArgs;
}
static ClassScopeFunctionSpecializationDecl *Create(ASTContext &C,
DeclContext *DC,
SourceLocation Loc,
CXXMethodDecl *FD,
bool HasExplicitTemplateArgs,
TemplateArgumentListInfo TemplateArgs) {
static ClassScopeFunctionSpecializationDecl *
Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, CXXMethodDecl *FD,
bool HasExplicitTemplateArgs,
const TemplateArgumentListInfo &TemplateArgs) {
return new (C, DC) ClassScopeFunctionSpecializationDecl(
DC, Loc, FD, HasExplicitTemplateArgs, std::move(TemplateArgs));
DC, Loc, FD,
HasExplicitTemplateArgs
? ASTTemplateArgumentListInfo::Create(C, TemplateArgs)
: nullptr);
}
static ClassScopeFunctionSpecializationDecl *
@ -2582,6 +2654,11 @@ public:
return getSpecializationKind() == TSK_ExplicitSpecialization;
}
bool isClassScopeExplicitSpecialization() const {
return isExplicitSpecialization() &&
isa<CXXRecordDecl>(getLexicalDeclContext());
}
/// True if this declaration is an explicit specialization,
/// explicit instantiation declaration, or explicit instantiation
/// definition.
@ -3013,6 +3090,42 @@ public:
static bool classofKind(Kind K) { return K == VarTemplate; }
};
// \brief Declaration of a C++2a concept.
class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
protected:
Expr *ConstraintExpr;
ConceptDecl(DeclContext *DC,
SourceLocation L, DeclarationName Name,
TemplateParameterList *Params,
Expr *ConstraintExpr)
: TemplateDecl(nullptr, Concept, DC, L, Name, Params),
ConstraintExpr(ConstraintExpr) {};
public:
static ConceptDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, DeclarationName Name,
TemplateParameterList *Params,
Expr *ConstraintExpr);
static ConceptDecl *CreateDeserialized(ASTContext &C, unsigned ID);
Expr *getConstraintExpr() const {
return ConstraintExpr;
}
SourceRange getSourceRange() const override LLVM_READONLY {
return SourceRange(getTemplateParameters()->getTemplateLoc(),
ConstraintExpr->getEndLoc());
}
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == Concept; }
friend class ASTReader;
friend class ASTDeclReader;
friend class ASTDeclWriter;
};
inline NamedDecl *getAsNamedDecl(TemplateParameter P) {
if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>())
return PD;

View File

@ -1,9 +1,8 @@
//===- DeclVisitor.h - Visitor for Decl subclasses --------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- DeclarationName.h - Representation of declaration names --*- 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
//
//===----------------------------------------------------------------------===//
//
@ -862,9 +861,26 @@ struct DenseMapInfo<clang::DeclarationName> {
}
};
template <>
struct isPodLike<clang::DeclarationName> { static const bool value = true; };
} // namespace llvm
// The definition of AssumedTemplateStorage is factored out of TemplateName to
// resolve a cyclic dependency between it and DeclarationName (via Type).
namespace clang {
/// A structure for storing the information associated with a name that has
/// been assumed to be a template name (despite finding no TemplateDecls).
class AssumedTemplateStorage : public UncommonTemplateNameStorage {
friend class ASTContext;
AssumedTemplateStorage(DeclarationName Name)
: UncommonTemplateNameStorage(Assumed, 0), Name(Name) {}
DeclarationName Name;
public:
/// Get the name of the template.
DeclarationName getDeclName() const { return Name; }
};
} // namespace clang
#endif // LLVM_CLANG_AST_DECLARATIONNAME_H

View File

@ -1,9 +1,8 @@
//==- DependentDiagnostic.h - Dependently-generated diagnostics --*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- EvaluatedExprVisitor.h - Evaluated expression visitor --*- 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
//
//===----------------------------------------------------------------------===//
//

File diff suppressed because it is too large Load Diff

View File

@ -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
//
//===----------------------------------------------------------------------===//
//
@ -217,6 +216,8 @@ public:
/// Represents a call to a CUDA kernel function.
class CUDAKernelCallExpr final : public CallExpr {
friend class ASTStmtReader;
enum { CONFIG, END_PREARG };
// CUDAKernelCallExpr has some trailing objects belonging
@ -242,20 +243,6 @@ public:
}
CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
/// Sets the kernel configuration expression.
///
/// Note that this method cannot be called if config has already been set to a
/// non-null value.
void setConfig(CallExpr *E) {
assert(!getConfig() &&
"Cannot call setConfig if config is not null");
setPreArg(CONFIG, E);
setInstantiationDependent(isInstantiationDependent() ||
E->isInstantiationDependent());
setContainsUnexpandedParameterPack(containsUnexpandedParameterPack() ||
E->containsUnexpandedParameterPack());
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == CUDAKernelCallExprClass;
}
@ -588,6 +575,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 +608,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 +654,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 +748,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 +811,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 +891,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 +976,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 +1030,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 +1092,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]).
@ -1076,7 +1109,11 @@ class CXXDefaultArgExpr final : public Expr {
/// The parameter whose default is being used.
ParmVarDecl *Param;
CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param)
/// The context where the default argument expression was used.
DeclContext *UsedContext;
CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
DeclContext *UsedContext)
: Expr(SC,
Param->hasUnparsedDefaultArg()
? Param->getType().getNonReferenceType()
@ -1084,7 +1121,7 @@ class CXXDefaultArgExpr final : public Expr {
Param->getDefaultArg()->getValueKind(),
Param->getDefaultArg()->getObjectKind(), false, false, false,
false),
Param(Param) {
Param(Param), UsedContext(UsedContext) {
CXXDefaultArgExprBits.Loc = Loc;
}
@ -1094,8 +1131,10 @@ public:
// \p Param is the parameter whose default argument is used by this
// expression.
static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
ParmVarDecl *Param) {
return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
ParmVarDecl *Param,
DeclContext *UsedContext) {
return new (C)
CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, UsedContext);
}
// Retrieve the parameter that the argument was created from.
@ -1106,6 +1145,9 @@ public:
const Expr *getExpr() const { return getParam()->getDefaultArg(); }
Expr *getExpr() { return getParam()->getDefaultArg(); }
const DeclContext *getUsedContext() const { return UsedContext; }
DeclContext *getUsedContext() { return UsedContext; }
/// Retrieve the location where this default argument was actually used.
SourceLocation getUsedLocation() const { return CXXDefaultArgExprBits.Loc; }
@ -1124,6 +1166,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
@ -1141,8 +1187,11 @@ class CXXDefaultInitExpr : public Expr {
/// The field whose default is being used.
FieldDecl *Field;
/// The context where the default initializer expression was used.
DeclContext *UsedContext;
CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
FieldDecl *Field, QualType Ty);
FieldDecl *Field, QualType Ty, DeclContext *UsedContext);
CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
@ -1150,8 +1199,8 @@ public:
/// \p Field is the non-static data member whose default initializer is used
/// by this expression.
static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc,
FieldDecl *Field) {
return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType());
FieldDecl *Field, DeclContext *UsedContext) {
return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType(), UsedContext);
}
/// Get the field whose initializer will be used.
@ -1168,6 +1217,13 @@ public:
return Field->getInClassInitializer();
}
const DeclContext *getUsedContext() const { return UsedContext; }
DeclContext *getUsedContext() { return UsedContext; }
/// Retrieve the location where this default initializer expression was
/// actually used.
SourceLocation getUsedLocation() const { return getBeginLoc(); }
SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; }
SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; }
@ -1179,6 +1235,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 +1316,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 +1503,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 +1576,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 +1906,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 +1941,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 +1989,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 +2065,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 +2080,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 +2123,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 +2249,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 +2319,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 +2511,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 +2599,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 +2670,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 +2734,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 +3030,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 +3188,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 +3261,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 +3394,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 +3646,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 +3815,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 +3890,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 +3974,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 +4099,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 +4149,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,10 +4215,14 @@ 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
/// substituted but not yet expanded.
/// Represents a reference to a function parameter pack or init-capture pack
/// that has been substituted but not yet expanded.
///
/// When a pack expansion contains multiple parameter packs at different levels,
/// this node is used to represent a function parameter pack at an outer level
@ -4077,13 +4237,13 @@ public:
/// \endcode
class FunctionParmPackExpr final
: public Expr,
private llvm::TrailingObjects<FunctionParmPackExpr, ParmVarDecl *> {
private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> {
friend class ASTReader;
friend class ASTStmtReader;
friend TrailingObjects;
/// The function parameter pack which was referenced.
ParmVarDecl *ParamPack;
VarDecl *ParamPack;
/// The location of the function parameter pack reference.
SourceLocation NameLoc;
@ -4091,35 +4251,35 @@ class FunctionParmPackExpr final
/// The number of expansions of this pack.
unsigned NumParameters;
FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
SourceLocation NameLoc, unsigned NumParams,
ParmVarDecl *const *Params);
VarDecl *const *Params);
public:
static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
ParmVarDecl *ParamPack,
VarDecl *ParamPack,
SourceLocation NameLoc,
ArrayRef<ParmVarDecl *> Params);
ArrayRef<VarDecl *> Params);
static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
unsigned NumParams);
/// Get the parameter pack which this expression refers to.
ParmVarDecl *getParameterPack() const { return ParamPack; }
VarDecl *getParameterPack() const { return ParamPack; }
/// Get the location of the parameter pack.
SourceLocation getParameterPackLocation() const { return NameLoc; }
/// Iterators over the parameters which the parameter pack expanded
/// into.
using iterator = ParmVarDecl * const *;
iterator begin() const { return getTrailingObjects<ParmVarDecl *>(); }
using iterator = VarDecl * const *;
iterator begin() const { return getTrailingObjects<VarDecl *>(); }
iterator end() const { return begin() + NumParameters; }
/// Get the number of parameters in this parameter pack.
unsigned getNumExpansions() const { return NumParameters; }
/// Get an expansion of the parameter pack by index.
ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
VarDecl *getExpansion(unsigned I) const { return begin()[I]; }
SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
@ -4131,6 +4291,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 +4417,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.
@ -4270,18 +4443,21 @@ class CXXFoldExpr : public Expr {
SourceLocation LParenLoc;
SourceLocation EllipsisLoc;
SourceLocation RParenLoc;
// When 0, the number of expansions is not known. Otherwise, this is one more
// than the number of expansions.
unsigned NumExpansions;
Stmt *SubExprs[2];
BinaryOperatorKind Opcode;
public:
CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
SourceLocation RParenLoc)
SourceLocation RParenLoc, Optional<unsigned> NumExpansions)
: Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
/*Dependent*/ true, true, true,
/*ContainsUnexpandedParameterPack*/ false),
LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
Opcode(Opcode) {
NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) {
SubExprs[0] = LHS;
SubExprs[1] = RHS;
}
@ -4308,6 +4484,12 @@ public:
SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
BinaryOperatorKind getOperator() const { return Opcode; }
Optional<unsigned> getNumExpansions() const {
if (NumExpansions)
return NumExpansions - 1;
return None;
}
SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
@ -4318,6 +4500,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 +4595,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 +4683,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;
}
@ -4522,6 +4716,35 @@ public:
}
};
/// Represents a C++2a __builtin_bit_cast(T, v) expression. Used to implement
/// std::bit_cast. These can sometimes be evaluated as part of a constant
/// expression, but otherwise CodeGen to a simple memcpy in general.
class BuiltinBitCastExpr final
: public ExplicitCastExpr,
private llvm::TrailingObjects<BuiltinBitCastExpr, CXXBaseSpecifier *> {
friend class ASTStmtReader;
friend class CastExpr;
friend class TrailingObjects;
SourceLocation KWLoc;
SourceLocation RParenLoc;
public:
BuiltinBitCastExpr(QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr,
TypeSourceInfo *DstType, SourceLocation KWLoc,
SourceLocation RParenLoc)
: ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0,
DstType),
KWLoc(KWLoc), RParenLoc(RParenLoc) {}
SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; }
SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
static bool classof(const Stmt *T) {
return T->getStmtClass() == BuiltinBitCastExprClass;
}
};
} // namespace clang
#endif // LLVM_CLANG_AST_EXPRCXX_H

View File

@ -1,9 +1,8 @@
//===- ExprObjC.h - Classes for representing ObjC 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
//
//===----------------------------------------------------------------------===//
//
@ -73,6 +72,10 @@ public:
// Iterators
child_range children() { return child_range(&String, &String+1); }
const_child_range children() const {
return const_child_range(&String, &String + 1);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == ObjCStringLiteralClass;
}
@ -105,6 +108,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() == ObjCBoolLiteralExprClass;
}
@ -139,6 +146,12 @@ public:
return BoxingMethod;
}
// Indicates whether this boxed expression can be emitted as a compile-time
// constant.
bool isExpressibleAsConstantInitializer() const {
return !BoxingMethod && SubExpr;
}
SourceLocation getAtLoc() const { return Range.getBegin(); }
SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
@ -151,6 +164,10 @@ public:
// Iterators
child_range children() { return child_range(&SubExpr, &SubExpr+1); }
const_child_range children() const {
return const_child_range(&SubExpr, &SubExpr + 1);
}
using const_arg_iterator = ConstExprIterator;
const_arg_iterator arg_begin() const {
@ -229,6 +246,11 @@ public:
reinterpret_cast<Stmt **>(getElements()) + NumElements);
}
const_child_range children() const {
auto Children = const_cast<ObjCArrayLiteral *>(this)->children();
return const_child_range(Children.begin(), Children.end());
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == ObjCArrayLiteralClass;
}
@ -256,12 +278,6 @@ struct ObjCDictionaryElement {
} // namespace clang
namespace llvm {
template <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {};
} // namespace llvm
namespace clang {
/// Internal struct for storing Key/value pair.
@ -375,6 +391,11 @@ public:
NumElements * 2);
}
const_child_range children() const {
auto Children = const_cast<ObjCDictionaryLiteral *>(this)->children();
return const_child_range(Children.begin(), Children.end());
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == ObjCDictionaryLiteralClass;
}
@ -420,6 +441,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() == ObjCEncodeExprClass;
}
@ -458,6 +483,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() == ObjCSelectorExprClass;
}
@ -504,6 +533,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() == ObjCProtocolExprClass;
}
@ -567,6 +600,10 @@ public:
// Iterators
child_range children() { return child_range(&Base, &Base+1); }
const_child_range children() const {
return const_child_range(&Base, &Base + 1);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == ObjCIvarRefExprClass;
}
@ -758,6 +795,11 @@ public:
return child_range(child_iterator(), child_iterator());
}
const_child_range children() const {
auto Children = const_cast<ObjCPropertyRefExpr *>(this)->children();
return const_child_range(Children.begin(), Children.end());
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == ObjCPropertyRefExprClass;
}
@ -867,6 +909,10 @@ public:
return child_range(SubExprs, SubExprs+END_EXPR);
}
const_child_range children() const {
return const_child_range(SubExprs, SubExprs + END_EXPR);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == ObjCSubscriptRefExprClass;
}
@ -1187,6 +1233,13 @@ public:
/// sent to.
ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
/// \return the return type of the message being sent.
/// This is not always the type of the message expression itself because
/// of references (the expression would not have a reference type).
/// It is also not always the declared return type of the method because
/// of `instancetype` (in that case it's an expression type).
QualType getCallReturnType(ASTContext &Ctx) const;
/// Source range of the receiver.
SourceRange getReceiverRange() const;
@ -1402,6 +1455,8 @@ public:
// Iterators
child_range children();
const_child_range children() const;
using arg_iterator = ExprIterator;
using const_arg_iterator = ConstExprIterator;
@ -1488,6 +1543,10 @@ public:
// Iterators
child_range children() { return child_range(&Base, &Base+1); }
const_child_range children() const {
return const_child_range(&Base, &Base + 1);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == ObjCIsaExprClass;
}
@ -1549,6 +1608,10 @@ public:
child_range children() { return child_range(&Operand, &Operand+1); }
const_child_range children() const {
return const_child_range(&Operand, &Operand + 1);
}
// Source locations are determined by the subexpression.
SourceLocation getBeginLoc() const LLVM_READONLY {
return Operand->getBeginLoc();
@ -1661,6 +1724,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() == ObjCAvailabilityCheckExprClass;
}

View File

@ -1,9 +1,8 @@
//===--- ExprOpenMP.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
//
//===----------------------------------------------------------------------===//
//
@ -123,6 +122,10 @@ public:
child_range children() {
return child_range(&SubExprs[BASE], &SubExprs[END_EXPR]);
}
const_child_range children() const {
return const_child_range(&SubExprs[BASE], &SubExprs[END_EXPR]);
}
};
} // end namespace clang

View File

@ -1,9 +1,8 @@
//===--- ExternalASTMerger.h - Merging External AST Interface ---*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- ExternalASTSource.h - Abstract External AST Interface ----*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//= FormatString.h - Analysis of printf/fprintf format strings --*- 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
//
//===----------------------------------------------------------------------===//
//
@ -68,6 +67,7 @@ public:
None,
AsChar, // 'hh'
AsShort, // 'h'
AsShortLong, // 'hl' (OpenCL float/int vector element)
AsLong, // 'l'
AsLongLong, // 'll'
AsQuad, // 'q' (BSD, deprecated, for 64-bit integer types)
@ -437,7 +437,8 @@ public:
bool usesPositionalArg() const { return UsesPositionalArg; }
bool hasValidLengthModifier(const TargetInfo &Target) const;
bool hasValidLengthModifier(const TargetInfo &Target,
const LangOptions &LO) const;
bool hasStandardLengthModifier() const;

View File

@ -1,9 +1,8 @@
//===- GlobalDecl.h - Global declaration holder -----------------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -28,6 +27,12 @@
namespace clang {
enum class DynamicInitKind : unsigned {
NoStub = 0,
Initializer,
AtExit,
};
/// GlobalDecl - represents a global declaration. This can either be a
/// CXXConstructorDecl and the constructor type (Base, Complete).
/// a CXXDestructorDecl and the destructor type (Base, Complete) or
@ -56,6 +61,8 @@ public:
GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
GlobalDecl(const VarDecl *D, DynamicInitKind StubKind)
: Value(D, unsigned(StubKind)) {}
GlobalDecl getCanonicalDecl() const {
GlobalDecl CanonGD;
@ -78,6 +85,13 @@ public:
return static_cast<CXXDtorType>(Value.getInt());
}
DynamicInitKind getDynamicInitKind() const {
assert(isa<VarDecl>(getDecl()) &&
cast<VarDecl>(getDecl())->hasGlobalStorage() &&
"Decl is not a global variable!");
return static_cast<DynamicInitKind>(Value.getInt());
}
unsigned getMultiVersionIndex() const {
assert(isa<FunctionDecl>(getDecl()) &&
!isa<CXXConstructorDecl>(getDecl()) &&
@ -105,6 +119,20 @@ public:
return Result;
}
GlobalDecl getWithCtorType(CXXCtorType Type) {
assert(isa<CXXConstructorDecl>(getDecl()));
GlobalDecl Result(*this);
Result.Value.setInt(Type);
return Result;
}
GlobalDecl getWithDtorType(CXXDtorType Type) {
assert(isa<CXXDestructorDecl>(getDecl()));
GlobalDecl Result(*this);
Result.Value.setInt(Type);
return Result;
}
GlobalDecl getWithMultiVersionIndex(unsigned Index) {
assert(isa<FunctionDecl>(getDecl()) &&
!isa<CXXConstructorDecl>(getDecl()) &&
@ -140,13 +168,6 @@ namespace llvm {
}
};
// GlobalDecl isn't *technically* a POD type. However, its copy constructor,
// copy assignment operator, and destructor are all trivial.
template <>
struct isPodLike<clang::GlobalDecl> {
static const bool value = true;
};
} // namespace llvm
#endif // LLVM_CLANG_AST_GLOBALDECL_H

View File

@ -0,0 +1,425 @@
//===--- JSONNodeDumper.h - Printing of AST nodes to JSON -----------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements AST dumping of components of individual AST nodes to
// a JSON.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_JSONNODEDUMPER_H
#define LLVM_CLANG_AST_JSONNODEDUMPER_H
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTNodeTraverser.h"
#include "clang/AST/ASTDumperUtils.h"
#include "clang/AST/AttrVisitor.h"
#include "clang/AST/CommentCommandTraits.h"
#include "clang/AST/CommentVisitor.h"
#include "clang/AST/ExprCXX.h"
#include "llvm/Support/JSON.h"
namespace clang {
class NodeStreamer {
bool FirstChild = true;
bool TopLevel = true;
llvm::SmallVector<std::function<void(bool IsLastChild)>, 32> Pending;
protected:
llvm::json::OStream JOS;
public:
/// Add a child of the current node. Calls DoAddChild without arguments
template <typename Fn> void AddChild(Fn DoAddChild) {
return AddChild("", DoAddChild);
}
/// Add a child of the current node with an optional label.
/// Calls DoAddChild without arguments.
template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
// If we're at the top level, there's nothing interesting to do; just
// run the dumper.
if (TopLevel) {
TopLevel = false;
JOS.objectBegin();
DoAddChild();
while (!Pending.empty()) {
Pending.back()(true);
Pending.pop_back();
}
JOS.objectEnd();
TopLevel = true;
return;
}
// We need to capture an owning-string in the lambda because the lambda
// is invoked in a deferred manner.
std::string LabelStr = !Label.empty() ? Label : "inner";
bool WasFirstChild = FirstChild;
auto DumpWithIndent = [=](bool IsLastChild) {
if (WasFirstChild) {
JOS.attributeBegin(LabelStr);
JOS.arrayBegin();
}
FirstChild = true;
unsigned Depth = Pending.size();
JOS.objectBegin();
DoAddChild();
// If any children are left, they're the last at their nesting level.
// Dump those ones out now.
while (Depth < Pending.size()) {
Pending.back()(true);
this->Pending.pop_back();
}
JOS.objectEnd();
if (IsLastChild) {
JOS.arrayEnd();
JOS.attributeEnd();
}
};
if (FirstChild) {
Pending.push_back(std::move(DumpWithIndent));
} else {
Pending.back()(false);
Pending.back() = std::move(DumpWithIndent);
}
FirstChild = false;
}
NodeStreamer(raw_ostream &OS) : JOS(OS, 2) {}
};
// Dumps AST nodes in JSON format. There is no implied stability for the
// content or format of the dump between major releases of Clang, other than it
// being valid JSON output. Further, there is no requirement that the
// information dumped is a complete representation of the AST, only that the
// information presented is correct.
class JSONNodeDumper
: public ConstAttrVisitor<JSONNodeDumper>,
public comments::ConstCommentVisitor<JSONNodeDumper, void,
const comments::FullComment *>,
public ConstTemplateArgumentVisitor<JSONNodeDumper>,
public ConstStmtVisitor<JSONNodeDumper>,
public TypeVisitor<JSONNodeDumper>,
public ConstDeclVisitor<JSONNodeDumper>,
public NodeStreamer {
friend class JSONDumper;
const SourceManager &SM;
ASTContext& Ctx;
PrintingPolicy PrintPolicy;
const comments::CommandTraits *Traits;
StringRef LastLocFilename;
unsigned LastLocLine, LastLocPresumedLine;
using InnerAttrVisitor = ConstAttrVisitor<JSONNodeDumper>;
using InnerCommentVisitor =
comments::ConstCommentVisitor<JSONNodeDumper, void,
const comments::FullComment *>;
using InnerTemplateArgVisitor = ConstTemplateArgumentVisitor<JSONNodeDumper>;
using InnerStmtVisitor = ConstStmtVisitor<JSONNodeDumper>;
using InnerTypeVisitor = TypeVisitor<JSONNodeDumper>;
using InnerDeclVisitor = ConstDeclVisitor<JSONNodeDumper>;
void attributeOnlyIfTrue(StringRef Key, bool Value) {
if (Value)
JOS.attribute(Key, Value);
}
// Writes the attributes of a SourceLocation object without.
void writeBareSourceLocation(SourceLocation Loc, bool IsSpelling);
// Writes the attributes of a SourceLocation to JSON based on its presumed
// spelling location. If the given location represents a macro invocation,
// this outputs two sub-objects: one for the spelling and one for the
// expansion location.
void writeSourceLocation(SourceLocation Loc);
void writeSourceRange(SourceRange R);
std::string createPointerRepresentation(const void *Ptr);
llvm::json::Object createQualType(QualType QT, bool Desugar = true);
llvm::json::Object createBareDeclRef(const Decl *D);
void writeBareDeclRef(const Decl *D);
llvm::json::Object createCXXRecordDefinitionData(const CXXRecordDecl *RD);
llvm::json::Object createCXXBaseSpecifier(const CXXBaseSpecifier &BS);
std::string createAccessSpecifier(AccessSpecifier AS);
llvm::json::Array createCastPath(const CastExpr *C);
void writePreviousDeclImpl(...) {}
template <typename T> void writePreviousDeclImpl(const Mergeable<T> *D) {
const T *First = D->getFirstDecl();
if (First != D)
JOS.attribute("firstRedecl", createPointerRepresentation(First));
}
template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
const T *Prev = D->getPreviousDecl();
if (Prev)
JOS.attribute("previousDecl", createPointerRepresentation(Prev));
}
void addPreviousDeclaration(const Decl *D);
StringRef getCommentCommandName(unsigned CommandID) const;
public:
JSONNodeDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx,
const PrintingPolicy &PrintPolicy,
const comments::CommandTraits *Traits)
: NodeStreamer(OS), SM(SrcMgr), Ctx(Ctx), PrintPolicy(PrintPolicy),
Traits(Traits), LastLocLine(0), LastLocPresumedLine(0) {}
void Visit(const Attr *A);
void Visit(const Stmt *Node);
void Visit(const Type *T);
void Visit(QualType T);
void Visit(const Decl *D);
void Visit(const comments::Comment *C, const comments::FullComment *FC);
void Visit(const TemplateArgument &TA, SourceRange R = {},
const Decl *From = nullptr, StringRef Label = {});
void Visit(const CXXCtorInitializer *Init);
void Visit(const OMPClause *C);
void Visit(const BlockDecl::Capture &C);
void Visit(const GenericSelectionExpr::ConstAssociation &A);
void VisitTypedefType(const TypedefType *TT);
void VisitFunctionType(const FunctionType *T);
void VisitFunctionProtoType(const FunctionProtoType *T);
void VisitRValueReferenceType(const ReferenceType *RT);
void VisitArrayType(const ArrayType *AT);
void VisitConstantArrayType(const ConstantArrayType *CAT);
void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *VT);
void VisitVectorType(const VectorType *VT);
void VisitUnresolvedUsingType(const UnresolvedUsingType *UUT);
void VisitUnaryTransformType(const UnaryTransformType *UTT);
void VisitTagType(const TagType *TT);
void VisitTemplateTypeParmType(const TemplateTypeParmType *TTPT);
void VisitAutoType(const AutoType *AT);
void VisitTemplateSpecializationType(const TemplateSpecializationType *TST);
void VisitInjectedClassNameType(const InjectedClassNameType *ICNT);
void VisitObjCInterfaceType(const ObjCInterfaceType *OIT);
void VisitPackExpansionType(const PackExpansionType *PET);
void VisitElaboratedType(const ElaboratedType *ET);
void VisitMacroQualifiedType(const MacroQualifiedType *MQT);
void VisitMemberPointerType(const MemberPointerType *MPT);
void VisitNamedDecl(const NamedDecl *ND);
void VisitTypedefDecl(const TypedefDecl *TD);
void VisitTypeAliasDecl(const TypeAliasDecl *TAD);
void VisitNamespaceDecl(const NamespaceDecl *ND);
void VisitUsingDirectiveDecl(const UsingDirectiveDecl *UDD);
void VisitNamespaceAliasDecl(const NamespaceAliasDecl *NAD);
void VisitUsingDecl(const UsingDecl *UD);
void VisitUsingShadowDecl(const UsingShadowDecl *USD);
void VisitVarDecl(const VarDecl *VD);
void VisitFieldDecl(const FieldDecl *FD);
void VisitFunctionDecl(const FunctionDecl *FD);
void VisitEnumDecl(const EnumDecl *ED);
void VisitEnumConstantDecl(const EnumConstantDecl *ECD);
void VisitRecordDecl(const RecordDecl *RD);
void VisitCXXRecordDecl(const CXXRecordDecl *RD);
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
void VisitLinkageSpecDecl(const LinkageSpecDecl *LSD);
void VisitAccessSpecDecl(const AccessSpecDecl *ASD);
void VisitFriendDecl(const FriendDecl *FD);
void VisitObjCIvarDecl(const ObjCIvarDecl *D);
void VisitObjCMethodDecl(const ObjCMethodDecl *D);
void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
void VisitBlockDecl(const BlockDecl *D);
void VisitDeclRefExpr(const DeclRefExpr *DRE);
void VisitPredefinedExpr(const PredefinedExpr *PE);
void VisitUnaryOperator(const UnaryOperator *UO);
void VisitBinaryOperator(const BinaryOperator *BO);
void VisitCompoundAssignOperator(const CompoundAssignOperator *CAO);
void VisitMemberExpr(const MemberExpr *ME);
void VisitCXXNewExpr(const CXXNewExpr *NE);
void VisitCXXDeleteExpr(const CXXDeleteExpr *DE);
void VisitCXXThisExpr(const CXXThisExpr *TE);
void VisitCastExpr(const CastExpr *CE);
void VisitImplicitCastExpr(const ImplicitCastExpr *ICE);
void VisitCallExpr(const CallExpr *CE);
void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *TTE);
void VisitSizeOfPackExpr(const SizeOfPackExpr *SOPE);
void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *ULE);
void VisitAddrLabelExpr(const AddrLabelExpr *ALE);
void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE);
void VisitConstantExpr(const ConstantExpr *CE);
void VisitInitListExpr(const InitListExpr *ILE);
void VisitGenericSelectionExpr(const GenericSelectionExpr *GSE);
void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *UCE);
void VisitCXXConstructExpr(const CXXConstructExpr *CE);
void VisitExprWithCleanups(const ExprWithCleanups *EWC);
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE);
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *MTE);
void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *ME);
void VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE);
void VisitObjCMessageExpr(const ObjCMessageExpr *OME);
void VisitObjCBoxedExpr(const ObjCBoxedExpr *OBE);
void VisitObjCSelectorExpr(const ObjCSelectorExpr *OSE);
void VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE);
void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE);
void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *OSRE);
void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *OIRE);
void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *OBLE);
void VisitIntegerLiteral(const IntegerLiteral *IL);
void VisitCharacterLiteral(const CharacterLiteral *CL);
void VisitFixedPointLiteral(const FixedPointLiteral *FPL);
void VisitFloatingLiteral(const FloatingLiteral *FL);
void VisitStringLiteral(const StringLiteral *SL);
void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *BLE);
void VisitIfStmt(const IfStmt *IS);
void VisitSwitchStmt(const SwitchStmt *SS);
void VisitCaseStmt(const CaseStmt *CS);
void VisitLabelStmt(const LabelStmt *LS);
void VisitGotoStmt(const GotoStmt *GS);
void VisitWhileStmt(const WhileStmt *WS);
void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *OACS);
void VisitNullTemplateArgument(const TemplateArgument &TA);
void VisitTypeTemplateArgument(const TemplateArgument &TA);
void VisitDeclarationTemplateArgument(const TemplateArgument &TA);
void VisitNullPtrTemplateArgument(const TemplateArgument &TA);
void VisitIntegralTemplateArgument(const TemplateArgument &TA);
void VisitTemplateTemplateArgument(const TemplateArgument &TA);
void VisitTemplateExpansionTemplateArgument(const TemplateArgument &TA);
void VisitExpressionTemplateArgument(const TemplateArgument &TA);
void VisitPackTemplateArgument(const TemplateArgument &TA);
void visitTextComment(const comments::TextComment *C,
const comments::FullComment *);
void visitInlineCommandComment(const comments::InlineCommandComment *C,
const comments::FullComment *);
void visitHTMLStartTagComment(const comments::HTMLStartTagComment *C,
const comments::FullComment *);
void visitHTMLEndTagComment(const comments::HTMLEndTagComment *C,
const comments::FullComment *);
void visitBlockCommandComment(const comments::BlockCommandComment *C,
const comments::FullComment *);
void visitParamCommandComment(const comments::ParamCommandComment *C,
const comments::FullComment *FC);
void visitTParamCommandComment(const comments::TParamCommandComment *C,
const comments::FullComment *FC);
void visitVerbatimBlockComment(const comments::VerbatimBlockComment *C,
const comments::FullComment *);
void
visitVerbatimBlockLineComment(const comments::VerbatimBlockLineComment *C,
const comments::FullComment *);
void visitVerbatimLineComment(const comments::VerbatimLineComment *C,
const comments::FullComment *);
};
class JSONDumper : public ASTNodeTraverser<JSONDumper, JSONNodeDumper> {
JSONNodeDumper NodeDumper;
template <typename SpecializationDecl>
void writeTemplateDeclSpecialization(const SpecializationDecl *SD,
bool DumpExplicitInst,
bool DumpRefOnly) {
bool DumpedAny = false;
for (const auto *RedeclWithBadType : SD->redecls()) {
// FIXME: The redecls() range sometimes has elements of a less-specific
// type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
// us TagDecls, and should give CXXRecordDecls).
const auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
if (!Redecl) {
// Found the injected-class-name for a class template. This will be
// dumped as part of its surrounding class so we don't need to dump it
// here.
assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
"expected an injected-class-name");
continue;
}
switch (Redecl->getTemplateSpecializationKind()) {
case TSK_ExplicitInstantiationDeclaration:
case TSK_ExplicitInstantiationDefinition:
if (!DumpExplicitInst)
break;
LLVM_FALLTHROUGH;
case TSK_Undeclared:
case TSK_ImplicitInstantiation:
if (DumpRefOnly)
NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(Redecl); });
else
Visit(Redecl);
DumpedAny = true;
break;
case TSK_ExplicitSpecialization:
break;
}
}
// Ensure we dump at least one decl for each specialization.
if (!DumpedAny)
NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(SD); });
}
template <typename TemplateDecl>
void writeTemplateDecl(const TemplateDecl *TD, bool DumpExplicitInst) {
// FIXME: it would be nice to dump template parameters and specializations
// to their own named arrays rather than shoving them into the "inner"
// array. However, template declarations are currently being handled at the
// wrong "level" of the traversal hierarchy and so it is difficult to
// achieve without losing information elsewhere.
dumpTemplateParameters(TD->getTemplateParameters());
Visit(TD->getTemplatedDecl());
for (const auto *Child : TD->specializations())
writeTemplateDeclSpecialization(Child, DumpExplicitInst,
!TD->isCanonicalDecl());
}
public:
JSONDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx,
const PrintingPolicy &PrintPolicy,
const comments::CommandTraits *Traits)
: NodeDumper(OS, SrcMgr, Ctx, PrintPolicy, Traits) {}
JSONNodeDumper &doGetNodeDelegate() { return NodeDumper; }
void VisitFunctionTemplateDecl(const FunctionTemplateDecl *FTD) {
writeTemplateDecl(FTD, true);
}
void VisitClassTemplateDecl(const ClassTemplateDecl *CTD) {
writeTemplateDecl(CTD, false);
}
void VisitVarTemplateDecl(const VarTemplateDecl *VTD) {
writeTemplateDecl(VTD, false);
}
};
} // namespace clang
#endif // LLVM_CLANG_AST_JSONNODEDUMPER_H

View File

@ -1,9 +1,8 @@
//===--- LambdaCapture.h - Types for C++ Lambda Captures --------*- 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
//
//===----------------------------------------------------------------------===//
///

View File

@ -1,9 +1,8 @@
//===--- LexicallyOrderedRecursiveASTVisitor.h - ----------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- LocInfoType.h - Parsed Type with Location Information---*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- Mangle.h - Mangle C++ Names ----------------------------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -244,6 +243,19 @@ public:
static MicrosoftMangleContext *create(ASTContext &Context,
DiagnosticsEngine &Diags);
};
class ASTNameGenerator {
public:
explicit ASTNameGenerator(ASTContext &Ctx);
~ASTNameGenerator();
bool writeName(const Decl *D, raw_ostream &OS);
std::string getName(const Decl *D);
std::vector<std::string> getAllManglings(const Decl *D);
private:
class Implementation;
std::unique_ptr<Implementation> Impl;
};
}
#endif

View File

@ -1,9 +1,8 @@
//=== MangleNumberingContext.h - Context for mangling numbers ---*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- NSAPI.h - NSFoundation APIs ----------------------------*- 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
//
//===----------------------------------------------------------------------===//

View File

@ -1,9 +1,8 @@
//===- NestedNameSpecifier.h - C++ nested name specifiers -------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===-- NonTrivialTypeVisitor.h - Visitor for non-trivial Types *- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===-- ODRHash.h - Hashing to diagnose ODR failures ------------*- 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
//
//===----------------------------------------------------------------------===//
///

View File

@ -1,9 +1,8 @@
//= OSLog.h - Analysis of calls to os_log builtins --*- 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
//
//===----------------------------------------------------------------------===//
//

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,8 @@
//===--- OperationKinds.def - Operations Database ---------------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -67,6 +66,10 @@ CAST_OPERATION(BitCast)
/// bool b; reinterpret_cast<char&>(b) = 'a';
CAST_OPERATION(LValueBitCast)
/// CK_LValueToRValueBitCast - A conversion that causes us to reinterpret an
/// lvalue as an rvalue of a different type. Created by __builtin_bit_cast.
CAST_OPERATION(LValueToRValueBitCast)
/// CK_LValueToRValue - A conversion which causes the extraction of
/// an r-value from the operand gl-value. The result of an r-value
/// conversion is always unqualified.
@ -201,6 +204,14 @@ CAST_OPERATION(IntegralToFloating)
/// (_Accum) 0.5r
CAST_OPERATION(FixedPointCast)
/// CK_FixedPointToIntegral - Fixed point to integral.
/// (int) 2.0k
CAST_OPERATION(FixedPointToIntegral)
/// CK_IntegralToFixedPoint - Integral to a fixed point.
/// (_Accum) 2
CAST_OPERATION(IntegralToFixedPoint)
/// CK_FixedPointToBoolean - Fixed point to boolean.
/// (bool) 0.5r
CAST_OPERATION(FixedPointToBoolean)

View File

@ -1,9 +1,8 @@
//===- OperationKinds.h - Operation enums -----------------------*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- ParentMap.h - Mappings from Stmts to their Parents -----*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- PrettyDeclStackTrace.h - Stack trace for decl processing -*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- PrettyPrinter.h - Classes for aiding with AST printing -*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,7 +1,8 @@
//===--- QualTypeNames.h - Generate Complete QualType Names ----*- C++ -*-===//
//
// 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
//
// ===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- RawCommentList.h - Classes for processing raw comments -*- 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
//
//===----------------------------------------------------------------------===//

View File

@ -1,9 +1,8 @@
//===- RecordLayout.h - Layout information for a struct/union ---*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -1066,6 +1065,9 @@ DEF_TRAVERSE_TYPE(AttributedType,
DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
DEF_TRAVERSE_TYPE(MacroQualifiedType,
{ TRY_TO(TraverseType(T->getUnderlyingType())); })
DEF_TRAVERSE_TYPE(ElaboratedType, {
if (T->getQualifier()) {
TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
@ -1309,6 +1311,9 @@ DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
DEF_TRAVERSE_TYPELOC(MacroQualifiedType,
{ TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
DEF_TRAVERSE_TYPELOC(AttributedType,
{ TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
@ -1459,9 +1464,9 @@ DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
TRY_TO(TraverseDecl(D->getSpecialization()));
if (D->hasExplicitTemplateArgs()) {
const TemplateArgumentListInfo &args = D->templateArgs();
TRY_TO(TraverseTemplateArgumentLocsHelper(args.getArgumentArray(),
args.size()));
TRY_TO(TraverseTemplateArgumentLocsHelper(
D->getTemplateArgsAsWritten()->getTemplateArgs(),
D->getTemplateArgsAsWritten()->NumTemplateArgs));
}
})
@ -1590,7 +1595,7 @@ DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
TRY_TO(TraverseStmt(I));
}
})
DEF_TRAVERSE_DECL(OMPRequiresDecl, {
for (auto *C : D->clauselists()) {
TRY_TO(TraverseOMPClause(C));
@ -1605,8 +1610,22 @@ DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
return true;
})
DEF_TRAVERSE_DECL(OMPDeclareMapperDecl, {
for (auto *C : D->clauselists())
TRY_TO(TraverseOMPClause(C));
TRY_TO(TraverseType(D->getType()));
return true;
})
DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
DEF_TRAVERSE_DECL(OMPAllocateDecl, {
for (auto *I : D->varlists())
TRY_TO(TraverseStmt(I));
for (auto *C : D->clauselists())
TRY_TO(TraverseOMPClause(C));
})
// A helper method for TemplateDecl's children.
template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
@ -1781,6 +1800,11 @@ DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
})
DEF_TRAVERSE_DECL(ConceptDecl, {
TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
TRY_TO(TraverseStmt(D->getConstraintExpr()));
})
DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
// A dependent using declaration which was marked with 'typename'.
// template<class T> class A : public B<T> { using typename B<T>::foo; };
@ -2263,6 +2287,10 @@ DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
})
DEF_TRAVERSE_STMT(BuiltinBitCastExpr, {
TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
})
template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
InitListExpr *S, DataRecursionQueue *Queue) {
@ -2301,10 +2329,10 @@ bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(
// generic associations).
DEF_TRAVERSE_STMT(GenericSelectionExpr, {
TRY_TO(TraverseStmt(S->getControllingExpr()));
for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAssocExpr(i));
for (const GenericSelectionExpr::Association &Assoc : S->associations()) {
if (TypeSourceInfo *TSI = Assoc.getTypeSourceInfo())
TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Assoc.getAssociationExpr());
}
ShouldVisitChildren = false;
})
@ -2410,6 +2438,10 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>();
for (Decl *D : S->getExplicitTemplateParameters()) {
// Visit explicit template parameters.
TRY_TO(TraverseDecl(D));
}
if (S->hasExplicitParameters()) {
// Visit parameters.
for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I)
@ -2527,6 +2559,8 @@ DEF_TRAVERSE_STMT(PredefinedExpr, {})
DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
DEF_TRAVERSE_STMT(StmtExpr, {})
DEF_TRAVERSE_STMT(SourceLocExpr, {})
DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
if (S->hasExplicitTemplateArgs()) {
@ -2813,6 +2847,20 @@ bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
return true;
}
template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPAllocatorClause(
OMPAllocatorClause *C) {
TRY_TO(TraverseStmt(C->getAllocator()));
return true;
}
template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPAllocateClause(OMPAllocateClause *C) {
TRY_TO(TraverseStmt(C->getAllocator()));
TRY_TO(VisitOMPClauseList(C));
return true;
}
template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
TRY_TO(VisitOMPClauseWithPreInit(C));

View File

@ -1,9 +1,8 @@
//===- Redeclarable.h - Base for Decls that can be redeclared --*- 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
//
//===----------------------------------------------------------------------===//
//
@ -362,6 +361,13 @@ public:
decl_type &operator*() { return *Ptr; }
const decl_type &operator*() const { return *Ptr; }
friend bool operator==(CanonicalDeclPtr LHS, CanonicalDeclPtr RHS) {
return LHS.Ptr == RHS.Ptr;
}
friend bool operator!=(CanonicalDeclPtr LHS, CanonicalDeclPtr RHS) {
return LHS.Ptr != RHS.Ptr;
}
private:
friend struct llvm::DenseMapInfo<CanonicalDeclPtr<decl_type>>;

View File

@ -1,9 +1,8 @@
//===--- SelectorLocationsKind.h - Kind of selector locations ---*- 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
//
//===----------------------------------------------------------------------===//
//

View File

@ -1,9 +1,8 @@
//===- Stmt.h - Classes for representing statements -------------*- 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
//
//===----------------------------------------------------------------------===//
//
@ -47,6 +46,7 @@ class Attr;
class CapturedDecl;
class Decl;
class Expr;
class AddrLabelExpr;
class LabelDecl;
class ODRHash;
class PrinterHelper;
@ -92,12 +92,20 @@ protected:
//===--- Statement bitfields classes ---===//
class StmtBitfields {
friend class ASTStmtReader;
friend class ASTStmtWriter;
friend class Stmt;
/// The statement class.
unsigned sClass : 8;
/// This bit is set only for the Stmts that are the structured-block of
/// OpenMP executable directives. Directives that have a structured block
/// are called "non-standalone" directives.
/// I.e. those returned by OMPExecutableDirective::getStructuredBlock().
unsigned IsOMPStructuredBlock : 1;
};
enum { NumStmtBits = 8 };
enum { NumStmtBits = 9 };
class NullStmtBitfields {
friend class ASTStmtReader;
@ -314,6 +322,33 @@ protected:
};
enum { NumExprBits = NumStmtBits + 9 };
class ConstantExprBitfields {
friend class ASTStmtReader;
friend class ASTStmtWriter;
friend class ConstantExpr;
unsigned : NumExprBits;
/// The kind of result that is trail-allocated.
unsigned ResultKind : 2;
/// Kind of Result as defined by APValue::Kind
unsigned APValueKind : 4;
/// When ResultKind == RSK_Int64. whether the trail-allocated integer is
/// signed.
unsigned IsUnsigned : 1;
/// When ResultKind == RSK_Int64. the BitWidth of the trail-allocated
/// integer. 7 bits because it is the minimal number of bit to represent a
/// value from 0 to 64 (the size of the trail-allocated number).
unsigned BitWidth : 7;
/// When ResultKind == RSK_APValue. Wether the ASTContext will cleanup the
/// destructor on the trail-allocated APValue.
unsigned HasCleanup : 1;
};
class PredefinedExprBitfields {
friend class ASTStmtReader;
friend class PredefinedExpr;
@ -343,19 +378,12 @@ protected:
unsigned HasFoundDecl : 1;
unsigned HadMultipleCandidates : 1;
unsigned RefersToEnclosingVariableOrCapture : 1;
unsigned NonOdrUseReason : 2;
/// The location of the declaration name itself.
SourceLocation Loc;
};
enum APFloatSemantics {
IEEEhalf,
IEEEsingle,
IEEEdouble,
x87DoubleExtended,
IEEEquad,
PPCDoubleDouble
};
class FloatingLiteralBitfields {
friend class FloatingLiteral;
@ -445,6 +473,7 @@ protected:
enum { NumCallExprBits = 32 };
class MemberExprBitfields {
friend class ASTStmtReader;
friend class MemberExpr;
unsigned : NumExprBits;
@ -469,6 +498,11 @@ protected:
/// was resolved from an overloaded set having size greater than 1.
unsigned HadMultipleCandidates : 1;
/// Value of type NonOdrUseReason indicating why this MemberExpr does
/// not constitute an odr-use of the named declaration. Meaningful only
/// when naming a static member.
unsigned NonOdrUseReason : 2;
/// This is the location of the -> or . in the expression.
SourceLocation OperatorLoc;
};
@ -521,6 +555,16 @@ protected:
unsigned NumExprs;
};
class GenericSelectionExprBitfields {
friend class ASTStmtReader;
friend class GenericSelectionExpr;
unsigned : NumExprBits;
/// The location of the "_Generic".
SourceLocation GenericLoc;
};
class PseudoObjectExprBitfields {
friend class ASTStmtReader; // deserialization
friend class PseudoObjectExpr;
@ -533,6 +577,17 @@ protected:
unsigned ResultIndex : 32 - 8 - NumExprBits;
};
class SourceLocExprBitfields {
friend class ASTStmtReader;
friend class SourceLocExpr;
unsigned : NumExprBits;
/// The kind of source location builtin represented by the SourceLocExpr.
/// Ex. __builtin_LINE, __builtin_FUNCTION, ect.
unsigned Kind : 2;
};
//===--- C++ Expression bitfields classes ---===//
class CXXOperatorCallExprBitfields {
@ -902,6 +957,7 @@ protected:
// Expressions
ExprBitfields ExprBits;
ConstantExprBitfields ConstantExprBits;
PredefinedExprBitfields PredefinedExprBits;
DeclRefExprBitfields DeclRefExprBits;
FloatingLiteralBitfields FloatingLiteralBits;
@ -916,7 +972,9 @@ protected:
BinaryOperatorBitfields BinaryOperatorBits;
InitListExprBitfields InitListExprBits;
ParenListExprBitfields ParenListExprBits;
GenericSelectionExprBitfields GenericSelectionExprBits;
PseudoObjectExprBitfields PseudoObjectExprBits;
SourceLocExprBitfields SourceLocExprBits;
// C++ Expressions
CXXOperatorCallExprBitfields CXXOperatorCallExprBits;
@ -976,37 +1034,30 @@ public:
struct EmptyShell {};
protected:
/// Iterator for iterating over Stmt * arrays that contain only Expr *
/// Iterator for iterating over Stmt * arrays that contain only T *.
///
/// This is needed because AST nodes use Stmt* arrays to store
/// references to children (to be compatible with StmtIterator).
struct ExprIterator
: llvm::iterator_adaptor_base<ExprIterator, Stmt **,
std::random_access_iterator_tag, Expr *> {
ExprIterator() : iterator_adaptor_base(nullptr) {}
ExprIterator(Stmt **I) : iterator_adaptor_base(I) {}
template<typename T, typename TPtr = T *, typename StmtPtr = Stmt *>
struct CastIterator
: llvm::iterator_adaptor_base<CastIterator<T, TPtr, StmtPtr>, StmtPtr *,
std::random_access_iterator_tag, TPtr> {
using Base = typename CastIterator::iterator_adaptor_base;
reference operator*() const {
assert((*I)->getStmtClass() >= firstExprConstant &&
(*I)->getStmtClass() <= lastExprConstant);
return *reinterpret_cast<Expr **>(I);
CastIterator() : Base(nullptr) {}
CastIterator(StmtPtr *I) : Base(I) {}
typename Base::value_type operator*() const {
return cast_or_null<T>(*this->I);
}
};
/// Const iterator for iterating over Stmt * arrays that contain only Expr *
struct ConstExprIterator
: llvm::iterator_adaptor_base<ConstExprIterator, const Stmt *const *,
std::random_access_iterator_tag,
const Expr *const> {
ConstExprIterator() : iterator_adaptor_base(nullptr) {}
ConstExprIterator(const Stmt *const *I) : iterator_adaptor_base(I) {}
/// Const iterator for iterating over Stmt * arrays that contain only T *.
template <typename T>
using ConstCastIterator = CastIterator<T, const T *const, const Stmt *const>;
reference operator*() const {
assert((*I)->getStmtClass() >= firstExprConstant &&
(*I)->getStmtClass() <= lastExprConstant);
return *reinterpret_cast<const Expr *const *>(I);
}
};
using ExprIterator = CastIterator<Expr>;
using ConstExprIterator = ConstCastIterator<Expr>;
private:
/// Whether statistic collection is enabled.
@ -1017,12 +1068,19 @@ protected:
explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
public:
Stmt() = delete;
Stmt(const Stmt &) = delete;
Stmt(Stmt &&) = delete;
Stmt &operator=(const Stmt &) = delete;
Stmt &operator=(Stmt &&) = delete;
Stmt(StmtClass SC) {
static_assert(sizeof(*this) <= 8,
"changing bitfields changed sizeof(Stmt)");
static_assert(sizeof(*this) % alignof(void *) == 0,
"Insufficient alignment!");
StmtBits.sClass = SC;
StmtBits.IsOMPStructuredBlock = false;
if (StatisticsEnabled) Stmt::addStmtClass(SC);
}
@ -1032,6 +1090,11 @@ public:
const char *getStmtClassName() const;
bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }
void setIsOMPStructuredBlock(bool IsOMPStructuredBlock) {
StmtBits.IsOMPStructuredBlock = IsOMPStructuredBlock;
}
/// SourceLocation tokens are not useful in isolation - they are low level
/// value objects created/interpreted by SourceManager. We assume AST
/// clients will have a pointer to the respective SourceManager.
@ -1065,17 +1128,14 @@ public:
StringRef NewlineSymbol = "\n",
const ASTContext *Context = nullptr) const;
/// Pretty-prints in JSON format.
void printJson(raw_ostream &Out, PrinterHelper *Helper,
const PrintingPolicy &Policy, bool AddQuotes) const;
/// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
/// works on systems with GraphViz (Mac OS X) or dot+gv installed.
void viewAST() const;
/// Skip past any implicit AST nodes which might surround this
/// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
Stmt *IgnoreImplicit();
const Stmt *IgnoreImplicit() const {
return const_cast<Stmt *>(this)->IgnoreImplicit();
}
/// Skip no-op (attributed, compound) container stmts and skip captured
/// stmt at the top, if \a IgnoreCaptured is true.
Stmt *IgnoreContainers(bool IgnoreCaptured = false);
@ -1178,6 +1238,11 @@ public:
child_iterator(DG.end(), DG.end()));
}
const_child_range children() const {
auto Children = const_cast<DeclStmt *>(this)->children();
return const_child_range(Children);
}
using decl_iterator = DeclGroupRef::iterator;
using const_decl_iterator = DeclGroupRef::const_iterator;
using decl_range = llvm::iterator_range<decl_iterator>;
@ -1235,6 +1300,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());
}
};
/// CompoundStmt - This represents a group of statements like { stmt stmt }.
@ -1280,11 +1349,6 @@ public:
return !body_empty() ? body_begin()[size() - 1] : nullptr;
}
void setLastStmt(Stmt *S) {
assert(!body_empty() && "setLastStmt");
body_begin()[size() - 1] = S;
}
using const_body_iterator = Stmt *const *;
using body_const_range = llvm::iterator_range<const_body_iterator>;
@ -1327,6 +1391,26 @@ public:
return const_reverse_body_iterator(body_begin());
}
// Get the Stmt that StmtExpr would consider to be the result of this
// compound statement. This is used by StmtExpr to properly emulate the GCC
// compound expression extension, which ignores trailing NullStmts when
// getting the result of the expression.
// i.e. ({ 5;;; })
// ^^ ignored
// If we don't find something that isn't a NullStmt, just return the last
// Stmt.
Stmt *getStmtExprResult() {
for (auto *B : llvm::reverse(body())) {
if (!isa<NullStmt>(B))
return B;
}
return body_back();
}
const Stmt *getStmtExprResult() const {
return const_cast<CompoundStmt *>(this)->getStmtExprResult();
}
SourceLocation getBeginLoc() const { return CompoundStmtBits.LBraceLoc; }
SourceLocation getEndLoc() const { return RBraceLoc; }
@ -1539,6 +1623,12 @@ public:
getTrailingObjects<Stmt *>() +
numTrailingObjects(OverloadToken<Stmt *>()));
}
const_child_range children() const {
return const_child_range(getTrailingObjects<Stmt *>(),
getTrailingObjects<Stmt *>() +
numTrailingObjects(OverloadToken<Stmt *>()));
}
};
class DefaultStmt : public SwitchCase {
@ -1570,6 +1660,10 @@ public:
// Iterators
child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
const_child_range children() const {
return const_child_range(&SubStmt, &SubStmt + 1);
}
};
SourceLocation SwitchCase::getEndLoc() const {
@ -1588,21 +1682,44 @@ Stmt *SwitchCase::getSubStmt() {
llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
}
/// Represents a statement that could possibly have a value and type. This
/// covers expression-statements, as well as labels and attributed statements.
///
/// Value statements have a special meaning when they are the last non-null
/// statement in a GNU statement expression, where they determine the value
/// of the statement expression.
class ValueStmt : public Stmt {
protected:
using Stmt::Stmt;
public:
const Expr *getExprStmt() const;
Expr *getExprStmt() {
const ValueStmt *ConstThis = this;
return const_cast<Expr*>(ConstThis->getExprStmt());
}
static bool classof(const Stmt *T) {
return T->getStmtClass() >= firstValueStmtConstant &&
T->getStmtClass() <= lastValueStmtConstant;
}
};
/// LabelStmt - Represents a label, which has a substatement. For example:
/// foo: return;
class LabelStmt : public Stmt {
class LabelStmt : public ValueStmt {
LabelDecl *TheDecl;
Stmt *SubStmt;
public:
/// Build a label statement.
LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
: Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) {
: ValueStmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) {
setIdentLoc(IL);
}
/// Build an empty label statement.
explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) {}
explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {}
SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; }
void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; }
@ -1621,6 +1738,10 @@ public:
child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
const_child_range children() const {
return const_child_range(&SubStmt, &SubStmt + 1);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == LabelStmtClass;
}
@ -1631,7 +1752,7 @@ public:
/// Represents an attribute applied to a statement. For example:
/// [[omp::for(...)]] for (...) { ... }
class AttributedStmt final
: public Stmt,
: public ValueStmt,
private llvm::TrailingObjects<AttributedStmt, const Attr *> {
friend class ASTStmtReader;
friend TrailingObjects;
@ -1640,14 +1761,14 @@ class AttributedStmt final
AttributedStmt(SourceLocation Loc, ArrayRef<const Attr *> Attrs,
Stmt *SubStmt)
: Stmt(AttributedStmtClass), SubStmt(SubStmt) {
: ValueStmt(AttributedStmtClass), SubStmt(SubStmt) {
AttributedStmtBits.NumAttrs = Attrs.size();
AttributedStmtBits.AttrLoc = Loc;
std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr());
}
explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
: Stmt(AttributedStmtClass, Empty) {
: ValueStmt(AttributedStmtClass, Empty) {
AttributedStmtBits.NumAttrs = NumAttrs;
AttributedStmtBits.AttrLoc = SourceLocation{};
std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
@ -1678,6 +1799,10 @@ public:
child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
const_child_range children() const {
return const_child_range(&SubStmt, &SubStmt + 1);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == AttributedStmtClass;
}
@ -1877,6 +2002,12 @@ public:
numTrailingObjects(OverloadToken<Stmt *>()));
}
const_child_range children() const {
return const_child_range(getTrailingObjects<Stmt *>(),
getTrailingObjects<Stmt *>() +
numTrailingObjects(OverloadToken<Stmt *>()));
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == IfStmtClass;
}
@ -2054,6 +2185,12 @@ public:
numTrailingObjects(OverloadToken<Stmt *>()));
}
const_child_range children() const {
return const_child_range(getTrailingObjects<Stmt *>(),
getTrailingObjects<Stmt *>() +
numTrailingObjects(OverloadToken<Stmt *>()));
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == SwitchStmtClass;
}
@ -2179,6 +2316,12 @@ public:
getTrailingObjects<Stmt *>() +
numTrailingObjects(OverloadToken<Stmt *>()));
}
const_child_range children() const {
return const_child_range(getTrailingObjects<Stmt *>(),
getTrailingObjects<Stmt *>() +
numTrailingObjects(OverloadToken<Stmt *>()));
}
};
/// DoStmt - This represents a 'do/while' stmt.
@ -2229,6 +2372,10 @@ public:
child_range children() {
return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
}
const_child_range children() const {
return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
}
};
/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
@ -2298,6 +2445,10 @@ public:
child_range children() {
return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
}
const_child_range children() const {
return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
}
};
/// GotoStmt - This represents a direct goto.
@ -2333,6 +2484,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());
}
};
/// IndirectGotoStmt - This represents an indirect goto.
@ -2378,6 +2533,10 @@ public:
// Iterators
child_range children() { return child_range(&Target, &Target + 1); }
const_child_range children() const {
return const_child_range(&Target, &Target + 1);
}
};
/// ContinueStmt - This represents a continue.
@ -2404,6 +2563,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());
}
};
/// BreakStmt - This represents a break.
@ -2430,6 +2593,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());
}
};
/// ReturnStmt - This represents a return, optionally of an expression:
@ -2514,6 +2681,12 @@ public:
return child_range(&RetExpr, &RetExpr + 1);
return child_range(child_iterator(), child_iterator());
}
const_child_range children() const {
if (RetExpr)
return const_child_range(&RetExpr, &RetExpr + 1);
return const_child_range(const_child_iterator(), const_child_iterator());
}
};
/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
@ -2669,6 +2842,10 @@ public:
child_range children() {
return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
}
const_child_range children() const {
return const_child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
}
};
/// This represents a GCC inline-assembly statement extension.
@ -2682,13 +2859,15 @@ class GCCAsmStmt : public AsmStmt {
StringLiteral **Constraints = nullptr;
StringLiteral **Clobbers = nullptr;
IdentifierInfo **Names = nullptr;
unsigned NumLabels = 0;
public:
GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
bool isvolatile, unsigned numoutputs, unsigned numinputs,
IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
StringLiteral *asmstr, unsigned numclobbers,
StringLiteral **clobbers, SourceLocation rparenloc);
StringLiteral **clobbers, unsigned numlabels,
SourceLocation rparenloc);
/// Build an empty inline-assembly statement.
explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
@ -2813,6 +2992,51 @@ public:
return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
}
//===--- Labels ---===//
bool isAsmGoto() const {
return NumLabels > 0;
}
unsigned getNumLabels() const {
return NumLabels;
}
IdentifierInfo *getLabelIdentifier(unsigned i) const {
return Names[i + NumInputs];
}
AddrLabelExpr *getLabelExpr(unsigned i) const;
StringRef getLabelName(unsigned i) const;
using labels_iterator = CastIterator<AddrLabelExpr>;
using const_labels_iterator = ConstCastIterator<AddrLabelExpr>;
using labels_range = llvm::iterator_range<labels_iterator>;
using labels_const_range = llvm::iterator_range<const_labels_iterator>;
labels_iterator begin_labels() {
return &Exprs[0] + NumInputs;
}
labels_iterator end_labels() {
return &Exprs[0] + NumInputs + NumLabels;
}
labels_range labels() {
return labels_range(begin_labels(), end_labels());
}
const_labels_iterator begin_labels() const {
return &Exprs[0] + NumInputs;
}
const_labels_iterator end_labels() const {
return &Exprs[0] + NumInputs + NumLabels;
}
labels_const_range labels() const {
return labels_const_range(begin_labels(), end_labels());
}
private:
void setOutputsAndInputsAndClobbers(const ASTContext &C,
IdentifierInfo **Names,
@ -2820,6 +3044,7 @@ private:
Stmt **Exprs,
unsigned NumOutputs,
unsigned NumInputs,
unsigned NumLabels,
StringLiteral **Clobbers,
unsigned NumClobbers);
@ -2945,6 +3170,10 @@ public:
child_range children() {
return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
}
const_child_range children() const {
return const_child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
}
};
class SEHExceptStmt : public Stmt {
@ -2982,6 +3211,10 @@ public:
return child_range(Children, Children+2);
}
const_child_range children() const {
return const_child_range(Children, Children + 2);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == SEHExceptStmtClass;
}
@ -3013,6 +3246,10 @@ public:
return child_range(&Block,&Block+1);
}
const_child_range children() const {
return const_child_range(&Block, &Block + 1);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == SEHFinallyStmtClass;
}
@ -3061,6 +3298,10 @@ public:
return child_range(Children, Children+2);
}
const_child_range children() const {
return const_child_range(Children, Children + 2);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == SEHTryStmtClass;
}
@ -3091,6 +3332,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());
}
};
/// This captures a statement into a function. For example, the following
@ -3311,6 +3556,8 @@ public:
}
child_range children();
const_child_range children() const;
};
} // namespace clang

View File

@ -1,9 +1,8 @@
//===--- StmtCXX.h - Classes for representing C++ statements ----*- 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
//
//===----------------------------------------------------------------------===//
//
@ -57,6 +56,10 @@ public:
child_range children() { return child_range(&HandlerBlock, &HandlerBlock+1); }
const_child_range children() const {
return const_child_range(&HandlerBlock, &HandlerBlock + 1);
}
friend class ASTStmtReader;
};
@ -115,6 +118,10 @@ public:
child_range children() {
return child_range(getStmts(), getStmts() + getNumHandlers() + 1);
}
const_child_range children() const {
return const_child_range(getStmts(), getStmts() + getNumHandlers() + 1);
}
};
/// CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for
@ -209,6 +216,10 @@ public:
child_range children() {
return child_range(&SubExprs[0], &SubExprs[END]);
}
const_child_range children() const {
return const_child_range(&SubExprs[0], &SubExprs[END]);
}
};
/// Representation of a Microsoft __if_exists or __if_not_exists
@ -291,6 +302,10 @@ public:
return child_range(&SubStmt, &SubStmt+1);
}
const_child_range children() const {
return const_child_range(&SubStmt, &SubStmt + 1);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == MSDependentExistsStmtClass;
}
@ -416,6 +431,12 @@ public:
getStoredStmts() + SubStmt::FirstParamMove + NumParams);
}
const_child_range children() const {
return const_child_range(getStoredStmts(), getStoredStmts() +
SubStmt::FirstParamMove +
NumParams);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == CoroutineBodyStmtClass;
}
@ -480,6 +501,13 @@ public:
return child_range(SubStmts, SubStmts + SubStmt::Count);
}
const_child_range children() const {
if (!getOperand())
return const_child_range(SubStmts + SubStmt::PromiseCall,
SubStmts + SubStmt::Count);
return const_child_range(SubStmts, SubStmts + SubStmt::Count);
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == CoreturnStmtClass;
}

View File

@ -189,8 +189,8 @@ class CXXFoldExpr {
}
class GenericSelectionExpr {
code Code = [{
for (unsigned i = 0; i < S->getNumAssocs(); ++i) {
addData(S->getAssocType(i));
for (const GenericSelectionExpr::ConstAssociation &Assoc : S->associations()) {
addData(Assoc.getType());
}
}];
}

View File

@ -1,9 +1,8 @@
//===- StmtGraphTraits.h - Graph Traits for the class Stmt ------*- 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
//
//===----------------------------------------------------------------------===//
//

Some files were not shown because too many files have changed in this diff Show More