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);
79  ExprNode(const Expression* expr, ExprNode* a, ExprNode* b);
80  ExprNode(const Expression* expr, ExprNode* a, ExprNode* b, const ExprType& type);
81  ExprNode(const Expression* expr, ExprNode* a, ExprNode* b, ExprNode* c);
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 _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;
292  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
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:
333  ExprBlockNode(const Expression* expr, ExprNode* a, ExprNode* b) : ExprNode(expr, a, b) {}
334 
335  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
336  virtual int buildInterpreter(Interpreter* interpreter) const;
337  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
338 };
339 
341 class ExprIfThenElseNode : public ExprNode {
342  public:
343  ExprIfThenElseNode(const Expression* expr, ExprNode* a, ExprNode* b, ExprNode* c) : ExprNode(expr, a, b, c), _varEnv(nullptr), _varEnvMergeIndex(0) {}
344 
345  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
346  virtual int buildInterpreter(Interpreter* interpreter) const;
347  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
348 
349  ExprVarEnv* _varEnv;
350  size_t _varEnvMergeIndex;
351 };
352 
354 class ExprAssignNode : public ExprNode {
355  public:
356  ExprAssignNode(const Expression* expr, const char* name, ExprNode* e)
357  : ExprNode(expr, e), _name(name), _localVar(0) {}
358 
359  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
360  virtual int buildInterpreter(Interpreter* interpreter) const;
361  // virtual void eval(Vec3d& result) const;
362  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
363 
364  const std::string& name() const {
365  return _name;
366  };
367  const ExprType& assignedType() const {
368  return _assignedType;
369  };
370  const ExprLocalVar* localVar() const { return _localVar; }
371 
372  private:
373  std::string _name;
376 };
377 
378 // TODO three scalars? Or 2 to 16 scalars??
380 class ExprVecNode : public ExprNode {
381  public:
382  ExprVecNode(const Expression* expr) : ExprNode(expr) {}
383 
384  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
385  virtual int buildInterpreter(Interpreter* interpreter) const;
386  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
387 
388  Vec3d value() const;
389 };
390 
392 class ExprUnaryOpNode : public ExprNode {
393  public:
395  ExprUnaryOpNode(const Expression* expr, ExprNode* a, char op) : ExprNode(expr, a), _op(op) {}
396 
397  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
398  virtual int buildInterpreter(Interpreter* interpreter) const;
399  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
400 
401  char _op;
402 };
403 
405 class ExprCondNode : public ExprNode {
406  public:
407  ExprCondNode(const Expression* expr, ExprNode* a, ExprNode* b, ExprNode* c) : ExprNode(expr, a, b, c) {}
408 
409  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
410  virtual int buildInterpreter(Interpreter* interpreter) const;
411  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
412 };
413 
415 class ExprSubscriptNode : public ExprNode {
416  public:
417  ExprSubscriptNode(const Expression* expr, ExprNode* a, ExprNode* b) : ExprNode(expr, a, b) {}
418 
419  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
420  virtual int buildInterpreter(Interpreter* interpreter) const;
421  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
422 };
423 
425 class ExprCompareEqNode : public ExprNode {
426  public:
427  ExprCompareEqNode(const Expression* expr, ExprNode* a, ExprNode* b, char op) : ExprNode(expr, a, b), _op(op) {}
428 
429  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
430  virtual int buildInterpreter(Interpreter* interpreter) const;
431  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
432 
433  char _op;
434 };
435 
437 class ExprCompareNode : public ExprNode {
438  public:
439  ExprCompareNode(const Expression* expr, ExprNode* a, ExprNode* b, char op) : ExprNode(expr, a, b), _op(op) {}
440 
441  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
442  virtual int buildInterpreter(Interpreter* interpreter) const;
443  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
444 
446  char _op;
447 };
448 
450 class ExprBinaryOpNode : public ExprNode {
451  public:
452  ExprBinaryOpNode(const Expression* expr, ExprNode* a, ExprNode* b, char op) : ExprNode(expr, a, b), _op(op) {}
453 
454  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
455  virtual int buildInterpreter(Interpreter* interpreter) const;
456  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
457 
458  char _op;
459 };
460 
462 class ExprVarNode : public ExprNode {
463  public:
464  ExprVarNode(const Expression* expr, const char* name) : ExprNode(expr), _name(name), _localVar(0), _var(0) {}
465 
466  ExprVarNode(const Expression* expr, const char* name, const ExprType& type)
467  : ExprNode(expr, type), _name(name), _localVar(0), _var(0) {}
468 
469  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
470  virtual int buildInterpreter(Interpreter* interpreter) const;
471  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
472  const char* name() const { return _name.c_str(); }
473  const ExprLocalVar* localVar() const { return _localVar; }
474  const ExprVarRef* var() const { return _var; }
475 
476  private:
477  std::string _name;
480 };
481 
483 class ExprNumNode : public ExprNode {
484  public:
485  ExprNumNode(const Expression* expr, double val) : ExprNode(expr), _val(val) {}
486 
487  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
488  virtual int buildInterpreter(Interpreter* interpreter) const;
489  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
490  double value() const {
491  return _val;
492  };
493 
494  private:
495  double _val;
496 };
497 
499 class ExprStrNode : public ExprNode {
500  public:
501  ExprStrNode(const Expression* expr, const char* str) : ExprNode(expr), _str(str) {}
502 
503  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
504  virtual int buildInterpreter(Interpreter* interpreter) const;
505  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
506  const char* str() const { return _str.c_str(); }
507  void str(const char* newstr) { _str = newstr; }
508 
509  private:
510  std::string _str;
511 };
512 
514 class ExprFuncNode : public ExprNode {
515  public:
516  ExprFuncNode(const Expression* expr, const char* name)
517  : ExprNode(expr), _name(name), _func(0), _localFunc(0), _data(0) {
518  expr->addFunc(name);
519  }
520  virtual ~ExprFuncNode() {/* TODO: fix delete _data;*/
521  }
522 
523  virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder& envBuilder);
524  virtual int buildInterpreter(Interpreter* interpreter) const;
525  virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY;
526 
527  const char* name() const { return _name.c_str(); }
528  bool checkArg(int argIndex, ExprType type, ExprVarEnvBuilder& envBuilder);
529 
530 #if 0
531  virtual void eval(Vec3d& result) const;
532  void setIsVec(bool isVec) { _isVec = isVec; }
533 
535  int nargs() const { return _nargs; }
536 
537 #if 0
538  double* scalarArgs() const { return &_scalarArgs[0]; }
539  Vec3d* vecArgs() const { return &_vecArgs[0]; }
540 
542  Vec3d* evalArgs() const;
543 
545  Vec3d evalArg(int n) const;
546 
548  bool isStrArg(int n) const;
549 
551  std::string getStrArg(int n) const;
552 #endif
553 
554 #endif
555 
556  // TODO: Remove those two methods.
557  bool isStrArg(int n) const { return n < numChildren() && dynamic_cast<const ExprStrNode*>(child(n)) != 0; }
558  std::string getStrArg(int n) const {
559  if (n < numChildren()) return static_cast<const ExprStrNode*>(child(n))->str();
560  return "";
561  }
562 
564  struct Data {
565  virtual ~Data() {}
566  };
567 
569  /***
570  Use this to set data associated with the node. Equivalently this is data
571  associated with a specific evaluation point of a function.
572  Examples would be tokenized values,
573  sorted lists for binary searches in curve evaluation, etc. This should be done
574  in ExprFuncX::prep().
575  */
576  void setData(Data* data) const { _data = data; }
577 
579  /***
580  Use this to get data associated in the prep() routine. This is typically
581  used from ExprFuncX::eval()
582  */
583  Data* getData() const { return _data; }
584  int promote(int i) const { return _promote[i]; }
585  const ExprFunc* func() const { return _func; }
586 
587  private:
588  std::string _name;
589  const ExprFunc* _func;
590  const ExprLocalFunctionNode* _localFunc; // TODO: it is dirty to have to have both.
591  // int _nargs;
592  // mutable std::vector<double> _scalarArgs;
593  // mutable std::vector<Vec3d> _vecArgs;
594  mutable std::vector<int> _promote;
595  mutable Data* _data;
596 };
597 
600  typedef ExprNode Base;
601  // TODO: fix this once we switch to a c++11 compiler
602  // typedef std::unique_ptr<Base*> Ptr;
603 
610  typedef ExprVecNode Vec;
616  typedef ExprVarNode Var;
617  typedef ExprNumNode Num;
618  typedef ExprStrNode Str;
620 };
621 }
622 
623 #endif
bool _isVec
True if node has a vector result.
Definition: ExprNode.h:234
virtual ~ExprFuncNode()
Definition: ExprNode.h:520
ExprModuleNode Module
Definition: ExprNode.h:604
Node that evaluates a conditional (if-then-else) expression.
Definition: ExprNode.h:405
Node that computes local variables before evaluating expression.
Definition: ExprNode.h:331
const ExprType & type() const
The type of the node.
Definition: ExprNode.h:145
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
ExprPrototypeNode(const Expression *expr, const std::string &name)
Definition: ExprNode.h:260
ExprCondNode Cond
Definition: ExprNode.h:612
int promote(int i) const
Definition: ExprNode.h:584
ExprCompareNode Compare
Definition: ExprNode.h:614
void setReturnType(const ExprType &type)
Definition: ExprNode.h:268
std::string _name
Definition: ExprNode.h:588
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
Definition: ExprNode.cpp:93
ExprNode * child(size_t i)
Get 0 indexed child.
Definition: ExprNode.h:120
ExprBinaryOpNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Definition: ExprNode.h:452
void addError(const std::string &error, const int startPos, const int endPos) const
Definition: Expression.h:205
Node that constructs a vector from three scalars.
Definition: ExprNode.h:380
ExprVarRef * _var
Definition: ExprNode.h:479
void swapChildren(size_t i, size_t j)
Swap children, do not use unless you know what you are doing.
Definition: ExprNode.h:123
Data * getData() const
get associated blind data (returns 0 if none)
Definition: ExprNode.h:583
ExprVecNode(const Expression *expr)
Definition: ExprNode.h:382
bool isFP() const
Direct is predicate checks.
Definition: ExprType.h:164
ExprPrototypeNode(const Expression *expr, const std::string &name, const ExprType &retType)
Definition: ExprNode.h:257
ExprLocalFunctionNode LocalFunction
Definition: ExprNode.h:606
Node that references a variable.
Definition: ExprNode.h:462
ExprBlockNode Block
Definition: ExprNode.h:607
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:125
void setData(Data *data) const
associate blind data with this node (subsequently owned by this object)
Definition: ExprNode.h:576
Node that contains local function.
Definition: ExprNode.h:307
const ExprLocalVar * localVar() const
Definition: ExprNode.h:370
Function Definition, used in parse tree and func table.
Definition: ExprFunc.h:44
Node that computes local variables before evaluating expression.
Definition: ExprNode.h:341
std::string toString() const
Stringify the type into a printable string.
Definition: ExprType.h:191
std::vector< ExprType > _argTypes
Definition: ExprNode.h:300
short int endPos() const
Access end position in input string.
Definition: ExprNode.h:159
bool checkIsValue(const ExprType &type, bool &error)
Checks if the type is a value (i.e. string or float[d])
Definition: ExprNode.h:198
bool isValue() const
Definition: ExprType.h:166
void str(const char *newstr)
Definition: ExprNode.h:507
virtual void eval(ArgHandle args)
short int length() const
Access length of input string.
Definition: ExprNode.h:161
bool isStrArg(int n) const
Definition: ExprNode.h:557
Node that evaluates a component of a vector.
Definition: ExprNode.h:415
Node that stores a string.
Definition: ExprNode.h:499
std::vector< int > _promote
Definition: ExprNode.h:594
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
Node that implements an binary operator.
Definition: ExprNode.h:450
#define LLVM_BODY
Definition: ExprLLVM.h:35
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
Definition: ExprNode.cpp:102
Node that contains entire program.
Definition: ExprNode.h:245
std::string getStrArg(int n) const
Definition: ExprNode.h:558
ExprVarNode(const Expression *expr, const char *name)
Definition: ExprNode.h:464
ExprCondNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
Definition: ExprNode.h:407
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
For any rgb or hsl value(except for negative s values)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
const Expression * _expr
Owning expression (node can&#39;t modify)
Definition: ExprNode.h:225
const std::string & getExpr() const
Get the string that this expression is currently set to evaluate.
Definition: Expression.h:122
virtual ~ExprNode()
Definition: ExprNode.cpp:82
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
Definition: ExprType.h:136
ExprLocalFunctionNode(const Expression *expr, ExprPrototypeNode *prototype, ExprNode *block)
Definition: ExprNode.h:309
ExprLocalVar reference, all local variables in seexpr are subclasses of this or this itself...
Definition: ExprEnv.h:38
unsigned short int _endPos
Definition: ExprNode.h:241
ExprIfThenElseNode IfThenElse
Definition: ExprNode.h:608
Node that calls a function.
Definition: ExprNode.h:514
Variable scope for tracking variable lookup.
Definition: ExprEnv.h:97
ExprFuncNode Func
Definition: ExprNode.h:619
Vec< double, 3, false > Vec3d
Definition: Vec.h:368
std::string _str
Definition: ExprNode.h:510
short int startPos() const
Access start position in input string.
Definition: ExprNode.h:157
const ExprVarRef * var() const
Definition: ExprNode.h:474
ExprStrNode(const Expression *expr, const char *str)
Definition: ExprNode.h:501
const ExprLocalVar * localVar() const
Definition: ExprNode.h:473
ExprCompareEqNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Definition: ExprNode.h:427
const ExprNode * parent() const
Access parent node - root node has no parent.
Definition: ExprNode.h:112
Between a and b
Definition: userdoc.txt:180
const ExprNode * arg(int i) const
Definition: ExprNode.h:284
ExprAssignNode(const Expression *expr, const char *name, ExprNode *e)
Definition: ExprNode.h:356
ExprModuleNode(const Expression *expr)
Definition: ExprNode.h:247
main expression class
Definition: Expression.h:76
const ExprLocalFunctionNode * _localFunc
Definition: ExprNode.h:590
void setType(const ExprType &t)
Set type of parameter.
Definition: ExprNode.h:172
const std::string & name() const
Definition: ExprNode.h:288
ExprType & Constant()
Mutate this into a constant lifetime.
Definition: ExprType.h:112
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
Definition: ExprType.h:173
ExprPrototypeNode Prototype
Definition: ExprNode.h:605
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
base class for custom instance data
Definition: ExprNode.h:564
std::string _name
Definition: ExprNode.h:477
void setTypeWithChildLife(const ExprType &t)
Set&#39;s the type to the argument but uses the children to determine lifetime.
Definition: ExprNode.h:176
void removeLastChild()
Remove last child and delete the entry.
Definition: ExprNode.h:129
ExprNode * _parent
Parent node (null if this the the root)
Definition: ExprNode.h:228
Node that compute a local variable assignment.
Definition: ExprNode.h:354
int numChildren() const
Number of children.
Definition: ExprNode.h:114
ExprLocalVar * _localVar
Definition: ExprNode.h:374
void addChild(ExprNode *child)
Add a child to the child list (for parser use only)
Definition: ExprNode.cpp:88
ExprNode(const Expression *expr)
Definition: ExprNode.cpp:39
ExprUnaryOpNode UnaryOp
Definition: ExprNode.h:611
const ExprFunc * func() const
Definition: ExprNode.h:585
void addFunc(const char *n) const
add function evaluation (this is for internal use)
Definition: Expression.h:321
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
Node that stores a numeric constant.
Definition: ExprNode.h:483
ExprLocalVar * _localVar
Definition: ExprNode.h:478
Node that implements a numeric comparison.
Definition: ExprNode.h:437
bool checkIsFP(const ExprType &type, bool &error)
Checks if the type is a float[d] for any d.
Definition: ExprNode.h:202
ExprType argType(int i) const
Definition: ExprNode.h:281
bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error)
types match (true if they do)
Definition: ExprNode.h:215
const Expression * expr() const
Access expression.
Definition: ExprNode.h:102
double LLVM_BUILDER
Definition: ExprLLVM.h:34
bool isReturnTypeSet() const
Definition: ExprNode.h:273
const ExprType & assignedType() const
Definition: ExprNode.h:367
ExprCompareNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Definition: ExprNode.h:439
Policy which provides all the AST Types for the parser.
Definition: ExprNode.h:599
ExprVarNode(const Expression *expr, const char *name, const ExprType &type)
Definition: ExprNode.h:466
NOde that computes with a single operand.
Definition: ExprNode.h:392
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
ExprBlockNode(const Expression *expr, ExprNode *a, ExprNode *b)
Definition: ExprNode.h:333
Node that contains prototype of function.
Definition: ExprNode.h:255
ExprType returnType() const
Definition: ExprNode.h:277
</pre > Once we have this we need an instance to store our variable and provide a reference to that We make it mutable
Definition: tutorial.txt:126
const ExprNode * child(size_t i) const
Get 0 indexed child.
Definition: ExprNode.h:117
ExprSubscriptNode(const Expression *expr, ExprNode *a, ExprNode *b)
Definition: ExprNode.h:417
const ExprFunc * _func
Definition: ExprNode.h:589
bool isVec() const
True if node has a vector result.
Definition: ExprNode.h:99
ExprFuncNode(const Expression *expr, const char *name)
Definition: ExprNode.h:516
ExprAssignNode Assign
Definition: ExprNode.h:609
std::string toString() const
Access to original string representation of current expression.
Definition: ExprNode.h:105
unsigned short int _startPos
Position line and collumn.
Definition: ExprNode.h:241
ExprUnaryOpNode(const Expression *expr, ExprNode *a, char op)
Construct with specific op (&#39;!x&#39; is logical negation, &#39;~x&#39; is 1-x, &#39;-x&#39; is -x)
Definition: ExprNode.h:395
ExprNumNode(const Expression *expr, double val)
Definition: ExprNode.h:485
ExprBinaryOpNode BinaryOp
Definition: ExprNode.h:615
std::vector< int > _interpreterOps
Definition: ExprNode.h:301
Node that implements a numeric/string comparison.
Definition: ExprNode.h:425
ExprIfThenElseNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
Definition: ExprNode.h:343
ExprType _type
Definition: ExprNode.h:237
double LLVM_VALUE
Definition: ExprLLVM.h:33
Defined as a *alpha b *alpha< br ></div >< br > float< b > float a
Definition: userdoc.txt:174
abstract class for implementing variable references
Definition: Expression.h:45
ExprCompareEqNode CompareEq
Definition: ExprNode.h:613
void setPosition(const short int startPos, const short int endPos)
Remember the line and column position in the input string.
Definition: ExprNode.h:152
std::vector< ExprNode * > _children
List of children.
Definition: ExprNode.h:231
const ExprPrototypeNode * prototype() const
TODO: Accessor for prototype (probably not needed when we use prep right)
Definition: ExprNode.h:317
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
Definition: ExprEnv.h:152