diff options
author | thegeorg <thegeorg@yandex-team.com> | 2024-03-13 13:58:24 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2024-03-13 14:11:53 +0300 |
commit | 11a895b7e15d1c5a1f52706396b82e3f9db953cb (patch) | |
tree | fabc6d883b0f946151f61ae7865cee9f529a1fdd /contrib/libs/clang16/include/clang/Sema/Designator.h | |
parent | 9685917341315774aad5733b1793b1e533a88bbb (diff) | |
download | ydb-11a895b7e15d1c5a1f52706396b82e3f9db953cb.tar.gz |
Export clang-format16 via ydblib project
6e6be3a95868fde888d801b7590af4044049563f
Diffstat (limited to 'contrib/libs/clang16/include/clang/Sema/Designator.h')
-rw-r--r-- | contrib/libs/clang16/include/clang/Sema/Designator.h | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/contrib/libs/clang16/include/clang/Sema/Designator.h b/contrib/libs/clang16/include/clang/Sema/Designator.h new file mode 100644 index 0000000000..b449537566 --- /dev/null +++ b/contrib/libs/clang16/include/clang/Sema/Designator.h @@ -0,0 +1,225 @@ +#pragma once + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif + +//===--- Designator.h - Initialization Designator ---------------*- C++ -*-===// +// +// 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 defines interfaces used to represent designators (a la +// C99 designated initializers) during parsing. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_SEMA_DESIGNATOR_H +#define LLVM_CLANG_SEMA_DESIGNATOR_H + +#include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/SmallVector.h" + +namespace clang { + +class Expr; +class IdentifierInfo; +class Sema; + +/// Designator - A designator in a C99 designated initializer. +/// +/// This class is a discriminated union which holds the various +/// different sorts of designators possible. A Designation is an array of +/// these. An example of a designator are things like this: +/// [8] .field [47] // C99 designation: 3 designators +/// [8 ... 47] field: // GNU extensions: 2 designators +/// These occur in initializers, e.g.: +/// int a[10] = {2, 4, [8]=9, 10}; +/// +class Designator { +public: + enum DesignatorKind { + FieldDesignator, ArrayDesignator, ArrayRangeDesignator + }; +private: + Designator() {}; + + DesignatorKind Kind; + + struct FieldDesignatorInfo { + const IdentifierInfo *II; + SourceLocation DotLoc; + SourceLocation NameLoc; + }; + struct ArrayDesignatorInfo { + Expr *Index; + SourceLocation LBracketLoc; + mutable SourceLocation RBracketLoc; + }; + struct ArrayRangeDesignatorInfo { + Expr *Start, *End; + SourceLocation LBracketLoc, EllipsisLoc; + mutable SourceLocation RBracketLoc; + }; + + union { + FieldDesignatorInfo FieldInfo; + ArrayDesignatorInfo ArrayInfo; + ArrayRangeDesignatorInfo ArrayRangeInfo; + }; + +public: + + DesignatorKind getKind() const { return Kind; } + bool isFieldDesignator() const { return Kind == FieldDesignator; } + bool isArrayDesignator() const { return Kind == ArrayDesignator; } + bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } + + const IdentifierInfo *getField() const { + assert(isFieldDesignator() && "Invalid accessor"); + return FieldInfo.II; + } + + SourceLocation getDotLoc() const { + assert(isFieldDesignator() && "Invalid accessor"); + return FieldInfo.DotLoc; + } + + SourceLocation getFieldLoc() const { + assert(isFieldDesignator() && "Invalid accessor"); + return FieldInfo.NameLoc; + } + + Expr *getArrayIndex() const { + assert(isArrayDesignator() && "Invalid accessor"); + return ArrayInfo.Index; + } + + Expr *getArrayRangeStart() const { + assert(isArrayRangeDesignator() && "Invalid accessor"); + return ArrayRangeInfo.Start; + } + Expr *getArrayRangeEnd() const { + assert(isArrayRangeDesignator() && "Invalid accessor"); + return ArrayRangeInfo.End; + } + + SourceLocation getLBracketLoc() const { + assert((isArrayDesignator() || isArrayRangeDesignator()) && + "Invalid accessor"); + if (isArrayDesignator()) + return ArrayInfo.LBracketLoc; + else + return ArrayRangeInfo.LBracketLoc; + } + + SourceLocation getRBracketLoc() const { + assert((isArrayDesignator() || isArrayRangeDesignator()) && + "Invalid accessor"); + if (isArrayDesignator()) + return ArrayInfo.RBracketLoc; + else + return ArrayRangeInfo.RBracketLoc; + } + + SourceLocation getEllipsisLoc() const { + assert(isArrayRangeDesignator() && "Invalid accessor"); + return ArrayRangeInfo.EllipsisLoc; + } + + static Designator getField(const IdentifierInfo *II, SourceLocation DotLoc, + SourceLocation NameLoc) { + Designator D; + D.Kind = FieldDesignator; + new (&D.FieldInfo) FieldDesignatorInfo; + D.FieldInfo.II = II; + D.FieldInfo.DotLoc = DotLoc; + D.FieldInfo.NameLoc = NameLoc; + return D; + } + + static Designator getArray(Expr *Index, + SourceLocation LBracketLoc) { + Designator D; + D.Kind = ArrayDesignator; + new (&D.ArrayInfo) ArrayDesignatorInfo; + D.ArrayInfo.Index = Index; + D.ArrayInfo.LBracketLoc = LBracketLoc; + D.ArrayInfo.RBracketLoc = SourceLocation(); + return D; + } + + static Designator getArrayRange(Expr *Start, + Expr *End, + SourceLocation LBracketLoc, + SourceLocation EllipsisLoc) { + Designator D; + D.Kind = ArrayRangeDesignator; + new (&D.ArrayRangeInfo) ArrayRangeDesignatorInfo; + D.ArrayRangeInfo.Start = Start; + D.ArrayRangeInfo.End = End; + D.ArrayRangeInfo.LBracketLoc = LBracketLoc; + D.ArrayRangeInfo.EllipsisLoc = EllipsisLoc; + D.ArrayRangeInfo.RBracketLoc = SourceLocation(); + return D; + } + + void setRBracketLoc(SourceLocation RBracketLoc) const { + assert((isArrayDesignator() || isArrayRangeDesignator()) && + "Invalid accessor"); + if (isArrayDesignator()) + ArrayInfo.RBracketLoc = RBracketLoc; + else + ArrayRangeInfo.RBracketLoc = RBracketLoc; + } + + /// ClearExprs - Null out any expression references, which prevents + /// them from being 'delete'd later. + void ClearExprs(Sema &Actions) {} + + /// FreeExprs - Release any unclaimed memory for the expressions in + /// this designator. + void FreeExprs(Sema &Actions) {} +}; + + +/// Designation - Represent a full designation, which is a sequence of +/// designators. This class is mostly a helper for InitListDesignations. +class Designation { + /// Designators - The actual designators for this initializer. + SmallVector<Designator, 2> Designators; + +public: + /// AddDesignator - Add a designator to the end of this list. + void AddDesignator(Designator D) { + Designators.push_back(D); + } + + bool empty() const { return Designators.empty(); } + + unsigned getNumDesignators() const { return Designators.size(); } + const Designator &getDesignator(unsigned Idx) const { + assert(Idx < Designators.size()); + return Designators[Idx]; + } + + /// ClearExprs - Null out any expression references, which prevents them from + /// being 'delete'd later. + void ClearExprs(Sema &Actions) {} + + /// FreeExprs - Release any unclaimed memory for the expressions in this + /// designation. + void FreeExprs(Sema &Actions) {} +}; + +} // end namespace clang + +#endif + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif |