Files
codeql/cpp/ql/lib/semmle/code/cpp/Comments.qll
Andrew Eisenberg 2c5dd2dfa3 Packaging: Refactor the cpp libraries
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.
2021-08-17 11:22:36 -07:00

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("//%") }
}