@@ -65,51 +65,63 @@ class DocumentableDeclaration extends Declaration {
6565 string declarationType ;
6666
6767 DocumentableDeclaration ( ) {
68- this instanceof UserType and
69- declarationType = "user-defined type" and
70- // Exclude template parameter types.
71- not this .( UserType ) .involvesTemplateParameter ( )
72- or
73- this instanceof Function and
74- declarationType = "function" and
75- // Exclude compiler generated functions, which cannot reasonably be documented.
76- not this .( Function ) .isCompilerGenerated ( ) and
77- // Exclude instantiated template functions, which cannot reasonably be documented.
78- not this .( Function ) .isFromTemplateInstantiation ( _) and
79- // Exclude anonymous lambda functions.
80- not exists ( LambdaExpression lc | lc .getLambdaFunction ( ) = this ) and
81- //Exclude friend functions (because they have 2 entries in the database), and only one shows documented truly
82- not exists ( FriendDecl d |
83- d .getFriend ( ) .( Function ) .getDefinition ( ) = this .getADeclarationEntry ( )
68+ // Within the users codebase, not a system header
69+ exists ( this .getFile ( ) .getRelativePath ( ) ) and
70+ // Not required to be documented, as used within same scope
71+ not isInFunctionScope ( this ) and
72+ (
73+ this instanceof UserType and
74+ declarationType = "user-defined type" and
75+ // Exclude template parameter types.
76+ not this .( UserType ) .involvesTemplateParameter ( )
77+ or
78+ this instanceof Function and
79+ declarationType = "function" and
80+ // Exclude compiler generated functions, which cannot reasonably be documented.
81+ not this .( Function ) .isCompilerGenerated ( ) and
82+ // Exclude instantiated template functions, which cannot reasonably be documented.
83+ not this .( Function ) .isFromTemplateInstantiation ( _) and
84+ // Exclude anonymous lambda functions.
85+ not exists ( LambdaExpression lc | lc .getLambdaFunction ( ) = this ) and
86+ //Exclude friend functions (because they have 2 entries in the database), and only one shows documented truly
87+ not exists ( FriendDecl d |
88+ d .getFriend ( ) .( Function ) .getDefinition ( ) = this .getADeclarationEntry ( )
89+ )
90+ or
91+ this instanceof MemberVariable and
92+ declarationType = "member variable" and
93+ // Exclude memeber variables in instantiated templates, which cannot reasonably be documented.
94+ not this .( MemberVariable ) .isFromTemplateInstantiation ( _) and
95+ // Exclude compiler generated variables, such as those for anonymous lambda functions
96+ not this .( MemberVariable ) .isCompilerGenerated ( )
8497 )
85- or
86- this instanceof MemberVariable and
87- declarationType = "member variable" and
88- // Exclude memeber variables in instantiated templates, which cannot reasonably be documented.
89- not this .( MemberVariable ) .isFromTemplateInstantiation ( _) and
90- // Exclude compiler generated variables, such as those for anonymous lambda functions
91- not this .( MemberVariable ) .isCompilerGenerated ( )
98+ }
99+
100+ private predicate hasDocumentedDefinition ( ) {
101+ // Check if the declaration has a documented definition
102+ exists ( DeclarationEntry de | de = getADeclarationEntry ( ) and isDocumented ( de ) )
103+ }
104+
105+ private predicate hasOnlyDefinitions ( ) {
106+ // Check if the declaration has only definitions, i.e., no non-definition entries
107+ not exists ( DeclarationEntry de | de = getADeclarationEntry ( ) and not de .isDefinition ( ) )
92108 }
93109
94110 /** Gets a `DeclarationEntry` for this declaration that should be documented. */
95111 DeclarationEntry getAnUndocumentedDeclarationEntry ( ) {
96112 // Find a declaration entry that is not documented
97113 result = getADeclarationEntry ( ) and
98114 not isDocumented ( result ) and
99- (
100- // Report any non definition DeclarationEntry that is not documented
101- // as long as there is no corresponding documented definition (which must be for a forward declaration)
102- not result .isDefinition ( ) and
103- not exists ( DeclarationEntry de |
104- de = getADeclarationEntry ( ) and de .isDefinition ( ) and isDocumented ( de )
105- )
106- or
115+ if result .isDefinition ( )
116+ then
107117 // Report the definition DeclarationEntry, only if there are no non-definition `DeclarationEntry`'s
108118 // The rationale here is that documenting both the non-definition and definition declaration entries
109119 // is redundant
110- result .isDefinition ( ) and
111- not exists ( DeclarationEntry de | de = getADeclarationEntry ( ) and not de .isDefinition ( ) )
112- )
120+ hasOnlyDefinitions ( )
121+ else
122+ // Report any non definition DeclarationEntry that is not documented
123+ // as long as there is no corresponding documented definition (which must be for a forward declaration)
124+ not hasDocumentedDefinition ( )
113125 }
114126
115127 /** Gets a string describing the type of declaration. */
@@ -144,7 +156,6 @@ from DocumentableDeclaration d, DeclarationEntry de
144156where
145157 not isExcluded ( de , CommentsPackage:: undocumentedUserDefinedTypeQuery ( ) ) and
146158 not isExcluded ( d , CommentsPackage:: undocumentedUserDefinedTypeQuery ( ) ) and
147- not isInFunctionScope ( d ) and
148159 d .getAnUndocumentedDeclarationEntry ( ) = de
149160select de ,
150161 "Declaration entry for " + d .getDeclarationType ( ) + " " + d .getName ( ) +
0 commit comments