MCPcopy Create free account
hub / github.com/LFYSec/MScan / TypeSystemImpl

Class TypeSystemImpl

src/main/java/pascal/taie/language/type/TypeSystemImpl.java:36–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35// TODO: optimize maps (classTypes and arrayTypes)
36public class TypeSystemImpl implements TypeSystem {
37
38 private final ClassHierarchy hierarchy;
39
40 private final Map<JClassLoader, Map<String, ClassType>> classTypes = newSmallMap();
41
42 /**
43 * This map may be concurrently written during IR construction,
44 * thus we use concurrent map to ensure its thread-safety.
45 */
46 private final ConcurrentMap<Integer, ConcurrentMap<Type, ArrayType>> arrayTypes
47 = newConcurrentMap(8);
48
49 private final ClassType OBJECT;
50 private final ClassType SERIALIZABLE;
51 private final ClassType CLONEABLE;
52
53 // Boxed types
54 private final ClassType BOOLEAN;
55 private final ClassType BYTE;
56 private final ClassType SHORT;
57 private final ClassType CHARACTER;
58 private final ClassType INTEGER;
59 private final ClassType LONG;
60 private final ClassType FLOAT;
61 private final ClassType DOUBLE;
62
63 public TypeSystemImpl(ClassHierarchy hierarchy) {
64 this.hierarchy = hierarchy;
65 // Initialize special types
66 JClassLoader loader = hierarchy.getBootstrapClassLoader();
67 OBJECT = getClassType(loader, ClassNames.OBJECT);
68 SERIALIZABLE = getClassType(loader, ClassNames.SERIALIZABLE);
69 CLONEABLE = getClassType(loader, ClassNames.CLONEABLE);
70 BOOLEAN = getClassType(loader, ClassNames.BOOLEAN);
71 BYTE = getClassType(loader, ClassNames.BYTE);
72 SHORT = getClassType(loader, ClassNames.SHORT);
73 CHARACTER = getClassType(loader, ClassNames.CHARACTER);
74 INTEGER = getClassType(loader, ClassNames.INTEGER);
75 LONG = getClassType(loader, ClassNames.LONG);
76 FLOAT = getClassType(loader, ClassNames.FLOAT);
77 DOUBLE = getClassType(loader, ClassNames.DOUBLE);
78 }
79
80 @Override
81 public Type getType(JClassLoader loader, String typeName) {
82 try {
83 if (typeName.endsWith("[]")) {
84 int dim = 0;
85 int i = typeName.length() - 1;
86 while (i > 0) {
87 if (typeName.charAt(i - 1) == '[' && typeName.charAt(i) == ']') {
88 ++dim;
89 i -= 2;
90 } else {
91 break;
92 }
93 }

Callers

nothing calls this directly

Calls 2

newConcurrentMapMethod · 0.80
newSmallMapMethod · 0.45

Tested by

no test coverage detected