@@ -28,14 +28,17 @@ package de.fraunhofer.aisec.cpg
28
28
import de.fraunhofer.aisec.cpg.frontends.CastNotPossible
29
29
import de.fraunhofer.aisec.cpg.frontends.CastResult
30
30
import de.fraunhofer.aisec.cpg.frontends.Language
31
+ import de.fraunhofer.aisec.cpg.graph.Name
31
32
import de.fraunhofer.aisec.cpg.graph.declarations.RecordDeclaration
32
33
import de.fraunhofer.aisec.cpg.graph.declarations.TemplateDeclaration
34
+ import de.fraunhofer.aisec.cpg.graph.parseName
33
35
import de.fraunhofer.aisec.cpg.graph.scopes.Scope
34
36
import de.fraunhofer.aisec.cpg.graph.scopes.TemplateScope
35
37
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Reference
36
38
import de.fraunhofer.aisec.cpg.graph.types.*
37
39
import de.fraunhofer.aisec.cpg.passes.Pass
38
40
import de.fraunhofer.aisec.cpg.passes.ResolveCallExpressionAmbiguityPass
41
+ import de.fraunhofer.aisec.cpg.passes.TypeResolver
39
42
import java.util.*
40
43
import java.util.concurrent.ConcurrentHashMap
41
44
import org.slf4j.Logger
@@ -57,8 +60,14 @@ class TypeManager {
57
60
MutableMap <TemplateDeclaration , MutableList <ParameterizedType >> =
58
61
ConcurrentHashMap ()
59
62
60
- val firstOrderTypes: MutableSet <Type > = ConcurrentHashMap .newKeySet()
61
- val secondOrderTypes: MutableSet <Type > = ConcurrentHashMap .newKeySet()
63
+ val firstOrderTypes = mutableListOf<Type >()
64
+ val secondOrderTypes = mutableListOf<Type >()
65
+
66
+ /* *
67
+ * A map of declared types by their name. Useful to check for the existence of a declared type
68
+ * by its fully qualified name across all scopes.
69
+ */
70
+ @PopulatedByPass(TypeResolver ::class ) val declaredTypes = mutableMapOf<Name , Type >()
62
71
63
72
/* *
64
73
* @param recordDeclaration that is instantiated by a template containing parameterizedtypes
@@ -200,26 +209,9 @@ class TypeManager {
200
209
}
201
210
202
211
if (t.isFirstOrderType) {
203
- // Make sure we only ever return one unique object per type
204
- if (! firstOrderTypes.add(t)) {
205
- return firstOrderTypes.first { it == t && it is T } as T
206
- } else {
207
- log.trace(
208
- " Registering unique first order type {}{}" ,
209
- t.name,
210
- if ((t as ? ObjectType )?.generics?.isNotEmpty() == true ) {
211
- " with generics ${t.generics.joinToString(" ," , " [" , " ]" ) { it.name.toString() }} "
212
- } else {
213
- " "
214
- }
215
- )
216
- }
212
+ synchronized(firstOrderTypes) { firstOrderTypes.add(t) }
217
213
} else if (t is SecondOrderType ) {
218
- if (! secondOrderTypes.add(t)) {
219
- return secondOrderTypes.first { it == t && it is T } as T
220
- } else {
221
- log.trace(" Registering unique second order type {}" , t.name)
222
- }
214
+ synchronized(secondOrderTypes) { secondOrderTypes.add(t) }
223
215
}
224
216
225
217
return t
@@ -240,25 +232,13 @@ class TypeManager {
240
232
* This function returns the first (there should be only one) [Type] with the given [fqn] that
241
233
* is [Type.Origin.RESOLVED].
242
234
*/
243
- fun lookupResolvedType (
244
- fqn : CharSequence ,
245
- generics : List <Type >? = null,
246
- language : Language <* >? = null
247
- ): Type ? {
235
+ fun lookupResolvedType (fqn : CharSequence , language : Language <* >? = null): Type ? {
248
236
var primitiveType = language?.getSimpleTypeOf(fqn)
249
237
if (primitiveType != null ) {
250
238
return primitiveType
251
239
}
252
240
253
- return firstOrderTypes.firstOrNull {
254
- (it.typeOrigin == Type .Origin .RESOLVED || it.typeOrigin == Type .Origin .GUESSED ) &&
255
- it.root.name == fqn &&
256
- if (generics != null ) {
257
- (it as ? ObjectType )?.generics == generics
258
- } else {
259
- true
260
- }
261
- }
241
+ return declaredTypes[language.parseName(fqn)]
262
242
}
263
243
}
264
244
0 commit comments