8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
29#define BOL(box) (box).Unbox<bool >()
30#define INT(box) (box).Unbox<integer>()
32#define FUNC( name,...) Box name( Scope& scope, \
35 { (void) scope; (void) args; (void) end; __VA_ARGS__ }
55SortedTypes SortedType( Type type )
57 if( type.IsType<
bool >() )
return SortedTypes::Bool;
58 if( type.IsType<integer>() )
return SortedTypes::Integer;
59 if( type.IsType<
double >() )
return SortedTypes::Float;
60 if( type.IsType<String >() )
return SortedTypes::String;
61 return SortedTypes::UNKNOWN;
65FUNC( castI2F ,
return double ( INT(ARG0) ); )
66FUNC( castB2F ,
return double ( BOL(ARG0) ); )
67FUNC( castB2I ,
return integer( BOL(ARG0)); )
75bool AutoCast::TryCompilation( CIAutoCast& ciAutoCast )
78 if ( ciAutoCast.ArgsBegin + 1 >= ciAutoCast.ArgsEnd )
82 SortedTypes t1= SortedType( * ciAutoCast.ArgsBegin );
83 SortedTypes t2= SortedType( *(ciAutoCast.ArgsBegin+1) );
88 if( t1 > t2 ) { major= t1; minor= t2; }
89 else { major= t2; minor= t1; }
93 String decompileFunctionCall;
94 ALIB_DBG(
const char* upgradeCastDBG; )
97 if( major == SortedTypes::String )
100 decompileFunctionCall =
A_CHAR(
"String");
101ALIB_DBG(upgradeCastDBG =
"CBToString"; )
105 else if( major == SortedTypes::Float && minor == SortedTypes::Integer )
107 upgradeCast = castI2F;
108 decompileFunctionCall =
A_CHAR(
"Float");
109ALIB_DBG(upgradeCastDBG =
"castI2F"; )
114 else if( major == SortedTypes::Float && minor == SortedTypes::Bool )
116 upgradeCast = castB2F;
117 decompileFunctionCall =
A_CHAR(
"Float");
118ALIB_DBG(upgradeCastDBG =
"castB2F"; )
123 else if( major == SortedTypes::Integer && minor == SortedTypes::Bool )
125 upgradeCast = castB2I;
126 decompileFunctionCall =
A_CHAR(
"Integer");
127ALIB_DBG(upgradeCastDBG =
"castB2I"; )
131 else if( major == SortedTypes::Bool )
134 decompileFunctionCall =
A_CHAR(
"Boolean");
135ALIB_DBG(upgradeCastDBG =
"ToBoolean"; )
144 ciAutoCast.Callback = upgradeCast;
145 ciAutoCast.TypeOrValue = *(ciAutoCast.ArgsBegin + 1);
146 ciAutoCast.ReverseCastFunctionName = decompileFunctionCall;
147ALIB_DBG(ciAutoCast.DbgCallbackName = upgradeCastDBG; )
151 ciAutoCast.CallbackRhs = upgradeCast;
152 ciAutoCast.TypeOrValueRhs = *(ciAutoCast.ArgsBegin );
153 ciAutoCast.ReverseCastFunctionNameRhs = decompileFunctionCall;
154ALIB_DBG(ciAutoCast.DbgCallbackNameRhs = upgradeCastDBG; )
158 if( ciAutoCast.IsConst && ciAutoCast.Callback !=
nullptr )
160 ciAutoCast.TypeOrValue = ciAutoCast.Callback( ciAutoCast.CompileTimeScope,
161 ciAutoCast.ArgsBegin ,
162 ciAutoCast.ArgsEnd - 1 );
163 ciAutoCast.Callback =
nullptr;
165 else if( ciAutoCast.RhsIsConst && ciAutoCast.CallbackRhs !=
nullptr )
167 ciAutoCast.TypeOrValueRhs= ciAutoCast.CallbackRhs( ciAutoCast.CompileTimeScope,
168 ciAutoCast.ArgsBegin + 1 ,
169 ciAutoCast.ArgsEnd );
170 ciAutoCast.CallbackRhs =
nullptr;
ALIB_DLL Box ToBoolean(Scope &scope, ArgIterator args, ArgIterator)
ALIB_DLL Box CBToString(Scope &scope, ArgIterator args, ArgIterator)
Box(*)(Scope &scope, ArgIterator argsBegin, ArgIterator argsEnd) CallbackDecl
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_DLL AutoCast(Compiler &compiler)