SeExpr
ExprNode.h
Go to the documentation of this file.
1 /*
2  Copyright Disney Enterprises, Inc. All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License
6  and the following modification to it: Section 6 Trademarks.
7  deleted and replaced with:
8 
9  6. Trademarks. This License does not grant permission to use the
10  trade names, trademarks, service marks, or product names of the
11  Licensor and its affiliates, except as required for reproducing
12  the content of the NOTICE file.
13 
14  You may obtain a copy of the License at
15  http://www.apache.org/licenses/LICENSE-2.0
16 */
17 
18 #ifndef ExprNode_h
19 #define ExprNode_h
20 
21 #include <cstdlib>
22 
23 // TODO: get rid of makedepends everywhere
24 #ifndef MAKEDEPEND
25 #include <string.h>
26 #include <string>
27 #include <vector>
28 #endif
29 
30 #include "ExprConfig.h"
31 #include "ExprLLVM.h"
32 #include "Expression.h"
33 #include "ExprType.h"
34 #include "ExprEnv.h"
35 #include "Vec.h"
36 #include "Interpreter.h"
37 
38 namespace SeExpr2 {
39 class ExprFunc;
40 class ExprFuncX;
41 
72 class ExprNode {
73  public:
74  ExprNode(const Expression* expr);
75  ExprNode(const Expression* expr, const ExprType& type);
77  ExprNode(const Expression* expr, ExprNode* a);
78  ExprNode(const Expression* expr, ExprNode* a, const ExprType& type);
80  ExprNode(const Expression* expr, ExprNode* a, ExprNode* b, const ExprType& type);
82  ExprNode(const Expression* expr, ExprNode* a, ExprNode* b, ExprNode* c, const ExprType& type);
84  virtual ~ExprNode();
85 
87 
90  virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder& envBuilder);
91 
93  virtual int buildInterpreter(Interpreter* interpreter) const;
95 
97 
99  bool isVec() const { return _isVec; }
100 
102  const Expression* expr() const { return _expr; }
103 
105  std::string toString() const {
106  return expr()->getExpr().substr(startPos(), length());
107  };
108 
110 
112  const ExprNode* parent() const { return _parent; }
114  int numChildren() const { return static_cast<int>(_children.size()); }
115 
117  const ExprNode* child(size_t i) const { return _children[i]; }
118 
120  ExprNode* child(size_t i) { return _children[i]; }
121 
123  void swapChildren(size_t i, size_t j) {
124  assert(i != j && i < _children.size() && j < _children.size());
125  std::swap(_children[i], _children[j]);
126  }
127 
130  if (_children.size()) {
131  delete _children.back();
132  _children.pop_back();
133  }
134  }
135 
137  void addChild(ExprNode* child);
138 
140  void addChildren(ExprNode* surrogate);
141 
143 
145  const ExprType& type() const {
146  return _type;
147  };
148 
150 
152  inline void setPosition(const short int startPos, const short int endPos) {
154  _endPos = endPos;
155  }
157  inline short int startPos() const { return _startPos; }
159  inline short int endPos() const { return _endPos; }
161  inline short int length() const {
162  return endPos() - startPos();
163  };
164 
166 
168  inline void addError(const std::string& error) const { _expr->addError(error, _startPos, _endPos); }
169 
170  protected: /*protected functions*/
172  inline void setType(const ExprType& t) {
173  _type = t;
174  };
176  inline void setTypeWithChildLife(const ExprType& t) {
177  setType(t);
178  int num = numChildren();
179  if (num > 0) {
180  _type.setLifetime(child(0)->type());
181  for (int i = 1; i < num; i++) _type.setLifetime(_type, child(i)->type());
182  } else // no children life is constant!
183  _type.Constant();
184  };
185 
187 
188  public:
190  inline bool checkCondition(bool check, const std::string& message, bool& error) {
191  if (!check) {
192  addError(message);
193  error = true;
194  }
195  return check;
196  };
198  bool checkIsValue(const ExprType& type, bool& error) {
199  return checkCondition(type.isValue(), "Expected String or Float[d]", error);
200  }
202  bool checkIsFP(const ExprType& type, bool& error) {
203  return checkCondition(type.isFP(), "Expected Float[d]", error);
204  }
206  bool checkIsFP(int d, const ExprType& type, bool& error) {
207  if (!type.isFP(d)) { // Defer creating expensive string creation unless error
208  std::stringstream s;
209  s << "Expected Float[" << d << "]" << std::endl;
210  return checkCondition(false, s.str(), error);
211  }
212  return false;
213  }
215  inline bool checkTypesCompatible(const ExprType& first, const ExprType& second, bool& error) {
216  if (!ExprType::valuesCompatible(first, second)) {
217  return checkCondition(
218  false, "Type mismatch. First: " + first.toString() + " Second: " + second.toString(), error);
219  } else
220  return false;
221  }
223  protected: /*protected data members*/
226 
229 
231  std::vector<ExprNode*> _children;
232 
234  bool _isVec;
235 
236  // Type of node
239 
241  unsigned short int _startPos, _endPos;
242 };
243 
245 class ExprModuleNode : public ExprNode {
246  public:
248 
249  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
250  virtual int buildInterpreter(Interpreter* interpreter) const;
252 };
253 
255 class ExprPrototypeNode : public ExprNode {
256  public:
257  ExprPrototypeNode(const Expression* expr, const std::string& name, const ExprType& retType)
258  : ExprNode(expr), _name(name), _retTypeSet(true), _retType(retType), _argTypes() {}
259 
260  ExprPrototypeNode(const Expression* expr, const std::string& name)
261  : ExprNode(expr), _name(name), _retTypeSet(false), _argTypes() {}
262 
263  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
264 
265  void addArgTypes(ExprNode* surrogate);
266  void addArgs(ExprNode* surrogate);
267 
268  inline void setReturnType(const ExprType& type) {
269  _retType = type;
270  _retTypeSet = true;
271  };
272 
273  inline bool isReturnTypeSet() const {
274  return _retTypeSet;
275  };
276 
277  inline ExprType returnType() const {
278  return (_retTypeSet ? _retType : ExprType().Error().Varying());
279  };
280 
281  inline ExprType argType(int i) const {
282  return _argTypes[i];
283  };
284  inline const ExprNode* arg(int i) const {
285  return child(i);
286  };
287 
288  const std::string& name() const { return _name; }
289 
291  int buildInterpreter(Interpreter* interpreter) const;
294  int interpreterOps(int c) const { return _interpreterOps.at(c); }
295 
296  private:
297  std::string _name;
300  std::vector<ExprType> _argTypes;
301  mutable std::vector<int> _interpreterOps; // operands for interpreter // TODO: this sucks... maybe a better place
302  // for this.
303 };
304 
305 class ExprFuncNode;
308  public:
310  : ExprNode(expr, prototype, block) {}
311 
313  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
315  virtual ExprType prep(ExprFuncNode* callerNode, bool scalarWanted, ExprVarEnvBuilder& envBuilder) const;
317  const ExprPrototypeNode* prototype() const { return static_cast<const ExprPrototypeNode*>(child(0)); }
318 
320  int buildInterpreter(Interpreter* interpreter) const;
322  int buildInterpreterForCall(const ExprFuncNode* callerNode, Interpreter* interpreter) const;
324 
325  private:
326  mutable int _procedurePC;
327  mutable int _returnedDataOp;
328 };
329 
331 class ExprBlockNode : public ExprNode {
332  public:
334 
335  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
336  virtual int buildInterpreter(Interpreter* interpreter) const;
338 };
339 
341 class ExprIfThenElseNode : public ExprNode {
342  public:
344  : ExprNode(expr, a, b, c), _varEnv(nullptr), _varEnvMergeIndex(0) {}
345 
346  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
347  virtual int buildInterpreter(Interpreter* interpreter) const;
349 
352 };
353 
355 class ExprAssignNode : public ExprNode {
356  public:
357  ExprAssignNode(const Expression* expr, const char* name, ExprNode* e)
358  : ExprNode(expr, e), _name(name), _localVar(0) {}
359 
360  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
361  virtual int buildInterpreter(Interpreter* interpreter) const;
362  // virtual void eval(Vec3d& result) const;
364 
365  const std::string& name() const {
366  return _name;
367  };
368  const ExprType& assignedType() const {
369  return _assignedType;
370  };
371  const ExprLocalVar* localVar() const { return _localVar; }
372 
373  private:
374  std::string _name;
377 };
378 
379 // TODO three scalars? Or 2 to 16 scalars??
381 class ExprVecNode : public ExprNode {
382  public:
384 
385  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
386  virtual int buildInterpreter(Interpreter* interpreter) const;
388 
389  Vec3d value() const;
390 };
391 
393 class ExprUnaryOpNode : public ExprNode {
394  public:
396  ExprUnaryOpNode(const Expression* expr, ExprNode* a, char op) : ExprNode(expr, a), _op(op) {}
397 
398  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
399  virtual int buildInterpreter(Interpreter* interpreter) const;
401 
402  char _op;
403 };
404 
406 class ExprCondNode : public ExprNode {
407  public:
409 
410  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
411  virtual int buildInterpreter(Interpreter* interpreter) const;
413 };
414 
416 class ExprSubscriptNode : public ExprNode {
417  public:
419 
420  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
421  virtual int buildInterpreter(Interpreter* interpreter) const;
423 };
424 
426 class ExprCompareEqNode : public ExprNode {
427  public:
428  ExprCompareEqNode(const Expression* expr, ExprNode* a, ExprNode* b, char op) : ExprNode(expr, a, b), _op(op) {}
429 
430  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
431  virtual int buildInterpreter(Interpreter* interpreter) const;
433 
434  char _op;
435 };
436 
438 class ExprCompareNode : public ExprNode {
439  public:
440  ExprCompareNode(const Expression* expr, ExprNode* a, ExprNode* b, char op) : ExprNode(expr, a, b), _op(op) {}
441 
442  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
443  virtual int buildInterpreter(Interpreter* interpreter) const;
445 
447  char _op;
448 };
449 
451 class ExprBinaryOpNode : public ExprNode {
452  public:
453  ExprBinaryOpNode(const Expression* expr, ExprNode* a, ExprNode* b, char op) : ExprNode(expr, a, b), _op(op), _out(0) {}
454  virtual ~ExprBinaryOpNode() { free(_out); }
455 
456  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
457  virtual int buildInterpreter(Interpreter* interpreter) const;
459 
460  char _op;
461  char* _out;
462 };
463 
465 class ExprVarNode : public ExprNode {
466  public:
467  ExprVarNode(const Expression* expr, const char* name) : ExprNode(expr), _name(name), _localVar(0), _var(0) {}
468 
469  ExprVarNode(const Expression* expr, const char* name, const ExprType& type)
470  : ExprNode(expr, type), _name(name), _localVar(0), _var(0) {}
471 
472  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
473  virtual int buildInterpreter(Interpreter* interpreter) const;
475  const char* name() const { return _name.c_str(); }
476  const ExprLocalVar* localVar() const { return _localVar; }
477  const ExprVarRef* var() const { return _var; }
478 
479  private:
480  std::string _name;
483 };
484 
486 class ExprNumNode : public ExprNode {
487  public:
488  ExprNumNode(const Expression* expr, double val) : ExprNode(expr), _val(val) {}
489 
490  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
491  virtual int buildInterpreter(Interpreter* interpreter) const;
493  double value() const {
494  return _val;
495  };
496 
497  private:
498  double _val;
499 };
500 
502 class ExprStrNode : public ExprNode {
503  public:
504  ExprStrNode(const Expression* expr, const char* str);
505 
506  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
507  virtual int buildInterpreter(Interpreter* interpreter) const;
509  const char* str() const { return _str.c_str(); }
510  void str(const char* newstr) { _str = newstr; }
511 
512  private:
513  std::string _str;
514 };
515 
517 class ExprFuncNode : public ExprNode {
518  public:
519  ExprFuncNode(const Expression* expr, const char* name)
520  : ExprNode(expr), _name(name), _func(0), _localFunc(0), _data(0) {
521  expr->addFunc(name);
522  }
523  virtual ~ExprFuncNode() {
524  if (_data != nullptr && _data->_cleanup == true) {
525  delete _data;
526  }
527  }
528 
529  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
530  virtual int buildInterpreter(Interpreter* interpreter) const;
532 
533  const char* name() const { return _name.c_str(); }
534  bool checkArg(int argIndex, ExprType type, ExprVarEnvBuilder& envBuilder);
535 
536 #if 0
537  virtual void eval(Vec3d& result) const;
538  void setIsVec(bool isVec) { _isVec = isVec; }
539 
541  int nargs() const { return _nargs; }
542 
543 #if 0
544  double* scalarArgs() const { return &_scalarArgs[0]; }
545  Vec3d* vecArgs() const { return &_vecArgs[0]; }
546 
548  Vec3d* evalArgs() const;
549 
551  Vec3d evalArg(int n) const;
552 
554  bool isStrArg(int n) const;
555 
557  std::string getStrArg(int n) const;
558 #endif
559 
560 #endif
561 
562  // TODO: Remove those two methods.
563  bool isStrArg(int n) const { return n < numChildren() && dynamic_cast<const ExprStrNode*>(child(n)) != 0; }
564  std::string getStrArg(int n) const {
565  if (n < numChildren()) return static_cast<const ExprStrNode*>(child(n))->str();
566  return "";
567  }
568 
570  struct Data {
571  Data(bool cleanup = false) : _cleanup(cleanup) {}
572  virtual ~Data() {}
573  bool _cleanup;
574  };
575 
577  /***
578  Use this to set data associated with the node. Equivalently this is data
579  associated with a specific evaluation point of a function.
580  Examples would be tokenized values,
581  sorted lists for binary searches in curve evaluation, etc. This should be done
582  in ExprFuncX::prep().
583  */
584  void setData(Data* data) const { _data = data; }
585 
587  /***
588  Use this to get data associated in the prep() routine. This is typically
589  used from ExprFuncX::eval()
590  */
591  Data* getData() const { return _data; }
592  int promote(int i) const { return _promote[i]; }
593  const ExprFunc* func() const { return _func; }
594 
595  private:
596  std::string _name;
597  const ExprFunc* _func;
598  const ExprLocalFunctionNode* _localFunc; // TODO: it is dirty to have to have both.
599  // int _nargs;
600  // mutable std::vector<double> _scalarArgs;
601  // mutable std::vector<Vec3d> _vecArgs;
602  mutable std::vector<int> _promote;
603  mutable Data* _data;
604 };
605 
608  typedef ExprNode Base;
609  // TODO: fix this once we switch to a c++11 compiler
610  // typedef std::unique_ptr<Base*> Ptr;
611 
618  typedef ExprVecNode Vec;
624  typedef ExprVarNode Var;
625  typedef ExprNumNode Num;
626  typedef ExprStrNode Str;
628 };
629 }
630 
631 #endif
SeExpr2::ExprPrototypeNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprIfThenElseNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:270
SeExpr2::ExprFuncNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:533
SeExpr2::ExprVarNode::_localVar
ExprLocalVar * _localVar
Definition: ExprNode.h:481
SeExpr2::ExprNumNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprFuncNode::name
const char * name() const
Definition: ExprNode.h:533
SeExpr2::ExprNode::checkIsFP
bool checkIsFP(const ExprType &type, bool &error)
Checks if the type is a float[d] for any d.
Definition: ExprNode.h:202
SeExpr2::ExprCompareEqNode::_op
char _op
Definition: ExprNode.h:434
SeExpr2::ExprIfThenElseNode::ExprIfThenElseNode
ExprIfThenElseNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
Definition: ExprNode.h:343
SeExpr2::ExprLocalFunctionNode::prototype
const ExprPrototypeNode * prototype() const
TODO: Accessor for prototype (probably not needed when we use prep right)
Definition: ExprNode.h:317
SeExpr2::ExprModuleNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:1050
SeExpr2::ExprVarNode::ExprVarNode
ExprVarNode(const Expression *expr, const char *name, const ExprType &type)
Definition: ExprNode.h:469
SeExpr2::ExprCompareEqNode::ExprCompareEqNode
ExprCompareEqNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Definition: ExprNode.h:428
SeExpr2::ExprPrototypeNode::returnType
ExprType returnType() const
Definition: ExprNode.h:277
SeExpr2::ExprUnaryOpNode::_op
char _op
Definition: ExprNode.h:402
SeExpr2::ExprNodePolicy::Block
ExprBlockNode Block
Definition: ExprNode.h:615
SeExpr2::ExprNode::child
ExprNode * child(size_t i)
Get 0 indexed child.
Definition: ExprNode.h:120
SeExpr2::ExprModuleNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:127
SeExpr2::ExprFuncNode::getStrArg
std::string getStrArg(int n) const
Definition: ExprNode.h:564
SeExpr2::ExprPrototypeNode::_retType
ExprType _retType
Definition: ExprNode.h:299
SeExpr2::ExprNode::numChildren
int numChildren() const
Number of children.
Definition: ExprNode.h:114
SeExpr2::ExprCompareEqNode
Node that implements a numeric/string comparison.
Definition: ExprNode.h:426
SeExpr2::ExprPrototypeNode::_name
std::string _name
Definition: ExprNode.h:297
SeExpr2::ExprNode::type
const ExprType & type() const
The type of the node.
Definition: ExprNode.h:145
SeExpr2::ExprCompareNode
Node that implements a numeric comparison.
Definition: ExprNode.h:438
SeExpr2::ExprNode::setTypeWithChildLife
void setTypeWithChildLife(const ExprType &t)
Set's the type to the argument but uses the children to determine lifetime.
Definition: ExprNode.h:176
SeExpr2::ExprIfThenElseNode::_varEnvMergeIndex
size_t _varEnvMergeIndex
Definition: ExprNode.h:351
SeExpr2::ExprNumNode::value
double value() const
Definition: ExprNode.h:493
SeExpr2::ExprNode::length
short int length() const
Access length of input string.
Definition: ExprNode.h:161
SeExpr2::ExprNode::addError
void addError(const std::string &error) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
Definition: ExprNode.h:168
SeExpr2::ExprPrototypeNode::_retTypeSet
bool _retTypeSet
Definition: ExprNode.h:298
SeExpr2::Vec< double, 3, false >
SeExpr2::ExprNode::~ExprNode
virtual ~ExprNode()
Definition: ExprNode.cpp:84
SeExpr2::ExprLocalFunctionNode::buildInterpreter
int buildInterpreter(Interpreter *interpreter) const
Build the interpreter.
Definition: Interpreter.cpp:472
SeExpr2::ExprNodePolicy::UnaryOp
ExprUnaryOpNode UnaryOp
Definition: ExprNode.h:619
SeExpr2::ExprNodePolicy::BinaryOp
ExprBinaryOpNode BinaryOp
Definition: ExprNode.h:623
SeExpr2::ExprStrNode::ExprStrNode
ExprStrNode(const Expression *expr, const char *str)
Definition: ExprNode.cpp:525
SeExpr2::ExprFuncNode::func
const ExprFunc * func() const
Definition: ExprNode.h:593
SeExpr2::ExprUnaryOpNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:658
SeExpr2::ExprFuncNode::setData
void setData(Data *data) const
associate blind data with this node (subsequently owned by this object)
Definition: ExprNode.h:584
SeExpr2::ExprStrNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:528
SeExpr2::ExprIfThenElseNode::_varEnv
ExprVarEnv * _varEnv
Definition: ExprNode.h:350
SeExpr2::ExprFuncNode::~ExprFuncNode
virtual ~ExprFuncNode()
Definition: ExprNode.h:523
SeExpr2::ExprNumNode
Node that stores a numeric constant.
Definition: ExprNode.h:486
SeExpr2::ExprNode
Definition: ExprNode.h:72
SeExpr2::ExprFuncNode::_promote
std::vector< int > _promote
Definition: ExprNode.h:602
SeExpr2::ExprBinaryOpNode
Node that implements an binary operator.
Definition: ExprNode.h:451
SeExpr2::ExprLocalFunctionNode::_procedurePC
int _procedurePC
Definition: ExprNode.h:326
SeExpr2::ExprSubscriptNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprNode::setPosition
void setPosition(const short int startPos, const short int endPos)
Remember the line and column position in the input string.
Definition: ExprNode.h:152
Interpreter.h
SeExpr2::ExprFuncNode::Data::Data
Data(bool cleanup=false)
Definition: ExprNode.h:571
LLVM_BUILDER
double LLVM_BUILDER
Definition: ExprLLVM.h:34
SeExpr2::ExprNodePolicy
Policy which provides all the AST Types for the parser.
Definition: ExprNode.h:607
SeExpr2::ExprNodePolicy::Vec
ExprVecNode Vec
Definition: ExprNode.h:618
SeExpr2::ExprVarNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprNodePolicy::CompareEq
ExprCompareEqNode CompareEq
Definition: ExprNode.h:621
SeExpr2::ExprAssignNode::_name
std::string _name
Definition: ExprNode.h:374
SeExpr2::ExprSubscriptNode::ExprSubscriptNode
ExprSubscriptNode(const Expression *expr, ExprNode *a, ExprNode *b)
Definition: ExprNode.h:418
SeExpr2::ExprCondNode::ExprCondNode
ExprCondNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
Definition: ExprNode.h:408
SeExpr2::Expression::addFunc
void addFunc(const char *n) const
add function evaluation (this is for internal use)
Definition: Expression.h:321
SeExpr2::ExprNode::_startPos
unsigned short int _startPos
Position line and collumn.
Definition: ExprNode.h:241
SeExpr2::ExprStrNode::str
const char * str() const
Definition: ExprNode.h:509
SeExpr2::ExprFuncNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprVarNode::var
const ExprVarRef * var() const
Definition: ExprNode.h:477
SeExpr2::ExprVarNode::name
const char * name() const
Definition: ExprNode.h:475
SeExpr2::ExprNode::toString
std::string toString() const
Access to original string representation of current expression.
Definition: ExprNode.h:105
SeExpr2::ExprType::Constant
ExprType & Constant()
Mutate this into a constant lifetime.
Definition: ExprType.h:112
SeExpr2::ExprUnaryOpNode
NOde that computes with a single operand.
Definition: ExprNode.h:393
SeExpr2::ExprType::isValue
bool isValue() const
Definition: ExprType.h:166
SeExpr2::ExprCompareNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprNodePolicy::Prototype
ExprPrototypeNode Prototype
Definition: ExprNode.h:613
SeExpr2::ExprCompareEqNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:931
SeExpr2::ExprCondNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:370
SeExpr2::ExprNumNode::ExprNumNode
ExprNumNode(const Expression *expr, double val)
Definition: ExprNode.h:488
SeExpr2::ExprSubscriptNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:400
SeExpr2::ExprPrototypeNode::_interpreterOps
std::vector< int > _interpreterOps
Definition: ExprNode.h:301
SeExpr2::ExprBinaryOpNode::_out
char * _out
Definition: ExprNode.h:461
SeExpr2::ExprNode::_parent
ExprNode * _parent
Parent node (null if this the the root)
Definition: ExprNode.h:228
SeExpr2::ExprType
Definition: ExprType.h:39
SeExpr2::ExprNodePolicy::IfThenElse
ExprIfThenElseNode IfThenElse
Definition: ExprNode.h:616
SeExpr2::ExprFuncNode
Node that calls a function.
Definition: ExprNode.h:517
SeExpr2::ExprCompareNode::_op
char _op
_op '<' less-than, 'l' less-than-eq, '>' greater-than, 'g' greater-than-eq
Definition: ExprNode.h:447
SeExpr2::ExprUnaryOpNode::ExprUnaryOpNode
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:396
SeExpr2::ExprNode::isVec
bool isVec() const
True if node has a vector result.
Definition: ExprNode.h:99
SeExpr2::ExprPrototypeNode::interpreterOps
int interpreterOps(int c) const
Return op for interpreter.
Definition: ExprNode.h:294
SeExpr2::ExprNode::checkIsFP
bool checkIsFP(int d, const ExprType &type, bool &error)
Checks if the type is a float[d] for a specific d.
Definition: ExprNode.h:206
SeExpr2::ExprNodePolicy::Func
ExprFuncNode Func
Definition: ExprNode.h:627
SeExpr2::ExprFunc
Function Definition, used in parse tree and func table.
Definition: ExprFunc.h:44
SeExpr2::ExprAssignNode
Node that compute a local variable assignment.
Definition: ExprNode.h:355
SeExpr2::ExprPrototypeNode
Node that contains prototype of function.
Definition: ExprNode.h:255
SeExpr2::ExprCompareNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:441
SeExpr2::ExprBinaryOpNode::~ExprBinaryOpNode
virtual ~ExprBinaryOpNode()
Definition: ExprNode.h:454
SeExpr2::ExprCondNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprVarEnv
Variable scope for tracking variable lookup.
Definition: ExprEnv.h:94
SeExpr2::ExprNumNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:543
SeExpr2::ExprVarNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:699
SeExpr2::ExprFuncNode::Data::~Data
virtual ~Data()
Definition: ExprNode.h:572
SeExpr2::ExprLocalFunctionNode::buildInterpreterForCall
int buildInterpreterForCall(const ExprFuncNode *callerNode, Interpreter *interpreter) const
Build interpreter if we are called.
Definition: Interpreter.cpp:487
LLVM_VALUE
double LLVM_VALUE
Definition: ExprLLVM.h:33
SeExpr2::ExprNode::_maxChildDim
int _maxChildDim
Definition: ExprNode.h:238
SeExpr2::ExprFuncNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: ExprNode.cpp:568
SeExpr2
Definition: Context.h:22
SeExpr2::ExprModuleNode
Node that contains entire program.
Definition: ExprNode.h:245
SeExpr2::ExprPrototypeNode::arg
const ExprNode * arg(int i) const
Definition: ExprNode.h:284
SeExpr2::ExprIfThenElseNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:785
SeExpr2::ExprAssignNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:743
ExprType.h
SeExpr2::ExprModuleNode::ExprModuleNode
ExprModuleNode(const Expression *expr)
Definition: ExprNode.h:247
SeExpr2::ExprLocalFunctionNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Vec.h
SeExpr2::ExprVarNode::localVar
const ExprLocalVar * localVar() const
Definition: ExprNode.h:476
SeExpr2::ExprAssignNode::ExprAssignNode
ExprAssignNode(const Expression *expr, const char *name, ExprNode *e)
Definition: ExprNode.h:357
SeExpr2::ExprPrototypeNode::name
const std::string & name() const
Definition: ExprNode.h:288
SeExpr2::ExprFuncNode::_localFunc
const ExprLocalFunctionNode * _localFunc
Definition: ExprNode.h:598
SeExpr2::ExprFuncNode::_data
Data * _data
Definition: ExprNode.h:603
SeExpr2::ExprCompareEqNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:420
SeExpr2::ExprFuncNode::Data::_cleanup
bool _cleanup
Definition: ExprNode.h:573
SeExpr2::ExprNodePolicy::Assign
ExprAssignNode Assign
Definition: ExprNode.h:617
ExprLLVM.h
SeExpr2::ExprCompareEqNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:538
SeExpr2::ExprVarNode::_var
ExprVarRef * _var
Definition: ExprNode.h:482
SeExpr2::ExprNode::parent
const ExprNode * parent() const
Access parent node - root node has no parent.
Definition: ExprNode.h:112
SeExpr2::ExprIfThenElseNode
Node that computes local variables before evaluating expression.
Definition: ExprNode.h:341
SeExpr2::ExprNumNode::_val
double _val
Definition: ExprNode.h:495
SeExpr2::ExprCompareNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:835
SeExpr2::ExprNumNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:520
SeExpr2::Expression::getExpr
const std::string & getExpr() const
Get the string that this expression is currently set to evaluate.
Definition: Expression.h:122
SeExpr2::ExprNode::_isVec
bool _isVec
True if node has a vector result.
Definition: ExprNode.h:234
SeExpr2::ExprVarEnvBuilder
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
Definition: ExprEnv.h:148
SeExpr2::ExprBlockNode::ExprBlockNode
ExprBlockNode(const Expression *expr, ExprNode *a, ExprNode *b)
Definition: ExprNode.h:333
SeExpr2::ExprBinaryOpNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprFuncNode::checkArg
bool checkArg(int argIndex, ExprType type, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:578
SeExpr2::ExprBlockNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:1044
SeExpr2::ExprVecNode
Node that constructs a vector from three scalars.
Definition: ExprNode.h:381
SeExpr2::ExprBlockNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:258
SeExpr2::ExprLocalFunctionNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Preps the definition of this site.
Definition: ExprNode.cpp:188
SeExpr2::Expression
main expression class
Definition: Expression.h:76
SeExpr2::ExprPrototypeNode::addArgs
void addArgs(ExprNode *surrogate)
Definition: ExprNode.cpp:173
SeExpr2::ExprType::isFP
bool isFP() const
Direct is predicate checks.
Definition: ExprType.h:164
SeExpr2::ExprNodePolicy::Compare
ExprCompareNode Compare
Definition: ExprNode.h:622
SeExpr2::ExprVecNode::value
Vec3d value() const
Definition: ExprNode.cpp:342
SeExpr2::ExprLocalFunctionNode::ExprLocalFunctionNode
ExprLocalFunctionNode(const Expression *expr, ExprPrototypeNode *prototype, ExprNode *block)
Definition: ExprNode.h:309
ExprEnv.h
SeExpr2::ExprPrototypeNode::ExprPrototypeNode
ExprPrototypeNode(const Expression *expr, const std::string &name)
Definition: ExprNode.h:260
SeExpr2::ExprVarNode
Node that references a variable.
Definition: ExprNode.h:465
SeExpr2::ExprNode::addChild
void addChild(ExprNode *child)
Add a child to the child list (for parser use only)
Definition: ExprNode.cpp:90
SeExpr2::ExprPrototypeNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:139
SeExpr2::ExprNode::checkCondition
bool checkCondition(bool check, const std::string &message, bool &error)
Checks the boolean value and records an error string with node if it is false.
Definition: ExprNode.h:190
SeExpr2::ExprNode::prep
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:104
SeExpr2::ExprStrNode::str
void str(const char *newstr)
Definition: ExprNode.h:510
SeExpr2::ExprVecNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprPrototypeNode::setReturnType
void setReturnType(const ExprType &type)
Definition: ExprNode.h:268
SeExpr2::ExprType::toString
std::string toString() const
Stringify the type into a printable string.
Definition: ExprType.h:191
SeExpr2::ExprFuncNode::ExprFuncNode
ExprFuncNode(const Expression *expr, const char *name)
Definition: ExprNode.h:519
eval
virtual void eval(ArgHandle args)
Definition: ExprBuiltins.cpp:22
SeExpr2::ExprBinaryOpNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:569
a
Defined as a *alpha b *alpha< br ></div >< br > float< b > float a
Definition: userdoc.txt:174
SeExpr2::ExprAssignNode::_assignedType
ExprType _assignedType
Definition: ExprNode.h:376
SeExpr2::ExprNode::swapChildren
void swapChildren(size_t i, size_t j)
Swap children, do not use unless you know what you are doing.
Definition: ExprNode.h:123
SeExpr2::ExprBinaryOpNode::_op
char _op
Definition: ExprNode.h:460
SeExpr2::ExprNodePolicy::Module
ExprModuleNode Module
Definition: ExprNode.h:612
SeExpr2::ExprSubscriptNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:684
SeExpr2::ExprUnaryOpNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:357
SeExpr2::Vec3d
Vec< double, 3, false > Vec3d
Definition: Vec.h:384
SeExpr2::ExprNodePolicy::Num
ExprNumNode Num
Definition: ExprNode.h:625
SeExpr2::ExprNodePolicy::Var
ExprVarNode Var
Definition: ExprNode.h:624
SeExpr2::ExprFuncNode::getData
Data * getData() const
get associated blind data (returns 0 if none)
Definition: ExprNode.h:591
SeExpr2::ExprVecNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:324
SeExpr2::ExprUnaryOpNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprCondNode
Node that evaluates a conditional (if-then-else) expression.
Definition: ExprNode.h:406
SeExpr2::ExprNodePolicy::Base
ExprNode Base
Definition: ExprNode.h:608
SeExpr2::ExprType::setLifetime
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
Definition: ExprType.h:136
SeExpr2::ExprAssignNode::assignedType
const ExprType & assignedType() const
Definition: ExprNode.h:368
SeExpr2::ExprIfThenElseNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprPrototypeNode::ExprPrototypeNode
ExprPrototypeNode(const Expression *expr, const std::string &name, const ExprType &retType)
Definition: ExprNode.h:257
SeExpr2::ExprStrNode
Node that stores a string.
Definition: ExprNode.h:502
SeExpr2::ExprAssignNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprVarNode::ExprVarNode
ExprVarNode(const Expression *expr, const char *name)
Definition: ExprNode.h:467
SeExpr2::ExprAssignNode::_localVar
ExprLocalVar * _localVar
Definition: ExprNode.h:375
SeExpr2::ExprFuncNode::Data
base class for custom instance data
Definition: ExprNode.h:570
SeExpr2::ExprSubscriptNode
Node that evaluates a component of a vector.
Definition: ExprNode.h:416
SeExpr2::ExprNode::expr
const Expression * expr() const
Access expression.
Definition: ExprNode.h:102
SeExpr2::ExprLocalFunctionNode
Node that contains local function.
Definition: ExprNode.h:307
SeExpr2::ExprNodePolicy::Cond
ExprCondNode Cond
Definition: ExprNode.h:620
SeExpr2::ExprFuncNode::isStrArg
bool isStrArg(int n) const
Definition: ExprNode.h:563
SeExpr2::ExprPrototypeNode::buildInterpreter
int buildInterpreter(Interpreter *interpreter) const
Build the interpreter.
Definition: Interpreter.cpp:910
SeExpr2::ExprNodePolicy::Str
ExprStrNode Str
Definition: ExprNode.h:626
SeExpr2::ExprBlockNode
Node that computes local variables before evaluating expression.
Definition: ExprNode.h:331
SeExpr2::ExprCondNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:980
SeExpr2::ExprPrototypeNode::_argTypes
std::vector< ExprType > _argTypes
Definition: ExprNode.h:300
SeExpr2::ExprType::valuesCompatible
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
Definition: ExprType.h:173
SeExpr2::ExprVecNode::ExprVecNode
ExprVecNode(const Expression *expr)
Definition: ExprNode.h:383
SeExpr2::ExprAssignNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:307
SeExpr2::ExprNode::checkTypesCompatible
bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error)
types match (true if they do)
Definition: ExprNode.h:215
SeExpr2::ExprBlockNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
LLVM_BODY
#define LLVM_BODY
Definition: ExprLLVM.h:35
SeExpr2::ExprNode::addChildren
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
Definition: ExprNode.cpp:95
SeExpr2::ExprAssignNode::localVar
const ExprLocalVar * localVar() const
Definition: ExprNode.h:371
SeExpr2::Expression::addError
void addError(const std::string &error, const int startPos, const int endPos) const
Definition: Expression.h:205
SeExpr2::ExprVarRef
abstract class for implementing variable references
Definition: Expression.h:45
SeExpr2::ExprNode::child
const ExprNode * child(size_t i) const
Get 0 indexed child.
Definition: ExprNode.h:117
SeExpr2::ExprNode::endPos
short int endPos() const
Access end position in input string.
Definition: ExprNode.h:159
SeExpr2::ExprNode::checkIsValue
bool checkIsValue(const ExprType &type, bool &error)
Checks if the type is a value (i.e. string or float[d])
Definition: ExprNode.h:198
SeExpr2::ExprBinaryOpNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:463
SeExpr2::ExprStrNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:549
SeExpr2::ExprModuleNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprPrototypeNode::isReturnTypeSet
bool isReturnTypeSet() const
Definition: ExprNode.h:273
SeExpr2::ExprNode::startPos
short int startPos() const
Access start position in input string.
Definition: ExprNode.h:157
SeExpr2::ExprNodePolicy::LocalFunction
ExprLocalFunctionNode LocalFunction
Definition: ExprNode.h:614
SeExpr2::ExprLocalFunctionNode::_returnedDataOp
int _returnedDataOp
Definition: ExprNode.h:327
SeExpr2::ExprPrototypeNode::argType
ExprType argType(int i) const
Definition: ExprNode.h:281
SeExpr2::ExprNode::_endPos
unsigned short int _endPos
Definition: ExprNode.h:241
SeExpr2::ExprNode::_type
ExprType _type
Definition: ExprNode.h:237
SeExpr2::ExprFuncNode::promote
int promote(int i) const
Definition: ExprNode.h:592
Expression.h
SeExpr2::Interpreter
Definition: Interpreter.h:40
SeExpr2::ExprNode::_expr
const Expression * _expr
Owning expression (node can't modify)
Definition: ExprNode.h:225
SeExpr2::ExprCompareNode::ExprCompareNode
ExprCompareNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Definition: ExprNode.h:440
SeExpr2::ExprAssignNode::name
const std::string & name() const
Definition: ExprNode.h:365
SeExpr2::ExprLocalVar
ExprLocalVar reference, all local variables in seexpr are subclasses of this or this itself.
Definition: ExprEnv.h:37
SeExpr2::ExprStrNode::_str
std::string _str
Definition: ExprNode.h:513
SeExpr2::ExprStrNode::codegen
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
SeExpr2::ExprNode::setType
void setType(const ExprType &t)
Set type of parameter.
Definition: ExprNode.h:172
b
Between a and b
Definition: userdoc.txt:180
SeExpr2::ExprPrototypeNode::addArgTypes
void addArgTypes(ExprNode *surrogate)
Definition: ExprNode.cpp:166
SeExpr2::ExprNode::removeLastChild
void removeLastChild()
Remove last child and delete the entry.
Definition: ExprNode.h:129
SeExpr2::ExprFuncNode::_func
const ExprFunc * _func
Definition: ExprNode.h:597
SeExpr2::ExprNode::ExprNode
ExprNode(const Expression *expr)
Definition: ExprNode.cpp:41
SeExpr2::ExprVarNode::prep
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:485
SeExpr2::ExprBinaryOpNode::ExprBinaryOpNode
ExprBinaryOpNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Definition: ExprNode.h:453
SeExpr2::ExprFuncNode::_name
std::string _name
Definition: ExprNode.h:596
SeExpr2::ExprVarNode::_name
std::string _name
Definition: ExprNode.h:480
SeExpr2::ExprVecNode::buildInterpreter
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Definition: Interpreter.cpp:555
SeExpr2::ExprNode::_children
std::vector< ExprNode * > _children
List of children.
Definition: ExprNode.h:231