Loading...
Searching...
No Matches
by::origin Class Referencefinal

User-defined origin type. More...

#include <origin.hpp>

Inheritance diagram for by::origin:
by::obj by::baseObj by::node by::statable by::frameInteractable

Public Member Functions

 origin (const mgdType &newType)
 
 origin (const mgdType &newType, node *subpod)
 
 origin (const me &rhs)
 
me & operator= (const me &rhs)
 
scopesubs () override
 
state getState () const override
 
void setState (state new1) override
 
const ntypegetType () const override
 
const nodegetSubPod () const override
 Retrieves a sub-pod represented as a node.
 
const srcgetSrc () const override
 
void onCloneDeep (const clonable &from) override
 
baseObjmake () const override
 
nodegetCallComplete () override
 Returns the node responsible for completing the object's construction or initialization calls.
 
void setCallComplete (const node &new1)
 
void setCallComplete (const node *it) BY_SIDE_FUNC(setCallComplete)
 
nbool isComplete () const override
 
clonable * clone () const override
 
clonable * cloneDeep () const override
 
- Public Member Functions inherited from by::obj
 obj ()
 Constructs an obj representing an "any" class.
 
 obj (const scope &subs)
 Constructs an obj from a given scope, typically representing its initial set of children.
 
 obj (const me &rhs)
 Copy constructor for obj.
 
me & operator= (const me &rhs)
 
tstr< nbicontainermySubs () const override
 
scopegetShares ()
 
const scope &getShares() const BY_CONST_FUNC(getShares()) scope const scope::super & getOwns () const BY_CONST_FUNC(getOwns()) const ntype &getType() const override
 
void onCloneDeep (const clonable &from) override
 Performs a deep clone operation, copying the contents from another clonable object.
 
const node *getCallComplete() const BY_CONST_FUNC(getCallComplete()) protected str _onBeforeCtor () override
 Hook method called before the object's constructor is fully executed.
 
- Public Member Functions inherited from by::baseObj
str eval (const args &a) override
 
priorType prioritize (const args &a) const override
 
virtual const baseObjgetOrigin () const
 
void inFrame (const bicontainable *args) const override
 
void outFrame () const override
 
const modifiergetModifier () const override
 
- Public Member Functions inherited from by::node
me & operator[] (const std::string &name)
 
const me & operator[] (const std::string &name) const BY_CONST_FUNC(operator[](name))
 
me & operator[] (const std::string *it)
 
const me & operator[] (const std::string *it) const BY_CONST_FUNC(operator[](it))
 
me & operator[] (const nchar *name)
 
const me & operator[] (const nchar *name) const BY_CONST_FUNC(operator[](name))
 
nbool in (const node &elem) const
 
nbool in (const node *elem) const
 
const scopesubs () const BY_CONST_FUNC(subs()) virtual tstr< nbicontainer > mySubs() const
 Returns a tstr to a container of immediate sub-nodes (excluding inherited or chained ones).
 
const nodepromote (const node &it) const
 
const nodepromote (const node *it) const BY_SIDE_FUNC(promote)
 
template<typename T >
T * sub (std::function< nbool(const std::string &, const T &)> l)
 
template<typename T >
const T * sub (std::function< nbool(const std::string &, const T &)> l) const BY_CONST_FUNC(sub< T >(l)) template< typename T
 
template<typename T = me>
const T * sub () const BY_CONST_FUNC(sub< T >()) template< typename T
 
template<typename T = me>
T * sub (const std::string *it) BY_SIDE_FUNC(sub)
 
template<typename T = me>
const T * sub (const std::string &name) const BY_CONST_FUNC(sub< T >(name)) template< typename T
 
