Skip to content

Commit 52682e2

Browse files
committed
C++: Replace the word 'repetition' with 'position' to properly reflect the semantics of the dbscheme.
1 parent 3daefa8 commit 52682e2

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

cpp/ql/lib/semmle/code/cpp/exprs/Literal.qll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ class ClassAggregateLiteral extends AggregateLiteral {
208208

209209
/**
210210
* Gets the expression within the aggregate literal that is used to initialize
211-
* field `field` the `repitition`'th time in the initializer list, if present.
211+
* field `field`, if present. The expression is the `position`'th entry in the
212+
* aggregate literal.
212213
*
213214
* For example, if `aggr` represents the initialization literal `{.x = 1234, .x = 5678}` in
214215
* ```cpp
@@ -217,10 +218,10 @@ class ClassAggregateLiteral extends AggregateLiteral {
217218
* ```
218219
* then `aggr.getFieldExpr(x, 0)` gives `1234`, and `aggr.getFieldExpr(x, 1)` gives `5678`.
219220
*/
220-
Expr getFieldExpr(Field field, int repitition) {
221+
Expr getFieldExpr(Field field, int position) {
221222
field = classType.getAField() and
222223
aggregate_field_init(underlyingElement(this), unresolveElement(result), unresolveElement(field),
223-
repitition)
224+
position)
224225
}
225226

226227
/**
@@ -309,16 +310,17 @@ class ArrayOrVectorAggregateLiteral extends AggregateLiteral {
309310

310311
/**
311312
* Gets the expression within the aggregate literal that is used to initialize
312-
* element `elementIndex` the `repitition`'th time in the initializer list, if present.
313+
* element `elementIndex`, if present. The expression is the `position`'th entry
314+
* in the aggregate literal.
313315
*
314316
* For example, if `a` represents the initialization literal `{[0] = 1234, [0] = 5678}` in
315317
* ```cpp
316318
* int x[1] = {[0] = 1234, [0] = 5678};
317319
* ```
318320
* then `a.getElementExpr(0, 0)` gives `1234`, and `a.getElementExpr(0, 1)` gives `5678`.
319321
*/
320-
Expr getElementExpr(int elementIndex, int repitition) {
321-
aggregate_array_init(underlyingElement(this), unresolveElement(result), elementIndex, repitition)
322+
Expr getElementExpr(int elementIndex, int position) {
323+
aggregate_array_init(underlyingElement(this), unresolveElement(result), elementIndex, position)
322324
}
323325

324326
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,19 +619,19 @@ newtype TTranslatedElement =
619619
)
620620
} or
621621
// The initialization of a field via a member of an initializer list.
622-
TTranslatedExplicitFieldInitialization(Expr ast, Field field, Expr expr, int repitition) {
622+
TTranslatedExplicitFieldInitialization(Expr ast, Field field, Expr expr, int position) {
623623
exists(ClassAggregateLiteral initList |
624624
not ignoreExpr(initList) and
625625
ast = initList and
626-
expr = initList.getFieldExpr(field, repitition).getFullyConverted()
626+
expr = initList.getFieldExpr(field, position).getFullyConverted()
627627
)
628628
or
629629
exists(ConstructorFieldInit init |
630630
not ignoreExpr(init) and
631631
ast = init and
632632
field = init.getTarget() and
633633
expr = init.getExpr().getFullyConverted() and
634-
repitition = 0
634+
position = -1
635635
)
636636
} or
637637
// The value initialization of a field due to an omitted member of an
@@ -645,10 +645,10 @@ newtype TTranslatedElement =
645645
} or
646646
// The initialization of an array element via a member of an initializer list.
647647
TTranslatedExplicitElementInitialization(
648-
ArrayOrVectorAggregateLiteral initList, int elementIndex, int repitition
648+
ArrayOrVectorAggregateLiteral initList, int elementIndex, int position
649649
) {
650650
not ignoreExpr(initList) and
651-
exists(initList.getElementExpr(elementIndex, repitition))
651+
exists(initList.getElementExpr(elementIndex, position))
652652
} or
653653
// The value initialization of a range of array elements that were omitted
654654
// from an initializer list.

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedInitialization.qll

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class TranslatedClassListInitialization extends TranslatedListInitialization {
206206
fieldInit = getTranslatedFieldInitialization(expr, _) and
207207
fieldInit.getOrder() = ord
208208
|
209-
fieldInit order by ord, fieldInit.getRepetitionIndex()
209+
fieldInit order by ord, fieldInit.getPosition()
210210
)
211211
}
212212
}
@@ -224,7 +224,7 @@ class TranslatedArrayListInitialization extends TranslatedListInitialization {
224224
rank[id + 1](TranslatedElementInitialization init |
225225
init.getInitList() = expr
226226
|
227-
init order by init.getElementIndex(), init.getRepetitionIndex()
227+
init order by init.getElementIndex(), init.getPosition()
228228
)
229229
}
230230
}
@@ -525,11 +525,8 @@ abstract class TranslatedFieldInitialization extends TranslatedElement {
525525

526526
final Field getField() { result = field }
527527

528-
/**
529-
* Gets the index of this initialization, if the field is mentioned
530-
* multiple times in the initializer.
531-
*/
532-
int getRepetitionIndex() { result = 0 }
528+
/** Gets the position in the initializer list, or `-1` if the initialization is implicit. */
529+
int getPosition() { result = -1 }
533530
}
534531

