Remove DeclaredEntity.getDecl().

It's not particularly useful except for functions, and the name is easy to confuse with `Entity.getDeclaration()`. Instead we now have `getFuncDecl()` just for functions, and a bit more API on `Function` to avoid its use where possible.
This commit is contained in:
Max Schaefer
2020-01-14 16:35:38 +00:00
parent b7a830593d
commit ad432965db
4 changed files with 13 additions and 17 deletions

View File

@@ -156,7 +156,7 @@ class FuncDecl extends @funcdecl, Decl, Documentable, FuncDef {
override BlockStmt getBody() { result = getChildStmt(2) }
/** Gets the function declared by this function declaration. */
DeclaredFunction getFunction() { this = result.getDecl() }
DeclaredFunction getFunction() { this = result.getFuncDecl() }
override string toString() { result = "function declaration" }
}

View File

@@ -482,7 +482,7 @@ class CallExpr extends CallOrConversionExpr {
* interface type.
*/
FuncDef getACallee() {
result = getTarget().(DeclaredFunction).getDecl()
result = getTarget().(DeclaredFunction).getFuncDecl()
or
exists(SelectorExpr sel, InterfaceType declaredRecv, Type actualRecv |
sel = getCalleeExpr().stripParens() and

View File

@@ -128,9 +128,6 @@ class Entity extends @object {
/** A declared entity (that is, type, constant, variable or function). */
class DeclaredEntity extends Entity, @declobject {
/** Gets the declaration of this entity. */
Decl getDecl() { none() }
/** Gets the expression to which this entity is initialized, if any. */
Expr getInit() {
exists(ValueSpec spec, int i |
@@ -151,9 +148,6 @@ class TypeEntity extends Entity, @typeobject { }
/** A declared named type. */
class DeclaredType extends TypeEntity, DeclaredEntity, @decltypeobject {
/** Gets the declaration of this type. */
override TypeDecl getDecl() { result.getASpec() = this.getSpec() }
/** Gets the declaration specifier declaring this type. */
TypeSpec getSpec() { result.getNameExpr() = this.getDeclaration() }
}
@@ -175,9 +169,6 @@ class Constant extends ValueEntity, @constobject { }
/** A declared constant. */
class DeclaredConstant extends Constant, DeclaredEntity, @declconstobject {
/** Gets the declaration of this constant. */
override ConstDecl getDecl() { result.getASpec() = this.getSpec() }
/** Gets the declaration specifier declaring this constant. */
ValueSpec getSpec() { result.getANameExpr() = this.getDeclaration() }
}
@@ -195,9 +186,6 @@ class Variable extends ValueEntity, @varobject { }
/** A declared variable. */
class DeclaredVariable extends Variable, DeclaredEntity, @declvarobject {
/** Gets the declaration of this variable. */
override VarDecl getDecl() { result.getASpec() = this.getSpec() }
/** Gets the declaration specifier declaring this variable. */
ValueSpec getSpec() { result.getANameExpr() = this.getDeclaration() }
}
@@ -297,6 +285,12 @@ class Function extends ValueEntity, @functionobject {
/** Gets the body of this function, if any. */
BlockStmt getBody() { none() }
/** Gets the `i`th parameter of this function. */
Parameter getParameter(int i) { none() }
/** Gets a parameter of this function. */
Parameter getAParameter() { result = getParameter(_) }
}
/** A method, that is, a function with a receiver variable. */
@@ -371,9 +365,11 @@ class Method extends Function {
/** A declared function. */
class DeclaredFunction extends Function, DeclaredEntity, @declfunctionobject {
/** Gets the declaration of this function. */
override FuncDecl getDecl() { result.getNameExpr() = this.getDeclaration() }
FuncDecl getFuncDecl() { result.getNameExpr() = this.getDeclaration() }
override BlockStmt getBody() { result = getDecl().getBody() }
override BlockStmt getBody() { result = getFuncDecl().getBody() }
override Parameter getParameter(int i) { result = getFuncDecl().getParameter(i) }
override predicate mayHaveSideEffects() {
not exists(getBody())

View File

@@ -223,7 +223,7 @@ class GlobalFunctionNode extends FunctionNode, MkGlobalFunctionNode {
GlobalFunctionNode() { this = MkGlobalFunctionNode(func) }
override ParameterNode getParameter(int i) {
result = parameterNode(func.(DeclaredFunction).getDecl().getParameter(i))
result = parameterNode(func.getParameter(i))
}
override string getName() { result = func.getName() }