CPP: QLDoc cleanup.

This commit is contained in:
Geoffrey White
2019-01-10 18:23:35 +00:00
parent 7c6dfc90de
commit fc142c71be
5 changed files with 28 additions and 8 deletions

View File

@@ -96,6 +96,7 @@ class BitField extends Field {
*/
int getBitOffset() { fieldoffsets(underlyingElement(this),_,result) }
/** Holds if this bitfield is anonymous. */
predicate isAnonymous() {
hasName("(unnamed bitfield)")
}

View File

@@ -36,7 +36,7 @@ class Namespace extends NameQualifyingElement, @namespace {
/** Holds if this element is named `name`. */
predicate hasName(string name) { name = this.getName() }
/** Holds if the namespace is anonymous. */
/** Holds if this namespace is anonymous. */
predicate isAnonymous() {
hasName("(unnamed namespace)")
}

View File

@@ -9,10 +9,15 @@ private import semmle.code.cpp.internal.ResolveClass
* `Enum`, and `TypedefType`.
*/
class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @usertype {
/** the name of this type */
/**
* Gets the name of this type.
*/
override string getName() { usertypes(underlyingElement(this),result,_) }
/** the simple name of this type, without any template parameters */
/**
* Gets the simple name of this type, without any template parameters. For example
* if the name of the type is `"myType<int>"`, the simple name is just `"myType"`.
*/
string getSimpleName() {
result = getName().regexpReplaceAll("<.*", "")
}
@@ -20,6 +25,8 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @
override predicate hasName(string name) {
usertypes(underlyingElement(this),name,_)
}
/** Holds if this type is anonymous. */
predicate isAnonymous() {
getName().matches("(unnamed%")
}
@@ -54,7 +61,6 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @
result.isDefinition()
}
/** the location of the definition */
override Location getDefinitionLocation() {
if exists(getDefinition()) then
result = getDefinition().getLocation()
@@ -62,12 +68,17 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @
exists(Class t | this.(Class).isConstructedFrom(t) and result = t.getDefinition().getLocation())
}
/** Gets the function that directly encloses this type (if any). */
/**
* Gets the function that directly encloses this type (if any).
*/
Function getEnclosingFunction() {
enclosingfunction(underlyingElement(this),unresolveElement(result))
}
/** Whether this is a local type (i.e. a type that has a directly-enclosing function). */
/**
* Holds if this is a local type (that is, a type that has a directly-enclosing
* function).
*/
predicate isLocal() {
exists(getEnclosingFunction())
}

View File

@@ -264,7 +264,8 @@ class ParameterDeclarationEntry extends VariableDeclarationEntry {
/**
* A C/C++ variable with block scope [N4140 3.3.3]. In other words, a local
* variable or a function parameter.
* variable or a function parameter. Local variables can be static; use the
* `isStatic` member predicate to detect those.
*/
class LocalScopeVariable extends Variable, @localscopevariable {
/** Gets the function to which this variable belongs. */
@@ -397,6 +398,10 @@ class FunctionPointerMemberVariable extends MemberVariable {
*/
class TemplateVariable extends Variable {
TemplateVariable() { is_variable_template(underlyingElement(this)) }
/**
* Gets an instantiation of this variable template.
*/
Variable getAnInstantiation() { result.isConstructedFrom(this) }
}

View File

@@ -79,7 +79,10 @@ class XMLParent extends @xmlparent {
result = this.charsSetUpTo(n-1) + " " + chars))
}
/** Append all the character sequences of this XML parent from left to right, separated by a space. */
/**
* Gets the result of appending all the character sequences of this XML parent from
* left to right, separated by a space.
*/
string allCharactersString() {
result = concat(string chars, int pos | xmlChars(_, chars, this, pos, _, _) | chars, " " order by pos)
}