535532
/**
@@ -540,10 +537,10 @@ class TranslatedExplicitFieldInitialization extends TranslatedFieldInitializatio
540537
InitializationContext, TTranslatedExplicitFieldInitialization
541538
{
542539
Expr expr;
543-
int repitition;
540+
int position;
544541

545542
TranslatedExplicitFieldInitialization() {
546-
this = TTranslatedExplicitFieldInitialization(ast, field, expr, repitition)
543+
this = TTranslatedExplicitFieldInitialization(ast, field, expr, position)
547544
}
548545

549546
override Instruction getTargetAddress() { result = getInstruction(getFieldAddressTag()) }
@@ -566,7 +563,7 @@ class TranslatedExplicitFieldInitialization extends TranslatedFieldInitializatio
566563
result = getTranslatedInitialization(expr)
567564
}
568565

569-
override int getRepetitionIndex() { result = repitition }
566+
override int getPosition() { result = position }
570567
}
571568

572569
private string getZeroValue(Type type) {
@@ -700,7 +697,7 @@ abstract class TranslatedElementInitialization extends TranslatedElement {
700697

701698
abstract int getElementIndex();
702699

703-
int getRepetitionIndex() { result = 0 }
700+
int getPosition() { result = -1 }
704701

705702
final InstructionTag getElementAddressTag() { result = InitializerElementAddressTag() }
706703

@@ -719,10 +716,10 @@ class TranslatedExplicitElementInitialization extends TranslatedElementInitializ
719716
TTranslatedExplicitElementInitialization, InitializationContext
720717
{
721718
int elementIndex;
722-
int repetition;
719+
int position;
723720

724721
TranslatedExplicitElementInitialization() {
725-
this = TTranslatedExplicitElementInitialization(initList, elementIndex, repetition)
722+
this = TTranslatedExplicitElementInitialization(initList, elementIndex, position)
726723
}
727724

728725
override Instruction getTargetAddress() { result = getInstruction(getElementAddressTag()) }
@@ -745,12 +742,12 @@ class TranslatedExplicitElementInitialization extends TranslatedElementInitializ
745742

746743
override int getElementIndex() { result = elementIndex }
747744

748-
override int getRepetitionIndex() { result = repetition }
745+
override int getPosition() { result = position }
749746

750747
TranslatedInitialization getInitialization() {
751748
result =
752749
getTranslatedInitialization(initList
753-
.getElementExpr(elementIndex, repetition)
750+
.getElementExpr(elementIndex, position)
754751
.getFullyConverted())
755752
}
756753
}

0 commit comments

Comments
 (0)