Skip to content

Commit

Permalink
Setting name
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Jun 11, 2023
1 parent f6c0259 commit 8560548
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import de.fraunhofer.aisec.cpg.TranslationContext
import de.fraunhofer.aisec.cpg.graph.Name
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.newUnknownType
import de.fraunhofer.aisec.cpg.graph.statements.expressions.BinaryOperator
Expand Down Expand Up @@ -114,7 +115,10 @@ abstract class Language<T : LanguageFrontend> : Node() {
}

init {
this.also { this.language = it }
this.also { language ->
this.language = language
language::class.simpleName?.let { this.name = Name(it) }
}
}

private fun arithmeticOpTypePropagation(lhs: Type, rhs: Type): Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ abstract class ValueDeclaration : Declaration(), HasType {
setType(value, null)
}

override val typeHint: Type? = null

@Relationship("POSSIBLE_SUB_TYPES") protected var _possibleSubTypes = mutableListOf<Type>()
override var possibleSubTypes: List<Type>
get() {
Expand All @@ -87,7 +85,6 @@ abstract class ValueDeclaration : Declaration(), HasType {
}

@Transient override val typeListeners: MutableSet<HasType.TypeListener> = HashSet()
@Transient override val typeHintListener = mutableSetOf<HasType.TypeHintListener>()

/**
* Links to all the [DeclaredReferenceExpression]s accessing the variable and the respective
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ abstract class Expression : Statement(), HasType {
setType(value, null)
}

override var typeHint: Type? = null

@Relationship("POSSIBLE_SUB_TYPES") protected var _possibleSubTypes = mutableListOf<Type>()

override var possibleSubTypes: List<Type>
Expand All @@ -86,7 +84,6 @@ abstract class Expression : Statement(), HasType {
}

@Transient override val typeListeners: MutableSet<HasType.TypeListener> = HashSet()
@Transient override val typeHintListener = mutableSetOf<HasType.TypeHintListener>()

override val propagationType: Type
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
package de.fraunhofer.aisec.cpg.graph

import de.fraunhofer.aisec.cpg.frontends.TranslationException
import de.fraunhofer.aisec.cpg.graph.declarations.VariableDeclaration
import de.fraunhofer.aisec.cpg.graph.statements.expressions.AssignExpression
import de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression
import de.fraunhofer.aisec.cpg.graph.types.Type
import java.util.Optional

Expand All @@ -41,25 +38,6 @@ interface HasType : ContextProvider {
*/
val propagationType: Type

/**
* In contrast to the [type] variable, which holds the actual type information of this node,
* [typeHint] contains hints about what the type *could* be. It is up to implementing node to
* decide, how to act on this hint.
*
* There are several possible use-cases for this. For example, when initializing a variable with
* an explicit constructor variable (`int a(5)`), results in a [ConstructExpression] as the
* [VariableDeclaration.initializer] of a [VariableDeclaration]. The type information is only
* available in the [VariableDeclaration] and not in the [ConstructExpression]; we therefore
* "hint" the type of a variable declaration to its initializer. If we would implement this
* using a regular type listener, we would introduce loops into the type system, which we do not
* want.
*
* Similarly, we are "hinting" the type of the lhs of an [AssignExpression] to its corresponding
* right-hand-side. This helps in a better inference of certain variables and functions because
* we then know which type the assignment is expecting.
*/
val typeHint: Type?

/**
* Side-effect free type modification WARNING: This should only be used by the TypeSystem Pass
*
Expand Down Expand Up @@ -104,16 +82,6 @@ interface HasType : ContextProvider {
typeListeners.remove(listener)
}

val typeHintListener: MutableSet<TypeHintListener>

fun registerTypeHintListener(listener: TypeHintListener) {
listener.typeHintChanged(this, type)
}

fun unregisterTypeHintListener(listener: TypeListener) {
typeListeners.remove(listener)
}

fun refreshType()

/**
Expand All @@ -130,10 +98,6 @@ interface HasType : ContextProvider {
fun possibleSubTypesChanged(src: HasType, root: MutableList<HasType>)
}

interface TypeHintListener {
fun typeHintChanged(src: HasType, hint: Type)
}

/**
* The Typeresolver needs to be aware of all outgoing edges to types in order to merge equal
* types to the same node. For the primary type edge, this is achieved through the hasType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ package de.fraunhofer.aisec.cpg.frontends.cxx
import com.fasterxml.jackson.annotation.JsonIgnore
import de.fraunhofer.aisec.cpg.TranslationContext
import de.fraunhofer.aisec.cpg.frontends.*
import de.fraunhofer.aisec.cpg.graph.Name
import de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration
import de.fraunhofer.aisec.cpg.graph.declarations.RecordDeclaration
import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration
Expand Down Expand Up @@ -56,7 +55,6 @@ open class CLanguage :
override val elaboratedTypeSpecifier = listOf("struct", "union", "enum")
override val conjunctiveOperators = listOf("&&")
override val disjunctiveOperators = listOf("||")
override var name = Name("C")

/**
* All operators which perform and assignment and an operation using lhs and rhs. See
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package de.fraunhofer.aisec.cpg.frontends.cxx

import de.fraunhofer.aisec.cpg.TranslationContext
import de.fraunhofer.aisec.cpg.frontends.*
import de.fraunhofer.aisec.cpg.graph.Name
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.declarations.*
import de.fraunhofer.aisec.cpg.graph.edge.Properties
Expand All @@ -51,7 +50,6 @@ class CPPLanguage :
override val fileExtensions = listOf("cpp", "cc", "cxx", "hpp", "hh")
override val elaboratedTypeSpecifier = listOf("class", "struct", "union", "enum")
override val unknownTypeString = listOf("auto")
override var name = Name("C++")

@Transient
override val builtInTypes =
Expand Down

0 comments on commit 8560548

Please sign in to comment.