Skip to content

Commit edb57c2

Browse files
authored
Merge pull request github#4731 from criemen/remove-cpp-abstract
C++: Remove uses of abstract from the standard library.
2 parents bc08e47 + f6c3c2b commit edb57c2

File tree

9 files changed

+70
-40
lines changed

9 files changed

+70
-40
lines changed

cpp/ql/src/semmle/code/cpp/Class.qll

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,12 @@ class ClassTemplateInstantiation extends Class {
977977
* specialization - see `FullClassTemplateSpecialization` and
978978
* `PartialClassTemplateSpecialization`).
979979
*/
980-
abstract class ClassTemplateSpecialization extends Class {
980+
class ClassTemplateSpecialization extends Class {
981+
ClassTemplateSpecialization() {
982+
isFullClassTemplateSpecialization(this) or
983+
isPartialClassTemplateSpecialization(this)
984+
}
985+
981986
/**
982987
* Gets the primary template for the specialization, for example on
983988
* `S<T,int>`, the result is `S<T,U>`.
@@ -997,6 +1002,16 @@ abstract class ClassTemplateSpecialization extends Class {
9971002
override string getAPrimaryQlClass() { result = "ClassTemplateSpecialization" }
9981003
}
9991004

1005+
private predicate isFullClassTemplateSpecialization(Class c) {
1006+
// This class has template arguments, but none of them involves a template parameter.
1007+
exists(c.getATemplateArgument()) and
1008+
not exists(Type ta | ta = c.getATemplateArgument() and ta.involvesTemplateParameter()) and
1009+
// This class does not have any instantiations.
1010+
not exists(c.(TemplateClass).getAnInstantiation()) and
1011+
// This class is not an instantiation of a class template.
1012+
not c instanceof ClassTemplateInstantiation
1013+
}
1014+
10001015
/**
10011016
* A full specialization of a class template. For example `MyTemplateClass<int>`
10021017
* in the following code is a `FullClassTemplateSpecialization`:
@@ -1013,19 +1028,31 @@ abstract class ClassTemplateSpecialization extends Class {
10131028
* ```
10141029
*/
10151030
class FullClassTemplateSpecialization extends ClassTemplateSpecialization {
1016-
FullClassTemplateSpecialization() {
1017-
// This class has template arguments, but none of them involves a template parameter.
1018-
exists(getATemplateArgument()) and
1019-
not exists(Type ta | ta = getATemplateArgument() and ta.involvesTemplateParameter()) and
1020-
// This class does not have any instantiations.
1021-
not exists(this.(TemplateClass).getAnInstantiation()) and
1022-
// This class is not an instantiation of a class template.
1023-
not this instanceof ClassTemplateInstantiation
1024-
}
1031+
FullClassTemplateSpecialization() { isFullClassTemplateSpecialization(this) }
10251032

10261033
override string getAPrimaryQlClass() { result = "FullClassTemplateSpecialization" }
10271034
}
10281035

1036+
private predicate isPartialClassTemplateSpecialization(Class c) {
1037+
/*
1038+
* (a) At least one of this class's template arguments involves a
1039+
* template parameter in some respect, for example T, T*, etc.
1040+
*
1041+
* (b) It is not the case that the n template arguments of this class
1042+
* are a set of n distinct template parameters.
1043+
*
1044+
* template <typename T,U> class X {}; // class template
1045+
* template <typename T> class X<T,T> {}; // partial class template specialization
1046+
* template <typename T> class X<T,int> {}; // partial class template specialization
1047+
* template <typename T> class Y {}; // class template
1048+
* template <typename T> class Y<T*> {}; // partial class template specialization
1049+
*/
1050+
1051+
exists(Type ta | ta = c.getATemplateArgument() and ta.involvesTemplateParameter()) and
1052+
count(TemplateParameter tp | tp = c.getATemplateArgument()) !=
1053+
count(int i | exists(c.getTemplateArgument(i)))
1054+
}
1055+
10291056
/**
10301057
* A partial specialization of a class template. For example `MyTemplateClass<int, T>`
10311058
* in the following code is a `PartialClassTemplateSpecialization`:
@@ -1042,25 +1069,7 @@ class FullClassTemplateSpecialization extends ClassTemplateSpecialization {
10421069
* ```
10431070
*/
10441071
class PartialClassTemplateSpecialization extends ClassTemplateSpecialization {
1045-
PartialClassTemplateSpecialization() {
1046-
/*
1047-
* (a) At least one of this class's template arguments involves a
1048-
* template parameter in some respect, for example T, T*, etc.
1049-
*
1050-
* (b) It is not the case that the n template arguments of this class
1051-
* are a set of n distinct template parameters.
1052-
*
1053-
* template <typename T,U> class X {}; // class template
1054-
* template <typename T> class X<T,T> {}; // partial class template specialization
1055-
* template <typename T> class X<T,int> {}; // partial class template specialization
1056-
* template <typename T> class Y {}; // class template
1057-
* template <typename T> class Y<T*> {}; // partial class template specialization
1058-
*/
1059-
1060-
exists(Type ta | ta = getATemplateArgument() and ta.involvesTemplateParameter()) and
1061-
count(TemplateParameter tp | tp = getATemplateArgument()) !=
1062-
count(int i | exists(getTemplateArgument(i)))
1063-
}
1072+
PartialClassTemplateSpecialization() { isPartialClassTemplateSpecialization(this) }
10641073

10651074
override string getAPrimaryQlClass() { result = "PartialClassTemplateSpecialization" }
10661075
}

cpp/ql/src/semmle/code/cpp/MemberFunction.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,21 @@ class Constructor extends MemberFunction {
205205
/**
206206
* A function that defines an implicit conversion.
207207
*/
208-
abstract class ImplicitConversionFunction extends MemberFunction {
208+
class ImplicitConversionFunction extends MemberFunction {
209+
ImplicitConversionFunction() {
210+
// ConversionOperator
211+
functions(underlyingElement(this), _, 4)
212+
or
213+
// ConversionConstructor (deprecated)
214+
strictcount(Parameter p | p = getAParameter() and not p.hasInitializer()) = 1 and
215+
not hasSpecifier("explicit")
216+
}
217+
209218
/** Gets the type this `ImplicitConversionFunction` takes as input. */
210-
abstract Type getSourceType();
219+
Type getSourceType() { none() } // overridden in subclasses
211220

212221
/** Gets the type this `ImplicitConversionFunction` converts to. */
213-
abstract Type getDestType();
222+
Type getDestType() { none() } // overridden in subclasses
214223
}
215224

216225
/**

cpp/ql/src/semmle/code/cpp/Print.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private string getTemplateArgumentString(Declaration d, int i) {
6060
/**
6161
* A `Declaration` extended to add methods for generating strings useful only for dumps and debugging.
6262
*/
63-
abstract private class DumpDeclaration extends Declaration {
63+
private class DumpDeclaration extends Declaration {
6464
DumpDeclaration() { shouldPrintDeclaration(this) }
6565

6666
/**

cpp/ql/src/semmle/code/cpp/Type.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,9 @@ class BoolType extends IntegralType {
577577
* unsigned char e, f;
578578
* ```
579579
*/
580-
abstract class CharType extends IntegralType { }
580+
class CharType extends IntegralType {
581+
CharType() { builtintypes(underlyingElement(this), _, [5, 6, 7], _, _, _) }
582+
}
581583

582584
/**
583585
* The C/C++ `char` type (which is distinct from `signed char` and

cpp/ql/src/semmle/code/cpp/exprs/ComparisonOperation.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ class RelationalOperation extends ComparisonOperation, @rel_op_expr {
6464
* if the overall expression evaluates to `true`; for example on
6565
* `x <= 20` this is the `20`, and on `y > 0` it is `y`.
6666
*/
67-
abstract Expr getGreaterOperand();
67+
Expr getGreaterOperand() { none() } // overridden in subclasses
6868

6969
/**
7070
* Gets the operand on the "lesser" (or "lesser-or-equal") side
7171
* of this relational expression, that is, the side that is smaller
7272
* if the overall expression evaluates to `true`; for example on
7373
* `x <= 20` this is `x`, and on `y > 0` it is the `0`.
7474
*/
75-
abstract Expr getLesserOperand();
75+
Expr getLesserOperand() { none() } // overridden in subclasses
7676
}
7777

7878
/**

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ class NewOrNewArrayExpr extends Expr, @any_new_expr {
838838
* For example, for `new int` the result is `int`.
839839
* For `new int[5]` the result is `int[5]`.
840840
*/
841-
abstract Type getAllocatedType();
841+
Type getAllocatedType() { none() } // overridden in subclasses
842842

843843
/**
844844
* Gets the pointer `p` if this expression is of the form `new(p) T...`.

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ class LabelLiteral extends Literal {
4747
}
4848

4949
/** A character literal or a string literal. */
50-
abstract class TextLiteral extends Literal {
50+
class TextLiteral extends Literal {
51+
TextLiteral() {
52+
// String Literal
53+
// Note that `AggregateLiteral`s can also have an array type, but they derive from
54+
// @aggregateliteral rather than @literal.
55+
this.getType() instanceof ArrayType
56+
or
57+
// Char literal
58+
this.getValueText().regexpMatch("(?s)\\s*L?'.*")
59+
}
60+
5161
/** Gets a hex escape sequence that appears in the character or string literal (see [lex.ccon] in the C++ Standard). */
5262
string getAHexEscapeSequence(int occurrence, int offset) {
5363
result = getValueText().regexpFind("(?<!\\\\)\\\\x[0-9a-fA-F]+", occurrence, offset)

cpp/ql/src/semmle/code/cpp/exprs/LogicalOperation.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BinaryLogicalOperation extends BinaryOperation, @bin_log_op_expr {
3939
* is true, `x` and `y` must also be true, so `impliesValue(x, true, true)` and
4040
* `impliesValue(y, true, true)` hold.
4141
*/
42-
abstract predicate impliesValue(Expr part, boolean partIsTrue, boolean wholeIsTrue);
42+
predicate impliesValue(Expr part, boolean partIsTrue, boolean wholeIsTrue) { none() } // overridden in subclasses
4343
}
4444

4545
/**

cpp/ql/src/semmle/code/cpp/internal/QualifiedName.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Namespace extends @namespace {
5959
}
6060
}
6161

62-
abstract class Declaration extends @declaration {
62+
class Declaration extends @declaration {
6363
string toString() { result = "QualifiedName Declaration" }
6464

6565
/** Gets the name of this declaration. */

0 commit comments

Comments
 (0)