From f2197e67f5ea1a9b3b1519a6a0912fba1b0f67d4 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Tue, 4 Apr 2023 15:14:27 +0100 Subject: [PATCH] C++: Deprecate single-parameter 'getFieldExpr' and 'getElementExpr'. --- cpp/ql/lib/semmle/code/cpp/PrintAST.qll | 8 ++++---- cpp/ql/lib/semmle/code/cpp/Variable.qll | 2 +- .../semmle/code/cpp/dataflow/internal/DataFlowPrivate.qll | 2 +- cpp/ql/lib/semmle/code/cpp/exprs/Lambda.qll | 2 +- cpp/ql/lib/semmle/code/cpp/exprs/Literal.qll | 8 ++++---- .../ir/implementation/raw/internal/TranslatedElement.qll | 8 ++++---- cpp/ql/lib/semmle/code/cpp/valuenumbering/HashCons.qll | 6 +++--- .../library-tests/literals/aggregate_literals/arrays.ql | 2 +- .../literals/aggregate_literals/arrays_child_exprs.ql | 2 +- .../library-tests/literals/aggregate_literals/classes.ql | 2 +- .../literals/aggregate_literals/classes_child_exprs.ql | 2 +- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/PrintAST.qll b/cpp/ql/lib/semmle/code/cpp/PrintAST.qll index 106e49aff74..1b04f5e7a7b 100644 --- a/cpp/ql/lib/semmle/code/cpp/PrintAST.qll +++ b/cpp/ql/lib/semmle/code/cpp/PrintAST.qll @@ -752,13 +752,13 @@ private predicate namedExprChildPredicates(Expr expr, Element ele, string pred) expr.(VariableAccess).getQualifier() = ele and pred = "getQualifier()" or exists(Field f | - expr.(ClassAggregateLiteral).getFieldExpr(f) = ele and - pred = "getFieldExpr(" + f.toString() + ")" + expr.(ClassAggregateLiteral).getAFieldExpr(f) = ele and + pred = "getAFieldExpr(" + f.toString() + ")" ) or exists(int n | - expr.(ArrayOrVectorAggregateLiteral).getElementExpr(n) = ele and - pred = "getElementExpr(" + n.toString() + ")" + expr.(ArrayOrVectorAggregateLiteral).getAnElementExpr(n) = ele and + pred = "getAnElementExpr(" + n.toString() + ")" ) or expr.(AlignofExprOperator).getExprOperand() = ele and pred = "getExprOperand()" diff --git a/cpp/ql/lib/semmle/code/cpp/Variable.qll b/cpp/ql/lib/semmle/code/cpp/Variable.qll index c82f3689c85..0f66c0f51d4 100644 --- a/cpp/ql/lib/semmle/code/cpp/Variable.qll +++ b/cpp/ql/lib/semmle/code/cpp/Variable.qll @@ -133,7 +133,7 @@ class Variable extends Declaration, @variable { or exists(AssignExpr ae | ae.getLValue().(Access).getTarget() = this and result = ae.getRValue()) or - exists(ClassAggregateLiteral l | result = l.getFieldExpr(this)) + exists(ClassAggregateLiteral l | result = l.getAFieldExpr(this)) } /** diff --git a/cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowPrivate.qll b/cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowPrivate.qll index 6f2da96f27f..9b4e0e6a4f9 100644 --- a/cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowPrivate.qll +++ b/cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowPrivate.qll @@ -159,7 +159,7 @@ predicate storeStep(Node node1, Content f, PostUpdateNode node2) { // `PostUpdateNode`, which means it must be an `ObjectInitializerNode`. node2.asExpr() = aggr and f.(FieldContent).getField() = field and - aggr.getFieldExpr(field) = node1.asExpr() + aggr.getAFieldExpr(field) = node1.asExpr() ) or exists(FieldAccess fa | diff --git a/cpp/ql/lib/semmle/code/cpp/exprs/Lambda.qll b/cpp/ql/lib/semmle/code/cpp/exprs/Lambda.qll index 6b75bd9b6c3..313875d1325 100644 --- a/cpp/ql/lib/semmle/code/cpp/exprs/Lambda.qll +++ b/cpp/ql/lib/semmle/code/cpp/exprs/Lambda.qll @@ -147,7 +147,7 @@ class LambdaCapture extends Locatable, @lambdacapture { */ Expr getInitializer() { exists(LambdaExpression lambda | this = lambda.getCapture(_) | - result = lambda.getInitializer().getFieldExpr(this.getField()) + result = lambda.getInitializer().getAFieldExpr(this.getField()) ) } } diff --git a/cpp/ql/lib/semmle/code/cpp/exprs/Literal.qll b/cpp/ql/lib/semmle/code/cpp/exprs/Literal.qll index 413cca13b3b..a92997217f9 100644 --- a/cpp/ql/lib/semmle/code/cpp/exprs/Literal.qll +++ b/cpp/ql/lib/semmle/code/cpp/exprs/Literal.qll @@ -204,7 +204,7 @@ class ClassAggregateLiteral extends AggregateLiteral { * This predicate may have multiple results since a field can be initialized * multiple times in the same initializer. */ - Expr getFieldExpr(Field field) { result = this.getFieldExpr(field, _) } + deprecated Expr getFieldExpr(Field field) { result = this.getFieldExpr(field, _) } /** * Gets the expression within the aggregate literal that is used to initialize @@ -238,7 +238,7 @@ class ClassAggregateLiteral extends AggregateLiteral { ( // If the field has an explicit initializer expression, then the field is // initialized. - exists(this.getFieldExpr(field)) + exists(this.getAFieldExpr(field)) or // If the type is not a union, all fields without initializers are value // initialized. @@ -262,7 +262,7 @@ class ClassAggregateLiteral extends AggregateLiteral { pragma[inline] predicate isValueInitialized(Field field) { this.isInitialized(field) and - not exists(this.getFieldExpr(field)) + not exists(this.getAFieldExpr(field)) } } @@ -309,7 +309,7 @@ class ArrayOrVectorAggregateLiteral extends AggregateLiteral { * This predicate may have multiple results since an element can be initialized * multiple times in the same initializer. */ - Expr getElementExpr(int elementIndex) { result = this.getElementExpr(elementIndex, _) } + deprecated Expr getElementExpr(int elementIndex) { result = this.getElementExpr(elementIndex, _) } /** * Gets the expression within the aggregate literal that is used to initialize diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll index c320c7aa49e..c92fd197db1 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll @@ -606,9 +606,9 @@ newtype TTranslatedElement = not ignoreExpr(expr) and ( exists(Initializer init | init.getExpr().getFullyConverted() = expr) or - exists(ClassAggregateLiteral initList | initList.getFieldExpr(_).getFullyConverted() = expr) or + exists(ClassAggregateLiteral initList | initList.getAFieldExpr(_).getFullyConverted() = expr) or exists(ArrayOrVectorAggregateLiteral initList | - initList.getElementExpr(_).getFullyConverted() = expr + initList.getAnElementExpr(_).getFullyConverted() = expr ) or exists(ReturnStmt returnStmt | returnStmt.getExpr().getFullyConverted() = expr) or exists(ConstructorFieldInit fieldInit | fieldInit.getExpr().getFullyConverted() = expr) or @@ -785,7 +785,7 @@ private int getNextExplicitlyInitializedElementAfter( ArrayOrVectorAggregateLiteral initList, int afterElementIndex ) { isFirstValueInitializedElementInRange(initList, afterElementIndex) and - result = min(int i | exists(initList.getElementExpr(i)) and i > afterElementIndex) + result = min(int i | exists(initList.getAnElementExpr(i)) and i > afterElementIndex) } /** @@ -798,7 +798,7 @@ private predicate isFirstValueInitializedElementInRange( initList.isValueInitialized(elementIndex) and ( elementIndex = 0 or - exists(initList.getElementExpr(elementIndex - 1)) + exists(initList.getAnElementExpr(elementIndex - 1)) ) } diff --git a/cpp/ql/lib/semmle/code/cpp/valuenumbering/HashCons.qll b/cpp/ql/lib/semmle/code/cpp/valuenumbering/HashCons.qll index cc368222b17..6570eb64425 100644 --- a/cpp/ql/lib/semmle/code/cpp/valuenumbering/HashCons.qll +++ b/cpp/ql/lib/semmle/code/cpp/valuenumbering/HashCons.qll @@ -741,7 +741,7 @@ private predicate mk_FieldCons( analyzableClassAggregateLiteral(cal) and cal.getUnspecifiedType() = c and exists(Expr e | - e = cal.getFieldExpr(f).getFullyConverted() and + e = cal.getAFieldExpr(f).getFullyConverted() and f.getInitializationOrder() = i and ( hc = hashCons(e) and @@ -757,9 +757,9 @@ private predicate mk_FieldCons( private predicate analyzableClassAggregateLiteral(ClassAggregateLiteral cal) { forall(int i | exists(cal.getChild(i)) | strictcount(cal.getChild(i).getFullyConverted()) = 1 and - strictcount(Field f | cal.getChild(i) = cal.getFieldExpr(f)) = 1 and + strictcount(Field f | cal.getChild(i) = cal.getAFieldExpr(f)) = 1 and strictcount(Field f, int j | - cal.getFieldExpr(f) = cal.getChild(i) and j = f.getInitializationOrder() + cal.getAFieldExpr(f) = cal.getChild(i) and j = f.getInitializationOrder() ) = 1 ) } diff --git a/cpp/ql/test/library-tests/literals/aggregate_literals/arrays.ql b/cpp/ql/test/library-tests/literals/aggregate_literals/arrays.ql index d4d19ccfd1b..41c7c8676c2 100644 --- a/cpp/ql/test/library-tests/literals/aggregate_literals/arrays.ql +++ b/cpp/ql/test/library-tests/literals/aggregate_literals/arrays.ql @@ -2,4 +2,4 @@ import cpp from ArrayType a, ArrayAggregateLiteral al, int i where a = al.getType() -select al, a, i, al.getElementExpr(i) +select al, a, i, al.getAnElementExpr(i) diff --git a/cpp/ql/test/library-tests/literals/aggregate_literals/arrays_child_exprs.ql b/cpp/ql/test/library-tests/literals/aggregate_literals/arrays_child_exprs.ql index 7cde1070add..927cc9aff13 100644 --- a/cpp/ql/test/library-tests/literals/aggregate_literals/arrays_child_exprs.ql +++ b/cpp/ql/test/library-tests/literals/aggregate_literals/arrays_child_exprs.ql @@ -5,5 +5,5 @@ import cpp // (which, in the case of designated initializers, will not necessarily match // the order of the array elements). from ArrayAggregateLiteral aal, int childIndex, int elementIndex -where aal.getElementExpr(elementIndex) = aal.getChild(childIndex) +where aal.getAnElementExpr(elementIndex) = aal.getChild(childIndex) select aal, aal.getUnspecifiedType(), childIndex, aal.getChild(childIndex), elementIndex diff --git a/cpp/ql/test/library-tests/literals/aggregate_literals/classes.ql b/cpp/ql/test/library-tests/literals/aggregate_literals/classes.ql index 560a403015d..dffad96079f 100644 --- a/cpp/ql/test/library-tests/literals/aggregate_literals/classes.ql +++ b/cpp/ql/test/library-tests/literals/aggregate_literals/classes.ql @@ -4,4 +4,4 @@ from Class c, ClassAggregateLiteral al, Field f where c = al.getType() and f = c.getAField() -select al, c, f, al.getFieldExpr(f) +select al, c, f, al.getAFieldExpr(f) diff --git a/cpp/ql/test/library-tests/literals/aggregate_literals/classes_child_exprs.ql b/cpp/ql/test/library-tests/literals/aggregate_literals/classes_child_exprs.ql index e6dbbd7e111..a8023412e64 100644 --- a/cpp/ql/test/library-tests/literals/aggregate_literals/classes_child_exprs.ql +++ b/cpp/ql/test/library-tests/literals/aggregate_literals/classes_child_exprs.ql @@ -5,5 +5,5 @@ import cpp // (which, in the case of designated initializers, will not necessarily match // the order in which the fields were declared). from ClassAggregateLiteral cal, int i, Field f -where cal.getFieldExpr(f) = cal.getChild(i) +where cal.getAFieldExpr(f) = cal.getChild(i) select cal, cal.getUnspecifiedType(), i, cal.getChild(i), f