4#define BOL(box) (box).Unbox<bool >()
5#define INT(box) (box).Unbox<integer>()
7#define FUNC( name,...) Box name( Scope& scope, \
10 { (void) scope; (void) args; (void) end; __VA_ARGS__ }
20enum class SortedTypes {
28SortedTypes SortedType( Type type ) {
29 if( type.IsType<
bool >() )
return SortedTypes::Bool;
30 if( type.IsType<integer>() )
return SortedTypes::Integer;
31 if( type.IsType<
double >() )
return SortedTypes::Float;
32 if( type.IsType<String >() )
return SortedTypes::String;
33 return SortedTypes::UNKNOWN;
37FUNC( castI2F ,
return double ( INT(ARG0) ); )
38FUNC( castB2F ,
return double ( BOL(ARG0) ); )
39FUNC( castB2I ,
return integer( BOL(ARG0)); )
47bool AutoCast::TryCompilation( CIAutoCast& ciAutoCast ) {
49 if ( ciAutoCast.ArgsBegin + 1 >= ciAutoCast.ArgsEnd )
53 SortedTypes t1= SortedType( * ciAutoCast.ArgsBegin );
54 SortedTypes t2= SortedType( *(ciAutoCast.ArgsBegin+1) );
59 if( t1 > t2 ) { major= t1; minor= t2; }
60 else { major= t2; minor= t1; }
64 String decompileFunctionCall;
65 ALIB_DBG(
const char* upgradeCastDBG; )
68 if( major == SortedTypes::String ) {
70 decompileFunctionCall =
A_CHAR(
"String");
71ALIB_DBG(upgradeCastDBG =
"CBToString"; )
75 else if( major == SortedTypes::Float && minor == SortedTypes::Integer ) {
76 upgradeCast = castI2F;
77 decompileFunctionCall =
A_CHAR(
"Float");
78ALIB_DBG(upgradeCastDBG =
"castI2F"; )
83 else if( major == SortedTypes::Float && minor == SortedTypes::Bool ) {
84 upgradeCast = castB2F;
85 decompileFunctionCall =
A_CHAR(
"Float");
86ALIB_DBG(upgradeCastDBG =
"castB2F"; )
91 else if( major == SortedTypes::Integer && minor == SortedTypes::Bool ) {
92 upgradeCast = castB2I;
93 decompileFunctionCall =
A_CHAR(
"Integer");
94ALIB_DBG(upgradeCastDBG =
"castB2I"; )
98 else if( major == SortedTypes::Bool ) {
100 decompileFunctionCall =
A_CHAR(
"Boolean");
101ALIB_DBG(upgradeCastDBG =
"ToBoolean"; )
109 ciAutoCast.Callback = upgradeCast;
110 ciAutoCast.TypeOrValue = *(ciAutoCast.ArgsBegin + 1);
111 ciAutoCast.ReverseCastFunctionName = decompileFunctionCall;
112ALIB_DBG(ciAutoCast.DbgCallbackName = upgradeCastDBG; )
114 ciAutoCast.CallbackRhs = upgradeCast;
115 ciAutoCast.TypeOrValueRhs = *(ciAutoCast.ArgsBegin );
116 ciAutoCast.ReverseCastFunctionNameRhs = decompileFunctionCall;
117ALIB_DBG(ciAutoCast.DbgCallbackNameRhs = upgradeCastDBG; )
121 if( ciAutoCast.IsConst && ciAutoCast.Callback !=
nullptr ) {
122 ciAutoCast.TypeOrValue = ciAutoCast.Callback( ciAutoCast.CompileTimeScope,
123 ciAutoCast.ArgsBegin ,
124 ciAutoCast.ArgsEnd - 1 );
125 ciAutoCast.Callback =
nullptr;
127 else if( ciAutoCast.RhsIsConst && ciAutoCast.CallbackRhs !=
nullptr ) {
128 ciAutoCast.TypeOrValueRhs= ciAutoCast.CallbackRhs( ciAutoCast.CompileTimeScope,
129 ciAutoCast.ArgsBegin + 1 ,
130 ciAutoCast.ArgsEnd );
131 ciAutoCast.CallbackRhs =
nullptr;
Box ToBoolean(Scope &scope, ArgIterator args, ArgIterator)
Box CBToString(Scope &scope, ArgIterator args, ArgIterator)
Box(*)(Scope &scope, ArgIterator argsBegin, ArgIterator argsEnd) CallbackDecl
platform_specific integer
expressions::Compiler Compiler
Type alias in namespace #"%alib".
strings::TString< character > String
Type alias in namespace #"%alib".
expressions::CompilerPlugin CompilerPlugin
Type alias in namespace #"%alib".
AutoCast(Compiler &compiler)