blob: fb1338b8b652cd57356c9cd9d6e8c7f37eab6d43 (
plain) (
blame)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.indexinglanguage.expressions;
import com.yahoo.document.DataType;
import java.util.HashMap;
import java.util.Map;
/**
* @author Simon Thoresen Hult
*/
public class VerificationContext implements FieldTypeAdapter, Cloneable {
private final Map<String, DataType> variables = new HashMap<>();
private final FieldTypeAdapter adapter;
private DataType value;
private String outputField;
public VerificationContext() {
this.adapter = null;
}
public VerificationContext(FieldTypeAdapter adapter) {
this.adapter = adapter;
}
public VerificationContext execute(Expression exp) {
if (exp != null) {
exp.verify(this);
}
return this;
}
@Override
public DataType getInputType(Expression exp, String fieldName) {
return adapter.getInputType(exp, fieldName);
}
@Override
public void tryOutputType(Expression exp, String fieldName, DataType valueType) {
adapter.tryOutputType(exp, fieldName, valueType);
}
public DataType getVariable(String name) {
return variables.get(name);
}
public VerificationContext setVariable(String name, DataType value) {
variables.put(name, value);
return this;
}
public DataType getValueType() {
return value;
}
/** Sets the output value type */
public VerificationContext setValueType(DataType value) {
this.value = value;
return this;
}
/** Sets the name of the (last) output field of the statement this is executed as a part of */
public void setOutputField(String outputField) { this.outputField = outputField; }
/**
* Returns the name of the (last) output field of the statement this is executed as a part of,
* or null if none or not yet verified
*/
public String getOutputField() { return outputField; }
public VerificationContext clear() {
variables.clear();
value = null;
return this;
}
}
|