tmock.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "core/ast/node.hpp"
6
7namespace by {
8
13 template <typename T> class _nout tmock: public T {
14 BY(ME(tmock, T))
15 friend class exprMaker;
16
17 public:
18 tmock(): super() {}
19
20 tmock(const T& org): super(), _org(org) {}
21
22 tmock(const T* org): super(), _org(org) {}
23
24 public:
25 const ntype& getType() const override {
26 if(_org) return _org->getType();
27 return ttype<node>::get();
28 }
29
30 using super::subs;
31
32 scope& subs() override {
33 if(_org) return _org->subs();
34 return dumScope::singleton();
35 }
36
37 using super::prioritize;
38
39 priorType prioritize(const args& a) const override {
40 if(_org) return _org->prioritize(a);
41 return NO_MATCH;
42 }
43
44 using super::run;
45
46 str run(const args& a) override {
47 if(_org) return _org->run(a);
48 return str();
49 }
50
51 clonable* clone() const override {
52 if(_org) return _org->clone();
53 return new me(*this);
54 }
55
56 const src& getSrc() const override {
57 if(_org) return _org->getSrc();
58 return super::getSrc();
59 }
60
61 using super::cast;
62
63 void* cast(const type& to) override {
64 if(ttype<me>::get().isSub(to)) return this;
65 if(_org) return _org->cast(to);
66 return nullptr;
67 }
68
69 clonable* cloneDeep() const override { return clone(); }
70
71 void onCloneDeep(const clonable& from) override {}
72
73 protected:
74 using super::_setSrc;
75
76 void _setSrc(const src& s) override {
77 if(!_org) return;
78 _org->_setSrc(s);
79 }
80
81 private:
82 str _org;
83 };
84
85 typedef tmock<node> mockNode;
86} // namespace by
Function call arguments container.
Definition: args.hpp:13
Interface for objects that can be cloned.
Definition: clonable.hpp:12
Factory for creating expressions with source location information.
Definition: exprMaker.hpp:17
Native type system for byeol language.
Definition: ntype.hpp:19
Source location information.
Definition: src.hpp:11
Mock object template for testing and verification.
Definition: tmock.hpp:13
Template type wrapper for type metadata management.
Definition: ttype.hpp:16
Base class for runtime type information in byeol language.
Definition: type.hpp:12
priorType
the lower value, the higher priority.
Definition: tpriorities.hpp:8
@ NO_MATCH
Definition: tpriorities.hpp:16