Skip to content

Commit bae2c54

Browse files
committed
[clang][NFC] Move documentation of Sema functions into Sema.h
This patch moves documentation of `Sema` functions from `.cpp` files to `Sema.h` when there was no documentation in the latter, or it can be trivially subsumed. More complicated cases when there's less trivial divergence between documentation attached to declaration and the one attached to implementation are left for a later PR that would require review. It appears that doxygen can find the documentation for a function defined out-of-line even if it's attached to an implementation, and not declaration. But other tools, e.g. clangd, are not as powerful. So this patch significantly improves autocompletion experience for (at least) clangd-based IDEs.
1 parent f9efc29 commit bae2c54

25 files changed

+3150
-2992
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 3148 additions & 13 deletions
Large diffs are not rendered by default.

clang/lib/Sema/Sema.cpp

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,6 @@ void Sema::runWithSufficientStackSpace(SourceLocation Loc,
566566
clang::runWithSufficientStackSpace([&] { warnStackExhausted(Loc); }, Fn);
567567
}
568568

569-
/// makeUnavailableInSystemHeader - There is an error in the current
570-
/// context. If we're still in a system header, and we can plausibly
571-
/// make the relevant declaration unavailable instead of erroring, do
572-
/// so and return true.
573569
bool Sema::makeUnavailableInSystemHeader(SourceLocation loc,
574570
UnavailableAttr::ImplicitReason reason) {
575571
// If we're not in a function, it's an error.
@@ -595,11 +591,6 @@ ASTMutationListener *Sema::getASTMutationListener() const {
595591
return getASTConsumer().GetASTMutationListener();
596592
}
597593

598-
///Registers an external source. If an external source already exists,
599-
/// creates a multiplex external source and appends to it.
600-
///
601-
///\param[in] E - A non-null external sema source.
602-
///
603594
void Sema::addExternalSource(ExternalSemaSource *E) {
604595
assert(E && "Cannot use with NULL ptr");
605596

@@ -614,7 +605,6 @@ void Sema::addExternalSource(ExternalSemaSource *E) {
614605
ExternalSource = new MultiplexExternalSemaSource(ExternalSource.get(), E);
615606
}
616607

617-
/// Print out statistics about the semantic analysis.
618608
void Sema::PrintStats() const {
619609
llvm::errs() << "\n*** Semantic Analysis Stats:\n";
620610
llvm::errs() << NumSFINAEErrors << " SFINAE diagnostics trapped.\n";
@@ -782,8 +772,6 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
782772
CurFPFeatureOverrides());
783773
}
784774

785-
/// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding
786-
/// to the conversion from scalar type ScalarTy to the Boolean type.
787775
CastKind Sema::ScalarTypeToBooleanCastKind(QualType ScalarTy) {
788776
switch (ScalarTy->getScalarTypeKind()) {
789777
case Type::STK_Bool: return CK_NoOp;
@@ -1100,9 +1088,6 @@ void Sema::emitAndClearUnusedLocalTypedefWarnings() {
11001088
UnusedLocalTypedefNameCandidates.clear();
11011089
}
11021090

1103-
/// This is called before the very first declaration in the translation unit
1104-
/// is parsed. Note that the ASTContext may have already injected some
1105-
/// declarations.
11061091
void Sema::ActOnStartOfTranslationUnit() {
11071092
if (getLangOpts().CPlusPlusModules &&
11081093
getLangOpts().getCompilingModule() == LangOptions::CMK_HeaderUnit)
@@ -1174,9 +1159,6 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
11741159
DelayedTypos.clear();
11751160
}
11761161

1177-
/// ActOnEndOfTranslationUnit - This is called at the very end of the
1178-
/// translation unit when EOF is reached and all but the top-level scope is
1179-
/// popped.
11801162
void Sema::ActOnEndOfTranslationUnit() {
11811163
assert(DelayedDiagnostics.getCurrentPool() == nullptr
11821164
&& "reached end of translation unit with a pool attached?");
@@ -2141,10 +2123,6 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
21412123
CheckType(FNPTy->getReturnType(), /*IsRetTy=*/true);
21422124
}
21432125

2144-
/// Looks through the macro-expansion chain for the given
2145-
/// location, looking for a macro expansion with the given name.
2146-
/// If one is found, returns true and sets the location to that
2147-
/// expansion loc.
21482126
bool Sema::findMacroSpelling(SourceLocation &locref, StringRef name) {
21492127
SourceLocation loc = locref;
21502128
if (!loc.isMacroID()) return false;
@@ -2162,17 +2140,6 @@ bool Sema::findMacroSpelling(SourceLocation &locref, StringRef name) {
21622140
return false;
21632141
}
21642142

2165-
/// Determines the active Scope associated with the given declaration
2166-
/// context.
2167-
///
2168-
/// This routine maps a declaration context to the active Scope object that
2169-
/// represents that declaration context in the parser. It is typically used
2170-
/// from "scope-less" code (e.g., template instantiation, lazy creation of
2171-
/// declarations) that injects a name for name-lookup purposes and, therefore,
2172-
/// must update the Scope.
2173-
///
2174-
/// \returns The scope corresponding to the given declaraion context, or NULL
2175-
/// if no such scope is open.
21762143
Scope *Sema::getScopeForContext(DeclContext *Ctx) {
21772144

21782145
if (!Ctx)
@@ -2303,13 +2270,6 @@ static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S) {
23032270
}
23042271
}
23052272

2306-
/// Pop a function (or block or lambda or captured region) scope from the stack.
2307-
///
2308-
/// \param WP The warning policy to use for CFG-based warnings, or null if such
2309-
/// warnings should not be produced.
2310-
/// \param D The declaration corresponding to this function scope, if producing
2311-
/// CFG-based warnings.
2312-
/// \param BlockType The type of the block expression, if D is a BlockDecl.
23132273
Sema::PoppedFunctionScopePtr
23142274
Sema::PopFunctionScopeInfo(const AnalysisBasedWarnings::Policy *WP,
23152275
const Decl *D, QualType BlockType) {
@@ -2356,8 +2316,6 @@ void Sema::PopCompoundScope() {
23562316
CurFunction->CompoundScopes.pop_back();
23572317
}
23582318

2359-
/// Determine whether any errors occurred within this function/method/
2360-
/// block.
23612319
bool Sema::hasAnyUnrecoverableErrorsInThisFunction() const {
23622320
return getCurFunction()->hasUnrecoverableErrorOccurred();
23632321
}
@@ -2508,17 +2466,6 @@ void ExternalSemaSource::ReadUndefinedButUsed(
25082466
void ExternalSemaSource::ReadMismatchingDeleteExpressions(llvm::MapVector<
25092467
FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &) {}
25102468

2511-
/// Figure out if an expression could be turned into a call.
2512-
///
2513-
/// Use this when trying to recover from an error where the programmer may have
2514-
/// written just the name of a function instead of actually calling it.
2515-
///
2516-
/// \param E - The expression to examine.
2517-
/// \param ZeroArgCallReturnTy - If the expression can be turned into a call
2518-
/// with no arguments, this parameter is set to the type returned by such a
2519-
/// call; otherwise, it is set to an empty QualType.
2520-
/// \param OverloadSet - If the expression is an overloaded function
2521-
/// name, this parameter is populated with the decls of the various overloads.
25222469
bool Sema::tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy,
25232470
UnresolvedSetImpl &OverloadSet) {
25242471
ZeroArgCallReturnTy = QualType();

clang/lib/Sema/SemaAccess.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ enum AccessResult {
3434
AR_dependent
3535
};
3636

37-
/// SetMemberAccessSpecifier - Set the access specifier of a member.
38-
/// Returns true on error (when the previous member decl access specifier
39-
/// is different from the new member decl access specifier).
4037
bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
4138
NamedDecl *PrevMemberDecl,
4239
AccessSpecifier LexicalAS) {
@@ -1590,8 +1587,6 @@ Sema::AccessResult Sema::CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
15901587
return CheckAccess(*this, E->getNameLoc(), Entity);
15911588
}
15921589

1593-
/// Perform access-control checking on a previously-unresolved member
1594-
/// access which has now been resolved to a member.
15951590
Sema::AccessResult Sema::CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
15961591
DeclAccessPair Found) {
15971592
if (!getLangOpts().AccessControl ||
@@ -1609,8 +1604,6 @@ Sema::AccessResult Sema::CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
16091604
return CheckAccess(*this, E->getMemberLoc(), Entity);
16101605
}
16111606

1612-
/// Is the given member accessible for the purposes of deciding whether to
1613-
/// define a special member function as deleted?
16141607
bool Sema::isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass,
16151608
DeclAccessPair Found,
16161609
QualType ObjectType,
@@ -1658,7 +1651,6 @@ Sema::AccessResult Sema::CheckDestructorAccess(SourceLocation Loc,
16581651
return CheckAccess(*this, Loc, Entity);
16591652
}
16601653

1661-
/// Checks access to a constructor.
16621654
Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
16631655
CXXConstructorDecl *Constructor,
16641656
DeclAccessPair Found,
@@ -1705,7 +1697,6 @@ Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
17051697
return CheckConstructorAccess(UseLoc, Constructor, Found, Entity, PD);
17061698
}
17071699

1708-
/// Checks access to a constructor.
17091700
Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
17101701
CXXConstructorDecl *Constructor,
17111702
DeclAccessPair Found,
@@ -1747,7 +1738,6 @@ Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
17471738
return CheckAccess(*this, UseLoc, AccessEntity);
17481739
}
17491740

1750-
/// Checks access to an overloaded operator new or delete.
17511741
Sema::AccessResult Sema::CheckAllocationAccess(SourceLocation OpLoc,
17521742
SourceRange PlacementRange,
17531743
CXXRecordDecl *NamingClass,
@@ -1767,7 +1757,6 @@ Sema::AccessResult Sema::CheckAllocationAccess(SourceLocation OpLoc,
17671757
return CheckAccess(*this, OpLoc, Entity);
17681758
}
17691759

1770-
/// Checks access to a member.
17711760
Sema::AccessResult Sema::CheckMemberAccess(SourceLocation UseLoc,
17721761
CXXRecordDecl *NamingClass,
17731762
DeclAccessPair Found) {
@@ -1782,7 +1771,6 @@ Sema::AccessResult Sema::CheckMemberAccess(SourceLocation UseLoc,
17821771
return CheckAccess(*this, UseLoc, Entity);
17831772
}
17841773

1785-
/// Checks implicit access to a member in a structured binding.
17861774
Sema::AccessResult
17871775
Sema::CheckStructuredBindingMemberAccess(SourceLocation UseLoc,
17881776
CXXRecordDecl *DecomposedClass,
@@ -1815,8 +1803,6 @@ Sema::AccessResult Sema::CheckMemberOperatorAccess(SourceLocation OpLoc,
18151803
return CheckAccess(*this, OpLoc, Entity);
18161804
}
18171805

1818-
/// Checks access to an overloaded member operator, including
1819-
/// conversion operators.
18201806
Sema::AccessResult Sema::CheckMemberOperatorAccess(SourceLocation OpLoc,
18211807
Expr *ObjectExpr,
18221808
Expr *ArgExpr,
@@ -1839,7 +1825,6 @@ Sema::AccessResult Sema::CheckMemberOperatorAccess(SourceLocation OpLoc,
18391825
return CheckMemberOperatorAccess(OpLoc, ObjectExpr, R, FoundDecl);
18401826
}
18411827

1842-
/// Checks access to the target of a friend declaration.
18431828
Sema::AccessResult Sema::CheckFriendAccess(NamedDecl *target) {
18441829
assert(isa<CXXMethodDecl>(target->getAsFunction()));
18451830

@@ -1889,12 +1874,6 @@ Sema::AccessResult Sema::CheckAddressOfMemberAccess(Expr *OvlExpr,
18891874
return CheckAccess(*this, Ovl->getNameLoc(), Entity);
18901875
}
18911876

1892-
/// Checks access for a hierarchy conversion.
1893-
///
1894-
/// \param ForceCheck true if this check should be performed even if access
1895-
/// control is disabled; some things rely on this for semantics
1896-
/// \param ForceUnprivileged true if this check should proceed as if the
1897-
/// context had no special privileges
18981877
Sema::AccessResult Sema::CheckBaseClassAccess(SourceLocation AccessLoc,
18991878
QualType Base,
19001879
QualType Derived,
@@ -1929,7 +1908,6 @@ Sema::AccessResult Sema::CheckBaseClassAccess(SourceLocation AccessLoc,
19291908
return CheckAccess(*this, AccessLoc, Entity);
19301909
}
19311910

1932-
/// Checks access to all the declarations in the given result set.
19331911
void Sema::CheckLookupAccess(const LookupResult &R) {
19341912
assert(getLangOpts().AccessControl
19351913
&& "performing access check without access control");
@@ -1946,23 +1924,6 @@ void Sema::CheckLookupAccess(const LookupResult &R) {
19461924
}
19471925
}
19481926

1949-
/// Checks access to Target from the given class. The check will take access
1950-
/// specifiers into account, but no member access expressions and such.
1951-
///
1952-
/// \param Target the declaration to check if it can be accessed
1953-
/// \param NamingClass the class in which the lookup was started.
1954-
/// \param BaseType type of the left side of member access expression.
1955-
/// \p BaseType and \p NamingClass are used for C++ access control.
1956-
/// Depending on the lookup case, they should be set to the following:
1957-
/// - lhs.target (member access without a qualifier):
1958-
/// \p BaseType and \p NamingClass are both the type of 'lhs'.
1959-
/// - lhs.X::target (member access with a qualifier):
1960-
/// BaseType is the type of 'lhs', NamingClass is 'X'
1961-
/// - X::target (qualified lookup without member access):
1962-
/// BaseType is null, NamingClass is 'X'.
1963-
/// - target (unqualified lookup).
1964-
/// BaseType is null, NamingClass is the parent class of 'target'.
1965-
/// \return true if the Target is accessible from the Class, false otherwise.
19661927
bool Sema::IsSimplyAccessible(NamedDecl *Target, CXXRecordDecl *NamingClass,
19671928
QualType BaseType) {
19681929
// Perform the C++ accessibility checks first.

clang/lib/Sema/SemaAttr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,6 @@ void Sema::AddPushedVisibilityAttribute(Decl *D) {
12311231
D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
12321232
}
12331233

1234-
/// FreeVisContext - Deallocate and null out VisContext.
12351234
void Sema::FreeVisContext() {
12361235
delete static_cast<VisStack*>(VisContext);
12371236
VisContext = nullptr;

0 commit comments

Comments
 (0)