Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
ast.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21#include <ql/errors.hpp>
22
23#include <sstream>
24
25namespace ore {
26namespace data {
27
28std::string to_string(const LocationInfo& l) {
29 if (l.initialised) {
30 if (l.lineStart == l.lineEnd && l.columnStart <= l.columnEnd)
31 return 'L' + std::to_string(l.lineStart) + ':' + std::to_string(l.columnStart) + ':' +
32 std::to_string(l.columnEnd - l.columnStart);
33 else
34 return 'L' + std::to_string(l.lineStart) + ':' + std::to_string(l.columnStart) + "-L" +
35 std::to_string(l.lineEnd) + ':' + std::to_string(l.columnEnd);
36 } else
37 return "L?";
38}
39
40ASTNode::ASTNode(const std::vector<ASTNodePtr>& args, const Size minArgs, const Size maxArgs) : args(args) {
41 QL_REQUIRE(minArgs <= args.size() && (maxArgs == Null<Size>() || args.size() <= maxArgs),
42 "ASTNode construction failed, got " << args.size() << " arguments, expected " << minArgs << "..."
43 << (maxArgs == Null<Size>() ? "inf" : std::to_string(maxArgs)));
44 if (maxArgs != Null<Size>())
45 this->args.resize(maxArgs, ASTNodePtr());
46}
47
48void ASTNode::accept(AcyclicVisitor& v) {
49 auto v1 = dynamic_cast<Visitor<ASTNode>*>(&v);
50 if (v1 != nullptr)
51 v1->visit(*this);
52 else
53 QL_FAIL("not an ASTNode visitor");
54}
55
56void OperatorPlusNode::accept(AcyclicVisitor& v) {
57 auto v1 = dynamic_cast<Visitor<OperatorPlusNode>*>(&v);
58 if (v1 != nullptr)
59 v1->visit(*this);
60 else
62}
63
64void OperatorMinusNode::accept(AcyclicVisitor& v) {
65 auto v1 = dynamic_cast<Visitor<OperatorMinusNode>*>(&v);
66 if (v1 != nullptr)
67 v1->visit(*this);
68 else
70}
71
72void OperatorMultiplyNode::accept(AcyclicVisitor& v) {
73 auto v1 = dynamic_cast<Visitor<OperatorMultiplyNode>*>(&v);
74 if (v1 != nullptr)
75 v1->visit(*this);
76 else
78}
79
80void OperatorDivideNode::accept(AcyclicVisitor& v) {
81 auto v1 = dynamic_cast<Visitor<OperatorDivideNode>*>(&v);
82 if (v1 != nullptr)
83 v1->visit(*this);
84 else
86}
87
88void NegateNode::accept(AcyclicVisitor& v) {
89 auto v1 = dynamic_cast<Visitor<NegateNode>*>(&v);
90 if (v1 != nullptr)
91 v1->visit(*this);
92 else
94}
95
96void FunctionAbsNode::accept(AcyclicVisitor& v) {
97 auto v1 = dynamic_cast<Visitor<FunctionAbsNode>*>(&v);
98 if (v1 != nullptr)
99 v1->visit(*this);
100 else
102}
103
104void FunctionExpNode::accept(AcyclicVisitor& v) {
105 auto v1 = dynamic_cast<Visitor<FunctionExpNode>*>(&v);
106 if (v1 != nullptr)
107 v1->visit(*this);
108 else
110}
111
112void FunctionLogNode::accept(AcyclicVisitor& v) {
113 auto v1 = dynamic_cast<Visitor<FunctionLogNode>*>(&v);
114 if (v1 != nullptr)
115 v1->visit(*this);
116 else
118}
119
120void FunctionSqrtNode::accept(AcyclicVisitor& v) {
121 auto v1 = dynamic_cast<Visitor<FunctionSqrtNode>*>(&v);
122 if (v1 != nullptr)
123 v1->visit(*this);
124 else
126}
127
128void FunctionNormalCdfNode::accept(AcyclicVisitor& v) {
129 auto v1 = dynamic_cast<Visitor<FunctionNormalCdfNode>*>(&v);
130 if (v1 != nullptr)
131 v1->visit(*this);
132 else
134}
135
136void FunctionNormalPdfNode::accept(AcyclicVisitor& v) {
137 auto v1 = dynamic_cast<Visitor<FunctionNormalPdfNode>*>(&v);
138 if (v1 != nullptr)
139 v1->visit(*this);
140 else
142}
143
144void FunctionMaxNode::accept(AcyclicVisitor& v) {
145 auto v1 = dynamic_cast<Visitor<FunctionMaxNode>*>(&v);
146 if (v1 != nullptr)
147 v1->visit(*this);
148 else
150}
151
152void FunctionMinNode::accept(AcyclicVisitor& v) {
153 auto v1 = dynamic_cast<Visitor<FunctionMinNode>*>(&v);
154 if (v1 != nullptr)
155 v1->visit(*this);
156 else
158}
159
160void FunctionPowNode::accept(AcyclicVisitor& v) {
161 auto v1 = dynamic_cast<Visitor<FunctionPowNode>*>(&v);
162 if (v1 != nullptr)
163 v1->visit(*this);
164 else
166}
167
168void FunctionBlackNode::accept(AcyclicVisitor& v) {
169 auto v1 = dynamic_cast<Visitor<FunctionBlackNode>*>(&v);
170 if (v1 != nullptr)
171 v1->visit(*this);
172 else
174}
175
176void FunctionDcfNode::accept(AcyclicVisitor& v) {
177 auto v1 = dynamic_cast<Visitor<FunctionDcfNode>*>(&v);
178 if (v1 != nullptr)
179 v1->visit(*this);
180 else
182}
183
184void FunctionDaysNode::accept(AcyclicVisitor& v) {
185 auto v1 = dynamic_cast<Visitor<FunctionDaysNode>*>(&v);
186 if (v1 != nullptr)
187 v1->visit(*this);
188 else
190}
191
192void FunctionPayNode::accept(AcyclicVisitor& v) {
193 auto v1 = dynamic_cast<Visitor<FunctionPayNode>*>(&v);
194 if (v1 != nullptr)
195 v1->visit(*this);
196 else
198}
199
200void FunctionLogPayNode::accept(AcyclicVisitor& v) {
201 auto v1 = dynamic_cast<Visitor<FunctionLogPayNode>*>(&v);
202 if (v1 != nullptr)
203 v1->visit(*this);
204 else
206}
207
208void FunctionNpvNode::accept(AcyclicVisitor& v) {
209 auto v1 = dynamic_cast<Visitor<FunctionNpvNode>*>(&v);
210 if (v1 != nullptr)
211 v1->visit(*this);
212 else
214}
215
216void FunctionNpvMemNode::accept(AcyclicVisitor& v) {
217 auto v1 = dynamic_cast<Visitor<FunctionNpvMemNode>*>(&v);
218 if (v1 != nullptr)
219 v1->visit(*this);
220 else
222}
223
224void HistFixingNode::accept(AcyclicVisitor& v) {
225 auto v1 = dynamic_cast<Visitor<HistFixingNode>*>(&v);
226 if (v1 != nullptr)
227 v1->visit(*this);
228 else
230}
231
232void FunctionDiscountNode::accept(AcyclicVisitor& v) {
233 auto v1 = dynamic_cast<Visitor<FunctionDiscountNode>*>(&v);
234 if (v1 != nullptr)
235 v1->visit(*this);
236 else
238}
239
240void FunctionFwdCompNode::accept(AcyclicVisitor& v) {
241 auto v1 = dynamic_cast<Visitor<FunctionFwdCompNode>*>(&v);
242 if (v1 != nullptr)
243 v1->visit(*this);
244 else
246}
247
248void FunctionFwdAvgNode::accept(AcyclicVisitor& v) {
249 auto v1 = dynamic_cast<Visitor<FunctionFwdAvgNode>*>(&v);
250 if (v1 != nullptr)
251 v1->visit(*this);
252 else
254}
255
256void FunctionAboveProbNode::accept(AcyclicVisitor& v) {
257 auto v1 = dynamic_cast<Visitor<FunctionAboveProbNode>*>(&v);
258 if (v1 != nullptr)
259 v1->visit(*this);
260 else
262}
263
264void FunctionBelowProbNode::accept(AcyclicVisitor& v) {
265 auto v1 = dynamic_cast<Visitor<FunctionBelowProbNode>*>(&v);
266 if (v1 != nullptr)
267 v1->visit(*this);
268 else
270}
271
272void FunctionDateIndexNode::accept(AcyclicVisitor& v) {
273 auto v1 = dynamic_cast<Visitor<FunctionDateIndexNode>*>(&v);
274 if (v1 != nullptr)
275 v1->visit(*this);
276 else
278}
279
280void SortNode::accept(AcyclicVisitor& v) {
281 auto v1 = dynamic_cast<Visitor<SortNode>*>(&v);
282 if (v1 != nullptr)
283 v1->visit(*this);
284 else
286}
287
288void PermuteNode::accept(AcyclicVisitor& v) {
289 auto v1 = dynamic_cast<Visitor<PermuteNode>*>(&v);
290 if (v1 != nullptr)
291 v1->visit(*this);
292 else
294}
295
296void ConstantNumberNode::accept(AcyclicVisitor& v) {
297 auto v1 = dynamic_cast<Visitor<ConstantNumberNode>*>(&v);
298 if (v1 != nullptr)
299 v1->visit(*this);
300 else
302}
303
304void VariableNode::accept(AcyclicVisitor& v) {
305 auto v1 = dynamic_cast<Visitor<VariableNode>*>(&v);
306 if (v1 != nullptr)
307 v1->visit(*this);
308 else
310}
311
312void SizeOpNode::accept(AcyclicVisitor& v) {
313 auto v1 = dynamic_cast<Visitor<SizeOpNode>*>(&v);
314 if (v1 != nullptr)
315 v1->visit(*this);
316 else
318}
319
320void VarEvaluationNode::accept(AcyclicVisitor& v) {
321 auto v1 = dynamic_cast<Visitor<VarEvaluationNode>*>(&v);
322 if (v1 != nullptr)
323 v1->visit(*this);
324 else
326}
327
328void AssignmentNode::accept(AcyclicVisitor& v) {
329 auto v1 = dynamic_cast<Visitor<AssignmentNode>*>(&v);
330 if (v1 != nullptr)
331 v1->visit(*this);
332 else
334}
335
336void RequireNode::accept(AcyclicVisitor& v) {
337 auto v1 = dynamic_cast<Visitor<RequireNode>*>(&v);
338 if (v1 != nullptr)
339 v1->visit(*this);
340 else
342}
343
344void DeclarationNumberNode::accept(AcyclicVisitor& v) {
345 auto v1 = dynamic_cast<Visitor<DeclarationNumberNode>*>(&v);
346 if (v1 != nullptr)
347 v1->visit(*this);
348 else
350}
351
352void SequenceNode::accept(AcyclicVisitor& v) {
353 auto v1 = dynamic_cast<Visitor<SequenceNode>*>(&v);
354 if (v1 != nullptr)
355 v1->visit(*this);
356 else
358}
359
360void ConditionEqNode::accept(AcyclicVisitor& v) {
361 auto v1 = dynamic_cast<Visitor<ConditionEqNode>*>(&v);
362 if (v1 != nullptr)
363 v1->visit(*this);
364 else
366}
367
368void ConditionNeqNode::accept(AcyclicVisitor& v) {
369 auto v1 = dynamic_cast<Visitor<ConditionNeqNode>*>(&v);
370 if (v1 != nullptr)
371 v1->visit(*this);
372 else
374}
375
376void ConditionLtNode::accept(AcyclicVisitor& v) {
377 auto v1 = dynamic_cast<Visitor<ConditionLtNode>*>(&v);
378 if (v1 != nullptr)
379 v1->visit(*this);
380 else
382}
383
384void ConditionLeqNode::accept(AcyclicVisitor& v) {
385 auto v1 = dynamic_cast<Visitor<ConditionLeqNode>*>(&v);
386 if (v1 != nullptr)
387 v1->visit(*this);
388 else
390}
391
392void ConditionGtNode::accept(AcyclicVisitor& v) {
393 auto v1 = dynamic_cast<Visitor<ConditionGtNode>*>(&v);
394 if (v1 != nullptr)
395 v1->visit(*this);
396 else
398}
399
400void ConditionGeqNode::accept(AcyclicVisitor& v) {
401 auto v1 = dynamic_cast<Visitor<ConditionGeqNode>*>(&v);
402 if (v1 != nullptr)
403 v1->visit(*this);
404 else
406}
407
408void ConditionNotNode::accept(AcyclicVisitor& v) {
409 auto v1 = dynamic_cast<Visitor<ConditionNotNode>*>(&v);
410 if (v1 != nullptr)
411 v1->visit(*this);
412 else
414}
415
416void ConditionAndNode::accept(AcyclicVisitor& v) {
417 auto v1 = dynamic_cast<Visitor<ConditionAndNode>*>(&v);
418 if (v1 != nullptr)
419 v1->visit(*this);
420 else
422}
423
424void ConditionOrNode::accept(AcyclicVisitor& v) {
425 auto v1 = dynamic_cast<Visitor<ConditionOrNode>*>(&v);
426 if (v1 != nullptr)
427 v1->visit(*this);
428 else
430}
431
432void IfThenElseNode::accept(AcyclicVisitor& v) {
433 auto v1 = dynamic_cast<Visitor<IfThenElseNode>*>(&v);
434 if (v1 != nullptr)
435 v1->visit(*this);
436 else
438}
439
440void LoopNode::accept(AcyclicVisitor& v) {
441 auto v1 = dynamic_cast<Visitor<LoopNode>*>(&v);
442 if (v1 != nullptr)
443 v1->visit(*this);
444 else
446}
447
448} // namespace data
449} // namespace ore
abstract syntax tree for payoff scripting
@ data
Definition: log.hpp:77
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
QuantLib::ext::shared_ptr< ASTNode > ASTNodePtr
Definition: ast.hpp:46
Serializable Credit Default Swap.
Definition: namespaces.docs:23
std::vector< ASTNodePtr > args
Definition: ast.hpp:64
virtual void accept(AcyclicVisitor &)
Definition: ast.cpp:48
void accept(AcyclicVisitor &) override
Definition: ast.cpp:328
void accept(AcyclicVisitor &) override
Definition: ast.cpp:416
void accept(AcyclicVisitor &) override
Definition: ast.cpp:360
void accept(AcyclicVisitor &) override
Definition: ast.cpp:400
void accept(AcyclicVisitor &) override
Definition: ast.cpp:392
void accept(AcyclicVisitor &) override
Definition: ast.cpp:384
void accept(AcyclicVisitor &) override
Definition: ast.cpp:376
void accept(AcyclicVisitor &) override
Definition: ast.cpp:368
void accept(AcyclicVisitor &) override
Definition: ast.cpp:408
void accept(AcyclicVisitor &) override
Definition: ast.cpp:424
void accept(AcyclicVisitor &) override
Definition: ast.cpp:296
void accept(AcyclicVisitor &) override
Definition: ast.cpp:344
void accept(AcyclicVisitor &) override
Definition: ast.cpp:256
void accept(AcyclicVisitor &) override
Definition: ast.cpp:96
void accept(AcyclicVisitor &) override
Definition: ast.cpp:264
void accept(AcyclicVisitor &) override
Definition: ast.cpp:168
void accept(AcyclicVisitor &) override
Definition: ast.cpp:272
void accept(AcyclicVisitor &) override
Definition: ast.cpp:184
void accept(AcyclicVisitor &) override
Definition: ast.cpp:176
void accept(AcyclicVisitor &) override
Definition: ast.cpp:232
void accept(AcyclicVisitor &) override
Definition: ast.cpp:104
void accept(AcyclicVisitor &) override
Definition: ast.cpp:248
void accept(AcyclicVisitor &) override
Definition: ast.cpp:240
void accept(AcyclicVisitor &) override
Definition: ast.cpp:112
void accept(AcyclicVisitor &) override
Definition: ast.cpp:200
void accept(AcyclicVisitor &) override
Definition: ast.cpp:144
void accept(AcyclicVisitor &) override
Definition: ast.cpp:152
void accept(AcyclicVisitor &) override
Definition: ast.cpp:128
void accept(AcyclicVisitor &) override
Definition: ast.cpp:136
void accept(AcyclicVisitor &) override
Definition: ast.cpp:216
void accept(AcyclicVisitor &) override
Definition: ast.cpp:208
void accept(AcyclicVisitor &) override
Definition: ast.cpp:192
void accept(AcyclicVisitor &) override
Definition: ast.cpp:160
void accept(AcyclicVisitor &) override
Definition: ast.cpp:120
void accept(AcyclicVisitor &) override
Definition: ast.cpp:224
void accept(AcyclicVisitor &) override
Definition: ast.cpp:432
void accept(AcyclicVisitor &) override
Definition: ast.cpp:440
void accept(AcyclicVisitor &) override
Definition: ast.cpp:88
void accept(AcyclicVisitor &) override
Definition: ast.cpp:80
void accept(AcyclicVisitor &) override
Definition: ast.cpp:64
void accept(AcyclicVisitor &) override
Definition: ast.cpp:72
void accept(AcyclicVisitor &) override
Definition: ast.cpp:56
void accept(AcyclicVisitor &) override
Definition: ast.cpp:288
void accept(AcyclicVisitor &) override
Definition: ast.cpp:336
void accept(AcyclicVisitor &) override
Definition: ast.cpp:352
void accept(AcyclicVisitor &) override
Definition: ast.cpp:312
void accept(AcyclicVisitor &) override
Definition: ast.cpp:280
void accept(AcyclicVisitor &) override
Definition: ast.cpp:320
void accept(AcyclicVisitor &) override
Definition: ast.cpp:304