use of de.fraunhofer.aisec.cpg.graph.HasType in project cpg by Fraunhofer-AISEC.
the class ConditionalExpression method typeChanged.
@Override
public void typeChanged(HasType src, Collection<HasType> root, Type oldType) {
if (!TypeManager.isTypeSystemActive()) {
return;
}
Type previous = this.type;
List<Type> types = new ArrayList<>();
if (thenExpr != null && thenExpr.getPropagationType() != null) {
types.add(thenExpr.getPropagationType());
}
if (elseExpr != null && elseExpr.getPropagationType() != null) {
types.add(elseExpr.getPropagationType());
}
Set<Type> subTypes = new HashSet<>(getPossibleSubTypes());
subTypes.remove(oldType);
subTypes.addAll(types);
Type alternative = !types.isEmpty() ? types.get(0) : UnknownType.getUnknownType();
setType(TypeManager.getInstance().getCommonType(types).orElse(alternative), root);
setPossibleSubTypes(subTypes, root);
if (!previous.equals(this.type)) {
this.type.setTypeOrigin(Type.Origin.DATAFLOW);
}
}
use of de.fraunhofer.aisec.cpg.graph.HasType in project cpg by Fraunhofer-AISEC.
the class ExpressionList method addExpression.
public void addExpression(Statement expression) {
if (!this.expressions.isEmpty()) {
Statement lastExpression = this.expressions.get(this.expressions.size() - 1).getEnd();
if (lastExpression instanceof HasType)
((HasType) lastExpression).unregisterTypeListener(this);
this.removePrevDFG(lastExpression);
}
PropertyEdge<Statement> propertyEdge = new PropertyEdge<>(this, expression);
propertyEdge.addProperty(Properties.INDEX, this.expressions.size());
this.expressions.add(propertyEdge);
this.addPrevDFG(expression);
if (expression instanceof HasType) {
((HasType) expression).registerTypeListener(this);
}
}
use of de.fraunhofer.aisec.cpg.graph.HasType in project cpg by Fraunhofer-AISEC.
the class ExpressionList method typeChanged.
@Override
public void typeChanged(HasType src, Collection<HasType> root, Type oldType) {
if (!TypeManager.isTypeSystemActive()) {
return;
}
Type previous = this.type;
setType(src.getPropagationType(), root);
setPossibleSubTypes(new HashSet<>(src.getPossibleSubTypes()), root);
if (!previous.equals(this.type)) {
this.type.setTypeOrigin(Type.Origin.DATAFLOW);
}
}
use of de.fraunhofer.aisec.cpg.graph.HasType in project cpg by Fraunhofer-AISEC.
the class ExpressionList method setExpressions.
public void setExpressions(List<Statement> expressions) {
if (!this.expressions.isEmpty()) {
Statement lastExpression = this.expressions.get(this.expressions.size() - 1).getEnd();
if (lastExpression instanceof HasType)
((HasType) lastExpression).unregisterTypeListener(this);
this.removePrevDFG(lastExpression);
}
this.expressions = PropertyEdge.transformIntoOutgoingPropertyEdgeList(expressions, this);
if (!this.expressions.isEmpty()) {
Statement lastExpression = this.expressions.get(this.expressions.size() - 1).getEnd();
this.addPrevDFG(lastExpression);
if (lastExpression instanceof HasType)
((HasType) lastExpression).registerTypeListener(this);
}
}
use of de.fraunhofer.aisec.cpg.graph.HasType in project cpg by Fraunhofer-AISEC.
the class FieldDeclaration method typeChanged.
@Override
public void typeChanged(HasType src, Collection<HasType> root, Type oldType) {
if (!TypeManager.isTypeSystemActive()) {
return;
}
if (!TypeManager.getInstance().isUnknown(this.type) && src.getPropagationType().equals(oldType)) {
return;
}
Type previous = this.type;
Type newType;
if (src == initializer && initializer instanceof InitializerListExpression) {
// can be ignored once we have a type
if (isArray) {
newType = src.getType();
} else if (!TypeManager.getInstance().isUnknown(this.type)) {
return;
} else {
newType = src.getType().dereference();
}
} else {
newType = src.getPropagationType();
}
setType(newType, root);
if (!previous.equals(this.type)) {
this.type.setTypeOrigin(Type.Origin.DATAFLOW);
}
}
Aggregations