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"
20 module ALib.Expressions.Impl;
21 import ALib.Characters.Functions;
24 import ALib.Strings.Calendar;
36#define ARG1 (*(args+1))
37#define INT(box) (box).Unbox<integer >()
38#define FLT(box) (box).Unbox<double >()
39#define DT(box) (box).Unbox<DateTime >()
40#define DUR(box) (box).Unbox<DateTime::Duration>()
41#define FUNC( name,...) Box name( Scope& scope, \
44 { (void) scope; (void) args; (void) end; __VA_ARGS__ }
46#if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
47# define TOINT(arg) arg
49# define TOINT(arg) integer(arg)
60DOX_MARKER([DOX_EXPR_FToLiteral_3])
61void FToLiteral_Duration(
const Box& constantValue,
AString& expressionString ) {
63 auto value= constantValue.Unbox<DateTime::Duration>().InNanoseconds();
68 result=
"Milliseconds";
70 result=
"Nanoseconds";
72 if( (value % 1000) == 0 ) {
74 result=
"Microseconds";
75 if( (value % 1000) == 0 ) {
77 result=
"Milliseconds";
78 if( (value % 1000) == 0 ) {
81 if( (value % 60) == 0 ) {
84 if( (value % 60) == 0 ) {
87 if( (value % 24) == 0 ) {
93 expressionString << result <<
'(' << value <<
')' ;
95DOX_MARKER([DOX_EXPR_FToLiteral_3])
97void FToLiteral_DateTime(
const Box& constantValue,
AString& expressionString ) {
100 expressionString <<
"UTCDateTime( " << ct.Year <<
','
106 << ct.Millisecond <<
')' ;
113FUNC( dateTime ,
auto qtyArgs= end-args;
115 ( qtyArgs> 1 ) ?
int( INT(*(args+1)) ) : 1,
116 ( qtyArgs> 2 ) ?
int( INT(*(args+2)) ) : 1,
117 ( qtyArgs> 3 ) ?
int( INT(*(args+3)) ) : 0,
118 ( qtyArgs> 4 ) ?
int( INT(*(args+4)) ) : 0,
119 ( qtyArgs> 5 ) ?
int( INT(*(args+5)) ) : 0,
120 ( qtyArgs> 6 ) ?
int( INT(*(args+6)) ) : 0
125FUNC( utcDateTime ,
auto qtyArgs= end-args;
127 ( qtyArgs> 1 ) ?
int( INT(*(args+1)) ) : 1,
128 ( qtyArgs> 2 ) ?
int( INT(*(args+2)) ) : 1,
129 ( qtyArgs> 3 ) ?
int( INT(*(args+3)) ) : 0,
130 ( qtyArgs> 4 ) ?
int( INT(*(args+4)) ) : 0,
131 ( qtyArgs> 5 ) ?
int( INT(*(args+5)) ) : 0,
132 ( qtyArgs> 6 ) ?
int( INT(*(args+6)) ) : 0
138 ct.
Hour= ct.Minute= ct.Second= ct.Millisecond= 0;
141 ct.
Hour= ct.Minute= ct.Second= ct.Millisecond= 0;
144FUNC( age ,
return DT(ARG0).Age(); )
145FUNC( isOlderThan ,
return DT(ARG0).IsOlderThan( DUR(ARG1) ); )
168FUNC( nanosecondsInt ,
return DateTime::Duration::FromNanoseconds ( INT(ARG0) ); )
170FUNC( microsecondsInt ,
return DateTime::Duration::FromAbsoluteMicroseconds ( INT(ARG0) ); )
171FUNC( millisecondsInt ,
return DateTime::Duration::FromAbsoluteMilliseconds ( INT(ARG0) ); )
172FUNC( secondsInt ,
return DateTime::Duration::FromAbsoluteSeconds ( INT(ARG0) ); )
173FUNC( minutesInt ,
return DateTime::Duration::FromAbsoluteMinutes ( INT(ARG0) ); )
174FUNC( hoursInt ,
return DateTime::Duration::FromAbsoluteHours ( INT(ARG0) ); )
175FUNC( daysInt ,
return DateTime::Duration::FromAbsoluteDays ( INT(ARG0) ); )
176FUNC( weeksInt ,
return DateTime::Duration::FromAbsoluteDays ( INT(ARG0) * 7 ); )
177FUNC( monthsInt ,
return DateTime::Duration::FromAbsoluteDays ( INT(ARG0) * 30 ); )
178FUNC( yearsInt ,
return DateTime::Duration::FromAbsoluteDays ( INT(ARG0) * 365 ); )
180FUNC( microsecondsFlt ,
return DateTime::Duration::FromMicroseconds ( FLT(ARG0) ); )
181FUNC( millisecondsFlt ,
return DateTime::Duration::FromMilliseconds ( FLT(ARG0) ); )
182FUNC( secondsFlt ,
return DateTime::Duration::FromSeconds ( FLT(ARG0) ); )
183FUNC( minutesFlt ,
return DateTime::Duration::FromMinutes ( FLT(ARG0) ); )
184FUNC( hoursFlt ,
return DateTime::Duration::FromHours ( FLT(ARG0) ); )
185FUNC( daysFlt ,
return DateTime::Duration::FromDays ( FLT(ARG0) ); )
186FUNC( weeksFlt ,
return DateTime::Duration::FromDays ( FLT(ARG0) * 7.0 ); )
187FUNC( monthsFlt ,
return DateTime::Duration::FromDays ( FLT(ARG0) * 30.0 ); )
188FUNC( yearsFlt ,
return DateTime::Duration::FromDays ( FLT(ARG0) * 365.0 ); )
192FUNC( inDays ,
return DUR(ARG0).InDays (); )
193FUNC( inHours ,
return DUR(ARG0).InHours (); )
194FUNC( inMinutes ,
return DUR(ARG0).InMinutes (); )
195FUNC( inSeconds ,
return DUR(ARG0).InSeconds (); )
196FUNC( inMilliseconds ,
return DUR(ARG0).InMilliseconds(); )
197FUNC( inMicroseconds ,
return DUR(ARG0).InMicroseconds(); )
198FUNC( inNanoseconds ,
return DUR(ARG0).InNanoseconds (); )
199FUNC( inHertz ,
return DUR(ARG0).InHertz(2); )
202FUNC( add_DTDUR ,
return DT(ARG0) + DUR(ARG1); )
203FUNC( add_DURDT ,
return DT(ARG1) + DUR(ARG0); )
204FUNC( sub_DTDUR ,
return DT(ARG0) - DUR(ARG1); )
205FUNC( sub_DTDT ,
return DT(ARG0) - DT(ARG1); )
206FUNC( eqDT ,
return DT(ARG0) == DT(ARG1); )
207FUNC( neqDT ,
return DT(ARG0) != DT(ARG1); )
208FUNC( gtDT ,
return DT(ARG0) > DT(ARG1); )
209FUNC( gteqDT ,
return DT(ARG0) >= DT(ARG1); )
210FUNC( smDT ,
return DT(ARG0) < DT(ARG1); )
211FUNC( smeqDT ,
return DT(ARG0) <= DT(ARG1); )
215FUNC( add_DURDUR ,
return DUR(ARG0) + DUR(ARG1); )
216FUNC( sub_DURDUR ,
return DUR(ARG0) - DUR(ARG1); )
217FUNC( mul_DURF ,
return DUR(ARG0) * FLT(ARG1); )
218FUNC( mul_FDUR ,
return DUR(ARG1) * FLT(ARG0); )
219FUNC( mul_DURI ,
return DUR(ARG0) * int64_t( INT(ARG1) ); )
220FUNC( mul_IDUR ,
return DUR(ARG1) * int64_t( INT(ARG0) ); )
221FUNC( div_DURF ,
return DUR(ARG0) / FLT(ARG1); )
222FUNC( div_DURI ,
return DUR(ARG0) / int64_t( INT(ARG1) ); )
224FUNC( eqDUR ,
return DUR(ARG0) == DUR(ARG1); )
225FUNC( neqDUR ,
return DUR(ARG0) != DUR(ARG1); )
226FUNC( gtDUR ,
return DUR(ARG0) > DUR(ARG1); )
227FUNC( gteqDUR ,
return DUR(ARG0) >= DUR(ARG1); )
228FUNC( smDUR ,
return DUR(ARG0) < DUR(ARG1); )
229FUNC( smeqDUR ,
return DUR(ARG0) <= DUR(ARG1); )
272DOX_MARKER([DOX_EXPR_FToLiteral_2])
275DOX_MARKER([DOX_EXPR_FToLiteral_2])
282 constexpr int tableSize= 58;
283 Token functionNames[tableSize];
284 strings::util::LoadResourcedTokens( EXPRESSIONS,
"CPD", functionNames
286 Token* descriptor= functionNames;
292 { *descriptor++, TOINT(1) }, { *descriptor++, TOINT( 2) }, { *descriptor++, TOINT( 3) }, { *descriptor++, TOINT( 4) },
293 { *descriptor++, TOINT(5) }, { *descriptor++, TOINT( 6) }, { *descriptor++, TOINT( 7) }, { *descriptor++, TOINT( 8) },
294 { *descriptor++, TOINT(9) }, { *descriptor++, TOINT(10) }, { *descriptor++, TOINT(11) }, { *descriptor++, TOINT(12) },
297 { *descriptor++, TOINT(0) }, { *descriptor++, TOINT(1) }, { *descriptor++, TOINT(2) }, { *descriptor++, TOINT( 3) },
298 { *descriptor++, TOINT(4) }, { *descriptor++, TOINT(5) }, { *descriptor++, TOINT(6) },
304DOX_MARKER([DOX_EXPR_FToLiteral_1])
306DOX_MARKER([DOX_EXPR_FToLiteral_1])
358 AddOperators( binaryOpTableDateTime );
361 "Descriptor table size mismatch: Consumed {} descriptors, {} available.",
362 descriptor - functionNames, tableSize )
375#undef BIN_ALIAS_ENTRY
int Hour
The calendar hour (0..23).
ALIB_DLL DateTime Get(lang::Timezone timezone=lang::Timezone::Local) const
#define CALCULUS_CALLBACK(func)
#define CALCULUS_SIGNATURE(BoxPointerArray)
#define ALIB_ASSERT_ERROR(cond, domain,...)
void BootstrapRegister(typename TFDecl::Signature function)
@ Local
Denotes local time.
@ UTC
Denotes UTC (coordinated universal time).
strings::util::Token Token
Type alias in namespace alib.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
time::DateTime DateTime
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
strings::util::CalendarDateTime CalendarDateTime
Type alias in namespace alib.
boxing::Box Box
Type alias in namespace alib.
expressions::Compiler Compiler
Type alias in namespace alib.
static ALIB_DLL Box Duration
Sample type-box for values of type DateTime::Duration).
static ALIB_DLL Box Integer
Sample type-box for integer types. (Precisely for type integer.)
static ALIB_DLL Box Boolean
Sample type-box for C++ type bool.
static ALIB_DLL Box Float
Sample type-box for C++ type double.
static ALIB_DLL Box DateTime
Sample type-box for date and time values of type DateTime).
static constexpr CTInvokable CTI
const std::tuple< String, Type, Type, CallbackDecl, Type, CTInvokable > OperatorTableEntry
static ALIB_DLL void Bootstrap()
ALIB_DLL DateAndTime(Compiler &compiler)