Skip to content

Commit

Permalink
Merge branch 'main' into dfg-fix-foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
KuechA authored Feb 9, 2023
2 parents 7220030 + 0bb383a commit b72e1a2
Show file tree
Hide file tree
Showing 61 changed files with 826 additions and 1,341 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ In the case of Golang, the necessary native code can be found in the `src/main/g

You need to install [jep](https://github.com/ninia/jep/). This can either be system-wide or in a virtual environment. Your jep version has to match the version used by the CPG (see [version catalog](./gradle/libs.versions.toml)).

Currently, only Python 3.10 is supported.
Currently, only Python 3.{9,10,11,12} is supported.

##### System Wide

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ public ParameterizedType searchTemplateScopeForDefinedParameterizedTypes(

// We need an additional check here, because of parsing or other errors, the AST node might
// not necessarily be a template declaration.
if (node instanceof TemplateDeclaration) {
TemplateDeclaration template = (TemplateDeclaration) node;
ParameterizedType parameterizedType = getTypeParameter(template, name);
if (node instanceof TemplateDeclaration templateDeclaration) {
ParameterizedType parameterizedType = getTypeParameter(templateDeclaration, name);
if (parameterizedType != null) {
return parameterizedType;
}
Expand Down Expand Up @@ -318,13 +317,13 @@ public boolean containsParameterizedType(List<Type> generics) {
* with parameterizedTypes as generics false otherwise
*/
public boolean stopPropagation(Type type, Type newType) {
if (type instanceof ObjectType
&& newType instanceof ObjectType
&& ((ObjectType) type).getGenerics() != null
&& ((ObjectType) newType).getGenerics() != null
if (type instanceof ObjectType typeObjectType
&& newType instanceof ObjectType newObjectType
&& typeObjectType.getGenerics() != null
&& newObjectType.getGenerics() != null
&& type.getName().equals(newType.getName())) {
return containsParameterizedType(((ObjectType) newType).getGenerics())
&& !(containsParameterizedType(((ObjectType) type).getGenerics()));
return containsParameterizedType(newObjectType.getGenerics())
&& !(containsParameterizedType(typeObjectType.getGenerics()));
}
return false;
}
Expand Down Expand Up @@ -482,7 +481,7 @@ public Optional<Type> getCommonType(@NotNull Collection<Type> types, ScopeProvid
.map(t -> typeToRecord.getOrDefault(t, null))
.filter(Objects::nonNull)
.map(r -> getAncestors(r, 0))
.collect(Collectors.toList());
.toList();

// normalize/reverse depth: roots start at 0, increasing on each level
for (Set<Ancestor> ancestors : allAncestors) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Fraunhofer AISEC. All rights reserved.
* Copyright (c) 2023, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,27 +23,20 @@
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.graph.types;
package de.fraunhofer.aisec.cpg.graph.types

import java.util.HashMap;
import java.util.Map;
import org.neo4j.ogm.typeconversion.CompositeAttributeConverter;
import de.fraunhofer.aisec.cpg.frontends.Language
import de.fraunhofer.aisec.cpg.frontends.LanguageFrontend

public class QualifierConverter implements CompositeAttributeConverter<Type.Qualifier> {
@Override
public Map<String, ?> toGraphProperties(Type.Qualifier value) {
Map<String, Boolean> properties = new HashMap<>();
properties.put("isConst", value.isConst());
properties.put("isVolatile", value.isVolatile());
properties.put("isRestrict", value.isRestrict());
properties.put("isAtomic", value.isAtomic());
return properties;
}
/** Instances of this class represent floating point types. */
class FloatingPointType(
typeName: CharSequence = "",
bitWidth: Int? = null,
language: Language<out LanguageFrontend>? = null,
modifier: Modifier = Modifier.SIGNED
) : NumericType(typeName, bitWidth, language, modifier) {

@Override
public Type.Qualifier toEntityAttribute(Map<String, ?> value) {
Map<String, Boolean> val = (Map<String, Boolean>) value;
return new Type.Qualifier(
val.get("isConst"), val.get("isVolatile"), val.get("isRestrict"), val.get("isAtomic"));
}
override fun duplicate(): Type {
return FloatingPointType(name, bitWidth, language, modifier)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ public void setReturnType(Type returnType) {
private FunctionPointerType() {}

public FunctionPointerType(
Type.Qualifier qualifier,
Type.Storage storage,
List<Type> parameters,
Type returnType,
Language<? extends LanguageFrontend> language) {
super("", storage, qualifier, language);
List<Type> parameters, Type returnType, Language<? extends LanguageFrontend> language) {
super("", language);
this.parameters = PropertyEdge.transformIntoOutgoingPropertyEdgeList(parameters, this);
this.returnType = returnType;
}
Expand Down Expand Up @@ -124,9 +120,8 @@ public boolean isSimilar(Type t) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof FunctionPointerType)) return false;
if (!(o instanceof FunctionPointerType that)) return false;
if (!super.equals(o)) return false;
FunctionPointerType that = (FunctionPointerType) o;
return Objects.equals(this.getParameters(), that.getParameters())
&& PropertyEdge.propertyEqualsList(parameters, that.parameters)
&& Objects.equals(returnType, that.returnType);
Expand All @@ -148,10 +143,6 @@ public String toString() {
+ ", typeName='"
+ getName()
+ '\''
+ ", storage="
+ this.getStorage()
+ ", qualifier="
+ this.getQualifier()
+ ", origin="
+ this.getTypeOrigin()
+ '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class FunctionType : Type {
parameters: List<Type>,
returnTypes: List<Type>,
language: Language<out LanguageFrontend>?,
qualifier: Qualifier = Qualifier(),
storage: Storage = Storage.AUTO
) : super(typeName, storage, qualifier, language) {
) : super(typeName, language) {
this.parameters = parameters
this.returnTypes = returnTypes
}
Expand All @@ -59,28 +57,15 @@ class FunctionType : Type {
override fun reference(pointer: PointerType.PointerOrigin?): Type {
// TODO(oxisto): In the future, we actually could just remove the FunctionPointerType
// and just have a regular PointerType here
return FunctionPointerType(
qualifier,
storage,
parameters.toList(),
returnTypes.first(),
language
)
return FunctionPointerType(parameters.toList(), returnTypes.first(), language)
}

override fun dereference(): Type {
return UnknownType.getUnknownType(language)
}

override fun duplicate(): Type {
return FunctionType(
typeName,
parameters.toList(),
returnTypes.toList(),
language,
qualifier,
storage
)
return FunctionType(typeName, parameters.toList(), returnTypes.toList(), language)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
* length, forward declarated classes in C++
*
* <p>Right now we are only dealing with void for objects with unknown size, therefore the name is
* fixed to void. However, this can be changed in future, in order to support other objects with
* unknown size apart from void. Therefore this Type is not called VoidType
* fixed to void. However, this can be changed in the future, in order to support other objects with
* unknown size apart from void. Therefore, this Type is not called VoidType
*/
public class IncompleteType extends Type {

public IncompleteType() {
super("void", Storage.AUTO, new Qualifier(false, false, false, false), null);
super("void", null);
}

public IncompleteType(Type type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.graph.types

import de.fraunhofer.aisec.cpg.frontends.Language
import de.fraunhofer.aisec.cpg.frontends.LanguageFrontend

/** Instances of this class represent integer types. */
class IntegerType(
typeName: CharSequence = "",
bitWidth: Int? = null,
language: Language<out LanguageFrontend>? = null,
modifier: Modifier = Modifier.SIGNED
) : NumericType(typeName, bitWidth, language, modifier) {

override fun duplicate(): Type {
return IntegerType(this.name, bitWidth, language, modifier)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2023, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.graph.types

import de.fraunhofer.aisec.cpg.frontends.Language
import de.fraunhofer.aisec.cpg.frontends.LanguageFrontend
import java.util.*

/** This type collects all kind of numeric types. */
open class NumericType(
typeName: CharSequence = "",
val bitWidth: Int? = null,
language: Language<out LanguageFrontend>? = null,
val modifier: Modifier = Modifier.SIGNED
) : ObjectType(typeName, listOf(), true, language) {

override fun duplicate(): Type {
return NumericType(this.name, bitWidth, language, modifier)
}

/**
* NumericTypes can have a modifier. The default is signed. Some types (e.g. char in C) may be
* neither of the signed/unsigned option. TODO: maybe replace with a flag "signed" or
* "unsigned"?
*/
enum class Modifier {
SIGNED,
UNSIGNED,
NOT_APPLICABLE
}

override fun equals(other: Any?) =
super.equals(other) && this.modifier == (other as? NumericType)?.modifier

override fun hashCode() = Objects.hash(super.hashCode(), generics, modifier, primitive)
}
Loading

0 comments on commit b72e1a2

Please sign in to comment.