mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
This PR separates the core cpp packs into `codeql/cpp-queries` and `codeql/cpp-all`. There are very few lines of code changed. Almost all changes are moving files around.
55 lines
1.4 KiB
Plaintext
55 lines
1.4 KiB
Plaintext
/**
|
|
* Provides classes representing C and C++ comments.
|
|
*/
|
|
|
|
import semmle.code.cpp.Location
|
|
import semmle.code.cpp.Element
|
|
|
|
/**
|
|
* A C/C++ comment. For example the comment in the following code:
|
|
* ```
|
|
* // C++ style single-line comment
|
|
* ```
|
|
* or a C style comment (which starts with `/*`).
|
|
*/
|
|
class Comment extends Locatable, @comment {
|
|
override string toString() { result = this.getContents() }
|
|
|
|
override Location getLocation() { comments(underlyingElement(this), _, result) }
|
|
|
|
/**
|
|
* Gets the text of this comment, including the opening `//` or `/*`, and the closing `*``/` if
|
|
* present.
|
|
*/
|
|
string getContents() { comments(underlyingElement(this), result, _) }
|
|
|
|
/**
|
|
* Gets the AST element this comment is associated with. For example, the comment in the
|
|
* following code is associated with the declaration of `j`.
|
|
* ```
|
|
* int i;
|
|
* int j; // Comment on j
|
|
* ```
|
|
*/
|
|
Element getCommentedElement() {
|
|
commentbinding(underlyingElement(this), unresolveElement(result))
|
|
}
|
|
}
|
|
|
|
/**
|
|
* A C style comment (one which starts with `/*`).
|
|
*/
|
|
class CStyleComment extends Comment {
|
|
CStyleComment() { this.getContents().matches("/*%") }
|
|
}
|
|
|
|
/**
|
|
* A CPP style comment. For example the comment in the following code:
|
|
* ```
|
|
* // C++ style single-line comment
|
|
* ```
|
|
*/
|
|
class CppStyleComment extends Comment {
|
|
CppStyleComment() { this.getContents().matches("//%") }
|
|
}
|