Expand PromotedField to PromotedValueEntity

This includes promoted methods as well
This commit is contained in:
Owen Mansel-Chan
2021-03-26 10:47:38 +00:00
parent 770c770a8f
commit a89a42df6f
2 changed files with 20 additions and 7 deletions

View File

@@ -594,14 +594,18 @@ class SelectorExpr extends @selectorexpr, Expr {
}
/**
* A selector expression that refers to a promoted field. These selectors may implicitly
* address an embedded struct of their base type - for example, the selector `x.field` may
* implicitly address `x.Embedded.field`). Note they may also explicitly address `field`;
* being a `PromotedFieldSelector` only indicates the addressed field may be promoted, not
* that it is promoted in this particular context.
* A selector expression that refers to a promoted field or a promoted method. These
* selectors may implicitly address an embedded struct of their base type - for example,
* the selector `x.field` may implicitly address `x.Embedded.field`). Note they may also
* explicitly address `field`; being a `PromotedSelector` only indicates the addressed
* field or method may be promoted, not that it is promoted in this particular context.
*/
class PromotedFieldSelector extends SelectorExpr {
PromotedFieldSelector() { this.refersTo(any(PromotedField f)) }
class PromotedSelector extends SelectorExpr {
PromotedSelector() {
exists(ValueEntity ve | this.refersTo(ve) |
ve instanceof PromotedField or ve instanceof PromotedMethod
)
}
/**
* Gets the underlying struct type of this selector's base. Note because this selector

View File

@@ -539,6 +539,15 @@ class Method extends Function {
}
}
/**
* A method whose receiver may be embedded within a struct.
*
* When a selector addresses such a method, it is possible it is implicitly addressing a nested struct.
*/
class PromotedMethod extends Method {
PromotedMethod() { this = any(StructType t).getMethodOfEmbedded(_, _, _) }
}
/** A declared function. */
class DeclaredFunction extends Function, DeclaredEntity, @declfunctionobject {
override FuncDecl getFuncDecl() { result.getNameExpr() = this.getDeclaration() }