use of de.fraunhofer.aisec.cpg.graph.HasType in project cpg by Fraunhofer-AISEC.
the class VariableDeclaration 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);
}
}
use of de.fraunhofer.aisec.cpg.graph.HasType in project cpg by Fraunhofer-AISEC.
the class ArraySubscriptionExpression method typeChanged.
@Override
public void typeChanged(HasType src, Collection<HasType> root, Type oldType) {
if (!TypeManager.isTypeSystemActive()) {
return;
}
Type previous = this.type;
setType(getSubscriptType(src.getPropagationType()), 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 UnaryOperator method typeChanged.
@Override
public void typeChanged(HasType src, Collection<HasType> root, Type oldType) {
if (!TypeManager.isTypeSystemActive()) {
return;
}
Type previous = this.type;
if (src == input) {
Type newType = src.getPropagationType();
if (operatorCode.equals("*")) {
newType = newType.dereference();
} else if (operatorCode.equals("&")) {
newType = newType.reference(PointerType.PointerOrigin.POINTER);
}
setType(newType, root);
} else {
// Our input didn't change, so we don't need to (de)reference the type
setType(src.getPropagationType(), root);
// Pass the type on to the input in an inversely (de)referenced way
Type newType = src.getPropagationType();
if (operatorCode.equals("*")) {
newType = src.getPropagationType().reference(PointerType.PointerOrigin.POINTER);
} else if (operatorCode.equals("&")) {
newType = src.getPropagationType().dereference();
}
// not null
if (input != null) {
input.setType(newType, new ArrayList<>(List.of(this)));
}
}
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 ValueDeclaration method setType.
@Override
public void setType(Type type, HasType root) {
if (!TypeManager.isTypeSystemActive()) {
TypeManager.getInstance().cacheType(this, type);
return;
}
if (type == null || root == this) {
return;
}
if (this.type instanceof FunctionPointerType && !(type instanceof FunctionPointerType)) {
return;
}
Type oldType = this.type;
if (TypeManager.getInstance().isUnknown(type)) {
return;
}
type = type.duplicate();
type.setQualifier(this.type.getQualifier().merge(type.getQualifier()));
Set<Type> subTypes = new HashSet<>();
for (Type t : getPossibleSubTypes()) {
if (!t.isSimilar(type)) {
subTypes.add(t);
}
}
subTypes.add(type);
this.type = TypeManager.getInstance().registerType(TypeManager.getInstance().getCommonType(subTypes).orElse(type));
subTypes = subTypes.stream().filter(s -> TypeManager.getInstance().isSupertypeOf(this.type, s)).collect(Collectors.toSet());
subTypes = subTypes.stream().map(s -> TypeManager.getInstance().registerType(s)).collect(Collectors.toSet());
setPossibleSubTypes(subTypes);
if (!Objects.equals(oldType, type)) {
this.typeListeners.stream().filter(l -> !l.equals(this)).forEach(l -> l.typeChanged(this, root == null ? this : root, oldType));
}
}
use of de.fraunhofer.aisec.cpg.graph.HasType in project cpg by Fraunhofer-AISEC.
the class ArrayCreationExpression method typeChanged.
@Override
public void typeChanged(HasType src, HasType root, Type oldType) {
if (!TypeManager.isTypeSystemActive()) {
return;
}
Type previous = this.type;
setType(src.getPropagationType(), root);
if (!previous.equals(this.type)) {
this.type.setTypeOrigin(Type.Origin.DATAFLOW);
}
}
Aggregations