KSeExpr 6.0.0.0
ExprNode.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
2// SPDX-License-Identifier: LicenseRef-Apache-2.0
3// SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6#pragma once
7
8#include <cstdlib>
9#include <cstring>
10#include <vector>
11
12#include "ExprConfig.h"
13#include "ExprEnv.h"
14#include "ExprLLVM.h"
15#include "ExprType.h"
16#include "Expression.h"
17#include "Interpreter.h"
18#include "Vec.h"
19
20namespace KSeExpr
21{
22class ExprFunc;
23class ExprFuncX;
24
56{
57public:
58 ExprNode(const Expression *expr);
59 ExprNode(const Expression *expr, const ExprType &type);
62 ExprNode(const Expression *expr, ExprNode *a, const ExprType &type);
68 virtual ~ExprNode();
69
71
75
77 virtual int buildInterpreter(Interpreter *interpreter) const;
79
81
83 bool isVec() const
84 {
85 return _isVec;
86 }
87
89 const Expression *expr() const
90 {
91 return _expr;
92 }
93
95 std::string toString() const
96 {
97 return expr()->getExpr().substr(startPos(), length());
98 };
99
101
103 const ExprNode *parent() const
104 {
105 return _parent;
106 }
108 int numChildren() const
109 {
110 return static_cast<int>(_children.size());
111 }
112
114 const ExprNode *child(size_t i) const
115 {
116 return _children[i];
117 }
118
120 ExprNode *child(size_t i)
121 {
122 return _children[i];
123 }
124
126 void swapChildren(size_t i, size_t j)
127 {
128 assert(i != j && i < _children.size() && j < _children.size());
129 std::swap(_children[i], _children[j]);
130 }
131
134 {
135 if (!_children.empty()) {
136 delete _children.back();
137 _children.pop_back();
138 }
139 }
140
142 void addChild(ExprNode *child);
143
146
148
150 const ExprType &type() const
151 {
152 return _type;
153 };
154
156
158 inline void setPosition(const short int startPos, const short int endPos)
159 {
161 _endPos = endPos;
162 }
164 inline unsigned short int startPos() const
165 {
166 return _startPos;
167 }
169 inline unsigned short int endPos() const
170 {
171 return _endPos;
172 }
174 inline unsigned short int length() const
175 {
176 return endPos() - startPos();
177 };
178
180
182 inline void addError(const ErrorCode error, const std::vector<std::string>& ids = {}) const
183 {
184 _expr->addError(error, ids, _startPos, _endPos);
185 }
186
187protected: /*protected functions*/
189 inline void setType(const ExprType &t)
190 {
191 _type = t;
192 };
194 inline void setTypeWithChildLife(const ExprType &t)
195 {
196 setType(t);
197 int num = numChildren();
198 if (num > 0) {
200 for (int i = 1; i < num; i++)
202 } else // no children life is constant!
203 _type.Constant();
204 };
205
207
208public:
210 inline bool checkCondition(bool check, const ErrorCode message, const std::vector<std::string>& ids, bool &error) const
211 {
212 if (!check) {
213 addError(message, ids);
214 error = true;
215 }
216 return check;
217 };
219 bool checkIsValue(const ExprType &type, bool &error) const
220 {
221 return checkCondition(type.isValue(), ErrorCode::ExpectedStringOrFloatAnyD, {}, error);
222 }
224 bool checkIsFP(const ExprType &type, bool &error) const
225 {
226 return checkCondition(type.isFP(), ErrorCode::ExpectedFloatAnyD, {}, error);
227 }
229 bool checkIsFP(int d, const ExprType &type, bool &error) const
230 {
231 return checkCondition(type.isFP(d), ErrorCode::ExpectedFloatD, {std::to_string(d)}, error);
232 }
234 inline bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error) const
235 {
237 }
239protected: /*protected data members*/
241 const Expression *_expr{nullptr};
242
244 ExprNode *_parent{nullptr};
245
247 std::vector<ExprNode *> _children;
248
250 bool _isVec;
251
252 // Type of node
255
257 unsigned short int _startPos{}, _endPos{};
258};
259
262{
263public:
265 : ExprNode(expr)
266 {
267 }
268
270 int buildInterpreter(Interpreter *interpreter) const override;
272};
273
276{
277public:
278 ExprPrototypeNode(const Expression *expr, const std::string &name, const ExprType &retType)
279 : ExprNode(expr)
280 , _name(name)
283 , _argTypes()
284 {
285 }
286
287 ExprPrototypeNode(const Expression *expr, const std::string &name)
288 : ExprNode(expr)
289 , _name(name)
291 , _argTypes()
292 {
293 }
294
296
299
300 inline void setReturnType(const ExprType &type)
301 {
302 _retType = type;
303 _retTypeSet = true;
304 };
305
306 inline bool isReturnTypeSet() const
307 {
308 return _retTypeSet;
309 };
310
311 inline ExprType returnType() const
312 {
313 return (_retTypeSet ? _retType : ExprType().Error().Varying());
314 };
315
316 inline ExprType argType(int i) const
317 {
318 return _argTypes[i];
319 };
320 inline const ExprNode *arg(int i) const
321 {
322 return child(i);
323 };
324
325 const std::string &name() const
326 {
327 return _name;
328 }
329
331 int buildInterpreter(Interpreter *interpreter) const override;
334 int interpreterOps(int c) const
335 {
336 return _interpreterOps.at(c);
337 }
338
339private:
340 std::string _name;
343 std::vector<ExprType> _argTypes;
344 mutable std::vector<int> _interpreterOps; // operands for interpreter // TODO: this sucks... maybe a better place
345 // for this.
346};
347
348class ExprFuncNode;
351{
352public:
357
364 {
365 return dynamic_cast<const ExprPrototypeNode *>(child(0));
366 }
367
369 int buildInterpreter(Interpreter *interpreter) const override;
373
374private:
375 mutable int _procedurePC{};
376 mutable int _returnedDataOp{};
377};
378
381{
382public:
384 : ExprNode(expr, a, b)
385 {
386 }
387
389 int buildInterpreter(Interpreter *interpreter) const override;
391};
392
411
414{
415public:
417 : ExprNode(expr, e)
418 , _name(name)
419 {
420 }
421
423 int buildInterpreter(Interpreter *interpreter) const override;
424 // virtual void eval(Vec3d& result) const;
426
427 const std::string &name() const
428 {
429 return _name;
430 };
431 const ExprType &assignedType() const
432 {
433 return _assignedType;
434 };
435 const ExprLocalVar *localVar() const
436 {
437 return _localVar;
438 }
439
440private:
441 std::string _name;
444};
445
446// TODO three scalars? Or 2 to 16 scalars??
448class ExprVecNode : public ExprNode
449{
450public:
452 : ExprNode(expr)
453 {
454 }
455
457 int buildInterpreter(Interpreter *interpreter) const override;
459
460 Vec3d value() const;
461};
462
465{
466public:
469 : ExprNode(expr, a)
470 , _op(op)
471 {
472 }
473
475 int buildInterpreter(Interpreter *interpreter) const override;
477
478 char _op;
479};
480
482class ExprCondNode : public ExprNode
483{
484public:
486 : ExprNode(expr, a, b, c)
487 {
488 }
489
491 int buildInterpreter(Interpreter *interpreter) const override;
493};
494
508
511{
512public:
514 : ExprNode(expr, a, b)
515 , _op(op)
516 {
517 }
518
520 int buildInterpreter(Interpreter *interpreter) const override;
522
523 char _op;
524};
525
528{
529public:
531 : ExprNode(expr, a, b)
532 , _op(op)
533 {
534 }
535
537 int buildInterpreter(Interpreter *interpreter) const override;
539
541 char _op;
542};
543
546{
547public:
549 : ExprNode(expr, a, b)
550 , _op(op)
551 {
552 }
558 {
559 delete _out;
560 }
561
563 int buildInterpreter(Interpreter *interpreter) const override;
565
566 char _op;
567 char *_out{nullptr};
568};
569
571class ExprVarNode : public ExprNode
572{
573public:
574 ExprVarNode(const Expression *expr, const char *name)
575 : ExprNode(expr)
576 , _name(name)
577 {
578 }
579
580 ExprVarNode(const Expression *expr, const char *name, const ExprType &type)
581 : ExprNode(expr, type)
582 , _name(name)
583 {
584 }
585
587 int buildInterpreter(Interpreter *interpreter) const override;
589 const char *name() const
590 {
591 return _name.c_str();
592 }
593 const ExprLocalVar *localVar() const
594 {
595 return _localVar;
596 }
597 const ExprVarRef *var() const
598 {
599 return _var;
600 }
601
602private:
603 std::string _name;
605 ExprVarRef *_var{nullptr};
606};
607
609class ExprNumNode : public ExprNode
610{
611public:
612 ExprNumNode(const Expression *expr, double val)
613 : ExprNode(expr)
614 , _val(val)
615 {
616 }
617
619 int buildInterpreter(Interpreter *interpreter) const override;
621 double value() const
622 {
623 return _val;
624 };
625
626private:
627 double _val;
628};
629
631class ExprStrNode : public ExprNode
632{
633public:
634 ExprStrNode(const Expression *expr, const char *str);
635
637 int buildInterpreter(Interpreter *interpreter) const override;
639 const char *str() const
640 {
641 return _str.c_str();
642 }
643 void str(const char *newstr)
644 {
645 _str = newstr;
646 }
647
648private:
649 std::string _str;
650};
651
653class ExprFuncNode : public ExprNode
654{
655public:
656 ExprFuncNode(const Expression *expr, const char *name)
657 : ExprNode(expr)
658 , _name(name)
659 {
660 expr->addFunc(name);
661 }
662 ExprFuncNode(const ExprFuncNode &) = default;
666
667 ~ExprFuncNode() override
668 {
669 if (_data != nullptr && _data->_cleanup == true) {
670 delete _data;
671 }
672 }
673
675 int buildInterpreter(Interpreter *interpreter) const override;
677
678 const char *name() const
679 {
680 return _name.c_str();
681 }
683
684#if 0
685 virtual void eval(Vec3d& result) const;
686 void setIsVec(bool isVec) { _isVec = isVec; }
687
689 int nargs() const { return _nargs; }
690
691#if 0
692 double* scalarArgs() const { return &_scalarArgs[0]; }
693 Vec3d* vecArgs() const { return &_vecArgs[0]; }
694
696 Vec3d* evalArgs() const;
697
699 Vec3d evalArg(int n) const;
700
702 bool isStrArg(int n) const;
703
705 std::string getStrArg(int n) const;
706#endif
707
708#endif
709
710 // TODO: Remove those two methods.
711 bool isStrArg(int n) const
712 {
714 }
715 std::string getStrArg(int n) const
716 {
717 if (n < numChildren())
718 return static_cast<const ExprStrNode *>(child(n))->str();
719 return "";
720 }
721
723 struct Data {
724 Data(bool cleanup = false)
725 : _cleanup(cleanup)
726 {
727 }
728 Data(const Data &) = default;
729 Data &operator=(const Data &) = default;
730 Data(Data &&) = default;
731 Data &operator=(Data &&) = default;
732 virtual ~Data() = default;
734 };
735
737 /***
738 Use this to set data associated with the node. Equivalently this is data
739 associated with a specific evaluation point of a function.
740 Examples would be tokenized values,
741 sorted lists for binary searches in curve evaluation, etc. This should be done
742 in ExprFuncX::prep().
743 */
744 void setData(Data *data) const
745 {
746 _data = data;
747 }
748
750 /***
751 Use this to get data associated in the prep() routine. This is typically
752 used from ExprFuncX::eval()
753 */
754 Data *getData() const
755 {
756 return _data;
757 }
758 int promote(int i) const
759 {
760 return _promote[i];
761 }
762 const ExprFunc *func() const
763 {
764 return _func;
765 }
766
767private:
768 std::string _name;
769 const ExprFunc *_func {nullptr};
770 const ExprLocalFunctionNode *_localFunc {nullptr}; // TODO: it is dirty to have to have both.
771 // int _nargs;
772 // mutable std::vector<double> _scalarArgs;
773 // mutable std::vector<Vec3d> _vecArgs;
774 mutable std::vector<int> _promote;
775 mutable Data *_data {nullptr};
776};
777
800} // namespace KSeExpr
void eval(ArgHandle args) override
double LLVM_BUILDER
Definition ExprLLVM.h:26
#define LLVM_BODY
Definition ExprLLVM.h:28
#define LLVM_BASE
Definition ExprLLVM.h:27
double LLVM_VALUE
Definition ExprLLVM.h:25
Node that compute a local variable assignment.
Definition ExprNode.h:414
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:337
ExprLocalVar * _localVar
Definition ExprNode.h:442
const std::string & name() const
Definition ExprNode.h:427
ExprAssignNode(const Expression *expr, const char *name, ExprNode *e)
Definition ExprNode.h:416
const ExprType & assignedType() const
Definition ExprNode.h:431
const ExprLocalVar * localVar() const
Definition ExprNode.h:435
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Node that implements an binary operator.
Definition ExprNode.h:546
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
ExprBinaryOpNode(const ExprBinaryOpNode &)=default
ExprBinaryOpNode & operator=(const ExprBinaryOpNode &)=default
ExprBinaryOpNode & operator=(ExprBinaryOpNode &&)=default
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:507
ExprBinaryOpNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Definition ExprNode.h:548
~ExprBinaryOpNode() override
Definition ExprNode.h:557
ExprBinaryOpNode(ExprBinaryOpNode &&)=default
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Node that computes local variables before evaluating expression.
Definition ExprNode.h:381
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:284
ExprBlockNode(const Expression *expr, ExprNode *a, ExprNode *b)
Definition ExprNode.h:383
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
Node that implements a numeric/string comparison.
Definition ExprNode.h:511
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprCompareEqNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Definition ExprNode.h:513
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:458
Node that implements a numeric comparison.
Definition ExprNode.h:528
char _op
_op '<' less-than, 'l' less-than-eq, '>' greater-than, 'g' greater-than-eq
Definition ExprNode.h:541
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprCompareNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Definition ExprNode.h:530
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:482
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
Node that evaluates a conditional (if-then-else) expression.
Definition ExprNode.h:483
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:403
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
ExprCondNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
Definition ExprNode.h:485
Node that calls a function.
Definition ExprNode.h:654
bool isStrArg(int n) const
Definition ExprNode.h:711
std::string _name
Definition ExprNode.h:768
bool checkArg(int argIndex, const ExprType &type, ExprVarEnvBuilder &envBuilder)
Definition ExprNode.cpp:631
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:585
void setData(Data *data) const
associate blind data with this node (subsequently owned by this object)
Definition ExprNode.h:744
ExprFuncNode(const Expression *expr, const char *name)
Definition ExprNode.h:656
ExprFuncNode & operator=(const ExprFuncNode &)=default
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
Definition ExprNode.cpp:620
std::vector< int > _promote
Definition ExprNode.h:774
Data * getData() const
get associated blind data (returns 0 if none)
Definition ExprNode.h:754
ExprFuncNode(ExprFuncNode &&)=default
int promote(int i) const
Definition ExprNode.h:758
std::string getStrArg(int n) const
Definition ExprNode.h:715
const ExprFunc * _func
Definition ExprNode.h:769
const ExprFunc * func() const
Definition ExprNode.h:762
ExprFuncNode(const ExprFuncNode &)=default
const char * name() const
Definition ExprNode.h:678
~ExprFuncNode() override
Definition ExprNode.h:667
ExprFuncNode & operator=(ExprFuncNode &&)=default
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const ExprLocalFunctionNode * _localFunc
Definition ExprNode.h:770
Function Definition, used in parse tree and func table.
Definition ExprFunc.h:35
Node that computes local variables before evaluating expression.
Definition ExprNode.h:395
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:297
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprIfThenElseNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
Definition ExprNode.h:397
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
Node that contains local function.
Definition ExprNode.h:351
int buildInterpreter(Interpreter *interpreter) const override
Build the interpreter.
int buildInterpreterForCall(const ExprFuncNode *callerNode, Interpreter *interpreter) const
Build interpreter if we are called.
const ExprPrototypeNode * prototype() const
TODO: Accessor for prototype (probably not needed when we use prep right)
Definition ExprNode.h:363
ExprLocalFunctionNode(const Expression *expr, ExprPrototypeNode *prototype, ExprNode *block)
Definition ExprNode.h:353
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Preps the definition of this site.
Definition ExprNode.cpp:212
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprLocalVar reference, all local variables in seexpr are subclasses of this or this itself.
Definition ExprEnv.h:28
Node that contains entire program.
Definition ExprNode.h:262
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:146
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprModuleNode(const Expression *expr)
Definition ExprNode.h:264
Policy which provides all the AST Types for the parser.
Definition ExprNode.h:780
std::unique_ptr< Base * > Ptr
Definition ExprNode.h:782
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
Definition ExprNode.cpp:112
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BASE
void setPosition(const short int startPos, const short int endPos)
Remember the line and column position in the input string.
Definition ExprNode.h:158
unsigned short int _startPos
Position line and collumn.
Definition ExprNode.h:257
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
Definition ExprNode.cpp:121
void swapChildren(size_t i, size_t j)
Swap children, do not use unless you know what you are doing.
Definition ExprNode.h:126
std::string toString() const
Access to original string representation of current expression.
Definition ExprNode.h:95
unsigned short int endPos() const
Access end position in input string.
Definition ExprNode.h:169
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
bool _isVec
True if node has a vector result.
Definition ExprNode.h:250
virtual ~ExprNode()
Definition ExprNode.cpp:98
ExprNode * child(size_t i)
Get 0 indexed child.
Definition ExprNode.h:120
bool checkIsFP(const ExprType &type, bool &error) const
Checks if the type is a float[d] for any d.
Definition ExprNode.h:224
void setTypeWithChildLife(const ExprType &t)
Set's the type to the argument but uses the children to determine lifetime.
Definition ExprNode.h:194
unsigned short int startPos() const
Access start position in input string.
Definition ExprNode.h:164
bool checkIsFP(int d, const ExprType &type, bool &error) const
Checks if the type is a float[d] for a specific d.
Definition ExprNode.h:229
const ExprType & type() const
The type of the node.
Definition ExprNode.h:150
int numChildren() const
Number of children.
Definition ExprNode.h:108
bool checkCondition(bool check, const ErrorCode message, const std::vector< std::string > &ids, bool &error) const
Checks the boolean value and records an error string with node if it is false.
Definition ExprNode.h:210
void removeLastChild()
Remove last child and delete the entry.
Definition ExprNode.h:133
unsigned short int _endPos
Definition ExprNode.h:257
std::vector< ExprNode * > _children
List of children.
Definition ExprNode.h:247
bool checkIsValue(const ExprType &type, bool &error) const
Checks if the type is a value (i.e. string or float[d])
Definition ExprNode.h:219
const ExprNode * child(size_t i) const
Get 0 indexed child.
Definition ExprNode.h:114
const Expression * expr() const
Access expression.
Definition ExprNode.h:89
bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error) const
types match (true if they do)
Definition ExprNode.h:234
const ExprNode * parent() const
Access parent node - root node has no parent.
Definition ExprNode.h:103
void addError(const ErrorCode error, const std::vector< std::string > &ids={}) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
Definition ExprNode.h:182
ExprNode * _parent
Parent node (null if this the the root)
Definition ExprNode.h:244
const Expression * _expr
Owning expression (node can't modify)
Definition ExprNode.h:241
void setType(const ExprType &t)
Set type of parameter.
Definition ExprNode.h:189
bool isVec() const
True if node has a vector result.
Definition ExprNode.h:83
void addChild(ExprNode *child)
Add a child to the child list (for parser use only)
Definition ExprNode.cpp:106
unsigned short int length() const
Access length of input string.
Definition ExprNode.h:174
Node that stores a numeric constant.
Definition ExprNode.h:610
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
double value() const
Definition ExprNode.h:621
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:567
ExprNumNode(const Expression *expr, double val)
Definition ExprNode.h:612
Node that contains prototype of function.
Definition ExprNode.h:276
std::vector< ExprType > _argTypes
Definition ExprNode.h:343
void addArgs(ExprNode *surrogate)
Definition ExprNode.cpp:196
ExprType returnType() const
Definition ExprNode.h:311
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:160
int interpreterOps(int c) const
Return op for interpreter.
Definition ExprNode.h:334
ExprPrototypeNode(const Expression *expr, const std::string &name)
Definition ExprNode.h:287
void setReturnType(const ExprType &type)
Definition ExprNode.h:300
ExprType argType(int i) const
Definition ExprNode.h:316
int buildInterpreter(Interpreter *interpreter) const override
Build the interpreter.
const ExprNode * arg(int i) const
Definition ExprNode.h:320
void addArgTypes(ExprNode *surrogate)
Definition ExprNode.cpp:188
bool isReturnTypeSet() const
Definition ExprNode.h:306
const std::string & name() const
Definition ExprNode.h:325
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
std::vector< int > _interpreterOps
Definition ExprNode.h:344
ExprPrototypeNode(const Expression *expr, const std::string &name, const ExprType &retType)
Definition ExprNode.h:278
Node that stores a string.
Definition ExprNode.h:632
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
std::string _str
Definition ExprNode.h:649
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const char * str() const
Definition ExprNode.h:639
void str(const char *newstr)
Definition ExprNode.h:643
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:579
Node that evaluates a component of a vector.
Definition ExprNode.h:497
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:436
ExprSubscriptNode(const Expression *expr, ExprNode *a, ExprNode *b)
Definition ExprNode.h:499
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
ExprType & Constant()
Mutate this into a constant lifetime.
Definition ExprType.h:122
ExprType & Varying()
Mutate this into a varying lifetime.
Definition ExprType.h:134
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
Definition ExprType.h:150
ExprType & Error()
Mutate this into an error type.
Definition ExprType.h:111
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
Definition ExprType.h:220
NOde that computes with a single operand.
Definition ExprNode.h:465
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:389
ExprUnaryOpNode(const Expression *expr, ExprNode *a, char op)
Construct with specific op ('!x' is logical negation, '~x' is 1-x, '-x' is -x)
Definition ExprNode.h:468
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
Definition ExprEnv.h:181
Variable scope for tracking variable lookup.
Definition ExprEnv.h:120
Node that references a variable.
Definition ExprNode.h:572
std::string _name
Definition ExprNode.h:603
const ExprLocalVar * localVar() const
Definition ExprNode.h:593
ExprVarRef * _var
Definition ExprNode.h:605
ExprVarNode(const Expression *expr, const char *name, const ExprType &type)
Definition ExprNode.h:580
ExprLocalVar * _localVar
Definition ExprNode.h:604
ExprVarNode(const Expression *expr, const char *name)
Definition ExprNode.h:574
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const ExprVarRef * var() const
Definition ExprNode.h:597
const char * name() const
Definition ExprNode.h:589
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:531
abstract class for implementing variable references
Definition Expression.h:36
Node that constructs a vector from three scalars.
Definition ExprNode.h:449
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Definition ExprNode.cpp:354
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Vec3d value() const
Definition ExprNode.cpp:373
ExprVecNode(const Expression *expr)
Definition ExprNode.h:451
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
main expression class
Definition Expression.h:67
@ ExpectedStringOrFloatAnyD
"Expected String or Float[d]"
Definition ErrorCode.h:12
@ ExpectedFloatAnyD
"Expected Float[d]"
Definition ErrorCode.h:14
@ ExpectedFloatD
"Expected Float[" << d << "]"
Definition ErrorCode.h:16
@ TypeMismatch12
"Type mismatch. First: " << first << " Second: " << second
Definition ErrorCode.h:18
Vec< double, 3, false > Vec3d
Definition Vec.h:352
base class for custom instance data
Definition ExprNode.h:723
Data(bool cleanup=false)
Definition ExprNode.h:724
Data & operator=(Data &&)=default
Data(const Data &)=default
virtual ~Data()=default
Data & operator=(const Data &)=default