Merge pull request #4731 from criemen/remove-cpp-abstract

C++: Remove uses of abstract from the standard library.
This commit is contained in:
Jonas Jensen
2020-11-27 09:53:24 +01:00
committed by GitHub
9 changed files with 70 additions and 40 deletions

View File

@@ -977,7 +977,12 @@ class ClassTemplateInstantiation extends Class {
* specialization - see `FullClassTemplateSpecialization` and
* `PartialClassTemplateSpecialization`).
*/
abstract class ClassTemplateSpecialization extends Class {
class ClassTemplateSpecialization extends Class {
ClassTemplateSpecialization() {
isFullClassTemplateSpecialization(this) or
isPartialClassTemplateSpecialization(this)
}
/**
* Gets the primary template for the specialization, for example on
* `S<T,int>`, the result is `S<T,U>`.
@@ -997,6 +1002,16 @@ abstract class ClassTemplateSpecialization extends Class {
override string getAPrimaryQlClass() { result = "ClassTemplateSpecialization" }
}
private predicate isFullClassTemplateSpecialization(Class c) {
// This class has template arguments, but none of them involves a template parameter.
exists(c.getATemplateArgument()) and
not exists(Type ta | ta = c.getATemplateArgument() and ta.involvesTemplateParameter()) and
// This class does not have any instantiations.
not exists(c.(TemplateClass).getAnInstantiation()) and
// This class is not an instantiation of a class template.
not c instanceof ClassTemplateInstantiation
}
/**
* A full specialization of a class template. For example `MyTemplateClass<int>`
* in the following code is a `FullClassTemplateSpecialization`:
@@ -1013,19 +1028,31 @@ abstract class ClassTemplateSpecialization extends Class {
* ```
*/
class FullClassTemplateSpecialization extends ClassTemplateSpecialization {
FullClassTemplateSpecialization() {
// This class has template arguments, but none of them involves a template parameter.
exists(getATemplateArgument()) and
not exists(Type ta | ta = getATemplateArgument() and ta.involvesTemplateParameter()) and
// This class does not have any instantiations.
not exists(this.(TemplateClass).getAnInstantiation()) and
// This class is not an instantiation of a class template.
not this instanceof ClassTemplateInstantiation
}
FullClassTemplateSpecialization() { isFullClassTemplateSpecialization(this) }
override string getAPrimaryQlClass() { result = "FullClassTemplateSpecialization" }
}
private predicate isPartialClassTemplateSpecialization(Class c) {
/*
* (a) At least one of this class's template arguments involves a
* template parameter in some respect, for example T, T*, etc.
*
* (b) It is not the case that the n template arguments of this class
* are a set of n distinct template parameters.
*
* template <typename T,U> class X {}; // class template
* template <typename T> class X<T,T> {}; // partial class template specialization
* template <typename T> class X<T,int> {}; // partial class template specialization
* template <typename T> class Y {}; // class template
* template <typename T> class Y<T*> {}; // partial class template specialization
*/
exists(Type ta | ta = c.getATemplateArgument() and ta.involvesTemplateParameter()) and
count(TemplateParameter tp | tp = c.getATemplateArgument()) !=
count(int i | exists(c.getTemplateArgument(i)))
}
/**
* A partial specialization of a class template. For example `MyTemplateClass<int, T>`
* in the following code is a `PartialClassTemplateSpecialization`:
@@ -1042,25 +1069,7 @@ class FullClassTemplateSpecialization extends ClassTemplateSpecialization {
* ```
*/
class PartialClassTemplateSpecialization extends ClassTemplateSpecialization {
PartialClassTemplateSpecialization() {
/*
* (a) At least one of this class's template arguments involves a
* template parameter in some respect, for example T, T*, etc.
*
* (b) It is not the case that the n template arguments of this class
* are a set of n distinct template parameters.
*
* template <typename T,U> class X {}; // class template
* template <typename T> class X<T,T> {}; // partial class template specialization
* template <typename T> class X<T,int> {}; // partial class template specialization
* template <typename T> class Y {}; // class template
* template <typename T> class Y<T*> {}; // partial class template specialization
*/
exists(Type ta | ta = getATemplateArgument() and ta.involvesTemplateParameter()) and
count(TemplateParameter tp | tp = getATemplateArgument()) !=
count(int i | exists(getTemplateArgument(i)))
}
PartialClassTemplateSpecialization() { isPartialClassTemplateSpecialization(this) }
override string getAPrimaryQlClass() { result = "PartialClassTemplateSpecialization" }
}

View File

@@ -205,12 +205,21 @@ class Constructor extends MemberFunction {
/**
* A function that defines an implicit conversion.
*/
abstract class ImplicitConversionFunction extends MemberFunction {
class ImplicitConversionFunction extends MemberFunction {
ImplicitConversionFunction() {
// ConversionOperator
functions(underlyingElement(this), _, 4)
or
// ConversionConstructor (deprecated)
strictcount(Parameter p | p = getAParameter() and not p.hasInitializer()) = 1 and
not hasSpecifier("explicit")
}
/** Gets the type this `ImplicitConversionFunction` takes as input. */
abstract Type getSourceType();
Type getSourceType() { none() } // overridden in subclasses
/** Gets the type this `ImplicitConversionFunction` converts to. */
abstract Type getDestType();
Type getDestType() { none() } // overridden in subclasses
}
/**

View File

@@ -60,7 +60,7 @@ private string getTemplateArgumentString(Declaration d, int i) {
/**
* A `Declaration` extended to add methods for generating strings useful only for dumps and debugging.
*/
abstract private class DumpDeclaration extends Declaration {
private class DumpDeclaration extends Declaration {
DumpDeclaration() { shouldPrintDeclaration(this) }
/**

View File

@@ -577,7 +577,9 @@ class BoolType extends IntegralType {
* unsigned char e, f;
* ```
*/
abstract class CharType extends IntegralType { }
class CharType extends IntegralType {
CharType() { builtintypes(underlyingElement(this), _, [5, 6, 7], _, _, _) }
}
/**
* The C/C++ `char` type (which is distinct from `signed char` and

View File

@@ -64,7 +64,7 @@ class RelationalOperation extends ComparisonOperation, @rel_op_expr {
* if the overall expression evaluates to `true`; for example on
* `x <= 20` this is the `20`, and on `y > 0` it is `y`.
*/
abstract Expr getGreaterOperand();
Expr getGreaterOperand() { none() } // overridden in subclasses
/**
* Gets the operand on the "lesser" (or "lesser-or-equal") side
@@ -72,7 +72,7 @@ class RelationalOperation extends ComparisonOperation, @rel_op_expr {
* if the overall expression evaluates to `true`; for example on
* `x <= 20` this is `x`, and on `y > 0` it is the `0`.
*/
abstract Expr getLesserOperand();
Expr getLesserOperand() { none() } // overridden in subclasses
}
/**

View File

@@ -838,7 +838,7 @@ class NewOrNewArrayExpr extends Expr, @any_new_expr {
* For example, for `new int` the result is `int`.
* For `new int[5]` the result is `int[5]`.
*/
abstract Type getAllocatedType();
Type getAllocatedType() { none() } // overridden in subclasses
/**
* Gets the pointer `p` if this expression is of the form `new(p) T...`.

View File

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

View File

@@ -39,7 +39,7 @@ class BinaryLogicalOperation extends BinaryOperation, @bin_log_op_expr {
* is true, `x` and `y` must also be true, so `impliesValue(x, true, true)` and
* `impliesValue(y, true, true)` hold.
*/
abstract predicate impliesValue(Expr part, boolean partIsTrue, boolean wholeIsTrue);
predicate impliesValue(Expr part, boolean partIsTrue, boolean wholeIsTrue) { none() } // overridden in subclasses
}
/**

View File

@@ -59,7 +59,7 @@ class Namespace extends @namespace {
}
}
abstract class Declaration extends @declaration {
class Declaration extends @declaration {
string toString() { result = "QualifiedName Declaration" }
/** Gets the name of this declaration. */