clang  12.0.0git
ASTConcept.h
Go to the documentation of this file.
1 //===--- ASTConcept.h - Concepts Related AST Data Structures ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file provides AST data structures related to concepts.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_AST_ASTCONCEPT_H
16 #define LLVM_CLANG_AST_ASTCONCEPT_H
17 #include "clang/AST/Expr.h"
19 #include "llvm/ADT/PointerUnion.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include <string>
22 #include <utility>
23 namespace clang {
24 class ConceptDecl;
25 class ConceptSpecializationExpr;
26 
27 /// The result of a constraint satisfaction check, containing the necessary
28 /// information to diagnose an unsatisfied constraint.
29 class ConstraintSatisfaction : public llvm::FoldingSetNode {
30  // The template-like entity that 'owns' the constraint checked here (can be a
31  // constrained entity or a concept).
32  const NamedDecl *ConstraintOwner = nullptr;
34 
35 public:
36 
37  ConstraintSatisfaction() = default;
38 
39  ConstraintSatisfaction(const NamedDecl *ConstraintOwner,
40  ArrayRef<TemplateArgument> TemplateArgs) :
41  ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs.begin(),
42  TemplateArgs.end()) { }
43 
44  using SubstitutionDiagnostic = std::pair<SourceLocation, StringRef>;
45  using Detail = llvm::PointerUnion<Expr *, SubstitutionDiagnostic *>;
46 
47  bool IsSatisfied = false;
48 
49  /// \brief Pairs of unsatisfied atomic constraint expressions along with the
50  /// substituted constraint expr, if the template arguments could be
51  /// substituted into them, or a diagnostic if substitution resulted in an
52  /// invalid expression.
54 
55  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) {
56  Profile(ID, C, ConstraintOwner, TemplateArgs);
57  }
58 
59  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C,
60  const NamedDecl *ConstraintOwner,
61  ArrayRef<TemplateArgument> TemplateArgs);
62 };
63 
64 /// Pairs of unsatisfied atomic constraint expressions along with the
65 /// substituted constraint expr, if the template arguments could be
66 /// substituted into them, or a diagnostic if substitution resulted in
67 /// an invalid expression.
69  std::pair<const Expr *,
70  llvm::PointerUnion<Expr *,
71  std::pair<SourceLocation, StringRef> *>>;
72 
73 /// \brief The result of a constraint satisfaction check, containing the
74 /// necessary information to diagnose an unsatisfied constraint.
75 ///
76 /// This is safe to store in an AST node, as opposed to ConstraintSatisfaction.
78  llvm::TrailingObjects<ASTConstraintSatisfaction,
79  UnsatisfiedConstraintRecord> {
81  bool IsSatisfied : 1;
82 
84  return getTrailingObjects<UnsatisfiedConstraintRecord>();
85  }
86 
88  return getTrailingObjects<UnsatisfiedConstraintRecord>() + NumRecords;
89  }
90 
92  const ConstraintSatisfaction &Satisfaction);
93 
94  static ASTConstraintSatisfaction *
95  Create(const ASTContext &C, const ConstraintSatisfaction &Satisfaction);
96 };
97 
98 /// \brief Common data class for constructs that reference concepts with
99 /// template arguments.
101 protected:
102  // \brief The optional nested name specifier used when naming the concept.
104 
105  /// \brief The location of the template keyword, if specified when naming the
106  /// concept.
108 
109  /// \brief The concept name used.
111 
112  /// \brief The declaration found by name lookup when the expression was
113  /// created.
114  /// Can differ from NamedConcept when, for example, the concept was found
115  /// through a UsingShadowDecl.
117 
118  /// \brief The concept named.
120 
121  /// \brief The template argument list source info used to specialize the
122  /// concept.
124 
125 public:
126 
128  DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl,
129  ConceptDecl *NamedConcept,
130  const ASTTemplateArgumentListInfo *ArgsAsWritten) :
131  NestedNameSpec(NNS), TemplateKWLoc(TemplateKWLoc),
132  ConceptName(ConceptNameInfo), FoundDecl(FoundDecl),
133  NamedConcept(NamedConcept), ArgsAsWritten(ArgsAsWritten) {}
134 
135  ConceptReference() : NestedNameSpec(), TemplateKWLoc(), ConceptName(),
136  FoundDecl(nullptr), NamedConcept(nullptr), ArgsAsWritten(nullptr) {}
137 
139  return NestedNameSpec;
140  }
141 
142  const DeclarationNameInfo &getConceptNameInfo() const { return ConceptName; }
143 
145  return getConceptNameInfo().getLoc();
146  }
147 
148  SourceLocation getTemplateKWLoc() const { return TemplateKWLoc; }
149 
151  return FoundDecl;
152  }
153 
155  return NamedConcept;
156  }
157 
159  return ArgsAsWritten;
160  }
161 
162  /// \brief Whether or not template arguments were explicitly specified in the
163  /// concept reference (they might not be in type constraints, for example)
164  bool hasExplicitTemplateArgs() const {
165  return ArgsAsWritten != nullptr;
166  }
167 };
168 
170  /// \brief The immediately-declared constraint expression introduced by this
171  /// type-constraint.
172  Expr *ImmediatelyDeclaredConstraint = nullptr;
173 
174 public:
176  DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl,
177  ConceptDecl *NamedConcept,
178  const ASTTemplateArgumentListInfo *ArgsAsWritten,
179  Expr *ImmediatelyDeclaredConstraint) :
180  ConceptReference(NNS, /*TemplateKWLoc=*/SourceLocation(), ConceptNameInfo,
181  FoundDecl, NamedConcept, ArgsAsWritten),
182  ImmediatelyDeclaredConstraint(ImmediatelyDeclaredConstraint) {}
183 
184  /// \brief Get the immediately-declared constraint expression introduced by
185  /// this type-constraint, that is - the constraint expression that is added to
186  /// the associated constraints of the enclosing declaration in practice.
188  return ImmediatelyDeclaredConstraint;
189  }
190 
191  void print(llvm::raw_ostream &OS, PrintingPolicy Policy) const;
192 };
193 
194 } // clang
195 
196 #endif // LLVM_CLANG_AST_ASTCONCEPT_H
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint, that is - the constraint expression that is added to the associated constraints of the enclosing declaration in practice.
Definition: ASTConcept.h:187
std::pair< const Expr *, llvm::PointerUnion< Expr *, std::pair< SourceLocation, StringRef > * > > UnsatisfiedConstraintRecord
Pairs of unsatisfied atomic constraint expressions along with the substituted constraint expr...
Definition: ASTConcept.h:71
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:605
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:49
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
Definition: InterpFrame.cpp:62
NamedDecl * getFoundDecl() const
Definition: ASTConcept.h:150
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:174
A C++ nested-name-specifier augmented with source location information.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:40
bool hasExplicitTemplateArgs() const
Whether or not template arguments were explicitly specified in the concept reference (they might not ...
Definition: ASTConcept.h:164
llvm::PointerUnion< Expr *, SubstitutionDiagnostic * > Detail
Definition: ASTConcept.h:45
ConceptReference(NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.h:127
ConceptDecl * getNamedConcept() const
Definition: ASTConcept.h:154
std::pair< SourceLocation, StringRef > SubstitutionDiagnostic
Definition: ASTConcept.h:44
const UnsatisfiedConstraintRecord * begin() const
Definition: ASTConcept.h:83
const UnsatisfiedConstraintRecord * end() const
Definition: ASTConcept.h:87
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:29
This represents one expression.
Definition: Expr.h:110
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C)
Definition: ASTConcept.h:55
SourceLocation getConceptNameLoc() const
Definition: ASTConcept.h:144
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:142
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:158
NestedNameSpecifierLoc NestedNameSpec
Definition: ASTConcept.h:103
NamedDecl * FoundDecl
The declaration found by name lookup when the expression was created.
Definition: ASTConcept.h:116
SourceLocation TemplateKWLoc
The location of the template keyword, if specified when naming the concept.
Definition: ASTConcept.h:107
Encodes a location in the source.
Common data class for constructs that reference concepts with template arguments. ...
Definition: ASTConcept.h:100
TypeConstraint(NestedNameSpecifierLoc NNS, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten, Expr *ImmediatelyDeclaredConstraint)
Definition: ASTConcept.h:175
DeclarationNameInfo ConceptName
The concept name used.
Definition: ASTConcept.h:110
Dataflow Directional Tag Classes.
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:138
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
llvm::SmallVector< std::pair< const Expr *, Detail >, 4 > Details
Pairs of unsatisfied atomic constraint expressions along with the substituted constraint expr...
Definition: ASTConcept.h:53
friend TrailingObjects
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:77
ConceptDecl * NamedConcept
The concept named.
Definition: ASTConcept.h:119
Defines the clang::SourceLocation class and associated facilities.
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:148
const ASTTemplateArgumentListInfo * ArgsAsWritten
The template argument list source info used to specialize the concept.
Definition: ASTConcept.h:123
This represents a decl that may have a name.
Definition: Decl.h:223
ConstraintSatisfaction(const NamedDecl *ConstraintOwner, ArrayRef< TemplateArgument > TemplateArgs)
Definition: ASTConcept.h:39
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.