/
ClassConstantMemory.java
56 lines (46 loc) · 1.57 KB
/
ClassConstantMemory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package php.runtime.memory.helper;
import php.runtime.Memory;
import php.runtime.common.Messages;
import php.runtime.env.Environment;
import php.runtime.env.TraceInfo;
import php.runtime.exceptions.support.ErrorType;
import php.runtime.memory.ReferenceMemory;
import php.runtime.reflection.ClassEntity;
import php.runtime.reflection.ConstantEntity;
public class ClassConstantMemory extends ReferenceMemory {
private final String name;
private final String lowerName;
private final String className;
private final String classLowerName;
public ClassConstantMemory(String className, String name){
super();
this.className = className;
this.classLowerName = className.toLowerCase();
this.name = name;
this.lowerName = name.toLowerCase();
}
@Override
public Memory toImmutable(Environment env, TraceInfo trace) {
ClassEntity classEntity = env.fetchClass(className, classLowerName, true);
if (classEntity == null) {
env.error(trace, ErrorType.E_ERROR, Messages.ERR_CLASS_NOT_FOUND, className);
return NULL;
}
ConstantEntity entity = classEntity.findConstant(name);
if (entity == null){
env.error(trace, ErrorType.E_ERROR, Messages.ERR_UNDEFINED_CLASS_CONSTANT, className + "::" + name);
return NULL;
}
return entity.getValue();
}
public String getName() {
return name;
}
public String getClassName() {
return className;
}
@Override
public Memory toValue() {
return this;
}
}