Skip to content

Commit f812c54

Browse files
committed
Documentation improvements
1 parent 902410b commit f812c54

File tree

4 files changed

+63
-22
lines changed

4 files changed

+63
-22
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
12471247

12481248
/// Returns true for local variable declarations other than parameters.
12491249
/// Note that this includes static variables inside of functions. It also
1250-
/// includes variables inside blocks.
1250+
/// includes variables inside blocks and expansion statements.
12511251
///
12521252
/// void foo() { int x; static int y; extern int z; }
12531253
bool isLocalVarDecl() const {

clang/include/clang/AST/DeclTemplate.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,7 +3375,18 @@ class TemplateParamObjectDecl : public ValueDecl,
33753375
/// 'CXXExpansionStmtInstantiation' is. The latter is also what's used for
33763376
/// codegen and constant evaluation.
33773377
///
3378-
/// For example, if the user writes the following expansion statement:
3378+
/// There are three kinds of expansion statements; they correspond to three
3379+
/// derived classes of 'CXXExpansionStmtPattern'. There is also a fourth derived
3380+
/// class that is used if we don't know what kind of expansion statement we're
3381+
/// dealing with (because the thing we're expanding is dependent). See the
3382+
/// comment on those classes for more information about how they work:
3383+
///
3384+
/// 1. CXXEnumeratingExpansionStmtPattern
3385+
/// 2. CXXIteratingExpansionStmtPattern
3386+
/// 3. CXXDestructuringExpansionStmtPattern
3387+
/// 4. CXXDependentExpansionStmtPattern
3388+
///
3389+
/// As an example, if the user writes the following expansion statement:
33793390
/// \verbatim
33803391
/// std::tuple<int, int, int> a{1, 2, 3};
33813392
/// template for (auto x : a) {
@@ -3389,28 +3400,33 @@ class TemplateParamObjectDecl : public ValueDecl,
33893400
/// 'a'.
33903401
///
33913402
/// After expansion, we end up with a 'CXXExpansionStmtInstantiation' that
3392-
/// contains a DecompositionDecl and 3 CompoundStmts, one for each expansion:
3403+
/// is *equivalent* to the AST shown below. Note that only the inner '{}' (i.e.
3404+
/// those marked as 'Actual "CompoundStmt"' below) are actually present as
3405+
/// 'CompoundStmt's in the AST; the outer braces that wrap everything do *not*
3406+
/// correspond to an actual 'CompoundStmt' and are implicit in the sense that we
3407+
/// simply push a scope when evaluating or emitting IR for a
3408+
/// 'CXXExpansionStmtInstantiation'.
33933409
///
33943410
/// \verbatim
3395-
/// {
3411+
/// { // Not actually present in the AST.
33963412
/// auto [__u0, __u1, __u2] = a;
3397-
/// {
3413+
/// { // Actual 'CompoundStmt'.
33983414
/// auto x = __u0;
33993415
/// // ...
34003416
/// }
3401-
/// {
3417+
/// { // Actual 'CompoundStmt'.
34023418
/// auto x = __u1;
34033419
/// // ...
34043420
/// }
3405-
/// {
3421+
/// { // Actual 'CompoundStmt'.
34063422
/// auto x = __u2;
34073423
/// // ...
34083424
/// }
34093425
/// }
34103426
/// \endverbatim
34113427
///
3412-
/// The outer braces shown above are implicit; we don't actually create another
3413-
/// CompoundStmt wrapping everything.
3428+
/// See the documentation around 'CXXExpansionStmtInstantiation' for more notes
3429+
/// as to why this node exist and how it is used.
34143430
///
34153431
/// \see CXXExpansionStmtPattern
34163432
/// \see CXXExpansionStmtInstantiation

clang/include/clang/AST/ExprCXX.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,6 +5501,19 @@ class BuiltinBitCastExpr final
55015501

55025502
/// Represents an expansion-init-list of an enumerating expansion statement.
55035503
///
5504+
/// For example, in
5505+
/// \verbatim
5506+
/// template for (auto x : { 1, 2, 3 }) {
5507+
/// // ...
5508+
/// }
5509+
/// \endverbatim
5510+
///
5511+
/// the '{ 1, 2, 3 }' part is parsed and stored as a 'CXXExpansionInitListExpr';
5512+
/// syntactically, this *looks* very similar to an initializer list, but it
5513+
/// isn't actually an expression: '{ 1, 2, 3 }' as a whole is never evaluated
5514+
/// or emitted, only the individual expressions '1', '2', and '3' are. We still
5515+
/// represent it as an expression in the AST for simplicity.
5516+
///
55045517
/// \see CXXEnumeratingExpansionStmtPattern
55055518
class CXXExpansionInitListExpr final
55065519
: public Expr,

clang/include/clang/AST/StmtCXX.h

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,7 @@ class CoreturnStmt : public Stmt {
533533
/// subexpressions required by its derived classes. This is to simplify the
534534
/// implementation of 'children()' and friends.
535535
///
536-
/// \see CXXExpansionStmtDecl
537-
/// \see CXXEnumeratingExpansionStmtPattern
538-
/// \see CXXIteratingExpansionStmtPattern
539-
/// \see CXXDestructuringExpansionStmtPattern
540-
/// \see CXXDependentExpansionStmtPattern
536+
/// \see CXXExpansionStmtDecl for more documentation on expansion statements.
541537
class CXXExpansionStmtPattern : public Stmt {
542538
friend class ASTStmtReader;
543539

@@ -878,25 +874,28 @@ class CXXDestructuringExpansionStmtPattern : public CXXExpansionStmtPattern {
878874
/// Represents the code generated for an expanded expansion statement.
879875
///
880876
/// This holds 'shared statements' and 'instantiations'; these encode the
881-
/// general underlying pattern that all expansion statements desugar to:
877+
/// general underlying pattern that all expansion statements desugar to. Note
878+
/// that only the inner '{}' (i.e. those marked as 'Actual "CompoundStmt"'
879+
/// below) are actually present as 'CompoundStmt's in the AST; the outer braces
880+
/// that wrap everything do *not* correspond to an actual 'CompoundStmt' and are
881+
/// implicit in the sense that we simply push a scope when evaluating or
882+
/// emitting IR for a 'CXXExpansionStmtInstantiation'.
883+
///
884+
/// The 'instantiations' are precisely these inner compound statements.
882885
///
883886
/// \verbatim
884-
/// {
887+
/// { // Not actually present in the AST.
885888
/// <shared statements>
886-
/// {
889+
/// { // Actual 'CompoundStmt'.
887890
/// <1st instantiation>
888891
/// }
889892
/// ...
890-
/// {
893+
/// { // Actual 'CompoundStmt'.
891894
/// <n-th instantiation>
892895
/// }
893896
/// }
894897
/// \endverbatim
895898
///
896-
/// Here, the only thing that is stored in the AST are the 'shared statements'
897-
/// and the 'CompoundStmt's that wrap the 'instantiations'. The outer braces
898-
/// shown above are implicit.
899-
///
900899
/// For example, the CXXExpansionStmtInstantiation that corresponds to the
901900
/// following expansion statement
902901
///
@@ -926,6 +925,19 @@ class CXXDestructuringExpansionStmtPattern : public CXXExpansionStmtPattern {
926925
/// }
927926
/// }
928927
/// \endverbatim
928+
///
929+
/// There are two reasons why this needs to exist and why we don't just store a
930+
/// list of instantiations in some other node:
931+
///
932+
/// 1. We need custom codegen to handle break/continue in expansion statements
933+
/// properly, so it can't just be a compound statement.
934+
///
935+
/// 2. The expansions are created after both the pattern and the
936+
/// 'CXXExpansionStmtDecl', so we can't just store them as trailing data in
937+
/// either of those nodes (because we don't know how many expansions there
938+
/// will be when those notes are allocated).
939+
///
940+
/// \see CXXExpansionStmtDecl
929941
class CXXExpansionStmtInstantiation final
930942
: public Stmt,
931943
llvm::TrailingObjects<CXXExpansionStmtInstantiation, Stmt *> {

0 commit comments

Comments
 (0)