Skip to content

Commit 86ba03b

Browse files
authored
Merge pull request github#3256 from Semmle/rdmarsh/cpp/add-qldoc-1
C++: Add QLdoc to some AST methods (Class.qll-Diagnostics.qll)
2 parents 5a51d2c + 7f5b3de commit 86ba03b

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

cpp/ql/src/semmle/code/cpp/Class.qll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,15 @@ class Class extends UserType {
458458
exists(ClassDerivation d | d.getDerivedClass() = this and d = result)
459459
}
460460

461+
/**
462+
* Gets class derivation number `index` of this class/struct, for example the
463+
* `public B` is derivation 1 in the following code:
464+
* ```
465+
* class D : public A, public B, public C {
466+
* ...
467+
* };
468+
* ```
469+
*/
461470
ClassDerivation getDerivation(int index) {
462471
exists(ClassDerivation d | d.getDerivedClass() = this and d.getIndex() = index and d = result)
463472
}
@@ -900,6 +909,22 @@ class AbstractClass extends Class {
900909
class TemplateClass extends Class {
901910
TemplateClass() { usertypes(underlyingElement(this), _, 6) }
902911

912+
/**
913+
* Gets a class instantiated from this template.
914+
*
915+
* For example for `MyTemplateClass<T>` in the following code, the results are
916+
* `MyTemplateClass<int>` and `MyTemplateClass<long>`:
917+
* ```
918+
* template<class T>
919+
* class MyTemplateClass {
920+
* ...
921+
* };
922+
*
923+
* MyTemplateClass<int> instance;
924+
*
925+
* MyTemplateClass<long> instance;
926+
* ```
927+
*/
903928
Class getAnInstantiation() {
904929
result.isConstructedFrom(this) and
905930
exists(result.getATemplateArgument())

cpp/ql/src/semmle/code/cpp/Comments.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@ class Comment extends Locatable, @comment {
1313

1414
override Location getLocation() { comments(underlyingElement(this), _, result) }
1515

16+
/**
17+
* Gets the text of this comment, including the opening `//` or `/*`, and the closing `*``/` if
18+
* present.
19+
*/
1620
string getContents() { comments(underlyingElement(this), result, _) }
1721

22+
/**
23+
* Gets the AST element this comment is associated with. For example, the comment in the
24+
* following code is associated with the declaration of `j`.
25+
* ```
26+
* int i;
27+
* int j; // Comment on j
28+
* ```
29+
*/
1830
Element getCommentedElement() {
1931
commentbinding(underlyingElement(this), unresolveElement(result))
2032
}

cpp/ql/src/semmle/code/cpp/Compilation.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Compilation extends @compilation {
4040
/** Gets a file compiled during this invocation. */
4141
File getAFileCompiled() { result = getFileCompiled(_) }
4242

43+
/** Gets the `i`th file compiled during this invocation */
4344
File getFileCompiled(int i) { compilation_compiling_files(this, i, unresolveElement(result)) }
4445

4546
/**

cpp/ql/src/semmle/code/cpp/Diagnostics.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Diagnostic extends Locatable, @diagnostic {
1111
/** Gets the error code for this compiler message. */
1212
string getTag() { diagnostics(underlyingElement(this), _, result, _, _, _) }
1313

14+
/** Holds if `s` is the error code for this compiler message. */
1415
predicate hasTag(string s) { this.getTag() = s }
1516

1617
/**

0 commit comments

Comments
 (0)