C#: Introduce type for Synthetic fields.

This commit is contained in:
Michael Nebel
2021-12-08 12:01:48 +01:00
parent b49ca6a24c
commit 60f3ff8c33
3 changed files with 21 additions and 1 deletions

View File

@@ -759,7 +759,8 @@ private module Cached {
newtype TContent =
TFieldContent(Field f) { f.isUnboundDeclaration() } or
TPropertyContent(Property p) { p.isUnboundDeclaration() } or
TElementContent()
TElementContent() or
TSyntheticFieldContent(SyntheticField f)
pragma[nomagic]
private predicate commonSubTypeGeneral(DataFlowTypeOrUnifiable t1, RelevantDataFlowType t2) {
@@ -2038,3 +2039,10 @@ predicate additionalLambdaFlowStep(Node nodeFrom, Node nodeTo, boolean preserves
predicate allowParameterReturnInSelf(ParameterNode p) {
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(p)
}
abstract class SyntheticField extends string {
bindingset[this]
SyntheticField() { any() }
Type getType() { result instanceof ObjectType }
}

View File

@@ -224,6 +224,16 @@ class FieldContent extends Content, TFieldContent {
deprecated override Gvn::GvnType getType() { result = Gvn::getGlobalValueNumber(f.getType()) }
}
class SyntheticFieldContent extends Content, TSyntheticFieldContent {
private SyntheticField f;
SyntheticFieldContent() { this = TSyntheticFieldContent(f) }
SyntheticField getField() { result = f }
override string toString() { result = "synthetic " + f.toString() }
}
/** A reference to a property. */
class PropertyContent extends Content, TPropertyContent {
private Property p;

View File

@@ -29,6 +29,8 @@ DataFlowType getContentType(Content c) {
or
t = c.(PropertyContent).getProperty().getType()
or
t = c.(SyntheticFieldContent).getField().getType()
or
c instanceof ElementContent and
t instanceof ObjectType // we don't know what the actual element type is
)