mirror of
https://github.com/github/codeql.git
synced 2025-12-18 09:43:15 +01:00
C++: Revert the getName() changes
This reverts the `getName()` parts of56e88cbac0and0a2e28858a.
This commit is contained in:
@@ -116,7 +116,7 @@ abstract class Declaration extends Locatable, @declaration {
|
|||||||
* To test whether this declaration has a particular name in the global
|
* To test whether this declaration has a particular name in the global
|
||||||
* namespace, use `hasGlobalName`.
|
* namespace, use `hasGlobalName`.
|
||||||
*/
|
*/
|
||||||
string getName() { result = underlyingElement(this).(Q::Declaration).getName() }
|
abstract string getName();
|
||||||
|
|
||||||
/** Holds if this declaration has the given name. */
|
/** Holds if this declaration has the given name. */
|
||||||
predicate hasName(string name) { name = this.getName() }
|
predicate hasName(string name) { name = this.getName() }
|
||||||
|
|||||||
@@ -100,6 +100,11 @@ class EnumConstant extends Declaration, @enumconstant {
|
|||||||
result = this.getDeclaringEnum().getDeclaringType()
|
result = this.getDeclaringEnum().getDeclaringType()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of this enumerator.
|
||||||
|
*/
|
||||||
|
override string getName() { enumconstants(underlyingElement(this),_,_,_,result,_) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value that this enumerator is initialized to, as a
|
* Gets the value that this enumerator is initialized to, as a
|
||||||
* string. This can be a value explicitly given to the enumerator, or an
|
* string. This can be a value explicitly given to the enumerator, or an
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ class FriendDecl extends Declaration, @frienddecl {
|
|||||||
/** Gets the location of this friend declaration. */
|
/** Gets the location of this friend declaration. */
|
||||||
override Location getLocation() { frienddecls(underlyingElement(this),_,_,result) }
|
override Location getLocation() { frienddecls(underlyingElement(this),_,_,result) }
|
||||||
|
|
||||||
|
/** Gets a descriptive string for this friend declaration. */
|
||||||
|
override string getName() {
|
||||||
|
result = this.getDeclaringClass().getName() + "'s friend"
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Friend declarations do not have specifiers. It makes no difference
|
* Friend declarations do not have specifiers. It makes no difference
|
||||||
* whether they are declared in a public, protected or private section of
|
* whether they are declared in a public, protected or private section of
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ private import semmle.code.cpp.internal.ResolveClass
|
|||||||
* in more detail in `Declaration.qll`.
|
* in more detail in `Declaration.qll`.
|
||||||
*/
|
*/
|
||||||
class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
|
class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
|
||||||
|
override string getName() { functions(underlyingElement(this),result,_) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DEPRECATED: Use `getIdentityString(Declaration)` from `semmle.code.cpp.Print` instead.
|
* DEPRECATED: Use `getIdentityString(Declaration)` from `semmle.code.cpp.Print` instead.
|
||||||
* Gets the full signature of this function, including return type, parameter
|
* Gets the full signature of this function, including return type, parameter
|
||||||
|
|||||||
@@ -148,6 +148,9 @@ deprecated class FinallyBlock extends Block {
|
|||||||
deprecated class Property extends Declaration {
|
deprecated class Property extends Declaration {
|
||||||
Property() { none() }
|
Property() { none() }
|
||||||
|
|
||||||
|
/** Gets the name of this property. */
|
||||||
|
override string getName() { none() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets nothing (provided for compatibility with Declaration).
|
* Gets nothing (provided for compatibility with Declaration).
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import semmle.code.cpp.Location
|
import semmle.code.cpp.Location
|
||||||
import semmle.code.cpp.Declaration
|
import semmle.code.cpp.Declaration
|
||||||
private import semmle.code.cpp.internal.ResolveClass
|
private import semmle.code.cpp.internal.ResolveClass
|
||||||
private import semmle.code.cpp.internal.QualifiedName as Q
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A C/C++ function parameter or catch block parameter.
|
* A C/C++ function parameter or catch block parameter.
|
||||||
@@ -14,6 +13,26 @@ private import semmle.code.cpp.internal.QualifiedName as Q
|
|||||||
* have multiple declarations.
|
* have multiple declarations.
|
||||||
*/
|
*/
|
||||||
class Parameter extends LocalScopeVariable, @parameter {
|
class Parameter extends LocalScopeVariable, @parameter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the canonical name, or names, of this parameter.
|
||||||
|
*
|
||||||
|
* The canonical names are the first non-empty category from the
|
||||||
|
* following list:
|
||||||
|
* 1. The name given to the parameter at the function's definition or
|
||||||
|
* (for catch block parameters) at the catch block.
|
||||||
|
* 2. A name given to the parameter at a function declaration.
|
||||||
|
* 3. The name "p#i" where i is the index of the parameter.
|
||||||
|
*/
|
||||||
|
override string getName() {
|
||||||
|
exists (VariableDeclarationEntry vde
|
||||||
|
| vde = getANamedDeclarationEntry() and result = vde.getName()
|
||||||
|
| vde.isDefinition() or not getANamedDeclarationEntry().isDefinition())
|
||||||
|
or
|
||||||
|
(not exists(getANamedDeclarationEntry()) and
|
||||||
|
result = "p#" + this.getIndex().toString())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of this parameter, including it's type.
|
* Gets the name of this parameter, including it's type.
|
||||||
*
|
*
|
||||||
@@ -34,6 +53,27 @@ class Parameter extends LocalScopeVariable, @parameter {
|
|||||||
else result = typeString + nameString))
|
else result = typeString + nameString))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private VariableDeclarationEntry getANamedDeclarationEntry() {
|
||||||
|
result = getAnEffectiveDeclarationEntry() and result.getName() != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a declaration entry corresponding to this declaration.
|
||||||
|
*
|
||||||
|
* This predicate is the same as getADeclarationEntry(), except that for
|
||||||
|
* parameters of instantiated function templates, gives the declaration
|
||||||
|
* entry of the prototype instantiation of the parameter (as
|
||||||
|
* non-prototype instantiations don't have declaration entries of their
|
||||||
|
* own).
|
||||||
|
*/
|
||||||
|
private VariableDeclarationEntry getAnEffectiveDeclarationEntry() {
|
||||||
|
if getFunction().isConstructedFrom(_)
|
||||||
|
then exists (Function prototypeInstantiation
|
||||||
|
| prototypeInstantiation.getParameter(getIndex()) = result.getVariable() and
|
||||||
|
getFunction().isConstructedFrom(prototypeInstantiation))
|
||||||
|
else result = getADeclarationEntry()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of this parameter in the given block (which should be
|
* Gets the name of this parameter in the given block (which should be
|
||||||
* the body of a function with which the parameter is associated).
|
* the body of a function with which the parameter is associated).
|
||||||
@@ -55,9 +95,7 @@ class Parameter extends LocalScopeVariable, @parameter {
|
|||||||
* In other words, this predicate holds precisely when the result of
|
* In other words, this predicate holds precisely when the result of
|
||||||
* `getName()` is not "p#i" (where `i` is the index of the parameter).
|
* `getName()` is not "p#i" (where `i` is the index of the parameter).
|
||||||
*/
|
*/
|
||||||
predicate isNamed() {
|
predicate isNamed() { exists(getANamedDeclarationEntry()) }
|
||||||
exists(underlyingElement(this).(Q::Parameter).getANamedDeclarationEntry())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the function to which this parameter belongs, if it is a function
|
* Gets the function to which this parameter belongs, if it is a function
|
||||||
@@ -97,13 +135,8 @@ class Parameter extends LocalScopeVariable, @parameter {
|
|||||||
* of the declaration locations.
|
* of the declaration locations.
|
||||||
*/
|
*/
|
||||||
override Location getLocation() {
|
override Location getLocation() {
|
||||||
exists(VariableDeclarationEntry vde |
|
exists(VariableDeclarationEntry vde | vde = getAnEffectiveDeclarationEntry() and result = vde.getLocation() |
|
||||||
vde = underlyingElement(this).(Q::Parameter).getAnEffectiveDeclarationEntry() and
|
vde.isDefinition() or not getAnEffectiveDeclarationEntry().isDefinition()
|
||||||
result = vde.getLocation()
|
|
||||||
|
|
|
||||||
vde.isDefinition()
|
|
||||||
or
|
|
||||||
not underlyingElement(this).(Q::Parameter).getAnEffectiveDeclarationEntry().isDefinition()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ private import semmle.code.cpp.internal.ResolveClass
|
|||||||
* `Enum`, and `TypedefType`.
|
* `Enum`, and `TypedefType`.
|
||||||
*/
|
*/
|
||||||
class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @usertype {
|
class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @usertype {
|
||||||
override string getName() {
|
/**
|
||||||
result = Declaration.super.getName()
|
* Gets the name of this type.
|
||||||
}
|
*/
|
||||||
|
override string getName() { usertypes(underlyingElement(this),result,_) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the simple name of this type, without any template parameters. For example
|
* Gets the simple name of this type, without any template parameters. For example
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ class Variable extends Declaration, @variable {
|
|||||||
/** Holds if this variable is `volatile`. */
|
/** Holds if this variable is `volatile`. */
|
||||||
predicate isVolatile() { this.getType().isVolatile() }
|
predicate isVolatile() { this.getType().isVolatile() }
|
||||||
|
|
||||||
|
/** Gets the name of this variable. */
|
||||||
|
override string getName() { none() }
|
||||||
|
|
||||||
/** Gets the type of this variable. */
|
/** Gets the type of this variable. */
|
||||||
Type getType() { none() }
|
Type getType() { none() }
|
||||||
|
|
||||||
@@ -294,6 +297,8 @@ deprecated class StackVariable extends Variable {
|
|||||||
* A local variable can be declared by a `DeclStmt` or a `ConditionDeclExpr`.
|
* A local variable can be declared by a `DeclStmt` or a `ConditionDeclExpr`.
|
||||||
*/
|
*/
|
||||||
class LocalVariable extends LocalScopeVariable, @localvariable {
|
class LocalVariable extends LocalScopeVariable, @localvariable {
|
||||||
|
override string getName() { localvariables(underlyingElement(this),_,result) }
|
||||||
|
|
||||||
override Type getType() { localvariables(underlyingElement(this),unresolveElement(result),_) }
|
override Type getType() { localvariables(underlyingElement(this),unresolveElement(result),_) }
|
||||||
|
|
||||||
override Function getFunction() {
|
override Function getFunction() {
|
||||||
@@ -306,6 +311,8 @@ class LocalVariable extends LocalScopeVariable, @localvariable {
|
|||||||
* A C/C++ variable which has global scope or namespace scope.
|
* A C/C++ variable which has global scope or namespace scope.
|
||||||
*/
|
*/
|
||||||
class GlobalOrNamespaceVariable extends Variable, @globalvariable {
|
class GlobalOrNamespaceVariable extends Variable, @globalvariable {
|
||||||
|
override string getName() { globalvariables(underlyingElement(this),_,result) }
|
||||||
|
|
||||||
override Type getType() { globalvariables(underlyingElement(this),unresolveElement(result),_) }
|
override Type getType() { globalvariables(underlyingElement(this),unresolveElement(result),_) }
|
||||||
|
|
||||||
override Element getEnclosingElement() { none() }
|
override Element getEnclosingElement() { none() }
|
||||||
@@ -353,6 +360,8 @@ class MemberVariable extends Variable, @membervariable {
|
|||||||
/** Holds if this member is public. */
|
/** Holds if this member is public. */
|
||||||
predicate isPublic() { this.hasSpecifier("public") }
|
predicate isPublic() { this.hasSpecifier("public") }
|
||||||
|
|
||||||
|
override string getName() { membervariables(underlyingElement(this),_,result) }
|
||||||
|
|
||||||
override Type getType() {
|
override Type getType() {
|
||||||
if (strictcount(this.getAType()) = 1) then (
|
if (strictcount(this.getAType()) = 1) then (
|
||||||
result = this.getAType()
|
result = this.getAType()
|
||||||
|
|||||||
Reference in New Issue
Block a user