Zen
A cross-platform functional programming language
|
00001 00009 #pragma once 00010 00011 namespace Ast { 00014 struct Storage { 00021 enum T { 00022 Init, 00023 Block, 00024 ClosureRef, 00025 ExternalRef, 00026 }; 00027 00031 static z::string getString(const T& t); 00032 }; 00033 00036 class Node { 00037 protected: 00039 inline Node() {} 00040 public: 00042 virtual ~Node(){} 00043 }; 00044 00046 class ChildTypeSpec; 00047 class VariableDef; 00048 00050 00057 class TypeSpec : public Node { 00058 public: 00061 struct AccessType { 00063 enum T { 00064 Private, 00065 Internal, 00066 Protected, 00067 Public, 00068 Export, 00069 Native, 00070 Test, 00071 }; 00072 00076 static inline bool isPublic(const T& t) { return ((t == Public) || (t == Protected) || (t == Export) || (t == Native)); } 00077 00081 static z::string getString(const T& t); 00082 }; 00083 00084 public: 00086 typedef z::list<ChildTypeSpec*> ChildList; 00087 00089 typedef z::dict<z::string, ChildTypeSpec*> ChildMap; 00090 00091 protected: 00095 inline TypeSpec(const AccessType::T& accessType, const z::string& name) : _accessType(accessType), _name(name) {} 00096 00097 public: 00100 inline bool isPublic() const { return AccessType::isPublic(_accessType); } 00101 00102 public: 00105 inline const AccessType::T& getAccessType() const { return _accessType; } 00106 00109 inline const z::string& getName() const { return _name; } 00110 00111 public: 00114 inline void setAccessType(const AccessType::T& accessType) { _accessType = accessType; } 00115 00118 inline void setName(const z::string& name) { _name = name; } 00119 00120 public: 00124 template <typename T> inline T& addChild(T& child); 00125 00129 template <typename T> inline T* hasChild(const z::string& name) const; 00130 00131 public: 00134 inline const ChildList& getChildList() const {return _childList;} 00135 00136 public: 00138 class Visitor; 00139 00142 virtual void visit(Visitor& visitor) const = 0; 00143 00144 public: 00149 virtual z::string getFullName(const z::string& sep) const = 0; 00150 00151 public: 00156 virtual const Ast::VariableDef* hasMember(const z::string& name) const {unused(name); return 0;} 00157 00158 private: 00160 AccessType::T _accessType; 00161 00163 z::string _name; 00164 00165 private: 00167 ChildList _childList; 00168 00170 ChildMap _childMap; 00171 }; 00172 00174 00179 class QualifiedType : public Node { 00180 public: 00183 typedef z::list<const QualifiedType*> List; 00184 00185 public: 00190 inline QualifiedType(const bool& isConst, const TypeSpec& type, const bool& isRef) : _isConst(isConst), _type(type), _isRef(isRef) {} 00191 00192 public: 00195 inline const bool& isConst() const {return _isConst;} 00196 00199 inline const bool& isRef() const { return _isRef; } 00200 00203 inline const TypeSpec& getTypeSpec() const { return _type; } 00204 00205 private: 00207 bool _isConst; 00208 00210 const TypeSpec& _type; 00211 00213 bool _isRef; 00214 }; 00215 00217 // Abstract types 00219 00225 class VariableDef : public Node { 00226 public: 00228 enum DefType { 00229 Param, 00230 Closure, 00231 Local, 00232 Shared, 00233 }; 00234 00235 public: 00238 typedef z::list<VariableDef*> List; 00239 00240 public: 00245 inline VariableDef(const DefType& defType, const Ast::QualifiedType& type, const z::string& name) : _defType(defType), _type(type), _name(name) {} 00246 00247 public: 00250 inline const DefType& getDefType() const {return _defType;} 00251 00254 inline const Ast::QualifiedType& getType() const {return _type;} 00255 00258 inline const z::string& getName() const {return _name;} 00259 00260 private: 00262 const DefType _defType; 00263 00265 const Ast::QualifiedType& _type; 00266 00268 z::string _name; 00269 }; 00270 00272 00277 class VariableDefListBase : public Node { 00278 public: 00282 typedef z::list<const VariableDef*> List; 00283 00284 protected: 00286 inline VariableDefListBase() {} 00287 00288 public: 00291 inline const List& getList() const {return _list;} 00292 00295 inline const VariableDef& getFirst() const {return ref(_list.front());} 00296 00299 inline const VariableDef& getLast() const {return ref(_list.last());} 00300 00305 inline const Ast::VariableDef& addDef(const Ast::VariableDef& child) { 00306 _list.append(ptr(child)); 00307 return child; 00308 } 00309 00310 private: 00312 List _list; 00313 }; 00314 00316 00323 class VariableRef : public VariableDefListBase { 00324 public: 00327 inline VariableRef(const Storage::T& storage) : _storage(storage) {} 00328 00329 public: 00332 inline const Ast::QualifiedType& getType() const {return getFirst().getType();} 00333 00336 inline const z::string& getName() const {return getFirst().getName();} 00337 00338 public: 00340 inline void setStorage(const Storage::T& storage) {_storage = storage;} 00341 00344 inline const Storage::T& getStorage() const {return _storage;} 00345 00346 private: 00348 Storage::T _storage; 00349 }; 00350 00352 00357 class VariableRefList : public Node { 00358 public: 00360 typedef z::list<const VariableRef*> List; 00361 00362 public: 00364 inline VariableRefList() {} 00365 00366 public: 00369 inline const List& getList() const {return _list;} 00370 00371 public: 00376 inline const Ast::VariableRef& addRef(const Ast::VariableRef& vref) { 00377 _list.append(ptr(vref)); 00378 return vref; 00379 } 00380 public: 00384 inline bool hasRef(const Ast::VariableRef& vref) const { 00385 for(List::iterator it(_list); !it.end(); ++it) { 00386 const VariableRef& vr = ref(*it); 00387 if(ptr(vr.getFirst()) == ptr(vref.getFirst())) 00388 return true; 00389 } 00390 return false; 00391 } 00392 00393 public: 00396 inline void appendList(const VariableRefList& src) { 00397 for(List::iterator it(src.getList()); !it.end(); ++it) { 00398 const Ast::VariableRef& vd = ref(*it); 00399 if(!hasRef(vd)) { 00400 addRef(vd); 00401 } 00402 } 00403 } 00404 00405 private: 00407 List _list; 00408 }; 00409 00411 00415 class VariableDefMap : public VariableDefListBase { 00416 public: 00418 inline VariableDefMap() {} 00419 00420 public: 00424 inline const Ast::VariableDef* hasDef(const z::string& name) const { 00425 DefMap::found f = _defMap.find(name); 00426 if(!f) 00427 return 0; 00428 const Ast::VariableDef* t = *f; 00429 return t; 00430 } 00431 00436 inline const Ast::VariableDef& addDef(const Ast::VariableDef& child) { 00437 const z::string& name = child.getName(); 00438 assert(hasDef(name) == 0); 00439 _defMap.insert(name, ptr(child)); 00440 return VariableDefListBase::addDef(child); 00441 } 00442 00445 inline void appendList(const VariableDefMap& src) { 00446 for(List::iterator it(src.getList()); !it.end(); ++it) { 00447 const Ast::VariableDef& vd = ref(*it); 00448 if(!hasDef(vd.getName())) { 00449 addDef(vd); 00450 } 00451 } 00452 } 00453 00454 private: 00456 typedef z::dict<z::string, const VariableDef*> DefMap; 00457 00459 DefMap _defMap; 00460 }; 00461 00463 00471 class Scope : public Node { 00472 public: 00474 enum Type { 00475 InParam, 00476 Block, 00477 Continuation, 00478 }; 00479 public: 00482 inline Scope(const Type& type) : /*ChildTypeSpec(AccessType::Private, ""),*/ _type(type) {} 00483 00484 public: 00487 inline const Type& getType() const {return _type;} 00488 00493 inline const Ast::VariableDef& addDef(const Ast::VariableDef& child) {return _defList.addDef(child);} 00494 00497 inline const VariableDefMap& getDefList() const {return _defList;} 00498 00499 private: 00501 const Type _type; 00502 00504 VariableDefMap _defList; 00505 }; 00506 00509 class Expr; 00510 00512 00517 class ExprVariableDef : public VariableDef { 00518 protected: 00524 inline ExprVariableDef(const DefType& defType, const Ast::QualifiedType& type, const z::string& name, const Ast::Expr& expr) : VariableDef(defType, type, name), _expr(expr) {} 00525 00526 public: 00529 inline const Expr& getExpr() const {return _expr;} 00530 00531 private: 00533 const Ast::Expr& _expr; 00534 }; 00535 00538 class ParamVariableDef : public ExprVariableDef { 00539 public: 00544 inline ParamVariableDef(const Ast::QualifiedType& type, const z::string& name, const Ast::Expr& expr) : ExprVariableDef(Param, type, name, expr) {} 00545 }; 00546 00549 class StructMemberVariableDef : public ExprVariableDef { 00550 public: 00555 inline StructMemberVariableDef(const Ast::QualifiedType& type, const z::string& name, const Ast::Expr& expr) : ExprVariableDef(Local, type, name, expr) {} 00556 }; 00557 00560 class InitVariableDef : public ExprVariableDef { 00561 public: 00567 inline InitVariableDef(const DefType& defType, const Ast::QualifiedType& qtype, const z::string& name, const Ast::Expr& expr) : ExprVariableDef(defType, qtype, name, expr) {} 00568 }; 00569 00572 class SharedVariableDef : public ExprVariableDef { 00573 public: 00580 inline SharedVariableDef(const DefType& defType, const Ast::QualifiedType& qtype, const z::string& name, const Ast::Expr& expr) : ExprVariableDef(defType, qtype, name, expr) {} 00581 }; 00582 00584 00589 class RootTypeSpec : public TypeSpec { 00590 protected: 00597 inline RootTypeSpec(const AccessType::T& accessType, const z::string& name) : TypeSpec(accessType, name) {} 00598 00599 private: 00603 virtual z::string getFullName(const z::string& sep) const {unused(sep); return getName();} 00604 }; 00605 00607 00611 class ChildTypeSpec : public TypeSpec { 00612 protected: 00619 inline ChildTypeSpec(const AccessType::T& accessType, const z::string& name) : TypeSpec(accessType, name), _parent(0) {} 00620 00626 inline ChildTypeSpec(const AccessType::T& accessType, TypeSpec& parent, const z::string& name) : TypeSpec(accessType, name), _parent(ptr(parent)) {} 00627 00628 public: 00634 inline void setParent(TypeSpec& parent) { 00635 assert(0 == _parent); 00636 _parent = ptr(parent); 00637 } 00638 00641 inline TypeSpec* hasParent() const {return _parent;} 00642 00645 inline TypeSpec& getParent() const {return ref(_parent);} 00646 00647 public: 00651 virtual z::string getFullName(const z::string& sep) const { 00652 const z::string& name = getName(); 00653 if(name.length() == 0) 00654 return getParent().getFullName(sep); 00655 if(hasParent()) { 00656 const z::string pname = getParent().getFullName(sep); 00657 if(pname.length() == 0) 00658 return name; 00659 return pname + sep + name; 00660 } 00661 return "??" + sep + name; 00662 } 00663 private: 00665 TypeSpec* _parent; 00666 }; 00667 00669 00673 class UserDefinedTypeSpec : public ChildTypeSpec { 00674 public: 00676 enum NativeType { 00677 ntNone, 00678 ntIntrinsic, 00679 ntSystem, 00680 ntQuery, 00681 }; 00682 00683 protected: 00689 inline UserDefinedTypeSpec(const AccessType::T& accessType, const z::string& name, const NativeType& ntype) : ChildTypeSpec(accessType, name), _ntype(ntype) {} 00690 00691 public: 00694 inline const NativeType& getNativeType() const {return _ntype;} 00695 00696 private: 00698 const NativeType _ntype; 00699 }; 00700 00703 class StructDefList; 00704 00708 class StructDef : public UserDefinedTypeSpec { 00709 public: 00715 inline StructDef(const AccessType::T& accessType, const z::string& name, const NativeType& ntype) 00716 : UserDefinedTypeSpec(accessType, name, ntype), _defList(0), _subTypeList(0) {} 00717 public: 00723 inline void setDefList(const VariableDefMap& defList) {assert(0 == _defList); _defList = ptr(defList);} 00724 00728 inline bool hasDefList() const {return (0 != _defList);} 00729 00732 inline const VariableDefMap& getDefList() const {return ref(_defList);} 00733 00734 public: 00740 inline void setSubTypeList(const StructDefList& subTypeList) {_subTypeList = ptr(subTypeList);} 00741 00744 inline bool hasSubTypeList() const {return (0 != _subTypeList);} 00745 00748 inline const StructDefList& getSubTypeList() const {return ref(_subTypeList);} 00749 00750 private: 00753 virtual void visit(TypeSpec::Visitor& visitor) const; 00754 00755 private: 00759 virtual const Ast::VariableDef* hasMember(const z::string& name) const; 00760 00761 private: 00763 const VariableDefMap* _defList; 00764 00766 const StructDefList* _subTypeList; 00767 }; 00768 00771 class StructDefList : public Node { 00772 public: 00774 typedef z::list<const StructDef*> List; 00775 public: 00777 inline StructDefList() {} 00778 00779 public: 00782 inline const List& getList() const {return _list;} 00783 00784 public: 00789 inline const Ast::StructDef& addSubType(const Ast::StructDef& subType) { 00790 _list.append(ptr(subType)); 00791 return subType; 00792 } 00793 00794 public: 00798 inline const StructDef* hasSubType(const z::string& name) const { 00799 for(List::iterator it(_list); !it.end(); ++it) { 00800 const StructDef& sd = ref(*it); 00801 if(sd.getName() == name) 00802 return ptr(sd); 00803 } 00804 return 0; 00805 } 00806 private: 00808 List _list; 00809 }; 00810 00813 class EnumMemberDef : public ChildTypeSpec { 00814 public: 00821 inline EnumMemberDef(const AccessType::T& accessType, const z::string& name, const bool& hasInit, const Ast::Expr& initExpr) 00822 : ChildTypeSpec(accessType, name), _hasInit(hasInit), _initExpr(initExpr) {} 00823 00824 public: 00827 inline const bool& hasInitExpr() const {return _hasInit;} 00828 00831 inline const Ast::Expr& getInitExpr() const {return _initExpr;} 00832 00833 private: 00836 virtual void visit(TypeSpec::Visitor& visitor) const; 00837 00838 private: 00840 const bool _hasInit; 00841 00843 const Ast::Expr& _initExpr; 00844 }; 00845 00848 class EnumMemberDefList : public Node { 00849 public: 00851 typedef z::list<const EnumMemberDef*> List; 00852 00853 public: 00855 inline EnumMemberDefList() {} 00856 00857 public: 00860 inline const List& getList() const {return _list;} 00861 00864 inline void addDef(const EnumMemberDef& def) {_list.append(ptr(def));} 00865 00866 private: 00868 List _list; 00869 }; 00870 00873 class EnumDef : public UserDefinedTypeSpec { 00874 public: 00881 inline EnumDef(const AccessType::T& accessType, const z::string& name, const NativeType& ntype, const EnumMemberDefList& defList) 00882 : UserDefinedTypeSpec(accessType, name, ntype), _defList(defList) {} 00883 00884 public: 00887 inline const EnumMemberDefList& getDefList() const {return _defList;} 00888 00889 private: 00892 virtual void visit(TypeSpec::Visitor& visitor) const; 00893 00894 private: 00896 const EnumMemberDefList& _defList; 00897 }; 00898 00901 class OutParam : public UserDefinedTypeSpec { 00902 public: 00910 inline OutParam(const AccessType::T& accessType, const z::string& name, const NativeType& ntype, const VariableDefMap& defList, const bool& isTuple) 00911 : UserDefinedTypeSpec(accessType, name, ntype), _defList(defList), _isTuple(isTuple) {} 00912 00913 public: 00916 inline const VariableDefMap& getDefList() const {return _defList;} 00917 00920 inline const bool& getIsTuple() const {return _isTuple;} 00921 00922 private: 00925 virtual void visit(TypeSpec::Visitor& visitor) const; 00926 00930 virtual const Ast::VariableDef* hasMember(const z::string& name) const; 00931 00932 private: 00934 const VariableDefMap& _defList; 00935 00937 const bool _isTuple; 00938 }; 00939 00942 class SharedDef : public UserDefinedTypeSpec { 00943 public: 00950 inline SharedDef(const AccessType::T& accessType, const z::string& name, const NativeType& ntype, const VariableDefMap& defList) 00951 : UserDefinedTypeSpec(accessType, name, ntype), _defList(defList) {} 00952 00953 public: 00956 inline const VariableDefMap& getDefList() const {return _defList;} 00957 00958 private: 00961 virtual void visit(TypeSpec::Visitor& visitor) const; 00962 00966 virtual const Ast::VariableDef* hasMember(const z::string& name) const; 00967 00968 private: 00970 const VariableDefMap& _defList; 00971 }; 00972 00975 class TypeDefTypeSpec : public UserDefinedTypeSpec { 00976 protected: 00982 inline TypeDefTypeSpec(const AccessType::T& accessType, const z::string& name, const NativeType& ntype) : UserDefinedTypeSpec(accessType, name, ntype) {} 00983 }; 00984 00987 class TypeDecl : public TypeDefTypeSpec { 00988 public: 00994 inline TypeDecl(const AccessType::T& accessType, const z::string& name, const NativeType& ntype) : TypeDefTypeSpec(accessType, name, ntype) {} 00995 00996 private: 00999 virtual void visit(TypeSpec::Visitor& visitor) const; 01000 }; 01001 01004 class TypeDef : public TypeDefTypeSpec { 01005 public: 01012 inline TypeDef(const AccessType::T& accessType, const z::string& name, const NativeType& ntype, const Ast::QualifiedType& type) 01013 : TypeDefTypeSpec(accessType, name, ntype), _type(type) {} 01014 01015 public: 01018 inline const Ast::QualifiedType& getTargetType() const {return _type;} 01019 01020 private: 01023 virtual void visit(TypeSpec::Visitor& visitor) const; 01024 01025 private: 01027 const Ast::QualifiedType& _type; 01028 }; 01029 01032 class TemplateTypeSpec : public ChildTypeSpec { 01033 public: 01038 inline TemplateTypeSpec(const AccessType::T& accessType, const z::string& name) : ChildTypeSpec(accessType, name) {} 01039 }; 01040 01042 01046 class OwnerTemplate : public TemplateTypeSpec { 01047 public: 01053 inline OwnerTemplate(const AccessType::T& accessType, const z::string& name, const Ast::QualifiedType& type) : TemplateTypeSpec(accessType, name), _type(type) {} 01054 01055 public: 01058 inline const Ast::QualifiedType& getType() const {return _type;} 01059 01060 private: 01063 virtual void visit(TypeSpec::Visitor& visitor) const; 01064 01065 private: 01067 const Ast::QualifiedType& _type; 01068 }; 01069 01072 class ListTemplate : public TemplateTypeSpec { 01073 public: 01079 inline ListTemplate(const AccessType::T& accessType, const z::string& name, const Ast::QualifiedType& type) : TemplateTypeSpec(accessType, name), _type(type) {} 01080 01081 public: 01084 inline const Ast::QualifiedType& getType() const {return _type;} 01085 01086 private: 01089 virtual void visit(TypeSpec::Visitor& visitor) const; 01090 01091 private: 01093 const Ast::QualifiedType& _type; 01094 }; 01095 01098 class DictTemplate : public TemplateTypeSpec { 01099 public: 01106 inline DictTemplate(const AccessType::T& accessType, const z::string& name, const Ast::QualifiedType& key, const Ast::QualifiedType& type) 01107 : TemplateTypeSpec(accessType, name), _key(key), _type(type) {} 01108 public: 01111 inline const Ast::QualifiedType& getKey() const {return _key;} 01112 01115 inline const Ast::QualifiedType& getType() const {return _type;} 01116 01117 private: 01120 virtual void visit(TypeSpec::Visitor& visitor) const; 01121 01122 private: 01124 const Ast::QualifiedType& _key; 01125 01127 const Ast::QualifiedType& _type; 01128 }; 01129 01133 class MethodTypeSpec : public UserDefinedTypeSpec { 01134 protected: 01142 inline MethodTypeSpec(const AccessType::T& accessType, const QualifiedType& out, const z::string& name, Ast::Scope& in, const NativeType& ntype) 01143 : UserDefinedTypeSpec(accessType, name, ntype), _out(out), _in(in), _isTuple(false) {} 01144 01145 public: 01148 inline const QualifiedType& getOutType() const {return _out;} 01149 01152 inline Scope& getInType() {return _in;} 01153 01156 inline const Scope& getInType() const {return _in;} 01157 01158 public: 01161 inline void setIsTuple(const bool& val) {_isTuple = val;} 01162 01165 inline const bool& getIsTuple() const {return _isTuple;} 01166 01167 private: 01169 const QualifiedType& _out; 01170 01172 Scope& _in; 01173 01175 bool _isTuple; 01176 }; 01177 01180 class ImplItem; 01181 01184 class FunctionDef : public MethodTypeSpec { 01185 public: 01187 struct Modifier { 01189 enum T { 01190 None, 01191 Routine, 01192 Grammar, 01193 Window, 01194 }; 01195 }; 01196 01197 public: 01206 inline FunctionDef(const AccessType::T& accessType, const QualifiedType& out, const z::string& name, Scope& in, const NativeType& ntype, const Ast::FunctionDef::Modifier::T& modifier) 01207 : MethodTypeSpec(accessType, out, name, in, ntype), _modifier(modifier), _impl(0) {} 01208 01209 public: 01212 inline const Modifier::T& getModifier() const {return _modifier;} 01213 01216 inline bool hasImpl() const {return (0 != _impl);} 01217 01220 inline const ImplItem& getImpl() const {return ref(_impl);} 01221 01224 inline void setImpl(const ImplItem& impl) {assert(0 == _impl); _impl = ptr(impl);} 01225 01226 public: 01229 inline void setGrammarName(const z::string& val) {_gname = val;} 01230 01233 inline const z::string& getGrammarName() const {return _gname;} 01234 01235 private: 01238 virtual void visit(TypeSpec::Visitor& visitor) const; 01239 01240 private: 01242 const Ast::FunctionDef::Modifier::T _modifier; 01243 01245 const ImplItem* _impl; 01246 01248 z::string _gname; 01249 }; 01250 01253 class Namespace : public ChildTypeSpec { 01254 public: 01260 inline Namespace(const AccessType::T& accessType, TypeSpec& parent, const z::string& name) : ChildTypeSpec(accessType, parent, name) {} 01261 01262 public: 01267 inline Namespace* hasNamespace(const z::string& name) {return TypeSpec::hasChild<Namespace>(name);} 01268 01272 inline Namespace& addNamespace(Namespace& child) {return TypeSpec::addChild<Namespace>(child);} 01273 01274 private: 01277 virtual void visit(TypeSpec::Visitor& visitor) const; 01278 }; 01279 01283 class StructInitItem : public Node { 01284 public: 01289 inline StructInitItem(const VariableDef& mref, const Ast::Expr& expr) : _mref(mref), _expr(expr) {} 01290 01291 public: 01294 inline const VariableDef& getMemberRef() const {return _mref;} 01295 01298 inline const Expr& getExpr() const {return _expr;} 01299 private: 01301 const VariableDef& _mref; 01302 01304 const Expr& _expr; 01305 }; 01306 01308 01312 class StructInitList : public Node { 01313 public: 01315 typedef z::list<const StructInitItem*> List; 01316 public: 01318 inline StructInitList() {} 01319 01320 public: 01323 inline void addItem(const StructInitItem& item) {_list.append(ptr(item));} 01324 01327 inline const List& getList() const {return _list;} 01328 01329 private: 01331 List _list; 01332 }; 01333 01338 class GrammarToken : public Node { 01339 public: 01346 inline GrammarToken(const z::string& name, const z::string& txt, const bool& isRex, const bool& isNot) 01347 : Node(), _name(name), _txt(txt), _isRex(isRex), _isNot(isNot) {} 01348 01349 public: 01352 inline const z::string& getName() const {return _name;} 01353 01356 inline const z::string& getText() const {return _txt;} 01357 01360 inline const bool& isRex() const {return _isRex;} 01361 01364 inline const bool& isNot() const {return _isNot;} 01365 01366 private: 01368 const z::string _name; 01369 01371 const z::string _txt; 01372 01374 const bool _isRex; 01375 01377 const bool _isNot; 01378 }; 01379 01383 class GrammarTokenList : public Node { 01384 public: 01386 typedef z::list<const GrammarToken*> List; 01387 01388 public: 01390 inline GrammarTokenList() : Node() {} 01391 01392 public: 01395 inline const List& getList() const {return _list;} 01396 01397 public: 01400 inline void addToken(const GrammarToken& token) {_list.append(ptr(token));} 01401 01404 inline bool isEmpty() {return _list.empty();} 01405 01407 inline void clear() {return _list.clear();} 01408 01409 private: 01411 List _list; 01412 }; 01413 01416 class GrammarMember : public Node { 01417 protected: 01419 inline GrammarMember() : Node() {} 01420 public: 01422 class Visitor; 01423 01426 virtual void visit(GrammarMember::Visitor& visitor) const = 0; 01427 }; 01428 01431 class GrammarMemberId : public GrammarMember { 01432 public: 01435 inline GrammarMemberId(const z::string& txt) : GrammarMember(), _txt(txt) {} 01436 01437 public: 01440 inline const z::string& getText() const {return _txt;} 01441 01442 private: 01445 virtual void visit(GrammarMember::Visitor& visitor) const; 01446 01447 private: 01449 const z::string _txt; 01450 }; 01451 01454 class GrammarMemberNameId : public GrammarMember { 01455 public: 01459 inline GrammarMemberNameId(const Ast::VariableDef& vdef, const z::string& txt) 01460 : GrammarMember(), _vdef(vdef), _txt(txt) {} 01461 01462 public: 01465 inline const Ast::VariableDef& getDef() const {return _vdef;} 01466 01469 inline const z::string& getText() const {return _txt;} 01470 01471 private: 01474 virtual void visit(GrammarMember::Visitor& visitor) const; 01475 01476 private: 01478 const Ast::VariableDef& _vdef; 01479 01481 const z::string _txt; 01482 }; 01483 01486 class GrammarMemberList : public Node { 01487 public: 01489 typedef z::list<const GrammarMember*> List; 01490 01491 public: 01493 inline GrammarMemberList() : Node() {} 01494 01495 public: 01498 inline void addMember(const GrammarMember& member) {_list.append(ptr(member));} 01499 01502 inline const List& getList() const {return _list;} 01503 01504 private: 01506 List _list; 01507 }; 01508 01511 class FunctionBlock; 01512 01515 class GrammarStatement : public Node { 01516 protected: 01522 inline GrammarStatement(const z::string& name, const Ast::FunctionDef& fdef, const Ast::FunctionBlock& fblock) 01523 : Node(), _name(name), _fdef(fdef), _fblock(fblock) {} 01524 01525 public: 01528 inline const z::string& getName() const {return _name;} 01529 01532 inline const FunctionDef& getFunctionDef() const {return _fdef;} 01533 01536 inline const FunctionBlock& getBlock() const {return _fblock;} 01537 01538 public: 01540 class Visitor; 01541 01544 virtual void visit(GrammarStatement::Visitor& visitor) const = 0; 01545 01546 private: 01548 const z::string _name; 01549 01551 const Ast::FunctionDef& _fdef; 01552 01554 const Ast::FunctionBlock& _fblock; 01555 }; 01556 01559 class GrammarRuleStatement : public GrammarStatement { 01560 public: 01567 inline GrammarRuleStatement(const z::string& name, const Ast::FunctionDef& fdef, const Ast::FunctionBlock& fblock, const Ast::GrammarMemberList& list) 01568 : GrammarStatement(name, fdef, fblock), _list(list) {} 01569 01570 public: 01573 inline const Ast::GrammarMemberList& getList() const {return _list;} 01574 01575 private: 01578 virtual void visit(GrammarStatement::Visitor& visitor) const; 01579 01580 private: 01582 const Ast::GrammarMemberList& _list; 01583 }; 01584 01587 class GrammarLexer; 01588 01591 class LexerStatement : public GrammarStatement { 01592 public: 01600 inline LexerStatement(const z::string& name, const Ast::FunctionDef& fdef, const Ast::FunctionBlock& fblock, GrammarLexer& lexer, const Ast::GrammarTokenList& list) 01601 : GrammarStatement(name, fdef, fblock), _lexer(lexer), _list(list) {} 01602 01603 public: 01606 inline const GrammarLexer& getLexer() const {return _lexer;} 01607 01610 inline const Ast::GrammarTokenList& getList() const {return _list;} 01611 01612 private: 01615 virtual void visit(GrammarStatement::Visitor& visitor) const; 01616 01617 private: 01619 const GrammarLexer& _lexer; 01620 01622 const Ast::GrammarTokenList& _list; 01623 }; 01624 01627 class LexerStatementList : public Node { 01628 public: 01630 typedef z::list<LexerStatement*> List; 01631 01632 public: 01634 inline LexerStatementList() : Node() {} 01635 01636 public: 01639 inline const List& getList() const {return _list;} 01640 01641 public: 01644 inline void addStatement(LexerStatement& statement) {_list.append(ptr(statement));} 01645 01646 private: 01648 List _list; 01649 }; 01650 01653 class GrammarLexer : public Node { 01654 public: 01658 inline GrammarLexer(const z::string& name) : Node(), _name(name), _list(0) {} 01659 01660 public: 01663 inline const z::string& getName() const {return _name;} 01664 01667 inline void setList(const LexerStatementList& value) {_list = ptr(value);} 01668 01671 inline const LexerStatementList& getList() const {return ref(_list);} 01672 01673 private: 01675 const z::string _name; 01676 01678 const LexerStatementList* _list; 01679 }; 01680 01683 class GrammarLexerList : public Node { 01684 public: 01686 typedef z::list<const GrammarLexer*> List; 01687 01688 public: 01690 inline GrammarLexerList() : Node() {} 01691 01692 public: 01695 inline const List& getList() const {return _list;} 01696 01699 inline void addLexer(const GrammarLexer& lexer) {_list.append(ptr(lexer));} 01700 01701 private: 01703 List _list; 01704 }; 01705 01708 class GrammarStatementList : public Node { 01709 public: 01711 typedef z::list<const GrammarStatement*> List; 01712 01713 public: 01715 inline GrammarStatementList() : Node() {} 01716 01717 public: 01720 inline const List& getList() const {return _list;} 01721 01722 public: 01725 inline void addRuleStatement(GrammarStatement& statement) {_list.append(ptr(statement));} 01726 01727 private: 01729 List _list; 01730 }; 01731 01734 class GrammarOptionValueList : public Node { 01735 public: 01737 inline GrammarOptionValueList() : Node() {} 01738 01739 public: 01742 inline const z::stringlist& getList() const {return _list;} 01743 01746 inline void addValue(const z::string& value) {_list.append(value);} 01747 01748 private: 01750 z::stringlist _list; 01751 }; 01752 01755 class GrammarOption : public Node { 01756 public: 01761 inline GrammarOption(const z::string& name, const GrammarOptionValueList& list) : Node(), _name(name), _list(list) {} 01762 01763 public: 01766 inline const z::string& getName() const {return _name;} 01767 01770 inline const GrammarOptionValueList& getList() const {return _list;} 01771 01772 private: 01774 const z::string _name; 01775 01777 const GrammarOptionValueList& _list; 01778 }; 01779 01782 class GrammarOptionList : public Node { 01783 public: 01785 typedef z::list<const GrammarOption*> List; 01786 01787 public: 01789 inline GrammarOptionList() : Node() {} 01790 01791 public: 01794 inline const List& getList() const {return _list;} 01795 01798 inline void addOption(GrammarOption& option) {_list.append(ptr(option));} 01799 01800 private: 01802 List _list; 01803 }; 01804 01808 class FunctionImplItem; 01809 01811 01815 class ImplItem : public Node { 01816 protected: 01821 inline ImplItem(const int& idx, const Ast::FunctionDef& fdef) : _idx(idx), _fdef(fdef) {} 01822 01823 public: 01826 inline const int& getIndex() const {return _idx;} 01827 01830 inline const Ast::FunctionDef& getFunctionDef() const {return _fdef;} 01831 01832 public: 01834 class Visitor; 01835 01838 virtual void visit(Visitor& visitor) const = 0; 01839 01840 public: 01844 virtual const Ast::FunctionImplItem& getFunctionImplItem() const = 0; 01845 01846 private: 01848 const int _idx; 01849 01851 const Ast::FunctionDef& _fdef; 01852 }; 01853 01855 // Container items 01858 class Expr; 01859 01862 template <typename ItemT> 01863 class ListBase : public Node { 01864 public: 01866 typedef z::list<const ItemT*> List; 01867 01868 public: 01870 inline ListBase() {} 01871 01872 public: 01875 inline const List& getList() const {return _list;} 01876 01879 inline void addItem(const ItemT& item) {_list.append(&item);} 01880 01881 private: 01883 List _list; 01884 }; 01885 01888 class ListItem : public Node { 01889 public: 01893 inline ListItem(const Expr& expr) : _expr(expr) {} 01894 01895 public: 01898 inline const Ast::Expr& getExpr() const {return _expr;} 01899 01900 private: 01902 const Expr& _expr; 01903 }; 01904 01907 class ListList : public ListBase<ListItem> { 01908 public: 01910 inline ListList() : _type(0) {} 01911 01912 public: 01915 inline const QualifiedType* hasType() const {return _type;} 01916 01920 inline void setType(const QualifiedType* type) {_type = type;} 01921 01922 private: 01924 const QualifiedType* _type; 01925 }; 01926 01929 class DictItem : public Node { 01930 public: 01935 inline DictItem(const Expr& key, const Expr& expr) : _key(key), _expr(expr) {} 01936 01937 public: 01940 inline const Ast::Expr& getKey() const {return _key;} 01941 01944 inline const Ast::Expr& getExpr() const {return _expr;} 01945 01946 private: 01948 const Expr& _key; 01949 01951 const Expr& _expr; 01952 }; 01953 01956 class DictList : public ListBase<DictItem> { 01957 public: 01959 inline DictList() : _key(0), _type(0) {} 01960 01961 public: 01964 inline const QualifiedType* hasKey() const {return _key;} 01965 01969 inline void setKeyType(const QualifiedType* key) {_key = key;} 01970 01973 inline const QualifiedType* hasType() const {return _type;} 01974 01978 inline void setValueType(const QualifiedType* type) {_type = type;} 01979 01980 private: 01982 const QualifiedType* _key; 01983 01985 const QualifiedType* _type; 01986 }; 01987 01989 // Expressions 01992 class Expr : public Node { 01993 public: 01997 inline Expr(const QualifiedType& type) : _type(type) {} 01998 01999 public: 02001 class Visitor; 02002 02005 virtual void visit(Visitor& visitor) const = 0; 02006 02007 public: 02010 inline const QualifiedType& getType() const { return _type; } 02011 02012 private: 02014 const QualifiedType& _type; 02015 }; 02016 02019 class ExprList : public Node { 02020 public: 02022 typedef z::list<const Expr*> List; 02023 02024 public: 02027 inline const List& getList() const {return _list;} 02028 02031 inline void addExpr(const Expr& expr) {_list.append(&expr);} 02032 02033 private: 02035 List _list; 02036 }; 02037 02039 02046 class InvokerType : public Node { 02047 protected: 02051 inline InvokerType(const FunctionDef& functionDef) : _functionDef(functionDef) {} 02052 02053 public: 02056 inline const FunctionDef& getFunctionDef() const {return _functionDef;} 02057 02058 public: 02060 class Visitor; 02061 02064 virtual void visit(Visitor& visitor) const = 0; 02065 02066 private: 02068 const FunctionDef& _functionDef; 02069 }; 02070 02073 class Invoker : public Node { 02074 public: 02079 inline Invoker(const InvokerType& invokerType, const ExprList& exprList) : _invokerType(invokerType), _exprList(exprList) {} 02080 02081 public: 02084 inline const InvokerType& getInvokerType() const {return _invokerType;} 02085 02088 inline const ExprList& getExprList() const {return _exprList;} 02089 02090 private: 02092 const InvokerType& _invokerType; 02093 02095 const ExprList& _exprList; 02096 }; 02097 02099 02106 class FunctionCall : public InvokerType { 02107 public: 02111 inline FunctionCall(const FunctionDef& functionDef) : InvokerType(functionDef) {} 02112 02113 private: 02116 virtual void visit(Visitor& visitor) const; 02117 }; 02118 02120 02128 class FunctorCall : public InvokerType { 02129 public: 02134 inline FunctorCall(const FunctionDef& functionDef, const Expr& expr) : InvokerType(functionDef), _expr(expr) {} 02135 02136 public: 02139 inline const Expr& getExpr() const {return _expr;} 02140 02141 private: 02144 virtual void visit(Visitor& visitor) const; 02145 02146 private: 02148 const Expr& _expr; 02149 }; 02150 02152 02159 class FunctionDefCall : public InvokerType { 02160 public: 02165 inline FunctionDefCall(const FunctionDef& functionDef, const ImplItem& item) : InvokerType(functionDef), _item(item) {} 02166 02167 public: 02170 inline const ImplItem& getImpl() const {return _item;} 02171 02172 private: 02175 virtual void visit(Visitor& visitor) const; 02176 02177 private: 02179 const ImplItem& _item; 02180 }; 02181 02183 02190 class FunctionImplCall : public InvokerType { 02191 public: 02196 inline FunctionImplCall(const FunctionDef& functionDef, const ImplItem& item) : InvokerType(functionDef), _item(item) {} 02197 02198 public: 02201 inline const ImplItem& getImpl() const {return _item;} 02202 02203 private: 02206 virtual void visit(Visitor& visitor) const; 02207 02208 private: 02210 const ImplItem& _item; 02211 }; 02212 02214 // Expression concrete classes 02216 02223 class TernaryOpExpr : public Expr { 02224 public: 02233 inline TernaryOpExpr(const QualifiedType& type, const Expr& lhs, const z::string& op1, const Expr& rhs1, const z::string& op2, const Expr& rhs2) 02234 : Expr(type), _lhs(lhs), _op1(op1), _rhs1(rhs1), _op2(op2), _rhs2(rhs2) {} 02235 02236 public: 02239 inline const Expr& getLhs() const {return _lhs;} 02240 02243 inline const z::string& getOp1() const {return _op1;} 02244 02247 inline const Expr& getRhs1() const {return _rhs1;} 02248 02251 inline const z::string& getOp2() const {return _op2;} 02252 02255 inline const Expr& getRhs2() const {return _rhs2;} 02256 02257 private: 02260 virtual void visit(Visitor& visitor) const; 02261 02262 private: 02264 const Expr& _lhs; 02265 02267 const z::string _op1; 02268 02270 const Expr& _rhs1; 02271 02273 const z::string _op2; 02274 02276 const Expr& _rhs2; 02277 }; 02278 02281 class BinaryExpr : public Expr { 02282 public: 02289 inline BinaryExpr(const QualifiedType& type, const Expr& lhs, const z::string& op, const Expr& rhs) : Expr(type), _lhs(lhs), _op(op), _rhs(rhs) {} 02290 02291 public: 02294 inline const Expr& getLhs() const {return _lhs;} 02295 02298 inline const z::string& getOp() const {return _op;} 02299 02302 inline const Expr& getRhs() const {return _rhs;} 02303 02304 private: 02306 const Expr& _lhs; 02307 02309 const z::string _op; 02310 02312 const Expr& _rhs; 02313 }; 02314 02317 class BinaryOpExpr : public BinaryExpr { 02318 public: 02325 inline BinaryOpExpr(const QualifiedType& type, const Expr& lhs, const z::string& op, const Expr& rhs) : BinaryExpr(type, lhs, op, rhs) {} 02326 private: 02329 virtual void visit(Visitor& visitor) const; 02330 02331 }; 02332 02335 class UnaryOpExpr : public Expr { 02336 protected: 02342 inline UnaryOpExpr(const QualifiedType& type, const z::string& op, const Expr& expr) : Expr(type), _op(op), _expr(expr) {} 02343 02344 public: 02347 inline const z::string& getOp() const {return _op;} 02348 02351 inline const Expr& getExpr() const {return _expr;} 02352 02353 private: 02355 const z::string _op; 02356 02358 const Expr& _expr; 02359 }; 02360 02362 02369 class PrefixOpExpr : public UnaryOpExpr { 02370 public: 02376 inline PrefixOpExpr(const QualifiedType& type, const z::string& op, const Expr& rhs) : UnaryOpExpr(type, op, rhs) {} 02377 02378 private: 02381 virtual void visit(Visitor& visitor) const; 02382 }; 02383 02385 02392 class PostfixOpExpr : public UnaryOpExpr { 02393 public: 02399 inline PostfixOpExpr(const QualifiedType& type, const Expr& lhs, const z::string& op) : UnaryOpExpr(type, op, lhs) {} 02400 02401 private: 02404 virtual void visit(Visitor& visitor) const; 02405 }; 02406 02408 02415 class OrderedExpr : public Expr { 02416 public: 02421 inline OrderedExpr(const QualifiedType& type, const Expr& expr) : Expr(type), _expr(expr) {} 02422 02423 public: 02426 inline const Expr& getExpr() const {return _expr;} 02427 02428 private: 02431 virtual void visit(Visitor& visitor) const; 02432 02433 private: 02435 const Expr& _expr; 02436 }; 02437 02439 02446 class IndexExpr : public Expr { 02447 public: 02453 inline IndexExpr(const QualifiedType& type, const Expr& expr, const Expr& idx) : Expr(type), _expr(expr), _idx(idx) {} 02454 02455 public: 02458 inline const Expr& getExpr() const {return _expr;} 02459 02462 inline const Expr& getIndex() const {return _idx;} 02463 02464 private: 02467 virtual void visit(Visitor& visitor) const; 02468 02469 private: 02471 const Expr& _expr; 02472 02474 const Expr& _idx; 02475 }; 02476 02478 02487 class Splice : public Node { 02488 public: 02494 inline Splice(const Expr& start, const Expr& stop, const Expr& step) : _start(start), _stop(stop), _step(step) {} 02495 02496 public: 02499 inline const Expr& getStart() const {return _start;} 02500 02503 inline const Expr& getStop() const {return _stop;} 02504 02507 inline const Expr& getStep() const {return _step;} 02508 02509 private: 02511 const Expr& _start; 02512 02514 const Expr& _stop; 02515 02517 const Expr& _step; 02518 }; 02519 02521 02526 class SpliceExpr : public Expr { 02527 public: 02533 inline SpliceExpr(const QualifiedType& type, const Expr& lhs, const Splice& splice) : Expr(type), _lhs(lhs), _splice(splice) {} 02534 02535 public: 02538 inline const Expr& getLhs() const {return _lhs;} 02539 02542 inline const Splice& getSplice() const {return _splice;} 02543 02544 private: 02547 virtual void visit(Visitor& visitor) const; 02548 02549 private: 02551 const Expr& _lhs; 02552 02554 const Splice& _splice; 02555 }; 02556 02558 02567 class StringFormatExpr : public Expr { 02568 public: 02574 inline StringFormatExpr(const QualifiedType& type, const Expr& format, const Ast::DictList& list) : Expr(type), _format(format), _list(list) {} 02575 02576 public: 02579 inline const Expr& getFormat() const {return _format;} 02580 02583 inline const Ast::DictList& getList() const {return _list;} 02584 02585 private: 02588 virtual void visit(Expr::Visitor& visitor) const; 02589 02590 private: 02592 const Expr& _format; 02593 02595 const Ast::DictList& _list; 02596 }; 02597 02599 02610 class InstanceExpr : public Expr { 02611 public: 02616 inline InstanceExpr(const QualifiedType& type, const Ast::ExprList& list) : Expr(type), _list(list) {} 02617 02618 public: 02621 inline const Ast::ExprList& getList() const {return _list;} 02622 02623 private: 02625 const Ast::ExprList& _list; 02626 }; 02627 02629 02640 class TypeDefExpr : public InstanceExpr { 02641 public: 02646 inline TypeDefExpr(const QualifiedType& type, const Ast::ExprList& list) : InstanceExpr(type, list) {} 02647 02648 private: 02651 virtual void visit(Expr::Visitor& visitor) const; 02652 }; 02653 02655 02666 class StructExpr : public InstanceExpr { 02667 public: 02672 inline StructExpr(const QualifiedType& type, const Ast::ExprList& list) : InstanceExpr(type, list) {} 02673 02674 private: 02677 virtual void visit(Expr::Visitor& visitor) const; 02678 }; 02679 02681 02692 class FunctionExpr : public InstanceExpr { 02693 public: 02699 inline FunctionExpr(const QualifiedType& type, const FunctionDef& function, const ExprList& list) : InstanceExpr(type, list), _function(function) {} 02700 02701 public: 02704 inline const FunctionDef& getFunction() const {return _function;} 02705 02706 private: 02709 virtual void visit(Expr::Visitor& visitor) const; 02710 02711 private: 02713 const FunctionDef& _function; 02714 }; 02715 02717 02731 class ListTemplateExpr : public InstanceExpr { 02732 public: 02737 inline ListTemplateExpr(const QualifiedType& type, const ExprList& list) : InstanceExpr(type, list) {} 02738 02739 private: 02742 virtual void visit(Expr::Visitor& visitor) const; 02743 }; 02744 02746 02760 class DictTemplateExpr : public InstanceExpr { 02761 public: 02766 inline DictTemplateExpr(const QualifiedType& type, const ExprList& list) : InstanceExpr(type, list) {} 02767 02768 private: 02771 virtual void visit(Expr::Visitor& visitor) const; 02772 }; 02773 02775 02789 class StructInitExpr : public Expr { 02790 public: 02795 inline StructInitExpr(const QualifiedType& type, const Ast::StructInitList& list) : Expr(type), _list(list) {} 02796 02797 public: 02800 inline const Ast::StructInitList& getStructInitList() const {return _list;} 02801 02802 private: 02805 virtual void visit(Expr::Visitor& visitor) const; 02806 02807 private: 02809 const Ast::StructInitList& _list; 02810 }; 02811 02813 02821 class ListExpr : public Expr { 02822 public: 02827 inline ListExpr(const QualifiedType& type, const ListList& list) : Expr(type), _list(list) {} 02828 02829 public: 02832 inline const ListList& getList() const {return _list;} 02833 02834 private: 02837 virtual void visit(Expr::Visitor& visitor) const; 02838 02839 private: 02841 const ListList& _list; 02842 }; 02843 02846 class DictExprBase : public Expr { 02847 protected: 02852 inline DictExprBase(const QualifiedType& type, const DictList& list) : Expr(type), _list(list) {} 02853 02854 public: 02857 inline const DictList& getList() const {return _list;} 02858 02859 private: 02861 const DictList& _list; 02862 }; 02863 02865 02873 class DictExpr : public DictExprBase { 02874 public: 02879 inline DictExpr(const QualifiedType& type, const DictList& list) : DictExprBase(type, list) {} 02880 02881 private: 02884 virtual void visit(Expr::Visitor& visitor) const; 02885 }; 02886 02888 02898 class TreeExpr : public DictExprBase { 02899 public: 02904 inline TreeExpr(const QualifiedType& type, const DictList& list) : DictExprBase(type, list) {} 02905 02906 private: 02909 virtual void visit(Expr::Visitor& visitor) const; 02910 }; 02911 02913 02922 class QueryExpr : public Expr { 02923 public: 02928 inline QueryExpr(const QualifiedType& type, const Expr& expr) : Expr(type), _expr(expr) {} 02929 02930 public: 02933 inline const Expr& getExpr() const {return _expr;} 02934 02935 private: 02938 virtual void visit(Expr::Visitor& visitor) const; 02939 02940 private: 02942 const Expr& _expr; 02943 }; 02944 02946 02955 class QueryPartExpr : public Expr { 02956 public: 02962 inline QueryPartExpr(const QualifiedType& type, const Expr& keyExpr, const Expr& valExpr) : Expr(type), _keyExpr(keyExpr), _valExpr(valExpr) {} 02963 02964 public: 02967 inline const Expr& getKeyExpr() const {return _keyExpr;} 02968 02971 inline const Expr& getValExpr() const {return _valExpr;} 02972 02973 private: 02976 virtual void visit(Expr::Visitor& visitor) const; 02977 private: 02979 const Expr& _keyExpr; 02980 02982 const Expr& _valExpr; 02983 }; 02984 02986 02994 class QueryBinaryExpr : public BinaryExpr { 02995 public: 03002 inline QueryBinaryExpr(const QualifiedType& type, const Expr& lhs, const z::string& op, const Expr& rhs) : BinaryExpr(type, lhs, op, rhs) {} 03003 03004 private: 03007 virtual void visit(Expr::Visitor& visitor) const; 03008 }; 03009 03011 03019 class QueryValExpr : public Expr { 03020 public: 03024 inline QueryValExpr(const QualifiedType& type) : Expr(type) {} 03025 03026 private: 03029 virtual void visit(Expr::Visitor& visitor) const; 03030 }; 03031 03033 03041 class QueryConstantExpr : public Expr { 03042 public: 03047 inline QueryConstantExpr(const QualifiedType& type, const Expr& expr) : Expr(type), _expr(expr) {} 03048 03049 public: 03052 inline const Expr& getExpr() const {return _expr;} 03053 03054 private: 03057 virtual void visit(Expr::Visitor& visitor) const; 03058 03059 private: 03061 const Expr& _expr; 03062 }; 03063 03066 03074 class VariableRefExpr : public Expr { 03075 public: 03080 inline VariableRefExpr(const QualifiedType& type, const VariableRef& vref) : Expr(type), _vref(vref) {} 03081 03082 public: 03085 inline const VariableRef& getRef() const {return _vref;} 03086 03087 private: 03090 virtual void visit(Expr::Visitor& visitor) const; 03091 03092 private: 03094 const VariableRef& _vref; 03095 }; 03096 03098 03107 class EnumRefExpr : public Expr { 03108 public: 03114 inline EnumRefExpr(const QualifiedType& type, const Ast::EnumDef& enumDef, const z::string& id) : Expr(type), _enumDef(enumDef), _id(id) {} 03115 03116 public: 03119 inline const EnumDef& getEnumDef() const {return _enumDef;} 03120 03123 inline const z::string& getId() const {return _id;} 03124 03125 private: 03128 virtual void visit(Expr::Visitor& visitor) const; 03129 03130 private: 03132 const EnumDef& _enumDef; 03133 03135 const z::string _id; 03136 }; 03137 03139 03148 class InternalCallExpr : public Expr { 03149 public: 03155 inline InternalCallExpr(const QualifiedType& type, const z::string& name, const ExprList& list) : Expr(type), _name(name), _list(list) {} 03156 03157 public: 03160 inline const z::string& getName() const {return _name;} 03161 03164 inline const ExprList& getList() const {return _list;} 03165 03166 private: 03169 virtual void visit(Expr::Visitor& visitor) const; 03170 03171 private: 03173 const z::string _name; 03174 03176 const ExprList& _list; 03177 }; 03178 03180 03188 class InvokerCallExpr : public Expr { 03189 public: 03194 inline InvokerCallExpr(const QualifiedType& type, const Invoker& invoker) : Expr(type), _invoker(invoker) {} 03195 03196 public: 03199 inline const Invoker& getInvoker() const {return _invoker;} 03200 03201 private: 03204 virtual void visit(Expr::Visitor& visitor) const; 03205 03206 private: 03208 const Invoker& _invoker; 03209 }; 03210 03213 class ContinuationImplItem; 03214 03216 03225 class FunctionCallExpr : public Expr { 03226 public: 03231 inline FunctionCallExpr(const QualifiedType& type, const Ast::ContinuationImplItem& continuation) : Expr(type), _continuation(continuation) {} 03232 03233 public: 03236 inline const Ast::ContinuationImplItem& getContinuation() const {return _continuation;} 03237 03238 private: 03241 virtual void visit(Expr::Visitor& visitor) const; 03242 03243 private: 03245 const Ast::ContinuationImplItem& _continuation; 03246 }; 03247 03249 03258 class FunctionImplExpr : public Expr { 03259 public: 03264 inline FunctionImplExpr(const QualifiedType& type, const Ast::FunctionImplItem& item) : Expr(type), _item(item) {} 03265 03266 public: 03269 inline const Ast::FunctionImplItem& getItem() const {return _item;} 03270 03271 private: 03274 virtual void visit(Expr::Visitor& visitor) const; 03275 03276 private: 03278 const Ast::FunctionImplItem& _item; 03279 }; 03280 03282 03290 class FunctionDefImplExpr : public Expr { 03291 public: 03296 inline FunctionDefImplExpr(const QualifiedType& type, const Ast::ImplItem& item) : Expr(type), _item(item) {} 03297 03298 public: 03301 inline const Ast::ImplItem& getItem() const {return _item;} 03302 03303 private: 03306 virtual void visit(Expr::Visitor& visitor) const; 03307 03308 private: 03310 const Ast::ImplItem& _item; 03311 }; 03312 03314 03322 class AnyExpr : public Expr { 03323 public: 03328 inline AnyExpr(const QualifiedType& type, const Expr& expr) : Expr(type), _expr(expr) {} 03329 03330 public: 03333 inline const Expr& getExpr() const {return _expr;} 03334 03335 private: 03338 virtual void visit(Expr::Visitor& visitor) const; 03339 03340 private: 03342 const Expr& _expr; 03343 }; 03344 03346 03350 class CastExpr : public Expr { 03351 public: 03356 inline CastExpr(const QualifiedType& type, const Expr& expr) : Expr(type), _expr(expr) {} 03357 03358 public: 03361 inline const Expr& getExpr() const {return _expr;} 03362 03363 private: 03366 virtual void visit(Expr::Visitor& visitor) const; 03367 03368 private: 03370 const Expr& _expr; 03371 }; 03372 03375 class ConstantExpr: public Expr { 03376 public: 03381 inline ConstantExpr(const QualifiedType& type, const z::string& value) : Expr(type), _value(value) {} 03382 03383 public: 03386 inline const z::string& getValue() const {return _value;} 03387 03388 private: 03390 const z::string _value; 03391 }; 03392 03394 03402 class NumericConstantExpr : public ConstantExpr { 03403 public: 03408 inline NumericConstantExpr(const QualifiedType& type, const z::string& value) : ConstantExpr(type, value) {} 03409 03410 private: 03413 virtual void visit(Expr::Visitor& visitor) const; 03414 }; 03415 03417 03425 class BooleanConstantExpr : public ConstantExpr { 03426 public: 03431 inline BooleanConstantExpr(const QualifiedType& type, const z::string& value) : ConstantExpr(type, value) {} 03432 03433 private: 03436 virtual void visit(Expr::Visitor& visitor) const; 03437 }; 03438 03440 03448 class CharConstantExpr : public ConstantExpr { 03449 public: 03454 inline CharConstantExpr(const QualifiedType& type, const z::string& value) : ConstantExpr(type, value) {} 03455 private: 03458 virtual void visit(Expr::Visitor& visitor) const; 03459 }; 03460 03462 03470 class StringConstantExpr : public ConstantExpr { 03471 public: 03476 inline StringConstantExpr(const QualifiedType& type, const z::string& value) : ConstantExpr(type, value) {} 03477 private: 03480 virtual void visit(Expr::Visitor& visitor) const; 03481 }; 03482 03484 // Closures 03487 class Closure : public Node { 03488 public: 03490 typedef z::list<const Closure*> List; 03491 public: 03493 enum Type { 03494 None, 03495 Link, 03496 Join, 03497 }; 03498 03499 protected: 03503 inline Closure(const VariableRefList& xRefList) : _type(None), _xRefList(xRefList) {} 03504 public: 03507 inline void setType(const Type& type) {_type = type;} 03508 03511 inline bool isJoin() const {return (Join == _type);} 03512 03515 inline const VariableRefList& getXRefList() const {return _xRefList;} 03516 03517 public: 03519 class Visitor; 03520 03523 virtual void visit(Visitor& visitor) const = 0; 03524 private: 03526 Type _type; 03527 03529 const VariableRefList _xRefList; 03530 }; 03531 03533 03537 class FunctionCallClosure : public Closure { 03538 public: 03544 inline FunctionCallClosure(const VariableRefList& xRefList, const Ast::VariableDef& vdef, const Ast::Invoker& invoker) 03545 : Closure(xRefList), _vdef(vdef), _invoker(invoker) {} 03546 03547 public: 03550 inline const VariableDef& getDef() const {return _vdef;} 03551 03554 inline const Invoker& getInvoker() const {return _invoker;} 03555 03556 private: 03559 virtual void visit(Visitor& visitor) const; 03560 03561 private: 03563 const Ast::VariableDef& _vdef; 03564 03566 const Ast::Invoker& _invoker; 03567 }; 03568 03570 03572 class InitClosure : public Closure { 03573 protected: 03577 inline InitClosure(const VariableRefList& xRefList) : Closure(xRefList) {} 03578 03579 public: 03582 virtual const Ast::QualifiedType& getOutType() const = 0; 03583 }; 03584 03586 03588 class RunClosure : public InitClosure { 03589 public: 03594 inline RunClosure(const VariableRefList& xRefList, const Ast::QualifiedType& qtype) : InitClosure(xRefList), _qtype(qtype) {} 03595 03596 private: 03599 virtual void visit(Visitor& visitor) const; 03600 03601 private: 03604 virtual const Ast::QualifiedType& getOutType() const {return _qtype;} 03605 03606 private: 03608 const Ast::QualifiedType& _qtype; 03609 }; 03610 03612 03614 class ExitClosure : public InitClosure { 03615 public: 03620 inline ExitClosure(const VariableRefList& xRefList, const Ast::QualifiedType& qtype) : InitClosure(xRefList), _qtype(qtype) {} 03621 private: 03624 virtual void visit(Visitor& visitor) const; 03625 03626 private: 03629 virtual const Ast::QualifiedType& getOutType() const {return _qtype;} 03630 03631 private: 03633 const Ast::QualifiedType& _qtype; 03634 }; 03635 03637 03642 class CallClosure : public InitClosure { 03643 public: 03649 inline CallClosure(const VariableRefList& xRefList, const Ast::VariableDef& vdef, const Ast::Invoker& invoker) 03650 : InitClosure(xRefList), _vdef(vdef), _invoker(invoker) {} 03651 03652 public: 03655 inline const VariableDef& getDef() const {return _vdef;} 03656 03659 inline const Invoker& getInvoker() const {return _invoker;} 03660 03661 private: 03664 virtual void visit(Visitor& visitor) const; 03665 03666 private: 03669 virtual const Ast::QualifiedType& getOutType() const {return _invoker.getInvokerType().getFunctionDef().getOutType();} 03670 03671 private: 03673 const Ast::VariableDef& _vdef; 03674 03676 const Ast::Invoker& _invoker; 03677 }; 03678 03680 03684 class LoopClosure : public Closure { 03685 public: 03690 inline LoopClosure(const VariableRefList& xRefList, const Ast::Expr& expr) : Closure(xRefList), _expr(expr) {} 03691 03692 public: 03695 inline const Ast::Expr& getExpr() const {return _expr;} 03696 03697 private: 03700 virtual void visit(Visitor& visitor) const; 03701 03702 private: 03704 const Ast::Expr& _expr; 03705 }; 03706 03708 03710 class SharedClosure : public Closure { 03711 public: 03717 inline SharedClosure(const VariableRefList& xRefList, const Ast::VariableDef& vdef, const Ast::SharedDef& sharedList) 03718 : Closure(xRefList), _vdef(vdef), _sharedList(sharedList) {} 03719 03720 public: 03723 inline const VariableDef& getDef() const {return _vdef;} 03724 03727 inline const Ast::SharedDef& getSharedList() const {return _sharedList;} 03728 03729 private: 03732 virtual void visit(Visitor& visitor) const; 03733 03734 private: 03736 const Ast::VariableDef& _vdef; 03737 03739 const Ast::SharedDef& _sharedList; 03740 }; 03741 03743 03745 class ReturnClosure : public Closure { 03746 public: 03751 inline ReturnClosure(const VariableRefList& xRefList, const Ast::ExprList& list) : Closure(xRefList), _list(list) {} 03752 03753 public: 03756 inline const ExprList& getList() const {return _list;} 03757 03758 private: 03761 virtual void visit(Visitor& visitor) const; 03762 03763 private: 03765 const Ast::ExprList& _list; 03766 }; 03767 03769 03771 class ClosureList : public Node { 03772 public: 03775 inline const Closure::List& getClosureList() const {return _list;} 03776 03779 inline void addClosure(const Closure& closure) { _list.append(ptr(closure));} 03780 03781 public: 03784 void visitClosureList(Closure::Visitor& visitor) const; 03785 03786 private: 03788 Closure::List _list; 03789 }; 03790 03792 // Statements 03794 03796 class Statement : public Node { 03797 protected: 03800 inline Statement(){} 03801 03802 public: 03804 class Visitor; 03805 03808 virtual void visit(Visitor& visitor) const = 0; 03809 }; 03810 03812 03822 class StatementList : public Node { 03823 public: 03825 typedef z::list<Statement*> List; 03826 03827 public: 03830 explicit inline StatementList() {} 03831 03832 public: 03835 inline void addStatement(Statement& statement) {_list.append(ptr(statement));} 03836 03839 inline const List& getList() const {return _list;} 03840 03841 private: 03843 List _list; 03844 }; 03845 03847 03858 class StatementBlock : public Statement { 03859 public: 03863 explicit inline StatementBlock(const StatementList& list) : Statement(), _list(list) {} 03864 03865 public: 03868 inline const StatementList& getList() const {return _list;} 03869 03870 private: 03873 virtual void visit(Statement::Visitor& visitor) const; 03874 03875 private: 03877 const StatementList& _list; 03878 }; 03879 03881 03889 class ExprStatement : public Statement { 03890 public: 03894 inline ExprStatement(const Ast::Expr& expr) : _expr(expr) {} 03895 03896 public: 03899 inline const Expr& getExpr() const {return _expr;} 03900 03901 private: 03904 virtual void visit(Statement::Visitor& visitor) const; 03905 03906 private: 03908 const Ast::Expr& _expr; 03909 }; 03910 03912 03920 class DefineVarStatement : public Statement { 03921 public: 03925 inline DefineVarStatement(const InitVariableDef& vdef) : _vdef(vdef) {} 03926 03927 public: 03930 inline const InitVariableDef& getDef() const {return _vdef;} 03931 03932 private: 03935 virtual void visit(Statement::Visitor& visitor) const; 03936 03937 private: 03939 const InitVariableDef& _vdef; 03940 }; 03941 03943 03951 class LogStatement : public Statement { 03952 public: 03957 inline LogStatement(const z::string& name, const Ast::ExprList& list) : _name(name), _list(list) {} 03958 03959 public: 03962 inline const z::string& getName() const {return _name;} 03963 03966 inline const ExprList& getList() const {return _list;} 03967 03968 private: 03971 virtual void visit(Statement::Visitor& visitor) const; 03972 03973 private: 03975 const z::string _name; 03976 03978 const Ast::ExprList& _list; 03979 }; 03980 03982 03984 class IfStatement : public Statement { 03985 protected: 03990 inline IfStatement(const Ast::Expr& cond, const Ast::StatementList& tlist) : _cond(cond), _tlist(tlist) {} 03991 03992 public: 03995 inline const Ast::Expr& getCond() const {return _cond;} 03996 03999 inline const Ast::StatementList& getTList() const {return _tlist;} 04000 04001 private: 04003 const Ast::Expr& _cond; 04004 04006 const Ast::StatementList& _tlist; 04007 }; 04008 04010 04012 class IfThenStatement : public IfStatement { 04013 public: 04018 inline IfThenStatement(const Ast::Expr& cond, const Ast::StatementList& tlist) : IfStatement(cond, tlist) {} 04019 private: 04022 virtual void visit(Statement::Visitor& visitor) const; 04023 }; 04024 04026 04028 class IfElseStatement : public IfStatement { 04029 public: 04035 inline IfElseStatement(const Ast::Expr& cond, const Ast::StatementList& tlist, const Ast::StatementList& flist) : IfStatement(cond, tlist), _flist(flist) {} 04036 04037 public: 04040 inline const Ast::StatementList& getFList() const {return _flist;} 04041 04042 private: 04045 virtual void visit(Statement::Visitor& visitor) const; 04046 04047 private: 04049 const Ast::StatementList& _flist; 04050 }; 04051 04053 04055 class SwitchLabel : public Node { 04056 protected: 04060 inline SwitchLabel(const Ast::StatementList& list) : _list(list) {} 04061 04062 public: 04065 inline const Ast::StatementList& getList() const {return _list;} 04066 04067 private: 04069 const Ast::StatementList& _list; 04070 }; 04071 04073 04075 class CaseLabel : public SwitchLabel { 04076 public: 04081 inline CaseLabel(const Ast::Expr& expr, const Ast::StatementList& list) : SwitchLabel(list), _expr(expr) {} 04082 04083 public: 04086 inline const Ast::Expr& getExpr() const {return _expr;} 04087 04088 private: 04090 const Ast::Expr& _expr; 04091 }; 04092 04094 04096 class DefaultLabel : public SwitchLabel { 04097 public: 04101 inline DefaultLabel(const Ast::StatementList& list) : SwitchLabel(list) {} 04102 }; 04103 04105 04107 class SwitchLabelList : public Node { 04108 public: 04110 typedef z::list<CaseLabel*> List; 04111 public: 04114 inline SwitchLabelList() : _defaultLabel(0) {} 04115 04116 public: 04119 inline void addCase(CaseLabel& label) {_list.append(ptr(label));} 04120 04123 inline void addDefault(DefaultLabel& label) {assert(_defaultLabel == 0); _defaultLabel = ptr(label);} 04124 04127 inline const List& getList() const {return _list;} 04128 04131 inline bool hasDefault() const {return (_defaultLabel != 0);} 04132 04135 inline const DefaultLabel& getDefault() const {return ref(_defaultLabel);} 04136 04137 private: 04139 List _list; 04140 04142 DefaultLabel* _defaultLabel; 04143 }; 04144 04146 04161 class SelectStatement : public Statement { 04162 public: 04166 inline SelectStatement(const Ast::SwitchLabelList& list) : _list(list) {} 04167 04168 public: 04171 inline const Ast::SwitchLabelList& getList() const {return _list;} 04172 04173 private: 04176 virtual void visit(Statement::Visitor& visitor) const; 04177 04178 private: 04180 const Ast::SwitchLabelList& _list; 04181 }; 04182 04184 04198 class SwitchStatement : public Statement { 04199 public: 04204 inline SwitchStatement(const Ast::Expr& expr, const Ast::SwitchLabelList& list) : _expr(expr), _list(list) {} 04205 04206 public: 04209 inline const Ast::Expr& getExpr() const {return _expr;} 04210 04213 inline const Ast::SwitchLabelList& getList() const {return _list;} 04214 04215 private: 04218 virtual void visit(Statement::Visitor& visitor) const; 04219 04220 private: 04222 const Ast::Expr& _expr; 04223 04225 const Ast::SwitchLabelList& _list; 04226 }; 04227 04229 04233 class TypeSpecStatement : public Statement { 04234 public: 04238 inline TypeSpecStatement(const Ast::TypeSpec& typeSpec) : _typeSpec(typeSpec) {} 04239 04240 public: 04243 inline const Ast::TypeSpec& getTypeSpec() const {return _typeSpec;} 04244 04245 private: 04248 virtual void visit(Statement::Visitor& visitor) const; 04249 04250 private: 04252 const Ast::TypeSpec& _typeSpec; 04253 }; 04254 04256 04258 class BreakStatement : public Statement { 04259 public: 04262 inline BreakStatement() {} 04263 04264 private: 04267 virtual void visit(Statement::Visitor& visitor) const; 04268 }; 04269 04271 04273 class ContinueStatement : public Statement { 04274 public: 04277 inline ContinueStatement() {} 04278 04279 private: 04282 virtual void visit(Statement::Visitor& visitor) const; 04283 }; 04284 04286 04290 class EmptyStatement : public Statement { 04291 public: 04294 inline EmptyStatement() {} 04295 04296 private: 04299 virtual void visit(Statement::Visitor& visitor) const; 04300 }; 04301 04303 04305 class ForStatement : public Statement { 04306 public: 04313 inline ForStatement(const Ast::InitVariableDef& init, const Ast::Expr& cond, const Ast::Expr& incx, const Ast::StatementList& list) 04314 : _init(init), _cond(cond), _incx(incx), _list(list) {} 04315 04316 public: 04319 inline const Ast::InitVariableDef& getInit() const {return _init;} 04320 04323 inline const Ast::Expr& getCond() const {return _cond;} 04324 04327 inline const Ast::Expr& getIncx() const {return _incx;} 04328 04331 inline const Ast::StatementList& getList() const {return _list;} 04332 04333 private: 04336 virtual void visit(Statement::Visitor& visitor) const; 04337 04338 private: 04340 const Ast::InitVariableDef& _init; 04341 04343 const Ast::Expr& _cond; 04344 04346 const Ast::Expr& _incx; 04347 04349 const Ast::StatementList& _list; 04350 }; 04351 04353 04357 class ForeachStatement : public Statement { 04358 public: 04363 inline ForeachStatement(const Ast::InitVariableDef& init, const Ast::StatementList& list) : _init(init), _list(list) {} 04364 04365 public: 04368 inline const Ast::InitVariableDef& getInit() const {return _init;} 04369 04372 inline const Ast::StatementList& getList() const {return _list;} 04373 04374 private: 04377 virtual void visit(Statement::Visitor& visitor) const; 04378 04379 private: 04381 const Ast::InitVariableDef& _init; 04382 04384 const Ast::StatementList& _list; 04385 }; 04386 04388 04390 class WhileStatement : public Statement { 04391 public: 04396 inline WhileStatement(const Ast::Expr& cond, const Ast::StatementList& list) : _cond(cond), _list(list) {} 04397 04398 public: 04401 inline const Ast::Expr& getCond() const {return _cond;} 04402 04405 inline const Ast::StatementList& getList() const {return _list;} 04406 04407 private: 04410 virtual void visit(Statement::Visitor& visitor) const; 04411 04412 private: 04414 const Ast::Expr& _cond; 04415 04417 const Ast::StatementList& _list; 04418 }; 04419 04421 04425 class DoWhileStatement : public Statement { 04426 public: 04431 inline DoWhileStatement(const Ast::Expr& cond, const Ast::StatementList& list) : _cond(cond), _list(list) {} 04432 04433 public: 04436 inline const Ast::Expr& getCond() const {return _cond;} 04437 04440 inline const Ast::StatementList& getList() const {return _list;} 04441 04442 private: 04445 virtual void visit(Statement::Visitor& visitor) const; 04446 04447 private: 04449 const Ast::Expr& _cond; 04450 04452 const Ast::StatementList& _list; 04453 }; 04454 04456 04458 class RoutineReturnStatement : public Statement { 04459 public: 04463 inline RoutineReturnStatement(const Expr& expr) : _expr(expr) {} 04464 04465 public: 04468 inline const Expr& getExpr() const {return _expr;} 04469 04470 private: 04473 virtual void visit(Statement::Visitor& visitor) const; 04474 04475 private: 04477 const Expr& _expr; 04478 }; 04479 04481 04483 class FunctionReturnStatement : public Statement { 04484 public: 04489 inline FunctionReturnStatement(Ast::FunctionDef& fdef, const ExprList& list) : _fdef(fdef), _list(list) {} 04490 04491 public: 04494 inline const Ast::FunctionDef& getFunctionDef() const {return _fdef;} 04495 04498 inline const ExprList& getList() const {return _list;} 04499 04500 private: 04503 virtual void visit(Statement::Visitor& visitor) const; 04504 04505 private: 04507 const Ast::FunctionDef& _fdef; 04508 04510 const ExprList& _list; 04511 }; 04512 04514 // Blocks 04516 04518 class BlockBase : public Node { 04519 public: 04523 explicit inline BlockBase(const VariableRefList& refList) : _xRefList(refList) {} 04524 04525 public: 04528 inline const VariableRefList& getXRefList() const {return _xRefList;} 04529 04530 private: 04532 const VariableRefList _xRefList; 04533 }; 04534 04536 04538 class RoutineBlock : public BlockBase { 04539 public: 04544 explicit inline RoutineBlock(const VariableRefList& refList, const StatementBlock& block) : BlockBase(refList), _block(block) {} 04545 04546 public: 04549 inline const StatementBlock& getStatementBlock() const {return _block;} 04550 04551 private: 04553 const StatementBlock& _block; 04554 }; 04555 04557 04561 class FunctionBlock : public BlockBase { 04562 public: 04567 explicit inline FunctionBlock(const VariableRefList& refList, const StatementBlock& block) : BlockBase(refList), _block(block) {} 04568 04569 public: 04572 inline const StatementBlock& getStatementBlock() const {return _block;} 04573 04574 private: 04576 const StatementBlock& _block; 04577 }; 04578 04580 04582 class GrammarBlock : public BlockBase { 04583 public: 04590 inline GrammarBlock(const VariableRefList& refList, const GrammarOptionList& optList, const GrammarStatementList& list, const GrammarLexerList& lexList) 04591 : BlockBase(refList), _optList(optList), _list(list), _lexList(lexList) {} 04592 04593 public: 04596 inline const GrammarOptionList& getOptList() const {return _optList;} 04597 04600 inline const GrammarStatementList& getList() const {return _list;} 04601 04604 inline const GrammarLexerList& getLexList() const {return _lexList;} 04605 04606 private: 04608 const Ast::GrammarOptionList& _optList; 04609 04611 const Ast::GrammarStatementList& _list; 04612 04614 const Ast::GrammarLexerList& _lexList; 04615 }; 04616 04618 04620 class WindowBlock : public BlockBase { 04621 public: 04626 inline WindowBlock(const VariableRefList& refList, const Ast::FunctionBlock& functionBlock) : BlockBase(refList), _functionBlock(functionBlock) {} 04627 04628 public: 04631 inline const FunctionBlock& getFunctionBlock() const {return _functionBlock;} 04632 04633 private: 04635 const Ast::FunctionBlock& _functionBlock; 04636 }; 04637 04639 // Implementation Items 04641 04646 class ContinuationImplItem : public ImplItem { 04647 public: 04654 inline ContinuationImplItem(const int& idx, const FunctionDef& fdef, const Ast::ClosureList& closureList, const ReturnClosure& retnClosure) 04655 : ImplItem(idx, fdef), _closureList(closureList), _retnClosure(retnClosure) {} 04656 04657 public: 04662 inline z::string getUniqueName(const z::string& sep) const { 04663 return z::string::creator("_cont_%{n}%{s}%{i}") 04664 .arg(z::any("n"), z::any(getFunctionDef().getName())) 04665 .arg(z::any("s"), z::any(sep)) 04666 .arg(z::any("i"), z::any(getIndex())).value(); 04667 } 04668 04669 public: 04672 inline const Ast::ClosureList& getClosureList() const {return _closureList;} 04673 04676 inline const Ast::ReturnClosure& getReturnClosure() const {return _retnClosure;} 04677 04680 inline const VariableRefList& getXRefList() const {return _xRefList;} 04681 04684 inline void setXRefList(const VariableRefList& xRefList) {_xRefList.appendList(xRefList);} 04685 04686 private: 04689 inline const InitClosure* getInitClosureP() const { 04690 assert(_closureList.getClosureList().size() > 0); 04691 const Closure* c = _closureList.getClosureList().at(0); 04692 const InitClosure* rv = dcast<const InitClosure>(c, "Closure is not an InitClosure"); 04693 return rv; 04694 } 04695 04696 public: 04699 inline const InitClosure& getInitClosure() const { 04700 const InitClosure* c = getInitClosureP(); 04701 assert(c); 04702 return ref(c); 04703 } 04704 04705 public: 04708 inline const Invoker* hasRoutineCall() const { 04709 const InitClosure* i = getInitClosureP(); 04710 assert(i); 04711 const CallClosure* c = dynamic_cast<const CallClosure*>(i); // not using dcast because 0 is a valid value 04712 if(!c) 04713 return 0; 04714 04715 const Invoker& invoker = ref(c).getInvoker(); 04716 if(invoker.getInvokerType().getFunctionDef().getModifier() != Ast::FunctionDef::Modifier::Routine) 04717 return 0; 04718 04719 return ptr(invoker); 04720 } 04721 04722 public: 04725 void visitClosureList(Closure::Visitor& visitor) const; 04726 04727 public: 04730 virtual const Ast::FunctionImplItem& getFunctionImplItem() const {throw z::exception(z::string::creator("Internal error").value());} 04731 04732 private: 04735 virtual void visit(ImplItem::Visitor& visitor) const; 04736 04737 private: 04739 VariableRefList _xRefList; 04740 04742 const Ast::ClosureList& _closureList; 04743 04745 const ReturnClosure& _retnClosure; 04746 }; 04747 04749 04751 class RoutineImplItem : public ImplItem { 04752 public: 04758 inline RoutineImplItem(const int& idx, const Ast::FunctionDef& fdef, const Ast::RoutineBlock& block) : ImplItem(idx, fdef), _block(block) {} 04759 04760 public: 04765 inline z::string getUniqueName(const z::string& sep) const { 04766 unused(sep); 04767 return z::string::creator("%{n}") 04768 .arg(z::any("n"), z::any(getFunctionDef().getName())) 04769 .value(); 04770 } 04771 04774 inline const Ast::RoutineBlock& getBlock() const {return _block;} 04775 04776 private: 04779 virtual void visit(ImplItem::Visitor& visitor) const; 04780 04783 virtual const Ast::FunctionImplItem& getFunctionImplItem() const {throw z::exception(z::string::creator("Internal error").value());} 04784 04785 private: 04787 const Ast::RoutineBlock& _block; 04788 }; 04789 04791 04793 class FunctionImplItem : public ImplItem { 04794 public: 04800 inline FunctionImplItem(const int& idx, const Ast::FunctionDef& fdef, const Ast::FunctionBlock& block) : ImplItem(idx, fdef), _block(block) {} 04801 04802 public: 04807 inline z::string getUniqueName(const z::string& sep) const { 04808 return z::string::creator("_fun_%{n}%{s}%{i}") 04809 .arg(z::any("n"), z::any(getFunctionDef().getName())) 04810 .arg(z::any("s"), z::any(sep)) 04811 .arg(z::any("i"), z::any(getIndex())).value(); 04812 } 04813 04814 public: 04817 inline const Ast::FunctionBlock& getBlock() const {return _block;} 04818 04819 private: 04822 virtual void visit(ImplItem::Visitor& visitor) const; 04823 04826 virtual const Ast::FunctionImplItem& getFunctionImplItem() const {return ref(this);} 04827 04828 private: 04830 const Ast::FunctionBlock& _block; 04831 }; 04832 04834 04836 class GrammarImplItem : public ImplItem { 04837 public: 04843 inline GrammarImplItem(const int& idx, const Ast::FunctionDef& fdef, const Ast::GrammarBlock& block) : ImplItem(idx, fdef), _block(block) {} 04844 04845 public: 04850 inline z::string getUniqueName(const z::string& sep) const { 04851 return z::string::creator("_gra_%{n}%{s}%{i}") 04852 .arg(z::any("n"), z::any(getFunctionDef().getName())) 04853 .arg(z::any("s"), z::any(sep)) 04854 .arg(z::any("i"), z::any(getIndex())).value(); 04855 } 04856 04859 inline const Ast::GrammarBlock& getBlock() const {return _block;} 04860 04861 private: 04864 virtual void visit(ImplItem::Visitor& visitor) const; 04865 04868 virtual const Ast::FunctionImplItem& getFunctionImplItem() const {throw z::exception(z::string::creator("Internal error").value());} 04869 04870 private: 04872 const Ast::GrammarBlock& _block; 04873 }; 04874 04876 04878 class WindowImplItem : public ImplItem { 04879 public: 04885 inline WindowImplItem(const int& idx, const Ast::FunctionDef& fdef, const Ast::WindowBlock& block) : ImplItem(idx, fdef), _block(block) {} 04886 04887 public: 04892 inline z::string getUniqueName(const z::string& sep) const { 04893 return z::string::creator("_win_%{n}%{s}%{i}") 04894 .arg(z::any("n"), z::any(getFunctionDef().getName())) 04895 .arg(z::any("s"), z::any(sep)) 04896 .arg(z::any("i"), z::any(getIndex())).value(); 04897 } 04898 04901 inline const Ast::WindowBlock& getBlock() const {return _block;} 04902 04903 private: 04906 virtual void visit(ImplItem::Visitor& visitor) const; 04907 04910 virtual const Ast::FunctionImplItem& getFunctionImplItem() const {throw z::exception(z::string::creator("Internal error").value());} 04911 04912 private: 04914 const Ast::WindowBlock& _block; 04915 }; 04916 04919 04921 class ImportStatement : public Node { 04922 public: 04924 enum Type { 04925 itImport, 04926 itInclude, 04927 itNative, 04928 }; 04929 04930 public: 04932 inline ImportStatement() : _type(itInclude) {} 04933 04934 public: 04937 inline void addPart(const z::string& part) {_name.append(part);} 04938 04942 inline const z::stringlist& getName() const {return _name;} 04943 04944 public: 04949 inline ImportStatement& setType(const Type& type) {_type = type; return ref(this);} 04950 04953 inline const Type& getType() const {return _type;} 04954 04955 private: 04957 z::stringlist _name; 04958 04960 Type _type; 04961 }; 04962 04964 // Represents a compilation unit. Owner for all nodes. 04966 04973 class Unit : public RootTypeSpec { 04974 public: 04976 typedef z::list<const Ast::ImportStatement*> ImportList; 04977 04979 typedef z::list<const Ast::ImplItem*> ImplList; 04980 04981 public: 04985 inline Unit(const AccessType::T& accessType) 04986 : RootTypeSpec(accessType, ""), 04987 _importNS(Ast::TypeSpec::AccessType::Public, ref(this), ""), 04988 _rootNS(Ast::TypeSpec::AccessType::Public, ref(this), ""), 04989 _mainContinuation(0), 04990 _projectDef(0) // if unit represents project file 04991 {} 04992 04993 public: 04997 inline void setProjectDef(const Ast::StructInitExpr& expr) {_projectDef = ptr(expr);} 04998 05001 inline const Ast::StructInitExpr& getProjectDef() {return ref(_projectDef);} 05002 05003 public: 05006 inline void setMainContinuation(const Ast::ContinuationImplItem& continuation) {_mainContinuation = ptr(continuation);} 05007 05010 inline bool hasMainContinuation() const {return (_mainContinuation != 0);} 05011 05014 inline const Ast::ContinuationImplItem& getMainContinuation() const {return ref(_mainContinuation);} 05015 05016 public: 05019 inline void setFilename(const z::string& filename) {_filename = filename;} 05020 05023 inline const z::string& getFilename() const {return _filename;} 05024 05028 inline Ast::ImportStatement& addImport(Ast::ImportStatement& stmt) {_importList.append(ptr(stmt)); return stmt;} 05029 05032 inline void addUnitNS(const z::string& name) {_unitNS.append(name);} 05033 05036 inline void addItem(const ImplItem& item) {_implList.append(ptr(item));} 05037 05041 template<typename T> 05042 inline T& addNode(T* node) {_nodeList.append(Ptr(node)); return ref(node);} 05043 05044 public: 05047 inline Namespace& getRootNS() {return _rootNS;} 05048 05051 inline const Namespace& getRootNS() const {return _rootNS;} 05052 05053 public: 05056 inline Namespace& getImportNS() {return _importNS;} 05057 05060 inline const Namespace& getImportNS() const {return _importNS;} 05061 05062 public: 05065 inline const z::stringlist& getUnitNS() const {return _unitNS;} 05066 05069 inline const ImportList& getImportList() const {return _importList;} 05070 05071 public: 05074 inline const ImplList& getImplList() const {return _implList;} 05075 05076 private: 05079 virtual void visit(TypeSpec::Visitor& visitor) const; 05080 05081 private: 05083 z::string _filename; 05084 05086 ImportList _importList; 05087 05088 private: 05090 Ast::Namespace _importNS; 05091 05093 Namespace _rootNS; 05094 05096 z::stringlist _unitNS; 05097 05098 private: 05100 ImplList _implList; 05101 05102 private: 05104 typedef z::sharedptr<Node> Ptr; 05105 05107 z::list<Ptr> _nodeList; 05108 05109 private: 05111 const Ast::ContinuationImplItem* _mainContinuation; 05112 05113 private: 05115 const Ast::StructInitExpr* _projectDef; 05116 }; 05117 05122 class TypeSpec::Visitor { 05123 public: 05125 inline Visitor(){} 05126 05128 virtual ~Visitor(){} 05129 05130 public: 05133 virtual void visit(const Ast::Unit& type) = 0; 05134 05137 virtual void visit(const Ast::Namespace& type) = 0; 05138 05141 virtual void visit(const Ast::StructDef& type) = 0; 05142 05145 virtual void visit(const Ast::EnumDef& type) = 0; 05146 05149 virtual void visit(const Ast::EnumMemberDef& type) = 0; 05150 05153 virtual void visit(const Ast::OutParam& type) = 0; 05154 05157 virtual void visit(const Ast::SharedDef& type) = 0; 05158 05161 virtual void visit(const Ast::TypeDecl& type) = 0; 05162 05165 virtual void visit(const Ast::TypeDef& type) = 0; 05166 05169 virtual void visit(const Ast::OwnerTemplate& type) = 0; 05170 05173 virtual void visit(const Ast::ListTemplate& type) = 0; 05174 05177 virtual void visit(const Ast::DictTemplate& type) = 0; 05178 05181 virtual void visit(const Ast::FunctionDef& type) = 0; 05182 }; 05183 05186 class InvokerType::Visitor { 05187 public: 05189 inline Visitor(){} 05190 05192 virtual ~Visitor(){} 05193 05194 public: 05197 virtual void visit(const Ast::FunctionCall& call) = 0; 05198 05201 virtual void visit(const Ast::FunctorCall& call) = 0; 05202 05205 virtual void visit(const Ast::FunctionDefCall& call) = 0; 05206 05209 virtual void visit(const Ast::FunctionImplCall& call) = 0; 05210 }; 05211 05214 class Expr::Visitor { 05215 public: 05217 inline Visitor(){} 05218 05220 virtual ~Visitor(){} 05221 05222 public: 05225 virtual void visit(const Ast::TernaryOpExpr& expr) = 0; 05226 05229 virtual void visit(const Ast::BinaryOpExpr& expr) = 0; 05230 05233 virtual void visit(const Ast::PrefixOpExpr& expr) = 0; 05234 05237 virtual void visit(const Ast::PostfixOpExpr& expr) = 0; 05238 05241 virtual void visit(const Ast::OrderedExpr& expr) = 0; 05242 05245 virtual void visit(const Ast::IndexExpr& expr) = 0; 05246 05249 virtual void visit(const Ast::ListExpr& expr) = 0; 05250 05253 virtual void visit(const Ast::DictExpr& expr) = 0; 05254 05257 virtual void visit(const Ast::TreeExpr& expr) = 0; 05258 05261 virtual void visit(const Ast::QueryExpr& expr) = 0; 05262 05265 virtual void visit(const Ast::QueryPartExpr& expr) = 0; 05266 05269 virtual void visit(const Ast::QueryBinaryExpr& expr) = 0; 05270 05273 virtual void visit(const Ast::QueryValExpr& expr) = 0; 05274 05277 virtual void visit(const Ast::QueryConstantExpr& expr) = 0; 05278 05281 virtual void visit(const Ast::StringFormatExpr& expr) = 0; 05282 05285 virtual void visit(const Ast::TypeDefExpr& expr) = 0; 05286 05289 virtual void visit(const Ast::StructExpr& expr) = 0; 05290 05293 virtual void visit(const Ast::StructInitExpr& expr) = 0; 05294 05297 virtual void visit(const Ast::FunctionExpr& expr) = 0; 05298 05301 virtual void visit(const Ast::ListTemplateExpr& expr) = 0; 05302 05305 virtual void visit(const Ast::DictTemplateExpr& expr) = 0; 05306 05309 virtual void visit(const Ast::VariableRefExpr& expr) = 0; 05310 05313 virtual void visit(const Ast::EnumRefExpr& expr) = 0; 05314 05317 virtual void visit(const Ast::InternalCallExpr& expr) = 0; 05318 05321 virtual void visit(const Ast::InvokerCallExpr& expr) = 0; 05322 05325 virtual void visit(const Ast::FunctionCallExpr& expr) = 0; 05326 05329 virtual void visit(const Ast::FunctionImplExpr& expr) = 0; 05330 05333 virtual void visit(const Ast::FunctionDefImplExpr& expr) = 0; 05334 05337 virtual void visit(const Ast::AnyExpr& expr) = 0; 05338 05341 virtual void visit(const Ast::CastExpr& expr) = 0; 05342 05345 virtual void visit(const Ast::NumericConstantExpr& expr) = 0; 05346 05349 virtual void visit(const Ast::BooleanConstantExpr& expr) = 0; 05350 05353 virtual void visit(const Ast::CharConstantExpr& expr) = 0; 05354 05357 virtual void visit(const Ast::StringConstantExpr& expr) = 0; 05358 }; 05359 05362 class Closure::Visitor { 05363 public: 05365 inline Visitor(){} 05366 05368 virtual ~Visitor(){} 05369 05370 public: 05373 virtual void visit(const Ast::RunClosure& closure) = 0; 05374 05377 virtual void visit(const Ast::ExitClosure& closure) = 0; 05378 05381 virtual void visit(const Ast::LoopClosure& closure) = 0; 05382 05385 virtual void visit(const Ast::SharedClosure& closure) = 0; 05386 05389 virtual void visit(const Ast::CallClosure& closure) = 0; 05390 05393 virtual void visit(const Ast::FunctionCallClosure& closure) = 0; 05394 05397 virtual void visit(const Ast::ReturnClosure& closure) = 0; 05398 }; 05399 05402 class ImplItem::Visitor { 05403 public: 05405 inline Visitor(){} 05406 05408 virtual ~Visitor(){} 05409 05410 public: 05413 virtual void visit(const Ast::ContinuationImplItem& item) = 0; 05414 05417 virtual void visit(const Ast::RoutineImplItem& item) = 0; 05418 05421 virtual void visit(const Ast::FunctionImplItem& item) = 0; 05422 05425 virtual void visit(const Ast::GrammarImplItem& item) = 0; 05426 05429 virtual void visit(const Ast::WindowImplItem& item) = 0; 05430 }; 05431 05434 class GrammarMember::Visitor { 05435 public: 05437 inline Visitor(){} 05438 05440 virtual ~Visitor(){} 05441 05442 public: 05445 virtual void visit(const Ast::GrammarMemberId& member) = 0; 05446 05449 virtual void visit(const Ast::GrammarMemberNameId& member) = 0; 05450 }; 05451 05454 class GrammarStatement::Visitor { 05455 public: 05457 inline Visitor(){} 05458 05460 virtual ~Visitor(){} 05461 05462 public: 05465 virtual void visit(const Ast::GrammarRuleStatement& stmt) = 0; 05466 05469 virtual void visit(const Ast::LexerStatement& stmt) = 0; 05470 }; 05471 05474 class Statement::Visitor { 05475 public: 05477 inline Visitor(){} 05478 05480 virtual ~Visitor(){} 05481 05482 public: 05485 virtual void visit(const Ast::StatementBlock& stmt) = 0; 05486 05489 virtual void visit(const Ast::ExprStatement& stmt) = 0; 05490 05493 virtual void visit(const Ast::TypeSpecStatement& stmt) = 0; 05494 05497 virtual void visit(const Ast::BreakStatement& stmt) = 0; 05498 05501 virtual void visit(const Ast::ContinueStatement& stmt) = 0; 05502 05505 virtual void visit(const Ast::EmptyStatement& stmt) = 0; 05506 05509 virtual void visit(const Ast::IfThenStatement& stmt) = 0; 05510 05513 virtual void visit(const Ast::IfElseStatement& stmt) = 0; 05514 05517 virtual void visit(const Ast::ForStatement& stmt) = 0; 05518 05521 virtual void visit(const Ast::ForeachStatement& stmt) = 0; 05522 05525 virtual void visit(const Ast::SelectStatement& stmt) = 0; 05526 05529 virtual void visit(const Ast::SwitchStatement& stmt) = 0; 05530 05533 virtual void visit(const Ast::WhileStatement& stmt) = 0; 05534 05537 virtual void visit(const Ast::DoWhileStatement& stmt) = 0; 05538 05541 virtual void visit(const Ast::DefineVarStatement& stmt) = 0; 05542 05545 virtual void visit(const Ast::LogStatement& stmt) = 0; 05546 05549 virtual void visit(const Ast::RoutineReturnStatement& stmt) = 0; 05550 05553 virtual void visit(const Ast::FunctionReturnStatement& stmt) = 0; 05554 }; 05555 } 05556 05558 // Inline method implementations that has dependencies. 05560 template <typename T> 05561 inline T& Ast::TypeSpec::addChild(T& child) { 05562 _childList.append(ptr(child)); 05563 if(!child.hasParent()) 05564 child.setParent(ref(this)); 05565 const z::string& name = child.getName(); 05566 _childMap.insert(name, ptr(child)); 05567 return child; 05568 } 05569 05571 template <typename T> 05572 inline T* Ast::TypeSpec::hasChild(const z::string& name) const { 05573 ChildMap::found f = _childMap.find(name); 05574 if(!f) 05575 return 0; 05576 T* t = dynamic_cast<T*>(*f); // not using dcast because 0 is a valid value 05577 return t; 05578 }