20#define BOL(box) (box).Unbox<bool >()
21#define INT(box) (box).Unbox<integer>()
23#define FUNC( name,...) Box name( Scope& scope, \
26 { (void) scope; (void) args; (void) end; __VA_ARGS__ }
29namespace alib {
namespace expressions {
namespace plugins {
46SortedTypes SortedType( Type type )
48 if( type.IsType<
bool >() )
return SortedTypes::Bool;
49 if( type.IsType<integer>() )
return SortedTypes::Integer;
50 if( type.IsType<
double >() )
return SortedTypes::Float;
51 if( type.IsType<String >() )
return SortedTypes::String;
52 return SortedTypes::UNKNOWN;
56FUNC( castI2F ,
return static_cast<double >( INT(ARG0) ); )
57FUNC( castB2F ,
return static_cast<double >( BOL(ARG0) ); )
58FUNC( castB2I ,
return static_cast<integer>( BOL(ARG0)); )
66bool AutoCast::TryCompilation( CIAutoCast& ciAutoCast )
69 if ( ciAutoCast.ArgsBegin + 1 >= ciAutoCast.ArgsEnd )
73 SortedTypes t1= SortedType( * ciAutoCast.ArgsBegin );
74 SortedTypes t2= SortedType( *(ciAutoCast.ArgsBegin+1) );
79 if( t1 > t2 ) { major= t1; minor= t2; }
80 else { major= t2; minor= t1; }
84 String decompileFunctionCall;
85 ALIB_DBG(
const char* upgradeCastDBG; )
88 if( major == SortedTypes::String )
91 decompileFunctionCall =
A_CHAR(
"String");
92ALIB_DBG(upgradeCastDBG =
"CBToString"; )
96 else if( major == SortedTypes::Float && minor == SortedTypes::Integer )
98 upgradeCast = castI2F;
99 decompileFunctionCall =
A_CHAR(
"Float");
100ALIB_DBG(upgradeCastDBG =
"castI2F"; )
105 else if( major == SortedTypes::Float && minor == SortedTypes::Bool )
107 upgradeCast = castB2F;
108 decompileFunctionCall =
A_CHAR(
"Float");
109ALIB_DBG(upgradeCastDBG =
"castB2F"; )
114 else if( major == SortedTypes::Integer && minor == SortedTypes::Bool )
116 upgradeCast = castB2I;
117 decompileFunctionCall =
A_CHAR(
"Integer");
118ALIB_DBG(upgradeCastDBG =
"castB2I"; )
122 else if( major == SortedTypes::Bool )
125 decompileFunctionCall =
A_CHAR(
"Boolean");
126ALIB_DBG(upgradeCastDBG =
"ToBoolean"; )
135 ciAutoCast.Callback = upgradeCast;
136 ciAutoCast.TypeOrValue = *(ciAutoCast.ArgsBegin + 1);
137 ciAutoCast.ReverseCastFunctionName = decompileFunctionCall;
138ALIB_DBG(ciAutoCast.DbgCallbackName = upgradeCastDBG; )
142 ciAutoCast.CallbackRhs = upgradeCast;
143 ciAutoCast.TypeOrValueRhs = *(ciAutoCast.ArgsBegin );
144 ciAutoCast.ReverseCastFunctionNameRhs = decompileFunctionCall;
145ALIB_DBG(ciAutoCast.DbgCallbackNameRhs = upgradeCastDBG; )
149 if( ciAutoCast.IsConst && ciAutoCast.Callback !=
nullptr )
151 ciAutoCast.TypeOrValue = ciAutoCast.Callback( ciAutoCast.CompileTimeScope,
152 ciAutoCast.ArgsBegin ,
153 ciAutoCast.ArgsEnd - 1 );
154 ciAutoCast.Callback =
nullptr;
156 else if( ciAutoCast.RhsIsConst && ciAutoCast.CallbackRhs !=
nullptr )
158 ciAutoCast.TypeOrValueRhs= ciAutoCast.CallbackRhs( ciAutoCast.CompileTimeScope,
159 ciAutoCast.ArgsBegin + 1 ,
160 ciAutoCast.ArgsEnd );
161 ciAutoCast.CallbackRhs =
nullptr;
ALIB_API Box CBToString(Scope &scope, ArgIterator args, ArgIterator)
ALIB_API Box ToBoolean(Scope &scope, ArgIterator args, ArgIterator)
Box(*)(Scope &scope, ArgIterator argsBegin, ArgIterator argsEnd) CallbackDecl
@ AutoCast
Auto-cast plug-in.
platform_specific integer
expressions::CompilerPlugin CompilerPlugin
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
expressions::Compiler Compiler
Type alias in namespace alib.
ALIB_API AutoCast(Compiler &compiler)