Skip to content

Commit a5601ce

Browse files
committed
C++: Lift 'getTypeOperand' to the superclass.
1 parent f4a6ba9 commit a5601ce

File tree

1 file changed

+26
-4
lines changed
  • cpp/ql/lib/semmle/code/cpp/exprs

1 file changed

+26
-4
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,16 @@ class SizeofPackTypeOperator extends SizeofPackOperator {
750750
*/
751751
class SizeofOperator extends Expr, @runtime_sizeof {
752752
override int getPrecedence() { result = 16 }
753+
754+
/**
755+
* Gets the contained type of this `sizeof`. For example,
756+
* the result is `int` in both cases below:
757+
* ```
758+
* sizeof(int);
759+
* sizeof(42);
760+
* ```
761+
*/
762+
Type getTypeOperand() { none() } // overridden in subclasses
753763
}
754764

755765
/**
@@ -766,6 +776,8 @@ class SizeofExprOperator extends SizeofOperator {
766776
/** Gets the contained expression. */
767777
Expr getExprOperand() { result = this.getChild(0) }
768778

779+
override Type getTypeOperand() { result = this.getExprOperand().getType() }
780+
769781
override string toString() { result = "sizeof(<expr>)" }
770782

771783
override predicate mayBeImpure() { this.getExprOperand().mayBeImpure() }
@@ -784,8 +796,7 @@ class SizeofTypeOperator extends SizeofOperator {
784796

785797
override string getAPrimaryQlClass() { result = "SizeofTypeOperator" }
786798

787-
/** Gets the contained type. */
788-
Type getTypeOperand() { sizeof_bind(underlyingElement(this), unresolveElement(result)) }
799+
override Type getTypeOperand() { sizeof_bind(underlyingElement(this), unresolveElement(result)) }
789800

790801
override string toString() { result = "sizeof(" + this.getTypeOperand().getName() + ")" }
791802

@@ -842,6 +853,16 @@ class AlignofTypeOperator extends AlignofOperator {
842853
*/
843854
class DatasizeofOperator extends Expr, @datasizeof {
844855
override int getPrecedence() { result = 16 }
856+
857+
/**
858+
* Gets the contained type of this `__datasizeof`. For example,
859+
* the result is `int` in both cases below:
860+
* ```
861+
* __datasizeof(int);
862+
* __datasizeof(42);
863+
* ```
864+
*/
865+
Type getTypeOperand() { none() }
845866
}
846867

847868
/**
@@ -855,6 +876,8 @@ class DatasizeofExprOperator extends DatasizeofOperator {
855876
/** Gets the contained expression. */
856877
Expr getExprOperand() { result = this.getChild(0) }
857878

879+
override Type getTypeOperand() { result = this.getExprOperand().getType() }
880+
858881
override string toString() { result = "__datasizeof(<expr>)" }
859882

860883
override predicate mayBeImpure() { this.getExprOperand().mayBeImpure() }
@@ -870,8 +893,7 @@ class DatasizeofTypeOperator extends DatasizeofOperator {
870893

871894
override string getAPrimaryQlClass() { result = "DatasizeofTypeOperator" }
872895

873-
/** Gets the contained type. */
874-
Type getTypeOperand() { sizeof_bind(underlyingElement(this), unresolveElement(result)) }
896+
override Type getTypeOperand() { sizeof_bind(underlyingElement(this), unresolveElement(result)) }
875897

876898
override string toString() { result = "__datasizeof(" + this.getTypeOperand().getName() + ")" }
877899

0 commit comments

Comments
 (0)