From 994f3b91fdff0cb04d1a77841ceea548e3c69b0d Mon Sep 17 00:00:00 2001 From: Vassily Litvinov Date: Tue, 19 Sep 2023 16:22:59 -0700 Subject: [PATCH 1/3] Disable where-clauses in chpldoc with a pragma Signed-off-by: Vassily Litvinov --- frontend/include/chpl/uast/PragmaList.h | 1 + modules/internal/ChapelRange.chpl | 1 + tools/chpldoc/chpldoc.cpp | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/frontend/include/chpl/uast/PragmaList.h b/frontend/include/chpl/uast/PragmaList.h index aff4378c5e82..46ea7053c100 100644 --- a/frontend/include/chpl/uast/PragmaList.h +++ b/frontend/include/chpl/uast/PragmaList.h @@ -415,6 +415,7 @@ PRAGMA(NO_COPY_RETURN, ypr, "no copy return", ncm) PRAGMA(NO_COPY_RETURNS_OWNED, ypr, "no copy returns owned", ncm) PRAGMA(NO_DEFAULT_FUNCTIONS, ypr, "no default functions", ncm) PRAGMA(NO_DOC, ypr, "no doc", "do not generate chpldoc documentation for this symbol") +PRAGMA(NO_WHERE_DOC, ypr, "no where doc", "do not include the where clause in chpldoc documentation for this symbol") PRAGMA(NO_IMPLICIT_COPY, ypr, "no implicit copy", "function does not require autoCopy/autoDestroy") // This flag disables initialization entirely. In contrast, `= noinit` diff --git a/modules/internal/ChapelRange.chpl b/modules/internal/ChapelRange.chpl index 96393ceb8439..cc05e1626bd6 100644 --- a/modules/internal/ChapelRange.chpl +++ b/modules/internal/ChapelRange.chpl @@ -1764,6 +1764,7 @@ proc range.safeCast(type t: range(?)) { the original bounds and/or stride do not fit in the new idxType or when the original stride is not legal for the new `strides` parameter. */ +pragma "no where doc" proc range.tryCast(type t: range(?)) where chpl_tryCastIsSafe(this, t) { const r = this; checkBounds(t, r); diff --git a/tools/chpldoc/chpldoc.cpp b/tools/chpldoc/chpldoc.cpp index 4de08496e609..707686b196f8 100644 --- a/tools/chpldoc/chpldoc.cpp +++ b/tools/chpldoc/chpldoc.cpp @@ -339,6 +339,13 @@ static bool isNoDoc(const Decl* e) { return false; } +static bool isNoWhereDoc(const Function* f) { + if (auto attrs = f->attributeGroup()) + if (attrs->hasPragma(pragmatags::PRAGMA_NO_WHERE_DOC)) + return true; + return false; +} + static std::vector splitLines(const std::string& s) { std::stringstream ss(s); std::string line; @@ -1145,8 +1152,10 @@ struct RstSignatureVisitor { // Where Clause if (const AstNode* wc = f->whereClause()) { + if (isNoWhereDoc(f)) { os_ << " where "; wc->traverse(*this); + } } return false; From 0d7828476b480a7ac571227efc583fb5db1940ac Mon Sep 17 00:00:00 2001 From: Vassily Litvinov Date: Tue, 19 Sep 2023 16:51:33 -0700 Subject: [PATCH 2/3] Fix a bug Signed-off-by: Vassily Litvinov --- tools/chpldoc/chpldoc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/chpldoc/chpldoc.cpp b/tools/chpldoc/chpldoc.cpp index 707686b196f8..7e2cc9b8eb14 100644 --- a/tools/chpldoc/chpldoc.cpp +++ b/tools/chpldoc/chpldoc.cpp @@ -1152,7 +1152,7 @@ struct RstSignatureVisitor { // Where Clause if (const AstNode* wc = f->whereClause()) { - if (isNoWhereDoc(f)) { + if (!isNoWhereDoc(f)) { os_ << " where "; wc->traverse(*this); } From 6dffc55aba35e15017ef26035c2deaa2a9d66ea0 Mon Sep 17 00:00:00 2001 From: Vassily Litvinov Date: Tue, 19 Sep 2023 18:29:30 -0700 Subject: [PATCH 3/3] Add test Signed-off-by: Vassily Litvinov --- test/chpldoc/functions/WhereClause.doc.chpl | 5 +++++ test/chpldoc/functions/WhereClause.doc.good | 2 ++ 2 files changed, 7 insertions(+) diff --git a/test/chpldoc/functions/WhereClause.doc.chpl b/test/chpldoc/functions/WhereClause.doc.chpl index f91c064fb607..d7cd93794c6e 100644 --- a/test/chpldoc/functions/WhereClause.doc.chpl +++ b/test/chpldoc/functions/WhereClause.doc.chpl @@ -30,6 +30,11 @@ module M { writeln("processRange 2"); } + pragma "no where doc" + proc processRangeNW(r: range) where r.low > 1 { + writeln("processRange no where"); + } + // From borrowed-in-where.chpl proc foo(type t) where isSubtype(t, int) { writeln("In foo where"); diff --git a/test/chpldoc/functions/WhereClause.doc.good b/test/chpldoc/functions/WhereClause.doc.good index 075b5174c4a1..51e7f39af927 100644 --- a/test/chpldoc/functions/WhereClause.doc.good +++ b/test/chpldoc/functions/WhereClause.doc.good @@ -33,6 +33,8 @@ or .. function:: proc processRange(r: range) where r.low > 1 +.. function:: proc processRangeNW(r: range) + .. function:: proc foo(type t) where isSubtype(t, int) .. function:: operator +(a: int, b: int) where a > 0