template<typename T = me>
T * sub (const std::string *name, const args &a) BY_SIDE_FUNC(name
 
template<typename T = me>
const T * sub (const std::string &name, const args &a) const BY_CONST_FUNC(sub< T >(name
 
template<typename T = me>
const T a const T * sub (const std::string *name, const args &a) const BY_CONST_FUNC(sub< T >(name
 
template<typename T >
const T a const T a tnarr< T, strTactic > subAll (std::function< nbool(const std::string &, const T &)> l) const
 
template<typename T = me>
tnarr< T, strTactic > subAll () const
 
template<typename T = me>
tpriorities< T > subAll (const std::string &name) const
 
template<typename T = me>
tpriorities< T > subAll (const std::string *it) const BY_SIDE_FUNC(subAll< T >) template< typename T
 
template<typename T = me>
tpriorities< T > subAll (const std::string &name, const args &a) const
 
template<typename T = me>
tpriorities< T > subAll (const std::string *name, const args *a) const BY_SIDE_FUNC(name
 
tpriorities< T > subAll< T > tpriorities ())
 
template<typename T = me>
tpriorities< T > subAll (const std::string *name, const args &a) const BY_SIDE_FUNC(name
 
tpriorities< T > subAll< T > tpriorities ())
 
bool canEval (const args &a) const
 
priorType prioritize (const args *it) const BY_SIDE_FUNC(it
 
str eval (const args *it) BY_SIDE_FUNC(eval)
 
str eval (const std::string &name, const args &a)
 
str eval (const std::string &name, const args *a) BY_SIDE_FUNC(a
 
str eval (name, a)
 
str str ())
 
str eval (const std::string *name, const args &a) BY_SIDE_FUNC(name
 
str eval str ())
 
str eval (const std::string *name, const args *a) BY_SIDE_FUNC(name &&a
 
str eval str ())
 
str eval (const std::string &name)
 
str eval (const std::string *it) BY_SIDE_FUNC(eval)
 
str eval ()
 
virtual void rel ()
 
template<typename T >
nbool is () const
 
nbool is (const typeProvidable &to) const
 
nbool is (const typeProvidable *it) const BY_SIDE_FUNC(is)
 
nbool is (const type &to) const
 
nbool is (const type *it) const BY_SIDE_FUNC(is)
 
template<typename T >
tstr< T > as () const
 
str as (const typeProvidable &to) const
 
str as (const typeProvidable *it) const BY_SIDE_FUNC(as)
 
str as (const type &to) const
 
str as (const type *it) const BY_SIDE_FUNC(as)
 
template<typename T >
nbool isImpli () const
 
virtual nbool isImpli (const type &to) const
 
nbool isImpli (const typeProvidable &to) const
 
nbool isImpli (const typeProvidable *it) const BY_SIDE_FUNC(isImpli)
 
template<typename T >
tstr< T > asImpli () const
 
virtual str asImpli (const type &to) const
 
str asImpli (const typeProvidable &to) const
 
str asImpli (const typeProvidable *it) const BY_SIDE_FUNC(asImpli)
 
virtual str infer () const
 
virtual void accept (const visitInfo &i, visitor &v)
 
void inFrame (const bicontainable *args) const override
 
void outFrame () const override
 
virtual void inFrame (const bicontainable *args) const=0
 
void inFrame () const
 
virtual void outFrame () const=0
 
- Public Member Functions inherited from by::frameInteractable
void inFrame () const
 

Additional Inherited Members

- Public Attributes inherited from by::node
T sub name
 
T sub nullptr
 
tpriorities< T > subAll< T > name
 
priorType prioritize it
 
priorType prioritize NO_MATCH
 
str eval name
 
- Static Public Attributes inherited from by::baseObj
static const std::string COMMON_NAME = "@common"
 
static const std::string EXPAND_NAME = "@expand"
 
- Protected Member Functions inherited from by::obj
 obj (const scope &shares, scope &owns)
 Protected constructor for obj, allowing explicit separation of shares and owns.
 
- Protected Member Functions inherited from by::baseObj
 baseObj ()=default
 Default constructor for baseObj.
 
 baseObj (const baseObj *org, nbool isScripted)
 Constructs a baseObj from an existing origin object.
 
str _onEvalSub (node &sub, const args &a) override
 Protected virtual method for evaluating a sub-node.
 
virtual void _inFrame (frame &fr, const bicontainable *args) const
 Enters this object's frame into the current execution stack.
 
- Protected Member Functions inherited from by::node
void _setSrc (const src *it) BY_SIDE_FUNC(_setSrc)
 
- Protected Attributes inherited from by::baseObj
tstr< baseObj_org
 

Detailed Description

User-defined origin type.

The original type defined by users in the byeol language is called an origin object. Constructor calls like ctor all create by copy-constructing origin objects.

Remarks
Never carelessly use metatype on origin. origin objects inherit from obj and are written assuming they'll be used as obj type except at creation time. Therefore, code like this is somewhat risky:
origin* new1 = new origin(...); // Referencing as origin* at creation is fine but..
new1->getType(); // Without understanding origin class characteristics,
// using the `meta` module to get type info like this isn't recommended.
// You might end up writing like below.
new1->cast<origin>(); // This code returns nullptr.
User-defined origin type.
Definition origin.hpp:99

Why cast<origin>() Returns nullptr

getType() doesn't just apply to script object origin types defined in byeol. It also provides types for native environment C++ classes like node and instance. For example, suppose a user writes this byeol code:

foo() void
boo() void
Definition tnarr.hpp:9

MyObj is part of the AST, so in C++ it's represented as an instance of obj. If you call getType() on the obj instance representing MyObj without additional code, what happens? Naturally ttype<obj>() is returned. The problem is calling on the obj instance representing YourObj also returns the same ttype<obj>(). Result: starter executing the program thinks YourObj and MyObj are the same type.

To solve this, the C++ obj class has a mgdType variable as a member. mgdType is type information for byeol types in the byeol runtime environment. See mgdType for details. The key point is this mgdType is structured to extend the existing native type meta information tree, so it's represented as inheriting from ttype<obj>. Thus, calling getType() on the C++ MyObj object yields mgdType, and this type can be distinguished from YourObj while having parent class obj type.

If we didn't do this but instead separated getType() and getMgdType(), all functions using type would need to distinguish whether the received node* is a native or script object, and if managed, call getMgdType() to handle it.

Sharp readers may now understand why cast<origin>() shouldn't be used. Without any processing, origin class's getType() would try to return ttype<origin>(). But as in the example above, the obj instance created to represent byeol code's MyObj must return mgdType. And naturally ttype<origin> has no inheritance relationship with the just-created mgdType instance, so calling cast<origin> fails the internal type check.

Therefore, the key is that starting from C++'s obj class, providing metatype by existing C++ class switches to providing metatype by C++ instance via mgdType. So don't carelessly try to use the meta module on origin objects. origin class's getType() returns a type with no relation to C++'s origin type. But this mgdType is created by the parser to have ttype<obj> as parent class. So type conversion to obj type or cast<obj>() etc. are no problem.

mgdType t = typeMaker::make<obj>("MyObj"); // mgdType usually created via typeMaker class.
// t has parent `obj` and name MyObj.
return new origin(t); // Unless necessary, return type should be obj* not origin*.
// But for origin-only functions like setCallComplete(),
// return as origin* type.
}
void main() {
auto* org = makeOrigin();
org->setCallComplete(....);
tstr<obj> bind1(org); // Success: obj is origin's parent class.
str bind2(org); // Success
obj* cast = bind2->cast<obj>(); // Success.
cast->getType().isSub<obj>(); // true
}
Script type for byeol objects.
Definition mgdType.hpp:18
Byeol runtime environment object.
Definition obj.hpp:62
Remarks
Since origin itself is premised on being used as obj type, almost all public functions except some are identical to obj type's API. No need to specifically use origin type.
The call itself has no C++ compiler restrictions. Type conversion is safely possible with dynamic_cast, and if you understand the above constraints well, you can freely call getType() from origin and use cast, isSub, etc. In summary, understand the intent and use it.

Member Function Documentation

◆ getCallComplete()

node * by::origin::getCallComplete ( )
overridevirtual

Returns the node responsible for completing the object's construction or initialization calls.

In the Byeol language, object construction might involve specific nodes that handle the final steps or logic after the object is initially created.

Returns
A pointer to the node that manages constructor completion, or nullptr if none.

Reimplemented from by::obj.

◆ getSrc()

const src & by::origin::getSrc ( ) const
overridevirtual

Reimplemented from by::baseObj.

◆ getState()

state by::origin::getState ( ) const
overridevirtual

Reimplemented from by::obj.

◆ getSubPod()

const node & by::origin::getSubPod ( ) const
overridevirtual

Retrieves a sub-pod represented as a node.

This method is used to access nested pod structures or components within this base object.

Returns
A const reference to the node representing the sub-pod.

Reimplemented from by::baseObj.

◆ isComplete()

nbool by::origin::isComplete ( ) const
overridevirtual

returns whether this instance is complete or not. if some instance is incomplete, it means that it's not accessible on byeolang source codes.

Reimplemented from by::node.

◆ make()

baseObj * by::origin::make ( ) const
overridevirtual

Reimplemented from by::baseObj.

◆ setState()

void by::origin::setState ( state new1)
overridevirtual

Reimplemented from by::obj.

◆ subs()

scope & by::origin::subs ( )
overridevirtual

Reimplemented from by::obj.


The documentation for this class was generated from the following file:
to Top