blob: 775db323f5dde8dcdc342bfdc7d15988e22fdc63 (
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
//: Textual form for types.
:(scenarios load)
:(scenario container)
container foo [
x:integer
y:integer
]
+parse: reading container foo
+parse: element name: x
+parse: type: 1
+parse: element name: y
+parse: type: 1
:(before "End Command Handlers")
else if (command == "container") {
insert_container(command, container, in);
}
:(code)
void insert_container(const string& command, kind_of_type kind, istream& in) {
skip_whitespace(in);
string name = next_word(in);
trace("parse") << "reading " << command << ' ' << name;
//? cout << name << '\n'; //? 1
assert(Type_number.find(name) == Type_number.end());
Type_number[name] = Next_type_number++;
skip_bracket(in, "'container' must begin with '['");
assert(Type.find(Type_number[name]) == Type.end());
type_info& t = Type[Type_number[name]];
recently_added_types.push_back(Type_number[name]);
t.name = name;
t.kind = kind;
while (!in.eof()) {
skip_whitespace_and_comments(in);
string element = next_word(in);
if (element == "]") break;
istringstream inner(element);
t.element_names.push_back(slurp_until(inner, ':'));
trace("parse") << " element name: " << t.element_names.back();
vector<type_number> types;
while (!inner.eof()) {
string type_name = slurp_until(inner, ':');
if (Type_number.find(type_name) == Type_number.end())
raise << "unknown type " << type_name << '\n';
types.push_back(Type_number[type_name]);
trace("parse") << " type: " << types.back();
}
t.elements.push_back(types);
}
assert(t.elements.size() == t.element_names.size());
t.size = t.elements.size();
}
//:: Similarly for exclusive_container.
:(scenario exclusive_container)
exclusive-container foo [
x:integer
y:integer
]
+parse: reading exclusive-container foo
+parse: element name: x
+parse: type: 1
+parse: element name: y
+parse: type: 1
:(before "End Command Handlers")
else if (command == "exclusive-container") {
insert_container(command, exclusive_container, in);
}
//:: ensure types created in one scenario don't leak outside it.
:(before "End Globals")
vector<type_number> recently_added_types;
:(before "End Setup")
for (index_t i = 0; i < recently_added_types.size(); ++i) {
//? cout << "erasing " << Type[recently_added_types.at(i)].name << '\n'; //? 1
Type_number.erase(Type[recently_added_types.at(i)].name);
Type.erase(recently_added_types.at(i));
}
recently_added_types.clear();
//: lastly, ensure scenarios are consistent by always starting them at the
//: same type number.
Next_type_number = 1000;
:(before "End Test Run Initialization")
assert(Next_type_number < 1000);
:(before "End Setup")
Next_type_number = 1000;
:(code)
void skip_bracket(istream& in, string message) {
skip_whitespace_and_comments(in);
if (in.get() != '[')
raise << message << '\n';
}
|