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, 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, 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 CallExpression method typeChanged.
@Override
public void typeChanged(HasType src, HasType root, Type oldType) {
if (!TypeManager.isTypeSystemActive()) {
return;
}
if (src == base) {
setFqn(src.getType().getRoot().getTypeName() + "." + this.getName());
} else {
Type previous = this.type;
List<Type> types = invokes.stream().map(PropertyEdge::getEnd).map(FunctionDeclaration::getType).filter(Objects::nonNull).collect(Collectors.toList());
Type alternative = !types.isEmpty() ? types.get(0) : null;
Type commonType = TypeManager.getInstance().getCommonType(types).orElse(alternative);
Set<Type> subTypes = new HashSet<>(getPossibleSubTypes());
subTypes.remove(oldType);
subTypes.addAll(types);
setType(commonType, 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 InitializerListExpression method typeChanged.
@Override
public void typeChanged(HasType src, 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;
Set<Type> subTypes;
if (this.getInitializers().contains(src)) {
Set<Type> types = this.initializers.parallelStream().map(PropertyEdge::getEnd).map(Expression::getType).filter(Objects::nonNull).map(t -> TypeManager.getInstance().registerType(t.reference(PointerOrigin.ARRAY))).collect(Collectors.toSet());
Type alternative = !types.isEmpty() ? types.iterator().next() : UnknownType.getUnknownType();
newType = TypeManager.getInstance().getCommonType(types).orElse(alternative);
subTypes = new HashSet<>(getPossibleSubTypes());
subTypes.remove(oldType);
subTypes.addAll(types);
} else {
newType = src.getType();
subTypes = new HashSet<>(getPossibleSubTypes());
subTypes.remove(oldType);
subTypes.add(newType);
}
setType(newType, 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 VariableDeclaration method typeChanged.
@Override
public void typeChanged(HasType src, 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 CallExpression method typeChanged.
@Override
public void typeChanged(HasType src, Collection<HasType> root, Type oldType) {
if (!TypeManager.isTypeSystemActive()) {
return;
}
if (src == base) {
setFqn(src.getType().getRoot().getTypeName() + "." + this.getName());
} else {
Type previous = this.type;
List<Type> types = invokes.stream().map(PropertyEdge::getEnd).map(FunctionDeclaration::getType).filter(Objects::nonNull).collect(Collectors.toList());
Type alternative = !types.isEmpty() ? types.get(0) : null;
Type commonType = TypeManager.getInstance().getCommonType(types).orElse(alternative);
Set<Type> subTypes = new HashSet<>(getPossibleSubTypes());
subTypes.remove(oldType);
subTypes.addAll(types);
setType(commonType, root);
setPossibleSubTypes(subTypes, root);
if (!previous.equals(this.type)) {
this.type.setTypeOrigin(Type.Origin.DATAFLOW);
}
}
}
Aggregations