1 /* 2 * ASTree.h 3 * Avida 4 * 5 * Created by David on 4/7/07. 6 * Copyright 2007-2011 Michigan State University. All rights reserved. 7 * 8 * 9 * This file is part of Avida. 10 * 11 * Avida is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License 12 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 13 * 14 * Avida is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License along with Avida. 18 * If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22 #ifndef ASTree_h 23 #define ASTree_h 24 25 #include "avida/Avida.h" 26 #include "AvidaScript.h" 27 28 #include "cString.h" 29 30 #include "tList.h" 31 #include "tManagedPointerArray.h" 32 33 34 class cASFunction; 35 class cASTVisitor; 36 37 class cASFilePosition 38 { 39 private: 40 cString m_filename; 41 int m_line; 42 43 44 cASFilePosition(); // @not_implemented 45 cASFilePosition& operator=(const cASFilePosition&); // @not_implemented 46 47 48 public: cASFilePosition(const cString & fn,int line)49 inline cASFilePosition(const cString& fn, int line) : m_filename(fn), m_line(line) { ; } cASFilePosition(const cASFilePosition & fp)50 inline cASFilePosition(const cASFilePosition& fp) : m_filename(fp.m_filename), m_line(fp.m_line) { ; } 51 GetFilename()52 inline const cString& GetFilename() const { return m_filename; } GetLineNumber()53 inline int GetLineNumber() const { return m_line; } 54 55 inline bool operator==(const cASFilePosition& fp) { return m_line == fp.m_line && m_filename == fp.m_filename; } 56 inline bool operator!=(const cASFilePosition& fp) { return m_line != fp.m_line || m_filename != fp.m_filename; } 57 }; 58 59 60 61 // -- Abstract Syntax Tree Base Class 62 // --------------------------------------------------------------------------------------------------------------------- 63 64 65 //! Abstract base class for all AvidaScript abstract syntax tree nodes 66 class cASTNode 67 { 68 private: 69 static const sASTypeInfo s_invalid_type; 70 71 cASTNode(); // @not_implemented 72 cASTNode(const cASTNode&); // @not_implemented 73 cASTNode& operator=(const cASTNode&); // @not_implmented 74 75 76 protected: 77 cASFilePosition m_file_pos; 78 cASTNode(const cASFilePosition & fp)79 cASTNode(const cASFilePosition& fp) : m_file_pos(fp) { ; } 80 81 82 public: ~cASTNode()83 virtual ~cASTNode() { ; } 84 GetType()85 virtual const sASTypeInfo& GetType() const { return s_invalid_type; } 86 GetFilePosition()87 inline const cASFilePosition& GetFilePosition() const { return m_file_pos; } 88 IsOutputSuppressed()89 virtual bool IsOutputSuppressed() const { return false; } SuppressOutput()90 virtual void SuppressOutput() { ; } 91 92 virtual void Accept(cASTVisitor& visitor) = 0; 93 }; 94 95 96 97 // -- Concrete Abstract Syntax Tree Nodes 98 // --------------------------------------------------------------------------------------------------------------------- 99 100 class cASTAssignment; 101 class cASTArgumentList; 102 class cASTObjectAssignment; 103 104 class cASTReturnStatement; 105 class cASTStatementList; 106 107 class cASTForeachBlock; 108 class cASTIfBlock; 109 class cASTWhileBlock; 110 111 class cASTFunctionDefinition; 112 class cASTVariableDefinition; 113 class cASTVariableDefinitionList; 114 115 class cASTExpressionBinary; 116 class cASTExpressionUnary; 117 118 class cASTBuiltInCall; 119 class cASTFunctionCall; 120 class cASTLiteral; 121 class cASTLiteralArray; 122 class cASTLiteralDict; 123 class cASTObjectCall; 124 class cASTObjectReference; 125 class cASTVariableReference; 126 class cASTUnpackTarget; 127 128 129 130 // -------- Assignment Nodes -------- 131 132 class cASTAssignment : public cASTNode 133 { 134 private: 135 cString m_var; 136 cASTNode* m_expr; 137 int m_id; 138 bool m_global; 139 140 public: cASTAssignment(const cASFilePosition & fp,const cString & var)141 cASTAssignment(const cASFilePosition& fp, const cString& var) 142 : cASTNode(fp), m_var(var), m_expr(NULL), m_id(-1), m_global(false) { ; } ~cASTAssignment()143 ~cASTAssignment() { delete m_expr; } 144 GetVariable()145 inline const cString& GetVariable() { return m_var; } 146 SetExpression(cASTNode * expr)147 inline void SetExpression(cASTNode* expr) { delete m_expr; m_expr = expr; } GetExpression()148 inline cASTNode* GetExpression() { return m_expr; } 149 GetVarID()150 inline int GetVarID() const { return m_id; } IsVarGlobal()151 inline bool IsVarGlobal() const { return m_global; } SetVar(int in_id,bool global)152 inline void SetVar(int in_id, bool global) { m_id = in_id; m_global = global; } 153 154 void Accept(cASTVisitor& visitor); 155 }; 156 157 158 class cASTArgumentList : public cASTNode 159 { 160 private: 161 tList<cASTNode> m_nodes; 162 163 public: cASTArgumentList(const cASFilePosition & fp)164 cASTArgumentList(const cASFilePosition& fp) : cASTNode(fp) { ; } ~cASTArgumentList()165 ~cASTArgumentList() { while (m_nodes.GetSize()) delete m_nodes.Pop(); } 166 AddNode(cASTNode * n)167 inline void AddNode(cASTNode* n) { m_nodes.PushRear(n); } GetSize()168 inline int GetSize() const { return m_nodes.GetSize(); } Iterator()169 inline tListIterator<cASTNode> Iterator() { return tListIterator<cASTNode>(m_nodes); } 170 171 void Accept(cASTVisitor& visitor); 172 }; 173 174 175 class cASTObjectAssignment : public cASTNode 176 { 177 private: 178 cASTNode* m_trgt; 179 cASTNode* m_expr; 180 181 public: cASTObjectAssignment(const cASFilePosition & fp,cASTNode * trgt)182 cASTObjectAssignment(const cASFilePosition& fp, cASTNode* trgt) 183 : cASTNode(fp), m_trgt(trgt), m_expr(NULL) { ; } ~cASTObjectAssignment()184 ~cASTObjectAssignment() { delete m_expr; } 185 GetTarget()186 inline cASTNode* GetTarget() { return m_trgt; } 187 SetExpression(cASTNode * expr)188 inline void SetExpression(cASTNode* expr) { delete m_expr; m_expr = expr; } GetExpression()189 inline cASTNode* GetExpression() { return m_expr; } 190 191 void Accept(cASTVisitor& visitor); 192 }; 193 194 195 196 197 // -------- Block Nodes -------- 198 199 class cASTReturnStatement : public cASTNode 200 { 201 private: 202 cASTNode* m_expr; 203 204 public: cASTReturnStatement(const cASFilePosition & fp,cASTNode * expr)205 cASTReturnStatement(const cASFilePosition& fp, cASTNode* expr) : cASTNode(fp), m_expr(expr) { ; } ~cASTReturnStatement()206 ~cASTReturnStatement() { delete m_expr; } 207 GetExpression()208 inline cASTNode* GetExpression() { return m_expr; } 209 210 void Accept(cASTVisitor& visitor); 211 }; 212 213 214 class cASTStatementList : public cASTNode 215 { 216 private: 217 tList<cASTNode> m_nodes; 218 219 public: cASTStatementList(const cASFilePosition & fp)220 cASTStatementList(const cASFilePosition& fp) : cASTNode(fp) { ; } 221 ~cASTStatementList(); 222 AddNode(cASTNode * n)223 inline void AddNode(cASTNode* n) { m_nodes.PushRear(n); } Iterator()224 inline tListIterator<cASTNode> Iterator() { return tListIterator<cASTNode>(m_nodes); } 225 226 void Accept(cASTVisitor& visitor); 227 }; 228 229 230 231 232 // -------- Conditional Block Nodes -------- 233 234 class cASTForeachBlock : public cASTNode 235 { 236 private: 237 cASTVariableDefinition* m_var; 238 cASTNode* m_expr; 239 cASTNode* m_code; 240 241 public: cASTForeachBlock(const cASFilePosition & fp,cASTVariableDefinition * v,cASTNode * e,cASTNode * c)242 cASTForeachBlock(const cASFilePosition& fp, cASTVariableDefinition* v, cASTNode* e, cASTNode* c) 243 : cASTNode(fp), m_var(v), m_expr(e), m_code(c) { ; } 244 GetVariable()245 inline cASTVariableDefinition* GetVariable() { return m_var; } GetValues()246 inline cASTNode* GetValues() { return m_expr; } GetCode()247 inline cASTNode* GetCode() { return m_code; } 248 249 void Accept(cASTVisitor& visitor); 250 }; 251 252 253 class cASTIfBlock : public cASTNode 254 { 255 public: 256 class cElseIf 257 { 258 friend class cASTIfBlock; 259 private: 260 cASTNode* m_expr; 261 cASTNode* m_code; 262 cElseIf(cASTNode * expr,cASTNode * code)263 cElseIf(cASTNode* expr, cASTNode* code) : m_expr(expr), m_code(code) { ; } 264 265 public: GetCondition()266 cASTNode* GetCondition() { return m_expr; } GetCode()267 cASTNode* GetCode() { return m_code; } 268 }; 269 270 private: 271 cASTNode* m_expr; 272 cASTNode* m_code; 273 cASTNode* m_else; 274 275 tList<cElseIf> m_elifs; 276 277 public: cASTIfBlock(const cASFilePosition & fp,cASTNode * expr,cASTNode * code)278 cASTIfBlock(const cASFilePosition& fp, cASTNode* expr, cASTNode* code) 279 : cASTNode(fp), m_expr(expr), m_code(code), m_else(NULL) { ; } ~cASTIfBlock()280 ~cASTIfBlock() 281 { 282 delete m_expr; 283 delete m_code; 284 delete m_else; 285 cElseIf* elif = NULL; 286 while ((elif = m_elifs.Pop())) delete elif; 287 } 288 289 GetCondition()290 inline cASTNode* GetCondition() { return m_expr; } GetCode()291 inline cASTNode* GetCode() { return m_code; } AddElseIf(cASTNode * expr,cASTNode * code)292 inline void AddElseIf(cASTNode* expr, cASTNode* code) { m_elifs.PushRear(new cElseIf(expr, code)); } ElseIfIterator()293 inline tListIterator<cElseIf> ElseIfIterator() { return tListIterator<cElseIf>(m_elifs); } SetElseCode(cASTNode * code)294 inline void SetElseCode(cASTNode* code) { m_else = code; } GetElseCode()295 inline cASTNode* GetElseCode() { return m_else; } 296 HasElseIfs()297 inline bool HasElseIfs() const { return (m_elifs.GetSize()); } HasElse()298 inline bool HasElse() const { return (m_else); } 299 300 void Accept(cASTVisitor& visitor); 301 }; 302 303 304 class cASTWhileBlock : public cASTNode 305 { 306 private: 307 cASTNode* m_expr; 308 cASTNode* m_code; 309 310 public: cASTWhileBlock(const cASFilePosition & fp,cASTNode * expr,cASTNode * code)311 cASTWhileBlock(const cASFilePosition& fp, cASTNode* expr, cASTNode* code) : cASTNode(fp), m_expr(expr), m_code(code) { ; } ~cASTWhileBlock()312 ~cASTWhileBlock() { delete m_expr; delete m_code; } 313 GetCondition()314 inline cASTNode* GetCondition() { return m_expr; } GetCode()315 inline cASTNode* GetCode() { return m_code; } 316 317 void Accept(cASTVisitor& visitor); 318 }; 319 320 321 322 323 // -------- Definition Nodes -------- 324 325 class cASTFunctionDefinition : public cASTNode 326 { 327 private: 328 sASTypeInfo m_type; 329 cString m_name; 330 cASTVariableDefinitionList* m_args; 331 cASTNode* m_code; 332 333 public: cASTFunctionDefinition(const cASFilePosition & fp,const sASTypeInfo & type,const cString & name,cASTVariableDefinitionList * args)334 cASTFunctionDefinition(const cASFilePosition& fp, const sASTypeInfo& type, const cString& name, 335 cASTVariableDefinitionList* args) 336 : cASTNode(fp), m_type(type), m_name(name), m_args(args), m_code(NULL) { ; } 337 ~cASTFunctionDefinition(); 338 GetType()339 inline const sASTypeInfo& GetType() const { return m_type; } GetName()340 inline const cString& GetName() { return m_name; } GetArguments()341 inline cASTVariableDefinitionList* GetArguments() { return m_args; } ClearArguments()342 inline void ClearArguments() { m_args = NULL; } 343 SetCode(cASTNode * code)344 inline void SetCode(cASTNode* code) { m_code = code; } GetCode()345 inline cASTNode* GetCode() { return m_code; } 346 347 void Accept(cASTVisitor& visitor); 348 }; 349 350 351 class cASTVariableDefinition : public cASTNode 352 { 353 private: 354 sASTypeInfo m_type; 355 cString m_name; 356 cASTNode* m_assign; 357 cASTArgumentList* m_dims; 358 int m_id; 359 360 public: cASTVariableDefinition(const cASFilePosition & fp,const sASTypeInfo & type,const cString & name)361 cASTVariableDefinition(const cASFilePosition& fp, const sASTypeInfo& type, const cString& name) 362 : cASTNode(fp), m_type(type), m_name(name), m_assign(NULL), m_dims(NULL), m_id(-1) { ; } ~cASTVariableDefinition()363 ~cASTVariableDefinition() { delete m_assign; delete m_dims; } 364 GetType()365 inline const sASTypeInfo& GetType() const { return m_type; } GetName()366 inline const cString& GetName() { return m_name; } SetAssignmentExpression(cASTNode * assign)367 inline void SetAssignmentExpression(cASTNode* assign) { delete m_assign; m_assign = assign; } GetAssignmentExpression()368 inline cASTNode* GetAssignmentExpression() { return m_assign; } SetDimensions(cASTArgumentList * dims)369 inline void SetDimensions(cASTArgumentList* dims) { delete m_dims; m_dims = dims; } GetDimensions()370 inline cASTArgumentList* GetDimensions() { return m_dims; } 371 GetVarID()372 inline int GetVarID() const { return m_id; } SetVar(int in_id)373 inline void SetVar(int in_id) { m_id = in_id; } 374 375 void Accept(cASTVisitor& visitor); 376 }; 377 378 379 class cASTVariableDefinitionList : public cASTNode 380 { 381 private: 382 tList<cASTVariableDefinition> m_nodes; 383 384 public: cASTVariableDefinitionList(const cASFilePosition & fp)385 cASTVariableDefinitionList(const cASFilePosition& fp) : cASTNode(fp) { ; } ~cASTVariableDefinitionList()386 ~cASTVariableDefinitionList() { ; } 387 AddNode(cASTVariableDefinition * n)388 inline void AddNode(cASTVariableDefinition* n) { m_nodes.PushRear(n); } Iterator()389 inline tListIterator<cASTVariableDefinition> Iterator() { return tListIterator<cASTVariableDefinition>(m_nodes); } GetFirst()390 inline cASTVariableDefinition* GetFirst() { return m_nodes.GetFirst(); } 391 GetSize()392 inline int GetSize() const { return m_nodes.GetSize(); } 393 394 void Accept(cASTVisitor& visitor); 395 }; 396 397 398 399 400 401 // -------- Expression Operation Nodes -------- 402 403 class cASTExpressionBinary : public cASTNode 404 { 405 private: 406 ASToken_t m_op; 407 cASTNode* m_left; 408 cASTNode* m_right; 409 sASTypeInfo m_type; 410 sASTypeInfo m_compare_type; 411 412 public: cASTExpressionBinary(const cASFilePosition & fp,ASToken_t op,cASTNode * l,cASTNode * r)413 cASTExpressionBinary(const cASFilePosition& fp, ASToken_t op, cASTNode* l, cASTNode* r) 414 : cASTNode(fp), m_op(op), m_left(l), m_right(r), m_type(AS_TYPE_INVALID), m_compare_type(AS_TYPE_INVALID) { ; } ~cASTExpressionBinary()415 ~cASTExpressionBinary() { delete m_left; delete m_right; } 416 GetOperator()417 inline ASToken_t GetOperator() { return m_op; } SetLeft(cASTNode * left)418 inline void SetLeft(cASTNode* left) { m_left = left; } GetLeft()419 inline cASTNode* GetLeft() { return m_left; } SetRight(cASTNode * right)420 inline void SetRight(cASTNode* right) { m_right = right; } GetRight()421 inline cASTNode* GetRight() { return m_right; } 422 GetType()423 const sASTypeInfo& GetType() const { return m_type; } SetType(const sASTypeInfo & type)424 inline void SetType(const sASTypeInfo& type) { m_type = type; } 425 GetCompareType()426 inline const sASTypeInfo& GetCompareType() const { return m_compare_type; } SetCompareType(const sASTypeInfo & type)427 inline void SetCompareType(const sASTypeInfo& type) { m_compare_type = type; } 428 429 void Accept(cASTVisitor& visitor); 430 }; 431 432 433 class cASTExpressionUnary : public cASTNode 434 { 435 private: 436 ASToken_t m_op; 437 cASTNode* m_expr; 438 sASTypeInfo m_type; 439 440 public: cASTExpressionUnary(const cASFilePosition & fp,ASToken_t op,cASTNode * e)441 cASTExpressionUnary(const cASFilePosition& fp, ASToken_t op, cASTNode* e) 442 : cASTNode(fp), m_op(op), m_expr(e), m_type(AS_TYPE_INVALID) { ; } ~cASTExpressionUnary()443 ~cASTExpressionUnary() { delete m_expr; } 444 GetOperator()445 inline ASToken_t GetOperator() { return m_op; } SetExpression(cASTNode * expr)446 inline void SetExpression(cASTNode* expr) { m_expr = expr; } GetExpression()447 inline cASTNode* GetExpression() { return m_expr; } 448 GetType()449 const sASTypeInfo& GetType() const { return m_type; } SetType(const sASTypeInfo & type)450 inline void SetType(const sASTypeInfo& type) { m_type = type; } 451 452 void Accept(cASTVisitor& visitor); 453 }; 454 455 456 457 // -------- Expression Value Nodes -------- 458 459 class cASTBuiltInCall : public cASTNode 460 { 461 private: 462 cASTArgumentList* m_args; 463 sASTypeInfo m_type; 464 ASBuiltIn_t m_builtin; 465 cASTNode* m_target; 466 467 public: 468 cASTBuiltInCall(const cASFilePosition& fp, const cString& name, cASTNode* target = NULL); ~cASTBuiltInCall()469 ~cASTBuiltInCall() { delete m_args; delete m_target; } 470 GetBuiltIn()471 ASBuiltIn_t GetBuiltIn() const { return m_builtin; } 472 SetArguments(cASTArgumentList * args)473 void SetArguments(cASTArgumentList* args) { delete m_args; m_args = args; } GetArguments()474 cASTArgumentList* GetArguments() { return m_args; } 475 GetType()476 inline const sASTypeInfo& GetType() const { return m_type; } SetType(const sASTypeInfo & type)477 inline void SetType(const sASTypeInfo& type) { m_type = type; } 478 GetTarget()479 inline cASTNode* GetTarget() { return m_target; } 480 HasArguments()481 bool HasArguments() const { return (m_args); } 482 483 void Accept(cASTVisitor& visitor); 484 }; 485 486 487 class cASTFunctionCall : public cASTNode 488 { 489 private: 490 cString m_name; 491 cASTArgumentList* m_args; 492 sASTypeInfo m_type; 493 int m_id; 494 bool m_global; 495 const cASFunction* m_func; 496 497 public: cASTFunctionCall(const cASFilePosition & fp,const cString & name)498 cASTFunctionCall(const cASFilePosition& fp, const cString& name) 499 : cASTNode(fp), m_name(name), m_args(NULL), m_type(AS_TYPE_INVALID), m_id(-1), m_global(false), m_func(NULL) { ; } ~cASTFunctionCall()500 ~cASTFunctionCall() { delete m_args; } 501 GetName()502 const cString& GetName() const { return m_name; } 503 SetArguments(cASTArgumentList * args)504 void SetArguments(cASTArgumentList* args) { delete m_args; m_args = args; } GetArguments()505 cASTArgumentList* GetArguments() { return m_args; } 506 GetType()507 const sASTypeInfo& GetType() const { return m_type; } SetType(const sASTypeInfo & type)508 inline void SetType(const sASTypeInfo& type) { m_type = type; } 509 GetFuncID()510 inline int GetFuncID() const { return m_id; } IsFuncGlobal()511 inline bool IsFuncGlobal() const { return m_global; } SetFunc(int in_id,bool global)512 inline void SetFunc(int in_id, bool global) { m_id = in_id; m_global = global; } 513 GetASFunction()514 inline const cASFunction* GetASFunction() const { return m_func; } IsASFunction()515 inline bool IsASFunction() const { return (m_func); } SetASFunction(const cASFunction * func)516 inline void SetASFunction(const cASFunction* func) { m_func = func; } 517 HasArguments()518 bool HasArguments() const { return (m_args); } 519 520 void Accept(cASTVisitor& visitor); 521 }; 522 523 524 class cASTLiteral : public cASTNode 525 { 526 private: 527 sASTypeInfo m_type; 528 cString m_value; 529 530 public: cASTLiteral(const cASFilePosition & fp,const sASTypeInfo & t,const cString & v)531 cASTLiteral(const cASFilePosition& fp, const sASTypeInfo& t, const cString& v) : cASTNode(fp), m_type(t), m_value(v) { ; } 532 GetType()533 const sASTypeInfo& GetType() const { return m_type; } GetValue()534 inline const cString& GetValue() { return m_value; } 535 536 void Accept(cASTVisitor& visitor); 537 }; 538 539 540 class cASTLiteralArray : public cASTNode 541 { 542 private: 543 cASTArgumentList* m_values; 544 bool m_is_matrix; 545 sASTypeInfo m_type; 546 547 public: cASTLiteralArray(const cASFilePosition & fp,cASTArgumentList * v,bool is_mat)548 cASTLiteralArray(const cASFilePosition& fp, cASTArgumentList* v, bool is_mat) 549 : cASTNode(fp), m_values(v), m_is_matrix(is_mat), m_type(m_is_matrix ? AS_TYPE_MATRIX : AS_TYPE_ARRAY) { ; } ~cASTLiteralArray()550 ~cASTLiteralArray() { delete m_values; } 551 GetValues()552 inline cASTArgumentList* GetValues() { return m_values; } IsMatrix()553 inline bool IsMatrix() const { return m_is_matrix; } 554 GetType()555 const sASTypeInfo& GetType() const { return m_type; } 556 557 void Accept(cASTVisitor& visitor); 558 }; 559 560 561 class cASTLiteralDict : public cASTNode 562 { 563 public: 564 struct sMapping { 565 cASTNode* idx; 566 cASTNode* val; 567 sMappingsMapping568 sMapping(cASTNode* in_idx, cASTNode* in_val) : idx(in_idx), val(in_val) { ; } ~sMappingsMapping569 ~sMapping() { delete idx; delete val; } 570 }; 571 572 private: 573 sASTypeInfo m_type; 574 tList<sMapping> m_mappings; 575 576 public: cASTLiteralDict(const cASFilePosition & fp)577 cASTLiteralDict(const cASFilePosition& fp) : cASTNode(fp), m_type(AS_TYPE_DICT) { ; } ~cASTLiteralDict()578 ~cASTLiteralDict() { ; } 579 AddMapping(cASTNode * idx,cASTNode * val)580 void AddMapping(cASTNode* idx, cASTNode* val) { m_mappings.PushRear(new sMapping(idx, val)); } Iterator()581 tListIterator<sMapping> Iterator() { return tListIterator<sMapping>(m_mappings); } 582 GetType()583 const sASTypeInfo& GetType() const { return m_type; } 584 585 void Accept(cASTVisitor& visitor); 586 }; 587 588 589 class cASTObjectCall : public cASTNode 590 { 591 private: 592 cASTNode* m_object; 593 cString m_name; 594 cASTArgumentList* m_args; 595 sASTypeInfo m_type; 596 597 public: cASTObjectCall(const cASFilePosition & fp,cASTNode * object,const cString & name)598 cASTObjectCall(const cASFilePosition& fp, cASTNode* object, const cString& name) 599 : cASTNode(fp), m_object(object), m_name(name), m_args(NULL), m_type(AS_TYPE_RUNTIME) { ; } ~cASTObjectCall()600 ~cASTObjectCall() { delete m_object; delete m_args; } 601 GetObject()602 cASTNode* GetObject() { return m_object; } GetName()603 const cString& GetName() const { return m_name; } 604 SetArguments(cASTArgumentList * args)605 void SetArguments(cASTArgumentList* args) { delete m_args; m_args = args; } GetArguments()606 cASTArgumentList* GetArguments() { return m_args; } 607 GetType()608 const sASTypeInfo& GetType() const { return m_type; } 609 HasArguments()610 bool HasArguments() const { return (m_args); } 611 612 void Accept(cASTVisitor& visitor); 613 }; 614 615 616 class cASTObjectReference : public cASTNode 617 { 618 private: 619 cASTNode* m_object; 620 cString m_name; 621 sASTypeInfo m_type; 622 623 public: cASTObjectReference(const cASFilePosition & fp,cASTNode * object,const cString & name)624 cASTObjectReference(const cASFilePosition& fp, cASTNode* object, const cString& name) 625 : cASTNode(fp), m_object(object), m_name(name), m_type(AS_TYPE_RUNTIME) { ; } ~cASTObjectReference()626 ~cASTObjectReference() { delete m_object; } 627 GetObject()628 cASTNode* GetObject() { return m_object; } GetName()629 inline const cString& GetName() { return m_name; } 630 GetType()631 const sASTypeInfo& GetType() const { return m_type; } 632 633 void Accept(cASTVisitor& visitor); 634 }; 635 636 637 class cASTVariableReference : public cASTNode 638 { 639 private: 640 cString m_name; 641 sASTypeInfo m_type; 642 int m_id; 643 bool m_global; 644 645 public: cASTVariableReference(const cASFilePosition & fp,const cString & name)646 cASTVariableReference(const cASFilePosition& fp, const cString& name) 647 : cASTNode(fp), m_name(name), m_type(AS_TYPE_INVALID), m_id(-1), m_global(false) { ; } 648 GetName()649 inline const cString& GetName() { return m_name; } 650 GetType()651 const sASTypeInfo& GetType() const { return m_type; } SetType(const sASTypeInfo & type)652 inline void SetType(const sASTypeInfo& type) { m_type = type; } 653 GetVarID()654 inline int GetVarID() const { return m_id; } IsVarGlobal()655 inline bool IsVarGlobal() const { return m_global; } SetVar(int in_id,bool global)656 inline void SetVar(int in_id, bool global) { m_id = in_id; m_global = global; } 657 658 void Accept(cASTVisitor& visitor); 659 }; 660 661 662 class cASTUnpackTarget : public cASTNode 663 { 664 private: 665 struct sUnpackNode { 666 cString name; 667 int var_id; 668 bool global; 669 sASTypeInfo type; 670 sUnpackNodesUnpackNode671 inline sUnpackNode() : name(""), var_id(-1), global(false), type(AS_TYPE_INVALID) { ; } sUnpackNodesUnpackNode672 inline sUnpackNode(const cString& in_name) : name(in_name), var_id(-1), global(false), type(AS_TYPE_INVALID) { ; } sUnpackNodesUnpackNode673 inline sUnpackNode(const sUnpackNode& un) : name(un.name), var_id(un.var_id), global(un.global), type(un.type) { ; } 674 SetVarsUnpackNode675 inline void SetVar(int in_vi, bool in_g, const sASTypeInfo& in_t) { var_id = in_vi; global = in_g; type = in_t; } 676 }; 677 tManagedPointerArray<sUnpackNode> m_nodes; 678 bool m_last_wild; 679 bool m_last_named; 680 cASTNode* m_expr; 681 682 public: cASTUnpackTarget(const cASFilePosition & fp)683 cASTUnpackTarget(const cASFilePosition& fp) : cASTNode(fp), m_last_wild(false), m_last_named(false), m_expr(NULL) { ; } ~cASTUnpackTarget()684 ~cASTUnpackTarget() { delete m_expr; } 685 AddVar(const cString & name)686 inline void AddVar(const cString& name) { m_nodes.Push(sUnpackNode(name)); } GetSize()687 inline int GetSize() const { return m_nodes.GetSize(); } GetVarName(int idx)688 inline const cString& GetVarName(int idx) const { return m_nodes[idx].name; } GetVarID(int idx)689 inline int GetVarID(int idx) const { return m_nodes[idx].var_id; } IsVarGlobal(int idx)690 inline bool IsVarGlobal(int idx) const { return m_nodes[idx].global; } GetVarType(int idx)691 inline const sASTypeInfo& GetVarType(int idx) const { return m_nodes[idx].type; } SetVar(int idx,int var_id,bool global,const sASTypeInfo & type)692 inline void SetVar(int idx, int var_id, bool global, const sASTypeInfo& type) 693 { m_nodes[idx].SetVar(var_id, global, type); } 694 IsLastNamed()695 inline bool IsLastNamed() const { return m_last_named; } IsLastWild()696 inline bool IsLastWild() const { return m_last_wild; } 697 SetLastNamed()698 inline void SetLastNamed() { m_last_wild = true; m_last_named = true; } SetLastWild()699 inline void SetLastWild() { m_last_wild = true; m_last_named = false; } 700 GetExpression()701 cASTNode* GetExpression() const { return m_expr; } SetExpression(cASTNode * expr)702 void SetExpression(cASTNode* expr) { delete m_expr; m_expr = expr; } 703 704 void Accept(cASTVisitor& visitor); 705 }; 706 707 708 #endif 709