CPP: class, struct or union where appropriate.

This commit is contained in:
Geoffrey White
2019-08-06 13:24:46 +01:00
parent 8d22eb87f0
commit ab823f45fc

View File

@@ -32,15 +32,15 @@ class Class extends UserType {
}
override string getCanonicalQLClass() { result = "Class" }
/** Gets a child declaration of this class. */
/** Gets a child declaration of this class, struct or union. */
override Declaration getADeclaration() { result = this.getAMember() }
/** Gets a type declared in this class. */
/** Gets a type declared in this class, struct or union. */
UserType getANestedType() { result = this.getAMember() }
/**
* Gets a function declared in this class.
* Gets a function declared in this class, struct or union.
* For template member functions, results include both the template
* and the instantiations of that template. If you only want the
* template, then use `getACanonicalMemberFunction()` instead.
@@ -48,7 +48,7 @@ class Class extends UserType {
MemberFunction getAMemberFunction() { result = this.getAMember() }
/**
* Gets a function declared in this class.
* Gets a function declared in this class, struct or union.
* For template member functions, results include only the template.
* If you also want instantiations of the template, then use
* `getAMemberFunction()` instead.
@@ -58,7 +58,7 @@ class Class extends UserType {
}
/**
* Gets a member variable declared in this class.
* Gets a member variable declared in this class, struct or union.
* For template member variables, results include both the template
* and the instantiations of that template. If you only want the
* template, then use `getACanonicalMemberVariable()` instead.
@@ -66,7 +66,7 @@ class Class extends UserType {
MemberVariable getAMemberVariable() { result = this.getAMember() }
/**
* Gets a member variable declared in this class.
* Gets a member variable declared in this class, struct or union.
* For template member variables, results include only the template.
* If you also want instantiations of the template, then use
* `getAMemberVariable()` instead.
@@ -74,22 +74,23 @@ class Class extends UserType {
MemberVariable getACanonicalMemberVariable() { result = this.getAMember() }
/**
* Gets a member declared in this class. For template members, this
* may be either the template or an instantiation of that template.
* If you only want the template, see
* Gets a member declared in this class, struct or union.
* For template members, this may be either the template or an instantiation
* of that template. If you only want the template, see
* `getACanonicalMember()`.
*/
Declaration getAMember() { result = this.getAMember(_) }
/**
* Gets a member declared in this class.
* Gets a member declared in this class, struct or union.
* If you also want template instantiations of results, see
* `getAMember()`.
*/
Declaration getACanonicalMember() { result = this.getCanonicalMember(_) }
/**
* Gets the (zero-based) `index`th member declared in this class.
* Gets the (zero-based) `index`th member declared in this class, struct
* or union.
* If you also want template instantiations of results, see
* `getAMember(int)`.
*/
@@ -97,8 +98,8 @@ class Class extends UserType {
/**
* Gets the (zero-based) `index`th canonical member declared in this
* class and, if that member is a template, all instantiations of that
* template. If you only want the canonical member, see
* class, struct or union. If that member is a template, all instantiations
* of that template. If you only want the canonical member, see
* `getCanonicalMember(int)`.
*/
Declaration getAMember(int index) {
@@ -125,7 +126,7 @@ class Class extends UserType {
deprecated int getNumMember() { result = count(this.getAMember()) }
/**
* Gets a private member declared in this class.
* Gets a private member declared in this class, struct or union.
* For template members, this may be either the template or an
* instantiation of that template. For just the template, use
* `getAPrivateCanonicalMember()`.
@@ -135,7 +136,7 @@ class Class extends UserType {
}
/**
* Gets a private canonical member declared in this class.
* Gets a private canonical member declared in this class, struct or union.
* If you also want template instantiations of results, see
* `getAPrivateMember()`.
*/
@@ -144,7 +145,7 @@ class Class extends UserType {
}
/**
* Gets a protected member declared in this class.
* Gets a protected member declared in this class, struct or union.
* For template members, this may be either the template or an
* instantiation of that template. For just the template, use
* `getAProtectedCanonicalMember()`.
@@ -154,7 +155,7 @@ class Class extends UserType {
}
/**
* Gets a protected canonical member declared in this class.
* Gets a protected canonical member declared in this class, struct or union.
* If you also want template instantiations of results, see
* `getAProtectedMember()`.
*/
@@ -163,7 +164,7 @@ class Class extends UserType {
}
/**
* Gets a public member declared in this class.
* Gets a public member declared in this class, struct or union.
* For template members, this may be either the template or an
* instantiation of that template. For just the template, use
* `getAPublicCanonicalMember()`.
@@ -173,7 +174,7 @@ class Class extends UserType {
}
/**
* Gets a public canonical member declared in this class.
* Gets a public canonical member declared in this class, struct or union.
* If you also want template instantiations of results, see
* `getAPublicMember()`.
*/
@@ -181,18 +182,18 @@ class Class extends UserType {
result = this.getACanonicalMember() and result.hasSpecifier("public")
}
/** Gets a static member declared in this class. */
/** Gets a static member declared in this class, struct or union. */
Declaration getAStaticMember() {
result = this.getAMember() and result.isStatic()
}
/** Gets a field of this class. */
/** Gets a field of this class, struct or union. */
Field getAField() { result = this.getAMemberVariable() }
/** Gets a constructor of this class. */
/** Gets a constructor of this class, struct or union. */
Constructor getAConstructor() { result = this.getAMemberFunction() }
/** Holds if this class has a constructor. */
/** Holds if this class, struct or union has a constructor. */
predicate hasConstructor() { exists(this.getAConstructor()) }
/**
@@ -290,12 +291,12 @@ class Class extends UserType {
}
/**
* Holds if this class has an implicitly-declared copy constructor that is
* not _deleted_. This predicate is more accurate than checking
* if this class has a `CopyConstructor cc` where `cc.isCompilerGenerated()`
* since such a `CopyConstructor` may not exist in the database if (1) it is
* never called or (2) it is _trivial_, meaning that it is equivalent to
* `memcpy`.
* Holds if this class, struct or union has an implicitly-declared copy
* constructor that is not _deleted_. This predicate is more accurate than
* checking if this class, struct or union has a `CopyConstructor cc` where
* `cc.isCompilerGenerated()` since such a `CopyConstructor` may not exist
* in the database if (1) it is never called or (2) it is _trivial_, meaning
* that it is equivalent to `memcpy`.
*/
predicate hasImplicitCopyConstructor() {
not this.implicitCopyConstructorDeleted() and
@@ -305,12 +306,12 @@ class Class extends UserType {
}
/**
* Holds if this class has an implicitly-declared copy assignment operator
* that is not _deleted_. This predicate is more accurate than checking
* if this class has a `CopyAssignmentOperator ca` where
* `ca.isCompilerGenerated()` since such a `CopyAssignmentOperator` may not
* exist in the database if (1) it is never called or (2) it is _trivial_,
* meaning that it is equivalent to `memcpy`.
* Holds if this class, struct or union has an implicitly-declared copy
* assignment operator that is not _deleted_. This predicate is more
* accurate than checking if this class, struct or union has a
* `CopyAssignmentOperator ca` where `ca.isCompilerGenerated()` since such a
* `CopyAssignmentOperator` may not exist in the database if (1) it is never
* called or (2) it is _trivial_, meaning that it is equivalent to `memcpy`.
*/
predicate hasImplicitCopyAssignmentOperator() {
not this.implicitCopyAssignmentOperatorDeleted() and
@@ -321,7 +322,8 @@ class Class extends UserType {
/**
* Holds if the compiler would be unable to generate a copy constructor for
* this class. This predicate implements the rules listed here:
* this class, struct or union. This predicate implements the rules listed
* here:
* http://en.cppreference.com/w/cpp/language/copy_constructor#Deleted_implicitly-declared_copy_constructor
*/
predicate implicitCopyConstructorDeleted() {
@@ -366,7 +368,8 @@ class Class extends UserType {
/**
* Holds if the compiler would be unable to generate a copy assignment
* operator for this class. This predicate implements the rules listed here:
* operator for this class, struct or union. This predicate implements the
* rules listed here:
* http://en.cppreference.com/w/cpp/language/copy_assignment#Deleted_implicitly-declared_copy_assignment_operator
*/
predicate implicitCopyAssignmentOperatorDeleted() {
@@ -420,14 +423,15 @@ class Class extends UserType {
// Not implemented
}
/** Gets the destructor of this class, if any. */
/** Gets the destructor of this class, struct or union, if any. */
Destructor getDestructor() { result = this.getAMemberFunction() }
/** Holds if this class has a destructor. */
/** Holds if this class, struct or union has a destructor. */
predicate hasDestructor() { exists(this.getDestructor()) }
/**
* Holds if this class is a POD (Plain Old Data) class [N4140 9(10)].
* Holds if this class, struct or union is a POD (Plain Old Data) class
* [N4140 9(10)].
*
* The definition of POD changed between C++03 and C++11, so whether
* a class is POD can depend on which version of the language it was
@@ -437,24 +441,24 @@ class Class extends UserType {
predicate isPOD() { is_pod_class(underlyingElement(this)) }
/**
* Holds if this class is a standard-layout class [N4140 9(7)]. Also holds
* for structs in C programs.
* Holds if this class, struct or union is a standard-layout class
* [N4140 9(7)]. Also holds for structs in C programs.
*/
predicate isStandardLayout() { is_standard_layout_class(underlyingElement(this)) }
/**
* Holds if this class is abstract, in other words whether it declares one
* or more pure virtual member functions.
* Holds if this class/struct is abstract, in other words whether
* it declares one or more pure virtual member functions.
*/
predicate isAbstract() { this.getAMemberFunction() instanceof PureVirtualFunction }
/** Gets a direct base class of this class [N4140 10]. */
/** Gets a direct base class/struct of this class/struct [N4140 10]. */
Class getABaseClass() { this.getADerivation().getBaseClass() = result }
/** Gets a class that is directly derived from this class [N4140 10]. */
/** Gets a class/struct that is directly derived from this class/struct [N4140 10]. */
Class getADerivedClass() { result.getABaseClass() = this }
/** Holds if this class derives directly from that. */
/** Holds if this class/struct derives directly from that. */
predicate derivesFrom(Class that) {
this.getABaseClass() = that
}
@@ -465,8 +469,8 @@ class Class extends UserType {
}
/**
* Gets a class derivation of this class, for example the `public B` in the
* following code:
* Gets a class derivation of this class/struct, for example the
* `public B` in the following code:
* ```
* class D : public B {
* ...
@@ -522,8 +526,8 @@ class Class extends UserType {
}
/**
* Holds if this class has a virtual class derivation, for example the
* `virtual public B` in the following code:
* Holds if this class/struct has a virtual class derivation, for
* example the `virtual public B` in the following code:
* ```
* class D : virtual public B {
* ...
@@ -551,8 +555,8 @@ class Class extends UserType {
}
/**
* Holds if this class has a private class derivation, for example the
* `private B` in the following code:
* Holds if this class/struct has a private class derivation, for
* example the `private B` in the following code:
* ```
* class D : private B {
* ...
@@ -568,8 +572,8 @@ class Class extends UserType {
}
/**
* Holds if this class has a public class derivation, for example the
* `public B` in the following code:
* Holds if this class/struct has a public class derivation, for
* example the `public B` in the following code:
* ```
* class D : public B {
* ...
@@ -585,8 +589,8 @@ class Class extends UserType {
}
/**
* Holds if this class has a protected class derivation, for example the
* `protected B` in the following code:
* Holds if this class/struct has a protected class derivation, for
* example the `protected B` in the following code:
* ```
* class D : protected B {
* ...
@@ -601,10 +605,10 @@ class Class extends UserType {
)
}
/** Gets the metric class. */
/** Gets the metric class associated with this class, struct or union. */
MetricClass getMetrics() { result = this }
/** Gets a friend declaration in this class. */
/** Gets a friend declaration in this class, struct or union. */
FriendDecl getAFriendDecl() { result.getDeclaringClass() = this }
override string explain() { result = "class " + this.getName() }
@@ -618,9 +622,9 @@ class Class extends UserType {
override int getAlignment() { usertypesize(underlyingElement(this),_,result) }
/**
* Holds if this class is constructed from another class as a result of
* template instantiation. It originates either from a class template or
* from a class nested in a class template.
* Holds if this class, struct or union is constructed from another class as
* a result of template instantiation. It originates either from a class
* template or from a class nested in a class template.
*/
predicate isConstructedFrom(Class c) {
class_instantiation(underlyingElement(this), unresolveElement(c))
@@ -636,8 +640,8 @@ class Class extends UserType {
}
/**
* Holds if or not this class is polymorphic (has a virtual function, or
* inherits one).
* Holds if or not this class/struct is polymorphic (has a virtual
* function, or inherits one).
*/
predicate isPolymorphic() {
exists(MemberFunction f | f.getDeclaringType() = getABaseClass*() and f.isVirtual())
@@ -647,19 +651,19 @@ class Class extends UserType {
getATemplateArgument().involvesTemplateParameter()
}
/** Holds if this class was declared 'final'. */
/** Holds if this class, struct or union was declared 'final'. */
predicate isFinal() {
usertype_final(underlyingElement(this))
}
/** Gets a link target which references this class. */
/** Gets a link target which references this class, struct or union. */
LinkTarget getALinkTarget() {
this = result.getAClass()
}
/**
* Gets the UUID that associated with this class via the `__declspec(uuid)`
* attribute.
* Gets the UUID that associated with this class, struct or union via the
* `__declspec(uuid)` attribute.
*
* Regardless of the format of the UUID string in source code, the returned
* value is normalized to the standard "registry format", without braces, and
@@ -817,7 +821,7 @@ class ClassDerivation extends Locatable, @derivation {
}
/**
* Gets the class that is doing the deriving. For example, the derived
* Gets the class/struct that is doing the deriving. For example, the derived
* class in the following code would be `D`:
* ```
* struct B {
@@ -833,7 +837,7 @@ class ClassDerivation extends Locatable, @derivation {
/**
* Gets the index of the derivation in the derivation list for the
* derived class (indexed from 0). For example, the index of the
* derived class/struct (indexed from 0). For example, the index of the
* derivation of `B2` in the following code would be `1`:
* ```
* struct D : B1, B2 {
@@ -883,8 +887,8 @@ class ClassDerivation extends Locatable, @derivation {
}
/**
* A class that is directly enclosed by a function. For example the `struct` in
* the following code is a `LocalClass`:
* A class, struct or union that is directly enclosed by a function. For example
* the `struct` in the following code is a `LocalClass`:
* ```
* void myFunction() {
* struct { int x; int y; } vec = { 1, 2 };
@@ -905,7 +909,7 @@ class LocalClass extends Class {
}
/**
* A nested class, that is, a class declared within another class. For example
* A class, struct or union that is declared within another class. For example
* the struct `PairT` in the following code is a nested class:
* ```
* template<class T>
@@ -937,7 +941,7 @@ class NestedClass extends Class {
}
/**
* An "abstract class", in other words a class that contains at least one
* An "abstract class", in other words a class/struct that contains at least one
* pure virtual function.
*/
class AbstractClass extends Class {
@@ -1131,8 +1135,8 @@ deprecated class Interface extends Class {
}
/**
* A class derivation that is virtual. For example the derivation in the following
* code is a `VirtualClassDerivation`:
* A class/struct derivation that is virtual. For example the derivation in
* the following code is a `VirtualClassDerivation`:
* ```
* class MyClass : public virtual MyBaseClass {
* ...
@@ -1148,8 +1152,9 @@ class VirtualClassDerivation extends ClassDerivation {
}
/**
* A class that is the base of some virtual class derivation. For example
* `MyBaseClass` in the following code is a `VirtualBaseClass` of `MyClass`:
* A class/struct that is the base of some virtual class derivation. For
* example `MyBaseClass` in the following code is a `VirtualBaseClass` of
* `MyClass`:
* ```
* class MyBaseClass {
* ...
@@ -1167,12 +1172,12 @@ class VirtualBaseClass extends Class {
override string getCanonicalQLClass() { result = "VirtualBaseClass" }
/** A virtual class derivation of which this class is the base. */
/** A virtual class derivation of which this class/struct is the base. */
VirtualClassDerivation getAVirtualDerivation() {
result.getBaseClass() = this
}
/** A class that is derived from this one using virtual inheritance. */
/** A class/struct that is derived from this one using virtual inheritance. */
Class getAVirtuallyDerivedClass() {
result = getAVirtualDerivation().getDerivedClass()
}